aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDave Jones <davej@redhat.com>2006-04-18 18:19:55 -0400
committerDave Jones <davej@redhat.com>2006-04-18 18:19:55 -0400
commitf1f76afd71e0f17af9a35fcb649f4bab53304a4d (patch)
treea56257b13a0eda4a9b7e950c3b85adad16341b80 /drivers
parent530515a06f90c0831732709efee4a99497bd2b7c (diff)
parent385910f2b275a636238f70844f1b6da9fda6f2da (diff)
Merge ../linus
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile6
-rw-r--r--drivers/acpi/Kconfig2
-rw-r--r--drivers/acpi/ec.c4
-rw-r--r--drivers/base/bus.c5
-rw-r--r--drivers/base/class.c13
-rw-r--r--drivers/base/dd.c2
-rw-r--r--drivers/base/node.c2
-rw-r--r--drivers/base/power/suspend.c12
-rw-r--r--drivers/block/amiflop.c1
-rw-r--r--drivers/block/cciss.c96
-rw-r--r--drivers/bluetooth/bluecard_cs.c119
-rw-r--r--drivers/bluetooth/bt3c_cs.c130
-rw-r--r--drivers/bluetooth/btuart_cs.c130
-rw-r--r--drivers/bluetooth/dtl1_cs.c120
-rw-r--r--drivers/cdrom/aztcd.c2
-rw-r--r--drivers/char/Kconfig21
-rw-r--r--drivers/char/Makefile5
-rw-r--r--drivers/char/agp/efficeon-agp.c8
-rw-r--r--drivers/char/applicom.c2
-rw-r--r--drivers/char/drm/drmP.h20
-rw-r--r--drivers/char/drm/drm_bufs.c20
-rw-r--r--drivers/char/drm/drm_dma.c4
-rw-r--r--drivers/char/drm/drm_drv.c4
-rw-r--r--drivers/char/drm/drm_memory.c173
-rw-r--r--drivers/char/drm/drm_memory.h128
-rw-r--r--drivers/char/drm/drm_memory_debug.h72
-rw-r--r--drivers/char/drm/drm_pci.c30
-rw-r--r--drivers/char/drm/drm_pciids.h116
-rw-r--r--drivers/char/drm/i915_dma.c2
-rw-r--r--drivers/char/drm/i915_irq.c2
-rw-r--r--drivers/char/drm/r300_cmdbuf.c86
-rw-r--r--drivers/char/drm/r300_reg.h39
-rw-r--r--drivers/char/drm/radeon_cp.c151
-rw-r--r--drivers/char/drm/radeon_drm.h5
-rw-r--r--drivers/char/drm/radeon_drv.h25
-rw-r--r--drivers/char/drm/radeon_state.c105
-rw-r--r--drivers/char/drm/sis_mm.c2
-rw-r--r--drivers/char/drm/via_irq.c12
-rw-r--r--drivers/char/dtlk.c2
-rw-r--r--drivers/char/generic_nvram.c5
-rw-r--r--drivers/char/hvc_console.c101
-rw-r--r--drivers/char/hvc_console.h63
-rw-r--r--drivers/char/hvc_rtas.c138
-rw-r--r--drivers/char/hvc_vio.c11
-rw-r--r--drivers/char/hvcs.c3
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c18
-rw-r--r--drivers/char/ipmi/ipmi_kcs_sm.c8
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c82
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c2
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c85
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c61
-rw-r--r--drivers/char/istallion.c32
-rw-r--r--drivers/char/keyboard.c118
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c121
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c133
-rw-r--r--drivers/char/pcmcia/synclink_cs.c116
-rw-r--r--drivers/char/random.c1
-rw-r--r--drivers/char/stallion.c46
-rw-r--r--drivers/char/tlclk.c36
-rw-r--r--drivers/char/tty_io.c30
-rw-r--r--drivers/char/vt.c4
-rw-r--r--drivers/char/watchdog/Kconfig7
-rw-r--r--drivers/char/watchdog/Makefile1
-rw-r--r--drivers/char/watchdog/at91_wdt.c228
-rw-r--r--drivers/char/watchdog/pcwd.c137
-rw-r--r--drivers/char/watchdog/pcwd_usb.c3
-rw-r--r--drivers/edac/Kconfig2
-rw-r--r--drivers/firmware/Makefile3
-rw-r--r--drivers/firmware/dmi_scan.c358
-rw-r--r--drivers/hwmon/hdaps.c51
-rw-r--r--drivers/hwmon/w83792d.c5
-rw-r--r--drivers/i2c/busses/Kconfig5
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c9
-rw-r--r--drivers/i2c/busses/i2c-parport.c9
-rw-r--r--drivers/i2c/busses/i2c-parport.h2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c8
-rw-r--r--drivers/i2c/chips/ds1374.c16
-rw-r--r--drivers/i2c/chips/m41t00.c16
-rw-r--r--drivers/ide/ide-disk.c3
-rw-r--r--drivers/ide/ide-taskfile.c8
-rw-r--r--drivers/ide/legacy/ide-cs.c127
-rw-r--r--drivers/ide/pci/via82cxxx.c2
-rw-r--r--drivers/ide/ppc/pmac.c2
-rw-r--r--drivers/ieee1394/ohci1394.c4
-rw-r--r--drivers/ieee1394/sbp2.c32
-rw-r--r--drivers/infiniband/Kconfig1
-rw-r--r--drivers/infiniband/Makefile1
-rw-r--r--drivers/infiniband/core/cache.c2
-rw-r--r--drivers/infiniband/core/mad.c114
-rw-r--r--drivers/infiniband/core/mad_priv.h3
-rw-r--r--drivers/infiniband/core/mad_rmpp.c54
-rw-r--r--drivers/infiniband/core/user_mad.c30
-rw-r--r--drivers/infiniband/core/verbs.c34
-rw-r--r--drivers/infiniband/hw/ipath/Kconfig16
-rw-r--r--drivers/infiniband/hw/ipath/Makefile36
-rw-r--r--drivers/infiniband/hw/ipath/ipath_common.h616
-rw-r--r--drivers/infiniband/hw/ipath/ipath_cq.c295
-rw-r--r--drivers/infiniband/hw/ipath/ipath_debug.h96
-rw-r--r--drivers/infiniband/hw/ipath/ipath_diag.c379
-rw-r--r--drivers/infiniband/hw/ipath/ipath_driver.c1983
-rw-r--r--drivers/infiniband/hw/ipath/ipath_eeprom.c613
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c1910
-rw-r--r--drivers/infiniband/hw/ipath/ipath_fs.c605
-rw-r--r--drivers/infiniband/hw/ipath/ipath_ht400.c1586
-rw-r--r--drivers/infiniband/hw/ipath/ipath_init_chip.c951
-rw-r--r--drivers/infiniband/hw/ipath/ipath_intr.c841
-rw-r--r--drivers/infiniband/hw/ipath/ipath_kernel.h884
-rw-r--r--drivers/infiniband/hw/ipath/ipath_keys.c236
-rw-r--r--drivers/infiniband/hw/ipath/ipath_layer.c1515
-rw-r--r--drivers/infiniband/hw/ipath/ipath_layer.h181
-rw-r--r--drivers/infiniband/hw/ipath/ipath_mad.c1352
-rw-r--r--drivers/infiniband/hw/ipath/ipath_mr.c383
-rw-r--r--drivers/infiniband/hw/ipath/ipath_pe800.c1247
-rw-r--r--drivers/infiniband/hw/ipath/ipath_qp.c913
-rw-r--r--drivers/infiniband/hw/ipath/ipath_rc.c1857
-rw-r--r--drivers/infiniband/hw/ipath/ipath_registers.h446
-rw-r--r--drivers/infiniband/hw/ipath/ipath_ruc.c552
-rw-r--r--drivers/infiniband/hw/ipath/ipath_srq.c273
-rw-r--r--drivers/infiniband/hw/ipath/ipath_stats.c303
-rw-r--r--drivers/infiniband/hw/ipath/ipath_sysfs.c778
-rw-r--r--drivers/infiniband/hw/ipath/ipath_uc.c645
-rw-r--r--drivers/infiniband/hw/ipath/ipath_ud.c621
-rw-r--r--drivers/infiniband/hw/ipath/ipath_user_pages.c207
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c1222
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.h697
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs_mcast.c333
-rw-r--r--drivers/infiniband/hw/ipath/ipath_wc_x86_64.c157
-rw-r--r--drivers/infiniband/hw/ipath/ips_common.h263
-rw-r--r--drivers/infiniband/hw/ipath/verbs_debug.h107
-rw-r--r--drivers/infiniband/hw/mthca/Kconfig11
-rw-r--r--drivers/infiniband/hw/mthca/Makefile4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c102
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.h1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_dev.h23
-rw-r--r--drivers/infiniband/hw/mthca/mthca_eq.c6
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mad.c44
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c28
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mcg.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_pd.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h3
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c48
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c31
-rw-r--r--drivers/infiniband/ulp/ipoib/Kconfig3
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h7
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_fs.c2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c22
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c90
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c58
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c6
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c5
-rw-r--r--drivers/input/evbug.c3
-rw-r--r--drivers/input/evdev.c6
-rw-r--r--drivers/input/gameport/gameport.c30
-rw-r--r--drivers/input/gameport/ns558.c13
-rw-r--r--drivers/input/input.c422
-rw-r--r--drivers/input/joydev.c6
-rw-r--r--drivers/input/joystick/amijoy.c11
-rw-r--r--drivers/input/joystick/db9.c13
-rw-r--r--drivers/input/joystick/gamecon.c96
-rw-r--r--drivers/input/joystick/iforce/iforce-ff.c24
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c2
-rw-r--r--drivers/input/joystick/iforce/iforce.h5
-rw-r--r--drivers/input/joystick/turbografx.c13
-rw-r--r--drivers/input/keyboard/Kconfig2
-rw-r--r--drivers/input/keyboard/atkbd.c24
-rw-r--r--drivers/input/keyboard/corgikbd.c35
-rw-r--r--drivers/input/keyboard/hil_kbd.c63
-rw-r--r--drivers/input/keyboard/hilkbd.c53
-rw-r--r--drivers/input/keyboard/spitzkbd.c10
-rw-r--r--drivers/input/misc/pcspkr.c27
-rw-r--r--drivers/input/misc/uinput.c14
-rw-r--r--drivers/input/mouse/hil_ptr.c93
-rw-r--r--drivers/input/mouse/psmouse-base.c38
-rw-r--r--drivers/input/mouse/synaptics.c18
-rw-r--r--drivers/input/mousedev.c6
-rw-r--r--drivers/input/power.c3
-rw-r--r--drivers/input/serio/gscps2.c4
-rw-r--r--drivers/input/serio/hil_mlc.c3
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h26
-rw-r--r--drivers/input/serio/libps2.c10
-rw-r--r--drivers/input/serio/parkbd.c3
-rw-r--r--drivers/input/serio/rpckbd.c3
-rw-r--r--drivers/input/serio/serio.c48
-rw-r--r--drivers/input/serio/serio_raw.c29
-rw-r--r--drivers/input/tsdev.c6
-rw-r--r--drivers/isdn/gigaset/Kconfig4
-rw-r--r--drivers/isdn/gigaset/asyncdata.c132
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c870
-rw-r--r--drivers/isdn/gigaset/common.c505
-rw-r--r--drivers/isdn/gigaset/ev-layer.c667
-rw-r--r--drivers/isdn/gigaset/gigaset.h600
-rw-r--r--drivers/isdn/gigaset/i4l.c231
-rw-r--r--drivers/isdn/gigaset/interface.c235
-rw-r--r--drivers/isdn/gigaset/isocdata.c139
-rw-r--r--drivers/isdn/gigaset/proc.c51
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c455
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c185
-rw-r--r--drivers/isdn/hisax/avma1_cs.c182
-rw-r--r--drivers/isdn/hisax/elsa_cs.c112
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c143
-rw-r--r--drivers/isdn/hisax/teles_cs.c121
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c20
-rw-r--r--drivers/isdn/sc/ioctl.c9
-rw-r--r--drivers/leds/Kconfig88
-rw-r--r--drivers/leds/Makefile17
-rw-r--r--drivers/leds/led-class.c167
-rw-r--r--drivers/leds/led-core.c25
-rw-r--r--drivers/leds/led-triggers.c239
-rw-r--r--drivers/leds/leds-corgi.c121
-rw-r--r--drivers/leds/leds-ixp4xx-gpio.c215
-rw-r--r--drivers/leds/leds-locomo.c95
-rw-r--r--drivers/leds/leds-s3c24xx.c163
-rw-r--r--drivers/leds/leds-spitz.c125
-rw-r--r--drivers/leds/leds-tosa.c131
-rw-r--r--drivers/leds/leds.h44
-rw-r--r--drivers/leds/ledtrig-ide-disk.c62
-rw-r--r--drivers/leds/ledtrig-timer.c170
-rw-r--r--drivers/macintosh/adb.c3
-rw-r--r--drivers/macintosh/adbhid.c4
-rw-r--r--drivers/macintosh/mediabay.c4
-rw-r--r--drivers/md/Kconfig11
-rw-r--r--drivers/md/dm-target.c3
-rw-r--r--drivers/md/md.c9
-rw-r--r--drivers/md/raid1.c19
-rw-r--r--drivers/md/raid10.c6
-rw-r--r--drivers/md/raid5.c34
-rw-r--r--drivers/md/raid6main.c31
-rw-r--r--drivers/media/Kconfig24
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig1
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c12
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c18
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h2
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c54
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c47
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h2
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x-fe.c5
-rw-r--r--drivers/media/dvb/frontends/Kconfig12
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c12
-rw-r--r--drivers/media/dvb/ttpci/av7110.c8
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c2
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c13
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c78
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c24
-rw-r--r--drivers/media/dvb/ttpci/budget.h13
-rw-r--r--drivers/media/video/Kconfig233
-rw-r--r--drivers/media/video/Makefile8
-rw-r--r--drivers/media/video/bt8xx/Makefile2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c170
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c2
-rw-r--r--drivers/media/video/cpia.c13
-rw-r--r--drivers/media/video/cpia2/cpia2.h2
-rw-r--r--drivers/media/video/cpia_pp.c2
-rw-r--r--drivers/media/video/cx25840/Makefile2
-rw-r--r--drivers/media/video/cx25840/cx25840-audio.c3
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c24
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h (renamed from drivers/media/video/cx25840/cx25840.h)46
-rw-r--r--drivers/media/video/cx25840/cx25840-firmware.c15
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c9
-rw-r--r--drivers/media/video/cx88/Kconfig15
-rw-r--r--drivers/media/video/cx88/Makefile6
-rw-r--r--drivers/media/video/em28xx/Makefile2
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c4
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c33
-rw-r--r--drivers/media/video/et61x251/Kconfig14
-rw-r--r--drivers/media/video/ir-kbd-i2c.c3
-rw-r--r--drivers/media/video/msp3400-driver.c91
-rw-r--r--drivers/media/video/msp3400-driver.h6
-rw-r--r--drivers/media/video/msp3400-kthreads.c121
-rw-r--r--drivers/media/video/planb.c2
-rw-r--r--drivers/media/video/pwc/Kconfig28
-rw-r--r--drivers/media/video/saa7115.c65
-rw-r--r--drivers/media/video/saa7127.c43
-rw-r--r--drivers/media/video/saa7134/Kconfig1
-rw-r--r--drivers/media/video/saa7134/Makefile6
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c66
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c3
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c4
-rw-r--r--drivers/media/video/saa7134/saa7134.h1
-rw-r--r--drivers/media/video/sn9c102/Kconfig11
-rw-r--r--drivers/media/video/tuner-core.c12
-rw-r--r--drivers/media/video/tvaudio.c15
-rw-r--r--drivers/media/video/tveeprom.c6
-rw-r--r--drivers/media/video/tvp5150.c140
-rw-r--r--drivers/media/video/upd64031a.c286
-rw-r--r--drivers/media/video/upd64083.c262
-rw-r--r--drivers/media/video/usbvideo/Kconfig38
-rw-r--r--drivers/media/video/usbvideo/Makefile8
-rw-r--r--drivers/media/video/v4l2-common.c8
-rw-r--r--drivers/media/video/video-buf.c14
-rw-r--r--drivers/media/video/wm8739.c355
-rw-r--r--drivers/media/video/zc0301/Kconfig11
-rw-r--r--drivers/message/fusion/mptsas.c10
-rw-r--r--drivers/mmc/Kconfig29
-rw-r--r--drivers/mmc/Makefile7
-rw-r--r--drivers/mmc/at91_mci.c988
-rw-r--r--drivers/mmc/au1xmmc.c19
-rw-r--r--drivers/mmc/imxmmc.c1096
-rw-r--r--drivers/mmc/imxmmc.h67
-rw-r--r--drivers/mmc/mmc.c19
-rw-r--r--drivers/mmc/mmci.c4
-rw-r--r--drivers/mmc/omap.c1226
-rw-r--r--drivers/mmc/omap.h55
-rw-r--r--drivers/mmc/pxamci.c24
-rw-r--r--drivers/mmc/sdhci.c6
-rw-r--r--drivers/mmc/wbsd.c9
-rw-r--r--drivers/mtd/chips/Kconfig21
-rw-r--r--drivers/mtd/chips/amd_flash.c4
-rw-r--r--drivers/mtd/chips/jedec_probe.c19
-rw-r--r--drivers/mtd/chips/sharp.c7
-rw-r--r--drivers/mtd/cmdlinepart.c7
-rw-r--r--drivers/mtd/devices/Kconfig13
-rw-r--r--drivers/mtd/devices/Makefile1
-rw-r--r--drivers/mtd/devices/blkmtd.c820
-rw-r--r--drivers/mtd/devices/block2mtd.c13
-rw-r--r--drivers/mtd/devices/doc2000.c37
-rw-r--r--drivers/mtd/devices/lart.c10
-rw-r--r--drivers/mtd/devices/m25p80.c2
-rw-r--r--drivers/mtd/devices/ms02-nv.c2
-rw-r--r--drivers/mtd/inftlcore.c7
-rw-r--r--drivers/mtd/maps/alchemy-flash.c4
-rw-r--r--drivers/mtd/maps/cfi_flagadm.c2
-rw-r--r--drivers/mtd/maps/dbox2-flash.c2
-rw-r--r--drivers/mtd/maps/dilnetpc.c4
-rw-r--r--drivers/mtd/maps/dmv182.c2
-rw-r--r--drivers/mtd/maps/h720x-flash.c2
-rw-r--r--drivers/mtd/maps/netsc520.c4
-rw-r--r--drivers/mtd/maps/nettel.c3
-rw-r--r--drivers/mtd/maps/ocotea.c6
-rw-r--r--drivers/mtd/maps/pci.c3
-rw-r--r--drivers/mtd/maps/pcmciamtd.c117
-rw-r--r--drivers/mtd/maps/redwood.c3
-rw-r--r--drivers/mtd/maps/sbc8240.c8
-rw-r--r--drivers/mtd/maps/sc520cdp.c2
-rw-r--r--drivers/mtd/maps/scx200_docflash.c2
-rw-r--r--drivers/mtd/maps/sharpsl-flash.c4
-rw-r--r--drivers/mtd/maps/ts5500_flash.c2
-rw-r--r--drivers/mtd/maps/uclinux.c2
-rw-r--r--drivers/mtd/maps/vmax301.c2
-rw-r--r--drivers/mtd/mtd_blkdevs.c32
-rw-r--r--drivers/mtd/mtdblock.c14
-rw-r--r--drivers/mtd/mtdcore.c45
-rw-r--r--drivers/mtd/nand/Kconfig17
-rw-r--r--drivers/mtd/nand/au1550nd.c4
-rw-r--r--drivers/mtd/nand/nand_base.c26
-rw-r--r--drivers/mtd/redboot.c6
-rw-r--r--drivers/net/3c59x.c33
-rw-r--r--drivers/net/8139cp.c12
-rw-r--r--drivers/net/8390.h2
-rw-r--r--drivers/net/Kconfig2
-rw-r--r--drivers/net/acenic_firmware.h10
-rw-r--r--drivers/net/arcnet/arcnet.c3
-rw-r--r--drivers/net/arcnet/com90xx.c4
-rw-r--r--drivers/net/b44.c77
-rw-r--r--drivers/net/bnx2.c2
-rw-r--r--drivers/net/bonding/bond_3ad.c28
-rw-r--r--drivers/net/bonding/bond_3ad.h1
-rw-r--r--drivers/net/bonding/bond_main.c97
-rw-r--r--drivers/net/bonding/bonding.h4
-rw-r--r--drivers/net/chelsio/Makefile2
-rw-r--r--drivers/net/chelsio/sge.c3
-rw-r--r--drivers/net/e1000/e1000_main.c3
-rw-r--r--drivers/net/eql.c3
-rw-r--r--drivers/net/hydra.h177
-rw-r--r--drivers/net/ibmveth.c30
-rw-r--r--drivers/net/irda/irda-usb.c365
-rw-r--r--drivers/net/irda/irda-usb.h43
-rw-r--r--drivers/net/irda/sa1100_ir.c3
-rw-r--r--drivers/net/irda/smsc-ircc2.c523
-rw-r--r--drivers/net/ixgb/ixgb_main.c13
-rw-r--r--drivers/net/ixp2000/ixpdev.c5
-rw-r--r--drivers/net/mv643xx_eth.c19
-rw-r--r--drivers/net/natsemi.c20
-rw-r--r--drivers/net/ne2k-pci.c4
-rw-r--r--drivers/net/netconsole.c3
-rw-r--r--drivers/net/ns83820.c3
-rw-r--r--drivers/net/pcmcia/3c574_cs.c115
-rw-r--r--drivers/net/pcmcia/3c589_cs.c122
-rw-r--r--drivers/net/pcmcia/axnet_cs.c189
-rw-r--r--drivers/net/pcmcia/com20020_cs.c127
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c166
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c121
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c126
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c161
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c235
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c187
-rw-r--r--drivers/net/pcnet32.c4
-rw-r--r--drivers/net/skge.c2
-rw-r--r--drivers/net/sky2.c6
-rw-r--r--drivers/net/sky2.h2
-rw-r--r--drivers/net/spider_net.c4
-rw-r--r--drivers/net/starfire.c5
-rw-r--r--drivers/net/tg3.c180
-rw-r--r--drivers/net/tg3.h3
-rw-r--r--drivers/net/tokenring/Kconfig2
-rw-r--r--drivers/net/tokenring/abyss.c3
-rw-r--r--drivers/net/tokenring/madgemc.c3
-rw-r--r--drivers/net/tulip/de4x5.c2
-rw-r--r--drivers/net/typhoon.c2
-rw-r--r--drivers/net/via-rhine.c26
-rw-r--r--drivers/net/wan/Kconfig97
-rw-r--r--drivers/net/wan/Makefile13
-rw-r--r--drivers/net/wan/sdla_chdlc.c4428
-rw-r--r--drivers/net/wan/sdla_fr.c5061
-rw-r--r--drivers/net/wan/sdla_ft1.c345
-rw-r--r--drivers/net/wan/sdla_ppp.c3430
-rw-r--r--drivers/net/wan/sdla_x25.c5497
-rw-r--r--drivers/net/wan/sdladrv.c2314
-rw-r--r--drivers/net/wan/sdlamain.c1346
-rw-r--r--drivers/net/wan/wanpipe_multppp.c2358
-rw-r--r--drivers/net/wireless/Kconfig9
-rw-r--r--drivers/net/wireless/Makefile1
-rw-r--r--drivers/net/wireless/airo_cs.c158
-rw-r--r--drivers/net/wireless/atmel_cs.c162
-rw-r--r--drivers/net/wireless/bcm43xx/Kconfig62
-rw-r--r--drivers/net/wireless/bcm43xx/Makefile12
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h926
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c499
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_debugfs.h117
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_dma.c968
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_dma.h218
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c50
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ethtool.h8
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ilt.c337
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_ilt.h32
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_leds.c293
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_leds.h56
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c3973
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.h168
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_phy.c2345
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_phy.h74
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_pio.c606
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_pio.h138
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_power.c358
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_power.h47
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_radio.c2026
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_radio.h99
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c322
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h25
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_wx.c1002
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_wx.h36
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_xmit.c582
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_xmit.h156
-rw-r--r--drivers/net/wireless/hostap/hostap_80211.h2
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_tx.c9
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c198
-rw-r--r--drivers/net/wireless/ipw2200.c9
-rw-r--r--drivers/net/wireless/netwave_cs.c127
-rw-r--r--drivers/net/wireless/orinoco_cs.c187
-rw-r--r--drivers/net/wireless/ray_cs.c279
-rw-r--r--drivers/net/wireless/ray_cs.h2
-rw-r--r--drivers/net/wireless/spectrum_cs.c173
-rw-r--r--drivers/net/wireless/wavelan_cs.c189
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h6
-rw-r--r--drivers/net/wireless/wl3501.h1
-rw-r--r--drivers/net/wireless/wl3501_cs.c178
-rw-r--r--drivers/net/yellowfin.c3
-rw-r--r--drivers/parisc/ccio-dma.c2
-rw-r--r--drivers/parisc/dino.c5
-rw-r--r--drivers/parisc/eisa.c2
-rw-r--r--drivers/parisc/iosapic.c2
-rw-r--r--drivers/parisc/lba_pci.c8
-rw-r--r--drivers/parisc/pdc_stable.c5
-rw-r--r--drivers/parisc/sba_iommu.c6
-rw-r--r--drivers/parisc/superio.c48
-rw-r--r--drivers/parport/parport_cs.c129
-rw-r--r--drivers/parport/parport_serial.c2
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c3
-rw-r--r--drivers/pci/msi.c227
-rw-r--r--drivers/pci/pci-driver.c6
-rw-r--r--drivers/pci/pci.c12
-rw-r--r--drivers/pci/pci.h11
-rw-r--r--drivers/pci/quirks.c4
-rw-r--r--drivers/pcmcia/Kconfig7
-rw-r--r--drivers/pcmcia/Makefile3
-rw-r--r--drivers/pcmcia/at91_cf.c376
-rw-r--r--drivers/pcmcia/cistpl.c1
-rw-r--r--drivers/pcmcia/cs.c43
-rw-r--r--drivers/pcmcia/cs_internal.h19
-rw-r--r--drivers/pcmcia/ds.c249
-rw-r--r--drivers/pcmcia/ds_internal.h4
-rw-r--r--drivers/pcmcia/i82092.c1
-rw-r--r--drivers/pcmcia/i82365.c1
-rw-r--r--drivers/pcmcia/pcmcia_compat.c65
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c81
-rw-r--r--drivers/pcmcia/pcmcia_resource.c228
-rw-r--r--drivers/pcmcia/pd6729.c1
-rw-r--r--drivers/pcmcia/rsrc_mgr.c5
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c41
-rw-r--r--drivers/pcmcia/sa1100_cerf.c1
-rw-r--r--drivers/pcmcia/socket_sysfs.c10
-rw-r--r--drivers/pcmcia/ti113x.h1
-rw-r--r--drivers/pcmcia/vrc4171_card.c12
-rw-r--r--drivers/pcmcia/vrc4173_cardu.c8
-rw-r--r--drivers/rtc/Kconfig10
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/class.c2
-rw-r--r--drivers/rtc/rtc-ds1672.c72
-rw-r--r--drivers/rtc/rtc-ep93xx.c2
-rw-r--r--drivers/rtc/rtc-m48t86.c9
-rw-r--r--drivers/rtc/rtc-pcf8563.c11
-rw-r--r--drivers/rtc/rtc-proc.c2
-rw-r--r--drivers/rtc/rtc-rs5c372.c28
-rw-r--r--drivers/rtc/rtc-sa1100.c14
-rw-r--r--drivers/rtc/rtc-test.c3
-rw-r--r--drivers/rtc/rtc-vr41xx.c (renamed from drivers/char/vr41xx_rtc.c)404
-rw-r--r--drivers/rtc/rtc-x1205.c29
-rw-r--r--drivers/s390/block/dasd.c45
-rw-r--r--drivers/s390/block/dasd_erp.c8
-rw-r--r--drivers/s390/block/dasd_proc.c17
-rw-r--r--drivers/s390/char/keyboard.c2
-rw-r--r--drivers/s390/char/sclp_rw.c2
-rw-r--r--drivers/s390/char/tape_block.c17
-rw-r--r--drivers/s390/char/tape_core.c10
-rw-r--r--drivers/s390/cio/blacklist.c4
-rw-r--r--drivers/s390/cio/cio.c2
-rw-r--r--drivers/s390/cio/cio_debug.h22
-rw-r--r--drivers/s390/net/lcs.c13
-rw-r--r--drivers/scsi/3w-9xxx.c9
-rw-r--r--drivers/scsi/3w-xxxx.c3
-rw-r--r--drivers/scsi/Kconfig24
-rw-r--r--drivers/scsi/Makefile1
-rw-r--r--drivers/scsi/aacraid/aachba.c94
-rw-r--r--drivers/scsi/aacraid/aacraid.h11
-rw-r--r--drivers/scsi/aacraid/commctrl.c12
-rw-r--r--drivers/scsi/aacraid/commsup.c41
-rw-r--r--drivers/scsi/aacraid/linit.c64
-rw-r--r--drivers/scsi/aacraid/rkt.c4
-rw-r--r--drivers/scsi/aacraid/rx.c4
-rw-r--r--drivers/scsi/aacraid/sa.c2
-rw-r--r--drivers/scsi/ahci.c5
-rw-r--r--drivers/scsi/aic7xxx/Kconfig.aic7xxx2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx.h4
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_core.c166
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c4
-rw-r--r--drivers/scsi/ata_piix.c5
-rw-r--r--drivers/scsi/hosts.c12
-rw-r--r--drivers/scsi/ibmmca.c2
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c251
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.h2
-rw-r--r--drivers/scsi/ibmvscsi/rpa_vscsi.c11
-rw-r--r--drivers/scsi/ibmvscsi/srp.h227
-rw-r--r--drivers/scsi/ibmvscsi/viosrp.h17
-rw-r--r--drivers/scsi/ipr.c122
-rw-r--r--drivers/scsi/ipr.h46
-rw-r--r--drivers/scsi/lasi700.c2
-rw-r--r--drivers/scsi/libata-bmdma.c26
-rw-r--r--drivers/scsi/libata-core.c197
-rw-r--r--drivers/scsi/libata-scsi.c16
-rw-r--r--drivers/scsi/libata.h3
-rw-r--r--drivers/scsi/mesh.c2
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c112
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c155
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c136
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.h8
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c127
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c124
-rw-r--r--drivers/scsi/pdc_adma.c1
-rw-r--r--drivers/scsi/qlogicfc.c2228
-rw-r--r--drivers/scsi/qlogicfc_asm.c9751
-rw-r--r--drivers/scsi/sata_mv.c45
-rw-r--r--drivers/scsi/sata_nv.c1
-rw-r--r--drivers/scsi/sata_promise.c1
-rw-r--r--drivers/scsi/sata_qstor.c1
-rw-r--r--drivers/scsi/sata_sil.c1
-rw-r--r--drivers/scsi/sata_sil24.c1
-rw-r--r--drivers/scsi/sata_sis.c1
-rw-r--r--drivers/scsi/sata_svw.c1
-rw-r--r--drivers/scsi/sata_sx4.c1
-rw-r--r--drivers/scsi/sata_uli.c1
-rw-r--r--drivers/scsi/sata_via.c1
-rw-r--r--drivers/scsi/sata_vsc.c1
-rw-r--r--drivers/scsi/scsi.c5
-rw-r--r--drivers/scsi/scsi_devinfo.c4
-rw-r--r--drivers/scsi/scsi_error.c4
-rw-r--r--drivers/scsi/scsi_ioctl.c176
-rw-r--r--drivers/scsi/scsi_lib.c15
-rw-r--r--drivers/scsi/scsi_sas_internal.h38
-rw-r--r--drivers/scsi/scsi_scan.c19
-rw-r--r--drivers/scsi/scsi_transport_fc.c466
-rw-r--r--drivers/scsi/scsi_transport_sas.c67
-rw-r--r--drivers/scsi/sg.c7
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_defs.h2
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c205
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.h2
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.c113
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_hipd.h2
-rw-r--r--drivers/scsi/zalon.c2
-rw-r--r--drivers/serial/8250_gsc.c15
-rw-r--r--drivers/serial/Kconfig27
-rw-r--r--drivers/serial/Makefile12
-rw-r--r--drivers/serial/jsm/jsm.h2
-rw-r--r--drivers/serial/jsm/jsm_driver.c2
-rw-r--r--drivers/serial/jsm/jsm_neo.c2
-rw-r--r--drivers/serial/jsm/jsm_tty.c29
-rw-r--r--drivers/serial/mux.c4
-rw-r--r--drivers/serial/serial_cs.c229
-rw-r--r--drivers/sn/ioc3.c5
-rw-r--r--drivers/telephony/ixj_pcmcia.c119
-rw-r--r--drivers/usb/atm/ueagle-atm.c52
-rw-r--r--drivers/usb/core/Kconfig7
-rw-r--r--drivers/usb/core/hcd-pci.c11
-rw-r--r--drivers/usb/core/hub.c8
-rw-r--r--drivers/usb/core/usb.c2
-rw-r--r--drivers/usb/gadget/Kconfig4
-rw-r--r--drivers/usb/gadget/at91_udc.c4
-rw-r--r--drivers/usb/gadget/ether.c6
-rw-r--r--drivers/usb/gadget/file_storage.c38
-rw-r--r--drivers/usb/gadget/gadget_chips.h6
-rw-r--r--drivers/usb/gadget/inode.c24
-rw-r--r--drivers/usb/gadget/net2280.c93
-rw-r--r--drivers/usb/gadget/net2280.h415
-rw-r--r--drivers/usb/gadget/zero.c7
-rw-r--r--drivers/usb/host/ohci-at91.c35
-rw-r--r--drivers/usb/host/ohci-s3c2410.c41
-rw-r--r--drivers/usb/host/pci-quirks.c1
-rw-r--r--drivers/usb/host/pci-quirks.h7
-rw-r--r--drivers/usb/host/sl811_cs.c119
-rw-r--r--drivers/usb/host/uhci-hcd.c7
-rw-r--r--drivers/usb/host/uhci-hcd.h1
-rw-r--r--drivers/usb/host/uhci-hub.c18
-rw-r--r--drivers/usb/input/Kconfig56
-rw-r--r--drivers/usb/input/Makefile1
-rw-r--r--drivers/usb/input/hid-core.c14
-rw-r--r--drivers/usb/input/hid-ff.c6
-rw-r--r--drivers/usb/input/hid-input.c2
-rw-r--r--drivers/usb/input/hid.h5
-rw-r--r--drivers/usb/input/keyspan_remote.c2
-rw-r--r--drivers/usb/input/usbtouchscreen.c605
-rw-r--r--drivers/usb/input/wacom.c136
-rw-r--r--drivers/usb/misc/usbtest.c13
-rw-r--r--drivers/usb/net/asix.c327
-rw-r--r--drivers/usb/net/pegasus.c2
-rw-r--r--drivers/usb/net/rndis_host.c28
-rw-r--r--drivers/usb/net/zd1201.c2
-rw-r--r--drivers/usb/serial/Kconfig9
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/console.c2
-rw-r--r--drivers/usb/serial/ftdi_sio.c2
-rw-r--r--drivers/usb/serial/ftdi_sio.h15
-rw-r--r--drivers/usb/serial/funsoft.c65
-rw-r--r--drivers/usb/serial/option.c5
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/usb-serial.c16
-rw-r--r--drivers/usb/serial/usb-serial.h6
-rw-r--r--drivers/usb/storage/Kconfig3
-rw-r--r--drivers/video/Kconfig14
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/aty/aty128fb.c7
-rw-r--r--drivers/video/aty/atyfb_base.c9
-rw-r--r--drivers/video/aty/radeon_pm.c4
-rw-r--r--drivers/video/backlight/Kconfig4
-rw-r--r--drivers/video/backlight/backlight.c84
-rw-r--r--drivers/video/backlight/corgi_bl.c124
-rw-r--r--drivers/video/backlight/hp680_bl.c139
-rw-r--r--drivers/video/cfbimgblt.c2
-rw-r--r--drivers/video/cirrusfb.c4
-rw-r--r--drivers/video/console/fbcon.c11
-rw-r--r--drivers/video/console/sticore.c22
-rw-r--r--drivers/video/fbmem.c7
-rw-r--r--drivers/video/matrox/matroxfb_base.c3
-rw-r--r--drivers/video/nvidia/nvidia.c5
-rw-r--r--drivers/video/pxafb.c8
-rw-r--r--drivers/video/radeonfb.c3167
-rw-r--r--drivers/video/riva/fbdev.c9
-rw-r--r--drivers/video/sticore.h37
-rw-r--r--drivers/video/stifb.c95
-rw-r--r--drivers/video/vesafb.c27
-rw-r--r--drivers/video/w100fb.c162
-rw-r--r--drivers/video/w100fb.h748
675 files changed, 61250 insertions, 53868 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 9f5c0da57c90..5c91d6afb117 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -64,6 +64,8 @@ source "drivers/usb/Kconfig"
64 64
65source "drivers/mmc/Kconfig" 65source "drivers/mmc/Kconfig"
66 66
67source "drivers/leds/Kconfig"
68
67source "drivers/infiniband/Kconfig" 69source "drivers/infiniband/Kconfig"
68 70
69source "drivers/sn/Kconfig" 71source "drivers/sn/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 424955274e60..447d8e68887a 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -25,9 +25,6 @@ obj-$(CONFIG_CONNECTOR) += connector/
25obj-$(CONFIG_FB_I810) += video/i810/ 25obj-$(CONFIG_FB_I810) += video/i810/
26obj-$(CONFIG_FB_INTEL) += video/intelfb/ 26obj-$(CONFIG_FB_INTEL) += video/intelfb/
27 27
28# we also need input/serio early so serio bus is initialized by the time
29# serial drivers start registering their serio ports
30obj-$(CONFIG_SERIO) += input/serio/
31obj-y += serial/ 28obj-y += serial/
32obj-$(CONFIG_PARPORT) += parport/ 29obj-$(CONFIG_PARPORT) += parport/
33obj-y += base/ block/ misc/ mfd/ net/ media/ 30obj-y += base/ block/ misc/ mfd/ net/ media/
@@ -53,6 +50,7 @@ obj-$(CONFIG_TC) += tc/
53obj-$(CONFIG_USB) += usb/ 50obj-$(CONFIG_USB) += usb/
54obj-$(CONFIG_PCI) += usb/ 51obj-$(CONFIG_PCI) += usb/
55obj-$(CONFIG_USB_GADGET) += usb/gadget/ 52obj-$(CONFIG_USB_GADGET) += usb/gadget/
53obj-$(CONFIG_SERIO) += input/serio/
56obj-$(CONFIG_GAMEPORT) += input/gameport/ 54obj-$(CONFIG_GAMEPORT) += input/gameport/
57obj-$(CONFIG_INPUT) += input/ 55obj-$(CONFIG_INPUT) += input/
58obj-$(CONFIG_I2O) += message/ 56obj-$(CONFIG_I2O) += message/
@@ -69,7 +67,9 @@ obj-$(CONFIG_MCA) += mca/
69obj-$(CONFIG_EISA) += eisa/ 67obj-$(CONFIG_EISA) += eisa/
70obj-$(CONFIG_CPU_FREQ) += cpufreq/ 68obj-$(CONFIG_CPU_FREQ) += cpufreq/
71obj-$(CONFIG_MMC) += mmc/ 69obj-$(CONFIG_MMC) += mmc/
70obj-$(CONFIG_NEW_LEDS) += leds/
72obj-$(CONFIG_INFINIBAND) += infiniband/ 71obj-$(CONFIG_INFINIBAND) += infiniband/
72obj-$(CONFIG_IPATH_CORE) += infiniband/
73obj-$(CONFIG_SGI_SN) += sn/ 73obj-$(CONFIG_SGI_SN) += sn/
74obj-y += firmware/ 74obj-y += firmware/
75obj-$(CONFIG_CRYPTO) += crypto/ 75obj-$(CONFIG_CRYPTO) += crypto/
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 5cb96300eb0f..c24652d31bf9 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -329,7 +329,7 @@ config ACPI_CONTAINER
329config ACPI_HOTPLUG_MEMORY 329config ACPI_HOTPLUG_MEMORY
330 tristate "Memory Hotplug" 330 tristate "Memory Hotplug"
331 depends on ACPI 331 depends on ACPI
332 depends on MEMORY_HOTPLUG 332 depends on MEMORY_HOTPLUG || X86_64
333 default n 333 default n
334 help 334 help
335 This driver adds supports for ACPI Memory Hotplug. This driver 335 This driver adds supports for ACPI Memory Hotplug. This driver
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 79b09d76c180..eee0864ba300 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1572,7 +1572,7 @@ static void __exit acpi_ec_exit(void)
1572static int __init acpi_fake_ecdt_setup(char *str) 1572static int __init acpi_fake_ecdt_setup(char *str)
1573{ 1573{
1574 acpi_fake_ecdt_enabled = 1; 1574 acpi_fake_ecdt_enabled = 1;
1575 return 0; 1575 return 1;
1576} 1576}
1577 1577
1578__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup); 1578__setup("acpi_fake_ecdt", acpi_fake_ecdt_setup);
@@ -1591,7 +1591,7 @@ static int __init acpi_ec_set_intr_mode(char *str)
1591 acpi_ec_driver.ops.add = acpi_ec_poll_add; 1591 acpi_ec_driver.ops.add = acpi_ec_poll_add;
1592 } 1592 }
1593 printk(KERN_INFO PREFIX "EC %s mode.\n", intr ? "interrupt" : "polling"); 1593 printk(KERN_INFO PREFIX "EC %s mode.\n", intr ? "interrupt" : "polling");
1594 return 0; 1594 return 1;
1595} 1595}
1596 1596
1597__setup("ec_intr=", acpi_ec_set_intr_mode); 1597__setup("ec_intr=", acpi_ec_set_intr_mode);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 48718b7f4fa0..76656acd00d4 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -188,6 +188,11 @@ static ssize_t driver_bind(struct device_driver *drv,
188 up(&dev->sem); 188 up(&dev->sem);
189 if (dev->parent) 189 if (dev->parent)
190 up(&dev->parent->sem); 190 up(&dev->parent->sem);
191
192 if (err > 0) /* success */
193 err = count;
194 else if (err == 0) /* driver didn't accept device */
195 err = -ENODEV;
191 } 196 }
192 put_device(dev); 197 put_device(dev);
193 put_bus(bus); 198 put_bus(bus);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index df7fdabd0730..0e71dff327cd 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -562,14 +562,13 @@ int class_device_add(struct class_device *class_dev)
562 kobject_uevent(&class_dev->kobj, KOBJ_ADD); 562 kobject_uevent(&class_dev->kobj, KOBJ_ADD);
563 563
564 /* notify any interfaces this device is now here */ 564 /* notify any interfaces this device is now here */
565 if (parent_class) { 565 down(&parent_class->sem);
566 down(&parent_class->sem); 566 list_add_tail(&class_dev->node, &parent_class->children);
567 list_add_tail(&class_dev->node, &parent_class->children); 567 list_for_each_entry(class_intf, &parent_class->interfaces, node) {
568 list_for_each_entry(class_intf, &parent_class->interfaces, node) 568 if (class_intf->add)
569 if (class_intf->add) 569 class_intf->add(class_dev, class_intf);
570 class_intf->add(class_dev, class_intf);
571 up(&parent_class->sem);
572 } 570 }
571 up(&parent_class->sem);
573 572
574 register_done: 573 register_done:
575 if (error) { 574 if (error) {
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 730a9ce0a14a..889c71111239 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -209,7 +209,7 @@ static void __device_release_driver(struct device * dev)
209 sysfs_remove_link(&dev->kobj, "driver"); 209 sysfs_remove_link(&dev->kobj, "driver");
210 klist_remove(&dev->knode_driver); 210 klist_remove(&dev->knode_driver);
211 211
212 if (dev->bus->remove) 212 if (dev->bus && dev->bus->remove)
213 dev->bus->remove(dev); 213 dev->bus->remove(dev);
214 else if (drv->remove) 214 else if (drv->remove)
215 drv->remove(dev); 215 drv->remove(dev);
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 16c513aa4d48..c80c3aeed004 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -106,7 +106,7 @@ static ssize_t node_read_numastat(struct sys_device * dev, char * buf)
106 other_node = 0; 106 other_node = 0;
107 for (i = 0; i < MAX_NR_ZONES; i++) { 107 for (i = 0; i < MAX_NR_ZONES; i++) {
108 struct zone *z = &pg->node_zones[i]; 108 struct zone *z = &pg->node_zones[i];
109 for (cpu = 0; cpu < NR_CPUS; cpu++) { 109 for_each_online_cpu(cpu) {
110 struct per_cpu_pageset *ps = zone_pcp(z,cpu); 110 struct per_cpu_pageset *ps = zone_pcp(z,cpu);
111 numa_hit += ps->numa_hit; 111 numa_hit += ps->numa_hit;
112 numa_miss += ps->numa_miss; 112 numa_miss += ps->numa_miss;
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index bdb60663f2ef..662209d3f42d 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -10,6 +10,8 @@
10 10
11#include <linux/vt_kern.h> 11#include <linux/vt_kern.h>
12#include <linux/device.h> 12#include <linux/device.h>
13#include <linux/kallsyms.h>
14#include <linux/pm.h>
13#include "../base.h" 15#include "../base.h"
14#include "power.h" 16#include "power.h"
15 17
@@ -58,6 +60,7 @@ int suspend_device(struct device * dev, pm_message_t state)
58 if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { 60 if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
59 dev_dbg(dev, "suspending\n"); 61 dev_dbg(dev, "suspending\n");
60 error = dev->bus->suspend(dev, state); 62 error = dev->bus->suspend(dev, state);
63 suspend_report_result(dev->bus->suspend, error);
61 } 64 }
62 up(&dev->sem); 65 up(&dev->sem);
63 return error; 66 return error;
@@ -169,3 +172,12 @@ int device_power_down(pm_message_t state)
169 172
170EXPORT_SYMBOL_GPL(device_power_down); 173EXPORT_SYMBOL_GPL(device_power_down);
171 174
175void __suspend_report_result(const char *function, void *fn, int ret)
176{
177 if (ret) {
178 printk(KERN_ERR "%s(): ", function);
179 print_fn_descriptor_symbol("%s() returns ", (unsigned long)fn);
180 printk("%d\n", ret);
181 }
182}
183EXPORT_SYMBOL_GPL(__suspend_report_result);
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index b6e290956214..2a8af685926f 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1850,6 +1850,7 @@ static int __init amiga_floppy_setup (char *str)
1850 return 0; 1850 return 0;
1851 printk (KERN_INFO "amiflop: Setting default df0 to %x\n", n); 1851 printk (KERN_INFO "amiflop: Setting default df0 to %x\n", n);
1852 fd_def_df0 = n; 1852 fd_def_df0 = n;
1853 return 1;
1853} 1854}
1854 1855
1855__setup("floppy=", amiga_floppy_setup); 1856__setup("floppy=", amiga_floppy_setup);
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 1b0fd31c57c3..1319d8f20640 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1180,6 +1180,53 @@ static int revalidate_allvol(ctlr_info_t *host)
1180 return 0; 1180 return 0;
1181} 1181}
1182 1182
1183static inline void complete_buffers(struct bio *bio, int status)
1184{
1185 while (bio) {
1186 struct bio *xbh = bio->bi_next;
1187 int nr_sectors = bio_sectors(bio);
1188
1189 bio->bi_next = NULL;
1190 blk_finished_io(len);
1191 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
1192 bio = xbh;
1193 }
1194
1195}
1196
1197static void cciss_softirq_done(struct request *rq)
1198{
1199 CommandList_struct *cmd = rq->completion_data;
1200 ctlr_info_t *h = hba[cmd->ctlr];
1201 unsigned long flags;
1202 u64bit temp64;
1203 int i, ddir;
1204
1205 if (cmd->Request.Type.Direction == XFER_READ)
1206 ddir = PCI_DMA_FROMDEVICE;
1207 else
1208 ddir = PCI_DMA_TODEVICE;
1209
1210 /* command did not need to be retried */
1211 /* unmap the DMA mapping for all the scatter gather elements */
1212 for(i=0; i<cmd->Header.SGList; i++) {
1213 temp64.val32.lower = cmd->SG[i].Addr.lower;
1214 temp64.val32.upper = cmd->SG[i].Addr.upper;
1215 pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir);
1216 }
1217
1218 complete_buffers(rq->bio, rq->errors);
1219
1220#ifdef CCISS_DEBUG
1221 printk("Done with %p\n", rq);
1222#endif /* CCISS_DEBUG */
1223
1224 spin_lock_irqsave(&h->lock, flags);
1225 end_that_request_last(rq, rq->errors);
1226 cmd_free(h, cmd,1);
1227 spin_unlock_irqrestore(&h->lock, flags);
1228}
1229
1183/* This function will check the usage_count of the drive to be updated/added. 1230/* This function will check the usage_count of the drive to be updated/added.
1184 * If the usage_count is zero then the drive information will be updated and 1231 * If the usage_count is zero then the drive information will be updated and
1185 * the disk will be re-registered with the kernel. If not then it will be 1232 * the disk will be re-registered with the kernel. If not then it will be
@@ -1248,6 +1295,8 @@ static void cciss_update_drive_info(int ctlr, int drv_index)
1248 1295
1249 blk_queue_max_sectors(disk->queue, 512); 1296 blk_queue_max_sectors(disk->queue, 512);
1250 1297
1298 blk_queue_softirq_done(disk->queue, cciss_softirq_done);
1299
1251 disk->queue->queuedata = hba[ctlr]; 1300 disk->queue->queuedata = hba[ctlr];
1252 1301
1253 blk_queue_hardsect_size(disk->queue, 1302 blk_queue_hardsect_size(disk->queue,
@@ -2147,20 +2196,6 @@ static void start_io( ctlr_info_t *h)
2147 addQ (&(h->cmpQ), c); 2196 addQ (&(h->cmpQ), c);
2148 } 2197 }
2149} 2198}
2150
2151static inline void complete_buffers(struct bio *bio, int status)
2152{
2153 while (bio) {
2154 struct bio *xbh = bio->bi_next;
2155 int nr_sectors = bio_sectors(bio);
2156
2157 bio->bi_next = NULL;
2158 blk_finished_io(len);
2159 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO);
2160 bio = xbh;
2161 }
2162
2163}
2164/* Assumes that CCISS_LOCK(h->ctlr) is held. */ 2199/* Assumes that CCISS_LOCK(h->ctlr) is held. */
2165/* Zeros out the error record and then resends the command back */ 2200/* Zeros out the error record and then resends the command back */
2166/* to the controller */ 2201/* to the controller */
@@ -2178,39 +2213,6 @@ static inline void resend_cciss_cmd( ctlr_info_t *h, CommandList_struct *c)
2178 start_io(h); 2213 start_io(h);
2179} 2214}
2180 2215
2181static void cciss_softirq_done(struct request *rq)
2182{
2183 CommandList_struct *cmd = rq->completion_data;
2184 ctlr_info_t *h = hba[cmd->ctlr];
2185 unsigned long flags;
2186 u64bit temp64;
2187 int i, ddir;
2188
2189 if (cmd->Request.Type.Direction == XFER_READ)
2190 ddir = PCI_DMA_FROMDEVICE;
2191 else
2192 ddir = PCI_DMA_TODEVICE;
2193
2194 /* command did not need to be retried */
2195 /* unmap the DMA mapping for all the scatter gather elements */
2196 for(i=0; i<cmd->Header.SGList; i++) {
2197 temp64.val32.lower = cmd->SG[i].Addr.lower;
2198 temp64.val32.upper = cmd->SG[i].Addr.upper;
2199 pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir);
2200 }
2201
2202 complete_buffers(rq->bio, rq->errors);
2203
2204#ifdef CCISS_DEBUG
2205 printk("Done with %p\n", rq);
2206#endif /* CCISS_DEBUG */
2207
2208 spin_lock_irqsave(&h->lock, flags);
2209 end_that_request_last(rq, rq->errors);
2210 cmd_free(h, cmd,1);
2211 spin_unlock_irqrestore(&h->lock, flags);
2212}
2213
2214/* checks the status of the job and calls complete buffers to mark all 2216/* checks the status of the job and calls complete buffers to mark all
2215 * buffers for the completed job. Note that this function does not need 2217 * buffers for the completed job. Note that this function does not need
2216 * to hold the hba/queue lock. 2218 * to hold the hba/queue lock.
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 9888bc151755..473a13b22b29 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -65,7 +65,7 @@ MODULE_LICENSE("GPL");
65 65
66 66
67typedef struct bluecard_info_t { 67typedef struct bluecard_info_t {
68 dev_link_t link; 68 struct pcmcia_device *p_dev;
69 dev_node_t node; 69 dev_node_t node;
70 70
71 struct hci_dev *hdev; 71 struct hci_dev *hdev;
@@ -85,8 +85,8 @@ typedef struct bluecard_info_t {
85} bluecard_info_t; 85} bluecard_info_t;
86 86
87 87
88static void bluecard_config(dev_link_t *link); 88static int bluecard_config(struct pcmcia_device *link);
89static void bluecard_release(dev_link_t *link); 89static void bluecard_release(struct pcmcia_device *link);
90 90
91static void bluecard_detach(struct pcmcia_device *p_dev); 91static void bluecard_detach(struct pcmcia_device *p_dev);
92 92
@@ -162,7 +162,7 @@ static void bluecard_detach(struct pcmcia_device *p_dev);
162static void bluecard_activity_led_timeout(u_long arg) 162static void bluecard_activity_led_timeout(u_long arg)
163{ 163{
164 bluecard_info_t *info = (bluecard_info_t *)arg; 164 bluecard_info_t *info = (bluecard_info_t *)arg;
165 unsigned int iobase = info->link.io.BasePort1; 165 unsigned int iobase = info->p_dev->io.BasePort1;
166 166
167 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) 167 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
168 return; 168 return;
@@ -179,7 +179,7 @@ static void bluecard_activity_led_timeout(u_long arg)
179 179
180static void bluecard_enable_activity_led(bluecard_info_t *info) 180static void bluecard_enable_activity_led(bluecard_info_t *info)
181{ 181{
182 unsigned int iobase = info->link.io.BasePort1; 182 unsigned int iobase = info->p_dev->io.BasePort1;
183 183
184 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) 184 if (!test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
185 return; 185 return;
@@ -235,7 +235,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
235 } 235 }
236 236
237 do { 237 do {
238 register unsigned int iobase = info->link.io.BasePort1; 238 register unsigned int iobase = info->p_dev->io.BasePort1;
239 register unsigned int offset; 239 register unsigned int offset;
240 register unsigned char command; 240 register unsigned char command;
241 register unsigned long ready_bit; 241 register unsigned long ready_bit;
@@ -244,7 +244,7 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
244 244
245 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 245 clear_bit(XMIT_WAKEUP, &(info->tx_state));
246 246
247 if (!(info->link.state & DEV_PRESENT)) 247 if (!pcmcia_dev_present(info->p_dev))
248 return; 248 return;
249 249
250 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) { 250 if (test_bit(XMIT_BUFFER_NUMBER, &(info->tx_state))) {
@@ -382,7 +382,7 @@ static void bluecard_receive(bluecard_info_t *info, unsigned int offset)
382 return; 382 return;
383 } 383 }
384 384
385 iobase = info->link.io.BasePort1; 385 iobase = info->p_dev->io.BasePort1;
386 386
387 if (test_bit(XMIT_SENDING_READY, &(info->tx_state))) 387 if (test_bit(XMIT_SENDING_READY, &(info->tx_state)))
388 bluecard_enable_activity_led(info); 388 bluecard_enable_activity_led(info);
@@ -512,7 +512,7 @@ static irqreturn_t bluecard_interrupt(int irq, void *dev_inst, struct pt_regs *r
512 if (!test_bit(CARD_READY, &(info->hw_state))) 512 if (!test_bit(CARD_READY, &(info->hw_state)))
513 return IRQ_HANDLED; 513 return IRQ_HANDLED;
514 514
515 iobase = info->link.io.BasePort1; 515 iobase = info->p_dev->io.BasePort1;
516 516
517 spin_lock(&(info->lock)); 517 spin_lock(&(info->lock));
518 518
@@ -626,7 +626,7 @@ static int bluecard_hci_flush(struct hci_dev *hdev)
626static int bluecard_hci_open(struct hci_dev *hdev) 626static int bluecard_hci_open(struct hci_dev *hdev)
627{ 627{
628 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data); 628 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
629 unsigned int iobase = info->link.io.BasePort1; 629 unsigned int iobase = info->p_dev->io.BasePort1;
630 630
631 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state))) 631 if (test_bit(CARD_HAS_PCCARD_ID, &(info->hw_state)))
632 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE); 632 bluecard_hci_set_baud_rate(hdev, DEFAULT_BAUD_RATE);
@@ -646,7 +646,7 @@ static int bluecard_hci_open(struct hci_dev *hdev)
646static int bluecard_hci_close(struct hci_dev *hdev) 646static int bluecard_hci_close(struct hci_dev *hdev)
647{ 647{
648 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data); 648 bluecard_info_t *info = (bluecard_info_t *)(hdev->driver_data);
649 unsigned int iobase = info->link.io.BasePort1; 649 unsigned int iobase = info->p_dev->io.BasePort1;
650 650
651 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags))) 651 if (!test_and_clear_bit(HCI_RUNNING, &(hdev->flags)))
652 return 0; 652 return 0;
@@ -713,7 +713,7 @@ static int bluecard_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned l
713 713
714static int bluecard_open(bluecard_info_t *info) 714static int bluecard_open(bluecard_info_t *info)
715{ 715{
716 unsigned int iobase = info->link.io.BasePort1; 716 unsigned int iobase = info->p_dev->io.BasePort1;
717 struct hci_dev *hdev; 717 struct hci_dev *hdev;
718 unsigned char id; 718 unsigned char id;
719 719
@@ -831,7 +831,7 @@ static int bluecard_open(bluecard_info_t *info)
831 831
832static int bluecard_close(bluecard_info_t *info) 832static int bluecard_close(bluecard_info_t *info)
833{ 833{
834 unsigned int iobase = info->link.io.BasePort1; 834 unsigned int iobase = info->p_dev->io.BasePort1;
835 struct hci_dev *hdev = info->hdev; 835 struct hci_dev *hdev = info->hdev;
836 836
837 if (!hdev) 837 if (!hdev)
@@ -856,17 +856,16 @@ static int bluecard_close(bluecard_info_t *info)
856 return 0; 856 return 0;
857} 857}
858 858
859static int bluecard_attach(struct pcmcia_device *p_dev) 859static int bluecard_probe(struct pcmcia_device *link)
860{ 860{
861 bluecard_info_t *info; 861 bluecard_info_t *info;
862 dev_link_t *link;
863 862
864 /* Create new info device */ 863 /* Create new info device */
865 info = kzalloc(sizeof(*info), GFP_KERNEL); 864 info = kzalloc(sizeof(*info), GFP_KERNEL);
866 if (!info) 865 if (!info)
867 return -ENOMEM; 866 return -ENOMEM;
868 867
869 link = &info->link; 868 info->p_dev = link;
870 link->priv = info; 869 link->priv = info;
871 870
872 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 871 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -878,32 +877,22 @@ static int bluecard_attach(struct pcmcia_device *p_dev)
878 link->irq.Instance = info; 877 link->irq.Instance = info;
879 878
880 link->conf.Attributes = CONF_ENABLE_IRQ; 879 link->conf.Attributes = CONF_ENABLE_IRQ;
881 link->conf.Vcc = 50;
882 link->conf.IntType = INT_MEMORY_AND_IO; 880 link->conf.IntType = INT_MEMORY_AND_IO;
883 881
884 link->handle = p_dev; 882 return bluecard_config(link);
885 p_dev->instance = link;
886
887 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
888 bluecard_config(link);
889
890 return 0;
891} 883}
892 884
893 885
894static void bluecard_detach(struct pcmcia_device *p_dev) 886static void bluecard_detach(struct pcmcia_device *link)
895{ 887{
896 dev_link_t *link = dev_to_instance(p_dev);
897 bluecard_info_t *info = link->priv; 888 bluecard_info_t *info = link->priv;
898 889
899 if (link->state & DEV_CONFIG) 890 bluecard_release(link);
900 bluecard_release(link);
901
902 kfree(info); 891 kfree(info);
903} 892}
904 893
905 894
906static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 895static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
907{ 896{
908 int i; 897 int i;
909 898
@@ -918,14 +907,12 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse
918 return pcmcia_parse_tuple(handle, tuple, parse); 907 return pcmcia_parse_tuple(handle, tuple, parse);
919} 908}
920 909
921static void bluecard_config(dev_link_t *link) 910static int bluecard_config(struct pcmcia_device *link)
922{ 911{
923 client_handle_t handle = link->handle;
924 bluecard_info_t *info = link->priv; 912 bluecard_info_t *info = link->priv;
925 tuple_t tuple; 913 tuple_t tuple;
926 u_short buf[256]; 914 u_short buf[256];
927 cisparse_t parse; 915 cisparse_t parse;
928 config_info_t config;
929 int i, n, last_ret, last_fn; 916 int i, n, last_ret, last_fn;
930 917
931 tuple.TupleData = (cisdata_t *)buf; 918 tuple.TupleData = (cisdata_t *)buf;
@@ -935,7 +922,7 @@ static void bluecard_config(dev_link_t *link)
935 922
936 /* Get configuration register information */ 923 /* Get configuration register information */
937 tuple.DesiredTuple = CISTPL_CONFIG; 924 tuple.DesiredTuple = CISTPL_CONFIG;
938 last_ret = first_tuple(handle, &tuple, &parse); 925 last_ret = first_tuple(link, &tuple, &parse);
939 if (last_ret != CS_SUCCESS) { 926 if (last_ret != CS_SUCCESS) {
940 last_fn = ParseTuple; 927 last_fn = ParseTuple;
941 goto cs_failed; 928 goto cs_failed;
@@ -943,36 +930,31 @@ static void bluecard_config(dev_link_t *link)
943 link->conf.ConfigBase = parse.config.base; 930 link->conf.ConfigBase = parse.config.base;
944 link->conf.Present = parse.config.rmask[0]; 931 link->conf.Present = parse.config.rmask[0];
945 932
946 /* Configure card */
947 link->state |= DEV_CONFIG;
948 i = pcmcia_get_configuration_info(handle, &config);
949 link->conf.Vcc = config.Vcc;
950
951 link->conf.ConfigIndex = 0x20; 933 link->conf.ConfigIndex = 0x20;
952 link->io.NumPorts1 = 64; 934 link->io.NumPorts1 = 64;
953 link->io.IOAddrLines = 6; 935 link->io.IOAddrLines = 6;
954 936
955 for (n = 0; n < 0x400; n += 0x40) { 937 for (n = 0; n < 0x400; n += 0x40) {
956 link->io.BasePort1 = n ^ 0x300; 938 link->io.BasePort1 = n ^ 0x300;
957 i = pcmcia_request_io(link->handle, &link->io); 939 i = pcmcia_request_io(link, &link->io);
958 if (i == CS_SUCCESS) 940 if (i == CS_SUCCESS)
959 break; 941 break;
960 } 942 }
961 943
962 if (i != CS_SUCCESS) { 944 if (i != CS_SUCCESS) {
963 cs_error(link->handle, RequestIO, i); 945 cs_error(link, RequestIO, i);
964 goto failed; 946 goto failed;
965 } 947 }
966 948
967 i = pcmcia_request_irq(link->handle, &link->irq); 949 i = pcmcia_request_irq(link, &link->irq);
968 if (i != CS_SUCCESS) { 950 if (i != CS_SUCCESS) {
969 cs_error(link->handle, RequestIRQ, i); 951 cs_error(link, RequestIRQ, i);
970 link->irq.AssignedIRQ = 0; 952 link->irq.AssignedIRQ = 0;
971 } 953 }
972 954
973 i = pcmcia_request_configuration(link->handle, &link->conf); 955 i = pcmcia_request_configuration(link, &link->conf);
974 if (i != CS_SUCCESS) { 956 if (i != CS_SUCCESS) {
975 cs_error(link->handle, RequestConfiguration, i); 957 cs_error(link, RequestConfiguration, i);
976 goto failed; 958 goto failed;
977 } 959 }
978 960
@@ -980,57 +962,28 @@ static void bluecard_config(dev_link_t *link)
980 goto failed; 962 goto failed;
981 963
982 strcpy(info->node.dev_name, info->hdev->name); 964 strcpy(info->node.dev_name, info->hdev->name);
983 link->dev = &info->node; 965 link->dev_node = &info->node;
984 link->state &= ~DEV_CONFIG_PENDING;
985 966
986 return; 967 return 0;
987 968
988cs_failed: 969cs_failed:
989 cs_error(link->handle, last_fn, last_ret); 970 cs_error(link, last_fn, last_ret);
990 971
991failed: 972failed:
992 bluecard_release(link); 973 bluecard_release(link);
974 return -ENODEV;
993} 975}
994 976
995 977
996static void bluecard_release(dev_link_t *link) 978static void bluecard_release(struct pcmcia_device *link)
997{ 979{
998 bluecard_info_t *info = link->priv; 980 bluecard_info_t *info = link->priv;
999 981
1000 if (link->state & DEV_PRESENT) 982 bluecard_close(info);
1001 bluecard_close(info);
1002 983
1003 del_timer(&(info->timer)); 984 del_timer(&(info->timer));
1004 985
1005 link->dev = NULL; 986 pcmcia_disable_device(link);
1006
1007 pcmcia_release_configuration(link->handle);
1008 pcmcia_release_io(link->handle, &link->io);
1009 pcmcia_release_irq(link->handle, &link->irq);
1010
1011 link->state &= ~DEV_CONFIG;
1012}
1013
1014static int bluecard_suspend(struct pcmcia_device *dev)
1015{
1016 dev_link_t *link = dev_to_instance(dev);
1017
1018 link->state |= DEV_SUSPEND;
1019 if (link->state & DEV_CONFIG)
1020 pcmcia_release_configuration(link->handle);
1021
1022 return 0;
1023}
1024
1025static int bluecard_resume(struct pcmcia_device *dev)
1026{
1027 dev_link_t *link = dev_to_instance(dev);
1028
1029 link->state &= ~DEV_SUSPEND;
1030 if (DEV_OK(link))
1031 pcmcia_request_configuration(link->handle, &link->conf);
1032
1033 return 0;
1034} 987}
1035 988
1036static struct pcmcia_device_id bluecard_ids[] = { 989static struct pcmcia_device_id bluecard_ids[] = {
@@ -1046,11 +999,9 @@ static struct pcmcia_driver bluecard_driver = {
1046 .drv = { 999 .drv = {
1047 .name = "bluecard_cs", 1000 .name = "bluecard_cs",
1048 }, 1001 },
1049 .probe = bluecard_attach, 1002 .probe = bluecard_probe,
1050 .remove = bluecard_detach, 1003 .remove = bluecard_detach,
1051 .id_table = bluecard_ids, 1004 .id_table = bluecard_ids,
1052 .suspend = bluecard_suspend,
1053 .resume = bluecard_resume,
1054}; 1005};
1055 1006
1056static int __init init_bluecard_cs(void) 1007static int __init init_bluecard_cs(void)
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 7e21b1ff27c4..b94ac2f9f7ba 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -72,7 +72,7 @@ MODULE_LICENSE("GPL");
72 72
73 73
74typedef struct bt3c_info_t { 74typedef struct bt3c_info_t {
75 dev_link_t link; 75 struct pcmcia_device *p_dev;
76 dev_node_t node; 76 dev_node_t node;
77 77
78 struct hci_dev *hdev; 78 struct hci_dev *hdev;
@@ -88,8 +88,8 @@ typedef struct bt3c_info_t {
88} bt3c_info_t; 88} bt3c_info_t;
89 89
90 90
91static void bt3c_config(dev_link_t *link); 91static int bt3c_config(struct pcmcia_device *link);
92static void bt3c_release(dev_link_t *link); 92static void bt3c_release(struct pcmcia_device *link);
93 93
94static void bt3c_detach(struct pcmcia_device *p_dev); 94static void bt3c_detach(struct pcmcia_device *p_dev);
95 95
@@ -191,11 +191,11 @@ static void bt3c_write_wakeup(bt3c_info_t *info)
191 return; 191 return;
192 192
193 do { 193 do {
194 register unsigned int iobase = info->link.io.BasePort1; 194 register unsigned int iobase = info->p_dev->io.BasePort1;
195 register struct sk_buff *skb; 195 register struct sk_buff *skb;
196 register int len; 196 register int len;
197 197
198 if (!(info->link.state & DEV_PRESENT)) 198 if (!pcmcia_dev_present(info->p_dev))
199 break; 199 break;
200 200
201 201
@@ -229,7 +229,7 @@ static void bt3c_receive(bt3c_info_t *info)
229 return; 229 return;
230 } 230 }
231 231
232 iobase = info->link.io.BasePort1; 232 iobase = info->p_dev->io.BasePort1;
233 233
234 avail = bt3c_read(iobase, 0x7006); 234 avail = bt3c_read(iobase, 0x7006);
235 //printk("bt3c_cs: receiving %d bytes\n", avail); 235 //printk("bt3c_cs: receiving %d bytes\n", avail);
@@ -350,7 +350,7 @@ static irqreturn_t bt3c_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
350 return IRQ_NONE; 350 return IRQ_NONE;
351 } 351 }
352 352
353 iobase = info->link.io.BasePort1; 353 iobase = info->p_dev->io.BasePort1;
354 354
355 spin_lock(&(info->lock)); 355 spin_lock(&(info->lock));
356 356
@@ -481,7 +481,7 @@ static int bt3c_load_firmware(bt3c_info_t *info, unsigned char *firmware, int co
481 unsigned int iobase, size, addr, fcs, tmp; 481 unsigned int iobase, size, addr, fcs, tmp;
482 int i, err = 0; 482 int i, err = 0;
483 483
484 iobase = info->link.io.BasePort1; 484 iobase = info->p_dev->io.BasePort1;
485 485
486 /* Reset */ 486 /* Reset */
487 bt3c_io_write(iobase, 0x8040, 0x0404); 487 bt3c_io_write(iobase, 0x8040, 0x0404);
@@ -562,7 +562,6 @@ static int bt3c_open(bt3c_info_t *info)
562{ 562{
563 const struct firmware *firmware; 563 const struct firmware *firmware;
564 struct hci_dev *hdev; 564 struct hci_dev *hdev;
565 client_handle_t handle;
566 int err; 565 int err;
567 566
568 spin_lock_init(&(info->lock)); 567 spin_lock_init(&(info->lock));
@@ -594,10 +593,8 @@ static int bt3c_open(bt3c_info_t *info)
594 593
595 hdev->owner = THIS_MODULE; 594 hdev->owner = THIS_MODULE;
596 595
597 handle = info->link.handle;
598
599 /* Load firmware */ 596 /* Load firmware */
600 err = request_firmware(&firmware, "BT3CPCC.bin", &handle_to_dev(handle)); 597 err = request_firmware(&firmware, "BT3CPCC.bin", &info->p_dev->dev);
601 if (err < 0) { 598 if (err < 0) {
602 BT_ERR("Firmware request failed"); 599 BT_ERR("Firmware request failed");
603 goto error; 600 goto error;
@@ -648,17 +645,16 @@ static int bt3c_close(bt3c_info_t *info)
648 return 0; 645 return 0;
649} 646}
650 647
651static int bt3c_attach(struct pcmcia_device *p_dev) 648static int bt3c_probe(struct pcmcia_device *link)
652{ 649{
653 bt3c_info_t *info; 650 bt3c_info_t *info;
654 dev_link_t *link;
655 651
656 /* Create new info device */ 652 /* Create new info device */
657 info = kzalloc(sizeof(*info), GFP_KERNEL); 653 info = kzalloc(sizeof(*info), GFP_KERNEL);
658 if (!info) 654 if (!info)
659 return -ENOMEM; 655 return -ENOMEM;
660 656
661 link = &info->link; 657 info->p_dev = link;
662 link->priv = info; 658 link->priv = info;
663 659
664 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 660 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -670,31 +666,21 @@ static int bt3c_attach(struct pcmcia_device *p_dev)
670 link->irq.Instance = info; 666 link->irq.Instance = info;
671 667
672 link->conf.Attributes = CONF_ENABLE_IRQ; 668 link->conf.Attributes = CONF_ENABLE_IRQ;
673 link->conf.Vcc = 50;
674 link->conf.IntType = INT_MEMORY_AND_IO; 669 link->conf.IntType = INT_MEMORY_AND_IO;
675 670
676 link->handle = p_dev; 671 return bt3c_config(link);
677 p_dev->instance = link;
678
679 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
680 bt3c_config(link);
681
682 return 0;
683} 672}
684 673
685 674
686static void bt3c_detach(struct pcmcia_device *p_dev) 675static void bt3c_detach(struct pcmcia_device *link)
687{ 676{
688 dev_link_t *link = dev_to_instance(p_dev);
689 bt3c_info_t *info = link->priv; 677 bt3c_info_t *info = link->priv;
690 678
691 if (link->state & DEV_CONFIG) 679 bt3c_release(link);
692 bt3c_release(link);
693
694 kfree(info); 680 kfree(info);
695} 681}
696 682
697static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 683static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
698{ 684{
699 int i; 685 int i;
700 686
@@ -705,30 +691,28 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
705 return pcmcia_parse_tuple(handle, tuple, parse); 691 return pcmcia_parse_tuple(handle, tuple, parse);
706} 692}
707 693
708static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 694static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
709{ 695{
710 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 696 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
711 return CS_NO_MORE_ITEMS; 697 return CS_NO_MORE_ITEMS;
712 return get_tuple(handle, tuple, parse); 698 return get_tuple(handle, tuple, parse);
713} 699}
714 700
715static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 701static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
716{ 702{
717 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 703 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
718 return CS_NO_MORE_ITEMS; 704 return CS_NO_MORE_ITEMS;
719 return get_tuple(handle, tuple, parse); 705 return get_tuple(handle, tuple, parse);
720} 706}
721 707
722static void bt3c_config(dev_link_t *link) 708static int bt3c_config(struct pcmcia_device *link)
723{ 709{
724 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 710 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
725 client_handle_t handle = link->handle;
726 bt3c_info_t *info = link->priv; 711 bt3c_info_t *info = link->priv;
727 tuple_t tuple; 712 tuple_t tuple;
728 u_short buf[256]; 713 u_short buf[256];
729 cisparse_t parse; 714 cisparse_t parse;
730 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 715 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
731 config_info_t config;
732 int i, j, try, last_ret, last_fn; 716 int i, j, try, last_ret, last_fn;
733 717
734 tuple.TupleData = (cisdata_t *)buf; 718 tuple.TupleData = (cisdata_t *)buf;
@@ -738,7 +722,7 @@ static void bt3c_config(dev_link_t *link)
738 722
739 /* Get configuration register information */ 723 /* Get configuration register information */
740 tuple.DesiredTuple = CISTPL_CONFIG; 724 tuple.DesiredTuple = CISTPL_CONFIG;
741 last_ret = first_tuple(handle, &tuple, &parse); 725 last_ret = first_tuple(link, &tuple, &parse);
742 if (last_ret != CS_SUCCESS) { 726 if (last_ret != CS_SUCCESS) {
743 last_fn = ParseTuple; 727 last_fn = ParseTuple;
744 goto cs_failed; 728 goto cs_failed;
@@ -746,11 +730,6 @@ static void bt3c_config(dev_link_t *link)
746 link->conf.ConfigBase = parse.config.base; 730 link->conf.ConfigBase = parse.config.base;
747 link->conf.Present = parse.config.rmask[0]; 731 link->conf.Present = parse.config.rmask[0];
748 732
749 /* Configure card */
750 link->state |= DEV_CONFIG;
751 i = pcmcia_get_configuration_info(handle, &config);
752 link->conf.Vcc = config.Vcc;
753
754 /* First pass: look for a config entry that looks normal. */ 733 /* First pass: look for a config entry that looks normal. */
755 tuple.TupleData = (cisdata_t *)buf; 734 tuple.TupleData = (cisdata_t *)buf;
756 tuple.TupleOffset = 0; 735 tuple.TupleOffset = 0;
@@ -759,59 +738,59 @@ static void bt3c_config(dev_link_t *link)
759 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 738 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
760 /* Two tries: without IO aliases, then with aliases */ 739 /* Two tries: without IO aliases, then with aliases */
761 for (try = 0; try < 2; try++) { 740 for (try = 0; try < 2; try++) {
762 i = first_tuple(handle, &tuple, &parse); 741 i = first_tuple(link, &tuple, &parse);
763 while (i != CS_NO_MORE_ITEMS) { 742 while (i != CS_NO_MORE_ITEMS) {
764 if (i != CS_SUCCESS) 743 if (i != CS_SUCCESS)
765 goto next_entry; 744 goto next_entry;
766 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 745 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
767 link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 746 link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
768 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { 747 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
769 link->conf.ConfigIndex = cf->index; 748 link->conf.ConfigIndex = cf->index;
770 link->io.BasePort1 = cf->io.win[0].base; 749 link->io.BasePort1 = cf->io.win[0].base;
771 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 750 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
772 i = pcmcia_request_io(link->handle, &link->io); 751 i = pcmcia_request_io(link, &link->io);
773 if (i == CS_SUCCESS) 752 if (i == CS_SUCCESS)
774 goto found_port; 753 goto found_port;
775 } 754 }
776next_entry: 755next_entry:
777 i = next_tuple(handle, &tuple, &parse); 756 i = next_tuple(link, &tuple, &parse);
778 } 757 }
779 } 758 }
780 759
781 /* Second pass: try to find an entry that isn't picky about 760 /* Second pass: try to find an entry that isn't picky about
782 its base address, then try to grab any standard serial port 761 its base address, then try to grab any standard serial port
783 address, and finally try to get any free port. */ 762 address, and finally try to get any free port. */
784 i = first_tuple(handle, &tuple, &parse); 763 i = first_tuple(link, &tuple, &parse);
785 while (i != CS_NO_MORE_ITEMS) { 764 while (i != CS_NO_MORE_ITEMS) {
786 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 765 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
787 link->conf.ConfigIndex = cf->index; 766 link->conf.ConfigIndex = cf->index;
788 for (j = 0; j < 5; j++) { 767 for (j = 0; j < 5; j++) {
789 link->io.BasePort1 = base[j]; 768 link->io.BasePort1 = base[j];
790 link->io.IOAddrLines = base[j] ? 16 : 3; 769 link->io.IOAddrLines = base[j] ? 16 : 3;
791 i = pcmcia_request_io(link->handle, &link->io); 770 i = pcmcia_request_io(link, &link->io);
792 if (i == CS_SUCCESS) 771 if (i == CS_SUCCESS)
793 goto found_port; 772 goto found_port;
794 } 773 }
795 } 774 }
796 i = next_tuple(handle, &tuple, &parse); 775 i = next_tuple(link, &tuple, &parse);
797 } 776 }
798 777
799found_port: 778found_port:
800 if (i != CS_SUCCESS) { 779 if (i != CS_SUCCESS) {
801 BT_ERR("No usable port range found"); 780 BT_ERR("No usable port range found");
802 cs_error(link->handle, RequestIO, i); 781 cs_error(link, RequestIO, i);
803 goto failed; 782 goto failed;
804 } 783 }
805 784
806 i = pcmcia_request_irq(link->handle, &link->irq); 785 i = pcmcia_request_irq(link, &link->irq);
807 if (i != CS_SUCCESS) { 786 if (i != CS_SUCCESS) {
808 cs_error(link->handle, RequestIRQ, i); 787 cs_error(link, RequestIRQ, i);
809 link->irq.AssignedIRQ = 0; 788 link->irq.AssignedIRQ = 0;
810 } 789 }
811 790
812 i = pcmcia_request_configuration(link->handle, &link->conf); 791 i = pcmcia_request_configuration(link, &link->conf);
813 if (i != CS_SUCCESS) { 792 if (i != CS_SUCCESS) {
814 cs_error(link->handle, RequestConfiguration, i); 793 cs_error(link, RequestConfiguration, i);
815 goto failed; 794 goto failed;
816 } 795 }
817 796
@@ -819,55 +798,26 @@ found_port:
819 goto failed; 798 goto failed;
820 799
821 strcpy(info->node.dev_name, info->hdev->name); 800 strcpy(info->node.dev_name, info->hdev->name);
822 link->dev = &info->node; 801 link->dev_node = &info->node;
823 link->state &= ~DEV_CONFIG_PENDING;
824 802
825 return; 803 return 0;
826 804
827cs_failed: 805cs_failed:
828 cs_error(link->handle, last_fn, last_ret); 806 cs_error(link, last_fn, last_ret);
829 807
830failed: 808failed:
831 bt3c_release(link); 809 bt3c_release(link);
810 return -ENODEV;
832} 811}
833 812
834 813
835static void bt3c_release(dev_link_t *link) 814static void bt3c_release(struct pcmcia_device *link)
836{ 815{
837 bt3c_info_t *info = link->priv; 816 bt3c_info_t *info = link->priv;
838 817
839 if (link->state & DEV_PRESENT) 818 bt3c_close(info);
840 bt3c_close(info);
841
842 link->dev = NULL;
843
844 pcmcia_release_configuration(link->handle);
845 pcmcia_release_io(link->handle, &link->io);
846 pcmcia_release_irq(link->handle, &link->irq);
847
848 link->state &= ~DEV_CONFIG;
849}
850
851static int bt3c_suspend(struct pcmcia_device *dev)
852{
853 dev_link_t *link = dev_to_instance(dev);
854 819
855 link->state |= DEV_SUSPEND; 820 pcmcia_disable_device(link);
856 if (link->state & DEV_CONFIG)
857 pcmcia_release_configuration(link->handle);
858
859 return 0;
860}
861
862static int bt3c_resume(struct pcmcia_device *dev)
863{
864 dev_link_t *link = dev_to_instance(dev);
865
866 link->state &= ~DEV_SUSPEND;
867 if (DEV_OK(link))
868 pcmcia_request_configuration(link->handle, &link->conf);
869
870 return 0;
871} 821}
872 822
873 823
@@ -882,11 +832,9 @@ static struct pcmcia_driver bt3c_driver = {
882 .drv = { 832 .drv = {
883 .name = "bt3c_cs", 833 .name = "bt3c_cs",
884 }, 834 },
885 .probe = bt3c_attach, 835 .probe = bt3c_probe,
886 .remove = bt3c_detach, 836 .remove = bt3c_detach,
887 .id_table = bt3c_ids, 837 .id_table = bt3c_ids,
888 .suspend = bt3c_suspend,
889 .resume = bt3c_resume,
890}; 838};
891 839
892static int __init init_bt3c_cs(void) 840static int __init init_bt3c_cs(void)
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 7b4bff4cfa2d..9ce4c93467e5 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -68,7 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69 69
70typedef struct btuart_info_t { 70typedef struct btuart_info_t {
71 dev_link_t link; 71 struct pcmcia_device *p_dev;
72 dev_node_t node; 72 dev_node_t node;
73 73
74 struct hci_dev *hdev; 74 struct hci_dev *hdev;
@@ -84,8 +84,8 @@ typedef struct btuart_info_t {
84} btuart_info_t; 84} btuart_info_t;
85 85
86 86
87static void btuart_config(dev_link_t *link); 87static int btuart_config(struct pcmcia_device *link);
88static void btuart_release(dev_link_t *link); 88static void btuart_release(struct pcmcia_device *link);
89 89
90static void btuart_detach(struct pcmcia_device *p_dev); 90static void btuart_detach(struct pcmcia_device *p_dev);
91 91
@@ -146,13 +146,13 @@ static void btuart_write_wakeup(btuart_info_t *info)
146 } 146 }
147 147
148 do { 148 do {
149 register unsigned int iobase = info->link.io.BasePort1; 149 register unsigned int iobase = info->p_dev->io.BasePort1;
150 register struct sk_buff *skb; 150 register struct sk_buff *skb;
151 register int len; 151 register int len;
152 152
153 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 153 clear_bit(XMIT_WAKEUP, &(info->tx_state));
154 154
155 if (!(info->link.state & DEV_PRESENT)) 155 if (!pcmcia_dev_present(info->p_dev))
156 return; 156 return;
157 157
158 if (!(skb = skb_dequeue(&(info->txq)))) 158 if (!(skb = skb_dequeue(&(info->txq))))
@@ -187,7 +187,7 @@ static void btuart_receive(btuart_info_t *info)
187 return; 187 return;
188 } 188 }
189 189
190 iobase = info->link.io.BasePort1; 190 iobase = info->p_dev->io.BasePort1;
191 191
192 do { 192 do {
193 info->hdev->stat.byte_rx++; 193 info->hdev->stat.byte_rx++;
@@ -301,7 +301,7 @@ static irqreturn_t btuart_interrupt(int irq, void *dev_inst, struct pt_regs *reg
301 return IRQ_NONE; 301 return IRQ_NONE;
302 } 302 }
303 303
304 iobase = info->link.io.BasePort1; 304 iobase = info->p_dev->io.BasePort1;
305 305
306 spin_lock(&(info->lock)); 306 spin_lock(&(info->lock));
307 307
@@ -357,7 +357,7 @@ static void btuart_change_speed(btuart_info_t *info, unsigned int speed)
357 return; 357 return;
358 } 358 }
359 359
360 iobase = info->link.io.BasePort1; 360 iobase = info->p_dev->io.BasePort1;
361 361
362 spin_lock_irqsave(&(info->lock), flags); 362 spin_lock_irqsave(&(info->lock), flags);
363 363
@@ -481,7 +481,7 @@ static int btuart_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned lon
481static int btuart_open(btuart_info_t *info) 481static int btuart_open(btuart_info_t *info)
482{ 482{
483 unsigned long flags; 483 unsigned long flags;
484 unsigned int iobase = info->link.io.BasePort1; 484 unsigned int iobase = info->p_dev->io.BasePort1;
485 struct hci_dev *hdev; 485 struct hci_dev *hdev;
486 486
487 spin_lock_init(&(info->lock)); 487 spin_lock_init(&(info->lock));
@@ -550,7 +550,7 @@ static int btuart_open(btuart_info_t *info)
550static int btuart_close(btuart_info_t *info) 550static int btuart_close(btuart_info_t *info)
551{ 551{
552 unsigned long flags; 552 unsigned long flags;
553 unsigned int iobase = info->link.io.BasePort1; 553 unsigned int iobase = info->p_dev->io.BasePort1;
554 struct hci_dev *hdev = info->hdev; 554 struct hci_dev *hdev = info->hdev;
555 555
556 if (!hdev) 556 if (!hdev)
@@ -576,17 +576,16 @@ static int btuart_close(btuart_info_t *info)
576 return 0; 576 return 0;
577} 577}
578 578
579static int btuart_attach(struct pcmcia_device *p_dev) 579static int btuart_probe(struct pcmcia_device *link)
580{ 580{
581 btuart_info_t *info; 581 btuart_info_t *info;
582 dev_link_t *link;
583 582
584 /* Create new info device */ 583 /* Create new info device */
585 info = kzalloc(sizeof(*info), GFP_KERNEL); 584 info = kzalloc(sizeof(*info), GFP_KERNEL);
586 if (!info) 585 if (!info)
587 return -ENOMEM; 586 return -ENOMEM;
588 587
589 link = &info->link; 588 info->p_dev = link;
590 link->priv = info; 589 link->priv = info;
591 590
592 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 591 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -598,31 +597,21 @@ static int btuart_attach(struct pcmcia_device *p_dev)
598 link->irq.Instance = info; 597 link->irq.Instance = info;
599 598
600 link->conf.Attributes = CONF_ENABLE_IRQ; 599 link->conf.Attributes = CONF_ENABLE_IRQ;
601 link->conf.Vcc = 50;
602 link->conf.IntType = INT_MEMORY_AND_IO; 600 link->conf.IntType = INT_MEMORY_AND_IO;
603 601
604 link->handle = p_dev; 602 return btuart_config(link);
605 p_dev->instance = link;
606
607 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
608 btuart_config(link);
609
610 return 0;
611} 603}
612 604
613 605
614static void btuart_detach(struct pcmcia_device *p_dev) 606static void btuart_detach(struct pcmcia_device *link)
615{ 607{
616 dev_link_t *link = dev_to_instance(p_dev);
617 btuart_info_t *info = link->priv; 608 btuart_info_t *info = link->priv;
618 609
619 if (link->state & DEV_CONFIG) 610 btuart_release(link);
620 btuart_release(link);
621
622 kfree(info); 611 kfree(info);
623} 612}
624 613
625static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 614static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
626{ 615{
627 int i; 616 int i;
628 617
@@ -633,30 +622,28 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
633 return pcmcia_parse_tuple(handle, tuple, parse); 622 return pcmcia_parse_tuple(handle, tuple, parse);
634} 623}
635 624
636static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 625static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
637{ 626{
638 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 627 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
639 return CS_NO_MORE_ITEMS; 628 return CS_NO_MORE_ITEMS;
640 return get_tuple(handle, tuple, parse); 629 return get_tuple(handle, tuple, parse);
641} 630}
642 631
643static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 632static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
644{ 633{
645 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 634 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
646 return CS_NO_MORE_ITEMS; 635 return CS_NO_MORE_ITEMS;
647 return get_tuple(handle, tuple, parse); 636 return get_tuple(handle, tuple, parse);
648} 637}
649 638
650static void btuart_config(dev_link_t *link) 639static int btuart_config(struct pcmcia_device *link)
651{ 640{
652 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 641 static kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
653 client_handle_t handle = link->handle;
654 btuart_info_t *info = link->priv; 642 btuart_info_t *info = link->priv;
655 tuple_t tuple; 643 tuple_t tuple;
656 u_short buf[256]; 644 u_short buf[256];
657 cisparse_t parse; 645 cisparse_t parse;
658 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 646 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
659 config_info_t config;
660 int i, j, try, last_ret, last_fn; 647 int i, j, try, last_ret, last_fn;
661 648
662 tuple.TupleData = (cisdata_t *)buf; 649 tuple.TupleData = (cisdata_t *)buf;
@@ -666,7 +653,7 @@ static void btuart_config(dev_link_t *link)
666 653
667 /* Get configuration register information */ 654 /* Get configuration register information */
668 tuple.DesiredTuple = CISTPL_CONFIG; 655 tuple.DesiredTuple = CISTPL_CONFIG;
669 last_ret = first_tuple(handle, &tuple, &parse); 656 last_ret = first_tuple(link, &tuple, &parse);
670 if (last_ret != CS_SUCCESS) { 657 if (last_ret != CS_SUCCESS) {
671 last_fn = ParseTuple; 658 last_fn = ParseTuple;
672 goto cs_failed; 659 goto cs_failed;
@@ -674,11 +661,6 @@ static void btuart_config(dev_link_t *link)
674 link->conf.ConfigBase = parse.config.base; 661 link->conf.ConfigBase = parse.config.base;
675 link->conf.Present = parse.config.rmask[0]; 662 link->conf.Present = parse.config.rmask[0];
676 663
677 /* Configure card */
678 link->state |= DEV_CONFIG;
679 i = pcmcia_get_configuration_info(handle, &config);
680 link->conf.Vcc = config.Vcc;
681
682 /* First pass: look for a config entry that looks normal. */ 664 /* First pass: look for a config entry that looks normal. */
683 tuple.TupleData = (cisdata_t *) buf; 665 tuple.TupleData = (cisdata_t *) buf;
684 tuple.TupleOffset = 0; 666 tuple.TupleOffset = 0;
@@ -687,29 +669,29 @@ static void btuart_config(dev_link_t *link)
687 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 669 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
688 /* Two tries: without IO aliases, then with aliases */ 670 /* Two tries: without IO aliases, then with aliases */
689 for (try = 0; try < 2; try++) { 671 for (try = 0; try < 2; try++) {
690 i = first_tuple(handle, &tuple, &parse); 672 i = first_tuple(link, &tuple, &parse);
691 while (i != CS_NO_MORE_ITEMS) { 673 while (i != CS_NO_MORE_ITEMS) {
692 if (i != CS_SUCCESS) 674 if (i != CS_SUCCESS)
693 goto next_entry; 675 goto next_entry;
694 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 676 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
695 link->conf.Vpp1 = link->conf.Vpp2 = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 677 link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
696 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) { 678 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
697 link->conf.ConfigIndex = cf->index; 679 link->conf.ConfigIndex = cf->index;
698 link->io.BasePort1 = cf->io.win[0].base; 680 link->io.BasePort1 = cf->io.win[0].base;
699 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 681 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
700 i = pcmcia_request_io(link->handle, &link->io); 682 i = pcmcia_request_io(link, &link->io);
701 if (i == CS_SUCCESS) 683 if (i == CS_SUCCESS)
702 goto found_port; 684 goto found_port;
703 } 685 }
704next_entry: 686next_entry:
705 i = next_tuple(handle, &tuple, &parse); 687 i = next_tuple(link, &tuple, &parse);
706 } 688 }
707 } 689 }
708 690
709 /* Second pass: try to find an entry that isn't picky about 691 /* Second pass: try to find an entry that isn't picky about
710 its base address, then try to grab any standard serial port 692 its base address, then try to grab any standard serial port
711 address, and finally try to get any free port. */ 693 address, and finally try to get any free port. */
712 i = first_tuple(handle, &tuple, &parse); 694 i = first_tuple(link, &tuple, &parse);
713 while (i != CS_NO_MORE_ITEMS) { 695 while (i != CS_NO_MORE_ITEMS) {
714 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) 696 if ((i == CS_SUCCESS) && (cf->io.nwin > 0)
715 && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 697 && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
@@ -717,30 +699,30 @@ next_entry:
717 for (j = 0; j < 5; j++) { 699 for (j = 0; j < 5; j++) {
718 link->io.BasePort1 = base[j]; 700 link->io.BasePort1 = base[j];
719 link->io.IOAddrLines = base[j] ? 16 : 3; 701 link->io.IOAddrLines = base[j] ? 16 : 3;
720 i = pcmcia_request_io(link->handle, &link->io); 702 i = pcmcia_request_io(link, &link->io);
721 if (i == CS_SUCCESS) 703 if (i == CS_SUCCESS)
722 goto found_port; 704 goto found_port;
723 } 705 }
724 } 706 }
725 i = next_tuple(handle, &tuple, &parse); 707 i = next_tuple(link, &tuple, &parse);
726 } 708 }
727 709
728found_port: 710found_port:
729 if (i != CS_SUCCESS) { 711 if (i != CS_SUCCESS) {
730 BT_ERR("No usable port range found"); 712 BT_ERR("No usable port range found");
731 cs_error(link->handle, RequestIO, i); 713 cs_error(link, RequestIO, i);
732 goto failed; 714 goto failed;
733 } 715 }
734 716
735 i = pcmcia_request_irq(link->handle, &link->irq); 717 i = pcmcia_request_irq(link, &link->irq);
736 if (i != CS_SUCCESS) { 718 if (i != CS_SUCCESS) {
737 cs_error(link->handle, RequestIRQ, i); 719 cs_error(link, RequestIRQ, i);
738 link->irq.AssignedIRQ = 0; 720 link->irq.AssignedIRQ = 0;
739 } 721 }
740 722
741 i = pcmcia_request_configuration(link->handle, &link->conf); 723 i = pcmcia_request_configuration(link, &link->conf);
742 if (i != CS_SUCCESS) { 724 if (i != CS_SUCCESS) {
743 cs_error(link->handle, RequestConfiguration, i); 725 cs_error(link, RequestConfiguration, i);
744 goto failed; 726 goto failed;
745 } 727 }
746 728
@@ -748,58 +730,28 @@ found_port:
748 goto failed; 730 goto failed;
749 731
750 strcpy(info->node.dev_name, info->hdev->name); 732 strcpy(info->node.dev_name, info->hdev->name);
751 link->dev = &info->node; 733 link->dev_node = &info->node;
752 link->state &= ~DEV_CONFIG_PENDING;
753 734
754 return; 735 return 0;
755 736
756cs_failed: 737cs_failed:
757 cs_error(link->handle, last_fn, last_ret); 738 cs_error(link, last_fn, last_ret);
758 739
759failed: 740failed:
760 btuart_release(link); 741 btuart_release(link);
742 return -ENODEV;
761} 743}
762 744
763 745
764static void btuart_release(dev_link_t *link) 746static void btuart_release(struct pcmcia_device *link)
765{ 747{
766 btuart_info_t *info = link->priv; 748 btuart_info_t *info = link->priv;
767 749
768 if (link->state & DEV_PRESENT) 750 btuart_close(info);
769 btuart_close(info);
770
771 link->dev = NULL;
772
773 pcmcia_release_configuration(link->handle);
774 pcmcia_release_io(link->handle, &link->io);
775 pcmcia_release_irq(link->handle, &link->irq);
776
777 link->state &= ~DEV_CONFIG;
778}
779
780static int btuart_suspend(struct pcmcia_device *dev)
781{
782 dev_link_t *link = dev_to_instance(dev);
783
784 link->state |= DEV_SUSPEND;
785 if (link->state & DEV_CONFIG)
786 pcmcia_release_configuration(link->handle);
787 751
788 return 0; 752 pcmcia_disable_device(link);
789} 753}
790 754
791static int btuart_resume(struct pcmcia_device *dev)
792{
793 dev_link_t *link = dev_to_instance(dev);
794
795 link->state &= ~DEV_SUSPEND;
796 if (DEV_OK(link))
797 pcmcia_request_configuration(link->handle, &link->conf);
798
799 return 0;
800}
801
802
803static struct pcmcia_device_id btuart_ids[] = { 755static struct pcmcia_device_id btuart_ids[] = {
804 /* don't use this driver. Use serial_cs + hci_uart instead */ 756 /* don't use this driver. Use serial_cs + hci_uart instead */
805 PCMCIA_DEVICE_NULL 757 PCMCIA_DEVICE_NULL
@@ -811,11 +763,9 @@ static struct pcmcia_driver btuart_driver = {
811 .drv = { 763 .drv = {
812 .name = "btuart_cs", 764 .name = "btuart_cs",
813 }, 765 },
814 .probe = btuart_attach, 766 .probe = btuart_probe,
815 .remove = btuart_detach, 767 .remove = btuart_detach,
816 .id_table = btuart_ids, 768 .id_table = btuart_ids,
817 .suspend = btuart_suspend,
818 .resume = btuart_resume,
819}; 769};
820 770
821static int __init init_btuart_cs(void) 771static int __init init_btuart_cs(void)
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 0449bc45ae5e..a71a240611e0 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -68,7 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69 69
70typedef struct dtl1_info_t { 70typedef struct dtl1_info_t {
71 dev_link_t link; 71 struct pcmcia_device *p_dev;
72 dev_node_t node; 72 dev_node_t node;
73 73
74 struct hci_dev *hdev; 74 struct hci_dev *hdev;
@@ -87,8 +87,8 @@ typedef struct dtl1_info_t {
87} dtl1_info_t; 87} dtl1_info_t;
88 88
89 89
90static void dtl1_config(dev_link_t *link); 90static int dtl1_config(struct pcmcia_device *link);
91static void dtl1_release(dev_link_t *link); 91static void dtl1_release(struct pcmcia_device *link);
92 92
93static void dtl1_detach(struct pcmcia_device *p_dev); 93static void dtl1_detach(struct pcmcia_device *p_dev);
94 94
@@ -153,13 +153,13 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
153 } 153 }
154 154
155 do { 155 do {
156 register unsigned int iobase = info->link.io.BasePort1; 156 register unsigned int iobase = info->p_dev->io.BasePort1;
157 register struct sk_buff *skb; 157 register struct sk_buff *skb;
158 register int len; 158 register int len;
159 159
160 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 160 clear_bit(XMIT_WAKEUP, &(info->tx_state));
161 161
162 if (!(info->link.state & DEV_PRESENT)) 162 if (!pcmcia_dev_present(info->p_dev))
163 return; 163 return;
164 164
165 if (!(skb = skb_dequeue(&(info->txq)))) 165 if (!(skb = skb_dequeue(&(info->txq))))
@@ -218,7 +218,7 @@ static void dtl1_receive(dtl1_info_t *info)
218 return; 218 return;
219 } 219 }
220 220
221 iobase = info->link.io.BasePort1; 221 iobase = info->p_dev->io.BasePort1;
222 222
223 do { 223 do {
224 info->hdev->stat.byte_rx++; 224 info->hdev->stat.byte_rx++;
@@ -305,7 +305,7 @@ static irqreturn_t dtl1_interrupt(int irq, void *dev_inst, struct pt_regs *regs)
305 return IRQ_NONE; 305 return IRQ_NONE;
306 } 306 }
307 307
308 iobase = info->link.io.BasePort1; 308 iobase = info->p_dev->io.BasePort1;
309 309
310 spin_lock(&(info->lock)); 310 spin_lock(&(info->lock));
311 311
@@ -458,7 +458,7 @@ static int dtl1_hci_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long
458static int dtl1_open(dtl1_info_t *info) 458static int dtl1_open(dtl1_info_t *info)
459{ 459{
460 unsigned long flags; 460 unsigned long flags;
461 unsigned int iobase = info->link.io.BasePort1; 461 unsigned int iobase = info->p_dev->io.BasePort1;
462 struct hci_dev *hdev; 462 struct hci_dev *hdev;
463 463
464 spin_lock_init(&(info->lock)); 464 spin_lock_init(&(info->lock));
@@ -504,7 +504,7 @@ static int dtl1_open(dtl1_info_t *info)
504 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */ 504 outb(UART_LCR_WLEN8, iobase + UART_LCR); /* Reset DLAB */
505 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR); 505 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), iobase + UART_MCR);
506 506
507 info->ri_latch = inb(info->link.io.BasePort1 + UART_MSR) & UART_MSR_RI; 507 info->ri_latch = inb(info->p_dev->io.BasePort1 + UART_MSR) & UART_MSR_RI;
508 508
509 /* Turn on interrupts */ 509 /* Turn on interrupts */
510 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER); 510 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
@@ -529,7 +529,7 @@ static int dtl1_open(dtl1_info_t *info)
529static int dtl1_close(dtl1_info_t *info) 529static int dtl1_close(dtl1_info_t *info)
530{ 530{
531 unsigned long flags; 531 unsigned long flags;
532 unsigned int iobase = info->link.io.BasePort1; 532 unsigned int iobase = info->p_dev->io.BasePort1;
533 struct hci_dev *hdev = info->hdev; 533 struct hci_dev *hdev = info->hdev;
534 534
535 if (!hdev) 535 if (!hdev)
@@ -555,17 +555,16 @@ static int dtl1_close(dtl1_info_t *info)
555 return 0; 555 return 0;
556} 556}
557 557
558static int dtl1_attach(struct pcmcia_device *p_dev) 558static int dtl1_probe(struct pcmcia_device *link)
559{ 559{
560 dtl1_info_t *info; 560 dtl1_info_t *info;
561 dev_link_t *link;
562 561
563 /* Create new info device */ 562 /* Create new info device */
564 info = kzalloc(sizeof(*info), GFP_KERNEL); 563 info = kzalloc(sizeof(*info), GFP_KERNEL);
565 if (!info) 564 if (!info)
566 return -ENOMEM; 565 return -ENOMEM;
567 566
568 link = &info->link; 567 info->p_dev = link;
569 link->priv = info; 568 link->priv = info;
570 569
571 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 570 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -577,31 +576,22 @@ static int dtl1_attach(struct pcmcia_device *p_dev)
577 link->irq.Instance = info; 576 link->irq.Instance = info;
578 577
579 link->conf.Attributes = CONF_ENABLE_IRQ; 578 link->conf.Attributes = CONF_ENABLE_IRQ;
580 link->conf.Vcc = 50;
581 link->conf.IntType = INT_MEMORY_AND_IO; 579 link->conf.IntType = INT_MEMORY_AND_IO;
582 580
583 link->handle = p_dev; 581 return dtl1_config(link);
584 p_dev->instance = link;
585
586 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
587 dtl1_config(link);
588
589 return 0;
590} 582}
591 583
592 584
593static void dtl1_detach(struct pcmcia_device *p_dev) 585static void dtl1_detach(struct pcmcia_device *link)
594{ 586{
595 dev_link_t *link = dev_to_instance(p_dev);
596 dtl1_info_t *info = link->priv; 587 dtl1_info_t *info = link->priv;
597 588
598 if (link->state & DEV_CONFIG) 589 dtl1_release(link);
599 dtl1_release(link);
600 590
601 kfree(info); 591 kfree(info);
602} 592}
603 593
604static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 594static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
605{ 595{
606 int i; 596 int i;
607 597
@@ -612,29 +602,27 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
612 return pcmcia_parse_tuple(handle, tuple, parse); 602 return pcmcia_parse_tuple(handle, tuple, parse);
613} 603}
614 604
615static int first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 605static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
616{ 606{
617 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 607 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
618 return CS_NO_MORE_ITEMS; 608 return CS_NO_MORE_ITEMS;
619 return get_tuple(handle, tuple, parse); 609 return get_tuple(handle, tuple, parse);
620} 610}
621 611
622static int next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 612static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
623{ 613{
624 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 614 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
625 return CS_NO_MORE_ITEMS; 615 return CS_NO_MORE_ITEMS;
626 return get_tuple(handle, tuple, parse); 616 return get_tuple(handle, tuple, parse);
627} 617}
628 618
629static void dtl1_config(dev_link_t *link) 619static int dtl1_config(struct pcmcia_device *link)
630{ 620{
631 client_handle_t handle = link->handle;
632 dtl1_info_t *info = link->priv; 621 dtl1_info_t *info = link->priv;
633 tuple_t tuple; 622 tuple_t tuple;
634 u_short buf[256]; 623 u_short buf[256];
635 cisparse_t parse; 624 cisparse_t parse;
636 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 625 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
637 config_info_t config;
638 int i, last_ret, last_fn; 626 int i, last_ret, last_fn;
639 627
640 tuple.TupleData = (cisdata_t *)buf; 628 tuple.TupleData = (cisdata_t *)buf;
@@ -644,7 +632,7 @@ static void dtl1_config(dev_link_t *link)
644 632
645 /* Get configuration register information */ 633 /* Get configuration register information */
646 tuple.DesiredTuple = CISTPL_CONFIG; 634 tuple.DesiredTuple = CISTPL_CONFIG;
647 last_ret = first_tuple(handle, &tuple, &parse); 635 last_ret = first_tuple(link, &tuple, &parse);
648 if (last_ret != CS_SUCCESS) { 636 if (last_ret != CS_SUCCESS) {
649 last_fn = ParseTuple; 637 last_fn = ParseTuple;
650 goto cs_failed; 638 goto cs_failed;
@@ -652,11 +640,6 @@ static void dtl1_config(dev_link_t *link)
652 link->conf.ConfigBase = parse.config.base; 640 link->conf.ConfigBase = parse.config.base;
653 link->conf.Present = parse.config.rmask[0]; 641 link->conf.Present = parse.config.rmask[0];
654 642
655 /* Configure card */
656 link->state |= DEV_CONFIG;
657 i = pcmcia_get_configuration_info(handle, &config);
658 link->conf.Vcc = config.Vcc;
659
660 tuple.TupleData = (cisdata_t *)buf; 643 tuple.TupleData = (cisdata_t *)buf;
661 tuple.TupleOffset = 0; 644 tuple.TupleOffset = 0;
662 tuple.TupleDataMax = 255; 645 tuple.TupleDataMax = 255;
@@ -665,34 +648,34 @@ static void dtl1_config(dev_link_t *link)
665 648
666 /* Look for a generic full-sized window */ 649 /* Look for a generic full-sized window */
667 link->io.NumPorts1 = 8; 650 link->io.NumPorts1 = 8;
668 i = first_tuple(handle, &tuple, &parse); 651 i = first_tuple(link, &tuple, &parse);
669 while (i != CS_NO_MORE_ITEMS) { 652 while (i != CS_NO_MORE_ITEMS) {
670 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { 653 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
671 link->conf.ConfigIndex = cf->index; 654 link->conf.ConfigIndex = cf->index;
672 link->io.BasePort1 = cf->io.win[0].base; 655 link->io.BasePort1 = cf->io.win[0].base;
673 link->io.NumPorts1 = cf->io.win[0].len; /*yo */ 656 link->io.NumPorts1 = cf->io.win[0].len; /*yo */
674 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; 657 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
675 i = pcmcia_request_io(link->handle, &link->io); 658 i = pcmcia_request_io(link, &link->io);
676 if (i == CS_SUCCESS) 659 if (i == CS_SUCCESS)
677 break; 660 break;
678 } 661 }
679 i = next_tuple(handle, &tuple, &parse); 662 i = next_tuple(link, &tuple, &parse);
680 } 663 }
681 664
682 if (i != CS_SUCCESS) { 665 if (i != CS_SUCCESS) {
683 cs_error(link->handle, RequestIO, i); 666 cs_error(link, RequestIO, i);
684 goto failed; 667 goto failed;
685 } 668 }
686 669
687 i = pcmcia_request_irq(link->handle, &link->irq); 670 i = pcmcia_request_irq(link, &link->irq);
688 if (i != CS_SUCCESS) { 671 if (i != CS_SUCCESS) {
689 cs_error(link->handle, RequestIRQ, i); 672 cs_error(link, RequestIRQ, i);
690 link->irq.AssignedIRQ = 0; 673 link->irq.AssignedIRQ = 0;
691 } 674 }
692 675
693 i = pcmcia_request_configuration(link->handle, &link->conf); 676 i = pcmcia_request_configuration(link, &link->conf);
694 if (i != CS_SUCCESS) { 677 if (i != CS_SUCCESS) {
695 cs_error(link->handle, RequestConfiguration, i); 678 cs_error(link, RequestConfiguration, i);
696 goto failed; 679 goto failed;
697 } 680 }
698 681
@@ -700,55 +683,26 @@ static void dtl1_config(dev_link_t *link)
700 goto failed; 683 goto failed;
701 684
702 strcpy(info->node.dev_name, info->hdev->name); 685 strcpy(info->node.dev_name, info->hdev->name);
703 link->dev = &info->node; 686 link->dev_node = &info->node;
704 link->state &= ~DEV_CONFIG_PENDING;
705 687
706 return; 688 return 0;
707 689
708cs_failed: 690cs_failed:
709 cs_error(link->handle, last_fn, last_ret); 691 cs_error(link, last_fn, last_ret);
710 692
711failed: 693failed:
712 dtl1_release(link); 694 dtl1_release(link);
695 return -ENODEV;
713} 696}
714 697
715 698
716static void dtl1_release(dev_link_t *link) 699static void dtl1_release(struct pcmcia_device *link)
717{ 700{
718 dtl1_info_t *info = link->priv; 701 dtl1_info_t *info = link->priv;
719 702
720 if (link->state & DEV_PRESENT) 703 dtl1_close(info);
721 dtl1_close(info);
722
723 link->dev = NULL;
724
725 pcmcia_release_configuration(link->handle);
726 pcmcia_release_io(link->handle, &link->io);
727 pcmcia_release_irq(link->handle, &link->irq);
728
729 link->state &= ~DEV_CONFIG;
730}
731
732static int dtl1_suspend(struct pcmcia_device *dev)
733{
734 dev_link_t *link = dev_to_instance(dev);
735
736 link->state |= DEV_SUSPEND;
737 if (link->state & DEV_CONFIG)
738 pcmcia_release_configuration(link->handle);
739
740 return 0;
741}
742
743static int dtl1_resume(struct pcmcia_device *dev)
744{
745 dev_link_t *link = dev_to_instance(dev);
746 704
747 link->state &= ~DEV_SUSPEND; 705 pcmcia_disable_device(link);
748 if (DEV_OK(link))
749 pcmcia_request_configuration(link->handle, &link->conf);
750
751 return 0;
752} 706}
753 707
754 708
@@ -765,11 +719,9 @@ static struct pcmcia_driver dtl1_driver = {
765 .drv = { 719 .drv = {
766 .name = "dtl1_cs", 720 .name = "dtl1_cs",
767 }, 721 },
768 .probe = dtl1_attach, 722 .probe = dtl1_probe,
769 .remove = dtl1_detach, 723 .remove = dtl1_detach,
770 .id_table = dtl1_ids, 724 .id_table = dtl1_ids,
771 .suspend = dtl1_suspend,
772 .resume = dtl1_resume,
773}; 725};
774 726
775static int __init init_dtl1_cs(void) 727static int __init init_dtl1_cs(void)
diff --git a/drivers/cdrom/aztcd.c b/drivers/cdrom/aztcd.c
index ce4a1ce59d6a..ec004897b634 100644
--- a/drivers/cdrom/aztcd.c
+++ b/drivers/cdrom/aztcd.c
@@ -1763,7 +1763,7 @@ static int __init aztcd_init(void)
1763 release_region(azt_port, 4); 1763 release_region(azt_port, 4);
1764 } 1764 }
1765 } 1765 }
1766 if ((azt_port_auto[i] == 0) || (i == 16)) { 1766 if ((i == 16) || (azt_port_auto[i] == 0)) {
1767 printk(KERN_INFO "aztcd: no AZTECH CD-ROM drive found\n"); 1767 printk(KERN_INFO "aztcd: no AZTECH CD-ROM drive found\n");
1768 return -EIO; 1768 return -EIO;
1769 } 1769 }
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 73d30bf01582..402296670d3a 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -561,14 +561,31 @@ config TIPAR
561 561
562 If unsure, say N. 562 If unsure, say N.
563 563
564config HVC_DRIVER
565 bool
566 help
567 Users of pSeries machines that want to utilize the hvc console front-end
568 module for their backend console driver should select this option.
569 It will automatically be selected if one of the back-end console drivers
570 is selected.
571
572
564config HVC_CONSOLE 573config HVC_CONSOLE
565 bool "pSeries Hypervisor Virtual Console support" 574 bool "pSeries Hypervisor Virtual Console support"
566 depends on PPC_PSERIES 575 depends on PPC_PSERIES
576 select HVC_DRIVER
567 help 577 help
568 pSeries machines when partitioned support a hypervisor virtual 578 pSeries machines when partitioned support a hypervisor virtual
569 console. This driver allows each pSeries partition to have a console 579 console. This driver allows each pSeries partition to have a console
570 which is accessed via the HMC. 580 which is accessed via the HMC.
571 581
582config HVC_RTAS
583 bool "IBM RTAS Console support"
584 depends on PPC_RTAS
585 select HVC_DRIVER
586 help
587 IBM Console device driver which makes use of RTAS
588
572config HVCS 589config HVCS
573 tristate "IBM Hypervisor Virtual Console Server support" 590 tristate "IBM Hypervisor Virtual Console Server support"
574 depends on PPC_PSERIES 591 depends on PPC_PSERIES
@@ -788,10 +805,6 @@ config S3C2410_RTC
788 Samsung S3C2410. This can provide periodic interrupt rates 805 Samsung S3C2410. This can provide periodic interrupt rates
789 from 1Hz to 64Hz for user programs, and wakeup from Alarm. 806 from 1Hz to 64Hz for user programs, and wakeup from Alarm.
790 807
791config RTC_VR41XX
792 tristate "NEC VR4100 series Real Time Clock Support"
793 depends on CPU_VR41XX
794
795config COBALT_LCD 808config COBALT_LCD
796 bool "Support for Cobalt LCD" 809 bool "Support for Cobalt LCD"
797 depends on MIPS_COBALT 810 depends on MIPS_COBALT
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index b2a11245fa95..f5b01c6d498e 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -41,7 +41,9 @@ obj-$(CONFIG_N_HDLC) += n_hdlc.o
41obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o 41obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
42obj-$(CONFIG_SX) += sx.o generic_serial.o 42obj-$(CONFIG_SX) += sx.o generic_serial.o
43obj-$(CONFIG_RIO) += rio/ generic_serial.o 43obj-$(CONFIG_RIO) += rio/ generic_serial.o
44obj-$(CONFIG_HVC_CONSOLE) += hvc_console.o hvc_vio.o hvsi.o 44obj-$(CONFIG_HVC_DRIVER) += hvc_console.o
45obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi.o
46obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
45obj-$(CONFIG_RAW_DRIVER) += raw.o 47obj-$(CONFIG_RAW_DRIVER) += raw.o
46obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o 48obj-$(CONFIG_SGI_SNSC) += snsc.o snsc_event.o
47obj-$(CONFIG_MMTIMER) += mmtimer.o 49obj-$(CONFIG_MMTIMER) += mmtimer.o
@@ -65,7 +67,6 @@ obj-$(CONFIG_SGI_DS1286) += ds1286.o
65obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o 67obj-$(CONFIG_SGI_IP27_RTC) += ip27-rtc.o
66obj-$(CONFIG_DS1302) += ds1302.o 68obj-$(CONFIG_DS1302) += ds1302.o
67obj-$(CONFIG_S3C2410_RTC) += s3c2410-rtc.o 69obj-$(CONFIG_S3C2410_RTC) += s3c2410-rtc.o
68obj-$(CONFIG_RTC_VR41XX) += vr41xx_rtc.o
69ifeq ($(CONFIG_GENERIC_NVRAM),y) 70ifeq ($(CONFIG_GENERIC_NVRAM),y)
70 obj-$(CONFIG_NVRAM) += generic_nvram.o 71 obj-$(CONFIG_NVRAM) += generic_nvram.o
71else 72else
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index fed0a87448d8..86a966b65236 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -64,6 +64,12 @@ static struct gatt_mask efficeon_generic_masks[] =
64 {.mask = 0x00000001, .type = 0} 64 {.mask = 0x00000001, .type = 0}
65}; 65};
66 66
67/* This function does the same thing as mask_memory() for this chipset... */
68static inline unsigned long efficeon_mask_memory(unsigned long addr)
69{
70 return addr | 0x00000001;
71}
72
67static struct aper_size_info_lvl2 efficeon_generic_sizes[4] = 73static struct aper_size_info_lvl2 efficeon_generic_sizes[4] =
68{ 74{
69 {256, 65536, 0}, 75 {256, 65536, 0},
@@ -251,7 +257,7 @@ static int efficeon_insert_memory(struct agp_memory * mem, off_t pg_start, int t
251 last_page = NULL; 257 last_page = NULL;
252 for (i = 0; i < count; i++) { 258 for (i = 0; i < count; i++) {
253 int index = pg_start + i; 259 int index = pg_start + i;
254 unsigned long insert = mem->memory[i]; 260 unsigned long insert = efficeon_mask_memory(mem->memory[i]);
255 261
256 page = (unsigned int *) efficeon_private.l1_table[index >> 10]; 262 page = (unsigned int *) efficeon_private.l1_table[index >> 10];
257 263
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index 927a5bbe112c..a370e7a0bad5 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -142,7 +142,7 @@ static int ac_register_board(unsigned long physloc, void __iomem *loc,
142 if (!boardno) 142 if (!boardno)
143 boardno = readb(loc + NUMCARD_OWNER_TO_PC); 143 boardno = readb(loc + NUMCARD_OWNER_TO_PC);
144 144
145 if (!boardno && boardno > MAX_BOARD) { 145 if (!boardno || boardno > MAX_BOARD) {
146 printk(KERN_WARNING "Board #%d (at 0x%lx) is out of range (1 <= x <= %d).\n", 146 printk(KERN_WARNING "Board #%d (at 0x%lx) is out of range (1 <= x <= %d).\n",
147 boardno, physloc, MAX_BOARD); 147 boardno, physloc, MAX_BOARD);
148 return 0; 148 return 0;
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index 107df9fdba4e..e1aadae00623 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -357,6 +357,12 @@ typedef struct drm_freelist {
357 spinlock_t lock; 357 spinlock_t lock;
358} drm_freelist_t; 358} drm_freelist_t;
359 359
360typedef struct drm_dma_handle {
361 dma_addr_t busaddr;
362 void *vaddr;
363 size_t size;
364} drm_dma_handle_t;
365
360/** 366/**
361 * Buffer entry. There is one of this for each buffer size order. 367 * Buffer entry. There is one of this for each buffer size order.
362 */ 368 */
@@ -366,7 +372,7 @@ typedef struct drm_buf_entry {
366 drm_buf_t *buflist; /**< buffer list */ 372 drm_buf_t *buflist; /**< buffer list */
367 int seg_count; 373 int seg_count;
368 int page_order; 374 int page_order;
369 unsigned long *seglist; 375 drm_dma_handle_t **seglist;
370 376
371 drm_freelist_t freelist; 377 drm_freelist_t freelist;
372} drm_buf_entry_t; 378} drm_buf_entry_t;
@@ -483,12 +489,6 @@ typedef struct drm_sigdata {
483 drm_hw_lock_t *lock; 489 drm_hw_lock_t *lock;
484} drm_sigdata_t; 490} drm_sigdata_t;
485 491
486typedef struct drm_dma_handle {
487 dma_addr_t busaddr;
488 void *vaddr;
489 size_t size;
490} drm_dma_handle_t;
491
492/** 492/**
493 * Mappings list 493 * Mappings list
494 */ 494 */
@@ -813,12 +813,8 @@ extern void drm_mem_init(void);
813extern int drm_mem_info(char *buf, char **start, off_t offset, 813extern int drm_mem_info(char *buf, char **start, off_t offset,
814 int request, int *eof, void *data); 814 int request, int *eof, void *data);
815extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area); 815extern void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area);
816extern unsigned long drm_alloc_pages(int order, int area);
817extern void drm_free_pages(unsigned long address, int order, int area);
818extern void *drm_ioremap(unsigned long offset, unsigned long size, 816extern void *drm_ioremap(unsigned long offset, unsigned long size,
819 drm_device_t * dev); 817 drm_device_t * dev);
820extern void *drm_ioremap_nocache(unsigned long offset, unsigned long size,
821 drm_device_t * dev);
822extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev); 818extern void drm_ioremapfree(void *pt, unsigned long size, drm_device_t * dev);
823 819
824extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type); 820extern DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type);
@@ -1024,11 +1020,13 @@ static __inline__ void drm_core_ioremap(struct drm_map *map,
1024 map->handle = drm_ioremap(map->offset, map->size, dev); 1020 map->handle = drm_ioremap(map->offset, map->size, dev);
1025} 1021}
1026 1022
1023#if 0
1027static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, 1024static __inline__ void drm_core_ioremap_nocache(struct drm_map *map,
1028 struct drm_device *dev) 1025 struct drm_device *dev)
1029{ 1026{
1030 map->handle = drm_ioremap_nocache(map->offset, map->size, dev); 1027 map->handle = drm_ioremap_nocache(map->offset, map->size, dev);
1031} 1028}
1029#endif /* 0 */
1032 1030
1033static __inline__ void drm_core_ioremapfree(struct drm_map *map, 1031static __inline__ void drm_core_ioremapfree(struct drm_map *map,
1034 struct drm_device *dev) 1032 struct drm_device *dev)
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index e2637b4d51de..8a9cf12e6183 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -474,8 +474,7 @@ static void drm_cleanup_buf_error(drm_device_t * dev, drm_buf_entry_t * entry)
474 if (entry->seg_count) { 474 if (entry->seg_count) {
475 for (i = 0; i < entry->seg_count; i++) { 475 for (i = 0; i < entry->seg_count; i++) {
476 if (entry->seglist[i]) { 476 if (entry->seglist[i]) {
477 drm_free_pages(entry->seglist[i], 477 drm_pci_free(dev, entry->seglist[i]);
478 entry->page_order, DRM_MEM_DMA);
479 } 478 }
480 } 479 }
481 drm_free(entry->seglist, 480 drm_free(entry->seglist,
@@ -678,7 +677,7 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
678 int total; 677 int total;
679 int page_order; 678 int page_order;
680 drm_buf_entry_t *entry; 679 drm_buf_entry_t *entry;
681 unsigned long page; 680 drm_dma_handle_t *dmah;
682 drm_buf_t *buf; 681 drm_buf_t *buf;
683 int alignment; 682 int alignment;
684 unsigned long offset; 683 unsigned long offset;
@@ -781,8 +780,10 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
781 page_count = 0; 780 page_count = 0;
782 781
783 while (entry->buf_count < count) { 782 while (entry->buf_count < count) {
784 page = drm_alloc_pages(page_order, DRM_MEM_DMA); 783
785 if (!page) { 784 dmah = drm_pci_alloc(dev, PAGE_SIZE << page_order, 0x1000, 0xfffffffful);
785
786 if (!dmah) {
786 /* Set count correctly so we free the proper amount. */ 787 /* Set count correctly so we free the proper amount. */
787 entry->buf_count = count; 788 entry->buf_count = count;
788 entry->seg_count = count; 789 entry->seg_count = count;
@@ -794,13 +795,13 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
794 atomic_dec(&dev->buf_alloc); 795 atomic_dec(&dev->buf_alloc);
795 return -ENOMEM; 796 return -ENOMEM;
796 } 797 }
797 entry->seglist[entry->seg_count++] = page; 798 entry->seglist[entry->seg_count++] = dmah;
798 for (i = 0; i < (1 << page_order); i++) { 799 for (i = 0; i < (1 << page_order); i++) {
799 DRM_DEBUG("page %d @ 0x%08lx\n", 800 DRM_DEBUG("page %d @ 0x%08lx\n",
800 dma->page_count + page_count, 801 dma->page_count + page_count,
801 page + PAGE_SIZE * i); 802 (unsigned long)dmah->vaddr + PAGE_SIZE * i);
802 temp_pagelist[dma->page_count + page_count++] 803 temp_pagelist[dma->page_count + page_count++]
803 = page + PAGE_SIZE * i; 804 = (unsigned long)dmah->vaddr + PAGE_SIZE * i;
804 } 805 }
805 for (offset = 0; 806 for (offset = 0;
806 offset + size <= total && entry->buf_count < count; 807 offset + size <= total && entry->buf_count < count;
@@ -811,7 +812,8 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
811 buf->order = order; 812 buf->order = order;
812 buf->used = 0; 813 buf->used = 0;
813 buf->offset = (dma->byte_count + byte_count + offset); 814 buf->offset = (dma->byte_count + byte_count + offset);
814 buf->address = (void *)(page + offset); 815 buf->address = (void *)(dmah->vaddr + offset);
816 buf->bus_address = dmah->busaddr + offset;
815 buf->next = NULL; 817 buf->next = NULL;
816 buf->waiting = 0; 818 buf->waiting = 0;
817 buf->pending = 0; 819 buf->pending = 0;
diff --git a/drivers/char/drm/drm_dma.c b/drivers/char/drm/drm_dma.c
index 2afab95ca036..892db7096986 100644
--- a/drivers/char/drm/drm_dma.c
+++ b/drivers/char/drm/drm_dma.c
@@ -85,9 +85,7 @@ void drm_dma_takedown(drm_device_t * dev)
85 dma->bufs[i].seg_count); 85 dma->bufs[i].seg_count);
86 for (j = 0; j < dma->bufs[i].seg_count; j++) { 86 for (j = 0; j < dma->bufs[i].seg_count; j++) {
87 if (dma->bufs[i].seglist[j]) { 87 if (dma->bufs[i].seglist[j]) {
88 drm_free_pages(dma->bufs[i].seglist[j], 88 drm_pci_free(dev, dma->bufs[i].seglist[j]);
89 dma->bufs[i].page_order,
90 DRM_MEM_DMA);
91 } 89 }
92 } 90 }
93 drm_free(dma->bufs[i].seglist, 91 drm_free(dma->bufs[i].seglist,
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index dc6bbe8a18dc..3c0b882a8e72 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -75,8 +75,8 @@ static drm_ioctl_desc_t drm_ioctls[] = {
75 [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = {drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 75 [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = {drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
76 [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = {drm_getsareactx, DRM_AUTH}, 76 [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = {drm_getsareactx, DRM_AUTH},
77 77
78 [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = {drm_addctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 78 [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = {drm_addctx, DRM_AUTH|DRM_ROOT_ONLY},
79 [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = {drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 79 [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = {drm_rmctx, DRM_AUTH|DRM_ROOT_ONLY},
80 [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = {drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 80 [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = {drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
81 [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = {drm_getctx, DRM_AUTH}, 81 [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = {drm_getctx, DRM_AUTH},
82 [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = {drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 82 [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = {drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
diff --git a/drivers/char/drm/drm_memory.c b/drivers/char/drm/drm_memory.c
index 8074771e348f..7e3318e1d1c6 100644
--- a/drivers/char/drm/drm_memory.c
+++ b/drivers/char/drm/drm_memory.c
@@ -79,66 +79,72 @@ void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
79 return pt; 79 return pt;
80} 80}
81 81
82/** 82#if __OS_HAS_AGP
83 * Allocate pages. 83/*
84 * 84 * Find the drm_map that covers the range [offset, offset+size).
85 * \param order size order.
86 * \param area memory area. (Not used.)
87 * \return page address on success, or zero on failure.
88 *
89 * Allocate and reserve free pages.
90 */ 85 */
91unsigned long drm_alloc_pages(int order, int area) 86static drm_map_t *drm_lookup_map(unsigned long offset,
87 unsigned long size, drm_device_t * dev)
92{ 88{
93 unsigned long address; 89 struct list_head *list;
94 unsigned long bytes = PAGE_SIZE << order; 90 drm_map_list_t *r_list;
95 unsigned long addr; 91 drm_map_t *map;
96 unsigned int sz; 92
97 93 list_for_each(list, &dev->maplist->head) {
98 address = __get_free_pages(GFP_KERNEL|__GFP_COMP, order); 94 r_list = (drm_map_list_t *) list;
99 if (!address) 95 map = r_list->map;
100 return 0; 96 if (!map)
101 97 continue;
102 /* Zero */ 98 if (map->offset <= offset
103 memset((void *)address, 0, bytes); 99 && (offset + size) <= (map->offset + map->size))
104 100 return map;
105 /* Reserve */
106 for (addr = address, sz = bytes;
107 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
108 SetPageReserved(virt_to_page(addr));
109 } 101 }
110 102 return NULL;
111 return address;
112} 103}
113 104
114/** 105static void *agp_remap(unsigned long offset, unsigned long size,
115 * Free pages. 106 drm_device_t * dev)
116 *
117 * \param address address of the pages to free.
118 * \param order size order.
119 * \param area memory area. (Not used.)
120 *
121 * Unreserve and free pages allocated by alloc_pages().
122 */
123void drm_free_pages(unsigned long address, int order, int area)
124{ 107{
125 unsigned long bytes = PAGE_SIZE << order; 108 unsigned long *phys_addr_map, i, num_pages =
126 unsigned long addr; 109 PAGE_ALIGN(size) / PAGE_SIZE;
127 unsigned int sz; 110 struct drm_agp_mem *agpmem;
111 struct page **page_map;
112 void *addr;
113
114 size = PAGE_ALIGN(size);
115
116#ifdef __alpha__
117 offset -= dev->hose->mem_space->start;
118#endif
119
120 for (agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next)
121 if (agpmem->bound <= offset
122 && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
123 (offset + size))
124 break;
125 if (!agpmem)
126 return NULL;
128 127
129 if (!address) 128 /*
130 return; 129 * OK, we're mapping AGP space on a chipset/platform on which memory accesses by
130 * the CPU do not get remapped by the GART. We fix this by using the kernel's
131 * page-table instead (that's probably faster anyhow...).
132 */
133 /* note: use vmalloc() because num_pages could be large... */
134 page_map = vmalloc(num_pages * sizeof(struct page *));
135 if (!page_map)
136 return NULL;
131 137
132 /* Unreserve */ 138 phys_addr_map =
133 for (addr = address, sz = bytes; 139 agpmem->memory->memory + (offset - agpmem->bound) / PAGE_SIZE;
134 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) { 140 for (i = 0; i < num_pages; ++i)
135 ClearPageReserved(virt_to_page(addr)); 141 page_map[i] = pfn_to_page(phys_addr_map[i] >> PAGE_SHIFT);
136 } 142 addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
143 vfree(page_map);
137 144
138 free_pages(address, order); 145 return addr;
139} 146}
140 147
141#if __OS_HAS_AGP
142/** Wrapper around agp_allocate_memory() */ 148/** Wrapper around agp_allocate_memory() */
143DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type) 149DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type)
144{ 150{
@@ -162,5 +168,74 @@ int drm_unbind_agp(DRM_AGP_MEM * handle)
162{ 168{
163 return drm_agp_unbind_memory(handle); 169 return drm_agp_unbind_memory(handle);
164} 170}
171
172#else /* __OS_HAS_AGP */
173
174static inline drm_map_t *drm_lookup_map(unsigned long offset,
175 unsigned long size, drm_device_t * dev)
176{
177 return NULL;
178}
179
180static inline void *agp_remap(unsigned long offset, unsigned long size,
181 drm_device_t * dev)
182{
183 return NULL;
184}
185
165#endif /* agp */ 186#endif /* agp */
187
188void *drm_ioremap(unsigned long offset, unsigned long size,
189 drm_device_t * dev)
190{
191 if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
192 drm_map_t *map = drm_lookup_map(offset, size, dev);
193
194 if (map && map->type == _DRM_AGP)
195 return agp_remap(offset, size, dev);
196 }
197 return ioremap(offset, size);
198}
199EXPORT_SYMBOL(drm_ioremap);
200
201#if 0
202void *drm_ioremap_nocache(unsigned long offset,
203 unsigned long size, drm_device_t * dev)
204{
205 if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
206 drm_map_t *map = drm_lookup_map(offset, size, dev);
207
208 if (map && map->type == _DRM_AGP)
209 return agp_remap(offset, size, dev);
210 }
211 return ioremap_nocache(offset, size);
212}
213#endif /* 0 */
214
215void drm_ioremapfree(void *pt, unsigned long size,
216 drm_device_t * dev)
217{
218 /*
219 * This is a bit ugly. It would be much cleaner if the DRM API would use separate
220 * routines for handling mappings in the AGP space. Hopefully this can be done in
221 * a future revision of the interface...
222 */
223 if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture
224 && ((unsigned long)pt >= VMALLOC_START
225 && (unsigned long)pt < VMALLOC_END)) {
226 unsigned long offset;
227 drm_map_t *map;
228
229 offset = drm_follow_page(pt) | ((unsigned long)pt & ~PAGE_MASK);
230 map = drm_lookup_map(offset, size, dev);
231 if (map && map->type == _DRM_AGP) {
232 vunmap(pt);
233 return;
234 }
235 }
236
237 iounmap(pt);
238}
239EXPORT_SYMBOL(drm_ioremapfree);
240
166#endif /* debug_memory */ 241#endif /* debug_memory */
diff --git a/drivers/char/drm/drm_memory.h b/drivers/char/drm/drm_memory.h
index 3732a61c3762..714d9aedcff5 100644
--- a/drivers/char/drm/drm_memory.h
+++ b/drivers/char/drm/drm_memory.h
@@ -57,71 +57,6 @@
57# endif 57# endif
58#endif 58#endif
59 59
60/*
61 * Find the drm_map that covers the range [offset, offset+size).
62 */
63static inline drm_map_t *drm_lookup_map(unsigned long offset,
64 unsigned long size, drm_device_t * dev)
65{
66 struct list_head *list;
67 drm_map_list_t *r_list;
68 drm_map_t *map;
69
70 list_for_each(list, &dev->maplist->head) {
71 r_list = (drm_map_list_t *) list;
72 map = r_list->map;
73 if (!map)
74 continue;
75 if (map->offset <= offset
76 && (offset + size) <= (map->offset + map->size))
77 return map;
78 }
79 return NULL;
80}
81
82static inline void *agp_remap(unsigned long offset, unsigned long size,
83 drm_device_t * dev)
84{
85 unsigned long *phys_addr_map, i, num_pages =
86 PAGE_ALIGN(size) / PAGE_SIZE;
87 struct drm_agp_mem *agpmem;
88 struct page **page_map;
89 void *addr;
90
91 size = PAGE_ALIGN(size);
92
93#ifdef __alpha__
94 offset -= dev->hose->mem_space->start;
95#endif
96
97 for (agpmem = dev->agp->memory; agpmem; agpmem = agpmem->next)
98 if (agpmem->bound <= offset
99 && (agpmem->bound + (agpmem->pages << PAGE_SHIFT)) >=
100 (offset + size))
101 break;
102 if (!agpmem)
103 return NULL;
104
105 /*
106 * OK, we're mapping AGP space on a chipset/platform on which memory accesses by
107 * the CPU do not get remapped by the GART. We fix this by using the kernel's
108 * page-table instead (that's probably faster anyhow...).
109 */
110 /* note: use vmalloc() because num_pages could be large... */
111 page_map = vmalloc(num_pages * sizeof(struct page *));
112 if (!page_map)
113 return NULL;
114
115 phys_addr_map =
116 agpmem->memory->memory + (offset - agpmem->bound) / PAGE_SIZE;
117 for (i = 0; i < num_pages; ++i)
118 page_map[i] = pfn_to_page(phys_addr_map[i] >> PAGE_SHIFT);
119 addr = vmap(page_map, num_pages, VM_IOREMAP, PAGE_AGP);
120 vfree(page_map);
121
122 return addr;
123}
124
125static inline unsigned long drm_follow_page(void *vaddr) 60static inline unsigned long drm_follow_page(void *vaddr)
126{ 61{
127 pgd_t *pgd = pgd_offset_k((unsigned long)vaddr); 62 pgd_t *pgd = pgd_offset_k((unsigned long)vaddr);
@@ -133,18 +68,6 @@ static inline unsigned long drm_follow_page(void *vaddr)
133 68
134#else /* __OS_HAS_AGP */ 69#else /* __OS_HAS_AGP */
135 70
136static inline drm_map_t *drm_lookup_map(unsigned long offset,
137 unsigned long size, drm_device_t * dev)
138{
139 return NULL;
140}
141
142static inline void *agp_remap(unsigned long offset, unsigned long size,
143 drm_device_t * dev)
144{
145 return NULL;
146}
147
148static inline unsigned long drm_follow_page(void *vaddr) 71static inline unsigned long drm_follow_page(void *vaddr)
149{ 72{
150 return 0; 73 return 0;
@@ -152,51 +75,8 @@ static inline unsigned long drm_follow_page(void *vaddr)
152 75
153#endif 76#endif
154 77
155static inline void *drm_ioremap(unsigned long offset, unsigned long size, 78void *drm_ioremap(unsigned long offset, unsigned long size,
156 drm_device_t * dev) 79 drm_device_t * dev);
157{
158 if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
159 drm_map_t *map = drm_lookup_map(offset, size, dev);
160
161 if (map && map->type == _DRM_AGP)
162 return agp_remap(offset, size, dev);
163 }
164 return ioremap(offset, size);
165}
166
167static inline void *drm_ioremap_nocache(unsigned long offset,
168 unsigned long size, drm_device_t * dev)
169{
170 if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture) {
171 drm_map_t *map = drm_lookup_map(offset, size, dev);
172
173 if (map && map->type == _DRM_AGP)
174 return agp_remap(offset, size, dev);
175 }
176 return ioremap_nocache(offset, size);
177}
178
179static inline void drm_ioremapfree(void *pt, unsigned long size,
180 drm_device_t * dev)
181{
182 /*
183 * This is a bit ugly. It would be much cleaner if the DRM API would use separate
184 * routines for handling mappings in the AGP space. Hopefully this can be done in
185 * a future revision of the interface...
186 */
187 if (drm_core_has_AGP(dev) && dev->agp && dev->agp->cant_use_aperture
188 && ((unsigned long)pt >= VMALLOC_START
189 && (unsigned long)pt < VMALLOC_END)) {
190 unsigned long offset;
191 drm_map_t *map;
192
193 offset = drm_follow_page(pt) | ((unsigned long)pt & ~PAGE_MASK);
194 map = drm_lookup_map(offset, size, dev);
195 if (map && map->type == _DRM_AGP) {
196 vunmap(pt);
197 return;
198 }
199 }
200 80
201 iounmap(pt); 81void drm_ioremapfree(void *pt, unsigned long size,
202} 82 drm_device_t * dev);
diff --git a/drivers/char/drm/drm_memory_debug.h b/drivers/char/drm/drm_memory_debug.h
index e84605fc54af..6543b9a14c42 100644
--- a/drivers/char/drm/drm_memory_debug.h
+++ b/drivers/char/drm/drm_memory_debug.h
@@ -206,76 +206,6 @@ void drm_free (void *pt, size_t size, int area) {
206 } 206 }
207} 207}
208 208
209unsigned long drm_alloc_pages (int order, int area) {
210 unsigned long address;
211 unsigned long bytes = PAGE_SIZE << order;
212 unsigned long addr;
213 unsigned int sz;
214
215 spin_lock(&drm_mem_lock);
216 if ((drm_ram_used >> PAGE_SHIFT)
217 > (DRM_RAM_PERCENT * drm_ram_available) / 100) {
218 spin_unlock(&drm_mem_lock);
219 return 0;
220 }
221 spin_unlock(&drm_mem_lock);
222
223 address = __get_free_pages(GFP_KERNEL|__GFP_COMP, order);
224 if (!address) {
225 spin_lock(&drm_mem_lock);
226 ++drm_mem_stats[area].fail_count;
227 spin_unlock(&drm_mem_lock);
228 return 0;
229 }
230 spin_lock(&drm_mem_lock);
231 ++drm_mem_stats[area].succeed_count;
232 drm_mem_stats[area].bytes_allocated += bytes;
233 drm_ram_used += bytes;
234 spin_unlock(&drm_mem_lock);
235
236 /* Zero outside the lock */
237 memset((void *)address, 0, bytes);
238
239 /* Reserve */
240 for (addr = address, sz = bytes;
241 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
242 SetPageReserved(virt_to_page(addr));
243 }
244
245 return address;
246}
247
248void drm_free_pages (unsigned long address, int order, int area) {
249 unsigned long bytes = PAGE_SIZE << order;
250 int alloc_count;
251 int free_count;
252 unsigned long addr;
253 unsigned int sz;
254
255 if (!address) {
256 DRM_MEM_ERROR(area, "Attempt to free address 0\n");
257 } else {
258 /* Unreserve */
259 for (addr = address, sz = bytes;
260 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
261 ClearPageReserved(virt_to_page(addr));
262 }
263 free_pages(address, order);
264 }
265
266 spin_lock(&drm_mem_lock);
267 free_count = ++drm_mem_stats[area].free_count;
268 alloc_count = drm_mem_stats[area].succeed_count;
269 drm_mem_stats[area].bytes_freed += bytes;
270 drm_ram_used -= bytes;
271 spin_unlock(&drm_mem_lock);
272 if (free_count > alloc_count) {
273 DRM_MEM_ERROR(area,
274 "Excess frees: %d frees, %d allocs\n",
275 free_count, alloc_count);
276 }
277}
278
279void *drm_ioremap (unsigned long offset, unsigned long size, 209void *drm_ioremap (unsigned long offset, unsigned long size,
280 drm_device_t * dev) { 210 drm_device_t * dev) {
281 void *pt; 211 void *pt;
@@ -299,6 +229,7 @@ void *drm_ioremap (unsigned long offset, unsigned long size,
299 return pt; 229 return pt;
300} 230}
301 231
232#if 0
302void *drm_ioremap_nocache (unsigned long offset, unsigned long size, 233void *drm_ioremap_nocache (unsigned long offset, unsigned long size,
303 drm_device_t * dev) { 234 drm_device_t * dev) {
304 void *pt; 235 void *pt;
@@ -321,6 +252,7 @@ void *drm_ioremap_nocache (unsigned long offset, unsigned long size,
321 spin_unlock(&drm_mem_lock); 252 spin_unlock(&drm_mem_lock);
322 return pt; 253 return pt;
323} 254}
255#endif /* 0 */
324 256
325void drm_ioremapfree (void *pt, unsigned long size, drm_device_t * dev) { 257void drm_ioremapfree (void *pt, unsigned long size, drm_device_t * dev) {
326 int alloc_count; 258 int alloc_count;
diff --git a/drivers/char/drm/drm_pci.c b/drivers/char/drm/drm_pci.c
index 1fd7ff164817..86a0f1c22091 100644
--- a/drivers/char/drm/drm_pci.c
+++ b/drivers/char/drm/drm_pci.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/dma-mapping.h>
40#include "drmP.h" 41#include "drmP.h"
41 42
42/**********************************************************************/ 43/**********************************************************************/
@@ -50,6 +51,10 @@ drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size, size_t align,
50 dma_addr_t maxaddr) 51 dma_addr_t maxaddr)
51{ 52{
52 drm_dma_handle_t *dmah; 53 drm_dma_handle_t *dmah;
54#if 1
55 unsigned long addr;
56 size_t sz;
57#endif
53#ifdef DRM_DEBUG_MEMORY 58#ifdef DRM_DEBUG_MEMORY
54 int area = DRM_MEM_DMA; 59 int area = DRM_MEM_DMA;
55 60
@@ -79,7 +84,7 @@ drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size, size_t align,
79 return NULL; 84 return NULL;
80 85
81 dmah->size = size; 86 dmah->size = size;
82 dmah->vaddr = pci_alloc_consistent(dev->pdev, size, &dmah->busaddr); 87 dmah->vaddr = dma_alloc_coherent(&dev->pdev->dev, size, &dmah->busaddr, GFP_KERNEL | __GFP_COMP);
83 88
84#ifdef DRM_DEBUG_MEMORY 89#ifdef DRM_DEBUG_MEMORY
85 if (dmah->vaddr == NULL) { 90 if (dmah->vaddr == NULL) {
@@ -104,18 +109,29 @@ drm_dma_handle_t *drm_pci_alloc(drm_device_t * dev, size_t size, size_t align,
104 109
105 memset(dmah->vaddr, 0, size); 110 memset(dmah->vaddr, 0, size);
106 111
112 /* XXX - Is virt_to_page() legal for consistent mem? */
113 /* Reserve */
114 for (addr = (unsigned long)dmah->vaddr, sz = size;
115 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
116 SetPageReserved(virt_to_page(addr));
117 }
118
107 return dmah; 119 return dmah;
108} 120}
109 121
110EXPORT_SYMBOL(drm_pci_alloc); 122EXPORT_SYMBOL(drm_pci_alloc);
111 123
112/** 124/**
113 * \brief Free a PCI consistent memory block with freeing its descriptor. 125 * \brief Free a PCI consistent memory block without freeing its descriptor.
114 * 126 *
115 * This function is for internal use in the Linux-specific DRM core code. 127 * This function is for internal use in the Linux-specific DRM core code.
116 */ 128 */
117void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah) 129void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah)
118{ 130{
131#if 1
132 unsigned long addr;
133 size_t sz;
134#endif
119#ifdef DRM_DEBUG_MEMORY 135#ifdef DRM_DEBUG_MEMORY
120 int area = DRM_MEM_DMA; 136 int area = DRM_MEM_DMA;
121 int alloc_count; 137 int alloc_count;
@@ -127,8 +143,14 @@ void __drm_pci_free(drm_device_t * dev, drm_dma_handle_t * dmah)
127 DRM_MEM_ERROR(area, "Attempt to free address 0\n"); 143 DRM_MEM_ERROR(area, "Attempt to free address 0\n");
128#endif 144#endif
129 } else { 145 } else {
130 pci_free_consistent(dev->pdev, dmah->size, dmah->vaddr, 146 /* XXX - Is virt_to_page() legal for consistent mem? */
131 dmah->busaddr); 147 /* Unreserve */
148 for (addr = (unsigned long)dmah->vaddr, sz = dmah->size;
149 sz > 0; addr += PAGE_SIZE, sz -= PAGE_SIZE) {
150 ClearPageReserved(virt_to_page(addr));
151 }
152 dma_free_coherent(&dev->pdev->dev, dmah->size, dmah->vaddr,
153 dmah->busaddr);
132 } 154 }
133 155
134#ifdef DRM_DEBUG_MEMORY 156#ifdef DRM_DEBUG_MEMORY
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index 2c17e88a8847..b1bb3c7b568d 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -3,49 +3,69 @@
3 Please contact dri-devel@lists.sf.net to add new cards to this list 3 Please contact dri-devel@lists.sf.net to add new cards to this list
4*/ 4*/
5#define radeon_PCI_IDS \ 5#define radeon_PCI_IDS \
6 {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350},\ 6 {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \
7 {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
8 {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
9 {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
10 {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
7 {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP}, \ 11 {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP}, \
8 {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \ 12 {0x1002, 0x4137, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \
9 {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 13 {0x1002, 0x4144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
10 {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 14 {0x1002, 0x4145, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
11 {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 15 {0x1002, 0x4146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
12 {0x1002, 0x4147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 16 {0x1002, 0x4147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
17 {0x1002, 0x4148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
18 {0x1002, 0x4149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
19 {0x1002, 0x414A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
20 {0x1002, 0x414B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
13 {0x1002, 0x4150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 21 {0x1002, 0x4150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
14 {0x1002, 0x4151, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 22 {0x1002, 0x4151, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
15 {0x1002, 0x4152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 23 {0x1002, 0x4152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
16 {0x1002, 0x4153, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 24 {0x1002, 0x4153, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
17 {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 25 {0x1002, 0x4154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
26 {0x1002, 0x4155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
18 {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 27 {0x1002, 0x4156, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \
19 {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS250|CHIP_IS_IGP}, \ 28 {0x1002, 0x4237, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP}, \
20 {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 29 {0x1002, 0x4242, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
21 {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 30 {0x1002, 0x4243, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
22 {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 31 {0x1002, 0x4336, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \
23 {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 32 {0x1002, 0x4337, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \
24 {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS250|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 33 {0x1002, 0x4437, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS200|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \
25 {0x1002, 0x4964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250}, \ 34 {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
26 {0x1002, 0x4965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250}, \ 35 {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250}, \
27 {0x1002, 0x4966, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250}, \ 36 {0x1002, 0x4A48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
28 {0x1002, 0x4967, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250}, \ 37 {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
29 {0x1002, 0x4A49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420}, \ 38 {0x1002, 0x4A4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
30 {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420}, \ 39 {0x1002, 0x4A4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
40 {0x1002, 0x4A4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
41 {0x1002, 0x4A4D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
42 {0x1002, 0x4A4E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
43 {0x1002, 0x4A4F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
44 {0x1002, 0x4A50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
45 {0x1002, 0x4A54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
46 {0x1002, 0x4B49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
47 {0x1002, 0x4B4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
48 {0x1002, 0x4B4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
49 {0x1002, 0x4B4C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
31 {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \ 50 {0x1002, 0x4C57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \
32 {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \ 51 {0x1002, 0x4C58, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200|CHIP_IS_MOBILITY}, \
33 {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \ 52 {0x1002, 0x4C59, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \
34 {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \ 53 {0x1002, 0x4C5A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100|CHIP_IS_MOBILITY}, \
35 {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250|CHIP_IS_MOBILITY}, \ 54 {0x1002, 0x4C64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \
36 {0x1002, 0x4C65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250|CHIP_IS_MOBILITY}, \ 55 {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \
37 {0x1002, 0x4C66, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250|CHIP_IS_MOBILITY}, \ 56 {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV250|CHIP_IS_MOBILITY}, \
38 {0x1002, 0x4C67, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R250|CHIP_IS_MOBILITY}, \
39 {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 57 {0x1002, 0x4E44, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
40 {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 58 {0x1002, 0x4E45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
41 {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 59 {0x1002, 0x4E46, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
42 {0x1002, 0x4E47, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \ 60 {0x1002, 0x4E47, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R300}, \
43 {0x1002, 0x4E48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 61 {0x1002, 0x4E48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
44 {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 62 {0x1002, 0x4E49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
45 {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 63 {0x1002, 0x4E4A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
46 {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 64 {0x1002, 0x4E4B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \
47 {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 65 {0x1002, 0x4E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \
48 {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 66 {0x1002, 0x4E51, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \
67 {0x1002, 0x4E52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \
68 {0x1002, 0x4E53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \
49 {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 69 {0x1002, 0x4E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \
50 {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \ 70 {0x1002, 0x4E56, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350|CHIP_IS_MOBILITY}, \
51 {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 71 {0x1002, 0x5144, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \
@@ -53,44 +73,66 @@
53 {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 73 {0x1002, 0x5146, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \
54 {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \ 74 {0x1002, 0x5147, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R100|CHIP_SINGLE_CRTC}, \
55 {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 75 {0x1002, 0x5148, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
56 {0x1002, 0x5149, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
57 {0x1002, 0x514A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
58 {0x1002, 0x514B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
59 {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 76 {0x1002, 0x514C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
60 {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 77 {0x1002, 0x514D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
61 {0x1002, 0x514E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
62 {0x1002, 0x514F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \
63 {0x1002, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \ 78 {0x1002, 0x5157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \
64 {0x1002, 0x5158, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \ 79 {0x1002, 0x5158, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV200}, \
65 {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 80 {0x1002, 0x5159, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
66 {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 81 {0x1002, 0x515A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
67 {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 82 {0x1002, 0x515E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
68 {0x1002, 0x5168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 83 {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \
69 {0x1002, 0x5169, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 84 {0x1002, 0x5462, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \
70 {0x1002, 0x516A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 85 {0x1002, 0x5464, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_IS_MOBILITY}, \
71 {0x1002, 0x516B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 86 {0x1002, 0x5548, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
72 {0x1002, 0x516C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R200}, \ 87 {0x1002, 0x5549, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
73 {0x1002, 0x5460, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV350}, \ 88 {0x1002, 0x554A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
74 {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 89 {0x1002, 0x554B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
90 {0x1002, 0x554C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
91 {0x1002, 0x554D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
92 {0x1002, 0x554E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
93 {0x1002, 0x554F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
94 {0x1002, 0x5550, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
95 {0x1002, 0x5551, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
96 {0x1002, 0x5552, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
97 {0x1002, 0x5554, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
98 {0x1002, 0x564A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
99 {0x1002, 0x564B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
100 {0x1002, 0x564F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
101 {0x1002, 0x5652, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
75 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP}, \ 103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP}, \
76 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \ 104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY}, \
77 {0x1002, 0x5836, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP}, \
78 {0x1002, 0x5837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP}, \
79 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 105 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
80 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 106 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
81 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 107 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
82 {0x1002, 0x5963, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
83 {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 108 {0x1002, 0x5964, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
84 {0x1002, 0x5968, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 109 {0x1002, 0x5965, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
85 {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \ 110 {0x1002, 0x5969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV100}, \
86 {0x1002, 0x596A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 111 {0x1002, 0x5b60, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
87 {0x1002, 0x596B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 112 {0x1002, 0x5b62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
113 {0x1002, 0x5b63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
114 {0x1002, 0x5b64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
115 {0x1002, 0x5b65, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|CHIP_NEW_MEMMAP}, \
88 {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \ 116 {0x1002, 0x5c61, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \
89 {0x1002, 0x5c62, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
90 {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \ 117 {0x1002, 0x5c63, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280|CHIP_IS_MOBILITY}, \
91 {0x1002, 0x5c64, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 118 {0x1002, 0x5d48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
92 {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R350}, \ 119 {0x1002, 0x5d49, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
93 {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420}, \ 120 {0x1002, 0x5d4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
121 {0x1002, 0x5d4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
122 {0x1002, 0x5d4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
123 {0x1002, 0x5d4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
124 {0x1002, 0x5d4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
125 {0x1002, 0x5d50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
126 {0x1002, 0x5d52, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
127 {0x1002, 0x5d57, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R420|CHIP_NEW_MEMMAP}, \
128 {0x1002, 0x5e48, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \
129 {0x1002, 0x5e4a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \
130 {0x1002, 0x5e4b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \
131 {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \
132 {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \
133 {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|CHIP_NEW_MEMMAP}, \
134 {0x1002, 0x7834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_NEW_MEMMAP}, \
135 {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|CHIP_IS_IGP|CHIP_IS_MOBILITY|CHIP_NEW_MEMMAP}, \
94 {0, 0, 0} 136 {0, 0, 0}
95 137
96#define r128_PCI_IDS \ 138#define r128_PCI_IDS \
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index 1ff4c7ca0bff..9f4b8ce4c05e 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -495,8 +495,6 @@ static int i915_dispatch_batchbuffer(drm_device_t * dev,
495 } 495 }
496 } 496 }
497 497
498 dev_priv->sarea_priv->last_enqueue = dev_priv->counter++;
499
500 i915_emit_breadcrumb(dev); 498 i915_emit_breadcrumb(dev);
501 499
502 return 0; 500 return 0;
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index d3879ac9970f..a752afd86ab8 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -53,6 +53,8 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
53 53
54 I915_WRITE16(I915REG_INT_IDENTITY_R, temp); 54 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
55 55
56 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
57
56 if (temp & USER_INT_FLAG) 58 if (temp & USER_INT_FLAG)
57 DRM_WAKEUP(&dev_priv->irq_queue); 59 DRM_WAKEUP(&dev_priv->irq_queue);
58 60
diff --git a/drivers/char/drm/r300_cmdbuf.c b/drivers/char/drm/r300_cmdbuf.c
index c08fa5076f05..b108c7f913b2 100644
--- a/drivers/char/drm/r300_cmdbuf.c
+++ b/drivers/char/drm/r300_cmdbuf.c
@@ -214,13 +214,13 @@ void r300_init_reg_flags(void)
214 ADD_RANGE(0x4F54, 1); 214 ADD_RANGE(0x4F54, 1);
215 215
216 ADD_RANGE(R300_TX_FILTER_0, 16); 216 ADD_RANGE(R300_TX_FILTER_0, 16);
217 ADD_RANGE(R300_TX_UNK1_0, 16); 217 ADD_RANGE(R300_TX_FILTER1_0, 16);
218 ADD_RANGE(R300_TX_SIZE_0, 16); 218 ADD_RANGE(R300_TX_SIZE_0, 16);
219 ADD_RANGE(R300_TX_FORMAT_0, 16); 219 ADD_RANGE(R300_TX_FORMAT_0, 16);
220 ADD_RANGE(R300_TX_PITCH_0, 16); 220 ADD_RANGE(R300_TX_PITCH_0, 16);
221 /* Texture offset is dangerous and needs more checking */ 221 /* Texture offset is dangerous and needs more checking */
222 ADD_RANGE_MARK(R300_TX_OFFSET_0, 16, MARK_CHECK_OFFSET); 222 ADD_RANGE_MARK(R300_TX_OFFSET_0, 16, MARK_CHECK_OFFSET);
223 ADD_RANGE(R300_TX_UNK4_0, 16); 223 ADD_RANGE(R300_TX_CHROMA_KEY_0, 16);
224 ADD_RANGE(R300_TX_BORDER_COLOR_0, 16); 224 ADD_RANGE(R300_TX_BORDER_COLOR_0, 16);
225 225
226 /* Sporadic registers used as primitives are emitted */ 226 /* Sporadic registers used as primitives are emitted */
@@ -242,8 +242,10 @@ static __inline__ int r300_check_range(unsigned reg, int count)
242 return 0; 242 return 0;
243} 243}
244 244
245 /* we expect offsets passed to the framebuffer to be either within video memory or 245/*
246 within AGP space */ 246 * we expect offsets passed to the framebuffer to be either within video
247 * memory or within AGP space
248 */
247static __inline__ int r300_check_offset(drm_radeon_private_t *dev_priv, 249static __inline__ int r300_check_offset(drm_radeon_private_t *dev_priv,
248 u32 offset) 250 u32 offset)
249{ 251{
@@ -251,11 +253,11 @@ static __inline__ int r300_check_offset(drm_radeon_private_t *dev_priv,
251 but this value is not being kept. 253 but this value is not being kept.
252 This code is correct for now (does the same thing as the 254 This code is correct for now (does the same thing as the
253 code that sets MC_FB_LOCATION) in radeon_cp.c */ 255 code that sets MC_FB_LOCATION) in radeon_cp.c */
254 if ((offset >= dev_priv->fb_location) && 256 if (offset >= dev_priv->fb_location &&
255 (offset < dev_priv->gart_vm_start)) 257 offset < (dev_priv->fb_location + dev_priv->fb_size))
256 return 0; 258 return 0;
257 if ((offset >= dev_priv->gart_vm_start) && 259 if (offset >= dev_priv->gart_vm_start &&
258 (offset < dev_priv->gart_vm_start + dev_priv->gart_size)) 260 offset < (dev_priv->gart_vm_start + dev_priv->gart_size))
259 return 0; 261 return 0;
260 return 1; 262 return 1;
261} 263}
@@ -490,6 +492,7 @@ static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
490 492
491 return 0; 493 return 0;
492} 494}
495
493static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv, 496static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
494 drm_radeon_kcmd_buffer_t *cmdbuf) 497 drm_radeon_kcmd_buffer_t *cmdbuf)
495{ 498{
@@ -701,6 +704,64 @@ static void r300_discard_buffer(drm_device_t * dev, drm_buf_t * buf)
701 buf->used = 0; 704 buf->used = 0;
702} 705}
703 706
707static int r300_scratch(drm_radeon_private_t *dev_priv,
708 drm_radeon_kcmd_buffer_t *cmdbuf,
709 drm_r300_cmd_header_t header)
710{
711 u32 *ref_age_base;
712 u32 i, buf_idx, h_pending;
713 RING_LOCALS;
714
715 if (cmdbuf->bufsz <
716 (sizeof(u64) + header.scratch.n_bufs * sizeof(buf_idx))) {
717 return DRM_ERR(EINVAL);
718 }
719
720 if (header.scratch.reg >= 5) {
721 return DRM_ERR(EINVAL);
722 }
723
724 dev_priv->scratch_ages[header.scratch.reg]++;
725
726 ref_age_base = *(u32 **)cmdbuf->buf;
727
728 cmdbuf->buf += sizeof(u64);
729 cmdbuf->bufsz -= sizeof(u64);
730
731 for (i=0; i < header.scratch.n_bufs; i++) {
732 buf_idx = *(u32 *)cmdbuf->buf;
733 buf_idx *= 2; /* 8 bytes per buf */
734
735 if (DRM_COPY_TO_USER(ref_age_base + buf_idx, &dev_priv->scratch_ages[header.scratch.reg], sizeof(u32))) {
736 return DRM_ERR(EINVAL);
737 }
738
739 if (DRM_COPY_FROM_USER(&h_pending, ref_age_base + buf_idx + 1, sizeof(u32))) {
740 return DRM_ERR(EINVAL);
741 }
742
743 if (h_pending == 0) {
744 return DRM_ERR(EINVAL);
745 }
746
747 h_pending--;
748
749 if (DRM_COPY_TO_USER(ref_age_base + buf_idx + 1, &h_pending, sizeof(u32))) {
750 return DRM_ERR(EINVAL);
751 }
752
753 cmdbuf->buf += sizeof(buf_idx);
754 cmdbuf->bufsz -= sizeof(buf_idx);
755 }
756
757 BEGIN_RING(2);
758 OUT_RING(CP_PACKET0(RADEON_SCRATCH_REG0 + header.scratch.reg * 4, 0));
759 OUT_RING(dev_priv->scratch_ages[header.scratch.reg]);
760 ADVANCE_RING();
761
762 return 0;
763}
764
704/** 765/**
705 * Parses and validates a user-supplied command buffer and emits appropriate 766 * Parses and validates a user-supplied command buffer and emits appropriate
706 * commands on the DMA ring buffer. 767 * commands on the DMA ring buffer.
@@ -838,6 +899,15 @@ int r300_do_cp_cmdbuf(drm_device_t *dev,
838 } 899 }
839 break; 900 break;
840 901
902 case R300_CMD_SCRATCH:
903 DRM_DEBUG("R300_CMD_SCRATCH\n");
904 ret = r300_scratch(dev_priv, cmdbuf, header);
905 if (ret) {
906 DRM_ERROR("r300_scratch failed\n");
907 goto cleanup;
908 }
909 break;
910
841 default: 911 default:
842 DRM_ERROR("bad cmd_type %i at %p\n", 912 DRM_ERROR("bad cmd_type %i at %p\n",
843 header.header.cmd_type, 913 header.header.cmd_type,
diff --git a/drivers/char/drm/r300_reg.h b/drivers/char/drm/r300_reg.h
index d1e19954406b..a881f96c983e 100644
--- a/drivers/char/drm/r300_reg.h
+++ b/drivers/char/drm/r300_reg.h
@@ -711,8 +711,22 @@ I am fairly certain that they are correct unless stated otherwise in comments.
711# define R300_TX_MAX_ANISO_16_TO_1 (8 << 21) 711# define R300_TX_MAX_ANISO_16_TO_1 (8 << 21)
712# define R300_TX_MAX_ANISO_MASK (14 << 21) 712# define R300_TX_MAX_ANISO_MASK (14 << 21)
713 713
714#define R300_TX_UNK1_0 0x4440 714#define R300_TX_FILTER1_0 0x4440
715# define R300_CHROMA_KEY_MODE_DISABLE 0
716# define R300_CHROMA_KEY_FORCE 1
717# define R300_CHROMA_KEY_BLEND 2
718# define R300_MC_ROUND_NORMAL (0<<2)
719# define R300_MC_ROUND_MPEG4 (1<<2)
715# define R300_LOD_BIAS_MASK 0x1fff 720# define R300_LOD_BIAS_MASK 0x1fff
721# define R300_EDGE_ANISO_EDGE_DIAG (0<<13)
722# define R300_EDGE_ANISO_EDGE_ONLY (1<<13)
723# define R300_MC_COORD_TRUNCATE_DISABLE (0<<14)
724# define R300_MC_COORD_TRUNCATE_MPEG (1<<14)
725# define R300_TX_TRI_PERF_0_8 (0<<15)
726# define R300_TX_TRI_PERF_1_8 (1<<15)
727# define R300_TX_TRI_PERF_1_4 (2<<15)
728# define R300_TX_TRI_PERF_3_8 (3<<15)
729# define R300_ANISO_THRESHOLD_MASK (7<<17)
716 730
717#define R300_TX_SIZE_0 0x4480 731#define R300_TX_SIZE_0 0x4480
718# define R300_TX_WIDTHMASK_SHIFT 0 732# define R300_TX_WIDTHMASK_SHIFT 0
@@ -722,6 +736,8 @@ I am fairly certain that they are correct unless stated otherwise in comments.
722# define R300_TX_UNK23 (1 << 23) 736# define R300_TX_UNK23 (1 << 23)
723# define R300_TX_SIZE_SHIFT 26 /* largest of width, height */ 737# define R300_TX_SIZE_SHIFT 26 /* largest of width, height */
724# define R300_TX_SIZE_MASK (15 << 26) 738# define R300_TX_SIZE_MASK (15 << 26)
739# define R300_TX_SIZE_PROJECTED (1<<30)
740# define R300_TX_SIZE_TXPITCH_EN (1<<31)
725#define R300_TX_FORMAT_0 0x44C0 741#define R300_TX_FORMAT_0 0x44C0
726 /* The interpretation of the format word by Wladimir van der Laan */ 742 /* The interpretation of the format word by Wladimir van der Laan */
727 /* The X, Y, Z and W refer to the layout of the components. 743 /* The X, Y, Z and W refer to the layout of the components.
@@ -750,7 +766,8 @@ I am fairly certain that they are correct unless stated otherwise in comments.
750# define R300_TX_FORMAT_B8G8_B8G8 0x14 /* no swizzle */ 766# define R300_TX_FORMAT_B8G8_B8G8 0x14 /* no swizzle */
751# define R300_TX_FORMAT_G8R8_G8B8 0x15 /* no swizzle */ 767# define R300_TX_FORMAT_G8R8_G8B8 0x15 /* no swizzle */
752 /* 0x16 - some 16 bit green format.. ?? */ 768 /* 0x16 - some 16 bit green format.. ?? */
753# define R300_TX_FORMAT_UNK25 (1 << 25) /* no swizzle */ 769# define R300_TX_FORMAT_UNK25 (1 << 25) /* no swizzle */
770# define R300_TX_FORMAT_CUBIC_MAP (1 << 26)
754 771
755 /* gap */ 772 /* gap */
756 /* Floating point formats */ 773 /* Floating point formats */
@@ -800,18 +817,20 @@ I am fairly certain that they are correct unless stated otherwise in comments.
800 817
801# define R300_TX_FORMAT_YUV_MODE 0x00800000 818# define R300_TX_FORMAT_YUV_MODE 0x00800000
802 819
803#define R300_TX_PITCH_0 0x4500 820#define R300_TX_PITCH_0 0x4500 /* obvious missing in gap */
804#define R300_TX_OFFSET_0 0x4540 821#define R300_TX_OFFSET_0 0x4540
805/* BEGIN: Guess from R200 */ 822/* BEGIN: Guess from R200 */
806# define R300_TXO_ENDIAN_NO_SWAP (0 << 0) 823# define R300_TXO_ENDIAN_NO_SWAP (0 << 0)
807# define R300_TXO_ENDIAN_BYTE_SWAP (1 << 0) 824# define R300_TXO_ENDIAN_BYTE_SWAP (1 << 0)
808# define R300_TXO_ENDIAN_WORD_SWAP (2 << 0) 825# define R300_TXO_ENDIAN_WORD_SWAP (2 << 0)
809# define R300_TXO_ENDIAN_HALFDW_SWAP (3 << 0) 826# define R300_TXO_ENDIAN_HALFDW_SWAP (3 << 0)
827# define R300_TXO_MACRO_TILE (1 << 2)
828# define R300_TXO_MICRO_TILE (1 << 3)
810# define R300_TXO_OFFSET_MASK 0xffffffe0 829# define R300_TXO_OFFSET_MASK 0xffffffe0
811# define R300_TXO_OFFSET_SHIFT 5 830# define R300_TXO_OFFSET_SHIFT 5
812/* END */ 831/* END */
813#define R300_TX_UNK4_0 0x4580 832#define R300_TX_CHROMA_KEY_0 0x4580 /* 32 bit chroma key */
814#define R300_TX_BORDER_COLOR_0 0x45C0 //ff00ff00 == { 0, 1.0, 0, 1.0 } 833#define R300_TX_BORDER_COLOR_0 0x45C0 //ff00ff00 == { 0, 1.0, 0, 1.0 }
815 834
816/* END */ 835/* END */
817 836
@@ -868,7 +887,9 @@ I am fairly certain that they are correct unless stated otherwise in comments.
868# define R300_PFS_NODE_TEX_OFFSET_MASK (31 << 12) 887# define R300_PFS_NODE_TEX_OFFSET_MASK (31 << 12)
869# define R300_PFS_NODE_TEX_END_SHIFT 17 888# define R300_PFS_NODE_TEX_END_SHIFT 17
870# define R300_PFS_NODE_TEX_END_MASK (31 << 17) 889# define R300_PFS_NODE_TEX_END_MASK (31 << 17)
871# define R300_PFS_NODE_LAST_NODE (1 << 22) 890/*# define R300_PFS_NODE_LAST_NODE (1 << 22) */
891# define R300_PFS_NODE_OUTPUT_COLOR (1 << 22)
892# define R300_PFS_NODE_OUTPUT_DEPTH (1 << 23)
872 893
873/* TEX 894/* TEX
874// As far as I can tell, texture instructions cannot write into output 895// As far as I can tell, texture instructions cannot write into output
@@ -887,6 +908,7 @@ I am fairly certain that they are correct unless stated otherwise in comments.
887 */ 908 */
888# define R300_FPITX_OPCODE_SHIFT 15 909# define R300_FPITX_OPCODE_SHIFT 15
889# define R300_FPITX_OP_TEX 1 910# define R300_FPITX_OP_TEX 1
911# define R300_FPITX_OP_KIL 2
890# define R300_FPITX_OP_TXP 3 912# define R300_FPITX_OP_TXP 3
891# define R300_FPITX_OP_TXB 4 913# define R300_FPITX_OP_TXB 4
892 914
@@ -962,9 +984,11 @@ I am fairly certain that they are correct unless stated otherwise in comments.
962# define R300_FPI1_SRC2C_CONST (1 << 17) 984# define R300_FPI1_SRC2C_CONST (1 << 17)
963# define R300_FPI1_DSTC_SHIFT 18 985# define R300_FPI1_DSTC_SHIFT 18
964# define R300_FPI1_DSTC_MASK (31 << 18) 986# define R300_FPI1_DSTC_MASK (31 << 18)
987# define R300_FPI1_DSTC_REG_MASK_SHIFT 23
965# define R300_FPI1_DSTC_REG_X (1 << 23) 988# define R300_FPI1_DSTC_REG_X (1 << 23)
966# define R300_FPI1_DSTC_REG_Y (1 << 24) 989# define R300_FPI1_DSTC_REG_Y (1 << 24)
967# define R300_FPI1_DSTC_REG_Z (1 << 25) 990# define R300_FPI1_DSTC_REG_Z (1 << 25)
991# define R300_FPI1_DSTC_OUTPUT_MASK_SHIFT 26
968# define R300_FPI1_DSTC_OUTPUT_X (1 << 26) 992# define R300_FPI1_DSTC_OUTPUT_X (1 << 26)
969# define R300_FPI1_DSTC_OUTPUT_Y (1 << 27) 993# define R300_FPI1_DSTC_OUTPUT_Y (1 << 27)
970# define R300_FPI1_DSTC_OUTPUT_Z (1 << 28) 994# define R300_FPI1_DSTC_OUTPUT_Z (1 << 28)
@@ -983,6 +1007,7 @@ I am fairly certain that they are correct unless stated otherwise in comments.
983# define R300_FPI3_DSTA_MASK (31 << 18) 1007# define R300_FPI3_DSTA_MASK (31 << 18)
984# define R300_FPI3_DSTA_REG (1 << 23) 1008# define R300_FPI3_DSTA_REG (1 << 23)
985# define R300_FPI3_DSTA_OUTPUT (1 << 24) 1009# define R300_FPI3_DSTA_OUTPUT (1 << 24)
1010# define R300_FPI3_DSTA_DEPTH (1 << 27)
986 1011
987#define R300_PFS_INSTR0_0 0x48C0 1012#define R300_PFS_INSTR0_0 0x48C0
988# define R300_FPI0_ARGC_SRC0C_XYZ 0 1013# define R300_FPI0_ARGC_SRC0C_XYZ 0
@@ -1036,7 +1061,7 @@ I am fairly certain that they are correct unless stated otherwise in comments.
1036# define R300_FPI0_OUTC_FRC (9 << 23) 1061# define R300_FPI0_OUTC_FRC (9 << 23)
1037# define R300_FPI0_OUTC_REPL_ALPHA (10 << 23) 1062# define R300_FPI0_OUTC_REPL_ALPHA (10 << 23)
1038# define R300_FPI0_OUTC_SAT (1 << 30) 1063# define R300_FPI0_OUTC_SAT (1 << 30)
1039# define R300_FPI0_UNKNOWN_31 (1 << 31) 1064# define R300_FPI0_INSERT_NOP (1 << 31)
1040 1065
1041#define R300_PFS_INSTR2_0 0x49C0 1066#define R300_PFS_INSTR2_0 0x49C0
1042# define R300_FPI2_ARGA_SRC0C_X 0 1067# define R300_FPI2_ARGA_SRC0C_X 0
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index 9bb8ae0c1c27..7f949c9c9691 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -1118,14 +1118,20 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1118{ 1118{
1119 u32 ring_start, cur_read_ptr; 1119 u32 ring_start, cur_read_ptr;
1120 u32 tmp; 1120 u32 tmp;
1121 1121
1122 /* Initialize the memory controller */ 1122 /* Initialize the memory controller. With new memory map, the fb location
1123 RADEON_WRITE(RADEON_MC_FB_LOCATION, 1123 * is not changed, it should have been properly initialized already. Part
1124 ((dev_priv->gart_vm_start - 1) & 0xffff0000) 1124 * of the problem is that the code below is bogus, assuming the GART is
1125 | (dev_priv->fb_location >> 16)); 1125 * always appended to the fb which is not necessarily the case
1126 */
1127 if (!dev_priv->new_memmap)
1128 RADEON_WRITE(RADEON_MC_FB_LOCATION,
1129 ((dev_priv->gart_vm_start - 1) & 0xffff0000)
1130 | (dev_priv->fb_location >> 16));
1126 1131
1127#if __OS_HAS_AGP 1132#if __OS_HAS_AGP
1128 if (dev_priv->flags & CHIP_IS_AGP) { 1133 if (dev_priv->flags & CHIP_IS_AGP) {
1134 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base);
1129 RADEON_WRITE(RADEON_MC_AGP_LOCATION, 1135 RADEON_WRITE(RADEON_MC_AGP_LOCATION,
1130 (((dev_priv->gart_vm_start - 1 + 1136 (((dev_priv->gart_vm_start - 1 +
1131 dev_priv->gart_size) & 0xffff0000) | 1137 dev_priv->gart_size) & 0xffff0000) |
@@ -1153,8 +1159,6 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1153 1159
1154#if __OS_HAS_AGP 1160#if __OS_HAS_AGP
1155 if (dev_priv->flags & CHIP_IS_AGP) { 1161 if (dev_priv->flags & CHIP_IS_AGP) {
1156 /* set RADEON_AGP_BASE here instead of relying on X from user space */
1157 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base);
1158 RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, 1162 RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
1159 dev_priv->ring_rptr->offset 1163 dev_priv->ring_rptr->offset
1160 - dev->agp->base + dev_priv->gart_vm_start); 1164 - dev->agp->base + dev_priv->gart_vm_start);
@@ -1174,6 +1178,17 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1174 entry->handle + tmp_ofs); 1178 entry->handle + tmp_ofs);
1175 } 1179 }
1176 1180
1181 /* Set ring buffer size */
1182#ifdef __BIG_ENDIAN
1183 RADEON_WRITE(RADEON_CP_RB_CNTL,
1184 dev_priv->ring.size_l2qw | RADEON_BUF_SWAP_32BIT);
1185#else
1186 RADEON_WRITE(RADEON_CP_RB_CNTL, dev_priv->ring.size_l2qw);
1187#endif
1188
1189 /* Start with assuming that writeback doesn't work */
1190 dev_priv->writeback_works = 0;
1191
1177 /* Initialize the scratch register pointer. This will cause 1192 /* Initialize the scratch register pointer. This will cause
1178 * the scratch register values to be written out to memory 1193 * the scratch register values to be written out to memory
1179 * whenever they are updated. 1194 * whenever they are updated.
@@ -1190,28 +1205,9 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1190 1205
1191 RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7); 1206 RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7);
1192 1207
1193 /* Writeback doesn't seem to work everywhere, test it first */ 1208 /* Turn on bus mastering */
1194 DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0); 1209 tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
1195 RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef); 1210 RADEON_WRITE(RADEON_BUS_CNTL, tmp);
1196
1197 for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
1198 if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) ==
1199 0xdeadbeef)
1200 break;
1201 DRM_UDELAY(1);
1202 }
1203
1204 if (tmp < dev_priv->usec_timeout) {
1205 dev_priv->writeback_works = 1;
1206 DRM_DEBUG("writeback test succeeded, tmp=%d\n", tmp);
1207 } else {
1208 dev_priv->writeback_works = 0;
1209 DRM_DEBUG("writeback test failed\n");
1210 }
1211 if (radeon_no_wb == 1) {
1212 dev_priv->writeback_works = 0;
1213 DRM_DEBUG("writeback forced off\n");
1214 }
1215 1211
1216 dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0; 1212 dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0;
1217 RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame); 1213 RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
@@ -1223,26 +1219,45 @@ static void radeon_cp_init_ring_buffer(drm_device_t * dev,
1223 dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0; 1219 dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0;
1224 RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear); 1220 RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear);
1225 1221
1226 /* Set ring buffer size */
1227#ifdef __BIG_ENDIAN
1228 RADEON_WRITE(RADEON_CP_RB_CNTL,
1229 dev_priv->ring.size_l2qw | RADEON_BUF_SWAP_32BIT);
1230#else
1231 RADEON_WRITE(RADEON_CP_RB_CNTL, dev_priv->ring.size_l2qw);
1232#endif
1233
1234 radeon_do_wait_for_idle(dev_priv); 1222 radeon_do_wait_for_idle(dev_priv);
1235 1223
1236 /* Turn on bus mastering */
1237 tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
1238 RADEON_WRITE(RADEON_BUS_CNTL, tmp);
1239
1240 /* Sync everything up */ 1224 /* Sync everything up */
1241 RADEON_WRITE(RADEON_ISYNC_CNTL, 1225 RADEON_WRITE(RADEON_ISYNC_CNTL,
1242 (RADEON_ISYNC_ANY2D_IDLE3D | 1226 (RADEON_ISYNC_ANY2D_IDLE3D |
1243 RADEON_ISYNC_ANY3D_IDLE2D | 1227 RADEON_ISYNC_ANY3D_IDLE2D |
1244 RADEON_ISYNC_WAIT_IDLEGUI | 1228 RADEON_ISYNC_WAIT_IDLEGUI |
1245 RADEON_ISYNC_CPSCRATCH_IDLEGUI)); 1229 RADEON_ISYNC_CPSCRATCH_IDLEGUI));
1230
1231}
1232
1233static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
1234{
1235 u32 tmp;
1236
1237 /* Writeback doesn't seem to work everywhere, test it here and possibly
1238 * enable it if it appears to work
1239 */
1240 DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0);
1241 RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef);
1242
1243 for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
1244 if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) ==
1245 0xdeadbeef)
1246 break;
1247 DRM_UDELAY(1);
1248 }
1249
1250 if (tmp < dev_priv->usec_timeout) {
1251 dev_priv->writeback_works = 1;
1252 DRM_INFO("writeback test succeeded in %d usecs\n", tmp);
1253 } else {
1254 dev_priv->writeback_works = 0;
1255 DRM_INFO("writeback test failed\n");
1256 }
1257 if (radeon_no_wb == 1) {
1258 dev_priv->writeback_works = 0;
1259 DRM_INFO("writeback forced off\n");
1260 }
1246} 1261}
1247 1262
1248/* Enable or disable PCI-E GART on the chip */ 1263/* Enable or disable PCI-E GART on the chip */
@@ -1317,6 +1332,14 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1317 1332
1318 DRM_DEBUG("\n"); 1333 DRM_DEBUG("\n");
1319 1334
1335 /* if we require new memory map but we don't have it fail */
1336 if ((dev_priv->flags & CHIP_NEW_MEMMAP) && !dev_priv->new_memmap)
1337 {
1338 DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX\n");
1339 radeon_do_cleanup_cp(dev);
1340 return DRM_ERR(EINVAL);
1341 }
1342
1320 if (init->is_pci && (dev_priv->flags & CHIP_IS_AGP)) 1343 if (init->is_pci && (dev_priv->flags & CHIP_IS_AGP))
1321 { 1344 {
1322 DRM_DEBUG("Forcing AGP card to PCI mode\n"); 1345 DRM_DEBUG("Forcing AGP card to PCI mode\n");
@@ -1496,6 +1519,9 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1496 1519
1497 dev_priv->fb_location = (RADEON_READ(RADEON_MC_FB_LOCATION) 1520 dev_priv->fb_location = (RADEON_READ(RADEON_MC_FB_LOCATION)
1498 & 0xffff) << 16; 1521 & 0xffff) << 16;
1522 dev_priv->fb_size =
1523 ((RADEON_READ(RADEON_MC_FB_LOCATION) & 0xffff0000u) + 0x10000)
1524 - dev_priv->fb_location;
1499 1525
1500 dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) | 1526 dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
1501 ((dev_priv->front_offset 1527 ((dev_priv->front_offset
@@ -1510,8 +1536,46 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1510 + dev_priv->fb_location) >> 10)); 1536 + dev_priv->fb_location) >> 10));
1511 1537
1512 dev_priv->gart_size = init->gart_size; 1538 dev_priv->gart_size = init->gart_size;
1513 dev_priv->gart_vm_start = dev_priv->fb_location 1539
1514 + RADEON_READ(RADEON_CONFIG_APER_SIZE); 1540 /* New let's set the memory map ... */
1541 if (dev_priv->new_memmap) {
1542 u32 base = 0;
1543
1544 DRM_INFO("Setting GART location based on new memory map\n");
1545
1546 /* If using AGP, try to locate the AGP aperture at the same
1547 * location in the card and on the bus, though we have to
1548 * align it down.
1549 */
1550#if __OS_HAS_AGP
1551 if (dev_priv->flags & CHIP_IS_AGP) {
1552 base = dev->agp->base;
1553 /* Check if valid */
1554 if ((base + dev_priv->gart_size) > dev_priv->fb_location &&
1555 base < (dev_priv->fb_location + dev_priv->fb_size)) {
1556 DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n",
1557 dev->agp->base);
1558 base = 0;
1559 }
1560 }
1561#endif
1562 /* If not or if AGP is at 0 (Macs), try to put it elsewhere */
1563 if (base == 0) {
1564 base = dev_priv->fb_location + dev_priv->fb_size;
1565 if (((base + dev_priv->gart_size) & 0xfffffffful)
1566 < base)
1567 base = dev_priv->fb_location
1568 - dev_priv->gart_size;
1569 }
1570 dev_priv->gart_vm_start = base & 0xffc00000u;
1571 if (dev_priv->gart_vm_start != base)
1572 DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n",
1573 base, dev_priv->gart_vm_start);
1574 } else {
1575 DRM_INFO("Setting GART location based on old memory map\n");
1576 dev_priv->gart_vm_start = dev_priv->fb_location +
1577 RADEON_READ(RADEON_CONFIG_APER_SIZE);
1578 }
1515 1579
1516#if __OS_HAS_AGP 1580#if __OS_HAS_AGP
1517 if (dev_priv->flags & CHIP_IS_AGP) 1581 if (dev_priv->flags & CHIP_IS_AGP)
@@ -1596,6 +1660,7 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1596 dev_priv->last_buf = 0; 1660 dev_priv->last_buf = 0;
1597 1661
1598 radeon_do_engine_reset(dev); 1662 radeon_do_engine_reset(dev);
1663 radeon_test_writeback(dev_priv);
1599 1664
1600 return 0; 1665 return 0;
1601} 1666}
diff --git a/drivers/char/drm/radeon_drm.h b/drivers/char/drm/radeon_drm.h
index 9c177a6b2a4c..c8e279e89c2e 100644
--- a/drivers/char/drm/radeon_drm.h
+++ b/drivers/char/drm/radeon_drm.h
@@ -222,6 +222,7 @@ typedef union {
222# define R300_WAIT_3D 0x2 222# define R300_WAIT_3D 0x2
223# define R300_WAIT_2D_CLEAN 0x3 223# define R300_WAIT_2D_CLEAN 0x3
224# define R300_WAIT_3D_CLEAN 0x4 224# define R300_WAIT_3D_CLEAN 0x4
225#define R300_CMD_SCRATCH 8
225 226
226typedef union { 227typedef union {
227 unsigned int u; 228 unsigned int u;
@@ -247,6 +248,9 @@ typedef union {
247 struct { 248 struct {
248 unsigned char cmd_type, flags, pad0, pad1; 249 unsigned char cmd_type, flags, pad0, pad1;
249 } wait; 250 } wait;
251 struct {
252 unsigned char cmd_type, reg, n_bufs, flags;
253 } scratch;
250} drm_r300_cmd_header_t; 254} drm_r300_cmd_header_t;
251 255
252#define RADEON_FRONT 0x1 256#define RADEON_FRONT 0x1
@@ -697,6 +701,7 @@ typedef struct drm_radeon_setparam {
697#define RADEON_SETPARAM_FB_LOCATION 1 /* determined framebuffer location */ 701#define RADEON_SETPARAM_FB_LOCATION 1 /* determined framebuffer location */
698#define RADEON_SETPARAM_SWITCH_TILING 2 /* enable/disable color tiling */ 702#define RADEON_SETPARAM_SWITCH_TILING 2 /* enable/disable color tiling */
699#define RADEON_SETPARAM_PCIGART_LOCATION 3 /* PCI Gart Location */ 703#define RADEON_SETPARAM_PCIGART_LOCATION 3 /* PCI Gart Location */
704#define RADEON_SETPARAM_NEW_MEMMAP 4 /* Use new memory map */
700 705
701/* 1.14: Clients can allocate/free a surface 706/* 1.14: Clients can allocate/free a surface
702 */ 707 */
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index 1f7d2ab8c4fc..78345cee8f8e 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -38,7 +38,7 @@
38 38
39#define DRIVER_NAME "radeon" 39#define DRIVER_NAME "radeon"
40#define DRIVER_DESC "ATI Radeon" 40#define DRIVER_DESC "ATI Radeon"
41#define DRIVER_DATE "20051229" 41#define DRIVER_DATE "20060225"
42 42
43/* Interface history: 43/* Interface history:
44 * 44 *
@@ -91,9 +91,11 @@
91 * 1.20- Add support for r300 texrect 91 * 1.20- Add support for r300 texrect
92 * 1.21- Add support for card type getparam 92 * 1.21- Add support for card type getparam
93 * 1.22- Add support for texture cache flushes (R300_TX_CNTL) 93 * 1.22- Add support for texture cache flushes (R300_TX_CNTL)
94 * 1.23- Add new radeon memory map work from benh
95 * 1.24- Add general-purpose packet for manipulating scratch registers (r300)
94 */ 96 */
95#define DRIVER_MAJOR 1 97#define DRIVER_MAJOR 1
96#define DRIVER_MINOR 22 98#define DRIVER_MINOR 24
97#define DRIVER_PATCHLEVEL 0 99#define DRIVER_PATCHLEVEL 0
98 100
99/* 101/*
@@ -101,20 +103,21 @@
101 */ 103 */
102enum radeon_family { 104enum radeon_family {
103 CHIP_R100, 105 CHIP_R100,
104 CHIP_RS100,
105 CHIP_RV100, 106 CHIP_RV100,
107 CHIP_RS100,
106 CHIP_RV200, 108 CHIP_RV200,
107 CHIP_R200,
108 CHIP_RS200, 109 CHIP_RS200,
109 CHIP_R250, 110 CHIP_R200,
110 CHIP_RS250,
111 CHIP_RV250, 111 CHIP_RV250,
112 CHIP_RS300,
112 CHIP_RV280, 113 CHIP_RV280,
113 CHIP_R300, 114 CHIP_R300,
114 CHIP_RS300,
115 CHIP_R350, 115 CHIP_R350,
116 CHIP_RV350, 116 CHIP_RV350,
117 CHIP_RV380,
117 CHIP_R420, 118 CHIP_R420,
119 CHIP_RV410,
120 CHIP_RS400,
118 CHIP_LAST, 121 CHIP_LAST,
119}; 122};
120 123
@@ -136,9 +139,11 @@ enum radeon_chip_flags {
136 CHIP_IS_AGP = 0x00080000UL, 139 CHIP_IS_AGP = 0x00080000UL,
137 CHIP_HAS_HIERZ = 0x00100000UL, 140 CHIP_HAS_HIERZ = 0x00100000UL,
138 CHIP_IS_PCIE = 0x00200000UL, 141 CHIP_IS_PCIE = 0x00200000UL,
142 CHIP_NEW_MEMMAP = 0x00400000UL,
139}; 143};
140 144
141#define GET_RING_HEAD(dev_priv) DRM_READ32( (dev_priv)->ring_rptr, 0 ) 145#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \
146 DRM_READ32( (dev_priv)->ring_rptr, 0 ) : RADEON_READ(RADEON_CP_RB_RPTR))
142#define SET_RING_HEAD(dev_priv,val) DRM_WRITE32( (dev_priv)->ring_rptr, 0, (val) ) 147#define SET_RING_HEAD(dev_priv,val) DRM_WRITE32( (dev_priv)->ring_rptr, 0, (val) )
143 148
144typedef struct drm_radeon_freelist { 149typedef struct drm_radeon_freelist {
@@ -199,6 +204,8 @@ typedef struct drm_radeon_private {
199 drm_radeon_sarea_t *sarea_priv; 204 drm_radeon_sarea_t *sarea_priv;
200 205
201 u32 fb_location; 206 u32 fb_location;
207 u32 fb_size;
208 int new_memmap;
202 209
203 int gart_size; 210 int gart_size;
204 u32 gart_vm_start; 211 u32 gart_vm_start;
@@ -272,6 +279,8 @@ typedef struct drm_radeon_private {
272 unsigned long pcigart_offset; 279 unsigned long pcigart_offset;
273 drm_ati_pcigart_info gart_info; 280 drm_ati_pcigart_info gart_info;
274 281
282 u32 scratch_ages[5];
283
275 /* starting from here on, data is preserved accross an open */ 284 /* starting from here on, data is preserved accross an open */
276 uint32_t flags; /* see radeon_chip_flags */ 285 uint32_t flags; /* see radeon_chip_flags */
277} drm_radeon_private_t; 286} drm_radeon_private_t;
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 7bc27516d425..c5b8f774a599 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -45,22 +45,53 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
45 u32 off = *offset; 45 u32 off = *offset;
46 struct drm_radeon_driver_file_fields *radeon_priv; 46 struct drm_radeon_driver_file_fields *radeon_priv;
47 47
48 if (off >= dev_priv->fb_location && 48 /* Hrm ... the story of the offset ... So this function converts
49 off < (dev_priv->gart_vm_start + dev_priv->gart_size)) 49 * the various ideas of what userland clients might have for an
50 return 0; 50 * offset in the card address space into an offset into the card
51 51 * address space :) So with a sane client, it should just keep
52 radeon_priv = filp_priv->driver_priv; 52 * the value intact and just do some boundary checking. However,
53 off += radeon_priv->radeon_fb_delta; 53 * not all clients are sane. Some older clients pass us 0 based
54 * offsets relative to the start of the framebuffer and some may
55 * assume the AGP aperture it appended to the framebuffer, so we
56 * try to detect those cases and fix them up.
57 *
58 * Note: It might be a good idea here to make sure the offset lands
59 * in some "allowed" area to protect things like the PCIE GART...
60 */
54 61
55 DRM_DEBUG("offset fixed up to 0x%x\n", off); 62 /* First, the best case, the offset already lands in either the
63 * framebuffer or the GART mapped space
64 */
65 if ((off >= dev_priv->fb_location &&
66 off < (dev_priv->fb_location + dev_priv->fb_size)) ||
67 (off >= dev_priv->gart_vm_start &&
68 off < (dev_priv->gart_vm_start + dev_priv->gart_size)))
69 return 0;
56 70
57 if (off < dev_priv->fb_location || 71 /* Ok, that didn't happen... now check if we have a zero based
58 off >= (dev_priv->gart_vm_start + dev_priv->gart_size)) 72 * offset that fits in the framebuffer + gart space, apply the
59 return DRM_ERR(EINVAL); 73 * magic offset we get from SETPARAM or calculated from fb_location
74 */
75 if (off < (dev_priv->fb_size + dev_priv->gart_size)) {
76 radeon_priv = filp_priv->driver_priv;
77 off += radeon_priv->radeon_fb_delta;
78 }
60 79
61 *offset = off; 80 /* Finally, assume we aimed at a GART offset if beyond the fb */
81 if (off > (dev_priv->fb_location + dev_priv->fb_size))
82 off = off - (dev_priv->fb_location + dev_priv->fb_size) +
83 dev_priv->gart_vm_start;
62 84
63 return 0; 85 /* Now recheck and fail if out of bounds */
86 if ((off >= dev_priv->fb_location &&
87 off < (dev_priv->fb_location + dev_priv->fb_size)) ||
88 (off >= dev_priv->gart_vm_start &&
89 off < (dev_priv->gart_vm_start + dev_priv->gart_size))) {
90 DRM_DEBUG("offset fixed up to 0x%x\n", off);
91 *offset = off;
92 return 0;
93 }
94 return DRM_ERR(EINVAL);
64} 95}
65 96
66static __inline__ int radeon_check_and_fixup_packets(drm_radeon_private_t * 97static __inline__ int radeon_check_and_fixup_packets(drm_radeon_private_t *
@@ -1939,11 +1970,6 @@ static int radeon_surface_alloc(DRM_IOCTL_ARGS)
1939 drm_radeon_private_t *dev_priv = dev->dev_private; 1970 drm_radeon_private_t *dev_priv = dev->dev_private;
1940 drm_radeon_surface_alloc_t alloc; 1971 drm_radeon_surface_alloc_t alloc;
1941 1972
1942 if (!dev_priv) {
1943 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1944 return DRM_ERR(EINVAL);
1945 }
1946
1947 DRM_COPY_FROM_USER_IOCTL(alloc, 1973 DRM_COPY_FROM_USER_IOCTL(alloc,
1948 (drm_radeon_surface_alloc_t __user *) data, 1974 (drm_radeon_surface_alloc_t __user *) data,
1949 sizeof(alloc)); 1975 sizeof(alloc));
@@ -1960,12 +1986,7 @@ static int radeon_surface_free(DRM_IOCTL_ARGS)
1960 drm_radeon_private_t *dev_priv = dev->dev_private; 1986 drm_radeon_private_t *dev_priv = dev->dev_private;
1961 drm_radeon_surface_free_t memfree; 1987 drm_radeon_surface_free_t memfree;
1962 1988
1963 if (!dev_priv) { 1989 DRM_COPY_FROM_USER_IOCTL(memfree, (drm_radeon_surface_free_t __user *) data,
1964 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
1965 return DRM_ERR(EINVAL);
1966 }
1967
1968 DRM_COPY_FROM_USER_IOCTL(memfree, (drm_radeon_mem_free_t __user *) data,
1969 sizeof(memfree)); 1990 sizeof(memfree));
1970 1991
1971 if (free_surface(filp, dev_priv, memfree.address)) 1992 if (free_surface(filp, dev_priv, memfree.address))
@@ -2100,11 +2121,6 @@ static int radeon_cp_vertex(DRM_IOCTL_ARGS)
2100 2121
2101 LOCK_TEST_WITH_RETURN(dev, filp); 2122 LOCK_TEST_WITH_RETURN(dev, filp);
2102 2123
2103 if (!dev_priv) {
2104 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2105 return DRM_ERR(EINVAL);
2106 }
2107
2108 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp); 2124 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp);
2109 2125
2110 DRM_COPY_FROM_USER_IOCTL(vertex, (drm_radeon_vertex_t __user *) data, 2126 DRM_COPY_FROM_USER_IOCTL(vertex, (drm_radeon_vertex_t __user *) data,
@@ -2189,11 +2205,6 @@ static int radeon_cp_indices(DRM_IOCTL_ARGS)
2189 2205
2190 LOCK_TEST_WITH_RETURN(dev, filp); 2206 LOCK_TEST_WITH_RETURN(dev, filp);
2191 2207
2192 if (!dev_priv) {
2193 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2194 return DRM_ERR(EINVAL);
2195 }
2196
2197 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp); 2208 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp);
2198 2209
2199 DRM_COPY_FROM_USER_IOCTL(elts, (drm_radeon_indices_t __user *) data, 2210 DRM_COPY_FROM_USER_IOCTL(elts, (drm_radeon_indices_t __user *) data,
@@ -2340,11 +2351,6 @@ static int radeon_cp_indirect(DRM_IOCTL_ARGS)
2340 2351
2341 LOCK_TEST_WITH_RETURN(dev, filp); 2352 LOCK_TEST_WITH_RETURN(dev, filp);
2342 2353
2343 if (!dev_priv) {
2344 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2345 return DRM_ERR(EINVAL);
2346 }
2347
2348 DRM_COPY_FROM_USER_IOCTL(indirect, 2354 DRM_COPY_FROM_USER_IOCTL(indirect,
2349 (drm_radeon_indirect_t __user *) data, 2355 (drm_radeon_indirect_t __user *) data,
2350 sizeof(indirect)); 2356 sizeof(indirect));
@@ -2417,11 +2423,6 @@ static int radeon_cp_vertex2(DRM_IOCTL_ARGS)
2417 2423
2418 LOCK_TEST_WITH_RETURN(dev, filp); 2424 LOCK_TEST_WITH_RETURN(dev, filp);
2419 2425
2420 if (!dev_priv) {
2421 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2422 return DRM_ERR(EINVAL);
2423 }
2424
2425 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp); 2426 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp);
2426 2427
2427 DRM_COPY_FROM_USER_IOCTL(vertex, (drm_radeon_vertex2_t __user *) data, 2428 DRM_COPY_FROM_USER_IOCTL(vertex, (drm_radeon_vertex2_t __user *) data,
@@ -2738,11 +2739,6 @@ static int radeon_cp_cmdbuf(DRM_IOCTL_ARGS)
2738 2739
2739 LOCK_TEST_WITH_RETURN(dev, filp); 2740 LOCK_TEST_WITH_RETURN(dev, filp);
2740 2741
2741 if (!dev_priv) {
2742 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2743 return DRM_ERR(EINVAL);
2744 }
2745
2746 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp); 2742 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp);
2747 2743
2748 DRM_COPY_FROM_USER_IOCTL(cmdbuf, 2744 DRM_COPY_FROM_USER_IOCTL(cmdbuf,
@@ -2897,11 +2893,6 @@ static int radeon_cp_getparam(DRM_IOCTL_ARGS)
2897 drm_radeon_getparam_t param; 2893 drm_radeon_getparam_t param;
2898 int value; 2894 int value;
2899 2895
2900 if (!dev_priv) {
2901 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2902 return DRM_ERR(EINVAL);
2903 }
2904
2905 DRM_COPY_FROM_USER_IOCTL(param, (drm_radeon_getparam_t __user *) data, 2896 DRM_COPY_FROM_USER_IOCTL(param, (drm_radeon_getparam_t __user *) data,
2906 sizeof(param)); 2897 sizeof(param));
2907 2898
@@ -2981,11 +2972,6 @@ static int radeon_cp_setparam(DRM_IOCTL_ARGS)
2981 drm_radeon_setparam_t sp; 2972 drm_radeon_setparam_t sp;
2982 struct drm_radeon_driver_file_fields *radeon_priv; 2973 struct drm_radeon_driver_file_fields *radeon_priv;
2983 2974
2984 if (!dev_priv) {
2985 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
2986 return DRM_ERR(EINVAL);
2987 }
2988
2989 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp); 2975 DRM_GET_PRIV_WITH_RETURN(filp_priv, filp);
2990 2976
2991 DRM_COPY_FROM_USER_IOCTL(sp, (drm_radeon_setparam_t __user *) data, 2977 DRM_COPY_FROM_USER_IOCTL(sp, (drm_radeon_setparam_t __user *) data,
@@ -3012,6 +2998,9 @@ static int radeon_cp_setparam(DRM_IOCTL_ARGS)
3012 case RADEON_SETPARAM_PCIGART_LOCATION: 2998 case RADEON_SETPARAM_PCIGART_LOCATION:
3013 dev_priv->pcigart_offset = sp.value; 2999 dev_priv->pcigart_offset = sp.value;
3014 break; 3000 break;
3001 case RADEON_SETPARAM_NEW_MEMMAP:
3002 dev_priv->new_memmap = sp.value;
3003 break;
3015 default: 3004 default:
3016 DRM_DEBUG("Invalid parameter %d\n", sp.param); 3005 DRM_DEBUG("Invalid parameter %d\n", sp.param);
3017 return DRM_ERR(EINVAL); 3006 return DRM_ERR(EINVAL);
diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c
index 6774d2fe3452..5e9936bc307f 100644
--- a/drivers/char/drm/sis_mm.c
+++ b/drivers/char/drm/sis_mm.c
@@ -110,7 +110,7 @@ static int sis_fb_alloc(DRM_IOCTL_ARGS)
110 110
111 DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb)); 111 DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb));
112 112
113 DRM_DEBUG("alloc fb, size = %d, offset = %ld\n", fb.size, req.offset); 113 DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, req.offset);
114 114
115 return retval; 115 return retval;
116} 116}
diff --git a/drivers/char/drm/via_irq.c b/drivers/char/drm/via_irq.c
index 6152415644e9..c33d068cde19 100644
--- a/drivers/char/drm/via_irq.c
+++ b/drivers/char/drm/via_irq.c
@@ -196,9 +196,9 @@ via_driver_irq_wait(drm_device_t * dev, unsigned int irq, int force_sequence,
196{ 196{
197 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; 197 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
198 unsigned int cur_irq_sequence; 198 unsigned int cur_irq_sequence;
199 drm_via_irq_t *cur_irq = dev_priv->via_irqs; 199 drm_via_irq_t *cur_irq;
200 int ret = 0; 200 int ret = 0;
201 maskarray_t *masks = dev_priv->irq_masks; 201 maskarray_t *masks;
202 int real_irq; 202 int real_irq;
203 203
204 DRM_DEBUG("%s\n", __FUNCTION__); 204 DRM_DEBUG("%s\n", __FUNCTION__);
@@ -221,8 +221,9 @@ via_driver_irq_wait(drm_device_t * dev, unsigned int irq, int force_sequence,
221 __FUNCTION__, irq); 221 __FUNCTION__, irq);
222 return DRM_ERR(EINVAL); 222 return DRM_ERR(EINVAL);
223 } 223 }
224 224
225 cur_irq += real_irq; 225 masks = dev_priv->irq_masks;
226 cur_irq = dev_priv->via_irqs + real_irq;
226 227
227 if (masks[real_irq][2] && !force_sequence) { 228 if (masks[real_irq][2] && !force_sequence) {
228 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ, 229 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
@@ -247,11 +248,12 @@ void via_driver_irq_preinstall(drm_device_t * dev)
247{ 248{
248 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private; 249 drm_via_private_t *dev_priv = (drm_via_private_t *) dev->dev_private;
249 u32 status; 250 u32 status;
250 drm_via_irq_t *cur_irq = dev_priv->via_irqs; 251 drm_via_irq_t *cur_irq;
251 int i; 252 int i;
252 253
253 DRM_DEBUG("driver_irq_preinstall: dev_priv: %p\n", dev_priv); 254 DRM_DEBUG("driver_irq_preinstall: dev_priv: %p\n", dev_priv);
254 if (dev_priv) { 255 if (dev_priv) {
256 cur_irq = dev_priv->via_irqs;
255 257
256 dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE; 258 dev_priv->irq_enable_mask = VIA_IRQ_VBLANK_ENABLE;
257 dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING; 259 dev_priv->irq_pending_mask = VIA_IRQ_VBLANK_PENDING;
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index a229915ce1b2..87dcaa237f07 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -490,7 +490,7 @@ for (i = 0; i < 10; i++) \
490 release_region(dtlk_portlist[i], DTLK_IO_EXTENT); 490 release_region(dtlk_portlist[i], DTLK_IO_EXTENT);
491 } 491 }
492 492
493 printk(KERN_INFO "\nDoubleTalk PC - not found\n"); 493 printk(KERN_INFO "DoubleTalk PC - not found\n");
494 return -ENODEV; 494 return -ENODEV;
495} 495}
496 496
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 1b5e01e6e129..43ff59816511 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -22,6 +22,9 @@
22#include <linux/smp_lock.h> 22#include <linux/smp_lock.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/nvram.h> 24#include <asm/nvram.h>
25#ifdef CONFIG_PPC_PMAC
26#include <asm/machdep.h>
27#endif
25 28
26#define NVRAM_SIZE 8192 29#define NVRAM_SIZE 8192
27 30
@@ -92,7 +95,7 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
92 case IOC_NVRAM_GET_OFFSET: { 95 case IOC_NVRAM_GET_OFFSET: {
93 int part, offset; 96 int part, offset;
94 97
95 if (_machine != _MACH_Pmac) 98 if (!machine_is(powermac))
96 return -EINVAL; 99 return -EINVAL;
97 if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0) 100 if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
98 return -EFAULT; 101 return -EFAULT;
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index f65b2e14a485..2b6a56b2bf35 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -39,8 +39,10 @@
39#include <linux/sched.h> 39#include <linux/sched.h>
40#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43#include <asm/hvconsole.h> 44
45#include "hvc_console.h"
44 46
45#define HVC_MAJOR 229 47#define HVC_MAJOR 229
46#define HVC_MINOR 0 48#define HVC_MINOR 0
@@ -54,17 +56,14 @@
54#define HVC_CLOSE_WAIT (HZ/100) /* 1/10 of a second */ 56#define HVC_CLOSE_WAIT (HZ/100) /* 1/10 of a second */
55 57
56/* 58/*
57 * The Linux TTY code does not support dynamic addition of tty derived devices 59 * These sizes are most efficient for vio, because they are the
58 * so we need to know how many tty devices we might need when space is allocated 60 * native transfer size. We could make them selectable in the
59 * for the tty device. Since this driver supports hotplug of vty adapters we 61 * future to better deal with backends that want other buffer sizes.
60 * need to make sure we have enough allocated.
61 */ 62 */
62#define HVC_ALLOC_TTY_ADAPTERS 8
63
64#define N_OUTBUF 16 63#define N_OUTBUF 16
65#define N_INBUF 16 64#define N_INBUF 16
66 65
67#define __ALIGNED__ __attribute__((__aligned__(8))) 66#define __ALIGNED__ __attribute__((__aligned__(sizeof(long))))
68 67
69static struct tty_driver *hvc_driver; 68static struct tty_driver *hvc_driver;
70static struct task_struct *hvc_task; 69static struct task_struct *hvc_task;
@@ -154,7 +153,7 @@ static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
154 153
155void hvc_console_print(struct console *co, const char *b, unsigned count) 154void hvc_console_print(struct console *co, const char *b, unsigned count)
156{ 155{
157 char c[16] __ALIGNED__; 156 char c[N_OUTBUF] __ALIGNED__;
158 unsigned i = 0, n = 0; 157 unsigned i = 0, n = 0;
159 int r, donecr = 0, index = co->index; 158 int r, donecr = 0, index = co->index;
160 159
@@ -473,8 +472,10 @@ static void hvc_push(struct hvc_struct *hp)
473 472
474 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf); 473 n = hp->ops->put_chars(hp->vtermno, hp->outbuf, hp->n_outbuf);
475 if (n <= 0) { 474 if (n <= 0) {
476 if (n == 0) 475 if (n == 0) {
476 hp->do_wakeup = 1;
477 return; 477 return;
478 }
478 /* throw away output on error; this happens when 479 /* throw away output on error; this happens when
479 there is no session connected to the vterm. */ 480 there is no session connected to the vterm. */
480 hp->n_outbuf = 0; 481 hp->n_outbuf = 0;
@@ -486,12 +487,19 @@ static void hvc_push(struct hvc_struct *hp)
486 hp->do_wakeup = 1; 487 hp->do_wakeup = 1;
487} 488}
488 489
489static inline int __hvc_write_kernel(struct hvc_struct *hp, 490static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count)
490 const unsigned char *buf, int count)
491{ 491{
492 struct hvc_struct *hp = tty->driver_data;
492 unsigned long flags; 493 unsigned long flags;
493 int rsize, written = 0; 494 int rsize, written = 0;
494 495
496 /* This write was probably executed during a tty close. */
497 if (!hp)
498 return -EPIPE;
499
500 if (hp->count <= 0)
501 return -EIO;
502
495 spin_lock_irqsave(&hp->lock, flags); 503 spin_lock_irqsave(&hp->lock, flags);
496 504
497 /* Push pending writes */ 505 /* Push pending writes */
@@ -510,26 +518,8 @@ static inline int __hvc_write_kernel(struct hvc_struct *hp,
510 } 518 }
511 spin_unlock_irqrestore(&hp->lock, flags); 519 spin_unlock_irqrestore(&hp->lock, flags);
512 520
513 return written;
514}
515static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count)
516{
517 struct hvc_struct *hp = tty->driver_data;
518 int written;
519
520 /* This write was probably executed during a tty close. */
521 if (!hp)
522 return -EPIPE;
523
524 if (hp->count <= 0)
525 return -EIO;
526
527 written = __hvc_write_kernel(hp, buf, count);
528
529 /* 521 /*
530 * Racy, but harmless, kick thread if there is still pending data. 522 * Racy, but harmless, kick thread if there is still pending data.
531 * There really is nothing wrong with kicking the thread, even if there
532 * is no buffered data.
533 */ 523 */
534 if (hp->n_outbuf) 524 if (hp->n_outbuf)
535 hvc_kick(); 525 hvc_kick();
@@ -614,6 +604,13 @@ static int hvc_poll(struct hvc_struct *hp)
614 spin_unlock_irqrestore(&hp->lock, flags); 604 spin_unlock_irqrestore(&hp->lock, flags);
615 tty_hangup(tty); 605 tty_hangup(tty);
616 spin_lock_irqsave(&hp->lock, flags); 606 spin_lock_irqsave(&hp->lock, flags);
607 } else if ( n == -EAGAIN ) {
608 /*
609 * Some back-ends can only ensure a certain min
610 * num of bytes read, which may be > 'count'.
611 * Let the tty clear the flip buff to make room.
612 */
613 poll_mask |= HVC_POLL_READ;
617 } 614 }
618 break; 615 break;
619 } 616 }
@@ -635,16 +632,7 @@ static int hvc_poll(struct hvc_struct *hp)
635 tty_insert_flip_char(tty, buf[i], 0); 632 tty_insert_flip_char(tty, buf[i], 0);
636 } 633 }
637 634
638 /*
639 * Account for the total amount read in one loop, and if above
640 * 64 bytes, we do a quick schedule loop to let the tty grok
641 * the data and eventually throttle us.
642 */
643 read_total += n; 635 read_total += n;
644 if (read_total >= 64) {
645 poll_mask |= HVC_POLL_QUICK;
646 break;
647 }
648 } 636 }
649 throttled: 637 throttled:
650 /* Wakeup write queue if necessary */ 638 /* Wakeup write queue if necessary */
@@ -767,7 +755,8 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
767 * see if this vterm id matches one registered for console. 755 * see if this vterm id matches one registered for console.
768 */ 756 */
769 for (i=0; i < MAX_NR_HVC_CONSOLES; i++) 757 for (i=0; i < MAX_NR_HVC_CONSOLES; i++)
770 if (vtermnos[i] == hp->vtermno) 758 if (vtermnos[i] == hp->vtermno &&
759 cons_ops[i] == hp->ops)
771 break; 760 break;
772 761
773 /* no matching slot, just use a counter */ 762 /* no matching slot, just use a counter */
@@ -823,34 +812,38 @@ EXPORT_SYMBOL(hvc_remove);
823 * interfaces start to become available. */ 812 * interfaces start to become available. */
824int __init hvc_init(void) 813int __init hvc_init(void)
825{ 814{
815 struct tty_driver *drv;
816
826 /* We need more than hvc_count adapters due to hotplug additions. */ 817 /* We need more than hvc_count adapters due to hotplug additions. */
827 hvc_driver = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS); 818 drv = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS);
828 if (!hvc_driver) 819 if (!drv)
829 return -ENOMEM; 820 return -ENOMEM;
830 821
831 hvc_driver->owner = THIS_MODULE; 822 drv->owner = THIS_MODULE;
832 hvc_driver->devfs_name = "hvc/"; 823 drv->devfs_name = "hvc/";
833 hvc_driver->driver_name = "hvc"; 824 drv->driver_name = "hvc";
834 hvc_driver->name = "hvc"; 825 drv->name = "hvc";
835 hvc_driver->major = HVC_MAJOR; 826 drv->major = HVC_MAJOR;
836 hvc_driver->minor_start = HVC_MINOR; 827 drv->minor_start = HVC_MINOR;
837 hvc_driver->type = TTY_DRIVER_TYPE_SYSTEM; 828 drv->type = TTY_DRIVER_TYPE_SYSTEM;
838 hvc_driver->init_termios = tty_std_termios; 829 drv->init_termios = tty_std_termios;
839 hvc_driver->flags = TTY_DRIVER_REAL_RAW; 830 drv->flags = TTY_DRIVER_REAL_RAW;
840 tty_set_operations(hvc_driver, &hvc_ops); 831 tty_set_operations(drv, &hvc_ops);
841 832
842 /* Always start the kthread because there can be hotplug vty adapters 833 /* Always start the kthread because there can be hotplug vty adapters
843 * added later. */ 834 * added later. */
844 hvc_task = kthread_run(khvcd, NULL, "khvcd"); 835 hvc_task = kthread_run(khvcd, NULL, "khvcd");
845 if (IS_ERR(hvc_task)) { 836 if (IS_ERR(hvc_task)) {
846 panic("Couldn't create kthread for console.\n"); 837 panic("Couldn't create kthread for console.\n");
847 put_tty_driver(hvc_driver); 838 put_tty_driver(drv);
848 return -EIO; 839 return -EIO;
849 } 840 }
850 841
851 if (tty_register_driver(hvc_driver)) 842 if (tty_register_driver(drv))
852 panic("Couldn't register hvc console driver\n"); 843 panic("Couldn't register hvc console driver\n");
853 844
845 mb();
846 hvc_driver = drv;
854 return 0; 847 return 0;
855} 848}
856module_init(hvc_init); 849module_init(hvc_init);
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
new file mode 100644
index 000000000000..96b7401319c1
--- /dev/null
+++ b/drivers/char/hvc_console.h
@@ -0,0 +1,63 @@
1/*
2 * hvc_console.h
3 * Copyright (C) 2005 IBM Corporation
4 *
5 * Author(s):
6 * Ryan S. Arnold <rsa@us.ibm.com>
7 *
8 * hvc_console header information:
9 * moved here from include/asm-powerpc/hvconsole.h
10 * and drivers/char/hvc_console.c
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#ifndef HVC_CONSOLE_H
28#define HVC_CONSOLE_H
29
30/*
31 * This is the max number of console adapters that can/will be found as
32 * console devices on first stage console init. Any number beyond this range
33 * can't be used as a console device but is still a valid tty device.
34 */
35#define MAX_NR_HVC_CONSOLES 16
36
37/*
38 * The Linux TTY code does not support dynamic addition of tty derived devices
39 * so we need to know how many tty devices we might need when space is allocated
40 * for the tty device. Since this driver supports hotplug of vty adapters we
41 * need to make sure we have enough allocated.
42 */
43#define HVC_ALLOC_TTY_ADAPTERS 8
44
45
46/* implemented by a low level driver */
47struct hv_ops {
48 int (*get_chars)(uint32_t vtermno, char *buf, int count);
49 int (*put_chars)(uint32_t vtermno, const char *buf, int count);
50};
51
52struct hvc_struct;
53
54/* Register a vterm and a slot index for use as a console (console_init) */
55extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
56
57/* register a vterm for hvc tty operation (module_init or hotplug add) */
58extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int irq,
59 struct hv_ops *ops);
60/* remove a vterm from hvc tty operation (modele_exit or hotplug remove) */
61extern int __devexit hvc_remove(struct hvc_struct *hp);
62
63#endif // HVC_CONSOLE_H
diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
new file mode 100644
index 000000000000..83364ea63cba
--- /dev/null
+++ b/drivers/char/hvc_rtas.c
@@ -0,0 +1,138 @@
1/*
2 * IBM RTAS driver interface to hvc_console.c
3 *
4 * (C) Copyright IBM Corporation 2001-2005
5 * (C) Copyright Red Hat, Inc. 2005
6 *
7 * Author(s): Maximino Augilar <IBM STI Design Center>
8 * : Ryan S. Arnold <rsa@us.ibm.com>
9 * : Utz Bacher <utz.bacher@de.ibm.com>
10 * : David Woodhouse <dwmw2@infradead.org>
11 *
12 * inspired by drivers/char/hvc_console.c
13 * written by Anton Blanchard and Paul Mackerras
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29
30#include <linux/console.h>
31#include <linux/delay.h>
32#include <linux/err.h>
33#include <linux/init.h>
34#include <linux/moduleparam.h>
35#include <linux/types.h>
36
37#include <asm/irq.h>
38#include <asm/rtas.h>
39#include "hvc_console.h"
40
41#define hvc_rtas_cookie 0x67781e15
42struct hvc_struct *hvc_rtas_dev;
43
44#define RTASCONS_PUT_ATTEMPTS 16
45
46static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE;
47static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE;
48static int rtascons_put_delay = 100;
49module_param_named(put_delay, rtascons_put_delay, int, 0644);
50
51static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf, int count)
52{
53 int done;
54
55 /* if there is more than one character to be displayed, wait a bit */
56 for (done = 0; done < count; done++) {
57 int result;
58 result = rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[done]);
59 if (result)
60 break;
61 }
62 /* the calling routine expects to receive the number of bytes sent */
63 return done;
64}
65
66static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
67{
68 int i;
69
70 for (i = 0; i < count; i++) {
71 int c, err;
72
73 err = rtas_call(rtascons_get_char_token, 0, 2, &c);
74 if (err)
75 break;
76
77 buf[i] = c;
78 }
79
80 return i;
81}
82
83static struct hv_ops hvc_rtas_get_put_ops = {
84 .get_chars = hvc_rtas_read_console,
85 .put_chars = hvc_rtas_write_console,
86};
87
88static int hvc_rtas_init(void)
89{
90 struct hvc_struct *hp;
91
92 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
93 rtascons_put_char_token = rtas_token("put-term-char");
94 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
95 return -EIO;
96
97 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
98 rtascons_get_char_token = rtas_token("get-term-char");
99 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
100 return -EIO;
101
102 BUG_ON(hvc_rtas_dev);
103
104 /* Allocate an hvc_struct for the console device we instantiated
105 * earlier. Save off hp so that we can return it on exit */
106 hp = hvc_alloc(hvc_rtas_cookie, NO_IRQ, &hvc_rtas_get_put_ops);
107 if (IS_ERR(hp))
108 return PTR_ERR(hp);
109 hvc_rtas_dev = hp;
110 return 0;
111}
112module_init(hvc_rtas_init);
113
114/* This will tear down the tty portion of the driver */
115static void __exit hvc_rtas_exit(void)
116{
117 /* Really the fun isn't over until the worker thread breaks down and the
118 * tty cleans up */
119 if (hvc_rtas_dev)
120 hvc_remove(hvc_rtas_dev);
121}
122module_exit(hvc_rtas_exit);
123
124/* This will happen prior to module init. There is no tty at this time? */
125static int hvc_rtas_console_init(void)
126{
127 rtascons_put_char_token = rtas_token("put-term-char");
128 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
129 return -EIO;
130 rtascons_get_char_token = rtas_token("get-term-char");
131 if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE)
132 return -EIO;
133
134 hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops );
135 add_preferred_console("hvc", 0, NULL);
136 return 0;
137}
138console_initcall(hvc_rtas_console_init);
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index f5212eb2b41d..9add81ceb440 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -31,10 +31,13 @@
31 31
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/init.h> 33#include <linux/init.h>
34
34#include <asm/hvconsole.h> 35#include <asm/hvconsole.h>
35#include <asm/vio.h> 36#include <asm/vio.h>
36#include <asm/prom.h> 37#include <asm/prom.h>
37 38
39#include "hvc_console.h"
40
38char hvc_driver_name[] = "hvc_console"; 41char hvc_driver_name[] = "hvc_console";
39 42
40static struct vio_device_id hvc_driver_table[] __devinitdata = { 43static struct vio_device_id hvc_driver_table[] __devinitdata = {
@@ -48,6 +51,14 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
48 unsigned long got; 51 unsigned long got;
49 int i; 52 int i;
50 53
54 /*
55 * Vio firmware will read up to SIZE_VIO_GET_CHARS at its own discretion
56 * so we play safe and avoid the situation where got > count which could
57 * overload the flip buffer.
58 */
59 if (count < SIZE_VIO_GET_CHARS)
60 return -EAGAIN;
61
51 got = hvc_get_chars(vtermno, buf, count); 62 got = hvc_get_chars(vtermno, buf, count);
52 63
53 /* 64 /*
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index f7ac31856572..8d97b3911293 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -439,7 +439,6 @@ static int hvcs_io(struct hvcs_struct *hvcsd)
439 char buf[HVCS_BUFF_LEN] __ALIGNED__; 439 char buf[HVCS_BUFF_LEN] __ALIGNED__;
440 unsigned long flags; 440 unsigned long flags;
441 int got = 0; 441 int got = 0;
442 int i;
443 442
444 spin_lock_irqsave(&hvcsd->lock, flags); 443 spin_lock_irqsave(&hvcsd->lock, flags);
445 444
@@ -905,7 +904,7 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
905 * It is possible the vty-server was removed after the irq was 904 * It is possible the vty-server was removed after the irq was
906 * requested but before we have time to enable interrupts. 905 * requested but before we have time to enable interrupts.
907 */ 906 */
908 if (vio_enable_interrupts(vdev) == H_Success) 907 if (vio_enable_interrupts(vdev) == H_SUCCESS)
909 return 0; 908 return 0;
910 else { 909 else {
911 printk(KERN_ERR "HVCS: int enable failed for" 910 printk(KERN_ERR "HVCS: int enable failed for"
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 932feedda262..e1c95374984c 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -42,7 +42,7 @@
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/devfs_fs_kernel.h> 43#include <linux/devfs_fs_kernel.h>
44#include <linux/ipmi.h> 44#include <linux/ipmi.h>
45#include <asm/semaphore.h> 45#include <linux/mutex.h>
46#include <linux/init.h> 46#include <linux/init.h>
47#include <linux/device.h> 47#include <linux/device.h>
48#include <linux/compat.h> 48#include <linux/compat.h>
@@ -55,7 +55,7 @@ struct ipmi_file_private
55 struct file *file; 55 struct file *file;
56 struct fasync_struct *fasync_queue; 56 struct fasync_struct *fasync_queue;
57 wait_queue_head_t wait; 57 wait_queue_head_t wait;
58 struct semaphore recv_sem; 58 struct mutex recv_mutex;
59 int default_retries; 59 int default_retries;
60 unsigned int default_retry_time_ms; 60 unsigned int default_retry_time_ms;
61}; 61};
@@ -141,7 +141,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
141 INIT_LIST_HEAD(&(priv->recv_msgs)); 141 INIT_LIST_HEAD(&(priv->recv_msgs));
142 init_waitqueue_head(&priv->wait); 142 init_waitqueue_head(&priv->wait);
143 priv->fasync_queue = NULL; 143 priv->fasync_queue = NULL;
144 sema_init(&(priv->recv_sem), 1); 144 mutex_init(&priv->recv_mutex);
145 145
146 /* Use the low-level defaults. */ 146 /* Use the low-level defaults. */
147 priv->default_retries = -1; 147 priv->default_retries = -1;
@@ -285,15 +285,15 @@ static int ipmi_ioctl(struct inode *inode,
285 break; 285 break;
286 } 286 }
287 287
288 /* We claim a semaphore because we don't want two 288 /* We claim a mutex because we don't want two
289 users getting something from the queue at a time. 289 users getting something from the queue at a time.
290 Since we have to release the spinlock before we can 290 Since we have to release the spinlock before we can
291 copy the data to the user, it's possible another 291 copy the data to the user, it's possible another
292 user will grab something from the queue, too. Then 292 user will grab something from the queue, too. Then
293 the messages might get out of order if something 293 the messages might get out of order if something
294 fails and the message gets put back onto the 294 fails and the message gets put back onto the
295 queue. This semaphore prevents that problem. */ 295 queue. This mutex prevents that problem. */
296 down(&(priv->recv_sem)); 296 mutex_lock(&priv->recv_mutex);
297 297
298 /* Grab the message off the list. */ 298 /* Grab the message off the list. */
299 spin_lock_irqsave(&(priv->recv_msg_lock), flags); 299 spin_lock_irqsave(&(priv->recv_msg_lock), flags);
@@ -352,7 +352,7 @@ static int ipmi_ioctl(struct inode *inode,
352 goto recv_putback_on_err; 352 goto recv_putback_on_err;
353 } 353 }
354 354
355 up(&(priv->recv_sem)); 355 mutex_unlock(&priv->recv_mutex);
356 ipmi_free_recv_msg(msg); 356 ipmi_free_recv_msg(msg);
357 break; 357 break;
358 358
@@ -362,11 +362,11 @@ static int ipmi_ioctl(struct inode *inode,
362 spin_lock_irqsave(&(priv->recv_msg_lock), flags); 362 spin_lock_irqsave(&(priv->recv_msg_lock), flags);
363 list_add(entry, &(priv->recv_msgs)); 363 list_add(entry, &(priv->recv_msgs));
364 spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); 364 spin_unlock_irqrestore(&(priv->recv_msg_lock), flags);
365 up(&(priv->recv_sem)); 365 mutex_unlock(&priv->recv_mutex);
366 break; 366 break;
367 367
368 recv_err: 368 recv_err:
369 up(&(priv->recv_sem)); 369 mutex_unlock(&priv->recv_mutex);
370 break; 370 break;
371 } 371 }
372 372
diff --git a/drivers/char/ipmi/ipmi_kcs_sm.c b/drivers/char/ipmi/ipmi_kcs_sm.c
index da1554194d3d..2062675f9e99 100644
--- a/drivers/char/ipmi/ipmi_kcs_sm.c
+++ b/drivers/char/ipmi/ipmi_kcs_sm.c
@@ -227,7 +227,7 @@ static inline int check_ibf(struct si_sm_data *kcs, unsigned char status,
227static inline int check_obf(struct si_sm_data *kcs, unsigned char status, 227static inline int check_obf(struct si_sm_data *kcs, unsigned char status,
228 long time) 228 long time)
229{ 229{
230 if (! GET_STATUS_OBF(status)) { 230 if (!GET_STATUS_OBF(status)) {
231 kcs->obf_timeout -= time; 231 kcs->obf_timeout -= time;
232 if (kcs->obf_timeout < 0) { 232 if (kcs->obf_timeout < 0) {
233 start_error_recovery(kcs, "OBF not ready in time"); 233 start_error_recovery(kcs, "OBF not ready in time");
@@ -407,7 +407,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
407 } 407 }
408 408
409 if (state == KCS_READ_STATE) { 409 if (state == KCS_READ_STATE) {
410 if (! check_obf(kcs, status, time)) 410 if (!check_obf(kcs, status, time))
411 return SI_SM_CALL_WITH_DELAY; 411 return SI_SM_CALL_WITH_DELAY;
412 read_next_byte(kcs); 412 read_next_byte(kcs);
413 } else { 413 } else {
@@ -447,7 +447,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
447 "Not in read state for error2"); 447 "Not in read state for error2");
448 break; 448 break;
449 } 449 }
450 if (! check_obf(kcs, status, time)) 450 if (!check_obf(kcs, status, time))
451 return SI_SM_CALL_WITH_DELAY; 451 return SI_SM_CALL_WITH_DELAY;
452 452
453 clear_obf(kcs, status); 453 clear_obf(kcs, status);
@@ -462,7 +462,7 @@ static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
462 break; 462 break;
463 } 463 }
464 464
465 if (! check_obf(kcs, status, time)) 465 if (!check_obf(kcs, status, time))
466 return SI_SM_CALL_WITH_DELAY; 466 return SI_SM_CALL_WITH_DELAY;
467 467
468 clear_obf(kcs, status); 468 clear_obf(kcs, status);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 40eb005b9d77..9f2f8fdec69a 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -38,6 +38,7 @@
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/poll.h> 39#include <linux/poll.h>
40#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/mutex.h>
41#include <linux/slab.h> 42#include <linux/slab.h>
42#include <linux/ipmi.h> 43#include <linux/ipmi.h>
43#include <linux/ipmi_smi.h> 44#include <linux/ipmi_smi.h>
@@ -234,7 +235,7 @@ struct ipmi_smi
234 235
235 /* The list of command receivers that are registered for commands 236 /* The list of command receivers that are registered for commands
236 on this interface. */ 237 on this interface. */
237 struct semaphore cmd_rcvrs_lock; 238 struct mutex cmd_rcvrs_mutex;
238 struct list_head cmd_rcvrs; 239 struct list_head cmd_rcvrs;
239 240
240 /* Events that were queues because no one was there to receive 241 /* Events that were queues because no one was there to receive
@@ -387,10 +388,10 @@ static void clean_up_interface_data(ipmi_smi_t intf)
387 388
388 /* Wholesale remove all the entries from the list in the 389 /* Wholesale remove all the entries from the list in the
389 * interface and wait for RCU to know that none are in use. */ 390 * interface and wait for RCU to know that none are in use. */
390 down(&intf->cmd_rcvrs_lock); 391 mutex_lock(&intf->cmd_rcvrs_mutex);
391 list_add_rcu(&list, &intf->cmd_rcvrs); 392 list_add_rcu(&list, &intf->cmd_rcvrs);
392 list_del_rcu(&intf->cmd_rcvrs); 393 list_del_rcu(&intf->cmd_rcvrs);
393 up(&intf->cmd_rcvrs_lock); 394 mutex_unlock(&intf->cmd_rcvrs_mutex);
394 synchronize_rcu(); 395 synchronize_rcu();
395 396
396 list_for_each_entry_safe(rcvr, rcvr2, &list, link) 397 list_for_each_entry_safe(rcvr, rcvr2, &list, link)
@@ -557,7 +558,7 @@ unsigned int ipmi_addr_length(int addr_type)
557 558
558static void deliver_response(struct ipmi_recv_msg *msg) 559static void deliver_response(struct ipmi_recv_msg *msg)
559{ 560{
560 if (! msg->user) { 561 if (!msg->user) {
561 ipmi_smi_t intf = msg->user_msg_data; 562 ipmi_smi_t intf = msg->user_msg_data;
562 unsigned long flags; 563 unsigned long flags;
563 564
@@ -598,11 +599,11 @@ static int intf_next_seq(ipmi_smi_t intf,
598 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq; 599 (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq;
599 i = (i+1)%IPMI_IPMB_NUM_SEQ) 600 i = (i+1)%IPMI_IPMB_NUM_SEQ)
600 { 601 {
601 if (! intf->seq_table[i].inuse) 602 if (!intf->seq_table[i].inuse)
602 break; 603 break;
603 } 604 }
604 605
605 if (! intf->seq_table[i].inuse) { 606 if (!intf->seq_table[i].inuse) {
606 intf->seq_table[i].recv_msg = recv_msg; 607 intf->seq_table[i].recv_msg = recv_msg;
607 608
608 /* Start with the maximum timeout, when the send response 609 /* Start with the maximum timeout, when the send response
@@ -763,7 +764,7 @@ int ipmi_create_user(unsigned int if_num,
763 } 764 }
764 765
765 new_user = kmalloc(sizeof(*new_user), GFP_KERNEL); 766 new_user = kmalloc(sizeof(*new_user), GFP_KERNEL);
766 if (! new_user) 767 if (!new_user)
767 return -ENOMEM; 768 return -ENOMEM;
768 769
769 spin_lock_irqsave(&interfaces_lock, flags); 770 spin_lock_irqsave(&interfaces_lock, flags);
@@ -819,14 +820,13 @@ static void free_user(struct kref *ref)
819 820
820int ipmi_destroy_user(ipmi_user_t user) 821int ipmi_destroy_user(ipmi_user_t user)
821{ 822{
822 int rv = -ENODEV;
823 ipmi_smi_t intf = user->intf; 823 ipmi_smi_t intf = user->intf;
824 int i; 824 int i;
825 unsigned long flags; 825 unsigned long flags;
826 struct cmd_rcvr *rcvr; 826 struct cmd_rcvr *rcvr;
827 struct cmd_rcvr *rcvrs = NULL; 827 struct cmd_rcvr *rcvrs = NULL;
828 828
829 user->valid = 1; 829 user->valid = 0;
830 830
831 /* Remove the user from the interface's sequence table. */ 831 /* Remove the user from the interface's sequence table. */
832 spin_lock_irqsave(&intf->seq_lock, flags); 832 spin_lock_irqsave(&intf->seq_lock, flags);
@@ -847,7 +847,7 @@ int ipmi_destroy_user(ipmi_user_t user)
847 * since other things may be using it till we do 847 * since other things may be using it till we do
848 * synchronize_rcu()) then free everything in that list. 848 * synchronize_rcu()) then free everything in that list.
849 */ 849 */
850 down(&intf->cmd_rcvrs_lock); 850 mutex_lock(&intf->cmd_rcvrs_mutex);
851 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { 851 list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) {
852 if (rcvr->user == user) { 852 if (rcvr->user == user) {
853 list_del_rcu(&rcvr->link); 853 list_del_rcu(&rcvr->link);
@@ -855,7 +855,7 @@ int ipmi_destroy_user(ipmi_user_t user)
855 rcvrs = rcvr; 855 rcvrs = rcvr;
856 } 856 }
857 } 857 }
858 up(&intf->cmd_rcvrs_lock); 858 mutex_unlock(&intf->cmd_rcvrs_mutex);
859 synchronize_rcu(); 859 synchronize_rcu();
860 while (rcvrs) { 860 while (rcvrs) {
861 rcvr = rcvrs; 861 rcvr = rcvrs;
@@ -871,7 +871,7 @@ int ipmi_destroy_user(ipmi_user_t user)
871 871
872 kref_put(&user->refcount, free_user); 872 kref_put(&user->refcount, free_user);
873 873
874 return rv; 874 return 0;
875} 875}
876 876
877void ipmi_get_version(ipmi_user_t user, 877void ipmi_get_version(ipmi_user_t user,
@@ -936,10 +936,12 @@ int ipmi_set_gets_events(ipmi_user_t user, int val)
936 936
937 if (val) { 937 if (val) {
938 /* Deliver any queued events. */ 938 /* Deliver any queued events. */
939 list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) { 939 list_for_each_entry_safe(msg, msg2, &intf->waiting_events,
940 link) {
940 list_del(&msg->link); 941 list_del(&msg->link);
941 list_add_tail(&msg->link, &msgs); 942 list_add_tail(&msg->link, &msgs);
942 } 943 }
944 intf->waiting_events_count = 0;
943 } 945 }
944 946
945 /* Hold the events lock while doing this to preserve order. */ 947 /* Hold the events lock while doing this to preserve order. */
@@ -978,13 +980,13 @@ int ipmi_register_for_cmd(ipmi_user_t user,
978 980
979 981
980 rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL); 982 rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL);
981 if (! rcvr) 983 if (!rcvr)
982 return -ENOMEM; 984 return -ENOMEM;
983 rcvr->cmd = cmd; 985 rcvr->cmd = cmd;
984 rcvr->netfn = netfn; 986 rcvr->netfn = netfn;
985 rcvr->user = user; 987 rcvr->user = user;
986 988
987 down(&intf->cmd_rcvrs_lock); 989 mutex_lock(&intf->cmd_rcvrs_mutex);
988 /* Make sure the command/netfn is not already registered. */ 990 /* Make sure the command/netfn is not already registered. */
989 entry = find_cmd_rcvr(intf, netfn, cmd); 991 entry = find_cmd_rcvr(intf, netfn, cmd);
990 if (entry) { 992 if (entry) {
@@ -995,7 +997,7 @@ int ipmi_register_for_cmd(ipmi_user_t user,
995 list_add_rcu(&rcvr->link, &intf->cmd_rcvrs); 997 list_add_rcu(&rcvr->link, &intf->cmd_rcvrs);
996 998
997 out_unlock: 999 out_unlock:
998 up(&intf->cmd_rcvrs_lock); 1000 mutex_unlock(&intf->cmd_rcvrs_mutex);
999 if (rv) 1001 if (rv)
1000 kfree(rcvr); 1002 kfree(rcvr);
1001 1003
@@ -1009,17 +1011,17 @@ int ipmi_unregister_for_cmd(ipmi_user_t user,
1009 ipmi_smi_t intf = user->intf; 1011 ipmi_smi_t intf = user->intf;
1010 struct cmd_rcvr *rcvr; 1012 struct cmd_rcvr *rcvr;
1011 1013
1012 down(&intf->cmd_rcvrs_lock); 1014 mutex_lock(&intf->cmd_rcvrs_mutex);
1013 /* Make sure the command/netfn is not already registered. */ 1015 /* Make sure the command/netfn is not already registered. */
1014 rcvr = find_cmd_rcvr(intf, netfn, cmd); 1016 rcvr = find_cmd_rcvr(intf, netfn, cmd);
1015 if ((rcvr) && (rcvr->user == user)) { 1017 if ((rcvr) && (rcvr->user == user)) {
1016 list_del_rcu(&rcvr->link); 1018 list_del_rcu(&rcvr->link);
1017 up(&intf->cmd_rcvrs_lock); 1019 mutex_unlock(&intf->cmd_rcvrs_mutex);
1018 synchronize_rcu(); 1020 synchronize_rcu();
1019 kfree(rcvr); 1021 kfree(rcvr);
1020 return 0; 1022 return 0;
1021 } else { 1023 } else {
1022 up(&intf->cmd_rcvrs_lock); 1024 mutex_unlock(&intf->cmd_rcvrs_mutex);
1023 return -ENOENT; 1025 return -ENOENT;
1024 } 1026 }
1025} 1027}
@@ -1514,7 +1516,7 @@ int ipmi_request_settime(ipmi_user_t user,
1514 unsigned char saddr, lun; 1516 unsigned char saddr, lun;
1515 int rv; 1517 int rv;
1516 1518
1517 if (! user) 1519 if (!user)
1518 return -EINVAL; 1520 return -EINVAL;
1519 rv = check_addr(user->intf, addr, &saddr, &lun); 1521 rv = check_addr(user->intf, addr, &saddr, &lun);
1520 if (rv) 1522 if (rv)
@@ -1545,7 +1547,7 @@ int ipmi_request_supply_msgs(ipmi_user_t user,
1545 unsigned char saddr, lun; 1547 unsigned char saddr, lun;
1546 int rv; 1548 int rv;
1547 1549
1548 if (! user) 1550 if (!user)
1549 return -EINVAL; 1551 return -EINVAL;
1550 rv = check_addr(user->intf, addr, &saddr, &lun); 1552 rv = check_addr(user->intf, addr, &saddr, &lun);
1551 if (rv) 1553 if (rv)
@@ -1570,7 +1572,7 @@ static int ipmb_file_read_proc(char *page, char **start, off_t off,
1570 char *out = (char *) page; 1572 char *out = (char *) page;
1571 ipmi_smi_t intf = data; 1573 ipmi_smi_t intf = data;
1572 int i; 1574 int i;
1573 int rv= 0; 1575 int rv = 0;
1574 1576
1575 for (i = 0; i < IPMI_MAX_CHANNELS; i++) 1577 for (i = 0; i < IPMI_MAX_CHANNELS; i++)
1576 rv += sprintf(out+rv, "%x ", intf->channels[i].address); 1578 rv += sprintf(out+rv, "%x ", intf->channels[i].address);
@@ -1989,7 +1991,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf)
1989 } else { 1991 } else {
1990 bmc->dev = platform_device_alloc("ipmi_bmc", 1992 bmc->dev = platform_device_alloc("ipmi_bmc",
1991 bmc->id.device_id); 1993 bmc->id.device_id);
1992 if (! bmc->dev) { 1994 if (!bmc->dev) {
1993 printk(KERN_ERR 1995 printk(KERN_ERR
1994 "ipmi_msghandler:" 1996 "ipmi_msghandler:"
1995 " Unable to allocate platform device\n"); 1997 " Unable to allocate platform device\n");
@@ -2305,8 +2307,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2305 void *send_info, 2307 void *send_info,
2306 struct ipmi_device_id *device_id, 2308 struct ipmi_device_id *device_id,
2307 struct device *si_dev, 2309 struct device *si_dev,
2308 unsigned char slave_addr, 2310 unsigned char slave_addr)
2309 ipmi_smi_t *new_intf)
2310{ 2311{
2311 int i, j; 2312 int i, j;
2312 int rv; 2313 int rv;
@@ -2366,7 +2367,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2366 spin_lock_init(&intf->events_lock); 2367 spin_lock_init(&intf->events_lock);
2367 INIT_LIST_HEAD(&intf->waiting_events); 2368 INIT_LIST_HEAD(&intf->waiting_events);
2368 intf->waiting_events_count = 0; 2369 intf->waiting_events_count = 0;
2369 init_MUTEX(&intf->cmd_rcvrs_lock); 2370 mutex_init(&intf->cmd_rcvrs_mutex);
2370 INIT_LIST_HEAD(&intf->cmd_rcvrs); 2371 INIT_LIST_HEAD(&intf->cmd_rcvrs);
2371 init_waitqueue_head(&intf->waitq); 2372 init_waitqueue_head(&intf->waitq);
2372 2373
@@ -2388,9 +2389,9 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2388 if (rv) 2389 if (rv)
2389 goto out; 2390 goto out;
2390 2391
2391 /* FIXME - this is an ugly kludge, this sets the intf for the 2392 rv = handlers->start_processing(send_info, intf);
2392 caller before sending any messages with it. */ 2393 if (rv)
2393 *new_intf = intf; 2394 goto out;
2394 2395
2395 get_guid(intf); 2396 get_guid(intf);
2396 2397
@@ -2622,7 +2623,7 @@ static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf,
2622 spin_unlock_irqrestore(&intf->counter_lock, flags); 2623 spin_unlock_irqrestore(&intf->counter_lock, flags);
2623 2624
2624 recv_msg = ipmi_alloc_recv_msg(); 2625 recv_msg = ipmi_alloc_recv_msg();
2625 if (! recv_msg) { 2626 if (!recv_msg) {
2626 /* We couldn't allocate memory for the 2627 /* We couldn't allocate memory for the
2627 message, so requeue it for handling 2628 message, so requeue it for handling
2628 later. */ 2629 later. */
@@ -2777,7 +2778,7 @@ static int handle_lan_get_msg_cmd(ipmi_smi_t intf,
2777 spin_unlock_irqrestore(&intf->counter_lock, flags); 2778 spin_unlock_irqrestore(&intf->counter_lock, flags);
2778 2779
2779 recv_msg = ipmi_alloc_recv_msg(); 2780 recv_msg = ipmi_alloc_recv_msg();
2780 if (! recv_msg) { 2781 if (!recv_msg) {
2781 /* We couldn't allocate memory for the 2782 /* We couldn't allocate memory for the
2782 message, so requeue it for handling 2783 message, so requeue it for handling
2783 later. */ 2784 later. */
@@ -2869,13 +2870,14 @@ static int handle_read_event_rsp(ipmi_smi_t intf,
2869 events. */ 2870 events. */
2870 rcu_read_lock(); 2871 rcu_read_lock();
2871 list_for_each_entry_rcu(user, &intf->users, link) { 2872 list_for_each_entry_rcu(user, &intf->users, link) {
2872 if (! user->gets_events) 2873 if (!user->gets_events)
2873 continue; 2874 continue;
2874 2875
2875 recv_msg = ipmi_alloc_recv_msg(); 2876 recv_msg = ipmi_alloc_recv_msg();
2876 if (! recv_msg) { 2877 if (!recv_msg) {
2877 rcu_read_unlock(); 2878 rcu_read_unlock();
2878 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) { 2879 list_for_each_entry_safe(recv_msg, recv_msg2, &msgs,
2880 link) {
2879 list_del(&recv_msg->link); 2881 list_del(&recv_msg->link);
2880 ipmi_free_recv_msg(recv_msg); 2882 ipmi_free_recv_msg(recv_msg);
2881 } 2883 }
@@ -2905,7 +2907,7 @@ static int handle_read_event_rsp(ipmi_smi_t intf,
2905 /* No one to receive the message, put it in queue if there's 2907 /* No one to receive the message, put it in queue if there's
2906 not already too many things in the queue. */ 2908 not already too many things in the queue. */
2907 recv_msg = ipmi_alloc_recv_msg(); 2909 recv_msg = ipmi_alloc_recv_msg();
2908 if (! recv_msg) { 2910 if (!recv_msg) {
2909 /* We couldn't allocate memory for the 2911 /* We couldn't allocate memory for the
2910 message, so requeue it for handling 2912 message, so requeue it for handling
2911 later. */ 2913 later. */
@@ -2915,6 +2917,7 @@ static int handle_read_event_rsp(ipmi_smi_t intf,
2915 2917
2916 copy_event_into_recv_msg(recv_msg, msg); 2918 copy_event_into_recv_msg(recv_msg, msg);
2917 list_add_tail(&(recv_msg->link), &(intf->waiting_events)); 2919 list_add_tail(&(recv_msg->link), &(intf->waiting_events));
2920 intf->waiting_events_count++;
2918 } else { 2921 } else {
2919 /* There's too many things in the queue, discard this 2922 /* There's too many things in the queue, discard this
2920 message. */ 2923 message. */
@@ -3190,7 +3193,7 @@ void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf)
3190 3193
3191 rcu_read_lock(); 3194 rcu_read_lock();
3192 list_for_each_entry_rcu(user, &intf->users, link) { 3195 list_for_each_entry_rcu(user, &intf->users, link) {
3193 if (! user->handler->ipmi_watchdog_pretimeout) 3196 if (!user->handler->ipmi_watchdog_pretimeout)
3194 continue; 3197 continue;
3195 3198
3196 user->handler->ipmi_watchdog_pretimeout(user->handler_data); 3199 user->handler->ipmi_watchdog_pretimeout(user->handler_data);
@@ -3278,7 +3281,7 @@ static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent,
3278 3281
3279 smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot, 3282 smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot,
3280 ent->seqid); 3283 ent->seqid);
3281 if (! smi_msg) 3284 if (!smi_msg)
3282 return; 3285 return;
3283 3286
3284 spin_unlock_irqrestore(&intf->seq_lock, *flags); 3287 spin_unlock_irqrestore(&intf->seq_lock, *flags);
@@ -3314,8 +3317,9 @@ static void ipmi_timeout_handler(long timeout_period)
3314 3317
3315 /* See if any waiting messages need to be processed. */ 3318 /* See if any waiting messages need to be processed. */
3316 spin_lock_irqsave(&intf->waiting_msgs_lock, flags); 3319 spin_lock_irqsave(&intf->waiting_msgs_lock, flags);
3317 list_for_each_entry_safe(smi_msg, smi_msg2, &intf->waiting_msgs, link) { 3320 list_for_each_entry_safe(smi_msg, smi_msg2,
3318 if (! handle_new_recv_msg(intf, smi_msg)) { 3321 &intf->waiting_msgs, link) {
3322 if (!handle_new_recv_msg(intf, smi_msg)) {
3319 list_del(&smi_msg->link); 3323 list_del(&smi_msg->link);
3320 ipmi_free_smi_msg(smi_msg); 3324 ipmi_free_smi_msg(smi_msg);
3321 } else { 3325 } else {
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 786a2802ca34..d0b5c08e7b4e 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -346,7 +346,7 @@ static int ipmi_dell_chassis_detect (ipmi_user_t user)
346{ 346{
347 const char ipmi_version_major = ipmi_version & 0xF; 347 const char ipmi_version_major = ipmi_version & 0xF;
348 const char ipmi_version_minor = (ipmi_version >> 4) & 0xF; 348 const char ipmi_version_minor = (ipmi_version >> 4) & 0xF;
349 const char mfr[3]=DELL_IANA_MFR_ID; 349 const char mfr[3] = DELL_IANA_MFR_ID;
350 if (!memcmp(mfr, &mfg_id, sizeof(mfr)) && 350 if (!memcmp(mfr, &mfg_id, sizeof(mfr)) &&
351 ipmi_version_major <= 1 && 351 ipmi_version_major <= 1 &&
352 ipmi_version_minor < 5) 352 ipmi_version_minor < 5)
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 35fbd4d8ed4b..a86c0f29953e 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -803,7 +803,7 @@ static int ipmi_thread(void *data)
803 set_user_nice(current, 19); 803 set_user_nice(current, 19);
804 while (!kthread_should_stop()) { 804 while (!kthread_should_stop()) {
805 spin_lock_irqsave(&(smi_info->si_lock), flags); 805 spin_lock_irqsave(&(smi_info->si_lock), flags);
806 smi_result=smi_event_handler(smi_info, 0); 806 smi_result = smi_event_handler(smi_info, 0);
807 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 807 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
808 if (smi_result == SI_SM_CALL_WITHOUT_DELAY) { 808 if (smi_result == SI_SM_CALL_WITHOUT_DELAY) {
809 /* do nothing */ 809 /* do nothing */
@@ -972,10 +972,37 @@ static irqreturn_t si_bt_irq_handler(int irq, void *data, struct pt_regs *regs)
972 return si_irq_handler(irq, data, regs); 972 return si_irq_handler(irq, data, regs);
973} 973}
974 974
975static int smi_start_processing(void *send_info,
976 ipmi_smi_t intf)
977{
978 struct smi_info *new_smi = send_info;
979
980 new_smi->intf = intf;
981
982 /* Set up the timer that drives the interface. */
983 setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi);
984 new_smi->last_timeout_jiffies = jiffies;
985 mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES);
986
987 if (new_smi->si_type != SI_BT) {
988 new_smi->thread = kthread_run(ipmi_thread, new_smi,
989 "kipmi%d", new_smi->intf_num);
990 if (IS_ERR(new_smi->thread)) {
991 printk(KERN_NOTICE "ipmi_si_intf: Could not start"
992 " kernel thread due to error %ld, only using"
993 " timers to drive the interface\n",
994 PTR_ERR(new_smi->thread));
995 new_smi->thread = NULL;
996 }
997 }
998
999 return 0;
1000}
975 1001
976static struct ipmi_smi_handlers handlers = 1002static struct ipmi_smi_handlers handlers =
977{ 1003{
978 .owner = THIS_MODULE, 1004 .owner = THIS_MODULE,
1005 .start_processing = smi_start_processing,
979 .sender = sender, 1006 .sender = sender,
980 .request_events = request_events, 1007 .request_events = request_events,
981 .set_run_to_completion = set_run_to_completion, 1008 .set_run_to_completion = set_run_to_completion,
@@ -987,7 +1014,7 @@ static struct ipmi_smi_handlers handlers =
987 1014
988#define SI_MAX_PARMS 4 1015#define SI_MAX_PARMS 4
989static LIST_HEAD(smi_infos); 1016static LIST_HEAD(smi_infos);
990static DECLARE_MUTEX(smi_infos_lock); 1017static DEFINE_MUTEX(smi_infos_lock);
991static int smi_num; /* Used to sequence the SMIs */ 1018static int smi_num; /* Used to sequence the SMIs */
992 1019
993#define DEFAULT_REGSPACING 1 1020#define DEFAULT_REGSPACING 1
@@ -2162,9 +2189,13 @@ static void setup_xaction_handlers(struct smi_info *smi_info)
2162 2189
2163static inline void wait_for_timer_and_thread(struct smi_info *smi_info) 2190static inline void wait_for_timer_and_thread(struct smi_info *smi_info)
2164{ 2191{
2165 if (smi_info->thread != NULL && smi_info->thread != ERR_PTR(-ENOMEM)) 2192 if (smi_info->intf) {
2166 kthread_stop(smi_info->thread); 2193 /* The timer and thread are only running if the
2167 del_timer_sync(&smi_info->si_timer); 2194 interface has been started up and registered. */
2195 if (smi_info->thread != NULL)
2196 kthread_stop(smi_info->thread);
2197 del_timer_sync(&smi_info->si_timer);
2198 }
2168} 2199}
2169 2200
2170static struct ipmi_default_vals 2201static struct ipmi_default_vals
@@ -2245,7 +2276,7 @@ static int try_smi_init(struct smi_info *new_smi)
2245 new_smi->slave_addr, new_smi->irq); 2276 new_smi->slave_addr, new_smi->irq);
2246 } 2277 }
2247 2278
2248 down(&smi_infos_lock); 2279 mutex_lock(&smi_infos_lock);
2249 if (!is_new_interface(new_smi)) { 2280 if (!is_new_interface(new_smi)) {
2250 printk(KERN_WARNING "ipmi_si: duplicate interface\n"); 2281 printk(KERN_WARNING "ipmi_si: duplicate interface\n");
2251 rv = -EBUSY; 2282 rv = -EBUSY;
@@ -2341,21 +2372,6 @@ static int try_smi_init(struct smi_info *new_smi)
2341 if (new_smi->irq) 2372 if (new_smi->irq)
2342 new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ; 2373 new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ;
2343 2374
2344 /* The ipmi_register_smi() code does some operations to
2345 determine the channel information, so we must be ready to
2346 handle operations before it is called. This means we have
2347 to stop the timer if we get an error after this point. */
2348 init_timer(&(new_smi->si_timer));
2349 new_smi->si_timer.data = (long) new_smi;
2350 new_smi->si_timer.function = smi_timeout;
2351 new_smi->last_timeout_jiffies = jiffies;
2352 new_smi->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES;
2353
2354 add_timer(&(new_smi->si_timer));
2355 if (new_smi->si_type != SI_BT)
2356 new_smi->thread = kthread_run(ipmi_thread, new_smi,
2357 "kipmi%d", new_smi->intf_num);
2358
2359 if (!new_smi->dev) { 2375 if (!new_smi->dev) {
2360 /* If we don't already have a device from something 2376 /* If we don't already have a device from something
2361 * else (like PCI), then register a new one. */ 2377 * else (like PCI), then register a new one. */
@@ -2365,7 +2381,7 @@ static int try_smi_init(struct smi_info *new_smi)
2365 printk(KERN_ERR 2381 printk(KERN_ERR
2366 "ipmi_si_intf:" 2382 "ipmi_si_intf:"
2367 " Unable to allocate platform device\n"); 2383 " Unable to allocate platform device\n");
2368 goto out_err_stop_timer; 2384 goto out_err;
2369 } 2385 }
2370 new_smi->dev = &new_smi->pdev->dev; 2386 new_smi->dev = &new_smi->pdev->dev;
2371 new_smi->dev->driver = &ipmi_driver; 2387 new_smi->dev->driver = &ipmi_driver;
@@ -2377,7 +2393,7 @@ static int try_smi_init(struct smi_info *new_smi)
2377 " Unable to register system interface device:" 2393 " Unable to register system interface device:"
2378 " %d\n", 2394 " %d\n",
2379 rv); 2395 rv);
2380 goto out_err_stop_timer; 2396 goto out_err;
2381 } 2397 }
2382 new_smi->dev_registered = 1; 2398 new_smi->dev_registered = 1;
2383 } 2399 }
@@ -2386,8 +2402,7 @@ static int try_smi_init(struct smi_info *new_smi)
2386 new_smi, 2402 new_smi,
2387 &new_smi->device_id, 2403 &new_smi->device_id,
2388 new_smi->dev, 2404 new_smi->dev,
2389 new_smi->slave_addr, 2405 new_smi->slave_addr);
2390 &(new_smi->intf));
2391 if (rv) { 2406 if (rv) {
2392 printk(KERN_ERR 2407 printk(KERN_ERR
2393 "ipmi_si: Unable to register device: error %d\n", 2408 "ipmi_si: Unable to register device: error %d\n",
@@ -2417,7 +2432,7 @@ static int try_smi_init(struct smi_info *new_smi)
2417 2432
2418 list_add_tail(&new_smi->link, &smi_infos); 2433 list_add_tail(&new_smi->link, &smi_infos);
2419 2434
2420 up(&smi_infos_lock); 2435 mutex_unlock(&smi_infos_lock);
2421 2436
2422 printk(" IPMI %s interface initialized\n",si_to_str[new_smi->si_type]); 2437 printk(" IPMI %s interface initialized\n",si_to_str[new_smi->si_type]);
2423 2438
@@ -2454,7 +2469,7 @@ static int try_smi_init(struct smi_info *new_smi)
2454 2469
2455 kfree(new_smi); 2470 kfree(new_smi);
2456 2471
2457 up(&smi_infos_lock); 2472 mutex_unlock(&smi_infos_lock);
2458 2473
2459 return rv; 2474 return rv;
2460} 2475}
@@ -2512,26 +2527,26 @@ static __devinit int init_ipmi_si(void)
2512#endif 2527#endif
2513 2528
2514 if (si_trydefaults) { 2529 if (si_trydefaults) {
2515 down(&smi_infos_lock); 2530 mutex_lock(&smi_infos_lock);
2516 if (list_empty(&smi_infos)) { 2531 if (list_empty(&smi_infos)) {
2517 /* No BMC was found, try defaults. */ 2532 /* No BMC was found, try defaults. */
2518 up(&smi_infos_lock); 2533 mutex_unlock(&smi_infos_lock);
2519 default_find_bmc(); 2534 default_find_bmc();
2520 } else { 2535 } else {
2521 up(&smi_infos_lock); 2536 mutex_unlock(&smi_infos_lock);
2522 } 2537 }
2523 } 2538 }
2524 2539
2525 down(&smi_infos_lock); 2540 mutex_lock(&smi_infos_lock);
2526 if (list_empty(&smi_infos)) { 2541 if (list_empty(&smi_infos)) {
2527 up(&smi_infos_lock); 2542 mutex_unlock(&smi_infos_lock);
2528#ifdef CONFIG_PCI 2543#ifdef CONFIG_PCI
2529 pci_unregister_driver(&ipmi_pci_driver); 2544 pci_unregister_driver(&ipmi_pci_driver);
2530#endif 2545#endif
2531 printk("ipmi_si: Unable to find any System Interface(s)\n"); 2546 printk("ipmi_si: Unable to find any System Interface(s)\n");
2532 return -ENODEV; 2547 return -ENODEV;
2533 } else { 2548 } else {
2534 up(&smi_infos_lock); 2549 mutex_unlock(&smi_infos_lock);
2535 return 0; 2550 return 0;
2536 } 2551 }
2537} 2552}
@@ -2607,10 +2622,10 @@ static __exit void cleanup_ipmi_si(void)
2607 pci_unregister_driver(&ipmi_pci_driver); 2622 pci_unregister_driver(&ipmi_pci_driver);
2608#endif 2623#endif
2609 2624
2610 down(&smi_infos_lock); 2625 mutex_lock(&smi_infos_lock);
2611 list_for_each_entry_safe(e, tmp_e, &smi_infos, link) 2626 list_for_each_entry_safe(e, tmp_e, &smi_infos, link)
2612 cleanup_one_si(e); 2627 cleanup_one_si(e);
2613 up(&smi_infos_lock); 2628 mutex_unlock(&smi_infos_lock);
2614 2629
2615 driver_unregister(&ipmi_driver); 2630 driver_unregister(&ipmi_driver);
2616} 2631}
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 7ece9f3c8f70..2d11ddd99e55 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -39,6 +39,7 @@
39#include <linux/watchdog.h> 39#include <linux/watchdog.h>
40#include <linux/miscdevice.h> 40#include <linux/miscdevice.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/completion.h>
42#include <linux/rwsem.h> 43#include <linux/rwsem.h>
43#include <linux/errno.h> 44#include <linux/errno.h>
44#include <asm/uaccess.h> 45#include <asm/uaccess.h>
@@ -303,21 +304,22 @@ static int ipmi_heartbeat(void);
303static void panic_halt_ipmi_heartbeat(void); 304static void panic_halt_ipmi_heartbeat(void);
304 305
305 306
306/* We use a semaphore to make sure that only one thing can send a set 307/* We use a mutex to make sure that only one thing can send a set
307 timeout at one time, because we only have one copy of the data. 308 timeout at one time, because we only have one copy of the data.
308 The semaphore is claimed when the set_timeout is sent and freed 309 The mutex is claimed when the set_timeout is sent and freed
309 when both messages are free. */ 310 when both messages are free. */
310static atomic_t set_timeout_tofree = ATOMIC_INIT(0); 311static atomic_t set_timeout_tofree = ATOMIC_INIT(0);
311static DECLARE_MUTEX(set_timeout_lock); 312static DEFINE_MUTEX(set_timeout_lock);
313static DECLARE_COMPLETION(set_timeout_wait);
312static void set_timeout_free_smi(struct ipmi_smi_msg *msg) 314static void set_timeout_free_smi(struct ipmi_smi_msg *msg)
313{ 315{
314 if (atomic_dec_and_test(&set_timeout_tofree)) 316 if (atomic_dec_and_test(&set_timeout_tofree))
315 up(&set_timeout_lock); 317 complete(&set_timeout_wait);
316} 318}
317static void set_timeout_free_recv(struct ipmi_recv_msg *msg) 319static void set_timeout_free_recv(struct ipmi_recv_msg *msg)
318{ 320{
319 if (atomic_dec_and_test(&set_timeout_tofree)) 321 if (atomic_dec_and_test(&set_timeout_tofree))
320 up(&set_timeout_lock); 322 complete(&set_timeout_wait);
321} 323}
322static struct ipmi_smi_msg set_timeout_smi_msg = 324static struct ipmi_smi_msg set_timeout_smi_msg =
323{ 325{
@@ -399,7 +401,7 @@ static int ipmi_set_timeout(int do_heartbeat)
399 401
400 402
401 /* We can only send one of these at a time. */ 403 /* We can only send one of these at a time. */
402 down(&set_timeout_lock); 404 mutex_lock(&set_timeout_lock);
403 405
404 atomic_set(&set_timeout_tofree, 2); 406 atomic_set(&set_timeout_tofree, 2);
405 407
@@ -407,16 +409,21 @@ static int ipmi_set_timeout(int do_heartbeat)
407 &set_timeout_recv_msg, 409 &set_timeout_recv_msg,
408 &send_heartbeat_now); 410 &send_heartbeat_now);
409 if (rv) { 411 if (rv) {
410 up(&set_timeout_lock); 412 mutex_unlock(&set_timeout_lock);
411 } else { 413 goto out;
412 if ((do_heartbeat == IPMI_SET_TIMEOUT_FORCE_HB)
413 || ((send_heartbeat_now)
414 && (do_heartbeat == IPMI_SET_TIMEOUT_HB_IF_NECESSARY)))
415 {
416 rv = ipmi_heartbeat();
417 }
418 } 414 }
419 415
416 wait_for_completion(&set_timeout_wait);
417
418 if ((do_heartbeat == IPMI_SET_TIMEOUT_FORCE_HB)
419 || ((send_heartbeat_now)
420 && (do_heartbeat == IPMI_SET_TIMEOUT_HB_IF_NECESSARY)))
421 {
422 rv = ipmi_heartbeat();
423 }
424 mutex_unlock(&set_timeout_lock);
425
426out:
420 return rv; 427 return rv;
421} 428}
422 429
@@ -458,17 +465,17 @@ static void panic_halt_ipmi_set_timeout(void)
458 The semaphore is claimed when the set_timeout is sent and freed 465 The semaphore is claimed when the set_timeout is sent and freed
459 when both messages are free. */ 466 when both messages are free. */
460static atomic_t heartbeat_tofree = ATOMIC_INIT(0); 467static atomic_t heartbeat_tofree = ATOMIC_INIT(0);
461static DECLARE_MUTEX(heartbeat_lock); 468static DEFINE_MUTEX(heartbeat_lock);
462static DECLARE_MUTEX_LOCKED(heartbeat_wait_lock); 469static DECLARE_COMPLETION(heartbeat_wait);
463static void heartbeat_free_smi(struct ipmi_smi_msg *msg) 470static void heartbeat_free_smi(struct ipmi_smi_msg *msg)
464{ 471{
465 if (atomic_dec_and_test(&heartbeat_tofree)) 472 if (atomic_dec_and_test(&heartbeat_tofree))
466 up(&heartbeat_wait_lock); 473 complete(&heartbeat_wait);
467} 474}
468static void heartbeat_free_recv(struct ipmi_recv_msg *msg) 475static void heartbeat_free_recv(struct ipmi_recv_msg *msg)
469{ 476{
470 if (atomic_dec_and_test(&heartbeat_tofree)) 477 if (atomic_dec_and_test(&heartbeat_tofree))
471 up(&heartbeat_wait_lock); 478 complete(&heartbeat_wait);
472} 479}
473static struct ipmi_smi_msg heartbeat_smi_msg = 480static struct ipmi_smi_msg heartbeat_smi_msg =
474{ 481{
@@ -511,14 +518,14 @@ static int ipmi_heartbeat(void)
511 return ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY); 518 return ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
512 } 519 }
513 520
514 down(&heartbeat_lock); 521 mutex_lock(&heartbeat_lock);
515 522
516 atomic_set(&heartbeat_tofree, 2); 523 atomic_set(&heartbeat_tofree, 2);
517 524
518 /* Don't reset the timer if we have the timer turned off, that 525 /* Don't reset the timer if we have the timer turned off, that
519 re-enables the watchdog. */ 526 re-enables the watchdog. */
520 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE) { 527 if (ipmi_watchdog_state == WDOG_TIMEOUT_NONE) {
521 up(&heartbeat_lock); 528 mutex_unlock(&heartbeat_lock);
522 return 0; 529 return 0;
523 } 530 }
524 531
@@ -539,14 +546,14 @@ static int ipmi_heartbeat(void)
539 &heartbeat_recv_msg, 546 &heartbeat_recv_msg,
540 1); 547 1);
541 if (rv) { 548 if (rv) {
542 up(&heartbeat_lock); 549 mutex_unlock(&heartbeat_lock);
543 printk(KERN_WARNING PFX "heartbeat failure: %d\n", 550 printk(KERN_WARNING PFX "heartbeat failure: %d\n",
544 rv); 551 rv);
545 return rv; 552 return rv;
546 } 553 }
547 554
548 /* Wait for the heartbeat to be sent. */ 555 /* Wait for the heartbeat to be sent. */
549 down(&heartbeat_wait_lock); 556 wait_for_completion(&heartbeat_wait);
550 557
551 if (heartbeat_recv_msg.msg.data[0] != 0) { 558 if (heartbeat_recv_msg.msg.data[0] != 0) {
552 /* Got an error in the heartbeat response. It was already 559 /* Got an error in the heartbeat response. It was already
@@ -555,7 +562,7 @@ static int ipmi_heartbeat(void)
555 rv = -EINVAL; 562 rv = -EINVAL;
556 } 563 }
557 564
558 up(&heartbeat_lock); 565 mutex_unlock(&heartbeat_lock);
559 566
560 return rv; 567 return rv;
561} 568}
@@ -589,7 +596,7 @@ static void panic_halt_ipmi_heartbeat(void)
589 1); 596 1);
590} 597}
591 598
592static struct watchdog_info ident= 599static struct watchdog_info ident =
593{ 600{
594 .options = 0, /* WDIOF_SETTIMEOUT, */ 601 .options = 0, /* WDIOF_SETTIMEOUT, */
595 .firmware_version = 1, 602 .firmware_version = 1,
@@ -790,13 +797,13 @@ static int ipmi_fasync(int fd, struct file *file, int on)
790 797
791static int ipmi_close(struct inode *ino, struct file *filep) 798static int ipmi_close(struct inode *ino, struct file *filep)
792{ 799{
793 if (iminor(ino)==WATCHDOG_MINOR) 800 if (iminor(ino) == WATCHDOG_MINOR) {
794 {
795 if (expect_close == 42) { 801 if (expect_close == 42) {
796 ipmi_watchdog_state = WDOG_TIMEOUT_NONE; 802 ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
797 ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB); 803 ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);
798 } else { 804 } else {
799 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); 805 printk(KERN_CRIT PFX
806 "Unexpected close, not stopping watchdog!\n");
800 ipmi_heartbeat(); 807 ipmi_heartbeat();
801 } 808 }
802 clear_bit(0, &ipmi_wdog_open); 809 clear_bit(0, &ipmi_wdog_open);
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index e5247f85a446..ef20c1fc9c4c 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -706,7 +706,6 @@ static int stli_portcmdstats(stliport_t *portp);
706static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp); 706static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
707static int stli_getportstruct(stliport_t __user *arg); 707static int stli_getportstruct(stliport_t __user *arg);
708static int stli_getbrdstruct(stlibrd_t __user *arg); 708static int stli_getbrdstruct(stlibrd_t __user *arg);
709static void *stli_memalloc(int len);
710static stlibrd_t *stli_allocbrd(void); 709static stlibrd_t *stli_allocbrd(void);
711 710
712static void stli_ecpinit(stlibrd_t *brdp); 711static void stli_ecpinit(stlibrd_t *brdp);
@@ -997,17 +996,6 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
997 996
998/*****************************************************************************/ 997/*****************************************************************************/
999 998
1000/*
1001 * Local driver kernel malloc routine.
1002 */
1003
1004static void *stli_memalloc(int len)
1005{
1006 return((void *) kmalloc(len, GFP_KERNEL));
1007}
1008
1009/*****************************************************************************/
1010
1011static int stli_open(struct tty_struct *tty, struct file *filp) 999static int stli_open(struct tty_struct *tty, struct file *filp)
1012{ 1000{
1013 stlibrd_t *brdp; 1001 stlibrd_t *brdp;
@@ -3227,13 +3215,12 @@ static int stli_initports(stlibrd_t *brdp)
3227#endif 3215#endif
3228 3216
3229 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 3217 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
3230 portp = (stliport_t *) stli_memalloc(sizeof(stliport_t)); 3218 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
3231 if (portp == (stliport_t *) NULL) { 3219 if (!portp) {
3232 printk("STALLION: failed to allocate port structure\n"); 3220 printk("STALLION: failed to allocate port structure\n");
3233 continue; 3221 continue;
3234 } 3222 }
3235 3223
3236 memset(portp, 0, sizeof(stliport_t));
3237 portp->magic = STLI_PORTMAGIC; 3224 portp->magic = STLI_PORTMAGIC;
3238 portp->portnr = i; 3225 portp->portnr = i;
3239 portp->brdnr = brdp->brdnr; 3226 portp->brdnr = brdp->brdnr;
@@ -4610,14 +4597,13 @@ static stlibrd_t *stli_allocbrd(void)
4610{ 4597{
4611 stlibrd_t *brdp; 4598 stlibrd_t *brdp;
4612 4599
4613 brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t)); 4600 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
4614 if (brdp == (stlibrd_t *) NULL) { 4601 if (!brdp) {
4615 printk(KERN_ERR "STALLION: failed to allocate memory " 4602 printk(KERN_ERR "STALLION: failed to allocate memory "
4616 "(size=%d)\n", sizeof(stlibrd_t)); 4603 "(size=%d)\n", sizeof(stlibrd_t));
4617 return((stlibrd_t *) NULL); 4604 return NULL;
4618 } 4605 }
4619 4606
4620 memset(brdp, 0, sizeof(stlibrd_t));
4621 brdp->magic = STLI_BOARDMAGIC; 4607 brdp->magic = STLI_BOARDMAGIC;
4622 return(brdp); 4608 return(brdp);
4623} 4609}
@@ -5210,12 +5196,12 @@ int __init stli_init(void)
5210/* 5196/*
5211 * Allocate a temporary write buffer. 5197 * Allocate a temporary write buffer.
5212 */ 5198 */
5213 stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE); 5199 stli_tmpwritebuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
5214 if (stli_tmpwritebuf == (char *) NULL) 5200 if (!stli_tmpwritebuf)
5215 printk(KERN_ERR "STALLION: failed to allocate memory " 5201 printk(KERN_ERR "STALLION: failed to allocate memory "
5216 "(size=%d)\n", STLI_TXBUFSIZE); 5202 "(size=%d)\n", STLI_TXBUFSIZE);
5217 stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE); 5203 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
5218 if (stli_txcookbuf == (char *) NULL) 5204 if (!stli_txcookbuf)
5219 printk(KERN_ERR "STALLION: failed to allocate memory " 5205 printk(KERN_ERR "STALLION: failed to allocate memory "
5220 "(size=%d)\n", STLI_TXBUFSIZE); 5206 "(size=%d)\n", STLI_TXBUFSIZE);
5221 5207
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 8b603b2d1c42..935670a3cd98 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -74,7 +74,7 @@ void compute_shiftstate(void);
74 k_self, k_fn, k_spec, k_pad,\ 74 k_self, k_fn, k_spec, k_pad,\
75 k_dead, k_cons, k_cur, k_shift,\ 75 k_dead, k_cons, k_cur, k_shift,\
76 k_meta, k_ascii, k_lock, k_lowercase,\ 76 k_meta, k_ascii, k_lock, k_lowercase,\
77 k_slock, k_dead2, k_ignore, k_ignore 77 k_slock, k_dead2, k_brl, k_ignore
78 78
79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value, 79typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
80 char up_flag, struct pt_regs *regs); 80 char up_flag, struct pt_regs *regs);
@@ -100,7 +100,7 @@ static fn_handler_fn *fn_handler[] = { FN_HANDLERS };
100const int max_vals[] = { 100const int max_vals[] = {
101 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1, 101 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,
102 NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1, 102 NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
103 255, NR_LOCK - 1, 255 103 255, NR_LOCK - 1, 255, NR_BRL - 1
104}; 104};
105 105
106const int NR_TYPES = ARRAY_SIZE(max_vals); 106const int NR_TYPES = ARRAY_SIZE(max_vals);
@@ -126,7 +126,7 @@ static unsigned long key_down[NBITS(KEY_MAX)]; /* keyboard key bitmap */
126static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ 126static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
127static int dead_key_next; 127static int dead_key_next;
128static int npadch = -1; /* -1 or number assembled on pad */ 128static int npadch = -1; /* -1 or number assembled on pad */
129static unsigned char diacr; 129static unsigned int diacr;
130static char rep; /* flag telling character repeat */ 130static char rep; /* flag telling character repeat */
131 131
132static unsigned char ledstate = 0xff; /* undefined */ 132static unsigned char ledstate = 0xff; /* undefined */
@@ -394,22 +394,30 @@ void compute_shiftstate(void)
394 * Otherwise, conclude that DIACR was not combining after all, 394 * Otherwise, conclude that DIACR was not combining after all,
395 * queue it and return CH. 395 * queue it and return CH.
396 */ 396 */
397static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch) 397static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
398{ 398{
399 int d = diacr; 399 unsigned int d = diacr;
400 unsigned int i; 400 unsigned int i;
401 401
402 diacr = 0; 402 diacr = 0;
403 403
404 for (i = 0; i < accent_table_size; i++) { 404 if ((d & ~0xff) == BRL_UC_ROW) {
405 if (accent_table[i].diacr == d && accent_table[i].base == ch) 405 if ((ch & ~0xff) == BRL_UC_ROW)
406 return accent_table[i].result; 406 return d | ch;
407 } else {
408 for (i = 0; i < accent_table_size; i++)
409 if (accent_table[i].diacr == d && accent_table[i].base == ch)
410 return accent_table[i].result;
407 } 411 }
408 412
409 if (ch == ' ' || ch == d) 413 if (ch == ' ' || ch == (BRL_UC_ROW|0) || ch == d)
410 return d; 414 return d;
411 415
412 put_queue(vc, d); 416 if (kbd->kbdmode == VC_UNICODE)
417 to_utf8(vc, d);
418 else if (d < 0x100)
419 put_queue(vc, d);
420
413 return ch; 421 return ch;
414} 422}
415 423
@@ -419,7 +427,10 @@ static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
419static void fn_enter(struct vc_data *vc, struct pt_regs *regs) 427static void fn_enter(struct vc_data *vc, struct pt_regs *regs)
420{ 428{
421 if (diacr) { 429 if (diacr) {
422 put_queue(vc, diacr); 430 if (kbd->kbdmode == VC_UNICODE)
431 to_utf8(vc, diacr);
432 else if (diacr < 0x100)
433 put_queue(vc, diacr);
423 diacr = 0; 434 diacr = 0;
424 } 435 }
425 put_queue(vc, 13); 436 put_queue(vc, 13);
@@ -615,7 +626,7 @@ static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag, s
615 printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n"); 626 printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n");
616} 627}
617 628
618static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 629static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs)
619{ 630{
620 if (up_flag) 631 if (up_flag)
621 return; /* no action, if this is a key release */ 632 return; /* no action, if this is a key release */
@@ -628,7 +639,10 @@ static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct
628 diacr = value; 639 diacr = value;
629 return; 640 return;
630 } 641 }
631 put_queue(vc, value); 642 if (kbd->kbdmode == VC_UNICODE)
643 to_utf8(vc, value);
644 else if (value < 0x100)
645 put_queue(vc, value);
632} 646}
633 647
634/* 648/*
@@ -636,13 +650,23 @@ static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct
636 * dead keys modifying the same character. Very useful 650 * dead keys modifying the same character. Very useful
637 * for Vietnamese. 651 * for Vietnamese.
638 */ 652 */
639static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 653static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs)
640{ 654{
641 if (up_flag) 655 if (up_flag)
642 return; 656 return;
643 diacr = (diacr ? handle_diacr(vc, value) : value); 657 diacr = (diacr ? handle_diacr(vc, value) : value);
644} 658}
645 659
660static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
661{
662 k_unicode(vc, value, up_flag, regs);
663}
664
665static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
666{
667 k_deadunicode(vc, value, up_flag, regs);
668}
669
646/* 670/*
647 * Obsolete - for backwards compatibility only 671 * Obsolete - for backwards compatibility only
648 */ 672 */
@@ -650,7 +674,7 @@ static void k_dead(struct vc_data *vc, unsigned char value, char up_flag, struct
650{ 674{
651 static unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; 675 static unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
652 value = ret_diacr[value]; 676 value = ret_diacr[value];
653 k_dead2(vc, value, up_flag, regs); 677 k_deadunicode(vc, value, up_flag, regs);
654} 678}
655 679
656static void k_cons(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs) 680static void k_cons(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
@@ -835,6 +859,62 @@ static void k_slock(struct vc_data *vc, unsigned char value, char up_flag, struc
835 } 859 }
836} 860}
837 861
862/* by default, 300ms interval for combination release */
863static long brl_timeout = 300;
864MODULE_PARM_DESC(brl_timeout, "Braille keys release delay in ms (0 for combination on first release, < 0 for dead characters)");
865module_param(brl_timeout, long, 0644);
866static void k_brl(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
867{
868 static unsigned pressed,committing;
869 static unsigned long releasestart;
870
871 if (kbd->kbdmode != VC_UNICODE) {
872 if (!up_flag)
873 printk("keyboard mode must be unicode for braille patterns\n");
874 return;
875 }
876
877 if (!value) {
878 k_unicode(vc, BRL_UC_ROW, up_flag, regs);
879 return;
880 }
881
882 if (value > 8)
883 return;
884
885 if (brl_timeout < 0) {
886 k_deadunicode(vc, BRL_UC_ROW | (1 << (value - 1)), up_flag, regs);
887 return;
888 }
889
890 if (up_flag) {
891 if (brl_timeout) {
892 if (!committing ||
893 jiffies - releasestart > (brl_timeout * HZ) / 1000) {
894 committing = pressed;
895 releasestart = jiffies;
896 }
897 pressed &= ~(1 << (value - 1));
898 if (!pressed) {
899 if (committing) {
900 k_unicode(vc, BRL_UC_ROW | committing, 0, regs);
901 committing = 0;
902 }
903 }
904 } else {
905 if (committing) {
906 k_unicode(vc, BRL_UC_ROW | committing, 0, regs);
907 committing = 0;
908 }
909 pressed &= ~(1 << (value - 1));
910 }
911 } else {
912 pressed |= 1 << (value - 1);
913 if (!brl_timeout)
914 committing = pressed;
915 }
916}
917
838/* 918/*
839 * The leds display either (i) the status of NumLock, CapsLock, ScrollLock, 919 * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
840 * or (ii) whatever pattern of lights people want to show using KDSETLED, 920 * or (ii) whatever pattern of lights people want to show using KDSETLED,
@@ -1125,9 +1205,13 @@ static void kbd_keycode(unsigned int keycode, int down,
1125 } 1205 }
1126 1206
1127 if (keycode > NR_KEYS) 1207 if (keycode > NR_KEYS)
1128 return; 1208 if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8)
1209 keysym = K(KT_BRL, keycode - KEY_BRL_DOT1 + 1);
1210 else
1211 return;
1212 else
1213 keysym = key_map[keycode];
1129 1214
1130 keysym = key_map[keycode];
1131 type = KTYP(keysym); 1215 type = KTYP(keysym);
1132 1216
1133 if (type < 0xf0) { 1217 if (type < 0xf0) {
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 5fdf18515433..02114a0bd0d9 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -46,7 +46,7 @@
46/* #define ATR_CSUM */ 46/* #define ATR_CSUM */
47 47
48#ifdef PCMCIA_DEBUG 48#ifdef PCMCIA_DEBUG
49#define reader_to_dev(x) (&handle_to_dev(x->link.handle)) 49#define reader_to_dev(x) (&handle_to_dev(x->p_dev->handle))
50static int pc_debug = PCMCIA_DEBUG; 50static int pc_debug = PCMCIA_DEBUG;
51module_param(pc_debug, int, 0600); 51module_param(pc_debug, int, 0600);
52#define DEBUGP(n, rdr, x, args...) do { \ 52#define DEBUGP(n, rdr, x, args...) do { \
@@ -67,7 +67,7 @@ static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte";
67#define T_100MSEC msecs_to_jiffies(100) 67#define T_100MSEC msecs_to_jiffies(100)
68#define T_500MSEC msecs_to_jiffies(500) 68#define T_500MSEC msecs_to_jiffies(500)
69 69
70static void cm4000_release(dev_link_t *link); 70static void cm4000_release(struct pcmcia_device *link);
71 71
72static int major; /* major number we get from the kernel */ 72static int major; /* major number we get from the kernel */
73 73
@@ -106,7 +106,7 @@ static int major; /* major number we get from the kernel */
106#define REG_STOPBITS(x) (x + 7) 106#define REG_STOPBITS(x) (x + 7)
107 107
108struct cm4000_dev { 108struct cm4000_dev {
109 dev_link_t link; /* pcmcia link */ 109 struct pcmcia_device *p_dev;
110 dev_node_t node; /* OS node (major,minor) */ 110 dev_node_t node; /* OS node (major,minor) */
111 111
112 unsigned char atr[MAX_ATR]; 112 unsigned char atr[MAX_ATR];
@@ -149,14 +149,14 @@ struct cm4000_dev {
149#define ZERO_DEV(dev) \ 149#define ZERO_DEV(dev) \
150 memset(&dev->atr_csum,0, \ 150 memset(&dev->atr_csum,0, \
151 sizeof(struct cm4000_dev) - \ 151 sizeof(struct cm4000_dev) - \
152 /*link*/ sizeof(dev_link_t) - \ 152 /*link*/ sizeof(struct pcmcia_device) - \
153 /*node*/ sizeof(dev_node_t) - \ 153 /*node*/ sizeof(dev_node_t) - \
154 /*atr*/ MAX_ATR*sizeof(char) - \ 154 /*atr*/ MAX_ATR*sizeof(char) - \
155 /*rbuf*/ 512*sizeof(char) - \ 155 /*rbuf*/ 512*sizeof(char) - \
156 /*sbuf*/ 512*sizeof(char) - \ 156 /*sbuf*/ 512*sizeof(char) - \
157 /*queue*/ 4*sizeof(wait_queue_head_t)) 157 /*queue*/ 4*sizeof(wait_queue_head_t))
158 158
159static dev_link_t *dev_table[CM4000_MAX_DEV]; 159static struct pcmcia_device *dev_table[CM4000_MAX_DEV];
160static struct class *cmm_class; 160static struct class *cmm_class;
161 161
162/* This table doesn't use spaces after the comma between fields and thus 162/* This table doesn't use spaces after the comma between fields and thus
@@ -454,7 +454,7 @@ static struct card_fixup card_fixups[] = {
454static void set_cardparameter(struct cm4000_dev *dev) 454static void set_cardparameter(struct cm4000_dev *dev)
455{ 455{
456 int i; 456 int i;
457 ioaddr_t iobase = dev->link.io.BasePort1; 457 ioaddr_t iobase = dev->p_dev->io.BasePort1;
458 u_int8_t stopbits = 0x02; /* ISO default */ 458 u_int8_t stopbits = 0x02; /* ISO default */
459 459
460 DEBUGP(3, dev, "-> set_cardparameter\n"); 460 DEBUGP(3, dev, "-> set_cardparameter\n");
@@ -487,7 +487,7 @@ static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq)
487 unsigned short num_bytes_read; 487 unsigned short num_bytes_read;
488 unsigned char pts_reply[4]; 488 unsigned char pts_reply[4];
489 ssize_t rc; 489 ssize_t rc;
490 ioaddr_t iobase = dev->link.io.BasePort1; 490 ioaddr_t iobase = dev->p_dev->io.BasePort1;
491 491
492 rc = 0; 492 rc = 0;
493 493
@@ -699,7 +699,7 @@ static void terminate_monitor(struct cm4000_dev *dev)
699static void monitor_card(unsigned long p) 699static void monitor_card(unsigned long p)
700{ 700{
701 struct cm4000_dev *dev = (struct cm4000_dev *) p; 701 struct cm4000_dev *dev = (struct cm4000_dev *) p;
702 ioaddr_t iobase = dev->link.io.BasePort1; 702 ioaddr_t iobase = dev->p_dev->io.BasePort1;
703 unsigned short s; 703 unsigned short s;
704 struct ptsreq ptsreq; 704 struct ptsreq ptsreq;
705 int i, atrc; 705 int i, atrc;
@@ -962,7 +962,7 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
962 loff_t *ppos) 962 loff_t *ppos)
963{ 963{
964 struct cm4000_dev *dev = filp->private_data; 964 struct cm4000_dev *dev = filp->private_data;
965 ioaddr_t iobase = dev->link.io.BasePort1; 965 ioaddr_t iobase = dev->p_dev->io.BasePort1;
966 ssize_t rc; 966 ssize_t rc;
967 int i, j, k; 967 int i, j, k;
968 968
@@ -971,7 +971,7 @@ static ssize_t cmm_read(struct file *filp, __user char *buf, size_t count,
971 if (count == 0) /* according to manpage */ 971 if (count == 0) /* according to manpage */
972 return 0; 972 return 0;
973 973
974 if ((dev->link.state & DEV_PRESENT) == 0 || /* socket removed */ 974 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */
975 test_bit(IS_CMM_ABSENT, &dev->flags)) 975 test_bit(IS_CMM_ABSENT, &dev->flags))
976 return -ENODEV; 976 return -ENODEV;
977 977
@@ -1083,7 +1083,7 @@ static ssize_t cmm_write(struct file *filp, const char __user *buf,
1083 size_t count, loff_t *ppos) 1083 size_t count, loff_t *ppos)
1084{ 1084{
1085 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data; 1085 struct cm4000_dev *dev = (struct cm4000_dev *) filp->private_data;
1086 ioaddr_t iobase = dev->link.io.BasePort1; 1086 ioaddr_t iobase = dev->p_dev->io.BasePort1;
1087 unsigned short s; 1087 unsigned short s;
1088 unsigned char tmp; 1088 unsigned char tmp;
1089 unsigned char infolen; 1089 unsigned char infolen;
@@ -1108,7 +1108,7 @@ static ssize_t cmm_write(struct file *filp, const char __user *buf,
1108 1108
1109 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0; 1109 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0;
1110 1110
1111 if ((dev->link.state & DEV_PRESENT) == 0 || /* socket removed */ 1111 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */
1112 test_bit(IS_CMM_ABSENT, &dev->flags)) 1112 test_bit(IS_CMM_ABSENT, &dev->flags))
1113 return -ENODEV; 1113 return -ENODEV;
1114 1114
@@ -1440,8 +1440,8 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1440 unsigned long arg) 1440 unsigned long arg)
1441{ 1441{
1442 struct cm4000_dev *dev = filp->private_data; 1442 struct cm4000_dev *dev = filp->private_data;
1443 ioaddr_t iobase = dev->link.io.BasePort1; 1443 ioaddr_t iobase = dev->p_dev->io.BasePort1;
1444 dev_link_t *link; 1444 struct pcmcia_device *link;
1445 int size; 1445 int size;
1446 int rc; 1446 int rc;
1447 void __user *argp = (void __user *)arg; 1447 void __user *argp = (void __user *)arg;
@@ -1458,7 +1458,7 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1458 iminor(inode), ioctl_names[_IOC_NR(cmd)]); 1458 iminor(inode), ioctl_names[_IOC_NR(cmd)]);
1459 1459
1460 link = dev_table[iminor(inode)]; 1460 link = dev_table[iminor(inode)];
1461 if (!(DEV_OK(link))) { 1461 if (!pcmcia_dev_present(link)) {
1462 DEBUGP(4, dev, "DEV_OK false\n"); 1462 DEBUGP(4, dev, "DEV_OK false\n");
1463 return -ENODEV; 1463 return -ENODEV;
1464 } 1464 }
@@ -1660,14 +1660,14 @@ static int cmm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1660static int cmm_open(struct inode *inode, struct file *filp) 1660static int cmm_open(struct inode *inode, struct file *filp)
1661{ 1661{
1662 struct cm4000_dev *dev; 1662 struct cm4000_dev *dev;
1663 dev_link_t *link; 1663 struct pcmcia_device *link;
1664 int rc, minor = iminor(inode); 1664 int rc, minor = iminor(inode);
1665 1665
1666 if (minor >= CM4000_MAX_DEV) 1666 if (minor >= CM4000_MAX_DEV)
1667 return -ENODEV; 1667 return -ENODEV;
1668 1668
1669 link = dev_table[minor]; 1669 link = dev_table[minor];
1670 if (link == NULL || !(DEV_OK(link))) 1670 if (link == NULL || !pcmcia_dev_present(link))
1671 return -ENODEV; 1671 return -ENODEV;
1672 1672
1673 if (link->open) 1673 if (link->open)
@@ -1709,7 +1709,7 @@ static int cmm_open(struct inode *inode, struct file *filp)
1709static int cmm_close(struct inode *inode, struct file *filp) 1709static int cmm_close(struct inode *inode, struct file *filp)
1710{ 1710{
1711 struct cm4000_dev *dev; 1711 struct cm4000_dev *dev;
1712 dev_link_t *link; 1712 struct pcmcia_device *link;
1713 int minor = iminor(inode); 1713 int minor = iminor(inode);
1714 1714
1715 if (minor >= CM4000_MAX_DEV) 1715 if (minor >= CM4000_MAX_DEV)
@@ -1735,7 +1735,7 @@ static int cmm_close(struct inode *inode, struct file *filp)
1735 return 0; 1735 return 0;
1736} 1736}
1737 1737
1738static void cmm_cm4000_release(dev_link_t * link) 1738static void cmm_cm4000_release(struct pcmcia_device * link)
1739{ 1739{
1740 struct cm4000_dev *dev = link->priv; 1740 struct cm4000_dev *dev = link->priv;
1741 1741
@@ -1759,13 +1759,11 @@ static void cmm_cm4000_release(dev_link_t * link)
1759 1759
1760/*==== Interface to PCMCIA Layer =======================================*/ 1760/*==== Interface to PCMCIA Layer =======================================*/
1761 1761
1762static void cm4000_config(dev_link_t * link, int devno) 1762static int cm4000_config(struct pcmcia_device * link, int devno)
1763{ 1763{
1764 client_handle_t handle = link->handle;
1765 struct cm4000_dev *dev; 1764 struct cm4000_dev *dev;
1766 tuple_t tuple; 1765 tuple_t tuple;
1767 cisparse_t parse; 1766 cisparse_t parse;
1768 config_info_t conf;
1769 u_char buf[64]; 1767 u_char buf[64];
1770 int fail_fn, fail_rc; 1768 int fail_fn, fail_rc;
1771 int rc; 1769 int rc;
@@ -1777,41 +1775,34 @@ static void cm4000_config(dev_link_t * link, int devno)
1777 tuple.TupleDataMax = sizeof(buf); 1775 tuple.TupleDataMax = sizeof(buf);
1778 tuple.TupleOffset = 0; 1776 tuple.TupleOffset = 0;
1779 1777
1780 if ((fail_rc = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) { 1778 if ((fail_rc = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) {
1781 fail_fn = GetFirstTuple; 1779 fail_fn = GetFirstTuple;
1782 goto cs_failed; 1780 goto cs_failed;
1783 } 1781 }
1784 if ((fail_rc = pcmcia_get_tuple_data(handle, &tuple)) != CS_SUCCESS) { 1782 if ((fail_rc = pcmcia_get_tuple_data(link, &tuple)) != CS_SUCCESS) {
1785 fail_fn = GetTupleData; 1783 fail_fn = GetTupleData;
1786 goto cs_failed; 1784 goto cs_failed;
1787 } 1785 }
1788 if ((fail_rc = 1786 if ((fail_rc =
1789 pcmcia_parse_tuple(handle, &tuple, &parse)) != CS_SUCCESS) { 1787 pcmcia_parse_tuple(link, &tuple, &parse)) != CS_SUCCESS) {
1790 fail_fn = ParseTuple; 1788 fail_fn = ParseTuple;
1791 goto cs_failed; 1789 goto cs_failed;
1792 } 1790 }
1793 if ((fail_rc =
1794 pcmcia_get_configuration_info(handle, &conf)) != CS_SUCCESS) {
1795 fail_fn = GetConfigurationInfo;
1796 goto cs_failed;
1797 }
1798 1791
1799 link->state |= DEV_CONFIG;
1800 link->conf.ConfigBase = parse.config.base; 1792 link->conf.ConfigBase = parse.config.base;
1801 link->conf.Present = parse.config.rmask[0]; 1793 link->conf.Present = parse.config.rmask[0];
1802 link->conf.Vcc = conf.Vcc;
1803 1794
1804 link->io.BasePort2 = 0; 1795 link->io.BasePort2 = 0;
1805 link->io.NumPorts2 = 0; 1796 link->io.NumPorts2 = 0;
1806 link->io.Attributes2 = 0; 1797 link->io.Attributes2 = 0;
1807 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 1798 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1808 for (rc = pcmcia_get_first_tuple(handle, &tuple); 1799 for (rc = pcmcia_get_first_tuple(link, &tuple);
1809 rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(handle, &tuple)) { 1800 rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(link, &tuple)) {
1810 1801
1811 rc = pcmcia_get_tuple_data(handle, &tuple); 1802 rc = pcmcia_get_tuple_data(link, &tuple);
1812 if (rc != CS_SUCCESS) 1803 if (rc != CS_SUCCESS)
1813 continue; 1804 continue;
1814 rc = pcmcia_parse_tuple(handle, &tuple, &parse); 1805 rc = pcmcia_parse_tuple(link, &tuple, &parse);
1815 if (rc != CS_SUCCESS) 1806 if (rc != CS_SUCCESS)
1816 continue; 1807 continue;
1817 1808
@@ -1831,7 +1822,7 @@ static void cm4000_config(dev_link_t * link, int devno)
1831 link->io.IOAddrLines = parse.cftable_entry.io.flags 1822 link->io.IOAddrLines = parse.cftable_entry.io.flags
1832 & CISTPL_IO_LINES_MASK; 1823 & CISTPL_IO_LINES_MASK;
1833 1824
1834 rc = pcmcia_request_io(handle, &link->io); 1825 rc = pcmcia_request_io(link, &link->io);
1835 if (rc == CS_SUCCESS) 1826 if (rc == CS_SUCCESS)
1836 break; /* we are done */ 1827 break; /* we are done */
1837 } 1828 }
@@ -1841,7 +1832,7 @@ static void cm4000_config(dev_link_t * link, int devno)
1841 link->conf.IntType = 00000002; 1832 link->conf.IntType = 00000002;
1842 1833
1843 if ((fail_rc = 1834 if ((fail_rc =
1844 pcmcia_request_configuration(handle, &link->conf)) != CS_SUCCESS) { 1835 pcmcia_request_configuration(link, &link->conf)) != CS_SUCCESS) {
1845 fail_fn = RequestConfiguration; 1836 fail_fn = RequestConfiguration;
1846 goto cs_release; 1837 goto cs_release;
1847 } 1838 }
@@ -1851,63 +1842,48 @@ static void cm4000_config(dev_link_t * link, int devno)
1851 dev->node.major = major; 1842 dev->node.major = major;
1852 dev->node.minor = devno; 1843 dev->node.minor = devno;
1853 dev->node.next = NULL; 1844 dev->node.next = NULL;
1854 link->dev = &dev->node; 1845 link->dev_node = &dev->node;
1855 link->state &= ~DEV_CONFIG_PENDING;
1856 1846
1857 return; 1847 return 0;
1858 1848
1859cs_failed: 1849cs_failed:
1860 cs_error(handle, fail_fn, fail_rc); 1850 cs_error(link, fail_fn, fail_rc);
1861cs_release: 1851cs_release:
1862 cm4000_release(link); 1852 cm4000_release(link);
1863 1853 return -ENODEV;
1864 link->state &= ~DEV_CONFIG_PENDING;
1865} 1854}
1866 1855
1867static int cm4000_suspend(struct pcmcia_device *p_dev) 1856static int cm4000_suspend(struct pcmcia_device *link)
1868{ 1857{
1869 dev_link_t *link = dev_to_instance(p_dev);
1870 struct cm4000_dev *dev; 1858 struct cm4000_dev *dev;
1871 1859
1872 dev = link->priv; 1860 dev = link->priv;
1873
1874 link->state |= DEV_SUSPEND;
1875 if (link->state & DEV_CONFIG)
1876 pcmcia_release_configuration(link->handle);
1877 stop_monitor(dev); 1861 stop_monitor(dev);
1878 1862
1879 return 0; 1863 return 0;
1880} 1864}
1881 1865
1882static int cm4000_resume(struct pcmcia_device *p_dev) 1866static int cm4000_resume(struct pcmcia_device *link)
1883{ 1867{
1884 dev_link_t *link = dev_to_instance(p_dev);
1885 struct cm4000_dev *dev; 1868 struct cm4000_dev *dev;
1886 1869
1887 dev = link->priv; 1870 dev = link->priv;
1888
1889 link->state &= ~DEV_SUSPEND;
1890 if (link->state & DEV_CONFIG)
1891 pcmcia_request_configuration(link->handle, &link->conf);
1892
1893 if (link->open) 1871 if (link->open)
1894 start_monitor(dev); 1872 start_monitor(dev);
1895 1873
1896 return 0; 1874 return 0;
1897} 1875}
1898 1876
1899static void cm4000_release(dev_link_t *link) 1877static void cm4000_release(struct pcmcia_device *link)
1900{ 1878{
1901 cmm_cm4000_release(link->priv); /* delay release until device closed */ 1879 cmm_cm4000_release(link->priv); /* delay release until device closed */
1902 pcmcia_release_configuration(link->handle); 1880 pcmcia_disable_device(link);
1903 pcmcia_release_io(link->handle, &link->io);
1904} 1881}
1905 1882
1906static int cm4000_attach(struct pcmcia_device *p_dev) 1883static int cm4000_probe(struct pcmcia_device *link)
1907{ 1884{
1908 struct cm4000_dev *dev; 1885 struct cm4000_dev *dev;
1909 dev_link_t *link; 1886 int i, ret;
1910 int i;
1911 1887
1912 for (i = 0; i < CM4000_MAX_DEV; i++) 1888 for (i = 0; i < CM4000_MAX_DEV; i++)
1913 if (dev_table[i] == NULL) 1889 if (dev_table[i] == NULL)
@@ -1923,7 +1899,7 @@ static int cm4000_attach(struct pcmcia_device *p_dev)
1923 if (dev == NULL) 1899 if (dev == NULL)
1924 return -ENOMEM; 1900 return -ENOMEM;
1925 1901
1926 link = &dev->link; 1902 dev->p_dev = link;
1927 link->priv = dev; 1903 link->priv = dev;
1928 link->conf.IntType = INT_MEMORY_AND_IO; 1904 link->conf.IntType = INT_MEMORY_AND_IO;
1929 dev_table[i] = link; 1905 dev_table[i] = link;
@@ -1933,11 +1909,9 @@ static int cm4000_attach(struct pcmcia_device *p_dev)
1933 init_waitqueue_head(&dev->atrq); 1909 init_waitqueue_head(&dev->atrq);
1934 init_waitqueue_head(&dev->readq); 1910 init_waitqueue_head(&dev->readq);
1935 1911
1936 link->handle = p_dev; 1912 ret = cm4000_config(link, i);
1937 p_dev->instance = link; 1913 if (ret)
1938 1914 return ret;
1939 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1940 cm4000_config(link, i);
1941 1915
1942 class_device_create(cmm_class, NULL, MKDEV(major, i), NULL, 1916 class_device_create(cmm_class, NULL, MKDEV(major, i), NULL,
1943 "cmm%d", i); 1917 "cmm%d", i);
@@ -1945,9 +1919,8 @@ static int cm4000_attach(struct pcmcia_device *p_dev)
1945 return 0; 1919 return 0;
1946} 1920}
1947 1921
1948static void cm4000_detach(struct pcmcia_device *p_dev) 1922static void cm4000_detach(struct pcmcia_device *link)
1949{ 1923{
1950 dev_link_t *link = dev_to_instance(p_dev);
1951 struct cm4000_dev *dev = link->priv; 1924 struct cm4000_dev *dev = link->priv;
1952 int devno; 1925 int devno;
1953 1926
@@ -1958,11 +1931,9 @@ static void cm4000_detach(struct pcmcia_device *p_dev)
1958 if (devno == CM4000_MAX_DEV) 1931 if (devno == CM4000_MAX_DEV)
1959 return; 1932 return;
1960 1933
1961 link->state &= ~DEV_PRESENT;
1962 stop_monitor(dev); 1934 stop_monitor(dev);
1963 1935
1964 if (link->state & DEV_CONFIG) 1936 cm4000_release(link);
1965 cm4000_release(link);
1966 1937
1967 dev_table[devno] = NULL; 1938 dev_table[devno] = NULL;
1968 kfree(dev); 1939 kfree(dev);
@@ -1993,7 +1964,7 @@ static struct pcmcia_driver cm4000_driver = {
1993 .drv = { 1964 .drv = {
1994 .name = "cm4000_cs", 1965 .name = "cm4000_cs",
1995 }, 1966 },
1996 .probe = cm4000_attach, 1967 .probe = cm4000_probe,
1997 .remove = cm4000_detach, 1968 .remove = cm4000_detach,
1998 .suspend = cm4000_suspend, 1969 .suspend = cm4000_suspend,
1999 .resume = cm4000_resume, 1970 .resume = cm4000_resume,
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 466e33bab029..29efa64580a8 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -41,7 +41,7 @@
41 41
42 42
43#ifdef PCMCIA_DEBUG 43#ifdef PCMCIA_DEBUG
44#define reader_to_dev(x) (&handle_to_dev(x->link.handle)) 44#define reader_to_dev(x) (&handle_to_dev(x->p_dev->handle))
45static int pc_debug = PCMCIA_DEBUG; 45static int pc_debug = PCMCIA_DEBUG;
46module_param(pc_debug, int, 0600); 46module_param(pc_debug, int, 0600);
47#define DEBUGP(n, rdr, x, args...) do { \ 47#define DEBUGP(n, rdr, x, args...) do { \
@@ -65,7 +65,7 @@ static char *version =
65/* how often to poll for fifo status change */ 65/* how often to poll for fifo status change */
66#define POLL_PERIOD msecs_to_jiffies(10) 66#define POLL_PERIOD msecs_to_jiffies(10)
67 67
68static void reader_release(dev_link_t *link); 68static void reader_release(struct pcmcia_device *link);
69 69
70static int major; 70static int major;
71static struct class *cmx_class; 71static struct class *cmx_class;
@@ -74,7 +74,7 @@ static struct class *cmx_class;
74#define BS_WRITABLE 0x02 74#define BS_WRITABLE 0x02
75 75
76struct reader_dev { 76struct reader_dev {
77 dev_link_t link; 77 struct pcmcia_device *p_dev;
78 dev_node_t node; 78 dev_node_t node;
79 wait_queue_head_t devq; 79 wait_queue_head_t devq;
80 wait_queue_head_t poll_wait; 80 wait_queue_head_t poll_wait;
@@ -87,7 +87,7 @@ struct reader_dev {
87 struct timer_list poll_timer; 87 struct timer_list poll_timer;
88}; 88};
89 89
90static dev_link_t *dev_table[CM_MAX_DEV]; 90static struct pcmcia_device *dev_table[CM_MAX_DEV];
91 91
92#ifndef PCMCIA_DEBUG 92#ifndef PCMCIA_DEBUG
93#define xoutb outb 93#define xoutb outb
@@ -116,7 +116,7 @@ static inline unsigned char xinb(unsigned short port)
116static void cm4040_do_poll(unsigned long dummy) 116static void cm4040_do_poll(unsigned long dummy)
117{ 117{
118 struct reader_dev *dev = (struct reader_dev *) dummy; 118 struct reader_dev *dev = (struct reader_dev *) dummy;
119 unsigned int obs = xinb(dev->link.io.BasePort1 119 unsigned int obs = xinb(dev->p_dev->io.BasePort1
120 + REG_OFFSET_BUFFER_STATUS); 120 + REG_OFFSET_BUFFER_STATUS);
121 121
122 if ((obs & BSR_BULK_IN_FULL)) { 122 if ((obs & BSR_BULK_IN_FULL)) {
@@ -147,7 +147,7 @@ static void cm4040_stop_poll(struct reader_dev *dev)
147static int wait_for_bulk_out_ready(struct reader_dev *dev) 147static int wait_for_bulk_out_ready(struct reader_dev *dev)
148{ 148{
149 int i, rc; 149 int i, rc;
150 int iobase = dev->link.io.BasePort1; 150 int iobase = dev->p_dev->io.BasePort1;
151 151
152 for (i = 0; i < POLL_LOOP_COUNT; i++) { 152 for (i = 0; i < POLL_LOOP_COUNT; i++) {
153 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS) 153 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
@@ -177,7 +177,7 @@ static int wait_for_bulk_out_ready(struct reader_dev *dev)
177/* Write to Sync Control Register */ 177/* Write to Sync Control Register */
178static int write_sync_reg(unsigned char val, struct reader_dev *dev) 178static int write_sync_reg(unsigned char val, struct reader_dev *dev)
179{ 179{
180 int iobase = dev->link.io.BasePort1; 180 int iobase = dev->p_dev->io.BasePort1;
181 int rc; 181 int rc;
182 182
183 rc = wait_for_bulk_out_ready(dev); 183 rc = wait_for_bulk_out_ready(dev);
@@ -195,7 +195,7 @@ static int write_sync_reg(unsigned char val, struct reader_dev *dev)
195static int wait_for_bulk_in_ready(struct reader_dev *dev) 195static int wait_for_bulk_in_ready(struct reader_dev *dev)
196{ 196{
197 int i, rc; 197 int i, rc;
198 int iobase = dev->link.io.BasePort1; 198 int iobase = dev->p_dev->io.BasePort1;
199 199
200 for (i = 0; i < POLL_LOOP_COUNT; i++) { 200 for (i = 0; i < POLL_LOOP_COUNT; i++) {
201 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS) 201 if ((xinb(iobase + REG_OFFSET_BUFFER_STATUS)
@@ -225,7 +225,7 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
225 size_t count, loff_t *ppos) 225 size_t count, loff_t *ppos)
226{ 226{
227 struct reader_dev *dev = filp->private_data; 227 struct reader_dev *dev = filp->private_data;
228 int iobase = dev->link.io.BasePort1; 228 int iobase = dev->p_dev->io.BasePort1;
229 size_t bytes_to_read; 229 size_t bytes_to_read;
230 unsigned long i; 230 unsigned long i;
231 size_t min_bytes_to_read; 231 size_t min_bytes_to_read;
@@ -246,7 +246,7 @@ static ssize_t cm4040_read(struct file *filp, char __user *buf,
246 return -EAGAIN; 246 return -EAGAIN;
247 } 247 }
248 248
249 if ((dev->link.state & DEV_PRESENT)==0) 249 if (!pcmcia_dev_present(dev->p_dev))
250 return -ENODEV; 250 return -ENODEV;
251 251
252 for (i = 0; i < 5; i++) { 252 for (i = 0; i < 5; i++) {
@@ -328,7 +328,7 @@ static ssize_t cm4040_write(struct file *filp, const char __user *buf,
328 size_t count, loff_t *ppos) 328 size_t count, loff_t *ppos)
329{ 329{
330 struct reader_dev *dev = filp->private_data; 330 struct reader_dev *dev = filp->private_data;
331 int iobase = dev->link.io.BasePort1; 331 int iobase = dev->p_dev->io.BasePort1;
332 ssize_t rc; 332 ssize_t rc;
333 int i; 333 int i;
334 unsigned int bytes_to_write; 334 unsigned int bytes_to_write;
@@ -351,7 +351,7 @@ static ssize_t cm4040_write(struct file *filp, const char __user *buf,
351 return -EAGAIN; 351 return -EAGAIN;
352 } 352 }
353 353
354 if ((dev->link.state & DEV_PRESENT) == 0) 354 if (!pcmcia_dev_present(dev->p_dev))
355 return -ENODEV; 355 return -ENODEV;
356 356
357 bytes_to_write = count; 357 bytes_to_write = count;
@@ -445,14 +445,14 @@ static unsigned int cm4040_poll(struct file *filp, poll_table *wait)
445static int cm4040_open(struct inode *inode, struct file *filp) 445static int cm4040_open(struct inode *inode, struct file *filp)
446{ 446{
447 struct reader_dev *dev; 447 struct reader_dev *dev;
448 dev_link_t *link; 448 struct pcmcia_device *link;
449 int minor = iminor(inode); 449 int minor = iminor(inode);
450 450
451 if (minor >= CM_MAX_DEV) 451 if (minor >= CM_MAX_DEV)
452 return -ENODEV; 452 return -ENODEV;
453 453
454 link = dev_table[minor]; 454 link = dev_table[minor];
455 if (link == NULL || !(DEV_OK(link))) 455 if (link == NULL || !pcmcia_dev_present(link))
456 return -ENODEV; 456 return -ENODEV;
457 457
458 if (link->open) 458 if (link->open)
@@ -478,7 +478,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)
478static int cm4040_close(struct inode *inode, struct file *filp) 478static int cm4040_close(struct inode *inode, struct file *filp)
479{ 479{
480 struct reader_dev *dev = filp->private_data; 480 struct reader_dev *dev = filp->private_data;
481 dev_link_t *link; 481 struct pcmcia_device *link;
482 int minor = iminor(inode); 482 int minor = iminor(inode);
483 483
484 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode), 484 DEBUGP(2, dev, "-> cm4040_close(maj/min=%d.%d)\n", imajor(inode),
@@ -500,7 +500,7 @@ static int cm4040_close(struct inode *inode, struct file *filp)
500 return 0; 500 return 0;
501} 501}
502 502
503static void cm4040_reader_release(dev_link_t *link) 503static void cm4040_reader_release(struct pcmcia_device *link)
504{ 504{
505 struct reader_dev *dev = link->priv; 505 struct reader_dev *dev = link->priv;
506 506
@@ -514,60 +514,49 @@ static void cm4040_reader_release(dev_link_t *link)
514 return; 514 return;
515} 515}
516 516
517static void reader_config(dev_link_t *link, int devno) 517static int reader_config(struct pcmcia_device *link, int devno)
518{ 518{
519 client_handle_t handle;
520 struct reader_dev *dev; 519 struct reader_dev *dev;
521 tuple_t tuple; 520 tuple_t tuple;
522 cisparse_t parse; 521 cisparse_t parse;
523 config_info_t conf;
524 u_char buf[64]; 522 u_char buf[64];
525 int fail_fn, fail_rc; 523 int fail_fn, fail_rc;
526 int rc; 524 int rc;
527 525
528 handle = link->handle;
529
530 tuple.DesiredTuple = CISTPL_CONFIG; 526 tuple.DesiredTuple = CISTPL_CONFIG;
531 tuple.Attributes = 0; 527 tuple.Attributes = 0;
532 tuple.TupleData = buf; 528 tuple.TupleData = buf;
533 tuple.TupleDataMax = sizeof(buf); 529 tuple.TupleDataMax = sizeof(buf);
534 tuple.TupleOffset = 0; 530 tuple.TupleOffset = 0;
535 531
536 if ((fail_rc = pcmcia_get_first_tuple(handle, &tuple)) != CS_SUCCESS) { 532 if ((fail_rc = pcmcia_get_first_tuple(link, &tuple)) != CS_SUCCESS) {
537 fail_fn = GetFirstTuple; 533 fail_fn = GetFirstTuple;
538 goto cs_failed; 534 goto cs_failed;
539 } 535 }
540 if ((fail_rc = pcmcia_get_tuple_data(handle, &tuple)) != CS_SUCCESS) { 536 if ((fail_rc = pcmcia_get_tuple_data(link, &tuple)) != CS_SUCCESS) {
541 fail_fn = GetTupleData; 537 fail_fn = GetTupleData;
542 goto cs_failed; 538 goto cs_failed;
543 } 539 }
544 if ((fail_rc = pcmcia_parse_tuple(handle, &tuple, &parse)) 540 if ((fail_rc = pcmcia_parse_tuple(link, &tuple, &parse))
545 != CS_SUCCESS) { 541 != CS_SUCCESS) {
546 fail_fn = ParseTuple; 542 fail_fn = ParseTuple;
547 goto cs_failed; 543 goto cs_failed;
548 } 544 }
549 if ((fail_rc = pcmcia_get_configuration_info(handle, &conf))
550 != CS_SUCCESS) {
551 fail_fn = GetConfigurationInfo;
552 goto cs_failed;
553 }
554 545
555 link->state |= DEV_CONFIG;
556 link->conf.ConfigBase = parse.config.base; 546 link->conf.ConfigBase = parse.config.base;
557 link->conf.Present = parse.config.rmask[0]; 547 link->conf.Present = parse.config.rmask[0];
558 link->conf.Vcc = conf.Vcc;
559 548
560 link->io.BasePort2 = 0; 549 link->io.BasePort2 = 0;
561 link->io.NumPorts2 = 0; 550 link->io.NumPorts2 = 0;
562 link->io.Attributes2 = 0; 551 link->io.Attributes2 = 0;
563 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 552 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
564 for (rc = pcmcia_get_first_tuple(handle, &tuple); 553 for (rc = pcmcia_get_first_tuple(link, &tuple);
565 rc == CS_SUCCESS; 554 rc == CS_SUCCESS;
566 rc = pcmcia_get_next_tuple(handle, &tuple)) { 555 rc = pcmcia_get_next_tuple(link, &tuple)) {
567 rc = pcmcia_get_tuple_data(handle, &tuple); 556 rc = pcmcia_get_tuple_data(link, &tuple);
568 if (rc != CS_SUCCESS) 557 if (rc != CS_SUCCESS)
569 continue; 558 continue;
570 rc = pcmcia_parse_tuple(handle, &tuple, &parse); 559 rc = pcmcia_parse_tuple(link, &tuple, &parse);
571 if (rc != CS_SUCCESS) 560 if (rc != CS_SUCCESS)
572 continue; 561 continue;
573 562
@@ -585,13 +574,13 @@ static void reader_config(dev_link_t *link, int devno)
585 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 574 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
586 link->io.IOAddrLines = parse.cftable_entry.io.flags 575 link->io.IOAddrLines = parse.cftable_entry.io.flags
587 & CISTPL_IO_LINES_MASK; 576 & CISTPL_IO_LINES_MASK;
588 rc = pcmcia_request_io(handle, &link->io); 577 rc = pcmcia_request_io(link, &link->io);
589 578
590 dev_printk(KERN_INFO, &handle_to_dev(handle), "foo"); 579 dev_printk(KERN_INFO, &handle_to_dev(link), "foo");
591 if (rc == CS_SUCCESS) 580 if (rc == CS_SUCCESS)
592 break; 581 break;
593 else 582 else
594 dev_printk(KERN_INFO, &handle_to_dev(handle), 583 dev_printk(KERN_INFO, &handle_to_dev(link),
595 "pcmcia_request_io failed 0x%x\n", rc); 584 "pcmcia_request_io failed 0x%x\n", rc);
596 } 585 }
597 if (rc != CS_SUCCESS) 586 if (rc != CS_SUCCESS)
@@ -599,10 +588,10 @@ static void reader_config(dev_link_t *link, int devno)
599 588
600 link->conf.IntType = 00000002; 589 link->conf.IntType = 00000002;
601 590
602 if ((fail_rc = pcmcia_request_configuration(handle,&link->conf)) 591 if ((fail_rc = pcmcia_request_configuration(link,&link->conf))
603 !=CS_SUCCESS) { 592 !=CS_SUCCESS) {
604 fail_fn = RequestConfiguration; 593 fail_fn = RequestConfiguration;
605 dev_printk(KERN_INFO, &handle_to_dev(handle), 594 dev_printk(KERN_INFO, &handle_to_dev(link),
606 "pcmcia_request_configuration failed 0x%x\n", 595 "pcmcia_request_configuration failed 0x%x\n",
607 fail_rc); 596 fail_rc);
608 goto cs_release; 597 goto cs_release;
@@ -612,57 +601,31 @@ static void reader_config(dev_link_t *link, int devno)
612 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno); 601 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
613 dev->node.major = major; 602 dev->node.major = major;
614 dev->node.minor = devno; 603 dev->node.minor = devno;
615 dev->node.next = NULL; 604 dev->node.next = &dev->node;
616 link->dev = &dev->node;
617 link->state &= ~DEV_CONFIG_PENDING;
618 605
619 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno, 606 DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno,
620 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1); 607 link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1);
621 DEBUGP(2, dev, "<- reader_config (succ)\n"); 608 DEBUGP(2, dev, "<- reader_config (succ)\n");
622 609
623 return; 610 return 0;
624 611
625cs_failed: 612cs_failed:
626 cs_error(handle, fail_fn, fail_rc); 613 cs_error(link, fail_fn, fail_rc);
627cs_release: 614cs_release:
628 reader_release(link); 615 reader_release(link);
629 link->state &= ~DEV_CONFIG_PENDING; 616 return -ENODEV;
630}
631
632static int reader_suspend(struct pcmcia_device *p_dev)
633{
634 dev_link_t *link = dev_to_instance(p_dev);
635
636 link->state |= DEV_SUSPEND;
637 if (link->state & DEV_CONFIG)
638 pcmcia_release_configuration(link->handle);
639
640 return 0;
641} 617}
642 618
643static int reader_resume(struct pcmcia_device *p_dev) 619static void reader_release(struct pcmcia_device *link)
644{
645 dev_link_t *link = dev_to_instance(p_dev);
646
647 link->state &= ~DEV_SUSPEND;
648 if (link->state & DEV_CONFIG)
649 pcmcia_request_configuration(link->handle, &link->conf);
650
651 return 0;
652}
653
654static void reader_release(dev_link_t *link)
655{ 620{
656 cm4040_reader_release(link->priv); 621 cm4040_reader_release(link->priv);
657 pcmcia_release_configuration(link->handle); 622 pcmcia_disable_device(link);
658 pcmcia_release_io(link->handle, &link->io);
659} 623}
660 624
661static int reader_attach(struct pcmcia_device *p_dev) 625static int reader_probe(struct pcmcia_device *link)
662{ 626{
663 struct reader_dev *dev; 627 struct reader_dev *dev;
664 dev_link_t *link; 628 int i, ret;
665 int i;
666 629
667 for (i = 0; i < CM_MAX_DEV; i++) { 630 for (i = 0; i < CM_MAX_DEV; i++) {
668 if (dev_table[i] == NULL) 631 if (dev_table[i] == NULL)
@@ -679,8 +642,8 @@ static int reader_attach(struct pcmcia_device *p_dev)
679 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT; 642 dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
680 dev->buffer_status = 0; 643 dev->buffer_status = 0;
681 644
682 link = &dev->link;
683 link->priv = dev; 645 link->priv = dev;
646 dev->p_dev = link;
684 647
685 link->conf.IntType = INT_MEMORY_AND_IO; 648 link->conf.IntType = INT_MEMORY_AND_IO;
686 dev_table[i] = link; 649 dev_table[i] = link;
@@ -692,11 +655,9 @@ static int reader_attach(struct pcmcia_device *p_dev)
692 init_timer(&dev->poll_timer); 655 init_timer(&dev->poll_timer);
693 dev->poll_timer.function = &cm4040_do_poll; 656 dev->poll_timer.function = &cm4040_do_poll;
694 657
695 link->handle = p_dev; 658 ret = reader_config(link, i);
696 p_dev->instance = link; 659 if (ret)
697 660 return ret;
698 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
699 reader_config(link, i);
700 661
701 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL, 662 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL,
702 "cmx%d", i); 663 "cmx%d", i);
@@ -704,9 +665,8 @@ static int reader_attach(struct pcmcia_device *p_dev)
704 return 0; 665 return 0;
705} 666}
706 667
707static void reader_detach(struct pcmcia_device *p_dev) 668static void reader_detach(struct pcmcia_device *link)
708{ 669{
709 dev_link_t *link = dev_to_instance(p_dev);
710 struct reader_dev *dev = link->priv; 670 struct reader_dev *dev = link->priv;
711 int devno; 671 int devno;
712 672
@@ -718,10 +678,7 @@ static void reader_detach(struct pcmcia_device *p_dev)
718 if (devno == CM_MAX_DEV) 678 if (devno == CM_MAX_DEV)
719 return; 679 return;
720 680
721 link->state &= ~DEV_PRESENT; 681 reader_release(link);
722
723 if (link->state & DEV_CONFIG)
724 reader_release(link);
725 682
726 dev_table[devno] = NULL; 683 dev_table[devno] = NULL;
727 kfree(dev); 684 kfree(dev);
@@ -753,10 +710,8 @@ static struct pcmcia_driver reader_driver = {
753 .drv = { 710 .drv = {
754 .name = "cm4040_cs", 711 .name = "cm4040_cs",
755 }, 712 },
756 .probe = reader_attach, 713 .probe = reader_probe,
757 .remove = reader_detach, 714 .remove = reader_detach,
758 .suspend = reader_suspend,
759 .resume = reader_resume,
760 .id_table = cm4040_ids, 715 .id_table = cm4040_ids,
761}; 716};
762 717
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index e6b714b6390d..07213454c458 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -228,7 +228,7 @@ typedef struct _mgslpc_info {
228 struct _input_signal_events input_signal_events; 228 struct _input_signal_events input_signal_events;
229 229
230 /* PCMCIA support */ 230 /* PCMCIA support */
231 dev_link_t link; 231 struct pcmcia_device *p_dev;
232 dev_node_t node; 232 dev_node_t node;
233 int stop; 233 int stop;
234 234
@@ -484,7 +484,7 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
484 484
485/* PCMCIA prototypes */ 485/* PCMCIA prototypes */
486 486
487static void mgslpc_config(dev_link_t *link); 487static int mgslpc_config(struct pcmcia_device *link);
488static void mgslpc_release(u_long arg); 488static void mgslpc_release(u_long arg);
489static void mgslpc_detach(struct pcmcia_device *p_dev); 489static void mgslpc_detach(struct pcmcia_device *p_dev);
490 490
@@ -533,14 +533,14 @@ static void ldisc_receive_buf(struct tty_struct *tty,
533 } 533 }
534} 534}
535 535
536static int mgslpc_attach(struct pcmcia_device *p_dev) 536static int mgslpc_probe(struct pcmcia_device *link)
537{ 537{
538 MGSLPC_INFO *info; 538 MGSLPC_INFO *info;
539 dev_link_t *link; 539 int ret;
540 540
541 if (debug_level >= DEBUG_LEVEL_INFO) 541 if (debug_level >= DEBUG_LEVEL_INFO)
542 printk("mgslpc_attach\n"); 542 printk("mgslpc_attach\n");
543 543
544 info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL); 544 info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
545 if (!info) { 545 if (!info) {
546 printk("Error can't allocate device instance data\n"); 546 printk("Error can't allocate device instance data\n");
@@ -565,25 +565,22 @@ static int mgslpc_attach(struct pcmcia_device *p_dev)
565 info->imrb_value = 0xffff; 565 info->imrb_value = 0xffff;
566 info->pim_value = 0xff; 566 info->pim_value = 0xff;
567 567
568 link = &info->link; 568 info->p_dev = link;
569 link->priv = info; 569 link->priv = info;
570 570
571 /* Initialize the dev_link_t structure */ 571 /* Initialize the struct pcmcia_device structure */
572 572
573 /* Interrupt setup */ 573 /* Interrupt setup */
574 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 574 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
575 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 575 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
576 link->irq.Handler = NULL; 576 link->irq.Handler = NULL;
577 577
578 link->conf.Attributes = 0; 578 link->conf.Attributes = 0;
579 link->conf.Vcc = 50;
580 link->conf.IntType = INT_MEMORY_AND_IO; 579 link->conf.IntType = INT_MEMORY_AND_IO;
581 580
582 link->handle = p_dev; 581 ret = mgslpc_config(link);
583 p_dev->instance = link; 582 if (ret)
584 583 return ret;
585 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
586 mgslpc_config(link);
587 584
588 mgslpc_add_device(info); 585 mgslpc_add_device(info);
589 586
@@ -596,15 +593,13 @@ static int mgslpc_attach(struct pcmcia_device *p_dev)
596#define CS_CHECK(fn, ret) \ 593#define CS_CHECK(fn, ret) \
597do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 594do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
598 595
599static void mgslpc_config(dev_link_t *link) 596static int mgslpc_config(struct pcmcia_device *link)
600{ 597{
601 client_handle_t handle = link->handle;
602 MGSLPC_INFO *info = link->priv; 598 MGSLPC_INFO *info = link->priv;
603 tuple_t tuple; 599 tuple_t tuple;
604 cisparse_t parse; 600 cisparse_t parse;
605 int last_fn, last_ret; 601 int last_fn, last_ret;
606 u_char buf[64]; 602 u_char buf[64];
607 config_info_t conf;
608 cistpl_cftable_entry_t dflt = { 0 }; 603 cistpl_cftable_entry_t dflt = { 0 };
609 cistpl_cftable_entry_t *cfg; 604 cistpl_cftable_entry_t *cfg;
610 605
@@ -617,27 +612,20 @@ static void mgslpc_config(dev_link_t *link)
617 tuple.TupleData = buf; 612 tuple.TupleData = buf;
618 tuple.TupleDataMax = sizeof(buf); 613 tuple.TupleDataMax = sizeof(buf);
619 tuple.TupleOffset = 0; 614 tuple.TupleOffset = 0;
620 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 615 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
621 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 616 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
622 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 617 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
623 link->conf.ConfigBase = parse.config.base; 618 link->conf.ConfigBase = parse.config.base;
624 link->conf.Present = parse.config.rmask[0]; 619 link->conf.Present = parse.config.rmask[0];
625
626 /* Configure card */
627 link->state |= DEV_CONFIG;
628
629 /* Look up the current Vcc */
630 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
631 link->conf.Vcc = conf.Vcc;
632 620
633 /* get CIS configuration entry */ 621 /* get CIS configuration entry */
634 622
635 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 623 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
636 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 624 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
637 625
638 cfg = &(parse.cftable_entry); 626 cfg = &(parse.cftable_entry);
639 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 627 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
640 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 628 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
641 629
642 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 630 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
643 if (cfg->index == 0) 631 if (cfg->index == 0)
@@ -658,11 +646,10 @@ static void mgslpc_config(dev_link_t *link)
658 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; 646 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
659 link->io.BasePort1 = io->win[0].base; 647 link->io.BasePort1 = io->win[0].base;
660 link->io.NumPorts1 = io->win[0].len; 648 link->io.NumPorts1 = io->win[0].len;
661 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io)); 649 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
662 } 650 }
663 651
664 link->conf.Attributes = CONF_ENABLE_IRQ; 652 link->conf.Attributes = CONF_ENABLE_IRQ;
665 link->conf.Vcc = 50;
666 link->conf.IntType = INT_MEMORY_AND_IO; 653 link->conf.IntType = INT_MEMORY_AND_IO;
667 link->conf.ConfigIndex = 8; 654 link->conf.ConfigIndex = 8;
668 link->conf.Present = PRESENT_OPTION; 655 link->conf.Present = PRESENT_OPTION;
@@ -670,9 +657,9 @@ static void mgslpc_config(dev_link_t *link)
670 link->irq.Attributes |= IRQ_HANDLE_PRESENT; 657 link->irq.Attributes |= IRQ_HANDLE_PRESENT;
671 link->irq.Handler = mgslpc_isr; 658 link->irq.Handler = mgslpc_isr;
672 link->irq.Instance = info; 659 link->irq.Instance = info;
673 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 660 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
674 661
675 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 662 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
676 663
677 info->io_base = link->io.BasePort1; 664 info->io_base = link->io.BasePort1;
678 info->irq_level = link->irq.AssignedIRQ; 665 info->irq_level = link->irq.AssignedIRQ;
@@ -680,7 +667,7 @@ static void mgslpc_config(dev_link_t *link)
680 /* add to linked list of devices */ 667 /* add to linked list of devices */
681 sprintf(info->node.dev_name, "mgslpc0"); 668 sprintf(info->node.dev_name, "mgslpc0");
682 info->node.major = info->node.minor = 0; 669 info->node.major = info->node.minor = 0;
683 link->dev = &info->node; 670 link->dev_node = &info->node;
684 671
685 printk(KERN_INFO "%s: index 0x%02x:", 672 printk(KERN_INFO "%s: index 0x%02x:",
686 info->node.dev_name, link->conf.ConfigIndex); 673 info->node.dev_name, link->conf.ConfigIndex);
@@ -690,13 +677,12 @@ static void mgslpc_config(dev_link_t *link)
690 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 677 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
691 link->io.BasePort1+link->io.NumPorts1-1); 678 link->io.BasePort1+link->io.NumPorts1-1);
692 printk("\n"); 679 printk("\n");
693 680 return 0;
694 link->state &= ~DEV_CONFIG_PENDING;
695 return;
696 681
697cs_failed: 682cs_failed:
698 cs_error(link->handle, last_fn, last_ret); 683 cs_error(link, last_fn, last_ret);
699 mgslpc_release((u_long)link); 684 mgslpc_release((u_long)link);
685 return -ENODEV;
700} 686}
701 687
702/* Card has been removed. 688/* Card has been removed.
@@ -705,58 +691,38 @@ cs_failed:
705 */ 691 */
706static void mgslpc_release(u_long arg) 692static void mgslpc_release(u_long arg)
707{ 693{
708 dev_link_t *link = (dev_link_t *)arg; 694 struct pcmcia_device *link = (struct pcmcia_device *)arg;
709 695
710 if (debug_level >= DEBUG_LEVEL_INFO) 696 if (debug_level >= DEBUG_LEVEL_INFO)
711 printk("mgslpc_release(0x%p)\n", link); 697 printk("mgslpc_release(0x%p)\n", link);
712
713 /* Unlink the device chain */
714 link->dev = NULL;
715 link->state &= ~DEV_CONFIG;
716 698
717 pcmcia_release_configuration(link->handle); 699 pcmcia_disable_device(link);
718 if (link->io.NumPorts1)
719 pcmcia_release_io(link->handle, &link->io);
720 if (link->irq.AssignedIRQ)
721 pcmcia_release_irq(link->handle, &link->irq);
722} 700}
723 701
724static void mgslpc_detach(struct pcmcia_device *p_dev) 702static void mgslpc_detach(struct pcmcia_device *link)
725{ 703{
726 dev_link_t *link = dev_to_instance(p_dev); 704 if (debug_level >= DEBUG_LEVEL_INFO)
727 705 printk("mgslpc_detach(0x%p)\n", link);
728 if (debug_level >= DEBUG_LEVEL_INFO)
729 printk("mgslpc_detach(0x%p)\n", link);
730 706
731 if (link->state & DEV_CONFIG) { 707 ((MGSLPC_INFO *)link->priv)->stop = 1;
732 ((MGSLPC_INFO *)link->priv)->stop = 1; 708 mgslpc_release((u_long)link);
733 mgslpc_release((u_long)link);
734 }
735 709
736 mgslpc_remove_device((MGSLPC_INFO *)link->priv); 710 mgslpc_remove_device((MGSLPC_INFO *)link->priv);
737} 711}
738 712
739static int mgslpc_suspend(struct pcmcia_device *dev) 713static int mgslpc_suspend(struct pcmcia_device *link)
740{ 714{
741 dev_link_t *link = dev_to_instance(dev);
742 MGSLPC_INFO *info = link->priv; 715 MGSLPC_INFO *info = link->priv;
743 716
744 link->state |= DEV_SUSPEND;
745 info->stop = 1; 717 info->stop = 1;
746 if (link->state & DEV_CONFIG)
747 pcmcia_release_configuration(link->handle);
748 718
749 return 0; 719 return 0;
750} 720}
751 721
752static int mgslpc_resume(struct pcmcia_device *dev) 722static int mgslpc_resume(struct pcmcia_device *link)
753{ 723{
754 dev_link_t *link = dev_to_instance(dev);
755 MGSLPC_INFO *info = link->priv; 724 MGSLPC_INFO *info = link->priv;
756 725
757 link->state &= ~DEV_SUSPEND;
758 if (link->state & DEV_CONFIG)
759 pcmcia_request_configuration(link->handle, &link->conf);
760 info->stop = 0; 726 info->stop = 0;
761 727
762 return 0; 728 return 0;
@@ -1280,7 +1246,7 @@ static irqreturn_t mgslpc_isr(int irq, void *dev_id, struct pt_regs * regs)
1280 if (!info) 1246 if (!info)
1281 return IRQ_NONE; 1247 return IRQ_NONE;
1282 1248
1283 if (!(info->link.state & DEV_CONFIG)) 1249 if (!(info->p_dev->_locked))
1284 return IRQ_HANDLED; 1250 return IRQ_HANDLED;
1285 1251
1286 spin_lock(&info->lock); 1252 spin_lock(&info->lock);
@@ -3033,7 +2999,7 @@ static struct pcmcia_driver mgslpc_driver = {
3033 .drv = { 2999 .drv = {
3034 .name = "synclink_cs", 3000 .name = "synclink_cs",
3035 }, 3001 },
3036 .probe = mgslpc_attach, 3002 .probe = mgslpc_probe,
3037 .remove = mgslpc_detach, 3003 .remove = mgslpc_detach,
3038 .id_table = mgslpc_ids, 3004 .id_table = mgslpc_ids,
3039 .suspend = mgslpc_suspend, 3005 .suspend = mgslpc_suspend,
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 86be04b241e1..58f3512c52e1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1584,7 +1584,6 @@ u32 secure_ipv6_port_ephemeral(const __u32 *saddr, const __u32 *daddr, __u16 dpo
1584 1584
1585 return twothirdsMD4Transform(daddr, hash); 1585 return twothirdsMD4Transform(daddr, hash);
1586} 1586}
1587EXPORT_SYMBOL(secure_ipv6_port_ephemeral);
1588#endif 1587#endif
1589 1588
1590#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE) 1589#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 3f5d6077f39c..a9c5a7230f89 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -504,7 +504,6 @@ static int stl_echmcaintr(stlbrd_t *brdp);
504static int stl_echpciintr(stlbrd_t *brdp); 504static int stl_echpciintr(stlbrd_t *brdp);
505static int stl_echpci64intr(stlbrd_t *brdp); 505static int stl_echpci64intr(stlbrd_t *brdp);
506static void stl_offintr(void *private); 506static void stl_offintr(void *private);
507static void *stl_memalloc(int len);
508static stlbrd_t *stl_allocbrd(void); 507static stlbrd_t *stl_allocbrd(void);
509static stlport_t *stl_getport(int brdnr, int panelnr, int portnr); 508static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
510 509
@@ -940,17 +939,6 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
940/*****************************************************************************/ 939/*****************************************************************************/
941 940
942/* 941/*
943 * Local driver kernel memory allocation routine.
944 */
945
946static void *stl_memalloc(int len)
947{
948 return (void *) kmalloc(len, GFP_KERNEL);
949}
950
951/*****************************************************************************/
952
953/*
954 * Allocate a new board structure. Fill out the basic info in it. 942 * Allocate a new board structure. Fill out the basic info in it.
955 */ 943 */
956 944
@@ -958,14 +946,13 @@ static stlbrd_t *stl_allocbrd(void)
958{ 946{
959 stlbrd_t *brdp; 947 stlbrd_t *brdp;
960 948
961 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t)); 949 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
962 if (brdp == (stlbrd_t *) NULL) { 950 if (!brdp) {
963 printk("STALLION: failed to allocate memory (size=%d)\n", 951 printk("STALLION: failed to allocate memory (size=%d)\n",
964 sizeof(stlbrd_t)); 952 sizeof(stlbrd_t));
965 return (stlbrd_t *) NULL; 953 return NULL;
966 } 954 }
967 955
968 memset(brdp, 0, sizeof(stlbrd_t));
969 brdp->magic = STL_BOARDMAGIC; 956 brdp->magic = STL_BOARDMAGIC;
970 return brdp; 957 return brdp;
971} 958}
@@ -1017,9 +1004,9 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
1017 portp->refcount++; 1004 portp->refcount++;
1018 1005
1019 if ((portp->flags & ASYNC_INITIALIZED) == 0) { 1006 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1020 if (portp->tx.buf == (char *) NULL) { 1007 if (!portp->tx.buf) {
1021 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE); 1008 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
1022 if (portp->tx.buf == (char *) NULL) 1009 if (!portp->tx.buf)
1023 return -ENOMEM; 1010 return -ENOMEM;
1024 portp->tx.head = portp->tx.buf; 1011 portp->tx.head = portp->tx.buf;
1025 portp->tx.tail = portp->tx.buf; 1012 portp->tx.tail = portp->tx.buf;
@@ -2178,13 +2165,12 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2178 * each ports data structures. 2165 * each ports data structures.
2179 */ 2166 */
2180 for (i = 0; (i < panelp->nrports); i++) { 2167 for (i = 0; (i < panelp->nrports); i++) {
2181 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t)); 2168 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2182 if (portp == (stlport_t *) NULL) { 2169 if (!portp) {
2183 printk("STALLION: failed to allocate memory " 2170 printk("STALLION: failed to allocate memory "
2184 "(size=%d)\n", sizeof(stlport_t)); 2171 "(size=%d)\n", sizeof(stlport_t));
2185 break; 2172 break;
2186 } 2173 }
2187 memset(portp, 0, sizeof(stlport_t));
2188 2174
2189 portp->magic = STL_PORTMAGIC; 2175 portp->magic = STL_PORTMAGIC;
2190 portp->portnr = i; 2176 portp->portnr = i;
@@ -2315,13 +2301,12 @@ static inline int stl_initeio(stlbrd_t *brdp)
2315 * can complete the setup. 2301 * can complete the setup.
2316 */ 2302 */
2317 2303
2318 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t)); 2304 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2319 if (panelp == (stlpanel_t *) NULL) { 2305 if (!panelp) {
2320 printk(KERN_WARNING "STALLION: failed to allocate memory " 2306 printk(KERN_WARNING "STALLION: failed to allocate memory "
2321 "(size=%d)\n", sizeof(stlpanel_t)); 2307 "(size=%d)\n", sizeof(stlpanel_t));
2322 return(-ENOMEM); 2308 return -ENOMEM;
2323 } 2309 }
2324 memset(panelp, 0, sizeof(stlpanel_t));
2325 2310
2326 panelp->magic = STL_PANELMAGIC; 2311 panelp->magic = STL_PANELMAGIC;
2327 panelp->brdnr = brdp->brdnr; 2312 panelp->brdnr = brdp->brdnr;
@@ -2490,13 +2475,12 @@ static inline int stl_initech(stlbrd_t *brdp)
2490 status = inb(ioaddr + ECH_PNLSTATUS); 2475 status = inb(ioaddr + ECH_PNLSTATUS);
2491 if ((status & ECH_PNLIDMASK) != nxtid) 2476 if ((status & ECH_PNLIDMASK) != nxtid)
2492 break; 2477 break;
2493 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t)); 2478 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2494 if (panelp == (stlpanel_t *) NULL) { 2479 if (!panelp) {
2495 printk("STALLION: failed to allocate memory " 2480 printk("STALLION: failed to allocate memory "
2496 "(size=%d)\n", sizeof(stlpanel_t)); 2481 "(size=%d)\n", sizeof(stlpanel_t));
2497 break; 2482 break;
2498 } 2483 }
2499 memset(panelp, 0, sizeof(stlpanel_t));
2500 panelp->magic = STL_PANELMAGIC; 2484 panelp->magic = STL_PANELMAGIC;
2501 panelp->brdnr = brdp->brdnr; 2485 panelp->brdnr = brdp->brdnr;
2502 panelp->panelnr = panelnr; 2486 panelp->panelnr = panelnr;
@@ -3074,8 +3058,8 @@ static int __init stl_init(void)
3074/* 3058/*
3075 * Allocate a temporary write buffer. 3059 * Allocate a temporary write buffer.
3076 */ 3060 */
3077 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE); 3061 stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
3078 if (stl_tmpwritebuf == (char *) NULL) 3062 if (!stl_tmpwritebuf)
3079 printk("STALLION: failed to allocate memory (size=%d)\n", 3063 printk("STALLION: failed to allocate memory (size=%d)\n",
3080 STL_TXBUFSIZE); 3064 STL_TXBUFSIZE);
3081 3065
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 2546637a55c0..f58ad7f68267 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -327,7 +327,7 @@ static ssize_t store_received_ref_clk3a(struct device *d,
327 return strnlen(buf, count); 327 return strnlen(buf, count);
328} 328}
329 329
330static DEVICE_ATTR(received_ref_clk3a, S_IWUGO, NULL, 330static DEVICE_ATTR(received_ref_clk3a, (S_IWUSR|S_IWGRP), NULL,
331 store_received_ref_clk3a); 331 store_received_ref_clk3a);
332 332
333 333
@@ -349,7 +349,7 @@ static ssize_t store_received_ref_clk3b(struct device *d,
349 return strnlen(buf, count); 349 return strnlen(buf, count);
350} 350}
351 351
352static DEVICE_ATTR(received_ref_clk3b, S_IWUGO, NULL, 352static DEVICE_ATTR(received_ref_clk3b, (S_IWUSR|S_IWGRP), NULL,
353 store_received_ref_clk3b); 353 store_received_ref_clk3b);
354 354
355 355
@@ -371,7 +371,7 @@ static ssize_t store_enable_clk3b_output(struct device *d,
371 return strnlen(buf, count); 371 return strnlen(buf, count);
372} 372}
373 373
374static DEVICE_ATTR(enable_clk3b_output, S_IWUGO, NULL, 374static DEVICE_ATTR(enable_clk3b_output, (S_IWUSR|S_IWGRP), NULL,
375 store_enable_clk3b_output); 375 store_enable_clk3b_output);
376 376
377static ssize_t store_enable_clk3a_output(struct device *d, 377static ssize_t store_enable_clk3a_output(struct device *d,
@@ -392,7 +392,7 @@ static ssize_t store_enable_clk3a_output(struct device *d,
392 return strnlen(buf, count); 392 return strnlen(buf, count);
393} 393}
394 394
395static DEVICE_ATTR(enable_clk3a_output, S_IWUGO, NULL, 395static DEVICE_ATTR(enable_clk3a_output, (S_IWUSR|S_IWGRP), NULL,
396 store_enable_clk3a_output); 396 store_enable_clk3a_output);
397 397
398static ssize_t store_enable_clkb1_output(struct device *d, 398static ssize_t store_enable_clkb1_output(struct device *d,
@@ -413,7 +413,7 @@ static ssize_t store_enable_clkb1_output(struct device *d,
413 return strnlen(buf, count); 413 return strnlen(buf, count);
414} 414}
415 415
416static DEVICE_ATTR(enable_clkb1_output, S_IWUGO, NULL, 416static DEVICE_ATTR(enable_clkb1_output, (S_IWUSR|S_IWGRP), NULL,
417 store_enable_clkb1_output); 417 store_enable_clkb1_output);
418 418
419 419
@@ -435,7 +435,7 @@ static ssize_t store_enable_clka1_output(struct device *d,
435 return strnlen(buf, count); 435 return strnlen(buf, count);
436} 436}
437 437
438static DEVICE_ATTR(enable_clka1_output, S_IWUGO, NULL, 438static DEVICE_ATTR(enable_clka1_output, (S_IWUSR|S_IWGRP), NULL,
439 store_enable_clka1_output); 439 store_enable_clka1_output);
440 440
441static ssize_t store_enable_clkb0_output(struct device *d, 441static ssize_t store_enable_clkb0_output(struct device *d,
@@ -456,7 +456,7 @@ static ssize_t store_enable_clkb0_output(struct device *d,
456 return strnlen(buf, count); 456 return strnlen(buf, count);
457} 457}
458 458
459static DEVICE_ATTR(enable_clkb0_output, S_IWUGO, NULL, 459static DEVICE_ATTR(enable_clkb0_output, (S_IWUSR|S_IWGRP), NULL,
460 store_enable_clkb0_output); 460 store_enable_clkb0_output);
461 461
462static ssize_t store_enable_clka0_output(struct device *d, 462static ssize_t store_enable_clka0_output(struct device *d,
@@ -477,7 +477,7 @@ static ssize_t store_enable_clka0_output(struct device *d,
477 return strnlen(buf, count); 477 return strnlen(buf, count);
478} 478}
479 479
480static DEVICE_ATTR(enable_clka0_output, S_IWUGO, NULL, 480static DEVICE_ATTR(enable_clka0_output, (S_IWUSR|S_IWGRP), NULL,
481 store_enable_clka0_output); 481 store_enable_clka0_output);
482 482
483static ssize_t store_select_amcb2_transmit_clock(struct device *d, 483static ssize_t store_select_amcb2_transmit_clock(struct device *d,
@@ -519,7 +519,7 @@ static ssize_t store_select_amcb2_transmit_clock(struct device *d,
519 return strnlen(buf, count); 519 return strnlen(buf, count);
520} 520}
521 521
522static DEVICE_ATTR(select_amcb2_transmit_clock, S_IWUGO, NULL, 522static DEVICE_ATTR(select_amcb2_transmit_clock, (S_IWUSR|S_IWGRP), NULL,
523 store_select_amcb2_transmit_clock); 523 store_select_amcb2_transmit_clock);
524 524
525static ssize_t store_select_amcb1_transmit_clock(struct device *d, 525static ssize_t store_select_amcb1_transmit_clock(struct device *d,
@@ -560,7 +560,7 @@ static ssize_t store_select_amcb1_transmit_clock(struct device *d,
560 return strnlen(buf, count); 560 return strnlen(buf, count);
561} 561}
562 562
563static DEVICE_ATTR(select_amcb1_transmit_clock, S_IWUGO, NULL, 563static DEVICE_ATTR(select_amcb1_transmit_clock, (S_IWUSR|S_IWGRP), NULL,
564 store_select_amcb1_transmit_clock); 564 store_select_amcb1_transmit_clock);
565 565
566static ssize_t store_select_redundant_clock(struct device *d, 566static ssize_t store_select_redundant_clock(struct device *d,
@@ -581,7 +581,7 @@ static ssize_t store_select_redundant_clock(struct device *d,
581 return strnlen(buf, count); 581 return strnlen(buf, count);
582} 582}
583 583
584static DEVICE_ATTR(select_redundant_clock, S_IWUGO, NULL, 584static DEVICE_ATTR(select_redundant_clock, (S_IWUSR|S_IWGRP), NULL,
585 store_select_redundant_clock); 585 store_select_redundant_clock);
586 586
587static ssize_t store_select_ref_frequency(struct device *d, 587static ssize_t store_select_ref_frequency(struct device *d,
@@ -602,7 +602,7 @@ static ssize_t store_select_ref_frequency(struct device *d,
602 return strnlen(buf, count); 602 return strnlen(buf, count);
603} 603}
604 604
605static DEVICE_ATTR(select_ref_frequency, S_IWUGO, NULL, 605static DEVICE_ATTR(select_ref_frequency, (S_IWUSR|S_IWGRP), NULL,
606 store_select_ref_frequency); 606 store_select_ref_frequency);
607 607
608static ssize_t store_filter_select(struct device *d, 608static ssize_t store_filter_select(struct device *d,
@@ -623,7 +623,7 @@ static ssize_t store_filter_select(struct device *d,
623 return strnlen(buf, count); 623 return strnlen(buf, count);
624} 624}
625 625
626static DEVICE_ATTR(filter_select, S_IWUGO, NULL, store_filter_select); 626static DEVICE_ATTR(filter_select, (S_IWUSR|S_IWGRP), NULL, store_filter_select);
627 627
628static ssize_t store_hardware_switching_mode(struct device *d, 628static ssize_t store_hardware_switching_mode(struct device *d,
629 struct device_attribute *attr, const char *buf, size_t count) 629 struct device_attribute *attr, const char *buf, size_t count)
@@ -643,7 +643,7 @@ static ssize_t store_hardware_switching_mode(struct device *d,
643 return strnlen(buf, count); 643 return strnlen(buf, count);
644} 644}
645 645
646static DEVICE_ATTR(hardware_switching_mode, S_IWUGO, NULL, 646static DEVICE_ATTR(hardware_switching_mode, (S_IWUSR|S_IWGRP), NULL,
647 store_hardware_switching_mode); 647 store_hardware_switching_mode);
648 648
649static ssize_t store_hardware_switching(struct device *d, 649static ssize_t store_hardware_switching(struct device *d,
@@ -664,7 +664,7 @@ static ssize_t store_hardware_switching(struct device *d,
664 return strnlen(buf, count); 664 return strnlen(buf, count);
665} 665}
666 666
667static DEVICE_ATTR(hardware_switching, S_IWUGO, NULL, 667static DEVICE_ATTR(hardware_switching, (S_IWUSR|S_IWGRP), NULL,
668 store_hardware_switching); 668 store_hardware_switching);
669 669
670static ssize_t store_refalign (struct device *d, 670static ssize_t store_refalign (struct device *d,
@@ -684,7 +684,7 @@ static ssize_t store_refalign (struct device *d,
684 return strnlen(buf, count); 684 return strnlen(buf, count);
685} 685}
686 686
687static DEVICE_ATTR(refalign, S_IWUGO, NULL, store_refalign); 687static DEVICE_ATTR(refalign, (S_IWUSR|S_IWGRP), NULL, store_refalign);
688 688
689static ssize_t store_mode_select (struct device *d, 689static ssize_t store_mode_select (struct device *d,
690 struct device_attribute *attr, const char *buf, size_t count) 690 struct device_attribute *attr, const char *buf, size_t count)
@@ -704,7 +704,7 @@ static ssize_t store_mode_select (struct device *d,
704 return strnlen(buf, count); 704 return strnlen(buf, count);
705} 705}
706 706
707static DEVICE_ATTR(mode_select, S_IWUGO, NULL, store_mode_select); 707static DEVICE_ATTR(mode_select, (S_IWUSR|S_IWGRP), NULL, store_mode_select);
708 708
709static ssize_t store_reset (struct device *d, 709static ssize_t store_reset (struct device *d,
710 struct device_attribute *attr, const char *buf, size_t count) 710 struct device_attribute *attr, const char *buf, size_t count)
@@ -724,7 +724,7 @@ static ssize_t store_reset (struct device *d,
724 return strnlen(buf, count); 724 return strnlen(buf, count);
725} 725}
726 726
727static DEVICE_ATTR(reset, S_IWUGO, NULL, store_reset); 727static DEVICE_ATTR(reset, (S_IWUSR|S_IWGRP), NULL, store_reset);
728 728
729static struct attribute *tlclk_sysfs_entries[] = { 729static struct attribute *tlclk_sysfs_entries[] = {
730 &dev_attr_current_ref.attr, 730 &dev_attr_current_ref.attr,
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 0bfd1b63662e..841f0bd3eaaf 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -351,10 +351,10 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
351 spin_unlock_irqrestore(&tty->buf.lock, flags); 351 spin_unlock_irqrestore(&tty->buf.lock, flags);
352 return size; 352 return size;
353} 353}
354
355EXPORT_SYMBOL_GPL(tty_buffer_request_room); 354EXPORT_SYMBOL_GPL(tty_buffer_request_room);
356 355
357int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, size_t size) 356int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
357 size_t size)
358{ 358{
359 int copied = 0; 359 int copied = 0;
360 do { 360 do {
@@ -368,17 +368,16 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, s
368 tb->used += space; 368 tb->used += space;
369 copied += space; 369 copied += space;
370 chars += space; 370 chars += space;
371/* printk("Flip insert %d.\n", space); */
372 } 371 }
373 /* There is a small chance that we need to split the data over 372 /* There is a small chance that we need to split the data over
374 several buffers. If this is the case we must loop */ 373 several buffers. If this is the case we must loop */
375 while (unlikely(size > copied)); 374 while (unlikely(size > copied));
376 return copied; 375 return copied;
377} 376}
377EXPORT_SYMBOL(tty_insert_flip_string);
378 378
379EXPORT_SYMBOL_GPL(tty_insert_flip_string); 379int tty_insert_flip_string_flags(struct tty_struct *tty,
380 380 const unsigned char *chars, const char *flags, size_t size)
381int tty_insert_flip_string_flags(struct tty_struct *tty, const unsigned char *chars, const char *flags, size_t size)
382{ 381{
383 int copied = 0; 382 int copied = 0;
384 do { 383 do {
@@ -399,9 +398,20 @@ int tty_insert_flip_string_flags(struct tty_struct *tty, const unsigned char *ch
399 while (unlikely(size > copied)); 398 while (unlikely(size > copied));
400 return copied; 399 return copied;
401} 400}
402
403EXPORT_SYMBOL_GPL(tty_insert_flip_string_flags); 401EXPORT_SYMBOL_GPL(tty_insert_flip_string_flags);
404 402
403void tty_schedule_flip(struct tty_struct *tty)
404{
405 unsigned long flags;
406 spin_lock_irqsave(&tty->buf.lock, flags);
407 if (tty->buf.tail != NULL) {
408 tty->buf.tail->active = 0;
409 tty->buf.tail->commit = tty->buf.tail->used;
410 }
411 spin_unlock_irqrestore(&tty->buf.lock, flags);
412 schedule_delayed_work(&tty->buf.work, 1);
413}
414EXPORT_SYMBOL(tty_schedule_flip);
405 415
406/* 416/*
407 * Prepare a block of space in the buffer for data. Returns the length 417 * Prepare a block of space in the buffer for data. Returns the length
@@ -1730,7 +1740,7 @@ static void release_dev(struct file * filp)
1730{ 1740{
1731 struct tty_struct *tty, *o_tty; 1741 struct tty_struct *tty, *o_tty;
1732 int pty_master, tty_closing, o_tty_closing, do_sleep; 1742 int pty_master, tty_closing, o_tty_closing, do_sleep;
1733 int devpts_master, devpts; 1743 int devpts;
1734 int idx; 1744 int idx;
1735 char buf[64]; 1745 char buf[64];
1736 unsigned long flags; 1746 unsigned long flags;
@@ -1747,7 +1757,6 @@ static void release_dev(struct file * filp)
1747 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && 1757 pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
1748 tty->driver->subtype == PTY_TYPE_MASTER); 1758 tty->driver->subtype == PTY_TYPE_MASTER);
1749 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; 1759 devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0;
1750 devpts_master = pty_master && devpts;
1751 o_tty = tty->link; 1760 o_tty = tty->link;
1752 1761
1753#ifdef TTY_PARANOIA_CHECK 1762#ifdef TTY_PARANOIA_CHECK
@@ -2185,6 +2194,7 @@ static int ptmx_open(struct inode * inode, struct file * filp)
2185 return 0; 2194 return 0;
2186out1: 2195out1:
2187 release_dev(filp); 2196 release_dev(filp);
2197 return retval;
2188out: 2198out:
2189 down(&allocated_ptys_lock); 2199 down(&allocated_ptys_lock);
2190 idr_remove(&allocated_ptys, index); 2200 idr_remove(&allocated_ptys, index);
@@ -2724,7 +2734,7 @@ static void __do_SAK(void *arg)
2724 printk(KERN_NOTICE "SAK: killed process %d" 2734 printk(KERN_NOTICE "SAK: killed process %d"
2725 " (%s): fd#%d opened to the tty\n", 2735 " (%s): fd#%d opened to the tty\n",
2726 p->pid, p->comm, i); 2736 p->pid, p->comm, i);
2727 send_sig(SIGKILL, p, 1); 2737 force_sig(SIGKILL, p);
2728 break; 2738 break;
2729 } 2739 }
2730 } 2740 }
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index ca4844c527da..acc5d47844eb 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -2328,6 +2328,10 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2328 case TIOCL_SETVESABLANK: 2328 case TIOCL_SETVESABLANK:
2329 set_vesa_blanking(p); 2329 set_vesa_blanking(p);
2330 break; 2330 break;
2331 case TIOCL_GETKMSGREDIRECT:
2332 data = kmsg_redirect;
2333 ret = __put_user(data, p);
2334 break;
2331 case TIOCL_SETKMSGREDIRECT: 2335 case TIOCL_SETKMSGREDIRECT:
2332 if (!capable(CAP_SYS_ADMIN)) { 2336 if (!capable(CAP_SYS_ADMIN)) {
2333 ret = -EPERM; 2337 ret = -EPERM;
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index 16e99db2e12d..d53f664a4dd8 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -60,6 +60,13 @@ config SOFT_WATCHDOG
60 60
61# ARM Architecture 61# ARM Architecture
62 62
63config AT91_WATCHDOG
64 tristate "AT91RM9200 watchdog"
65 depends on WATCHDOG && ARCH_AT91RM9200
66 help
67 Watchdog timer embedded into AT91RM9200 chips. This will reboot your
68 system when the timeout is reached.
69
63config 21285_WATCHDOG 70config 21285_WATCHDOG
64 tristate "DC21285 watchdog" 71 tristate "DC21285 watchdog"
65 depends on WATCHDOG && FOOTBRIDGE 72 depends on WATCHDOG && FOOTBRIDGE
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
index d6f27fde9905..6ab77b61a643 100644
--- a/drivers/char/watchdog/Makefile
+++ b/drivers/char/watchdog/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_WDTPCI) += wdt_pci.o
23obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o 23obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb.o
24 24
25# ARM Architecture 25# ARM Architecture
26obj-$(CONFIG_AT91_WATCHDOG) += at91_wdt.o
26obj-$(CONFIG_21285_WATCHDOG) += wdt285.o 27obj-$(CONFIG_21285_WATCHDOG) += wdt285.o
27obj-$(CONFIG_977_WATCHDOG) += wdt977.o 28obj-$(CONFIG_977_WATCHDOG) += wdt977.o
28obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o 29obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o
diff --git a/drivers/char/watchdog/at91_wdt.c b/drivers/char/watchdog/at91_wdt.c
new file mode 100644
index 000000000000..ac83bc4b019a
--- /dev/null
+++ b/drivers/char/watchdog/at91_wdt.c
@@ -0,0 +1,228 @@
1/*
2 * Watchdog driver for Atmel AT91RM9200 (Thunder)
3 *
4 * Copyright (C) 2003 SAN People (Pty) Ltd
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/config.h>
13#include <linux/errno.h>
14#include <linux/fs.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/miscdevice.h>
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/types.h>
21#include <linux/watchdog.h>
22#include <asm/bitops.h>
23#include <asm/uaccess.h>
24
25
26#define WDT_DEFAULT_TIME 5 /* 5 seconds */
27#define WDT_MAX_TIME 256 /* 256 seconds */
28
29static int wdt_time = WDT_DEFAULT_TIME;
30static int nowayout = WATCHDOG_NOWAYOUT;
31
32module_param(wdt_time, int, 0);
33MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="__MODULE_STRING(WDT_DEFAULT_TIME) ")");
34
35module_param(nowayout, int, 0);
36MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
37
38
39static unsigned long at91wdt_busy;
40
41/* ......................................................................... */
42
43/*
44 * Disable the watchdog.
45 */
46static void inline at91_wdt_stop(void)
47{
48 at91_sys_write(AT91_ST_WDMR, AT91_ST_EXTEN);
49}
50
51/*
52 * Enable and reset the watchdog.
53 */
54static void inline at91_wdt_start(void)
55{
56 at91_sys_write(AT91_ST_WDMR, AT91_ST_EXTEN | AT91_ST_RSTEN | (((65536 * wdt_time) >> 8) & AT91_ST_WDV));
57 at91_sys_write(AT91_ST_CR, AT91_ST_WDRST);
58}
59
60/*
61 * Reload the watchdog timer. (ie, pat the watchdog)
62 */
63static void inline at91_wdt_reload(void)
64{
65 at91_sys_write(AT91_ST_CR, AT91_ST_WDRST);
66}
67
68/* ......................................................................... */
69
70/*
71 * Watchdog device is opened, and watchdog starts running.
72 */
73static int at91_wdt_open(struct inode *inode, struct file *file)
74{
75 if (test_and_set_bit(0, &at91wdt_busy))
76 return -EBUSY;
77
78 at91_wdt_start();
79 return nonseekable_open(inode, file);
80}
81
82/*
83 * Close the watchdog device.
84 * If CONFIG_WATCHDOG_NOWAYOUT is NOT defined then the watchdog is also
85 * disabled.
86 */
87static int at91_wdt_close(struct inode *inode, struct file *file)
88{
89 if (!nowayout)
90 at91_wdt_stop(); /* Disable the watchdog when file is closed */
91
92 clear_bit(0, &at91wdt_busy);
93 return 0;
94}
95
96/*
97 * Change the watchdog time interval.
98 */
99static int at91_wdt_settimeout(int new_time)
100{
101 /*
102 * All counting occurs at SLOW_CLOCK / 128 = 0.256 Hz
103 *
104 * Since WDV is a 16-bit counter, the maximum period is
105 * 65536 / 0.256 = 256 seconds.
106 */
107 if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
108 return -EINVAL;
109
110 /* Set new watchdog time. It will be used when at91_wdt_start() is called. */
111 wdt_time = new_time;
112 return 0;
113}
114
115static struct watchdog_info at91_wdt_info = {
116 .identity = "at91 watchdog",
117 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
118};
119
120/*
121 * Handle commands from user-space.
122 */
123static int at91_wdt_ioctl(struct inode *inode, struct file *file,
124 unsigned int cmd, unsigned long arg)
125{
126 void __user *argp = (void __user *)arg;
127 int __user *p = argp;
128 int new_value;
129
130 switch(cmd) {
131 case WDIOC_KEEPALIVE:
132 at91_wdt_reload(); /* pat the watchdog */
133 return 0;
134
135 case WDIOC_GETSUPPORT:
136 return copy_to_user(argp, &at91_wdt_info, sizeof(at91_wdt_info)) ? -EFAULT : 0;
137
138 case WDIOC_SETTIMEOUT:
139 if (get_user(new_value, p))
140 return -EFAULT;
141
142 if (at91_wdt_settimeout(new_value))
143 return -EINVAL;
144
145 /* Enable new time value */
146 at91_wdt_start();
147
148 /* Return current value */
149 return put_user(wdt_time, p);
150
151 case WDIOC_GETTIMEOUT:
152 return put_user(wdt_time, p);
153
154 case WDIOC_GETSTATUS:
155 case WDIOC_GETBOOTSTATUS:
156 return put_user(0, p);
157
158 case WDIOC_SETOPTIONS:
159 if (get_user(new_value, p))
160 return -EFAULT;
161
162 if (new_value & WDIOS_DISABLECARD)
163 at91_wdt_stop();
164 if (new_value & WDIOS_ENABLECARD)
165 at91_wdt_start();
166 return 0;
167
168 default:
169 return -ENOIOCTLCMD;
170 }
171}
172
173/*
174 * Pat the watchdog whenever device is written to.
175 */
176static ssize_t at91_wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
177{
178 at91_wdt_reload(); /* pat the watchdog */
179 return len;
180}
181
182/* ......................................................................... */
183
184static struct file_operations at91wdt_fops = {
185 .owner = THIS_MODULE,
186 .llseek = no_llseek,
187 .ioctl = at91_wdt_ioctl,
188 .open = at91_wdt_open,
189 .release = at91_wdt_close,
190 .write = at91_wdt_write,
191};
192
193static struct miscdevice at91wdt_miscdev = {
194 .minor = WATCHDOG_MINOR,
195 .name = "watchdog",
196 .fops = &at91wdt_fops,
197};
198
199static int __init at91_wdt_init(void)
200{
201 int res;
202
203 /* Check that the heartbeat value is within range; if not reset to the default */
204 if (at91_wdt_settimeout(wdt_time)) {
205 at91_wdt_settimeout(WDT_DEFAULT_TIME);
206 printk(KERN_INFO "at91_wdt: wdt_time value must be 1 <= wdt_time <= 256, using %d\n", wdt_time);
207 }
208
209 res = misc_register(&at91wdt_miscdev);
210 if (res)
211 return res;
212
213 printk("AT91 Watchdog Timer enabled (%d seconds, nowayout=%d)\n", wdt_time, nowayout);
214 return 0;
215}
216
217static void __exit at91_wdt_exit(void)
218{
219 misc_deregister(&at91wdt_miscdev);
220}
221
222module_init(at91_wdt_init);
223module_exit(at91_wdt_exit);
224
225MODULE_AUTHOR("Andrew Victor");
226MODULE_DESCRIPTION("Watchdog driver for Atmel AT91RM9200");
227MODULE_LICENSE("GPL");
228MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index 8d6b249ad66b..6d44ca68312d 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -66,15 +66,13 @@
66#include <linux/fs.h> /* For file operations */ 66#include <linux/fs.h> /* For file operations */
67#include <linux/ioport.h> /* For io-port access */ 67#include <linux/ioport.h> /* For io-port access */
68#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */ 68#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
69#include <linux/sched.h> /* TASK_INTERRUPTIBLE, set_current_state() and friends */
70#include <linux/slab.h> /* For kmalloc */
71 69
72#include <asm/uaccess.h> /* For copy_to_user/put_user/... */ 70#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
73#include <asm/io.h> /* For inb/outb/... */ 71#include <asm/io.h> /* For inb/outb/... */
74 72
75/* Module and version information */ 73/* Module and version information */
76#define WATCHDOG_VERSION "1.16" 74#define WATCHDOG_VERSION "1.17"
77#define WATCHDOG_DATE "03 Jan 2006" 75#define WATCHDOG_DATE "12 Feb 2006"
78#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog" 76#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
79#define WATCHDOG_NAME "pcwd" 77#define WATCHDOG_NAME "pcwd"
80#define PFX WATCHDOG_NAME ": " 78#define PFX WATCHDOG_NAME ": "
@@ -96,15 +94,19 @@
96 * PCI-PC Watchdog card. 94 * PCI-PC Watchdog card.
97*/ 95*/
98/* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */ 96/* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
99#define WD_WDRST 0x01 /* Previously reset state */ 97#define WD_WDRST 0x01 /* Previously reset state */
100#define WD_T110 0x02 /* Temperature overheat sense */ 98#define WD_T110 0x02 /* Temperature overheat sense */
101#define WD_HRTBT 0x04 /* Heartbeat sense */ 99#define WD_HRTBT 0x04 /* Heartbeat sense */
102#define WD_RLY2 0x08 /* External relay triggered */ 100#define WD_RLY2 0x08 /* External relay triggered */
103#define WD_SRLY2 0x80 /* Software external relay triggered */ 101#define WD_SRLY2 0x80 /* Software external relay triggered */
104/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */ 102/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
105#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */ 103#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
106#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */ 104#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
107#define WD_REVC_TTRP 0x04 /* Temperature Trip status */ 105#define WD_REVC_TTRP 0x04 /* Temperature Trip status */
106#define WD_REVC_RL2A 0x08 /* Relay 2 activated by on-board processor */
107#define WD_REVC_RL1A 0x10 /* Relay 1 active */
108#define WD_REVC_R2DS 0x40 /* Relay 2 disable */
109#define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
108/* Port 2 : Control Status #2 */ 110/* Port 2 : Control Status #2 */
109#define WD_WDIS 0x10 /* Watchdog Disabled */ 111#define WD_WDIS 0x10 /* Watchdog Disabled */
110#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */ 112#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
@@ -122,9 +124,14 @@
122#define CMD_ISA_VERSION_HUNDRETH 0x03 124#define CMD_ISA_VERSION_HUNDRETH 0x03
123#define CMD_ISA_VERSION_MINOR 0x04 125#define CMD_ISA_VERSION_MINOR 0x04
124#define CMD_ISA_SWITCH_SETTINGS 0x05 126#define CMD_ISA_SWITCH_SETTINGS 0x05
127#define CMD_ISA_RESET_PC 0x06
128#define CMD_ISA_ARM_0 0x07
129#define CMD_ISA_ARM_30 0x08
130#define CMD_ISA_ARM_60 0x09
125#define CMD_ISA_DELAY_TIME_2SECS 0x0A 131#define CMD_ISA_DELAY_TIME_2SECS 0x0A
126#define CMD_ISA_DELAY_TIME_4SECS 0x0B 132#define CMD_ISA_DELAY_TIME_4SECS 0x0B
127#define CMD_ISA_DELAY_TIME_8SECS 0x0C 133#define CMD_ISA_DELAY_TIME_8SECS 0x0C
134#define CMD_ISA_RESET_RELAYS 0x0D
128 135
129/* 136/*
130 * We are using an kernel timer to do the pinging of the watchdog 137 * We are using an kernel timer to do the pinging of the watchdog
@@ -142,6 +149,7 @@ static atomic_t open_allowed = ATOMIC_INIT(1);
142static char expect_close; 149static char expect_close;
143static int temp_panic; 150static int temp_panic;
144static struct { /* this is private data for each ISA-PC watchdog card */ 151static struct { /* this is private data for each ISA-PC watchdog card */
152 char fw_ver_str[6]; /* The cards firmware version */
145 int revision; /* The card's revision */ 153 int revision; /* The card's revision */
146 int supports_temp; /* Wether or not the card has a temperature device */ 154 int supports_temp; /* Wether or not the card has a temperature device */
147 int command_mode; /* Wether or not the card is in command mode */ 155 int command_mode; /* Wether or not the card is in command mode */
@@ -153,6 +161,13 @@ static struct { /* this is private data for each ISA-PC watchdog card */
153} pcwd_private; 161} pcwd_private;
154 162
155/* module parameters */ 163/* module parameters */
164#define QUIET 0 /* Default */
165#define VERBOSE 1 /* Verbose */
166#define DEBUG 2 /* print fancy stuff too */
167static int debug = QUIET;
168module_param(debug, int, 0);
169MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
170
156#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat */ 171#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat */
157static int heartbeat = WATCHDOG_HEARTBEAT; 172static int heartbeat = WATCHDOG_HEARTBEAT;
158module_param(heartbeat, int, 0); 173module_param(heartbeat, int, 0);
@@ -172,6 +187,10 @@ static int send_isa_command(int cmd)
172 int control_status; 187 int control_status;
173 int port0, last_port0; /* Double read for stabilising */ 188 int port0, last_port0; /* Double read for stabilising */
174 189
190 if (debug >= DEBUG)
191 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
192 cmd);
193
175 /* The WCMD bit must be 1 and the command is only 4 bits in size */ 194 /* The WCMD bit must be 1 and the command is only 4 bits in size */
176 control_status = (cmd & 0x0F) | WD_WCMD; 195 control_status = (cmd & 0x0F) | WD_WCMD;
177 outb_p(control_status, pcwd_private.io_addr + 2); 196 outb_p(control_status, pcwd_private.io_addr + 2);
@@ -188,6 +207,10 @@ static int send_isa_command(int cmd)
188 udelay (250); 207 udelay (250);
189 } 208 }
190 209
210 if (debug >= DEBUG)
211 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
212 cmd, port0, last_port0);
213
191 return port0; 214 return port0;
192} 215}
193 216
@@ -214,6 +237,10 @@ static int set_command_mode(void)
214 spin_unlock(&pcwd_private.io_lock); 237 spin_unlock(&pcwd_private.io_lock);
215 pcwd_private.command_mode = found; 238 pcwd_private.command_mode = found;
216 239
240 if (debug >= DEBUG)
241 printk(KERN_DEBUG PFX "command_mode=%d\n",
242 pcwd_private.command_mode);
243
217 return(found); 244 return(found);
218} 245}
219 246
@@ -226,6 +253,10 @@ static void unset_command_mode(void)
226 spin_unlock(&pcwd_private.io_lock); 253 spin_unlock(&pcwd_private.io_lock);
227 254
228 pcwd_private.command_mode = 0; 255 pcwd_private.command_mode = 0;
256
257 if (debug >= DEBUG)
258 printk(KERN_DEBUG PFX "command_mode=%d\n",
259 pcwd_private.command_mode);
229} 260}
230 261
231static inline void pcwd_check_temperature_support(void) 262static inline void pcwd_check_temperature_support(void)
@@ -234,27 +265,22 @@ static inline void pcwd_check_temperature_support(void)
234 pcwd_private.supports_temp = 1; 265 pcwd_private.supports_temp = 1;
235} 266}
236 267
237static inline char *get_firmware(void) 268static inline void pcwd_get_firmware(void)
238{ 269{
239 int one, ten, hund, minor; 270 int one, ten, hund, minor;
240 char *ret;
241 271
242 ret = kmalloc(6, GFP_KERNEL); 272 strcpy(pcwd_private.fw_ver_str, "ERROR");
243 if(ret == NULL)
244 return NULL;
245 273
246 if (set_command_mode()) { 274 if (set_command_mode()) {
247 one = send_isa_command(CMD_ISA_VERSION_INTEGER); 275 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
248 ten = send_isa_command(CMD_ISA_VERSION_TENTH); 276 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
249 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH); 277 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
250 minor = send_isa_command(CMD_ISA_VERSION_MINOR); 278 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
251 sprintf(ret, "%c.%c%c%c", one, ten, hund, minor); 279 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
252 } 280 }
253 else
254 sprintf(ret, "ERROR");
255
256 unset_command_mode(); 281 unset_command_mode();
257 return(ret); 282
283 return;
258} 284}
259 285
260static inline int pcwd_get_option_switches(void) 286static inline int pcwd_get_option_switches(void)
@@ -272,17 +298,15 @@ static inline int pcwd_get_option_switches(void)
272 298
273static void pcwd_show_card_info(void) 299static void pcwd_show_card_info(void)
274{ 300{
275 char *firmware;
276 int option_switches; 301 int option_switches;
277 302
278 /* Get some extra info from the hardware (in command/debug/diag mode) */ 303 /* Get some extra info from the hardware (in command/debug/diag mode) */
279 if (pcwd_private.revision == PCWD_REVISION_A) 304 if (pcwd_private.revision == PCWD_REVISION_A)
280 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr); 305 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
281 else if (pcwd_private.revision == PCWD_REVISION_C) { 306 else if (pcwd_private.revision == PCWD_REVISION_C) {
282 firmware = get_firmware(); 307 pcwd_get_firmware();
283 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n", 308 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
284 pcwd_private.io_addr, firmware); 309 pcwd_private.io_addr, pcwd_private.fw_ver_str);
285 kfree(firmware);
286 option_switches = pcwd_get_option_switches(); 310 option_switches = pcwd_get_option_switches();
287 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", 311 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
288 option_switches, 312 option_switches,
@@ -362,6 +386,10 @@ static int pcwd_start(void)
362 return -EIO; 386 return -EIO;
363 } 387 }
364 } 388 }
389
390 if (debug >= VERBOSE)
391 printk(KERN_DEBUG PFX "Watchdog started\n");
392
365 return 0; 393 return 0;
366} 394}
367 395
@@ -386,6 +414,10 @@ static int pcwd_stop(void)
386 return -EIO; 414 return -EIO;
387 } 415 }
388 } 416 }
417
418 if (debug >= VERBOSE)
419 printk(KERN_DEBUG PFX "Watchdog stopped\n");
420
389 return 0; 421 return 0;
390} 422}
391 423
@@ -393,6 +425,10 @@ static int pcwd_keepalive(void)
393{ 425{
394 /* user land ping */ 426 /* user land ping */
395 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); 427 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
428
429 if (debug >= DEBUG)
430 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
431
396 return 0; 432 return 0;
397} 433}
398 434
@@ -402,12 +438,17 @@ static int pcwd_set_heartbeat(int t)
402 return -EINVAL; 438 return -EINVAL;
403 439
404 heartbeat = t; 440 heartbeat = t;
441
442 if (debug >= VERBOSE)
443 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
444 heartbeat);
445
405 return 0; 446 return 0;
406} 447}
407 448
408static int pcwd_get_status(int *status) 449static int pcwd_get_status(int *status)
409{ 450{
410 int card_status; 451 int control_status;
411 452
412 *status=0; 453 *status=0;
413 spin_lock(&pcwd_private.io_lock); 454 spin_lock(&pcwd_private.io_lock);
@@ -415,37 +456,39 @@ static int pcwd_get_status(int *status)
415 /* Rev A cards return status information from 456 /* Rev A cards return status information from
416 * the base register, which is used for the 457 * the base register, which is used for the
417 * temperature in other cards. */ 458 * temperature in other cards. */
418 card_status = inb(pcwd_private.io_addr); 459 control_status = inb(pcwd_private.io_addr);
419 else { 460 else {
420 /* Rev C cards return card status in the base 461 /* Rev C cards return card status in the base
421 * address + 1 register. And use different bits 462 * address + 1 register. And use different bits
422 * to indicate a card initiated reset, and an 463 * to indicate a card initiated reset, and an
423 * over-temperature condition. And the reboot 464 * over-temperature condition. And the reboot
424 * status can be reset. */ 465 * status can be reset. */
425 card_status = inb(pcwd_private.io_addr + 1); 466 control_status = inb(pcwd_private.io_addr + 1);
426 } 467 }
427 spin_unlock(&pcwd_private.io_lock); 468 spin_unlock(&pcwd_private.io_lock);
428 469
429 if (pcwd_private.revision == PCWD_REVISION_A) { 470 if (pcwd_private.revision == PCWD_REVISION_A) {
430 if (card_status & WD_WDRST) 471 if (control_status & WD_WDRST)
431 *status |= WDIOF_CARDRESET; 472 *status |= WDIOF_CARDRESET;
432 473
433 if (card_status & WD_T110) { 474 if (control_status & WD_T110) {
434 *status |= WDIOF_OVERHEAT; 475 *status |= WDIOF_OVERHEAT;
435 if (temp_panic) { 476 if (temp_panic) {
436 printk (KERN_INFO PFX "Temperature overheat trip!\n"); 477 printk (KERN_INFO PFX "Temperature overheat trip!\n");
437 kernel_power_off(); 478 kernel_power_off();
479 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
438 } 480 }
439 } 481 }
440 } else { 482 } else {
441 if (card_status & WD_REVC_WTRP) 483 if (control_status & WD_REVC_WTRP)
442 *status |= WDIOF_CARDRESET; 484 *status |= WDIOF_CARDRESET;
443 485
444 if (card_status & WD_REVC_TTRP) { 486 if (control_status & WD_REVC_TTRP) {
445 *status |= WDIOF_OVERHEAT; 487 *status |= WDIOF_OVERHEAT;
446 if (temp_panic) { 488 if (temp_panic) {
447 printk (KERN_INFO PFX "Temperature overheat trip!\n"); 489 printk (KERN_INFO PFX "Temperature overheat trip!\n");
448 kernel_power_off(); 490 kernel_power_off();
491 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
449 } 492 }
450 } 493 }
451 } 494 }
@@ -455,9 +498,25 @@ static int pcwd_get_status(int *status)
455 498
456static int pcwd_clear_status(void) 499static int pcwd_clear_status(void)
457{ 500{
501 int control_status;
502
458 if (pcwd_private.revision == PCWD_REVISION_C) { 503 if (pcwd_private.revision == PCWD_REVISION_C) {
459 spin_lock(&pcwd_private.io_lock); 504 spin_lock(&pcwd_private.io_lock);
460 outb_p(0x00, pcwd_private.io_addr + 1); /* clear reset status */ 505
506 if (debug >= VERBOSE)
507 printk(KERN_INFO PFX "clearing watchdog trip status\n");
508
509 control_status = inb_p(pcwd_private.io_addr + 1);
510
511 if (debug >= DEBUG) {
512 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
513 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
514 (control_status & WD_REVC_R2DS));
515 }
516
517 /* clear reset status & Keep Relay 2 disable state as it is */
518 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
519
461 spin_unlock(&pcwd_private.io_lock); 520 spin_unlock(&pcwd_private.io_lock);
462 } 521 }
463 return 0; 522 return 0;
@@ -481,6 +540,11 @@ static int pcwd_get_temperature(int *temperature)
481 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32; 540 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
482 spin_unlock(&pcwd_private.io_lock); 541 spin_unlock(&pcwd_private.io_lock);
483 542
543 if (debug >= DEBUG) {
544 printk(KERN_DEBUG PFX "temperature is: %d F\n",
545 *temperature);
546 }
547
484 return 0; 548 return 0;
485} 549}
486 550
@@ -599,6 +663,8 @@ static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
599static int pcwd_open(struct inode *inode, struct file *file) 663static int pcwd_open(struct inode *inode, struct file *file)
600{ 664{
601 if (!atomic_dec_and_test(&open_allowed) ) { 665 if (!atomic_dec_and_test(&open_allowed) ) {
666 if (debug >= VERBOSE)
667 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
602 atomic_inc( &open_allowed ); 668 atomic_inc( &open_allowed );
603 return -EBUSY; 669 return -EBUSY;
604 } 670 }
@@ -922,7 +988,8 @@ static void __exit pcwd_cleanup_module(void)
922{ 988{
923 if (pcwd_private.io_addr) 989 if (pcwd_private.io_addr)
924 pcwatchdog_exit(); 990 pcwatchdog_exit();
925 return; 991
992 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
926} 993}
927 994
928module_init(pcwd_init_module); 995module_init(pcwd_init_module);
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index 2700c5c45b8a..3fdfda9324fa 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -705,7 +705,8 @@ err_out_misc_deregister:
705err_out_unregister_reboot: 705err_out_unregister_reboot:
706 unregister_reboot_notifier(&usb_pcwd_notifier); 706 unregister_reboot_notifier(&usb_pcwd_notifier);
707error: 707error:
708 usb_pcwd_delete (usb_pcwd); 708 if (usb_pcwd)
709 usb_pcwd_delete(usb_pcwd);
709 usb_pcwd_device = NULL; 710 usb_pcwd_device = NULL;
710 return retval; 711 return retval;
711} 712}
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index b582d0cdc24f..4f0898400c6d 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -71,7 +71,7 @@ config EDAC_E7XXX
71 71
72config EDAC_E752X 72config EDAC_E752X
73 tristate "Intel e752x (e7520, e7525, e7320)" 73 tristate "Intel e752x (e7520, e7525, e7320)"
74 depends on EDAC_MM_EDAC && PCI && X86 74 depends on EDAC_MM_EDAC && PCI && X86 && HOTPLUG
75 help 75 help
76 Support for error detection and correction on the Intel 76 Support for error detection and correction on the Intel
77 E7520, E7525, E7320 server chipsets. 77 E7520, E7525, E7320 server chipsets.
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 85429979d0db..98e395f4bb29 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -1,7 +1,8 @@
1# 1#
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4obj-$(CONFIG_EDD) += edd.o 4obj-$(CONFIG_DMI) += dmi_scan.o
5obj-$(CONFIG_EDD) += edd.o
5obj-$(CONFIG_EFI_VARS) += efivars.o 6obj-$(CONFIG_EFI_VARS) += efivars.o
6obj-$(CONFIG_EFI_PCDP) += pcdp.o 7obj-$(CONFIG_EFI_PCDP) += pcdp.o
7obj-$(CONFIG_DELL_RBU) += dell_rbu.o 8obj-$(CONFIG_DELL_RBU) += dell_rbu.o
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
new file mode 100644
index 000000000000..948bd7e1445a
--- /dev/null
+++ b/drivers/firmware/dmi_scan.c
@@ -0,0 +1,358 @@
1#include <linux/types.h>
2#include <linux/string.h>
3#include <linux/init.h>
4#include <linux/module.h>
5#include <linux/dmi.h>
6#include <linux/efi.h>
7#include <linux/bootmem.h>
8#include <linux/slab.h>
9#include <asm/dmi.h>
10
11static char * __init dmi_string(struct dmi_header *dm, u8 s)
12{
13 u8 *bp = ((u8 *) dm) + dm->length;
14 char *str = "";
15
16 if (s) {
17 s--;
18 while (s > 0 && *bp) {
19 bp += strlen(bp) + 1;
20 s--;
21 }
22
23 if (*bp != 0) {
24 str = dmi_alloc(strlen(bp) + 1);
25 if (str != NULL)
26 strcpy(str, bp);
27 else
28 printk(KERN_ERR "dmi_string: out of memory.\n");
29 }
30 }
31
32 return str;
33}
34
35/*
36 * We have to be cautious here. We have seen BIOSes with DMI pointers
37 * pointing to completely the wrong place for example
38 */
39static int __init dmi_table(u32 base, int len, int num,
40 void (*decode)(struct dmi_header *))
41{
42 u8 *buf, *data;
43 int i = 0;
44
45 buf = dmi_ioremap(base, len);
46 if (buf == NULL)
47 return -1;
48
49 data = buf;
50
51 /*
52 * Stop when we see all the items the table claimed to have
53 * OR we run off the end of the table (also happens)
54 */
55 while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
56 struct dmi_header *dm = (struct dmi_header *)data;
57 /*
58 * We want to know the total length (formated area and strings)
59 * before decoding to make sure we won't run off the table in
60 * dmi_decode or dmi_string
61 */
62 data += dm->length;
63 while ((data - buf < len - 1) && (data[0] || data[1]))
64 data++;
65 if (data - buf < len - 1)
66 decode(dm);
67 data += 2;
68 i++;
69 }
70 dmi_iounmap(buf, len);
71 return 0;
72}
73
74static int __init dmi_checksum(u8 *buf)
75{
76 u8 sum = 0;
77 int a;
78
79 for (a = 0; a < 15; a++)
80 sum += buf[a];
81
82 return sum == 0;
83}
84
85static char *dmi_ident[DMI_STRING_MAX];
86static LIST_HEAD(dmi_devices);
87
88/*
89 * Save a DMI string
90 */
91static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
92{
93 char *p, *d = (char*) dm;
94
95 if (dmi_ident[slot])
96 return;
97
98 p = dmi_string(dm, d[string]);
99 if (p == NULL)
100 return;
101
102 dmi_ident[slot] = p;
103}
104
105static void __init dmi_save_devices(struct dmi_header *dm)
106{
107 int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
108 struct dmi_device *dev;
109
110 for (i = 0; i < count; i++) {
111 char *d = (char *)(dm + 1) + (i * 2);
112
113 /* Skip disabled device */
114 if ((*d & 0x80) == 0)
115 continue;
116
117 dev = dmi_alloc(sizeof(*dev));
118 if (!dev) {
119 printk(KERN_ERR "dmi_save_devices: out of memory.\n");
120 break;
121 }
122
123 dev->type = *d++ & 0x7f;
124 dev->name = dmi_string(dm, *d);
125 dev->device_data = NULL;
126
127 list_add(&dev->list, &dmi_devices);
128 }
129}
130
131static void __init dmi_save_ipmi_device(struct dmi_header *dm)
132{
133 struct dmi_device *dev;
134 void * data;
135
136 data = dmi_alloc(dm->length);
137 if (data == NULL) {
138 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
139 return;
140 }
141
142 memcpy(data, dm, dm->length);
143
144 dev = dmi_alloc(sizeof(*dev));
145 if (!dev) {
146 printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
147 return;
148 }
149
150 dev->type = DMI_DEV_TYPE_IPMI;
151 dev->name = "IPMI controller";
152 dev->device_data = data;
153
154 list_add(&dev->list, &dmi_devices);
155}
156
157/*
158 * Process a DMI table entry. Right now all we care about are the BIOS
159 * and machine entries. For 2.5 we should pull the smbus controller info
160 * out of here.
161 */
162static void __init dmi_decode(struct dmi_header *dm)
163{
164 switch(dm->type) {
165 case 0: /* BIOS Information */
166 dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
167 dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
168 dmi_save_ident(dm, DMI_BIOS_DATE, 8);
169 break;
170 case 1: /* System Information */
171 dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
172 dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
173 dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
174 dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
175 break;
176 case 2: /* Base Board Information */
177 dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
178 dmi_save_ident(dm, DMI_BOARD_NAME, 5);
179 dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
180 break;
181 case 10: /* Onboard Devices Information */
182 dmi_save_devices(dm);
183 break;
184 case 38: /* IPMI Device Information */
185 dmi_save_ipmi_device(dm);
186 }
187}
188
189static int __init dmi_present(char __iomem *p)
190{
191 u8 buf[15];
192 memcpy_fromio(buf, p, 15);
193 if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
194 u16 num = (buf[13] << 8) | buf[12];
195 u16 len = (buf[7] << 8) | buf[6];
196 u32 base = (buf[11] << 24) | (buf[10] << 16) |
197 (buf[9] << 8) | buf[8];
198
199 /*
200 * DMI version 0.0 means that the real version is taken from
201 * the SMBIOS version, which we don't know at this point.
202 */
203 if (buf[14] != 0)
204 printk(KERN_INFO "DMI %d.%d present.\n",
205 buf[14] >> 4, buf[14] & 0xF);
206 else
207 printk(KERN_INFO "DMI present.\n");
208 if (dmi_table(base,len, num, dmi_decode) == 0)
209 return 0;
210 }
211 return 1;
212}
213
214void __init dmi_scan_machine(void)
215{
216 char __iomem *p, *q;
217 int rc;
218
219 if (efi_enabled) {
220 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
221 goto out;
222
223 /* This is called as a core_initcall() because it isn't
224 * needed during early boot. This also means we can
225 * iounmap the space when we're done with it.
226 */
227 p = dmi_ioremap(efi.smbios, 32);
228 if (p == NULL)
229 goto out;
230
231 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
232 dmi_iounmap(p, 32);
233 if (!rc)
234 return;
235 }
236 else {
237 /*
238 * no iounmap() for that ioremap(); it would be a no-op, but
239 * it's so early in setup that sucker gets confused into doing
240 * what it shouldn't if we actually call it.
241 */
242 p = dmi_ioremap(0xF0000, 0x10000);
243 if (p == NULL)
244 goto out;
245
246 for (q = p; q < p + 0x10000; q += 16) {
247 rc = dmi_present(q);
248 if (!rc)
249 return;
250 }
251 }
252 out: printk(KERN_INFO "DMI not present or invalid.\n");
253}
254
255/**
256 * dmi_check_system - check system DMI data
257 * @list: array of dmi_system_id structures to match against
258 *
259 * Walk the blacklist table running matching functions until someone
260 * returns non zero or we hit the end. Callback function is called for
261 * each successfull match. Returns the number of matches.
262 */
263int dmi_check_system(struct dmi_system_id *list)
264{
265 int i, count = 0;
266 struct dmi_system_id *d = list;
267
268 while (d->ident) {
269 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
270 int s = d->matches[i].slot;
271 if (s == DMI_NONE)
272 continue;
273 if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
274 continue;
275 /* No match */
276 goto fail;
277 }
278 count++;
279 if (d->callback && d->callback(d))
280 break;
281fail: d++;
282 }
283
284 return count;
285}
286EXPORT_SYMBOL(dmi_check_system);
287
288/**
289 * dmi_get_system_info - return DMI data value
290 * @field: data index (see enum dmi_filed)
291 *
292 * Returns one DMI data value, can be used to perform
293 * complex DMI data checks.
294 */
295char *dmi_get_system_info(int field)
296{
297 return dmi_ident[field];
298}
299EXPORT_SYMBOL(dmi_get_system_info);
300
301/**
302 * dmi_find_device - find onboard device by type/name
303 * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
304 * @desc: device name string or %NULL to match all
305 * @from: previous device found in search, or %NULL for new search.
306 *
307 * Iterates through the list of known onboard devices. If a device is
308 * found with a matching @vendor and @device, a pointer to its device
309 * structure is returned. Otherwise, %NULL is returned.
310 * A new search is initiated by passing %NULL to the @from argument.
311 * If @from is not %NULL, searches continue from next device.
312 */
313struct dmi_device * dmi_find_device(int type, const char *name,
314 struct dmi_device *from)
315{
316 struct list_head *d, *head = from ? &from->list : &dmi_devices;
317
318 for(d = head->next; d != &dmi_devices; d = d->next) {
319 struct dmi_device *dev = list_entry(d, struct dmi_device, list);
320
321 if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
322 ((name == NULL) || (strcmp(dev->name, name) == 0)))
323 return dev;
324 }
325
326 return NULL;
327}
328EXPORT_SYMBOL(dmi_find_device);
329
330/**
331 * dmi_get_year - Return year of a DMI date
332 * @field: data index (like dmi_get_system_info)
333 *
334 * Returns -1 when the field doesn't exist. 0 when it is broken.
335 */
336int dmi_get_year(int field)
337{
338 int year;
339 char *s = dmi_get_system_info(field);
340
341 if (!s)
342 return -1;
343 if (*s == '\0')
344 return 0;
345 s = strrchr(s, '/');
346 if (!s)
347 return 0;
348
349 s += 1;
350 year = simple_strtoul(s, NULL, 0);
351 if (year && year < 100) { /* 2-digit year */
352 year += 1900;
353 if (year < 1996) /* no dates < spec 1.0 */
354 year += 100;
355 }
356
357 return year;
358}
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index 7636c1a58f9c..1659f6c41458 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -33,7 +33,6 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/timer.h> 34#include <linux/timer.h>
35#include <linux/dmi.h> 35#include <linux/dmi.h>
36#include <linux/mutex.h>
37#include <asm/io.h> 36#include <asm/io.h>
38 37
39#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ 38#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
@@ -71,10 +70,10 @@ static u8 km_activity;
71static int rest_x; 70static int rest_x;
72static int rest_y; 71static int rest_y;
73 72
74static DEFINE_MUTEX(hdaps_mutex); 73static DECLARE_MUTEX(hdaps_sem);
75 74
76/* 75/*
77 * __get_latch - Get the value from a given port. Callers must hold hdaps_mutex. 76 * __get_latch - Get the value from a given port. Callers must hold hdaps_sem.
78 */ 77 */
79static inline u8 __get_latch(u16 port) 78static inline u8 __get_latch(u16 port)
80{ 79{
@@ -83,7 +82,7 @@ static inline u8 __get_latch(u16 port)
83 82
84/* 83/*
85 * __check_latch - Check a port latch for a given value. Returns zero if the 84 * __check_latch - Check a port latch for a given value. Returns zero if the
86 * port contains the given value. Callers must hold hdaps_mutex. 85 * port contains the given value. Callers must hold hdaps_sem.
87 */ 86 */
88static inline int __check_latch(u16 port, u8 val) 87static inline int __check_latch(u16 port, u8 val)
89{ 88{
@@ -94,7 +93,7 @@ static inline int __check_latch(u16 port, u8 val)
94 93
95/* 94/*
96 * __wait_latch - Wait up to 100us for a port latch to get a certain value, 95 * __wait_latch - Wait up to 100us for a port latch to get a certain value,
97 * returning zero if the value is obtained. Callers must hold hdaps_mutex. 96 * returning zero if the value is obtained. Callers must hold hdaps_sem.
98 */ 97 */
99static int __wait_latch(u16 port, u8 val) 98static int __wait_latch(u16 port, u8 val)
100{ 99{
@@ -111,7 +110,7 @@ static int __wait_latch(u16 port, u8 val)
111 110
112/* 111/*
113 * __device_refresh - request a refresh from the accelerometer. Does not wait 112 * __device_refresh - request a refresh from the accelerometer. Does not wait
114 * for refresh to complete. Callers must hold hdaps_mutex. 113 * for refresh to complete. Callers must hold hdaps_sem.
115 */ 114 */
116static void __device_refresh(void) 115static void __device_refresh(void)
117{ 116{
@@ -125,7 +124,7 @@ static void __device_refresh(void)
125/* 124/*
126 * __device_refresh_sync - request a synchronous refresh from the 125 * __device_refresh_sync - request a synchronous refresh from the
127 * accelerometer. We wait for the refresh to complete. Returns zero if 126 * accelerometer. We wait for the refresh to complete. Returns zero if
128 * successful and nonzero on error. Callers must hold hdaps_mutex. 127 * successful and nonzero on error. Callers must hold hdaps_sem.
129 */ 128 */
130static int __device_refresh_sync(void) 129static int __device_refresh_sync(void)
131{ 130{
@@ -135,7 +134,7 @@ static int __device_refresh_sync(void)
135 134
136/* 135/*
137 * __device_complete - indicate to the accelerometer that we are done reading 136 * __device_complete - indicate to the accelerometer that we are done reading
138 * data, and then initiate an async refresh. Callers must hold hdaps_mutex. 137 * data, and then initiate an async refresh. Callers must hold hdaps_sem.
139 */ 138 */
140static inline void __device_complete(void) 139static inline void __device_complete(void)
141{ 140{
@@ -153,7 +152,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
153{ 152{
154 int ret; 153 int ret;
155 154
156 mutex_lock(&hdaps_mutex); 155 down(&hdaps_sem);
157 156
158 /* do a sync refresh -- we need to be sure that we read fresh data */ 157 /* do a sync refresh -- we need to be sure that we read fresh data */
159 ret = __device_refresh_sync(); 158 ret = __device_refresh_sync();
@@ -164,7 +163,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
164 __device_complete(); 163 __device_complete();
165 164
166out: 165out:
167 mutex_unlock(&hdaps_mutex); 166 up(&hdaps_sem);
168 return ret; 167 return ret;
169} 168}
170 169
@@ -199,9 +198,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
199{ 198{
200 int ret; 199 int ret;
201 200
202 mutex_lock(&hdaps_mutex); 201 down(&hdaps_sem);
203 ret = __hdaps_read_pair(port1, port2, val1, val2); 202 ret = __hdaps_read_pair(port1, port2, val1, val2);
204 mutex_unlock(&hdaps_mutex); 203 up(&hdaps_sem);
205 204
206 return ret; 205 return ret;
207} 206}
@@ -214,7 +213,7 @@ static int hdaps_device_init(void)
214{ 213{
215 int total, ret = -ENXIO; 214 int total, ret = -ENXIO;
216 215
217 mutex_lock(&hdaps_mutex); 216 down(&hdaps_sem);
218 217
219 outb(0x13, 0x1610); 218 outb(0x13, 0x1610);
220 outb(0x01, 0x161f); 219 outb(0x01, 0x161f);
@@ -280,7 +279,7 @@ static int hdaps_device_init(void)
280 } 279 }
281 280
282out: 281out:
283 mutex_unlock(&hdaps_mutex); 282 up(&hdaps_sem);
284 return ret; 283 return ret;
285} 284}
286 285
@@ -314,7 +313,7 @@ static struct platform_driver hdaps_driver = {
314}; 313};
315 314
316/* 315/*
317 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mutex. 316 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem.
318 */ 317 */
319static void hdaps_calibrate(void) 318static void hdaps_calibrate(void)
320{ 319{
@@ -326,7 +325,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
326 int x, y; 325 int x, y;
327 326
328 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ 327 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
329 if (!mutex_trylock(&hdaps_mutex)) { 328 if (down_trylock(&hdaps_sem)) {
330 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); 329 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
331 return; 330 return;
332 } 331 }
@@ -341,7 +340,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
341 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); 340 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
342 341
343out: 342out:
344 mutex_unlock(&hdaps_mutex); 343 up(&hdaps_sem);
345} 344}
346 345
347 346
@@ -421,9 +420,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
421 struct device_attribute *attr, 420 struct device_attribute *attr,
422 const char *buf, size_t count) 421 const char *buf, size_t count)
423{ 422{
424 mutex_lock(&hdaps_mutex); 423 down(&hdaps_sem);
425 hdaps_calibrate(); 424 hdaps_calibrate();
426 mutex_unlock(&hdaps_mutex); 425 up(&hdaps_sem);
427 426
428 return count; 427 return count;
429} 428}
@@ -510,12 +509,22 @@ static int hdaps_dmi_match_invert(struct dmi_system_id *id)
510 } \ 509 } \
511} 510}
512 511
512#define HDAPS_DMI_MATCH_LENOVO(model) { \
513 .ident = "Lenovo " model, \
514 .callback = hdaps_dmi_match_invert, \
515 .matches = { \
516 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"), \
517 DMI_MATCH(DMI_PRODUCT_VERSION, model) \
518 } \
519}
520
513static int __init hdaps_init(void) 521static int __init hdaps_init(void)
514{ 522{
515 int ret; 523 int ret;
516 524
517 /* Note that DMI_MATCH(...,"ThinkPad T42") will match "ThinkPad T42p" */ 525 /* Note that DMI_MATCH(...,"ThinkPad T42") will match "ThinkPad T42p" */
518 struct dmi_system_id hdaps_whitelist[] = { 526 struct dmi_system_id hdaps_whitelist[] = {
527 HDAPS_DMI_MATCH_NORMAL("ThinkPad H"),
519 HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"), 528 HDAPS_DMI_MATCH_INVERT("ThinkPad R50p"),
520 HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"), 529 HDAPS_DMI_MATCH_NORMAL("ThinkPad R50"),
521 HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"), 530 HDAPS_DMI_MATCH_NORMAL("ThinkPad R51"),
@@ -525,15 +534,17 @@ static int __init hdaps_init(void)
525 HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"), 534 HDAPS_DMI_MATCH_INVERT("ThinkPad T42p"),
526 HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"), 535 HDAPS_DMI_MATCH_NORMAL("ThinkPad T42"),
527 HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"), 536 HDAPS_DMI_MATCH_NORMAL("ThinkPad T43"),
537 HDAPS_DMI_MATCH_LENOVO("ThinkPad T60p"),
528 HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"), 538 HDAPS_DMI_MATCH_NORMAL("ThinkPad X40"),
529 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41 Tablet"), 539 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41 Tablet"),
530 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"), 540 HDAPS_DMI_MATCH_NORMAL("ThinkPad X41"),
541 HDAPS_DMI_MATCH_LENOVO("ThinkPad X60"),
531 { .ident = NULL } 542 { .ident = NULL }
532 }; 543 };
533 544
534 if (!dmi_check_system(hdaps_whitelist)) { 545 if (!dmi_check_system(hdaps_whitelist)) {
535 printk(KERN_WARNING "hdaps: supported laptop not found!\n"); 546 printk(KERN_WARNING "hdaps: supported laptop not found!\n");
536 ret = -ENXIO; 547 ret = -ENODEV;
537 goto out; 548 goto out;
538 } 549 }
539 550
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 6865c64d8a51..958602e28412 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -1161,7 +1161,7 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1161 bank. */ 1161 bank. */
1162 if (kind < 0) { 1162 if (kind < 0) {
1163 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) { 1163 if (w83792d_read_value(client, W83792D_REG_CONFIG) & 0x80) {
1164 dev_warn(dev, "Detection failed at step 3\n"); 1164 dev_dbg(dev, "Detection failed at step 1\n");
1165 goto ERROR1; 1165 goto ERROR1;
1166 } 1166 }
1167 val1 = w83792d_read_value(client, W83792D_REG_BANK); 1167 val1 = w83792d_read_value(client, W83792D_REG_BANK);
@@ -1170,6 +1170,7 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1170 if (!(val1 & 0x07)) { /* is Bank0 */ 1170 if (!(val1 & 0x07)) { /* is Bank0 */
1171 if (((!(val1 & 0x80)) && (val2 != 0xa3)) || 1171 if (((!(val1 & 0x80)) && (val2 != 0xa3)) ||
1172 ((val1 & 0x80) && (val2 != 0x5c))) { 1172 ((val1 & 0x80) && (val2 != 0x5c))) {
1173 dev_dbg(dev, "Detection failed at step 2\n");
1173 goto ERROR1; 1174 goto ERROR1;
1174 } 1175 }
1175 } 1176 }
@@ -1177,7 +1178,7 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1177 should match */ 1178 should match */
1178 if (w83792d_read_value(client, 1179 if (w83792d_read_value(client,
1179 W83792D_REG_I2C_ADDR) != address) { 1180 W83792D_REG_I2C_ADDR) != address) {
1180 dev_warn(dev, "Detection failed at step 5\n"); 1181 dev_dbg(dev, "Detection failed at step 3\n");
1181 goto ERROR1; 1182 goto ERROR1;
1182 } 1183 }
1183 } 1184 }
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 089c6f5b24de..d6d44946a283 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -286,7 +286,10 @@ config I2C_PARPORT
286 This driver is a replacement for (and was inspired by) an older 286 This driver is a replacement for (and was inspired by) an older
287 driver named i2c-philips-par. The new driver supports more devices, 287 driver named i2c-philips-par. The new driver supports more devices,
288 and makes it easier to add support for new devices. 288 and makes it easier to add support for new devices.
289 289
290 An adapter type parameter is now mandatory. Please read the file
291 Documentation/i2c/busses/i2c-parport for details.
292
290 Another driver exists, named i2c-parport-light, which doesn't depend 293 Another driver exists, named i2c-parport-light, which doesn't depend
291 on the parport driver. This is meant for embedded systems. Don't say 294 on the parport driver. This is meant for embedded systems. Don't say
292 Y here if you intend to say Y or M there. 295 Y here if you intend to say Y or M there.
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index c63025a4c861..e09ebbb2f9f0 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -121,9 +121,14 @@ static struct i2c_adapter parport_adapter = {
121 121
122static int __init i2c_parport_init(void) 122static int __init i2c_parport_init(void)
123{ 123{
124 if (type < 0 || type >= ARRAY_SIZE(adapter_parm)) { 124 if (type < 0) {
125 printk(KERN_WARNING "i2c-parport: adapter type unspecified\n");
126 return -ENODEV;
127 }
128
129 if (type >= ARRAY_SIZE(adapter_parm)) {
125 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); 130 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type);
126 type = 0; 131 return -ENODEV;
127 } 132 }
128 133
129 if (base == 0) { 134 if (base == 0) {
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 7e2e8cd1c14a..934bd55bae15 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -241,9 +241,14 @@ static struct parport_driver i2c_parport_driver = {
241 241
242static int __init i2c_parport_init(void) 242static int __init i2c_parport_init(void)
243{ 243{
244 if (type < 0 || type >= ARRAY_SIZE(adapter_parm)) { 244 if (type < 0) {
245 printk(KERN_WARNING "i2c-parport: adapter type unspecified\n");
246 return -ENODEV;
247 }
248
249 if (type >= ARRAY_SIZE(adapter_parm)) {
245 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); 250 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type);
246 type = 0; 251 return -ENODEV;
247 } 252 }
248 253
249 return parport_register_driver(&i2c_parport_driver); 254 return parport_register_driver(&i2c_parport_driver);
diff --git a/drivers/i2c/busses/i2c-parport.h b/drivers/i2c/busses/i2c-parport.h
index d702e5e0388d..9ddd816d5d0f 100644
--- a/drivers/i2c/busses/i2c-parport.h
+++ b/drivers/i2c/busses/i2c-parport.h
@@ -90,7 +90,7 @@ static struct adapter_parm adapter_parm[] = {
90 }, 90 },
91}; 91};
92 92
93static int type; 93static int type = -1;
94module_param(type, int, 0); 94module_param(type, int, 0);
95MODULE_PARM_DESC(type, 95MODULE_PARM_DESC(type,
96 "Type of adapter:\n" 96 "Type of adapter:\n"
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 3024907cdafe..1a73c0532fc7 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -43,13 +43,6 @@
43#include <linux/init.h> 43#include <linux/init.h>
44#include <asm/io.h> 44#include <asm/io.h>
45 45
46/*
47 HISTORY:
48 2003-05-11 1.0.0 Updated from lm_sensors project for kernel 2.5
49 (was i2c-sis645.c from lm_sensors 2.7.0)
50*/
51#define SIS96x_VERSION "1.0.0"
52
53/* base address register in PCI config space */ 46/* base address register in PCI config space */
54#define SIS96x_BAR 0x04 47#define SIS96x_BAR 0x04
55 48
@@ -337,7 +330,6 @@ static struct pci_driver sis96x_driver = {
337 330
338static int __init i2c_sis96x_init(void) 331static int __init i2c_sis96x_init(void)
339{ 332{
340 printk(KERN_INFO "i2c-sis96x version %s\n", SIS96x_VERSION);
341 return pci_register_driver(&sis96x_driver); 333 return pci_register_driver(&sis96x_driver);
342} 334}
343 335
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index 03d09ed5ec2c..4630f1969a09 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -27,6 +27,7 @@
27#include <linux/rtc.h> 27#include <linux/rtc.h>
28#include <linux/bcd.h> 28#include <linux/bcd.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/workqueue.h>
30 31
31#define DS1374_REG_TOD0 0x00 32#define DS1374_REG_TOD0 0x00
32#define DS1374_REG_TOD1 0x01 33#define DS1374_REG_TOD1 0x01
@@ -139,7 +140,7 @@ ulong ds1374_get_rtc_time(void)
139 return t1; 140 return t1;
140} 141}
141 142
142static void ds1374_set_tlet(ulong arg) 143static void ds1374_set_work(void *arg)
143{ 144{
144 ulong t1, t2; 145 ulong t1, t2;
145 int limit = 10; /* arbitrary retry limit */ 146 int limit = 10; /* arbitrary retry limit */
@@ -168,17 +169,18 @@ static void ds1374_set_tlet(ulong arg)
168 169
169static ulong new_time; 170static ulong new_time;
170 171
171static DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, 172static struct workqueue_struct *ds1374_workqueue;
172 (ulong) & new_time); 173
174static DECLARE_WORK(ds1374_work, ds1374_set_work, &new_time);
173 175
174int ds1374_set_rtc_time(ulong nowtime) 176int ds1374_set_rtc_time(ulong nowtime)
175{ 177{
176 new_time = nowtime; 178 new_time = nowtime;
177 179
178 if (in_interrupt()) 180 if (in_interrupt())
179 tasklet_schedule(&ds1374_tasklet); 181 queue_work(ds1374_workqueue, &ds1374_work);
180 else 182 else
181 ds1374_set_tlet((ulong) & new_time); 183 ds1374_set_work(&new_time);
182 184
183 return 0; 185 return 0;
184} 186}
@@ -204,6 +206,8 @@ static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
204 client->adapter = adap; 206 client->adapter = adap;
205 client->driver = &ds1374_driver; 207 client->driver = &ds1374_driver;
206 208
209 ds1374_workqueue = create_singlethread_workqueue("ds1374");
210
207 if ((rc = i2c_attach_client(client)) != 0) { 211 if ((rc = i2c_attach_client(client)) != 0) {
208 kfree(client); 212 kfree(client);
209 return rc; 213 return rc;
@@ -227,7 +231,7 @@ static int ds1374_detach(struct i2c_client *client)
227 231
228 if ((rc = i2c_detach_client(client)) == 0) { 232 if ((rc = i2c_detach_client(client)) == 0) {
229 kfree(i2c_get_clientdata(client)); 233 kfree(i2c_get_clientdata(client));
230 tasklet_kill(&ds1374_tasklet); 234 destroy_workqueue(ds1374_workqueue);
231 } 235 }
232 return rc; 236 return rc;
233} 237}
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index b5aabe7cf792..27fc9ff2961a 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -25,6 +25,7 @@
25#include <linux/rtc.h> 25#include <linux/rtc.h>
26#include <linux/bcd.h> 26#include <linux/bcd.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/workqueue.h>
28 29
29#include <asm/time.h> 30#include <asm/time.h>
30#include <asm/rtc.h> 31#include <asm/rtc.h>
@@ -111,7 +112,7 @@ m41t00_get_rtc_time(void)
111} 112}
112 113
113static void 114static void
114m41t00_set_tlet(ulong arg) 115m41t00_set(void *arg)
115{ 116{
116 struct rtc_time tm; 117 struct rtc_time tm;
117 ulong nowtime = *(ulong *)arg; 118 ulong nowtime = *(ulong *)arg;
@@ -145,9 +146,9 @@ m41t00_set_tlet(ulong arg)
145 return; 146 return;
146} 147}
147 148
148static ulong new_time; 149static ulong new_time;
149 150static struct workqueue_struct *m41t00_wq;
150DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time); 151static DECLARE_WORK(m41t00_work, m41t00_set, &new_time);
151 152
152int 153int
153m41t00_set_rtc_time(ulong nowtime) 154m41t00_set_rtc_time(ulong nowtime)
@@ -155,9 +156,9 @@ m41t00_set_rtc_time(ulong nowtime)
155 new_time = nowtime; 156 new_time = nowtime;
156 157
157 if (in_interrupt()) 158 if (in_interrupt())
158 tasklet_schedule(&m41t00_tasklet); 159 queue_work(m41t00_wq, &m41t00_work);
159 else 160 else
160 m41t00_set_tlet((ulong)&new_time); 161 m41t00_set(&new_time);
161 162
162 return 0; 163 return 0;
163} 164}
@@ -189,6 +190,7 @@ m41t00_probe(struct i2c_adapter *adap, int addr, int kind)
189 return rc; 190 return rc;
190 } 191 }
191 192
193 m41t00_wq = create_singlethread_workqueue("m41t00");
192 save_client = client; 194 save_client = client;
193 return 0; 195 return 0;
194} 196}
@@ -206,7 +208,7 @@ m41t00_detach(struct i2c_client *client)
206 208
207 if ((rc = i2c_detach_client(client)) == 0) { 209 if ((rc = i2c_detach_client(client)) == 0) {
208 kfree(client); 210 kfree(client);
209 tasklet_kill(&m41t00_tasklet); 211 destroy_workqueue(m41t00_wq);
210 } 212 }
211 return rc; 213 return rc;
212} 214}
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index ccf528d733bf..a5017de72da5 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -61,6 +61,7 @@
61#include <linux/slab.h> 61#include <linux/slab.h>
62#include <linux/delay.h> 62#include <linux/delay.h>
63#include <linux/mutex.h> 63#include <linux/mutex.h>
64#include <linux/leds.h>
64 65
65#define _IDE_DISK 66#define _IDE_DISK
66 67
@@ -317,6 +318,8 @@ static ide_startstop_t ide_do_rw_disk (ide_drive_t *drive, struct request *rq, s
317 return ide_stopped; 318 return ide_stopped;
318 } 319 }
319 320
321 ledtrig_ide_activity();
322
320 pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n", 323 pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n",
321 drive->name, rq_data_dir(rq) == READ ? "read" : "writ", 324 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
322 (unsigned long long)block, rq->nr_sectors, 325 (unsigned long long)block, rq->nr_sectors,
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 0606bd2f6020..9233b8109a0f 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -375,7 +375,13 @@ static void task_end_request(ide_drive_t *drive, struct request *rq, u8 stat)
375 } 375 }
376 } 376 }
377 377
378 ide_end_request(drive, 1, rq->hard_nr_sectors); 378 if (rq->rq_disk) {
379 ide_driver_t *drv;
380
381 drv = *(ide_driver_t **)rq->rq_disk->private_data;;
382 drv->end_request(drive, 1, rq->hard_nr_sectors);
383 } else
384 ide_end_request(drive, 1, rq->hard_nr_sectors);
379} 385}
380 386
381/* 387/*
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index 6213bd3caee5..4961f1e764a7 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -81,14 +81,14 @@ static const char ide_major[] = {
81}; 81};
82 82
83typedef struct ide_info_t { 83typedef struct ide_info_t {
84 dev_link_t link; 84 struct pcmcia_device *p_dev;
85 int ndev; 85 int ndev;
86 dev_node_t node; 86 dev_node_t node;
87 int hd; 87 int hd;
88} ide_info_t; 88} ide_info_t;
89 89
90static void ide_release(dev_link_t *); 90static void ide_release(struct pcmcia_device *);
91static void ide_config(dev_link_t *); 91static int ide_config(struct pcmcia_device *);
92 92
93static void ide_detach(struct pcmcia_device *p_dev); 93static void ide_detach(struct pcmcia_device *p_dev);
94 94
@@ -103,10 +103,9 @@ static void ide_detach(struct pcmcia_device *p_dev);
103 103
104======================================================================*/ 104======================================================================*/
105 105
106static int ide_attach(struct pcmcia_device *p_dev) 106static int ide_probe(struct pcmcia_device *link)
107{ 107{
108 ide_info_t *info; 108 ide_info_t *info;
109 dev_link_t *link;
110 109
111 DEBUG(0, "ide_attach()\n"); 110 DEBUG(0, "ide_attach()\n");
112 111
@@ -114,7 +113,9 @@ static int ide_attach(struct pcmcia_device *p_dev)
114 info = kzalloc(sizeof(*info), GFP_KERNEL); 113 info = kzalloc(sizeof(*info), GFP_KERNEL);
115 if (!info) 114 if (!info)
116 return -ENOMEM; 115 return -ENOMEM;
117 link = &info->link; link->priv = info; 116
117 info->p_dev = link;
118 link->priv = info;
118 119
119 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 120 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
120 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 121 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
@@ -122,16 +123,9 @@ static int ide_attach(struct pcmcia_device *p_dev)
122 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 123 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
123 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 124 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
124 link->conf.Attributes = CONF_ENABLE_IRQ; 125 link->conf.Attributes = CONF_ENABLE_IRQ;
125 link->conf.Vcc = 50;
126 link->conf.IntType = INT_MEMORY_AND_IO; 126 link->conf.IntType = INT_MEMORY_AND_IO;
127 127
128 link->handle = p_dev; 128 return ide_config(link);
129 p_dev->instance = link;
130
131 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
132 ide_config(link);
133
134 return 0;
135} /* ide_attach */ 129} /* ide_attach */
136 130
137/*====================================================================== 131/*======================================================================
@@ -143,14 +137,11 @@ static int ide_attach(struct pcmcia_device *p_dev)
143 137
144======================================================================*/ 138======================================================================*/
145 139
146static void ide_detach(struct pcmcia_device *p_dev) 140static void ide_detach(struct pcmcia_device *link)
147{ 141{
148 dev_link_t *link = dev_to_instance(p_dev);
149
150 DEBUG(0, "ide_detach(0x%p)\n", link); 142 DEBUG(0, "ide_detach(0x%p)\n", link);
151 143
152 if (link->state & DEV_CONFIG) 144 ide_release(link);
153 ide_release(link);
154 145
155 kfree(link->priv); 146 kfree(link->priv);
156} /* ide_detach */ 147} /* ide_detach */
@@ -177,9 +168,8 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
177#define CS_CHECK(fn, ret) \ 168#define CS_CHECK(fn, ret) \
178do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 169do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
179 170
180static void ide_config(dev_link_t *link) 171static int ide_config(struct pcmcia_device *link)
181{ 172{
182 client_handle_t handle = link->handle;
183 ide_info_t *info = link->priv; 173 ide_info_t *info = link->priv;
184 tuple_t tuple; 174 tuple_t tuple;
185 struct { 175 struct {
@@ -203,34 +193,30 @@ static void ide_config(dev_link_t *link)
203 tuple.TupleDataMax = 255; 193 tuple.TupleDataMax = 255;
204 tuple.Attributes = 0; 194 tuple.Attributes = 0;
205 tuple.DesiredTuple = CISTPL_CONFIG; 195 tuple.DesiredTuple = CISTPL_CONFIG;
206 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 196 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
207 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 197 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
208 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &stk->parse)); 198 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &stk->parse));
209 link->conf.ConfigBase = stk->parse.config.base; 199 link->conf.ConfigBase = stk->parse.config.base;
210 link->conf.Present = stk->parse.config.rmask[0]; 200 link->conf.Present = stk->parse.config.rmask[0];
211 201
212 tuple.DesiredTuple = CISTPL_MANFID; 202 tuple.DesiredTuple = CISTPL_MANFID;
213 if (!pcmcia_get_first_tuple(handle, &tuple) && 203 if (!pcmcia_get_first_tuple(link, &tuple) &&
214 !pcmcia_get_tuple_data(handle, &tuple) && 204 !pcmcia_get_tuple_data(link, &tuple) &&
215 !pcmcia_parse_tuple(handle, &tuple, &stk->parse)) 205 !pcmcia_parse_tuple(link, &tuple, &stk->parse))
216 is_kme = ((stk->parse.manfid.manf == MANFID_KME) && 206 is_kme = ((stk->parse.manfid.manf == MANFID_KME) &&
217 ((stk->parse.manfid.card == PRODID_KME_KXLC005_A) || 207 ((stk->parse.manfid.card == PRODID_KME_KXLC005_A) ||
218 (stk->parse.manfid.card == PRODID_KME_KXLC005_B))); 208 (stk->parse.manfid.card == PRODID_KME_KXLC005_B)));
219 209
220 /* Configure card */
221 link->state |= DEV_CONFIG;
222
223 /* Not sure if this is right... look up the current Vcc */ 210 /* Not sure if this is right... look up the current Vcc */
224 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &stk->conf)); 211 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf));
225 link->conf.Vcc = stk->conf.Vcc;
226 212
227 pass = io_base = ctl_base = 0; 213 pass = io_base = ctl_base = 0;
228 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 214 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
229 tuple.Attributes = 0; 215 tuple.Attributes = 0;
230 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 216 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
231 while (1) { 217 while (1) {
232 if (pcmcia_get_tuple_data(handle, &tuple) != 0) goto next_entry; 218 if (pcmcia_get_tuple_data(link, &tuple) != 0) goto next_entry;
233 if (pcmcia_parse_tuple(handle, &tuple, &stk->parse) != 0) goto next_entry; 219 if (pcmcia_parse_tuple(link, &tuple, &stk->parse) != 0) goto next_entry;
234 220
235 /* Check for matching Vcc, unless we're desperate */ 221 /* Check for matching Vcc, unless we're desperate */
236 if (!pass) { 222 if (!pass) {
@@ -244,10 +230,10 @@ static void ide_config(dev_link_t *link)
244 } 230 }
245 231
246 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 232 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
247 link->conf.Vpp1 = link->conf.Vpp2 = 233 link->conf.Vpp =
248 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 234 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
249 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 235 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
250 link->conf.Vpp1 = link->conf.Vpp2 = 236 link->conf.Vpp =
251 stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 237 stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
252 238
253 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) { 239 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
@@ -261,14 +247,14 @@ static void ide_config(dev_link_t *link)
261 link->io.NumPorts1 = 8; 247 link->io.NumPorts1 = 8;
262 link->io.BasePort2 = io->win[1].base; 248 link->io.BasePort2 = io->win[1].base;
263 link->io.NumPorts2 = (is_kme) ? 2 : 1; 249 link->io.NumPorts2 = (is_kme) ? 2 : 1;
264 if (pcmcia_request_io(link->handle, &link->io) != 0) 250 if (pcmcia_request_io(link, &link->io) != 0)
265 goto next_entry; 251 goto next_entry;
266 io_base = link->io.BasePort1; 252 io_base = link->io.BasePort1;
267 ctl_base = link->io.BasePort2; 253 ctl_base = link->io.BasePort2;
268 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) { 254 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
269 link->io.NumPorts1 = io->win[0].len; 255 link->io.NumPorts1 = io->win[0].len;
270 link->io.NumPorts2 = 0; 256 link->io.NumPorts2 = 0;
271 if (pcmcia_request_io(link->handle, &link->io) != 0) 257 if (pcmcia_request_io(link, &link->io) != 0)
272 goto next_entry; 258 goto next_entry;
273 io_base = link->io.BasePort1; 259 io_base = link->io.BasePort1;
274 ctl_base = link->io.BasePort1 + 0x0e; 260 ctl_base = link->io.BasePort1 + 0x0e;
@@ -281,16 +267,16 @@ static void ide_config(dev_link_t *link)
281 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 267 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
282 memcpy(&stk->dflt, cfg, sizeof(stk->dflt)); 268 memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
283 if (pass) { 269 if (pass) {
284 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 270 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
285 } else if (pcmcia_get_next_tuple(handle, &tuple) != 0) { 271 } else if (pcmcia_get_next_tuple(link, &tuple) != 0) {
286 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 272 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
287 memset(&stk->dflt, 0, sizeof(stk->dflt)); 273 memset(&stk->dflt, 0, sizeof(stk->dflt));
288 pass++; 274 pass++;
289 } 275 }
290 } 276 }
291 277
292 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 278 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
293 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 279 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
294 280
295 /* disable drive interrupts during IDE probe */ 281 /* disable drive interrupts during IDE probe */
296 outb(0x02, ctl_base); 282 outb(0x02, ctl_base);
@@ -301,12 +287,12 @@ static void ide_config(dev_link_t *link)
301 287
302 /* retry registration in case device is still spinning up */ 288 /* retry registration in case device is still spinning up */
303 for (hd = -1, i = 0; i < 10; i++) { 289 for (hd = -1, i = 0; i < 10; i++) {
304 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, handle); 290 hd = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
305 if (hd >= 0) break; 291 if (hd >= 0) break;
306 if (link->io.NumPorts1 == 0x20) { 292 if (link->io.NumPorts1 == 0x20) {
307 outb(0x02, ctl_base + 0x10); 293 outb(0x02, ctl_base + 0x10);
308 hd = idecs_register(io_base + 0x10, ctl_base + 0x10, 294 hd = idecs_register(io_base + 0x10, ctl_base + 0x10,
309 link->irq.AssignedIRQ, handle); 295 link->irq.AssignedIRQ, link);
310 if (hd >= 0) { 296 if (hd >= 0) {
311 io_base += 0x10; 297 io_base += 0x10;
312 ctl_base += 0x10; 298 ctl_base += 0x10;
@@ -328,25 +314,23 @@ static void ide_config(dev_link_t *link)
328 info->node.major = ide_major[hd]; 314 info->node.major = ide_major[hd];
329 info->node.minor = 0; 315 info->node.minor = 0;
330 info->hd = hd; 316 info->hd = hd;
331 link->dev = &info->node; 317 link->dev_node = &info->node;
332 printk(KERN_INFO "ide-cs: %s: Vcc = %d.%d, Vpp = %d.%d\n", 318 printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n",
333 info->node.dev_name, link->conf.Vcc / 10, link->conf.Vcc % 10, 319 info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10);
334 link->conf.Vpp1 / 10, link->conf.Vpp1 % 10);
335 320
336 link->state &= ~DEV_CONFIG_PENDING;
337 kfree(stk); 321 kfree(stk);
338 return; 322 return 0;
339 323
340err_mem: 324err_mem:
341 printk(KERN_NOTICE "ide-cs: ide_config failed memory allocation\n"); 325 printk(KERN_NOTICE "ide-cs: ide_config failed memory allocation\n");
342 goto failed; 326 goto failed;
343 327
344cs_failed: 328cs_failed:
345 cs_error(link->handle, last_fn, last_ret); 329 cs_error(link, last_fn, last_ret);
346failed: 330failed:
347 kfree(stk); 331 kfree(stk);
348 ide_release(link); 332 ide_release(link);
349 link->state &= ~DEV_CONFIG_PENDING; 333 return -ENODEV;
350} /* ide_config */ 334} /* ide_config */
351 335
352/*====================================================================== 336/*======================================================================
@@ -357,7 +341,7 @@ failed:
357 341
358======================================================================*/ 342======================================================================*/
359 343
360void ide_release(dev_link_t *link) 344void ide_release(struct pcmcia_device *link)
361{ 345{
362 ide_info_t *info = link->priv; 346 ide_info_t *info = link->priv;
363 347
@@ -369,37 +353,10 @@ void ide_release(dev_link_t *link)
369 ide_unregister(info->hd); 353 ide_unregister(info->hd);
370 } 354 }
371 info->ndev = 0; 355 info->ndev = 0;
372 link->dev = NULL;
373
374 pcmcia_release_configuration(link->handle);
375 pcmcia_release_io(link->handle, &link->io);
376 pcmcia_release_irq(link->handle, &link->irq);
377
378 link->state &= ~DEV_CONFIG;
379 356
357 pcmcia_disable_device(link);
380} /* ide_release */ 358} /* ide_release */
381 359
382static int ide_suspend(struct pcmcia_device *dev)
383{
384 dev_link_t *link = dev_to_instance(dev);
385
386 link->state |= DEV_SUSPEND;
387 if (link->state & DEV_CONFIG)
388 pcmcia_release_configuration(link->handle);
389
390 return 0;
391}
392
393static int ide_resume(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state &= ~DEV_SUSPEND;
398 if (DEV_OK(link))
399 pcmcia_request_configuration(link->handle, &link->conf);
400
401 return 0;
402}
403 360
404/*====================================================================== 361/*======================================================================
405 362
@@ -459,11 +416,9 @@ static struct pcmcia_driver ide_cs_driver = {
459 .drv = { 416 .drv = {
460 .name = "ide-cs", 417 .name = "ide-cs",
461 }, 418 },
462 .probe = ide_attach, 419 .probe = ide_probe,
463 .remove = ide_detach, 420 .remove = ide_detach,
464 .id_table = ide_ids, 421 .id_table = ide_ids,
465 .suspend = ide_suspend,
466 .resume = ide_resume,
467}; 422};
468 423
469static int __init init_ide_cs(void) 424static int __init init_ide_cs(void)
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index c85b87cb59d1..3e677c4f8c28 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -440,7 +440,7 @@ static void __devinit init_hwif_via82cxxx(ide_hwif_t *hwif)
440 440
441 441
442#if defined(CONFIG_PPC_CHRP) && defined(CONFIG_PPC32) 442#if defined(CONFIG_PPC_CHRP) && defined(CONFIG_PPC32)
443 if(_machine == _MACH_chrp && _chrp_type == _CHRP_Pegasos) { 443 if(machine_is(chrp) && _chrp_type == _CHRP_Pegasos) {
444 hwif->irq = hwif->channel ? 15 : 14; 444 hwif->irq = hwif->channel ? 15 : 14;
445 } 445 }
446#endif 446#endif
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 5013b1285e22..78e30f803671 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1677,7 +1677,7 @@ MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
1677void __init 1677void __init
1678pmac_ide_probe(void) 1678pmac_ide_probe(void)
1679{ 1679{
1680 if (_machine != _MACH_Pmac) 1680 if (!machine_is(powermac))
1681 return; 1681 return;
1682 1682
1683#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST 1683#ifdef CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST
diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
index a86beeb6af5d..19222878aae9 100644
--- a/drivers/ieee1394/ohci1394.c
+++ b/drivers/ieee1394/ohci1394.c
@@ -3529,7 +3529,7 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
3529static int ohci1394_pci_resume (struct pci_dev *pdev) 3529static int ohci1394_pci_resume (struct pci_dev *pdev)
3530{ 3530{
3531#ifdef CONFIG_PPC_PMAC 3531#ifdef CONFIG_PPC_PMAC
3532 if (_machine == _MACH_Pmac) { 3532 if (machine_is(powermac)) {
3533 struct device_node *of_node; 3533 struct device_node *of_node;
3534 3534
3535 /* Re-enable 1394 */ 3535 /* Re-enable 1394 */
@@ -3548,7 +3548,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
3548static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3548static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
3549{ 3549{
3550#ifdef CONFIG_PPC_PMAC 3550#ifdef CONFIG_PPC_PMAC
3551 if (_machine == _MACH_Pmac) { 3551 if (machine_is(powermac)) {
3552 struct device_node *of_node; 3552 struct device_node *of_node;
3553 3553
3554 /* Disable 1394 */ 3554 /* Disable 1394 */
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 2c765ca5aa50..f4206604db03 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -496,22 +496,17 @@ static struct sbp2_command_info *sbp2util_find_command_for_orb(
496/* 496/*
497 * This function finds the sbp2_command for a given outstanding SCpnt. 497 * This function finds the sbp2_command for a given outstanding SCpnt.
498 * Only looks at the inuse list. 498 * Only looks at the inuse list.
499 * Must be called with scsi_id->sbp2_command_orb_lock held.
499 */ 500 */
500static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(struct scsi_id_instance_data *scsi_id, void *SCpnt) 501static struct sbp2_command_info *sbp2util_find_command_for_SCpnt(
502 struct scsi_id_instance_data *scsi_id, void *SCpnt)
501{ 503{
502 struct sbp2_command_info *command; 504 struct sbp2_command_info *command;
503 unsigned long flags;
504 505
505 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); 506 if (!list_empty(&scsi_id->sbp2_command_orb_inuse))
506 if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) { 507 list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list)
507 list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { 508 if (command->Current_SCpnt == SCpnt)
508 if (command->Current_SCpnt == SCpnt) {
509 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
510 return command; 509 return command;
511 }
512 }
513 }
514 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
515 return NULL; 510 return NULL;
516} 511}
517 512
@@ -580,17 +575,15 @@ static void sbp2util_free_command_dma(struct sbp2_command_info *command)
580 575
581/* 576/*
582 * This function moves a command to the completed orb list. 577 * This function moves a command to the completed orb list.
578 * Must be called with scsi_id->sbp2_command_orb_lock held.
583 */ 579 */
584static void sbp2util_mark_command_completed(struct scsi_id_instance_data *scsi_id, 580static void sbp2util_mark_command_completed(
585 struct sbp2_command_info *command) 581 struct scsi_id_instance_data *scsi_id,
582 struct sbp2_command_info *command)
586{ 583{
587 unsigned long flags;
588
589 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
590 list_del(&command->list); 584 list_del(&command->list);
591 sbp2util_free_command_dma(command); 585 sbp2util_free_command_dma(command);
592 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); 586 list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed);
593 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
594} 587}
595 588
596/* 589/*
@@ -2148,7 +2141,9 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest
2148 * Matched status with command, now grab scsi command pointers and check status 2141 * Matched status with command, now grab scsi command pointers and check status
2149 */ 2142 */
2150 SCpnt = command->Current_SCpnt; 2143 SCpnt = command->Current_SCpnt;
2144 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
2151 sbp2util_mark_command_completed(scsi_id, command); 2145 sbp2util_mark_command_completed(scsi_id, command);
2146 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
2152 2147
2153 if (SCpnt) { 2148 if (SCpnt) {
2154 2149
@@ -2484,6 +2479,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2484 (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; 2479 (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0];
2485 struct sbp2scsi_host_info *hi = scsi_id->hi; 2480 struct sbp2scsi_host_info *hi = scsi_id->hi;
2486 struct sbp2_command_info *command; 2481 struct sbp2_command_info *command;
2482 unsigned long flags;
2487 2483
2488 SBP2_ERR("aborting sbp2 command"); 2484 SBP2_ERR("aborting sbp2 command");
2489 scsi_print_command(SCpnt); 2485 scsi_print_command(SCpnt);
@@ -2494,6 +2490,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2494 * Right now, just return any matching command structures 2490 * Right now, just return any matching command structures
2495 * to the free pool. 2491 * to the free pool.
2496 */ 2492 */
2493 spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags);
2497 command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt); 2494 command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt);
2498 if (command) { 2495 if (command) {
2499 SBP2_DEBUG("Found command to abort"); 2496 SBP2_DEBUG("Found command to abort");
@@ -2511,6 +2508,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2511 command->Current_done(command->Current_SCpnt); 2508 command->Current_done(command->Current_SCpnt);
2512 } 2509 }
2513 } 2510 }
2511 spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags);
2514 2512
2515 /* 2513 /*
2516 * Initiate a fetch agent reset. 2514 * Initiate a fetch agent reset.
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index bdf0891a92dd..afc612b8577d 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -30,6 +30,7 @@ config INFINIBAND_USER_ACCESS
30 <http://www.openib.org>. 30 <http://www.openib.org>.
31 31
32source "drivers/infiniband/hw/mthca/Kconfig" 32source "drivers/infiniband/hw/mthca/Kconfig"
33source "drivers/infiniband/hw/ipath/Kconfig"
33 34
34source "drivers/infiniband/ulp/ipoib/Kconfig" 35source "drivers/infiniband/ulp/ipoib/Kconfig"
35 36
diff --git a/drivers/infiniband/Makefile b/drivers/infiniband/Makefile
index a43fb34cca94..eea27322a22d 100644
--- a/drivers/infiniband/Makefile
+++ b/drivers/infiniband/Makefile
@@ -1,4 +1,5 @@
1obj-$(CONFIG_INFINIBAND) += core/ 1obj-$(CONFIG_INFINIBAND) += core/
2obj-$(CONFIG_INFINIBAND_MTHCA) += hw/mthca/ 2obj-$(CONFIG_INFINIBAND_MTHCA) += hw/mthca/
3obj-$(CONFIG_IPATH_CORE) += hw/ipath/
3obj-$(CONFIG_INFINIBAND_IPOIB) += ulp/ipoib/ 4obj-$(CONFIG_INFINIBAND_IPOIB) += ulp/ipoib/
4obj-$(CONFIG_INFINIBAND_SRP) += ulp/srp/ 5obj-$(CONFIG_INFINIBAND_SRP) += ulp/srp/
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index c57a3871184c..50364c0b090c 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -302,7 +302,7 @@ static void ib_cache_setup_one(struct ib_device *device)
302 kmalloc(sizeof *device->cache.pkey_cache * 302 kmalloc(sizeof *device->cache.pkey_cache *
303 (end_port(device) - start_port(device) + 1), GFP_KERNEL); 303 (end_port(device) - start_port(device) + 1), GFP_KERNEL);
304 device->cache.gid_cache = 304 device->cache.gid_cache =
305 kmalloc(sizeof *device->cache.pkey_cache * 305 kmalloc(sizeof *device->cache.gid_cache *
306 (end_port(device) - start_port(device) + 1), GFP_KERNEL); 306 (end_port(device) - start_port(device) + 1), GFP_KERNEL);
307 307
308 if (!device->cache.pkey_cache || !device->cache.gid_cache) { 308 if (!device->cache.pkey_cache || !device->cache.gid_cache) {
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index f7854b65fd55..3a702da83e41 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -227,6 +227,14 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
227 if (!is_vendor_oui(mad_reg_req->oui)) 227 if (!is_vendor_oui(mad_reg_req->oui))
228 goto error1; 228 goto error1;
229 } 229 }
230 /* Make sure class supplied is consistent with RMPP */
231 if (ib_is_mad_class_rmpp(mad_reg_req->mgmt_class)) {
232 if (!rmpp_version)
233 goto error1;
234 } else {
235 if (rmpp_version)
236 goto error1;
237 }
230 /* Make sure class supplied is consistent with QP type */ 238 /* Make sure class supplied is consistent with QP type */
231 if (qp_type == IB_QPT_SMI) { 239 if (qp_type == IB_QPT_SMI) {
232 if ((mad_reg_req->mgmt_class != 240 if ((mad_reg_req->mgmt_class !=
@@ -890,6 +898,35 @@ struct ib_mad_send_buf * ib_create_send_mad(struct ib_mad_agent *mad_agent,
890} 898}
891EXPORT_SYMBOL(ib_create_send_mad); 899EXPORT_SYMBOL(ib_create_send_mad);
892 900
901int ib_get_mad_data_offset(u8 mgmt_class)
902{
903 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
904 return IB_MGMT_SA_HDR;
905 else if ((mgmt_class == IB_MGMT_CLASS_DEVICE_MGMT) ||
906 (mgmt_class == IB_MGMT_CLASS_DEVICE_ADM) ||
907 (mgmt_class == IB_MGMT_CLASS_BIS))
908 return IB_MGMT_DEVICE_HDR;
909 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
910 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
911 return IB_MGMT_VENDOR_HDR;
912 else
913 return IB_MGMT_MAD_HDR;
914}
915EXPORT_SYMBOL(ib_get_mad_data_offset);
916
917int ib_is_mad_class_rmpp(u8 mgmt_class)
918{
919 if ((mgmt_class == IB_MGMT_CLASS_SUBN_ADM) ||
920 (mgmt_class == IB_MGMT_CLASS_DEVICE_MGMT) ||
921 (mgmt_class == IB_MGMT_CLASS_DEVICE_ADM) ||
922 (mgmt_class == IB_MGMT_CLASS_BIS) ||
923 ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
924 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END)))
925 return 1;
926 return 0;
927}
928EXPORT_SYMBOL(ib_is_mad_class_rmpp);
929
893void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num) 930void *ib_get_rmpp_segment(struct ib_mad_send_buf *send_buf, int seg_num)
894{ 931{
895 struct ib_mad_send_wr_private *mad_send_wr; 932 struct ib_mad_send_wr_private *mad_send_wr;
@@ -1022,6 +1059,13 @@ int ib_post_send_mad(struct ib_mad_send_buf *send_buf,
1022 goto error; 1059 goto error;
1023 } 1060 }
1024 1061
1062 if (!ib_is_mad_class_rmpp(((struct ib_mad_hdr *) send_buf->mad)->mgmt_class)) {
1063 if (mad_agent_priv->agent.rmpp_version) {
1064 ret = -EINVAL;
1065 goto error;
1066 }
1067 }
1068
1025 /* 1069 /*
1026 * Save pointer to next work request to post in case the 1070 * Save pointer to next work request to post in case the
1027 * current one completes, and the user modifies the work 1071 * current one completes, and the user modifies the work
@@ -1618,14 +1662,59 @@ static int is_data_mad(struct ib_mad_agent_private *mad_agent_priv,
1618 (rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_DATA); 1662 (rmpp_mad->rmpp_hdr.rmpp_type == IB_MGMT_RMPP_TYPE_DATA);
1619} 1663}
1620 1664
1665static inline int rcv_has_same_class(struct ib_mad_send_wr_private *wr,
1666 struct ib_mad_recv_wc *rwc)
1667{
1668 return ((struct ib_mad *)(wr->send_buf.mad))->mad_hdr.mgmt_class ==
1669 rwc->recv_buf.mad->mad_hdr.mgmt_class;
1670}
1671
1672static inline int rcv_has_same_gid(struct ib_mad_send_wr_private *wr,
1673 struct ib_mad_recv_wc *rwc )
1674{
1675 struct ib_ah_attr attr;
1676 u8 send_resp, rcv_resp;
1677
1678 send_resp = ((struct ib_mad *)(wr->send_buf.mad))->
1679 mad_hdr.method & IB_MGMT_METHOD_RESP;
1680 rcv_resp = rwc->recv_buf.mad->mad_hdr.method & IB_MGMT_METHOD_RESP;
1681
1682 if (!send_resp && rcv_resp)
1683 /* is request/response. GID/LIDs are both local (same). */
1684 return 1;
1685
1686 if (send_resp == rcv_resp)
1687 /* both requests, or both responses. GIDs different */
1688 return 0;
1689
1690 if (ib_query_ah(wr->send_buf.ah, &attr))
1691 /* Assume not equal, to avoid false positives. */
1692 return 0;
1693
1694 if (!(attr.ah_flags & IB_AH_GRH) && !(rwc->wc->wc_flags & IB_WC_GRH))
1695 return attr.dlid == rwc->wc->slid;
1696 else if ((attr.ah_flags & IB_AH_GRH) &&
1697 (rwc->wc->wc_flags & IB_WC_GRH))
1698 return memcmp(attr.grh.dgid.raw,
1699 rwc->recv_buf.grh->sgid.raw, 16) == 0;
1700 else
1701 /* one has GID, other does not. Assume different */
1702 return 0;
1703}
1621struct ib_mad_send_wr_private* 1704struct ib_mad_send_wr_private*
1622ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, __be64 tid) 1705ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv,
1706 struct ib_mad_recv_wc *mad_recv_wc)
1623{ 1707{
1624 struct ib_mad_send_wr_private *mad_send_wr; 1708 struct ib_mad_send_wr_private *mad_send_wr;
1709 struct ib_mad *mad;
1710
1711 mad = (struct ib_mad *)mad_recv_wc->recv_buf.mad;
1625 1712
1626 list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list, 1713 list_for_each_entry(mad_send_wr, &mad_agent_priv->wait_list,
1627 agent_list) { 1714 agent_list) {
1628 if (mad_send_wr->tid == tid) 1715 if ((mad_send_wr->tid == mad->mad_hdr.tid) &&
1716 rcv_has_same_class(mad_send_wr, mad_recv_wc) &&
1717 rcv_has_same_gid(mad_send_wr, mad_recv_wc))
1629 return mad_send_wr; 1718 return mad_send_wr;
1630 } 1719 }
1631 1720
@@ -1636,7 +1725,10 @@ ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, __be64 tid)
1636 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list, 1725 list_for_each_entry(mad_send_wr, &mad_agent_priv->send_list,
1637 agent_list) { 1726 agent_list) {
1638 if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) && 1727 if (is_data_mad(mad_agent_priv, mad_send_wr->send_buf.mad) &&
1639 mad_send_wr->tid == tid && mad_send_wr->timeout) { 1728 mad_send_wr->tid == mad->mad_hdr.tid &&
1729 mad_send_wr->timeout &&
1730 rcv_has_same_class(mad_send_wr, mad_recv_wc) &&
1731 rcv_has_same_gid(mad_send_wr, mad_recv_wc)) {
1640 /* Verify request has not been canceled */ 1732 /* Verify request has not been canceled */
1641 return (mad_send_wr->status == IB_WC_SUCCESS) ? 1733 return (mad_send_wr->status == IB_WC_SUCCESS) ?
1642 mad_send_wr : NULL; 1734 mad_send_wr : NULL;
@@ -1661,7 +1753,6 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
1661 struct ib_mad_send_wr_private *mad_send_wr; 1753 struct ib_mad_send_wr_private *mad_send_wr;
1662 struct ib_mad_send_wc mad_send_wc; 1754 struct ib_mad_send_wc mad_send_wc;
1663 unsigned long flags; 1755 unsigned long flags;
1664 __be64 tid;
1665 1756
1666 INIT_LIST_HEAD(&mad_recv_wc->rmpp_list); 1757 INIT_LIST_HEAD(&mad_recv_wc->rmpp_list);
1667 list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list); 1758 list_add(&mad_recv_wc->recv_buf.list, &mad_recv_wc->rmpp_list);
@@ -1677,9 +1768,8 @@ static void ib_mad_complete_recv(struct ib_mad_agent_private *mad_agent_priv,
1677 1768
1678 /* Complete corresponding request */ 1769 /* Complete corresponding request */
1679 if (response_mad(mad_recv_wc->recv_buf.mad)) { 1770 if (response_mad(mad_recv_wc->recv_buf.mad)) {
1680 tid = mad_recv_wc->recv_buf.mad->mad_hdr.tid;
1681 spin_lock_irqsave(&mad_agent_priv->lock, flags); 1771 spin_lock_irqsave(&mad_agent_priv->lock, flags);
1682 mad_send_wr = ib_find_send_mad(mad_agent_priv, tid); 1772 mad_send_wr = ib_find_send_mad(mad_agent_priv, mad_recv_wc);
1683 if (!mad_send_wr) { 1773 if (!mad_send_wr) {
1684 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 1774 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
1685 ib_free_recv_mad(mad_recv_wc); 1775 ib_free_recv_mad(mad_recv_wc);
@@ -2221,6 +2311,7 @@ static void local_completions(void *data)
2221 local = list_entry(mad_agent_priv->local_list.next, 2311 local = list_entry(mad_agent_priv->local_list.next,
2222 struct ib_mad_local_private, 2312 struct ib_mad_local_private,
2223 completion_list); 2313 completion_list);
2314 list_del(&local->completion_list);
2224 spin_unlock_irqrestore(&mad_agent_priv->lock, flags); 2315 spin_unlock_irqrestore(&mad_agent_priv->lock, flags);
2225 if (local->mad_priv) { 2316 if (local->mad_priv) {
2226 recv_mad_agent = local->recv_mad_agent; 2317 recv_mad_agent = local->recv_mad_agent;
@@ -2272,7 +2363,6 @@ local_send_completion:
2272 &mad_send_wc); 2363 &mad_send_wc);
2273 2364
2274 spin_lock_irqsave(&mad_agent_priv->lock, flags); 2365 spin_lock_irqsave(&mad_agent_priv->lock, flags);
2275 list_del(&local->completion_list);
2276 atomic_dec(&mad_agent_priv->refcount); 2366 atomic_dec(&mad_agent_priv->refcount);
2277 if (!recv) 2367 if (!recv)
2278 kmem_cache_free(ib_mad_cache, local->mad_priv); 2368 kmem_cache_free(ib_mad_cache, local->mad_priv);
@@ -2408,11 +2498,11 @@ static int ib_mad_post_receive_mads(struct ib_mad_qp_info *qp_info,
2408 } 2498 }
2409 } 2499 }
2410 sg_list.addr = dma_map_single(qp_info->port_priv-> 2500 sg_list.addr = dma_map_single(qp_info->port_priv->
2411 device->dma_device, 2501 device->dma_device,
2412 &mad_priv->grh, 2502 &mad_priv->grh,
2413 sizeof *mad_priv - 2503 sizeof *mad_priv -
2414 sizeof mad_priv->header, 2504 sizeof mad_priv->header,
2415 DMA_FROM_DEVICE); 2505 DMA_FROM_DEVICE);
2416 pci_unmap_addr_set(&mad_priv->header, mapping, sg_list.addr); 2506 pci_unmap_addr_set(&mad_priv->header, mapping, sg_list.addr);
2417 recv_wr.wr_id = (unsigned long)&mad_priv->header.mad_list; 2507 recv_wr.wr_id = (unsigned long)&mad_priv->header.mad_list;
2418 mad_priv->header.mad_list.mad_queue = recv_queue; 2508 mad_priv->header.mad_list.mad_queue = recv_queue;
diff --git a/drivers/infiniband/core/mad_priv.h b/drivers/infiniband/core/mad_priv.h
index a7125d4b5ccf..6c9c133d71ef 100644
--- a/drivers/infiniband/core/mad_priv.h
+++ b/drivers/infiniband/core/mad_priv.h
@@ -216,7 +216,8 @@ extern kmem_cache_t *ib_mad_cache;
216int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr); 216int ib_send_mad(struct ib_mad_send_wr_private *mad_send_wr);
217 217
218struct ib_mad_send_wr_private * 218struct ib_mad_send_wr_private *
219ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv, __be64 tid); 219ib_find_send_mad(struct ib_mad_agent_private *mad_agent_priv,
220 struct ib_mad_recv_wc *mad_recv_wc);
220 221
221void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr, 222void ib_mad_complete_send_wr(struct ib_mad_send_wr_private *mad_send_wr,
222 struct ib_mad_send_wc *mad_send_wc); 223 struct ib_mad_send_wc *mad_send_wc);
diff --git a/drivers/infiniband/core/mad_rmpp.c b/drivers/infiniband/core/mad_rmpp.c
index bacfdd5bddad..dfd4e588ce03 100644
--- a/drivers/infiniband/core/mad_rmpp.c
+++ b/drivers/infiniband/core/mad_rmpp.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Intel Inc. All rights reserved. 2 * Copyright (c) 2005 Intel Inc. All rights reserved.
3 * Copyright (c) 2005 Voltaire, Inc. All rights reserved. 3 * Copyright (c) 2005-2006 Voltaire, Inc. All rights reserved.
4 * 4 *
5 * This software is available to you under a choice of one of two 5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU 6 * licenses. You may choose to be licensed under the terms of the GNU
@@ -100,17 +100,6 @@ void ib_cancel_rmpp_recvs(struct ib_mad_agent_private *agent)
100 } 100 }
101} 101}
102 102
103static int data_offset(u8 mgmt_class)
104{
105 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
106 return IB_MGMT_SA_HDR;
107 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
108 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
109 return IB_MGMT_VENDOR_HDR;
110 else
111 return IB_MGMT_RMPP_HDR;
112}
113
114static void format_ack(struct ib_mad_send_buf *msg, 103static void format_ack(struct ib_mad_send_buf *msg,
115 struct ib_rmpp_mad *data, 104 struct ib_rmpp_mad *data,
116 struct mad_rmpp_recv *rmpp_recv) 105 struct mad_rmpp_recv *rmpp_recv)
@@ -137,7 +126,7 @@ static void ack_recv(struct mad_rmpp_recv *rmpp_recv,
137 struct ib_mad_send_buf *msg; 126 struct ib_mad_send_buf *msg;
138 int ret, hdr_len; 127 int ret, hdr_len;
139 128
140 hdr_len = data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class); 129 hdr_len = ib_get_mad_data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
141 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp, 130 msg = ib_create_send_mad(&rmpp_recv->agent->agent, recv_wc->wc->src_qp,
142 recv_wc->wc->pkey_index, 1, hdr_len, 131 recv_wc->wc->pkey_index, 1, hdr_len,
143 0, GFP_KERNEL); 132 0, GFP_KERNEL);
@@ -163,7 +152,7 @@ static struct ib_mad_send_buf *alloc_response_msg(struct ib_mad_agent *agent,
163 if (IS_ERR(ah)) 152 if (IS_ERR(ah))
164 return (void *) ah; 153 return (void *) ah;
165 154
166 hdr_len = data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class); 155 hdr_len = ib_get_mad_data_offset(recv_wc->recv_buf.mad->mad_hdr.mgmt_class);
167 msg = ib_create_send_mad(agent, recv_wc->wc->src_qp, 156 msg = ib_create_send_mad(agent, recv_wc->wc->src_qp,
168 recv_wc->wc->pkey_index, 1, 157 recv_wc->wc->pkey_index, 1,
169 hdr_len, 0, GFP_KERNEL); 158 hdr_len, 0, GFP_KERNEL);
@@ -408,7 +397,7 @@ static inline int get_mad_len(struct mad_rmpp_recv *rmpp_recv)
408 397
409 rmpp_mad = (struct ib_rmpp_mad *)rmpp_recv->cur_seg_buf->mad; 398 rmpp_mad = (struct ib_rmpp_mad *)rmpp_recv->cur_seg_buf->mad;
410 399
411 hdr_size = data_offset(rmpp_mad->mad_hdr.mgmt_class); 400 hdr_size = ib_get_mad_data_offset(rmpp_mad->mad_hdr.mgmt_class);
412 data_size = sizeof(struct ib_rmpp_mad) - hdr_size; 401 data_size = sizeof(struct ib_rmpp_mad) - hdr_size;
413 pad = IB_MGMT_RMPP_DATA - be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin); 402 pad = IB_MGMT_RMPP_DATA - be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
414 if (pad > IB_MGMT_RMPP_DATA || pad < 0) 403 if (pad > IB_MGMT_RMPP_DATA || pad < 0)
@@ -562,15 +551,15 @@ static int send_next_seg(struct ib_mad_send_wr_private *mad_send_wr)
562 return ib_send_mad(mad_send_wr); 551 return ib_send_mad(mad_send_wr);
563} 552}
564 553
565static void abort_send(struct ib_mad_agent_private *agent, __be64 tid, 554static void abort_send(struct ib_mad_agent_private *agent,
566 u8 rmpp_status) 555 struct ib_mad_recv_wc *mad_recv_wc, u8 rmpp_status)
567{ 556{
568 struct ib_mad_send_wr_private *mad_send_wr; 557 struct ib_mad_send_wr_private *mad_send_wr;
569 struct ib_mad_send_wc wc; 558 struct ib_mad_send_wc wc;
570 unsigned long flags; 559 unsigned long flags;
571 560
572 spin_lock_irqsave(&agent->lock, flags); 561 spin_lock_irqsave(&agent->lock, flags);
573 mad_send_wr = ib_find_send_mad(agent, tid); 562 mad_send_wr = ib_find_send_mad(agent, mad_recv_wc);
574 if (!mad_send_wr) 563 if (!mad_send_wr)
575 goto out; /* Unmatched send */ 564 goto out; /* Unmatched send */
576 565
@@ -612,8 +601,7 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
612 601
613 rmpp_mad = (struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad; 602 rmpp_mad = (struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad;
614 if (rmpp_mad->rmpp_hdr.rmpp_status) { 603 if (rmpp_mad->rmpp_hdr.rmpp_status) {
615 abort_send(agent, rmpp_mad->mad_hdr.tid, 604 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS);
616 IB_MGMT_RMPP_STATUS_BAD_STATUS);
617 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS); 605 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS);
618 return; 606 return;
619 } 607 }
@@ -621,14 +609,13 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
621 seg_num = be32_to_cpu(rmpp_mad->rmpp_hdr.seg_num); 609 seg_num = be32_to_cpu(rmpp_mad->rmpp_hdr.seg_num);
622 newwin = be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin); 610 newwin = be32_to_cpu(rmpp_mad->rmpp_hdr.paylen_newwin);
623 if (newwin < seg_num) { 611 if (newwin < seg_num) {
624 abort_send(agent, rmpp_mad->mad_hdr.tid, 612 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_W2S);
625 IB_MGMT_RMPP_STATUS_W2S);
626 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_W2S); 613 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_W2S);
627 return; 614 return;
628 } 615 }
629 616
630 spin_lock_irqsave(&agent->lock, flags); 617 spin_lock_irqsave(&agent->lock, flags);
631 mad_send_wr = ib_find_send_mad(agent, rmpp_mad->mad_hdr.tid); 618 mad_send_wr = ib_find_send_mad(agent, mad_recv_wc);
632 if (!mad_send_wr) 619 if (!mad_send_wr)
633 goto out; /* Unmatched ACK */ 620 goto out; /* Unmatched ACK */
634 621
@@ -639,8 +626,7 @@ static void process_rmpp_ack(struct ib_mad_agent_private *agent,
639 if (seg_num > mad_send_wr->send_buf.seg_count || 626 if (seg_num > mad_send_wr->send_buf.seg_count ||
640 seg_num > mad_send_wr->newwin) { 627 seg_num > mad_send_wr->newwin) {
641 spin_unlock_irqrestore(&agent->lock, flags); 628 spin_unlock_irqrestore(&agent->lock, flags);
642 abort_send(agent, rmpp_mad->mad_hdr.tid, 629 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_S2B);
643 IB_MGMT_RMPP_STATUS_S2B);
644 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_S2B); 630 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_S2B);
645 return; 631 return;
646 } 632 }
@@ -728,12 +714,10 @@ static void process_rmpp_stop(struct ib_mad_agent_private *agent,
728 rmpp_mad = (struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad; 714 rmpp_mad = (struct ib_rmpp_mad *)mad_recv_wc->recv_buf.mad;
729 715
730 if (rmpp_mad->rmpp_hdr.rmpp_status != IB_MGMT_RMPP_STATUS_RESX) { 716 if (rmpp_mad->rmpp_hdr.rmpp_status != IB_MGMT_RMPP_STATUS_RESX) {
731 abort_send(agent, rmpp_mad->mad_hdr.tid, 717 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS);
732 IB_MGMT_RMPP_STATUS_BAD_STATUS);
733 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS); 718 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS);
734 } else 719 } else
735 abort_send(agent, rmpp_mad->mad_hdr.tid, 720 abort_send(agent, mad_recv_wc, rmpp_mad->rmpp_hdr.rmpp_status);
736 rmpp_mad->rmpp_hdr.rmpp_status);
737} 721}
738 722
739static void process_rmpp_abort(struct ib_mad_agent_private *agent, 723static void process_rmpp_abort(struct ib_mad_agent_private *agent,
@@ -745,12 +729,10 @@ static void process_rmpp_abort(struct ib_mad_agent_private *agent,
745 729
746 if (rmpp_mad->rmpp_hdr.rmpp_status < IB_MGMT_RMPP_STATUS_ABORT_MIN || 730 if (rmpp_mad->rmpp_hdr.rmpp_status < IB_MGMT_RMPP_STATUS_ABORT_MIN ||
747 rmpp_mad->rmpp_hdr.rmpp_status > IB_MGMT_RMPP_STATUS_ABORT_MAX) { 731 rmpp_mad->rmpp_hdr.rmpp_status > IB_MGMT_RMPP_STATUS_ABORT_MAX) {
748 abort_send(agent, rmpp_mad->mad_hdr.tid, 732 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS);
749 IB_MGMT_RMPP_STATUS_BAD_STATUS);
750 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS); 733 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BAD_STATUS);
751 } else 734 } else
752 abort_send(agent, rmpp_mad->mad_hdr.tid, 735 abort_send(agent, mad_recv_wc, rmpp_mad->rmpp_hdr.rmpp_status);
753 rmpp_mad->rmpp_hdr.rmpp_status);
754} 736}
755 737
756struct ib_mad_recv_wc * 738struct ib_mad_recv_wc *
@@ -764,8 +746,7 @@ ib_process_rmpp_recv_wc(struct ib_mad_agent_private *agent,
764 return mad_recv_wc; 746 return mad_recv_wc;
765 747
766 if (rmpp_mad->rmpp_hdr.rmpp_version != IB_MGMT_RMPP_VERSION) { 748 if (rmpp_mad->rmpp_hdr.rmpp_version != IB_MGMT_RMPP_VERSION) {
767 abort_send(agent, rmpp_mad->mad_hdr.tid, 749 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_UNV);
768 IB_MGMT_RMPP_STATUS_UNV);
769 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_UNV); 750 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_UNV);
770 goto out; 751 goto out;
771 } 752 }
@@ -783,8 +764,7 @@ ib_process_rmpp_recv_wc(struct ib_mad_agent_private *agent,
783 process_rmpp_abort(agent, mad_recv_wc); 764 process_rmpp_abort(agent, mad_recv_wc);
784 break; 765 break;
785 default: 766 default:
786 abort_send(agent, rmpp_mad->mad_hdr.tid, 767 abort_send(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BADT);
787 IB_MGMT_RMPP_STATUS_BADT);
788 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BADT); 768 nack_recv(agent, mad_recv_wc, IB_MGMT_RMPP_STATUS_BADT);
789 break; 769 break;
790 } 770 }
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index fb6cd42601f9..afe70a549c2f 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -177,17 +177,6 @@ static int queue_packet(struct ib_umad_file *file,
177 return ret; 177 return ret;
178} 178}
179 179
180static int data_offset(u8 mgmt_class)
181{
182 if (mgmt_class == IB_MGMT_CLASS_SUBN_ADM)
183 return IB_MGMT_SA_HDR;
184 else if ((mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START) &&
185 (mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END))
186 return IB_MGMT_VENDOR_HDR;
187 else
188 return IB_MGMT_RMPP_HDR;
189}
190
191static void send_handler(struct ib_mad_agent *agent, 180static void send_handler(struct ib_mad_agent *agent,
192 struct ib_mad_send_wc *send_wc) 181 struct ib_mad_send_wc *send_wc)
193{ 182{
@@ -283,7 +272,7 @@ static ssize_t copy_recv_mad(char __user *buf, struct ib_umad_packet *packet,
283 */ 272 */
284 return -ENOSPC; 273 return -ENOSPC;
285 } 274 }
286 offset = data_offset(recv_buf->mad->mad_hdr.mgmt_class); 275 offset = ib_get_mad_data_offset(recv_buf->mad->mad_hdr.mgmt_class);
287 max_seg_payload = sizeof (struct ib_mad) - offset; 276 max_seg_payload = sizeof (struct ib_mad) - offset;
288 277
289 for (left = packet->length - seg_payload, buf += seg_payload; 278 for (left = packet->length - seg_payload, buf += seg_payload;
@@ -441,21 +430,14 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
441 } 430 }
442 431
443 rmpp_mad = (struct ib_rmpp_mad *) packet->mad.data; 432 rmpp_mad = (struct ib_rmpp_mad *) packet->mad.data;
444 if (rmpp_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_ADM) { 433 hdr_len = ib_get_mad_data_offset(rmpp_mad->mad_hdr.mgmt_class);
445 hdr_len = IB_MGMT_SA_HDR; 434 if (!ib_is_mad_class_rmpp(rmpp_mad->mad_hdr.mgmt_class)) {
446 copy_offset = IB_MGMT_RMPP_HDR; 435 copy_offset = IB_MGMT_MAD_HDR;
447 rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 436 rmpp_active = 0;
448 IB_MGMT_RMPP_FLAG_ACTIVE; 437 } else {
449 } else if (rmpp_mad->mad_hdr.mgmt_class >= IB_MGMT_CLASS_VENDOR_RANGE2_START &&
450 rmpp_mad->mad_hdr.mgmt_class <= IB_MGMT_CLASS_VENDOR_RANGE2_END) {
451 hdr_len = IB_MGMT_VENDOR_HDR;
452 copy_offset = IB_MGMT_RMPP_HDR; 438 copy_offset = IB_MGMT_RMPP_HDR;
453 rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) & 439 rmpp_active = ib_get_rmpp_flags(&rmpp_mad->rmpp_hdr) &
454 IB_MGMT_RMPP_FLAG_ACTIVE; 440 IB_MGMT_RMPP_FLAG_ACTIVE;
455 } else {
456 hdr_len = IB_MGMT_MAD_HDR;
457 copy_offset = IB_MGMT_MAD_HDR;
458 rmpp_active = 0;
459 } 441 }
460 442
461 data_len = count - sizeof (struct ib_user_mad) - hdr_len; 443 data_len = count - sizeof (struct ib_user_mad) - hdr_len;
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index cae0845f472a..b78e7dc69330 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -45,6 +45,40 @@
45#include <rdma/ib_verbs.h> 45#include <rdma/ib_verbs.h>
46#include <rdma/ib_cache.h> 46#include <rdma/ib_cache.h>
47 47
48int ib_rate_to_mult(enum ib_rate rate)
49{
50 switch (rate) {
51 case IB_RATE_2_5_GBPS: return 1;
52 case IB_RATE_5_GBPS: return 2;
53 case IB_RATE_10_GBPS: return 4;
54 case IB_RATE_20_GBPS: return 8;
55 case IB_RATE_30_GBPS: return 12;
56 case IB_RATE_40_GBPS: return 16;
57 case IB_RATE_60_GBPS: return 24;
58 case IB_RATE_80_GBPS: return 32;
59 case IB_RATE_120_GBPS: return 48;
60 default: return -1;
61 }
62}
63EXPORT_SYMBOL(ib_rate_to_mult);
64
65enum ib_rate mult_to_ib_rate(int mult)
66{
67 switch (mult) {
68 case 1: return IB_RATE_2_5_GBPS;
69 case 2: return IB_RATE_5_GBPS;
70 case 4: return IB_RATE_10_GBPS;
71 case 8: return IB_RATE_20_GBPS;
72 case 12: return IB_RATE_30_GBPS;
73 case 16: return IB_RATE_40_GBPS;
74 case 24: return IB_RATE_60_GBPS;
75 case 32: return IB_RATE_80_GBPS;
76 case 48: return IB_RATE_120_GBPS;
77 default: return IB_RATE_PORT_CURRENT;
78 }
79}
80EXPORT_SYMBOL(mult_to_ib_rate);
81
48/* Protection domains */ 82/* Protection domains */
49 83
50struct ib_pd *ib_alloc_pd(struct ib_device *device) 84struct ib_pd *ib_alloc_pd(struct ib_device *device)
diff --git a/drivers/infiniband/hw/ipath/Kconfig b/drivers/infiniband/hw/ipath/Kconfig
new file mode 100644
index 000000000000..9ea67c409b6d
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/Kconfig
@@ -0,0 +1,16 @@
1config IPATH_CORE
2 tristate "PathScale InfiniPath Driver"
3 depends on 64BIT && PCI_MSI && NET
4 ---help---
5 This is a low-level driver for PathScale InfiniPath host channel
6 adapters (HCAs) based on the HT-400 and PE-800 chips.
7
8config INFINIBAND_IPATH
9 tristate "PathScale InfiniPath Verbs Driver"
10 depends on IPATH_CORE && INFINIBAND
11 ---help---
12 This is a driver that provides InfiniBand verbs support for
13 PathScale InfiniPath host channel adapters (HCAs). This
14 allows these devices to be used with both kernel upper level
15 protocols such as IP-over-InfiniBand as well as with userspace
16 applications (in conjunction with InfiniBand userspace access).
diff --git a/drivers/infiniband/hw/ipath/Makefile b/drivers/infiniband/hw/ipath/Makefile
new file mode 100644
index 000000000000..b4d084abfd22
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/Makefile
@@ -0,0 +1,36 @@
1EXTRA_CFLAGS += -DIPATH_IDSTR='"PathScale kernel.org driver"' \
2 -DIPATH_KERN_TYPE=0
3
4obj-$(CONFIG_IPATH_CORE) += ipath_core.o
5obj-$(CONFIG_INFINIBAND_IPATH) += ib_ipath.o
6
7ipath_core-y := \
8 ipath_diag.o \
9 ipath_driver.o \
10 ipath_eeprom.o \
11 ipath_file_ops.o \
12 ipath_fs.o \
13 ipath_ht400.o \
14 ipath_init_chip.o \
15 ipath_intr.o \
16 ipath_layer.o \
17 ipath_pe800.o \
18 ipath_stats.o \
19 ipath_sysfs.o \
20 ipath_user_pages.o
21
22ipath_core-$(CONFIG_X86_64) += ipath_wc_x86_64.o
23
24ib_ipath-y := \
25 ipath_cq.o \
26 ipath_keys.o \
27 ipath_mad.o \
28 ipath_mr.o \
29 ipath_qp.o \
30 ipath_rc.o \
31 ipath_ruc.o \
32 ipath_srq.o \
33 ipath_uc.o \
34 ipath_ud.o \
35 ipath_verbs.o \
36 ipath_verbs_mcast.o
diff --git a/drivers/infiniband/hw/ipath/ipath_common.h b/drivers/infiniband/hw/ipath/ipath_common.h
new file mode 100644
index 000000000000..48a55247b832
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_common.h
@@ -0,0 +1,616 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _IPATH_COMMON_H
34#define _IPATH_COMMON_H
35
36/*
37 * This file contains defines, structures, etc. that are used
38 * to communicate between kernel and user code.
39 */
40
41/* This is the IEEE-assigned OUI for PathScale, Inc. */
42#define IPATH_SRC_OUI_1 0x00
43#define IPATH_SRC_OUI_2 0x11
44#define IPATH_SRC_OUI_3 0x75
45
46/* version of protocol header (known to chip also). In the long run,
47 * we should be able to generate and accept a range of version numbers;
48 * for now we only accept one, and it's compiled in.
49 */
50#define IPS_PROTO_VERSION 2
51
52/*
53 * These are compile time constants that you may want to enable or disable
54 * if you are trying to debug problems with code or performance.
55 * IPATH_VERBOSE_TRACING define as 1 if you want additional tracing in
56 * fastpath code
57 * IPATH_TRACE_REGWRITES define as 1 if you want register writes to be
58 * traced in faspath code
59 * _IPATH_TRACING define as 0 if you want to remove all tracing in a
60 * compilation unit
61 * _IPATH_DEBUGGING define as 0 if you want to remove debug prints
62 */
63
64/*
65 * The value in the BTH QP field that InfiniPath uses to differentiate
66 * an infinipath protocol IB packet vs standard IB transport
67 */
68#define IPATH_KD_QP 0x656b79
69
70/*
71 * valid states passed to ipath_set_linkstate() user call
72 */
73#define IPATH_IB_LINKDOWN 0
74#define IPATH_IB_LINKARM 1
75#define IPATH_IB_LINKACTIVE 2
76#define IPATH_IB_LINKINIT 3
77#define IPATH_IB_LINKDOWN_SLEEP 4
78#define IPATH_IB_LINKDOWN_DISABLE 5
79
80/*
81 * stats maintained by the driver. For now, at least, this is global
82 * to all minor devices.
83 */
84struct infinipath_stats {
85 /* number of interrupts taken */
86 __u64 sps_ints;
87 /* number of interrupts for errors */
88 __u64 sps_errints;
89 /* number of errors from chip (not incl. packet errors or CRC) */
90 __u64 sps_errs;
91 /* number of packet errors from chip other than CRC */
92 __u64 sps_pkterrs;
93 /* number of packets with CRC errors (ICRC and VCRC) */
94 __u64 sps_crcerrs;
95 /* number of hardware errors reported (parity, etc.) */
96 __u64 sps_hwerrs;
97 /* number of times IB link changed state unexpectedly */
98 __u64 sps_iblink;
99 /* no longer used; left for compatibility */
100 __u64 sps_unused3;
101 /* number of kernel (port0) packets received */
102 __u64 sps_port0pkts;
103 /* number of "ethernet" packets sent by driver */
104 __u64 sps_ether_spkts;
105 /* number of "ethernet" packets received by driver */
106 __u64 sps_ether_rpkts;
107 /* number of SMA packets sent by driver */
108 __u64 sps_sma_spkts;
109 /* number of SMA packets received by driver */
110 __u64 sps_sma_rpkts;
111 /* number of times all ports rcvhdrq was full and packet dropped */
112 __u64 sps_hdrqfull;
113 /* number of times all ports egrtid was full and packet dropped */
114 __u64 sps_etidfull;
115 /*
116 * number of times we tried to send from driver, but no pio buffers
117 * avail
118 */
119 __u64 sps_nopiobufs;
120 /* number of ports currently open */
121 __u64 sps_ports;
122 /* list of pkeys (other than default) accepted (0 means not set) */
123 __u16 sps_pkeys[4];
124 /* lids for up to 4 infinipaths, indexed by infinipath # */
125 __u16 sps_lid[4];
126 /* number of user ports per chip (not IB ports) */
127 __u32 sps_nports;
128 /* not our interrupt, or already handled */
129 __u32 sps_nullintr;
130 /* max number of packets handled per receive call */
131 __u32 sps_maxpkts_call;
132 /* avg number of packets handled per receive call */
133 __u32 sps_avgpkts_call;
134 /* total number of pages locked */
135 __u64 sps_pagelocks;
136 /* total number of pages unlocked */
137 __u64 sps_pageunlocks;
138 /*
139 * Number of packets dropped in kernel other than errors (ether
140 * packets if ipath not configured, sma/mad, etc.)
141 */
142 __u64 sps_krdrops;
143 /* mlids for up to 4 infinipaths, indexed by infinipath # */
144 __u16 sps_mlid[4];
145 /* pad for future growth */
146 __u64 __sps_pad[45];
147};
148
149/*
150 * These are the status bits readable (in ascii form, 64bit value)
151 * from the "status" sysfs file.
152 */
153#define IPATH_STATUS_INITTED 0x1 /* basic initialization done */
154#define IPATH_STATUS_DISABLED 0x2 /* hardware disabled */
155/* Device has been disabled via admin request */
156#define IPATH_STATUS_ADMIN_DISABLED 0x4
157#define IPATH_STATUS_OIB_SMA 0x8 /* ipath_mad kernel SMA running */
158#define IPATH_STATUS_SMA 0x10 /* user SMA running */
159/* Chip has been found and initted */
160#define IPATH_STATUS_CHIP_PRESENT 0x20
161/* IB link is at ACTIVE, usable for data traffic */
162#define IPATH_STATUS_IB_READY 0x40
163/* link is configured, LID, MTU, etc. have been set */
164#define IPATH_STATUS_IB_CONF 0x80
165/* no link established, probably no cable */
166#define IPATH_STATUS_IB_NOCABLE 0x100
167/* A Fatal hardware error has occurred. */
168#define IPATH_STATUS_HWERROR 0x200
169
170/*
171 * The list of usermode accessible registers. Also see Reg_* later in file.
172 */
173typedef enum _ipath_ureg {
174 /* (RO) DMA RcvHdr to be used next. */
175 ur_rcvhdrtail = 0,
176 /* (RW) RcvHdr entry to be processed next by host. */
177 ur_rcvhdrhead = 1,
178 /* (RO) Index of next Eager index to use. */
179 ur_rcvegrindextail = 2,
180 /* (RW) Eager TID to be processed next */
181 ur_rcvegrindexhead = 3,
182 /* For internal use only; max register number. */
183 _IPATH_UregMax
184} ipath_ureg;
185
186/* bit values for spi_runtime_flags */
187#define IPATH_RUNTIME_HT 0x1
188#define IPATH_RUNTIME_PCIE 0x2
189#define IPATH_RUNTIME_FORCE_WC_ORDER 0x4
190#define IPATH_RUNTIME_RCVHDR_COPY 0x8
191
192/*
193 * This structure is returned by ipath_userinit() immediately after
194 * open to get implementation-specific info, and info specific to this
195 * instance.
196 *
197 * This struct must have explict pad fields where type sizes
198 * may result in different alignments between 32 and 64 bit
199 * programs, since the 64 bit * bit kernel requires the user code
200 * to have matching offsets
201 */
202struct ipath_base_info {
203 /* version of hardware, for feature checking. */
204 __u32 spi_hw_version;
205 /* version of software, for feature checking. */
206 __u32 spi_sw_version;
207 /* InfiniPath port assigned, goes into sent packets */
208 __u32 spi_port;
209 /*
210 * IB MTU, packets IB data must be less than this.
211 * The MTU is in bytes, and will be a multiple of 4 bytes.
212 */
213 __u32 spi_mtu;
214 /*
215 * Size of a PIO buffer. Any given packet's total size must be less
216 * than this (in words). Included is the starting control word, so
217 * if 513 is returned, then total pkt size is 512 words or less.
218 */
219 __u32 spi_piosize;
220 /* size of the TID cache in infinipath, in entries */
221 __u32 spi_tidcnt;
222 /* size of the TID Eager list in infinipath, in entries */
223 __u32 spi_tidegrcnt;
224 /* size of a single receive header queue entry. */
225 __u32 spi_rcvhdrent_size;
226 /*
227 * Count of receive header queue entries allocated.
228 * This may be less than the spu_rcvhdrcnt passed in!.
229 */
230 __u32 spi_rcvhdr_cnt;
231
232 /* per-chip and other runtime features bitmap (IPATH_RUNTIME_*) */
233 __u32 spi_runtime_flags;
234
235 /* address where receive buffer queue is mapped into */
236 __u64 spi_rcvhdr_base;
237
238 /* user program. */
239
240 /* base address of eager TID receive buffers. */
241 __u64 spi_rcv_egrbufs;
242
243 /* Allocated by initialization code, not by protocol. */
244
245 /*
246 * Size of each TID buffer in host memory, starting at
247 * spi_rcv_egrbufs. The buffers are virtually contiguous.
248 */
249 __u32 spi_rcv_egrbufsize;
250 /*
251 * The special QP (queue pair) value that identifies an infinipath
252 * protocol packet from standard IB packets. More, probably much
253 * more, to be added.
254 */
255 __u32 spi_qpair;
256
257 /*
258 * User register base for init code, not to be used directly by
259 * protocol or applications.
260 */
261 __u64 __spi_uregbase;
262 /*
263 * Maximum buffer size in bytes that can be used in a single TID
264 * entry (assuming the buffer is aligned to this boundary). This is
265 * the minimum of what the hardware and software support Guaranteed
266 * to be a power of 2.
267 */
268 __u32 spi_tid_maxsize;
269 /*
270 * alignment of each pio send buffer (byte count
271 * to add to spi_piobufbase to get to second buffer)
272 */
273 __u32 spi_pioalign;
274 /*
275 * The index of the first pio buffer available to this process;
276 * needed to do lookup in spi_pioavailaddr; not added to
277 * spi_piobufbase.
278 */
279 __u32 spi_pioindex;
280 /* number of buffers mapped for this process */
281 __u32 spi_piocnt;
282
283 /*
284 * Base address of writeonly pio buffers for this process.
285 * Each buffer has spi_piosize words, and is aligned on spi_pioalign
286 * boundaries. spi_piocnt buffers are mapped from this address
287 */
288 __u64 spi_piobufbase;
289
290 /*
291 * Base address of readonly memory copy of the pioavail registers.
292 * There are 2 bits for each buffer.
293 */
294 __u64 spi_pioavailaddr;
295
296 /*
297 * Address where driver updates a copy of the interface and driver
298 * status (IPATH_STATUS_*) as a 64 bit value. It's followed by a
299 * string indicating hardware error, if there was one.
300 */
301 __u64 spi_status;
302
303 /* number of chip ports available to user processes */
304 __u32 spi_nports;
305 /* unit number of chip we are using */
306 __u32 spi_unit;
307 /* num bufs in each contiguous set */
308 __u32 spi_rcv_egrperchunk;
309 /* size in bytes of each contiguous set */
310 __u32 spi_rcv_egrchunksize;
311 /* total size of mmap to cover full rcvegrbuffers */
312 __u32 spi_rcv_egrbuftotlen;
313} __attribute__ ((aligned(8)));
314
315
316/*
317 * This version number is given to the driver by the user code during
318 * initialization in the spu_userversion field of ipath_user_info, so
319 * the driver can check for compatibility with user code.
320 *
321 * The major version changes when data structures
322 * change in an incompatible way. The driver must be the same or higher
323 * for initialization to succeed. In some cases, a higher version
324 * driver will not interoperate with older software, and initialization
325 * will return an error.
326 */
327#define IPATH_USER_SWMAJOR 1
328
329/*
330 * Minor version differences are always compatible
331 * a within a major version, however if if user software is larger
332 * than driver software, some new features and/or structure fields
333 * may not be implemented; the user code must deal with this if it
334 * cares, or it must abort after initialization reports the difference
335 */
336#define IPATH_USER_SWMINOR 2
337
338#define IPATH_USER_SWVERSION ((IPATH_USER_SWMAJOR<<16) | IPATH_USER_SWMINOR)
339
340#define IPATH_KERN_TYPE 0
341
342/*
343 * Similarly, this is the kernel version going back to the user. It's
344 * slightly different, in that we want to tell if the driver was built as
345 * part of a PathScale release, or from the driver from OpenIB, kernel.org,
346 * or a standard distribution, for support reasons. The high bit is 0 for
347 * non-PathScale, and 1 for PathScale-built/supplied.
348 *
349 * It's returned by the driver to the user code during initialization in the
350 * spi_sw_version field of ipath_base_info, so the user code can in turn
351 * check for compatibility with the kernel.
352*/
353#define IPATH_KERN_SWVERSION ((IPATH_KERN_TYPE<<31) | IPATH_USER_SWVERSION)
354
355/*
356 * This structure is passed to ipath_userinit() to tell the driver where
357 * user code buffers are, sizes, etc. The offsets and sizes of the
358 * fields must remain unchanged, for binary compatibility. It can
359 * be extended, if userversion is changed so user code can tell, if needed
360 */
361struct ipath_user_info {
362 /*
363 * version of user software, to detect compatibility issues.
364 * Should be set to IPATH_USER_SWVERSION.
365 */
366 __u32 spu_userversion;
367
368 /* desired number of receive header queue entries */
369 __u32 spu_rcvhdrcnt;
370
371 /* size of struct base_info to write to */
372 __u32 spu_base_info_size;
373
374 /*
375 * number of words in KD protocol header
376 * This tells InfiniPath how many words to copy to rcvhdrq. If 0,
377 * kernel uses a default. Once set, attempts to set any other value
378 * are an error (EAGAIN) until driver is reloaded.
379 */
380 __u32 spu_rcvhdrsize;
381
382 /*
383 * cache line aligned (64 byte) user address to
384 * which the rcvhdrtail register will be written by infinipath
385 * whenever it changes, so that no chip registers are read in
386 * the performance path.
387 */
388 __u64 spu_rcvhdraddr;
389
390 /*
391 * address of struct base_info to write to
392 */
393 __u64 spu_base_info;
394
395} __attribute__ ((aligned(8)));
396
397/* User commands. */
398
399#define IPATH_CMD_MIN 16
400
401#define IPATH_CMD_USER_INIT 16 /* set up userspace */
402#define IPATH_CMD_PORT_INFO 17 /* find out what resources we got */
403#define IPATH_CMD_RECV_CTRL 18 /* control receipt of packets */
404#define IPATH_CMD_TID_UPDATE 19 /* update expected TID entries */
405#define IPATH_CMD_TID_FREE 20 /* free expected TID entries */
406#define IPATH_CMD_SET_PART_KEY 21 /* add partition key */
407
408#define IPATH_CMD_MAX 21
409
410struct ipath_port_info {
411 __u32 num_active; /* number of active units */
412 __u32 unit; /* unit (chip) assigned to caller */
413 __u32 port; /* port on unit assigned to caller */
414};
415
416struct ipath_tid_info {
417 __u32 tidcnt;
418 /* make structure same size in 32 and 64 bit */
419 __u32 tid__unused;
420 /* virtual address of first page in transfer */
421 __u64 tidvaddr;
422 /* pointer (same size 32/64 bit) to __u16 tid array */
423 __u64 tidlist;
424
425 /*
426 * pointer (same size 32/64 bit) to bitmap of TIDs used
427 * for this call; checked for being large enough at open
428 */
429 __u64 tidmap;
430};
431
432struct ipath_cmd {
433 __u32 type; /* command type */
434 union {
435 struct ipath_tid_info tid_info;
436 struct ipath_user_info user_info;
437 /* address in userspace of struct ipath_port_info to
438 write result to */
439 __u64 port_info;
440 /* enable/disable receipt of packets */
441 __u32 recv_ctrl;
442 /* partition key to set */
443 __u16 part_key;
444 } cmd;
445};
446
447struct ipath_iovec {
448 /* Pointer to data, but same size 32 and 64 bit */
449 __u64 iov_base;
450
451 /*
452 * Length of data; don't need 64 bits, but want
453 * ipath_sendpkt to remain same size as before 32 bit changes, so...
454 */
455 __u64 iov_len;
456};
457
458/*
459 * Describes a single packet for send. Each packet can have one or more
460 * buffers, but the total length (exclusive of IB headers) must be less
461 * than the MTU, and if using the PIO method, entire packet length,
462 * including IB headers, must be less than the ipath_piosize value (words).
463 * Use of this necessitates including sys/uio.h
464 */
465struct __ipath_sendpkt {
466 __u32 sps_flags; /* flags for packet (TBD) */
467 __u32 sps_cnt; /* number of entries to use in sps_iov */
468 /* array of iov's describing packet. TEMPORARY */
469 struct ipath_iovec sps_iov[4];
470};
471
472/* Passed into SMA special file's ->read and ->write methods. */
473struct ipath_sma_pkt
474{
475 __u32 unit; /* unit on which to send packet */
476 __u64 data; /* address of payload in userspace */
477 __u32 len; /* length of payload */
478};
479
480/*
481 * Data layout in I2C flash (for GUID, etc.)
482 * All fields are little-endian binary unless otherwise stated
483 */
484#define IPATH_FLASH_VERSION 1
485struct ipath_flash {
486 /* flash layout version (IPATH_FLASH_VERSION) */
487 __u8 if_fversion;
488 /* checksum protecting if_length bytes */
489 __u8 if_csum;
490 /*
491 * valid length (in use, protected by if_csum), including
492 * if_fversion and if_sum themselves)
493 */
494 __u8 if_length;
495 /* the GUID, in network order */
496 __u8 if_guid[8];
497 /* number of GUIDs to use, starting from if_guid */
498 __u8 if_numguid;
499 /* the board serial number, in ASCII */
500 char if_serial[12];
501 /* board mfg date (YYYYMMDD ASCII) */
502 char if_mfgdate[8];
503 /* last board rework/test date (YYYYMMDD ASCII) */
504 char if_testdate[8];
505 /* logging of error counts, TBD */
506 __u8 if_errcntp[4];
507 /* powered on hours, updated at driver unload */
508 __u8 if_powerhour[2];
509 /* ASCII free-form comment field */
510 char if_comment[32];
511 /* 78 bytes used, min flash size is 128 bytes */
512 __u8 if_future[50];
513};
514
515/*
516 * These are the counters implemented in the chip, and are listed in order.
517 * The InterCaps naming is taken straight from the chip spec.
518 */
519struct infinipath_counters {
520 __u64 LBIntCnt;
521 __u64 LBFlowStallCnt;
522 __u64 Reserved1;
523 __u64 TxUnsupVLErrCnt;
524 __u64 TxDataPktCnt;
525 __u64 TxFlowPktCnt;
526 __u64 TxDwordCnt;
527 __u64 TxLenErrCnt;
528 __u64 TxMaxMinLenErrCnt;
529 __u64 TxUnderrunCnt;
530 __u64 TxFlowStallCnt;
531 __u64 TxDroppedPktCnt;
532 __u64 RxDroppedPktCnt;
533 __u64 RxDataPktCnt;
534 __u64 RxFlowPktCnt;
535 __u64 RxDwordCnt;
536 __u64 RxLenErrCnt;
537 __u64 RxMaxMinLenErrCnt;
538 __u64 RxICRCErrCnt;
539 __u64 RxVCRCErrCnt;
540 __u64 RxFlowCtrlErrCnt;
541 __u64 RxBadFormatCnt;
542 __u64 RxLinkProblemCnt;
543 __u64 RxEBPCnt;
544 __u64 RxLPCRCErrCnt;
545 __u64 RxBufOvflCnt;
546 __u64 RxTIDFullErrCnt;
547 __u64 RxTIDValidErrCnt;
548 __u64 RxPKeyMismatchCnt;
549 __u64 RxP0HdrEgrOvflCnt;
550 __u64 RxP1HdrEgrOvflCnt;
551 __u64 RxP2HdrEgrOvflCnt;
552 __u64 RxP3HdrEgrOvflCnt;
553 __u64 RxP4HdrEgrOvflCnt;
554 __u64 RxP5HdrEgrOvflCnt;
555 __u64 RxP6HdrEgrOvflCnt;
556 __u64 RxP7HdrEgrOvflCnt;
557 __u64 RxP8HdrEgrOvflCnt;
558 __u64 Reserved6;
559 __u64 Reserved7;
560 __u64 IBStatusChangeCnt;
561 __u64 IBLinkErrRecoveryCnt;
562 __u64 IBLinkDownedCnt;
563 __u64 IBSymbolErrCnt;
564};
565
566/*
567 * The next set of defines are for packet headers, and chip register
568 * and memory bits that are visible to and/or used by user-mode software
569 * The other bits that are used only by the driver or diags are in
570 * ipath_registers.h
571 */
572
573/* RcvHdrFlags bits */
574#define INFINIPATH_RHF_LENGTH_MASK 0x7FF
575#define INFINIPATH_RHF_LENGTH_SHIFT 0
576#define INFINIPATH_RHF_RCVTYPE_MASK 0x7
577#define INFINIPATH_RHF_RCVTYPE_SHIFT 11
578#define INFINIPATH_RHF_EGRINDEX_MASK 0x7FF
579#define INFINIPATH_RHF_EGRINDEX_SHIFT 16
580#define INFINIPATH_RHF_H_ICRCERR 0x80000000
581#define INFINIPATH_RHF_H_VCRCERR 0x40000000
582#define INFINIPATH_RHF_H_PARITYERR 0x20000000
583#define INFINIPATH_RHF_H_LENERR 0x10000000
584#define INFINIPATH_RHF_H_MTUERR 0x08000000
585#define INFINIPATH_RHF_H_IHDRERR 0x04000000
586#define INFINIPATH_RHF_H_TIDERR 0x02000000
587#define INFINIPATH_RHF_H_MKERR 0x01000000
588#define INFINIPATH_RHF_H_IBERR 0x00800000
589#define INFINIPATH_RHF_L_SWA 0x00008000
590#define INFINIPATH_RHF_L_SWB 0x00004000
591
592/* infinipath header fields */
593#define INFINIPATH_I_VERS_MASK 0xF
594#define INFINIPATH_I_VERS_SHIFT 28
595#define INFINIPATH_I_PORT_MASK 0xF
596#define INFINIPATH_I_PORT_SHIFT 24
597#define INFINIPATH_I_TID_MASK 0x7FF
598#define INFINIPATH_I_TID_SHIFT 13
599#define INFINIPATH_I_OFFSET_MASK 0x1FFF
600#define INFINIPATH_I_OFFSET_SHIFT 0
601
602/* K_PktFlags bits */
603#define INFINIPATH_KPF_INTR 0x1
604
605/* SendPIO per-buffer control */
606#define INFINIPATH_SP_LENGTHP1_MASK 0x3FF
607#define INFINIPATH_SP_LENGTHP1_SHIFT 0
608#define INFINIPATH_SP_INTR 0x80000000
609#define INFINIPATH_SP_TEST 0x40000000
610#define INFINIPATH_SP_TESTEBP 0x20000000
611
612/* SendPIOAvail bits */
613#define INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT 1
614#define INFINIPATH_SENDPIOAVAIL_CHECK_SHIFT 0
615
616#endif /* _IPATH_COMMON_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_cq.c b/drivers/infiniband/hw/ipath/ipath_cq.c
new file mode 100644
index 000000000000..7ece1135ddfe
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_cq.c
@@ -0,0 +1,295 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/err.h>
34#include <linux/vmalloc.h>
35
36#include "ipath_verbs.h"
37
38/**
39 * ipath_cq_enter - add a new entry to the completion queue
40 * @cq: completion queue
41 * @entry: work completion entry to add
42 * @sig: true if @entry is a solicitated entry
43 *
44 * This may be called with one of the qp->s_lock or qp->r_rq.lock held.
45 */
46void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int solicited)
47{
48 unsigned long flags;
49 u32 next;
50
51 spin_lock_irqsave(&cq->lock, flags);
52
53 if (cq->head == cq->ibcq.cqe)
54 next = 0;
55 else
56 next = cq->head + 1;
57 if (unlikely(next == cq->tail)) {
58 spin_unlock_irqrestore(&cq->lock, flags);
59 if (cq->ibcq.event_handler) {
60 struct ib_event ev;
61
62 ev.device = cq->ibcq.device;
63 ev.element.cq = &cq->ibcq;
64 ev.event = IB_EVENT_CQ_ERR;
65 cq->ibcq.event_handler(&ev, cq->ibcq.cq_context);
66 }
67 return;
68 }
69 cq->queue[cq->head] = *entry;
70 cq->head = next;
71
72 if (cq->notify == IB_CQ_NEXT_COMP ||
73 (cq->notify == IB_CQ_SOLICITED && solicited)) {
74 cq->notify = IB_CQ_NONE;
75 cq->triggered++;
76 /*
77 * This will cause send_complete() to be called in
78 * another thread.
79 */
80 tasklet_hi_schedule(&cq->comptask);
81 }
82
83 spin_unlock_irqrestore(&cq->lock, flags);
84
85 if (entry->status != IB_WC_SUCCESS)
86 to_idev(cq->ibcq.device)->n_wqe_errs++;
87}
88
89/**
90 * ipath_poll_cq - poll for work completion entries
91 * @ibcq: the completion queue to poll
92 * @num_entries: the maximum number of entries to return
93 * @entry: pointer to array where work completions are placed
94 *
95 * Returns the number of completion entries polled.
96 *
97 * This may be called from interrupt context. Also called by ib_poll_cq()
98 * in the generic verbs code.
99 */
100int ipath_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry)
101{
102 struct ipath_cq *cq = to_icq(ibcq);
103 unsigned long flags;
104 int npolled;
105
106 spin_lock_irqsave(&cq->lock, flags);
107
108 for (npolled = 0; npolled < num_entries; ++npolled, ++entry) {
109 if (cq->tail == cq->head)
110 break;
111 *entry = cq->queue[cq->tail];
112 if (cq->tail == cq->ibcq.cqe)
113 cq->tail = 0;
114 else
115 cq->tail++;
116 }
117
118 spin_unlock_irqrestore(&cq->lock, flags);
119
120 return npolled;
121}
122
123static void send_complete(unsigned long data)
124{
125 struct ipath_cq *cq = (struct ipath_cq *)data;
126
127 /*
128 * The completion handler will most likely rearm the notification
129 * and poll for all pending entries. If a new completion entry
130 * is added while we are in this routine, tasklet_hi_schedule()
131 * won't call us again until we return so we check triggered to
132 * see if we need to call the handler again.
133 */
134 for (;;) {
135 u8 triggered = cq->triggered;
136
137 cq->ibcq.comp_handler(&cq->ibcq, cq->ibcq.cq_context);
138
139 if (cq->triggered == triggered)
140 return;
141 }
142}
143
144/**
145 * ipath_create_cq - create a completion queue
146 * @ibdev: the device this completion queue is attached to
147 * @entries: the minimum size of the completion queue
148 * @context: unused by the InfiniPath driver
149 * @udata: unused by the InfiniPath driver
150 *
151 * Returns a pointer to the completion queue or negative errno values
152 * for failure.
153 *
154 * Called by ib_create_cq() in the generic verbs code.
155 */
156struct ib_cq *ipath_create_cq(struct ib_device *ibdev, int entries,
157 struct ib_ucontext *context,
158 struct ib_udata *udata)
159{
160 struct ipath_cq *cq;
161 struct ib_wc *wc;
162 struct ib_cq *ret;
163
164 /*
165 * Need to use vmalloc() if we want to support large #s of
166 * entries.
167 */
168 cq = kmalloc(sizeof(*cq), GFP_KERNEL);
169 if (!cq) {
170 ret = ERR_PTR(-ENOMEM);
171 goto bail;
172 }
173
174 /*
175 * Need to use vmalloc() if we want to support large #s of entries.
176 */
177 wc = vmalloc(sizeof(*wc) * (entries + 1));
178 if (!wc) {
179 kfree(cq);
180 ret = ERR_PTR(-ENOMEM);
181 goto bail;
182 }
183 /*
184 * ib_create_cq() will initialize cq->ibcq except for cq->ibcq.cqe.
185 * The number of entries should be >= the number requested or return
186 * an error.
187 */
188 cq->ibcq.cqe = entries;
189 cq->notify = IB_CQ_NONE;
190 cq->triggered = 0;
191 spin_lock_init(&cq->lock);
192 tasklet_init(&cq->comptask, send_complete, (unsigned long)cq);
193 cq->head = 0;
194 cq->tail = 0;
195 cq->queue = wc;
196
197 ret = &cq->ibcq;
198
199bail:
200 return ret;
201}
202
203/**
204 * ipath_destroy_cq - destroy a completion queue
205 * @ibcq: the completion queue to destroy.
206 *
207 * Returns 0 for success.
208 *
209 * Called by ib_destroy_cq() in the generic verbs code.
210 */
211int ipath_destroy_cq(struct ib_cq *ibcq)
212{
213 struct ipath_cq *cq = to_icq(ibcq);
214
215 tasklet_kill(&cq->comptask);
216 vfree(cq->queue);
217 kfree(cq);
218
219 return 0;
220}
221
222/**
223 * ipath_req_notify_cq - change the notification type for a completion queue
224 * @ibcq: the completion queue
225 * @notify: the type of notification to request
226 *
227 * Returns 0 for success.
228 *
229 * This may be called from interrupt context. Also called by
230 * ib_req_notify_cq() in the generic verbs code.
231 */
232int ipath_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify notify)
233{
234 struct ipath_cq *cq = to_icq(ibcq);
235 unsigned long flags;
236
237 spin_lock_irqsave(&cq->lock, flags);
238 /*
239 * Don't change IB_CQ_NEXT_COMP to IB_CQ_SOLICITED but allow
240 * any other transitions.
241 */
242 if (cq->notify != IB_CQ_NEXT_COMP)
243 cq->notify = notify;
244 spin_unlock_irqrestore(&cq->lock, flags);
245 return 0;
246}
247
248int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
249{
250 struct ipath_cq *cq = to_icq(ibcq);
251 struct ib_wc *wc, *old_wc;
252 u32 n;
253 int ret;
254
255 /*
256 * Need to use vmalloc() if we want to support large #s of entries.
257 */
258 wc = vmalloc(sizeof(*wc) * (cqe + 1));
259 if (!wc) {
260 ret = -ENOMEM;
261 goto bail;
262 }
263
264 spin_lock_irq(&cq->lock);
265 if (cq->head < cq->tail)
266 n = cq->ibcq.cqe + 1 + cq->head - cq->tail;
267 else
268 n = cq->head - cq->tail;
269 if (unlikely((u32)cqe < n)) {
270 spin_unlock_irq(&cq->lock);
271 vfree(wc);
272 ret = -EOVERFLOW;
273 goto bail;
274 }
275 for (n = 0; cq->tail != cq->head; n++) {
276 wc[n] = cq->queue[cq->tail];
277 if (cq->tail == cq->ibcq.cqe)
278 cq->tail = 0;
279 else
280 cq->tail++;
281 }
282 cq->ibcq.cqe = cqe;
283 cq->head = n;
284 cq->tail = 0;
285 old_wc = cq->queue;
286 cq->queue = wc;
287 spin_unlock_irq(&cq->lock);
288
289 vfree(old_wc);
290
291 ret = 0;
292
293bail:
294 return ret;
295}
diff --git a/drivers/infiniband/hw/ipath/ipath_debug.h b/drivers/infiniband/hw/ipath/ipath_debug.h
new file mode 100644
index 000000000000..593e28969c69
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_debug.h
@@ -0,0 +1,96 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _IPATH_DEBUG_H
34#define _IPATH_DEBUG_H
35
36#ifndef _IPATH_DEBUGGING /* debugging enabled or not */
37#define _IPATH_DEBUGGING 1
38#endif
39
40#if _IPATH_DEBUGGING
41
42/*
43 * Mask values for debugging. The scheme allows us to compile out any
44 * of the debug tracing stuff, and if compiled in, to enable or disable
45 * dynamically. This can be set at modprobe time also:
46 * modprobe infinipath.ko infinipath_debug=7
47 */
48
49#define __IPATH_INFO 0x1 /* generic low verbosity stuff */
50#define __IPATH_DBG 0x2 /* generic debug */
51#define __IPATH_TRSAMPLE 0x8 /* generate trace buffer sample entries */
52/* leave some low verbosity spots open */
53#define __IPATH_VERBDBG 0x40 /* very verbose debug */
54#define __IPATH_PKTDBG 0x80 /* print packet data */
55/* print process startup (init)/exit messages */
56#define __IPATH_PROCDBG 0x100
57/* print mmap/nopage stuff, not using VDBG any more */
58#define __IPATH_MMDBG 0x200
59#define __IPATH_USER_SEND 0x1000 /* use user mode send */
60#define __IPATH_KERNEL_SEND 0x2000 /* use kernel mode send */
61#define __IPATH_EPKTDBG 0x4000 /* print ethernet packet data */
62#define __IPATH_SMADBG 0x8000 /* sma packet debug */
63#define __IPATH_IPATHDBG 0x10000 /* Ethernet (IPATH) general debug on */
64#define __IPATH_IPATHWARN 0x20000 /* Ethernet (IPATH) warnings on */
65#define __IPATH_IPATHERR 0x40000 /* Ethernet (IPATH) errors on */
66#define __IPATH_IPATHPD 0x80000 /* Ethernet (IPATH) packet dump on */
67#define __IPATH_IPATHTABLE 0x100000 /* Ethernet (IPATH) table dump on */
68
69#else /* _IPATH_DEBUGGING */
70
71/*
72 * define all of these even with debugging off, for the few places that do
73 * if(infinipath_debug & _IPATH_xyzzy), but in a way that will make the
74 * compiler eliminate the code
75 */
76
77#define __IPATH_INFO 0x0 /* generic low verbosity stuff */
78#define __IPATH_DBG 0x0 /* generic debug */
79#define __IPATH_TRSAMPLE 0x0 /* generate trace buffer sample entries */
80#define __IPATH_VERBDBG 0x0 /* very verbose debug */
81#define __IPATH_PKTDBG 0x0 /* print packet data */
82#define __IPATH_PROCDBG 0x0 /* print process startup (init)/exit messages */
83/* print mmap/nopage stuff, not using VDBG any more */
84#define __IPATH_MMDBG 0x0
85#define __IPATH_EPKTDBG 0x0 /* print ethernet packet data */
86#define __IPATH_SMADBG 0x0 /* print process startup (init)/exit messages */#define __IPATH_IPATHDBG 0x0 /* Ethernet (IPATH) table dump on */
87#define __IPATH_IPATHWARN 0x0 /* Ethernet (IPATH) warnings on */
88#define __IPATH_IPATHERR 0x0 /* Ethernet (IPATH) errors on */
89#define __IPATH_IPATHPD 0x0 /* Ethernet (IPATH) packet dump on */
90#define __IPATH_IPATHTABLE 0x0 /* Ethernet (IPATH) packet dump on */
91
92#endif /* _IPATH_DEBUGGING */
93
94#define __IPATH_VERBOSEDBG __IPATH_VERBDBG
95
96#endif /* _IPATH_DEBUG_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_diag.c b/drivers/infiniband/hw/ipath/ipath_diag.c
new file mode 100644
index 000000000000..cd533cf951c2
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_diag.c
@@ -0,0 +1,379 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33/*
34 * This file contains support for diagnostic functions. It is accessed by
35 * opening the ipath_diag device, normally minor number 129. Diagnostic use
36 * of the InfiniPath chip may render the chip or board unusable until the
37 * driver is unloaded, or in some cases, until the system is rebooted.
38 *
39 * Accesses to the chip through this interface are not similar to going
40 * through the /sys/bus/pci resource mmap interface.
41 */
42
43#include <linux/pci.h>
44#include <asm/uaccess.h>
45
46#include "ipath_common.h"
47#include "ipath_kernel.h"
48#include "ips_common.h"
49#include "ipath_layer.h"
50
51int ipath_diag_inuse;
52static int diag_set_link;
53
54static int ipath_diag_open(struct inode *in, struct file *fp);
55static int ipath_diag_release(struct inode *in, struct file *fp);
56static ssize_t ipath_diag_read(struct file *fp, char __user *data,
57 size_t count, loff_t *off);
58static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
59 size_t count, loff_t *off);
60
61static struct file_operations diag_file_ops = {
62 .owner = THIS_MODULE,
63 .write = ipath_diag_write,
64 .read = ipath_diag_read,
65 .open = ipath_diag_open,
66 .release = ipath_diag_release
67};
68
69static struct cdev *diag_cdev;
70static struct class_device *diag_class_dev;
71
72int ipath_diag_init(void)
73{
74 return ipath_cdev_init(IPATH_DIAG_MINOR, "ipath_diag",
75 &diag_file_ops, &diag_cdev, &diag_class_dev);
76}
77
78void ipath_diag_cleanup(void)
79{
80 ipath_cdev_cleanup(&diag_cdev, &diag_class_dev);
81}
82
83/**
84 * ipath_read_umem64 - read a 64-bit quantity from the chip into user space
85 * @dd: the infinipath device
86 * @uaddr: the location to store the data in user memory
87 * @caddr: the source chip address (full pointer, not offset)
88 * @count: number of bytes to copy (multiple of 32 bits)
89 *
90 * This function also localizes all chip memory accesses.
91 * The copy should be written such that we read full cacheline packets
92 * from the chip. This is usually used for a single qword
93 *
94 * NOTE: This assumes the chip address is 64-bit aligned.
95 */
96static int ipath_read_umem64(struct ipath_devdata *dd, void __user *uaddr,
97 const void __iomem *caddr, size_t count)
98{
99 const u64 __iomem *reg_addr = caddr;
100 const u64 __iomem *reg_end = reg_addr + (count / sizeof(u64));
101 int ret;
102
103 /* not very efficient, but it works for now */
104 if (reg_addr < dd->ipath_kregbase ||
105 reg_end > dd->ipath_kregend) {
106 ret = -EINVAL;
107 goto bail;
108 }
109 while (reg_addr < reg_end) {
110 u64 data = readq(reg_addr);
111 if (copy_to_user(uaddr, &data, sizeof(u64))) {
112 ret = -EFAULT;
113 goto bail;
114 }
115 reg_addr++;
116 uaddr++;
117 }
118 ret = 0;
119bail:
120 return ret;
121}
122
123/**
124 * ipath_write_umem64 - write a 64-bit quantity to the chip from user space
125 * @dd: the infinipath device
126 * @caddr: the destination chip address (full pointer, not offset)
127 * @uaddr: the source of the data in user memory
128 * @count: the number of bytes to copy (multiple of 32 bits)
129 *
130 * This is usually used for a single qword
131 * NOTE: This assumes the chip address is 64-bit aligned.
132 */
133
134static int ipath_write_umem64(struct ipath_devdata *dd, void __iomem *caddr,
135 const void __user *uaddr, size_t count)
136{
137 u64 __iomem *reg_addr = caddr;
138 const u64 __iomem *reg_end = reg_addr + (count / sizeof(u64));
139 int ret;
140
141 /* not very efficient, but it works for now */
142 if (reg_addr < dd->ipath_kregbase ||
143 reg_end > dd->ipath_kregend) {
144 ret = -EINVAL;
145 goto bail;
146 }
147 while (reg_addr < reg_end) {
148 u64 data;
149 if (copy_from_user(&data, uaddr, sizeof(data))) {
150 ret = -EFAULT;
151 goto bail;
152 }
153 writeq(data, reg_addr);
154
155 reg_addr++;
156 uaddr++;
157 }
158 ret = 0;
159bail:
160 return ret;
161}
162
163/**
164 * ipath_read_umem32 - read a 32-bit quantity from the chip into user space
165 * @dd: the infinipath device
166 * @uaddr: the location to store the data in user memory
167 * @caddr: the source chip address (full pointer, not offset)
168 * @count: number of bytes to copy
169 *
170 * read 32 bit values, not 64 bit; for memories that only
171 * support 32 bit reads; usually a single dword.
172 */
173static int ipath_read_umem32(struct ipath_devdata *dd, void __user *uaddr,
174 const void __iomem *caddr, size_t count)
175{
176 const u32 __iomem *reg_addr = caddr;
177 const u32 __iomem *reg_end = reg_addr + (count / sizeof(u32));
178 int ret;
179
180 if (reg_addr < (u32 __iomem *) dd->ipath_kregbase ||
181 reg_end > (u32 __iomem *) dd->ipath_kregend) {
182 ret = -EINVAL;
183 goto bail;
184 }
185 /* not very efficient, but it works for now */
186 while (reg_addr < reg_end) {
187 u32 data = readl(reg_addr);
188 if (copy_to_user(uaddr, &data, sizeof(data))) {
189 ret = -EFAULT;
190 goto bail;
191 }
192
193 reg_addr++;
194 uaddr++;
195 }
196 ret = 0;
197bail:
198 return ret;
199}
200
201/**
202 * ipath_write_umem32 - write a 32-bit quantity to the chip from user space
203 * @dd: the infinipath device
204 * @caddr: the destination chip address (full pointer, not offset)
205 * @uaddr: the source of the data in user memory
206 * @count: number of bytes to copy
207 *
208 * write 32 bit values, not 64 bit; for memories that only
209 * support 32 bit write; usually a single dword.
210 */
211
212static int ipath_write_umem32(struct ipath_devdata *dd, void __iomem *caddr,
213 const void __user *uaddr, size_t count)
214{
215 u32 __iomem *reg_addr = caddr;
216 const u32 __iomem *reg_end = reg_addr + (count / sizeof(u32));
217 int ret;
218
219 if (reg_addr < (u32 __iomem *) dd->ipath_kregbase ||
220 reg_end > (u32 __iomem *) dd->ipath_kregend) {
221 ret = -EINVAL;
222 goto bail;
223 }
224 while (reg_addr < reg_end) {
225 u32 data;
226 if (copy_from_user(&data, uaddr, sizeof(data))) {
227 ret = -EFAULT;
228 goto bail;
229 }
230 writel(data, reg_addr);
231
232 reg_addr++;
233 uaddr++;
234 }
235 ret = 0;
236bail:
237 return ret;
238}
239
240static int ipath_diag_open(struct inode *in, struct file *fp)
241{
242 struct ipath_devdata *dd;
243 int unit = 0; /* XXX this is bogus */
244 unsigned long flags;
245 int ret;
246
247 dd = ipath_lookup(unit);
248
249 mutex_lock(&ipath_mutex);
250 spin_lock_irqsave(&ipath_devs_lock, flags);
251
252 if (ipath_diag_inuse) {
253 ret = -EBUSY;
254 goto bail;
255 }
256
257 list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
258 /*
259 * we need at least one infinipath device to be present
260 * (don't use INITTED, because we want to be able to open
261 * even if device is in freeze mode, which cleared INITTED).
262 * There is a small amount of risk to this, which is why we
263 * also verify kregbase is set.
264 */
265
266 if (!(dd->ipath_flags & IPATH_PRESENT) ||
267 !dd->ipath_kregbase)
268 continue;
269
270 ipath_diag_inuse = 1;
271 diag_set_link = 0;
272 ret = 0;
273 goto bail;
274 }
275
276 ret = -ENODEV;
277
278bail:
279 spin_unlock_irqrestore(&ipath_devs_lock, flags);
280 mutex_unlock(&ipath_mutex);
281
282 /* Only expose a way to reset the device if we
283 make it into diag mode. */
284 if (ret == 0)
285 ipath_expose_reset(&dd->pcidev->dev);
286
287 return ret;
288}
289
290static int ipath_diag_release(struct inode *i, struct file *f)
291{
292 mutex_lock(&ipath_mutex);
293 ipath_diag_inuse = 0;
294 mutex_unlock(&ipath_mutex);
295 return 0;
296}
297
298static ssize_t ipath_diag_read(struct file *fp, char __user *data,
299 size_t count, loff_t *off)
300{
301 int unit = 0; /* XXX provide for reads on other units some day */
302 struct ipath_devdata *dd;
303 void __iomem *kreg_base;
304 ssize_t ret;
305
306 dd = ipath_lookup(unit);
307 if (!dd) {
308 ret = -ENODEV;
309 goto bail;
310 }
311
312 kreg_base = dd->ipath_kregbase;
313
314 if (count == 0)
315 ret = 0;
316 else if ((count % 4) || (*off % 4))
317 /* address or length is not 32-bit aligned, hence invalid */
318 ret = -EINVAL;
319 else if ((count % 8) || (*off % 8))
320 /* address or length not 64-bit aligned; do 32-bit reads */
321 ret = ipath_read_umem32(dd, data, kreg_base + *off, count);
322 else
323 ret = ipath_read_umem64(dd, data, kreg_base + *off, count);
324
325 if (ret >= 0) {
326 *off += count;
327 ret = count;
328 }
329
330bail:
331 return ret;
332}
333
334static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
335 size_t count, loff_t *off)
336{
337 int unit = 0; /* XXX this is bogus */
338 struct ipath_devdata *dd;
339 void __iomem *kreg_base;
340 ssize_t ret;
341
342 dd = ipath_lookup(unit);
343 if (!dd) {
344 ret = -ENODEV;
345 goto bail;
346 }
347 kreg_base = dd->ipath_kregbase;
348
349 if (count == 0)
350 ret = 0;
351 else if ((count % 4) || (*off % 4))
352 /* address or length is not 32-bit aligned, hence invalid */
353 ret = -EINVAL;
354 else if ((count % 8) || (*off % 8))
355 /* address or length not 64-bit aligned; do 32-bit writes */
356 ret = ipath_write_umem32(dd, kreg_base + *off, data, count);
357 else
358 ret = ipath_write_umem64(dd, kreg_base + *off, data, count);
359
360 if (ret >= 0) {
361 *off += count;
362 ret = count;
363 }
364
365bail:
366 return ret;
367}
368
369void ipath_diag_bringup_link(struct ipath_devdata *dd)
370{
371 if (diag_set_link || (dd->ipath_flags & IPATH_LINKACTIVE))
372 return;
373
374 diag_set_link = 1;
375 ipath_cdbg(VERBOSE, "Trying to set to set link active for "
376 "diag pkt\n");
377 ipath_layer_set_linkstate(dd, IPATH_IB_LINKARM);
378 ipath_layer_set_linkstate(dd, IPATH_IB_LINKACTIVE);
379}
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c
new file mode 100644
index 000000000000..58a94efb0070
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c
@@ -0,0 +1,1983 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/spinlock.h>
34#include <linux/idr.h>
35#include <linux/pci.h>
36#include <linux/delay.h>
37#include <linux/netdevice.h>
38#include <linux/vmalloc.h>
39
40#include "ipath_kernel.h"
41#include "ips_common.h"
42#include "ipath_layer.h"
43
44static void ipath_update_pio_bufs(struct ipath_devdata *);
45
46const char *ipath_get_unit_name(int unit)
47{
48 static char iname[16];
49 snprintf(iname, sizeof iname, "infinipath%u", unit);
50 return iname;
51}
52
53EXPORT_SYMBOL_GPL(ipath_get_unit_name);
54
55#define DRIVER_LOAD_MSG "PathScale " IPATH_DRV_NAME " loaded: "
56#define PFX IPATH_DRV_NAME ": "
57
58/*
59 * The size has to be longer than this string, so we can append
60 * board/chip information to it in the init code.
61 */
62const char ipath_core_version[] = IPATH_IDSTR "\n";
63
64static struct idr unit_table;
65DEFINE_SPINLOCK(ipath_devs_lock);
66LIST_HEAD(ipath_dev_list);
67
68wait_queue_head_t ipath_sma_state_wait;
69
70unsigned ipath_debug = __IPATH_INFO;
71
72module_param_named(debug, ipath_debug, uint, S_IWUSR | S_IRUGO);
73MODULE_PARM_DESC(debug, "mask for debug prints");
74EXPORT_SYMBOL_GPL(ipath_debug);
75
76MODULE_LICENSE("GPL");
77MODULE_AUTHOR("PathScale <support@pathscale.com>");
78MODULE_DESCRIPTION("Pathscale InfiniPath driver");
79
80const char *ipath_ibcstatus_str[] = {
81 "Disabled",
82 "LinkUp",
83 "PollActive",
84 "PollQuiet",
85 "SleepDelay",
86 "SleepQuiet",
87 "LState6", /* unused */
88 "LState7", /* unused */
89 "CfgDebounce",
90 "CfgRcvfCfg",
91 "CfgWaitRmt",
92 "CfgIdle",
93 "RecovRetrain",
94 "LState0xD", /* unused */
95 "RecovWaitRmt",
96 "RecovIdle",
97};
98
99/*
100 * These variables are initialized in the chip-specific files
101 * but are defined here.
102 */
103u16 ipath_gpio_sda_num, ipath_gpio_scl_num;
104u64 ipath_gpio_sda, ipath_gpio_scl;
105u64 infinipath_i_bitsextant;
106ipath_err_t infinipath_e_bitsextant, infinipath_hwe_bitsextant;
107u32 infinipath_i_rcvavail_mask, infinipath_i_rcvurg_mask;
108
109static void __devexit ipath_remove_one(struct pci_dev *);
110static int __devinit ipath_init_one(struct pci_dev *,
111 const struct pci_device_id *);
112
113/* Only needed for registration, nothing else needs this info */
114#define PCI_VENDOR_ID_PATHSCALE 0x1fc1
115#define PCI_DEVICE_ID_INFINIPATH_HT 0xd
116#define PCI_DEVICE_ID_INFINIPATH_PE800 0x10
117
118static const struct pci_device_id ipath_pci_tbl[] = {
119 {PCI_DEVICE(PCI_VENDOR_ID_PATHSCALE,
120 PCI_DEVICE_ID_INFINIPATH_HT)},
121 {PCI_DEVICE(PCI_VENDOR_ID_PATHSCALE,
122 PCI_DEVICE_ID_INFINIPATH_PE800)},
123};
124
125MODULE_DEVICE_TABLE(pci, ipath_pci_tbl);
126
127static struct pci_driver ipath_driver = {
128 .name = IPATH_DRV_NAME,
129 .probe = ipath_init_one,
130 .remove = __devexit_p(ipath_remove_one),
131 .id_table = ipath_pci_tbl,
132};
133
134/*
135 * This is where port 0's rcvhdrtail register is written back; we also
136 * want nothing else sharing the cache line, so make it a cache line
137 * in size. Used for all units.
138 */
139volatile __le64 *ipath_port0_rcvhdrtail;
140dma_addr_t ipath_port0_rcvhdrtail_dma;
141static int port0_rcvhdrtail_refs;
142
143static inline void read_bars(struct ipath_devdata *dd, struct pci_dev *dev,
144 u32 *bar0, u32 *bar1)
145{
146 int ret;
147
148 ret = pci_read_config_dword(dev, PCI_BASE_ADDRESS_0, bar0);
149 if (ret)
150 ipath_dev_err(dd, "failed to read bar0 before enable: "
151 "error %d\n", -ret);
152
153 ret = pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, bar1);
154 if (ret)
155 ipath_dev_err(dd, "failed to read bar1 before enable: "
156 "error %d\n", -ret);
157
158 ipath_dbg("Read bar0 %x bar1 %x\n", *bar0, *bar1);
159}
160
161static void ipath_free_devdata(struct pci_dev *pdev,
162 struct ipath_devdata *dd)
163{
164 unsigned long flags;
165
166 pci_set_drvdata(pdev, NULL);
167
168 if (dd->ipath_unit != -1) {
169 spin_lock_irqsave(&ipath_devs_lock, flags);
170 idr_remove(&unit_table, dd->ipath_unit);
171 list_del(&dd->ipath_list);
172 spin_unlock_irqrestore(&ipath_devs_lock, flags);
173 }
174 dma_free_coherent(&pdev->dev, sizeof(*dd), dd, dd->ipath_dma_addr);
175}
176
177static struct ipath_devdata *ipath_alloc_devdata(struct pci_dev *pdev)
178{
179 unsigned long flags;
180 struct ipath_devdata *dd;
181 dma_addr_t dma_addr;
182 int ret;
183
184 if (!idr_pre_get(&unit_table, GFP_KERNEL)) {
185 dd = ERR_PTR(-ENOMEM);
186 goto bail;
187 }
188
189 dd = dma_alloc_coherent(&pdev->dev, sizeof(*dd), &dma_addr,
190 GFP_KERNEL);
191
192 if (!dd) {
193 dd = ERR_PTR(-ENOMEM);
194 goto bail;
195 }
196
197 dd->ipath_dma_addr = dma_addr;
198 dd->ipath_unit = -1;
199
200 spin_lock_irqsave(&ipath_devs_lock, flags);
201
202 ret = idr_get_new(&unit_table, dd, &dd->ipath_unit);
203 if (ret < 0) {
204 printk(KERN_ERR IPATH_DRV_NAME
205 ": Could not allocate unit ID: error %d\n", -ret);
206 ipath_free_devdata(pdev, dd);
207 dd = ERR_PTR(ret);
208 goto bail_unlock;
209 }
210
211 dd->pcidev = pdev;
212 pci_set_drvdata(pdev, dd);
213
214 list_add(&dd->ipath_list, &ipath_dev_list);
215
216bail_unlock:
217 spin_unlock_irqrestore(&ipath_devs_lock, flags);
218
219bail:
220 return dd;
221}
222
223static inline struct ipath_devdata *__ipath_lookup(int unit)
224{
225 return idr_find(&unit_table, unit);
226}
227
228struct ipath_devdata *ipath_lookup(int unit)
229{
230 struct ipath_devdata *dd;
231 unsigned long flags;
232
233 spin_lock_irqsave(&ipath_devs_lock, flags);
234 dd = __ipath_lookup(unit);
235 spin_unlock_irqrestore(&ipath_devs_lock, flags);
236
237 return dd;
238}
239
240int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp)
241{
242 int nunits, npresent, nup;
243 struct ipath_devdata *dd;
244 unsigned long flags;
245 u32 maxports;
246
247 nunits = npresent = nup = maxports = 0;
248
249 spin_lock_irqsave(&ipath_devs_lock, flags);
250
251 list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
252 nunits++;
253 if ((dd->ipath_flags & IPATH_PRESENT) && dd->ipath_kregbase)
254 npresent++;
255 if (dd->ipath_lid &&
256 !(dd->ipath_flags & (IPATH_DISABLED | IPATH_LINKDOWN
257 | IPATH_LINKUNK)))
258 nup++;
259 if (dd->ipath_cfgports > maxports)
260 maxports = dd->ipath_cfgports;
261 }
262
263 spin_unlock_irqrestore(&ipath_devs_lock, flags);
264
265 if (npresentp)
266 *npresentp = npresent;
267 if (nupp)
268 *nupp = nup;
269 if (maxportsp)
270 *maxportsp = maxports;
271
272 return nunits;
273}
274
275static int init_port0_rcvhdrtail(struct pci_dev *pdev)
276{
277 int ret;
278
279 mutex_lock(&ipath_mutex);
280
281 if (!ipath_port0_rcvhdrtail) {
282 ipath_port0_rcvhdrtail =
283 dma_alloc_coherent(&pdev->dev,
284 IPATH_PORT0_RCVHDRTAIL_SIZE,
285 &ipath_port0_rcvhdrtail_dma,
286 GFP_KERNEL);
287
288 if (!ipath_port0_rcvhdrtail) {
289 ret = -ENOMEM;
290 goto bail;
291 }
292 }
293 port0_rcvhdrtail_refs++;
294 ret = 0;
295
296bail:
297 mutex_unlock(&ipath_mutex);
298
299 return ret;
300}
301
302static void cleanup_port0_rcvhdrtail(struct pci_dev *pdev)
303{
304 mutex_lock(&ipath_mutex);
305
306 if (!--port0_rcvhdrtail_refs) {
307 dma_free_coherent(&pdev->dev, IPATH_PORT0_RCVHDRTAIL_SIZE,
308 (void *) ipath_port0_rcvhdrtail,
309 ipath_port0_rcvhdrtail_dma);
310 ipath_port0_rcvhdrtail = NULL;
311 }
312
313 mutex_unlock(&ipath_mutex);
314}
315
316/*
317 * These next two routines are placeholders in case we don't have per-arch
318 * code for controlling write combining. If explicit control of write
319 * combining is not available, performance will probably be awful.
320 */
321
322int __attribute__((weak)) ipath_enable_wc(struct ipath_devdata *dd)
323{
324 return -EOPNOTSUPP;
325}
326
327void __attribute__((weak)) ipath_disable_wc(struct ipath_devdata *dd)
328{
329}
330
331static int __devinit ipath_init_one(struct pci_dev *pdev,
332 const struct pci_device_id *ent)
333{
334 int ret, len, j;
335 struct ipath_devdata *dd;
336 unsigned long long addr;
337 u32 bar0 = 0, bar1 = 0;
338 u8 rev;
339
340 ret = init_port0_rcvhdrtail(pdev);
341 if (ret < 0) {
342 printk(KERN_ERR IPATH_DRV_NAME
343 ": Could not allocate port0_rcvhdrtail: error %d\n",
344 -ret);
345 goto bail;
346 }
347
348 dd = ipath_alloc_devdata(pdev);
349 if (IS_ERR(dd)) {
350 ret = PTR_ERR(dd);
351 printk(KERN_ERR IPATH_DRV_NAME
352 ": Could not allocate devdata: error %d\n", -ret);
353 goto bail_rcvhdrtail;
354 }
355
356 ipath_cdbg(VERBOSE, "initializing unit #%u\n", dd->ipath_unit);
357
358 read_bars(dd, pdev, &bar0, &bar1);
359
360 ret = pci_enable_device(pdev);
361 if (ret) {
362 /* This can happen iff:
363 *
364 * We did a chip reset, and then failed to reprogram the
365 * BAR, or the chip reset due to an internal error. We then
366 * unloaded the driver and reloaded it.
367 *
368 * Both reset cases set the BAR back to initial state. For
369 * the latter case, the AER sticky error bit at offset 0x718
370 * should be set, but the Linux kernel doesn't yet know
371 * about that, it appears. If the original BAR was retained
372 * in the kernel data structures, this may be OK.
373 */
374 ipath_dev_err(dd, "enable unit %d failed: error %d\n",
375 dd->ipath_unit, -ret);
376 goto bail_devdata;
377 }
378 addr = pci_resource_start(pdev, 0);
379 len = pci_resource_len(pdev, 0);
380 ipath_cdbg(VERBOSE, "regbase (0) %llx len %d irq %x, vend %x/%x "
381 "driver_data %lx\n", addr, len, pdev->irq, ent->vendor,
382 ent->device, ent->driver_data);
383
384 read_bars(dd, pdev, &bar0, &bar1);
385
386 if (!bar1 && !(bar0 & ~0xf)) {
387 if (addr) {
388 dev_info(&pdev->dev, "BAR is 0 (probable RESET), "
389 "rewriting as %llx\n", addr);
390 ret = pci_write_config_dword(
391 pdev, PCI_BASE_ADDRESS_0, addr);
392 if (ret) {
393 ipath_dev_err(dd, "rewrite of BAR0 "
394 "failed: err %d\n", -ret);
395 goto bail_disable;
396 }
397 ret = pci_write_config_dword(
398 pdev, PCI_BASE_ADDRESS_1, addr >> 32);
399 if (ret) {
400 ipath_dev_err(dd, "rewrite of BAR1 "
401 "failed: err %d\n", -ret);
402 goto bail_disable;
403 }
404 } else {
405 ipath_dev_err(dd, "BAR is 0 (probable RESET), "
406 "not usable until reboot\n");
407 ret = -ENODEV;
408 goto bail_disable;
409 }
410 }
411
412 ret = pci_request_regions(pdev, IPATH_DRV_NAME);
413 if (ret) {
414 dev_info(&pdev->dev, "pci_request_regions unit %u fails: "
415 "err %d\n", dd->ipath_unit, -ret);
416 goto bail_disable;
417 }
418
419 ret = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
420 if (ret) {
421 dev_info(&pdev->dev, "pci_set_dma_mask unit %u "
422 "fails: %d\n", dd->ipath_unit, ret);
423 goto bail_regions;
424 }
425
426 pci_set_master(pdev);
427
428 /*
429 * Save BARs to rewrite after device reset. Save all 64 bits of
430 * BAR, just in case.
431 */
432 dd->ipath_pcibar0 = addr;
433 dd->ipath_pcibar1 = addr >> 32;
434 dd->ipath_deviceid = ent->device; /* save for later use */
435 dd->ipath_vendorid = ent->vendor;
436
437 /* setup the chip-specific functions, as early as possible. */
438 switch (ent->device) {
439 case PCI_DEVICE_ID_INFINIPATH_HT:
440 ipath_init_ht400_funcs(dd);
441 break;
442 case PCI_DEVICE_ID_INFINIPATH_PE800:
443 ipath_init_pe800_funcs(dd);
444 break;
445 default:
446 ipath_dev_err(dd, "Found unknown PathScale deviceid 0x%x, "
447 "failing\n", ent->device);
448 return -ENODEV;
449 }
450
451 for (j = 0; j < 6; j++) {
452 if (!pdev->resource[j].start)
453 continue;
454 ipath_cdbg(VERBOSE, "BAR %d start %lx, end %lx, len %lx\n",
455 j, pdev->resource[j].start,
456 pdev->resource[j].end,
457 pci_resource_len(pdev, j));
458 }
459
460 if (!addr) {
461 ipath_dev_err(dd, "No valid address in BAR 0!\n");
462 ret = -ENODEV;
463 goto bail_regions;
464 }
465
466 dd->ipath_deviceid = ent->device; /* save for later use */
467 dd->ipath_vendorid = ent->vendor;
468
469 ret = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
470 if (ret) {
471 ipath_dev_err(dd, "Failed to read PCI revision ID unit "
472 "%u: err %d\n", dd->ipath_unit, -ret);
473 goto bail_regions; /* shouldn't ever happen */
474 }
475 dd->ipath_pcirev = rev;
476
477 dd->ipath_kregbase = ioremap_nocache(addr, len);
478
479 if (!dd->ipath_kregbase) {
480 ipath_dbg("Unable to map io addr %llx to kvirt, failing\n",
481 addr);
482 ret = -ENOMEM;
483 goto bail_iounmap;
484 }
485 dd->ipath_kregend = (u64 __iomem *)
486 ((void __iomem *)dd->ipath_kregbase + len);
487 dd->ipath_physaddr = addr; /* used for io_remap, etc. */
488 /* for user mmap */
489 dd->ipath_kregvirt = (u64 __iomem *) phys_to_virt(addr);
490 ipath_cdbg(VERBOSE, "mapped io addr %llx to kregbase %p "
491 "kregvirt %p\n", addr, dd->ipath_kregbase,
492 dd->ipath_kregvirt);
493
494 /*
495 * clear ipath_flags here instead of in ipath_init_chip as it is set
496 * by ipath_setup_htconfig.
497 */
498 dd->ipath_flags = 0;
499
500 if (dd->ipath_f_bus(dd, pdev))
501 ipath_dev_err(dd, "Failed to setup config space; "
502 "continuing anyway\n");
503
504 /*
505 * set up our interrupt handler; SA_SHIRQ probably not needed,
506 * since MSI interrupts shouldn't be shared but won't hurt for now.
507 * check 0 irq after we return from chip-specific bus setup, since
508 * that can affect this due to setup
509 */
510 if (!pdev->irq)
511 ipath_dev_err(dd, "irq is 0, BIOS error? Interrupts won't "
512 "work\n");
513 else {
514 ret = request_irq(pdev->irq, ipath_intr, SA_SHIRQ,
515 IPATH_DRV_NAME, dd);
516 if (ret) {
517 ipath_dev_err(dd, "Couldn't setup irq handler, "
518 "irq=%u: %d\n", pdev->irq, ret);
519 goto bail_iounmap;
520 }
521 }
522
523 ret = ipath_init_chip(dd, 0); /* do the chip-specific init */
524 if (ret)
525 goto bail_iounmap;
526
527 ret = ipath_enable_wc(dd);
528
529 if (ret) {
530 ipath_dev_err(dd, "Write combining not enabled "
531 "(err %d): performance may be poor\n",
532 -ret);
533 ret = 0;
534 }
535
536 ipath_device_create_group(&pdev->dev, dd);
537 ipathfs_add_device(dd);
538 ipath_user_add(dd);
539 ipath_layer_add(dd);
540
541 goto bail;
542
543bail_iounmap:
544 iounmap((volatile void __iomem *) dd->ipath_kregbase);
545
546bail_regions:
547 pci_release_regions(pdev);
548
549bail_disable:
550 pci_disable_device(pdev);
551
552bail_devdata:
553 ipath_free_devdata(pdev, dd);
554
555bail_rcvhdrtail:
556 cleanup_port0_rcvhdrtail(pdev);
557
558bail:
559 return ret;
560}
561
562static void __devexit ipath_remove_one(struct pci_dev *pdev)
563{
564 struct ipath_devdata *dd;
565
566 ipath_cdbg(VERBOSE, "removing, pdev=%p\n", pdev);
567 if (!pdev)
568 return;
569
570 dd = pci_get_drvdata(pdev);
571 ipath_layer_del(dd);
572 ipath_user_del(dd);
573 ipathfs_remove_device(dd);
574 ipath_device_remove_group(&pdev->dev, dd);
575 ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
576 "unit %u\n", dd, (u32) dd->ipath_unit);
577 if (dd->ipath_kregbase) {
578 ipath_cdbg(VERBOSE, "Unmapping kregbase %p\n",
579 dd->ipath_kregbase);
580 iounmap((volatile void __iomem *) dd->ipath_kregbase);
581 dd->ipath_kregbase = NULL;
582 }
583 pci_release_regions(pdev);
584 ipath_cdbg(VERBOSE, "calling pci_disable_device\n");
585 pci_disable_device(pdev);
586
587 ipath_free_devdata(pdev, dd);
588 cleanup_port0_rcvhdrtail(pdev);
589}
590
591/* general driver use */
592DEFINE_MUTEX(ipath_mutex);
593
594static DEFINE_SPINLOCK(ipath_pioavail_lock);
595
596/**
597 * ipath_disarm_piobufs - cancel a range of PIO buffers
598 * @dd: the infinipath device
599 * @first: the first PIO buffer to cancel
600 * @cnt: the number of PIO buffers to cancel
601 *
602 * cancel a range of PIO buffers, used when they might be armed, but
603 * not triggered. Used at init to ensure buffer state, and also user
604 * process close, in case it died while writing to a PIO buffer
605 * Also after errors.
606 */
607void ipath_disarm_piobufs(struct ipath_devdata *dd, unsigned first,
608 unsigned cnt)
609{
610 unsigned i, last = first + cnt;
611 u64 sendctrl, sendorig;
612
613 ipath_cdbg(PKT, "disarm %u PIObufs first=%u\n", cnt, first);
614 sendorig = dd->ipath_sendctrl | INFINIPATH_S_DISARM;
615 for (i = first; i < last; i++) {
616 sendctrl = sendorig |
617 (i << INFINIPATH_S_DISARMPIOBUF_SHIFT);
618 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
619 sendctrl);
620 }
621
622 /*
623 * Write it again with current value, in case ipath_sendctrl changed
624 * while we were looping; no critical bits that would require
625 * locking.
626 *
627 * Write a 0, and then the original value, reading scratch in
628 * between. This seems to avoid a chip timing race that causes
629 * pioavail updates to memory to stop.
630 */
631 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
632 0);
633 sendorig = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
634 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
635 dd->ipath_sendctrl);
636}
637
638/**
639 * ipath_wait_linkstate - wait for an IB link state change to occur
640 * @dd: the infinipath device
641 * @state: the state to wait for
642 * @msecs: the number of milliseconds to wait
643 *
644 * wait up to msecs milliseconds for IB link state change to occur for
645 * now, take the easy polling route. Currently used only by
646 * ipath_layer_set_linkstate. Returns 0 if state reached, otherwise
647 * -ETIMEDOUT state can have multiple states set, for any of several
648 * transitions.
649 */
650int ipath_wait_linkstate(struct ipath_devdata *dd, u32 state, int msecs)
651{
652 dd->ipath_sma_state_wanted = state;
653 wait_event_interruptible_timeout(ipath_sma_state_wait,
654 (dd->ipath_flags & state),
655 msecs_to_jiffies(msecs));
656 dd->ipath_sma_state_wanted = 0;
657
658 if (!(dd->ipath_flags & state)) {
659 u64 val;
660 ipath_cdbg(SMA, "Didn't reach linkstate %s within %u ms\n",
661 /* test INIT ahead of DOWN, both can be set */
662 (state & IPATH_LINKINIT) ? "INIT" :
663 ((state & IPATH_LINKDOWN) ? "DOWN" :
664 ((state & IPATH_LINKARMED) ? "ARM" : "ACTIVE")),
665 msecs);
666 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
667 ipath_cdbg(VERBOSE, "ibcc=%llx ibcstatus=%llx (%s)\n",
668 (unsigned long long) ipath_read_kreg64(
669 dd, dd->ipath_kregs->kr_ibcctrl),
670 (unsigned long long) val,
671 ipath_ibcstatus_str[val & 0xf]);
672 }
673 return (dd->ipath_flags & state) ? 0 : -ETIMEDOUT;
674}
675
676void ipath_decode_err(char *buf, size_t blen, ipath_err_t err)
677{
678 *buf = '\0';
679 if (err & INFINIPATH_E_RHDRLEN)
680 strlcat(buf, "rhdrlen ", blen);
681 if (err & INFINIPATH_E_RBADTID)
682 strlcat(buf, "rbadtid ", blen);
683 if (err & INFINIPATH_E_RBADVERSION)
684 strlcat(buf, "rbadversion ", blen);
685 if (err & INFINIPATH_E_RHDR)
686 strlcat(buf, "rhdr ", blen);
687 if (err & INFINIPATH_E_RLONGPKTLEN)
688 strlcat(buf, "rlongpktlen ", blen);
689 if (err & INFINIPATH_E_RSHORTPKTLEN)
690 strlcat(buf, "rshortpktlen ", blen);
691 if (err & INFINIPATH_E_RMAXPKTLEN)
692 strlcat(buf, "rmaxpktlen ", blen);
693 if (err & INFINIPATH_E_RMINPKTLEN)
694 strlcat(buf, "rminpktlen ", blen);
695 if (err & INFINIPATH_E_RFORMATERR)
696 strlcat(buf, "rformaterr ", blen);
697 if (err & INFINIPATH_E_RUNSUPVL)
698 strlcat(buf, "runsupvl ", blen);
699 if (err & INFINIPATH_E_RUNEXPCHAR)
700 strlcat(buf, "runexpchar ", blen);
701 if (err & INFINIPATH_E_RIBFLOW)
702 strlcat(buf, "ribflow ", blen);
703 if (err & INFINIPATH_E_REBP)
704 strlcat(buf, "EBP ", blen);
705 if (err & INFINIPATH_E_SUNDERRUN)
706 strlcat(buf, "sunderrun ", blen);
707 if (err & INFINIPATH_E_SPIOARMLAUNCH)
708 strlcat(buf, "spioarmlaunch ", blen);
709 if (err & INFINIPATH_E_SUNEXPERRPKTNUM)
710 strlcat(buf, "sunexperrpktnum ", blen);
711 if (err & INFINIPATH_E_SDROPPEDDATAPKT)
712 strlcat(buf, "sdroppeddatapkt ", blen);
713 if (err & INFINIPATH_E_SDROPPEDSMPPKT)
714 strlcat(buf, "sdroppedsmppkt ", blen);
715 if (err & INFINIPATH_E_SMAXPKTLEN)
716 strlcat(buf, "smaxpktlen ", blen);
717 if (err & INFINIPATH_E_SMINPKTLEN)
718 strlcat(buf, "sminpktlen ", blen);
719 if (err & INFINIPATH_E_SUNSUPVL)
720 strlcat(buf, "sunsupVL ", blen);
721 if (err & INFINIPATH_E_SPKTLEN)
722 strlcat(buf, "spktlen ", blen);
723 if (err & INFINIPATH_E_INVALIDADDR)
724 strlcat(buf, "invalidaddr ", blen);
725 if (err & INFINIPATH_E_RICRC)
726 strlcat(buf, "CRC ", blen);
727 if (err & INFINIPATH_E_RVCRC)
728 strlcat(buf, "VCRC ", blen);
729 if (err & INFINIPATH_E_RRCVEGRFULL)
730 strlcat(buf, "rcvegrfull ", blen);
731 if (err & INFINIPATH_E_RRCVHDRFULL)
732 strlcat(buf, "rcvhdrfull ", blen);
733 if (err & INFINIPATH_E_IBSTATUSCHANGED)
734 strlcat(buf, "ibcstatuschg ", blen);
735 if (err & INFINIPATH_E_RIBLOSTLINK)
736 strlcat(buf, "riblostlink ", blen);
737 if (err & INFINIPATH_E_HARDWARE)
738 strlcat(buf, "hardware ", blen);
739 if (err & INFINIPATH_E_RESET)
740 strlcat(buf, "reset ", blen);
741}
742
743/**
744 * get_rhf_errstring - decode RHF errors
745 * @err: the err number
746 * @msg: the output buffer
747 * @len: the length of the output buffer
748 *
749 * only used one place now, may want more later
750 */
751static void get_rhf_errstring(u32 err, char *msg, size_t len)
752{
753 /* if no errors, and so don't need to check what's first */
754 *msg = '\0';
755
756 if (err & INFINIPATH_RHF_H_ICRCERR)
757 strlcat(msg, "icrcerr ", len);
758 if (err & INFINIPATH_RHF_H_VCRCERR)
759 strlcat(msg, "vcrcerr ", len);
760 if (err & INFINIPATH_RHF_H_PARITYERR)
761 strlcat(msg, "parityerr ", len);
762 if (err & INFINIPATH_RHF_H_LENERR)
763 strlcat(msg, "lenerr ", len);
764 if (err & INFINIPATH_RHF_H_MTUERR)
765 strlcat(msg, "mtuerr ", len);
766 if (err & INFINIPATH_RHF_H_IHDRERR)
767 /* infinipath hdr checksum error */
768 strlcat(msg, "ipathhdrerr ", len);
769 if (err & INFINIPATH_RHF_H_TIDERR)
770 strlcat(msg, "tiderr ", len);
771 if (err & INFINIPATH_RHF_H_MKERR)
772 /* bad port, offset, etc. */
773 strlcat(msg, "invalid ipathhdr ", len);
774 if (err & INFINIPATH_RHF_H_IBERR)
775 strlcat(msg, "iberr ", len);
776 if (err & INFINIPATH_RHF_L_SWA)
777 strlcat(msg, "swA ", len);
778 if (err & INFINIPATH_RHF_L_SWB)
779 strlcat(msg, "swB ", len);
780}
781
782/**
783 * ipath_get_egrbuf - get an eager buffer
784 * @dd: the infinipath device
785 * @bufnum: the eager buffer to get
786 * @err: unused
787 *
788 * must only be called if ipath_pd[port] is known to be allocated
789 */
790static inline void *ipath_get_egrbuf(struct ipath_devdata *dd, u32 bufnum,
791 int err)
792{
793 return dd->ipath_port0_skbs ?
794 (void *)dd->ipath_port0_skbs[bufnum]->data : NULL;
795}
796
797/**
798 * ipath_alloc_skb - allocate an skb and buffer with possible constraints
799 * @dd: the infinipath device
800 * @gfp_mask: the sk_buff SFP mask
801 */
802struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd,
803 gfp_t gfp_mask)
804{
805 struct sk_buff *skb;
806 u32 len;
807
808 /*
809 * Only fully supported way to handle this is to allocate lots
810 * extra, align as needed, and then do skb_reserve(). That wastes
811 * a lot of memory... I'll have to hack this into infinipath_copy
812 * also.
813 */
814
815 /*
816 * We need 4 extra bytes for unaligned transfer copying
817 */
818 if (dd->ipath_flags & IPATH_4BYTE_TID) {
819 /* we need a 4KB multiple alignment, and there is no way
820 * to do it except to allocate extra and then skb_reserve
821 * enough to bring it up to the right alignment.
822 */
823 len = dd->ipath_ibmaxlen + 4 + (1 << 11) - 1;
824 }
825 else
826 len = dd->ipath_ibmaxlen + 4;
827 skb = __dev_alloc_skb(len, gfp_mask);
828 if (!skb) {
829 ipath_dev_err(dd, "Failed to allocate skbuff, length %u\n",
830 len);
831 goto bail;
832 }
833 if (dd->ipath_flags & IPATH_4BYTE_TID) {
834 u32 una = ((1 << 11) - 1) & (unsigned long)(skb->data + 4);
835 if (una)
836 skb_reserve(skb, 4 + (1 << 11) - una);
837 else
838 skb_reserve(skb, 4);
839 } else
840 skb_reserve(skb, 4);
841
842bail:
843 return skb;
844}
845
846/**
847 * ipath_rcv_layer - receive a packet for the layered (ethernet) driver
848 * @dd: the infinipath device
849 * @etail: the sk_buff number
850 * @tlen: the total packet length
851 * @hdr: the ethernet header
852 *
853 * Separate routine for better overall optimization
854 */
855static void ipath_rcv_layer(struct ipath_devdata *dd, u32 etail,
856 u32 tlen, struct ether_header *hdr)
857{
858 u32 elen;
859 u8 pad, *bthbytes;
860 struct sk_buff *skb, *nskb;
861
862 if (dd->ipath_port0_skbs && hdr->sub_opcode == OPCODE_ENCAP) {
863 /*
864 * Allocate a new sk_buff to replace the one we give
865 * to the network stack.
866 */
867 nskb = ipath_alloc_skb(dd, GFP_ATOMIC);
868 if (!nskb) {
869 /* count OK packets that we drop */
870 ipath_stats.sps_krdrops++;
871 return;
872 }
873
874 bthbytes = (u8 *) hdr->bth;
875 pad = (bthbytes[1] >> 4) & 3;
876 /* +CRC32 */
877 elen = tlen - (sizeof(*hdr) + pad + sizeof(u32));
878
879 skb = dd->ipath_port0_skbs[etail];
880 dd->ipath_port0_skbs[etail] = nskb;
881 skb_put(skb, elen);
882
883 dd->ipath_f_put_tid(dd, etail + (u64 __iomem *)
884 ((char __iomem *) dd->ipath_kregbase
885 + dd->ipath_rcvegrbase), 0,
886 virt_to_phys(nskb->data));
887
888 __ipath_layer_rcv(dd, hdr, skb);
889
890 /* another ether packet received */
891 ipath_stats.sps_ether_rpkts++;
892 }
893 else if (hdr->sub_opcode == OPCODE_LID_ARP)
894 __ipath_layer_rcv_lid(dd, hdr);
895}
896
897/*
898 * ipath_kreceive - receive a packet
899 * @dd: the infinipath device
900 *
901 * called from interrupt handler for errors or receive interrupt
902 */
903void ipath_kreceive(struct ipath_devdata *dd)
904{
905 u64 *rc;
906 void *ebuf;
907 const u32 rsize = dd->ipath_rcvhdrentsize; /* words */
908 const u32 maxcnt = dd->ipath_rcvhdrcnt * rsize; /* words */
909 u32 etail = -1, l, hdrqtail;
910 struct ips_message_header *hdr;
911 u32 eflags, i, etype, tlen, pkttot = 0;
912 static u64 totcalls; /* stats, may eventually remove */
913 char emsg[128];
914
915 if (!dd->ipath_hdrqtailptr) {
916 ipath_dev_err(dd,
917 "hdrqtailptr not set, can't do receives\n");
918 goto bail;
919 }
920
921 /* There is already a thread processing this queue. */
922 if (test_and_set_bit(0, &dd->ipath_rcv_pending))
923 goto bail;
924
925 if (dd->ipath_port0head ==
926 (u32)le64_to_cpu(*dd->ipath_hdrqtailptr))
927 goto done;
928
929gotmore:
930 /*
931 * read only once at start. If in flood situation, this helps
932 * performance slightly. If more arrive while we are processing,
933 * we'll come back here and do them
934 */
935 hdrqtail = (u32)le64_to_cpu(*dd->ipath_hdrqtailptr);
936
937 for (i = 0, l = dd->ipath_port0head; l != hdrqtail; i++) {
938 u32 qp;
939 u8 *bthbytes;
940
941 rc = (u64 *) (dd->ipath_pd[0]->port_rcvhdrq + (l << 2));
942 hdr = (struct ips_message_header *)&rc[1];
943 /*
944 * could make a network order version of IPATH_KD_QP, and
945 * do the obvious shift before masking to speed this up.
946 */
947 qp = ntohl(hdr->bth[1]) & 0xffffff;
948 bthbytes = (u8 *) hdr->bth;
949
950 eflags = ips_get_hdr_err_flags((__le32 *) rc);
951 etype = ips_get_rcv_type((__le32 *) rc);
952 /* total length */
953 tlen = ips_get_length_in_bytes((__le32 *) rc);
954 ebuf = NULL;
955 if (etype != RCVHQ_RCV_TYPE_EXPECTED) {
956 /*
957 * it turns out that the chips uses an eager buffer
958 * for all non-expected packets, whether it "needs"
959 * one or not. So always get the index, but don't
960 * set ebuf (so we try to copy data) unless the
961 * length requires it.
962 */
963 etail = ips_get_index((__le32 *) rc);
964 if (tlen > sizeof(*hdr) ||
965 etype == RCVHQ_RCV_TYPE_NON_KD)
966 ebuf = ipath_get_egrbuf(dd, etail, 0);
967 }
968
969 /*
970 * both tiderr and ipathhdrerr are set for all plain IB
971 * packets; only ipathhdrerr should be set.
972 */
973
974 if (etype != RCVHQ_RCV_TYPE_NON_KD && etype !=
975 RCVHQ_RCV_TYPE_ERROR && ips_get_ipath_ver(
976 hdr->iph.ver_port_tid_offset) !=
977 IPS_PROTO_VERSION) {
978 ipath_cdbg(PKT, "Bad InfiniPath protocol version "
979 "%x\n", etype);
980 }
981
982 if (eflags & ~(INFINIPATH_RHF_H_TIDERR |
983 INFINIPATH_RHF_H_IHDRERR)) {
984 get_rhf_errstring(eflags, emsg, sizeof emsg);
985 ipath_cdbg(PKT, "RHFerrs %x hdrqtail=%x typ=%u "
986 "tlen=%x opcode=%x egridx=%x: %s\n",
987 eflags, l, etype, tlen, bthbytes[0],
988 ips_get_index((__le32 *) rc), emsg);
989 } else if (etype == RCVHQ_RCV_TYPE_NON_KD) {
990 int ret = __ipath_verbs_rcv(dd, rc + 1,
991 ebuf, tlen);
992 if (ret == -ENODEV)
993 ipath_cdbg(VERBOSE,
994 "received IB packet, "
995 "not SMA (QP=%x)\n", qp);
996 } else if (etype == RCVHQ_RCV_TYPE_EAGER) {
997 if (qp == IPATH_KD_QP &&
998 bthbytes[0] == ipath_layer_rcv_opcode &&
999 ebuf)
1000 ipath_rcv_layer(dd, etail, tlen,
1001 (struct ether_header *)hdr);
1002 else
1003 ipath_cdbg(PKT, "typ %x, opcode %x (eager, "
1004 "qp=%x), len %x; ignored\n",
1005 etype, bthbytes[0], qp, tlen);
1006 }
1007 else if (etype == RCVHQ_RCV_TYPE_EXPECTED)
1008 ipath_dbg("Bug: Expected TID, opcode %x; ignored\n",
1009 be32_to_cpu(hdr->bth[0]) & 0xff);
1010 else if (eflags & (INFINIPATH_RHF_H_TIDERR |
1011 INFINIPATH_RHF_H_IHDRERR)) {
1012 /*
1013 * This is a type 3 packet, only the LRH is in the
1014 * rcvhdrq, the rest of the header is in the eager
1015 * buffer.
1016 */
1017 u8 opcode;
1018 if (ebuf) {
1019 bthbytes = (u8 *) ebuf;
1020 opcode = *bthbytes;
1021 }
1022 else
1023 opcode = 0;
1024 get_rhf_errstring(eflags, emsg, sizeof emsg);
1025 ipath_dbg("Err %x (%s), opcode %x, egrbuf %x, "
1026 "len %x\n", eflags, emsg, opcode, etail,
1027 tlen);
1028 } else {
1029 /*
1030 * error packet, type of error unknown.
1031 * Probably type 3, but we don't know, so don't
1032 * even try to print the opcode, etc.
1033 */
1034 ipath_dbg("Error Pkt, but no eflags! egrbuf %x, "
1035 "len %x\nhdrq@%lx;hdrq+%x rhf: %llx; "
1036 "hdr %llx %llx %llx %llx %llx\n",
1037 etail, tlen, (unsigned long) rc, l,
1038 (unsigned long long) rc[0],
1039 (unsigned long long) rc[1],
1040 (unsigned long long) rc[2],
1041 (unsigned long long) rc[3],
1042 (unsigned long long) rc[4],
1043 (unsigned long long) rc[5]);
1044 }
1045 l += rsize;
1046 if (l >= maxcnt)
1047 l = 0;
1048 /*
1049 * update for each packet, to help prevent overflows if we
1050 * have lots of packets.
1051 */
1052 (void)ipath_write_ureg(dd, ur_rcvhdrhead,
1053 dd->ipath_rhdrhead_intr_off | l, 0);
1054 if (etype != RCVHQ_RCV_TYPE_EXPECTED)
1055 (void)ipath_write_ureg(dd, ur_rcvegrindexhead,
1056 etail, 0);
1057 }
1058
1059 pkttot += i;
1060
1061 dd->ipath_port0head = l;
1062
1063 if (hdrqtail != (u32)le64_to_cpu(*dd->ipath_hdrqtailptr))
1064 /* more arrived while we handled first batch */
1065 goto gotmore;
1066
1067 if (pkttot > ipath_stats.sps_maxpkts_call)
1068 ipath_stats.sps_maxpkts_call = pkttot;
1069 ipath_stats.sps_port0pkts += pkttot;
1070 ipath_stats.sps_avgpkts_call =
1071 ipath_stats.sps_port0pkts / ++totcalls;
1072
1073done:
1074 clear_bit(0, &dd->ipath_rcv_pending);
1075 smp_mb__after_clear_bit();
1076
1077bail:;
1078}
1079
1080/**
1081 * ipath_update_pio_bufs - update shadow copy of the PIO availability map
1082 * @dd: the infinipath device
1083 *
1084 * called whenever our local copy indicates we have run out of send buffers
1085 * NOTE: This can be called from interrupt context by some code
1086 * and from non-interrupt context by ipath_getpiobuf().
1087 */
1088
1089static void ipath_update_pio_bufs(struct ipath_devdata *dd)
1090{
1091 unsigned long flags;
1092 int i;
1093 const unsigned piobregs = (unsigned)dd->ipath_pioavregs;
1094
1095 /* If the generation (check) bits have changed, then we update the
1096 * busy bit for the corresponding PIO buffer. This algorithm will
1097 * modify positions to the value they already have in some cases
1098 * (i.e., no change), but it's faster than changing only the bits
1099 * that have changed.
1100 *
1101 * We would like to do this atomicly, to avoid spinlocks in the
1102 * critical send path, but that's not really possible, given the
1103 * type of changes, and that this routine could be called on
1104 * multiple cpu's simultaneously, so we lock in this routine only,
1105 * to avoid conflicting updates; all we change is the shadow, and
1106 * it's a single 64 bit memory location, so by definition the update
1107 * is atomic in terms of what other cpu's can see in testing the
1108 * bits. The spin_lock overhead isn't too bad, since it only
1109 * happens when all buffers are in use, so only cpu overhead, not
1110 * latency or bandwidth is affected.
1111 */
1112#define _IPATH_ALL_CHECKBITS 0x5555555555555555ULL
1113 if (!dd->ipath_pioavailregs_dma) {
1114 ipath_dbg("Update shadow pioavail, but regs_dma NULL!\n");
1115 return;
1116 }
1117 if (ipath_debug & __IPATH_VERBDBG) {
1118 /* only if packet debug and verbose */
1119 volatile __le64 *dma = dd->ipath_pioavailregs_dma;
1120 unsigned long *shadow = dd->ipath_pioavailshadow;
1121
1122 ipath_cdbg(PKT, "Refill avail, dma0=%llx shad0=%lx, "
1123 "d1=%llx s1=%lx, d2=%llx s2=%lx, d3=%llx "
1124 "s3=%lx\n",
1125 (unsigned long long) le64_to_cpu(dma[0]),
1126 shadow[0],
1127 (unsigned long long) le64_to_cpu(dma[1]),
1128 shadow[1],
1129 (unsigned long long) le64_to_cpu(dma[2]),
1130 shadow[2],
1131 (unsigned long long) le64_to_cpu(dma[3]),
1132 shadow[3]);
1133 if (piobregs > 4)
1134 ipath_cdbg(
1135 PKT, "2nd group, dma4=%llx shad4=%lx, "
1136 "d5=%llx s5=%lx, d6=%llx s6=%lx, "
1137 "d7=%llx s7=%lx\n",
1138 (unsigned long long) le64_to_cpu(dma[4]),
1139 shadow[4],
1140 (unsigned long long) le64_to_cpu(dma[5]),
1141 shadow[5],
1142 (unsigned long long) le64_to_cpu(dma[6]),
1143 shadow[6],
1144 (unsigned long long) le64_to_cpu(dma[7]),
1145 shadow[7]);
1146 }
1147 spin_lock_irqsave(&ipath_pioavail_lock, flags);
1148 for (i = 0; i < piobregs; i++) {
1149 u64 pchbusy, pchg, piov, pnew;
1150 /*
1151 * Chip Errata: bug 6641; even and odd qwords>3 are swapped
1152 */
1153 if (i > 3) {
1154 if (i & 1)
1155 piov = le64_to_cpu(
1156 dd->ipath_pioavailregs_dma[i - 1]);
1157 else
1158 piov = le64_to_cpu(
1159 dd->ipath_pioavailregs_dma[i + 1]);
1160 } else
1161 piov = le64_to_cpu(dd->ipath_pioavailregs_dma[i]);
1162 pchg = _IPATH_ALL_CHECKBITS &
1163 ~(dd->ipath_pioavailshadow[i] ^ piov);
1164 pchbusy = pchg << INFINIPATH_SENDPIOAVAIL_BUSY_SHIFT;
1165 if (pchg && (pchbusy & dd->ipath_pioavailshadow[i])) {
1166 pnew = dd->ipath_pioavailshadow[i] & ~pchbusy;
1167 pnew |= piov & pchbusy;
1168 dd->ipath_pioavailshadow[i] = pnew;
1169 }
1170 }
1171 spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
1172}
1173
1174/**
1175 * ipath_setrcvhdrsize - set the receive header size
1176 * @dd: the infinipath device
1177 * @rhdrsize: the receive header size
1178 *
1179 * called from user init code, and also layered driver init
1180 */
1181int ipath_setrcvhdrsize(struct ipath_devdata *dd, unsigned rhdrsize)
1182{
1183 int ret = 0;
1184
1185 if (dd->ipath_flags & IPATH_RCVHDRSZ_SET) {
1186 if (dd->ipath_rcvhdrsize != rhdrsize) {
1187 dev_info(&dd->pcidev->dev,
1188 "Error: can't set protocol header "
1189 "size %u, already %u\n",
1190 rhdrsize, dd->ipath_rcvhdrsize);
1191 ret = -EAGAIN;
1192 } else
1193 ipath_cdbg(VERBOSE, "Reuse same protocol header "
1194 "size %u\n", dd->ipath_rcvhdrsize);
1195 } else if (rhdrsize > (dd->ipath_rcvhdrentsize -
1196 (sizeof(u64) / sizeof(u32)))) {
1197 ipath_dbg("Error: can't set protocol header size %u "
1198 "(> max %u)\n", rhdrsize,
1199 dd->ipath_rcvhdrentsize -
1200 (u32) (sizeof(u64) / sizeof(u32)));
1201 ret = -EOVERFLOW;
1202 } else {
1203 dd->ipath_flags |= IPATH_RCVHDRSZ_SET;
1204 dd->ipath_rcvhdrsize = rhdrsize;
1205 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrsize,
1206 dd->ipath_rcvhdrsize);
1207 ipath_cdbg(VERBOSE, "Set protocol header size to %u\n",
1208 dd->ipath_rcvhdrsize);
1209 }
1210 return ret;
1211}
1212
1213/**
1214 * ipath_getpiobuf - find an available pio buffer
1215 * @dd: the infinipath device
1216 * @pbufnum: the buffer number is placed here
1217 *
1218 * do appropriate marking as busy, etc.
1219 * returns buffer number if one found (>=0), negative number is error.
1220 * Used by ipath_sma_send_pkt and ipath_layer_send
1221 */
1222u32 __iomem *ipath_getpiobuf(struct ipath_devdata *dd, u32 * pbufnum)
1223{
1224 int i, j, starti, updated = 0;
1225 unsigned piobcnt, iter;
1226 unsigned long flags;
1227 unsigned long *shadow = dd->ipath_pioavailshadow;
1228 u32 __iomem *buf;
1229
1230 piobcnt = (unsigned)(dd->ipath_piobcnt2k
1231 + dd->ipath_piobcnt4k);
1232 starti = dd->ipath_lastport_piobuf;
1233 iter = piobcnt - starti;
1234 if (dd->ipath_upd_pio_shadow) {
1235 /*
1236 * Minor optimization. If we had no buffers on last call,
1237 * start out by doing the update; continue and do scan even
1238 * if no buffers were updated, to be paranoid
1239 */
1240 ipath_update_pio_bufs(dd);
1241 /* we scanned here, don't do it at end of scan */
1242 updated = 1;
1243 i = starti;
1244 } else
1245 i = dd->ipath_lastpioindex;
1246
1247rescan:
1248 /*
1249 * while test_and_set_bit() is atomic, we do that and then the
1250 * change_bit(), and the pair is not. See if this is the cause
1251 * of the remaining armlaunch errors.
1252 */
1253 spin_lock_irqsave(&ipath_pioavail_lock, flags);
1254 for (j = 0; j < iter; j++, i++) {
1255 if (i >= piobcnt)
1256 i = starti;
1257 /*
1258 * To avoid bus lock overhead, we first find a candidate
1259 * buffer, then do the test and set, and continue if that
1260 * fails.
1261 */
1262 if (test_bit((2 * i) + 1, shadow) ||
1263 test_and_set_bit((2 * i) + 1, shadow))
1264 continue;
1265 /* flip generation bit */
1266 change_bit(2 * i, shadow);
1267 break;
1268 }
1269 spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
1270
1271 if (j == iter) {
1272 volatile __le64 *dma = dd->ipath_pioavailregs_dma;
1273
1274 /*
1275 * first time through; shadow exhausted, but may be real
1276 * buffers available, so go see; if any updated, rescan
1277 * (once)
1278 */
1279 if (!updated) {
1280 ipath_update_pio_bufs(dd);
1281 updated = 1;
1282 i = starti;
1283 goto rescan;
1284 }
1285 dd->ipath_upd_pio_shadow = 1;
1286 /*
1287 * not atomic, but if we lose one once in a while, that's OK
1288 */
1289 ipath_stats.sps_nopiobufs++;
1290 if (!(++dd->ipath_consec_nopiobuf % 100000)) {
1291 ipath_dbg(
1292 "%u pio sends with no bufavail; dmacopy: "
1293 "%llx %llx %llx %llx; shadow: "
1294 "%lx %lx %lx %lx\n",
1295 dd->ipath_consec_nopiobuf,
1296 (unsigned long long) le64_to_cpu(dma[0]),
1297 (unsigned long long) le64_to_cpu(dma[1]),
1298 (unsigned long long) le64_to_cpu(dma[2]),
1299 (unsigned long long) le64_to_cpu(dma[3]),
1300 shadow[0], shadow[1], shadow[2],
1301 shadow[3]);
1302 /*
1303 * 4 buffers per byte, 4 registers above, cover rest
1304 * below
1305 */
1306 if ((dd->ipath_piobcnt2k + dd->ipath_piobcnt4k) >
1307 (sizeof(shadow[0]) * 4 * 4))
1308 ipath_dbg("2nd group: dmacopy: %llx %llx "
1309 "%llx %llx; shadow: %lx %lx "
1310 "%lx %lx\n",
1311 (unsigned long long)
1312 le64_to_cpu(dma[4]),
1313 (unsigned long long)
1314 le64_to_cpu(dma[5]),
1315 (unsigned long long)
1316 le64_to_cpu(dma[6]),
1317 (unsigned long long)
1318 le64_to_cpu(dma[7]),
1319 shadow[4], shadow[5],
1320 shadow[6], shadow[7]);
1321 }
1322 buf = NULL;
1323 goto bail;
1324 }
1325
1326 if (updated)
1327 /*
1328 * ran out of bufs, now some (at least this one we just
1329 * got) are now available, so tell the layered driver.
1330 */
1331 __ipath_layer_intr(dd, IPATH_LAYER_INT_SEND_CONTINUE);
1332
1333 /*
1334 * set next starting place. Since it's just an optimization,
1335 * it doesn't matter who wins on this, so no locking
1336 */
1337 dd->ipath_lastpioindex = i + 1;
1338 if (dd->ipath_upd_pio_shadow)
1339 dd->ipath_upd_pio_shadow = 0;
1340 if (dd->ipath_consec_nopiobuf)
1341 dd->ipath_consec_nopiobuf = 0;
1342 if (i < dd->ipath_piobcnt2k)
1343 buf = (u32 __iomem *) (dd->ipath_pio2kbase +
1344 i * dd->ipath_palign);
1345 else
1346 buf = (u32 __iomem *)
1347 (dd->ipath_pio4kbase +
1348 (i - dd->ipath_piobcnt2k) * dd->ipath_4kalign);
1349 ipath_cdbg(VERBOSE, "Return piobuf%u %uk @ %p\n",
1350 i, (i < dd->ipath_piobcnt2k) ? 2 : 4, buf);
1351 if (pbufnum)
1352 *pbufnum = i;
1353
1354bail:
1355 return buf;
1356}
1357
1358/**
1359 * ipath_create_rcvhdrq - create a receive header queue
1360 * @dd: the infinipath device
1361 * @pd: the port data
1362 *
1363 * this *must* be physically contiguous memory, and for now,
1364 * that limits it to what kmalloc can do.
1365 */
1366int ipath_create_rcvhdrq(struct ipath_devdata *dd,
1367 struct ipath_portdata *pd)
1368{
1369 int ret = 0, amt;
1370
1371 amt = ALIGN(dd->ipath_rcvhdrcnt * dd->ipath_rcvhdrentsize *
1372 sizeof(u32), PAGE_SIZE);
1373 if (!pd->port_rcvhdrq) {
1374 /*
1375 * not using REPEAT isn't viable; at 128KB, we can easily
1376 * fail this. The problem with REPEAT is we can block here
1377 * "forever". There isn't an inbetween, unfortunately. We
1378 * could reduce the risk by never freeing the rcvhdrq except
1379 * at unload, but even then, the first time a port is used,
1380 * we could delay for some time...
1381 */
1382 gfp_t gfp_flags = GFP_USER | __GFP_COMP;
1383
1384 pd->port_rcvhdrq = dma_alloc_coherent(
1385 &dd->pcidev->dev, amt, &pd->port_rcvhdrq_phys,
1386 gfp_flags);
1387
1388 if (!pd->port_rcvhdrq) {
1389 ipath_dev_err(dd, "attempt to allocate %d bytes "
1390 "for port %u rcvhdrq failed\n",
1391 amt, pd->port_port);
1392 ret = -ENOMEM;
1393 goto bail;
1394 }
1395
1396 pd->port_rcvhdrq_size = amt;
1397
1398 ipath_cdbg(VERBOSE, "%d pages at %p (phys %lx) size=%lu "
1399 "for port %u rcvhdr Q\n",
1400 amt >> PAGE_SHIFT, pd->port_rcvhdrq,
1401 (unsigned long) pd->port_rcvhdrq_phys,
1402 (unsigned long) pd->port_rcvhdrq_size,
1403 pd->port_port);
1404 } else {
1405 /*
1406 * clear for security, sanity, and/or debugging, each
1407 * time we reuse
1408 */
1409 memset(pd->port_rcvhdrq, 0, amt);
1410 }
1411
1412 /*
1413 * tell chip each time we init it, even if we are re-using previous
1414 * memory (we zero it at process close)
1415 */
1416 ipath_cdbg(VERBOSE, "writing port %d rcvhdraddr as %lx\n",
1417 pd->port_port, (unsigned long) pd->port_rcvhdrq_phys);
1418 ipath_write_kreg_port(dd, dd->ipath_kregs->kr_rcvhdraddr,
1419 pd->port_port, pd->port_rcvhdrq_phys);
1420
1421 ret = 0;
1422bail:
1423 return ret;
1424}
1425
1426int ipath_waitfor_complete(struct ipath_devdata *dd, ipath_kreg reg_id,
1427 u64 bits_to_wait_for, u64 * valp)
1428{
1429 unsigned long timeout;
1430 u64 lastval, val;
1431 int ret;
1432
1433 lastval = ipath_read_kreg64(dd, reg_id);
1434 /* wait a ridiculously long time */
1435 timeout = jiffies + msecs_to_jiffies(5);
1436 do {
1437 val = ipath_read_kreg64(dd, reg_id);
1438 /* set so they have something, even on failures. */
1439 *valp = val;
1440 if ((val & bits_to_wait_for) == bits_to_wait_for) {
1441 ret = 0;
1442 break;
1443 }
1444 if (val != lastval)
1445 ipath_cdbg(VERBOSE, "Changed from %llx to %llx, "
1446 "waiting for %llx bits\n",
1447 (unsigned long long) lastval,
1448 (unsigned long long) val,
1449 (unsigned long long) bits_to_wait_for);
1450 cond_resched();
1451 if (time_after(jiffies, timeout)) {
1452 ipath_dbg("Didn't get bits %llx in register 0x%x, "
1453 "got %llx\n",
1454 (unsigned long long) bits_to_wait_for,
1455 reg_id, (unsigned long long) *valp);
1456 ret = -ENODEV;
1457 break;
1458 }
1459 } while (1);
1460
1461 return ret;
1462}
1463
1464/**
1465 * ipath_waitfor_mdio_cmdready - wait for last command to complete
1466 * @dd: the infinipath device
1467 *
1468 * Like ipath_waitfor_complete(), but we wait for the CMDVALID bit to go
1469 * away indicating the last command has completed. It doesn't return data
1470 */
1471int ipath_waitfor_mdio_cmdready(struct ipath_devdata *dd)
1472{
1473 unsigned long timeout;
1474 u64 val;
1475 int ret;
1476
1477 /* wait a ridiculously long time */
1478 timeout = jiffies + msecs_to_jiffies(5);
1479 do {
1480 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_mdio);
1481 if (!(val & IPATH_MDIO_CMDVALID)) {
1482 ret = 0;
1483 break;
1484 }
1485 cond_resched();
1486 if (time_after(jiffies, timeout)) {
1487 ipath_dbg("CMDVALID stuck in mdio reg? (%llx)\n",
1488 (unsigned long long) val);
1489 ret = -ENODEV;
1490 break;
1491 }
1492 } while (1);
1493
1494 return ret;
1495}
1496
1497void ipath_set_ib_lstate(struct ipath_devdata *dd, int which)
1498{
1499 static const char *what[4] = {
1500 [0] = "DOWN",
1501 [INFINIPATH_IBCC_LINKCMD_INIT] = "INIT",
1502 [INFINIPATH_IBCC_LINKCMD_ARMED] = "ARMED",
1503 [INFINIPATH_IBCC_LINKCMD_ACTIVE] = "ACTIVE"
1504 };
1505 ipath_cdbg(SMA, "Trying to move unit %u to %s, current ltstate "
1506 "is %s\n", dd->ipath_unit,
1507 what[(which >> INFINIPATH_IBCC_LINKCMD_SHIFT) &
1508 INFINIPATH_IBCC_LINKCMD_MASK],
1509 ipath_ibcstatus_str[
1510 (ipath_read_kreg64
1511 (dd, dd->ipath_kregs->kr_ibcstatus) >>
1512 INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
1513 INFINIPATH_IBCS_LINKTRAININGSTATE_MASK]);
1514
1515 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
1516 dd->ipath_ibcctrl | which);
1517}
1518
1519/**
1520 * ipath_read_kreg64_port - read a device's per-port 64-bit kernel register
1521 * @dd: the infinipath device
1522 * @regno: the register number to read
1523 * @port: the port containing the register
1524 *
1525 * Registers that vary with the chip implementation constants (port)
1526 * use this routine.
1527 */
1528u64 ipath_read_kreg64_port(const struct ipath_devdata *dd, ipath_kreg regno,
1529 unsigned port)
1530{
1531 u16 where;
1532
1533 if (port < dd->ipath_portcnt &&
1534 (regno == dd->ipath_kregs->kr_rcvhdraddr ||
1535 regno == dd->ipath_kregs->kr_rcvhdrtailaddr))
1536 where = regno + port;
1537 else
1538 where = -1;
1539
1540 return ipath_read_kreg64(dd, where);
1541}
1542
1543/**
1544 * ipath_write_kreg_port - write a device's per-port 64-bit kernel register
1545 * @dd: the infinipath device
1546 * @regno: the register number to write
1547 * @port: the port containing the register
1548 * @value: the value to write
1549 *
1550 * Registers that vary with the chip implementation constants (port)
1551 * use this routine.
1552 */
1553void ipath_write_kreg_port(const struct ipath_devdata *dd, ipath_kreg regno,
1554 unsigned port, u64 value)
1555{
1556 u16 where;
1557
1558 if (port < dd->ipath_portcnt &&
1559 (regno == dd->ipath_kregs->kr_rcvhdraddr ||
1560 regno == dd->ipath_kregs->kr_rcvhdrtailaddr))
1561 where = regno + port;
1562 else
1563 where = -1;
1564
1565 ipath_write_kreg(dd, where, value);
1566}
1567
1568/**
1569 * ipath_shutdown_device - shut down a device
1570 * @dd: the infinipath device
1571 *
1572 * This is called to make the device quiet when we are about to
1573 * unload the driver, and also when the device is administratively
1574 * disabled. It does not free any data structures.
1575 * Everything it does has to be setup again by ipath_init_chip(dd,1)
1576 */
1577void ipath_shutdown_device(struct ipath_devdata *dd)
1578{
1579 u64 val;
1580
1581 ipath_dbg("Shutting down the device\n");
1582
1583 dd->ipath_flags |= IPATH_LINKUNK;
1584 dd->ipath_flags &= ~(IPATH_INITTED | IPATH_LINKDOWN |
1585 IPATH_LINKINIT | IPATH_LINKARMED |
1586 IPATH_LINKACTIVE);
1587 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_CONF |
1588 IPATH_STATUS_IB_READY);
1589
1590 /* mask interrupts, but not errors */
1591 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
1592
1593 dd->ipath_rcvctrl = 0;
1594 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1595 dd->ipath_rcvctrl);
1596
1597 /*
1598 * gracefully stop all sends allowing any in progress to trickle out
1599 * first.
1600 */
1601 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, 0ULL);
1602 /* flush it */
1603 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
1604 /*
1605 * enough for anything that's going to trickle out to have actually
1606 * done so.
1607 */
1608 udelay(5);
1609
1610 /*
1611 * abort any armed or launched PIO buffers that didn't go. (self
1612 * clearing). Will cause any packet currently being transmitted to
1613 * go out with an EBP, and may also cause a short packet error on
1614 * the receiver.
1615 */
1616 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1617 INFINIPATH_S_ABORT);
1618
1619 ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKINITCMD_DISABLE <<
1620 INFINIPATH_IBCC_LINKINITCMD_SHIFT);
1621
1622 /*
1623 * we are shutting down, so tell the layered driver. We don't do
1624 * this on just a link state change, much like ethernet, a cable
1625 * unplug, etc. doesn't change driver state
1626 */
1627 ipath_layer_intr(dd, IPATH_LAYER_INT_IF_DOWN);
1628
1629 /* disable IBC */
1630 dd->ipath_control &= ~INFINIPATH_C_LINKENABLE;
1631 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
1632 dd->ipath_control);
1633
1634 /*
1635 * clear SerdesEnable and turn the leds off; do this here because
1636 * we are unloading, so don't count on interrupts to move along
1637 * Turn the LEDs off explictly for the same reason.
1638 */
1639 dd->ipath_f_quiet_serdes(dd);
1640 dd->ipath_f_setextled(dd, 0, 0);
1641
1642 if (dd->ipath_stats_timer_active) {
1643 del_timer_sync(&dd->ipath_stats_timer);
1644 dd->ipath_stats_timer_active = 0;
1645 }
1646
1647 /*
1648 * clear all interrupts and errors, so that the next time the driver
1649 * is loaded or device is enabled, we know that whatever is set
1650 * happened while we were unloaded
1651 */
1652 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
1653 ~0ULL & ~INFINIPATH_HWE_MEMBISTFAILED);
1654 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, -1LL);
1655 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, -1LL);
1656}
1657
1658/**
1659 * ipath_free_pddata - free a port's allocated data
1660 * @dd: the infinipath device
1661 * @port: the port
1662 * @freehdrq: free the port data structure if true
1663 *
1664 * when closing, free up any allocated data for a port, if the
1665 * reference count goes to zero
1666 * Note: this also optionally frees the portdata itself!
1667 * Any changes here have to be matched up with the reinit case
1668 * of ipath_init_chip(), which calls this routine on reinit after reset.
1669 */
1670void ipath_free_pddata(struct ipath_devdata *dd, u32 port, int freehdrq)
1671{
1672 struct ipath_portdata *pd = dd->ipath_pd[port];
1673
1674 if (!pd)
1675 return;
1676 if (freehdrq)
1677 /*
1678 * only clear and free portdata if we are going to also
1679 * release the hdrq, otherwise we leak the hdrq on each
1680 * open/close cycle
1681 */
1682 dd->ipath_pd[port] = NULL;
1683 if (freehdrq && pd->port_rcvhdrq) {
1684 ipath_cdbg(VERBOSE, "free closed port %d rcvhdrq @ %p "
1685 "(size=%lu)\n", pd->port_port, pd->port_rcvhdrq,
1686 (unsigned long) pd->port_rcvhdrq_size);
1687 dma_free_coherent(&dd->pcidev->dev, pd->port_rcvhdrq_size,
1688 pd->port_rcvhdrq, pd->port_rcvhdrq_phys);
1689 pd->port_rcvhdrq = NULL;
1690 }
1691 if (port && pd->port_rcvegrbuf) {
1692 /* always free this */
1693 if (pd->port_rcvegrbuf) {
1694 unsigned e;
1695
1696 for (e = 0; e < pd->port_rcvegrbuf_chunks; e++) {
1697 void *base = pd->port_rcvegrbuf[e];
1698 size_t size = pd->port_rcvegrbuf_size;
1699
1700 ipath_cdbg(VERBOSE, "egrbuf free(%p, %lu), "
1701 "chunk %u/%u\n", base,
1702 (unsigned long) size,
1703 e, pd->port_rcvegrbuf_chunks);
1704 dma_free_coherent(
1705 &dd->pcidev->dev, size, base,
1706 pd->port_rcvegrbuf_phys[e]);
1707 }
1708 vfree(pd->port_rcvegrbuf);
1709 pd->port_rcvegrbuf = NULL;
1710 vfree(pd->port_rcvegrbuf_phys);
1711 pd->port_rcvegrbuf_phys = NULL;
1712 }
1713 pd->port_rcvegrbuf_chunks = 0;
1714 } else if (port == 0 && dd->ipath_port0_skbs) {
1715 unsigned e;
1716 struct sk_buff **skbs = dd->ipath_port0_skbs;
1717
1718 dd->ipath_port0_skbs = NULL;
1719 ipath_cdbg(VERBOSE, "free closed port %d ipath_port0_skbs "
1720 "@ %p\n", pd->port_port, skbs);
1721 for (e = 0; e < dd->ipath_rcvegrcnt; e++)
1722 if (skbs[e])
1723 dev_kfree_skb(skbs[e]);
1724 vfree(skbs);
1725 }
1726 if (freehdrq) {
1727 kfree(pd->port_tid_pg_list);
1728 kfree(pd);
1729 }
1730}
1731
1732int __init infinipath_init(void)
1733{
1734 int ret;
1735
1736 ipath_dbg(KERN_INFO DRIVER_LOAD_MSG "%s", ipath_core_version);
1737
1738 /*
1739 * These must be called before the driver is registered with
1740 * the PCI subsystem.
1741 */
1742 idr_init(&unit_table);
1743 if (!idr_pre_get(&unit_table, GFP_KERNEL)) {
1744 ret = -ENOMEM;
1745 goto bail;
1746 }
1747
1748 ret = pci_register_driver(&ipath_driver);
1749 if (ret < 0) {
1750 printk(KERN_ERR IPATH_DRV_NAME
1751 ": Unable to register driver: error %d\n", -ret);
1752 goto bail_unit;
1753 }
1754
1755 ret = ipath_driver_create_group(&ipath_driver.driver);
1756 if (ret < 0) {
1757 printk(KERN_ERR IPATH_DRV_NAME ": Unable to create driver "
1758 "sysfs entries: error %d\n", -ret);
1759 goto bail_pci;
1760 }
1761
1762 ret = ipath_init_ipathfs();
1763 if (ret < 0) {
1764 printk(KERN_ERR IPATH_DRV_NAME ": Unable to create "
1765 "ipathfs: error %d\n", -ret);
1766 goto bail_group;
1767 }
1768
1769 goto bail;
1770
1771bail_group:
1772 ipath_driver_remove_group(&ipath_driver.driver);
1773
1774bail_pci:
1775 pci_unregister_driver(&ipath_driver);
1776
1777bail_unit:
1778 idr_destroy(&unit_table);
1779
1780bail:
1781 return ret;
1782}
1783
1784static void cleanup_device(struct ipath_devdata *dd)
1785{
1786 int port;
1787
1788 ipath_shutdown_device(dd);
1789
1790 if (*dd->ipath_statusp & IPATH_STATUS_CHIP_PRESENT) {
1791 /* can't do anything more with chip; needs re-init */
1792 *dd->ipath_statusp &= ~IPATH_STATUS_CHIP_PRESENT;
1793 if (dd->ipath_kregbase) {
1794 /*
1795 * if we haven't already cleaned up before these are
1796 * to ensure any register reads/writes "fail" until
1797 * re-init
1798 */
1799 dd->ipath_kregbase = NULL;
1800 dd->ipath_kregvirt = NULL;
1801 dd->ipath_uregbase = 0;
1802 dd->ipath_sregbase = 0;
1803 dd->ipath_cregbase = 0;
1804 dd->ipath_kregsize = 0;
1805 }
1806 ipath_disable_wc(dd);
1807 }
1808
1809 if (dd->ipath_pioavailregs_dma) {
1810 dma_free_coherent(&dd->pcidev->dev, PAGE_SIZE,
1811 (void *) dd->ipath_pioavailregs_dma,
1812 dd->ipath_pioavailregs_phys);
1813 dd->ipath_pioavailregs_dma = NULL;
1814 }
1815
1816 if (dd->ipath_pageshadow) {
1817 struct page **tmpp = dd->ipath_pageshadow;
1818 int i, cnt = 0;
1819
1820 ipath_cdbg(VERBOSE, "Unlocking any expTID pages still "
1821 "locked\n");
1822 for (port = 0; port < dd->ipath_cfgports; port++) {
1823 int port_tidbase = port * dd->ipath_rcvtidcnt;
1824 int maxtid = port_tidbase + dd->ipath_rcvtidcnt;
1825 for (i = port_tidbase; i < maxtid; i++) {
1826 if (!tmpp[i])
1827 continue;
1828 ipath_release_user_pages(&tmpp[i], 1);
1829 tmpp[i] = NULL;
1830 cnt++;
1831 }
1832 }
1833 if (cnt) {
1834 ipath_stats.sps_pageunlocks += cnt;
1835 ipath_cdbg(VERBOSE, "There were still %u expTID "
1836 "entries locked\n", cnt);
1837 }
1838 if (ipath_stats.sps_pagelocks ||
1839 ipath_stats.sps_pageunlocks)
1840 ipath_cdbg(VERBOSE, "%llu pages locked, %llu "
1841 "unlocked via ipath_m{un}lock\n",
1842 (unsigned long long)
1843 ipath_stats.sps_pagelocks,
1844 (unsigned long long)
1845 ipath_stats.sps_pageunlocks);
1846
1847 ipath_cdbg(VERBOSE, "Free shadow page tid array at %p\n",
1848 dd->ipath_pageshadow);
1849 vfree(dd->ipath_pageshadow);
1850 dd->ipath_pageshadow = NULL;
1851 }
1852
1853 /*
1854 * free any resources still in use (usually just kernel ports)
1855 * at unload
1856 */
1857 for (port = 0; port < dd->ipath_cfgports; port++)
1858 ipath_free_pddata(dd, port, 1);
1859 kfree(dd->ipath_pd);
1860 /*
1861 * debuggability, in case some cleanup path tries to use it
1862 * after this
1863 */
1864 dd->ipath_pd = NULL;
1865}
1866
1867static void __exit infinipath_cleanup(void)
1868{
1869 struct ipath_devdata *dd, *tmp;
1870 unsigned long flags;
1871
1872 ipath_exit_ipathfs();
1873
1874 ipath_driver_remove_group(&ipath_driver.driver);
1875
1876 spin_lock_irqsave(&ipath_devs_lock, flags);
1877
1878 /*
1879 * turn off rcv, send, and interrupts for all ports, all drivers
1880 * should also hard reset the chip here?
1881 * free up port 0 (kernel) rcvhdr, egr bufs, and eventually tid bufs
1882 * for all versions of the driver, if they were allocated
1883 */
1884 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
1885 spin_unlock_irqrestore(&ipath_devs_lock, flags);
1886
1887 if (dd->ipath_kregbase)
1888 cleanup_device(dd);
1889
1890 if (dd->pcidev) {
1891 if (dd->pcidev->irq) {
1892 ipath_cdbg(VERBOSE,
1893 "unit %u free_irq of irq %x\n",
1894 dd->ipath_unit, dd->pcidev->irq);
1895 free_irq(dd->pcidev->irq, dd);
1896 } else
1897 ipath_dbg("irq is 0, not doing free_irq "
1898 "for unit %u\n", dd->ipath_unit);
1899 dd->pcidev = NULL;
1900 }
1901
1902 /*
1903 * we check for NULL here, because it's outside the kregbase
1904 * check, and we need to call it after the free_irq. Thus
1905 * it's possible that the function pointers were never
1906 * initialized.
1907 */
1908 if (dd->ipath_f_cleanup)
1909 /* clean up chip-specific stuff */
1910 dd->ipath_f_cleanup(dd);
1911
1912 spin_lock_irqsave(&ipath_devs_lock, flags);
1913 }
1914
1915 spin_unlock_irqrestore(&ipath_devs_lock, flags);
1916
1917 ipath_cdbg(VERBOSE, "Unregistering pci driver\n");
1918 pci_unregister_driver(&ipath_driver);
1919
1920 idr_destroy(&unit_table);
1921}
1922
1923/**
1924 * ipath_reset_device - reset the chip if possible
1925 * @unit: the device to reset
1926 *
1927 * Whether or not reset is successful, we attempt to re-initialize the chip
1928 * (that is, much like a driver unload/reload). We clear the INITTED flag
1929 * so that the various entry points will fail until we reinitialize. For
1930 * now, we only allow this if no user ports are open that use chip resources
1931 */
1932int ipath_reset_device(int unit)
1933{
1934 int ret, i;
1935 struct ipath_devdata *dd = ipath_lookup(unit);
1936
1937 if (!dd) {
1938 ret = -ENODEV;
1939 goto bail;
1940 }
1941
1942 dev_info(&dd->pcidev->dev, "Reset on unit %u requested\n", unit);
1943
1944 if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT)) {
1945 dev_info(&dd->pcidev->dev, "Invalid unit number %u or "
1946 "not initialized or not present\n", unit);
1947 ret = -ENXIO;
1948 goto bail;
1949 }
1950
1951 if (dd->ipath_pd)
1952 for (i = 1; i < dd->ipath_portcnt; i++) {
1953 if (dd->ipath_pd[i] && dd->ipath_pd[i]->port_cnt) {
1954 ipath_dbg("unit %u port %d is in use "
1955 "(PID %u cmd %s), can't reset\n",
1956 unit, i,
1957 dd->ipath_pd[i]->port_pid,
1958 dd->ipath_pd[i]->port_comm);
1959 ret = -EBUSY;
1960 goto bail;
1961 }
1962 }
1963
1964 dd->ipath_flags &= ~IPATH_INITTED;
1965 ret = dd->ipath_f_reset(dd);
1966 if (ret != 1)
1967 ipath_dbg("reset was not successful\n");
1968 ipath_dbg("Trying to reinitialize unit %u after reset attempt\n",
1969 unit);
1970 ret = ipath_init_chip(dd, 1);
1971 if (ret)
1972 ipath_dev_err(dd, "Reinitialize unit %u after "
1973 "reset failed with %d\n", unit, ret);
1974 else
1975 dev_info(&dd->pcidev->dev, "Reinitialized unit %u after "
1976 "resetting\n", unit);
1977
1978bail:
1979 return ret;
1980}
1981
1982module_init(infinipath_init);
1983module_exit(infinipath_cleanup);
diff --git a/drivers/infiniband/hw/ipath/ipath_eeprom.c b/drivers/infiniband/hw/ipath/ipath_eeprom.c
new file mode 100644
index 000000000000..f11a900e8cd7
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_eeprom.c
@@ -0,0 +1,613 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/delay.h>
34#include <linux/pci.h>
35#include <linux/vmalloc.h>
36
37#include "ipath_kernel.h"
38
39/*
40 * InfiniPath I2C driver for a serial eeprom. This is not a generic
41 * I2C interface. For a start, the device we're using (Atmel AT24C11)
42 * doesn't work like a regular I2C device. It looks like one
43 * electrically, but not logically. Normal I2C devices have a single
44 * 7-bit or 10-bit I2C address that they respond to. Valid 7-bit
45 * addresses range from 0x03 to 0x77. Addresses 0x00 to 0x02 and 0x78
46 * to 0x7F are special reserved addresses (e.g. 0x00 is the "general
47 * call" address.) The Atmel device, on the other hand, responds to ALL
48 * 7-bit addresses. It's designed to be the only device on a given I2C
49 * bus. A 7-bit address corresponds to the memory address within the
50 * Atmel device itself.
51 *
52 * Also, the timing requirements mean more than simple software
53 * bitbanging, with readbacks from chip to ensure timing (simple udelay
54 * is not enough).
55 *
56 * This all means that accessing the device is specialized enough
57 * that using the standard kernel I2C bitbanging interface would be
58 * impossible. For example, the core I2C eeprom driver expects to find
59 * a device at one or more of a limited set of addresses only. It doesn't
60 * allow writing to an eeprom. It also doesn't provide any means of
61 * accessing eeprom contents from within the kernel, only via sysfs.
62 */
63
64enum i2c_type {
65 i2c_line_scl = 0,
66 i2c_line_sda
67};
68
69enum i2c_state {
70 i2c_line_low = 0,
71 i2c_line_high
72};
73
74#define READ_CMD 1
75#define WRITE_CMD 0
76
77static int eeprom_init;
78
79/*
80 * The gpioval manipulation really should be protected by spinlocks
81 * or be converted to use atomic operations.
82 */
83
84/**
85 * i2c_gpio_set - set a GPIO line
86 * @dd: the infinipath device
87 * @line: the line to set
88 * @new_line_state: the state to set
89 *
90 * Returns 0 if the line was set to the new state successfully, non-zero
91 * on error.
92 */
93static int i2c_gpio_set(struct ipath_devdata *dd,
94 enum i2c_type line,
95 enum i2c_state new_line_state)
96{
97 u64 read_val, write_val, mask, *gpioval;
98
99 gpioval = &dd->ipath_gpio_out;
100 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extctrl);
101 if (line == i2c_line_scl)
102 mask = ipath_gpio_scl;
103 else
104 mask = ipath_gpio_sda;
105
106 if (new_line_state == i2c_line_high)
107 /* tri-state the output rather than force high */
108 write_val = read_val & ~mask;
109 else
110 /* config line to be an output */
111 write_val = read_val | mask;
112 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, write_val);
113
114 /* set high and verify */
115 if (new_line_state == i2c_line_high)
116 write_val = 0x1UL;
117 else
118 write_val = 0x0UL;
119
120 if (line == i2c_line_scl) {
121 write_val <<= ipath_gpio_scl_num;
122 *gpioval = *gpioval & ~(1UL << ipath_gpio_scl_num);
123 *gpioval |= write_val;
124 } else {
125 write_val <<= ipath_gpio_sda_num;
126 *gpioval = *gpioval & ~(1UL << ipath_gpio_sda_num);
127 *gpioval |= write_val;
128 }
129 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_out, *gpioval);
130
131 return 0;
132}
133
134/**
135 * i2c_gpio_get - get a GPIO line state
136 * @dd: the infinipath device
137 * @line: the line to get
138 * @curr_statep: where to put the line state
139 *
140 * Returns 0 if the line was set to the new state successfully, non-zero
141 * on error. curr_state is not set on error.
142 */
143static int i2c_gpio_get(struct ipath_devdata *dd,
144 enum i2c_type line,
145 enum i2c_state *curr_statep)
146{
147 u64 read_val, write_val, mask;
148 int ret;
149
150 /* check args */
151 if (curr_statep == NULL) {
152 ret = 1;
153 goto bail;
154 }
155
156 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extctrl);
157 /* config line to be an input */
158 if (line == i2c_line_scl)
159 mask = ipath_gpio_scl;
160 else
161 mask = ipath_gpio_sda;
162 write_val = read_val & ~mask;
163 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, write_val);
164 read_val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
165
166 if (read_val & mask)
167 *curr_statep = i2c_line_high;
168 else
169 *curr_statep = i2c_line_low;
170
171 ret = 0;
172
173bail:
174 return ret;
175}
176
177/**
178 * i2c_wait_for_writes - wait for a write
179 * @dd: the infinipath device
180 *
181 * We use this instead of udelay directly, so we can make sure
182 * that previous register writes have been flushed all the way
183 * to the chip. Since we are delaying anyway, the cost doesn't
184 * hurt, and makes the bit twiddling more regular
185 */
186static void i2c_wait_for_writes(struct ipath_devdata *dd)
187{
188 (void)ipath_read_kreg32(dd, dd->ipath_kregs->kr_scratch);
189}
190
191static void scl_out(struct ipath_devdata *dd, u8 bit)
192{
193 i2c_gpio_set(dd, i2c_line_scl, bit ? i2c_line_high : i2c_line_low);
194
195 i2c_wait_for_writes(dd);
196}
197
198static void sda_out(struct ipath_devdata *dd, u8 bit)
199{
200 i2c_gpio_set(dd, i2c_line_sda, bit ? i2c_line_high : i2c_line_low);
201
202 i2c_wait_for_writes(dd);
203}
204
205static u8 sda_in(struct ipath_devdata *dd, int wait)
206{
207 enum i2c_state bit;
208
209 if (i2c_gpio_get(dd, i2c_line_sda, &bit))
210 ipath_dbg("get bit failed!\n");
211
212 if (wait)
213 i2c_wait_for_writes(dd);
214
215 return bit == i2c_line_high ? 1U : 0;
216}
217
218/**
219 * i2c_ackrcv - see if ack following write is true
220 * @dd: the infinipath device
221 */
222static int i2c_ackrcv(struct ipath_devdata *dd)
223{
224 u8 ack_received;
225
226 /* AT ENTRY SCL = LOW */
227 /* change direction, ignore data */
228 ack_received = sda_in(dd, 1);
229 scl_out(dd, i2c_line_high);
230 ack_received = sda_in(dd, 1) == 0;
231 scl_out(dd, i2c_line_low);
232 return ack_received;
233}
234
235/**
236 * wr_byte - write a byte, one bit at a time
237 * @dd: the infinipath device
238 * @data: the byte to write
239 *
240 * Returns 0 if we got the following ack, otherwise 1
241 */
242static int wr_byte(struct ipath_devdata *dd, u8 data)
243{
244 int bit_cntr;
245 u8 bit;
246
247 for (bit_cntr = 7; bit_cntr >= 0; bit_cntr--) {
248 bit = (data >> bit_cntr) & 1;
249 sda_out(dd, bit);
250 scl_out(dd, i2c_line_high);
251 scl_out(dd, i2c_line_low);
252 }
253 return (!i2c_ackrcv(dd)) ? 1 : 0;
254}
255
256static void send_ack(struct ipath_devdata *dd)
257{
258 sda_out(dd, i2c_line_low);
259 scl_out(dd, i2c_line_high);
260 scl_out(dd, i2c_line_low);
261 sda_out(dd, i2c_line_high);
262}
263
264/**
265 * i2c_startcmd - transmit the start condition, followed by address/cmd
266 * @dd: the infinipath device
267 * @offset_dir: direction byte
268 *
269 * (both clock/data high, clock high, data low while clock is high)
270 */
271static int i2c_startcmd(struct ipath_devdata *dd, u8 offset_dir)
272{
273 int res;
274
275 /* issue start sequence */
276 sda_out(dd, i2c_line_high);
277 scl_out(dd, i2c_line_high);
278 sda_out(dd, i2c_line_low);
279 scl_out(dd, i2c_line_low);
280
281 /* issue length and direction byte */
282 res = wr_byte(dd, offset_dir);
283
284 if (res)
285 ipath_cdbg(VERBOSE, "No ack to complete start\n");
286
287 return res;
288}
289
290/**
291 * stop_cmd - transmit the stop condition
292 * @dd: the infinipath device
293 *
294 * (both clock/data low, clock high, data high while clock is high)
295 */
296static void stop_cmd(struct ipath_devdata *dd)
297{
298 scl_out(dd, i2c_line_low);
299 sda_out(dd, i2c_line_low);
300 scl_out(dd, i2c_line_high);
301 sda_out(dd, i2c_line_high);
302 udelay(2);
303}
304
305/**
306 * eeprom_reset - reset I2C communication
307 * @dd: the infinipath device
308 */
309
310static int eeprom_reset(struct ipath_devdata *dd)
311{
312 int clock_cycles_left = 9;
313 u64 *gpioval = &dd->ipath_gpio_out;
314 int ret;
315
316 eeprom_init = 1;
317 *gpioval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_out);
318 ipath_cdbg(VERBOSE, "Resetting i2c eeprom; initial gpioout reg "
319 "is %llx\n", (unsigned long long) *gpioval);
320
321 /*
322 * This is to get the i2c into a known state, by first going low,
323 * then tristate sda (and then tristate scl as first thing
324 * in loop)
325 */
326 scl_out(dd, i2c_line_low);
327 sda_out(dd, i2c_line_high);
328
329 while (clock_cycles_left--) {
330 scl_out(dd, i2c_line_high);
331
332 if (sda_in(dd, 0)) {
333 sda_out(dd, i2c_line_low);
334 scl_out(dd, i2c_line_low);
335 ret = 0;
336 goto bail;
337 }
338
339 scl_out(dd, i2c_line_low);
340 }
341
342 ret = 1;
343
344bail:
345 return ret;
346}
347
348/**
349 * ipath_eeprom_read - receives bytes from the eeprom via I2C
350 * @dd: the infinipath device
351 * @eeprom_offset: address to read from
352 * @buffer: where to store result
353 * @len: number of bytes to receive
354 */
355
356int ipath_eeprom_read(struct ipath_devdata *dd, u8 eeprom_offset,
357 void *buffer, int len)
358{
359 /* compiler complains unless initialized */
360 u8 single_byte = 0;
361 int bit_cntr;
362 int ret;
363
364 if (!eeprom_init)
365 eeprom_reset(dd);
366
367 eeprom_offset = (eeprom_offset << 1) | READ_CMD;
368
369 if (i2c_startcmd(dd, eeprom_offset)) {
370 ipath_dbg("Failed startcmd\n");
371 stop_cmd(dd);
372 ret = 1;
373 goto bail;
374 }
375
376 /*
377 * eeprom keeps clocking data out as long as we ack, automatically
378 * incrementing the address.
379 */
380 while (len-- > 0) {
381 /* get data */
382 single_byte = 0;
383 for (bit_cntr = 8; bit_cntr; bit_cntr--) {
384 u8 bit;
385 scl_out(dd, i2c_line_high);
386 bit = sda_in(dd, 0);
387 single_byte |= bit << (bit_cntr - 1);
388 scl_out(dd, i2c_line_low);
389 }
390
391 /* send ack if not the last byte */
392 if (len)
393 send_ack(dd);
394
395 *((u8 *) buffer) = single_byte;
396 buffer++;
397 }
398
399 stop_cmd(dd);
400
401 ret = 0;
402
403bail:
404 return ret;
405}
406
407/**
408 * ipath_eeprom_write - writes data to the eeprom via I2C
409 * @dd: the infinipath device
410 * @eeprom_offset: where to place data
411 * @buffer: data to write
412 * @len: number of bytes to write
413 */
414int ipath_eeprom_write(struct ipath_devdata *dd, u8 eeprom_offset,
415 const void *buffer, int len)
416{
417 u8 single_byte;
418 int sub_len;
419 const u8 *bp = buffer;
420 int max_wait_time, i;
421 int ret;
422
423 if (!eeprom_init)
424 eeprom_reset(dd);
425
426 while (len > 0) {
427 if (i2c_startcmd(dd, (eeprom_offset << 1) | WRITE_CMD)) {
428 ipath_dbg("Failed to start cmd offset %u\n",
429 eeprom_offset);
430 goto failed_write;
431 }
432
433 sub_len = min(len, 4);
434 eeprom_offset += sub_len;
435 len -= sub_len;
436
437 for (i = 0; i < sub_len; i++) {
438 if (wr_byte(dd, *bp++)) {
439 ipath_dbg("no ack after byte %u/%u (%u "
440 "total remain)\n", i, sub_len,
441 len + sub_len - i);
442 goto failed_write;
443 }
444 }
445
446 stop_cmd(dd);
447
448 /*
449 * wait for write complete by waiting for a successful
450 * read (the chip replies with a zero after the write
451 * cmd completes, and before it writes to the eeprom.
452 * The startcmd for the read will fail the ack until
453 * the writes have completed. We do this inline to avoid
454 * the debug prints that are in the real read routine
455 * if the startcmd fails.
456 */
457 max_wait_time = 100;
458 while (i2c_startcmd(dd, READ_CMD)) {
459 stop_cmd(dd);
460 if (!--max_wait_time) {
461 ipath_dbg("Did not get successful read to "
462 "complete write\n");
463 goto failed_write;
464 }
465 }
466 /* now read the zero byte */
467 for (i = single_byte = 0; i < 8; i++) {
468 u8 bit;
469 scl_out(dd, i2c_line_high);
470 bit = sda_in(dd, 0);
471 scl_out(dd, i2c_line_low);
472 single_byte <<= 1;
473 single_byte |= bit;
474 }
475 stop_cmd(dd);
476 }
477
478 ret = 0;
479 goto bail;
480
481failed_write:
482 stop_cmd(dd);
483 ret = 1;
484
485bail:
486 return ret;
487}
488
489static u8 flash_csum(struct ipath_flash *ifp, int adjust)
490{
491 u8 *ip = (u8 *) ifp;
492 u8 csum = 0, len;
493
494 for (len = 0; len < ifp->if_length; len++)
495 csum += *ip++;
496 csum -= ifp->if_csum;
497 csum = ~csum;
498 if (adjust)
499 ifp->if_csum = csum;
500
501 return csum;
502}
503
504/**
505 * ipath_get_guid - get the GUID from the i2c device
506 * @dd: the infinipath device
507 *
508 * When we add the multi-chip support, we will probably have to add
509 * the ability to use the number of guids field, and get the guid from
510 * the first chip's flash, to use for all of them.
511 */
512void ipath_get_guid(struct ipath_devdata *dd)
513{
514 void *buf;
515 struct ipath_flash *ifp;
516 __be64 guid;
517 int len;
518 u8 csum, *bguid;
519 int t = dd->ipath_unit;
520 struct ipath_devdata *dd0 = ipath_lookup(0);
521
522 if (t && dd0->ipath_nguid > 1 && t <= dd0->ipath_nguid) {
523 u8 *bguid, oguid;
524 dd->ipath_guid = dd0->ipath_guid;
525 bguid = (u8 *) & dd->ipath_guid;
526
527 oguid = bguid[7];
528 bguid[7] += t;
529 if (oguid > bguid[7]) {
530 if (bguid[6] == 0xff) {
531 if (bguid[5] == 0xff) {
532 ipath_dev_err(
533 dd,
534 "Can't set %s GUID from "
535 "base, wraps to OUI!\n",
536 ipath_get_unit_name(t));
537 dd->ipath_guid = 0;
538 goto bail;
539 }
540 bguid[5]++;
541 }
542 bguid[6]++;
543 }
544 dd->ipath_nguid = 1;
545
546 ipath_dbg("nguid %u, so adding %u to device 0 guid, "
547 "for %llx\n",
548 dd0->ipath_nguid, t,
549 (unsigned long long) be64_to_cpu(dd->ipath_guid));
550 goto bail;
551 }
552
553 len = offsetof(struct ipath_flash, if_future);
554 buf = vmalloc(len);
555 if (!buf) {
556 ipath_dev_err(dd, "Couldn't allocate memory to read %u "
557 "bytes from eeprom for GUID\n", len);
558 goto bail;
559 }
560
561 if (ipath_eeprom_read(dd, 0, buf, len)) {
562 ipath_dev_err(dd, "Failed reading GUID from eeprom\n");
563 goto done;
564 }
565 ifp = (struct ipath_flash *)buf;
566
567 csum = flash_csum(ifp, 0);
568 if (csum != ifp->if_csum) {
569 dev_info(&dd->pcidev->dev, "Bad I2C flash checksum: "
570 "0x%x, not 0x%x\n", csum, ifp->if_csum);
571 goto done;
572 }
573 if (*(__be64 *) ifp->if_guid == 0ULL ||
574 *(__be64 *) ifp->if_guid == __constant_cpu_to_be64(-1LL)) {
575 ipath_dev_err(dd, "Invalid GUID %llx from flash; "
576 "ignoring\n",
577 *(unsigned long long *) ifp->if_guid);
578 /* don't allow GUID if all 0 or all 1's */
579 goto done;
580 }
581
582 /* complain, but allow it */
583 if (*(u64 *) ifp->if_guid == 0x100007511000000ULL)
584 dev_info(&dd->pcidev->dev, "Warning, GUID %llx is "
585 "default, probably not correct!\n",
586 *(unsigned long long *) ifp->if_guid);
587
588 bguid = ifp->if_guid;
589 if (!bguid[0] && !bguid[1] && !bguid[2]) {
590 /* original incorrect GUID format in flash; fix in
591 * core copy, by shifting up 2 octets; don't need to
592 * change top octet, since both it and shifted are
593 * 0.. */
594 bguid[1] = bguid[3];
595 bguid[2] = bguid[4];
596 bguid[3] = bguid[4] = 0;
597 guid = *(__be64 *) ifp->if_guid;
598 ipath_cdbg(VERBOSE, "Old GUID format in flash, top 3 zero, "
599 "shifting 2 octets\n");
600 } else
601 guid = *(__be64 *) ifp->if_guid;
602 dd->ipath_guid = guid;
603 dd->ipath_nguid = ifp->if_numguid;
604 memcpy(dd->ipath_serial, ifp->if_serial,
605 sizeof(ifp->if_serial));
606 ipath_cdbg(VERBOSE, "Initted GUID to %llx from eeprom\n",
607 (unsigned long long) be64_to_cpu(dd->ipath_guid));
608
609done:
610 vfree(buf);
611
612bail:;
613}
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
new file mode 100644
index 000000000000..c347191f02bf
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -0,0 +1,1910 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/pci.h>
34#include <linux/poll.h>
35#include <linux/cdev.h>
36#include <linux/swap.h>
37#include <linux/vmalloc.h>
38#include <asm/pgtable.h>
39
40#include "ipath_kernel.h"
41#include "ips_common.h"
42#include "ipath_layer.h"
43
44static int ipath_open(struct inode *, struct file *);
45static int ipath_close(struct inode *, struct file *);
46static ssize_t ipath_write(struct file *, const char __user *, size_t,
47 loff_t *);
48static unsigned int ipath_poll(struct file *, struct poll_table_struct *);
49static int ipath_mmap(struct file *, struct vm_area_struct *);
50
51static struct file_operations ipath_file_ops = {
52 .owner = THIS_MODULE,
53 .write = ipath_write,
54 .open = ipath_open,
55 .release = ipath_close,
56 .poll = ipath_poll,
57 .mmap = ipath_mmap
58};
59
60static int ipath_get_base_info(struct ipath_portdata *pd,
61 void __user *ubase, size_t ubase_size)
62{
63 int ret = 0;
64 struct ipath_base_info *kinfo = NULL;
65 struct ipath_devdata *dd = pd->port_dd;
66
67 if (ubase_size < sizeof(*kinfo)) {
68 ipath_cdbg(PROC,
69 "Base size %lu, need %lu (version mismatch?)\n",
70 (unsigned long) ubase_size,
71 (unsigned long) sizeof(*kinfo));
72 ret = -EINVAL;
73 goto bail;
74 }
75
76 kinfo = kzalloc(sizeof(*kinfo), GFP_KERNEL);
77 if (kinfo == NULL) {
78 ret = -ENOMEM;
79 goto bail;
80 }
81
82 ret = dd->ipath_f_get_base_info(pd, kinfo);
83 if (ret < 0)
84 goto bail;
85
86 kinfo->spi_rcvhdr_cnt = dd->ipath_rcvhdrcnt;
87 kinfo->spi_rcvhdrent_size = dd->ipath_rcvhdrentsize;
88 kinfo->spi_tidegrcnt = dd->ipath_rcvegrcnt;
89 kinfo->spi_rcv_egrbufsize = dd->ipath_rcvegrbufsize;
90 /*
91 * have to mmap whole thing
92 */
93 kinfo->spi_rcv_egrbuftotlen =
94 pd->port_rcvegrbuf_chunks * pd->port_rcvegrbuf_size;
95 kinfo->spi_rcv_egrperchunk = pd->port_rcvegrbufs_perchunk;
96 kinfo->spi_rcv_egrchunksize = kinfo->spi_rcv_egrbuftotlen /
97 pd->port_rcvegrbuf_chunks;
98 kinfo->spi_tidcnt = dd->ipath_rcvtidcnt;
99 /*
100 * for this use, may be ipath_cfgports summed over all chips that
101 * are are configured and present
102 */
103 kinfo->spi_nports = dd->ipath_cfgports;
104 /* unit (chip/board) our port is on */
105 kinfo->spi_unit = dd->ipath_unit;
106 /* for now, only a single page */
107 kinfo->spi_tid_maxsize = PAGE_SIZE;
108
109 /*
110 * Doing this per port, and based on the skip value, etc. This has
111 * to be the actual buffer size, since the protocol code treats it
112 * as an array.
113 *
114 * These have to be set to user addresses in the user code via mmap.
115 * These values are used on return to user code for the mmap target
116 * addresses only. For 32 bit, same 44 bit address problem, so use
117 * the physical address, not virtual. Before 2.6.11, using the
118 * page_address() macro worked, but in 2.6.11, even that returns the
119 * full 64 bit address (upper bits all 1's). So far, using the
120 * physical addresses (or chip offsets, for chip mapping) works, but
121 * no doubt some future kernel release will chang that, and we'll be
122 * on to yet another method of dealing with this
123 */
124 kinfo->spi_rcvhdr_base = (u64) pd->port_rcvhdrq_phys;
125 kinfo->spi_rcv_egrbufs = (u64) pd->port_rcvegr_phys;
126 kinfo->spi_pioavailaddr = (u64) dd->ipath_pioavailregs_phys;
127 kinfo->spi_status = (u64) kinfo->spi_pioavailaddr +
128 (void *) dd->ipath_statusp -
129 (void *) dd->ipath_pioavailregs_dma;
130 kinfo->spi_piobufbase = (u64) pd->port_piobufs;
131 kinfo->__spi_uregbase =
132 dd->ipath_uregbase + dd->ipath_palign * pd->port_port;
133
134 kinfo->spi_pioindex = dd->ipath_pbufsport * (pd->port_port - 1);
135 kinfo->spi_piocnt = dd->ipath_pbufsport;
136 kinfo->spi_pioalign = dd->ipath_palign;
137
138 kinfo->spi_qpair = IPATH_KD_QP;
139 kinfo->spi_piosize = dd->ipath_ibmaxlen;
140 kinfo->spi_mtu = dd->ipath_ibmaxlen; /* maxlen, not ibmtu */
141 kinfo->spi_port = pd->port_port;
142 kinfo->spi_sw_version = IPATH_USER_SWVERSION;
143 kinfo->spi_hw_version = dd->ipath_revision;
144
145 if (copy_to_user(ubase, kinfo, sizeof(*kinfo)))
146 ret = -EFAULT;
147
148bail:
149 kfree(kinfo);
150 return ret;
151}
152
153/**
154 * ipath_tid_update - update a port TID
155 * @pd: the port
156 * @ti: the TID information
157 *
158 * The new implementation as of Oct 2004 is that the driver assigns
159 * the tid and returns it to the caller. To make it easier to
160 * catch bugs, and to reduce search time, we keep a cursor for
161 * each port, walking the shadow tid array to find one that's not
162 * in use.
163 *
164 * For now, if we can't allocate the full list, we fail, although
165 * in the long run, we'll allocate as many as we can, and the
166 * caller will deal with that by trying the remaining pages later.
167 * That means that when we fail, we have to mark the tids as not in
168 * use again, in our shadow copy.
169 *
170 * It's up to the caller to free the tids when they are done.
171 * We'll unlock the pages as they free them.
172 *
173 * Also, right now we are locking one page at a time, but since
174 * the intended use of this routine is for a single group of
175 * virtually contiguous pages, that should change to improve
176 * performance.
177 */
178static int ipath_tid_update(struct ipath_portdata *pd,
179 const struct ipath_tid_info *ti)
180{
181 int ret = 0, ntids;
182 u32 tid, porttid, cnt, i, tidcnt;
183 u16 *tidlist;
184 struct ipath_devdata *dd = pd->port_dd;
185 u64 physaddr;
186 unsigned long vaddr;
187 u64 __iomem *tidbase;
188 unsigned long tidmap[8];
189 struct page **pagep = NULL;
190
191 if (!dd->ipath_pageshadow) {
192 ret = -ENOMEM;
193 goto done;
194 }
195
196 cnt = ti->tidcnt;
197 if (!cnt) {
198 ipath_dbg("After copyin, tidcnt 0, tidlist %llx\n",
199 (unsigned long long) ti->tidlist);
200 /*
201 * Should we treat as success? likely a bug
202 */
203 ret = -EFAULT;
204 goto done;
205 }
206 tidcnt = dd->ipath_rcvtidcnt;
207 if (cnt >= tidcnt) {
208 /* make sure it all fits in port_tid_pg_list */
209 dev_info(&dd->pcidev->dev, "Process tried to allocate %u "
210 "TIDs, only trying max (%u)\n", cnt, tidcnt);
211 cnt = tidcnt;
212 }
213 pagep = (struct page **)pd->port_tid_pg_list;
214 tidlist = (u16 *) (&pagep[cnt]);
215
216 memset(tidmap, 0, sizeof(tidmap));
217 tid = pd->port_tidcursor;
218 /* before decrement; chip actual # */
219 porttid = pd->port_port * tidcnt;
220 ntids = tidcnt;
221 tidbase = (u64 __iomem *) (((char __iomem *) dd->ipath_kregbase) +
222 dd->ipath_rcvtidbase +
223 porttid * sizeof(*tidbase));
224
225 ipath_cdbg(VERBOSE, "Port%u %u tids, cursor %u, tidbase %p\n",
226 pd->port_port, cnt, tid, tidbase);
227
228 /* virtual address of first page in transfer */
229 vaddr = ti->tidvaddr;
230 if (!access_ok(VERIFY_WRITE, (void __user *) vaddr,
231 cnt * PAGE_SIZE)) {
232 ipath_dbg("Fail vaddr %p, %u pages, !access_ok\n",
233 (void *)vaddr, cnt);
234 ret = -EFAULT;
235 goto done;
236 }
237 ret = ipath_get_user_pages(vaddr, cnt, pagep);
238 if (ret) {
239 if (ret == -EBUSY) {
240 ipath_dbg("Failed to lock addr %p, %u pages "
241 "(already locked)\n",
242 (void *) vaddr, cnt);
243 /*
244 * for now, continue, and see what happens but with
245 * the new implementation, this should never happen,
246 * unless perhaps the user has mpin'ed the pages
247 * themselves (something we need to test)
248 */
249 ret = 0;
250 } else {
251 dev_info(&dd->pcidev->dev,
252 "Failed to lock addr %p, %u pages: "
253 "errno %d\n", (void *) vaddr, cnt, -ret);
254 goto done;
255 }
256 }
257 for (i = 0; i < cnt; i++, vaddr += PAGE_SIZE) {
258 for (; ntids--; tid++) {
259 if (tid == tidcnt)
260 tid = 0;
261 if (!dd->ipath_pageshadow[porttid + tid])
262 break;
263 }
264 if (ntids < 0) {
265 /*
266 * oops, wrapped all the way through their TIDs,
267 * and didn't have enough free; see comments at
268 * start of routine
269 */
270 ipath_dbg("Not enough free TIDs for %u pages "
271 "(index %d), failing\n", cnt, i);
272 i--; /* last tidlist[i] not filled in */
273 ret = -ENOMEM;
274 break;
275 }
276 tidlist[i] = tid;
277 ipath_cdbg(VERBOSE, "Updating idx %u to TID %u, "
278 "vaddr %lx\n", i, tid, vaddr);
279 /* we "know" system pages and TID pages are same size */
280 dd->ipath_pageshadow[porttid + tid] = pagep[i];
281 /*
282 * don't need atomic or it's overhead
283 */
284 __set_bit(tid, tidmap);
285 physaddr = page_to_phys(pagep[i]);
286 ipath_stats.sps_pagelocks++;
287 ipath_cdbg(VERBOSE,
288 "TID %u, vaddr %lx, physaddr %llx pgp %p\n",
289 tid, vaddr, (unsigned long long) physaddr,
290 pagep[i]);
291 dd->ipath_f_put_tid(dd, &tidbase[tid], 1, physaddr);
292 /*
293 * don't check this tid in ipath_portshadow, since we
294 * just filled it in; start with the next one.
295 */
296 tid++;
297 }
298
299 if (ret) {
300 u32 limit;
301 cleanup:
302 /* jump here if copy out of updated info failed... */
303 ipath_dbg("After failure (ret=%d), undo %d of %d entries\n",
304 -ret, i, cnt);
305 /* same code that's in ipath_free_tid() */
306 limit = sizeof(tidmap) * BITS_PER_BYTE;
307 if (limit > tidcnt)
308 /* just in case size changes in future */
309 limit = tidcnt;
310 tid = find_first_bit((const unsigned long *)tidmap, limit);
311 for (; tid < limit; tid++) {
312 if (!test_bit(tid, tidmap))
313 continue;
314 if (dd->ipath_pageshadow[porttid + tid]) {
315 ipath_cdbg(VERBOSE, "Freeing TID %u\n",
316 tid);
317 dd->ipath_f_put_tid(dd, &tidbase[tid], 1,
318 dd->ipath_tidinvalid);
319 dd->ipath_pageshadow[porttid + tid] = NULL;
320 ipath_stats.sps_pageunlocks++;
321 }
322 }
323 ipath_release_user_pages(pagep, cnt);
324 } else {
325 /*
326 * Copy the updated array, with ipath_tid's filled in, back
327 * to user. Since we did the copy in already, this "should
328 * never fail" If it does, we have to clean up...
329 */
330 if (copy_to_user((void __user *)
331 (unsigned long) ti->tidlist,
332 tidlist, cnt * sizeof(*tidlist))) {
333 ret = -EFAULT;
334 goto cleanup;
335 }
336 if (copy_to_user((void __user *) (unsigned long) ti->tidmap,
337 tidmap, sizeof tidmap)) {
338 ret = -EFAULT;
339 goto cleanup;
340 }
341 if (tid == tidcnt)
342 tid = 0;
343 pd->port_tidcursor = tid;
344 }
345
346done:
347 if (ret)
348 ipath_dbg("Failed to map %u TID pages, failing with %d\n",
349 ti->tidcnt, -ret);
350 return ret;
351}
352
353/**
354 * ipath_tid_free - free a port TID
355 * @pd: the port
356 * @ti: the TID info
357 *
358 * right now we are unlocking one page at a time, but since
359 * the intended use of this routine is for a single group of
360 * virtually contiguous pages, that should change to improve
361 * performance. We check that the TID is in range for this port
362 * but otherwise don't check validity; if user has an error and
363 * frees the wrong tid, it's only their own data that can thereby
364 * be corrupted. We do check that the TID was in use, for sanity
365 * We always use our idea of the saved address, not the address that
366 * they pass in to us.
367 */
368
369static int ipath_tid_free(struct ipath_portdata *pd,
370 const struct ipath_tid_info *ti)
371{
372 int ret = 0;
373 u32 tid, porttid, cnt, limit, tidcnt;
374 struct ipath_devdata *dd = pd->port_dd;
375 u64 __iomem *tidbase;
376 unsigned long tidmap[8];
377
378 if (!dd->ipath_pageshadow) {
379 ret = -ENOMEM;
380 goto done;
381 }
382
383 if (copy_from_user(tidmap, (void __user *)(unsigned long)ti->tidmap,
384 sizeof tidmap)) {
385 ret = -EFAULT;
386 goto done;
387 }
388
389 porttid = pd->port_port * dd->ipath_rcvtidcnt;
390 tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
391 dd->ipath_rcvtidbase +
392 porttid * sizeof(*tidbase));
393
394 tidcnt = dd->ipath_rcvtidcnt;
395 limit = sizeof(tidmap) * BITS_PER_BYTE;
396 if (limit > tidcnt)
397 /* just in case size changes in future */
398 limit = tidcnt;
399 tid = find_first_bit(tidmap, limit);
400 ipath_cdbg(VERBOSE, "Port%u free %u tids; first bit (max=%d) "
401 "set is %d, porttid %u\n", pd->port_port, ti->tidcnt,
402 limit, tid, porttid);
403 for (cnt = 0; tid < limit; tid++) {
404 /*
405 * small optimization; if we detect a run of 3 or so without
406 * any set, use find_first_bit again. That's mainly to
407 * accelerate the case where we wrapped, so we have some at
408 * the beginning, and some at the end, and a big gap
409 * in the middle.
410 */
411 if (!test_bit(tid, tidmap))
412 continue;
413 cnt++;
414 if (dd->ipath_pageshadow[porttid + tid]) {
415 ipath_cdbg(VERBOSE, "PID %u freeing TID %u\n",
416 pd->port_pid, tid);
417 dd->ipath_f_put_tid(dd, &tidbase[tid], 1,
418 dd->ipath_tidinvalid);
419 ipath_release_user_pages(
420 &dd->ipath_pageshadow[porttid + tid], 1);
421 dd->ipath_pageshadow[porttid + tid] = NULL;
422 ipath_stats.sps_pageunlocks++;
423 } else
424 ipath_dbg("Unused tid %u, ignoring\n", tid);
425 }
426 if (cnt != ti->tidcnt)
427 ipath_dbg("passed in tidcnt %d, only %d bits set in map\n",
428 ti->tidcnt, cnt);
429done:
430 if (ret)
431 ipath_dbg("Failed to unmap %u TID pages, failing with %d\n",
432 ti->tidcnt, -ret);
433 return ret;
434}
435
436/**
437 * ipath_set_part_key - set a partition key
438 * @pd: the port
439 * @key: the key
440 *
441 * We can have up to 4 active at a time (other than the default, which is
442 * always allowed). This is somewhat tricky, since multiple ports may set
443 * the same key, so we reference count them, and clean up at exit. All 4
444 * partition keys are packed into a single infinipath register. It's an
445 * error for a process to set the same pkey multiple times. We provide no
446 * mechanism to de-allocate a pkey at this time, we may eventually need to
447 * do that. I've used the atomic operations, and no locking, and only make
448 * a single pass through what's available. This should be more than
449 * adequate for some time. I'll think about spinlocks or the like if and as
450 * it's necessary.
451 */
452static int ipath_set_part_key(struct ipath_portdata *pd, u16 key)
453{
454 struct ipath_devdata *dd = pd->port_dd;
455 int i, any = 0, pidx = -1;
456 u16 lkey = key & 0x7FFF;
457 int ret;
458
459 if (lkey == (IPS_DEFAULT_P_KEY & 0x7FFF)) {
460 /* nothing to do; this key always valid */
461 ret = 0;
462 goto bail;
463 }
464
465 ipath_cdbg(VERBOSE, "p%u try to set pkey %hx, current keys "
466 "%hx:%x %hx:%x %hx:%x %hx:%x\n",
467 pd->port_port, key, dd->ipath_pkeys[0],
468 atomic_read(&dd->ipath_pkeyrefs[0]), dd->ipath_pkeys[1],
469 atomic_read(&dd->ipath_pkeyrefs[1]), dd->ipath_pkeys[2],
470 atomic_read(&dd->ipath_pkeyrefs[2]), dd->ipath_pkeys[3],
471 atomic_read(&dd->ipath_pkeyrefs[3]));
472
473 if (!lkey) {
474 ipath_cdbg(PROC, "p%u tries to set key 0, not allowed\n",
475 pd->port_port);
476 ret = -EINVAL;
477 goto bail;
478 }
479
480 /*
481 * Set the full membership bit, because it has to be
482 * set in the register or the packet, and it seems
483 * cleaner to set in the register than to force all
484 * callers to set it. (see bug 4331)
485 */
486 key |= 0x8000;
487
488 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
489 if (!pd->port_pkeys[i] && pidx == -1)
490 pidx = i;
491 if (pd->port_pkeys[i] == key) {
492 ipath_cdbg(VERBOSE, "p%u tries to set same pkey "
493 "(%x) more than once\n",
494 pd->port_port, key);
495 ret = -EEXIST;
496 goto bail;
497 }
498 }
499 if (pidx == -1) {
500 ipath_dbg("All pkeys for port %u already in use, "
501 "can't set %x\n", pd->port_port, key);
502 ret = -EBUSY;
503 goto bail;
504 }
505 for (any = i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
506 if (!dd->ipath_pkeys[i]) {
507 any++;
508 continue;
509 }
510 if (dd->ipath_pkeys[i] == key) {
511 atomic_t *pkrefs = &dd->ipath_pkeyrefs[i];
512
513 if (atomic_inc_return(pkrefs) > 1) {
514 pd->port_pkeys[pidx] = key;
515 ipath_cdbg(VERBOSE, "p%u set key %x "
516 "matches #%d, count now %d\n",
517 pd->port_port, key, i,
518 atomic_read(pkrefs));
519 ret = 0;
520 goto bail;
521 } else {
522 /*
523 * lost race, decrement count, catch below
524 */
525 atomic_dec(pkrefs);
526 ipath_cdbg(VERBOSE, "Lost race, count was "
527 "0, after dec, it's %d\n",
528 atomic_read(pkrefs));
529 any++;
530 }
531 }
532 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
533 /*
534 * It makes no sense to have both the limited and
535 * full membership PKEY set at the same time since
536 * the unlimited one will disable the limited one.
537 */
538 ret = -EEXIST;
539 goto bail;
540 }
541 }
542 if (!any) {
543 ipath_dbg("port %u, all pkeys already in use, "
544 "can't set %x\n", pd->port_port, key);
545 ret = -EBUSY;
546 goto bail;
547 }
548 for (any = i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
549 if (!dd->ipath_pkeys[i] &&
550 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
551 u64 pkey;
552
553 /* for ipathstats, etc. */
554 ipath_stats.sps_pkeys[i] = lkey;
555 pd->port_pkeys[pidx] = dd->ipath_pkeys[i] = key;
556 pkey =
557 (u64) dd->ipath_pkeys[0] |
558 ((u64) dd->ipath_pkeys[1] << 16) |
559 ((u64) dd->ipath_pkeys[2] << 32) |
560 ((u64) dd->ipath_pkeys[3] << 48);
561 ipath_cdbg(PROC, "p%u set key %x in #%d, "
562 "portidx %d, new pkey reg %llx\n",
563 pd->port_port, key, i, pidx,
564 (unsigned long long) pkey);
565 ipath_write_kreg(
566 dd, dd->ipath_kregs->kr_partitionkey, pkey);
567
568 ret = 0;
569 goto bail;
570 }
571 }
572 ipath_dbg("port %u, all pkeys already in use 2nd pass, "
573 "can't set %x\n", pd->port_port, key);
574 ret = -EBUSY;
575
576bail:
577 return ret;
578}
579
580/**
581 * ipath_manage_rcvq - manage a port's receive queue
582 * @pd: the port
583 * @start_stop: action to carry out
584 *
585 * start_stop == 0 disables receive on the port, for use in queue
586 * overflow conditions. start_stop==1 re-enables, to be used to
587 * re-init the software copy of the head register
588 */
589static int ipath_manage_rcvq(struct ipath_portdata *pd, int start_stop)
590{
591 struct ipath_devdata *dd = pd->port_dd;
592 u64 tval;
593
594 ipath_cdbg(PROC, "%sabling rcv for unit %u port %u\n",
595 start_stop ? "en" : "dis", dd->ipath_unit,
596 pd->port_port);
597 /* atomically clear receive enable port. */
598 if (start_stop) {
599 /*
600 * On enable, force in-memory copy of the tail register to
601 * 0, so that protocol code doesn't have to worry about
602 * whether or not the chip has yet updated the in-memory
603 * copy or not on return from the system call. The chip
604 * always resets it's tail register back to 0 on a
605 * transition from disabled to enabled. This could cause a
606 * problem if software was broken, and did the enable w/o
607 * the disable, but eventually the in-memory copy will be
608 * updated and correct itself, even in the face of software
609 * bugs.
610 */
611 *pd->port_rcvhdrtail_kvaddr = 0;
612 set_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port,
613 &dd->ipath_rcvctrl);
614 } else
615 clear_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port,
616 &dd->ipath_rcvctrl);
617 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
618 dd->ipath_rcvctrl);
619 /* now be sure chip saw it before we return */
620 tval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
621 if (start_stop) {
622 /*
623 * And try to be sure that tail reg update has happened too.
624 * This should in theory interlock with the RXE changes to
625 * the tail register. Don't assign it to the tail register
626 * in memory copy, since we could overwrite an update by the
627 * chip if we did.
628 */
629 tval = ipath_read_ureg32(dd, ur_rcvhdrtail, pd->port_port);
630 }
631 /* always; new head should be equal to new tail; see above */
632 return 0;
633}
634
635static void ipath_clean_part_key(struct ipath_portdata *pd,
636 struct ipath_devdata *dd)
637{
638 int i, j, pchanged = 0;
639 u64 oldpkey;
640
641 /* for debugging only */
642 oldpkey = (u64) dd->ipath_pkeys[0] |
643 ((u64) dd->ipath_pkeys[1] << 16) |
644 ((u64) dd->ipath_pkeys[2] << 32) |
645 ((u64) dd->ipath_pkeys[3] << 48);
646
647 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
648 if (!pd->port_pkeys[i])
649 continue;
650 ipath_cdbg(VERBOSE, "look for key[%d] %hx in pkeys\n", i,
651 pd->port_pkeys[i]);
652 for (j = 0; j < ARRAY_SIZE(dd->ipath_pkeys); j++) {
653 /* check for match independent of the global bit */
654 if ((dd->ipath_pkeys[j] & 0x7fff) !=
655 (pd->port_pkeys[i] & 0x7fff))
656 continue;
657 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[j])) {
658 ipath_cdbg(VERBOSE, "p%u clear key "
659 "%x matches #%d\n",
660 pd->port_port,
661 pd->port_pkeys[i], j);
662 ipath_stats.sps_pkeys[j] =
663 dd->ipath_pkeys[j] = 0;
664 pchanged++;
665 }
666 else ipath_cdbg(
667 VERBOSE, "p%u key %x matches #%d, "
668 "but ref still %d\n", pd->port_port,
669 pd->port_pkeys[i], j,
670 atomic_read(&dd->ipath_pkeyrefs[j]));
671 break;
672 }
673 pd->port_pkeys[i] = 0;
674 }
675 if (pchanged) {
676 u64 pkey = (u64) dd->ipath_pkeys[0] |
677 ((u64) dd->ipath_pkeys[1] << 16) |
678 ((u64) dd->ipath_pkeys[2] << 32) |
679 ((u64) dd->ipath_pkeys[3] << 48);
680 ipath_cdbg(VERBOSE, "p%u old pkey reg %llx, "
681 "new pkey reg %llx\n", pd->port_port,
682 (unsigned long long) oldpkey,
683 (unsigned long long) pkey);
684 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
685 pkey);
686 }
687}
688
689/**
690 * ipath_create_user_egr - allocate eager TID buffers
691 * @pd: the port to allocate TID buffers for
692 *
693 * This routine is now quite different for user and kernel, because
694 * the kernel uses skb's, for the accelerated network performance
695 * This is the user port version
696 *
697 * Allocate the eager TID buffers and program them into infinipath
698 * They are no longer completely contiguous, we do multiple allocation
699 * calls.
700 */
701static int ipath_create_user_egr(struct ipath_portdata *pd)
702{
703 struct ipath_devdata *dd = pd->port_dd;
704 unsigned e, egrcnt, alloced, egrperchunk, chunk, egrsize, egroff;
705 size_t size;
706 int ret;
707
708 egrcnt = dd->ipath_rcvegrcnt;
709 /* TID number offset for this port */
710 egroff = pd->port_port * egrcnt;
711 egrsize = dd->ipath_rcvegrbufsize;
712 ipath_cdbg(VERBOSE, "Allocating %d egr buffers, at egrtid "
713 "offset %x, egrsize %u\n", egrcnt, egroff, egrsize);
714
715 /*
716 * to avoid wasting a lot of memory, we allocate 32KB chunks of
717 * physically contiguous memory, advance through it until used up
718 * and then allocate more. Of course, we need memory to store those
719 * extra pointers, now. Started out with 256KB, but under heavy
720 * memory pressure (creating large files and then copying them over
721 * NFS while doing lots of MPI jobs), we hit some allocation
722 * failures, even though we can sleep... (2.6.10) Still get
723 * failures at 64K. 32K is the lowest we can go without waiting
724 * more memory again. It seems likely that the coalescing in
725 * free_pages, etc. still has issues (as it has had previously
726 * during 2.6.x development).
727 */
728 size = 0x8000;
729 alloced = ALIGN(egrsize * egrcnt, size);
730 egrperchunk = size / egrsize;
731 chunk = (egrcnt + egrperchunk - 1) / egrperchunk;
732 pd->port_rcvegrbuf_chunks = chunk;
733 pd->port_rcvegrbufs_perchunk = egrperchunk;
734 pd->port_rcvegrbuf_size = size;
735 pd->port_rcvegrbuf = vmalloc(chunk * sizeof(pd->port_rcvegrbuf[0]));
736 if (!pd->port_rcvegrbuf) {
737 ret = -ENOMEM;
738 goto bail;
739 }
740 pd->port_rcvegrbuf_phys =
741 vmalloc(chunk * sizeof(pd->port_rcvegrbuf_phys[0]));
742 if (!pd->port_rcvegrbuf_phys) {
743 ret = -ENOMEM;
744 goto bail_rcvegrbuf;
745 }
746 for (e = 0; e < pd->port_rcvegrbuf_chunks; e++) {
747 /*
748 * GFP_USER, but without GFP_FS, so buffer cache can be
749 * coalesced (we hope); otherwise, even at order 4,
750 * heavy filesystem activity makes these fail
751 */
752 gfp_t gfp_flags = __GFP_WAIT | __GFP_IO | __GFP_COMP;
753
754 pd->port_rcvegrbuf[e] = dma_alloc_coherent(
755 &dd->pcidev->dev, size, &pd->port_rcvegrbuf_phys[e],
756 gfp_flags);
757
758 if (!pd->port_rcvegrbuf[e]) {
759 ret = -ENOMEM;
760 goto bail_rcvegrbuf_phys;
761 }
762 }
763
764 pd->port_rcvegr_phys = pd->port_rcvegrbuf_phys[0];
765
766 for (e = chunk = 0; chunk < pd->port_rcvegrbuf_chunks; chunk++) {
767 dma_addr_t pa = pd->port_rcvegrbuf_phys[chunk];
768 unsigned i;
769
770 for (i = 0; e < egrcnt && i < egrperchunk; e++, i++) {
771 dd->ipath_f_put_tid(dd, e + egroff +
772 (u64 __iomem *)
773 ((char __iomem *)
774 dd->ipath_kregbase +
775 dd->ipath_rcvegrbase), 0, pa);
776 pa += egrsize;
777 }
778 cond_resched(); /* don't hog the cpu */
779 }
780
781 ret = 0;
782 goto bail;
783
784bail_rcvegrbuf_phys:
785 for (e = 0; e < pd->port_rcvegrbuf_chunks &&
786 pd->port_rcvegrbuf[e]; e++)
787 dma_free_coherent(&dd->pcidev->dev, size,
788 pd->port_rcvegrbuf[e],
789 pd->port_rcvegrbuf_phys[e]);
790
791 vfree(pd->port_rcvegrbuf_phys);
792 pd->port_rcvegrbuf_phys = NULL;
793bail_rcvegrbuf:
794 vfree(pd->port_rcvegrbuf);
795 pd->port_rcvegrbuf = NULL;
796bail:
797 return ret;
798}
799
800static int ipath_do_user_init(struct ipath_portdata *pd,
801 const struct ipath_user_info *uinfo)
802{
803 int ret = 0;
804 struct ipath_devdata *dd = pd->port_dd;
805 u64 physaddr, uaddr, off, atmp;
806 struct page *pagep;
807 u32 head32;
808 u64 head;
809
810 /* for now, if major version is different, bail */
811 if ((uinfo->spu_userversion >> 16) != IPATH_USER_SWMAJOR) {
812 dev_info(&dd->pcidev->dev,
813 "User major version %d not same as driver "
814 "major %d\n", uinfo->spu_userversion >> 16,
815 IPATH_USER_SWMAJOR);
816 ret = -ENODEV;
817 goto done;
818 }
819
820 if ((uinfo->spu_userversion & 0xffff) != IPATH_USER_SWMINOR)
821 ipath_dbg("User minor version %d not same as driver "
822 "minor %d\n", uinfo->spu_userversion & 0xffff,
823 IPATH_USER_SWMINOR);
824
825 if (uinfo->spu_rcvhdrsize) {
826 ret = ipath_setrcvhdrsize(dd, uinfo->spu_rcvhdrsize);
827 if (ret)
828 goto done;
829 }
830
831 /* for now we do nothing with rcvhdrcnt: uinfo->spu_rcvhdrcnt */
832
833 /* set up for the rcvhdr Q tail register writeback to user memory */
834 if (!uinfo->spu_rcvhdraddr ||
835 !access_ok(VERIFY_WRITE, (u64 __user *) (unsigned long)
836 uinfo->spu_rcvhdraddr, sizeof(u64))) {
837 ipath_dbg("Port %d rcvhdrtail addr %llx not valid\n",
838 pd->port_port,
839 (unsigned long long) uinfo->spu_rcvhdraddr);
840 ret = -EINVAL;
841 goto done;
842 }
843
844 off = offset_in_page(uinfo->spu_rcvhdraddr);
845 uaddr = PAGE_MASK & (unsigned long) uinfo->spu_rcvhdraddr;
846 ret = ipath_get_user_pages_nocopy(uaddr, &pagep);
847 if (ret) {
848 dev_info(&dd->pcidev->dev, "Failed to lookup and lock "
849 "address %llx for rcvhdrtail: errno %d\n",
850 (unsigned long long) uinfo->spu_rcvhdraddr, -ret);
851 goto done;
852 }
853 ipath_stats.sps_pagelocks++;
854 pd->port_rcvhdrtail_uaddr = uaddr;
855 pd->port_rcvhdrtail_pagep = pagep;
856 pd->port_rcvhdrtail_kvaddr =
857 page_address(pagep);
858 pd->port_rcvhdrtail_kvaddr += off;
859 physaddr = page_to_phys(pagep) + off;
860 ipath_cdbg(VERBOSE, "port %d user addr %llx hdrtailaddr, %llx "
861 "physical (off=%llx)\n",
862 pd->port_port,
863 (unsigned long long) uinfo->spu_rcvhdraddr,
864 (unsigned long long) physaddr, (unsigned long long) off);
865 ipath_write_kreg_port(dd, dd->ipath_kregs->kr_rcvhdrtailaddr,
866 pd->port_port, physaddr);
867 atmp = ipath_read_kreg64_port(dd,
868 dd->ipath_kregs->kr_rcvhdrtailaddr,
869 pd->port_port);
870 if (physaddr != atmp) {
871 ipath_dev_err(dd,
872 "Catastrophic software error, "
873 "RcvHdrTailAddr%u written as %llx, "
874 "read back as %llx\n", pd->port_port,
875 (unsigned long long) physaddr,
876 (unsigned long long) atmp);
877 ret = -EINVAL;
878 goto done;
879 }
880
881 /* for right now, kernel piobufs are at end, so port 1 is at 0 */
882 pd->port_piobufs = dd->ipath_piobufbase +
883 dd->ipath_pbufsport * (pd->port_port -
884 1) * dd->ipath_palign;
885 ipath_cdbg(VERBOSE, "Set base of piobufs for port %u to 0x%x\n",
886 pd->port_port, pd->port_piobufs);
887
888 /*
889 * Now allocate the rcvhdr Q and eager TIDs; skip the TID
890 * array for time being. If pd->port_port > chip-supported,
891 * we need to do extra stuff here to handle by handling overflow
892 * through port 0, someday
893 */
894 ret = ipath_create_rcvhdrq(dd, pd);
895 if (!ret)
896 ret = ipath_create_user_egr(pd);
897 if (ret)
898 goto done;
899 /* enable receives now */
900 /* atomically set enable bit for this port */
901 set_bit(INFINIPATH_R_PORTENABLE_SHIFT + pd->port_port,
902 &dd->ipath_rcvctrl);
903
904 /*
905 * set the head registers for this port to the current values
906 * of the tail pointers, since we don't know if they were
907 * updated on last use of the port.
908 */
909 head32 = ipath_read_ureg32(dd, ur_rcvhdrtail, pd->port_port);
910 head = (u64) head32;
911 ipath_write_ureg(dd, ur_rcvhdrhead, head, pd->port_port);
912 head32 = ipath_read_ureg32(dd, ur_rcvegrindextail, pd->port_port);
913 ipath_write_ureg(dd, ur_rcvegrindexhead, head32, pd->port_port);
914 dd->ipath_lastegrheads[pd->port_port] = -1;
915 dd->ipath_lastrcvhdrqtails[pd->port_port] = -1;
916 ipath_cdbg(VERBOSE, "Wrote port%d head %llx, egrhead %x from "
917 "tail regs\n", pd->port_port,
918 (unsigned long long) head, head32);
919 pd->port_tidcursor = 0; /* start at beginning after open */
920 /*
921 * now enable the port; the tail registers will be written to memory
922 * by the chip as soon as it sees the write to
923 * dd->ipath_kregs->kr_rcvctrl. The update only happens on
924 * transition from 0 to 1, so clear it first, then set it as part of
925 * enabling the port. This will (very briefly) affect any other
926 * open ports, but it shouldn't be long enough to be an issue.
927 */
928 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
929 dd->ipath_rcvctrl & ~INFINIPATH_R_TAILUPD);
930 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
931 dd->ipath_rcvctrl);
932
933done:
934 return ret;
935}
936
937static int mmap_ureg(struct vm_area_struct *vma, struct ipath_devdata *dd,
938 u64 ureg)
939{
940 unsigned long phys;
941 int ret;
942
943 /* it's the real hardware, so io_remap works */
944
945 if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) {
946 dev_info(&dd->pcidev->dev, "FAIL mmap userreg: reqlen "
947 "%lx > PAGE\n", vma->vm_end - vma->vm_start);
948 ret = -EFAULT;
949 } else {
950 phys = dd->ipath_physaddr + ureg;
951 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
952
953 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
954 ret = io_remap_pfn_range(vma, vma->vm_start,
955 phys >> PAGE_SHIFT,
956 vma->vm_end - vma->vm_start,
957 vma->vm_page_prot);
958 }
959 return ret;
960}
961
962static int mmap_piobufs(struct vm_area_struct *vma,
963 struct ipath_devdata *dd,
964 struct ipath_portdata *pd)
965{
966 unsigned long phys;
967 int ret;
968
969 /*
970 * When we map the PIO buffers, we want to map them as writeonly, no
971 * read possible.
972 */
973
974 if ((vma->vm_end - vma->vm_start) >
975 (dd->ipath_pbufsport * dd->ipath_palign)) {
976 dev_info(&dd->pcidev->dev, "FAIL mmap piobufs: "
977 "reqlen %lx > PAGE\n",
978 vma->vm_end - vma->vm_start);
979 ret = -EFAULT;
980 goto bail;
981 }
982
983 phys = dd->ipath_physaddr + pd->port_piobufs;
984 /*
985 * Do *NOT* mark this as non-cached (PWT bit), or we don't get the
986 * write combining behavior we want on the PIO buffers!
987 * vma->vm_page_prot =
988 * pgprot_noncached(vma->vm_page_prot);
989 */
990
991 if (vma->vm_flags & VM_READ) {
992 dev_info(&dd->pcidev->dev,
993 "Can't map piobufs as readable (flags=%lx)\n",
994 vma->vm_flags);
995 ret = -EPERM;
996 goto bail;
997 }
998
999 /* don't allow them to later change to readable with mprotect */
1000
1001 vma->vm_flags &= ~VM_MAYWRITE;
1002 vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
1003
1004 ret = io_remap_pfn_range(vma, vma->vm_start, phys >> PAGE_SHIFT,
1005 vma->vm_end - vma->vm_start,
1006 vma->vm_page_prot);
1007bail:
1008 return ret;
1009}
1010
1011static int mmap_rcvegrbufs(struct vm_area_struct *vma,
1012 struct ipath_portdata *pd)
1013{
1014 struct ipath_devdata *dd = pd->port_dd;
1015 unsigned long start, size;
1016 size_t total_size, i;
1017 dma_addr_t *phys;
1018 int ret;
1019
1020 if (!pd->port_rcvegrbuf) {
1021 ret = -EFAULT;
1022 goto bail;
1023 }
1024
1025 size = pd->port_rcvegrbuf_size;
1026 total_size = pd->port_rcvegrbuf_chunks * size;
1027 if ((vma->vm_end - vma->vm_start) > total_size) {
1028 dev_info(&dd->pcidev->dev, "FAIL on egr bufs: "
1029 "reqlen %lx > actual %lx\n",
1030 vma->vm_end - vma->vm_start,
1031 (unsigned long) total_size);
1032 ret = -EFAULT;
1033 goto bail;
1034 }
1035
1036 if (vma->vm_flags & VM_WRITE) {
1037 dev_info(&dd->pcidev->dev, "Can't map eager buffers as "
1038 "writable (flags=%lx)\n", vma->vm_flags);
1039 ret = -EPERM;
1040 goto bail;
1041 }
1042
1043 start = vma->vm_start;
1044 phys = pd->port_rcvegrbuf_phys;
1045
1046 /* don't allow them to later change to writeable with mprotect */
1047 vma->vm_flags &= ~VM_MAYWRITE;
1048
1049 for (i = 0; i < pd->port_rcvegrbuf_chunks; i++, start += size) {
1050 ret = remap_pfn_range(vma, start, phys[i] >> PAGE_SHIFT,
1051 size, vma->vm_page_prot);
1052 if (ret < 0)
1053 goto bail;
1054 }
1055 ret = 0;
1056
1057bail:
1058 return ret;
1059}
1060
1061static int mmap_rcvhdrq(struct vm_area_struct *vma,
1062 struct ipath_portdata *pd)
1063{
1064 struct ipath_devdata *dd = pd->port_dd;
1065 size_t total_size;
1066 int ret;
1067
1068 /*
1069 * kmalloc'ed memory, physically contiguous; this is from
1070 * spi_rcvhdr_base; we allow user to map read-write so they can
1071 * write hdrq entries to allow protocol code to directly poll
1072 * whether a hdrq entry has been written.
1073 */
1074 total_size = ALIGN(dd->ipath_rcvhdrcnt * dd->ipath_rcvhdrentsize *
1075 sizeof(u32), PAGE_SIZE);
1076 if ((vma->vm_end - vma->vm_start) > total_size) {
1077 dev_info(&dd->pcidev->dev,
1078 "FAIL on rcvhdrq: reqlen %lx > actual %lx\n",
1079 vma->vm_end - vma->vm_start,
1080 (unsigned long) total_size);
1081 ret = -EFAULT;
1082 goto bail;
1083 }
1084
1085 ret = remap_pfn_range(vma, vma->vm_start,
1086 pd->port_rcvhdrq_phys >> PAGE_SHIFT,
1087 vma->vm_end - vma->vm_start,
1088 vma->vm_page_prot);
1089bail:
1090 return ret;
1091}
1092
1093static int mmap_pioavailregs(struct vm_area_struct *vma,
1094 struct ipath_portdata *pd)
1095{
1096 struct ipath_devdata *dd = pd->port_dd;
1097 int ret;
1098
1099 /*
1100 * when we map the PIO bufferavail registers, we want to map them as
1101 * readonly, no write possible.
1102 *
1103 * kmalloc'ed memory, physically contiguous, one page only, readonly
1104 */
1105
1106 if ((vma->vm_end - vma->vm_start) > PAGE_SIZE) {
1107 dev_info(&dd->pcidev->dev, "FAIL on pioavailregs_dma: "
1108 "reqlen %lx > actual %lx\n",
1109 vma->vm_end - vma->vm_start,
1110 (unsigned long) PAGE_SIZE);
1111 ret = -EFAULT;
1112 goto bail;
1113 }
1114
1115 if (vma->vm_flags & VM_WRITE) {
1116 dev_info(&dd->pcidev->dev,
1117 "Can't map pioavailregs as writable (flags=%lx)\n",
1118 vma->vm_flags);
1119 ret = -EPERM;
1120 goto bail;
1121 }
1122
1123 /* don't allow them to later change with mprotect */
1124 vma->vm_flags &= ~VM_MAYWRITE;
1125
1126 ret = remap_pfn_range(vma, vma->vm_start,
1127 dd->ipath_pioavailregs_phys >> PAGE_SHIFT,
1128 PAGE_SIZE, vma->vm_page_prot);
1129bail:
1130 return ret;
1131}
1132
1133/**
1134 * ipath_mmap - mmap various structures into user space
1135 * @fp: the file pointer
1136 * @vma: the VM area
1137 *
1138 * We use this to have a shared buffer between the kernel and the user code
1139 * for the rcvhdr queue, egr buffers, and the per-port user regs and pio
1140 * buffers in the chip. We have the open and close entries so we can bump
1141 * the ref count and keep the driver from being unloaded while still mapped.
1142 */
1143static int ipath_mmap(struct file *fp, struct vm_area_struct *vma)
1144{
1145 struct ipath_portdata *pd;
1146 struct ipath_devdata *dd;
1147 u64 pgaddr, ureg;
1148 int ret;
1149
1150 pd = port_fp(fp);
1151 dd = pd->port_dd;
1152 /*
1153 * This is the ipath_do_user_init() code, mapping the shared buffers
1154 * into the user process. The address referred to by vm_pgoff is the
1155 * virtual, not physical, address; we only do one mmap for each
1156 * space mapped.
1157 */
1158 pgaddr = vma->vm_pgoff << PAGE_SHIFT;
1159
1160 /*
1161 * note that ureg does *NOT* have the kregvirt as part of it, to be
1162 * sure that for 32 bit programs, we don't end up trying to map a >
1163 * 44 address. Has to match ipath_get_base_info() code that sets
1164 * __spi_uregbase
1165 */
1166
1167 ureg = dd->ipath_uregbase + dd->ipath_palign * pd->port_port;
1168
1169 ipath_cdbg(MM, "ushare: pgaddr %llx vm_start=%lx, vmlen %lx\n",
1170 (unsigned long long) pgaddr, vma->vm_start,
1171 vma->vm_end - vma->vm_start);
1172
1173 if (pgaddr == ureg)
1174 ret = mmap_ureg(vma, dd, ureg);
1175 else if (pgaddr == pd->port_piobufs)
1176 ret = mmap_piobufs(vma, dd, pd);
1177 else if (pgaddr == (u64) pd->port_rcvegr_phys)
1178 ret = mmap_rcvegrbufs(vma, pd);
1179 else if (pgaddr == (u64) pd->port_rcvhdrq_phys)
1180 ret = mmap_rcvhdrq(vma, pd);
1181 else if (pgaddr == dd->ipath_pioavailregs_phys)
1182 ret = mmap_pioavailregs(vma, pd);
1183 else
1184 ret = -EINVAL;
1185
1186 vma->vm_private_data = NULL;
1187
1188 if (ret < 0)
1189 dev_info(&dd->pcidev->dev,
1190 "Failure %d on addr %lx, off %lx\n",
1191 -ret, vma->vm_start, vma->vm_pgoff);
1192
1193 return ret;
1194}
1195
1196static unsigned int ipath_poll(struct file *fp,
1197 struct poll_table_struct *pt)
1198{
1199 struct ipath_portdata *pd;
1200 u32 head, tail;
1201 int bit;
1202 struct ipath_devdata *dd;
1203
1204 pd = port_fp(fp);
1205 dd = pd->port_dd;
1206
1207 bit = pd->port_port + INFINIPATH_R_INTRAVAIL_SHIFT;
1208 set_bit(bit, &dd->ipath_rcvctrl);
1209
1210 /*
1211 * Before blocking, make sure that head is still == tail,
1212 * reading from the chip, so we can be sure the interrupt
1213 * enable has made it to the chip. If not equal, disable
1214 * interrupt again and return immediately. This avoids races,
1215 * and the overhead of the chip read doesn't matter much at
1216 * this point, since we are waiting for something anyway.
1217 */
1218
1219 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1220 dd->ipath_rcvctrl);
1221
1222 head = ipath_read_ureg32(dd, ur_rcvhdrhead, pd->port_port);
1223 tail = ipath_read_ureg32(dd, ur_rcvhdrtail, pd->port_port);
1224
1225 if (tail == head) {
1226 set_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag);
1227 poll_wait(fp, &pd->port_wait, pt);
1228
1229 if (test_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag)) {
1230 /* timed out, no packets received */
1231 clear_bit(IPATH_PORT_WAITING_RCV, &pd->port_flag);
1232 pd->port_rcvwait_to++;
1233 }
1234 }
1235 else {
1236 /* it's already happened; don't do wait_event overhead */
1237 pd->port_rcvnowait++;
1238 }
1239
1240 clear_bit(bit, &dd->ipath_rcvctrl);
1241 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
1242 dd->ipath_rcvctrl);
1243
1244 return 0;
1245}
1246
1247static int try_alloc_port(struct ipath_devdata *dd, int port,
1248 struct file *fp)
1249{
1250 int ret;
1251
1252 if (!dd->ipath_pd[port]) {
1253 void *p, *ptmp;
1254
1255 p = kzalloc(sizeof(struct ipath_portdata), GFP_KERNEL);
1256
1257 /*
1258 * Allocate memory for use in ipath_tid_update() just once
1259 * at open, not per call. Reduces cost of expected send
1260 * setup.
1261 */
1262 ptmp = kmalloc(dd->ipath_rcvtidcnt * sizeof(u16) +
1263 dd->ipath_rcvtidcnt * sizeof(struct page **),
1264 GFP_KERNEL);
1265 if (!p || !ptmp) {
1266 ipath_dev_err(dd, "Unable to allocate portdata "
1267 "memory, failing open\n");
1268 ret = -ENOMEM;
1269 kfree(p);
1270 kfree(ptmp);
1271 goto bail;
1272 }
1273 dd->ipath_pd[port] = p;
1274 dd->ipath_pd[port]->port_port = port;
1275 dd->ipath_pd[port]->port_dd = dd;
1276 dd->ipath_pd[port]->port_tid_pg_list = ptmp;
1277 init_waitqueue_head(&dd->ipath_pd[port]->port_wait);
1278 }
1279 if (!dd->ipath_pd[port]->port_cnt) {
1280 dd->ipath_pd[port]->port_cnt = 1;
1281 fp->private_data = (void *) dd->ipath_pd[port];
1282 ipath_cdbg(PROC, "%s[%u] opened unit:port %u:%u\n",
1283 current->comm, current->pid, dd->ipath_unit,
1284 port);
1285 dd->ipath_pd[port]->port_pid = current->pid;
1286 strncpy(dd->ipath_pd[port]->port_comm, current->comm,
1287 sizeof(dd->ipath_pd[port]->port_comm));
1288 ipath_stats.sps_ports++;
1289 ret = 0;
1290 goto bail;
1291 }
1292 ret = -EBUSY;
1293
1294bail:
1295 return ret;
1296}
1297
1298static inline int usable(struct ipath_devdata *dd)
1299{
1300 return dd &&
1301 (dd->ipath_flags & IPATH_PRESENT) &&
1302 dd->ipath_kregbase &&
1303 dd->ipath_lid &&
1304 !(dd->ipath_flags & (IPATH_LINKDOWN | IPATH_DISABLED
1305 | IPATH_LINKUNK));
1306}
1307
1308static int find_free_port(int unit, struct file *fp)
1309{
1310 struct ipath_devdata *dd = ipath_lookup(unit);
1311 int ret, i;
1312
1313 if (!dd) {
1314 ret = -ENODEV;
1315 goto bail;
1316 }
1317
1318 if (!usable(dd)) {
1319 ret = -ENETDOWN;
1320 goto bail;
1321 }
1322
1323 for (i = 0; i < dd->ipath_cfgports; i++) {
1324 ret = try_alloc_port(dd, i, fp);
1325 if (ret != -EBUSY)
1326 goto bail;
1327 }
1328 ret = -EBUSY;
1329
1330bail:
1331 return ret;
1332}
1333
1334static int find_best_unit(struct file *fp)
1335{
1336 int ret = 0, i, prefunit = -1, devmax;
1337 int maxofallports, npresent, nup;
1338 int ndev;
1339
1340 (void) ipath_count_units(&npresent, &nup, &maxofallports);
1341
1342 /*
1343 * This code is present to allow a knowledgeable person to
1344 * specify the layout of processes to processors before opening
1345 * this driver, and then we'll assign the process to the "closest"
1346 * HT-400 to that processor (we assume reasonable connectivity,
1347 * for now). This code assumes that if affinity has been set
1348 * before this point, that at most one cpu is set; for now this
1349 * is reasonable. I check for both cpus_empty() and cpus_full(),
1350 * in case some kernel variant sets none of the bits when no
1351 * affinity is set. 2.6.11 and 12 kernels have all present
1352 * cpus set. Some day we'll have to fix it up further to handle
1353 * a cpu subset. This algorithm fails for two HT-400's connected
1354 * in tunnel fashion. Eventually this needs real topology
1355 * information. There may be some issues with dual core numbering
1356 * as well. This needs more work prior to release.
1357 */
1358 if (!cpus_empty(current->cpus_allowed) &&
1359 !cpus_full(current->cpus_allowed)) {
1360 int ncpus = num_online_cpus(), curcpu = -1;
1361 for (i = 0; i < ncpus; i++)
1362 if (cpu_isset(i, current->cpus_allowed)) {
1363 ipath_cdbg(PROC, "%s[%u] affinity set for "
1364 "cpu %d\n", current->comm,
1365 current->pid, i);
1366 curcpu = i;
1367 }
1368 if (curcpu != -1) {
1369 if (npresent) {
1370 prefunit = curcpu / (ncpus / npresent);
1371 ipath_dbg("%s[%u] %d chips, %d cpus, "
1372 "%d cpus/chip, select unit %d\n",
1373 current->comm, current->pid,
1374 npresent, ncpus, ncpus / npresent,
1375 prefunit);
1376 }
1377 }
1378 }
1379
1380 /*
1381 * user ports start at 1, kernel port is 0
1382 * For now, we do round-robin access across all chips
1383 */
1384
1385 if (prefunit != -1)
1386 devmax = prefunit + 1;
1387 else
1388 devmax = ipath_count_units(NULL, NULL, NULL);
1389recheck:
1390 for (i = 1; i < maxofallports; i++) {
1391 for (ndev = prefunit != -1 ? prefunit : 0; ndev < devmax;
1392 ndev++) {
1393 struct ipath_devdata *dd = ipath_lookup(ndev);
1394
1395 if (!usable(dd))
1396 continue; /* can't use this unit */
1397 if (i >= dd->ipath_cfgports)
1398 /*
1399 * Maxed out on users of this unit. Try
1400 * next.
1401 */
1402 continue;
1403 ret = try_alloc_port(dd, i, fp);
1404 if (!ret)
1405 goto done;
1406 }
1407 }
1408
1409 if (npresent) {
1410 if (nup == 0) {
1411 ret = -ENETDOWN;
1412 ipath_dbg("No ports available (none initialized "
1413 "and ready)\n");
1414 } else {
1415 if (prefunit > 0) {
1416 /* if started above 0, retry from 0 */
1417 ipath_cdbg(PROC,
1418 "%s[%u] no ports on prefunit "
1419 "%d, clear and re-check\n",
1420 current->comm, current->pid,
1421 prefunit);
1422 devmax = ipath_count_units(NULL, NULL,
1423 NULL);
1424 prefunit = -1;
1425 goto recheck;
1426 }
1427 ret = -EBUSY;
1428 ipath_dbg("No ports available\n");
1429 }
1430 } else {
1431 ret = -ENXIO;
1432 ipath_dbg("No boards found\n");
1433 }
1434
1435done:
1436 return ret;
1437}
1438
1439static int ipath_open(struct inode *in, struct file *fp)
1440{
1441 int ret, minor;
1442
1443 mutex_lock(&ipath_mutex);
1444
1445 minor = iminor(in);
1446 ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n",
1447 (long)in->i_rdev, minor);
1448
1449 if (minor)
1450 ret = find_free_port(minor - 1, fp);
1451 else
1452 ret = find_best_unit(fp);
1453
1454 mutex_unlock(&ipath_mutex);
1455 return ret;
1456}
1457
1458/**
1459 * unlock_exptid - unlock any expected TID entries port still had in use
1460 * @pd: port
1461 *
1462 * We don't actually update the chip here, because we do a bulk update
1463 * below, using ipath_f_clear_tids.
1464 */
1465static void unlock_expected_tids(struct ipath_portdata *pd)
1466{
1467 struct ipath_devdata *dd = pd->port_dd;
1468 int port_tidbase = pd->port_port * dd->ipath_rcvtidcnt;
1469 int i, cnt = 0, maxtid = port_tidbase + dd->ipath_rcvtidcnt;
1470
1471 ipath_cdbg(VERBOSE, "Port %u unlocking any locked expTID pages\n",
1472 pd->port_port);
1473 for (i = port_tidbase; i < maxtid; i++) {
1474 if (!dd->ipath_pageshadow[i])
1475 continue;
1476
1477 ipath_release_user_pages_on_close(&dd->ipath_pageshadow[i],
1478 1);
1479 dd->ipath_pageshadow[i] = NULL;
1480 cnt++;
1481 ipath_stats.sps_pageunlocks++;
1482 }
1483 if (cnt)
1484 ipath_cdbg(VERBOSE, "Port %u locked %u expTID entries\n",
1485 pd->port_port, cnt);
1486
1487 if (ipath_stats.sps_pagelocks || ipath_stats.sps_pageunlocks)
1488 ipath_cdbg(VERBOSE, "%llu pages locked, %llu unlocked\n",
1489 (unsigned long long) ipath_stats.sps_pagelocks,
1490 (unsigned long long)
1491 ipath_stats.sps_pageunlocks);
1492}
1493
1494static int ipath_close(struct inode *in, struct file *fp)
1495{
1496 int ret = 0;
1497 struct ipath_portdata *pd;
1498 struct ipath_devdata *dd;
1499 unsigned port;
1500
1501 ipath_cdbg(VERBOSE, "close on dev %lx, private data %p\n",
1502 (long)in->i_rdev, fp->private_data);
1503
1504 mutex_lock(&ipath_mutex);
1505
1506 pd = port_fp(fp);
1507 port = pd->port_port;
1508 fp->private_data = NULL;
1509 dd = pd->port_dd;
1510
1511 if (pd->port_hdrqfull) {
1512 ipath_cdbg(PROC, "%s[%u] had %u rcvhdrqfull errors "
1513 "during run\n", pd->port_comm, pd->port_pid,
1514 pd->port_hdrqfull);
1515 pd->port_hdrqfull = 0;
1516 }
1517
1518 if (pd->port_rcvwait_to || pd->port_piowait_to
1519 || pd->port_rcvnowait || pd->port_pionowait) {
1520 ipath_cdbg(VERBOSE, "port%u, %u rcv, %u pio wait timeo; "
1521 "%u rcv %u, pio already\n",
1522 pd->port_port, pd->port_rcvwait_to,
1523 pd->port_piowait_to, pd->port_rcvnowait,
1524 pd->port_pionowait);
1525 pd->port_rcvwait_to = pd->port_piowait_to =
1526 pd->port_rcvnowait = pd->port_pionowait = 0;
1527 }
1528 if (pd->port_flag) {
1529 ipath_dbg("port %u port_flag still set to 0x%lx\n",
1530 pd->port_port, pd->port_flag);
1531 pd->port_flag = 0;
1532 }
1533
1534 if (dd->ipath_kregbase) {
1535 if (pd->port_rcvhdrtail_uaddr) {
1536 pd->port_rcvhdrtail_uaddr = 0;
1537 pd->port_rcvhdrtail_kvaddr = NULL;
1538 ipath_release_user_pages_on_close(
1539 &pd->port_rcvhdrtail_pagep, 1);
1540 pd->port_rcvhdrtail_pagep = NULL;
1541 ipath_stats.sps_pageunlocks++;
1542 }
1543 ipath_write_kreg_port(
1544 dd, dd->ipath_kregs->kr_rcvhdrtailaddr,
1545 port, 0ULL);
1546 ipath_write_kreg_port(
1547 dd, dd->ipath_kregs->kr_rcvhdraddr,
1548 pd->port_port, 0);
1549
1550 /* clean up the pkeys for this port user */
1551 ipath_clean_part_key(pd, dd);
1552
1553 if (port < dd->ipath_cfgports) {
1554 int i = dd->ipath_pbufsport * (port - 1);
1555 ipath_disarm_piobufs(dd, i, dd->ipath_pbufsport);
1556
1557 /* atomically clear receive enable port. */
1558 clear_bit(INFINIPATH_R_PORTENABLE_SHIFT + port,
1559 &dd->ipath_rcvctrl);
1560 ipath_write_kreg(
1561 dd,
1562 dd->ipath_kregs->kr_rcvctrl,
1563 dd->ipath_rcvctrl);
1564
1565 if (dd->ipath_pageshadow)
1566 unlock_expected_tids(pd);
1567 ipath_stats.sps_ports--;
1568 ipath_cdbg(PROC, "%s[%u] closed port %u:%u\n",
1569 pd->port_comm, pd->port_pid,
1570 dd->ipath_unit, port);
1571 }
1572 }
1573
1574 pd->port_cnt = 0;
1575 pd->port_pid = 0;
1576
1577 dd->ipath_f_clear_tids(dd, pd->port_port);
1578
1579 ipath_free_pddata(dd, pd->port_port, 0);
1580
1581 mutex_unlock(&ipath_mutex);
1582
1583 return ret;
1584}
1585
1586static int ipath_port_info(struct ipath_portdata *pd,
1587 struct ipath_port_info __user *uinfo)
1588{
1589 struct ipath_port_info info;
1590 int nup;
1591 int ret;
1592
1593 (void) ipath_count_units(NULL, &nup, NULL);
1594 info.num_active = nup;
1595 info.unit = pd->port_dd->ipath_unit;
1596 info.port = pd->port_port;
1597
1598 if (copy_to_user(uinfo, &info, sizeof(info))) {
1599 ret = -EFAULT;
1600 goto bail;
1601 }
1602 ret = 0;
1603
1604bail:
1605 return ret;
1606}
1607
1608static ssize_t ipath_write(struct file *fp, const char __user *data,
1609 size_t count, loff_t *off)
1610{
1611 const struct ipath_cmd __user *ucmd;
1612 struct ipath_portdata *pd;
1613 const void __user *src;
1614 size_t consumed, copy;
1615 struct ipath_cmd cmd;
1616 ssize_t ret = 0;
1617 void *dest;
1618
1619 if (count < sizeof(cmd.type)) {
1620 ret = -EINVAL;
1621 goto bail;
1622 }
1623
1624 ucmd = (const struct ipath_cmd __user *) data;
1625
1626 if (copy_from_user(&cmd.type, &ucmd->type, sizeof(cmd.type))) {
1627 ret = -EFAULT;
1628 goto bail;
1629 }
1630
1631 consumed = sizeof(cmd.type);
1632
1633 switch (cmd.type) {
1634 case IPATH_CMD_USER_INIT:
1635 copy = sizeof(cmd.cmd.user_info);
1636 dest = &cmd.cmd.user_info;
1637 src = &ucmd->cmd.user_info;
1638 break;
1639 case IPATH_CMD_RECV_CTRL:
1640 copy = sizeof(cmd.cmd.recv_ctrl);
1641 dest = &cmd.cmd.recv_ctrl;
1642 src = &ucmd->cmd.recv_ctrl;
1643 break;
1644 case IPATH_CMD_PORT_INFO:
1645 copy = sizeof(cmd.cmd.port_info);
1646 dest = &cmd.cmd.port_info;
1647 src = &ucmd->cmd.port_info;
1648 break;
1649 case IPATH_CMD_TID_UPDATE:
1650 case IPATH_CMD_TID_FREE:
1651 copy = sizeof(cmd.cmd.tid_info);
1652 dest = &cmd.cmd.tid_info;
1653 src = &ucmd->cmd.tid_info;
1654 break;
1655 case IPATH_CMD_SET_PART_KEY:
1656 copy = sizeof(cmd.cmd.part_key);
1657 dest = &cmd.cmd.part_key;
1658 src = &ucmd->cmd.part_key;
1659 break;
1660 default:
1661 ret = -EINVAL;
1662 goto bail;
1663 }
1664
1665 if ((count - consumed) < copy) {
1666 ret = -EINVAL;
1667 goto bail;
1668 }
1669
1670 if (copy_from_user(dest, src, copy)) {
1671 ret = -EFAULT;
1672 goto bail;
1673 }
1674
1675 consumed += copy;
1676 pd = port_fp(fp);
1677
1678 switch (cmd.type) {
1679 case IPATH_CMD_USER_INIT:
1680 ret = ipath_do_user_init(pd, &cmd.cmd.user_info);
1681 if (ret < 0)
1682 goto bail;
1683 ret = ipath_get_base_info(
1684 pd, (void __user *) (unsigned long)
1685 cmd.cmd.user_info.spu_base_info,
1686 cmd.cmd.user_info.spu_base_info_size);
1687 break;
1688 case IPATH_CMD_RECV_CTRL:
1689 ret = ipath_manage_rcvq(pd, cmd.cmd.recv_ctrl);
1690 break;
1691 case IPATH_CMD_PORT_INFO:
1692 ret = ipath_port_info(pd,
1693 (struct ipath_port_info __user *)
1694 (unsigned long) cmd.cmd.port_info);
1695 break;
1696 case IPATH_CMD_TID_UPDATE:
1697 ret = ipath_tid_update(pd, &cmd.cmd.tid_info);
1698 break;
1699 case IPATH_CMD_TID_FREE:
1700 ret = ipath_tid_free(pd, &cmd.cmd.tid_info);
1701 break;
1702 case IPATH_CMD_SET_PART_KEY:
1703 ret = ipath_set_part_key(pd, cmd.cmd.part_key);
1704 break;
1705 }
1706
1707 if (ret >= 0)
1708 ret = consumed;
1709
1710bail:
1711 return ret;
1712}
1713
1714static struct class *ipath_class;
1715
1716static int init_cdev(int minor, char *name, struct file_operations *fops,
1717 struct cdev **cdevp, struct class_device **class_devp)
1718{
1719 const dev_t dev = MKDEV(IPATH_MAJOR, minor);
1720 struct cdev *cdev = NULL;
1721 struct class_device *class_dev = NULL;
1722 int ret;
1723
1724 cdev = cdev_alloc();
1725 if (!cdev) {
1726 printk(KERN_ERR IPATH_DRV_NAME
1727 ": Could not allocate cdev for minor %d, %s\n",
1728 minor, name);
1729 ret = -ENOMEM;
1730 goto done;
1731 }
1732
1733 cdev->owner = THIS_MODULE;
1734 cdev->ops = fops;
1735 kobject_set_name(&cdev->kobj, name);
1736
1737 ret = cdev_add(cdev, dev, 1);
1738 if (ret < 0) {
1739 printk(KERN_ERR IPATH_DRV_NAME
1740 ": Could not add cdev for minor %d, %s (err %d)\n",
1741 minor, name, -ret);
1742 goto err_cdev;
1743 }
1744
1745 class_dev = class_device_create(ipath_class, NULL, dev, NULL, name);
1746
1747 if (IS_ERR(class_dev)) {
1748 ret = PTR_ERR(class_dev);
1749 printk(KERN_ERR IPATH_DRV_NAME ": Could not create "
1750 "class_dev for minor %d, %s (err %d)\n",
1751 minor, name, -ret);
1752 goto err_cdev;
1753 }
1754
1755 goto done;
1756
1757err_cdev:
1758 cdev_del(cdev);
1759 cdev = NULL;
1760
1761done:
1762 if (ret >= 0) {
1763 *cdevp = cdev;
1764 *class_devp = class_dev;
1765 } else {
1766 *cdevp = NULL;
1767 *class_devp = NULL;
1768 }
1769
1770 return ret;
1771}
1772
1773int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
1774 struct cdev **cdevp, struct class_device **class_devp)
1775{
1776 return init_cdev(minor, name, fops, cdevp, class_devp);
1777}
1778
1779static void cleanup_cdev(struct cdev **cdevp,
1780 struct class_device **class_devp)
1781{
1782 struct class_device *class_dev = *class_devp;
1783
1784 if (class_dev) {
1785 class_device_unregister(class_dev);
1786 *class_devp = NULL;
1787 }
1788
1789 if (*cdevp) {
1790 cdev_del(*cdevp);
1791 *cdevp = NULL;
1792 }
1793}
1794
1795void ipath_cdev_cleanup(struct cdev **cdevp,
1796 struct class_device **class_devp)
1797{
1798 cleanup_cdev(cdevp, class_devp);
1799}
1800
1801static struct cdev *wildcard_cdev;
1802static struct class_device *wildcard_class_dev;
1803
1804static const dev_t dev = MKDEV(IPATH_MAJOR, 0);
1805
1806static int user_init(void)
1807{
1808 int ret;
1809
1810 ret = register_chrdev_region(dev, IPATH_NMINORS, IPATH_DRV_NAME);
1811 if (ret < 0) {
1812 printk(KERN_ERR IPATH_DRV_NAME ": Could not register "
1813 "chrdev region (err %d)\n", -ret);
1814 goto done;
1815 }
1816
1817 ipath_class = class_create(THIS_MODULE, IPATH_DRV_NAME);
1818
1819 if (IS_ERR(ipath_class)) {
1820 ret = PTR_ERR(ipath_class);
1821 printk(KERN_ERR IPATH_DRV_NAME ": Could not create "
1822 "device class (err %d)\n", -ret);
1823 goto bail;
1824 }
1825
1826 goto done;
1827bail:
1828 unregister_chrdev_region(dev, IPATH_NMINORS);
1829done:
1830 return ret;
1831}
1832
1833static void user_cleanup(void)
1834{
1835 if (ipath_class) {
1836 class_destroy(ipath_class);
1837 ipath_class = NULL;
1838 }
1839
1840 unregister_chrdev_region(dev, IPATH_NMINORS);
1841}
1842
1843static atomic_t user_count = ATOMIC_INIT(0);
1844static atomic_t user_setup = ATOMIC_INIT(0);
1845
1846int ipath_user_add(struct ipath_devdata *dd)
1847{
1848 char name[10];
1849 int ret;
1850
1851 if (atomic_inc_return(&user_count) == 1) {
1852 ret = user_init();
1853 if (ret < 0) {
1854 ipath_dev_err(dd, "Unable to set up user support: "
1855 "error %d\n", -ret);
1856 goto bail;
1857 }
1858 ret = ipath_diag_init();
1859 if (ret < 0) {
1860 ipath_dev_err(dd, "Unable to set up diag support: "
1861 "error %d\n", -ret);
1862 goto bail_sma;
1863 }
1864
1865 ret = init_cdev(0, "ipath", &ipath_file_ops, &wildcard_cdev,
1866 &wildcard_class_dev);
1867 if (ret < 0) {
1868 ipath_dev_err(dd, "Could not create wildcard "
1869 "minor: error %d\n", -ret);
1870 goto bail_diag;
1871 }
1872
1873 atomic_set(&user_setup, 1);
1874 }
1875
1876 snprintf(name, sizeof(name), "ipath%d", dd->ipath_unit);
1877
1878 ret = init_cdev(dd->ipath_unit + 1, name, &ipath_file_ops,
1879 &dd->cdev, &dd->class_dev);
1880 if (ret < 0)
1881 ipath_dev_err(dd, "Could not create user minor %d, %s\n",
1882 dd->ipath_unit + 1, name);
1883
1884 goto bail;
1885
1886bail_diag:
1887 ipath_diag_cleanup();
1888bail_sma:
1889 user_cleanup();
1890bail:
1891 return ret;
1892}
1893
1894void ipath_user_del(struct ipath_devdata *dd)
1895{
1896 cleanup_cdev(&dd->cdev, &dd->class_dev);
1897
1898 if (atomic_dec_return(&user_count) == 0) {
1899 if (atomic_read(&user_setup) == 0)
1900 goto bail;
1901
1902 cleanup_cdev(&wildcard_cdev, &wildcard_class_dev);
1903 ipath_diag_cleanup();
1904 user_cleanup();
1905
1906 atomic_set(&user_setup, 0);
1907 }
1908bail:
1909 return;
1910}
diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
new file mode 100644
index 000000000000..e274120567e1
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
@@ -0,0 +1,605 @@
1/*
2 * Copyright (c) 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/version.h>
34#include <linux/config.h>
35#include <linux/module.h>
36#include <linux/fs.h>
37#include <linux/mount.h>
38#include <linux/pagemap.h>
39#include <linux/init.h>
40#include <linux/namei.h>
41#include <linux/pci.h>
42
43#include "ipath_kernel.h"
44
45#define IPATHFS_MAGIC 0x726a77
46
47static struct super_block *ipath_super;
48
49static int ipathfs_mknod(struct inode *dir, struct dentry *dentry,
50 int mode, struct file_operations *fops,
51 void *data)
52{
53 int error;
54 struct inode *inode = new_inode(dir->i_sb);
55
56 if (!inode) {
57 error = -EPERM;
58 goto bail;
59 }
60
61 inode->i_mode = mode;
62 inode->i_uid = 0;
63 inode->i_gid = 0;
64 inode->i_blksize = PAGE_CACHE_SIZE;
65 inode->i_blocks = 0;
66 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
67 inode->u.generic_ip = data;
68 if ((mode & S_IFMT) == S_IFDIR) {
69 inode->i_op = &simple_dir_inode_operations;
70 inode->i_nlink++;
71 dir->i_nlink++;
72 }
73
74 inode->i_fop = fops;
75
76 d_instantiate(dentry, inode);
77 error = 0;
78
79bail:
80 return error;
81}
82
83static int create_file(const char *name, mode_t mode,
84 struct dentry *parent, struct dentry **dentry,
85 struct file_operations *fops, void *data)
86{
87 int error;
88
89 *dentry = NULL;
90 mutex_lock(&parent->d_inode->i_mutex);
91 *dentry = lookup_one_len(name, parent, strlen(name));
92 if (!IS_ERR(dentry))
93 error = ipathfs_mknod(parent->d_inode, *dentry,
94 mode, fops, data);
95 else
96 error = PTR_ERR(dentry);
97 mutex_unlock(&parent->d_inode->i_mutex);
98
99 return error;
100}
101
102static ssize_t atomic_stats_read(struct file *file, char __user *buf,
103 size_t count, loff_t *ppos)
104{
105 return simple_read_from_buffer(buf, count, ppos, &ipath_stats,
106 sizeof ipath_stats);
107}
108
109static struct file_operations atomic_stats_ops = {
110 .read = atomic_stats_read,
111};
112
113#define NUM_COUNTERS sizeof(struct infinipath_counters) / sizeof(u64)
114
115static ssize_t atomic_counters_read(struct file *file, char __user *buf,
116 size_t count, loff_t *ppos)
117{
118 u64 counters[NUM_COUNTERS];
119 u16 i;
120 struct ipath_devdata *dd;
121
122 dd = file->f_dentry->d_inode->u.generic_ip;
123
124 for (i = 0; i < NUM_COUNTERS; i++)
125 counters[i] = ipath_snap_cntr(dd, i);
126
127 return simple_read_from_buffer(buf, count, ppos, counters,
128 sizeof counters);
129}
130
131static struct file_operations atomic_counters_ops = {
132 .read = atomic_counters_read,
133};
134
135static ssize_t atomic_node_info_read(struct file *file, char __user *buf,
136 size_t count, loff_t *ppos)
137{
138 u32 nodeinfo[10];
139 struct ipath_devdata *dd;
140 u64 guid;
141
142 dd = file->f_dentry->d_inode->u.generic_ip;
143
144 guid = be64_to_cpu(dd->ipath_guid);
145
146 nodeinfo[0] = /* BaseVersion is SMA */
147 /* ClassVersion is SMA */
148 (1 << 8) /* NodeType */
149 | (1 << 0); /* NumPorts */
150 nodeinfo[1] = (u32) (guid >> 32);
151 nodeinfo[2] = (u32) (guid & 0xffffffff);
152 /* PortGUID == SystemImageGUID for us */
153 nodeinfo[3] = nodeinfo[1];
154 /* PortGUID == SystemImageGUID for us */
155 nodeinfo[4] = nodeinfo[2];
156 /* PortGUID == NodeGUID for us */
157 nodeinfo[5] = nodeinfo[3];
158 /* PortGUID == NodeGUID for us */
159 nodeinfo[6] = nodeinfo[4];
160 nodeinfo[7] = (4 << 16) /* we support 4 pkeys */
161 | (dd->ipath_deviceid << 0);
162 /* our chip version as 16 bits major, 16 bits minor */
163 nodeinfo[8] = dd->ipath_minrev | (dd->ipath_majrev << 16);
164 nodeinfo[9] = (dd->ipath_unit << 24) | (dd->ipath_vendorid << 0);
165
166 return simple_read_from_buffer(buf, count, ppos, nodeinfo,
167 sizeof nodeinfo);
168}
169
170static struct file_operations atomic_node_info_ops = {
171 .read = atomic_node_info_read,
172};
173
174static ssize_t atomic_port_info_read(struct file *file, char __user *buf,
175 size_t count, loff_t *ppos)
176{
177 u32 portinfo[13];
178 u32 tmp, tmp2;
179 struct ipath_devdata *dd;
180
181 dd = file->f_dentry->d_inode->u.generic_ip;
182
183 /* so we only initialize non-zero fields. */
184 memset(portinfo, 0, sizeof portinfo);
185
186 /*
187 * Notimpl yet M_Key (64)
188 * Notimpl yet GID (64)
189 */
190
191 portinfo[4] = (dd->ipath_lid << 16);
192
193 /*
194 * Notimpl yet SMLID (should we store this in the driver, in case
195 * SMA dies?) CapabilityMask is 0, we don't support any of these
196 * DiagCode is 0; we don't store any diag info for now Notimpl yet
197 * M_KeyLeasePeriod (we don't support M_Key)
198 */
199
200 /* LocalPortNum is whichever port number they ask for */
201 portinfo[7] = (dd->ipath_unit << 24)
202 /* LinkWidthEnabled */
203 | (2 << 16)
204 /* LinkWidthSupported (really 2, but not IB valid) */
205 | (3 << 8)
206 /* LinkWidthActive */
207 | (2 << 0);
208 tmp = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK;
209 tmp2 = 5;
210 if (tmp == IPATH_IBSTATE_INIT)
211 tmp = 2;
212 else if (tmp == IPATH_IBSTATE_ARM)
213 tmp = 3;
214 else if (tmp == IPATH_IBSTATE_ACTIVE)
215 tmp = 4;
216 else {
217 tmp = 0; /* down */
218 tmp2 = tmp & 0xf;
219 }
220
221 portinfo[8] = (1 << 28) /* LinkSpeedSupported */
222 | (tmp << 24) /* PortState */
223 | (tmp2 << 20) /* PortPhysicalState */
224 | (2 << 16)
225
226 /* LinkDownDefaultState */
227 /* M_KeyProtectBits == 0 */
228 /* NotImpl yet LMC == 0 (we can support all values) */
229 | (1 << 4) /* LinkSpeedActive */
230 | (1 << 0); /* LinkSpeedEnabled */
231 switch (dd->ipath_ibmtu) {
232 case 4096:
233 tmp = 5;
234 break;
235 case 2048:
236 tmp = 4;
237 break;
238 case 1024:
239 tmp = 3;
240 break;
241 case 512:
242 tmp = 2;
243 break;
244 case 256:
245 tmp = 1;
246 break;
247 default: /* oops, something is wrong */
248 ipath_dbg("Problem, ipath_ibmtu 0x%x not a valid IB MTU, "
249 "treat as 2048\n", dd->ipath_ibmtu);
250 tmp = 4;
251 break;
252 }
253 portinfo[9] = (tmp << 28)
254 /* NeighborMTU */
255 /* Notimpl MasterSMSL */
256 | (1 << 20)
257
258 /* VLCap */
259 /* Notimpl InitType (actually, an SMA decision) */
260 /* VLHighLimit is 0 (only one VL) */
261 ; /* VLArbitrationHighCap is 0 (only one VL) */
262 portinfo[10] = /* VLArbitrationLowCap is 0 (only one VL) */
263 /* InitTypeReply is SMA decision */
264 (5 << 16) /* MTUCap 4096 */
265 | (7 << 13) /* VLStallCount */
266 | (0x1f << 8) /* HOQLife */
267 | (1 << 4)
268
269 /* OperationalVLs 0 */
270 /* PartitionEnforcementInbound */
271 /* PartitionEnforcementOutbound not enforced */
272 /* FilterRawinbound not enforced */
273 ; /* FilterRawOutbound not enforced */
274 /* M_KeyViolations are not counted by hardware, SMA can count */
275 tmp = ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
276 /* P_KeyViolations are counted by hardware. */
277 portinfo[11] = ((tmp & 0xffff) << 0);
278 portinfo[12] =
279 /* Q_KeyViolations are not counted by hardware */
280 (1 << 8)
281
282 /* GUIDCap */
283 /* SubnetTimeOut handled by SMA */
284 /* RespTimeValue handled by SMA */
285 ;
286 /* LocalPhyErrors are programmed to max */
287 portinfo[12] |= (0xf << 20)
288 | (0xf << 16) /* OverRunErrors are programmed to max */
289 ;
290
291 return simple_read_from_buffer(buf, count, ppos, portinfo,
292 sizeof portinfo);
293}
294
295static struct file_operations atomic_port_info_ops = {
296 .read = atomic_port_info_read,
297};
298
299static ssize_t flash_read(struct file *file, char __user *buf,
300 size_t count, loff_t *ppos)
301{
302 struct ipath_devdata *dd;
303 ssize_t ret;
304 loff_t pos;
305 char *tmp;
306
307 pos = *ppos;
308
309 if ( pos < 0) {
310 ret = -EINVAL;
311 goto bail;
312 }
313
314 if (pos >= sizeof(struct ipath_flash)) {
315 ret = 0;
316 goto bail;
317 }
318
319 if (count > sizeof(struct ipath_flash) - pos)
320 count = sizeof(struct ipath_flash) - pos;
321
322 tmp = kmalloc(count, GFP_KERNEL);
323 if (!tmp) {
324 ret = -ENOMEM;
325 goto bail;
326 }
327
328 dd = file->f_dentry->d_inode->u.generic_ip;
329 if (ipath_eeprom_read(dd, pos, tmp, count)) {
330 ipath_dev_err(dd, "failed to read from flash\n");
331 ret = -ENXIO;
332 goto bail_tmp;
333 }
334
335 if (copy_to_user(buf, tmp, count)) {
336 ret = -EFAULT;
337 goto bail_tmp;
338 }
339
340 *ppos = pos + count;
341 ret = count;
342
343bail_tmp:
344 kfree(tmp);
345
346bail:
347 return ret;
348}
349
350static ssize_t flash_write(struct file *file, const char __user *buf,
351 size_t count, loff_t *ppos)
352{
353 struct ipath_devdata *dd;
354 ssize_t ret;
355 loff_t pos;
356 char *tmp;
357
358 pos = *ppos;
359
360 if ( pos < 0) {
361 ret = -EINVAL;
362 goto bail;
363 }
364
365 if (pos >= sizeof(struct ipath_flash)) {
366 ret = 0;
367 goto bail;
368 }
369
370 if (count > sizeof(struct ipath_flash) - pos)
371 count = sizeof(struct ipath_flash) - pos;
372
373 tmp = kmalloc(count, GFP_KERNEL);
374 if (!tmp) {
375 ret = -ENOMEM;
376 goto bail;
377 }
378
379 if (copy_from_user(tmp, buf, count)) {
380 ret = -EFAULT;
381 goto bail_tmp;
382 }
383
384 dd = file->f_dentry->d_inode->u.generic_ip;
385 if (ipath_eeprom_write(dd, pos, tmp, count)) {
386 ret = -ENXIO;
387 ipath_dev_err(dd, "failed to write to flash\n");
388 goto bail_tmp;
389 }
390
391 *ppos = pos + count;
392 ret = count;
393
394bail_tmp:
395 kfree(tmp);
396
397bail:
398 return ret;
399}
400
401static struct file_operations flash_ops = {
402 .read = flash_read,
403 .write = flash_write,
404};
405
406static int create_device_files(struct super_block *sb,
407 struct ipath_devdata *dd)
408{
409 struct dentry *dir, *tmp;
410 char unit[10];
411 int ret;
412
413 snprintf(unit, sizeof unit, "%02d", dd->ipath_unit);
414 ret = create_file(unit, S_IFDIR|S_IRUGO|S_IXUGO, sb->s_root, &dir,
415 (struct file_operations *) &simple_dir_operations,
416 dd);
417 if (ret) {
418 printk(KERN_ERR "create_file(%s) failed: %d\n", unit, ret);
419 goto bail;
420 }
421
422 ret = create_file("atomic_counters", S_IFREG|S_IRUGO, dir, &tmp,
423 &atomic_counters_ops, dd);
424 if (ret) {
425 printk(KERN_ERR "create_file(%s/atomic_counters) "
426 "failed: %d\n", unit, ret);
427 goto bail;
428 }
429
430 ret = create_file("node_info", S_IFREG|S_IRUGO, dir, &tmp,
431 &atomic_node_info_ops, dd);
432 if (ret) {
433 printk(KERN_ERR "create_file(%s/node_info) "
434 "failed: %d\n", unit, ret);
435 goto bail;
436 }
437
438 ret = create_file("port_info", S_IFREG|S_IRUGO, dir, &tmp,
439 &atomic_port_info_ops, dd);
440 if (ret) {
441 printk(KERN_ERR "create_file(%s/port_info) "
442 "failed: %d\n", unit, ret);
443 goto bail;
444 }
445
446 ret = create_file("flash", S_IFREG|S_IWUSR|S_IRUGO, dir, &tmp,
447 &flash_ops, dd);
448 if (ret) {
449 printk(KERN_ERR "create_file(%s/flash) "
450 "failed: %d\n", unit, ret);
451 goto bail;
452 }
453
454bail:
455 return ret;
456}
457
458static void remove_file(struct dentry *parent, char *name)
459{
460 struct dentry *tmp;
461
462 tmp = lookup_one_len(name, parent, strlen(name));
463
464 spin_lock(&dcache_lock);
465 spin_lock(&tmp->d_lock);
466 if (!(d_unhashed(tmp) && tmp->d_inode)) {
467 dget_locked(tmp);
468 __d_drop(tmp);
469 spin_unlock(&tmp->d_lock);
470 spin_unlock(&dcache_lock);
471 simple_unlink(parent->d_inode, tmp);
472 } else {
473 spin_unlock(&tmp->d_lock);
474 spin_unlock(&dcache_lock);
475 }
476}
477
478static int remove_device_files(struct super_block *sb,
479 struct ipath_devdata *dd)
480{
481 struct dentry *dir, *root;
482 char unit[10];
483 int ret;
484
485 root = dget(sb->s_root);
486 mutex_lock(&root->d_inode->i_mutex);
487 snprintf(unit, sizeof unit, "%02d", dd->ipath_unit);
488 dir = lookup_one_len(unit, root, strlen(unit));
489
490 if (IS_ERR(dir)) {
491 ret = PTR_ERR(dir);
492 printk(KERN_ERR "Lookup of %s failed\n", unit);
493 goto bail;
494 }
495
496 remove_file(dir, "flash");
497 remove_file(dir, "port_info");
498 remove_file(dir, "node_info");
499 remove_file(dir, "atomic_counters");
500 d_delete(dir);
501 ret = simple_rmdir(root->d_inode, dir);
502
503bail:
504 mutex_unlock(&root->d_inode->i_mutex);
505 dput(root);
506 return ret;
507}
508
509static int ipathfs_fill_super(struct super_block *sb, void *data,
510 int silent)
511{
512 struct ipath_devdata *dd, *tmp;
513 unsigned long flags;
514 int ret;
515
516 static struct tree_descr files[] = {
517 [1] = {"atomic_stats", &atomic_stats_ops, S_IRUGO},
518 {""},
519 };
520
521 ret = simple_fill_super(sb, IPATHFS_MAGIC, files);
522 if (ret) {
523 printk(KERN_ERR "simple_fill_super failed: %d\n", ret);
524 goto bail;
525 }
526
527 spin_lock_irqsave(&ipath_devs_lock, flags);
528
529 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
530 spin_unlock_irqrestore(&ipath_devs_lock, flags);
531 ret = create_device_files(sb, dd);
532 if (ret) {
533 deactivate_super(sb);
534 goto bail;
535 }
536 spin_lock_irqsave(&ipath_devs_lock, flags);
537 }
538
539 spin_unlock_irqrestore(&ipath_devs_lock, flags);
540
541bail:
542 return ret;
543}
544
545static struct super_block *ipathfs_get_sb(struct file_system_type *fs_type,
546 int flags, const char *dev_name,
547 void *data)
548{
549 ipath_super = get_sb_single(fs_type, flags, data,
550 ipathfs_fill_super);
551 return ipath_super;
552}
553
554static void ipathfs_kill_super(struct super_block *s)
555{
556 kill_litter_super(s);
557 ipath_super = NULL;
558}
559
560int ipathfs_add_device(struct ipath_devdata *dd)
561{
562 int ret;
563
564 if (ipath_super == NULL) {
565 ret = 0;
566 goto bail;
567 }
568
569 ret = create_device_files(ipath_super, dd);
570
571bail:
572 return ret;
573}
574
575int ipathfs_remove_device(struct ipath_devdata *dd)
576{
577 int ret;
578
579 if (ipath_super == NULL) {
580 ret = 0;
581 goto bail;
582 }
583
584 ret = remove_device_files(ipath_super, dd);
585
586bail:
587 return ret;
588}
589
590static struct file_system_type ipathfs_fs_type = {
591 .owner = THIS_MODULE,
592 .name = "ipathfs",
593 .get_sb = ipathfs_get_sb,
594 .kill_sb = ipathfs_kill_super,
595};
596
597int __init ipath_init_ipathfs(void)
598{
599 return register_filesystem(&ipathfs_fs_type);
600}
601
602void __exit ipath_exit_ipathfs(void)
603{
604 unregister_filesystem(&ipathfs_fs_type);
605}
diff --git a/drivers/infiniband/hw/ipath/ipath_ht400.c b/drivers/infiniband/hw/ipath/ipath_ht400.c
new file mode 100644
index 000000000000..4652435998f3
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_ht400.c
@@ -0,0 +1,1586 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33/*
34 * This file contains all of the code that is specific to the InfiniPath
35 * HT-400 chip.
36 */
37
38#include <linux/pci.h>
39#include <linux/delay.h>
40
41#include "ipath_kernel.h"
42#include "ipath_registers.h"
43
44/*
45 * This lists the InfiniPath HT400 registers, in the actual chip layout.
46 * This structure should never be directly accessed.
47 *
48 * The names are in InterCap form because they're taken straight from
49 * the chip specification. Since they're only used in this file, they
50 * don't pollute the rest of the source.
51*/
52
53struct _infinipath_do_not_use_kernel_regs {
54 unsigned long long Revision;
55 unsigned long long Control;
56 unsigned long long PageAlign;
57 unsigned long long PortCnt;
58 unsigned long long DebugPortSelect;
59 unsigned long long DebugPort;
60 unsigned long long SendRegBase;
61 unsigned long long UserRegBase;
62 unsigned long long CounterRegBase;
63 unsigned long long Scratch;
64 unsigned long long ReservedMisc1;
65 unsigned long long InterruptConfig;
66 unsigned long long IntBlocked;
67 unsigned long long IntMask;
68 unsigned long long IntStatus;
69 unsigned long long IntClear;
70 unsigned long long ErrorMask;
71 unsigned long long ErrorStatus;
72 unsigned long long ErrorClear;
73 unsigned long long HwErrMask;
74 unsigned long long HwErrStatus;
75 unsigned long long HwErrClear;
76 unsigned long long HwDiagCtrl;
77 unsigned long long MDIO;
78 unsigned long long IBCStatus;
79 unsigned long long IBCCtrl;
80 unsigned long long ExtStatus;
81 unsigned long long ExtCtrl;
82 unsigned long long GPIOOut;
83 unsigned long long GPIOMask;
84 unsigned long long GPIOStatus;
85 unsigned long long GPIOClear;
86 unsigned long long RcvCtrl;
87 unsigned long long RcvBTHQP;
88 unsigned long long RcvHdrSize;
89 unsigned long long RcvHdrCnt;
90 unsigned long long RcvHdrEntSize;
91 unsigned long long RcvTIDBase;
92 unsigned long long RcvTIDCnt;
93 unsigned long long RcvEgrBase;
94 unsigned long long RcvEgrCnt;
95 unsigned long long RcvBufBase;
96 unsigned long long RcvBufSize;
97 unsigned long long RxIntMemBase;
98 unsigned long long RxIntMemSize;
99 unsigned long long RcvPartitionKey;
100 unsigned long long ReservedRcv[10];
101 unsigned long long SendCtrl;
102 unsigned long long SendPIOBufBase;
103 unsigned long long SendPIOSize;
104 unsigned long long SendPIOBufCnt;
105 unsigned long long SendPIOAvailAddr;
106 unsigned long long TxIntMemBase;
107 unsigned long long TxIntMemSize;
108 unsigned long long ReservedSend[9];
109 unsigned long long SendBufferError;
110 unsigned long long SendBufferErrorCONT1;
111 unsigned long long SendBufferErrorCONT2;
112 unsigned long long SendBufferErrorCONT3;
113 unsigned long long ReservedSBE[4];
114 unsigned long long RcvHdrAddr0;
115 unsigned long long RcvHdrAddr1;
116 unsigned long long RcvHdrAddr2;
117 unsigned long long RcvHdrAddr3;
118 unsigned long long RcvHdrAddr4;
119 unsigned long long RcvHdrAddr5;
120 unsigned long long RcvHdrAddr6;
121 unsigned long long RcvHdrAddr7;
122 unsigned long long RcvHdrAddr8;
123 unsigned long long ReservedRHA[7];
124 unsigned long long RcvHdrTailAddr0;
125 unsigned long long RcvHdrTailAddr1;
126 unsigned long long RcvHdrTailAddr2;
127 unsigned long long RcvHdrTailAddr3;
128 unsigned long long RcvHdrTailAddr4;
129 unsigned long long RcvHdrTailAddr5;
130 unsigned long long RcvHdrTailAddr6;
131 unsigned long long RcvHdrTailAddr7;
132 unsigned long long RcvHdrTailAddr8;
133 unsigned long long ReservedRHTA[7];
134 unsigned long long Sync; /* Software only */
135 unsigned long long Dump; /* Software only */
136 unsigned long long SimVer; /* Software only */
137 unsigned long long ReservedSW[5];
138 unsigned long long SerdesConfig0;
139 unsigned long long SerdesConfig1;
140 unsigned long long SerdesStatus;
141 unsigned long long XGXSConfig;
142 unsigned long long ReservedSW2[4];
143};
144
145#define IPATH_KREG_OFFSET(field) (offsetof(struct \
146 _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
147#define IPATH_CREG_OFFSET(field) (offsetof( \
148 struct infinipath_counters, field) / sizeof(u64))
149
150static const struct ipath_kregs ipath_ht_kregs = {
151 .kr_control = IPATH_KREG_OFFSET(Control),
152 .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
153 .kr_debugport = IPATH_KREG_OFFSET(DebugPort),
154 .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
155 .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
156 .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
157 .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
158 .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
159 .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
160 .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
161 .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
162 .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
163 .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
164 .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
165 .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
166 .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
167 .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
168 .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
169 .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
170 .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
171 .kr_intclear = IPATH_KREG_OFFSET(IntClear),
172 .kr_interruptconfig = IPATH_KREG_OFFSET(InterruptConfig),
173 .kr_intmask = IPATH_KREG_OFFSET(IntMask),
174 .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
175 .kr_mdio = IPATH_KREG_OFFSET(MDIO),
176 .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
177 .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
178 .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
179 .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
180 .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
181 .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
182 .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
183 .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
184 .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
185 .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
186 .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
187 .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
188 .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
189 .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
190 .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
191 .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
192 .kr_revision = IPATH_KREG_OFFSET(Revision),
193 .kr_scratch = IPATH_KREG_OFFSET(Scratch),
194 .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
195 .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
196 .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
197 .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
198 .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
199 .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
200 .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
201 .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
202 .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
203 .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
204 .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
205 .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
206 .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
207 .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
208 /*
209 * These should not be used directly via ipath_read_kreg64(),
210 * use them with ipath_read_kreg64_port(),
211 */
212 .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
213 .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0)
214};
215
216static const struct ipath_cregs ipath_ht_cregs = {
217 .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
218 .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
219 .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
220 .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
221 .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
222 .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
223 .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
224 .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
225 .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
226 .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
227 .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
228 .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
229 /* calc from Reg_CounterRegBase + offset */
230 .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
231 .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
232 .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
233 .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
234 .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
235 .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
236 .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
237 .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
238 .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
239 .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
240 .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
241 .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
242 .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
243 .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
244 .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
245 .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
246 .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
247 .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
248 .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
249 .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
250 .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
251};
252
253/* kr_intstatus, kr_intclear, kr_intmask bits */
254#define INFINIPATH_I_RCVURG_MASK 0x1FF
255#define INFINIPATH_I_RCVAVAIL_MASK 0x1FF
256
257/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
258#define INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT 0
259#define INFINIPATH_HWE_HTCMEMPARITYERR_MASK 0x3FFFFFULL
260#define INFINIPATH_HWE_HTCLNKABYTE0CRCERR 0x0000000000800000ULL
261#define INFINIPATH_HWE_HTCLNKABYTE1CRCERR 0x0000000001000000ULL
262#define INFINIPATH_HWE_HTCLNKBBYTE0CRCERR 0x0000000002000000ULL
263#define INFINIPATH_HWE_HTCLNKBBYTE1CRCERR 0x0000000004000000ULL
264#define INFINIPATH_HWE_HTCMISCERR4 0x0000000008000000ULL
265#define INFINIPATH_HWE_HTCMISCERR5 0x0000000010000000ULL
266#define INFINIPATH_HWE_HTCMISCERR6 0x0000000020000000ULL
267#define INFINIPATH_HWE_HTCMISCERR7 0x0000000040000000ULL
268#define INFINIPATH_HWE_HTCBUSTREQPARITYERR 0x0000000080000000ULL
269#define INFINIPATH_HWE_HTCBUSTRESPPARITYERR 0x0000000100000000ULL
270#define INFINIPATH_HWE_HTCBUSIREQPARITYERR 0x0000000200000000ULL
271#define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
272#define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
273#define INFINIPATH_HWE_HTBPLL_FBSLIP 0x0200000000000000ULL
274#define INFINIPATH_HWE_HTBPLL_RFSLIP 0x0400000000000000ULL
275#define INFINIPATH_HWE_HTAPLL_FBSLIP 0x0800000000000000ULL
276#define INFINIPATH_HWE_HTAPLL_RFSLIP 0x1000000000000000ULL
277#define INFINIPATH_HWE_SERDESPLLFAILED 0x2000000000000000ULL
278
279/* kr_extstatus bits */
280#define INFINIPATH_EXTS_FREQSEL 0x2
281#define INFINIPATH_EXTS_SERDESSEL 0x4
282#define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
283#define INFINIPATH_EXTS_MEMBIST_CORRECT 0x0000000000008000
284
285/*
286 * masks and bits that are different in different chips, or present only
287 * in one
288 */
289static const ipath_err_t infinipath_hwe_htcmemparityerr_mask =
290 INFINIPATH_HWE_HTCMEMPARITYERR_MASK;
291static const ipath_err_t infinipath_hwe_htcmemparityerr_shift =
292 INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT;
293
294static const ipath_err_t infinipath_hwe_htclnkabyte0crcerr =
295 INFINIPATH_HWE_HTCLNKABYTE0CRCERR;
296static const ipath_err_t infinipath_hwe_htclnkabyte1crcerr =
297 INFINIPATH_HWE_HTCLNKABYTE1CRCERR;
298static const ipath_err_t infinipath_hwe_htclnkbbyte0crcerr =
299 INFINIPATH_HWE_HTCLNKBBYTE0CRCERR;
300static const ipath_err_t infinipath_hwe_htclnkbbyte1crcerr =
301 INFINIPATH_HWE_HTCLNKBBYTE1CRCERR;
302
303#define _IPATH_GPIO_SDA_NUM 1
304#define _IPATH_GPIO_SCL_NUM 0
305
306#define IPATH_GPIO_SDA \
307 (1ULL << (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
308#define IPATH_GPIO_SCL \
309 (1ULL << (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
310
311/* keep the code below somewhat more readonable; not used elsewhere */
312#define _IPATH_HTLINK0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
313 infinipath_hwe_htclnkabyte1crcerr)
314#define _IPATH_HTLINK1_CRCBITS (infinipath_hwe_htclnkbbyte0crcerr | \
315 infinipath_hwe_htclnkbbyte1crcerr)
316#define _IPATH_HTLANE0_CRCBITS (infinipath_hwe_htclnkabyte0crcerr | \
317 infinipath_hwe_htclnkbbyte0crcerr)
318#define _IPATH_HTLANE1_CRCBITS (infinipath_hwe_htclnkabyte1crcerr | \
319 infinipath_hwe_htclnkbbyte1crcerr)
320
321static void hwerr_crcbits(struct ipath_devdata *dd, ipath_err_t hwerrs,
322 char *msg, size_t msgl)
323{
324 char bitsmsg[64];
325 ipath_err_t crcbits = hwerrs &
326 (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS);
327 /* don't check if 8bit HT */
328 if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
329 crcbits &= ~infinipath_hwe_htclnkabyte1crcerr;
330 /* don't check if 8bit HT */
331 if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
332 crcbits &= ~infinipath_hwe_htclnkbbyte1crcerr;
333 /*
334 * we'll want to ignore link errors on link that is
335 * not in use, if any. For now, complain about both
336 */
337 if (crcbits) {
338 u16 ctrl0, ctrl1;
339 snprintf(bitsmsg, sizeof bitsmsg,
340 "[HT%s lane %s CRC (%llx); ignore till reload]",
341 !(crcbits & _IPATH_HTLINK1_CRCBITS) ?
342 "0 (A)" : (!(crcbits & _IPATH_HTLINK0_CRCBITS)
343 ? "1 (B)" : "0+1 (A+B)"),
344 !(crcbits & _IPATH_HTLANE1_CRCBITS) ? "0"
345 : (!(crcbits & _IPATH_HTLANE0_CRCBITS) ? "1" :
346 "0+1"), (unsigned long long) crcbits);
347 strlcat(msg, bitsmsg, msgl);
348
349 /*
350 * print extra info for debugging. slave/primary
351 * config word 4, 8 (link control 0, 1)
352 */
353
354 if (pci_read_config_word(dd->pcidev,
355 dd->ipath_ht_slave_off + 0x4,
356 &ctrl0))
357 dev_info(&dd->pcidev->dev, "Couldn't read "
358 "linkctrl0 of slave/primary "
359 "config block\n");
360 else if (!(ctrl0 & 1 << 6))
361 /* not if EOC bit set */
362 ipath_dbg("HT linkctrl0 0x%x%s%s\n", ctrl0,
363 ((ctrl0 >> 8) & 7) ? " CRC" : "",
364 ((ctrl0 >> 4) & 1) ? "linkfail" :
365 "");
366 if (pci_read_config_word(dd->pcidev,
367 dd->ipath_ht_slave_off + 0x8,
368 &ctrl1))
369 dev_info(&dd->pcidev->dev, "Couldn't read "
370 "linkctrl1 of slave/primary "
371 "config block\n");
372 else if (!(ctrl1 & 1 << 6))
373 /* not if EOC bit set */
374 ipath_dbg("HT linkctrl1 0x%x%s%s\n", ctrl1,
375 ((ctrl1 >> 8) & 7) ? " CRC" : "",
376 ((ctrl1 >> 4) & 1) ? "linkfail" :
377 "");
378
379 /* disable until driver reloaded */
380 dd->ipath_hwerrmask &= ~crcbits;
381 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
382 dd->ipath_hwerrmask);
383 ipath_dbg("HT crc errs: %s\n", msg);
384 } else
385 ipath_dbg("ignoring HT crc errors 0x%llx, "
386 "not in use\n", (unsigned long long)
387 (hwerrs & (_IPATH_HTLINK0_CRCBITS |
388 _IPATH_HTLINK1_CRCBITS)));
389}
390
391/**
392 * ipath_ht_handle_hwerrors - display hardware errors
393 * @dd: the infinipath device
394 * @msg: the output buffer
395 * @msgl: the size of the output buffer
396 *
397 * Use same msg buffer as regular errors to avoid
398 * excessive stack use. Most hardware errors are catastrophic, but for
399 * right now, we'll print them and continue.
400 * We reuse the same message buffer as ipath_handle_errors() to avoid
401 * excessive stack usage.
402 */
403static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
404 size_t msgl)
405{
406 ipath_err_t hwerrs;
407 u32 bits, ctrl;
408 int isfatal = 0;
409 char bitsmsg[64];
410
411 hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
412
413 if (!hwerrs) {
414 ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
415 /*
416 * better than printing cofusing messages
417 * This seems to be related to clearing the crc error, or
418 * the pll error during init.
419 */
420 goto bail;
421 } else if (hwerrs == -1LL) {
422 ipath_dev_err(dd, "Read of hardware error status failed "
423 "(all bits set); ignoring\n");
424 goto bail;
425 }
426 ipath_stats.sps_hwerrs++;
427
428 /* Always clear the error status register, except MEMBISTFAIL,
429 * regardless of whether we continue or stop using the chip.
430 * We want that set so we know it failed, even across driver reload.
431 * We'll still ignore it in the hwerrmask. We do this partly for
432 * diagnostics, but also for support */
433 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
434 hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
435
436 hwerrs &= dd->ipath_hwerrmask;
437
438 /*
439 * make sure we get this much out, unless told to be quiet,
440 * or it's occurred within the last 5 seconds
441 */
442 if ((hwerrs & ~dd->ipath_lasthwerror) ||
443 (ipath_debug & __IPATH_VERBDBG))
444 dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
445 "(cleared)\n", (unsigned long long) hwerrs);
446 dd->ipath_lasthwerror |= hwerrs;
447
448 if (hwerrs & ~infinipath_hwe_bitsextant)
449 ipath_dev_err(dd, "hwerror interrupt with unknown errors "
450 "%llx set\n", (unsigned long long)
451 (hwerrs & ~infinipath_hwe_bitsextant));
452
453 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
454 if (ctrl & INFINIPATH_C_FREEZEMODE) {
455 if (hwerrs) {
456 /*
457 * if any set that we aren't ignoring; only
458 * make the complaint once, in case it's stuck
459 * or recurring, and we get here multiple
460 * times.
461 */
462 if (dd->ipath_flags & IPATH_INITTED) {
463 ipath_dev_err(dd, "Fatal Error (freeze "
464 "mode), no longer usable\n");
465 isfatal = 1;
466 }
467 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
468 /* mark as having had error */
469 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
470 /*
471 * mark as not usable, at a minimum until driver
472 * is reloaded, probably until reboot, since no
473 * other reset is possible.
474 */
475 dd->ipath_flags &= ~IPATH_INITTED;
476 } else {
477 ipath_dbg("Clearing freezemode on ignored hardware "
478 "error\n");
479 ctrl &= ~INFINIPATH_C_FREEZEMODE;
480 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
481 ctrl);
482 }
483 }
484
485 *msg = '\0';
486
487 /*
488 * may someday want to decode into which bits are which
489 * functional area for parity errors, etc.
490 */
491 if (hwerrs & (infinipath_hwe_htcmemparityerr_mask
492 << INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT)) {
493 bits = (u32) ((hwerrs >>
494 INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) &
495 INFINIPATH_HWE_HTCMEMPARITYERR_MASK);
496 snprintf(bitsmsg, sizeof bitsmsg, "[HTC Parity Errs %x] ",
497 bits);
498 strlcat(msg, bitsmsg, msgl);
499 }
500 if (hwerrs & (INFINIPATH_HWE_RXEMEMPARITYERR_MASK
501 << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)) {
502 bits = (u32) ((hwerrs >>
503 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) &
504 INFINIPATH_HWE_RXEMEMPARITYERR_MASK);
505 snprintf(bitsmsg, sizeof bitsmsg, "[RXE Parity Errs %x] ",
506 bits);
507 strlcat(msg, bitsmsg, msgl);
508 }
509 if (hwerrs & (INFINIPATH_HWE_TXEMEMPARITYERR_MASK
510 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
511 bits = (u32) ((hwerrs >>
512 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) &
513 INFINIPATH_HWE_TXEMEMPARITYERR_MASK);
514 snprintf(bitsmsg, sizeof bitsmsg, "[TXE Parity Errs %x] ",
515 bits);
516 strlcat(msg, bitsmsg, msgl);
517 }
518 if (hwerrs & INFINIPATH_HWE_IBCBUSTOSPCPARITYERR)
519 strlcat(msg, "[IB2IPATH Parity]", msgl);
520 if (hwerrs & INFINIPATH_HWE_IBCBUSFRSPCPARITYERR)
521 strlcat(msg, "[IPATH2IB Parity]", msgl);
522 if (hwerrs & INFINIPATH_HWE_HTCBUSIREQPARITYERR)
523 strlcat(msg, "[HTC Ireq Parity]", msgl);
524 if (hwerrs & INFINIPATH_HWE_HTCBUSTREQPARITYERR)
525 strlcat(msg, "[HTC Treq Parity]", msgl);
526 if (hwerrs & INFINIPATH_HWE_HTCBUSTRESPPARITYERR)
527 strlcat(msg, "[HTC Tresp Parity]", msgl);
528
529 if (hwerrs & (_IPATH_HTLINK0_CRCBITS | _IPATH_HTLINK1_CRCBITS))
530 hwerr_crcbits(dd, hwerrs, msg, msgl);
531
532 if (hwerrs & INFINIPATH_HWE_HTCMISCERR5)
533 strlcat(msg, "[HT core Misc5]", msgl);
534 if (hwerrs & INFINIPATH_HWE_HTCMISCERR6)
535 strlcat(msg, "[HT core Misc6]", msgl);
536 if (hwerrs & INFINIPATH_HWE_HTCMISCERR7)
537 strlcat(msg, "[HT core Misc7]", msgl);
538 if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
539 strlcat(msg, "[Memory BIST test failed, HT-400 unusable]",
540 msgl);
541 /* ignore from now on, so disable until driver reloaded */
542 dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
543 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
544 dd->ipath_hwerrmask);
545 }
546#define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
547 INFINIPATH_HWE_COREPLL_RFSLIP | \
548 INFINIPATH_HWE_HTBPLL_FBSLIP | \
549 INFINIPATH_HWE_HTBPLL_RFSLIP | \
550 INFINIPATH_HWE_HTAPLL_FBSLIP | \
551 INFINIPATH_HWE_HTAPLL_RFSLIP)
552
553 if (hwerrs & _IPATH_PLL_FAIL) {
554 snprintf(bitsmsg, sizeof bitsmsg,
555 "[PLL failed (%llx), HT-400 unusable]",
556 (unsigned long long) (hwerrs & _IPATH_PLL_FAIL));
557 strlcat(msg, bitsmsg, msgl);
558 /* ignore from now on, so disable until driver reloaded */
559 dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
560 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
561 dd->ipath_hwerrmask);
562 }
563
564 if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
565 /*
566 * If it occurs, it is left masked since the eternal
567 * interface is unused
568 */
569 dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
570 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
571 dd->ipath_hwerrmask);
572 }
573
574 if (hwerrs & INFINIPATH_HWE_RXDSYNCMEMPARITYERR)
575 strlcat(msg, "[Rx Dsync]", msgl);
576 if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED)
577 strlcat(msg, "[SerDes PLL]", msgl);
578
579 ipath_dev_err(dd, "%s hardware error\n", msg);
580 if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
581 /*
582 * for status file; if no trailing brace is copied,
583 * we'll know it was truncated.
584 */
585 snprintf(dd->ipath_freezemsg,
586 dd->ipath_freezelen, "{%s}", msg);
587
588bail:;
589}
590
591/**
592 * ipath_ht_boardname - fill in the board name
593 * @dd: the infinipath device
594 * @name: the output buffer
595 * @namelen: the size of the output buffer
596 *
597 * fill in the board name, based on the board revision register
598 */
599static int ipath_ht_boardname(struct ipath_devdata *dd, char *name,
600 size_t namelen)
601{
602 char *n = NULL;
603 u8 boardrev = dd->ipath_boardrev;
604 int ret;
605
606 switch (boardrev) {
607 case 4: /* Ponderosa is one of the bringup boards */
608 n = "Ponderosa";
609 break;
610 case 5: /* HT-460 original production board */
611 n = "InfiniPath_HT-460";
612 break;
613 case 6:
614 n = "OEM_Board_3";
615 break;
616 case 7:
617 /* HT-460 small form factor production board */
618 n = "InfiniPath_HT-465";
619 break;
620 case 8:
621 n = "LS/X-1";
622 break;
623 case 9: /* Comstock bringup test board */
624 n = "Comstock";
625 break;
626 case 10:
627 n = "OEM_Board_2";
628 break;
629 case 11:
630 n = "InfiniPath_HT-470";
631 break;
632 case 12:
633 n = "OEM_Board_4";
634 break;
635 default: /* don't know, just print the number */
636 ipath_dev_err(dd, "Don't yet know about board "
637 "with ID %u\n", boardrev);
638 snprintf(name, namelen, "Unknown_InfiniPath_HT-4xx_%u",
639 boardrev);
640 break;
641 }
642 if (n)
643 snprintf(name, namelen, "%s", n);
644
645 if (dd->ipath_majrev != 3 || dd->ipath_minrev != 2) {
646 /*
647 * This version of the driver only supports the HT-400
648 * Rev 3.2
649 */
650 ipath_dev_err(dd,
651 "Unsupported HT-400 revision %u.%u!\n",
652 dd->ipath_majrev, dd->ipath_minrev);
653 ret = 1;
654 goto bail;
655 }
656 /*
657 * pkt/word counters are 32 bit, and therefore wrap fast enough
658 * that we snapshot them from a timer, and maintain 64 bit shadow
659 * copies
660 */
661 dd->ipath_flags |= IPATH_32BITCOUNTERS;
662 if (dd->ipath_htspeed != 800)
663 ipath_dev_err(dd,
664 "Incorrectly configured for HT @ %uMHz\n",
665 dd->ipath_htspeed);
666 if (dd->ipath_boardrev == 7 || dd->ipath_boardrev == 11 ||
667 dd->ipath_boardrev == 6)
668 dd->ipath_flags |= IPATH_GPIO_INTR;
669 else
670 dd->ipath_flags |= IPATH_POLL_RX_INTR;
671 if (dd->ipath_boardrev == 8) { /* LS/X-1 */
672 u64 val;
673 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
674 if (val & INFINIPATH_EXTS_SERDESSEL) {
675 /*
676 * hardware disabled
677 *
678 * This means that the chip is hardware disabled,
679 * and will not be able to bring up the link,
680 * in any case. We special case this and abort
681 * early, to avoid later messages. We also set
682 * the DISABLED status bit
683 */
684 ipath_dbg("Unit %u is hardware-disabled\n",
685 dd->ipath_unit);
686 *dd->ipath_statusp |= IPATH_STATUS_DISABLED;
687 /* this value is handled differently */
688 ret = 2;
689 goto bail;
690 }
691 }
692 ret = 0;
693
694bail:
695 return ret;
696}
697
698static void ipath_check_htlink(struct ipath_devdata *dd)
699{
700 u8 linkerr, link_off, i;
701
702 for (i = 0; i < 2; i++) {
703 link_off = dd->ipath_ht_slave_off + i * 4 + 0xd;
704 if (pci_read_config_byte(dd->pcidev, link_off, &linkerr))
705 dev_info(&dd->pcidev->dev, "Couldn't read "
706 "linkerror%d of HT slave/primary block\n",
707 i);
708 else if (linkerr & 0xf0) {
709 ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
710 "clearing\n", linkerr >> 4, i);
711 /*
712 * writing the linkerr bits that are set should
713 * clear them
714 */
715 if (pci_write_config_byte(dd->pcidev, link_off,
716 linkerr))
717 ipath_dbg("Failed write to clear HT "
718 "linkerror%d\n", i);
719 if (pci_read_config_byte(dd->pcidev, link_off,
720 &linkerr))
721 dev_info(&dd->pcidev->dev,
722 "Couldn't reread linkerror%d of "
723 "HT slave/primary block\n", i);
724 else if (linkerr & 0xf0)
725 dev_info(&dd->pcidev->dev,
726 "HT linkerror%d bits 0x%x "
727 "couldn't be cleared\n",
728 i, linkerr >> 4);
729 }
730 }
731}
732
733static int ipath_setup_ht_reset(struct ipath_devdata *dd)
734{
735 ipath_dbg("No reset possible for HT-400\n");
736 return 0;
737}
738
739#define HT_CAPABILITY_ID 0x08 /* HT capabilities not defined in kernel */
740#define HT_INTR_DISC_CONFIG 0x80 /* HT interrupt and discovery cap */
741#define HT_INTR_REG_INDEX 2 /* intconfig requires indirect accesses */
742
743/*
744 * Bits 13-15 of command==0 is slave/primary block. Clear any HT CRC
745 * errors. We only bother to do this at load time, because it's OK if
746 * it happened before we were loaded (first time after boot/reset),
747 * but any time after that, it's fatal anyway. Also need to not check
748 * for for upper byte errors if we are in 8 bit mode, so figure out
749 * our width. For now, at least, also complain if it's 8 bit.
750 */
751static void slave_or_pri_blk(struct ipath_devdata *dd, struct pci_dev *pdev,
752 int pos, u8 cap_type)
753{
754 u8 linkwidth = 0, linkerr, link_a_b_off, link_off;
755 u16 linkctrl = 0;
756 int i;
757
758 dd->ipath_ht_slave_off = pos;
759 /* command word, master_host bit */
760 /* master host || slave */
761 if ((cap_type >> 2) & 1)
762 link_a_b_off = 4;
763 else
764 link_a_b_off = 0;
765 ipath_cdbg(VERBOSE, "HT%u (Link %c) connected to processor\n",
766 link_a_b_off ? 1 : 0,
767 link_a_b_off ? 'B' : 'A');
768
769 link_a_b_off += pos;
770
771 /*
772 * check both link control registers; clear both HT CRC sets if
773 * necessary.
774 */
775 for (i = 0; i < 2; i++) {
776 link_off = pos + i * 4 + 0x4;
777 if (pci_read_config_word(pdev, link_off, &linkctrl))
778 ipath_dev_err(dd, "Couldn't read HT link control%d "
779 "register\n", i);
780 else if (linkctrl & (0xf << 8)) {
781 ipath_cdbg(VERBOSE, "Clear linkctrl%d CRC Error "
782 "bits %x\n", i, linkctrl & (0xf << 8));
783 /*
784 * now write them back to clear the error.
785 */
786 pci_write_config_byte(pdev, link_off,
787 linkctrl & (0xf << 8));
788 }
789 }
790
791 /*
792 * As with HT CRC bits, same for protocol errors that might occur
793 * during boot.
794 */
795 for (i = 0; i < 2; i++) {
796 link_off = pos + i * 4 + 0xd;
797 if (pci_read_config_byte(pdev, link_off, &linkerr))
798 dev_info(&pdev->dev, "Couldn't read linkerror%d "
799 "of HT slave/primary block\n", i);
800 else if (linkerr & 0xf0) {
801 ipath_cdbg(VERBOSE, "HT linkerr%d bits 0x%x set, "
802 "clearing\n", linkerr >> 4, i);
803 /*
804 * writing the linkerr bits that are set will clear
805 * them
806 */
807 if (pci_write_config_byte
808 (pdev, link_off, linkerr))
809 ipath_dbg("Failed write to clear HT "
810 "linkerror%d\n", i);
811 if (pci_read_config_byte(pdev, link_off, &linkerr))
812 dev_info(&pdev->dev, "Couldn't reread "
813 "linkerror%d of HT slave/primary "
814 "block\n", i);
815 else if (linkerr & 0xf0)
816 dev_info(&pdev->dev, "HT linkerror%d bits "
817 "0x%x couldn't be cleared\n",
818 i, linkerr >> 4);
819 }
820 }
821
822 /*
823 * this is just for our link to the host, not devices connected
824 * through tunnel.
825 */
826
827 if (pci_read_config_byte(pdev, link_a_b_off + 7, &linkwidth))
828 ipath_dev_err(dd, "Couldn't read HT link width "
829 "config register\n");
830 else {
831 u32 width;
832 switch (linkwidth & 7) {
833 case 5:
834 width = 4;
835 break;
836 case 4:
837 width = 2;
838 break;
839 case 3:
840 width = 32;
841 break;
842 case 1:
843 width = 16;
844 break;
845 case 0:
846 default: /* if wrong, assume 8 bit */
847 width = 8;
848 break;
849 }
850
851 dd->ipath_htwidth = width;
852
853 if (linkwidth != 0x11) {
854 ipath_dev_err(dd, "Not configured for 16 bit HT "
855 "(%x)\n", linkwidth);
856 if (!(linkwidth & 0xf)) {
857 ipath_dbg("Will ignore HT lane1 errors\n");
858 dd->ipath_flags |= IPATH_8BIT_IN_HT0;
859 }
860 }
861 }
862
863 /*
864 * this is just for our link to the host, not devices connected
865 * through tunnel.
866 */
867 if (pci_read_config_byte(pdev, link_a_b_off + 0xd, &linkwidth))
868 ipath_dev_err(dd, "Couldn't read HT link frequency "
869 "config register\n");
870 else {
871 u32 speed;
872 switch (linkwidth & 0xf) {
873 case 6:
874 speed = 1000;
875 break;
876 case 5:
877 speed = 800;
878 break;
879 case 4:
880 speed = 600;
881 break;
882 case 3:
883 speed = 500;
884 break;
885 case 2:
886 speed = 400;
887 break;
888 case 1:
889 speed = 300;
890 break;
891 default:
892 /*
893 * assume reserved and vendor-specific are 200...
894 */
895 case 0:
896 speed = 200;
897 break;
898 }
899 dd->ipath_htspeed = speed;
900 }
901}
902
903static int set_int_handler(struct ipath_devdata *dd, struct pci_dev *pdev,
904 int pos)
905{
906 u32 int_handler_addr_lower;
907 u32 int_handler_addr_upper;
908 u64 ihandler;
909 u32 intvec;
910
911 /* use indirection register to get the intr handler */
912 pci_write_config_byte(pdev, pos + HT_INTR_REG_INDEX, 0x10);
913 pci_read_config_dword(pdev, pos + 4, &int_handler_addr_lower);
914 pci_write_config_byte(pdev, pos + HT_INTR_REG_INDEX, 0x11);
915 pci_read_config_dword(pdev, pos + 4, &int_handler_addr_upper);
916
917 ihandler = (u64) int_handler_addr_lower |
918 ((u64) int_handler_addr_upper << 32);
919
920 /*
921 * kernels with CONFIG_PCI_MSI set the vector in the irq field of
922 * struct pci_device, so we use that to program the HT-400 internal
923 * interrupt register (not config space) with that value. The BIOS
924 * must still have done the basic MSI setup.
925 */
926 intvec = pdev->irq;
927 /*
928 * clear any vector bits there; normally not set but we'll overload
929 * this for some debug purposes (setting the HTC debug register
930 * value from software, rather than GPIOs), so it might be set on a
931 * driver reload.
932 */
933 ihandler &= ~0xff0000;
934 /* x86 vector goes in intrinfo[23:16] */
935 ihandler |= intvec << 16;
936 ipath_cdbg(VERBOSE, "ihandler lower %x, upper %x, intvec %x, "
937 "interruptconfig %llx\n", int_handler_addr_lower,
938 int_handler_addr_upper, intvec,
939 (unsigned long long) ihandler);
940
941 /* can't program yet, so save for interrupt setup */
942 dd->ipath_intconfig = ihandler;
943 /* keep going, so we find link control stuff also */
944
945 return ihandler != 0;
946}
947
948/**
949 * ipath_setup_ht_config - setup the interruptconfig register
950 * @dd: the infinipath device
951 * @pdev: the PCI device
952 *
953 * setup the interruptconfig register from the HT config info.
954 * Also clear CRC errors in HT linkcontrol, if necessary.
955 * This is done only for the real hardware. It is done before
956 * chip address space is initted, so can't touch infinipath registers
957 */
958static int ipath_setup_ht_config(struct ipath_devdata *dd,
959 struct pci_dev *pdev)
960{
961 int pos, ret = 0;
962 int ihandler = 0;
963
964 /*
965 * Read the capability info to find the interrupt info, and also
966 * handle clearing CRC errors in linkctrl register if necessary. We
967 * do this early, before we ever enable errors or hardware errors,
968 * mostly to avoid causing the chip to enter freeze mode.
969 */
970 pos = pci_find_capability(pdev, HT_CAPABILITY_ID);
971 if (!pos) {
972 ipath_dev_err(dd, "Couldn't find HyperTransport "
973 "capability; no interrupts\n");
974 ret = -ENODEV;
975 goto bail;
976 }
977 do {
978 u8 cap_type;
979
980 /* the HT capability type byte is 3 bytes after the
981 * capability byte.
982 */
983 if (pci_read_config_byte(pdev, pos + 3, &cap_type)) {
984 dev_info(&pdev->dev, "Couldn't read config "
985 "command @ %d\n", pos);
986 continue;
987 }
988 if (!(cap_type & 0xE0))
989 slave_or_pri_blk(dd, pdev, pos, cap_type);
990 else if (cap_type == HT_INTR_DISC_CONFIG)
991 ihandler = set_int_handler(dd, pdev, pos);
992 } while ((pos = pci_find_next_capability(pdev, pos,
993 HT_CAPABILITY_ID)));
994
995 if (!ihandler) {
996 ipath_dev_err(dd, "Couldn't find interrupt handler in "
997 "config space\n");
998 ret = -ENODEV;
999 }
1000
1001bail:
1002 return ret;
1003}
1004
1005/**
1006 * ipath_setup_ht_cleanup - clean up any per-chip chip-specific stuff
1007 * @dd: the infinipath device
1008 *
1009 * Called during driver unload.
1010 * This is currently a nop for the HT-400, not for all chips
1011 */
1012static void ipath_setup_ht_cleanup(struct ipath_devdata *dd)
1013{
1014}
1015
1016/**
1017 * ipath_setup_ht_setextled - set the state of the two external LEDs
1018 * @dd: the infinipath device
1019 * @lst: the L state
1020 * @ltst: the LT state
1021 *
1022 * Set the state of the two external LEDs, to indicate physical and
1023 * logical state of IB link. For this chip (at least with recommended
1024 * board pinouts), LED1 is Green (physical state), and LED2 is Yellow
1025 * (logical state)
1026 *
1027 * Note: We try to match the Mellanox HCA LED behavior as best
1028 * we can. Green indicates physical link state is OK (something is
1029 * plugged in, and we can train).
1030 * Amber indicates the link is logically up (ACTIVE).
1031 * Mellanox further blinks the amber LED to indicate data packet
1032 * activity, but we have no hardware support for that, so it would
1033 * require waking up every 10-20 msecs and checking the counters
1034 * on the chip, and then turning the LED off if appropriate. That's
1035 * visible overhead, so not something we will do.
1036 *
1037 */
1038static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
1039 u64 lst, u64 ltst)
1040{
1041 u64 extctl;
1042
1043 /* the diags use the LED to indicate diag info, so we leave
1044 * the external LED alone when the diags are running */
1045 if (ipath_diag_inuse)
1046 return;
1047
1048 /*
1049 * start by setting both LED control bits to off, then turn
1050 * on the appropriate bit(s).
1051 */
1052 if (dd->ipath_boardrev == 8) { /* LS/X-1 uses different pins */
1053 /*
1054 * major difference is that INFINIPATH_EXTC_LEDGBLERR_OFF
1055 * is inverted, because it is normally used to indicate
1056 * a hardware fault at reset, if there were errors
1057 */
1058 extctl = (dd->ipath_extctrl & ~INFINIPATH_EXTC_LEDGBLOK_ON)
1059 | INFINIPATH_EXTC_LEDGBLERR_OFF;
1060 if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
1061 extctl &= ~INFINIPATH_EXTC_LEDGBLERR_OFF;
1062 if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
1063 extctl |= INFINIPATH_EXTC_LEDGBLOK_ON;
1064 }
1065 else {
1066 extctl = dd->ipath_extctrl &
1067 ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
1068 INFINIPATH_EXTC_LED2PRIPORT_ON);
1069 if (ltst == INFINIPATH_IBCS_LT_STATE_LINKUP)
1070 extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
1071 if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
1072 extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
1073 }
1074 dd->ipath_extctrl = extctl;
1075 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
1076}
1077
1078static void ipath_init_ht_variables(void)
1079{
1080 ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
1081 ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
1082 ipath_gpio_sda = IPATH_GPIO_SDA;
1083 ipath_gpio_scl = IPATH_GPIO_SCL;
1084
1085 infinipath_i_bitsextant =
1086 (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
1087 (INFINIPATH_I_RCVAVAIL_MASK <<
1088 INFINIPATH_I_RCVAVAIL_SHIFT) |
1089 INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
1090 INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
1091
1092 infinipath_e_bitsextant =
1093 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
1094 INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
1095 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
1096 INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
1097 INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
1098 INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
1099 INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
1100 INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
1101 INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
1102 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
1103 INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
1104 INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
1105 INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
1106 INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
1107 INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
1108 INFINIPATH_E_HARDWARE;
1109
1110 infinipath_hwe_bitsextant =
1111 (INFINIPATH_HWE_HTCMEMPARITYERR_MASK <<
1112 INFINIPATH_HWE_HTCMEMPARITYERR_SHIFT) |
1113 (INFINIPATH_HWE_TXEMEMPARITYERR_MASK <<
1114 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) |
1115 (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
1116 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
1117 INFINIPATH_HWE_HTCLNKABYTE0CRCERR |
1118 INFINIPATH_HWE_HTCLNKABYTE1CRCERR |
1119 INFINIPATH_HWE_HTCLNKBBYTE0CRCERR |
1120 INFINIPATH_HWE_HTCLNKBBYTE1CRCERR |
1121 INFINIPATH_HWE_HTCMISCERR4 |
1122 INFINIPATH_HWE_HTCMISCERR5 | INFINIPATH_HWE_HTCMISCERR6 |
1123 INFINIPATH_HWE_HTCMISCERR7 |
1124 INFINIPATH_HWE_HTCBUSTREQPARITYERR |
1125 INFINIPATH_HWE_HTCBUSTRESPPARITYERR |
1126 INFINIPATH_HWE_HTCBUSIREQPARITYERR |
1127 INFINIPATH_HWE_RXDSYNCMEMPARITYERR |
1128 INFINIPATH_HWE_MEMBISTFAILED |
1129 INFINIPATH_HWE_COREPLL_FBSLIP |
1130 INFINIPATH_HWE_COREPLL_RFSLIP |
1131 INFINIPATH_HWE_HTBPLL_FBSLIP |
1132 INFINIPATH_HWE_HTBPLL_RFSLIP |
1133 INFINIPATH_HWE_HTAPLL_FBSLIP |
1134 INFINIPATH_HWE_HTAPLL_RFSLIP |
1135 INFINIPATH_HWE_SERDESPLLFAILED |
1136 INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
1137 INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
1138
1139 infinipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
1140 infinipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
1141}
1142
1143/**
1144 * ipath_ht_init_hwerrors - enable hardware errors
1145 * @dd: the infinipath device
1146 *
1147 * now that we have finished initializing everything that might reasonably
1148 * cause a hardware error, and cleared those errors bits as they occur,
1149 * we can enable hardware errors in the mask (potentially enabling
1150 * freeze mode), and enable hardware errors as errors (along with
1151 * everything else) in errormask
1152 */
1153static void ipath_ht_init_hwerrors(struct ipath_devdata *dd)
1154{
1155 ipath_err_t val;
1156 u64 extsval;
1157
1158 extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
1159
1160 if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
1161 ipath_dev_err(dd, "MemBIST did not complete!\n");
1162
1163 ipath_check_htlink(dd);
1164
1165 /* barring bugs, all hwerrors become interrupts, which can */
1166 val = -1LL;
1167 /* don't look at crc lane1 if 8 bit */
1168 if (dd->ipath_flags & IPATH_8BIT_IN_HT0)
1169 val &= ~infinipath_hwe_htclnkabyte1crcerr;
1170 /* don't look at crc lane1 if 8 bit */
1171 if (dd->ipath_flags & IPATH_8BIT_IN_HT1)
1172 val &= ~infinipath_hwe_htclnkbbyte1crcerr;
1173
1174 /*
1175 * disable RXDSYNCMEMPARITY because external serdes is unused,
1176 * and therefore the logic will never be used or initialized,
1177 * and uninitialized state will normally result in this error
1178 * being asserted. Similarly for the external serdess pll
1179 * lock signal.
1180 */
1181 val &= ~(INFINIPATH_HWE_SERDESPLLFAILED |
1182 INFINIPATH_HWE_RXDSYNCMEMPARITYERR);
1183
1184 /*
1185 * Disable MISCERR4 because of an inversion in the HT core
1186 * logic checking for errors that cause this bit to be set.
1187 * The errata can also cause the protocol error bit to be set
1188 * in the HT config space linkerror register(s).
1189 */
1190 val &= ~INFINIPATH_HWE_HTCMISCERR4;
1191
1192 /*
1193 * PLL ignored because MDIO interface has a logic problem
1194 * for reads, on Comstock and Ponderosa. BRINGUP
1195 */
1196 if (dd->ipath_boardrev == 4 || dd->ipath_boardrev == 9)
1197 val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
1198 dd->ipath_hwerrmask = val;
1199}
1200
1201/**
1202 * ipath_ht_bringup_serdes - bring up the serdes
1203 * @dd: the infinipath device
1204 */
1205static int ipath_ht_bringup_serdes(struct ipath_devdata *dd)
1206{
1207 u64 val, config1;
1208 int ret = 0, change = 0;
1209
1210 ipath_dbg("Trying to bringup serdes\n");
1211
1212 if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
1213 INFINIPATH_HWE_SERDESPLLFAILED)
1214 {
1215 ipath_dbg("At start, serdes PLL failed bit set in "
1216 "hwerrstatus, clearing and continuing\n");
1217 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
1218 INFINIPATH_HWE_SERDESPLLFAILED);
1219 }
1220
1221 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
1222 config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
1223
1224 ipath_cdbg(VERBOSE, "Initial serdes status is config0=%llx "
1225 "config1=%llx, sstatus=%llx xgxs %llx\n",
1226 (unsigned long long) val, (unsigned long long) config1,
1227 (unsigned long long)
1228 ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
1229 (unsigned long long)
1230 ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
1231
1232 /* force reset on */
1233 val |= INFINIPATH_SERDC0_RESET_PLL
1234 /* | INFINIPATH_SERDC0_RESET_MASK */
1235 ;
1236 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
1237 udelay(15); /* need pll reset set at least for a bit */
1238
1239 if (val & INFINIPATH_SERDC0_RESET_PLL) {
1240 u64 val2 = val &= ~INFINIPATH_SERDC0_RESET_PLL;
1241 /* set lane resets, and tx idle, during pll reset */
1242 val2 |= INFINIPATH_SERDC0_RESET_MASK |
1243 INFINIPATH_SERDC0_TXIDLE;
1244 ipath_cdbg(VERBOSE, "Clearing serdes PLL reset (writing "
1245 "%llx)\n", (unsigned long long) val2);
1246 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
1247 val2);
1248 /*
1249 * be sure chip saw it
1250 */
1251 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
1252 /*
1253 * need pll reset clear at least 11 usec before lane
1254 * resets cleared; give it a few more
1255 */
1256 udelay(15);
1257 val = val2; /* for check below */
1258 }
1259
1260 if (val & (INFINIPATH_SERDC0_RESET_PLL |
1261 INFINIPATH_SERDC0_RESET_MASK |
1262 INFINIPATH_SERDC0_TXIDLE)) {
1263 val &= ~(INFINIPATH_SERDC0_RESET_PLL |
1264 INFINIPATH_SERDC0_RESET_MASK |
1265 INFINIPATH_SERDC0_TXIDLE);
1266 /* clear them */
1267 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0,
1268 val);
1269 }
1270
1271 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
1272 if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
1273 INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
1274 val &= ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
1275 INFINIPATH_XGXS_MDIOADDR_SHIFT);
1276 /*
1277 * we use address 3
1278 */
1279 val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
1280 change = 1;
1281 }
1282 if (val & INFINIPATH_XGXS_RESET) {
1283 /* normally true after boot */
1284 val &= ~INFINIPATH_XGXS_RESET;
1285 change = 1;
1286 }
1287 if (change)
1288 ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
1289
1290 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
1291
1292 /* clear current and de-emphasis bits */
1293 config1 &= ~0x0ffffffff00ULL;
1294 /* set current to 20ma */
1295 config1 |= 0x00000000000ULL;
1296 /* set de-emphasis to -5.68dB */
1297 config1 |= 0x0cccc000000ULL;
1298 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
1299
1300 ipath_cdbg(VERBOSE, "After setup: serdes status is config0=%llx "
1301 "config1=%llx, sstatus=%llx xgxs %llx\n",
1302 (unsigned long long) val, (unsigned long long) config1,
1303 (unsigned long long)
1304 ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
1305 (unsigned long long)
1306 ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
1307
1308 if (!ipath_waitfor_mdio_cmdready(dd)) {
1309 ipath_write_kreg(dd, dd->ipath_kregs->kr_mdio,
1310 ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
1311 IPATH_MDIO_CTRL_XGXS_REG_8,
1312 0));
1313 if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
1314 IPATH_MDIO_DATAVALID, &val))
1315 ipath_dbg("Never got MDIO data for XGXS status "
1316 "read\n");
1317 else
1318 ipath_cdbg(VERBOSE, "MDIO Read reg8, "
1319 "'bank' 31 %x\n", (u32) val);
1320 } else
1321 ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
1322
1323 return ret; /* for now, say we always succeeded */
1324}
1325
1326/**
1327 * ipath_ht_quiet_serdes - set serdes to txidle
1328 * @dd: the infinipath device
1329 * driver is being unloaded
1330 */
1331static void ipath_ht_quiet_serdes(struct ipath_devdata *dd)
1332{
1333 u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
1334
1335 val |= INFINIPATH_SERDC0_TXIDLE;
1336 ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
1337 (unsigned long long) val);
1338 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
1339}
1340
1341static int ipath_ht_intconfig(struct ipath_devdata *dd)
1342{
1343 int ret;
1344
1345 if (!dd->ipath_intconfig) {
1346 ipath_dev_err(dd, "No interrupts enabled, couldn't setup "
1347 "interrupt address\n");
1348 ret = 1;
1349 goto bail;
1350 }
1351
1352 ipath_write_kreg(dd, dd->ipath_kregs->kr_interruptconfig,
1353 dd->ipath_intconfig); /* interrupt address */
1354 ret = 0;
1355
1356bail:
1357 return ret;
1358}
1359
1360/**
1361 * ipath_pe_put_tid - write a TID in chip
1362 * @dd: the infinipath device
1363 * @tidptr: pointer to the expected TID (in chip) to udpate
1364 * @tidtype: 0 for eager, 1 for expected
1365 * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
1366 *
1367 * This exists as a separate routine to allow for special locking etc.
1368 * It's used for both the full cleanup on exit, as well as the normal
1369 * setup and teardown.
1370 */
1371static void ipath_ht_put_tid(struct ipath_devdata *dd,
1372 u64 __iomem *tidptr, u32 type,
1373 unsigned long pa)
1374{
1375 if (pa != dd->ipath_tidinvalid) {
1376 if (unlikely((pa & ~INFINIPATH_RT_ADDR_MASK))) {
1377 dev_info(&dd->pcidev->dev,
1378 "physaddr %lx has more than "
1379 "40 bits, using only 40!!!\n", pa);
1380 pa &= INFINIPATH_RT_ADDR_MASK;
1381 }
1382 if (type == 0)
1383 pa |= dd->ipath_tidtemplate;
1384 else {
1385 /* in words (fixed, full page). */
1386 u64 lenvalid = PAGE_SIZE >> 2;
1387 lenvalid <<= INFINIPATH_RT_BUFSIZE_SHIFT;
1388 pa |= lenvalid | INFINIPATH_RT_VALID;
1389 }
1390 }
1391 if (dd->ipath_kregbase)
1392 writeq(pa, tidptr);
1393}
1394
1395/**
1396 * ipath_ht_clear_tid - clear all TID entries for a port, expected and eager
1397 * @dd: the infinipath device
1398 * @port: the port
1399 *
1400 * Used from ipath_close(), and at chip initialization.
1401 */
1402static void ipath_ht_clear_tids(struct ipath_devdata *dd, unsigned port)
1403{
1404 u64 __iomem *tidbase;
1405 int i;
1406
1407 if (!dd->ipath_kregbase)
1408 return;
1409
1410 ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
1411
1412 /*
1413 * need to invalidate all of the expected TID entries for this
1414 * port, so we don't have valid entries that might somehow get
1415 * used (early in next use of this port, or through some bug)
1416 */
1417 tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
1418 dd->ipath_rcvtidbase +
1419 port * dd->ipath_rcvtidcnt *
1420 sizeof(*tidbase));
1421 for (i = 0; i < dd->ipath_rcvtidcnt; i++)
1422 ipath_ht_put_tid(dd, &tidbase[i], 1, dd->ipath_tidinvalid);
1423
1424 tidbase = (u64 __iomem *) ((char __iomem *)(dd->ipath_kregbase) +
1425 dd->ipath_rcvegrbase +
1426 port * dd->ipath_rcvegrcnt *
1427 sizeof(*tidbase));
1428
1429 for (i = 0; i < dd->ipath_rcvegrcnt; i++)
1430 ipath_ht_put_tid(dd, &tidbase[i], 0, dd->ipath_tidinvalid);
1431}
1432
1433/**
1434 * ipath_ht_tidtemplate - setup constants for TID updates
1435 * @dd: the infinipath device
1436 *
1437 * We setup stuff that we use a lot, to avoid calculating each time
1438 */
1439static void ipath_ht_tidtemplate(struct ipath_devdata *dd)
1440{
1441 dd->ipath_tidtemplate = dd->ipath_ibmaxlen >> 2;
1442 dd->ipath_tidtemplate <<= INFINIPATH_RT_BUFSIZE_SHIFT;
1443 dd->ipath_tidtemplate |= INFINIPATH_RT_VALID;
1444
1445 /*
1446 * work around chip errata bug 7358, by marking invalid tids
1447 * as having max length
1448 */
1449 dd->ipath_tidinvalid = (-1LL & INFINIPATH_RT_BUFSIZE_MASK) <<
1450 INFINIPATH_RT_BUFSIZE_SHIFT;
1451}
1452
1453static int ipath_ht_early_init(struct ipath_devdata *dd)
1454{
1455 u32 __iomem *piobuf;
1456 u32 pioincr, val32, egrsize;
1457 int i;
1458
1459 /*
1460 * one cache line; long IB headers will spill over into received
1461 * buffer
1462 */
1463 dd->ipath_rcvhdrentsize = 16;
1464 dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
1465
1466 /*
1467 * For HT-400, we allocate a somewhat overly large eager buffer,
1468 * such that we can guarantee that we can receive the largest
1469 * packet that we can send out. To truly support a 4KB MTU,
1470 * we need to bump this to a large value. To date, other than
1471 * testing, we have never encountered an HCA that can really
1472 * send 4KB MTU packets, so we do not handle that (we'll get
1473 * errors interrupts if we ever see one).
1474 */
1475 dd->ipath_rcvegrbufsize = dd->ipath_piosize2k;
1476 egrsize = dd->ipath_rcvegrbufsize;
1477
1478 /*
1479 * the min() check here is currently a nop, but it may not
1480 * always be, depending on just how we do ipath_rcvegrbufsize
1481 */
1482 dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
1483 dd->ipath_rcvegrbufsize);
1484 dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
1485 ipath_ht_tidtemplate(dd);
1486
1487 /*
1488 * zero all the TID entries at startup. We do this for sanity,
1489 * in case of a previous driver crash of some kind, and also
1490 * because the chip powers up with these memories in an unknown
1491 * state. Use portcnt, not cfgports, since this is for the
1492 * full chip, not for current (possibly different) configuration
1493 * value.
1494 * Chip Errata bug 6447
1495 */
1496 for (val32 = 0; val32 < dd->ipath_portcnt; val32++)
1497 ipath_ht_clear_tids(dd, val32);
1498
1499 /*
1500 * write the pbc of each buffer, to be sure it's initialized, then
1501 * cancel all the buffers, and also abort any packets that might
1502 * have been in flight for some reason (the latter is for driver
1503 * unload/reload, but isn't a bad idea at first init). PIO send
1504 * isn't enabled at this point, so there is no danger of sending
1505 * these out on the wire.
1506 * Chip Errata bug 6610
1507 */
1508 piobuf = (u32 __iomem *) (((char __iomem *)(dd->ipath_kregbase)) +
1509 dd->ipath_piobufbase);
1510 pioincr = dd->ipath_palign / sizeof(*piobuf);
1511 for (i = 0; i < dd->ipath_piobcnt2k; i++) {
1512 /*
1513 * reasonable word count, just to init pbc
1514 */
1515 writel(16, piobuf);
1516 piobuf += pioincr;
1517 }
1518 /*
1519 * self-clearing
1520 */
1521 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1522 INFINIPATH_S_ABORT);
1523 return 0;
1524}
1525
1526/**
1527 * ipath_init_ht_get_base_info - set chip-specific flags for user code
1528 * @dd: the infinipath device
1529 * @kbase: ipath_base_info pointer
1530 *
1531 * We set the PCIE flag because the lower bandwidth on PCIe vs
1532 * HyperTransport can affect some user packet algorithims.
1533 */
1534static int ipath_ht_get_base_info(struct ipath_portdata *pd, void *kbase)
1535{
1536 struct ipath_base_info *kinfo = kbase;
1537
1538 kinfo->spi_runtime_flags |= IPATH_RUNTIME_HT |
1539 IPATH_RUNTIME_RCVHDR_COPY;
1540
1541 return 0;
1542}
1543
1544/**
1545 * ipath_init_ht400_funcs - set up the chip-specific function pointers
1546 * @dd: the infinipath device
1547 *
1548 * This is global, and is called directly at init to set up the
1549 * chip-specific function pointers for later use.
1550 */
1551void ipath_init_ht400_funcs(struct ipath_devdata *dd)
1552{
1553 dd->ipath_f_intrsetup = ipath_ht_intconfig;
1554 dd->ipath_f_bus = ipath_setup_ht_config;
1555 dd->ipath_f_reset = ipath_setup_ht_reset;
1556 dd->ipath_f_get_boardname = ipath_ht_boardname;
1557 dd->ipath_f_init_hwerrors = ipath_ht_init_hwerrors;
1558 dd->ipath_f_init_hwerrors = ipath_ht_init_hwerrors;
1559 dd->ipath_f_early_init = ipath_ht_early_init;
1560 dd->ipath_f_handle_hwerrors = ipath_ht_handle_hwerrors;
1561 dd->ipath_f_quiet_serdes = ipath_ht_quiet_serdes;
1562 dd->ipath_f_bringup_serdes = ipath_ht_bringup_serdes;
1563 dd->ipath_f_clear_tids = ipath_ht_clear_tids;
1564 dd->ipath_f_put_tid = ipath_ht_put_tid;
1565 dd->ipath_f_cleanup = ipath_setup_ht_cleanup;
1566 dd->ipath_f_setextled = ipath_setup_ht_setextled;
1567 dd->ipath_f_get_base_info = ipath_ht_get_base_info;
1568
1569 /*
1570 * initialize chip-specific variables
1571 */
1572 dd->ipath_f_tidtemplate = ipath_ht_tidtemplate;
1573
1574 /*
1575 * setup the register offsets, since they are different for each
1576 * chip
1577 */
1578 dd->ipath_kregs = &ipath_ht_kregs;
1579 dd->ipath_cregs = &ipath_ht_cregs;
1580
1581 /*
1582 * do very early init that is needed before ipath_f_bus is
1583 * called
1584 */
1585 ipath_init_ht_variables();
1586}
diff --git a/drivers/infiniband/hw/ipath/ipath_init_chip.c b/drivers/infiniband/hw/ipath/ipath_init_chip.c
new file mode 100644
index 000000000000..2823ff9c0c62
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_init_chip.c
@@ -0,0 +1,951 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/pci.h>
34#include <linux/netdevice.h>
35#include <linux/vmalloc.h>
36
37#include "ipath_kernel.h"
38#include "ips_common.h"
39
40/*
41 * min buffers we want to have per port, after driver
42 */
43#define IPATH_MIN_USER_PORT_BUFCNT 8
44
45/*
46 * Number of ports we are configured to use (to allow for more pio
47 * buffers per port, etc.) Zero means use chip value.
48 */
49static ushort ipath_cfgports;
50
51module_param_named(cfgports, ipath_cfgports, ushort, S_IRUGO);
52MODULE_PARM_DESC(cfgports, "Set max number of ports to use");
53
54/*
55 * Number of buffers reserved for driver (layered drivers and SMA
56 * send). Reserved at end of buffer list.
57 */
58static ushort ipath_kpiobufs = 32;
59
60static int ipath_set_kpiobufs(const char *val, struct kernel_param *kp);
61
62module_param_call(kpiobufs, ipath_set_kpiobufs, param_get_uint,
63 &ipath_kpiobufs, S_IWUSR | S_IRUGO);
64MODULE_PARM_DESC(kpiobufs, "Set number of PIO buffers for driver");
65
66/**
67 * create_port0_egr - allocate the eager TID buffers
68 * @dd: the infinipath device
69 *
70 * This code is now quite different for user and kernel, because
71 * the kernel uses skb's, for the accelerated network performance.
72 * This is the kernel (port0) version.
73 *
74 * Allocate the eager TID buffers and program them into infinipath.
75 * We use the network layer alloc_skb() allocator to allocate the
76 * memory, and either use the buffers as is for things like SMA
77 * packets, or pass the buffers up to the ipath layered driver and
78 * thence the network layer, replacing them as we do so (see
79 * ipath_rcv_layer()).
80 */
81static int create_port0_egr(struct ipath_devdata *dd)
82{
83 unsigned e, egrcnt;
84 struct sk_buff **skbs;
85 int ret;
86
87 egrcnt = dd->ipath_rcvegrcnt;
88
89 skbs = vmalloc(sizeof(*dd->ipath_port0_skbs) * egrcnt);
90 if (skbs == NULL) {
91 ipath_dev_err(dd, "allocation error for eager TID "
92 "skb array\n");
93 ret = -ENOMEM;
94 goto bail;
95 }
96 for (e = 0; e < egrcnt; e++) {
97 /*
98 * This is a bit tricky in that we allocate extra
99 * space for 2 bytes of the 14 byte ethernet header.
100 * These two bytes are passed in the ipath header so
101 * the rest of the data is word aligned. We allocate
102 * 4 bytes so that the data buffer stays word aligned.
103 * See ipath_kreceive() for more details.
104 */
105 skbs[e] = ipath_alloc_skb(dd, GFP_KERNEL);
106 if (!skbs[e]) {
107 ipath_dev_err(dd, "SKB allocation error for "
108 "eager TID %u\n", e);
109 while (e != 0)
110 dev_kfree_skb(skbs[--e]);
111 ret = -ENOMEM;
112 goto bail;
113 }
114 }
115 /*
116 * After loop above, so we can test non-NULL to see if ready
117 * to use at receive, etc.
118 */
119 dd->ipath_port0_skbs = skbs;
120
121 for (e = 0; e < egrcnt; e++) {
122 unsigned long phys =
123 virt_to_phys(dd->ipath_port0_skbs[e]->data);
124 dd->ipath_f_put_tid(dd, e + (u64 __iomem *)
125 ((char __iomem *) dd->ipath_kregbase +
126 dd->ipath_rcvegrbase), 0, phys);
127 }
128
129 ret = 0;
130
131bail:
132 return ret;
133}
134
135static int bringup_link(struct ipath_devdata *dd)
136{
137 u64 val, ibc;
138 int ret = 0;
139
140 /* hold IBC in reset */
141 dd->ipath_control &= ~INFINIPATH_C_LINKENABLE;
142 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
143 dd->ipath_control);
144
145 /*
146 * Note that prior to try 14 or 15 of IB, the credit scaling
147 * wasn't working, because it was swapped for writes with the
148 * 1 bit default linkstate field
149 */
150
151 /* ignore pbc and align word */
152 val = dd->ipath_piosize2k - 2 * sizeof(u32);
153 /*
154 * for ICRC, which we only send in diag test pkt mode, and we
155 * don't need to worry about that for mtu
156 */
157 val += 1;
158 /*
159 * Set the IBC maxpktlength to the size of our pio buffers the
160 * maxpktlength is in words. This is *not* the IB data MTU.
161 */
162 ibc = (val / sizeof(u32)) << INFINIPATH_IBCC_MAXPKTLEN_SHIFT;
163 /* in KB */
164 ibc |= 0x5ULL << INFINIPATH_IBCC_FLOWCTRLWATERMARK_SHIFT;
165 /*
166 * How often flowctrl sent. More or less in usecs; balance against
167 * watermark value, so that in theory senders always get a flow
168 * control update in time to not let the IB link go idle.
169 */
170 ibc |= 0x3ULL << INFINIPATH_IBCC_FLOWCTRLPERIOD_SHIFT;
171 /* max error tolerance */
172 ibc |= 0xfULL << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
173 /* use "real" buffer space for */
174 ibc |= 4ULL << INFINIPATH_IBCC_CREDITSCALE_SHIFT;
175 /* IB credit flow control. */
176 ibc |= 0xfULL << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
177 /* initially come up waiting for TS1, without sending anything. */
178 dd->ipath_ibcctrl = ibc;
179 /*
180 * Want to start out with both LINKCMD and LINKINITCMD in NOP
181 * (0 and 0). Don't put linkinitcmd in ipath_ibcctrl, want that
182 * to stay a NOP
183 */
184 ibc |= INFINIPATH_IBCC_LINKINITCMD_DISABLE <<
185 INFINIPATH_IBCC_LINKINITCMD_SHIFT;
186 ipath_cdbg(VERBOSE, "Writing 0x%llx to ibcctrl\n",
187 (unsigned long long) ibc);
188 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl, ibc);
189
190 // be sure chip saw it
191 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
192
193 ret = dd->ipath_f_bringup_serdes(dd);
194
195 if (ret)
196 dev_info(&dd->pcidev->dev, "Could not initialize SerDes, "
197 "not usable\n");
198 else {
199 /* enable IBC */
200 dd->ipath_control |= INFINIPATH_C_LINKENABLE;
201 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
202 dd->ipath_control);
203 }
204
205 return ret;
206}
207
208static int init_chip_first(struct ipath_devdata *dd,
209 struct ipath_portdata **pdp)
210{
211 struct ipath_portdata *pd = NULL;
212 int ret = 0;
213 u64 val;
214
215 /*
216 * skip cfgports stuff because we are not allocating memory,
217 * and we don't want problems if the portcnt changed due to
218 * cfgports. We do still check and report a difference, if
219 * not same (should be impossible).
220 */
221 dd->ipath_portcnt =
222 ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
223 if (!ipath_cfgports)
224 dd->ipath_cfgports = dd->ipath_portcnt;
225 else if (ipath_cfgports <= dd->ipath_portcnt) {
226 dd->ipath_cfgports = ipath_cfgports;
227 ipath_dbg("Configured to use %u ports out of %u in chip\n",
228 dd->ipath_cfgports, dd->ipath_portcnt);
229 } else {
230 dd->ipath_cfgports = dd->ipath_portcnt;
231 ipath_dbg("Tried to configured to use %u ports; chip "
232 "only supports %u\n", ipath_cfgports,
233 dd->ipath_portcnt);
234 }
235 dd->ipath_pd = kzalloc(sizeof(*dd->ipath_pd) * dd->ipath_cfgports,
236 GFP_KERNEL);
237
238 if (!dd->ipath_pd) {
239 ipath_dev_err(dd, "Unable to allocate portdata array, "
240 "failing\n");
241 ret = -ENOMEM;
242 goto done;
243 }
244
245 dd->ipath_lastegrheads = kzalloc(sizeof(*dd->ipath_lastegrheads)
246 * dd->ipath_cfgports,
247 GFP_KERNEL);
248 dd->ipath_lastrcvhdrqtails =
249 kzalloc(sizeof(*dd->ipath_lastrcvhdrqtails)
250 * dd->ipath_cfgports, GFP_KERNEL);
251
252 if (!dd->ipath_lastegrheads || !dd->ipath_lastrcvhdrqtails) {
253 ipath_dev_err(dd, "Unable to allocate head arrays, "
254 "failing\n");
255 ret = -ENOMEM;
256 goto done;
257 }
258
259 dd->ipath_pd[0] = kzalloc(sizeof(*pd), GFP_KERNEL);
260
261 if (!dd->ipath_pd[0]) {
262 ipath_dev_err(dd, "Unable to allocate portdata for port "
263 "0, failing\n");
264 ret = -ENOMEM;
265 goto done;
266 }
267 pd = dd->ipath_pd[0];
268 pd->port_dd = dd;
269 pd->port_port = 0;
270 pd->port_cnt = 1;
271 /* The port 0 pkey table is used by the layer interface. */
272 pd->port_pkeys[0] = IPS_DEFAULT_P_KEY;
273 dd->ipath_rcvtidcnt =
274 ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidcnt);
275 dd->ipath_rcvtidbase =
276 ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidbase);
277 dd->ipath_rcvegrcnt =
278 ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
279 dd->ipath_rcvegrbase =
280 ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrbase);
281 dd->ipath_palign =
282 ipath_read_kreg32(dd, dd->ipath_kregs->kr_pagealign);
283 dd->ipath_piobufbase =
284 ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpiobufbase);
285 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpiosize);
286 dd->ipath_piosize2k = val & ~0U;
287 dd->ipath_piosize4k = val >> 32;
288 dd->ipath_ibmtu = 4096; /* default to largest legal MTU */
289 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpiobufcnt);
290 dd->ipath_piobcnt2k = val & ~0U;
291 dd->ipath_piobcnt4k = val >> 32;
292 dd->ipath_pio2kbase =
293 (u32 __iomem *) (((char __iomem *) dd->ipath_kregbase) +
294 (dd->ipath_piobufbase & 0xffffffff));
295 if (dd->ipath_piobcnt4k) {
296 dd->ipath_pio4kbase = (u32 __iomem *)
297 (((char __iomem *) dd->ipath_kregbase) +
298 (dd->ipath_piobufbase >> 32));
299 /*
300 * 4K buffers take 2 pages; we use roundup just to be
301 * paranoid; we calculate it once here, rather than on
302 * ever buf allocate
303 */
304 dd->ipath_4kalign = ALIGN(dd->ipath_piosize4k,
305 dd->ipath_palign);
306 ipath_dbg("%u 2k(%x) piobufs @ %p, %u 4k(%x) @ %p "
307 "(%x aligned)\n",
308 dd->ipath_piobcnt2k, dd->ipath_piosize2k,
309 dd->ipath_pio2kbase, dd->ipath_piobcnt4k,
310 dd->ipath_piosize4k, dd->ipath_pio4kbase,
311 dd->ipath_4kalign);
312 }
313 else ipath_dbg("%u 2k piobufs @ %p\n",
314 dd->ipath_piobcnt2k, dd->ipath_pio2kbase);
315
316 spin_lock_init(&dd->ipath_tid_lock);
317
318done:
319 *pdp = pd;
320 return ret;
321}
322
323/**
324 * init_chip_reset - re-initialize after a reset, or enable
325 * @dd: the infinipath device
326 * @pdp: output for port data
327 *
328 * sanity check at least some of the values after reset, and
329 * ensure no receive or transmit (explictly, in case reset
330 * failed
331 */
332static int init_chip_reset(struct ipath_devdata *dd,
333 struct ipath_portdata **pdp)
334{
335 struct ipath_portdata *pd;
336 u32 rtmp;
337
338 *pdp = pd = dd->ipath_pd[0];
339 /* ensure chip does no sends or receives while we re-initialize */
340 dd->ipath_control = dd->ipath_sendctrl = dd->ipath_rcvctrl = 0U;
341 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl, 0);
342 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl, 0);
343 ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 0);
344
345 rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_portcnt);
346 if (dd->ipath_portcnt != rtmp)
347 dev_info(&dd->pcidev->dev, "portcnt was %u before "
348 "reset, now %u, using original\n",
349 dd->ipath_portcnt, rtmp);
350 rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidcnt);
351 if (rtmp != dd->ipath_rcvtidcnt)
352 dev_info(&dd->pcidev->dev, "tidcnt was %u before "
353 "reset, now %u, using original\n",
354 dd->ipath_rcvtidcnt, rtmp);
355 rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvtidbase);
356 if (rtmp != dd->ipath_rcvtidbase)
357 dev_info(&dd->pcidev->dev, "tidbase was %u before "
358 "reset, now %u, using original\n",
359 dd->ipath_rcvtidbase, rtmp);
360 rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrcnt);
361 if (rtmp != dd->ipath_rcvegrcnt)
362 dev_info(&dd->pcidev->dev, "egrcnt was %u before "
363 "reset, now %u, using original\n",
364 dd->ipath_rcvegrcnt, rtmp);
365 rtmp = ipath_read_kreg32(dd, dd->ipath_kregs->kr_rcvegrbase);
366 if (rtmp != dd->ipath_rcvegrbase)
367 dev_info(&dd->pcidev->dev, "egrbase was %u before "
368 "reset, now %u, using original\n",
369 dd->ipath_rcvegrbase, rtmp);
370
371 return 0;
372}
373
374static int init_pioavailregs(struct ipath_devdata *dd)
375{
376 int ret;
377
378 dd->ipath_pioavailregs_dma = dma_alloc_coherent(
379 &dd->pcidev->dev, PAGE_SIZE, &dd->ipath_pioavailregs_phys,
380 GFP_KERNEL);
381 if (!dd->ipath_pioavailregs_dma) {
382 ipath_dev_err(dd, "failed to allocate PIOavail reg area "
383 "in memory\n");
384 ret = -ENOMEM;
385 goto done;
386 }
387
388 /*
389 * we really want L2 cache aligned, but for current CPUs of
390 * interest, they are the same.
391 */
392 dd->ipath_statusp = (u64 *)
393 ((char *)dd->ipath_pioavailregs_dma +
394 ((2 * L1_CACHE_BYTES +
395 dd->ipath_pioavregs * sizeof(u64)) & ~L1_CACHE_BYTES));
396 /* copy the current value now that it's really allocated */
397 *dd->ipath_statusp = dd->_ipath_status;
398 /*
399 * setup buffer to hold freeze msg, accessible to apps,
400 * following statusp
401 */
402 dd->ipath_freezemsg = (char *)&dd->ipath_statusp[1];
403 /* and its length */
404 dd->ipath_freezelen = L1_CACHE_BYTES - sizeof(dd->ipath_statusp[0]);
405
406 if (dd->ipath_unit * 64 > (IPATH_PORT0_RCVHDRTAIL_SIZE - 64)) {
407 ipath_dev_err(dd, "unit %u too large for port 0 "
408 "rcvhdrtail buffer size\n", dd->ipath_unit);
409 ret = -ENODEV;
410 }
411 else
412 ret = 0;
413
414 /* so we can get current tail in ipath_kreceive(), per chip */
415 dd->ipath_hdrqtailptr = &ipath_port0_rcvhdrtail[
416 dd->ipath_unit * (64 / sizeof(*ipath_port0_rcvhdrtail))];
417done:
418 return ret;
419}
420
421/**
422 * init_shadow_tids - allocate the shadow TID array
423 * @dd: the infinipath device
424 *
425 * allocate the shadow TID array, so we can ipath_munlock previous
426 * entries. It may make more sense to move the pageshadow to the
427 * port data structure, so we only allocate memory for ports actually
428 * in use, since we at 8k per port, now.
429 */
430static void init_shadow_tids(struct ipath_devdata *dd)
431{
432 dd->ipath_pageshadow = (struct page **)
433 vmalloc(dd->ipath_cfgports * dd->ipath_rcvtidcnt *
434 sizeof(struct page *));
435 if (!dd->ipath_pageshadow)
436 ipath_dev_err(dd, "failed to allocate shadow page * "
437 "array, no expected sends!\n");
438 else
439 memset(dd->ipath_pageshadow, 0,
440 dd->ipath_cfgports * dd->ipath_rcvtidcnt *
441 sizeof(struct page *));
442}
443
444static void enable_chip(struct ipath_devdata *dd,
445 struct ipath_portdata *pd, int reinit)
446{
447 u32 val;
448 int i;
449
450 if (!reinit) {
451 init_waitqueue_head(&ipath_sma_state_wait);
452 }
453 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
454 dd->ipath_rcvctrl);
455
456 /* Enable PIO send, and update of PIOavail regs to memory. */
457 dd->ipath_sendctrl = INFINIPATH_S_PIOENABLE |
458 INFINIPATH_S_PIOBUFAVAILUPD;
459 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
460 dd->ipath_sendctrl);
461
462 /*
463 * enable port 0 receive, and receive interrupt. other ports
464 * done as user opens and inits them.
465 */
466 dd->ipath_rcvctrl = INFINIPATH_R_TAILUPD |
467 (1ULL << INFINIPATH_R_PORTENABLE_SHIFT) |
468 (1ULL << INFINIPATH_R_INTRAVAIL_SHIFT);
469 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
470 dd->ipath_rcvctrl);
471
472 /*
473 * now ready for use. this should be cleared whenever we
474 * detect a reset, or initiate one.
475 */
476 dd->ipath_flags |= IPATH_INITTED;
477
478 /*
479 * init our shadow copies of head from tail values, and write
480 * head values to match.
481 */
482 val = ipath_read_ureg32(dd, ur_rcvegrindextail, 0);
483 (void)ipath_write_ureg(dd, ur_rcvegrindexhead, val, 0);
484 dd->ipath_port0head = ipath_read_ureg32(dd, ur_rcvhdrtail, 0);
485
486 /* Initialize so we interrupt on next packet received */
487 (void)ipath_write_ureg(dd, ur_rcvhdrhead,
488 dd->ipath_rhdrhead_intr_off |
489 dd->ipath_port0head, 0);
490
491 /*
492 * by now pioavail updates to memory should have occurred, so
493 * copy them into our working/shadow registers; this is in
494 * case something went wrong with abort, but mostly to get the
495 * initial values of the generation bit correct.
496 */
497 for (i = 0; i < dd->ipath_pioavregs; i++) {
498 __le64 val;
499
500 /*
501 * Chip Errata bug 6641; even and odd qwords>3 are swapped.
502 */
503 if (i > 3) {
504 if (i & 1)
505 val = dd->ipath_pioavailregs_dma[i - 1];
506 else
507 val = dd->ipath_pioavailregs_dma[i + 1];
508 }
509 else
510 val = dd->ipath_pioavailregs_dma[i];
511 dd->ipath_pioavailshadow[i] = le64_to_cpu(val);
512 }
513 /* can get counters, stats, etc. */
514 dd->ipath_flags |= IPATH_PRESENT;
515}
516
517static int init_housekeeping(struct ipath_devdata *dd,
518 struct ipath_portdata **pdp, int reinit)
519{
520 char boardn[32];
521 int ret = 0;
522
523 /*
524 * have to clear shadow copies of registers at init that are
525 * not otherwise set here, or all kinds of bizarre things
526 * happen with driver on chip reset
527 */
528 dd->ipath_rcvhdrsize = 0;
529
530 /*
531 * Don't clear ipath_flags as 8bit mode was set before
532 * entering this func. However, we do set the linkstate to
533 * unknown, so we can watch for a transition.
534 */
535 dd->ipath_flags |= IPATH_LINKUNK;
536 dd->ipath_flags &= ~(IPATH_LINKACTIVE | IPATH_LINKARMED |
537 IPATH_LINKDOWN | IPATH_LINKINIT);
538
539 ipath_cdbg(VERBOSE, "Try to read spc chip revision\n");
540 dd->ipath_revision =
541 ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
542
543 /*
544 * set up fundamental info we need to use the chip; we assume
545 * if the revision reg and these regs are OK, we don't need to
546 * special case the rest
547 */
548 dd->ipath_sregbase =
549 ipath_read_kreg32(dd, dd->ipath_kregs->kr_sendregbase);
550 dd->ipath_cregbase =
551 ipath_read_kreg32(dd, dd->ipath_kregs->kr_counterregbase);
552 dd->ipath_uregbase =
553 ipath_read_kreg32(dd, dd->ipath_kregs->kr_userregbase);
554 ipath_cdbg(VERBOSE, "ipath_kregbase %p, sendbase %x usrbase %x, "
555 "cntrbase %x\n", dd->ipath_kregbase, dd->ipath_sregbase,
556 dd->ipath_uregbase, dd->ipath_cregbase);
557 if ((dd->ipath_revision & 0xffffffff) == 0xffffffff
558 || (dd->ipath_sregbase & 0xffffffff) == 0xffffffff
559 || (dd->ipath_cregbase & 0xffffffff) == 0xffffffff
560 || (dd->ipath_uregbase & 0xffffffff) == 0xffffffff) {
561 ipath_dev_err(dd, "Register read failures from chip, "
562 "giving up initialization\n");
563 ret = -ENODEV;
564 goto done;
565 }
566
567 /* clear the initial reset flag, in case first driver load */
568 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear,
569 INFINIPATH_E_RESET);
570
571 if (reinit)
572 ret = init_chip_reset(dd, pdp);
573 else
574 ret = init_chip_first(dd, pdp);
575
576 if (ret)
577 goto done;
578
579 ipath_cdbg(VERBOSE, "Revision %llx (PCI %x), %u ports, %u tids, "
580 "%u egrtids\n", (unsigned long long) dd->ipath_revision,
581 dd->ipath_pcirev, dd->ipath_portcnt, dd->ipath_rcvtidcnt,
582 dd->ipath_rcvegrcnt);
583
584 if (((dd->ipath_revision >> INFINIPATH_R_SOFTWARE_SHIFT) &
585 INFINIPATH_R_SOFTWARE_MASK) != IPATH_CHIP_SWVERSION) {
586 ipath_dev_err(dd, "Driver only handles version %d, "
587 "chip swversion is %d (%llx), failng\n",
588 IPATH_CHIP_SWVERSION,
589 (int)(dd->ipath_revision >>
590 INFINIPATH_R_SOFTWARE_SHIFT) &
591 INFINIPATH_R_SOFTWARE_MASK,
592 (unsigned long long) dd->ipath_revision);
593 ret = -ENOSYS;
594 goto done;
595 }
596 dd->ipath_majrev = (u8) ((dd->ipath_revision >>
597 INFINIPATH_R_CHIPREVMAJOR_SHIFT) &
598 INFINIPATH_R_CHIPREVMAJOR_MASK);
599 dd->ipath_minrev = (u8) ((dd->ipath_revision >>
600 INFINIPATH_R_CHIPREVMINOR_SHIFT) &
601 INFINIPATH_R_CHIPREVMINOR_MASK);
602 dd->ipath_boardrev = (u8) ((dd->ipath_revision >>
603 INFINIPATH_R_BOARDID_SHIFT) &
604 INFINIPATH_R_BOARDID_MASK);
605
606 ret = dd->ipath_f_get_boardname(dd, boardn, sizeof boardn);
607
608 snprintf(dd->ipath_boardversion, sizeof(dd->ipath_boardversion),
609 "Driver %u.%u, %s, InfiniPath%u %u.%u, PCI %u, "
610 "SW Compat %u\n",
611 IPATH_CHIP_VERS_MAJ, IPATH_CHIP_VERS_MIN, boardn,
612 (unsigned)(dd->ipath_revision >> INFINIPATH_R_ARCH_SHIFT) &
613 INFINIPATH_R_ARCH_MASK,
614 dd->ipath_majrev, dd->ipath_minrev, dd->ipath_pcirev,
615 (unsigned)(dd->ipath_revision >>
616 INFINIPATH_R_SOFTWARE_SHIFT) &
617 INFINIPATH_R_SOFTWARE_MASK);
618
619 ipath_dbg("%s", dd->ipath_boardversion);
620
621done:
622 return ret;
623}
624
625
626/**
627 * ipath_init_chip - do the actual initialization sequence on the chip
628 * @dd: the infinipath device
629 * @reinit: reinitializing, so don't allocate new memory
630 *
631 * Do the actual initialization sequence on the chip. This is done
632 * both from the init routine called from the PCI infrastructure, and
633 * when we reset the chip, or detect that it was reset internally,
634 * or it's administratively re-enabled.
635 *
636 * Memory allocation here and in called routines is only done in
637 * the first case (reinit == 0). We have to be careful, because even
638 * without memory allocation, we need to re-write all the chip registers
639 * TIDs, etc. after the reset or enable has completed.
640 */
641int ipath_init_chip(struct ipath_devdata *dd, int reinit)
642{
643 int ret = 0, i;
644 u32 val32, kpiobufs;
645 u64 val, atmp;
646 struct ipath_portdata *pd = NULL; /* keep gcc4 happy */
647
648 ret = init_housekeeping(dd, &pd, reinit);
649 if (ret)
650 goto done;
651
652 /*
653 * we ignore most issues after reporting them, but have to specially
654 * handle hardware-disabled chips.
655 */
656 if (ret == 2) {
657 /* unique error, known to ipath_init_one */
658 ret = -EPERM;
659 goto done;
660 }
661
662 /*
663 * We could bump this to allow for full rcvegrcnt + rcvtidcnt,
664 * but then it no longer nicely fits power of two, and since
665 * we now use routines that backend onto __get_free_pages, the
666 * rest would be wasted.
667 */
668 dd->ipath_rcvhdrcnt = dd->ipath_rcvegrcnt;
669 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrcnt,
670 dd->ipath_rcvhdrcnt);
671
672 /*
673 * Set up the shadow copies of the piobufavail registers,
674 * which we compare against the chip registers for now, and
675 * the in memory DMA'ed copies of the registers. This has to
676 * be done early, before we calculate lastport, etc.
677 */
678 val = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
679 /*
680 * calc number of pioavail registers, and save it; we have 2
681 * bits per buffer.
682 */
683 dd->ipath_pioavregs = ALIGN(val, sizeof(u64) * BITS_PER_BYTE / 2)
684 / (sizeof(u64) * BITS_PER_BYTE / 2);
685 if (!ipath_kpiobufs) /* have to have at least 1, for SMA */
686 kpiobufs = ipath_kpiobufs = 1;
687 else if ((dd->ipath_piobcnt2k + dd->ipath_piobcnt4k) <
688 (dd->ipath_cfgports * IPATH_MIN_USER_PORT_BUFCNT)) {
689 dev_info(&dd->pcidev->dev, "Too few PIO buffers (%u) "
690 "for %u ports to have %u each!\n",
691 dd->ipath_piobcnt2k + dd->ipath_piobcnt4k,
692 dd->ipath_cfgports, IPATH_MIN_USER_PORT_BUFCNT);
693 kpiobufs = 1; /* reserve just the minimum for SMA/ether */
694 } else
695 kpiobufs = ipath_kpiobufs;
696
697 if (kpiobufs >
698 (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -
699 (dd->ipath_cfgports * IPATH_MIN_USER_PORT_BUFCNT))) {
700 i = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -
701 (dd->ipath_cfgports * IPATH_MIN_USER_PORT_BUFCNT);
702 if (i < 0)
703 i = 0;
704 dev_info(&dd->pcidev->dev, "Allocating %d PIO bufs for "
705 "kernel leaves too few for %d user ports "
706 "(%d each); using %u\n", kpiobufs,
707 dd->ipath_cfgports - 1,
708 IPATH_MIN_USER_PORT_BUFCNT, i);
709 /*
710 * shouldn't change ipath_kpiobufs, because could be
711 * different for different devices...
712 */
713 kpiobufs = i;
714 }
715 dd->ipath_lastport_piobuf =
716 dd->ipath_piobcnt2k + dd->ipath_piobcnt4k - kpiobufs;
717 dd->ipath_pbufsport = dd->ipath_cfgports > 1
718 ? dd->ipath_lastport_piobuf / (dd->ipath_cfgports - 1)
719 : 0;
720 val32 = dd->ipath_lastport_piobuf -
721 (dd->ipath_pbufsport * (dd->ipath_cfgports - 1));
722 if (val32 > 0) {
723 ipath_dbg("allocating %u pbufs/port leaves %u unused, "
724 "add to kernel\n", dd->ipath_pbufsport, val32);
725 dd->ipath_lastport_piobuf -= val32;
726 ipath_dbg("%u pbufs/port leaves %u unused, add to kernel\n",
727 dd->ipath_pbufsport, val32);
728 }
729 dd->ipath_lastpioindex = dd->ipath_lastport_piobuf;
730 ipath_cdbg(VERBOSE, "%d PIO bufs for kernel out of %d total %u "
731 "each for %u user ports\n", kpiobufs,
732 dd->ipath_piobcnt2k + dd->ipath_piobcnt4k,
733 dd->ipath_pbufsport, dd->ipath_cfgports - 1);
734
735 dd->ipath_f_early_init(dd);
736
737 /* early_init sets rcvhdrentsize and rcvhdrsize, so this must be
738 * done after early_init */
739 dd->ipath_hdrqlast =
740 dd->ipath_rcvhdrentsize * (dd->ipath_rcvhdrcnt - 1);
741 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrentsize,
742 dd->ipath_rcvhdrentsize);
743 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvhdrsize,
744 dd->ipath_rcvhdrsize);
745
746 if (!reinit) {
747 ret = init_pioavailregs(dd);
748 init_shadow_tids(dd);
749 if (ret)
750 goto done;
751 }
752
753 (void)ipath_write_kreg(dd, dd->ipath_kregs->kr_sendpioavailaddr,
754 dd->ipath_pioavailregs_phys);
755 /*
756 * this is to detect s/w errors, which the h/w works around by
757 * ignoring the low 6 bits of address, if it wasn't aligned.
758 */
759 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_sendpioavailaddr);
760 if (val != dd->ipath_pioavailregs_phys) {
761 ipath_dev_err(dd, "Catastrophic software error, "
762 "SendPIOAvailAddr written as %lx, "
763 "read back as %llx\n",
764 (unsigned long) dd->ipath_pioavailregs_phys,
765 (unsigned long long) val);
766 ret = -EINVAL;
767 goto done;
768 }
769
770 val = ipath_port0_rcvhdrtail_dma + dd->ipath_unit * 64;
771
772 /* verify that the alignment requirement was met */
773 ipath_write_kreg_port(dd, dd->ipath_kregs->kr_rcvhdrtailaddr,
774 0, val);
775 atmp = ipath_read_kreg64_port(
776 dd, dd->ipath_kregs->kr_rcvhdrtailaddr, 0);
777 if (val != atmp) {
778 ipath_dev_err(dd, "Catastrophic software error, "
779 "RcvHdrTailAddr0 written as %llx, "
780 "read back as %llx from %x\n",
781 (unsigned long long) val,
782 (unsigned long long) atmp,
783 dd->ipath_kregs->kr_rcvhdrtailaddr);
784 ret = -EINVAL;
785 goto done;
786 }
787
788 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvbthqp, IPATH_KD_QP);
789
790 /*
791 * make sure we are not in freeze, and PIO send enabled, so
792 * writes to pbc happen
793 */
794 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask, 0ULL);
795 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
796 ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);
797 ipath_write_kreg(dd, dd->ipath_kregs->kr_control, 0ULL);
798 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
799 INFINIPATH_S_PIOENABLE);
800
801 /*
802 * before error clears, since we expect serdes pll errors during
803 * this, the first time after reset
804 */
805 if (bringup_link(dd)) {
806 dev_info(&dd->pcidev->dev, "Failed to bringup IB link\n");
807 ret = -ENETDOWN;
808 goto done;
809 }
810
811 /*
812 * clear any "expected" hwerrs from reset and/or initialization
813 * clear any that aren't enabled (at least this once), and then
814 * set the enable mask
815 */
816 dd->ipath_f_init_hwerrors(dd);
817 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
818 ~0ULL&~INFINIPATH_HWE_MEMBISTFAILED);
819 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
820 dd->ipath_hwerrmask);
821
822 dd->ipath_maskederrs = dd->ipath_ignorederrs;
823 /* clear all */
824 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, -1LL);
825 /* enable errors that are masked, at least this first time. */
826 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
827 ~dd->ipath_maskederrs);
828 /* clear any interrups up to this point (ints still not enabled) */
829 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, -1LL);
830
831 ipath_stats.sps_lid[dd->ipath_unit] = dd->ipath_lid;
832
833 /*
834 * Set up the port 0 (kernel) rcvhdr q and egr TIDs. If doing
835 * re-init, the simplest way to handle this is to free
836 * existing, and re-allocate.
837 */
838 if (reinit)
839 ipath_free_pddata(dd, 0, 0);
840 dd->ipath_f_tidtemplate(dd);
841 ret = ipath_create_rcvhdrq(dd, pd);
842 if (!ret)
843 ret = create_port0_egr(dd);
844 if (ret)
845 ipath_dev_err(dd, "failed to allocate port 0 (kernel) "
846 "rcvhdrq and/or egr bufs\n");
847 else
848 enable_chip(dd, pd, reinit);
849
850 /*
851 * cause retrigger of pending interrupts ignored during init,
852 * even if we had errors
853 */
854 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, 0ULL);
855
856 if(!dd->ipath_stats_timer_active) {
857 /*
858 * first init, or after an admin disable/enable
859 * set up stats retrieval timer, even if we had errors
860 * in last portion of setup
861 */
862 init_timer(&dd->ipath_stats_timer);
863 dd->ipath_stats_timer.function = ipath_get_faststats;
864 dd->ipath_stats_timer.data = (unsigned long) dd;
865 /* every 5 seconds; */
866 dd->ipath_stats_timer.expires = jiffies + 5 * HZ;
867 /* takes ~16 seconds to overflow at full IB 4x bandwdith */
868 add_timer(&dd->ipath_stats_timer);
869 dd->ipath_stats_timer_active = 1;
870 }
871
872done:
873 if (!ret) {
874 ipath_get_guid(dd);
875 *dd->ipath_statusp |= IPATH_STATUS_CHIP_PRESENT;
876 if (!dd->ipath_f_intrsetup(dd)) {
877 /* now we can enable all interrupts from the chip */
878 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
879 -1LL);
880 /* force re-interrupt of any pending interrupts. */
881 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear,
882 0ULL);
883 /* chip is usable; mark it as initialized */
884 *dd->ipath_statusp |= IPATH_STATUS_INITTED;
885 } else
886 ipath_dev_err(dd, "No interrupts enabled, couldn't "
887 "setup interrupt address\n");
888
889 if (dd->ipath_cfgports > ipath_stats.sps_nports)
890 /*
891 * sps_nports is a global, so, we set it to
892 * the highest number of ports of any of the
893 * chips we find; we never decrement it, at
894 * least for now. Since this might have changed
895 * over disable/enable or prior to reset, always
896 * do the check and potentially adjust.
897 */
898 ipath_stats.sps_nports = dd->ipath_cfgports;
899 } else
900 ipath_dbg("Failed (%d) to initialize chip\n", ret);
901
902 /* if ret is non-zero, we probably should do some cleanup
903 here... */
904 return ret;
905}
906
907static int ipath_set_kpiobufs(const char *str, struct kernel_param *kp)
908{
909 struct ipath_devdata *dd;
910 unsigned long flags;
911 unsigned short val;
912 int ret;
913
914 ret = ipath_parse_ushort(str, &val);
915
916 spin_lock_irqsave(&ipath_devs_lock, flags);
917
918 if (ret < 0)
919 goto bail;
920
921 if (val == 0) {
922 ret = -EINVAL;
923 goto bail;
924 }
925
926 list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
927 if (dd->ipath_kregbase)
928 continue;
929 if (val > (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k -
930 (dd->ipath_cfgports *
931 IPATH_MIN_USER_PORT_BUFCNT)))
932 {
933 ipath_dev_err(
934 dd,
935 "Allocating %d PIO bufs for kernel leaves "
936 "too few for %d user ports (%d each)\n",
937 val, dd->ipath_cfgports - 1,
938 IPATH_MIN_USER_PORT_BUFCNT);
939 ret = -EINVAL;
940 goto bail;
941 }
942 dd->ipath_lastport_piobuf =
943 dd->ipath_piobcnt2k + dd->ipath_piobcnt4k - val;
944 }
945
946 ret = 0;
947bail:
948 spin_unlock_irqrestore(&ipath_devs_lock, flags);
949
950 return ret;
951}
diff --git a/drivers/infiniband/hw/ipath/ipath_intr.c b/drivers/infiniband/hw/ipath/ipath_intr.c
new file mode 100644
index 000000000000..60f5f4108069
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_intr.c
@@ -0,0 +1,841 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/pci.h>
34
35#include "ipath_kernel.h"
36#include "ips_common.h"
37#include "ipath_layer.h"
38
39#define E_SUM_PKTERRS \
40 (INFINIPATH_E_RHDRLEN | INFINIPATH_E_RBADTID | \
41 INFINIPATH_E_RBADVERSION | INFINIPATH_E_RHDR | \
42 INFINIPATH_E_RLONGPKTLEN | INFINIPATH_E_RSHORTPKTLEN | \
43 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RMINPKTLEN | \
44 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RUNSUPVL | \
45 INFINIPATH_E_RUNEXPCHAR | INFINIPATH_E_REBP)
46
47#define E_SUM_ERRS \
48 (INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM | \
49 INFINIPATH_E_SDROPPEDDATAPKT | INFINIPATH_E_SDROPPEDSMPPKT | \
50 INFINIPATH_E_SMAXPKTLEN | INFINIPATH_E_SUNSUPVL | \
51 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SPKTLEN | \
52 INFINIPATH_E_INVALIDADDR)
53
54static u64 handle_e_sum_errs(struct ipath_devdata *dd, ipath_err_t errs)
55{
56 unsigned long sbuf[4];
57 u64 ignore_this_time = 0;
58 u32 piobcnt;
59
60 /* if possible that sendbuffererror could be valid */
61 piobcnt = dd->ipath_piobcnt2k + dd->ipath_piobcnt4k;
62 /* read these before writing errorclear */
63 sbuf[0] = ipath_read_kreg64(
64 dd, dd->ipath_kregs->kr_sendbuffererror);
65 sbuf[1] = ipath_read_kreg64(
66 dd, dd->ipath_kregs->kr_sendbuffererror + 1);
67 if (piobcnt > 128) {
68 sbuf[2] = ipath_read_kreg64(
69 dd, dd->ipath_kregs->kr_sendbuffererror + 2);
70 sbuf[3] = ipath_read_kreg64(
71 dd, dd->ipath_kregs->kr_sendbuffererror + 3);
72 }
73
74 if (sbuf[0] || sbuf[1] || (piobcnt > 128 && (sbuf[2] || sbuf[3]))) {
75 int i;
76
77 ipath_cdbg(PKT, "SendbufErrs %lx %lx ", sbuf[0], sbuf[1]);
78 if (ipath_debug & __IPATH_PKTDBG && piobcnt > 128)
79 printk("%lx %lx ", sbuf[2], sbuf[3]);
80 for (i = 0; i < piobcnt; i++) {
81 if (test_bit(i, sbuf)) {
82 u32 __iomem *piobuf;
83 if (i < dd->ipath_piobcnt2k)
84 piobuf = (u32 __iomem *)
85 (dd->ipath_pio2kbase +
86 i * dd->ipath_palign);
87 else
88 piobuf = (u32 __iomem *)
89 (dd->ipath_pio4kbase +
90 (i - dd->ipath_piobcnt2k) *
91 dd->ipath_4kalign);
92
93 ipath_cdbg(PKT,
94 "PIObuf[%u] @%p pbc is %x; ",
95 i, piobuf, readl(piobuf));
96
97 ipath_disarm_piobufs(dd, i, 1);
98 }
99 }
100 if (ipath_debug & __IPATH_PKTDBG)
101 printk("\n");
102 }
103 if ((errs & (INFINIPATH_E_SDROPPEDDATAPKT |
104 INFINIPATH_E_SDROPPEDSMPPKT |
105 INFINIPATH_E_SMINPKTLEN)) &&
106 !(dd->ipath_flags & IPATH_LINKACTIVE)) {
107 /*
108 * This can happen when SMA is trying to bring the link
109 * up, but the IB link changes state at the "wrong" time.
110 * The IB logic then complains that the packet isn't
111 * valid. We don't want to confuse people, so we just
112 * don't print them, except at debug
113 */
114 ipath_dbg("Ignoring pktsend errors %llx, because not "
115 "yet active\n", (unsigned long long) errs);
116 ignore_this_time = INFINIPATH_E_SDROPPEDDATAPKT |
117 INFINIPATH_E_SDROPPEDSMPPKT |
118 INFINIPATH_E_SMINPKTLEN;
119 }
120
121 return ignore_this_time;
122}
123
124/* return the strings for the most common link states */
125static char *ib_linkstate(u32 linkstate)
126{
127 char *ret;
128
129 switch (linkstate) {
130 case IPATH_IBSTATE_INIT:
131 ret = "Init";
132 break;
133 case IPATH_IBSTATE_ARM:
134 ret = "Arm";
135 break;
136 case IPATH_IBSTATE_ACTIVE:
137 ret = "Active";
138 break;
139 default:
140 ret = "Down";
141 }
142
143 return ret;
144}
145
146static void handle_e_ibstatuschanged(struct ipath_devdata *dd,
147 ipath_err_t errs, int noprint)
148{
149 u64 val;
150 u32 ltstate, lstate;
151
152 /*
153 * even if diags are enabled, we want to notice LINKINIT, etc.
154 * We just don't want to change the LED state, or
155 * dd->ipath_kregs->kr_ibcctrl
156 */
157 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_ibcstatus);
158 lstate = val & IPATH_IBSTATE_MASK;
159 if (lstate == IPATH_IBSTATE_INIT || lstate == IPATH_IBSTATE_ARM ||
160 lstate == IPATH_IBSTATE_ACTIVE) {
161 /*
162 * only print at SMA if there is a change, debug if not
163 * (sometimes we want to know that, usually not).
164 */
165 if (lstate == ((unsigned) dd->ipath_lastibcstat
166 & IPATH_IBSTATE_MASK)) {
167 ipath_dbg("Status change intr but no change (%s)\n",
168 ib_linkstate(lstate));
169 }
170 else
171 ipath_cdbg(SMA, "Unit %u link state %s, last "
172 "was %s\n", dd->ipath_unit,
173 ib_linkstate(lstate),
174 ib_linkstate((unsigned)
175 dd->ipath_lastibcstat
176 & IPATH_IBSTATE_MASK));
177 }
178 else {
179 lstate = dd->ipath_lastibcstat & IPATH_IBSTATE_MASK;
180 if (lstate == IPATH_IBSTATE_INIT ||
181 lstate == IPATH_IBSTATE_ARM ||
182 lstate == IPATH_IBSTATE_ACTIVE)
183 ipath_cdbg(SMA, "Unit %u link state down"
184 " (state 0x%x), from %s\n",
185 dd->ipath_unit,
186 (u32)val & IPATH_IBSTATE_MASK,
187 ib_linkstate(lstate));
188 else
189 ipath_cdbg(VERBOSE, "Unit %u link state changed "
190 "to 0x%x from down (%x)\n",
191 dd->ipath_unit, (u32) val, lstate);
192 }
193 ltstate = (val >> INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) &
194 INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
195 lstate = (val >> INFINIPATH_IBCS_LINKSTATE_SHIFT) &
196 INFINIPATH_IBCS_LINKSTATE_MASK;
197
198 if (ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE ||
199 ltstate == INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
200 u32 last_ltstate;
201
202 /*
203 * Ignore cycling back and forth from Polling.Active
204 * to Polling.Quiet while waiting for the other end of
205 * the link to come up. We will cycle back and forth
206 * between them if no cable is plugged in,
207 * the other device is powered off or disabled, etc.
208 */
209 last_ltstate = (dd->ipath_lastibcstat >>
210 INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT)
211 & INFINIPATH_IBCS_LINKTRAININGSTATE_MASK;
212 if (last_ltstate == INFINIPATH_IBCS_LT_STATE_POLLACTIVE
213 || last_ltstate ==
214 INFINIPATH_IBCS_LT_STATE_POLLQUIET) {
215 if (dd->ipath_ibpollcnt > 40) {
216 dd->ipath_flags |= IPATH_NOCABLE;
217 *dd->ipath_statusp |=
218 IPATH_STATUS_IB_NOCABLE;
219 } else
220 dd->ipath_ibpollcnt++;
221 goto skip_ibchange;
222 }
223 }
224 dd->ipath_ibpollcnt = 0; /* some state other than 2 or 3 */
225 ipath_stats.sps_iblink++;
226 if (ltstate != INFINIPATH_IBCS_LT_STATE_LINKUP) {
227 dd->ipath_flags |= IPATH_LINKDOWN;
228 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
229 | IPATH_LINKACTIVE |
230 IPATH_LINKARMED);
231 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
232 if (!noprint) {
233 if (((dd->ipath_lastibcstat >>
234 INFINIPATH_IBCS_LINKSTATE_SHIFT) &
235 INFINIPATH_IBCS_LINKSTATE_MASK)
236 == INFINIPATH_IBCS_L_STATE_ACTIVE)
237 /* if from up to down be more vocal */
238 ipath_cdbg(SMA,
239 "Unit %u link now down (%s)\n",
240 dd->ipath_unit,
241 ipath_ibcstatus_str[ltstate]);
242 else
243 ipath_cdbg(VERBOSE, "Unit %u link is "
244 "down (%s)\n", dd->ipath_unit,
245 ipath_ibcstatus_str[ltstate]);
246 }
247
248 dd->ipath_f_setextled(dd, lstate, ltstate);
249 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ACTIVE) {
250 dd->ipath_flags |= IPATH_LINKACTIVE;
251 dd->ipath_flags &=
252 ~(IPATH_LINKUNK | IPATH_LINKINIT | IPATH_LINKDOWN |
253 IPATH_LINKARMED | IPATH_NOCABLE);
254 *dd->ipath_statusp &= ~IPATH_STATUS_IB_NOCABLE;
255 *dd->ipath_statusp |=
256 IPATH_STATUS_IB_READY | IPATH_STATUS_IB_CONF;
257 dd->ipath_f_setextled(dd, lstate, ltstate);
258
259 __ipath_layer_intr(dd, IPATH_LAYER_INT_IF_UP);
260 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_INIT) {
261 /*
262 * set INIT and DOWN. Down is checked by most of the other
263 * code, but INIT is useful to know in a few places.
264 */
265 dd->ipath_flags |= IPATH_LINKINIT | IPATH_LINKDOWN;
266 dd->ipath_flags &=
267 ~(IPATH_LINKUNK | IPATH_LINKACTIVE | IPATH_LINKARMED
268 | IPATH_NOCABLE);
269 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
270 | IPATH_STATUS_IB_READY);
271 dd->ipath_f_setextled(dd, lstate, ltstate);
272 } else if ((val & IPATH_IBSTATE_MASK) == IPATH_IBSTATE_ARM) {
273 dd->ipath_flags |= IPATH_LINKARMED;
274 dd->ipath_flags &=
275 ~(IPATH_LINKUNK | IPATH_LINKDOWN | IPATH_LINKINIT |
276 IPATH_LINKACTIVE | IPATH_NOCABLE);
277 *dd->ipath_statusp &= ~(IPATH_STATUS_IB_NOCABLE
278 | IPATH_STATUS_IB_READY);
279 dd->ipath_f_setextled(dd, lstate, ltstate);
280 } else {
281 if (!noprint)
282 ipath_dbg("IBstatuschange unit %u: %s (%x)\n",
283 dd->ipath_unit,
284 ipath_ibcstatus_str[ltstate], ltstate);
285 }
286skip_ibchange:
287 dd->ipath_lastibcstat = val;
288}
289
290static void handle_supp_msgs(struct ipath_devdata *dd,
291 unsigned supp_msgs, char msg[512])
292{
293 /*
294 * Print the message unless it's ibc status change only, which
295 * happens so often we never want to count it.
296 */
297 if (dd->ipath_lasterror & ~INFINIPATH_E_IBSTATUSCHANGED) {
298 ipath_decode_err(msg, sizeof msg, dd->ipath_lasterror &
299 ~INFINIPATH_E_IBSTATUSCHANGED);
300 if (dd->ipath_lasterror &
301 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
302 ipath_dev_err(dd, "Suppressed %u messages for "
303 "fast-repeating errors (%s) (%llx)\n",
304 supp_msgs, msg,
305 (unsigned long long)
306 dd->ipath_lasterror);
307 else {
308 /*
309 * rcvegrfull and rcvhdrqfull are "normal", for some
310 * types of processes (mostly benchmarks) that send
311 * huge numbers of messages, while not processing
312 * them. So only complain about these at debug
313 * level.
314 */
315 ipath_dbg("Suppressed %u messages for %s\n",
316 supp_msgs, msg);
317 }
318 }
319}
320
321static unsigned handle_frequent_errors(struct ipath_devdata *dd,
322 ipath_err_t errs, char msg[512],
323 int *noprint)
324{
325 unsigned long nc;
326 static unsigned long nextmsg_time;
327 static unsigned nmsgs, supp_msgs;
328
329 /*
330 * Throttle back "fast" messages to no more than 10 per 5 seconds.
331 * This isn't perfect, but it's a reasonable heuristic. If we get
332 * more than 10, give a 6x longer delay.
333 */
334 nc = jiffies;
335 if (nmsgs > 10) {
336 if (time_before(nc, nextmsg_time)) {
337 *noprint = 1;
338 if (!supp_msgs++)
339 nextmsg_time = nc + HZ * 3;
340 }
341 else if (supp_msgs) {
342 handle_supp_msgs(dd, supp_msgs, msg);
343 supp_msgs = 0;
344 nmsgs = 0;
345 }
346 }
347 else if (!nmsgs++ || time_after(nc, nextmsg_time))
348 nextmsg_time = nc + HZ / 2;
349
350 return supp_msgs;
351}
352
353static void handle_errors(struct ipath_devdata *dd, ipath_err_t errs)
354{
355 char msg[512];
356 u64 ignore_this_time = 0;
357 int i;
358 int chkerrpkts = 0, noprint = 0;
359 unsigned supp_msgs;
360
361 supp_msgs = handle_frequent_errors(dd, errs, msg, &noprint);
362
363 /*
364 * don't report errors that are masked (includes those always
365 * ignored)
366 */
367 errs &= ~dd->ipath_maskederrs;
368
369 /* do these first, they are most important */
370 if (errs & INFINIPATH_E_HARDWARE) {
371 /* reuse same msg buf */
372 dd->ipath_f_handle_hwerrors(dd, msg, sizeof msg);
373 }
374
375 if (!noprint && (errs & ~infinipath_e_bitsextant))
376 ipath_dev_err(dd, "error interrupt with unknown errors "
377 "%llx set\n", (unsigned long long)
378 (errs & ~infinipath_e_bitsextant));
379
380 if (errs & E_SUM_ERRS)
381 ignore_this_time = handle_e_sum_errs(dd, errs);
382
383 if (supp_msgs == 250000) {
384 /*
385 * It's not entirely reasonable assuming that the errors set
386 * in the last clear period are all responsible for the
387 * problem, but the alternative is to assume it's the only
388 * ones on this particular interrupt, which also isn't great
389 */
390 dd->ipath_maskederrs |= dd->ipath_lasterror | errs;
391 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
392 ~dd->ipath_maskederrs);
393 ipath_decode_err(msg, sizeof msg,
394 (dd->ipath_maskederrs & ~dd->
395 ipath_ignorederrs));
396
397 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
398 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
399 ipath_dev_err(dd, "Disabling error(s) %llx because "
400 "occuring too frequently (%s)\n",
401 (unsigned long long)
402 (dd->ipath_maskederrs &
403 ~dd->ipath_ignorederrs), msg);
404 else {
405 /*
406 * rcvegrfull and rcvhdrqfull are "normal",
407 * for some types of processes (mostly benchmarks)
408 * that send huge numbers of messages, while not
409 * processing them. So only complain about
410 * these at debug level.
411 */
412 ipath_dbg("Disabling frequent queue full errors "
413 "(%s)\n", msg);
414 }
415
416 /*
417 * Re-enable the masked errors after around 3 minutes. in
418 * ipath_get_faststats(). If we have a series of fast
419 * repeating but different errors, the interval will keep
420 * stretching out, but that's OK, as that's pretty
421 * catastrophic.
422 */
423 dd->ipath_unmasktime = jiffies + HZ * 180;
424 }
425
426 ipath_write_kreg(dd, dd->ipath_kregs->kr_errorclear, errs);
427 if (ignore_this_time)
428 errs &= ~ignore_this_time;
429 if (errs & ~dd->ipath_lasterror) {
430 errs &= ~dd->ipath_lasterror;
431 /* never suppress duplicate hwerrors or ibstatuschange */
432 dd->ipath_lasterror |= errs &
433 ~(INFINIPATH_E_HARDWARE |
434 INFINIPATH_E_IBSTATUSCHANGED);
435 }
436 if (!errs)
437 return;
438
439 if (!noprint)
440 /*
441 * the ones we mask off are handled specially below or above
442 */
443 ipath_decode_err(msg, sizeof msg,
444 errs & ~(INFINIPATH_E_IBSTATUSCHANGED |
445 INFINIPATH_E_RRCVEGRFULL |
446 INFINIPATH_E_RRCVHDRFULL |
447 INFINIPATH_E_HARDWARE));
448 else
449 /* so we don't need if (!noprint) at strlcat's below */
450 *msg = 0;
451
452 if (errs & E_SUM_PKTERRS) {
453 ipath_stats.sps_pkterrs++;
454 chkerrpkts = 1;
455 }
456 if (errs & E_SUM_ERRS)
457 ipath_stats.sps_errs++;
458
459 if (errs & (INFINIPATH_E_RICRC | INFINIPATH_E_RVCRC)) {
460 ipath_stats.sps_crcerrs++;
461 chkerrpkts = 1;
462 }
463
464 /*
465 * We don't want to print these two as they happen, or we can make
466 * the situation even worse, because it takes so long to print
467 * messages to serial consoles. Kernel ports get printed from
468 * fast_stats, no more than every 5 seconds, user ports get printed
469 * on close
470 */
471 if (errs & INFINIPATH_E_RRCVHDRFULL) {
472 int any;
473 u32 hd, tl;
474 ipath_stats.sps_hdrqfull++;
475 for (any = i = 0; i < dd->ipath_cfgports; i++) {
476 struct ipath_portdata *pd = dd->ipath_pd[i];
477 if (i == 0) {
478 hd = dd->ipath_port0head;
479 tl = (u32) le64_to_cpu(
480 *dd->ipath_hdrqtailptr);
481 } else if (pd && pd->port_cnt &&
482 pd->port_rcvhdrtail_kvaddr) {
483 /*
484 * don't report same point multiple times,
485 * except kernel
486 */
487 tl = (u32) * pd->port_rcvhdrtail_kvaddr;
488 if (tl == dd->ipath_lastrcvhdrqtails[i])
489 continue;
490 hd = ipath_read_ureg32(dd, ur_rcvhdrhead,
491 i);
492 } else
493 continue;
494 if (hd == (tl + 1) ||
495 (!hd && tl == dd->ipath_hdrqlast)) {
496 dd->ipath_lastrcvhdrqtails[i] = tl;
497 pd->port_hdrqfull++;
498 if (i == 0)
499 chkerrpkts = 1;
500 }
501 }
502 }
503 if (errs & INFINIPATH_E_RRCVEGRFULL) {
504 /*
505 * since this is of less importance and not likely to
506 * happen without also getting hdrfull, only count
507 * occurrences; don't check each port (or even the kernel
508 * vs user)
509 */
510 ipath_stats.sps_etidfull++;
511 if (dd->ipath_port0head !=
512 (u32) le64_to_cpu(*dd->ipath_hdrqtailptr))
513 chkerrpkts = 1;
514 }
515
516 /*
517 * do this before IBSTATUSCHANGED, in case both bits set in a single
518 * interrupt; we want the STATUSCHANGE to "win", so we do our
519 * internal copy of state machine correctly
520 */
521 if (errs & INFINIPATH_E_RIBLOSTLINK) {
522 /*
523 * force through block below
524 */
525 errs |= INFINIPATH_E_IBSTATUSCHANGED;
526 ipath_stats.sps_iblink++;
527 dd->ipath_flags |= IPATH_LINKDOWN;
528 dd->ipath_flags &= ~(IPATH_LINKUNK | IPATH_LINKINIT
529 | IPATH_LINKARMED | IPATH_LINKACTIVE);
530 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
531 if (!noprint) {
532 u64 st = ipath_read_kreg64(
533 dd, dd->ipath_kregs->kr_ibcstatus);
534
535 ipath_dbg("Lost link, link now down (%s)\n",
536 ipath_ibcstatus_str[st & 0xf]);
537 }
538 }
539 if (errs & INFINIPATH_E_IBSTATUSCHANGED)
540 handle_e_ibstatuschanged(dd, errs, noprint);
541
542 if (errs & INFINIPATH_E_RESET) {
543 if (!noprint)
544 ipath_dev_err(dd, "Got reset, requires re-init "
545 "(unload and reload driver)\n");
546 dd->ipath_flags &= ~IPATH_INITTED; /* needs re-init */
547 /* mark as having had error */
548 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
549 *dd->ipath_statusp &= ~IPATH_STATUS_IB_CONF;
550 }
551
552 if (!noprint && *msg)
553 ipath_dev_err(dd, "%s error\n", msg);
554 if (dd->ipath_sma_state_wanted & dd->ipath_flags) {
555 ipath_cdbg(VERBOSE, "sma wanted state %x, iflags now %x, "
556 "waking\n", dd->ipath_sma_state_wanted,
557 dd->ipath_flags);
558 wake_up_interruptible(&ipath_sma_state_wait);
559 }
560
561 if (chkerrpkts)
562 /* process possible error packets in hdrq */
563 ipath_kreceive(dd);
564}
565
566/* this is separate to allow for better optimization of ipath_intr() */
567
568static void ipath_bad_intr(struct ipath_devdata *dd, u32 * unexpectp)
569{
570 /*
571 * sometimes happen during driver init and unload, don't want
572 * to process any interrupts at that point
573 */
574
575 /* this is just a bandaid, not a fix, if something goes badly
576 * wrong */
577 if (++*unexpectp > 100) {
578 if (++*unexpectp > 105) {
579 /*
580 * ok, we must be taking somebody else's interrupts,
581 * due to a messed up mptable and/or PIRQ table, so
582 * unregister the interrupt. We've seen this during
583 * linuxbios development work, and it may happen in
584 * the future again.
585 */
586 if (dd->pcidev && dd->pcidev->irq) {
587 ipath_dev_err(dd, "Now %u unexpected "
588 "interrupts, unregistering "
589 "interrupt handler\n",
590 *unexpectp);
591 ipath_dbg("free_irq of irq %x\n",
592 dd->pcidev->irq);
593 free_irq(dd->pcidev->irq, dd);
594 }
595 }
596 if (ipath_read_kreg32(dd, dd->ipath_kregs->kr_intmask)) {
597 ipath_dev_err(dd, "%u unexpected interrupts, "
598 "disabling interrupts completely\n",
599 *unexpectp);
600 /*
601 * disable all interrupts, something is very wrong
602 */
603 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask,
604 0ULL);
605 }
606 } else if (*unexpectp > 1)
607 ipath_dbg("Interrupt when not ready, should not happen, "
608 "ignoring\n");
609}
610
611static void ipath_bad_regread(struct ipath_devdata *dd)
612{
613 static int allbits;
614
615 /* separate routine, for better optimization of ipath_intr() */
616
617 /*
618 * We print the message and disable interrupts, in hope of
619 * having a better chance of debugging the problem.
620 */
621 ipath_dev_err(dd,
622 "Read of interrupt status failed (all bits set)\n");
623 if (allbits++) {
624 /* disable all interrupts, something is very wrong */
625 ipath_write_kreg(dd, dd->ipath_kregs->kr_intmask, 0ULL);
626 if (allbits == 2) {
627 ipath_dev_err(dd, "Still bad interrupt status, "
628 "unregistering interrupt\n");
629 free_irq(dd->pcidev->irq, dd);
630 } else if (allbits > 2) {
631 if ((allbits % 10000) == 0)
632 printk(".");
633 } else
634 ipath_dev_err(dd, "Disabling interrupts, "
635 "multiple errors\n");
636 }
637}
638
639static void handle_port_pioavail(struct ipath_devdata *dd)
640{
641 u32 i;
642 /*
643 * start from port 1, since for now port 0 is never using
644 * wait_event for PIO
645 */
646 for (i = 1; dd->ipath_portpiowait && i < dd->ipath_cfgports; i++) {
647 struct ipath_portdata *pd = dd->ipath_pd[i];
648
649 if (pd && pd->port_cnt &&
650 dd->ipath_portpiowait & (1U << i)) {
651 clear_bit(i, &dd->ipath_portpiowait);
652 if (test_bit(IPATH_PORT_WAITING_PIO,
653 &pd->port_flag)) {
654 clear_bit(IPATH_PORT_WAITING_PIO,
655 &pd->port_flag);
656 wake_up_interruptible(&pd->port_wait);
657 }
658 }
659 }
660}
661
662static void handle_layer_pioavail(struct ipath_devdata *dd)
663{
664 int ret;
665
666 ret = __ipath_layer_intr(dd, IPATH_LAYER_INT_SEND_CONTINUE);
667 if (ret > 0)
668 goto clear;
669
670 ret = __ipath_verbs_piobufavail(dd);
671 if (ret > 0)
672 goto clear;
673
674 return;
675clear:
676 set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
677 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
678 dd->ipath_sendctrl);
679}
680
681static void handle_rcv(struct ipath_devdata *dd, u32 istat)
682{
683 u64 portr;
684 int i;
685 int rcvdint = 0;
686
687 portr = ((istat >> INFINIPATH_I_RCVAVAIL_SHIFT) &
688 infinipath_i_rcvavail_mask)
689 | ((istat >> INFINIPATH_I_RCVURG_SHIFT) &
690 infinipath_i_rcvurg_mask);
691 for (i = 0; i < dd->ipath_cfgports; i++) {
692 struct ipath_portdata *pd = dd->ipath_pd[i];
693 if (portr & (1 << i) && pd &&
694 pd->port_cnt) {
695 if (i == 0)
696 ipath_kreceive(dd);
697 else if (test_bit(IPATH_PORT_WAITING_RCV,
698 &pd->port_flag)) {
699 int rcbit;
700 clear_bit(IPATH_PORT_WAITING_RCV,
701 &pd->port_flag);
702 rcbit = i + INFINIPATH_R_INTRAVAIL_SHIFT;
703 clear_bit(1UL << rcbit, &dd->ipath_rcvctrl);
704 wake_up_interruptible(&pd->port_wait);
705 rcvdint = 1;
706 }
707 }
708 }
709 if (rcvdint) {
710 /* only want to take one interrupt, so turn off the rcv
711 * interrupt for all the ports that we did the wakeup on
712 * (but never for kernel port)
713 */
714 ipath_write_kreg(dd, dd->ipath_kregs->kr_rcvctrl,
715 dd->ipath_rcvctrl);
716 }
717}
718
719irqreturn_t ipath_intr(int irq, void *data, struct pt_regs *regs)
720{
721 struct ipath_devdata *dd = data;
722 u32 istat = ipath_read_kreg32(dd, dd->ipath_kregs->kr_intstatus);
723 ipath_err_t estat = 0;
724 static unsigned unexpected = 0;
725 irqreturn_t ret;
726
727 if (unlikely(!istat)) {
728 ipath_stats.sps_nullintr++;
729 ret = IRQ_NONE; /* not our interrupt, or already handled */
730 goto bail;
731 }
732 if (unlikely(istat == -1)) {
733 ipath_bad_regread(dd);
734 /* don't know if it was our interrupt or not */
735 ret = IRQ_NONE;
736 goto bail;
737 }
738
739 ipath_stats.sps_ints++;
740
741 /*
742 * this needs to be flags&initted, not statusp, so we keep
743 * taking interrupts even after link goes down, etc.
744 * Also, we *must* clear the interrupt at some point, or we won't
745 * take it again, which can be real bad for errors, etc...
746 */
747
748 if (!(dd->ipath_flags & IPATH_INITTED)) {
749 ipath_bad_intr(dd, &unexpected);
750 ret = IRQ_NONE;
751 goto bail;
752 }
753 if (unexpected)
754 unexpected = 0;
755
756 ipath_cdbg(VERBOSE, "intr stat=0x%x\n", istat);
757
758 if (istat & ~infinipath_i_bitsextant)
759 ipath_dev_err(dd,
760 "interrupt with unknown interrupts %x set\n",
761 istat & (u32) ~ infinipath_i_bitsextant);
762
763 if (istat & INFINIPATH_I_ERROR) {
764 ipath_stats.sps_errints++;
765 estat = ipath_read_kreg64(dd,
766 dd->ipath_kregs->kr_errorstatus);
767 if (!estat)
768 dev_info(&dd->pcidev->dev, "error interrupt (%x), "
769 "but no error bits set!\n", istat);
770 else if (estat == -1LL)
771 /*
772 * should we try clearing all, or hope next read
773 * works?
774 */
775 ipath_dev_err(dd, "Read of error status failed "
776 "(all bits set); ignoring\n");
777 else
778 handle_errors(dd, estat);
779 }
780
781 if (istat & INFINIPATH_I_GPIO) {
782 if (unlikely(!(dd->ipath_flags & IPATH_GPIO_INTR))) {
783 u32 gpiostatus;
784 gpiostatus = ipath_read_kreg32(
785 dd, dd->ipath_kregs->kr_gpio_status);
786 ipath_dbg("Unexpected GPIO interrupt bits %x\n",
787 gpiostatus);
788 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
789 gpiostatus);
790 }
791 else {
792 /* Clear GPIO status bit 2 */
793 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_clear,
794 (u64) (1 << 2));
795
796 /*
797 * Packets are available in the port 0 rcv queue.
798 * Eventually this needs to be generalized to check
799 * IPATH_GPIO_INTR, and the specific GPIO bit, if
800 * GPIO interrupts are used for anything else.
801 */
802 ipath_kreceive(dd);
803 }
804 }
805
806 /*
807 * clear the ones we will deal with on this round
808 * We clear it early, mostly for receive interrupts, so we
809 * know the chip will have seen this by the time we process
810 * the queue, and will re-interrupt if necessary. The processor
811 * itself won't take the interrupt again until we return.
812 */
813 ipath_write_kreg(dd, dd->ipath_kregs->kr_intclear, istat);
814
815 if (istat & INFINIPATH_I_SPIOBUFAVAIL) {
816 clear_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
817 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
818 dd->ipath_sendctrl);
819
820 if (dd->ipath_portpiowait)
821 handle_port_pioavail(dd);
822
823 handle_layer_pioavail(dd);
824 }
825
826 /*
827 * we check for both transition from empty to non-empty, and urgent
828 * packets (those with the interrupt bit set in the header)
829 */
830
831 if (istat & ((infinipath_i_rcvavail_mask <<
832 INFINIPATH_I_RCVAVAIL_SHIFT)
833 | (infinipath_i_rcvurg_mask <<
834 INFINIPATH_I_RCVURG_SHIFT)))
835 handle_rcv(dd, istat);
836
837 ret = IRQ_HANDLED;
838
839bail:
840 return ret;
841}
diff --git a/drivers/infiniband/hw/ipath/ipath_kernel.h b/drivers/infiniband/hw/ipath/ipath_kernel.h
new file mode 100644
index 000000000000..159d0aed31a5
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h
@@ -0,0 +1,884 @@
1#ifndef _IPATH_KERNEL_H
2#define _IPATH_KERNEL_H
3/*
4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35/*
36 * This header file is the base header file for infinipath kernel code
37 * ipath_user.h serves a similar purpose for user code.
38 */
39
40#include <linux/interrupt.h>
41#include <asm/io.h>
42
43#include "ipath_common.h"
44#include "ipath_debug.h"
45#include "ipath_registers.h"
46
47/* only s/w major version of InfiniPath we can handle */
48#define IPATH_CHIP_VERS_MAJ 2U
49
50/* don't care about this except printing */
51#define IPATH_CHIP_VERS_MIN 0U
52
53/* temporary, maybe always */
54extern struct infinipath_stats ipath_stats;
55
56#define IPATH_CHIP_SWVERSION IPATH_CHIP_VERS_MAJ
57
58struct ipath_portdata {
59 void **port_rcvegrbuf;
60 dma_addr_t *port_rcvegrbuf_phys;
61 /* rcvhdrq base, needs mmap before useful */
62 void *port_rcvhdrq;
63 /* kernel virtual address where hdrqtail is updated */
64 u64 *port_rcvhdrtail_kvaddr;
65 /* page * used for uaddr */
66 struct page *port_rcvhdrtail_pagep;
67 /*
68 * temp buffer for expected send setup, allocated at open, instead
69 * of each setup call
70 */
71 void *port_tid_pg_list;
72 /* when waiting for rcv or pioavail */
73 wait_queue_head_t port_wait;
74 /*
75 * rcvegr bufs base, physical, must fit
76 * in 44 bits so 32 bit programs mmap64 44 bit works)
77 */
78 dma_addr_t port_rcvegr_phys;
79 /* mmap of hdrq, must fit in 44 bits */
80 dma_addr_t port_rcvhdrq_phys;
81 /*
82 * the actual user address that we ipath_mlock'ed, so we can
83 * ipath_munlock it at close
84 */
85 unsigned long port_rcvhdrtail_uaddr;
86 /*
87 * number of opens on this instance (0 or 1; ignoring forks, dup,
88 * etc. for now)
89 */
90 int port_cnt;
91 /*
92 * how much space to leave at start of eager TID entries for
93 * protocol use, on each TID
94 */
95 /* instead of calculating it */
96 unsigned port_port;
97 /* chip offset of PIO buffers for this port */
98 u32 port_piobufs;
99 /* how many alloc_pages() chunks in port_rcvegrbuf_pages */
100 u32 port_rcvegrbuf_chunks;
101 /* how many egrbufs per chunk */
102 u32 port_rcvegrbufs_perchunk;
103 /* order for port_rcvegrbuf_pages */
104 size_t port_rcvegrbuf_size;
105 /* rcvhdrq size (for freeing) */
106 size_t port_rcvhdrq_size;
107 /* next expected TID to check when looking for free */
108 u32 port_tidcursor;
109 /* next expected TID to check */
110 unsigned long port_flag;
111 /* WAIT_RCV that timed out, no interrupt */
112 u32 port_rcvwait_to;
113 /* WAIT_PIO that timed out, no interrupt */
114 u32 port_piowait_to;
115 /* WAIT_RCV already happened, no wait */
116 u32 port_rcvnowait;
117 /* WAIT_PIO already happened, no wait */
118 u32 port_pionowait;
119 /* total number of rcvhdrqfull errors */
120 u32 port_hdrqfull;
121 /* pid of process using this port */
122 pid_t port_pid;
123 /* same size as task_struct .comm[] */
124 char port_comm[16];
125 /* pkeys set by this use of this port */
126 u16 port_pkeys[4];
127 /* so file ops can get at unit */
128 struct ipath_devdata *port_dd;
129};
130
131struct sk_buff;
132
133/*
134 * control information for layered drivers
135 */
136struct _ipath_layer {
137 void *l_arg;
138};
139
140/* Verbs layer interface */
141struct _verbs_layer {
142 void *l_arg;
143 struct timer_list l_timer;
144};
145
146struct ipath_devdata {
147 struct list_head ipath_list;
148
149 struct ipath_kregs const *ipath_kregs;
150 struct ipath_cregs const *ipath_cregs;
151
152 /* mem-mapped pointer to base of chip regs */
153 u64 __iomem *ipath_kregbase;
154 /* end of mem-mapped chip space; range checking */
155 u64 __iomem *ipath_kregend;
156 /* physical address of chip for io_remap, etc. */
157 unsigned long ipath_physaddr;
158 /* base of memory alloced for ipath_kregbase, for free */
159 u64 *ipath_kregalloc;
160 /*
161 * version of kregbase that doesn't have high bits set (for 32 bit
162 * programs, so mmap64 44 bit works)
163 */
164 u64 __iomem *ipath_kregvirt;
165 /*
166 * virtual address where port0 rcvhdrqtail updated for this unit.
167 * only written to by the chip, not the driver.
168 */
169 volatile __le64 *ipath_hdrqtailptr;
170 dma_addr_t ipath_dma_addr;
171 /* ipath_cfgports pointers */
172 struct ipath_portdata **ipath_pd;
173 /* sk_buffs used by port 0 eager receive queue */
174 struct sk_buff **ipath_port0_skbs;
175 /* kvirt address of 1st 2k pio buffer */
176 void __iomem *ipath_pio2kbase;
177 /* kvirt address of 1st 4k pio buffer */
178 void __iomem *ipath_pio4kbase;
179 /*
180 * points to area where PIOavail registers will be DMA'ed.
181 * Has to be on a page of it's own, because the page will be
182 * mapped into user program space. This copy is *ONLY* ever
183 * written by DMA, not by the driver! Need a copy per device
184 * when we get to multiple devices
185 */
186 volatile __le64 *ipath_pioavailregs_dma;
187 /* physical address where updates occur */
188 dma_addr_t ipath_pioavailregs_phys;
189 struct _ipath_layer ipath_layer;
190 /* setup intr */
191 int (*ipath_f_intrsetup)(struct ipath_devdata *);
192 /* setup on-chip bus config */
193 int (*ipath_f_bus)(struct ipath_devdata *, struct pci_dev *);
194 /* hard reset chip */
195 int (*ipath_f_reset)(struct ipath_devdata *);
196 int (*ipath_f_get_boardname)(struct ipath_devdata *, char *,
197 size_t);
198 void (*ipath_f_init_hwerrors)(struct ipath_devdata *);
199 void (*ipath_f_handle_hwerrors)(struct ipath_devdata *, char *,
200 size_t);
201 void (*ipath_f_quiet_serdes)(struct ipath_devdata *);
202 int (*ipath_f_bringup_serdes)(struct ipath_devdata *);
203 int (*ipath_f_early_init)(struct ipath_devdata *);
204 void (*ipath_f_clear_tids)(struct ipath_devdata *, unsigned);
205 void (*ipath_f_put_tid)(struct ipath_devdata *, u64 __iomem*,
206 u32, unsigned long);
207 void (*ipath_f_tidtemplate)(struct ipath_devdata *);
208 void (*ipath_f_cleanup)(struct ipath_devdata *);
209 void (*ipath_f_setextled)(struct ipath_devdata *, u64, u64);
210 /* fill out chip-specific fields */
211 int (*ipath_f_get_base_info)(struct ipath_portdata *, void *);
212 struct _verbs_layer verbs_layer;
213 /* total dwords sent (summed from counter) */
214 u64 ipath_sword;
215 /* total dwords rcvd (summed from counter) */
216 u64 ipath_rword;
217 /* total packets sent (summed from counter) */
218 u64 ipath_spkts;
219 /* total packets rcvd (summed from counter) */
220 u64 ipath_rpkts;
221 /* ipath_statusp initially points to this. */
222 u64 _ipath_status;
223 /* GUID for this interface, in network order */
224 __be64 ipath_guid;
225 /*
226 * aggregrate of error bits reported since last cleared, for
227 * limiting of error reporting
228 */
229 ipath_err_t ipath_lasterror;
230 /*
231 * aggregrate of error bits reported since last cleared, for
232 * limiting of hwerror reporting
233 */
234 ipath_err_t ipath_lasthwerror;
235 /*
236 * errors masked because they occur too fast, also includes errors
237 * that are always ignored (ipath_ignorederrs)
238 */
239 ipath_err_t ipath_maskederrs;
240 /* time in jiffies at which to re-enable maskederrs */
241 unsigned long ipath_unmasktime;
242 /*
243 * errors always ignored (masked), at least for a given
244 * chip/device, because they are wrong or not useful
245 */
246 ipath_err_t ipath_ignorederrs;
247 /* count of egrfull errors, combined for all ports */
248 u64 ipath_last_tidfull;
249 /* for ipath_qcheck() */
250 u64 ipath_lastport0rcv_cnt;
251 /* template for writing TIDs */
252 u64 ipath_tidtemplate;
253 /* value to write to free TIDs */
254 u64 ipath_tidinvalid;
255 /* PE-800 rcv interrupt setup */
256 u64 ipath_rhdrhead_intr_off;
257
258 /* size of memory at ipath_kregbase */
259 u32 ipath_kregsize;
260 /* number of registers used for pioavail */
261 u32 ipath_pioavregs;
262 /* IPATH_POLL, etc. */
263 u32 ipath_flags;
264 /* ipath_flags sma is waiting for */
265 u32 ipath_sma_state_wanted;
266 /* last buffer for user use, first buf for kernel use is this
267 * index. */
268 u32 ipath_lastport_piobuf;
269 /* is a stats timer active */
270 u32 ipath_stats_timer_active;
271 /* dwords sent read from counter */
272 u32 ipath_lastsword;
273 /* dwords received read from counter */
274 u32 ipath_lastrword;
275 /* sent packets read from counter */
276 u32 ipath_lastspkts;
277 /* received packets read from counter */
278 u32 ipath_lastrpkts;
279 /* pio bufs allocated per port */
280 u32 ipath_pbufsport;
281 /*
282 * number of ports configured as max; zero is set to number chip
283 * supports, less gives more pio bufs/port, etc.
284 */
285 u32 ipath_cfgports;
286 /* port0 rcvhdrq head offset */
287 u32 ipath_port0head;
288 /* count of port 0 hdrqfull errors */
289 u32 ipath_p0_hdrqfull;
290
291 /*
292 * (*cfgports) used to suppress multiple instances of same
293 * port staying stuck at same point
294 */
295 u32 *ipath_lastrcvhdrqtails;
296 /*
297 * (*cfgports) used to suppress multiple instances of same
298 * port staying stuck at same point
299 */
300 u32 *ipath_lastegrheads;
301 /*
302 * index of last piobuffer we used. Speeds up searching, by
303 * starting at this point. Doesn't matter if multiple cpu's use and
304 * update, last updater is only write that matters. Whenever it
305 * wraps, we update shadow copies. Need a copy per device when we
306 * get to multiple devices
307 */
308 u32 ipath_lastpioindex;
309 /* max length of freezemsg */
310 u32 ipath_freezelen;
311 /*
312 * consecutive times we wanted a PIO buffer but were unable to
313 * get one
314 */
315 u32 ipath_consec_nopiobuf;
316 /*
317 * hint that we should update ipath_pioavailshadow before
318 * looking for a PIO buffer
319 */
320 u32 ipath_upd_pio_shadow;
321 /* so we can rewrite it after a chip reset */
322 u32 ipath_pcibar0;
323 /* so we can rewrite it after a chip reset */
324 u32 ipath_pcibar1;
325 /* sequential tries for SMA send and no bufs */
326 u32 ipath_nosma_bufs;
327 /* duration (seconds) ipath_nosma_bufs set */
328 u32 ipath_nosma_secs;
329
330 /* HT/PCI Vendor ID (here for NodeInfo) */
331 u16 ipath_vendorid;
332 /* HT/PCI Device ID (here for NodeInfo) */
333 u16 ipath_deviceid;
334 /* offset in HT config space of slave/primary interface block */
335 u8 ipath_ht_slave_off;
336 /* for write combining settings */
337 unsigned long ipath_wc_cookie;
338 /* ref count for each pkey */
339 atomic_t ipath_pkeyrefs[4];
340 /* shadow copy of all exptids physaddr; used only by funcsim */
341 u64 *ipath_tidsimshadow;
342 /* shadow copy of struct page *'s for exp tid pages */
343 struct page **ipath_pageshadow;
344 /* lock to workaround chip bug 9437 */
345 spinlock_t ipath_tid_lock;
346
347 /*
348 * IPATH_STATUS_*,
349 * this address is mapped readonly into user processes so they can
350 * get status cheaply, whenever they want.
351 */
352 u64 *ipath_statusp;
353 /* freeze msg if hw error put chip in freeze */
354 char *ipath_freezemsg;
355 /* pci access data structure */
356 struct pci_dev *pcidev;
357 struct cdev *cdev;
358 struct class_device *class_dev;
359 /* timer used to prevent stats overflow, error throttling, etc. */
360 struct timer_list ipath_stats_timer;
361 /* check for stale messages in rcv queue */
362 /* only allow one intr at a time. */
363 unsigned long ipath_rcv_pending;
364
365 /*
366 * Shadow copies of registers; size indicates read access size.
367 * Most of them are readonly, but some are write-only register,
368 * where we manipulate the bits in the shadow copy, and then write
369 * the shadow copy to infinipath.
370 *
371 * We deliberately make most of these 32 bits, since they have
372 * restricted range. For any that we read, we won't to generate 32
373 * bit accesses, since Opteron will generate 2 separate 32 bit HT
374 * transactions for a 64 bit read, and we want to avoid unnecessary
375 * HT transactions.
376 */
377
378 /* This is the 64 bit group */
379
380 /*
381 * shadow of pioavail, check to be sure it's large enough at
382 * init time.
383 */
384 unsigned long ipath_pioavailshadow[8];
385 /* shadow of kr_gpio_out, for rmw ops */
386 u64 ipath_gpio_out;
387 /* kr_revision shadow */
388 u64 ipath_revision;
389 /*
390 * shadow of ibcctrl, for interrupt handling of link changes,
391 * etc.
392 */
393 u64 ipath_ibcctrl;
394 /*
395 * last ibcstatus, to suppress "duplicate" status change messages,
396 * mostly from 2 to 3
397 */
398 u64 ipath_lastibcstat;
399 /* hwerrmask shadow */
400 ipath_err_t ipath_hwerrmask;
401 /* interrupt config reg shadow */
402 u64 ipath_intconfig;
403 /* kr_sendpiobufbase value */
404 u64 ipath_piobufbase;
405
406 /* these are the "32 bit" regs */
407
408 /*
409 * number of GUIDs in the flash for this interface; may need some
410 * rethinking for setting on other ifaces
411 */
412 u32 ipath_nguid;
413 /*
414 * the following two are 32-bit bitmasks, but {test,clear,set}_bit
415 * all expect bit fields to be "unsigned long"
416 */
417 /* shadow kr_rcvctrl */
418 unsigned long ipath_rcvctrl;
419 /* shadow kr_sendctrl */
420 unsigned long ipath_sendctrl;
421
422 /* value we put in kr_rcvhdrcnt */
423 u32 ipath_rcvhdrcnt;
424 /* value we put in kr_rcvhdrsize */
425 u32 ipath_rcvhdrsize;
426 /* value we put in kr_rcvhdrentsize */
427 u32 ipath_rcvhdrentsize;
428 /* offset of last entry in rcvhdrq */
429 u32 ipath_hdrqlast;
430 /* kr_portcnt value */
431 u32 ipath_portcnt;
432 /* kr_pagealign value */
433 u32 ipath_palign;
434 /* number of "2KB" PIO buffers */
435 u32 ipath_piobcnt2k;
436 /* size in bytes of "2KB" PIO buffers */
437 u32 ipath_piosize2k;
438 /* number of "4KB" PIO buffers */
439 u32 ipath_piobcnt4k;
440 /* size in bytes of "4KB" PIO buffers */
441 u32 ipath_piosize4k;
442 /* kr_rcvegrbase value */
443 u32 ipath_rcvegrbase;
444 /* kr_rcvegrcnt value */
445 u32 ipath_rcvegrcnt;
446 /* kr_rcvtidbase value */
447 u32 ipath_rcvtidbase;
448 /* kr_rcvtidcnt value */
449 u32 ipath_rcvtidcnt;
450 /* kr_sendregbase */
451 u32 ipath_sregbase;
452 /* kr_userregbase */
453 u32 ipath_uregbase;
454 /* kr_counterregbase */
455 u32 ipath_cregbase;
456 /* shadow the control register contents */
457 u32 ipath_control;
458 /* shadow the gpio output contents */
459 u32 ipath_extctrl;
460 /* PCI revision register (HTC rev on FPGA) */
461 u32 ipath_pcirev;
462
463 /* chip address space used by 4k pio buffers */
464 u32 ipath_4kalign;
465 /* The MTU programmed for this unit */
466 u32 ipath_ibmtu;
467 /*
468 * The max size IB packet, included IB headers that we can send.
469 * Starts same as ipath_piosize, but is affected when ibmtu is
470 * changed, or by size of eager buffers
471 */
472 u32 ipath_ibmaxlen;
473 /*
474 * ibmaxlen at init time, limited by chip and by receive buffer
475 * size. Not changed after init.
476 */
477 u32 ipath_init_ibmaxlen;
478 /* size of each rcvegrbuffer */
479 u32 ipath_rcvegrbufsize;
480 /* width (2,4,8,16,32) from HT config reg */
481 u32 ipath_htwidth;
482 /* HT speed (200,400,800,1000) from HT config */
483 u32 ipath_htspeed;
484 /* ports waiting for PIOavail intr */
485 unsigned long ipath_portpiowait;
486 /*
487 * number of sequential ibcstatus change for polling active/quiet
488 * (i.e., link not coming up).
489 */
490 u32 ipath_ibpollcnt;
491 /* low and high portions of MSI capability/vector */
492 u32 ipath_msi_lo;
493 /* saved after PCIe init for restore after reset */
494 u32 ipath_msi_hi;
495 /* MSI data (vector) saved for restore */
496 u16 ipath_msi_data;
497 /* MLID programmed for this instance */
498 u16 ipath_mlid;
499 /* LID programmed for this instance */
500 u16 ipath_lid;
501 /* list of pkeys programmed; 0 if not set */
502 u16 ipath_pkeys[4];
503 /* ASCII serial number, from flash */
504 u8 ipath_serial[12];
505 /* human readable board version */
506 u8 ipath_boardversion[80];
507 /* chip major rev, from ipath_revision */
508 u8 ipath_majrev;
509 /* chip minor rev, from ipath_revision */
510 u8 ipath_minrev;
511 /* board rev, from ipath_revision */
512 u8 ipath_boardrev;
513 /* unit # of this chip, if present */
514 int ipath_unit;
515 /* saved for restore after reset */
516 u8 ipath_pci_cacheline;
517 /* LID mask control */
518 u8 ipath_lmc;
519};
520
521extern volatile __le64 *ipath_port0_rcvhdrtail;
522extern dma_addr_t ipath_port0_rcvhdrtail_dma;
523
524#define IPATH_PORT0_RCVHDRTAIL_SIZE PAGE_SIZE
525
526extern struct list_head ipath_dev_list;
527extern spinlock_t ipath_devs_lock;
528extern struct ipath_devdata *ipath_lookup(int unit);
529
530extern u16 ipath_layer_rcv_opcode;
531extern int ipath_verbs_registered;
532extern int __ipath_layer_intr(struct ipath_devdata *, u32);
533extern int ipath_layer_intr(struct ipath_devdata *, u32);
534extern int __ipath_layer_rcv(struct ipath_devdata *, void *,
535 struct sk_buff *);
536extern int __ipath_layer_rcv_lid(struct ipath_devdata *, void *);
537extern int __ipath_verbs_piobufavail(struct ipath_devdata *);
538extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);
539
540void ipath_layer_add(struct ipath_devdata *);
541void ipath_layer_del(struct ipath_devdata *);
542
543int ipath_init_chip(struct ipath_devdata *, int);
544int ipath_enable_wc(struct ipath_devdata *dd);
545void ipath_disable_wc(struct ipath_devdata *dd);
546int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
547void ipath_shutdown_device(struct ipath_devdata *);
548
549struct file_operations;
550int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
551 struct cdev **cdevp, struct class_device **class_devp);
552void ipath_cdev_cleanup(struct cdev **cdevp,
553 struct class_device **class_devp);
554
555int ipath_diag_init(void);
556void ipath_diag_cleanup(void);
557void ipath_diag_bringup_link(struct ipath_devdata *);
558
559extern wait_queue_head_t ipath_sma_state_wait;
560
561int ipath_user_add(struct ipath_devdata *dd);
562void ipath_user_del(struct ipath_devdata *dd);
563
564struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
565
566extern int ipath_diag_inuse;
567
568irqreturn_t ipath_intr(int irq, void *devid, struct pt_regs *regs);
569void ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
570#if __IPATH_INFO || __IPATH_DBG
571extern const char *ipath_ibcstatus_str[];
572#endif
573
574/* clean up any per-chip chip-specific stuff */
575void ipath_chip_cleanup(struct ipath_devdata *);
576/* clean up any chip type-specific stuff */
577void ipath_chip_done(void);
578
579/* check to see if we have to force ordering for write combining */
580int ipath_unordered_wc(void);
581
582void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
583 unsigned cnt);
584
585int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
586void ipath_free_pddata(struct ipath_devdata *, u32, int);
587
588int ipath_parse_ushort(const char *str, unsigned short *valp);
589
590int ipath_wait_linkstate(struct ipath_devdata *, u32, int);
591void ipath_set_ib_lstate(struct ipath_devdata *, int);
592void ipath_kreceive(struct ipath_devdata *);
593int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
594int ipath_reset_device(int);
595void ipath_get_faststats(unsigned long);
596
597/* for use in system calls, where we want to know device type, etc. */
598#define port_fp(fp) ((struct ipath_portdata *) (fp)->private_data)
599
600/*
601 * values for ipath_flags
602 */
603/* The chip is up and initted */
604#define IPATH_INITTED 0x2
605 /* set if any user code has set kr_rcvhdrsize */
606#define IPATH_RCVHDRSZ_SET 0x4
607 /* The chip is present and valid for accesses */
608#define IPATH_PRESENT 0x8
609 /* HT link0 is only 8 bits wide, ignore upper byte crc
610 * errors, etc. */
611#define IPATH_8BIT_IN_HT0 0x10
612 /* HT link1 is only 8 bits wide, ignore upper byte crc
613 * errors, etc. */
614#define IPATH_8BIT_IN_HT1 0x20
615 /* The link is down */
616#define IPATH_LINKDOWN 0x40
617 /* The link level is up (0x11) */
618#define IPATH_LINKINIT 0x80
619 /* The link is in the armed (0x21) state */
620#define IPATH_LINKARMED 0x100
621 /* The link is in the active (0x31) state */
622#define IPATH_LINKACTIVE 0x200
623 /* link current state is unknown */
624#define IPATH_LINKUNK 0x400
625 /* no IB cable, or no device on IB cable */
626#define IPATH_NOCABLE 0x4000
627 /* Supports port zero per packet receive interrupts via
628 * GPIO */
629#define IPATH_GPIO_INTR 0x8000
630 /* uses the coded 4byte TID, not 8 byte */
631#define IPATH_4BYTE_TID 0x10000
632 /* packet/word counters are 32 bit, else those 4 counters
633 * are 64bit */
634#define IPATH_32BITCOUNTERS 0x20000
635 /* can miss port0 rx interrupts */
636#define IPATH_POLL_RX_INTR 0x40000
637#define IPATH_DISABLED 0x80000 /* administratively disabled */
638
639/* portdata flag bit offsets */
640 /* waiting for a packet to arrive */
641#define IPATH_PORT_WAITING_RCV 2
642 /* waiting for a PIO buffer to be available */
643#define IPATH_PORT_WAITING_PIO 3
644
645/* free up any allocated data at closes */
646void ipath_free_data(struct ipath_portdata *dd);
647int ipath_waitfor_mdio_cmdready(struct ipath_devdata *);
648int ipath_waitfor_complete(struct ipath_devdata *, ipath_kreg, u64, u64 *);
649u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
650/* init PE-800-specific func */
651void ipath_init_pe800_funcs(struct ipath_devdata *);
652/* init HT-400-specific func */
653void ipath_init_ht400_funcs(struct ipath_devdata *);
654void ipath_get_guid(struct ipath_devdata *);
655u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
656
657/*
658 * number of words used for protocol header if not set by ipath_userinit();
659 */
660#define IPATH_DFLT_RCVHDRSIZE 9
661
662#define IPATH_MDIO_CMD_WRITE 1
663#define IPATH_MDIO_CMD_READ 2
664#define IPATH_MDIO_CLD_DIV 25 /* to get 2.5 Mhz mdio clock */
665#define IPATH_MDIO_CMDVALID 0x40000000 /* bit 30 */
666#define IPATH_MDIO_DATAVALID 0x80000000 /* bit 31 */
667#define IPATH_MDIO_CTRL_STD 0x0
668
669static inline u64 ipath_mdio_req(int cmd, int dev, int reg, int data)
670{
671 return (((u64) IPATH_MDIO_CLD_DIV) << 32) |
672 (cmd << 26) |
673 (dev << 21) |
674 (reg << 16) |
675 (data & 0xFFFF);
676}
677
678 /* signal and fifo status, in bank 31 */
679#define IPATH_MDIO_CTRL_XGXS_REG_8 0x8
680 /* controls loopback, redundancy */
681#define IPATH_MDIO_CTRL_8355_REG_1 0x10
682 /* premph, encdec, etc. */
683#define IPATH_MDIO_CTRL_8355_REG_2 0x11
684 /* Kchars, etc. */
685#define IPATH_MDIO_CTRL_8355_REG_6 0x15
686#define IPATH_MDIO_CTRL_8355_REG_9 0x18
687#define IPATH_MDIO_CTRL_8355_REG_10 0x1D
688
689int ipath_get_user_pages(unsigned long, size_t, struct page **);
690int ipath_get_user_pages_nocopy(unsigned long, struct page **);
691void ipath_release_user_pages(struct page **, size_t);
692void ipath_release_user_pages_on_close(struct page **, size_t);
693int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
694int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
695
696/* these are used for the registers that vary with port */
697void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
698 unsigned, u64);
699u64 ipath_read_kreg64_port(const struct ipath_devdata *, ipath_kreg,
700 unsigned);
701
702/*
703 * We could have a single register get/put routine, that takes a group type,
704 * but this is somewhat clearer and cleaner. It also gives us some error
705 * checking. 64 bit register reads should always work, but are inefficient
706 * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
707 * so we use kreg32 wherever possible. User register and counter register
708 * reads are always 32 bit reads, so only one form of those routines.
709 */
710
711/*
712 * At the moment, none of the s-registers are writable, so no
713 * ipath_write_sreg(), and none of the c-registers are writable, so no
714 * ipath_write_creg().
715 */
716
717/**
718 * ipath_read_ureg32 - read 32-bit virtualized per-port register
719 * @dd: device
720 * @regno: register number
721 * @port: port number
722 *
723 * Return the contents of a register that is virtualized to be per port.
724 * Prints a debug message and returns -1 on errors (not distinguishable from
725 * valid contents at runtime; we may add a separate error variable at some
726 * point).
727 *
728 * This is normally not used by the kernel, but may be for debugging, and
729 * has a different implementation than user mode, which is why it's not in
730 * _common.h.
731 */
732static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
733 ipath_ureg regno, int port)
734{
735 if (!dd->ipath_kregbase)
736 return 0;
737
738 return readl(regno + (u64 __iomem *)
739 (dd->ipath_uregbase +
740 (char __iomem *)dd->ipath_kregbase +
741 dd->ipath_palign * port));
742}
743
744/**
745 * ipath_write_ureg - write 32-bit virtualized per-port register
746 * @dd: device
747 * @regno: register number
748 * @value: value
749 * @port: port
750 *
751 * Write the contents of a register that is virtualized to be per port.
752 */
753static inline void ipath_write_ureg(const struct ipath_devdata *dd,
754 ipath_ureg regno, u64 value, int port)
755{
756 u64 __iomem *ubase = (u64 __iomem *)
757 (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
758 dd->ipath_palign * port);
759 if (dd->ipath_kregbase)
760 writeq(value, &ubase[regno]);
761}
762
763static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
764 ipath_kreg regno)
765{
766 if (!dd->ipath_kregbase)
767 return -1;
768 return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
769}
770
771static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
772 ipath_kreg regno)
773{
774 if (!dd->ipath_kregbase)
775 return -1;
776
777 return readq(&dd->ipath_kregbase[regno]);
778}
779
780static inline void ipath_write_kreg(const struct ipath_devdata *dd,
781 ipath_kreg regno, u64 value)
782{
783 if (dd->ipath_kregbase)
784 writeq(value, &dd->ipath_kregbase[regno]);
785}
786
787static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
788 ipath_sreg regno)
789{
790 if (!dd->ipath_kregbase)
791 return 0;
792
793 return readq(regno + (u64 __iomem *)
794 (dd->ipath_cregbase +
795 (char __iomem *)dd->ipath_kregbase));
796}
797
798static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
799 ipath_sreg regno)
800{
801 if (!dd->ipath_kregbase)
802 return 0;
803 return readl(regno + (u64 __iomem *)
804 (dd->ipath_cregbase +
805 (char __iomem *)dd->ipath_kregbase));
806}
807
808/*
809 * sysfs interface.
810 */
811
812struct device_driver;
813
814extern const char ipath_core_version[];
815
816int ipath_driver_create_group(struct device_driver *);
817void ipath_driver_remove_group(struct device_driver *);
818
819int ipath_device_create_group(struct device *, struct ipath_devdata *);
820void ipath_device_remove_group(struct device *, struct ipath_devdata *);
821int ipath_expose_reset(struct device *);
822
823int ipath_init_ipathfs(void);
824void ipath_exit_ipathfs(void);
825int ipathfs_add_device(struct ipath_devdata *);
826int ipathfs_remove_device(struct ipath_devdata *);
827
828/*
829 * Flush write combining store buffers (if present) and perform a write
830 * barrier.
831 */
832#if defined(CONFIG_X86_64)
833#define ipath_flush_wc() asm volatile("sfence" ::: "memory")
834#else
835#define ipath_flush_wc() wmb()
836#endif
837
838extern unsigned ipath_debug; /* debugging bit mask */
839
840const char *ipath_get_unit_name(int unit);
841
842extern struct mutex ipath_mutex;
843
844#define IPATH_DRV_NAME "ipath_core"
845#define IPATH_MAJOR 233
846#define IPATH_SMA_MINOR 128
847#define IPATH_DIAG_MINOR 129
848#define IPATH_NMINORS 130
849
850#define ipath_dev_err(dd,fmt,...) \
851 do { \
852 const struct ipath_devdata *__dd = (dd); \
853 if (__dd->pcidev) \
854 dev_err(&__dd->pcidev->dev, "%s: " fmt, \
855 ipath_get_unit_name(__dd->ipath_unit), \
856 ##__VA_ARGS__); \
857 else \
858 printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
859 ipath_get_unit_name(__dd->ipath_unit), \
860 ##__VA_ARGS__); \
861 } while (0)
862
863#if _IPATH_DEBUGGING
864
865# define __IPATH_DBG_WHICH(which,fmt,...) \
866 do { \
867 if(unlikely(ipath_debug&(which))) \
868 printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
869 __func__,##__VA_ARGS__); \
870 } while(0)
871
872# define ipath_dbg(fmt,...) \
873 __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
874# define ipath_cdbg(which,fmt,...) \
875 __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
876
877#else /* ! _IPATH_DEBUGGING */
878
879# define ipath_dbg(fmt,...)
880# define ipath_cdbg(which,fmt,...)
881
882#endif /* _IPATH_DEBUGGING */
883
884#endif /* _IPATH_KERNEL_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_keys.c b/drivers/infiniband/hw/ipath/ipath_keys.c
new file mode 100644
index 000000000000..aa33b0e9f2f6
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_keys.c
@@ -0,0 +1,236 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <asm/io.h>
34
35#include "ipath_verbs.h"
36
37/**
38 * ipath_alloc_lkey - allocate an lkey
39 * @rkt: lkey table in which to allocate the lkey
40 * @mr: memory region that this lkey protects
41 *
42 * Returns 1 if successful, otherwise returns 0.
43 */
44
45int ipath_alloc_lkey(struct ipath_lkey_table *rkt, struct ipath_mregion *mr)
46{
47 unsigned long flags;
48 u32 r;
49 u32 n;
50 int ret;
51
52 spin_lock_irqsave(&rkt->lock, flags);
53
54 /* Find the next available LKEY */
55 r = n = rkt->next;
56 for (;;) {
57 if (rkt->table[r] == NULL)
58 break;
59 r = (r + 1) & (rkt->max - 1);
60 if (r == n) {
61 spin_unlock_irqrestore(&rkt->lock, flags);
62 _VERBS_INFO("LKEY table full\n");
63 ret = 0;
64 goto bail;
65 }
66 }
67 rkt->next = (r + 1) & (rkt->max - 1);
68 /*
69 * Make sure lkey is never zero which is reserved to indicate an
70 * unrestricted LKEY.
71 */
72 rkt->gen++;
73 mr->lkey = (r << (32 - ib_ipath_lkey_table_size)) |
74 ((((1 << (24 - ib_ipath_lkey_table_size)) - 1) & rkt->gen)
75 << 8);
76 if (mr->lkey == 0) {
77 mr->lkey |= 1 << 8;
78 rkt->gen++;
79 }
80 rkt->table[r] = mr;
81 spin_unlock_irqrestore(&rkt->lock, flags);
82
83 ret = 1;
84
85bail:
86 return ret;
87}
88
89/**
90 * ipath_free_lkey - free an lkey
91 * @rkt: table from which to free the lkey
92 * @lkey: lkey id to free
93 */
94void ipath_free_lkey(struct ipath_lkey_table *rkt, u32 lkey)
95{
96 unsigned long flags;
97 u32 r;
98
99 if (lkey == 0)
100 return;
101 r = lkey >> (32 - ib_ipath_lkey_table_size);
102 spin_lock_irqsave(&rkt->lock, flags);
103 rkt->table[r] = NULL;
104 spin_unlock_irqrestore(&rkt->lock, flags);
105}
106
107/**
108 * ipath_lkey_ok - check IB SGE for validity and initialize
109 * @rkt: table containing lkey to check SGE against
110 * @isge: outgoing internal SGE
111 * @sge: SGE to check
112 * @acc: access flags
113 *
114 * Return 1 if valid and successful, otherwise returns 0.
115 *
116 * Check the IB SGE for validity and initialize our internal version
117 * of it.
118 */
119int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge,
120 struct ib_sge *sge, int acc)
121{
122 struct ipath_mregion *mr;
123 size_t off;
124 int ret;
125
126 /*
127 * We use LKEY == zero to mean a physical kmalloc() address.
128 * This is a bit of a hack since we rely on dma_map_single()
129 * being reversible by calling bus_to_virt().
130 */
131 if (sge->lkey == 0) {
132 isge->mr = NULL;
133 isge->vaddr = bus_to_virt(sge->addr);
134 isge->length = sge->length;
135 isge->sge_length = sge->length;
136 ret = 1;
137 goto bail;
138 }
139 spin_lock(&rkt->lock);
140 mr = rkt->table[(sge->lkey >> (32 - ib_ipath_lkey_table_size))];
141 spin_unlock(&rkt->lock);
142 if (unlikely(mr == NULL || mr->lkey != sge->lkey)) {
143 ret = 0;
144 goto bail;
145 }
146
147 off = sge->addr - mr->user_base;
148 if (unlikely(sge->addr < mr->user_base ||
149 off + sge->length > mr->length ||
150 (mr->access_flags & acc) != acc)) {
151 ret = 0;
152 goto bail;
153 }
154
155 off += mr->offset;
156 isge->mr = mr;
157 isge->m = 0;
158 isge->n = 0;
159 while (off >= mr->map[isge->m]->segs[isge->n].length) {
160 off -= mr->map[isge->m]->segs[isge->n].length;
161 isge->n++;
162 if (isge->n >= IPATH_SEGSZ) {
163 isge->m++;
164 isge->n = 0;
165 }
166 }
167 isge->vaddr = mr->map[isge->m]->segs[isge->n].vaddr + off;
168 isge->length = mr->map[isge->m]->segs[isge->n].length - off;
169 isge->sge_length = sge->length;
170
171 ret = 1;
172
173bail:
174 return ret;
175}
176
177/**
178 * ipath_rkey_ok - check the IB virtual address, length, and RKEY
179 * @dev: infiniband device
180 * @ss: SGE state
181 * @len: length of data
182 * @vaddr: virtual address to place data
183 * @rkey: rkey to check
184 * @acc: access flags
185 *
186 * Return 1 if successful, otherwise 0.
187 *
188 * The QP r_rq.lock should be held.
189 */
190int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss,
191 u32 len, u64 vaddr, u32 rkey, int acc)
192{
193 struct ipath_lkey_table *rkt = &dev->lk_table;
194 struct ipath_sge *sge = &ss->sge;
195 struct ipath_mregion *mr;
196 size_t off;
197 int ret;
198
199 spin_lock(&rkt->lock);
200 mr = rkt->table[(rkey >> (32 - ib_ipath_lkey_table_size))];
201 spin_unlock(&rkt->lock);
202 if (unlikely(mr == NULL || mr->lkey != rkey)) {
203 ret = 0;
204 goto bail;
205 }
206
207 off = vaddr - mr->iova;
208 if (unlikely(vaddr < mr->iova || off + len > mr->length ||
209 (mr->access_flags & acc) == 0)) {
210 ret = 0;
211 goto bail;
212 }
213
214 off += mr->offset;
215 sge->mr = mr;
216 sge->m = 0;
217 sge->n = 0;
218 while (off >= mr->map[sge->m]->segs[sge->n].length) {
219 off -= mr->map[sge->m]->segs[sge->n].length;
220 sge->n++;
221 if (sge->n >= IPATH_SEGSZ) {
222 sge->m++;
223 sge->n = 0;
224 }
225 }
226 sge->vaddr = mr->map[sge->m]->segs[sge->n].vaddr + off;
227 sge->length = mr->map[sge->m]->segs[sge->n].length - off;
228 sge->sge_length = len;
229 ss->sg_list = NULL;
230 ss->num_sge = 1;
231
232 ret = 1;
233
234bail:
235 return ret;
236}
diff --git a/drivers/infiniband/hw/ipath/ipath_layer.c b/drivers/infiniband/hw/ipath/ipath_layer.c
new file mode 100644
index 000000000000..2cabf6340572
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_layer.c
@@ -0,0 +1,1515 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33/*
34 * These are the routines used by layered drivers, currently just the
35 * layered ethernet driver and verbs layer.
36 */
37
38#include <linux/io.h>
39#include <linux/pci.h>
40#include <asm/byteorder.h>
41
42#include "ipath_kernel.h"
43#include "ips_common.h"
44#include "ipath_layer.h"
45
46/* Acquire before ipath_devs_lock. */
47static DEFINE_MUTEX(ipath_layer_mutex);
48
49u16 ipath_layer_rcv_opcode;
50static int (*layer_intr)(void *, u32);
51static int (*layer_rcv)(void *, void *, struct sk_buff *);
52static int (*layer_rcv_lid)(void *, void *);
53static int (*verbs_piobufavail)(void *);
54static void (*verbs_rcv)(void *, void *, void *, u32);
55int ipath_verbs_registered;
56
57static void *(*layer_add_one)(int, struct ipath_devdata *);
58static void (*layer_remove_one)(void *);
59static void *(*verbs_add_one)(int, struct ipath_devdata *);
60static void (*verbs_remove_one)(void *);
61static void (*verbs_timer_cb)(void *);
62
63int __ipath_layer_intr(struct ipath_devdata *dd, u32 arg)
64{
65 int ret = -ENODEV;
66
67 if (dd->ipath_layer.l_arg && layer_intr)
68 ret = layer_intr(dd->ipath_layer.l_arg, arg);
69
70 return ret;
71}
72
73int ipath_layer_intr(struct ipath_devdata *dd, u32 arg)
74{
75 int ret;
76
77 mutex_lock(&ipath_layer_mutex);
78
79 ret = __ipath_layer_intr(dd, arg);
80
81 mutex_unlock(&ipath_layer_mutex);
82
83 return ret;
84}
85
86int __ipath_layer_rcv(struct ipath_devdata *dd, void *hdr,
87 struct sk_buff *skb)
88{
89 int ret = -ENODEV;
90
91 if (dd->ipath_layer.l_arg && layer_rcv)
92 ret = layer_rcv(dd->ipath_layer.l_arg, hdr, skb);
93
94 return ret;
95}
96
97int __ipath_layer_rcv_lid(struct ipath_devdata *dd, void *hdr)
98{
99 int ret = -ENODEV;
100
101 if (dd->ipath_layer.l_arg && layer_rcv_lid)
102 ret = layer_rcv_lid(dd->ipath_layer.l_arg, hdr);
103
104 return ret;
105}
106
107int __ipath_verbs_piobufavail(struct ipath_devdata *dd)
108{
109 int ret = -ENODEV;
110
111 if (dd->verbs_layer.l_arg && verbs_piobufavail)
112 ret = verbs_piobufavail(dd->verbs_layer.l_arg);
113
114 return ret;
115}
116
117int __ipath_verbs_rcv(struct ipath_devdata *dd, void *rc, void *ebuf,
118 u32 tlen)
119{
120 int ret = -ENODEV;
121
122 if (dd->verbs_layer.l_arg && verbs_rcv) {
123 verbs_rcv(dd->verbs_layer.l_arg, rc, ebuf, tlen);
124 ret = 0;
125 }
126
127 return ret;
128}
129
130int ipath_layer_set_linkstate(struct ipath_devdata *dd, u8 newstate)
131{
132 u32 lstate;
133 int ret;
134
135 switch (newstate) {
136 case IPATH_IB_LINKDOWN:
137 ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKINITCMD_POLL <<
138 INFINIPATH_IBCC_LINKINITCMD_SHIFT);
139 /* don't wait */
140 ret = 0;
141 goto bail;
142
143 case IPATH_IB_LINKDOWN_SLEEP:
144 ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKINITCMD_SLEEP <<
145 INFINIPATH_IBCC_LINKINITCMD_SHIFT);
146 /* don't wait */
147 ret = 0;
148 goto bail;
149
150 case IPATH_IB_LINKDOWN_DISABLE:
151 ipath_set_ib_lstate(dd,
152 INFINIPATH_IBCC_LINKINITCMD_DISABLE <<
153 INFINIPATH_IBCC_LINKINITCMD_SHIFT);
154 /* don't wait */
155 ret = 0;
156 goto bail;
157
158 case IPATH_IB_LINKINIT:
159 if (dd->ipath_flags & IPATH_LINKINIT) {
160 ret = 0;
161 goto bail;
162 }
163 ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_INIT <<
164 INFINIPATH_IBCC_LINKCMD_SHIFT);
165 lstate = IPATH_LINKINIT;
166 break;
167
168 case IPATH_IB_LINKARM:
169 if (dd->ipath_flags & IPATH_LINKARMED) {
170 ret = 0;
171 goto bail;
172 }
173 if (!(dd->ipath_flags &
174 (IPATH_LINKINIT | IPATH_LINKACTIVE))) {
175 ret = -EINVAL;
176 goto bail;
177 }
178 ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_ARMED <<
179 INFINIPATH_IBCC_LINKCMD_SHIFT);
180 /*
181 * Since the port can transition to ACTIVE by receiving
182 * a non VL 15 packet, wait for either state.
183 */
184 lstate = IPATH_LINKARMED | IPATH_LINKACTIVE;
185 break;
186
187 case IPATH_IB_LINKACTIVE:
188 if (dd->ipath_flags & IPATH_LINKACTIVE) {
189 ret = 0;
190 goto bail;
191 }
192 if (!(dd->ipath_flags & IPATH_LINKARMED)) {
193 ret = -EINVAL;
194 goto bail;
195 }
196 ipath_set_ib_lstate(dd, INFINIPATH_IBCC_LINKCMD_ACTIVE <<
197 INFINIPATH_IBCC_LINKCMD_SHIFT);
198 lstate = IPATH_LINKACTIVE;
199 break;
200
201 default:
202 ipath_dbg("Invalid linkstate 0x%x requested\n", newstate);
203 ret = -EINVAL;
204 goto bail;
205 }
206 ret = ipath_wait_linkstate(dd, lstate, 2000);
207
208bail:
209 return ret;
210}
211
212EXPORT_SYMBOL_GPL(ipath_layer_set_linkstate);
213
214/**
215 * ipath_layer_set_mtu - set the MTU
216 * @dd: the infinipath device
217 * @arg: the new MTU
218 *
219 * we can handle "any" incoming size, the issue here is whether we
220 * need to restrict our outgoing size. For now, we don't do any
221 * sanity checking on this, and we don't deal with what happens to
222 * programs that are already running when the size changes.
223 * NOTE: changing the MTU will usually cause the IBC to go back to
224 * link initialize (IPATH_IBSTATE_INIT) state...
225 */
226int ipath_layer_set_mtu(struct ipath_devdata *dd, u16 arg)
227{
228 u32 piosize;
229 int changed = 0;
230 int ret;
231
232 /*
233 * mtu is IB data payload max. It's the largest power of 2 less
234 * than piosize (or even larger, since it only really controls the
235 * largest we can receive; we can send the max of the mtu and
236 * piosize). We check that it's one of the valid IB sizes.
237 */
238 if (arg != 256 && arg != 512 && arg != 1024 && arg != 2048 &&
239 arg != 4096) {
240 ipath_dbg("Trying to set invalid mtu %u, failing\n", arg);
241 ret = -EINVAL;
242 goto bail;
243 }
244 if (dd->ipath_ibmtu == arg) {
245 ret = 0; /* same as current */
246 goto bail;
247 }
248
249 piosize = dd->ipath_ibmaxlen;
250 dd->ipath_ibmtu = arg;
251
252 if (arg >= (piosize - IPATH_PIO_MAXIBHDR)) {
253 /* Only if it's not the initial value (or reset to it) */
254 if (piosize != dd->ipath_init_ibmaxlen) {
255 dd->ipath_ibmaxlen = piosize;
256 changed = 1;
257 }
258 } else if ((arg + IPATH_PIO_MAXIBHDR) != dd->ipath_ibmaxlen) {
259 piosize = arg + IPATH_PIO_MAXIBHDR;
260 ipath_cdbg(VERBOSE, "ibmaxlen was 0x%x, setting to 0x%x "
261 "(mtu 0x%x)\n", dd->ipath_ibmaxlen, piosize,
262 arg);
263 dd->ipath_ibmaxlen = piosize;
264 changed = 1;
265 }
266
267 if (changed) {
268 /*
269 * set the IBC maxpktlength to the size of our pio
270 * buffers in words
271 */
272 u64 ibc = dd->ipath_ibcctrl;
273 ibc &= ~(INFINIPATH_IBCC_MAXPKTLEN_MASK <<
274 INFINIPATH_IBCC_MAXPKTLEN_SHIFT);
275
276 piosize = piosize - 2 * sizeof(u32); /* ignore pbc */
277 dd->ipath_ibmaxlen = piosize;
278 piosize /= sizeof(u32); /* in words */
279 /*
280 * for ICRC, which we only send in diag test pkt mode, and
281 * we don't need to worry about that for mtu
282 */
283 piosize += 1;
284
285 ibc |= piosize << INFINIPATH_IBCC_MAXPKTLEN_SHIFT;
286 dd->ipath_ibcctrl = ibc;
287 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
288 dd->ipath_ibcctrl);
289 dd->ipath_f_tidtemplate(dd);
290 }
291
292 ret = 0;
293
294bail:
295 return ret;
296}
297
298EXPORT_SYMBOL_GPL(ipath_layer_set_mtu);
299
300int ipath_set_sps_lid(struct ipath_devdata *dd, u32 arg, u8 lmc)
301{
302 ipath_stats.sps_lid[dd->ipath_unit] = arg;
303 dd->ipath_lid = arg;
304 dd->ipath_lmc = lmc;
305
306 mutex_lock(&ipath_layer_mutex);
307
308 if (dd->ipath_layer.l_arg && layer_intr)
309 layer_intr(dd->ipath_layer.l_arg, IPATH_LAYER_INT_LID);
310
311 mutex_unlock(&ipath_layer_mutex);
312
313 return 0;
314}
315
316EXPORT_SYMBOL_GPL(ipath_set_sps_lid);
317
318int ipath_layer_set_guid(struct ipath_devdata *dd, __be64 guid)
319{
320 /* XXX - need to inform anyone who cares this just happened. */
321 dd->ipath_guid = guid;
322 return 0;
323}
324
325EXPORT_SYMBOL_GPL(ipath_layer_set_guid);
326
327__be64 ipath_layer_get_guid(struct ipath_devdata *dd)
328{
329 return dd->ipath_guid;
330}
331
332EXPORT_SYMBOL_GPL(ipath_layer_get_guid);
333
334u32 ipath_layer_get_nguid(struct ipath_devdata *dd)
335{
336 return dd->ipath_nguid;
337}
338
339EXPORT_SYMBOL_GPL(ipath_layer_get_nguid);
340
341int ipath_layer_query_device(struct ipath_devdata *dd, u32 * vendor,
342 u32 * boardrev, u32 * majrev, u32 * minrev)
343{
344 *vendor = dd->ipath_vendorid;
345 *boardrev = dd->ipath_boardrev;
346 *majrev = dd->ipath_majrev;
347 *minrev = dd->ipath_minrev;
348
349 return 0;
350}
351
352EXPORT_SYMBOL_GPL(ipath_layer_query_device);
353
354u32 ipath_layer_get_flags(struct ipath_devdata *dd)
355{
356 return dd->ipath_flags;
357}
358
359EXPORT_SYMBOL_GPL(ipath_layer_get_flags);
360
361struct device *ipath_layer_get_device(struct ipath_devdata *dd)
362{
363 return &dd->pcidev->dev;
364}
365
366EXPORT_SYMBOL_GPL(ipath_layer_get_device);
367
368u16 ipath_layer_get_deviceid(struct ipath_devdata *dd)
369{
370 return dd->ipath_deviceid;
371}
372
373EXPORT_SYMBOL_GPL(ipath_layer_get_deviceid);
374
375u64 ipath_layer_get_lastibcstat(struct ipath_devdata *dd)
376{
377 return dd->ipath_lastibcstat;
378}
379
380EXPORT_SYMBOL_GPL(ipath_layer_get_lastibcstat);
381
382u32 ipath_layer_get_ibmtu(struct ipath_devdata *dd)
383{
384 return dd->ipath_ibmtu;
385}
386
387EXPORT_SYMBOL_GPL(ipath_layer_get_ibmtu);
388
389void ipath_layer_add(struct ipath_devdata *dd)
390{
391 mutex_lock(&ipath_layer_mutex);
392
393 if (layer_add_one)
394 dd->ipath_layer.l_arg =
395 layer_add_one(dd->ipath_unit, dd);
396
397 if (verbs_add_one)
398 dd->verbs_layer.l_arg =
399 verbs_add_one(dd->ipath_unit, dd);
400
401 mutex_unlock(&ipath_layer_mutex);
402}
403
404void ipath_layer_del(struct ipath_devdata *dd)
405{
406 mutex_lock(&ipath_layer_mutex);
407
408 if (dd->ipath_layer.l_arg && layer_remove_one) {
409 layer_remove_one(dd->ipath_layer.l_arg);
410 dd->ipath_layer.l_arg = NULL;
411 }
412
413 if (dd->verbs_layer.l_arg && verbs_remove_one) {
414 verbs_remove_one(dd->verbs_layer.l_arg);
415 dd->verbs_layer.l_arg = NULL;
416 }
417
418 mutex_unlock(&ipath_layer_mutex);
419}
420
421int ipath_layer_register(void *(*l_add)(int, struct ipath_devdata *),
422 void (*l_remove)(void *),
423 int (*l_intr)(void *, u32),
424 int (*l_rcv)(void *, void *, struct sk_buff *),
425 u16 l_rcv_opcode,
426 int (*l_rcv_lid)(void *, void *))
427{
428 struct ipath_devdata *dd, *tmp;
429 unsigned long flags;
430
431 mutex_lock(&ipath_layer_mutex);
432
433 layer_add_one = l_add;
434 layer_remove_one = l_remove;
435 layer_intr = l_intr;
436 layer_rcv = l_rcv;
437 layer_rcv_lid = l_rcv_lid;
438 ipath_layer_rcv_opcode = l_rcv_opcode;
439
440 spin_lock_irqsave(&ipath_devs_lock, flags);
441
442 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
443 if (!(dd->ipath_flags & IPATH_INITTED))
444 continue;
445
446 if (dd->ipath_layer.l_arg)
447 continue;
448
449 if (!(*dd->ipath_statusp & IPATH_STATUS_SMA))
450 *dd->ipath_statusp |= IPATH_STATUS_OIB_SMA;
451
452 spin_unlock_irqrestore(&ipath_devs_lock, flags);
453 dd->ipath_layer.l_arg = l_add(dd->ipath_unit, dd);
454 spin_lock_irqsave(&ipath_devs_lock, flags);
455 }
456
457 spin_unlock_irqrestore(&ipath_devs_lock, flags);
458 mutex_unlock(&ipath_layer_mutex);
459
460 return 0;
461}
462
463EXPORT_SYMBOL_GPL(ipath_layer_register);
464
465void ipath_layer_unregister(void)
466{
467 struct ipath_devdata *dd, *tmp;
468 unsigned long flags;
469
470 mutex_lock(&ipath_layer_mutex);
471 spin_lock_irqsave(&ipath_devs_lock, flags);
472
473 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
474 if (dd->ipath_layer.l_arg && layer_remove_one) {
475 spin_unlock_irqrestore(&ipath_devs_lock, flags);
476 layer_remove_one(dd->ipath_layer.l_arg);
477 spin_lock_irqsave(&ipath_devs_lock, flags);
478 dd->ipath_layer.l_arg = NULL;
479 }
480 }
481
482 spin_unlock_irqrestore(&ipath_devs_lock, flags);
483
484 layer_add_one = NULL;
485 layer_remove_one = NULL;
486 layer_intr = NULL;
487 layer_rcv = NULL;
488 layer_rcv_lid = NULL;
489
490 mutex_unlock(&ipath_layer_mutex);
491}
492
493EXPORT_SYMBOL_GPL(ipath_layer_unregister);
494
495static void __ipath_verbs_timer(unsigned long arg)
496{
497 struct ipath_devdata *dd = (struct ipath_devdata *) arg;
498
499 /*
500 * If port 0 receive packet interrupts are not available, or
501 * can be missed, poll the receive queue
502 */
503 if (dd->ipath_flags & IPATH_POLL_RX_INTR)
504 ipath_kreceive(dd);
505
506 /* Handle verbs layer timeouts. */
507 if (dd->verbs_layer.l_arg && verbs_timer_cb)
508 verbs_timer_cb(dd->verbs_layer.l_arg);
509
510 mod_timer(&dd->verbs_layer.l_timer, jiffies + 1);
511}
512
513/**
514 * ipath_verbs_register - verbs layer registration
515 * @l_piobufavail: callback for when PIO buffers become available
516 * @l_rcv: callback for receiving a packet
517 * @l_timer_cb: timer callback
518 * @ipath_devdata: device data structure is put here
519 */
520int ipath_verbs_register(void *(*l_add)(int, struct ipath_devdata *),
521 void (*l_remove)(void *arg),
522 int (*l_piobufavail) (void *arg),
523 void (*l_rcv) (void *arg, void *rhdr,
524 void *data, u32 tlen),
525 void (*l_timer_cb) (void *arg))
526{
527 struct ipath_devdata *dd, *tmp;
528 unsigned long flags;
529
530 mutex_lock(&ipath_layer_mutex);
531
532 verbs_add_one = l_add;
533 verbs_remove_one = l_remove;
534 verbs_piobufavail = l_piobufavail;
535 verbs_rcv = l_rcv;
536 verbs_timer_cb = l_timer_cb;
537
538 spin_lock_irqsave(&ipath_devs_lock, flags);
539
540 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
541 if (!(dd->ipath_flags & IPATH_INITTED))
542 continue;
543
544 if (dd->verbs_layer.l_arg)
545 continue;
546
547 spin_unlock_irqrestore(&ipath_devs_lock, flags);
548 dd->verbs_layer.l_arg = l_add(dd->ipath_unit, dd);
549 spin_lock_irqsave(&ipath_devs_lock, flags);
550 }
551
552 spin_unlock_irqrestore(&ipath_devs_lock, flags);
553 mutex_unlock(&ipath_layer_mutex);
554
555 ipath_verbs_registered = 1;
556
557 return 0;
558}
559
560EXPORT_SYMBOL_GPL(ipath_verbs_register);
561
562void ipath_verbs_unregister(void)
563{
564 struct ipath_devdata *dd, *tmp;
565 unsigned long flags;
566
567 mutex_lock(&ipath_layer_mutex);
568 spin_lock_irqsave(&ipath_devs_lock, flags);
569
570 list_for_each_entry_safe(dd, tmp, &ipath_dev_list, ipath_list) {
571 *dd->ipath_statusp &= ~IPATH_STATUS_OIB_SMA;
572
573 if (dd->verbs_layer.l_arg && verbs_remove_one) {
574 spin_unlock_irqrestore(&ipath_devs_lock, flags);
575 verbs_remove_one(dd->verbs_layer.l_arg);
576 spin_lock_irqsave(&ipath_devs_lock, flags);
577 dd->verbs_layer.l_arg = NULL;
578 }
579 }
580
581 spin_unlock_irqrestore(&ipath_devs_lock, flags);
582
583 verbs_add_one = NULL;
584 verbs_remove_one = NULL;
585 verbs_piobufavail = NULL;
586 verbs_rcv = NULL;
587 verbs_timer_cb = NULL;
588
589 mutex_unlock(&ipath_layer_mutex);
590}
591
592EXPORT_SYMBOL_GPL(ipath_verbs_unregister);
593
594int ipath_layer_open(struct ipath_devdata *dd, u32 * pktmax)
595{
596 int ret;
597 u32 intval = 0;
598
599 mutex_lock(&ipath_layer_mutex);
600
601 if (!dd->ipath_layer.l_arg) {
602 ret = -EINVAL;
603 goto bail;
604 }
605
606 ret = ipath_setrcvhdrsize(dd, NUM_OF_EXTRA_WORDS_IN_HEADER_QUEUE);
607
608 if (ret < 0)
609 goto bail;
610
611 *pktmax = dd->ipath_ibmaxlen;
612
613 if (*dd->ipath_statusp & IPATH_STATUS_IB_READY)
614 intval |= IPATH_LAYER_INT_IF_UP;
615 if (ipath_stats.sps_lid[dd->ipath_unit])
616 intval |= IPATH_LAYER_INT_LID;
617 if (ipath_stats.sps_mlid[dd->ipath_unit])
618 intval |= IPATH_LAYER_INT_BCAST;
619 /*
620 * do this on open, in case low level is already up and
621 * just layered driver was reloaded, etc.
622 */
623 if (intval)
624 layer_intr(dd->ipath_layer.l_arg, intval);
625
626 ret = 0;
627bail:
628 mutex_unlock(&ipath_layer_mutex);
629
630 return ret;
631}
632
633EXPORT_SYMBOL_GPL(ipath_layer_open);
634
635u16 ipath_layer_get_lid(struct ipath_devdata *dd)
636{
637 return dd->ipath_lid;
638}
639
640EXPORT_SYMBOL_GPL(ipath_layer_get_lid);
641
642/**
643 * ipath_layer_get_mac - get the MAC address
644 * @dd: the infinipath device
645 * @mac: the MAC is put here
646 *
647 * This is the EUID-64 OUI octets (top 3), then
648 * skip the next 2 (which should both be zero or 0xff).
649 * The returned MAC is in network order
650 * mac points to at least 6 bytes of buffer
651 * We assume that by the time the LID is set, that the GUID is as valid
652 * as it's ever going to be, rather than adding yet another status bit.
653 */
654
655int ipath_layer_get_mac(struct ipath_devdata *dd, u8 * mac)
656{
657 u8 *guid;
658
659 guid = (u8 *) &dd->ipath_guid;
660
661 mac[0] = guid[0];
662 mac[1] = guid[1];
663 mac[2] = guid[2];
664 mac[3] = guid[5];
665 mac[4] = guid[6];
666 mac[5] = guid[7];
667 if ((guid[3] || guid[4]) && !(guid[3] == 0xff && guid[4] == 0xff))
668 ipath_dbg("Warning, guid bytes 3 and 4 not 0 or 0xffff: "
669 "%x %x\n", guid[3], guid[4]);
670 return 0;
671}
672
673EXPORT_SYMBOL_GPL(ipath_layer_get_mac);
674
675u16 ipath_layer_get_bcast(struct ipath_devdata *dd)
676{
677 return dd->ipath_mlid;
678}
679
680EXPORT_SYMBOL_GPL(ipath_layer_get_bcast);
681
682u32 ipath_layer_get_cr_errpkey(struct ipath_devdata *dd)
683{
684 return ipath_read_creg32(dd, dd->ipath_cregs->cr_errpkey);
685}
686
687EXPORT_SYMBOL_GPL(ipath_layer_get_cr_errpkey);
688
689static void update_sge(struct ipath_sge_state *ss, u32 length)
690{
691 struct ipath_sge *sge = &ss->sge;
692
693 sge->vaddr += length;
694 sge->length -= length;
695 sge->sge_length -= length;
696 if (sge->sge_length == 0) {
697 if (--ss->num_sge)
698 *sge = *ss->sg_list++;
699 } else if (sge->length == 0 && sge->mr != NULL) {
700 if (++sge->n >= IPATH_SEGSZ) {
701 if (++sge->m >= sge->mr->mapsz)
702 return;
703 sge->n = 0;
704 }
705 sge->vaddr = sge->mr->map[sge->m]->segs[sge->n].vaddr;
706 sge->length = sge->mr->map[sge->m]->segs[sge->n].length;
707 }
708}
709
710#ifdef __LITTLE_ENDIAN
711static inline u32 get_upper_bits(u32 data, u32 shift)
712{
713 return data >> shift;
714}
715
716static inline u32 set_upper_bits(u32 data, u32 shift)
717{
718 return data << shift;
719}
720
721static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
722{
723 data <<= ((sizeof(u32) - n) * BITS_PER_BYTE);
724 data >>= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
725 return data;
726}
727#else
728static inline u32 get_upper_bits(u32 data, u32 shift)
729{
730 return data << shift;
731}
732
733static inline u32 set_upper_bits(u32 data, u32 shift)
734{
735 return data >> shift;
736}
737
738static inline u32 clear_upper_bytes(u32 data, u32 n, u32 off)
739{
740 data >>= ((sizeof(u32) - n) * BITS_PER_BYTE);
741 data <<= ((sizeof(u32) - n - off) * BITS_PER_BYTE);
742 return data;
743}
744#endif
745
746static void copy_io(u32 __iomem *piobuf, struct ipath_sge_state *ss,
747 u32 length)
748{
749 u32 extra = 0;
750 u32 data = 0;
751 u32 last;
752
753 while (1) {
754 u32 len = ss->sge.length;
755 u32 off;
756
757 BUG_ON(len == 0);
758 if (len > length)
759 len = length;
760 if (len > ss->sge.sge_length)
761 len = ss->sge.sge_length;
762 /* If the source address is not aligned, try to align it. */
763 off = (unsigned long)ss->sge.vaddr & (sizeof(u32) - 1);
764 if (off) {
765 u32 *addr = (u32 *)((unsigned long)ss->sge.vaddr &
766 ~(sizeof(u32) - 1));
767 u32 v = get_upper_bits(*addr, off * BITS_PER_BYTE);
768 u32 y;
769
770 y = sizeof(u32) - off;
771 if (len > y)
772 len = y;
773 if (len + extra >= sizeof(u32)) {
774 data |= set_upper_bits(v, extra *
775 BITS_PER_BYTE);
776 len = sizeof(u32) - extra;
777 if (len == length) {
778 last = data;
779 break;
780 }
781 __raw_writel(data, piobuf);
782 piobuf++;
783 extra = 0;
784 data = 0;
785 } else {
786 /* Clear unused upper bytes */
787 data |= clear_upper_bytes(v, len, extra);
788 if (len == length) {
789 last = data;
790 break;
791 }
792 extra += len;
793 }
794 } else if (extra) {
795 /* Source address is aligned. */
796 u32 *addr = (u32 *) ss->sge.vaddr;
797 int shift = extra * BITS_PER_BYTE;
798 int ushift = 32 - shift;
799 u32 l = len;
800
801 while (l >= sizeof(u32)) {
802 u32 v = *addr;
803
804 data |= set_upper_bits(v, shift);
805 __raw_writel(data, piobuf);
806 data = get_upper_bits(v, ushift);
807 piobuf++;
808 addr++;
809 l -= sizeof(u32);
810 }
811 /*
812 * We still have 'extra' number of bytes leftover.
813 */
814 if (l) {
815 u32 v = *addr;
816
817 if (l + extra >= sizeof(u32)) {
818 data |= set_upper_bits(v, shift);
819 len -= l + extra - sizeof(u32);
820 if (len == length) {
821 last = data;
822 break;
823 }
824 __raw_writel(data, piobuf);
825 piobuf++;
826 extra = 0;
827 data = 0;
828 } else {
829 /* Clear unused upper bytes */
830 data |= clear_upper_bytes(v, l,
831 extra);
832 if (len == length) {
833 last = data;
834 break;
835 }
836 extra += l;
837 }
838 } else if (len == length) {
839 last = data;
840 break;
841 }
842 } else if (len == length) {
843 u32 w;
844
845 /*
846 * Need to round up for the last dword in the
847 * packet.
848 */
849 w = (len + 3) >> 2;
850 __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
851 piobuf += w - 1;
852 last = ((u32 *) ss->sge.vaddr)[w - 1];
853 break;
854 } else {
855 u32 w = len >> 2;
856
857 __iowrite32_copy(piobuf, ss->sge.vaddr, w);
858 piobuf += w;
859
860 extra = len & (sizeof(u32) - 1);
861 if (extra) {
862 u32 v = ((u32 *) ss->sge.vaddr)[w];
863
864 /* Clear unused upper bytes */
865 data = clear_upper_bytes(v, extra, 0);
866 }
867 }
868 update_sge(ss, len);
869 length -= len;
870 }
871 /* must flush early everything before trigger word */
872 ipath_flush_wc();
873 __raw_writel(last, piobuf);
874 /* be sure trigger word is written */
875 ipath_flush_wc();
876 update_sge(ss, length);
877}
878
879/**
880 * ipath_verbs_send - send a packet from the verbs layer
881 * @dd: the infinipath device
882 * @hdrwords: the number of works in the header
883 * @hdr: the packet header
884 * @len: the length of the packet in bytes
885 * @ss: the SGE to send
886 *
887 * This is like ipath_sma_send_pkt() in that we need to be able to send
888 * packets after the chip is initialized (MADs) but also like
889 * ipath_layer_send_hdr() since its used by the verbs layer.
890 */
891int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
892 u32 *hdr, u32 len, struct ipath_sge_state *ss)
893{
894 u32 __iomem *piobuf;
895 u32 plen;
896 int ret;
897
898 /* +1 is for the qword padding of pbc */
899 plen = hdrwords + ((len + 3) >> 2) + 1;
900 if (unlikely((plen << 2) > dd->ipath_ibmaxlen)) {
901 ipath_dbg("packet len 0x%x too long, failing\n", plen);
902 ret = -EINVAL;
903 goto bail;
904 }
905
906 /* Get a PIO buffer to use. */
907 piobuf = ipath_getpiobuf(dd, NULL);
908 if (unlikely(piobuf == NULL)) {
909 ret = -EBUSY;
910 goto bail;
911 }
912
913 /*
914 * Write len to control qword, no flags.
915 * We have to flush after the PBC for correctness on some cpus
916 * or WC buffer can be written out of order.
917 */
918 writeq(plen, piobuf);
919 ipath_flush_wc();
920 piobuf += 2;
921 if (len == 0) {
922 /*
923 * If there is just the header portion, must flush before
924 * writing last word of header for correctness, and after
925 * the last header word (trigger word).
926 */
927 __iowrite32_copy(piobuf, hdr, hdrwords - 1);
928 ipath_flush_wc();
929 __raw_writel(hdr[hdrwords - 1], piobuf + hdrwords - 1);
930 ipath_flush_wc();
931 ret = 0;
932 goto bail;
933 }
934
935 __iowrite32_copy(piobuf, hdr, hdrwords);
936 piobuf += hdrwords;
937
938 /* The common case is aligned and contained in one segment. */
939 if (likely(ss->num_sge == 1 && len <= ss->sge.length &&
940 !((unsigned long)ss->sge.vaddr & (sizeof(u32) - 1)))) {
941 u32 w;
942
943 /* Need to round up for the last dword in the packet. */
944 w = (len + 3) >> 2;
945 __iowrite32_copy(piobuf, ss->sge.vaddr, w - 1);
946 /* must flush early everything before trigger word */
947 ipath_flush_wc();
948 __raw_writel(((u32 *) ss->sge.vaddr)[w - 1],
949 piobuf + w - 1);
950 /* be sure trigger word is written */
951 ipath_flush_wc();
952 update_sge(ss, len);
953 ret = 0;
954 goto bail;
955 }
956 copy_io(piobuf, ss, len);
957 ret = 0;
958
959bail:
960 return ret;
961}
962
963EXPORT_SYMBOL_GPL(ipath_verbs_send);
964
965int ipath_layer_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
966 u64 *rwords, u64 *spkts, u64 *rpkts,
967 u64 *xmit_wait)
968{
969 int ret;
970
971 if (!(dd->ipath_flags & IPATH_INITTED)) {
972 /* no hardware, freeze, etc. */
973 ipath_dbg("unit %u not usable\n", dd->ipath_unit);
974 ret = -EINVAL;
975 goto bail;
976 }
977 *swords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
978 *rwords = ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
979 *spkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
980 *rpkts = ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
981 *xmit_wait = ipath_snap_cntr(dd, dd->ipath_cregs->cr_sendstallcnt);
982
983 ret = 0;
984
985bail:
986 return ret;
987}
988
989EXPORT_SYMBOL_GPL(ipath_layer_snapshot_counters);
990
991/**
992 * ipath_layer_get_counters - get various chip counters
993 * @dd: the infinipath device
994 * @cntrs: counters are placed here
995 *
996 * Return the counters needed by recv_pma_get_portcounters().
997 */
998int ipath_layer_get_counters(struct ipath_devdata *dd,
999 struct ipath_layer_counters *cntrs)
1000{
1001 int ret;
1002
1003 if (!(dd->ipath_flags & IPATH_INITTED)) {
1004 /* no hardware, freeze, etc. */
1005 ipath_dbg("unit %u not usable\n", dd->ipath_unit);
1006 ret = -EINVAL;
1007 goto bail;
1008 }
1009 cntrs->symbol_error_counter =
1010 ipath_snap_cntr(dd, dd->ipath_cregs->cr_ibsymbolerrcnt);
1011 cntrs->link_error_recovery_counter =
1012 ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkerrrecovcnt);
1013 cntrs->link_downed_counter =
1014 ipath_snap_cntr(dd, dd->ipath_cregs->cr_iblinkdowncnt);
1015 cntrs->port_rcv_errors =
1016 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rxdroppktcnt) +
1017 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvovflcnt) +
1018 ipath_snap_cntr(dd, dd->ipath_cregs->cr_portovflcnt) +
1019 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errrcvflowctrlcnt) +
1020 ipath_snap_cntr(dd, dd->ipath_cregs->cr_err_rlencnt) +
1021 ipath_snap_cntr(dd, dd->ipath_cregs->cr_invalidrlencnt) +
1022 ipath_snap_cntr(dd, dd->ipath_cregs->cr_erricrccnt) +
1023 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errvcrccnt) +
1024 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlpcrccnt) +
1025 ipath_snap_cntr(dd, dd->ipath_cregs->cr_errlinkcnt) +
1026 ipath_snap_cntr(dd, dd->ipath_cregs->cr_badformatcnt);
1027 cntrs->port_rcv_remphys_errors =
1028 ipath_snap_cntr(dd, dd->ipath_cregs->cr_rcvebpcnt);
1029 cntrs->port_xmit_discards =
1030 ipath_snap_cntr(dd, dd->ipath_cregs->cr_unsupvlcnt);
1031 cntrs->port_xmit_data =
1032 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
1033 cntrs->port_rcv_data =
1034 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
1035 cntrs->port_xmit_packets =
1036 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
1037 cntrs->port_rcv_packets =
1038 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
1039
1040 ret = 0;
1041
1042bail:
1043 return ret;
1044}
1045
1046EXPORT_SYMBOL_GPL(ipath_layer_get_counters);
1047
1048int ipath_layer_want_buffer(struct ipath_devdata *dd)
1049{
1050 set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
1051 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1052 dd->ipath_sendctrl);
1053
1054 return 0;
1055}
1056
1057EXPORT_SYMBOL_GPL(ipath_layer_want_buffer);
1058
1059int ipath_layer_send_hdr(struct ipath_devdata *dd, struct ether_header *hdr)
1060{
1061 int ret = 0;
1062 u32 __iomem *piobuf;
1063 u32 plen, *uhdr;
1064 size_t count;
1065 __be16 vlsllnh;
1066
1067 if (!(dd->ipath_flags & IPATH_RCVHDRSZ_SET)) {
1068 ipath_dbg("send while not open\n");
1069 ret = -EINVAL;
1070 } else
1071 if ((dd->ipath_flags & (IPATH_LINKUNK | IPATH_LINKDOWN)) ||
1072 dd->ipath_lid == 0) {
1073 /*
1074 * lid check is for when sma hasn't yet configured
1075 */
1076 ret = -ENETDOWN;
1077 ipath_cdbg(VERBOSE, "send while not ready, "
1078 "mylid=%u, flags=0x%x\n",
1079 dd->ipath_lid, dd->ipath_flags);
1080 }
1081
1082 vlsllnh = *((__be16 *) hdr);
1083 if (vlsllnh != htons(IPS_LRH_BTH)) {
1084 ipath_dbg("Warning: lrh[0] wrong (%x, not %x); "
1085 "not sending\n", be16_to_cpu(vlsllnh),
1086 IPS_LRH_BTH);
1087 ret = -EINVAL;
1088 }
1089 if (ret)
1090 goto done;
1091
1092 /* Get a PIO buffer to use. */
1093 piobuf = ipath_getpiobuf(dd, NULL);
1094 if (piobuf == NULL) {
1095 ret = -EBUSY;
1096 goto done;
1097 }
1098
1099 plen = (sizeof(*hdr) >> 2); /* actual length */
1100 ipath_cdbg(EPKT, "0x%x+1w pio %p\n", plen, piobuf);
1101
1102 writeq(plen+1, piobuf); /* len (+1 for pad) to pbc, no flags */
1103 ipath_flush_wc();
1104 piobuf += 2;
1105 uhdr = (u32 *)hdr;
1106 count = plen-1; /* amount we can copy before trigger word */
1107 __iowrite32_copy(piobuf, uhdr, count);
1108 ipath_flush_wc();
1109 __raw_writel(uhdr[count], piobuf + count);
1110 ipath_flush_wc(); /* ensure it's sent, now */
1111
1112 ipath_stats.sps_ether_spkts++; /* ether packet sent */
1113
1114done:
1115 return ret;
1116}
1117
1118EXPORT_SYMBOL_GPL(ipath_layer_send_hdr);
1119
1120int ipath_layer_set_piointbufavail_int(struct ipath_devdata *dd)
1121{
1122 set_bit(IPATH_S_PIOINTBUFAVAIL, &dd->ipath_sendctrl);
1123
1124 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
1125 dd->ipath_sendctrl);
1126 return 0;
1127}
1128
1129EXPORT_SYMBOL_GPL(ipath_layer_set_piointbufavail_int);
1130
1131int ipath_layer_enable_timer(struct ipath_devdata *dd)
1132{
1133 /*
1134 * HT-400 has a design flaw where the chip and kernel idea
1135 * of the tail register don't always agree, and therefore we won't
1136 * get an interrupt on the next packet received.
1137 * If the board supports per packet receive interrupts, use it.
1138 * Otherwise, the timer function periodically checks for packets
1139 * to cover this case.
1140 * Either way, the timer is needed for verbs layer related
1141 * processing.
1142 */
1143 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1144 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
1145 0x2074076542310ULL);
1146 /* Enable GPIO bit 2 interrupt */
1147 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1148 (u64) (1 << 2));
1149 }
1150
1151 init_timer(&dd->verbs_layer.l_timer);
1152 dd->verbs_layer.l_timer.function = __ipath_verbs_timer;
1153 dd->verbs_layer.l_timer.data = (unsigned long)dd;
1154 dd->verbs_layer.l_timer.expires = jiffies + 1;
1155 add_timer(&dd->verbs_layer.l_timer);
1156
1157 return 0;
1158}
1159
1160EXPORT_SYMBOL_GPL(ipath_layer_enable_timer);
1161
1162int ipath_layer_disable_timer(struct ipath_devdata *dd)
1163{
1164 /* Disable GPIO bit 2 interrupt */
1165 if (dd->ipath_flags & IPATH_GPIO_INTR)
1166 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask, 0);
1167
1168 del_timer_sync(&dd->verbs_layer.l_timer);
1169
1170 return 0;
1171}
1172
1173EXPORT_SYMBOL_GPL(ipath_layer_disable_timer);
1174
1175/**
1176 * ipath_layer_set_verbs_flags - set the verbs layer flags
1177 * @dd: the infinipath device
1178 * @flags: the flags to set
1179 */
1180int ipath_layer_set_verbs_flags(struct ipath_devdata *dd, unsigned flags)
1181{
1182 struct ipath_devdata *ss;
1183 unsigned long lflags;
1184
1185 spin_lock_irqsave(&ipath_devs_lock, lflags);
1186
1187 list_for_each_entry(ss, &ipath_dev_list, ipath_list) {
1188 if (!(ss->ipath_flags & IPATH_INITTED))
1189 continue;
1190 if ((flags & IPATH_VERBS_KERNEL_SMA) &&
1191 !(*ss->ipath_statusp & IPATH_STATUS_SMA))
1192 *ss->ipath_statusp |= IPATH_STATUS_OIB_SMA;
1193 else
1194 *ss->ipath_statusp &= ~IPATH_STATUS_OIB_SMA;
1195 }
1196
1197 spin_unlock_irqrestore(&ipath_devs_lock, lflags);
1198
1199 return 0;
1200}
1201
1202EXPORT_SYMBOL_GPL(ipath_layer_set_verbs_flags);
1203
1204/**
1205 * ipath_layer_get_npkeys - return the size of the PKEY table for port 0
1206 * @dd: the infinipath device
1207 */
1208unsigned ipath_layer_get_npkeys(struct ipath_devdata *dd)
1209{
1210 return ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys);
1211}
1212
1213EXPORT_SYMBOL_GPL(ipath_layer_get_npkeys);
1214
1215/**
1216 * ipath_layer_get_pkey - return the indexed PKEY from the port 0 PKEY table
1217 * @dd: the infinipath device
1218 * @index: the PKEY index
1219 */
1220unsigned ipath_layer_get_pkey(struct ipath_devdata *dd, unsigned index)
1221{
1222 unsigned ret;
1223
1224 if (index >= ARRAY_SIZE(dd->ipath_pd[0]->port_pkeys))
1225 ret = 0;
1226 else
1227 ret = dd->ipath_pd[0]->port_pkeys[index];
1228
1229 return ret;
1230}
1231
1232EXPORT_SYMBOL_GPL(ipath_layer_get_pkey);
1233
1234/**
1235 * ipath_layer_get_pkeys - return the PKEY table for port 0
1236 * @dd: the infinipath device
1237 * @pkeys: the pkey table is placed here
1238 */
1239int ipath_layer_get_pkeys(struct ipath_devdata *dd, u16 * pkeys)
1240{
1241 struct ipath_portdata *pd = dd->ipath_pd[0];
1242
1243 memcpy(pkeys, pd->port_pkeys, sizeof(pd->port_pkeys));
1244
1245 return 0;
1246}
1247
1248EXPORT_SYMBOL_GPL(ipath_layer_get_pkeys);
1249
1250/**
1251 * rm_pkey - decrecment the reference count for the given PKEY
1252 * @dd: the infinipath device
1253 * @key: the PKEY index
1254 *
1255 * Return true if this was the last reference and the hardware table entry
1256 * needs to be changed.
1257 */
1258static int rm_pkey(struct ipath_devdata *dd, u16 key)
1259{
1260 int i;
1261 int ret;
1262
1263 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
1264 if (dd->ipath_pkeys[i] != key)
1265 continue;
1266 if (atomic_dec_and_test(&dd->ipath_pkeyrefs[i])) {
1267 dd->ipath_pkeys[i] = 0;
1268 ret = 1;
1269 goto bail;
1270 }
1271 break;
1272 }
1273
1274 ret = 0;
1275
1276bail:
1277 return ret;
1278}
1279
1280/**
1281 * add_pkey - add the given PKEY to the hardware table
1282 * @dd: the infinipath device
1283 * @key: the PKEY
1284 *
1285 * Return an error code if unable to add the entry, zero if no change,
1286 * or 1 if the hardware PKEY register needs to be updated.
1287 */
1288static int add_pkey(struct ipath_devdata *dd, u16 key)
1289{
1290 int i;
1291 u16 lkey = key & 0x7FFF;
1292 int any = 0;
1293 int ret;
1294
1295 if (lkey == 0x7FFF) {
1296 ret = 0;
1297 goto bail;
1298 }
1299
1300 /* Look for an empty slot or a matching PKEY. */
1301 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
1302 if (!dd->ipath_pkeys[i]) {
1303 any++;
1304 continue;
1305 }
1306 /* If it matches exactly, try to increment the ref count */
1307 if (dd->ipath_pkeys[i] == key) {
1308 if (atomic_inc_return(&dd->ipath_pkeyrefs[i]) > 1) {
1309 ret = 0;
1310 goto bail;
1311 }
1312 /* Lost the race. Look for an empty slot below. */
1313 atomic_dec(&dd->ipath_pkeyrefs[i]);
1314 any++;
1315 }
1316 /*
1317 * It makes no sense to have both the limited and unlimited
1318 * PKEY set at the same time since the unlimited one will
1319 * disable the limited one.
1320 */
1321 if ((dd->ipath_pkeys[i] & 0x7FFF) == lkey) {
1322 ret = -EEXIST;
1323 goto bail;
1324 }
1325 }
1326 if (!any) {
1327 ret = -EBUSY;
1328 goto bail;
1329 }
1330 for (i = 0; i < ARRAY_SIZE(dd->ipath_pkeys); i++) {
1331 if (!dd->ipath_pkeys[i] &&
1332 atomic_inc_return(&dd->ipath_pkeyrefs[i]) == 1) {
1333 /* for ipathstats, etc. */
1334 ipath_stats.sps_pkeys[i] = lkey;
1335 dd->ipath_pkeys[i] = key;
1336 ret = 1;
1337 goto bail;
1338 }
1339 }
1340 ret = -EBUSY;
1341
1342bail:
1343 return ret;
1344}
1345
1346/**
1347 * ipath_layer_set_pkeys - set the PKEY table for port 0
1348 * @dd: the infinipath device
1349 * @pkeys: the PKEY table
1350 */
1351int ipath_layer_set_pkeys(struct ipath_devdata *dd, u16 * pkeys)
1352{
1353 struct ipath_portdata *pd;
1354 int i;
1355 int changed = 0;
1356
1357 pd = dd->ipath_pd[0];
1358
1359 for (i = 0; i < ARRAY_SIZE(pd->port_pkeys); i++) {
1360 u16 key = pkeys[i];
1361 u16 okey = pd->port_pkeys[i];
1362
1363 if (key == okey)
1364 continue;
1365 /*
1366 * The value of this PKEY table entry is changing.
1367 * Remove the old entry in the hardware's array of PKEYs.
1368 */
1369 if (okey & 0x7FFF)
1370 changed |= rm_pkey(dd, okey);
1371 if (key & 0x7FFF) {
1372 int ret = add_pkey(dd, key);
1373
1374 if (ret < 0)
1375 key = 0;
1376 else
1377 changed |= ret;
1378 }
1379 pd->port_pkeys[i] = key;
1380 }
1381 if (changed) {
1382 u64 pkey;
1383
1384 pkey = (u64) dd->ipath_pkeys[0] |
1385 ((u64) dd->ipath_pkeys[1] << 16) |
1386 ((u64) dd->ipath_pkeys[2] << 32) |
1387 ((u64) dd->ipath_pkeys[3] << 48);
1388 ipath_cdbg(VERBOSE, "p0 new pkey reg %llx\n",
1389 (unsigned long long) pkey);
1390 ipath_write_kreg(dd, dd->ipath_kregs->kr_partitionkey,
1391 pkey);
1392 }
1393 return 0;
1394}
1395
1396EXPORT_SYMBOL_GPL(ipath_layer_set_pkeys);
1397
1398/**
1399 * ipath_layer_get_linkdowndefaultstate - get the default linkdown state
1400 * @dd: the infinipath device
1401 *
1402 * Returns zero if the default is POLL, 1 if the default is SLEEP.
1403 */
1404int ipath_layer_get_linkdowndefaultstate(struct ipath_devdata *dd)
1405{
1406 return !!(dd->ipath_ibcctrl & INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE);
1407}
1408
1409EXPORT_SYMBOL_GPL(ipath_layer_get_linkdowndefaultstate);
1410
1411/**
1412 * ipath_layer_set_linkdowndefaultstate - set the default linkdown state
1413 * @dd: the infinipath device
1414 * @sleep: the new state
1415 *
1416 * Note that this will only take effect when the link state changes.
1417 */
1418int ipath_layer_set_linkdowndefaultstate(struct ipath_devdata *dd,
1419 int sleep)
1420{
1421 if (sleep)
1422 dd->ipath_ibcctrl |= INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
1423 else
1424 dd->ipath_ibcctrl &= ~INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE;
1425 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
1426 dd->ipath_ibcctrl);
1427 return 0;
1428}
1429
1430EXPORT_SYMBOL_GPL(ipath_layer_set_linkdowndefaultstate);
1431
1432int ipath_layer_get_phyerrthreshold(struct ipath_devdata *dd)
1433{
1434 return (dd->ipath_ibcctrl >>
1435 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
1436 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
1437}
1438
1439EXPORT_SYMBOL_GPL(ipath_layer_get_phyerrthreshold);
1440
1441/**
1442 * ipath_layer_set_phyerrthreshold - set the physical error threshold
1443 * @dd: the infinipath device
1444 * @n: the new threshold
1445 *
1446 * Note that this will only take effect when the link state changes.
1447 */
1448int ipath_layer_set_phyerrthreshold(struct ipath_devdata *dd, unsigned n)
1449{
1450 unsigned v;
1451
1452 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT) &
1453 INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK;
1454 if (v != n) {
1455 dd->ipath_ibcctrl &=
1456 ~(INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK <<
1457 INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT);
1458 dd->ipath_ibcctrl |=
1459 (u64) n << INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT;
1460 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
1461 dd->ipath_ibcctrl);
1462 }
1463 return 0;
1464}
1465
1466EXPORT_SYMBOL_GPL(ipath_layer_set_phyerrthreshold);
1467
1468int ipath_layer_get_overrunthreshold(struct ipath_devdata *dd)
1469{
1470 return (dd->ipath_ibcctrl >>
1471 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
1472 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
1473}
1474
1475EXPORT_SYMBOL_GPL(ipath_layer_get_overrunthreshold);
1476
1477/**
1478 * ipath_layer_set_overrunthreshold - set the overrun threshold
1479 * @dd: the infinipath device
1480 * @n: the new threshold
1481 *
1482 * Note that this will only take effect when the link state changes.
1483 */
1484int ipath_layer_set_overrunthreshold(struct ipath_devdata *dd, unsigned n)
1485{
1486 unsigned v;
1487
1488 v = (dd->ipath_ibcctrl >> INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT) &
1489 INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK;
1490 if (v != n) {
1491 dd->ipath_ibcctrl &=
1492 ~(INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK <<
1493 INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT);
1494 dd->ipath_ibcctrl |=
1495 (u64) n << INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT;
1496 ipath_write_kreg(dd, dd->ipath_kregs->kr_ibcctrl,
1497 dd->ipath_ibcctrl);
1498 }
1499 return 0;
1500}
1501
1502EXPORT_SYMBOL_GPL(ipath_layer_set_overrunthreshold);
1503
1504int ipath_layer_get_boardname(struct ipath_devdata *dd, char *name,
1505 size_t namelen)
1506{
1507 return dd->ipath_f_get_boardname(dd, name, namelen);
1508}
1509EXPORT_SYMBOL_GPL(ipath_layer_get_boardname);
1510
1511u32 ipath_layer_get_rcvhdrentsize(struct ipath_devdata *dd)
1512{
1513 return dd->ipath_rcvhdrentsize;
1514}
1515EXPORT_SYMBOL_GPL(ipath_layer_get_rcvhdrentsize);
diff --git a/drivers/infiniband/hw/ipath/ipath_layer.h b/drivers/infiniband/hw/ipath/ipath_layer.h
new file mode 100644
index 000000000000..6fefd15bd2da
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_layer.h
@@ -0,0 +1,181 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _IPATH_LAYER_H
34#define _IPATH_LAYER_H
35
36/*
37 * This header file is for symbols shared between the infinipath driver
38 * and drivers layered upon it (such as ipath).
39 */
40
41struct sk_buff;
42struct ipath_sge_state;
43struct ipath_devdata;
44struct ether_header;
45
46struct ipath_layer_counters {
47 u64 symbol_error_counter;
48 u64 link_error_recovery_counter;
49 u64 link_downed_counter;
50 u64 port_rcv_errors;
51 u64 port_rcv_remphys_errors;
52 u64 port_xmit_discards;
53 u64 port_xmit_data;
54 u64 port_rcv_data;
55 u64 port_xmit_packets;
56 u64 port_rcv_packets;
57};
58
59/*
60 * A segment is a linear region of low physical memory.
61 * XXX Maybe we should use phys addr here and kmap()/kunmap().
62 * Used by the verbs layer.
63 */
64struct ipath_seg {
65 void *vaddr;
66 size_t length;
67};
68
69/* The number of ipath_segs that fit in a page. */
70#define IPATH_SEGSZ (PAGE_SIZE / sizeof (struct ipath_seg))
71
72struct ipath_segarray {
73 struct ipath_seg segs[IPATH_SEGSZ];
74};
75
76struct ipath_mregion {
77 u64 user_base; /* User's address for this region */
78 u64 iova; /* IB start address of this region */
79 size_t length;
80 u32 lkey;
81 u32 offset; /* offset (bytes) to start of region */
82 int access_flags;
83 u32 max_segs; /* number of ipath_segs in all the arrays */
84 u32 mapsz; /* size of the map array */
85 struct ipath_segarray *map[0]; /* the segments */
86};
87
88/*
89 * These keep track of the copy progress within a memory region.
90 * Used by the verbs layer.
91 */
92struct ipath_sge {
93 struct ipath_mregion *mr;
94 void *vaddr; /* current pointer into the segment */
95 u32 sge_length; /* length of the SGE */
96 u32 length; /* remaining length of the segment */
97 u16 m; /* current index: mr->map[m] */
98 u16 n; /* current index: mr->map[m]->segs[n] */
99};
100
101struct ipath_sge_state {
102 struct ipath_sge *sg_list; /* next SGE to be used if any */
103 struct ipath_sge sge; /* progress state for the current SGE */
104 u8 num_sge;
105};
106
107int ipath_layer_register(void *(*l_add)(int, struct ipath_devdata *),
108 void (*l_remove)(void *),
109 int (*l_intr)(void *, u32),
110 int (*l_rcv)(void *, void *,
111 struct sk_buff *),
112 u16 rcv_opcode,
113 int (*l_rcv_lid)(void *, void *));
114int ipath_verbs_register(void *(*l_add)(int, struct ipath_devdata *),
115 void (*l_remove)(void *arg),
116 int (*l_piobufavail)(void *arg),
117 void (*l_rcv)(void *arg, void *rhdr,
118 void *data, u32 tlen),
119 void (*l_timer_cb)(void *arg));
120void ipath_layer_unregister(void);
121void ipath_verbs_unregister(void);
122int ipath_layer_open(struct ipath_devdata *, u32 * pktmax);
123u16 ipath_layer_get_lid(struct ipath_devdata *dd);
124int ipath_layer_get_mac(struct ipath_devdata *dd, u8 *);
125u16 ipath_layer_get_bcast(struct ipath_devdata *dd);
126u32 ipath_layer_get_cr_errpkey(struct ipath_devdata *dd);
127int ipath_layer_set_linkstate(struct ipath_devdata *dd, u8 state);
128int ipath_layer_set_mtu(struct ipath_devdata *, u16);
129int ipath_set_sps_lid(struct ipath_devdata *, u32, u8);
130int ipath_layer_send_hdr(struct ipath_devdata *dd,
131 struct ether_header *hdr);
132int ipath_verbs_send(struct ipath_devdata *dd, u32 hdrwords,
133 u32 * hdr, u32 len, struct ipath_sge_state *ss);
134int ipath_layer_set_piointbufavail_int(struct ipath_devdata *dd);
135int ipath_layer_get_boardname(struct ipath_devdata *dd, char *name,
136 size_t namelen);
137int ipath_layer_snapshot_counters(struct ipath_devdata *dd, u64 *swords,
138 u64 *rwords, u64 *spkts, u64 *rpkts,
139 u64 *xmit_wait);
140int ipath_layer_get_counters(struct ipath_devdata *dd,
141 struct ipath_layer_counters *cntrs);
142int ipath_layer_want_buffer(struct ipath_devdata *dd);
143int ipath_layer_set_guid(struct ipath_devdata *, __be64 guid);
144__be64 ipath_layer_get_guid(struct ipath_devdata *);
145u32 ipath_layer_get_nguid(struct ipath_devdata *);
146int ipath_layer_query_device(struct ipath_devdata *, u32 * vendor,
147 u32 * boardrev, u32 * majrev, u32 * minrev);
148u32 ipath_layer_get_flags(struct ipath_devdata *dd);
149struct device *ipath_layer_get_device(struct ipath_devdata *dd);
150u16 ipath_layer_get_deviceid(struct ipath_devdata *dd);
151u64 ipath_layer_get_lastibcstat(struct ipath_devdata *dd);
152u32 ipath_layer_get_ibmtu(struct ipath_devdata *dd);
153int ipath_layer_enable_timer(struct ipath_devdata *dd);
154int ipath_layer_disable_timer(struct ipath_devdata *dd);
155int ipath_layer_set_verbs_flags(struct ipath_devdata *dd, unsigned flags);
156unsigned ipath_layer_get_npkeys(struct ipath_devdata *dd);
157unsigned ipath_layer_get_pkey(struct ipath_devdata *dd, unsigned index);
158int ipath_layer_get_pkeys(struct ipath_devdata *dd, u16 *pkeys);
159int ipath_layer_set_pkeys(struct ipath_devdata *dd, u16 *pkeys);
160int ipath_layer_get_linkdowndefaultstate(struct ipath_devdata *dd);
161int ipath_layer_set_linkdowndefaultstate(struct ipath_devdata *dd,
162 int sleep);
163int ipath_layer_get_phyerrthreshold(struct ipath_devdata *dd);
164int ipath_layer_set_phyerrthreshold(struct ipath_devdata *dd, unsigned n);
165int ipath_layer_get_overrunthreshold(struct ipath_devdata *dd);
166int ipath_layer_set_overrunthreshold(struct ipath_devdata *dd, unsigned n);
167u32 ipath_layer_get_rcvhdrentsize(struct ipath_devdata *dd);
168
169/* ipath_ether interrupt values */
170#define IPATH_LAYER_INT_IF_UP 0x2
171#define IPATH_LAYER_INT_IF_DOWN 0x4
172#define IPATH_LAYER_INT_LID 0x8
173#define IPATH_LAYER_INT_SEND_CONTINUE 0x10
174#define IPATH_LAYER_INT_BCAST 0x40
175
176/* _verbs_layer.l_flags */
177#define IPATH_VERBS_KERNEL_SMA 0x1
178
179extern unsigned ipath_debug; /* debugging bit mask */
180
181#endif /* _IPATH_LAYER_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_mad.c b/drivers/infiniband/hw/ipath/ipath_mad.c
new file mode 100644
index 000000000000..f7f8391fe43f
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_mad.c
@@ -0,0 +1,1352 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/ib_smi.h>
34
35#include "ipath_kernel.h"
36#include "ipath_verbs.h"
37#include "ips_common.h"
38
39#define IB_SMP_UNSUP_VERSION __constant_htons(0x0004)
40#define IB_SMP_UNSUP_METHOD __constant_htons(0x0008)
41#define IB_SMP_UNSUP_METH_ATTR __constant_htons(0x000C)
42#define IB_SMP_INVALID_FIELD __constant_htons(0x001C)
43
44static int reply(struct ib_smp *smp)
45{
46 /*
47 * The verbs framework will handle the directed/LID route
48 * packet changes.
49 */
50 smp->method = IB_MGMT_METHOD_GET_RESP;
51 if (smp->mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
52 smp->status |= IB_SMP_DIRECTION;
53 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
54}
55
56static int recv_subn_get_nodedescription(struct ib_smp *smp,
57 struct ib_device *ibdev)
58{
59 if (smp->attr_mod)
60 smp->status |= IB_SMP_INVALID_FIELD;
61
62 strncpy(smp->data, ibdev->node_desc, sizeof(smp->data));
63
64 return reply(smp);
65}
66
67struct nodeinfo {
68 u8 base_version;
69 u8 class_version;
70 u8 node_type;
71 u8 num_ports;
72 __be64 sys_guid;
73 __be64 node_guid;
74 __be64 port_guid;
75 __be16 partition_cap;
76 __be16 device_id;
77 __be32 revision;
78 u8 local_port_num;
79 u8 vendor_id[3];
80} __attribute__ ((packed));
81
82static int recv_subn_get_nodeinfo(struct ib_smp *smp,
83 struct ib_device *ibdev, u8 port)
84{
85 struct nodeinfo *nip = (struct nodeinfo *)&smp->data;
86 struct ipath_devdata *dd = to_idev(ibdev)->dd;
87 u32 vendor, boardid, majrev, minrev;
88
89 if (smp->attr_mod)
90 smp->status |= IB_SMP_INVALID_FIELD;
91
92 nip->base_version = 1;
93 nip->class_version = 1;
94 nip->node_type = 1; /* channel adapter */
95 /*
96 * XXX The num_ports value will need a layer function to get
97 * the value if we ever have more than one IB port on a chip.
98 * We will also need to get the GUID for the port.
99 */
100 nip->num_ports = ibdev->phys_port_cnt;
101 /* This is already in network order */
102 nip->sys_guid = to_idev(ibdev)->sys_image_guid;
103 nip->node_guid = ipath_layer_get_guid(dd);
104 nip->port_guid = nip->sys_guid;
105 nip->partition_cap = cpu_to_be16(ipath_layer_get_npkeys(dd));
106 nip->device_id = cpu_to_be16(ipath_layer_get_deviceid(dd));
107 ipath_layer_query_device(dd, &vendor, &boardid, &majrev, &minrev);
108 nip->revision = cpu_to_be32((majrev << 16) | minrev);
109 nip->local_port_num = port;
110 nip->vendor_id[0] = 0;
111 nip->vendor_id[1] = vendor >> 8;
112 nip->vendor_id[2] = vendor;
113
114 return reply(smp);
115}
116
117static int recv_subn_get_guidinfo(struct ib_smp *smp,
118 struct ib_device *ibdev)
119{
120 u32 startgx = 8 * be32_to_cpu(smp->attr_mod);
121 __be64 *p = (__be64 *) smp->data;
122
123 /* 32 blocks of 8 64-bit GUIDs per block */
124
125 memset(smp->data, 0, sizeof(smp->data));
126
127 /*
128 * We only support one GUID for now. If this changes, the
129 * portinfo.guid_cap field needs to be updated too.
130 */
131 if (startgx == 0)
132 /* The first is a copy of the read-only HW GUID. */
133 *p = ipath_layer_get_guid(to_idev(ibdev)->dd);
134 else
135 smp->status |= IB_SMP_INVALID_FIELD;
136
137 return reply(smp);
138}
139
140struct port_info {
141 __be64 mkey;
142 __be64 gid_prefix;
143 __be16 lid;
144 __be16 sm_lid;
145 __be32 cap_mask;
146 __be16 diag_code;
147 __be16 mkey_lease_period;
148 u8 local_port_num;
149 u8 link_width_enabled;
150 u8 link_width_supported;
151 u8 link_width_active;
152 u8 linkspeed_portstate; /* 4 bits, 4 bits */
153 u8 portphysstate_linkdown; /* 4 bits, 4 bits */
154 u8 mkeyprot_resv_lmc; /* 2 bits, 3, 3 */
155 u8 linkspeedactive_enabled; /* 4 bits, 4 bits */
156 u8 neighbormtu_mastersmsl; /* 4 bits, 4 bits */
157 u8 vlcap_inittype; /* 4 bits, 4 bits */
158 u8 vl_high_limit;
159 u8 vl_arb_high_cap;
160 u8 vl_arb_low_cap;
161 u8 inittypereply_mtucap; /* 4 bits, 4 bits */
162 u8 vlstallcnt_hoqlife; /* 3 bits, 5 bits */
163 u8 operationalvl_pei_peo_fpi_fpo; /* 4 bits, 1, 1, 1, 1 */
164 __be16 mkey_violations;
165 __be16 pkey_violations;
166 __be16 qkey_violations;
167 u8 guid_cap;
168 u8 clientrereg_resv_subnetto; /* 1 bit, 2 bits, 5 */
169 u8 resv_resptimevalue; /* 3 bits, 5 bits */
170 u8 localphyerrors_overrunerrors; /* 4 bits, 4 bits */
171 __be16 max_credit_hint;
172 u8 resv;
173 u8 link_roundtrip_latency[3];
174} __attribute__ ((packed));
175
176static int recv_subn_get_portinfo(struct ib_smp *smp,
177 struct ib_device *ibdev, u8 port)
178{
179 struct ipath_ibdev *dev;
180 struct port_info *pip = (struct port_info *)smp->data;
181 u16 lid;
182 u8 ibcstat;
183 u8 mtu;
184 int ret;
185
186 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt) {
187 smp->status |= IB_SMP_INVALID_FIELD;
188 ret = reply(smp);
189 goto bail;
190 }
191
192 dev = to_idev(ibdev);
193
194 /* Clear all fields. Only set the non-zero fields. */
195 memset(smp->data, 0, sizeof(smp->data));
196
197 /* Only return the mkey if the protection field allows it. */
198 if (smp->method == IB_MGMT_METHOD_SET || dev->mkey == smp->mkey ||
199 (dev->mkeyprot_resv_lmc >> 6) == 0)
200 pip->mkey = dev->mkey;
201 pip->gid_prefix = dev->gid_prefix;
202 lid = ipath_layer_get_lid(dev->dd);
203 pip->lid = lid ? cpu_to_be16(lid) : IB_LID_PERMISSIVE;
204 pip->sm_lid = cpu_to_be16(dev->sm_lid);
205 pip->cap_mask = cpu_to_be32(dev->port_cap_flags);
206 /* pip->diag_code; */
207 pip->mkey_lease_period = cpu_to_be16(dev->mkey_lease_period);
208 pip->local_port_num = port;
209 pip->link_width_enabled = dev->link_width_enabled;
210 pip->link_width_supported = 3; /* 1x or 4x */
211 pip->link_width_active = 2; /* 4x */
212 pip->linkspeed_portstate = 0x10; /* 2.5Gbps */
213 ibcstat = ipath_layer_get_lastibcstat(dev->dd);
214 pip->linkspeed_portstate |= ((ibcstat >> 4) & 0x3) + 1;
215 pip->portphysstate_linkdown =
216 (ipath_cvt_physportstate[ibcstat & 0xf] << 4) |
217 (ipath_layer_get_linkdowndefaultstate(dev->dd) ? 1 : 2);
218 pip->mkeyprot_resv_lmc = dev->mkeyprot_resv_lmc;
219 pip->linkspeedactive_enabled = 0x11; /* 2.5Gbps, 2.5Gbps */
220 switch (ipath_layer_get_ibmtu(dev->dd)) {
221 case 4096:
222 mtu = IB_MTU_4096;
223 break;
224 case 2048:
225 mtu = IB_MTU_2048;
226 break;
227 case 1024:
228 mtu = IB_MTU_1024;
229 break;
230 case 512:
231 mtu = IB_MTU_512;
232 break;
233 case 256:
234 mtu = IB_MTU_256;
235 break;
236 default: /* oops, something is wrong */
237 mtu = IB_MTU_2048;
238 break;
239 }
240 pip->neighbormtu_mastersmsl = (mtu << 4) | dev->sm_sl;
241 pip->vlcap_inittype = 0x10; /* VLCap = VL0, InitType = 0 */
242 pip->vl_high_limit = dev->vl_high_limit;
243 /* pip->vl_arb_high_cap; // only one VL */
244 /* pip->vl_arb_low_cap; // only one VL */
245 /* InitTypeReply = 0 */
246 pip->inittypereply_mtucap = IB_MTU_4096;
247 // HCAs ignore VLStallCount and HOQLife
248 /* pip->vlstallcnt_hoqlife; */
249 pip->operationalvl_pei_peo_fpi_fpo = 0x10; /* OVLs = 1 */
250 pip->mkey_violations = cpu_to_be16(dev->mkey_violations);
251 /* P_KeyViolations are counted by hardware. */
252 pip->pkey_violations =
253 cpu_to_be16((ipath_layer_get_cr_errpkey(dev->dd) -
254 dev->n_pkey_violations) & 0xFFFF);
255 pip->qkey_violations = cpu_to_be16(dev->qkey_violations);
256 /* Only the hardware GUID is supported for now */
257 pip->guid_cap = 1;
258 pip->clientrereg_resv_subnetto = dev->subnet_timeout;
259 /* 32.768 usec. response time (guessing) */
260 pip->resv_resptimevalue = 3;
261 pip->localphyerrors_overrunerrors =
262 (ipath_layer_get_phyerrthreshold(dev->dd) << 4) |
263 ipath_layer_get_overrunthreshold(dev->dd);
264 /* pip->max_credit_hint; */
265 /* pip->link_roundtrip_latency[3]; */
266
267 ret = reply(smp);
268
269bail:
270 return ret;
271}
272
273static int recv_subn_get_pkeytable(struct ib_smp *smp,
274 struct ib_device *ibdev)
275{
276 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
277 u16 *p = (u16 *) smp->data;
278 __be16 *q = (__be16 *) smp->data;
279
280 /* 64 blocks of 32 16-bit P_Key entries */
281
282 memset(smp->data, 0, sizeof(smp->data));
283 if (startpx == 0) {
284 struct ipath_ibdev *dev = to_idev(ibdev);
285 unsigned i, n = ipath_layer_get_npkeys(dev->dd);
286
287 ipath_layer_get_pkeys(dev->dd, p);
288
289 for (i = 0; i < n; i++)
290 q[i] = cpu_to_be16(p[i]);
291 } else
292 smp->status |= IB_SMP_INVALID_FIELD;
293
294 return reply(smp);
295}
296
297static int recv_subn_set_guidinfo(struct ib_smp *smp,
298 struct ib_device *ibdev)
299{
300 /* The only GUID we support is the first read-only entry. */
301 return recv_subn_get_guidinfo(smp, ibdev);
302}
303
304/**
305 * recv_subn_set_portinfo - set port information
306 * @smp: the incoming SM packet
307 * @ibdev: the infiniband device
308 * @port: the port on the device
309 *
310 * Set Portinfo (see ch. 14.2.5.6).
311 */
312static int recv_subn_set_portinfo(struct ib_smp *smp,
313 struct ib_device *ibdev, u8 port)
314{
315 struct port_info *pip = (struct port_info *)smp->data;
316 struct ib_event event;
317 struct ipath_ibdev *dev;
318 u32 flags;
319 char clientrereg = 0;
320 u16 lid, smlid;
321 u8 lwe;
322 u8 lse;
323 u8 state;
324 u16 lstate;
325 u32 mtu;
326 int ret;
327
328 if (be32_to_cpu(smp->attr_mod) > ibdev->phys_port_cnt)
329 goto err;
330
331 dev = to_idev(ibdev);
332 event.device = ibdev;
333 event.element.port_num = port;
334
335 dev->mkey = pip->mkey;
336 dev->gid_prefix = pip->gid_prefix;
337 dev->mkey_lease_period = be16_to_cpu(pip->mkey_lease_period);
338
339 lid = be16_to_cpu(pip->lid);
340 if (lid != ipath_layer_get_lid(dev->dd)) {
341 /* Must be a valid unicast LID address. */
342 if (lid == 0 || lid >= IPS_MULTICAST_LID_BASE)
343 goto err;
344 ipath_set_sps_lid(dev->dd, lid, pip->mkeyprot_resv_lmc & 7);
345 event.event = IB_EVENT_LID_CHANGE;
346 ib_dispatch_event(&event);
347 }
348
349 smlid = be16_to_cpu(pip->sm_lid);
350 if (smlid != dev->sm_lid) {
351 /* Must be a valid unicast LID address. */
352 if (smlid == 0 || smlid >= IPS_MULTICAST_LID_BASE)
353 goto err;
354 dev->sm_lid = smlid;
355 event.event = IB_EVENT_SM_CHANGE;
356 ib_dispatch_event(&event);
357 }
358
359 /* Only 4x supported but allow 1x or 4x to be set (see 14.2.6.6). */
360 lwe = pip->link_width_enabled;
361 if ((lwe >= 4 && lwe <= 8) || (lwe >= 0xC && lwe <= 0xFE))
362 goto err;
363 if (lwe == 0xFF)
364 dev->link_width_enabled = 3; /* 1x or 4x */
365 else if (lwe)
366 dev->link_width_enabled = lwe;
367
368 /* Only 2.5 Gbs supported. */
369 lse = pip->linkspeedactive_enabled & 0xF;
370 if (lse >= 2 && lse <= 0xE)
371 goto err;
372
373 /* Set link down default state. */
374 switch (pip->portphysstate_linkdown & 0xF) {
375 case 0: /* NOP */
376 break;
377 case 1: /* SLEEP */
378 if (ipath_layer_set_linkdowndefaultstate(dev->dd, 1))
379 goto err;
380 break;
381 case 2: /* POLL */
382 if (ipath_layer_set_linkdowndefaultstate(dev->dd, 0))
383 goto err;
384 break;
385 default:
386 goto err;
387 }
388
389 dev->mkeyprot_resv_lmc = pip->mkeyprot_resv_lmc;
390 dev->vl_high_limit = pip->vl_high_limit;
391
392 switch ((pip->neighbormtu_mastersmsl >> 4) & 0xF) {
393 case IB_MTU_256:
394 mtu = 256;
395 break;
396 case IB_MTU_512:
397 mtu = 512;
398 break;
399 case IB_MTU_1024:
400 mtu = 1024;
401 break;
402 case IB_MTU_2048:
403 mtu = 2048;
404 break;
405 case IB_MTU_4096:
406 mtu = 4096;
407 break;
408 default:
409 /* XXX We have already partially updated our state! */
410 goto err;
411 }
412 ipath_layer_set_mtu(dev->dd, mtu);
413
414 dev->sm_sl = pip->neighbormtu_mastersmsl & 0xF;
415
416 /* We only support VL0 */
417 if (((pip->operationalvl_pei_peo_fpi_fpo >> 4) & 0xF) > 1)
418 goto err;
419
420 if (pip->mkey_violations == 0)
421 dev->mkey_violations = 0;
422
423 /*
424 * Hardware counter can't be reset so snapshot and subtract
425 * later.
426 */
427 if (pip->pkey_violations == 0)
428 dev->n_pkey_violations =
429 ipath_layer_get_cr_errpkey(dev->dd);
430
431 if (pip->qkey_violations == 0)
432 dev->qkey_violations = 0;
433
434 if (ipath_layer_set_phyerrthreshold(
435 dev->dd,
436 (pip->localphyerrors_overrunerrors >> 4) & 0xF))
437 goto err;
438
439 if (ipath_layer_set_overrunthreshold(
440 dev->dd,
441 (pip->localphyerrors_overrunerrors & 0xF)))
442 goto err;
443
444 dev->subnet_timeout = pip->clientrereg_resv_subnetto & 0x1F;
445
446 if (pip->clientrereg_resv_subnetto & 0x80) {
447 clientrereg = 1;
448 event.event = IB_EVENT_LID_CHANGE;
449 ib_dispatch_event(&event);
450 }
451
452 /*
453 * Do the port state change now that the other link parameters
454 * have been set.
455 * Changing the port physical state only makes sense if the link
456 * is down or is being set to down.
457 */
458 state = pip->linkspeed_portstate & 0xF;
459 flags = ipath_layer_get_flags(dev->dd);
460 lstate = (pip->portphysstate_linkdown >> 4) & 0xF;
461 if (lstate && !(state == IB_PORT_DOWN || state == IB_PORT_NOP))
462 goto err;
463
464 /*
465 * Only state changes of DOWN, ARM, and ACTIVE are valid
466 * and must be in the correct state to take effect (see 7.2.6).
467 */
468 switch (state) {
469 case IB_PORT_NOP:
470 if (lstate == 0)
471 break;
472 /* FALLTHROUGH */
473 case IB_PORT_DOWN:
474 if (lstate == 0)
475 if (ipath_layer_get_linkdowndefaultstate(dev->dd))
476 lstate = IPATH_IB_LINKDOWN_SLEEP;
477 else
478 lstate = IPATH_IB_LINKDOWN;
479 else if (lstate == 1)
480 lstate = IPATH_IB_LINKDOWN_SLEEP;
481 else if (lstate == 2)
482 lstate = IPATH_IB_LINKDOWN;
483 else if (lstate == 3)
484 lstate = IPATH_IB_LINKDOWN_DISABLE;
485 else
486 goto err;
487 ipath_layer_set_linkstate(dev->dd, lstate);
488 if (flags & IPATH_LINKACTIVE) {
489 event.event = IB_EVENT_PORT_ERR;
490 ib_dispatch_event(&event);
491 }
492 break;
493 case IB_PORT_ARMED:
494 if (!(flags & (IPATH_LINKINIT | IPATH_LINKACTIVE)))
495 break;
496 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKARM);
497 if (flags & IPATH_LINKACTIVE) {
498 event.event = IB_EVENT_PORT_ERR;
499 ib_dispatch_event(&event);
500 }
501 break;
502 case IB_PORT_ACTIVE:
503 if (!(flags & IPATH_LINKARMED))
504 break;
505 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKACTIVE);
506 event.event = IB_EVENT_PORT_ACTIVE;
507 ib_dispatch_event(&event);
508 break;
509 default:
510 /* XXX We have already partially updated our state! */
511 goto err;
512 }
513
514 ret = recv_subn_get_portinfo(smp, ibdev, port);
515
516 if (clientrereg)
517 pip->clientrereg_resv_subnetto |= 0x80;
518
519 goto done;
520
521err:
522 smp->status |= IB_SMP_INVALID_FIELD;
523 ret = recv_subn_get_portinfo(smp, ibdev, port);
524
525done:
526 return ret;
527}
528
529static int recv_subn_set_pkeytable(struct ib_smp *smp,
530 struct ib_device *ibdev)
531{
532 u32 startpx = 32 * (be32_to_cpu(smp->attr_mod) & 0xffff);
533 __be16 *p = (__be16 *) smp->data;
534 u16 *q = (u16 *) smp->data;
535 struct ipath_ibdev *dev = to_idev(ibdev);
536 unsigned i, n = ipath_layer_get_npkeys(dev->dd);
537
538 for (i = 0; i < n; i++)
539 q[i] = be16_to_cpu(p[i]);
540
541 if (startpx != 0 ||
542 ipath_layer_set_pkeys(dev->dd, q) != 0)
543 smp->status |= IB_SMP_INVALID_FIELD;
544
545 return recv_subn_get_pkeytable(smp, ibdev);
546}
547
548#define IB_PMA_CLASS_PORT_INFO __constant_htons(0x0001)
549#define IB_PMA_PORT_SAMPLES_CONTROL __constant_htons(0x0010)
550#define IB_PMA_PORT_SAMPLES_RESULT __constant_htons(0x0011)
551#define IB_PMA_PORT_COUNTERS __constant_htons(0x0012)
552#define IB_PMA_PORT_COUNTERS_EXT __constant_htons(0x001D)
553#define IB_PMA_PORT_SAMPLES_RESULT_EXT __constant_htons(0x001E)
554
555struct ib_perf {
556 u8 base_version;
557 u8 mgmt_class;
558 u8 class_version;
559 u8 method;
560 __be16 status;
561 __be16 unused;
562 __be64 tid;
563 __be16 attr_id;
564 __be16 resv;
565 __be32 attr_mod;
566 u8 reserved[40];
567 u8 data[192];
568} __attribute__ ((packed));
569
570struct ib_pma_classportinfo {
571 u8 base_version;
572 u8 class_version;
573 __be16 cap_mask;
574 u8 reserved[3];
575 u8 resp_time_value; /* only lower 5 bits */
576 union ib_gid redirect_gid;
577 __be32 redirect_tc_sl_fl; /* 8, 4, 20 bits respectively */
578 __be16 redirect_lid;
579 __be16 redirect_pkey;
580 __be32 redirect_qp; /* only lower 24 bits */
581 __be32 redirect_qkey;
582 union ib_gid trap_gid;
583 __be32 trap_tc_sl_fl; /* 8, 4, 20 bits respectively */
584 __be16 trap_lid;
585 __be16 trap_pkey;
586 __be32 trap_hl_qp; /* 8, 24 bits respectively */
587 __be32 trap_qkey;
588} __attribute__ ((packed));
589
590struct ib_pma_portsamplescontrol {
591 u8 opcode;
592 u8 port_select;
593 u8 tick;
594 u8 counter_width; /* only lower 3 bits */
595 __be32 counter_mask0_9; /* 2, 10 * 3, bits */
596 __be16 counter_mask10_14; /* 1, 5 * 3, bits */
597 u8 sample_mechanisms;
598 u8 sample_status; /* only lower 2 bits */
599 __be64 option_mask;
600 __be64 vendor_mask;
601 __be32 sample_start;
602 __be32 sample_interval;
603 __be16 tag;
604 __be16 counter_select[15];
605} __attribute__ ((packed));
606
607struct ib_pma_portsamplesresult {
608 __be16 tag;
609 __be16 sample_status; /* only lower 2 bits */
610 __be32 counter[15];
611} __attribute__ ((packed));
612
613struct ib_pma_portsamplesresult_ext {
614 __be16 tag;
615 __be16 sample_status; /* only lower 2 bits */
616 __be32 extended_width; /* only upper 2 bits */
617 __be64 counter[15];
618} __attribute__ ((packed));
619
620struct ib_pma_portcounters {
621 u8 reserved;
622 u8 port_select;
623 __be16 counter_select;
624 __be16 symbol_error_counter;
625 u8 link_error_recovery_counter;
626 u8 link_downed_counter;
627 __be16 port_rcv_errors;
628 __be16 port_rcv_remphys_errors;
629 __be16 port_rcv_switch_relay_errors;
630 __be16 port_xmit_discards;
631 u8 port_xmit_constraint_errors;
632 u8 port_rcv_constraint_errors;
633 u8 reserved1;
634 u8 lli_ebor_errors; /* 4, 4, bits */
635 __be16 reserved2;
636 __be16 vl15_dropped;
637 __be32 port_xmit_data;
638 __be32 port_rcv_data;
639 __be32 port_xmit_packets;
640 __be32 port_rcv_packets;
641} __attribute__ ((packed));
642
643#define IB_PMA_SEL_SYMBOL_ERROR __constant_htons(0x0001)
644#define IB_PMA_SEL_LINK_ERROR_RECOVERY __constant_htons(0x0002)
645#define IB_PMA_SEL_LINK_DOWNED __constant_htons(0x0004)
646#define IB_PMA_SEL_PORT_RCV_ERRORS __constant_htons(0x0008)
647#define IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS __constant_htons(0x0010)
648#define IB_PMA_SEL_PORT_XMIT_DISCARDS __constant_htons(0x0040)
649#define IB_PMA_SEL_PORT_XMIT_DATA __constant_htons(0x1000)
650#define IB_PMA_SEL_PORT_RCV_DATA __constant_htons(0x2000)
651#define IB_PMA_SEL_PORT_XMIT_PACKETS __constant_htons(0x4000)
652#define IB_PMA_SEL_PORT_RCV_PACKETS __constant_htons(0x8000)
653
654struct ib_pma_portcounters_ext {
655 u8 reserved;
656 u8 port_select;
657 __be16 counter_select;
658 __be32 reserved1;
659 __be64 port_xmit_data;
660 __be64 port_rcv_data;
661 __be64 port_xmit_packets;
662 __be64 port_rcv_packets;
663 __be64 port_unicast_xmit_packets;
664 __be64 port_unicast_rcv_packets;
665 __be64 port_multicast_xmit_packets;
666 __be64 port_multicast_rcv_packets;
667} __attribute__ ((packed));
668
669#define IB_PMA_SELX_PORT_XMIT_DATA __constant_htons(0x0001)
670#define IB_PMA_SELX_PORT_RCV_DATA __constant_htons(0x0002)
671#define IB_PMA_SELX_PORT_XMIT_PACKETS __constant_htons(0x0004)
672#define IB_PMA_SELX_PORT_RCV_PACKETS __constant_htons(0x0008)
673#define IB_PMA_SELX_PORT_UNI_XMIT_PACKETS __constant_htons(0x0010)
674#define IB_PMA_SELX_PORT_UNI_RCV_PACKETS __constant_htons(0x0020)
675#define IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS __constant_htons(0x0040)
676#define IB_PMA_SELX_PORT_MULTI_RCV_PACKETS __constant_htons(0x0080)
677
678static int recv_pma_get_classportinfo(struct ib_perf *pmp)
679{
680 struct ib_pma_classportinfo *p =
681 (struct ib_pma_classportinfo *)pmp->data;
682
683 memset(pmp->data, 0, sizeof(pmp->data));
684
685 if (pmp->attr_mod != 0)
686 pmp->status |= IB_SMP_INVALID_FIELD;
687
688 /* Indicate AllPortSelect is valid (only one port anyway) */
689 p->cap_mask = __constant_cpu_to_be16(1 << 8);
690 p->base_version = 1;
691 p->class_version = 1;
692 /*
693 * Expected response time is 4.096 usec. * 2^18 == 1.073741824
694 * sec.
695 */
696 p->resp_time_value = 18;
697
698 return reply((struct ib_smp *) pmp);
699}
700
701/*
702 * The PortSamplesControl.CounterMasks field is an array of 3 bit fields
703 * which specify the N'th counter's capabilities. See ch. 16.1.3.2.
704 * We support 5 counters which only count the mandatory quantities.
705 */
706#define COUNTER_MASK(q, n) (q << ((9 - n) * 3))
707#define COUNTER_MASK0_9 \
708 __constant_cpu_to_be32(COUNTER_MASK(1, 0) | \
709 COUNTER_MASK(1, 1) | \
710 COUNTER_MASK(1, 2) | \
711 COUNTER_MASK(1, 3) | \
712 COUNTER_MASK(1, 4))
713
714static int recv_pma_get_portsamplescontrol(struct ib_perf *pmp,
715 struct ib_device *ibdev, u8 port)
716{
717 struct ib_pma_portsamplescontrol *p =
718 (struct ib_pma_portsamplescontrol *)pmp->data;
719 struct ipath_ibdev *dev = to_idev(ibdev);
720 unsigned long flags;
721 u8 port_select = p->port_select;
722
723 memset(pmp->data, 0, sizeof(pmp->data));
724
725 p->port_select = port_select;
726 if (pmp->attr_mod != 0 ||
727 (port_select != port && port_select != 0xFF))
728 pmp->status |= IB_SMP_INVALID_FIELD;
729 /*
730 * Ticks are 10x the link transfer period which for 2.5Gbs is 4
731 * nsec. 0 == 4 nsec., 1 == 8 nsec., ..., 255 == 1020 nsec. Sample
732 * intervals are counted in ticks. Since we use Linux timers, that
733 * count in jiffies, we can't sample for less than 1000 ticks if HZ
734 * == 1000 (4000 ticks if HZ is 250).
735 */
736 /* XXX This is WRONG. */
737 p->tick = 250; /* 1 usec. */
738 p->counter_width = 4; /* 32 bit counters */
739 p->counter_mask0_9 = COUNTER_MASK0_9;
740 spin_lock_irqsave(&dev->pending_lock, flags);
741 p->sample_status = dev->pma_sample_status;
742 p->sample_start = cpu_to_be32(dev->pma_sample_start);
743 p->sample_interval = cpu_to_be32(dev->pma_sample_interval);
744 p->tag = cpu_to_be16(dev->pma_tag);
745 p->counter_select[0] = dev->pma_counter_select[0];
746 p->counter_select[1] = dev->pma_counter_select[1];
747 p->counter_select[2] = dev->pma_counter_select[2];
748 p->counter_select[3] = dev->pma_counter_select[3];
749 p->counter_select[4] = dev->pma_counter_select[4];
750 spin_unlock_irqrestore(&dev->pending_lock, flags);
751
752 return reply((struct ib_smp *) pmp);
753}
754
755static int recv_pma_set_portsamplescontrol(struct ib_perf *pmp,
756 struct ib_device *ibdev, u8 port)
757{
758 struct ib_pma_portsamplescontrol *p =
759 (struct ib_pma_portsamplescontrol *)pmp->data;
760 struct ipath_ibdev *dev = to_idev(ibdev);
761 unsigned long flags;
762 u32 start;
763 int ret;
764
765 if (pmp->attr_mod != 0 ||
766 (p->port_select != port && p->port_select != 0xFF)) {
767 pmp->status |= IB_SMP_INVALID_FIELD;
768 ret = reply((struct ib_smp *) pmp);
769 goto bail;
770 }
771
772 start = be32_to_cpu(p->sample_start);
773 if (start != 0) {
774 spin_lock_irqsave(&dev->pending_lock, flags);
775 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_DONE) {
776 dev->pma_sample_status =
777 IB_PMA_SAMPLE_STATUS_STARTED;
778 dev->pma_sample_start = start;
779 dev->pma_sample_interval =
780 be32_to_cpu(p->sample_interval);
781 dev->pma_tag = be16_to_cpu(p->tag);
782 if (p->counter_select[0])
783 dev->pma_counter_select[0] =
784 p->counter_select[0];
785 if (p->counter_select[1])
786 dev->pma_counter_select[1] =
787 p->counter_select[1];
788 if (p->counter_select[2])
789 dev->pma_counter_select[2] =
790 p->counter_select[2];
791 if (p->counter_select[3])
792 dev->pma_counter_select[3] =
793 p->counter_select[3];
794 if (p->counter_select[4])
795 dev->pma_counter_select[4] =
796 p->counter_select[4];
797 }
798 spin_unlock_irqrestore(&dev->pending_lock, flags);
799 }
800 ret = recv_pma_get_portsamplescontrol(pmp, ibdev, port);
801
802bail:
803 return ret;
804}
805
806static u64 get_counter(struct ipath_ibdev *dev, __be16 sel)
807{
808 u64 ret;
809
810 switch (sel) {
811 case IB_PMA_PORT_XMIT_DATA:
812 ret = dev->ipath_sword;
813 break;
814 case IB_PMA_PORT_RCV_DATA:
815 ret = dev->ipath_rword;
816 break;
817 case IB_PMA_PORT_XMIT_PKTS:
818 ret = dev->ipath_spkts;
819 break;
820 case IB_PMA_PORT_RCV_PKTS:
821 ret = dev->ipath_rpkts;
822 break;
823 case IB_PMA_PORT_XMIT_WAIT:
824 ret = dev->ipath_xmit_wait;
825 break;
826 default:
827 ret = 0;
828 }
829
830 return ret;
831}
832
833static int recv_pma_get_portsamplesresult(struct ib_perf *pmp,
834 struct ib_device *ibdev)
835{
836 struct ib_pma_portsamplesresult *p =
837 (struct ib_pma_portsamplesresult *)pmp->data;
838 struct ipath_ibdev *dev = to_idev(ibdev);
839 int i;
840
841 memset(pmp->data, 0, sizeof(pmp->data));
842 p->tag = cpu_to_be16(dev->pma_tag);
843 p->sample_status = cpu_to_be16(dev->pma_sample_status);
844 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
845 p->counter[i] = cpu_to_be32(
846 get_counter(dev, dev->pma_counter_select[i]));
847
848 return reply((struct ib_smp *) pmp);
849}
850
851static int recv_pma_get_portsamplesresult_ext(struct ib_perf *pmp,
852 struct ib_device *ibdev)
853{
854 struct ib_pma_portsamplesresult_ext *p =
855 (struct ib_pma_portsamplesresult_ext *)pmp->data;
856 struct ipath_ibdev *dev = to_idev(ibdev);
857 int i;
858
859 memset(pmp->data, 0, sizeof(pmp->data));
860 p->tag = cpu_to_be16(dev->pma_tag);
861 p->sample_status = cpu_to_be16(dev->pma_sample_status);
862 /* 64 bits */
863 p->extended_width = __constant_cpu_to_be32(0x80000000);
864 for (i = 0; i < ARRAY_SIZE(dev->pma_counter_select); i++)
865 p->counter[i] = cpu_to_be64(
866 get_counter(dev, dev->pma_counter_select[i]));
867
868 return reply((struct ib_smp *) pmp);
869}
870
871static int recv_pma_get_portcounters(struct ib_perf *pmp,
872 struct ib_device *ibdev, u8 port)
873{
874 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
875 pmp->data;
876 struct ipath_ibdev *dev = to_idev(ibdev);
877 struct ipath_layer_counters cntrs;
878 u8 port_select = p->port_select;
879
880 ipath_layer_get_counters(dev->dd, &cntrs);
881
882 /* Adjust counters for any resets done. */
883 cntrs.symbol_error_counter -= dev->n_symbol_error_counter;
884 cntrs.link_error_recovery_counter -=
885 dev->n_link_error_recovery_counter;
886 cntrs.link_downed_counter -= dev->n_link_downed_counter;
887 cntrs.port_rcv_errors += dev->rcv_errors;
888 cntrs.port_rcv_errors -= dev->n_port_rcv_errors;
889 cntrs.port_rcv_remphys_errors -= dev->n_port_rcv_remphys_errors;
890 cntrs.port_xmit_discards -= dev->n_port_xmit_discards;
891 cntrs.port_xmit_data -= dev->n_port_xmit_data;
892 cntrs.port_rcv_data -= dev->n_port_rcv_data;
893 cntrs.port_xmit_packets -= dev->n_port_xmit_packets;
894 cntrs.port_rcv_packets -= dev->n_port_rcv_packets;
895
896 memset(pmp->data, 0, sizeof(pmp->data));
897
898 p->port_select = port_select;
899 if (pmp->attr_mod != 0 ||
900 (port_select != port && port_select != 0xFF))
901 pmp->status |= IB_SMP_INVALID_FIELD;
902
903 if (cntrs.symbol_error_counter > 0xFFFFUL)
904 p->symbol_error_counter = __constant_cpu_to_be16(0xFFFF);
905 else
906 p->symbol_error_counter =
907 cpu_to_be16((u16)cntrs.symbol_error_counter);
908 if (cntrs.link_error_recovery_counter > 0xFFUL)
909 p->link_error_recovery_counter = 0xFF;
910 else
911 p->link_error_recovery_counter =
912 (u8)cntrs.link_error_recovery_counter;
913 if (cntrs.link_downed_counter > 0xFFUL)
914 p->link_downed_counter = 0xFF;
915 else
916 p->link_downed_counter = (u8)cntrs.link_downed_counter;
917 if (cntrs.port_rcv_errors > 0xFFFFUL)
918 p->port_rcv_errors = __constant_cpu_to_be16(0xFFFF);
919 else
920 p->port_rcv_errors =
921 cpu_to_be16((u16) cntrs.port_rcv_errors);
922 if (cntrs.port_rcv_remphys_errors > 0xFFFFUL)
923 p->port_rcv_remphys_errors = __constant_cpu_to_be16(0xFFFF);
924 else
925 p->port_rcv_remphys_errors =
926 cpu_to_be16((u16)cntrs.port_rcv_remphys_errors);
927 if (cntrs.port_xmit_discards > 0xFFFFUL)
928 p->port_xmit_discards = __constant_cpu_to_be16(0xFFFF);
929 else
930 p->port_xmit_discards =
931 cpu_to_be16((u16)cntrs.port_xmit_discards);
932 if (cntrs.port_xmit_data > 0xFFFFFFFFUL)
933 p->port_xmit_data = __constant_cpu_to_be32(0xFFFFFFFF);
934 else
935 p->port_xmit_data = cpu_to_be32((u32)cntrs.port_xmit_data);
936 if (cntrs.port_rcv_data > 0xFFFFFFFFUL)
937 p->port_rcv_data = __constant_cpu_to_be32(0xFFFFFFFF);
938 else
939 p->port_rcv_data = cpu_to_be32((u32)cntrs.port_rcv_data);
940 if (cntrs.port_xmit_packets > 0xFFFFFFFFUL)
941 p->port_xmit_packets = __constant_cpu_to_be32(0xFFFFFFFF);
942 else
943 p->port_xmit_packets =
944 cpu_to_be32((u32)cntrs.port_xmit_packets);
945 if (cntrs.port_rcv_packets > 0xFFFFFFFFUL)
946 p->port_rcv_packets = __constant_cpu_to_be32(0xFFFFFFFF);
947 else
948 p->port_rcv_packets =
949 cpu_to_be32((u32) cntrs.port_rcv_packets);
950
951 return reply((struct ib_smp *) pmp);
952}
953
954static int recv_pma_get_portcounters_ext(struct ib_perf *pmp,
955 struct ib_device *ibdev, u8 port)
956{
957 struct ib_pma_portcounters_ext *p =
958 (struct ib_pma_portcounters_ext *)pmp->data;
959 struct ipath_ibdev *dev = to_idev(ibdev);
960 u64 swords, rwords, spkts, rpkts, xwait;
961 u8 port_select = p->port_select;
962
963 ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
964 &rpkts, &xwait);
965
966 /* Adjust counters for any resets done. */
967 swords -= dev->n_port_xmit_data;
968 rwords -= dev->n_port_rcv_data;
969 spkts -= dev->n_port_xmit_packets;
970 rpkts -= dev->n_port_rcv_packets;
971
972 memset(pmp->data, 0, sizeof(pmp->data));
973
974 p->port_select = port_select;
975 if (pmp->attr_mod != 0 ||
976 (port_select != port && port_select != 0xFF))
977 pmp->status |= IB_SMP_INVALID_FIELD;
978
979 p->port_xmit_data = cpu_to_be64(swords);
980 p->port_rcv_data = cpu_to_be64(rwords);
981 p->port_xmit_packets = cpu_to_be64(spkts);
982 p->port_rcv_packets = cpu_to_be64(rpkts);
983 p->port_unicast_xmit_packets = cpu_to_be64(dev->n_unicast_xmit);
984 p->port_unicast_rcv_packets = cpu_to_be64(dev->n_unicast_rcv);
985 p->port_multicast_xmit_packets = cpu_to_be64(dev->n_multicast_xmit);
986 p->port_multicast_rcv_packets = cpu_to_be64(dev->n_multicast_rcv);
987
988 return reply((struct ib_smp *) pmp);
989}
990
991static int recv_pma_set_portcounters(struct ib_perf *pmp,
992 struct ib_device *ibdev, u8 port)
993{
994 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
995 pmp->data;
996 struct ipath_ibdev *dev = to_idev(ibdev);
997 struct ipath_layer_counters cntrs;
998
999 /*
1000 * Since the HW doesn't support clearing counters, we save the
1001 * current count and subtract it from future responses.
1002 */
1003 ipath_layer_get_counters(dev->dd, &cntrs);
1004
1005 if (p->counter_select & IB_PMA_SEL_SYMBOL_ERROR)
1006 dev->n_symbol_error_counter = cntrs.symbol_error_counter;
1007
1008 if (p->counter_select & IB_PMA_SEL_LINK_ERROR_RECOVERY)
1009 dev->n_link_error_recovery_counter =
1010 cntrs.link_error_recovery_counter;
1011
1012 if (p->counter_select & IB_PMA_SEL_LINK_DOWNED)
1013 dev->n_link_downed_counter = cntrs.link_downed_counter;
1014
1015 if (p->counter_select & IB_PMA_SEL_PORT_RCV_ERRORS)
1016 dev->n_port_rcv_errors =
1017 cntrs.port_rcv_errors + dev->rcv_errors;
1018
1019 if (p->counter_select & IB_PMA_SEL_PORT_RCV_REMPHYS_ERRORS)
1020 dev->n_port_rcv_remphys_errors =
1021 cntrs.port_rcv_remphys_errors;
1022
1023 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DISCARDS)
1024 dev->n_port_xmit_discards = cntrs.port_xmit_discards;
1025
1026 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_DATA)
1027 dev->n_port_xmit_data = cntrs.port_xmit_data;
1028
1029 if (p->counter_select & IB_PMA_SEL_PORT_RCV_DATA)
1030 dev->n_port_rcv_data = cntrs.port_rcv_data;
1031
1032 if (p->counter_select & IB_PMA_SEL_PORT_XMIT_PACKETS)
1033 dev->n_port_xmit_packets = cntrs.port_xmit_packets;
1034
1035 if (p->counter_select & IB_PMA_SEL_PORT_RCV_PACKETS)
1036 dev->n_port_rcv_packets = cntrs.port_rcv_packets;
1037
1038 return recv_pma_get_portcounters(pmp, ibdev, port);
1039}
1040
1041static int recv_pma_set_portcounters_ext(struct ib_perf *pmp,
1042 struct ib_device *ibdev, u8 port)
1043{
1044 struct ib_pma_portcounters *p = (struct ib_pma_portcounters *)
1045 pmp->data;
1046 struct ipath_ibdev *dev = to_idev(ibdev);
1047 u64 swords, rwords, spkts, rpkts, xwait;
1048
1049 ipath_layer_snapshot_counters(dev->dd, &swords, &rwords, &spkts,
1050 &rpkts, &xwait);
1051
1052 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_DATA)
1053 dev->n_port_xmit_data = swords;
1054
1055 if (p->counter_select & IB_PMA_SELX_PORT_RCV_DATA)
1056 dev->n_port_rcv_data = rwords;
1057
1058 if (p->counter_select & IB_PMA_SELX_PORT_XMIT_PACKETS)
1059 dev->n_port_xmit_packets = spkts;
1060
1061 if (p->counter_select & IB_PMA_SELX_PORT_RCV_PACKETS)
1062 dev->n_port_rcv_packets = rpkts;
1063
1064 if (p->counter_select & IB_PMA_SELX_PORT_UNI_XMIT_PACKETS)
1065 dev->n_unicast_xmit = 0;
1066
1067 if (p->counter_select & IB_PMA_SELX_PORT_UNI_RCV_PACKETS)
1068 dev->n_unicast_rcv = 0;
1069
1070 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_XMIT_PACKETS)
1071 dev->n_multicast_xmit = 0;
1072
1073 if (p->counter_select & IB_PMA_SELX_PORT_MULTI_RCV_PACKETS)
1074 dev->n_multicast_rcv = 0;
1075
1076 return recv_pma_get_portcounters_ext(pmp, ibdev, port);
1077}
1078
1079static int process_subn(struct ib_device *ibdev, int mad_flags,
1080 u8 port_num, struct ib_mad *in_mad,
1081 struct ib_mad *out_mad)
1082{
1083 struct ib_smp *smp = (struct ib_smp *)out_mad;
1084 struct ipath_ibdev *dev = to_idev(ibdev);
1085 int ret;
1086
1087 *out_mad = *in_mad;
1088 if (smp->class_version != 1) {
1089 smp->status |= IB_SMP_UNSUP_VERSION;
1090 ret = reply(smp);
1091 goto bail;
1092 }
1093
1094 /* Is the mkey in the process of expiring? */
1095 if (dev->mkey_lease_timeout && jiffies >= dev->mkey_lease_timeout) {
1096 /* Clear timeout and mkey protection field. */
1097 dev->mkey_lease_timeout = 0;
1098 dev->mkeyprot_resv_lmc &= 0x3F;
1099 }
1100
1101 /*
1102 * M_Key checking depends on
1103 * Portinfo:M_Key_protect_bits
1104 */
1105 if ((mad_flags & IB_MAD_IGNORE_MKEY) == 0 && dev->mkey != 0 &&
1106 dev->mkey != smp->mkey &&
1107 (smp->method == IB_MGMT_METHOD_SET ||
1108 (smp->method == IB_MGMT_METHOD_GET &&
1109 (dev->mkeyprot_resv_lmc >> 7) != 0))) {
1110 if (dev->mkey_violations != 0xFFFF)
1111 ++dev->mkey_violations;
1112 if (dev->mkey_lease_timeout ||
1113 dev->mkey_lease_period == 0) {
1114 ret = IB_MAD_RESULT_SUCCESS |
1115 IB_MAD_RESULT_CONSUMED;
1116 goto bail;
1117 }
1118 dev->mkey_lease_timeout = jiffies +
1119 dev->mkey_lease_period * HZ;
1120 /* Future: Generate a trap notice. */
1121 ret = IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
1122 goto bail;
1123 } else if (dev->mkey_lease_timeout)
1124 dev->mkey_lease_timeout = 0;
1125
1126 switch (smp->method) {
1127 case IB_MGMT_METHOD_GET:
1128 switch (smp->attr_id) {
1129 case IB_SMP_ATTR_NODE_DESC:
1130 ret = recv_subn_get_nodedescription(smp, ibdev);
1131 goto bail;
1132 case IB_SMP_ATTR_NODE_INFO:
1133 ret = recv_subn_get_nodeinfo(smp, ibdev, port_num);
1134 goto bail;
1135 case IB_SMP_ATTR_GUID_INFO:
1136 ret = recv_subn_get_guidinfo(smp, ibdev);
1137 goto bail;
1138 case IB_SMP_ATTR_PORT_INFO:
1139 ret = recv_subn_get_portinfo(smp, ibdev, port_num);
1140 goto bail;
1141 case IB_SMP_ATTR_PKEY_TABLE:
1142 ret = recv_subn_get_pkeytable(smp, ibdev);
1143 goto bail;
1144 case IB_SMP_ATTR_SM_INFO:
1145 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1146 ret = IB_MAD_RESULT_SUCCESS |
1147 IB_MAD_RESULT_CONSUMED;
1148 goto bail;
1149 }
1150 if (dev->port_cap_flags & IB_PORT_SM) {
1151 ret = IB_MAD_RESULT_SUCCESS;
1152 goto bail;
1153 }
1154 /* FALLTHROUGH */
1155 default:
1156 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1157 ret = reply(smp);
1158 goto bail;
1159 }
1160
1161 case IB_MGMT_METHOD_SET:
1162 switch (smp->attr_id) {
1163 case IB_SMP_ATTR_GUID_INFO:
1164 ret = recv_subn_set_guidinfo(smp, ibdev);
1165 goto bail;
1166 case IB_SMP_ATTR_PORT_INFO:
1167 ret = recv_subn_set_portinfo(smp, ibdev, port_num);
1168 goto bail;
1169 case IB_SMP_ATTR_PKEY_TABLE:
1170 ret = recv_subn_set_pkeytable(smp, ibdev);
1171 goto bail;
1172 case IB_SMP_ATTR_SM_INFO:
1173 if (dev->port_cap_flags & IB_PORT_SM_DISABLED) {
1174 ret = IB_MAD_RESULT_SUCCESS |
1175 IB_MAD_RESULT_CONSUMED;
1176 goto bail;
1177 }
1178 if (dev->port_cap_flags & IB_PORT_SM) {
1179 ret = IB_MAD_RESULT_SUCCESS;
1180 goto bail;
1181 }
1182 /* FALLTHROUGH */
1183 default:
1184 smp->status |= IB_SMP_UNSUP_METH_ATTR;
1185 ret = reply(smp);
1186 goto bail;
1187 }
1188
1189 case IB_MGMT_METHOD_GET_RESP:
1190 /*
1191 * The ib_mad module will call us to process responses
1192 * before checking for other consumers.
1193 * Just tell the caller to process it normally.
1194 */
1195 ret = IB_MAD_RESULT_FAILURE;
1196 goto bail;
1197 default:
1198 smp->status |= IB_SMP_UNSUP_METHOD;
1199 ret = reply(smp);
1200 }
1201
1202bail:
1203 return ret;
1204}
1205
1206static int process_perf(struct ib_device *ibdev, u8 port_num,
1207 struct ib_mad *in_mad,
1208 struct ib_mad *out_mad)
1209{
1210 struct ib_perf *pmp = (struct ib_perf *)out_mad;
1211 int ret;
1212
1213 *out_mad = *in_mad;
1214 if (pmp->class_version != 1) {
1215 pmp->status |= IB_SMP_UNSUP_VERSION;
1216 ret = reply((struct ib_smp *) pmp);
1217 goto bail;
1218 }
1219
1220 switch (pmp->method) {
1221 case IB_MGMT_METHOD_GET:
1222 switch (pmp->attr_id) {
1223 case IB_PMA_CLASS_PORT_INFO:
1224 ret = recv_pma_get_classportinfo(pmp);
1225 goto bail;
1226 case IB_PMA_PORT_SAMPLES_CONTROL:
1227 ret = recv_pma_get_portsamplescontrol(pmp, ibdev,
1228 port_num);
1229 goto bail;
1230 case IB_PMA_PORT_SAMPLES_RESULT:
1231 ret = recv_pma_get_portsamplesresult(pmp, ibdev);
1232 goto bail;
1233 case IB_PMA_PORT_SAMPLES_RESULT_EXT:
1234 ret = recv_pma_get_portsamplesresult_ext(pmp,
1235 ibdev);
1236 goto bail;
1237 case IB_PMA_PORT_COUNTERS:
1238 ret = recv_pma_get_portcounters(pmp, ibdev,
1239 port_num);
1240 goto bail;
1241 case IB_PMA_PORT_COUNTERS_EXT:
1242 ret = recv_pma_get_portcounters_ext(pmp, ibdev,
1243 port_num);
1244 goto bail;
1245 default:
1246 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1247 ret = reply((struct ib_smp *) pmp);
1248 goto bail;
1249 }
1250
1251 case IB_MGMT_METHOD_SET:
1252 switch (pmp->attr_id) {
1253 case IB_PMA_PORT_SAMPLES_CONTROL:
1254 ret = recv_pma_set_portsamplescontrol(pmp, ibdev,
1255 port_num);
1256 goto bail;
1257 case IB_PMA_PORT_COUNTERS:
1258 ret = recv_pma_set_portcounters(pmp, ibdev,
1259 port_num);
1260 goto bail;
1261 case IB_PMA_PORT_COUNTERS_EXT:
1262 ret = recv_pma_set_portcounters_ext(pmp, ibdev,
1263 port_num);
1264 goto bail;
1265 default:
1266 pmp->status |= IB_SMP_UNSUP_METH_ATTR;
1267 ret = reply((struct ib_smp *) pmp);
1268 goto bail;
1269 }
1270
1271 case IB_MGMT_METHOD_GET_RESP:
1272 /*
1273 * The ib_mad module will call us to process responses
1274 * before checking for other consumers.
1275 * Just tell the caller to process it normally.
1276 */
1277 ret = IB_MAD_RESULT_FAILURE;
1278 goto bail;
1279 default:
1280 pmp->status |= IB_SMP_UNSUP_METHOD;
1281 ret = reply((struct ib_smp *) pmp);
1282 }
1283
1284bail:
1285 return ret;
1286}
1287
1288/**
1289 * ipath_process_mad - process an incoming MAD packet
1290 * @ibdev: the infiniband device this packet came in on
1291 * @mad_flags: MAD flags
1292 * @port_num: the port number this packet came in on
1293 * @in_wc: the work completion entry for this packet
1294 * @in_grh: the global route header for this packet
1295 * @in_mad: the incoming MAD
1296 * @out_mad: any outgoing MAD reply
1297 *
1298 * Returns IB_MAD_RESULT_SUCCESS if this is a MAD that we are not
1299 * interested in processing.
1300 *
1301 * Note that the verbs framework has already done the MAD sanity checks,
1302 * and hop count/pointer updating for IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE
1303 * MADs.
1304 *
1305 * This is called by the ib_mad module.
1306 */
1307int ipath_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
1308 struct ib_wc *in_wc, struct ib_grh *in_grh,
1309 struct ib_mad *in_mad, struct ib_mad *out_mad)
1310{
1311 struct ipath_ibdev *dev = to_idev(ibdev);
1312 int ret;
1313
1314 /*
1315 * Snapshot current HW counters to "clear" them.
1316 * This should be done when the driver is loaded except that for
1317 * some reason we get a zillion errors when brining up the link.
1318 */
1319 if (dev->rcv_errors == 0) {
1320 struct ipath_layer_counters cntrs;
1321
1322 ipath_layer_get_counters(to_idev(ibdev)->dd, &cntrs);
1323 dev->rcv_errors++;
1324 dev->n_symbol_error_counter = cntrs.symbol_error_counter;
1325 dev->n_link_error_recovery_counter =
1326 cntrs.link_error_recovery_counter;
1327 dev->n_link_downed_counter = cntrs.link_downed_counter;
1328 dev->n_port_rcv_errors = cntrs.port_rcv_errors + 1;
1329 dev->n_port_rcv_remphys_errors =
1330 cntrs.port_rcv_remphys_errors;
1331 dev->n_port_xmit_discards = cntrs.port_xmit_discards;
1332 dev->n_port_xmit_data = cntrs.port_xmit_data;
1333 dev->n_port_rcv_data = cntrs.port_rcv_data;
1334 dev->n_port_xmit_packets = cntrs.port_xmit_packets;
1335 dev->n_port_rcv_packets = cntrs.port_rcv_packets;
1336 }
1337 switch (in_mad->mad_hdr.mgmt_class) {
1338 case IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE:
1339 case IB_MGMT_CLASS_SUBN_LID_ROUTED:
1340 ret = process_subn(ibdev, mad_flags, port_num,
1341 in_mad, out_mad);
1342 goto bail;
1343 case IB_MGMT_CLASS_PERF_MGMT:
1344 ret = process_perf(ibdev, port_num, in_mad, out_mad);
1345 goto bail;
1346 default:
1347 ret = IB_MAD_RESULT_SUCCESS;
1348 }
1349
1350bail:
1351 return ret;
1352}
diff --git a/drivers/infiniband/hw/ipath/ipath_mr.c b/drivers/infiniband/hw/ipath/ipath_mr.c
new file mode 100644
index 000000000000..69ffec66d45d
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_mr.c
@@ -0,0 +1,383 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/ib_pack.h>
34#include <rdma/ib_smi.h>
35
36#include "ipath_verbs.h"
37
38/**
39 * ipath_get_dma_mr - get a DMA memory region
40 * @pd: protection domain for this memory region
41 * @acc: access flags
42 *
43 * Returns the memory region on success, otherwise returns an errno.
44 */
45struct ib_mr *ipath_get_dma_mr(struct ib_pd *pd, int acc)
46{
47 struct ipath_mr *mr;
48 struct ib_mr *ret;
49
50 mr = kzalloc(sizeof *mr, GFP_KERNEL);
51 if (!mr) {
52 ret = ERR_PTR(-ENOMEM);
53 goto bail;
54 }
55
56 mr->mr.access_flags = acc;
57 ret = &mr->ibmr;
58
59bail:
60 return ret;
61}
62
63static struct ipath_mr *alloc_mr(int count,
64 struct ipath_lkey_table *lk_table)
65{
66 struct ipath_mr *mr;
67 int m, i = 0;
68
69 /* Allocate struct plus pointers to first level page tables. */
70 m = (count + IPATH_SEGSZ - 1) / IPATH_SEGSZ;
71 mr = kmalloc(sizeof *mr + m * sizeof mr->mr.map[0], GFP_KERNEL);
72 if (!mr)
73 goto done;
74
75 /* Allocate first level page tables. */
76 for (; i < m; i++) {
77 mr->mr.map[i] = kmalloc(sizeof *mr->mr.map[0], GFP_KERNEL);
78 if (!mr->mr.map[i])
79 goto bail;
80 }
81 mr->mr.mapsz = m;
82
83 /*
84 * ib_reg_phys_mr() will initialize mr->ibmr except for
85 * lkey and rkey.
86 */
87 if (!ipath_alloc_lkey(lk_table, &mr->mr))
88 goto bail;
89 mr->ibmr.rkey = mr->ibmr.lkey = mr->mr.lkey;
90
91 goto done;
92
93bail:
94 while (i) {
95 i--;
96 kfree(mr->mr.map[i]);
97 }
98 kfree(mr);
99 mr = NULL;
100
101done:
102 return mr;
103}
104
105/**
106 * ipath_reg_phys_mr - register a physical memory region
107 * @pd: protection domain for this memory region
108 * @buffer_list: pointer to the list of physical buffers to register
109 * @num_phys_buf: the number of physical buffers to register
110 * @iova_start: the starting address passed over IB which maps to this MR
111 *
112 * Returns the memory region on success, otherwise returns an errno.
113 */
114struct ib_mr *ipath_reg_phys_mr(struct ib_pd *pd,
115 struct ib_phys_buf *buffer_list,
116 int num_phys_buf, int acc, u64 *iova_start)
117{
118 struct ipath_mr *mr;
119 int n, m, i;
120 struct ib_mr *ret;
121
122 mr = alloc_mr(num_phys_buf, &to_idev(pd->device)->lk_table);
123 if (mr == NULL) {
124 ret = ERR_PTR(-ENOMEM);
125 goto bail;
126 }
127
128 mr->mr.user_base = *iova_start;
129 mr->mr.iova = *iova_start;
130 mr->mr.length = 0;
131 mr->mr.offset = 0;
132 mr->mr.access_flags = acc;
133 mr->mr.max_segs = num_phys_buf;
134
135 m = 0;
136 n = 0;
137 for (i = 0; i < num_phys_buf; i++) {
138 mr->mr.map[m]->segs[n].vaddr =
139 phys_to_virt(buffer_list[i].addr);
140 mr->mr.map[m]->segs[n].length = buffer_list[i].size;
141 mr->mr.length += buffer_list[i].size;
142 n++;
143 if (n == IPATH_SEGSZ) {
144 m++;
145 n = 0;
146 }
147 }
148
149 ret = &mr->ibmr;
150
151bail:
152 return ret;
153}
154
155/**
156 * ipath_reg_user_mr - register a userspace memory region
157 * @pd: protection domain for this memory region
158 * @region: the user memory region
159 * @mr_access_flags: access flags for this memory region
160 * @udata: unused by the InfiniPath driver
161 *
162 * Returns the memory region on success, otherwise returns an errno.
163 */
164struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
165 int mr_access_flags, struct ib_udata *udata)
166{
167 struct ipath_mr *mr;
168 struct ib_umem_chunk *chunk;
169 int n, m, i;
170 struct ib_mr *ret;
171
172 n = 0;
173 list_for_each_entry(chunk, &region->chunk_list, list)
174 n += chunk->nents;
175
176 mr = alloc_mr(n, &to_idev(pd->device)->lk_table);
177 if (!mr) {
178 ret = ERR_PTR(-ENOMEM);
179 goto bail;
180 }
181
182 mr->mr.user_base = region->user_base;
183 mr->mr.iova = region->virt_base;
184 mr->mr.length = region->length;
185 mr->mr.offset = region->offset;
186 mr->mr.access_flags = mr_access_flags;
187 mr->mr.max_segs = n;
188
189 m = 0;
190 n = 0;
191 list_for_each_entry(chunk, &region->chunk_list, list) {
192 for (i = 0; i < chunk->nmap; i++) {
193 mr->mr.map[m]->segs[n].vaddr =
194 page_address(chunk->page_list[i].page);
195 mr->mr.map[m]->segs[n].length = region->page_size;
196 n++;
197 if (n == IPATH_SEGSZ) {
198 m++;
199 n = 0;
200 }
201 }
202 }
203 ret = &mr->ibmr;
204
205bail:
206 return ret;
207}
208
209/**
210 * ipath_dereg_mr - unregister and free a memory region
211 * @ibmr: the memory region to free
212 *
213 * Returns 0 on success.
214 *
215 * Note that this is called to free MRs created by ipath_get_dma_mr()
216 * or ipath_reg_user_mr().
217 */
218int ipath_dereg_mr(struct ib_mr *ibmr)
219{
220 struct ipath_mr *mr = to_imr(ibmr);
221 int i;
222
223 ipath_free_lkey(&to_idev(ibmr->device)->lk_table, ibmr->lkey);
224 i = mr->mr.mapsz;
225 while (i) {
226 i--;
227 kfree(mr->mr.map[i]);
228 }
229 kfree(mr);
230 return 0;
231}
232
233/**
234 * ipath_alloc_fmr - allocate a fast memory region
235 * @pd: the protection domain for this memory region
236 * @mr_access_flags: access flags for this memory region
237 * @fmr_attr: fast memory region attributes
238 *
239 * Returns the memory region on success, otherwise returns an errno.
240 */
241struct ib_fmr *ipath_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
242 struct ib_fmr_attr *fmr_attr)
243{
244 struct ipath_fmr *fmr;
245 int m, i = 0;
246 struct ib_fmr *ret;
247
248 /* Allocate struct plus pointers to first level page tables. */
249 m = (fmr_attr->max_pages + IPATH_SEGSZ - 1) / IPATH_SEGSZ;
250 fmr = kmalloc(sizeof *fmr + m * sizeof fmr->mr.map[0], GFP_KERNEL);
251 if (!fmr)
252 goto bail;
253
254 /* Allocate first level page tables. */
255 for (; i < m; i++) {
256 fmr->mr.map[i] = kmalloc(sizeof *fmr->mr.map[0],
257 GFP_KERNEL);
258 if (!fmr->mr.map[i])
259 goto bail;
260 }
261 fmr->mr.mapsz = m;
262
263 /*
264 * ib_alloc_fmr() will initialize fmr->ibfmr except for lkey &
265 * rkey.
266 */
267 if (!ipath_alloc_lkey(&to_idev(pd->device)->lk_table, &fmr->mr))
268 goto bail;
269 fmr->ibfmr.rkey = fmr->ibfmr.lkey = fmr->mr.lkey;
270 /*
271 * Resources are allocated but no valid mapping (RKEY can't be
272 * used).
273 */
274 fmr->mr.user_base = 0;
275 fmr->mr.iova = 0;
276 fmr->mr.length = 0;
277 fmr->mr.offset = 0;
278 fmr->mr.access_flags = mr_access_flags;
279 fmr->mr.max_segs = fmr_attr->max_pages;
280 fmr->page_shift = fmr_attr->page_shift;
281
282 ret = &fmr->ibfmr;
283 goto done;
284
285bail:
286 while (i)
287 kfree(fmr->mr.map[--i]);
288 kfree(fmr);
289 ret = ERR_PTR(-ENOMEM);
290
291done:
292 return ret;
293}
294
295/**
296 * ipath_map_phys_fmr - set up a fast memory region
297 * @ibmfr: the fast memory region to set up
298 * @page_list: the list of pages to associate with the fast memory region
299 * @list_len: the number of pages to associate with the fast memory region
300 * @iova: the virtual address of the start of the fast memory region
301 *
302 * This may be called from interrupt context.
303 */
304
305int ipath_map_phys_fmr(struct ib_fmr *ibfmr, u64 * page_list,
306 int list_len, u64 iova)
307{
308 struct ipath_fmr *fmr = to_ifmr(ibfmr);
309 struct ipath_lkey_table *rkt;
310 unsigned long flags;
311 int m, n, i;
312 u32 ps;
313 int ret;
314
315 if (list_len > fmr->mr.max_segs) {
316 ret = -EINVAL;
317 goto bail;
318 }
319 rkt = &to_idev(ibfmr->device)->lk_table;
320 spin_lock_irqsave(&rkt->lock, flags);
321 fmr->mr.user_base = iova;
322 fmr->mr.iova = iova;
323 ps = 1 << fmr->page_shift;
324 fmr->mr.length = list_len * ps;
325 m = 0;
326 n = 0;
327 ps = 1 << fmr->page_shift;
328 for (i = 0; i < list_len; i++) {
329 fmr->mr.map[m]->segs[n].vaddr = phys_to_virt(page_list[i]);
330 fmr->mr.map[m]->segs[n].length = ps;
331 if (++n == IPATH_SEGSZ) {
332 m++;
333 n = 0;
334 }
335 }
336 spin_unlock_irqrestore(&rkt->lock, flags);
337 ret = 0;
338
339bail:
340 return ret;
341}
342
343/**
344 * ipath_unmap_fmr - unmap fast memory regions
345 * @fmr_list: the list of fast memory regions to unmap
346 *
347 * Returns 0 on success.
348 */
349int ipath_unmap_fmr(struct list_head *fmr_list)
350{
351 struct ipath_fmr *fmr;
352 struct ipath_lkey_table *rkt;
353 unsigned long flags;
354
355 list_for_each_entry(fmr, fmr_list, ibfmr.list) {
356 rkt = &to_idev(fmr->ibfmr.device)->lk_table;
357 spin_lock_irqsave(&rkt->lock, flags);
358 fmr->mr.user_base = 0;
359 fmr->mr.iova = 0;
360 fmr->mr.length = 0;
361 spin_unlock_irqrestore(&rkt->lock, flags);
362 }
363 return 0;
364}
365
366/**
367 * ipath_dealloc_fmr - deallocate a fast memory region
368 * @ibfmr: the fast memory region to deallocate
369 *
370 * Returns 0 on success.
371 */
372int ipath_dealloc_fmr(struct ib_fmr *ibfmr)
373{
374 struct ipath_fmr *fmr = to_ifmr(ibfmr);
375 int i;
376
377 ipath_free_lkey(&to_idev(ibfmr->device)->lk_table, ibfmr->lkey);
378 i = fmr->mr.mapsz;
379 while (i)
380 kfree(fmr->mr.map[--i]);
381 kfree(fmr);
382 return 0;
383}
diff --git a/drivers/infiniband/hw/ipath/ipath_pe800.c b/drivers/infiniband/hw/ipath/ipath_pe800.c
new file mode 100644
index 000000000000..e693a7a82667
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_pe800.c
@@ -0,0 +1,1247 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32/*
33 * This file contains all of the code that is specific to the
34 * InfiniPath PE-800 chip.
35 */
36
37#include <linux/interrupt.h>
38#include <linux/pci.h>
39#include <linux/delay.h>
40
41
42#include "ipath_kernel.h"
43#include "ipath_registers.h"
44
45/*
46 * This file contains all the chip-specific register information and
47 * access functions for the PathScale PE800, the PCI-Express chip.
48 *
49 * This lists the InfiniPath PE800 registers, in the actual chip layout.
50 * This structure should never be directly accessed.
51 */
52struct _infinipath_do_not_use_kernel_regs {
53 unsigned long long Revision;
54 unsigned long long Control;
55 unsigned long long PageAlign;
56 unsigned long long PortCnt;
57 unsigned long long DebugPortSelect;
58 unsigned long long Reserved0;
59 unsigned long long SendRegBase;
60 unsigned long long UserRegBase;
61 unsigned long long CounterRegBase;
62 unsigned long long Scratch;
63 unsigned long long Reserved1;
64 unsigned long long Reserved2;
65 unsigned long long IntBlocked;
66 unsigned long long IntMask;
67 unsigned long long IntStatus;
68 unsigned long long IntClear;
69 unsigned long long ErrorMask;
70 unsigned long long ErrorStatus;
71 unsigned long long ErrorClear;
72 unsigned long long HwErrMask;
73 unsigned long long HwErrStatus;
74 unsigned long long HwErrClear;
75 unsigned long long HwDiagCtrl;
76 unsigned long long MDIO;
77 unsigned long long IBCStatus;
78 unsigned long long IBCCtrl;
79 unsigned long long ExtStatus;
80 unsigned long long ExtCtrl;
81 unsigned long long GPIOOut;
82 unsigned long long GPIOMask;
83 unsigned long long GPIOStatus;
84 unsigned long long GPIOClear;
85 unsigned long long RcvCtrl;
86 unsigned long long RcvBTHQP;
87 unsigned long long RcvHdrSize;
88 unsigned long long RcvHdrCnt;
89 unsigned long long RcvHdrEntSize;
90 unsigned long long RcvTIDBase;
91 unsigned long long RcvTIDCnt;
92 unsigned long long RcvEgrBase;
93 unsigned long long RcvEgrCnt;
94 unsigned long long RcvBufBase;
95 unsigned long long RcvBufSize;
96 unsigned long long RxIntMemBase;
97 unsigned long long RxIntMemSize;
98 unsigned long long RcvPartitionKey;
99 unsigned long long Reserved3;
100 unsigned long long RcvPktLEDCnt;
101 unsigned long long Reserved4[8];
102 unsigned long long SendCtrl;
103 unsigned long long SendPIOBufBase;
104 unsigned long long SendPIOSize;
105 unsigned long long SendPIOBufCnt;
106 unsigned long long SendPIOAvailAddr;
107 unsigned long long TxIntMemBase;
108 unsigned long long TxIntMemSize;
109 unsigned long long Reserved5;
110 unsigned long long PCIeRBufTestReg0;
111 unsigned long long PCIeRBufTestReg1;
112 unsigned long long Reserved51[6];
113 unsigned long long SendBufferError;
114 unsigned long long SendBufferErrorCONT1;
115 unsigned long long Reserved6SBE[6];
116 unsigned long long RcvHdrAddr0;
117 unsigned long long RcvHdrAddr1;
118 unsigned long long RcvHdrAddr2;
119 unsigned long long RcvHdrAddr3;
120 unsigned long long RcvHdrAddr4;
121 unsigned long long Reserved7RHA[11];
122 unsigned long long RcvHdrTailAddr0;
123 unsigned long long RcvHdrTailAddr1;
124 unsigned long long RcvHdrTailAddr2;
125 unsigned long long RcvHdrTailAddr3;
126 unsigned long long RcvHdrTailAddr4;
127 unsigned long long Reserved8RHTA[11];
128 unsigned long long Reserved9SW[8];
129 unsigned long long SerdesConfig0;
130 unsigned long long SerdesConfig1;
131 unsigned long long SerdesStatus;
132 unsigned long long XGXSConfig;
133 unsigned long long IBPLLCfg;
134 unsigned long long Reserved10SW2[3];
135 unsigned long long PCIEQ0SerdesConfig0;
136 unsigned long long PCIEQ0SerdesConfig1;
137 unsigned long long PCIEQ0SerdesStatus;
138 unsigned long long Reserved11;
139 unsigned long long PCIEQ1SerdesConfig0;
140 unsigned long long PCIEQ1SerdesConfig1;
141 unsigned long long PCIEQ1SerdesStatus;
142 unsigned long long Reserved12;
143};
144
145#define IPATH_KREG_OFFSET(field) (offsetof(struct \
146 _infinipath_do_not_use_kernel_regs, field) / sizeof(u64))
147#define IPATH_CREG_OFFSET(field) (offsetof( \
148 struct infinipath_counters, field) / sizeof(u64))
149
150static const struct ipath_kregs ipath_pe_kregs = {
151 .kr_control = IPATH_KREG_OFFSET(Control),
152 .kr_counterregbase = IPATH_KREG_OFFSET(CounterRegBase),
153 .kr_debugportselect = IPATH_KREG_OFFSET(DebugPortSelect),
154 .kr_errorclear = IPATH_KREG_OFFSET(ErrorClear),
155 .kr_errormask = IPATH_KREG_OFFSET(ErrorMask),
156 .kr_errorstatus = IPATH_KREG_OFFSET(ErrorStatus),
157 .kr_extctrl = IPATH_KREG_OFFSET(ExtCtrl),
158 .kr_extstatus = IPATH_KREG_OFFSET(ExtStatus),
159 .kr_gpio_clear = IPATH_KREG_OFFSET(GPIOClear),
160 .kr_gpio_mask = IPATH_KREG_OFFSET(GPIOMask),
161 .kr_gpio_out = IPATH_KREG_OFFSET(GPIOOut),
162 .kr_gpio_status = IPATH_KREG_OFFSET(GPIOStatus),
163 .kr_hwdiagctrl = IPATH_KREG_OFFSET(HwDiagCtrl),
164 .kr_hwerrclear = IPATH_KREG_OFFSET(HwErrClear),
165 .kr_hwerrmask = IPATH_KREG_OFFSET(HwErrMask),
166 .kr_hwerrstatus = IPATH_KREG_OFFSET(HwErrStatus),
167 .kr_ibcctrl = IPATH_KREG_OFFSET(IBCCtrl),
168 .kr_ibcstatus = IPATH_KREG_OFFSET(IBCStatus),
169 .kr_intblocked = IPATH_KREG_OFFSET(IntBlocked),
170 .kr_intclear = IPATH_KREG_OFFSET(IntClear),
171 .kr_intmask = IPATH_KREG_OFFSET(IntMask),
172 .kr_intstatus = IPATH_KREG_OFFSET(IntStatus),
173 .kr_mdio = IPATH_KREG_OFFSET(MDIO),
174 .kr_pagealign = IPATH_KREG_OFFSET(PageAlign),
175 .kr_partitionkey = IPATH_KREG_OFFSET(RcvPartitionKey),
176 .kr_portcnt = IPATH_KREG_OFFSET(PortCnt),
177 .kr_rcvbthqp = IPATH_KREG_OFFSET(RcvBTHQP),
178 .kr_rcvbufbase = IPATH_KREG_OFFSET(RcvBufBase),
179 .kr_rcvbufsize = IPATH_KREG_OFFSET(RcvBufSize),
180 .kr_rcvctrl = IPATH_KREG_OFFSET(RcvCtrl),
181 .kr_rcvegrbase = IPATH_KREG_OFFSET(RcvEgrBase),
182 .kr_rcvegrcnt = IPATH_KREG_OFFSET(RcvEgrCnt),
183 .kr_rcvhdrcnt = IPATH_KREG_OFFSET(RcvHdrCnt),
184 .kr_rcvhdrentsize = IPATH_KREG_OFFSET(RcvHdrEntSize),
185 .kr_rcvhdrsize = IPATH_KREG_OFFSET(RcvHdrSize),
186 .kr_rcvintmembase = IPATH_KREG_OFFSET(RxIntMemBase),
187 .kr_rcvintmemsize = IPATH_KREG_OFFSET(RxIntMemSize),
188 .kr_rcvtidbase = IPATH_KREG_OFFSET(RcvTIDBase),
189 .kr_rcvtidcnt = IPATH_KREG_OFFSET(RcvTIDCnt),
190 .kr_revision = IPATH_KREG_OFFSET(Revision),
191 .kr_scratch = IPATH_KREG_OFFSET(Scratch),
192 .kr_sendbuffererror = IPATH_KREG_OFFSET(SendBufferError),
193 .kr_sendctrl = IPATH_KREG_OFFSET(SendCtrl),
194 .kr_sendpioavailaddr = IPATH_KREG_OFFSET(SendPIOAvailAddr),
195 .kr_sendpiobufbase = IPATH_KREG_OFFSET(SendPIOBufBase),
196 .kr_sendpiobufcnt = IPATH_KREG_OFFSET(SendPIOBufCnt),
197 .kr_sendpiosize = IPATH_KREG_OFFSET(SendPIOSize),
198 .kr_sendregbase = IPATH_KREG_OFFSET(SendRegBase),
199 .kr_txintmembase = IPATH_KREG_OFFSET(TxIntMemBase),
200 .kr_txintmemsize = IPATH_KREG_OFFSET(TxIntMemSize),
201 .kr_userregbase = IPATH_KREG_OFFSET(UserRegBase),
202 .kr_serdesconfig0 = IPATH_KREG_OFFSET(SerdesConfig0),
203 .kr_serdesconfig1 = IPATH_KREG_OFFSET(SerdesConfig1),
204 .kr_serdesstatus = IPATH_KREG_OFFSET(SerdesStatus),
205 .kr_xgxsconfig = IPATH_KREG_OFFSET(XGXSConfig),
206 .kr_ibpllcfg = IPATH_KREG_OFFSET(IBPLLCfg),
207
208 /*
209 * These should not be used directly via ipath_read_kreg64(),
210 * use them with ipath_read_kreg64_port()
211 */
212 .kr_rcvhdraddr = IPATH_KREG_OFFSET(RcvHdrAddr0),
213 .kr_rcvhdrtailaddr = IPATH_KREG_OFFSET(RcvHdrTailAddr0),
214
215 /* This group is pe-800-specific; and used only in this file */
216 /* The rcvpktled register controls one of the debug port signals, so
217 * a packet activity LED can be connected to it. */
218 .kr_rcvpktledcnt = IPATH_KREG_OFFSET(RcvPktLEDCnt),
219 .kr_pcierbuftestreg0 = IPATH_KREG_OFFSET(PCIeRBufTestReg0),
220 .kr_pcierbuftestreg1 = IPATH_KREG_OFFSET(PCIeRBufTestReg1),
221 .kr_pcieq0serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig0),
222 .kr_pcieq0serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ0SerdesConfig1),
223 .kr_pcieq0serdesstatus = IPATH_KREG_OFFSET(PCIEQ0SerdesStatus),
224 .kr_pcieq1serdesconfig0 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig0),
225 .kr_pcieq1serdesconfig1 = IPATH_KREG_OFFSET(PCIEQ1SerdesConfig1),
226 .kr_pcieq1serdesstatus = IPATH_KREG_OFFSET(PCIEQ1SerdesStatus)
227};
228
229static const struct ipath_cregs ipath_pe_cregs = {
230 .cr_badformatcnt = IPATH_CREG_OFFSET(RxBadFormatCnt),
231 .cr_erricrccnt = IPATH_CREG_OFFSET(RxICRCErrCnt),
232 .cr_errlinkcnt = IPATH_CREG_OFFSET(RxLinkProblemCnt),
233 .cr_errlpcrccnt = IPATH_CREG_OFFSET(RxLPCRCErrCnt),
234 .cr_errpkey = IPATH_CREG_OFFSET(RxPKeyMismatchCnt),
235 .cr_errrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowCtrlErrCnt),
236 .cr_err_rlencnt = IPATH_CREG_OFFSET(RxLenErrCnt),
237 .cr_errslencnt = IPATH_CREG_OFFSET(TxLenErrCnt),
238 .cr_errtidfull = IPATH_CREG_OFFSET(RxTIDFullErrCnt),
239 .cr_errtidvalid = IPATH_CREG_OFFSET(RxTIDValidErrCnt),
240 .cr_errvcrccnt = IPATH_CREG_OFFSET(RxVCRCErrCnt),
241 .cr_ibstatuschange = IPATH_CREG_OFFSET(IBStatusChangeCnt),
242 .cr_intcnt = IPATH_CREG_OFFSET(LBIntCnt),
243 .cr_invalidrlencnt = IPATH_CREG_OFFSET(RxMaxMinLenErrCnt),
244 .cr_invalidslencnt = IPATH_CREG_OFFSET(TxMaxMinLenErrCnt),
245 .cr_lbflowstallcnt = IPATH_CREG_OFFSET(LBFlowStallCnt),
246 .cr_pktrcvcnt = IPATH_CREG_OFFSET(RxDataPktCnt),
247 .cr_pktrcvflowctrlcnt = IPATH_CREG_OFFSET(RxFlowPktCnt),
248 .cr_pktsendcnt = IPATH_CREG_OFFSET(TxDataPktCnt),
249 .cr_pktsendflowcnt = IPATH_CREG_OFFSET(TxFlowPktCnt),
250 .cr_portovflcnt = IPATH_CREG_OFFSET(RxP0HdrEgrOvflCnt),
251 .cr_rcvebpcnt = IPATH_CREG_OFFSET(RxEBPCnt),
252 .cr_rcvovflcnt = IPATH_CREG_OFFSET(RxBufOvflCnt),
253 .cr_senddropped = IPATH_CREG_OFFSET(TxDroppedPktCnt),
254 .cr_sendstallcnt = IPATH_CREG_OFFSET(TxFlowStallCnt),
255 .cr_sendunderruncnt = IPATH_CREG_OFFSET(TxUnderrunCnt),
256 .cr_wordrcvcnt = IPATH_CREG_OFFSET(RxDwordCnt),
257 .cr_wordsendcnt = IPATH_CREG_OFFSET(TxDwordCnt),
258 .cr_unsupvlcnt = IPATH_CREG_OFFSET(TxUnsupVLErrCnt),
259 .cr_rxdroppktcnt = IPATH_CREG_OFFSET(RxDroppedPktCnt),
260 .cr_iblinkerrrecovcnt = IPATH_CREG_OFFSET(IBLinkErrRecoveryCnt),
261 .cr_iblinkdowncnt = IPATH_CREG_OFFSET(IBLinkDownedCnt),
262 .cr_ibsymbolerrcnt = IPATH_CREG_OFFSET(IBSymbolErrCnt)
263};
264
265/* kr_intstatus, kr_intclear, kr_intmask bits */
266#define INFINIPATH_I_RCVURG_MASK 0x1F
267#define INFINIPATH_I_RCVAVAIL_MASK 0x1F
268
269/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
270#define INFINIPATH_HWE_PCIEMEMPARITYERR_MASK 0x000000000000003fULL
271#define INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT 0
272#define INFINIPATH_HWE_PCIEPOISONEDTLP 0x0000000010000000ULL
273#define INFINIPATH_HWE_PCIECPLTIMEOUT 0x0000000020000000ULL
274#define INFINIPATH_HWE_PCIEBUSPARITYXTLH 0x0000000040000000ULL
275#define INFINIPATH_HWE_PCIEBUSPARITYXADM 0x0000000080000000ULL
276#define INFINIPATH_HWE_PCIEBUSPARITYRADM 0x0000000100000000ULL
277#define INFINIPATH_HWE_COREPLL_FBSLIP 0x0080000000000000ULL
278#define INFINIPATH_HWE_COREPLL_RFSLIP 0x0100000000000000ULL
279#define INFINIPATH_HWE_PCIE1PLLFAILED 0x0400000000000000ULL
280#define INFINIPATH_HWE_PCIE0PLLFAILED 0x0800000000000000ULL
281#define INFINIPATH_HWE_SERDESPLLFAILED 0x1000000000000000ULL
282
283/* kr_extstatus bits */
284#define INFINIPATH_EXTS_FREQSEL 0x2
285#define INFINIPATH_EXTS_SERDESSEL 0x4
286#define INFINIPATH_EXTS_MEMBIST_ENDTEST 0x0000000000004000
287#define INFINIPATH_EXTS_MEMBIST_FOUND 0x0000000000008000
288
289#define _IPATH_GPIO_SDA_NUM 1
290#define _IPATH_GPIO_SCL_NUM 0
291
292#define IPATH_GPIO_SDA (1ULL << \
293 (_IPATH_GPIO_SDA_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
294#define IPATH_GPIO_SCL (1ULL << \
295 (_IPATH_GPIO_SCL_NUM+INFINIPATH_EXTC_GPIOOE_SHIFT))
296
297/**
298 * ipath_pe_handle_hwerrors - display hardware errors.
299 * @dd: the infinipath device
300 * @msg: the output buffer
301 * @msgl: the size of the output buffer
302 *
303 * Use same msg buffer as regular errors to avoid excessive stack
304 * use. Most hardware errors are catastrophic, but for right now,
305 * we'll print them and continue. We reuse the same message buffer as
306 * ipath_handle_errors() to avoid excessive stack usage.
307 */
308void ipath_pe_handle_hwerrors(struct ipath_devdata *dd, char *msg,
309 size_t msgl)
310{
311 ipath_err_t hwerrs;
312 u32 bits, ctrl;
313 int isfatal = 0;
314 char bitsmsg[64];
315
316 hwerrs = ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus);
317 if (!hwerrs) {
318 /*
319 * better than printing cofusing messages
320 * This seems to be related to clearing the crc error, or
321 * the pll error during init.
322 */
323 ipath_cdbg(VERBOSE, "Called but no hardware errors set\n");
324 return;
325 } else if (hwerrs == ~0ULL) {
326 ipath_dev_err(dd, "Read of hardware error status failed "
327 "(all bits set); ignoring\n");
328 return;
329 }
330 ipath_stats.sps_hwerrs++;
331
332 /* Always clear the error status register, except MEMBISTFAIL,
333 * regardless of whether we continue or stop using the chip.
334 * We want that set so we know it failed, even across driver reload.
335 * We'll still ignore it in the hwerrmask. We do this partly for
336 * diagnostics, but also for support */
337 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
338 hwerrs&~INFINIPATH_HWE_MEMBISTFAILED);
339
340 hwerrs &= dd->ipath_hwerrmask;
341
342 /*
343 * make sure we get this much out, unless told to be quiet,
344 * or it's occurred within the last 5 seconds
345 */
346 if ((hwerrs & ~dd->ipath_lasthwerror) ||
347 (ipath_debug & __IPATH_VERBDBG))
348 dev_info(&dd->pcidev->dev, "Hardware error: hwerr=0x%llx "
349 "(cleared)\n", (unsigned long long) hwerrs);
350 dd->ipath_lasthwerror |= hwerrs;
351
352 if (hwerrs & ~infinipath_hwe_bitsextant)
353 ipath_dev_err(dd, "hwerror interrupt with unknown errors "
354 "%llx set\n", (unsigned long long)
355 (hwerrs & ~infinipath_hwe_bitsextant));
356
357 ctrl = ipath_read_kreg32(dd, dd->ipath_kregs->kr_control);
358 if (ctrl & INFINIPATH_C_FREEZEMODE) {
359 if (hwerrs) {
360 /*
361 * if any set that we aren't ignoring only make the
362 * complaint once, in case it's stuck or recurring,
363 * and we get here multiple times
364 */
365 if (dd->ipath_flags & IPATH_INITTED) {
366 ipath_dev_err(dd, "Fatal Error (freeze "
367 "mode), no longer usable\n");
368 isfatal = 1;
369 }
370 /*
371 * Mark as having had an error for driver, and also
372 * for /sys and status word mapped to user programs.
373 * This marks unit as not usable, until reset
374 */
375 *dd->ipath_statusp &= ~IPATH_STATUS_IB_READY;
376 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
377 dd->ipath_flags &= ~IPATH_INITTED;
378 } else {
379 ipath_dbg("Clearing freezemode on ignored hardware "
380 "error\n");
381 ctrl &= ~INFINIPATH_C_FREEZEMODE;
382 ipath_write_kreg(dd, dd->ipath_kregs->kr_control,
383 ctrl);
384 }
385 }
386
387 *msg = '\0';
388
389 if (hwerrs & INFINIPATH_HWE_MEMBISTFAILED) {
390 strlcat(msg, "[Memory BIST test failed, PE-800 unusable]",
391 msgl);
392 /* ignore from now on, so disable until driver reloaded */
393 *dd->ipath_statusp |= IPATH_STATUS_HWERROR;
394 dd->ipath_hwerrmask &= ~INFINIPATH_HWE_MEMBISTFAILED;
395 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
396 dd->ipath_hwerrmask);
397 }
398 if (hwerrs & (INFINIPATH_HWE_RXEMEMPARITYERR_MASK
399 << INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT)) {
400 bits = (u32) ((hwerrs >>
401 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) &
402 INFINIPATH_HWE_RXEMEMPARITYERR_MASK);
403 snprintf(bitsmsg, sizeof bitsmsg, "[RXE Parity Errs %x] ",
404 bits);
405 strlcat(msg, bitsmsg, msgl);
406 }
407 if (hwerrs & (INFINIPATH_HWE_TXEMEMPARITYERR_MASK
408 << INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT)) {
409 bits = (u32) ((hwerrs >>
410 INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT) &
411 INFINIPATH_HWE_TXEMEMPARITYERR_MASK);
412 snprintf(bitsmsg, sizeof bitsmsg, "[TXE Parity Errs %x] ",
413 bits);
414 strlcat(msg, bitsmsg, msgl);
415 }
416 if (hwerrs & (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK
417 << INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT)) {
418 bits = (u32) ((hwerrs >>
419 INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) &
420 INFINIPATH_HWE_PCIEMEMPARITYERR_MASK);
421 snprintf(bitsmsg, sizeof bitsmsg,
422 "[PCIe Mem Parity Errs %x] ", bits);
423 strlcat(msg, bitsmsg, msgl);
424 }
425 if (hwerrs & INFINIPATH_HWE_IBCBUSTOSPCPARITYERR)
426 strlcat(msg, "[IB2IPATH Parity]", msgl);
427 if (hwerrs & INFINIPATH_HWE_IBCBUSFRSPCPARITYERR)
428 strlcat(msg, "[IPATH2IB Parity]", msgl);
429
430#define _IPATH_PLL_FAIL (INFINIPATH_HWE_COREPLL_FBSLIP | \
431 INFINIPATH_HWE_COREPLL_RFSLIP )
432
433 if (hwerrs & _IPATH_PLL_FAIL) {
434 snprintf(bitsmsg, sizeof bitsmsg,
435 "[PLL failed (%llx), PE-800 unusable]",
436 (unsigned long long) hwerrs & _IPATH_PLL_FAIL);
437 strlcat(msg, bitsmsg, msgl);
438 /* ignore from now on, so disable until driver reloaded */
439 dd->ipath_hwerrmask &= ~(hwerrs & _IPATH_PLL_FAIL);
440 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
441 dd->ipath_hwerrmask);
442 }
443
444 if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED) {
445 /*
446 * If it occurs, it is left masked since the eternal
447 * interface is unused
448 */
449 dd->ipath_hwerrmask &= ~INFINIPATH_HWE_SERDESPLLFAILED;
450 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrmask,
451 dd->ipath_hwerrmask);
452 }
453
454 if (hwerrs & INFINIPATH_HWE_PCIEPOISONEDTLP)
455 strlcat(msg, "[PCIe Poisoned TLP]", msgl);
456 if (hwerrs & INFINIPATH_HWE_PCIECPLTIMEOUT)
457 strlcat(msg, "[PCIe completion timeout]", msgl);
458
459 /*
460 * In practice, it's unlikely wthat we'll see PCIe PLL, or bus
461 * parity or memory parity error failures, because most likely we
462 * won't be able to talk to the core of the chip. Nonetheless, we
463 * might see them, if they are in parts of the PCIe core that aren't
464 * essential.
465 */
466 if (hwerrs & INFINIPATH_HWE_PCIE1PLLFAILED)
467 strlcat(msg, "[PCIePLL1]", msgl);
468 if (hwerrs & INFINIPATH_HWE_PCIE0PLLFAILED)
469 strlcat(msg, "[PCIePLL0]", msgl);
470 if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYXTLH)
471 strlcat(msg, "[PCIe XTLH core parity]", msgl);
472 if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYXADM)
473 strlcat(msg, "[PCIe ADM TX core parity]", msgl);
474 if (hwerrs & INFINIPATH_HWE_PCIEBUSPARITYRADM)
475 strlcat(msg, "[PCIe ADM RX core parity]", msgl);
476
477 if (hwerrs & INFINIPATH_HWE_RXDSYNCMEMPARITYERR)
478 strlcat(msg, "[Rx Dsync]", msgl);
479 if (hwerrs & INFINIPATH_HWE_SERDESPLLFAILED)
480 strlcat(msg, "[SerDes PLL]", msgl);
481
482 ipath_dev_err(dd, "%s hardware error\n", msg);
483 if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg) {
484 /*
485 * for /sys status file ; if no trailing } is copied, we'll
486 * know it was truncated.
487 */
488 snprintf(dd->ipath_freezemsg, dd->ipath_freezelen,
489 "{%s}", msg);
490 }
491}
492
493/**
494 * ipath_pe_boardname - fill in the board name
495 * @dd: the infinipath device
496 * @name: the output buffer
497 * @namelen: the size of the output buffer
498 *
499 * info is based on the board revision register
500 */
501static int ipath_pe_boardname(struct ipath_devdata *dd, char *name,
502 size_t namelen)
503{
504 char *n = NULL;
505 u8 boardrev = dd->ipath_boardrev;
506 int ret;
507
508 switch (boardrev) {
509 case 0:
510 n = "InfiniPath_Emulation";
511 break;
512 case 1:
513 n = "InfiniPath_PE-800-Bringup";
514 break;
515 case 2:
516 n = "InfiniPath_PE-880";
517 break;
518 case 3:
519 n = "InfiniPath_PE-850";
520 break;
521 case 4:
522 n = "InfiniPath_PE-860";
523 break;
524 default:
525 ipath_dev_err(dd,
526 "Don't yet know about board with ID %u\n",
527 boardrev);
528 snprintf(name, namelen, "Unknown_InfiniPath_PE-8xx_%u",
529 boardrev);
530 break;
531 }
532 if (n)
533 snprintf(name, namelen, "%s", n);
534
535 if (dd->ipath_majrev != 4 || dd->ipath_minrev != 1) {
536 ipath_dev_err(dd, "Unsupported PE-800 revision %u.%u!\n",
537 dd->ipath_majrev, dd->ipath_minrev);
538 ret = 1;
539 } else
540 ret = 0;
541
542 return ret;
543}
544
545/**
546 * ipath_pe_init_hwerrors - enable hardware errors
547 * @dd: the infinipath device
548 *
549 * now that we have finished initializing everything that might reasonably
550 * cause a hardware error, and cleared those errors bits as they occur,
551 * we can enable hardware errors in the mask (potentially enabling
552 * freeze mode), and enable hardware errors as errors (along with
553 * everything else) in errormask
554 */
555void ipath_pe_init_hwerrors(struct ipath_devdata *dd)
556{
557 ipath_err_t val;
558 u64 extsval;
559
560 extsval = ipath_read_kreg64(dd, dd->ipath_kregs->kr_extstatus);
561
562 if (!(extsval & INFINIPATH_EXTS_MEMBIST_ENDTEST))
563 ipath_dev_err(dd, "MemBIST did not complete!\n");
564
565 val = ~0ULL; /* barring bugs, all hwerrors become interrupts, */
566
567 if (!dd->ipath_boardrev) // no PLL for Emulator
568 val &= ~INFINIPATH_HWE_SERDESPLLFAILED;
569
570 /* workaround bug 9460 in internal interface bus parity checking */
571 val &= ~INFINIPATH_HWE_PCIEBUSPARITYRADM;
572
573 dd->ipath_hwerrmask = val;
574}
575
576/**
577 * ipath_pe_bringup_serdes - bring up the serdes
578 * @dd: the infinipath device
579 */
580int ipath_pe_bringup_serdes(struct ipath_devdata *dd)
581{
582 u64 val, tmp, config1;
583 int ret = 0, change = 0;
584
585 ipath_dbg("Trying to bringup serdes\n");
586
587 if (ipath_read_kreg64(dd, dd->ipath_kregs->kr_hwerrstatus) &
588 INFINIPATH_HWE_SERDESPLLFAILED) {
589 ipath_dbg("At start, serdes PLL failed bit set "
590 "in hwerrstatus, clearing and continuing\n");
591 ipath_write_kreg(dd, dd->ipath_kregs->kr_hwerrclear,
592 INFINIPATH_HWE_SERDESPLLFAILED);
593 }
594
595 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
596 config1 = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig1);
597
598 ipath_cdbg(VERBOSE, "SerDes status config0=%llx config1=%llx, "
599 "xgxsconfig %llx\n", (unsigned long long) val,
600 (unsigned long long) config1, (unsigned long long)
601 ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
602
603 /*
604 * Force reset on, also set rxdetect enable. Must do before reading
605 * serdesstatus at least for simulation, or some of the bits in
606 * serdes status will come back as undefined and cause simulation
607 * failures
608 */
609 val |= INFINIPATH_SERDC0_RESET_PLL | INFINIPATH_SERDC0_RXDETECT_EN
610 | INFINIPATH_SERDC0_L1PWR_DN;
611 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
612 /* be sure chip saw it */
613 tmp = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
614 udelay(5); /* need pll reset set at least for a bit */
615 /*
616 * after PLL is reset, set the per-lane Resets and TxIdle and
617 * clear the PLL reset and rxdetect (to get falling edge).
618 * Leave L1PWR bits set (permanently)
619 */
620 val &= ~(INFINIPATH_SERDC0_RXDETECT_EN | INFINIPATH_SERDC0_RESET_PLL
621 | INFINIPATH_SERDC0_L1PWR_DN);
622 val |= INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE;
623 ipath_cdbg(VERBOSE, "Clearing pll reset and setting lane resets "
624 "and txidle (%llx)\n", (unsigned long long) val);
625 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
626 /* be sure chip saw it */
627 tmp = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
628 /* need PLL reset clear for at least 11 usec before lane
629 * resets cleared; give it a few more to be sure */
630 udelay(15);
631 val &= ~(INFINIPATH_SERDC0_RESET_MASK | INFINIPATH_SERDC0_TXIDLE);
632
633 ipath_cdbg(VERBOSE, "Clearing lane resets and txidle "
634 "(writing %llx)\n", (unsigned long long) val);
635 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
636 /* be sure chip saw it */
637 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_scratch);
638
639 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig);
640 if (((val >> INFINIPATH_XGXS_MDIOADDR_SHIFT) &
641 INFINIPATH_XGXS_MDIOADDR_MASK) != 3) {
642 val &=
643 ~(INFINIPATH_XGXS_MDIOADDR_MASK <<
644 INFINIPATH_XGXS_MDIOADDR_SHIFT);
645 /* MDIO address 3 */
646 val |= 3ULL << INFINIPATH_XGXS_MDIOADDR_SHIFT;
647 change = 1;
648 }
649 if (val & INFINIPATH_XGXS_RESET) {
650 val &= ~INFINIPATH_XGXS_RESET;
651 change = 1;
652 }
653 if (change)
654 ipath_write_kreg(dd, dd->ipath_kregs->kr_xgxsconfig, val);
655
656 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
657
658 /* clear current and de-emphasis bits */
659 config1 &= ~0x0ffffffff00ULL;
660 /* set current to 20ma */
661 config1 |= 0x00000000000ULL;
662 /* set de-emphasis to -5.68dB */
663 config1 |= 0x0cccc000000ULL;
664 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig1, config1);
665
666 ipath_cdbg(VERBOSE, "done: SerDes status config0=%llx "
667 "config1=%llx, sstatus=%llx xgxs=%llx\n",
668 (unsigned long long) val, (unsigned long long) config1,
669 (unsigned long long)
670 ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesstatus),
671 (unsigned long long)
672 ipath_read_kreg64(dd, dd->ipath_kregs->kr_xgxsconfig));
673
674 if (!ipath_waitfor_mdio_cmdready(dd)) {
675 ipath_write_kreg(
676 dd, dd->ipath_kregs->kr_mdio,
677 ipath_mdio_req(IPATH_MDIO_CMD_READ, 31,
678 IPATH_MDIO_CTRL_XGXS_REG_8, 0));
679 if (ipath_waitfor_complete(dd, dd->ipath_kregs->kr_mdio,
680 IPATH_MDIO_DATAVALID, &val))
681 ipath_dbg("Never got MDIO data for XGXS "
682 "status read\n");
683 else
684 ipath_cdbg(VERBOSE, "MDIO Read reg8, "
685 "'bank' 31 %x\n", (u32) val);
686 } else
687 ipath_dbg("Never got MDIO cmdready for XGXS status read\n");
688
689 return ret;
690}
691
692/**
693 * ipath_pe_quiet_serdes - set serdes to txidle
694 * @dd: the infinipath device
695 * Called when driver is being unloaded
696 */
697void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
698{
699 u64 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_serdesconfig0);
700
701 val |= INFINIPATH_SERDC0_TXIDLE;
702 ipath_dbg("Setting TxIdleEn on serdes (config0 = %llx)\n",
703 (unsigned long long) val);
704 ipath_write_kreg(dd, dd->ipath_kregs->kr_serdesconfig0, val);
705}
706
707/* this is not yet needed on the PE800, so just return 0. */
708static int ipath_pe_intconfig(struct ipath_devdata *dd)
709{
710 return 0;
711}
712
713/**
714 * ipath_setup_pe_setextled - set the state of the two external LEDs
715 * @dd: the infinipath device
716 * @lst: the L state
717 * @ltst: the LT state
718
719 * These LEDs indicate the physical and logical state of IB link.
720 * For this chip (at least with recommended board pinouts), LED1
721 * is Yellow (logical state) and LED2 is Green (physical state),
722 *
723 * Note: We try to match the Mellanox HCA LED behavior as best
724 * we can. Green indicates physical link state is OK (something is
725 * plugged in, and we can train).
726 * Amber indicates the link is logically up (ACTIVE).
727 * Mellanox further blinks the amber LED to indicate data packet
728 * activity, but we have no hardware support for that, so it would
729 * require waking up every 10-20 msecs and checking the counters
730 * on the chip, and then turning the LED off if appropriate. That's
731 * visible overhead, so not something we will do.
732 *
733 */
734static void ipath_setup_pe_setextled(struct ipath_devdata *dd, u64 lst,
735 u64 ltst)
736{
737 u64 extctl;
738
739 /* the diags use the LED to indicate diag info, so we leave
740 * the external LED alone when the diags are running */
741 if (ipath_diag_inuse)
742 return;
743
744 extctl = dd->ipath_extctrl & ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
745 INFINIPATH_EXTC_LED2PRIPORT_ON);
746
747 if (ltst & INFINIPATH_IBCS_LT_STATE_LINKUP)
748 extctl |= INFINIPATH_EXTC_LED2PRIPORT_ON;
749 if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
750 extctl |= INFINIPATH_EXTC_LED1PRIPORT_ON;
751 dd->ipath_extctrl = extctl;
752 ipath_write_kreg(dd, dd->ipath_kregs->kr_extctrl, extctl);
753}
754
755/**
756 * ipath_setup_pe_cleanup - clean up any per-chip chip-specific stuff
757 * @dd: the infinipath device
758 *
759 * This is called during driver unload.
760 * We do the pci_disable_msi here, not in generic code, because it
761 * isn't used for the HT-400. If we do end up needing pci_enable_msi
762 * at some point in the future for HT-400, we'll move the call back
763 * into the main init_one code.
764 */
765static void ipath_setup_pe_cleanup(struct ipath_devdata *dd)
766{
767 dd->ipath_msi_lo = 0; /* just in case unload fails */
768 pci_disable_msi(dd->pcidev);
769}
770
771/**
772 * ipath_setup_pe_config - setup PCIe config related stuff
773 * @dd: the infinipath device
774 * @pdev: the PCI device
775 *
776 * The pci_enable_msi() call will fail on systems with MSI quirks
777 * such as those with AMD8131, even if the device of interest is not
778 * attached to that device, (in the 2.6.13 - 2.6.15 kernels, at least, fixed
779 * late in 2.6.16).
780 * All that can be done is to edit the kernel source to remove the quirk
781 * check until that is fixed.
782 * We do not need to call enable_msi() for our HyperTransport chip (HT-400),
783 * even those it uses MSI, and we want to avoid the quirk warning, so
784 * So we call enable_msi only for the PE-800. If we do end up needing
785 * pci_enable_msi at some point in the future for HT-400, we'll move the
786 * call back into the main init_one code.
787 * We save the msi lo and hi values, so we can restore them after
788 * chip reset (the kernel PCI infrastructure doesn't yet handle that
789 * correctly).
790 */
791static int ipath_setup_pe_config(struct ipath_devdata *dd,
792 struct pci_dev *pdev)
793{
794 int pos, ret;
795
796 dd->ipath_msi_lo = 0; /* used as a flag during reset processing */
797 ret = pci_enable_msi(dd->pcidev);
798 if (ret)
799 ipath_dev_err(dd, "pci_enable_msi failed: %d, "
800 "interrupts may not work\n", ret);
801 /* continue even if it fails, we may still be OK... */
802
803 if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
804 u16 control;
805 pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
806 &dd->ipath_msi_lo);
807 pci_read_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
808 &dd->ipath_msi_hi);
809 pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
810 &control);
811 /* now save the data (vector) info */
812 pci_read_config_word(dd->pcidev,
813 pos + ((control & PCI_MSI_FLAGS_64BIT)
814 ? 12 : 8),
815 &dd->ipath_msi_data);
816 ipath_cdbg(VERBOSE, "Read msi data 0x%x from config offset "
817 "0x%x, control=0x%x\n", dd->ipath_msi_data,
818 pos + ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
819 control);
820 /* we save the cachelinesize also, although it doesn't
821 * really matter */
822 pci_read_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
823 &dd->ipath_pci_cacheline);
824 } else
825 ipath_dev_err(dd, "Can't find MSI capability, "
826 "can't save MSI settings for reset\n");
827 if ((pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_EXP))) {
828 u16 linkstat;
829 pci_read_config_word(dd->pcidev, pos + PCI_EXP_LNKSTA,
830 &linkstat);
831 linkstat >>= 4;
832 linkstat &= 0x1f;
833 if (linkstat != 8)
834 ipath_dev_err(dd, "PCIe width %u, "
835 "performance reduced\n", linkstat);
836 }
837 else
838 ipath_dev_err(dd, "Can't find PCI Express "
839 "capability!\n");
840 return 0;
841}
842
843static void ipath_init_pe_variables(void)
844{
845 /*
846 * bits for selecting i2c direction and values,
847 * used for I2C serial flash
848 */
849 ipath_gpio_sda_num = _IPATH_GPIO_SDA_NUM;
850 ipath_gpio_scl_num = _IPATH_GPIO_SCL_NUM;
851 ipath_gpio_sda = IPATH_GPIO_SDA;
852 ipath_gpio_scl = IPATH_GPIO_SCL;
853
854 /* variables for sanity checking interrupt and errors */
855 infinipath_hwe_bitsextant =
856 (INFINIPATH_HWE_RXEMEMPARITYERR_MASK <<
857 INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT) |
858 (INFINIPATH_HWE_PCIEMEMPARITYERR_MASK <<
859 INFINIPATH_HWE_PCIEMEMPARITYERR_SHIFT) |
860 INFINIPATH_HWE_PCIE1PLLFAILED |
861 INFINIPATH_HWE_PCIE0PLLFAILED |
862 INFINIPATH_HWE_PCIEPOISONEDTLP |
863 INFINIPATH_HWE_PCIECPLTIMEOUT |
864 INFINIPATH_HWE_PCIEBUSPARITYXTLH |
865 INFINIPATH_HWE_PCIEBUSPARITYXADM |
866 INFINIPATH_HWE_PCIEBUSPARITYRADM |
867 INFINIPATH_HWE_MEMBISTFAILED |
868 INFINIPATH_HWE_COREPLL_FBSLIP |
869 INFINIPATH_HWE_COREPLL_RFSLIP |
870 INFINIPATH_HWE_SERDESPLLFAILED |
871 INFINIPATH_HWE_IBCBUSTOSPCPARITYERR |
872 INFINIPATH_HWE_IBCBUSFRSPCPARITYERR;
873 infinipath_i_bitsextant =
874 (INFINIPATH_I_RCVURG_MASK << INFINIPATH_I_RCVURG_SHIFT) |
875 (INFINIPATH_I_RCVAVAIL_MASK <<
876 INFINIPATH_I_RCVAVAIL_SHIFT) |
877 INFINIPATH_I_ERROR | INFINIPATH_I_SPIOSENT |
878 INFINIPATH_I_SPIOBUFAVAIL | INFINIPATH_I_GPIO;
879 infinipath_e_bitsextant =
880 INFINIPATH_E_RFORMATERR | INFINIPATH_E_RVCRC |
881 INFINIPATH_E_RICRC | INFINIPATH_E_RMINPKTLEN |
882 INFINIPATH_E_RMAXPKTLEN | INFINIPATH_E_RLONGPKTLEN |
883 INFINIPATH_E_RSHORTPKTLEN | INFINIPATH_E_RUNEXPCHAR |
884 INFINIPATH_E_RUNSUPVL | INFINIPATH_E_REBP |
885 INFINIPATH_E_RIBFLOW | INFINIPATH_E_RBADVERSION |
886 INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL |
887 INFINIPATH_E_RBADTID | INFINIPATH_E_RHDRLEN |
888 INFINIPATH_E_RHDR | INFINIPATH_E_RIBLOSTLINK |
889 INFINIPATH_E_SMINPKTLEN | INFINIPATH_E_SMAXPKTLEN |
890 INFINIPATH_E_SUNDERRUN | INFINIPATH_E_SPKTLEN |
891 INFINIPATH_E_SDROPPEDSMPPKT | INFINIPATH_E_SDROPPEDDATAPKT |
892 INFINIPATH_E_SPIOARMLAUNCH | INFINIPATH_E_SUNEXPERRPKTNUM |
893 INFINIPATH_E_SUNSUPVL | INFINIPATH_E_IBSTATUSCHANGED |
894 INFINIPATH_E_INVALIDADDR | INFINIPATH_E_RESET |
895 INFINIPATH_E_HARDWARE;
896
897 infinipath_i_rcvavail_mask = INFINIPATH_I_RCVAVAIL_MASK;
898 infinipath_i_rcvurg_mask = INFINIPATH_I_RCVURG_MASK;
899}
900
901/* setup the MSI stuff again after a reset. I'd like to just call
902 * pci_enable_msi() and request_irq() again, but when I do that,
903 * the MSI enable bit doesn't get set in the command word, and
904 * we switch to to a different interrupt vector, which is confusing,
905 * so I instead just do it all inline. Perhaps somehow can tie this
906 * into the PCIe hotplug support at some point
907 * Note, because I'm doing it all here, I don't call pci_disable_msi()
908 * or free_irq() at the start of ipath_setup_pe_reset().
909 */
910static int ipath_reinit_msi(struct ipath_devdata *dd)
911{
912 int pos;
913 u16 control;
914 int ret;
915
916 if (!dd->ipath_msi_lo) {
917 dev_info(&dd->pcidev->dev, "Can't restore MSI config, "
918 "initial setup failed?\n");
919 ret = 0;
920 goto bail;
921 }
922
923 if (!(pos = pci_find_capability(dd->pcidev, PCI_CAP_ID_MSI))) {
924 ipath_dev_err(dd, "Can't find MSI capability, "
925 "can't restore MSI settings\n");
926 ret = 0;
927 goto bail;
928 }
929 ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
930 dd->ipath_msi_lo, pos + PCI_MSI_ADDRESS_LO);
931 pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_LO,
932 dd->ipath_msi_lo);
933 ipath_cdbg(VERBOSE, "Writing msi_lo 0x%x to config offset 0x%x\n",
934 dd->ipath_msi_hi, pos + PCI_MSI_ADDRESS_HI);
935 pci_write_config_dword(dd->pcidev, pos + PCI_MSI_ADDRESS_HI,
936 dd->ipath_msi_hi);
937 pci_read_config_word(dd->pcidev, pos + PCI_MSI_FLAGS, &control);
938 if (!(control & PCI_MSI_FLAGS_ENABLE)) {
939 ipath_cdbg(VERBOSE, "MSI control at off %x was %x, "
940 "setting MSI enable (%x)\n", pos + PCI_MSI_FLAGS,
941 control, control | PCI_MSI_FLAGS_ENABLE);
942 control |= PCI_MSI_FLAGS_ENABLE;
943 pci_write_config_word(dd->pcidev, pos + PCI_MSI_FLAGS,
944 control);
945 }
946 /* now rewrite the data (vector) info */
947 pci_write_config_word(dd->pcidev, pos +
948 ((control & PCI_MSI_FLAGS_64BIT) ? 12 : 8),
949 dd->ipath_msi_data);
950 /* we restore the cachelinesize also, although it doesn't really
951 * matter */
952 pci_write_config_byte(dd->pcidev, PCI_CACHE_LINE_SIZE,
953 dd->ipath_pci_cacheline);
954 /* and now set the pci master bit again */
955 pci_set_master(dd->pcidev);
956 ret = 1;
957
958bail:
959 return ret;
960}
961
962/* This routine sleeps, so it can only be called from user context, not
963 * from interrupt context. If we need interrupt context, we can split
964 * it into two routines.
965*/
966static int ipath_setup_pe_reset(struct ipath_devdata *dd)
967{
968 u64 val;
969 int i;
970 int ret;
971
972 /* Use ERROR so it shows up in logs, etc. */
973 ipath_dev_err(dd, "Resetting PE-800 unit %u\n",
974 dd->ipath_unit);
975 val = dd->ipath_control | INFINIPATH_C_RESET;
976 ipath_write_kreg(dd, dd->ipath_kregs->kr_control, val);
977 mb();
978
979 for (i = 1; i <= 5; i++) {
980 int r;
981 /* allow MBIST, etc. to complete; longer on each retry.
982 * We sometimes get machine checks from bus timeout if no
983 * response, so for now, make it *really* long.
984 */
985 msleep(1000 + (1 + i) * 2000);
986 if ((r =
987 pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_0,
988 dd->ipath_pcibar0)))
989 ipath_dev_err(dd, "rewrite of BAR0 failed: %d\n",
990 r);
991 if ((r =
992 pci_write_config_dword(dd->pcidev, PCI_BASE_ADDRESS_1,
993 dd->ipath_pcibar1)))
994 ipath_dev_err(dd, "rewrite of BAR1 failed: %d\n",
995 r);
996 /* now re-enable memory access */
997 if ((r = pci_enable_device(dd->pcidev)))
998 ipath_dev_err(dd, "pci_enable_device failed after "
999 "reset: %d\n", r);
1000 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_revision);
1001 if (val == dd->ipath_revision) {
1002 ipath_cdbg(VERBOSE, "Got matching revision "
1003 "register %llx on try %d\n",
1004 (unsigned long long) val, i);
1005 ret = ipath_reinit_msi(dd);
1006 goto bail;
1007 }
1008 /* Probably getting -1 back */
1009 ipath_dbg("Didn't get expected revision register, "
1010 "got %llx, try %d\n", (unsigned long long) val,
1011 i + 1);
1012 }
1013 ret = 0; /* failed */
1014
1015bail:
1016 return ret;
1017}
1018
1019/**
1020 * ipath_pe_put_tid - write a TID in chip
1021 * @dd: the infinipath device
1022 * @tidptr: pointer to the expected TID (in chip) to udpate
1023 * @tidtype: 0 for eager, 1 for expected
1024 * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
1025 *
1026 * This exists as a separate routine to allow for special locking etc.
1027 * It's used for both the full cleanup on exit, as well as the normal
1028 * setup and teardown.
1029 */
1030static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
1031 u32 type, unsigned long pa)
1032{
1033 u32 __iomem *tidp32 = (u32 __iomem *)tidptr;
1034 unsigned long flags = 0; /* keep gcc quiet */
1035
1036 if (pa != dd->ipath_tidinvalid) {
1037 if (pa & ((1U << 11) - 1)) {
1038 dev_info(&dd->pcidev->dev, "BUG: physaddr %lx "
1039 "not 4KB aligned!\n", pa);
1040 return;
1041 }
1042 pa >>= 11;
1043 /* paranoia check */
1044 if (pa & (7<<29))
1045 ipath_dev_err(dd,
1046 "BUG: Physical page address 0x%lx "
1047 "has bits set in 31-29\n", pa);
1048
1049 if (type == 0)
1050 pa |= dd->ipath_tidtemplate;
1051 else /* for now, always full 4KB page */
1052 pa |= 2 << 29;
1053 }
1054
1055 /* workaround chip bug 9437 by writing each TID twice
1056 * and holding a spinlock around the writes, so they don't
1057 * intermix with other TID (eager or expected) writes
1058 * Unfortunately, this call can be done from interrupt level
1059 * for the port 0 eager TIDs, so we have to use irqsave
1060 */
1061 spin_lock_irqsave(&dd->ipath_tid_lock, flags);
1062 ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xfeeddeaf);
1063 if (dd->ipath_kregbase)
1064 writel(pa, tidp32);
1065 ipath_write_kreg(dd, dd->ipath_kregs->kr_scratch, 0xdeadbeef);
1066 mmiowb();
1067 spin_unlock_irqrestore(&dd->ipath_tid_lock, flags);
1068}
1069
1070/**
1071 * ipath_pe_clear_tid - clear all TID entries for a port, expected and eager
1072 * @dd: the infinipath device
1073 * @port: the port
1074 *
1075 * clear all TID entries for a port, expected and eager.
1076 * Used from ipath_close(). On PE800, TIDs are only 32 bits,
1077 * not 64, but they are still on 64 bit boundaries, so tidbase
1078 * is declared as u64 * for the pointer math, even though we write 32 bits
1079 */
1080static void ipath_pe_clear_tids(struct ipath_devdata *dd, unsigned port)
1081{
1082 u64 __iomem *tidbase;
1083 unsigned long tidinv;
1084 int i;
1085
1086 if (!dd->ipath_kregbase)
1087 return;
1088
1089 ipath_cdbg(VERBOSE, "Invalidate TIDs for port %u\n", port);
1090
1091 tidinv = dd->ipath_tidinvalid;
1092 tidbase = (u64 __iomem *)
1093 ((char __iomem *)(dd->ipath_kregbase) +
1094 dd->ipath_rcvtidbase +
1095 port * dd->ipath_rcvtidcnt * sizeof(*tidbase));
1096
1097 for (i = 0; i < dd->ipath_rcvtidcnt; i++)
1098 ipath_pe_put_tid(dd, &tidbase[i], 0, tidinv);
1099
1100 tidbase = (u64 __iomem *)
1101 ((char __iomem *)(dd->ipath_kregbase) +
1102 dd->ipath_rcvegrbase +
1103 port * dd->ipath_rcvegrcnt * sizeof(*tidbase));
1104
1105 for (i = 0; i < dd->ipath_rcvegrcnt; i++)
1106 ipath_pe_put_tid(dd, &tidbase[i], 1, tidinv);
1107}
1108
1109/**
1110 * ipath_pe_tidtemplate - setup constants for TID updates
1111 * @dd: the infinipath device
1112 *
1113 * We setup stuff that we use a lot, to avoid calculating each time
1114 */
1115static void ipath_pe_tidtemplate(struct ipath_devdata *dd)
1116{
1117 u32 egrsize = dd->ipath_rcvegrbufsize;
1118
1119 /* For now, we always allocate 4KB buffers (at init) so we can
1120 * receive max size packets. We may want a module parameter to
1121 * specify 2KB or 4KB and/or make be per port instead of per device
1122 * for those who want to reduce memory footprint. Note that the
1123 * ipath_rcvhdrentsize size must be large enough to hold the largest
1124 * IB header (currently 96 bytes) that we expect to handle (plus of
1125 * course the 2 dwords of RHF).
1126 */
1127 if (egrsize == 2048)
1128 dd->ipath_tidtemplate = 1U << 29;
1129 else if (egrsize == 4096)
1130 dd->ipath_tidtemplate = 2U << 29;
1131 else {
1132 egrsize = 4096;
1133 dev_info(&dd->pcidev->dev, "BUG: unsupported egrbufsize "
1134 "%u, using %u\n", dd->ipath_rcvegrbufsize,
1135 egrsize);
1136 dd->ipath_tidtemplate = 2U << 29;
1137 }
1138 dd->ipath_tidinvalid = 0;
1139}
1140
1141static int ipath_pe_early_init(struct ipath_devdata *dd)
1142{
1143 dd->ipath_flags |= IPATH_4BYTE_TID;
1144
1145 /*
1146 * For openib, we need to be able to handle an IB header of 96 bytes
1147 * or 24 dwords. HT-400 has arbitrary sized receive buffers, so we
1148 * made them the same size as the PIO buffers. The PE-800 does not
1149 * handle arbitrary size buffers, so we need the header large enough
1150 * to handle largest IB header, but still have room for a 2KB MTU
1151 * standard IB packet.
1152 */
1153 dd->ipath_rcvhdrentsize = 24;
1154 dd->ipath_rcvhdrsize = IPATH_DFLT_RCVHDRSIZE;
1155
1156 /* For HT-400, we allocate a somewhat overly large eager buffer,
1157 * such that we can guarantee that we can receive the largest packet
1158 * that we can send out. To truly support a 4KB MTU, we need to
1159 * bump this to a larger value. We'll do this when I get around to
1160 * testing 4KB sends on the PE-800, which I have not yet done.
1161 */
1162 dd->ipath_rcvegrbufsize = 2048;
1163 /*
1164 * the min() check here is currently a nop, but it may not always
1165 * be, depending on just how we do ipath_rcvegrbufsize
1166 */
1167 dd->ipath_ibmaxlen = min(dd->ipath_piosize2k,
1168 dd->ipath_rcvegrbufsize +
1169 (dd->ipath_rcvhdrentsize << 2));
1170 dd->ipath_init_ibmaxlen = dd->ipath_ibmaxlen;
1171
1172 /*
1173 * For PE-800, we can request a receive interrupt for 1 or
1174 * more packets from current offset. For now, we set this
1175 * up for a single packet, to match the HT-400 behavior.
1176 */
1177 dd->ipath_rhdrhead_intr_off = 1ULL<<32;
1178
1179 return 0;
1180}
1181
1182int __attribute__((weak)) ipath_unordered_wc(void)
1183{
1184 return 0;
1185}
1186
1187/**
1188 * ipath_init_pe_get_base_info - set chip-specific flags for user code
1189 * @dd: the infinipath device
1190 * @kbase: ipath_base_info pointer
1191 *
1192 * We set the PCIE flag because the lower bandwidth on PCIe vs
1193 * HyperTransport can affect some user packet algorithims.
1194 */
1195static int ipath_pe_get_base_info(struct ipath_portdata *pd, void *kbase)
1196{
1197 struct ipath_base_info *kinfo = kbase;
1198
1199 if (ipath_unordered_wc()) {
1200 kinfo->spi_runtime_flags |= IPATH_RUNTIME_FORCE_WC_ORDER;
1201 ipath_cdbg(PROC, "Intel processor, forcing WC order\n");
1202 }
1203 else
1204 ipath_cdbg(PROC, "Not Intel processor, WC ordered\n");
1205
1206 kinfo->spi_runtime_flags |= IPATH_RUNTIME_PCIE;
1207
1208 return 0;
1209}
1210
1211/**
1212 * ipath_init_pe800_funcs - set up the chip-specific function pointers
1213 * @dd: the infinipath device
1214 *
1215 * This is global, and is called directly at init to set up the
1216 * chip-specific function pointers for later use.
1217 */
1218void ipath_init_pe800_funcs(struct ipath_devdata *dd)
1219{
1220 dd->ipath_f_intrsetup = ipath_pe_intconfig;
1221 dd->ipath_f_bus = ipath_setup_pe_config;
1222 dd->ipath_f_reset = ipath_setup_pe_reset;
1223 dd->ipath_f_get_boardname = ipath_pe_boardname;
1224 dd->ipath_f_init_hwerrors = ipath_pe_init_hwerrors;
1225 dd->ipath_f_early_init = ipath_pe_early_init;
1226 dd->ipath_f_handle_hwerrors = ipath_pe_handle_hwerrors;
1227 dd->ipath_f_quiet_serdes = ipath_pe_quiet_serdes;
1228 dd->ipath_f_bringup_serdes = ipath_pe_bringup_serdes;
1229 dd->ipath_f_clear_tids = ipath_pe_clear_tids;
1230 dd->ipath_f_put_tid = ipath_pe_put_tid;
1231 dd->ipath_f_cleanup = ipath_setup_pe_cleanup;
1232 dd->ipath_f_setextled = ipath_setup_pe_setextled;
1233 dd->ipath_f_get_base_info = ipath_pe_get_base_info;
1234
1235 /* initialize chip-specific variables */
1236 dd->ipath_f_tidtemplate = ipath_pe_tidtemplate;
1237
1238 /*
1239 * setup the register offsets, since they are different for each
1240 * chip
1241 */
1242 dd->ipath_kregs = &ipath_pe_kregs;
1243 dd->ipath_cregs = &ipath_pe_cregs;
1244
1245 ipath_init_pe_variables();
1246}
1247
diff --git a/drivers/infiniband/hw/ipath/ipath_qp.c b/drivers/infiniband/hw/ipath/ipath_qp.c
new file mode 100644
index 000000000000..6058d70d7577
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_qp.c
@@ -0,0 +1,913 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/err.h>
34#include <linux/vmalloc.h>
35
36#include "ipath_verbs.h"
37#include "ips_common.h"
38
39#define BITS_PER_PAGE (PAGE_SIZE*BITS_PER_BYTE)
40#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
41#define mk_qpn(qpt, map, off) (((map) - (qpt)->map) * BITS_PER_PAGE + \
42 (off))
43#define find_next_offset(map, off) find_next_zero_bit((map)->page, \
44 BITS_PER_PAGE, off)
45
46#define TRANS_INVALID 0
47#define TRANS_ANY2RST 1
48#define TRANS_RST2INIT 2
49#define TRANS_INIT2INIT 3
50#define TRANS_INIT2RTR 4
51#define TRANS_RTR2RTS 5
52#define TRANS_RTS2RTS 6
53#define TRANS_SQERR2RTS 7
54#define TRANS_ANY2ERR 8
55#define TRANS_RTS2SQD 9 /* XXX Wait for expected ACKs & signal event */
56#define TRANS_SQD2SQD 10 /* error if not drained & parameter change */
57#define TRANS_SQD2RTS 11 /* error if not drained */
58
59/*
60 * Convert the AETH credit code into the number of credits.
61 */
62static u32 credit_table[31] = {
63 0, /* 0 */
64 1, /* 1 */
65 2, /* 2 */
66 3, /* 3 */
67 4, /* 4 */
68 6, /* 5 */
69 8, /* 6 */
70 12, /* 7 */
71 16, /* 8 */
72 24, /* 9 */
73 32, /* A */
74 48, /* B */
75 64, /* C */
76 96, /* D */
77 128, /* E */
78 192, /* F */
79 256, /* 10 */
80 384, /* 11 */
81 512, /* 12 */
82 768, /* 13 */
83 1024, /* 14 */
84 1536, /* 15 */
85 2048, /* 16 */
86 3072, /* 17 */
87 4096, /* 18 */
88 6144, /* 19 */
89 8192, /* 1A */
90 12288, /* 1B */
91 16384, /* 1C */
92 24576, /* 1D */
93 32768 /* 1E */
94};
95
96static u32 alloc_qpn(struct ipath_qp_table *qpt)
97{
98 u32 i, offset, max_scan, qpn;
99 struct qpn_map *map;
100 u32 ret;
101
102 qpn = qpt->last + 1;
103 if (qpn >= QPN_MAX)
104 qpn = 2;
105 offset = qpn & BITS_PER_PAGE_MASK;
106 map = &qpt->map[qpn / BITS_PER_PAGE];
107 max_scan = qpt->nmaps - !offset;
108 for (i = 0;;) {
109 if (unlikely(!map->page)) {
110 unsigned long page = get_zeroed_page(GFP_KERNEL);
111 unsigned long flags;
112
113 /*
114 * Free the page if someone raced with us
115 * installing it:
116 */
117 spin_lock_irqsave(&qpt->lock, flags);
118 if (map->page)
119 free_page(page);
120 else
121 map->page = (void *)page;
122 spin_unlock_irqrestore(&qpt->lock, flags);
123 if (unlikely(!map->page))
124 break;
125 }
126 if (likely(atomic_read(&map->n_free))) {
127 do {
128 if (!test_and_set_bit(offset, map->page)) {
129 atomic_dec(&map->n_free);
130 qpt->last = qpn;
131 ret = qpn;
132 goto bail;
133 }
134 offset = find_next_offset(map, offset);
135 qpn = mk_qpn(qpt, map, offset);
136 /*
137 * This test differs from alloc_pidmap().
138 * If find_next_offset() does find a zero
139 * bit, we don't need to check for QPN
140 * wrapping around past our starting QPN.
141 * We just need to be sure we don't loop
142 * forever.
143 */
144 } while (offset < BITS_PER_PAGE && qpn < QPN_MAX);
145 }
146 /*
147 * In order to keep the number of pages allocated to a
148 * minimum, we scan the all existing pages before increasing
149 * the size of the bitmap table.
150 */
151 if (++i > max_scan) {
152 if (qpt->nmaps == QPNMAP_ENTRIES)
153 break;
154 map = &qpt->map[qpt->nmaps++];
155 offset = 0;
156 } else if (map < &qpt->map[qpt->nmaps]) {
157 ++map;
158 offset = 0;
159 } else {
160 map = &qpt->map[0];
161 offset = 2;
162 }
163 qpn = mk_qpn(qpt, map, offset);
164 }
165
166 ret = 0;
167
168bail:
169 return ret;
170}
171
172static void free_qpn(struct ipath_qp_table *qpt, u32 qpn)
173{
174 struct qpn_map *map;
175
176 map = qpt->map + qpn / BITS_PER_PAGE;
177 if (map->page)
178 clear_bit(qpn & BITS_PER_PAGE_MASK, map->page);
179 atomic_inc(&map->n_free);
180}
181
182/**
183 * ipath_alloc_qpn - allocate a QP number
184 * @qpt: the QP table
185 * @qp: the QP
186 * @type: the QP type (IB_QPT_SMI and IB_QPT_GSI are special)
187 *
188 * Allocate the next available QPN and put the QP into the hash table.
189 * The hash table holds a reference to the QP.
190 */
191int ipath_alloc_qpn(struct ipath_qp_table *qpt, struct ipath_qp *qp,
192 enum ib_qp_type type)
193{
194 unsigned long flags;
195 u32 qpn;
196 int ret;
197
198 if (type == IB_QPT_SMI)
199 qpn = 0;
200 else if (type == IB_QPT_GSI)
201 qpn = 1;
202 else {
203 /* Allocate the next available QPN */
204 qpn = alloc_qpn(qpt);
205 if (qpn == 0) {
206 ret = -ENOMEM;
207 goto bail;
208 }
209 }
210 qp->ibqp.qp_num = qpn;
211
212 /* Add the QP to the hash table. */
213 spin_lock_irqsave(&qpt->lock, flags);
214
215 qpn %= qpt->max;
216 qp->next = qpt->table[qpn];
217 qpt->table[qpn] = qp;
218 atomic_inc(&qp->refcount);
219
220 spin_unlock_irqrestore(&qpt->lock, flags);
221 ret = 0;
222
223bail:
224 return ret;
225}
226
227/**
228 * ipath_free_qp - remove a QP from the QP table
229 * @qpt: the QP table
230 * @qp: the QP to remove
231 *
232 * Remove the QP from the table so it can't be found asynchronously by
233 * the receive interrupt routine.
234 */
235void ipath_free_qp(struct ipath_qp_table *qpt, struct ipath_qp *qp)
236{
237 struct ipath_qp *q, **qpp;
238 unsigned long flags;
239 int fnd = 0;
240
241 spin_lock_irqsave(&qpt->lock, flags);
242
243 /* Remove QP from the hash table. */
244 qpp = &qpt->table[qp->ibqp.qp_num % qpt->max];
245 for (; (q = *qpp) != NULL; qpp = &q->next) {
246 if (q == qp) {
247 *qpp = qp->next;
248 qp->next = NULL;
249 atomic_dec(&qp->refcount);
250 fnd = 1;
251 break;
252 }
253 }
254
255 spin_unlock_irqrestore(&qpt->lock, flags);
256
257 if (!fnd)
258 return;
259
260 /* If QPN is not reserved, mark QPN free in the bitmap. */
261 if (qp->ibqp.qp_num > 1)
262 free_qpn(qpt, qp->ibqp.qp_num);
263
264 wait_event(qp->wait, !atomic_read(&qp->refcount));
265}
266
267/**
268 * ipath_free_all_qps - remove all QPs from the table
269 * @qpt: the QP table to empty
270 */
271void ipath_free_all_qps(struct ipath_qp_table *qpt)
272{
273 unsigned long flags;
274 struct ipath_qp *qp, *nqp;
275 u32 n;
276
277 for (n = 0; n < qpt->max; n++) {
278 spin_lock_irqsave(&qpt->lock, flags);
279 qp = qpt->table[n];
280 qpt->table[n] = NULL;
281 spin_unlock_irqrestore(&qpt->lock, flags);
282
283 while (qp) {
284 nqp = qp->next;
285 if (qp->ibqp.qp_num > 1)
286 free_qpn(qpt, qp->ibqp.qp_num);
287 if (!atomic_dec_and_test(&qp->refcount) ||
288 !ipath_destroy_qp(&qp->ibqp))
289 _VERBS_INFO("QP memory leak!\n");
290 qp = nqp;
291 }
292 }
293
294 for (n = 0; n < ARRAY_SIZE(qpt->map); n++) {
295 if (qpt->map[n].page)
296 free_page((unsigned long)qpt->map[n].page);
297 }
298}
299
300/**
301 * ipath_lookup_qpn - return the QP with the given QPN
302 * @qpt: the QP table
303 * @qpn: the QP number to look up
304 *
305 * The caller is responsible for decrementing the QP reference count
306 * when done.
307 */
308struct ipath_qp *ipath_lookup_qpn(struct ipath_qp_table *qpt, u32 qpn)
309{
310 unsigned long flags;
311 struct ipath_qp *qp;
312
313 spin_lock_irqsave(&qpt->lock, flags);
314
315 for (qp = qpt->table[qpn % qpt->max]; qp; qp = qp->next) {
316 if (qp->ibqp.qp_num == qpn) {
317 atomic_inc(&qp->refcount);
318 break;
319 }
320 }
321
322 spin_unlock_irqrestore(&qpt->lock, flags);
323 return qp;
324}
325
326/**
327 * ipath_reset_qp - initialize the QP state to the reset state
328 * @qp: the QP to reset
329 */
330static void ipath_reset_qp(struct ipath_qp *qp)
331{
332 qp->remote_qpn = 0;
333 qp->qkey = 0;
334 qp->qp_access_flags = 0;
335 qp->s_hdrwords = 0;
336 qp->s_psn = 0;
337 qp->r_psn = 0;
338 atomic_set(&qp->msn, 0);
339 if (qp->ibqp.qp_type == IB_QPT_RC) {
340 qp->s_state = IB_OPCODE_RC_SEND_LAST;
341 qp->r_state = IB_OPCODE_RC_SEND_LAST;
342 } else {
343 qp->s_state = IB_OPCODE_UC_SEND_LAST;
344 qp->r_state = IB_OPCODE_UC_SEND_LAST;
345 }
346 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
347 qp->s_nak_state = 0;
348 qp->s_rnr_timeout = 0;
349 qp->s_head = 0;
350 qp->s_tail = 0;
351 qp->s_cur = 0;
352 qp->s_last = 0;
353 qp->s_ssn = 1;
354 qp->s_lsn = 0;
355 qp->r_rq.head = 0;
356 qp->r_rq.tail = 0;
357 qp->r_reuse_sge = 0;
358}
359
360/**
361 * ipath_modify_qp - modify the attributes of a queue pair
362 * @ibqp: the queue pair who's attributes we're modifying
363 * @attr: the new attributes
364 * @attr_mask: the mask of attributes to modify
365 *
366 * Returns 0 on success, otherwise returns an errno.
367 */
368int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
369 int attr_mask)
370{
371 struct ipath_qp *qp = to_iqp(ibqp);
372 enum ib_qp_state cur_state, new_state;
373 unsigned long flags;
374 int ret;
375
376 spin_lock_irqsave(&qp->r_rq.lock, flags);
377 spin_lock(&qp->s_lock);
378
379 cur_state = attr_mask & IB_QP_CUR_STATE ?
380 attr->cur_qp_state : qp->state;
381 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
382
383 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
384 attr_mask))
385 goto inval;
386
387 switch (new_state) {
388 case IB_QPS_RESET:
389 ipath_reset_qp(qp);
390 break;
391
392 case IB_QPS_ERR:
393 ipath_error_qp(qp);
394 break;
395
396 default:
397 break;
398
399 }
400
401 if (attr_mask & IB_QP_PKEY_INDEX) {
402 struct ipath_ibdev *dev = to_idev(ibqp->device);
403
404 if (attr->pkey_index >= ipath_layer_get_npkeys(dev->dd))
405 goto inval;
406 qp->s_pkey_index = attr->pkey_index;
407 }
408
409 if (attr_mask & IB_QP_DEST_QPN)
410 qp->remote_qpn = attr->dest_qp_num;
411
412 if (attr_mask & IB_QP_SQ_PSN) {
413 qp->s_next_psn = attr->sq_psn;
414 qp->s_last_psn = qp->s_next_psn - 1;
415 }
416
417 if (attr_mask & IB_QP_RQ_PSN)
418 qp->r_psn = attr->rq_psn;
419
420 if (attr_mask & IB_QP_ACCESS_FLAGS)
421 qp->qp_access_flags = attr->qp_access_flags;
422
423 if (attr_mask & IB_QP_AV) {
424 if (attr->ah_attr.dlid == 0 ||
425 attr->ah_attr.dlid >= IPS_MULTICAST_LID_BASE)
426 goto inval;
427 qp->remote_ah_attr = attr->ah_attr;
428 }
429
430 if (attr_mask & IB_QP_PATH_MTU)
431 qp->path_mtu = attr->path_mtu;
432
433 if (attr_mask & IB_QP_RETRY_CNT)
434 qp->s_retry = qp->s_retry_cnt = attr->retry_cnt;
435
436 if (attr_mask & IB_QP_RNR_RETRY) {
437 qp->s_rnr_retry = attr->rnr_retry;
438 if (qp->s_rnr_retry > 7)
439 qp->s_rnr_retry = 7;
440 qp->s_rnr_retry_cnt = qp->s_rnr_retry;
441 }
442
443 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
444 if (attr->min_rnr_timer > 31)
445 goto inval;
446 qp->s_min_rnr_timer = attr->min_rnr_timer;
447 }
448
449 if (attr_mask & IB_QP_QKEY)
450 qp->qkey = attr->qkey;
451
452 if (attr_mask & IB_QP_PKEY_INDEX)
453 qp->s_pkey_index = attr->pkey_index;
454
455 qp->state = new_state;
456 spin_unlock(&qp->s_lock);
457 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
458
459 /*
460 * If QP1 changed to the RTS state, try to move to the link to INIT
461 * even if it was ACTIVE so the SM will reinitialize the SMA's
462 * state.
463 */
464 if (qp->ibqp.qp_num == 1 && new_state == IB_QPS_RTS) {
465 struct ipath_ibdev *dev = to_idev(ibqp->device);
466
467 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
468 }
469 ret = 0;
470 goto bail;
471
472inval:
473 spin_unlock(&qp->s_lock);
474 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
475 ret = -EINVAL;
476
477bail:
478 return ret;
479}
480
481int ipath_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
482 int attr_mask, struct ib_qp_init_attr *init_attr)
483{
484 struct ipath_qp *qp = to_iqp(ibqp);
485
486 attr->qp_state = qp->state;
487 attr->cur_qp_state = attr->qp_state;
488 attr->path_mtu = qp->path_mtu;
489 attr->path_mig_state = 0;
490 attr->qkey = qp->qkey;
491 attr->rq_psn = qp->r_psn;
492 attr->sq_psn = qp->s_next_psn;
493 attr->dest_qp_num = qp->remote_qpn;
494 attr->qp_access_flags = qp->qp_access_flags;
495 attr->cap.max_send_wr = qp->s_size - 1;
496 attr->cap.max_recv_wr = qp->r_rq.size - 1;
497 attr->cap.max_send_sge = qp->s_max_sge;
498 attr->cap.max_recv_sge = qp->r_rq.max_sge;
499 attr->cap.max_inline_data = 0;
500 attr->ah_attr = qp->remote_ah_attr;
501 memset(&attr->alt_ah_attr, 0, sizeof(attr->alt_ah_attr));
502 attr->pkey_index = qp->s_pkey_index;
503 attr->alt_pkey_index = 0;
504 attr->en_sqd_async_notify = 0;
505 attr->sq_draining = 0;
506 attr->max_rd_atomic = 1;
507 attr->max_dest_rd_atomic = 1;
508 attr->min_rnr_timer = qp->s_min_rnr_timer;
509 attr->port_num = 1;
510 attr->timeout = 0;
511 attr->retry_cnt = qp->s_retry_cnt;
512 attr->rnr_retry = qp->s_rnr_retry;
513 attr->alt_port_num = 0;
514 attr->alt_timeout = 0;
515
516 init_attr->event_handler = qp->ibqp.event_handler;
517 init_attr->qp_context = qp->ibqp.qp_context;
518 init_attr->send_cq = qp->ibqp.send_cq;
519 init_attr->recv_cq = qp->ibqp.recv_cq;
520 init_attr->srq = qp->ibqp.srq;
521 init_attr->cap = attr->cap;
522 init_attr->sq_sig_type =
523 (qp->s_flags & (1 << IPATH_S_SIGNAL_REQ_WR))
524 ? IB_SIGNAL_REQ_WR : 0;
525 init_attr->qp_type = qp->ibqp.qp_type;
526 init_attr->port_num = 1;
527 return 0;
528}
529
530/**
531 * ipath_compute_aeth - compute the AETH (syndrome + MSN)
532 * @qp: the queue pair to compute the AETH for
533 *
534 * Returns the AETH.
535 *
536 * The QP s_lock should be held.
537 */
538__be32 ipath_compute_aeth(struct ipath_qp *qp)
539{
540 u32 aeth = atomic_read(&qp->msn) & IPS_MSN_MASK;
541
542 if (qp->s_nak_state) {
543 aeth |= qp->s_nak_state << IPS_AETH_CREDIT_SHIFT;
544 } else if (qp->ibqp.srq) {
545 /*
546 * Shared receive queues don't generate credits.
547 * Set the credit field to the invalid value.
548 */
549 aeth |= IPS_AETH_CREDIT_INVAL << IPS_AETH_CREDIT_SHIFT;
550 } else {
551 u32 min, max, x;
552 u32 credits;
553
554 /*
555 * Compute the number of credits available (RWQEs).
556 * XXX Not holding the r_rq.lock here so there is a small
557 * chance that the pair of reads are not atomic.
558 */
559 credits = qp->r_rq.head - qp->r_rq.tail;
560 if ((int)credits < 0)
561 credits += qp->r_rq.size;
562 /*
563 * Binary search the credit table to find the code to
564 * use.
565 */
566 min = 0;
567 max = 31;
568 for (;;) {
569 x = (min + max) / 2;
570 if (credit_table[x] == credits)
571 break;
572 if (credit_table[x] > credits)
573 max = x;
574 else if (min == x)
575 break;
576 else
577 min = x;
578 }
579 aeth |= x << IPS_AETH_CREDIT_SHIFT;
580 }
581 return cpu_to_be32(aeth);
582}
583
584/**
585 * ipath_create_qp - create a queue pair for a device
586 * @ibpd: the protection domain who's device we create the queue pair for
587 * @init_attr: the attributes of the queue pair
588 * @udata: unused by InfiniPath
589 *
590 * Returns the queue pair on success, otherwise returns an errno.
591 *
592 * Called by the ib_create_qp() core verbs function.
593 */
594struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
595 struct ib_qp_init_attr *init_attr,
596 struct ib_udata *udata)
597{
598 struct ipath_qp *qp;
599 int err;
600 struct ipath_swqe *swq = NULL;
601 struct ipath_ibdev *dev;
602 size_t sz;
603 struct ib_qp *ret;
604
605 if (init_attr->cap.max_send_sge > 255 ||
606 init_attr->cap.max_recv_sge > 255) {
607 ret = ERR_PTR(-ENOMEM);
608 goto bail;
609 }
610
611 switch (init_attr->qp_type) {
612 case IB_QPT_UC:
613 case IB_QPT_RC:
614 sz = sizeof(struct ipath_sge) *
615 init_attr->cap.max_send_sge +
616 sizeof(struct ipath_swqe);
617 swq = vmalloc((init_attr->cap.max_send_wr + 1) * sz);
618 if (swq == NULL) {
619 ret = ERR_PTR(-ENOMEM);
620 goto bail;
621 }
622 /* FALLTHROUGH */
623 case IB_QPT_UD:
624 case IB_QPT_SMI:
625 case IB_QPT_GSI:
626 qp = kmalloc(sizeof(*qp), GFP_KERNEL);
627 if (!qp) {
628 ret = ERR_PTR(-ENOMEM);
629 goto bail;
630 }
631 qp->r_rq.size = init_attr->cap.max_recv_wr + 1;
632 sz = sizeof(struct ipath_sge) *
633 init_attr->cap.max_recv_sge +
634 sizeof(struct ipath_rwqe);
635 qp->r_rq.wq = vmalloc(qp->r_rq.size * sz);
636 if (!qp->r_rq.wq) {
637 kfree(qp);
638 ret = ERR_PTR(-ENOMEM);
639 goto bail;
640 }
641
642 /*
643 * ib_create_qp() will initialize qp->ibqp
644 * except for qp->ibqp.qp_num.
645 */
646 spin_lock_init(&qp->s_lock);
647 spin_lock_init(&qp->r_rq.lock);
648 atomic_set(&qp->refcount, 0);
649 init_waitqueue_head(&qp->wait);
650 tasklet_init(&qp->s_task,
651 init_attr->qp_type == IB_QPT_RC ?
652 ipath_do_rc_send : ipath_do_uc_send,
653 (unsigned long)qp);
654 qp->piowait.next = LIST_POISON1;
655 qp->piowait.prev = LIST_POISON2;
656 qp->timerwait.next = LIST_POISON1;
657 qp->timerwait.prev = LIST_POISON2;
658 qp->state = IB_QPS_RESET;
659 qp->s_wq = swq;
660 qp->s_size = init_attr->cap.max_send_wr + 1;
661 qp->s_max_sge = init_attr->cap.max_send_sge;
662 qp->r_rq.max_sge = init_attr->cap.max_recv_sge;
663 qp->s_flags = init_attr->sq_sig_type == IB_SIGNAL_REQ_WR ?
664 1 << IPATH_S_SIGNAL_REQ_WR : 0;
665 dev = to_idev(ibpd->device);
666 err = ipath_alloc_qpn(&dev->qp_table, qp,
667 init_attr->qp_type);
668 if (err) {
669 vfree(swq);
670 vfree(qp->r_rq.wq);
671 kfree(qp);
672 ret = ERR_PTR(err);
673 goto bail;
674 }
675 ipath_reset_qp(qp);
676
677 /* Tell the core driver that the kernel SMA is present. */
678 if (qp->ibqp.qp_type == IB_QPT_SMI)
679 ipath_layer_set_verbs_flags(dev->dd,
680 IPATH_VERBS_KERNEL_SMA);
681 break;
682
683 default:
684 /* Don't support raw QPs */
685 ret = ERR_PTR(-ENOSYS);
686 goto bail;
687 }
688
689 init_attr->cap.max_inline_data = 0;
690
691 ret = &qp->ibqp;
692
693bail:
694 return ret;
695}
696
697/**
698 * ipath_destroy_qp - destroy a queue pair
699 * @ibqp: the queue pair to destroy
700 *
701 * Returns 0 on success.
702 *
703 * Note that this can be called while the QP is actively sending or
704 * receiving!
705 */
706int ipath_destroy_qp(struct ib_qp *ibqp)
707{
708 struct ipath_qp *qp = to_iqp(ibqp);
709 struct ipath_ibdev *dev = to_idev(ibqp->device);
710 unsigned long flags;
711
712 /* Tell the core driver that the kernel SMA is gone. */
713 if (qp->ibqp.qp_type == IB_QPT_SMI)
714 ipath_layer_set_verbs_flags(dev->dd, 0);
715
716 spin_lock_irqsave(&qp->r_rq.lock, flags);
717 spin_lock(&qp->s_lock);
718 qp->state = IB_QPS_ERR;
719 spin_unlock(&qp->s_lock);
720 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
721
722 /* Stop the sending tasklet. */
723 tasklet_kill(&qp->s_task);
724
725 /* Make sure the QP isn't on the timeout list. */
726 spin_lock_irqsave(&dev->pending_lock, flags);
727 if (qp->timerwait.next != LIST_POISON1)
728 list_del(&qp->timerwait);
729 if (qp->piowait.next != LIST_POISON1)
730 list_del(&qp->piowait);
731 spin_unlock_irqrestore(&dev->pending_lock, flags);
732
733 /*
734 * Make sure that the QP is not in the QPN table so receive
735 * interrupts will discard packets for this QP. XXX Also remove QP
736 * from multicast table.
737 */
738 if (atomic_read(&qp->refcount) != 0)
739 ipath_free_qp(&dev->qp_table, qp);
740
741 vfree(qp->s_wq);
742 vfree(qp->r_rq.wq);
743 kfree(qp);
744 return 0;
745}
746
747/**
748 * ipath_init_qp_table - initialize the QP table for a device
749 * @idev: the device who's QP table we're initializing
750 * @size: the size of the QP table
751 *
752 * Returns 0 on success, otherwise returns an errno.
753 */
754int ipath_init_qp_table(struct ipath_ibdev *idev, int size)
755{
756 int i;
757 int ret;
758
759 idev->qp_table.last = 1; /* QPN 0 and 1 are special. */
760 idev->qp_table.max = size;
761 idev->qp_table.nmaps = 1;
762 idev->qp_table.table = kzalloc(size * sizeof(*idev->qp_table.table),
763 GFP_KERNEL);
764 if (idev->qp_table.table == NULL) {
765 ret = -ENOMEM;
766 goto bail;
767 }
768
769 for (i = 0; i < ARRAY_SIZE(idev->qp_table.map); i++) {
770 atomic_set(&idev->qp_table.map[i].n_free, BITS_PER_PAGE);
771 idev->qp_table.map[i].page = NULL;
772 }
773
774 ret = 0;
775
776bail:
777 return ret;
778}
779
780/**
781 * ipath_sqerror_qp - put a QP's send queue into an error state
782 * @qp: QP who's send queue will be put into an error state
783 * @wc: the WC responsible for putting the QP in this state
784 *
785 * Flushes the send work queue.
786 * The QP s_lock should be held.
787 */
788
789void ipath_sqerror_qp(struct ipath_qp *qp, struct ib_wc *wc)
790{
791 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
792 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
793
794 _VERBS_INFO("Send queue error on QP%d/%d: err: %d\n",
795 qp->ibqp.qp_num, qp->remote_qpn, wc->status);
796
797 spin_lock(&dev->pending_lock);
798 /* XXX What if its already removed by the timeout code? */
799 if (qp->timerwait.next != LIST_POISON1)
800 list_del(&qp->timerwait);
801 if (qp->piowait.next != LIST_POISON1)
802 list_del(&qp->piowait);
803 spin_unlock(&dev->pending_lock);
804
805 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1);
806 if (++qp->s_last >= qp->s_size)
807 qp->s_last = 0;
808
809 wc->status = IB_WC_WR_FLUSH_ERR;
810
811 while (qp->s_last != qp->s_head) {
812 wc->wr_id = wqe->wr.wr_id;
813 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
814 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 1);
815 if (++qp->s_last >= qp->s_size)
816 qp->s_last = 0;
817 wqe = get_swqe_ptr(qp, qp->s_last);
818 }
819 qp->s_cur = qp->s_tail = qp->s_head;
820 qp->state = IB_QPS_SQE;
821}
822
823/**
824 * ipath_error_qp - put a QP into an error state
825 * @qp: the QP to put into an error state
826 *
827 * Flushes both send and receive work queues.
828 * QP r_rq.lock and s_lock should be held.
829 */
830
831void ipath_error_qp(struct ipath_qp *qp)
832{
833 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
834 struct ib_wc wc;
835
836 _VERBS_INFO("QP%d/%d in error state\n",
837 qp->ibqp.qp_num, qp->remote_qpn);
838
839 spin_lock(&dev->pending_lock);
840 /* XXX What if its already removed by the timeout code? */
841 if (qp->timerwait.next != LIST_POISON1)
842 list_del(&qp->timerwait);
843 if (qp->piowait.next != LIST_POISON1)
844 list_del(&qp->piowait);
845 spin_unlock(&dev->pending_lock);
846
847 wc.status = IB_WC_WR_FLUSH_ERR;
848 wc.vendor_err = 0;
849 wc.byte_len = 0;
850 wc.imm_data = 0;
851 wc.qp_num = qp->ibqp.qp_num;
852 wc.src_qp = 0;
853 wc.wc_flags = 0;
854 wc.pkey_index = 0;
855 wc.slid = 0;
856 wc.sl = 0;
857 wc.dlid_path_bits = 0;
858 wc.port_num = 0;
859
860 while (qp->s_last != qp->s_head) {
861 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
862
863 wc.wr_id = wqe->wr.wr_id;
864 wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
865 if (++qp->s_last >= qp->s_size)
866 qp->s_last = 0;
867 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 1);
868 }
869 qp->s_cur = qp->s_tail = qp->s_head;
870 qp->s_hdrwords = 0;
871 qp->s_ack_state = IB_OPCODE_RC_ACKNOWLEDGE;
872
873 wc.opcode = IB_WC_RECV;
874 while (qp->r_rq.tail != qp->r_rq.head) {
875 wc.wr_id = get_rwqe_ptr(&qp->r_rq, qp->r_rq.tail)->wr_id;
876 if (++qp->r_rq.tail >= qp->r_rq.size)
877 qp->r_rq.tail = 0;
878 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 1);
879 }
880}
881
882/**
883 * ipath_get_credit - flush the send work queue of a QP
884 * @qp: the qp who's send work queue to flush
885 * @aeth: the Acknowledge Extended Transport Header
886 *
887 * The QP s_lock should be held.
888 */
889void ipath_get_credit(struct ipath_qp *qp, u32 aeth)
890{
891 u32 credit = (aeth >> IPS_AETH_CREDIT_SHIFT) & IPS_AETH_CREDIT_MASK;
892
893 /*
894 * If the credit is invalid, we can send
895 * as many packets as we like. Otherwise, we have to
896 * honor the credit field.
897 */
898 if (credit == IPS_AETH_CREDIT_INVAL) {
899 qp->s_lsn = (u32) -1;
900 } else if (qp->s_lsn != (u32) -1) {
901 /* Compute new LSN (i.e., MSN + credit) */
902 credit = (aeth + credit_table[credit]) & IPS_MSN_MASK;
903 if (ipath_cmp24(credit, qp->s_lsn) > 0)
904 qp->s_lsn = credit;
905 }
906
907 /* Restart sending if it was blocked due to lack of credits. */
908 if (qp->s_cur != qp->s_head &&
909 (qp->s_lsn == (u32) -1 ||
910 ipath_cmp24(get_swqe_ptr(qp, qp->s_cur)->ssn,
911 qp->s_lsn + 1) <= 0))
912 tasklet_hi_schedule(&qp->s_task);
913}
diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
new file mode 100644
index 000000000000..a4055ca00614
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
@@ -0,0 +1,1857 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include "ipath_verbs.h"
34#include "ips_common.h"
35
36/* cut down ridiculously long IB macro names */
37#define OP(x) IB_OPCODE_RC_##x
38
39/**
40 * ipath_init_restart- initialize the qp->s_sge after a restart
41 * @qp: the QP who's SGE we're restarting
42 * @wqe: the work queue to initialize the QP's SGE from
43 *
44 * The QP s_lock should be held.
45 */
46static void ipath_init_restart(struct ipath_qp *qp, struct ipath_swqe *wqe)
47{
48 struct ipath_ibdev *dev;
49 u32 len;
50
51 len = ((qp->s_psn - wqe->psn) & IPS_PSN_MASK) *
52 ib_mtu_enum_to_int(qp->path_mtu);
53 qp->s_sge.sge = wqe->sg_list[0];
54 qp->s_sge.sg_list = wqe->sg_list + 1;
55 qp->s_sge.num_sge = wqe->wr.num_sge;
56 ipath_skip_sge(&qp->s_sge, len);
57 qp->s_len = wqe->length - len;
58 dev = to_idev(qp->ibqp.device);
59 spin_lock(&dev->pending_lock);
60 if (qp->timerwait.next == LIST_POISON1)
61 list_add_tail(&qp->timerwait,
62 &dev->pending[dev->pending_index]);
63 spin_unlock(&dev->pending_lock);
64}
65
66/**
67 * ipath_make_rc_ack - construct a response packet (ACK, NAK, or RDMA read)
68 * @qp: a pointer to the QP
69 * @ohdr: a pointer to the IB header being constructed
70 * @pmtu: the path MTU
71 *
72 * Return bth0 if constructed; otherwise, return 0.
73 * Note the QP s_lock must be held.
74 */
75static inline u32 ipath_make_rc_ack(struct ipath_qp *qp,
76 struct ipath_other_headers *ohdr,
77 u32 pmtu)
78{
79 struct ipath_sge_state *ss;
80 u32 hwords;
81 u32 len;
82 u32 bth0;
83
84 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
85 hwords = 5;
86
87 /*
88 * Send a response. Note that we are in the responder's
89 * side of the QP context.
90 */
91 switch (qp->s_ack_state) {
92 case OP(RDMA_READ_REQUEST):
93 ss = &qp->s_rdma_sge;
94 len = qp->s_rdma_len;
95 if (len > pmtu) {
96 len = pmtu;
97 qp->s_ack_state = OP(RDMA_READ_RESPONSE_FIRST);
98 }
99 else
100 qp->s_ack_state = OP(RDMA_READ_RESPONSE_ONLY);
101 qp->s_rdma_len -= len;
102 bth0 = qp->s_ack_state << 24;
103 ohdr->u.aeth = ipath_compute_aeth(qp);
104 hwords++;
105 break;
106
107 case OP(RDMA_READ_RESPONSE_FIRST):
108 qp->s_ack_state = OP(RDMA_READ_RESPONSE_MIDDLE);
109 /* FALLTHROUGH */
110 case OP(RDMA_READ_RESPONSE_MIDDLE):
111 ss = &qp->s_rdma_sge;
112 len = qp->s_rdma_len;
113 if (len > pmtu)
114 len = pmtu;
115 else {
116 ohdr->u.aeth = ipath_compute_aeth(qp);
117 hwords++;
118 qp->s_ack_state = OP(RDMA_READ_RESPONSE_LAST);
119 }
120 qp->s_rdma_len -= len;
121 bth0 = qp->s_ack_state << 24;
122 break;
123
124 case OP(RDMA_READ_RESPONSE_LAST):
125 case OP(RDMA_READ_RESPONSE_ONLY):
126 /*
127 * We have to prevent new requests from changing
128 * the r_sge state while a ipath_verbs_send()
129 * is in progress.
130 * Changing r_state allows the receiver
131 * to continue processing new packets.
132 * We do it here now instead of above so
133 * that we are sure the packet was sent before
134 * changing the state.
135 */
136 qp->r_state = OP(RDMA_READ_RESPONSE_LAST);
137 qp->s_ack_state = OP(ACKNOWLEDGE);
138 return 0;
139
140 case OP(COMPARE_SWAP):
141 case OP(FETCH_ADD):
142 ss = NULL;
143 len = 0;
144 qp->r_state = OP(SEND_LAST);
145 qp->s_ack_state = OP(ACKNOWLEDGE);
146 bth0 = IB_OPCODE_ATOMIC_ACKNOWLEDGE << 24;
147 ohdr->u.at.aeth = ipath_compute_aeth(qp);
148 ohdr->u.at.atomic_ack_eth = cpu_to_be64(qp->s_ack_atomic);
149 hwords += sizeof(ohdr->u.at) / 4;
150 break;
151
152 default:
153 /* Send a regular ACK. */
154 ss = NULL;
155 len = 0;
156 qp->s_ack_state = OP(ACKNOWLEDGE);
157 bth0 = qp->s_ack_state << 24;
158 ohdr->u.aeth = ipath_compute_aeth(qp);
159 hwords++;
160 }
161 qp->s_hdrwords = hwords;
162 qp->s_cur_sge = ss;
163 qp->s_cur_size = len;
164
165 return bth0;
166}
167
168/**
169 * ipath_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC)
170 * @qp: a pointer to the QP
171 * @ohdr: a pointer to the IB header being constructed
172 * @pmtu: the path MTU
173 * @bth0p: pointer to the BTH opcode word
174 * @bth2p: pointer to the BTH PSN word
175 *
176 * Return 1 if constructed; otherwise, return 0.
177 * Note the QP s_lock must be held.
178 */
179static inline int ipath_make_rc_req(struct ipath_qp *qp,
180 struct ipath_other_headers *ohdr,
181 u32 pmtu, u32 *bth0p, u32 *bth2p)
182{
183 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
184 struct ipath_sge_state *ss;
185 struct ipath_swqe *wqe;
186 u32 hwords;
187 u32 len;
188 u32 bth0;
189 u32 bth2;
190 char newreq;
191
192 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK) ||
193 qp->s_rnr_timeout)
194 goto done;
195
196 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
197 hwords = 5;
198 bth0 = 0;
199
200 /* Send a request. */
201 wqe = get_swqe_ptr(qp, qp->s_cur);
202 switch (qp->s_state) {
203 default:
204 /*
205 * Resend an old request or start a new one.
206 *
207 * We keep track of the current SWQE so that
208 * we don't reset the "furthest progress" state
209 * if we need to back up.
210 */
211 newreq = 0;
212 if (qp->s_cur == qp->s_tail) {
213 /* Check if send work queue is empty. */
214 if (qp->s_tail == qp->s_head)
215 goto done;
216 qp->s_psn = wqe->psn = qp->s_next_psn;
217 newreq = 1;
218 }
219 /*
220 * Note that we have to be careful not to modify the
221 * original work request since we may need to resend
222 * it.
223 */
224 qp->s_sge.sge = wqe->sg_list[0];
225 qp->s_sge.sg_list = wqe->sg_list + 1;
226 qp->s_sge.num_sge = wqe->wr.num_sge;
227 qp->s_len = len = wqe->length;
228 ss = &qp->s_sge;
229 bth2 = 0;
230 switch (wqe->wr.opcode) {
231 case IB_WR_SEND:
232 case IB_WR_SEND_WITH_IMM:
233 /* If no credit, return. */
234 if (qp->s_lsn != (u32) -1 &&
235 ipath_cmp24(wqe->ssn, qp->s_lsn + 1) > 0)
236 goto done;
237 wqe->lpsn = wqe->psn;
238 if (len > pmtu) {
239 wqe->lpsn += (len - 1) / pmtu;
240 qp->s_state = OP(SEND_FIRST);
241 len = pmtu;
242 break;
243 }
244 if (wqe->wr.opcode == IB_WR_SEND)
245 qp->s_state = OP(SEND_ONLY);
246 else {
247 qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE);
248 /* Immediate data comes after the BTH */
249 ohdr->u.imm_data = wqe->wr.imm_data;
250 hwords += 1;
251 }
252 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
253 bth0 |= 1 << 23;
254 bth2 = 1 << 31; /* Request ACK. */
255 if (++qp->s_cur == qp->s_size)
256 qp->s_cur = 0;
257 break;
258
259 case IB_WR_RDMA_WRITE:
260 if (newreq)
261 qp->s_lsn++;
262 /* FALLTHROUGH */
263 case IB_WR_RDMA_WRITE_WITH_IMM:
264 /* If no credit, return. */
265 if (qp->s_lsn != (u32) -1 &&
266 ipath_cmp24(wqe->ssn, qp->s_lsn + 1) > 0)
267 goto done;
268 ohdr->u.rc.reth.vaddr =
269 cpu_to_be64(wqe->wr.wr.rdma.remote_addr);
270 ohdr->u.rc.reth.rkey =
271 cpu_to_be32(wqe->wr.wr.rdma.rkey);
272 ohdr->u.rc.reth.length = cpu_to_be32(len);
273 hwords += sizeof(struct ib_reth) / 4;
274 wqe->lpsn = wqe->psn;
275 if (len > pmtu) {
276 wqe->lpsn += (len - 1) / pmtu;
277 qp->s_state = OP(RDMA_WRITE_FIRST);
278 len = pmtu;
279 break;
280 }
281 if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
282 qp->s_state = OP(RDMA_WRITE_ONLY);
283 else {
284 qp->s_state =
285 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
286 /* Immediate data comes
287 * after RETH */
288 ohdr->u.rc.imm_data = wqe->wr.imm_data;
289 hwords += 1;
290 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
291 bth0 |= 1 << 23;
292 }
293 bth2 = 1 << 31; /* Request ACK. */
294 if (++qp->s_cur == qp->s_size)
295 qp->s_cur = 0;
296 break;
297
298 case IB_WR_RDMA_READ:
299 ohdr->u.rc.reth.vaddr =
300 cpu_to_be64(wqe->wr.wr.rdma.remote_addr);
301 ohdr->u.rc.reth.rkey =
302 cpu_to_be32(wqe->wr.wr.rdma.rkey);
303 ohdr->u.rc.reth.length = cpu_to_be32(len);
304 qp->s_state = OP(RDMA_READ_REQUEST);
305 hwords += sizeof(ohdr->u.rc.reth) / 4;
306 if (newreq) {
307 qp->s_lsn++;
308 /*
309 * Adjust s_next_psn to count the
310 * expected number of responses.
311 */
312 if (len > pmtu)
313 qp->s_next_psn += (len - 1) / pmtu;
314 wqe->lpsn = qp->s_next_psn++;
315 }
316 ss = NULL;
317 len = 0;
318 if (++qp->s_cur == qp->s_size)
319 qp->s_cur = 0;
320 break;
321
322 case IB_WR_ATOMIC_CMP_AND_SWP:
323 case IB_WR_ATOMIC_FETCH_AND_ADD:
324 if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP)
325 qp->s_state = OP(COMPARE_SWAP);
326 else
327 qp->s_state = OP(FETCH_ADD);
328 ohdr->u.atomic_eth.vaddr = cpu_to_be64(
329 wqe->wr.wr.atomic.remote_addr);
330 ohdr->u.atomic_eth.rkey = cpu_to_be32(
331 wqe->wr.wr.atomic.rkey);
332 ohdr->u.atomic_eth.swap_data = cpu_to_be64(
333 wqe->wr.wr.atomic.swap);
334 ohdr->u.atomic_eth.compare_data = cpu_to_be64(
335 wqe->wr.wr.atomic.compare_add);
336 hwords += sizeof(struct ib_atomic_eth) / 4;
337 if (newreq) {
338 qp->s_lsn++;
339 wqe->lpsn = wqe->psn;
340 }
341 if (++qp->s_cur == qp->s_size)
342 qp->s_cur = 0;
343 ss = NULL;
344 len = 0;
345 break;
346
347 default:
348 goto done;
349 }
350 if (newreq) {
351 qp->s_tail++;
352 if (qp->s_tail >= qp->s_size)
353 qp->s_tail = 0;
354 }
355 bth2 |= qp->s_psn++ & IPS_PSN_MASK;
356 if ((int)(qp->s_psn - qp->s_next_psn) > 0)
357 qp->s_next_psn = qp->s_psn;
358 spin_lock(&dev->pending_lock);
359 if (qp->timerwait.next == LIST_POISON1)
360 list_add_tail(&qp->timerwait,
361 &dev->pending[dev->pending_index]);
362 spin_unlock(&dev->pending_lock);
363 break;
364
365 case OP(RDMA_READ_RESPONSE_FIRST):
366 /*
367 * This case can only happen if a send is restarted. See
368 * ipath_restart_rc().
369 */
370 ipath_init_restart(qp, wqe);
371 /* FALLTHROUGH */
372 case OP(SEND_FIRST):
373 qp->s_state = OP(SEND_MIDDLE);
374 /* FALLTHROUGH */
375 case OP(SEND_MIDDLE):
376 bth2 = qp->s_psn++ & IPS_PSN_MASK;
377 if ((int)(qp->s_psn - qp->s_next_psn) > 0)
378 qp->s_next_psn = qp->s_psn;
379 ss = &qp->s_sge;
380 len = qp->s_len;
381 if (len > pmtu) {
382 /*
383 * Request an ACK every 1/2 MB to avoid retransmit
384 * timeouts.
385 */
386 if (((wqe->length - len) % (512 * 1024)) == 0)
387 bth2 |= 1 << 31;
388 len = pmtu;
389 break;
390 }
391 if (wqe->wr.opcode == IB_WR_SEND)
392 qp->s_state = OP(SEND_LAST);
393 else {
394 qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
395 /* Immediate data comes after the BTH */
396 ohdr->u.imm_data = wqe->wr.imm_data;
397 hwords += 1;
398 }
399 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
400 bth0 |= 1 << 23;
401 bth2 |= 1 << 31; /* Request ACK. */
402 qp->s_cur++;
403 if (qp->s_cur >= qp->s_size)
404 qp->s_cur = 0;
405 break;
406
407 case OP(RDMA_READ_RESPONSE_LAST):
408 /*
409 * This case can only happen if a RDMA write is restarted.
410 * See ipath_restart_rc().
411 */
412 ipath_init_restart(qp, wqe);
413 /* FALLTHROUGH */
414 case OP(RDMA_WRITE_FIRST):
415 qp->s_state = OP(RDMA_WRITE_MIDDLE);
416 /* FALLTHROUGH */
417 case OP(RDMA_WRITE_MIDDLE):
418 bth2 = qp->s_psn++ & IPS_PSN_MASK;
419 if ((int)(qp->s_psn - qp->s_next_psn) > 0)
420 qp->s_next_psn = qp->s_psn;
421 ss = &qp->s_sge;
422 len = qp->s_len;
423 if (len > pmtu) {
424 /*
425 * Request an ACK every 1/2 MB to avoid retransmit
426 * timeouts.
427 */
428 if (((wqe->length - len) % (512 * 1024)) == 0)
429 bth2 |= 1 << 31;
430 len = pmtu;
431 break;
432 }
433 if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
434 qp->s_state = OP(RDMA_WRITE_LAST);
435 else {
436 qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
437 /* Immediate data comes after the BTH */
438 ohdr->u.imm_data = wqe->wr.imm_data;
439 hwords += 1;
440 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
441 bth0 |= 1 << 23;
442 }
443 bth2 |= 1 << 31; /* Request ACK. */
444 qp->s_cur++;
445 if (qp->s_cur >= qp->s_size)
446 qp->s_cur = 0;
447 break;
448
449 case OP(RDMA_READ_RESPONSE_MIDDLE):
450 /*
451 * This case can only happen if a RDMA read is restarted.
452 * See ipath_restart_rc().
453 */
454 ipath_init_restart(qp, wqe);
455 len = ((qp->s_psn - wqe->psn) & IPS_PSN_MASK) * pmtu;
456 ohdr->u.rc.reth.vaddr =
457 cpu_to_be64(wqe->wr.wr.rdma.remote_addr + len);
458 ohdr->u.rc.reth.rkey =
459 cpu_to_be32(wqe->wr.wr.rdma.rkey);
460 ohdr->u.rc.reth.length = cpu_to_be32(qp->s_len);
461 qp->s_state = OP(RDMA_READ_REQUEST);
462 hwords += sizeof(ohdr->u.rc.reth) / 4;
463 bth2 = qp->s_psn++ & IPS_PSN_MASK;
464 if ((int)(qp->s_psn - qp->s_next_psn) > 0)
465 qp->s_next_psn = qp->s_psn;
466 ss = NULL;
467 len = 0;
468 qp->s_cur++;
469 if (qp->s_cur == qp->s_size)
470 qp->s_cur = 0;
471 break;
472
473 case OP(RDMA_READ_REQUEST):
474 case OP(COMPARE_SWAP):
475 case OP(FETCH_ADD):
476 /*
477 * We shouldn't start anything new until this request is
478 * finished. The ACK will handle rescheduling us. XXX The
479 * number of outstanding ones is negotiated at connection
480 * setup time (see pg. 258,289)? XXX Also, if we support
481 * multiple outstanding requests, we need to check the WQE
482 * IB_SEND_FENCE flag and not send a new request if a RDMA
483 * read or atomic is pending.
484 */
485 goto done;
486 }
487 qp->s_len -= len;
488 qp->s_hdrwords = hwords;
489 qp->s_cur_sge = ss;
490 qp->s_cur_size = len;
491 *bth0p = bth0 | (qp->s_state << 24);
492 *bth2p = bth2;
493 return 1;
494
495done:
496 return 0;
497}
498
499static inline void ipath_make_rc_grh(struct ipath_qp *qp,
500 struct ib_global_route *grh,
501 u32 nwords)
502{
503 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
504
505 /* GRH header size in 32-bit words. */
506 qp->s_hdrwords += 10;
507 qp->s_hdr.u.l.grh.version_tclass_flow =
508 cpu_to_be32((6 << 28) |
509 (grh->traffic_class << 20) |
510 grh->flow_label);
511 qp->s_hdr.u.l.grh.paylen =
512 cpu_to_be16(((qp->s_hdrwords - 12) + nwords +
513 SIZE_OF_CRC) << 2);
514 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
515 qp->s_hdr.u.l.grh.next_hdr = 0x1B;
516 qp->s_hdr.u.l.grh.hop_limit = grh->hop_limit;
517 /* The SGID is 32-bit aligned. */
518 qp->s_hdr.u.l.grh.sgid.global.subnet_prefix = dev->gid_prefix;
519 qp->s_hdr.u.l.grh.sgid.global.interface_id =
520 ipath_layer_get_guid(dev->dd);
521 qp->s_hdr.u.l.grh.dgid = grh->dgid;
522}
523
524/**
525 * ipath_do_rc_send - perform a send on an RC QP
526 * @data: contains a pointer to the QP
527 *
528 * Process entries in the send work queue until credit or queue is
529 * exhausted. Only allow one CPU to send a packet per QP (tasklet).
530 * Otherwise, after we drop the QP s_lock, two threads could send
531 * packets out of order.
532 */
533void ipath_do_rc_send(unsigned long data)
534{
535 struct ipath_qp *qp = (struct ipath_qp *)data;
536 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
537 unsigned long flags;
538 u16 lrh0;
539 u32 nwords;
540 u32 extra_bytes;
541 u32 bth0;
542 u32 bth2;
543 u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
544 struct ipath_other_headers *ohdr;
545
546 if (test_and_set_bit(IPATH_S_BUSY, &qp->s_flags))
547 goto bail;
548
549 if (unlikely(qp->remote_ah_attr.dlid ==
550 ipath_layer_get_lid(dev->dd))) {
551 struct ib_wc wc;
552
553 /*
554 * Pass in an uninitialized ib_wc to be consistent with
555 * other places where ipath_ruc_loopback() is called.
556 */
557 ipath_ruc_loopback(qp, &wc);
558 goto clear;
559 }
560
561 ohdr = &qp->s_hdr.u.oth;
562 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
563 ohdr = &qp->s_hdr.u.l.oth;
564
565again:
566 /* Check for a constructed packet to be sent. */
567 if (qp->s_hdrwords != 0) {
568 /*
569 * If no PIO bufs are available, return. An interrupt will
570 * call ipath_ib_piobufavail() when one is available.
571 */
572 _VERBS_INFO("h %u %p\n", qp->s_hdrwords, &qp->s_hdr);
573 _VERBS_INFO("d %u %p %u %p %u %u %u %u\n", qp->s_cur_size,
574 qp->s_cur_sge->sg_list,
575 qp->s_cur_sge->num_sge,
576 qp->s_cur_sge->sge.vaddr,
577 qp->s_cur_sge->sge.sge_length,
578 qp->s_cur_sge->sge.length,
579 qp->s_cur_sge->sge.m,
580 qp->s_cur_sge->sge.n);
581 if (ipath_verbs_send(dev->dd, qp->s_hdrwords,
582 (u32 *) &qp->s_hdr, qp->s_cur_size,
583 qp->s_cur_sge)) {
584 ipath_no_bufs_available(qp, dev);
585 goto bail;
586 }
587 dev->n_unicast_xmit++;
588 /* Record that we sent the packet and s_hdr is empty. */
589 qp->s_hdrwords = 0;
590 }
591
592 /*
593 * The lock is needed to synchronize between setting
594 * qp->s_ack_state, resend timer, and post_send().
595 */
596 spin_lock_irqsave(&qp->s_lock, flags);
597
598 /* Sending responses has higher priority over sending requests. */
599 if (qp->s_ack_state != OP(ACKNOWLEDGE) &&
600 (bth0 = ipath_make_rc_ack(qp, ohdr, pmtu)) != 0)
601 bth2 = qp->s_ack_psn++ & IPS_PSN_MASK;
602 else if (!ipath_make_rc_req(qp, ohdr, pmtu, &bth0, &bth2))
603 goto done;
604
605 spin_unlock_irqrestore(&qp->s_lock, flags);
606
607 /* Construct the header. */
608 extra_bytes = (4 - qp->s_cur_size) & 3;
609 nwords = (qp->s_cur_size + extra_bytes) >> 2;
610 lrh0 = IPS_LRH_BTH;
611 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
612 ipath_make_rc_grh(qp, &qp->remote_ah_attr.grh, nwords);
613 lrh0 = IPS_LRH_GRH;
614 }
615 lrh0 |= qp->remote_ah_attr.sl << 4;
616 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);
617 qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
618 qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords +
619 SIZE_OF_CRC);
620 qp->s_hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd));
621 bth0 |= ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
622 bth0 |= extra_bytes << 20;
623 ohdr->bth[0] = cpu_to_be32(bth0);
624 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
625 ohdr->bth[2] = cpu_to_be32(bth2);
626
627 /* Check for more work to do. */
628 goto again;
629
630done:
631 spin_unlock_irqrestore(&qp->s_lock, flags);
632clear:
633 clear_bit(IPATH_S_BUSY, &qp->s_flags);
634bail:
635 return;
636}
637
638static void send_rc_ack(struct ipath_qp *qp)
639{
640 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
641 u16 lrh0;
642 u32 bth0;
643 struct ipath_other_headers *ohdr;
644
645 /* Construct the header. */
646 ohdr = &qp->s_hdr.u.oth;
647 lrh0 = IPS_LRH_BTH;
648 /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */
649 qp->s_hdrwords = 6;
650 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
651 ipath_make_rc_grh(qp, &qp->remote_ah_attr.grh, 0);
652 ohdr = &qp->s_hdr.u.l.oth;
653 lrh0 = IPS_LRH_GRH;
654 }
655 bth0 = ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
656 ohdr->u.aeth = ipath_compute_aeth(qp);
657 if (qp->s_ack_state >= OP(COMPARE_SWAP)) {
658 bth0 |= IB_OPCODE_ATOMIC_ACKNOWLEDGE << 24;
659 ohdr->u.at.atomic_ack_eth = cpu_to_be64(qp->s_ack_atomic);
660 qp->s_hdrwords += sizeof(ohdr->u.at.atomic_ack_eth) / 4;
661 }
662 else
663 bth0 |= OP(ACKNOWLEDGE) << 24;
664 lrh0 |= qp->remote_ah_attr.sl << 4;
665 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);
666 qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
667 qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + SIZE_OF_CRC);
668 qp->s_hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd));
669 ohdr->bth[0] = cpu_to_be32(bth0);
670 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
671 ohdr->bth[2] = cpu_to_be32(qp->s_ack_psn & IPS_PSN_MASK);
672
673 /*
674 * If we can send the ACK, clear the ACK state.
675 */
676 if (ipath_verbs_send(dev->dd, qp->s_hdrwords, (u32 *) &qp->s_hdr,
677 0, NULL) == 0) {
678 qp->s_ack_state = OP(ACKNOWLEDGE);
679 dev->n_rc_qacks++;
680 dev->n_unicast_xmit++;
681 }
682}
683
684/**
685 * ipath_restart_rc - back up requester to resend the last un-ACKed request
686 * @qp: the QP to restart
687 * @psn: packet sequence number for the request
688 * @wc: the work completion request
689 *
690 * The QP s_lock should be held.
691 */
692void ipath_restart_rc(struct ipath_qp *qp, u32 psn, struct ib_wc *wc)
693{
694 struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
695 struct ipath_ibdev *dev;
696 u32 n;
697
698 /*
699 * If there are no requests pending, we are done.
700 */
701 if (ipath_cmp24(psn, qp->s_next_psn) >= 0 ||
702 qp->s_last == qp->s_tail)
703 goto done;
704
705 if (qp->s_retry == 0) {
706 wc->wr_id = wqe->wr.wr_id;
707 wc->status = IB_WC_RETRY_EXC_ERR;
708 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
709 wc->vendor_err = 0;
710 wc->byte_len = 0;
711 wc->qp_num = qp->ibqp.qp_num;
712 wc->src_qp = qp->remote_qpn;
713 wc->pkey_index = 0;
714 wc->slid = qp->remote_ah_attr.dlid;
715 wc->sl = qp->remote_ah_attr.sl;
716 wc->dlid_path_bits = 0;
717 wc->port_num = 0;
718 ipath_sqerror_qp(qp, wc);
719 goto bail;
720 }
721 qp->s_retry--;
722
723 /*
724 * Remove the QP from the timeout queue.
725 * Note: it may already have been removed by ipath_ib_timer().
726 */
727 dev = to_idev(qp->ibqp.device);
728 spin_lock(&dev->pending_lock);
729 if (qp->timerwait.next != LIST_POISON1)
730 list_del(&qp->timerwait);
731 spin_unlock(&dev->pending_lock);
732
733 if (wqe->wr.opcode == IB_WR_RDMA_READ)
734 dev->n_rc_resends++;
735 else
736 dev->n_rc_resends += (int)qp->s_psn - (int)psn;
737
738 /*
739 * If we are starting the request from the beginning, let the normal
740 * send code handle initialization.
741 */
742 qp->s_cur = qp->s_last;
743 if (ipath_cmp24(psn, wqe->psn) <= 0) {
744 qp->s_state = OP(SEND_LAST);
745 qp->s_psn = wqe->psn;
746 } else {
747 n = qp->s_cur;
748 for (;;) {
749 if (++n == qp->s_size)
750 n = 0;
751 if (n == qp->s_tail) {
752 if (ipath_cmp24(psn, qp->s_next_psn) >= 0) {
753 qp->s_cur = n;
754 wqe = get_swqe_ptr(qp, n);
755 }
756 break;
757 }
758 wqe = get_swqe_ptr(qp, n);
759 if (ipath_cmp24(psn, wqe->psn) < 0)
760 break;
761 qp->s_cur = n;
762 }
763 qp->s_psn = psn;
764
765 /*
766 * Reset the state to restart in the middle of a request.
767 * Don't change the s_sge, s_cur_sge, or s_cur_size.
768 * See ipath_do_rc_send().
769 */
770 switch (wqe->wr.opcode) {
771 case IB_WR_SEND:
772 case IB_WR_SEND_WITH_IMM:
773 qp->s_state = OP(RDMA_READ_RESPONSE_FIRST);
774 break;
775
776 case IB_WR_RDMA_WRITE:
777 case IB_WR_RDMA_WRITE_WITH_IMM:
778 qp->s_state = OP(RDMA_READ_RESPONSE_LAST);
779 break;
780
781 case IB_WR_RDMA_READ:
782 qp->s_state =
783 OP(RDMA_READ_RESPONSE_MIDDLE);
784 break;
785
786 default:
787 /*
788 * This case shouldn't happen since its only
789 * one PSN per req.
790 */
791 qp->s_state = OP(SEND_LAST);
792 }
793 }
794
795done:
796 tasklet_hi_schedule(&qp->s_task);
797
798bail:
799 return;
800}
801
802/**
803 * reset_psn - reset the QP state to send starting from PSN
804 * @qp: the QP
805 * @psn: the packet sequence number to restart at
806 *
807 * This is called from ipath_rc_rcv() to process an incoming RC ACK
808 * for the given QP.
809 * Called at interrupt level with the QP s_lock held.
810 */
811static void reset_psn(struct ipath_qp *qp, u32 psn)
812{
813 struct ipath_swqe *wqe;
814 u32 n;
815
816 n = qp->s_cur;
817 wqe = get_swqe_ptr(qp, n);
818 for (;;) {
819 if (++n == qp->s_size)
820 n = 0;
821 if (n == qp->s_tail) {
822 if (ipath_cmp24(psn, qp->s_next_psn) >= 0) {
823 qp->s_cur = n;
824 wqe = get_swqe_ptr(qp, n);
825 }
826 break;
827 }
828 wqe = get_swqe_ptr(qp, n);
829 if (ipath_cmp24(psn, wqe->psn) < 0)
830 break;
831 qp->s_cur = n;
832 }
833 qp->s_psn = psn;
834
835 /*
836 * Set the state to restart in the middle of a
837 * request. Don't change the s_sge, s_cur_sge, or
838 * s_cur_size. See ipath_do_rc_send().
839 */
840 switch (wqe->wr.opcode) {
841 case IB_WR_SEND:
842 case IB_WR_SEND_WITH_IMM:
843 qp->s_state = OP(RDMA_READ_RESPONSE_FIRST);
844 break;
845
846 case IB_WR_RDMA_WRITE:
847 case IB_WR_RDMA_WRITE_WITH_IMM:
848 qp->s_state = OP(RDMA_READ_RESPONSE_LAST);
849 break;
850
851 case IB_WR_RDMA_READ:
852 qp->s_state = OP(RDMA_READ_RESPONSE_MIDDLE);
853 break;
854
855 default:
856 /*
857 * This case shouldn't happen since its only
858 * one PSN per req.
859 */
860 qp->s_state = OP(SEND_LAST);
861 }
862}
863
864/**
865 * do_rc_ack - process an incoming RC ACK
866 * @qp: the QP the ACK came in on
867 * @psn: the packet sequence number of the ACK
868 * @opcode: the opcode of the request that resulted in the ACK
869 *
870 * This is called from ipath_rc_rcv() to process an incoming RC ACK
871 * for the given QP.
872 * Called at interrupt level with the QP s_lock held.
873 * Returns 1 if OK, 0 if current operation should be aborted (NAK).
874 */
875static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
876{
877 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
878 struct ib_wc wc;
879 struct ipath_swqe *wqe;
880 int ret = 0;
881
882 /*
883 * Remove the QP from the timeout queue (or RNR timeout queue).
884 * If ipath_ib_timer() has already removed it,
885 * it's OK since we hold the QP s_lock and ipath_restart_rc()
886 * just won't find anything to restart if we ACK everything.
887 */
888 spin_lock(&dev->pending_lock);
889 if (qp->timerwait.next != LIST_POISON1)
890 list_del(&qp->timerwait);
891 spin_unlock(&dev->pending_lock);
892
893 /*
894 * Note that NAKs implicitly ACK outstanding SEND and RDMA write
895 * requests and implicitly NAK RDMA read and atomic requests issued
896 * before the NAK'ed request. The MSN won't include the NAK'ed
897 * request but will include an ACK'ed request(s).
898 */
899 wqe = get_swqe_ptr(qp, qp->s_last);
900
901 /* Nothing is pending to ACK/NAK. */
902 if (qp->s_last == qp->s_tail)
903 goto bail;
904
905 /*
906 * The MSN might be for a later WQE than the PSN indicates so
907 * only complete WQEs that the PSN finishes.
908 */
909 while (ipath_cmp24(psn, wqe->lpsn) >= 0) {
910 /* If we are ACKing a WQE, the MSN should be >= the SSN. */
911 if (ipath_cmp24(aeth, wqe->ssn) < 0)
912 break;
913 /*
914 * If this request is a RDMA read or atomic, and the ACK is
915 * for a later operation, this ACK NAKs the RDMA read or
916 * atomic. In other words, only a RDMA_READ_LAST or ONLY
917 * can ACK a RDMA read and likewise for atomic ops. Note
918 * that the NAK case can only happen if relaxed ordering is
919 * used and requests are sent after an RDMA read or atomic
920 * is sent but before the response is received.
921 */
922 if ((wqe->wr.opcode == IB_WR_RDMA_READ &&
923 opcode != OP(RDMA_READ_RESPONSE_LAST)) ||
924 ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
925 wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
926 (opcode != OP(ATOMIC_ACKNOWLEDGE) ||
927 ipath_cmp24(wqe->psn, psn) != 0))) {
928 /*
929 * The last valid PSN seen is the previous
930 * request's.
931 */
932 qp->s_last_psn = wqe->psn - 1;
933 /* Retry this request. */
934 ipath_restart_rc(qp, wqe->psn, &wc);
935 /*
936 * No need to process the ACK/NAK since we are
937 * restarting an earlier request.
938 */
939 goto bail;
940 }
941 /* Post a send completion queue entry if requested. */
942 if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) ||
943 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
944 wc.wr_id = wqe->wr.wr_id;
945 wc.status = IB_WC_SUCCESS;
946 wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
947 wc.vendor_err = 0;
948 wc.byte_len = wqe->length;
949 wc.qp_num = qp->ibqp.qp_num;
950 wc.src_qp = qp->remote_qpn;
951 wc.pkey_index = 0;
952 wc.slid = qp->remote_ah_attr.dlid;
953 wc.sl = qp->remote_ah_attr.sl;
954 wc.dlid_path_bits = 0;
955 wc.port_num = 0;
956 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0);
957 }
958 qp->s_retry = qp->s_retry_cnt;
959 /*
960 * If we are completing a request which is in the process of
961 * being resent, we can stop resending it since we know the
962 * responder has already seen it.
963 */
964 if (qp->s_last == qp->s_cur) {
965 if (++qp->s_cur >= qp->s_size)
966 qp->s_cur = 0;
967 wqe = get_swqe_ptr(qp, qp->s_cur);
968 qp->s_state = OP(SEND_LAST);
969 qp->s_psn = wqe->psn;
970 }
971 if (++qp->s_last >= qp->s_size)
972 qp->s_last = 0;
973 wqe = get_swqe_ptr(qp, qp->s_last);
974 if (qp->s_last == qp->s_tail)
975 break;
976 }
977
978 switch (aeth >> 29) {
979 case 0: /* ACK */
980 dev->n_rc_acks++;
981 /* If this is a partial ACK, reset the retransmit timer. */
982 if (qp->s_last != qp->s_tail) {
983 spin_lock(&dev->pending_lock);
984 list_add_tail(&qp->timerwait,
985 &dev->pending[dev->pending_index]);
986 spin_unlock(&dev->pending_lock);
987 }
988 ipath_get_credit(qp, aeth);
989 qp->s_rnr_retry = qp->s_rnr_retry_cnt;
990 qp->s_retry = qp->s_retry_cnt;
991 qp->s_last_psn = psn;
992 ret = 1;
993 goto bail;
994
995 case 1: /* RNR NAK */
996 dev->n_rnr_naks++;
997 if (qp->s_rnr_retry == 0) {
998 if (qp->s_last == qp->s_tail)
999 goto bail;
1000
1001 wc.status = IB_WC_RNR_RETRY_EXC_ERR;
1002 goto class_b;
1003 }
1004 if (qp->s_rnr_retry_cnt < 7)
1005 qp->s_rnr_retry--;
1006 if (qp->s_last == qp->s_tail)
1007 goto bail;
1008
1009 /* The last valid PSN seen is the previous request's. */
1010 qp->s_last_psn = wqe->psn - 1;
1011
1012 dev->n_rc_resends += (int)qp->s_psn - (int)psn;
1013
1014 /*
1015 * If we are starting the request from the beginning, let
1016 * the normal send code handle initialization.
1017 */
1018 qp->s_cur = qp->s_last;
1019 wqe = get_swqe_ptr(qp, qp->s_cur);
1020 if (ipath_cmp24(psn, wqe->psn) <= 0) {
1021 qp->s_state = OP(SEND_LAST);
1022 qp->s_psn = wqe->psn;
1023 } else
1024 reset_psn(qp, psn);
1025
1026 qp->s_rnr_timeout =
1027 ib_ipath_rnr_table[(aeth >> IPS_AETH_CREDIT_SHIFT) &
1028 IPS_AETH_CREDIT_MASK];
1029 ipath_insert_rnr_queue(qp);
1030 goto bail;
1031
1032 case 3: /* NAK */
1033 /* The last valid PSN seen is the previous request's. */
1034 if (qp->s_last != qp->s_tail)
1035 qp->s_last_psn = wqe->psn - 1;
1036 switch ((aeth >> IPS_AETH_CREDIT_SHIFT) &
1037 IPS_AETH_CREDIT_MASK) {
1038 case 0: /* PSN sequence error */
1039 dev->n_seq_naks++;
1040 /*
1041 * Back up to the responder's expected PSN. XXX
1042 * Note that we might get a NAK in the middle of an
1043 * RDMA READ response which terminates the RDMA
1044 * READ.
1045 */
1046 if (qp->s_last == qp->s_tail)
1047 break;
1048
1049 if (ipath_cmp24(psn, wqe->psn) < 0)
1050 break;
1051
1052 /* Retry the request. */
1053 ipath_restart_rc(qp, psn, &wc);
1054 break;
1055
1056 case 1: /* Invalid Request */
1057 wc.status = IB_WC_REM_INV_REQ_ERR;
1058 dev->n_other_naks++;
1059 goto class_b;
1060
1061 case 2: /* Remote Access Error */
1062 wc.status = IB_WC_REM_ACCESS_ERR;
1063 dev->n_other_naks++;
1064 goto class_b;
1065
1066 case 3: /* Remote Operation Error */
1067 wc.status = IB_WC_REM_OP_ERR;
1068 dev->n_other_naks++;
1069 class_b:
1070 wc.wr_id = wqe->wr.wr_id;
1071 wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
1072 wc.vendor_err = 0;
1073 wc.byte_len = 0;
1074 wc.qp_num = qp->ibqp.qp_num;
1075 wc.src_qp = qp->remote_qpn;
1076 wc.pkey_index = 0;
1077 wc.slid = qp->remote_ah_attr.dlid;
1078 wc.sl = qp->remote_ah_attr.sl;
1079 wc.dlid_path_bits = 0;
1080 wc.port_num = 0;
1081 ipath_sqerror_qp(qp, &wc);
1082 break;
1083
1084 default:
1085 /* Ignore other reserved NAK error codes */
1086 goto reserved;
1087 }
1088 qp->s_rnr_retry = qp->s_rnr_retry_cnt;
1089 goto bail;
1090
1091 default: /* 2: reserved */
1092 reserved:
1093 /* Ignore reserved NAK codes. */
1094 goto bail;
1095 }
1096
1097bail:
1098 return ret;
1099}
1100
1101/**
1102 * ipath_rc_rcv_resp - process an incoming RC response packet
1103 * @dev: the device this packet came in on
1104 * @ohdr: the other headers for this packet
1105 * @data: the packet data
1106 * @tlen: the packet length
1107 * @qp: the QP for this packet
1108 * @opcode: the opcode for this packet
1109 * @psn: the packet sequence number for this packet
1110 * @hdrsize: the header length
1111 * @pmtu: the path MTU
1112 * @header_in_data: true if part of the header data is in the data buffer
1113 *
1114 * This is called from ipath_rc_rcv() to process an incoming RC response
1115 * packet for the given QP.
1116 * Called at interrupt level.
1117 */
1118static inline void ipath_rc_rcv_resp(struct ipath_ibdev *dev,
1119 struct ipath_other_headers *ohdr,
1120 void *data, u32 tlen,
1121 struct ipath_qp *qp,
1122 u32 opcode,
1123 u32 psn, u32 hdrsize, u32 pmtu,
1124 int header_in_data)
1125{
1126 unsigned long flags;
1127 struct ib_wc wc;
1128 int diff;
1129 u32 pad;
1130 u32 aeth;
1131
1132 spin_lock_irqsave(&qp->s_lock, flags);
1133
1134 /* Ignore invalid responses. */
1135 if (ipath_cmp24(psn, qp->s_next_psn) >= 0)
1136 goto ack_done;
1137
1138 /* Ignore duplicate responses. */
1139 diff = ipath_cmp24(psn, qp->s_last_psn);
1140 if (unlikely(diff <= 0)) {
1141 /* Update credits for "ghost" ACKs */
1142 if (diff == 0 && opcode == OP(ACKNOWLEDGE)) {
1143 if (!header_in_data)
1144 aeth = be32_to_cpu(ohdr->u.aeth);
1145 else {
1146 aeth = be32_to_cpu(((__be32 *) data)[0]);
1147 data += sizeof(__be32);
1148 }
1149 if ((aeth >> 29) == 0)
1150 ipath_get_credit(qp, aeth);
1151 }
1152 goto ack_done;
1153 }
1154
1155 switch (opcode) {
1156 case OP(ACKNOWLEDGE):
1157 case OP(ATOMIC_ACKNOWLEDGE):
1158 case OP(RDMA_READ_RESPONSE_FIRST):
1159 if (!header_in_data)
1160 aeth = be32_to_cpu(ohdr->u.aeth);
1161 else {
1162 aeth = be32_to_cpu(((__be32 *) data)[0]);
1163 data += sizeof(__be32);
1164 }
1165 if (opcode == OP(ATOMIC_ACKNOWLEDGE))
1166 *(u64 *) qp->s_sge.sge.vaddr = *(u64 *) data;
1167 if (!do_rc_ack(qp, aeth, psn, opcode) ||
1168 opcode != OP(RDMA_READ_RESPONSE_FIRST))
1169 goto ack_done;
1170 hdrsize += 4;
1171 /*
1172 * do_rc_ack() has already checked the PSN so skip
1173 * the sequence check.
1174 */
1175 goto rdma_read;
1176
1177 case OP(RDMA_READ_RESPONSE_MIDDLE):
1178 /* no AETH, no ACK */
1179 if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) {
1180 dev->n_rdma_seq++;
1181 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
1182 goto ack_done;
1183 }
1184 rdma_read:
1185 if (unlikely(qp->s_state != OP(RDMA_READ_REQUEST)))
1186 goto ack_done;
1187 if (unlikely(tlen != (hdrsize + pmtu + 4)))
1188 goto ack_done;
1189 if (unlikely(pmtu >= qp->s_len))
1190 goto ack_done;
1191 /* We got a response so update the timeout. */
1192 if (unlikely(qp->s_last == qp->s_tail ||
1193 get_swqe_ptr(qp, qp->s_last)->wr.opcode !=
1194 IB_WR_RDMA_READ))
1195 goto ack_done;
1196 spin_lock(&dev->pending_lock);
1197 if (qp->s_rnr_timeout == 0 &&
1198 qp->timerwait.next != LIST_POISON1)
1199 list_move_tail(&qp->timerwait,
1200 &dev->pending[dev->pending_index]);
1201 spin_unlock(&dev->pending_lock);
1202 /*
1203 * Update the RDMA receive state but do the copy w/o holding the
1204 * locks and blocking interrupts. XXX Yet another place that
1205 * affects relaxed RDMA order since we don't want s_sge modified.
1206 */
1207 qp->s_len -= pmtu;
1208 qp->s_last_psn = psn;
1209 spin_unlock_irqrestore(&qp->s_lock, flags);
1210 ipath_copy_sge(&qp->s_sge, data, pmtu);
1211 goto bail;
1212
1213 case OP(RDMA_READ_RESPONSE_LAST):
1214 /* ACKs READ req. */
1215 if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) {
1216 dev->n_rdma_seq++;
1217 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
1218 goto ack_done;
1219 }
1220 /* FALLTHROUGH */
1221 case OP(RDMA_READ_RESPONSE_ONLY):
1222 if (unlikely(qp->s_state != OP(RDMA_READ_REQUEST)))
1223 goto ack_done;
1224 /*
1225 * Get the number of bytes the message was padded by.
1226 */
1227 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
1228 /*
1229 * Check that the data size is >= 1 && <= pmtu.
1230 * Remember to account for the AETH header (4) and
1231 * ICRC (4).
1232 */
1233 if (unlikely(tlen <= (hdrsize + pad + 8))) {
1234 /*
1235 * XXX Need to generate an error CQ
1236 * entry.
1237 */
1238 goto ack_done;
1239 }
1240 tlen -= hdrsize + pad + 8;
1241 if (unlikely(tlen != qp->s_len)) {
1242 /*
1243 * XXX Need to generate an error CQ
1244 * entry.
1245 */
1246 goto ack_done;
1247 }
1248 if (!header_in_data)
1249 aeth = be32_to_cpu(ohdr->u.aeth);
1250 else {
1251 aeth = be32_to_cpu(((__be32 *) data)[0]);
1252 data += sizeof(__be32);
1253 }
1254 ipath_copy_sge(&qp->s_sge, data, tlen);
1255 if (do_rc_ack(qp, aeth, psn, OP(RDMA_READ_RESPONSE_LAST))) {
1256 /*
1257 * Change the state so we contimue
1258 * processing new requests.
1259 */
1260 qp->s_state = OP(SEND_LAST);
1261 }
1262 goto ack_done;
1263 }
1264
1265ack_done:
1266 spin_unlock_irqrestore(&qp->s_lock, flags);
1267bail:
1268 return;
1269}
1270
1271/**
1272 * ipath_rc_rcv_error - process an incoming duplicate or error RC packet
1273 * @dev: the device this packet came in on
1274 * @ohdr: the other headers for this packet
1275 * @data: the packet data
1276 * @qp: the QP for this packet
1277 * @opcode: the opcode for this packet
1278 * @psn: the packet sequence number for this packet
1279 * @diff: the difference between the PSN and the expected PSN
1280 * @header_in_data: true if part of the header data is in the data buffer
1281 *
1282 * This is called from ipath_rc_rcv() to process an unexpected
1283 * incoming RC packet for the given QP.
1284 * Called at interrupt level.
1285 * Return 1 if no more processing is needed; otherwise return 0 to
1286 * schedule a response to be sent and the s_lock unlocked.
1287 */
1288static inline int ipath_rc_rcv_error(struct ipath_ibdev *dev,
1289 struct ipath_other_headers *ohdr,
1290 void *data,
1291 struct ipath_qp *qp,
1292 u32 opcode,
1293 u32 psn,
1294 int diff,
1295 int header_in_data)
1296{
1297 struct ib_reth *reth;
1298
1299 if (diff > 0) {
1300 /*
1301 * Packet sequence error.
1302 * A NAK will ACK earlier sends and RDMA writes.
1303 * Don't queue the NAK if a RDMA read, atomic, or
1304 * NAK is pending though.
1305 */
1306 spin_lock(&qp->s_lock);
1307 if ((qp->s_ack_state >= OP(RDMA_READ_REQUEST) &&
1308 qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE) ||
1309 qp->s_nak_state != 0) {
1310 spin_unlock(&qp->s_lock);
1311 goto done;
1312 }
1313 qp->s_ack_state = OP(SEND_ONLY);
1314 qp->s_nak_state = IB_NAK_PSN_ERROR;
1315 /* Use the expected PSN. */
1316 qp->s_ack_psn = qp->r_psn;
1317 goto resched;
1318 }
1319
1320 /*
1321 * Handle a duplicate request. Don't re-execute SEND, RDMA
1322 * write or atomic op. Don't NAK errors, just silently drop
1323 * the duplicate request. Note that r_sge, r_len, and
1324 * r_rcv_len may be in use so don't modify them.
1325 *
1326 * We are supposed to ACK the earliest duplicate PSN but we
1327 * can coalesce an outstanding duplicate ACK. We have to
1328 * send the earliest so that RDMA reads can be restarted at
1329 * the requester's expected PSN.
1330 */
1331 spin_lock(&qp->s_lock);
1332 if (qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE &&
1333 ipath_cmp24(psn, qp->s_ack_psn) >= 0) {
1334 if (qp->s_ack_state < IB_OPCODE_RDMA_READ_REQUEST)
1335 qp->s_ack_psn = psn;
1336 spin_unlock(&qp->s_lock);
1337 goto done;
1338 }
1339 switch (opcode) {
1340 case OP(RDMA_READ_REQUEST):
1341 /*
1342 * We have to be careful to not change s_rdma_sge
1343 * while ipath_do_rc_send() is using it and not
1344 * holding the s_lock.
1345 */
1346 if (qp->s_ack_state != OP(ACKNOWLEDGE) &&
1347 qp->s_ack_state >= IB_OPCODE_RDMA_READ_REQUEST) {
1348 spin_unlock(&qp->s_lock);
1349 dev->n_rdma_dup_busy++;
1350 goto done;
1351 }
1352 /* RETH comes after BTH */
1353 if (!header_in_data)
1354 reth = &ohdr->u.rc.reth;
1355 else {
1356 reth = (struct ib_reth *)data;
1357 data += sizeof(*reth);
1358 }
1359 qp->s_rdma_len = be32_to_cpu(reth->length);
1360 if (qp->s_rdma_len != 0) {
1361 u32 rkey = be32_to_cpu(reth->rkey);
1362 u64 vaddr = be64_to_cpu(reth->vaddr);
1363 int ok;
1364
1365 /*
1366 * Address range must be a subset of the original
1367 * request and start on pmtu boundaries.
1368 */
1369 ok = ipath_rkey_ok(dev, &qp->s_rdma_sge,
1370 qp->s_rdma_len, vaddr, rkey,
1371 IB_ACCESS_REMOTE_READ);
1372 if (unlikely(!ok))
1373 goto done;
1374 } else {
1375 qp->s_rdma_sge.sg_list = NULL;
1376 qp->s_rdma_sge.num_sge = 0;
1377 qp->s_rdma_sge.sge.mr = NULL;
1378 qp->s_rdma_sge.sge.vaddr = NULL;
1379 qp->s_rdma_sge.sge.length = 0;
1380 qp->s_rdma_sge.sge.sge_length = 0;
1381 }
1382 break;
1383
1384 case OP(COMPARE_SWAP):
1385 case OP(FETCH_ADD):
1386 /*
1387 * Check for the PSN of the last atomic operations
1388 * performed and resend the result if found.
1389 */
1390 if ((psn & IPS_PSN_MASK) != qp->r_atomic_psn) {
1391 spin_unlock(&qp->s_lock);
1392 goto done;
1393 }
1394 qp->s_ack_atomic = qp->r_atomic_data;
1395 break;
1396 }
1397 qp->s_ack_state = opcode;
1398 qp->s_nak_state = 0;
1399 qp->s_ack_psn = psn;
1400resched:
1401 return 0;
1402
1403done:
1404 return 1;
1405}
1406
1407/**
1408 * ipath_rc_rcv - process an incoming RC packet
1409 * @dev: the device this packet came in on
1410 * @hdr: the header of this packet
1411 * @has_grh: true if the header has a GRH
1412 * @data: the packet data
1413 * @tlen: the packet length
1414 * @qp: the QP for this packet
1415 *
1416 * This is called from ipath_qp_rcv() to process an incoming RC packet
1417 * for the given QP.
1418 * Called at interrupt level.
1419 */
1420void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
1421 int has_grh, void *data, u32 tlen, struct ipath_qp *qp)
1422{
1423 struct ipath_other_headers *ohdr;
1424 u32 opcode;
1425 u32 hdrsize;
1426 u32 psn;
1427 u32 pad;
1428 unsigned long flags;
1429 struct ib_wc wc;
1430 u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
1431 int diff;
1432 struct ib_reth *reth;
1433 int header_in_data;
1434
1435 /* Check for GRH */
1436 if (!has_grh) {
1437 ohdr = &hdr->u.oth;
1438 hdrsize = 8 + 12; /* LRH + BTH */
1439 psn = be32_to_cpu(ohdr->bth[2]);
1440 header_in_data = 0;
1441 } else {
1442 ohdr = &hdr->u.l.oth;
1443 hdrsize = 8 + 40 + 12; /* LRH + GRH + BTH */
1444 /*
1445 * The header with GRH is 60 bytes and the core driver sets
1446 * the eager header buffer size to 56 bytes so the last 4
1447 * bytes of the BTH header (PSN) is in the data buffer.
1448 */
1449 header_in_data =
1450 ipath_layer_get_rcvhdrentsize(dev->dd) == 16;
1451 if (header_in_data) {
1452 psn = be32_to_cpu(((__be32 *) data)[0]);
1453 data += sizeof(__be32);
1454 } else
1455 psn = be32_to_cpu(ohdr->bth[2]);
1456 }
1457 /*
1458 * The opcode is in the low byte when its in network order
1459 * (top byte when in host order).
1460 */
1461 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
1462
1463 /*
1464 * Process responses (ACKs) before anything else. Note that the
1465 * packet sequence number will be for something in the send work
1466 * queue rather than the expected receive packet sequence number.
1467 * In other words, this QP is the requester.
1468 */
1469 if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) &&
1470 opcode <= OP(ATOMIC_ACKNOWLEDGE)) {
1471 ipath_rc_rcv_resp(dev, ohdr, data, tlen, qp, opcode, psn,
1472 hdrsize, pmtu, header_in_data);
1473 goto bail;
1474 }
1475
1476 spin_lock_irqsave(&qp->r_rq.lock, flags);
1477
1478 /* Compute 24 bits worth of difference. */
1479 diff = ipath_cmp24(psn, qp->r_psn);
1480 if (unlikely(diff)) {
1481 if (ipath_rc_rcv_error(dev, ohdr, data, qp, opcode,
1482 psn, diff, header_in_data))
1483 goto done;
1484 goto resched;
1485 }
1486
1487 /* Check for opcode sequence errors. */
1488 switch (qp->r_state) {
1489 case OP(SEND_FIRST):
1490 case OP(SEND_MIDDLE):
1491 if (opcode == OP(SEND_MIDDLE) ||
1492 opcode == OP(SEND_LAST) ||
1493 opcode == OP(SEND_LAST_WITH_IMMEDIATE))
1494 break;
1495 nack_inv:
1496 /*
1497 * A NAK will ACK earlier sends and RDMA writes. Don't queue the
1498 * NAK if a RDMA read, atomic, or NAK is pending though.
1499 */
1500 spin_lock(&qp->s_lock);
1501 if (qp->s_ack_state >= OP(RDMA_READ_REQUEST) &&
1502 qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE) {
1503 spin_unlock(&qp->s_lock);
1504 goto done;
1505 }
1506 /* XXX Flush WQEs */
1507 qp->state = IB_QPS_ERR;
1508 qp->s_ack_state = OP(SEND_ONLY);
1509 qp->s_nak_state = IB_NAK_INVALID_REQUEST;
1510 qp->s_ack_psn = qp->r_psn;
1511 goto resched;
1512
1513 case OP(RDMA_WRITE_FIRST):
1514 case OP(RDMA_WRITE_MIDDLE):
1515 if (opcode == OP(RDMA_WRITE_MIDDLE) ||
1516 opcode == OP(RDMA_WRITE_LAST) ||
1517 opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
1518 break;
1519 goto nack_inv;
1520
1521 case OP(RDMA_READ_REQUEST):
1522 case OP(COMPARE_SWAP):
1523 case OP(FETCH_ADD):
1524 /*
1525 * Drop all new requests until a response has been sent. A
1526 * new request then ACKs the RDMA response we sent. Relaxed
1527 * ordering would allow new requests to be processed but we
1528 * would need to keep a queue of rwqe's for all that are in
1529 * progress. Note that we can't RNR NAK this request since
1530 * the RDMA READ or atomic response is already queued to be
1531 * sent (unless we implement a response send queue).
1532 */
1533 goto done;
1534
1535 default:
1536 if (opcode == OP(SEND_MIDDLE) ||
1537 opcode == OP(SEND_LAST) ||
1538 opcode == OP(SEND_LAST_WITH_IMMEDIATE) ||
1539 opcode == OP(RDMA_WRITE_MIDDLE) ||
1540 opcode == OP(RDMA_WRITE_LAST) ||
1541 opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
1542 goto nack_inv;
1543 break;
1544 }
1545
1546 wc.imm_data = 0;
1547 wc.wc_flags = 0;
1548
1549 /* OK, process the packet. */
1550 switch (opcode) {
1551 case OP(SEND_FIRST):
1552 if (!ipath_get_rwqe(qp, 0)) {
1553 rnr_nak:
1554 /*
1555 * A RNR NAK will ACK earlier sends and RDMA writes.
1556 * Don't queue the NAK if a RDMA read or atomic
1557 * is pending though.
1558 */
1559 spin_lock(&qp->s_lock);
1560 if (qp->s_ack_state >=
1561 OP(RDMA_READ_REQUEST) &&
1562 qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE) {
1563 spin_unlock(&qp->s_lock);
1564 goto done;
1565 }
1566 qp->s_ack_state = OP(SEND_ONLY);
1567 qp->s_nak_state = IB_RNR_NAK | qp->s_min_rnr_timer;
1568 qp->s_ack_psn = qp->r_psn;
1569 goto resched;
1570 }
1571 qp->r_rcv_len = 0;
1572 /* FALLTHROUGH */
1573 case OP(SEND_MIDDLE):
1574 case OP(RDMA_WRITE_MIDDLE):
1575 send_middle:
1576 /* Check for invalid length PMTU or posted rwqe len. */
1577 if (unlikely(tlen != (hdrsize + pmtu + 4)))
1578 goto nack_inv;
1579 qp->r_rcv_len += pmtu;
1580 if (unlikely(qp->r_rcv_len > qp->r_len))
1581 goto nack_inv;
1582 ipath_copy_sge(&qp->r_sge, data, pmtu);
1583 break;
1584
1585 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
1586 /* consume RWQE */
1587 if (!ipath_get_rwqe(qp, 1))
1588 goto rnr_nak;
1589 goto send_last_imm;
1590
1591 case OP(SEND_ONLY):
1592 case OP(SEND_ONLY_WITH_IMMEDIATE):
1593 if (!ipath_get_rwqe(qp, 0))
1594 goto rnr_nak;
1595 qp->r_rcv_len = 0;
1596 if (opcode == OP(SEND_ONLY))
1597 goto send_last;
1598 /* FALLTHROUGH */
1599 case OP(SEND_LAST_WITH_IMMEDIATE):
1600 send_last_imm:
1601 if (header_in_data) {
1602 wc.imm_data = *(__be32 *) data;
1603 data += sizeof(__be32);
1604 } else {
1605 /* Immediate data comes after BTH */
1606 wc.imm_data = ohdr->u.imm_data;
1607 }
1608 hdrsize += 4;
1609 wc.wc_flags = IB_WC_WITH_IMM;
1610 /* FALLTHROUGH */
1611 case OP(SEND_LAST):
1612 case OP(RDMA_WRITE_LAST):
1613 send_last:
1614 /* Get the number of bytes the message was padded by. */
1615 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
1616 /* Check for invalid length. */
1617 /* XXX LAST len should be >= 1 */
1618 if (unlikely(tlen < (hdrsize + pad + 4)))
1619 goto nack_inv;
1620 /* Don't count the CRC. */
1621 tlen -= (hdrsize + pad + 4);
1622 wc.byte_len = tlen + qp->r_rcv_len;
1623 if (unlikely(wc.byte_len > qp->r_len))
1624 goto nack_inv;
1625 ipath_copy_sge(&qp->r_sge, data, tlen);
1626 atomic_inc(&qp->msn);
1627 if (opcode == OP(RDMA_WRITE_LAST) ||
1628 opcode == OP(RDMA_WRITE_ONLY))
1629 break;
1630 wc.wr_id = qp->r_wr_id;
1631 wc.status = IB_WC_SUCCESS;
1632 wc.opcode = IB_WC_RECV;
1633 wc.vendor_err = 0;
1634 wc.qp_num = qp->ibqp.qp_num;
1635 wc.src_qp = qp->remote_qpn;
1636 wc.pkey_index = 0;
1637 wc.slid = qp->remote_ah_attr.dlid;
1638 wc.sl = qp->remote_ah_attr.sl;
1639 wc.dlid_path_bits = 0;
1640 wc.port_num = 0;
1641 /* Signal completion event if the solicited bit is set. */
1642 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
1643 (ohdr->bth[0] &
1644 __constant_cpu_to_be32(1 << 23)) != 0);
1645 break;
1646
1647 case OP(RDMA_WRITE_FIRST):
1648 case OP(RDMA_WRITE_ONLY):
1649 case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
1650 /* consume RWQE */
1651 /* RETH comes after BTH */
1652 if (!header_in_data)
1653 reth = &ohdr->u.rc.reth;
1654 else {
1655 reth = (struct ib_reth *)data;
1656 data += sizeof(*reth);
1657 }
1658 hdrsize += sizeof(*reth);
1659 qp->r_len = be32_to_cpu(reth->length);
1660 qp->r_rcv_len = 0;
1661 if (qp->r_len != 0) {
1662 u32 rkey = be32_to_cpu(reth->rkey);
1663 u64 vaddr = be64_to_cpu(reth->vaddr);
1664 int ok;
1665
1666 /* Check rkey & NAK */
1667 ok = ipath_rkey_ok(dev, &qp->r_sge,
1668 qp->r_len, vaddr, rkey,
1669 IB_ACCESS_REMOTE_WRITE);
1670 if (unlikely(!ok)) {
1671 nack_acc:
1672 /*
1673 * A NAK will ACK earlier sends and RDMA
1674 * writes. Don't queue the NAK if a RDMA
1675 * read, atomic, or NAK is pending though.
1676 */
1677 spin_lock(&qp->s_lock);
1678 if (qp->s_ack_state >=
1679 OP(RDMA_READ_REQUEST) &&
1680 qp->s_ack_state !=
1681 IB_OPCODE_ACKNOWLEDGE) {
1682 spin_unlock(&qp->s_lock);
1683 goto done;
1684 }
1685 /* XXX Flush WQEs */
1686 qp->state = IB_QPS_ERR;
1687 qp->s_ack_state = OP(RDMA_WRITE_ONLY);
1688 qp->s_nak_state =
1689 IB_NAK_REMOTE_ACCESS_ERROR;
1690 qp->s_ack_psn = qp->r_psn;
1691 goto resched;
1692 }
1693 } else {
1694 qp->r_sge.sg_list = NULL;
1695 qp->r_sge.sge.mr = NULL;
1696 qp->r_sge.sge.vaddr = NULL;
1697 qp->r_sge.sge.length = 0;
1698 qp->r_sge.sge.sge_length = 0;
1699 }
1700 if (unlikely(!(qp->qp_access_flags &
1701 IB_ACCESS_REMOTE_WRITE)))
1702 goto nack_acc;
1703 if (opcode == OP(RDMA_WRITE_FIRST))
1704 goto send_middle;
1705 else if (opcode == OP(RDMA_WRITE_ONLY))
1706 goto send_last;
1707 if (!ipath_get_rwqe(qp, 1))
1708 goto rnr_nak;
1709 goto send_last_imm;
1710
1711 case OP(RDMA_READ_REQUEST):
1712 /* RETH comes after BTH */
1713 if (!header_in_data)
1714 reth = &ohdr->u.rc.reth;
1715 else {
1716 reth = (struct ib_reth *)data;
1717 data += sizeof(*reth);
1718 }
1719 spin_lock(&qp->s_lock);
1720 if (qp->s_ack_state != OP(ACKNOWLEDGE) &&
1721 qp->s_ack_state >= IB_OPCODE_RDMA_READ_REQUEST) {
1722 spin_unlock(&qp->s_lock);
1723 goto done;
1724 }
1725 qp->s_rdma_len = be32_to_cpu(reth->length);
1726 if (qp->s_rdma_len != 0) {
1727 u32 rkey = be32_to_cpu(reth->rkey);
1728 u64 vaddr = be64_to_cpu(reth->vaddr);
1729 int ok;
1730
1731 /* Check rkey & NAK */
1732 ok = ipath_rkey_ok(dev, &qp->s_rdma_sge,
1733 qp->s_rdma_len, vaddr, rkey,
1734 IB_ACCESS_REMOTE_READ);
1735 if (unlikely(!ok)) {
1736 spin_unlock(&qp->s_lock);
1737 goto nack_acc;
1738 }
1739 /*
1740 * Update the next expected PSN. We add 1 later
1741 * below, so only add the remainder here.
1742 */
1743 if (qp->s_rdma_len > pmtu)
1744 qp->r_psn += (qp->s_rdma_len - 1) / pmtu;
1745 } else {
1746 qp->s_rdma_sge.sg_list = NULL;
1747 qp->s_rdma_sge.num_sge = 0;
1748 qp->s_rdma_sge.sge.mr = NULL;
1749 qp->s_rdma_sge.sge.vaddr = NULL;
1750 qp->s_rdma_sge.sge.length = 0;
1751 qp->s_rdma_sge.sge.sge_length = 0;
1752 }
1753 if (unlikely(!(qp->qp_access_flags &
1754 IB_ACCESS_REMOTE_READ)))
1755 goto nack_acc;
1756 /*
1757 * We need to increment the MSN here instead of when we
1758 * finish sending the result since a duplicate request would
1759 * increment it more than once.
1760 */
1761 atomic_inc(&qp->msn);
1762 qp->s_ack_state = opcode;
1763 qp->s_nak_state = 0;
1764 qp->s_ack_psn = psn;
1765 qp->r_psn++;
1766 qp->r_state = opcode;
1767 goto rdmadone;
1768
1769 case OP(COMPARE_SWAP):
1770 case OP(FETCH_ADD): {
1771 struct ib_atomic_eth *ateth;
1772 u64 vaddr;
1773 u64 sdata;
1774 u32 rkey;
1775
1776 if (!header_in_data)
1777 ateth = &ohdr->u.atomic_eth;
1778 else {
1779 ateth = (struct ib_atomic_eth *)data;
1780 data += sizeof(*ateth);
1781 }
1782 vaddr = be64_to_cpu(ateth->vaddr);
1783 if (unlikely(vaddr & (sizeof(u64) - 1)))
1784 goto nack_inv;
1785 rkey = be32_to_cpu(ateth->rkey);
1786 /* Check rkey & NAK */
1787 if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge,
1788 sizeof(u64), vaddr, rkey,
1789 IB_ACCESS_REMOTE_ATOMIC)))
1790 goto nack_acc;
1791 if (unlikely(!(qp->qp_access_flags &
1792 IB_ACCESS_REMOTE_ATOMIC)))
1793 goto nack_acc;
1794 /* Perform atomic OP and save result. */
1795 sdata = be64_to_cpu(ateth->swap_data);
1796 spin_lock(&dev->pending_lock);
1797 qp->r_atomic_data = *(u64 *) qp->r_sge.sge.vaddr;
1798 if (opcode == OP(FETCH_ADD))
1799 *(u64 *) qp->r_sge.sge.vaddr =
1800 qp->r_atomic_data + sdata;
1801 else if (qp->r_atomic_data ==
1802 be64_to_cpu(ateth->compare_data))
1803 *(u64 *) qp->r_sge.sge.vaddr = sdata;
1804 spin_unlock(&dev->pending_lock);
1805 atomic_inc(&qp->msn);
1806 qp->r_atomic_psn = psn & IPS_PSN_MASK;
1807 psn |= 1 << 31;
1808 break;
1809 }
1810
1811 default:
1812 /* Drop packet for unknown opcodes. */
1813 goto done;
1814 }
1815 qp->r_psn++;
1816 qp->r_state = opcode;
1817 /* Send an ACK if requested or required. */
1818 if (psn & (1 << 31)) {
1819 /*
1820 * Coalesce ACKs unless there is a RDMA READ or
1821 * ATOMIC pending.
1822 */
1823 spin_lock(&qp->s_lock);
1824 if (qp->s_ack_state == OP(ACKNOWLEDGE) ||
1825 qp->s_ack_state < IB_OPCODE_RDMA_READ_REQUEST) {
1826 qp->s_ack_state = opcode;
1827 qp->s_nak_state = 0;
1828 qp->s_ack_psn = psn;
1829 qp->s_ack_atomic = qp->r_atomic_data;
1830 goto resched;
1831 }
1832 spin_unlock(&qp->s_lock);
1833 }
1834done:
1835 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
1836 goto bail;
1837
1838resched:
1839 /*
1840 * Try to send ACK right away but not if ipath_do_rc_send() is
1841 * active.
1842 */
1843 if (qp->s_hdrwords == 0 &&
1844 (qp->s_ack_state < IB_OPCODE_RDMA_READ_REQUEST ||
1845 qp->s_ack_state >= IB_OPCODE_COMPARE_SWAP))
1846 send_rc_ack(qp);
1847
1848rdmadone:
1849 spin_unlock(&qp->s_lock);
1850 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
1851
1852 /* Call ipath_do_rc_send() in another thread. */
1853 tasklet_hi_schedule(&qp->s_task);
1854
1855bail:
1856 return;
1857}
diff --git a/drivers/infiniband/hw/ipath/ipath_registers.h b/drivers/infiniband/hw/ipath/ipath_registers.h
new file mode 100644
index 000000000000..1e59750c5f63
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_registers.h
@@ -0,0 +1,446 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _IPATH_REGISTERS_H
34#define _IPATH_REGISTERS_H
35
36/*
37 * This file should only be included by kernel source, and by the diags.
38 * It defines the registers, and their contents, for the InfiniPath HT-400 chip
39 */
40
41/*
42 * These are the InfiniPath register and buffer bit definitions,
43 * that are visible to software, and needed only by the kernel
44 * and diag code. A few, that are visible to protocol and user
45 * code are in ipath_common.h. Some bits are specific
46 * to a given chip implementation, and have been moved to the
47 * chip-specific source file
48 */
49
50/* kr_revision bits */
51#define INFINIPATH_R_CHIPREVMINOR_MASK 0xFF
52#define INFINIPATH_R_CHIPREVMINOR_SHIFT 0
53#define INFINIPATH_R_CHIPREVMAJOR_MASK 0xFF
54#define INFINIPATH_R_CHIPREVMAJOR_SHIFT 8
55#define INFINIPATH_R_ARCH_MASK 0xFF
56#define INFINIPATH_R_ARCH_SHIFT 16
57#define INFINIPATH_R_SOFTWARE_MASK 0xFF
58#define INFINIPATH_R_SOFTWARE_SHIFT 24
59#define INFINIPATH_R_BOARDID_MASK 0xFF
60#define INFINIPATH_R_BOARDID_SHIFT 32
61
62/* kr_control bits */
63#define INFINIPATH_C_FREEZEMODE 0x00000002
64#define INFINIPATH_C_LINKENABLE 0x00000004
65#define INFINIPATH_C_RESET 0x00000001
66
67/* kr_sendctrl bits */
68#define INFINIPATH_S_DISARMPIOBUF_SHIFT 16
69
70#define IPATH_S_ABORT 0
71#define IPATH_S_PIOINTBUFAVAIL 1
72#define IPATH_S_PIOBUFAVAILUPD 2
73#define IPATH_S_PIOENABLE 3
74#define IPATH_S_DISARM 31
75
76#define INFINIPATH_S_ABORT (1U << IPATH_S_ABORT)
77#define INFINIPATH_S_PIOINTBUFAVAIL (1U << IPATH_S_PIOINTBUFAVAIL)
78#define INFINIPATH_S_PIOBUFAVAILUPD (1U << IPATH_S_PIOBUFAVAILUPD)
79#define INFINIPATH_S_PIOENABLE (1U << IPATH_S_PIOENABLE)
80#define INFINIPATH_S_DISARM (1U << IPATH_S_DISARM)
81
82/* kr_rcvctrl bits */
83#define INFINIPATH_R_PORTENABLE_SHIFT 0
84#define INFINIPATH_R_INTRAVAIL_SHIFT 16
85#define INFINIPATH_R_TAILUPD 0x80000000
86
87/* kr_intstatus, kr_intclear, kr_intmask bits */
88#define INFINIPATH_I_RCVURG_SHIFT 0
89#define INFINIPATH_I_RCVAVAIL_SHIFT 12
90#define INFINIPATH_I_ERROR 0x80000000
91#define INFINIPATH_I_SPIOSENT 0x40000000
92#define INFINIPATH_I_SPIOBUFAVAIL 0x20000000
93#define INFINIPATH_I_GPIO 0x10000000
94
95/* kr_errorstatus, kr_errorclear, kr_errormask bits */
96#define INFINIPATH_E_RFORMATERR 0x0000000000000001ULL
97#define INFINIPATH_E_RVCRC 0x0000000000000002ULL
98#define INFINIPATH_E_RICRC 0x0000000000000004ULL
99#define INFINIPATH_E_RMINPKTLEN 0x0000000000000008ULL
100#define INFINIPATH_E_RMAXPKTLEN 0x0000000000000010ULL
101#define INFINIPATH_E_RLONGPKTLEN 0x0000000000000020ULL
102#define INFINIPATH_E_RSHORTPKTLEN 0x0000000000000040ULL
103#define INFINIPATH_E_RUNEXPCHAR 0x0000000000000080ULL
104#define INFINIPATH_E_RUNSUPVL 0x0000000000000100ULL
105#define INFINIPATH_E_REBP 0x0000000000000200ULL
106#define INFINIPATH_E_RIBFLOW 0x0000000000000400ULL
107#define INFINIPATH_E_RBADVERSION 0x0000000000000800ULL
108#define INFINIPATH_E_RRCVEGRFULL 0x0000000000001000ULL
109#define INFINIPATH_E_RRCVHDRFULL 0x0000000000002000ULL
110#define INFINIPATH_E_RBADTID 0x0000000000004000ULL
111#define INFINIPATH_E_RHDRLEN 0x0000000000008000ULL
112#define INFINIPATH_E_RHDR 0x0000000000010000ULL
113#define INFINIPATH_E_RIBLOSTLINK 0x0000000000020000ULL
114#define INFINIPATH_E_SMINPKTLEN 0x0000000020000000ULL
115#define INFINIPATH_E_SMAXPKTLEN 0x0000000040000000ULL
116#define INFINIPATH_E_SUNDERRUN 0x0000000080000000ULL
117#define INFINIPATH_E_SPKTLEN 0x0000000100000000ULL
118#define INFINIPATH_E_SDROPPEDSMPPKT 0x0000000200000000ULL
119#define INFINIPATH_E_SDROPPEDDATAPKT 0x0000000400000000ULL
120#define INFINIPATH_E_SPIOARMLAUNCH 0x0000000800000000ULL
121#define INFINIPATH_E_SUNEXPERRPKTNUM 0x0000001000000000ULL
122#define INFINIPATH_E_SUNSUPVL 0x0000002000000000ULL
123#define INFINIPATH_E_IBSTATUSCHANGED 0x0001000000000000ULL
124#define INFINIPATH_E_INVALIDADDR 0x0002000000000000ULL
125#define INFINIPATH_E_RESET 0x0004000000000000ULL
126#define INFINIPATH_E_HARDWARE 0x0008000000000000ULL
127
128/* kr_hwerrclear, kr_hwerrmask, kr_hwerrstatus, bits */
129/* TXEMEMPARITYERR bit 0: PIObuf, 1: PIOpbc, 2: launchfifo
130 * RXEMEMPARITYERR bit 0: rcvbuf, 1: lookupq, 2: eagerTID, 3: expTID
131 * bit 4: flag buffer, 5: datainfo, 6: header info */
132#define INFINIPATH_HWE_TXEMEMPARITYERR_MASK 0xFULL
133#define INFINIPATH_HWE_TXEMEMPARITYERR_SHIFT 40
134#define INFINIPATH_HWE_RXEMEMPARITYERR_MASK 0x7FULL
135#define INFINIPATH_HWE_RXEMEMPARITYERR_SHIFT 44
136#define INFINIPATH_HWE_RXDSYNCMEMPARITYERR 0x0000000400000000ULL
137#define INFINIPATH_HWE_MEMBISTFAILED 0x0040000000000000ULL
138#define INFINIPATH_HWE_IBCBUSTOSPCPARITYERR 0x4000000000000000ULL
139#define INFINIPATH_HWE_IBCBUSFRSPCPARITYERR 0x8000000000000000ULL
140
141/* kr_hwdiagctrl bits */
142#define INFINIPATH_DC_FORCETXEMEMPARITYERR_MASK 0xFULL
143#define INFINIPATH_DC_FORCETXEMEMPARITYERR_SHIFT 40
144#define INFINIPATH_DC_FORCERXEMEMPARITYERR_MASK 0x7FULL
145#define INFINIPATH_DC_FORCERXEMEMPARITYERR_SHIFT 44
146#define INFINIPATH_DC_FORCERXDSYNCMEMPARITYERR 0x0000000400000000ULL
147#define INFINIPATH_DC_COUNTERDISABLE 0x1000000000000000ULL
148#define INFINIPATH_DC_COUNTERWREN 0x2000000000000000ULL
149#define INFINIPATH_DC_FORCEIBCBUSTOSPCPARITYERR 0x4000000000000000ULL
150#define INFINIPATH_DC_FORCEIBCBUSFRSPCPARITYERR 0x8000000000000000ULL
151
152/* kr_ibcctrl bits */
153#define INFINIPATH_IBCC_FLOWCTRLPERIOD_MASK 0xFFULL
154#define INFINIPATH_IBCC_FLOWCTRLPERIOD_SHIFT 0
155#define INFINIPATH_IBCC_FLOWCTRLWATERMARK_MASK 0xFFULL
156#define INFINIPATH_IBCC_FLOWCTRLWATERMARK_SHIFT 8
157#define INFINIPATH_IBCC_LINKINITCMD_MASK 0x3ULL
158#define INFINIPATH_IBCC_LINKINITCMD_DISABLE 1
159#define INFINIPATH_IBCC_LINKINITCMD_POLL 2 /* cycle through TS1/TS2 till OK */
160#define INFINIPATH_IBCC_LINKINITCMD_SLEEP 3 /* wait for TS1, then go on */
161#define INFINIPATH_IBCC_LINKINITCMD_SHIFT 16
162#define INFINIPATH_IBCC_LINKCMD_MASK 0x3ULL
163#define INFINIPATH_IBCC_LINKCMD_INIT 1 /* move to 0x11 */
164#define INFINIPATH_IBCC_LINKCMD_ARMED 2 /* move to 0x21 */
165#define INFINIPATH_IBCC_LINKCMD_ACTIVE 3 /* move to 0x31 */
166#define INFINIPATH_IBCC_LINKCMD_SHIFT 18
167#define INFINIPATH_IBCC_MAXPKTLEN_MASK 0x7FFULL
168#define INFINIPATH_IBCC_MAXPKTLEN_SHIFT 20
169#define INFINIPATH_IBCC_PHYERRTHRESHOLD_MASK 0xFULL
170#define INFINIPATH_IBCC_PHYERRTHRESHOLD_SHIFT 32
171#define INFINIPATH_IBCC_OVERRUNTHRESHOLD_MASK 0xFULL
172#define INFINIPATH_IBCC_OVERRUNTHRESHOLD_SHIFT 36
173#define INFINIPATH_IBCC_CREDITSCALE_MASK 0x7ULL
174#define INFINIPATH_IBCC_CREDITSCALE_SHIFT 40
175#define INFINIPATH_IBCC_LOOPBACK 0x8000000000000000ULL
176#define INFINIPATH_IBCC_LINKDOWNDEFAULTSTATE 0x4000000000000000ULL
177
178/* kr_ibcstatus bits */
179#define INFINIPATH_IBCS_LINKTRAININGSTATE_MASK 0xF
180#define INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT 0
181#define INFINIPATH_IBCS_LINKSTATE_MASK 0x7
182#define INFINIPATH_IBCS_LINKSTATE_SHIFT 4
183#define INFINIPATH_IBCS_TXREADY 0x40000000
184#define INFINIPATH_IBCS_TXCREDITOK 0x80000000
185/* link training states (shift by INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT) */
186#define INFINIPATH_IBCS_LT_STATE_DISABLED 0x00
187#define INFINIPATH_IBCS_LT_STATE_LINKUP 0x01
188#define INFINIPATH_IBCS_LT_STATE_POLLACTIVE 0x02
189#define INFINIPATH_IBCS_LT_STATE_POLLQUIET 0x03
190#define INFINIPATH_IBCS_LT_STATE_SLEEPDELAY 0x04
191#define INFINIPATH_IBCS_LT_STATE_SLEEPQUIET 0x05
192#define INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE 0x08
193#define INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG 0x09
194#define INFINIPATH_IBCS_LT_STATE_CFGWAITRMT 0x0a
195#define INFINIPATH_IBCS_LT_STATE_CFGIDLE 0x0b
196#define INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN 0x0c
197#define INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT 0x0e
198#define INFINIPATH_IBCS_LT_STATE_RECOVERIDLE 0x0f
199/* link state machine states (shift by INFINIPATH_IBCS_LINKSTATE_SHIFT) */
200#define INFINIPATH_IBCS_L_STATE_DOWN 0x0
201#define INFINIPATH_IBCS_L_STATE_INIT 0x1
202#define INFINIPATH_IBCS_L_STATE_ARM 0x2
203#define INFINIPATH_IBCS_L_STATE_ACTIVE 0x3
204#define INFINIPATH_IBCS_L_STATE_ACT_DEFER 0x4
205
206/* combination link status states that we use with some frequency */
207#define IPATH_IBSTATE_MASK ((INFINIPATH_IBCS_LINKTRAININGSTATE_MASK \
208 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \
209 (INFINIPATH_IBCS_LINKSTATE_MASK \
210 <<INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT))
211#define IPATH_IBSTATE_INIT ((INFINIPATH_IBCS_L_STATE_INIT \
212 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \
213 (INFINIPATH_IBCS_LT_STATE_LINKUP \
214 <<INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT))
215#define IPATH_IBSTATE_ARM ((INFINIPATH_IBCS_L_STATE_ARM \
216 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \
217 (INFINIPATH_IBCS_LT_STATE_LINKUP \
218 <<INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT))
219#define IPATH_IBSTATE_ACTIVE ((INFINIPATH_IBCS_L_STATE_ACTIVE \
220 << INFINIPATH_IBCS_LINKSTATE_SHIFT) | \
221 (INFINIPATH_IBCS_LT_STATE_LINKUP \
222 <<INFINIPATH_IBCS_LINKTRAININGSTATE_SHIFT))
223
224/* kr_extstatus bits */
225#define INFINIPATH_EXTS_SERDESPLLLOCK 0x1
226#define INFINIPATH_EXTS_GPIOIN_MASK 0xFFFFULL
227#define INFINIPATH_EXTS_GPIOIN_SHIFT 48
228
229/* kr_extctrl bits */
230#define INFINIPATH_EXTC_GPIOINVERT_MASK 0xFFFFULL
231#define INFINIPATH_EXTC_GPIOINVERT_SHIFT 32
232#define INFINIPATH_EXTC_GPIOOE_MASK 0xFFFFULL
233#define INFINIPATH_EXTC_GPIOOE_SHIFT 48
234#define INFINIPATH_EXTC_SERDESENABLE 0x80000000ULL
235#define INFINIPATH_EXTC_SERDESCONNECT 0x40000000ULL
236#define INFINIPATH_EXTC_SERDESENTRUNKING 0x20000000ULL
237#define INFINIPATH_EXTC_SERDESDISRXFIFO 0x10000000ULL
238#define INFINIPATH_EXTC_SERDESENPLPBK1 0x08000000ULL
239#define INFINIPATH_EXTC_SERDESENPLPBK2 0x04000000ULL
240#define INFINIPATH_EXTC_SERDESENENCDEC 0x02000000ULL
241#define INFINIPATH_EXTC_LED1SECPORT_ON 0x00000020ULL
242#define INFINIPATH_EXTC_LED2SECPORT_ON 0x00000010ULL
243#define INFINIPATH_EXTC_LED1PRIPORT_ON 0x00000008ULL
244#define INFINIPATH_EXTC_LED2PRIPORT_ON 0x00000004ULL
245#define INFINIPATH_EXTC_LEDGBLOK_ON 0x00000002ULL
246#define INFINIPATH_EXTC_LEDGBLERR_OFF 0x00000001ULL
247
248/* kr_mdio bits */
249#define INFINIPATH_MDIO_CLKDIV_MASK 0x7FULL
250#define INFINIPATH_MDIO_CLKDIV_SHIFT 32
251#define INFINIPATH_MDIO_COMMAND_MASK 0x7ULL
252#define INFINIPATH_MDIO_COMMAND_SHIFT 26
253#define INFINIPATH_MDIO_DEVADDR_MASK 0x1FULL
254#define INFINIPATH_MDIO_DEVADDR_SHIFT 21
255#define INFINIPATH_MDIO_REGADDR_MASK 0x1FULL
256#define INFINIPATH_MDIO_REGADDR_SHIFT 16
257#define INFINIPATH_MDIO_DATA_MASK 0xFFFFULL
258#define INFINIPATH_MDIO_DATA_SHIFT 0
259#define INFINIPATH_MDIO_CMDVALID 0x0000000040000000ULL
260#define INFINIPATH_MDIO_RDDATAVALID 0x0000000080000000ULL
261
262/* kr_partitionkey bits */
263#define INFINIPATH_PKEY_SIZE 16
264#define INFINIPATH_PKEY_MASK 0xFFFF
265#define INFINIPATH_PKEY_DEFAULT_PKEY 0xFFFF
266
267/* kr_serdesconfig0 bits */
268#define INFINIPATH_SERDC0_RESET_MASK 0xfULL /* overal reset bits */
269#define INFINIPATH_SERDC0_RESET_PLL 0x10000000ULL /* pll reset */
270#define INFINIPATH_SERDC0_TXIDLE 0xF000ULL /* tx idle enables (per lane) */
271#define INFINIPATH_SERDC0_RXDETECT_EN 0xF0000ULL /* rx detect enables (per lane) */
272#define INFINIPATH_SERDC0_L1PWR_DN 0xF0ULL /* L1 Power down; use with RXDETECT,
273 Otherwise not used on IB side */
274
275/* kr_xgxsconfig bits */
276#define INFINIPATH_XGXS_RESET 0x7ULL
277#define INFINIPATH_XGXS_MDIOADDR_MASK 0xfULL
278#define INFINIPATH_XGXS_MDIOADDR_SHIFT 4
279
280#define INFINIPATH_RT_ADDR_MASK 0xFFFFFFFFFFULL /* 40 bits valid */
281
282/* TID entries (memory), HT400-only */
283#define INFINIPATH_RT_VALID 0x8000000000000000ULL
284#define INFINIPATH_RT_ADDR_SHIFT 0
285#define INFINIPATH_RT_BUFSIZE_MASK 0x3FFF
286#define INFINIPATH_RT_BUFSIZE_SHIFT 48
287
288/*
289 * IPATH_PIO_MAXIBHDR is the max IB header size allowed for in our
290 * PIO send buffers. This is well beyond anything currently
291 * defined in the InfiniBand spec.
292 */
293#define IPATH_PIO_MAXIBHDR 128
294
295typedef u64 ipath_err_t;
296
297/* mask of defined bits for various registers */
298extern u64 infinipath_i_bitsextant;
299extern ipath_err_t infinipath_e_bitsextant, infinipath_hwe_bitsextant;
300
301/* masks that are different in various chips, or only exist in some chips */
302extern u32 infinipath_i_rcvavail_mask, infinipath_i_rcvurg_mask;
303
304/*
305 * register bits for selecting i2c direction and values, used for I2C serial
306 * flash
307 */
308extern u16 ipath_gpio_sda_num, ipath_gpio_scl_num;
309extern u64 ipath_gpio_sda, ipath_gpio_scl;
310
311/*
312 * These are the infinipath general register numbers (not offsets).
313 * The kernel registers are used directly, those beyond the kernel
314 * registers are calculated from one of the base registers. The use of
315 * an integer type doesn't allow type-checking as thorough as, say,
316 * an enum but allows for better hiding of chip differences.
317 */
318typedef const u16 ipath_kreg, /* infinipath general registers */
319 ipath_creg, /* infinipath counter registers */
320 ipath_sreg; /* kernel-only, infinipath send registers */
321
322/*
323 * These are the chip registers common to all infinipath chips, and
324 * used both by the kernel and the diagnostics or other user code.
325 * They are all implemented such that 64 bit accesses work.
326 * Some implement no more than 32 bits. Because 64 bit reads
327 * require 2 HT cmds on opteron, we access those with 32 bit
328 * reads for efficiency (they are written as 64 bits, since
329 * the extra 32 bits are nearly free on writes, and it slightly reduces
330 * complexity). The rest are all accessed as 64 bits.
331 */
332struct ipath_kregs {
333 /* These are the 32 bit group */
334 ipath_kreg kr_control;
335 ipath_kreg kr_counterregbase;
336 ipath_kreg kr_intmask;
337 ipath_kreg kr_intstatus;
338 ipath_kreg kr_pagealign;
339 ipath_kreg kr_portcnt;
340 ipath_kreg kr_rcvtidbase;
341 ipath_kreg kr_rcvtidcnt;
342 ipath_kreg kr_rcvegrbase;
343 ipath_kreg kr_rcvegrcnt;
344 ipath_kreg kr_scratch;
345 ipath_kreg kr_sendctrl;
346 ipath_kreg kr_sendpiobufbase;
347 ipath_kreg kr_sendpiobufcnt;
348 ipath_kreg kr_sendpiosize;
349 ipath_kreg kr_sendregbase;
350 ipath_kreg kr_userregbase;
351 /* These are the 64 bit group */
352 ipath_kreg kr_debugport;
353 ipath_kreg kr_debugportselect;
354 ipath_kreg kr_errorclear;
355 ipath_kreg kr_errormask;
356 ipath_kreg kr_errorstatus;
357 ipath_kreg kr_extctrl;
358 ipath_kreg kr_extstatus;
359 ipath_kreg kr_gpio_clear;
360 ipath_kreg kr_gpio_mask;
361 ipath_kreg kr_gpio_out;
362 ipath_kreg kr_gpio_status;
363 ipath_kreg kr_hwdiagctrl;
364 ipath_kreg kr_hwerrclear;
365 ipath_kreg kr_hwerrmask;
366 ipath_kreg kr_hwerrstatus;
367 ipath_kreg kr_ibcctrl;
368 ipath_kreg kr_ibcstatus;
369 ipath_kreg kr_intblocked;
370 ipath_kreg kr_intclear;
371 ipath_kreg kr_interruptconfig;
372 ipath_kreg kr_mdio;
373 ipath_kreg kr_partitionkey;
374 ipath_kreg kr_rcvbthqp;
375 ipath_kreg kr_rcvbufbase;
376 ipath_kreg kr_rcvbufsize;
377 ipath_kreg kr_rcvctrl;
378 ipath_kreg kr_rcvhdrcnt;
379 ipath_kreg kr_rcvhdrentsize;
380 ipath_kreg kr_rcvhdrsize;
381 ipath_kreg kr_rcvintmembase;
382 ipath_kreg kr_rcvintmemsize;
383 ipath_kreg kr_revision;
384 ipath_kreg kr_sendbuffererror;
385 ipath_kreg kr_sendpioavailaddr;
386 ipath_kreg kr_serdesconfig0;
387 ipath_kreg kr_serdesconfig1;
388 ipath_kreg kr_serdesstatus;
389 ipath_kreg kr_txintmembase;
390 ipath_kreg kr_txintmemsize;
391 ipath_kreg kr_xgxsconfig;
392 ipath_kreg kr_ibpllcfg;
393 /* use these two (and the following N ports) only with ipath_k*_kreg64_port();
394 * not *kreg64() */
395 ipath_kreg kr_rcvhdraddr;
396 ipath_kreg kr_rcvhdrtailaddr;
397
398 /* remaining registers are not present on all types of infinipath chips */
399 ipath_kreg kr_rcvpktledcnt;
400 ipath_kreg kr_pcierbuftestreg0;
401 ipath_kreg kr_pcierbuftestreg1;
402 ipath_kreg kr_pcieq0serdesconfig0;
403 ipath_kreg kr_pcieq0serdesconfig1;
404 ipath_kreg kr_pcieq0serdesstatus;
405 ipath_kreg kr_pcieq1serdesconfig0;
406 ipath_kreg kr_pcieq1serdesconfig1;
407 ipath_kreg kr_pcieq1serdesstatus;
408};
409
410struct ipath_cregs {
411 ipath_creg cr_badformatcnt;
412 ipath_creg cr_erricrccnt;
413 ipath_creg cr_errlinkcnt;
414 ipath_creg cr_errlpcrccnt;
415 ipath_creg cr_errpkey;
416 ipath_creg cr_errrcvflowctrlcnt;
417 ipath_creg cr_err_rlencnt;
418 ipath_creg cr_errslencnt;
419 ipath_creg cr_errtidfull;
420 ipath_creg cr_errtidvalid;
421 ipath_creg cr_errvcrccnt;
422 ipath_creg cr_ibstatuschange;
423 ipath_creg cr_intcnt;
424 ipath_creg cr_invalidrlencnt;
425 ipath_creg cr_invalidslencnt;
426 ipath_creg cr_lbflowstallcnt;
427 ipath_creg cr_iblinkdowncnt;
428 ipath_creg cr_iblinkerrrecovcnt;
429 ipath_creg cr_ibsymbolerrcnt;
430 ipath_creg cr_pktrcvcnt;
431 ipath_creg cr_pktrcvflowctrlcnt;
432 ipath_creg cr_pktsendcnt;
433 ipath_creg cr_pktsendflowcnt;
434 ipath_creg cr_portovflcnt;
435 ipath_creg cr_rcvebpcnt;
436 ipath_creg cr_rcvovflcnt;
437 ipath_creg cr_rxdroppktcnt;
438 ipath_creg cr_senddropped;
439 ipath_creg cr_sendstallcnt;
440 ipath_creg cr_sendunderruncnt;
441 ipath_creg cr_unsupvlcnt;
442 ipath_creg cr_wordrcvcnt;
443 ipath_creg cr_wordsendcnt;
444};
445
446#endif /* _IPATH_REGISTERS_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
new file mode 100644
index 000000000000..f232e77b78ee
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
@@ -0,0 +1,552 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include "ipath_verbs.h"
34
35/*
36 * Convert the AETH RNR timeout code into the number of milliseconds.
37 */
38const u32 ib_ipath_rnr_table[32] = {
39 656, /* 0 */
40 1, /* 1 */
41 1, /* 2 */
42 1, /* 3 */
43 1, /* 4 */
44 1, /* 5 */
45 1, /* 6 */
46 1, /* 7 */
47 1, /* 8 */
48 1, /* 9 */
49 1, /* A */
50 1, /* B */
51 1, /* C */
52 1, /* D */
53 2, /* E */
54 2, /* F */
55 3, /* 10 */
56 4, /* 11 */
57 6, /* 12 */
58 8, /* 13 */
59 11, /* 14 */
60 16, /* 15 */
61 21, /* 16 */
62 31, /* 17 */
63 41, /* 18 */
64 62, /* 19 */
65 82, /* 1A */
66 123, /* 1B */
67 164, /* 1C */
68 246, /* 1D */
69 328, /* 1E */
70 492 /* 1F */
71};
72
73/**
74 * ipath_insert_rnr_queue - put QP on the RNR timeout list for the device
75 * @qp: the QP
76 *
77 * XXX Use a simple list for now. We might need a priority
78 * queue if we have lots of QPs waiting for RNR timeouts
79 * but that should be rare.
80 */
81void ipath_insert_rnr_queue(struct ipath_qp *qp)
82{
83 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
84 unsigned long flags;
85
86 spin_lock_irqsave(&dev->pending_lock, flags);
87 if (list_empty(&dev->rnrwait))
88 list_add(&qp->timerwait, &dev->rnrwait);
89 else {
90 struct list_head *l = &dev->rnrwait;
91 struct ipath_qp *nqp = list_entry(l->next, struct ipath_qp,
92 timerwait);
93
94 while (qp->s_rnr_timeout >= nqp->s_rnr_timeout) {
95 qp->s_rnr_timeout -= nqp->s_rnr_timeout;
96 l = l->next;
97 if (l->next == &dev->rnrwait)
98 break;
99 nqp = list_entry(l->next, struct ipath_qp,
100 timerwait);
101 }
102 list_add(&qp->timerwait, l);
103 }
104 spin_unlock_irqrestore(&dev->pending_lock, flags);
105}
106
107/**
108 * ipath_get_rwqe - copy the next RWQE into the QP's RWQE
109 * @qp: the QP
110 * @wr_id_only: update wr_id only, not SGEs
111 *
112 * Return 0 if no RWQE is available, otherwise return 1.
113 *
114 * Called at interrupt level with the QP r_rq.lock held.
115 */
116int ipath_get_rwqe(struct ipath_qp *qp, int wr_id_only)
117{
118 struct ipath_rq *rq;
119 struct ipath_srq *srq;
120 struct ipath_rwqe *wqe;
121 int ret;
122
123 if (!qp->ibqp.srq) {
124 rq = &qp->r_rq;
125 if (unlikely(rq->tail == rq->head)) {
126 ret = 0;
127 goto bail;
128 }
129 wqe = get_rwqe_ptr(rq, rq->tail);
130 qp->r_wr_id = wqe->wr_id;
131 if (!wr_id_only) {
132 qp->r_sge.sge = wqe->sg_list[0];
133 qp->r_sge.sg_list = wqe->sg_list + 1;
134 qp->r_sge.num_sge = wqe->num_sge;
135 qp->r_len = wqe->length;
136 }
137 if (++rq->tail >= rq->size)
138 rq->tail = 0;
139 ret = 1;
140 goto bail;
141 }
142
143 srq = to_isrq(qp->ibqp.srq);
144 rq = &srq->rq;
145 spin_lock(&rq->lock);
146 if (unlikely(rq->tail == rq->head)) {
147 spin_unlock(&rq->lock);
148 ret = 0;
149 goto bail;
150 }
151 wqe = get_rwqe_ptr(rq, rq->tail);
152 qp->r_wr_id = wqe->wr_id;
153 if (!wr_id_only) {
154 qp->r_sge.sge = wqe->sg_list[0];
155 qp->r_sge.sg_list = wqe->sg_list + 1;
156 qp->r_sge.num_sge = wqe->num_sge;
157 qp->r_len = wqe->length;
158 }
159 if (++rq->tail >= rq->size)
160 rq->tail = 0;
161 if (srq->ibsrq.event_handler) {
162 struct ib_event ev;
163 u32 n;
164
165 if (rq->head < rq->tail)
166 n = rq->size + rq->head - rq->tail;
167 else
168 n = rq->head - rq->tail;
169 if (n < srq->limit) {
170 srq->limit = 0;
171 spin_unlock(&rq->lock);
172 ev.device = qp->ibqp.device;
173 ev.element.srq = qp->ibqp.srq;
174 ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
175 srq->ibsrq.event_handler(&ev,
176 srq->ibsrq.srq_context);
177 } else
178 spin_unlock(&rq->lock);
179 } else
180 spin_unlock(&rq->lock);
181 ret = 1;
182
183bail:
184 return ret;
185}
186
187/**
188 * ipath_ruc_loopback - handle UC and RC lookback requests
189 * @sqp: the loopback QP
190 * @wc: the work completion entry
191 *
192 * This is called from ipath_do_uc_send() or ipath_do_rc_send() to
193 * forward a WQE addressed to the same HCA.
194 * Note that although we are single threaded due to the tasklet, we still
195 * have to protect against post_send(). We don't have to worry about
196 * receive interrupts since this is a connected protocol and all packets
197 * will pass through here.
198 */
199void ipath_ruc_loopback(struct ipath_qp *sqp, struct ib_wc *wc)
200{
201 struct ipath_ibdev *dev = to_idev(sqp->ibqp.device);
202 struct ipath_qp *qp;
203 struct ipath_swqe *wqe;
204 struct ipath_sge *sge;
205 unsigned long flags;
206 u64 sdata;
207
208 qp = ipath_lookup_qpn(&dev->qp_table, sqp->remote_qpn);
209 if (!qp) {
210 dev->n_pkt_drops++;
211 return;
212 }
213
214again:
215 spin_lock_irqsave(&sqp->s_lock, flags);
216
217 if (!(ib_ipath_state_ops[sqp->state] & IPATH_PROCESS_SEND_OK)) {
218 spin_unlock_irqrestore(&sqp->s_lock, flags);
219 goto done;
220 }
221
222 /* Get the next send request. */
223 if (sqp->s_last == sqp->s_head) {
224 /* Send work queue is empty. */
225 spin_unlock_irqrestore(&sqp->s_lock, flags);
226 goto done;
227 }
228
229 /*
230 * We can rely on the entry not changing without the s_lock
231 * being held until we update s_last.
232 */
233 wqe = get_swqe_ptr(sqp, sqp->s_last);
234 spin_unlock_irqrestore(&sqp->s_lock, flags);
235
236 wc->wc_flags = 0;
237 wc->imm_data = 0;
238
239 sqp->s_sge.sge = wqe->sg_list[0];
240 sqp->s_sge.sg_list = wqe->sg_list + 1;
241 sqp->s_sge.num_sge = wqe->wr.num_sge;
242 sqp->s_len = wqe->length;
243 switch (wqe->wr.opcode) {
244 case IB_WR_SEND_WITH_IMM:
245 wc->wc_flags = IB_WC_WITH_IMM;
246 wc->imm_data = wqe->wr.imm_data;
247 /* FALLTHROUGH */
248 case IB_WR_SEND:
249 spin_lock_irqsave(&qp->r_rq.lock, flags);
250 if (!ipath_get_rwqe(qp, 0)) {
251 rnr_nak:
252 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
253 /* Handle RNR NAK */
254 if (qp->ibqp.qp_type == IB_QPT_UC)
255 goto send_comp;
256 if (sqp->s_rnr_retry == 0) {
257 wc->status = IB_WC_RNR_RETRY_EXC_ERR;
258 goto err;
259 }
260 if (sqp->s_rnr_retry_cnt < 7)
261 sqp->s_rnr_retry--;
262 dev->n_rnr_naks++;
263 sqp->s_rnr_timeout =
264 ib_ipath_rnr_table[sqp->s_min_rnr_timer];
265 ipath_insert_rnr_queue(sqp);
266 goto done;
267 }
268 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
269 break;
270
271 case IB_WR_RDMA_WRITE_WITH_IMM:
272 wc->wc_flags = IB_WC_WITH_IMM;
273 wc->imm_data = wqe->wr.imm_data;
274 spin_lock_irqsave(&qp->r_rq.lock, flags);
275 if (!ipath_get_rwqe(qp, 1))
276 goto rnr_nak;
277 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
278 /* FALLTHROUGH */
279 case IB_WR_RDMA_WRITE:
280 if (wqe->length == 0)
281 break;
282 if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, wqe->length,
283 wqe->wr.wr.rdma.remote_addr,
284 wqe->wr.wr.rdma.rkey,
285 IB_ACCESS_REMOTE_WRITE))) {
286 acc_err:
287 wc->status = IB_WC_REM_ACCESS_ERR;
288 err:
289 wc->wr_id = wqe->wr.wr_id;
290 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
291 wc->vendor_err = 0;
292 wc->byte_len = 0;
293 wc->qp_num = sqp->ibqp.qp_num;
294 wc->src_qp = sqp->remote_qpn;
295 wc->pkey_index = 0;
296 wc->slid = sqp->remote_ah_attr.dlid;
297 wc->sl = sqp->remote_ah_attr.sl;
298 wc->dlid_path_bits = 0;
299 wc->port_num = 0;
300 ipath_sqerror_qp(sqp, wc);
301 goto done;
302 }
303 break;
304
305 case IB_WR_RDMA_READ:
306 if (unlikely(!ipath_rkey_ok(dev, &sqp->s_sge, wqe->length,
307 wqe->wr.wr.rdma.remote_addr,
308 wqe->wr.wr.rdma.rkey,
309 IB_ACCESS_REMOTE_READ)))
310 goto acc_err;
311 if (unlikely(!(qp->qp_access_flags &
312 IB_ACCESS_REMOTE_READ)))
313 goto acc_err;
314 qp->r_sge.sge = wqe->sg_list[0];
315 qp->r_sge.sg_list = wqe->sg_list + 1;
316 qp->r_sge.num_sge = wqe->wr.num_sge;
317 break;
318
319 case IB_WR_ATOMIC_CMP_AND_SWP:
320 case IB_WR_ATOMIC_FETCH_AND_ADD:
321 if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge, sizeof(u64),
322 wqe->wr.wr.rdma.remote_addr,
323 wqe->wr.wr.rdma.rkey,
324 IB_ACCESS_REMOTE_ATOMIC)))
325 goto acc_err;
326 /* Perform atomic OP and save result. */
327 sdata = wqe->wr.wr.atomic.swap;
328 spin_lock_irqsave(&dev->pending_lock, flags);
329 qp->r_atomic_data = *(u64 *) qp->r_sge.sge.vaddr;
330 if (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
331 *(u64 *) qp->r_sge.sge.vaddr =
332 qp->r_atomic_data + sdata;
333 else if (qp->r_atomic_data == wqe->wr.wr.atomic.compare_add)
334 *(u64 *) qp->r_sge.sge.vaddr = sdata;
335 spin_unlock_irqrestore(&dev->pending_lock, flags);
336 *(u64 *) sqp->s_sge.sge.vaddr = qp->r_atomic_data;
337 goto send_comp;
338
339 default:
340 goto done;
341 }
342
343 sge = &sqp->s_sge.sge;
344 while (sqp->s_len) {
345 u32 len = sqp->s_len;
346
347 if (len > sge->length)
348 len = sge->length;
349 BUG_ON(len == 0);
350 ipath_copy_sge(&qp->r_sge, sge->vaddr, len);
351 sge->vaddr += len;
352 sge->length -= len;
353 sge->sge_length -= len;
354 if (sge->sge_length == 0) {
355 if (--sqp->s_sge.num_sge)
356 *sge = *sqp->s_sge.sg_list++;
357 } else if (sge->length == 0 && sge->mr != NULL) {
358 if (++sge->n >= IPATH_SEGSZ) {
359 if (++sge->m >= sge->mr->mapsz)
360 break;
361 sge->n = 0;
362 }
363 sge->vaddr =
364 sge->mr->map[sge->m]->segs[sge->n].vaddr;
365 sge->length =
366 sge->mr->map[sge->m]->segs[sge->n].length;
367 }
368 sqp->s_len -= len;
369 }
370
371 if (wqe->wr.opcode == IB_WR_RDMA_WRITE ||
372 wqe->wr.opcode == IB_WR_RDMA_READ)
373 goto send_comp;
374
375 if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM)
376 wc->opcode = IB_WC_RECV_RDMA_WITH_IMM;
377 else
378 wc->opcode = IB_WC_RECV;
379 wc->wr_id = qp->r_wr_id;
380 wc->status = IB_WC_SUCCESS;
381 wc->vendor_err = 0;
382 wc->byte_len = wqe->length;
383 wc->qp_num = qp->ibqp.qp_num;
384 wc->src_qp = qp->remote_qpn;
385 /* XXX do we know which pkey matched? Only needed for GSI. */
386 wc->pkey_index = 0;
387 wc->slid = qp->remote_ah_attr.dlid;
388 wc->sl = qp->remote_ah_attr.sl;
389 wc->dlid_path_bits = 0;
390 /* Signal completion event if the solicited bit is set. */
391 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), wc,
392 wqe->wr.send_flags & IB_SEND_SOLICITED);
393
394send_comp:
395 sqp->s_rnr_retry = sqp->s_rnr_retry_cnt;
396
397 if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &sqp->s_flags) ||
398 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
399 wc->wr_id = wqe->wr.wr_id;
400 wc->status = IB_WC_SUCCESS;
401 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
402 wc->vendor_err = 0;
403 wc->byte_len = wqe->length;
404 wc->qp_num = sqp->ibqp.qp_num;
405 wc->src_qp = 0;
406 wc->pkey_index = 0;
407 wc->slid = 0;
408 wc->sl = 0;
409 wc->dlid_path_bits = 0;
410 wc->port_num = 0;
411 ipath_cq_enter(to_icq(sqp->ibqp.send_cq), wc, 0);
412 }
413
414 /* Update s_last now that we are finished with the SWQE */
415 spin_lock_irqsave(&sqp->s_lock, flags);
416 if (++sqp->s_last >= sqp->s_size)
417 sqp->s_last = 0;
418 spin_unlock_irqrestore(&sqp->s_lock, flags);
419 goto again;
420
421done:
422 if (atomic_dec_and_test(&qp->refcount))
423 wake_up(&qp->wait);
424}
425
426/**
427 * ipath_no_bufs_available - tell the layer driver we need buffers
428 * @qp: the QP that caused the problem
429 * @dev: the device we ran out of buffers on
430 *
431 * Called when we run out of PIO buffers.
432 */
433void ipath_no_bufs_available(struct ipath_qp *qp, struct ipath_ibdev *dev)
434{
435 unsigned long flags;
436
437 spin_lock_irqsave(&dev->pending_lock, flags);
438 if (qp->piowait.next == LIST_POISON1)
439 list_add_tail(&qp->piowait, &dev->piowait);
440 spin_unlock_irqrestore(&dev->pending_lock, flags);
441 /*
442 * Note that as soon as ipath_layer_want_buffer() is called and
443 * possibly before it returns, ipath_ib_piobufavail()
444 * could be called. If we are still in the tasklet function,
445 * tasklet_hi_schedule() will not call us until the next time
446 * tasklet_hi_schedule() is called.
447 * We clear the tasklet flag now since we are committing to return
448 * from the tasklet function.
449 */
450 clear_bit(IPATH_S_BUSY, &qp->s_flags);
451 tasklet_unlock(&qp->s_task);
452 ipath_layer_want_buffer(dev->dd);
453 dev->n_piowait++;
454}
455
456/**
457 * ipath_post_rc_send - post RC and UC sends
458 * @qp: the QP to post on
459 * @wr: the work request to send
460 */
461int ipath_post_rc_send(struct ipath_qp *qp, struct ib_send_wr *wr)
462{
463 struct ipath_swqe *wqe;
464 unsigned long flags;
465 u32 next;
466 int i, j;
467 int acc;
468 int ret;
469
470 /*
471 * Don't allow RDMA reads or atomic operations on UC or
472 * undefined operations.
473 * Make sure buffer is large enough to hold the result for atomics.
474 */
475 if (qp->ibqp.qp_type == IB_QPT_UC) {
476 if ((unsigned) wr->opcode >= IB_WR_RDMA_READ) {
477 ret = -EINVAL;
478 goto bail;
479 }
480 } else if ((unsigned) wr->opcode > IB_WR_ATOMIC_FETCH_AND_ADD) {
481 ret = -EINVAL;
482 goto bail;
483 } else if (wr->opcode >= IB_WR_ATOMIC_CMP_AND_SWP &&
484 (wr->num_sge == 0 ||
485 wr->sg_list[0].length < sizeof(u64) ||
486 wr->sg_list[0].addr & (sizeof(u64) - 1))) {
487 ret = -EINVAL;
488 goto bail;
489 }
490 /* IB spec says that num_sge == 0 is OK. */
491 if (wr->num_sge > qp->s_max_sge) {
492 ret = -ENOMEM;
493 goto bail;
494 }
495 spin_lock_irqsave(&qp->s_lock, flags);
496 next = qp->s_head + 1;
497 if (next >= qp->s_size)
498 next = 0;
499 if (next == qp->s_last) {
500 spin_unlock_irqrestore(&qp->s_lock, flags);
501 ret = -EINVAL;
502 goto bail;
503 }
504
505 wqe = get_swqe_ptr(qp, qp->s_head);
506 wqe->wr = *wr;
507 wqe->ssn = qp->s_ssn++;
508 wqe->sg_list[0].mr = NULL;
509 wqe->sg_list[0].vaddr = NULL;
510 wqe->sg_list[0].length = 0;
511 wqe->sg_list[0].sge_length = 0;
512 wqe->length = 0;
513 acc = wr->opcode >= IB_WR_RDMA_READ ? IB_ACCESS_LOCAL_WRITE : 0;
514 for (i = 0, j = 0; i < wr->num_sge; i++) {
515 if (to_ipd(qp->ibqp.pd)->user && wr->sg_list[i].lkey == 0) {
516 spin_unlock_irqrestore(&qp->s_lock, flags);
517 ret = -EINVAL;
518 goto bail;
519 }
520 if (wr->sg_list[i].length == 0)
521 continue;
522 if (!ipath_lkey_ok(&to_idev(qp->ibqp.device)->lk_table,
523 &wqe->sg_list[j], &wr->sg_list[i],
524 acc)) {
525 spin_unlock_irqrestore(&qp->s_lock, flags);
526 ret = -EINVAL;
527 goto bail;
528 }
529 wqe->length += wr->sg_list[i].length;
530 j++;
531 }
532 wqe->wr.num_sge = j;
533 qp->s_head = next;
534 /*
535 * Wake up the send tasklet if the QP is not waiting
536 * for an RNR timeout.
537 */
538 next = qp->s_rnr_timeout;
539 spin_unlock_irqrestore(&qp->s_lock, flags);
540
541 if (next == 0) {
542 if (qp->ibqp.qp_type == IB_QPT_UC)
543 ipath_do_uc_send((unsigned long) qp);
544 else
545 ipath_do_rc_send((unsigned long) qp);
546 }
547
548 ret = 0;
549
550bail:
551 return ret;
552}
diff --git a/drivers/infiniband/hw/ipath/ipath_srq.c b/drivers/infiniband/hw/ipath/ipath_srq.c
new file mode 100644
index 000000000000..01c4c6c56118
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_srq.c
@@ -0,0 +1,273 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/err.h>
34#include <linux/vmalloc.h>
35
36#include "ipath_verbs.h"
37
38/**
39 * ipath_post_srq_receive - post a receive on a shared receive queue
40 * @ibsrq: the SRQ to post the receive on
41 * @wr: the list of work requests to post
42 * @bad_wr: the first WR to cause a problem is put here
43 *
44 * This may be called from interrupt context.
45 */
46int ipath_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
47 struct ib_recv_wr **bad_wr)
48{
49 struct ipath_srq *srq = to_isrq(ibsrq);
50 struct ipath_ibdev *dev = to_idev(ibsrq->device);
51 unsigned long flags;
52 int ret;
53
54 for (; wr; wr = wr->next) {
55 struct ipath_rwqe *wqe;
56 u32 next;
57 int i, j;
58
59 if (wr->num_sge > srq->rq.max_sge) {
60 *bad_wr = wr;
61 ret = -ENOMEM;
62 goto bail;
63 }
64
65 spin_lock_irqsave(&srq->rq.lock, flags);
66 next = srq->rq.head + 1;
67 if (next >= srq->rq.size)
68 next = 0;
69 if (next == srq->rq.tail) {
70 spin_unlock_irqrestore(&srq->rq.lock, flags);
71 *bad_wr = wr;
72 ret = -ENOMEM;
73 goto bail;
74 }
75
76 wqe = get_rwqe_ptr(&srq->rq, srq->rq.head);
77 wqe->wr_id = wr->wr_id;
78 wqe->sg_list[0].mr = NULL;
79 wqe->sg_list[0].vaddr = NULL;
80 wqe->sg_list[0].length = 0;
81 wqe->sg_list[0].sge_length = 0;
82 wqe->length = 0;
83 for (i = 0, j = 0; i < wr->num_sge; i++) {
84 /* Check LKEY */
85 if (to_ipd(srq->ibsrq.pd)->user &&
86 wr->sg_list[i].lkey == 0) {
87 spin_unlock_irqrestore(&srq->rq.lock,
88 flags);
89 *bad_wr = wr;
90 ret = -EINVAL;
91 goto bail;
92 }
93 if (wr->sg_list[i].length == 0)
94 continue;
95 if (!ipath_lkey_ok(&dev->lk_table,
96 &wqe->sg_list[j],
97 &wr->sg_list[i],
98 IB_ACCESS_LOCAL_WRITE)) {
99 spin_unlock_irqrestore(&srq->rq.lock,
100 flags);
101 *bad_wr = wr;
102 ret = -EINVAL;
103 goto bail;
104 }
105 wqe->length += wr->sg_list[i].length;
106 j++;
107 }
108 wqe->num_sge = j;
109 srq->rq.head = next;
110 spin_unlock_irqrestore(&srq->rq.lock, flags);
111 }
112 ret = 0;
113
114bail:
115 return ret;
116}
117
118/**
119 * ipath_create_srq - create a shared receive queue
120 * @ibpd: the protection domain of the SRQ to create
121 * @attr: the attributes of the SRQ
122 * @udata: not used by the InfiniPath verbs driver
123 */
124struct ib_srq *ipath_create_srq(struct ib_pd *ibpd,
125 struct ib_srq_init_attr *srq_init_attr,
126 struct ib_udata *udata)
127{
128 struct ipath_srq *srq;
129 u32 sz;
130 struct ib_srq *ret;
131
132 if (srq_init_attr->attr.max_sge < 1) {
133 ret = ERR_PTR(-EINVAL);
134 goto bail;
135 }
136
137 srq = kmalloc(sizeof(*srq), GFP_KERNEL);
138 if (!srq) {
139 ret = ERR_PTR(-ENOMEM);
140 goto bail;
141 }
142
143 /*
144 * Need to use vmalloc() if we want to support large #s of entries.
145 */
146 srq->rq.size = srq_init_attr->attr.max_wr + 1;
147 sz = sizeof(struct ipath_sge) * srq_init_attr->attr.max_sge +
148 sizeof(struct ipath_rwqe);
149 srq->rq.wq = vmalloc(srq->rq.size * sz);
150 if (!srq->rq.wq) {
151 kfree(srq);
152 ret = ERR_PTR(-ENOMEM);
153 goto bail;
154 }
155
156 /*
157 * ib_create_srq() will initialize srq->ibsrq.
158 */
159 spin_lock_init(&srq->rq.lock);
160 srq->rq.head = 0;
161 srq->rq.tail = 0;
162 srq->rq.max_sge = srq_init_attr->attr.max_sge;
163 srq->limit = srq_init_attr->attr.srq_limit;
164
165 ret = &srq->ibsrq;
166
167bail:
168 return ret;
169}
170
171/**
172 * ipath_modify_srq - modify a shared receive queue
173 * @ibsrq: the SRQ to modify
174 * @attr: the new attributes of the SRQ
175 * @attr_mask: indicates which attributes to modify
176 */
177int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
178 enum ib_srq_attr_mask attr_mask)
179{
180 struct ipath_srq *srq = to_isrq(ibsrq);
181 unsigned long flags;
182 int ret;
183
184 if (attr_mask & IB_SRQ_LIMIT) {
185 spin_lock_irqsave(&srq->rq.lock, flags);
186 srq->limit = attr->srq_limit;
187 spin_unlock_irqrestore(&srq->rq.lock, flags);
188 }
189 if (attr_mask & IB_SRQ_MAX_WR) {
190 u32 size = attr->max_wr + 1;
191 struct ipath_rwqe *wq, *p;
192 u32 n;
193 u32 sz;
194
195 if (attr->max_sge < srq->rq.max_sge) {
196 ret = -EINVAL;
197 goto bail;
198 }
199
200 sz = sizeof(struct ipath_rwqe) +
201 attr->max_sge * sizeof(struct ipath_sge);
202 wq = vmalloc(size * sz);
203 if (!wq) {
204 ret = -ENOMEM;
205 goto bail;
206 }
207
208 spin_lock_irqsave(&srq->rq.lock, flags);
209 if (srq->rq.head < srq->rq.tail)
210 n = srq->rq.size + srq->rq.head - srq->rq.tail;
211 else
212 n = srq->rq.head - srq->rq.tail;
213 if (size <= n || size <= srq->limit) {
214 spin_unlock_irqrestore(&srq->rq.lock, flags);
215 vfree(wq);
216 ret = -EINVAL;
217 goto bail;
218 }
219 n = 0;
220 p = wq;
221 while (srq->rq.tail != srq->rq.head) {
222 struct ipath_rwqe *wqe;
223 int i;
224
225 wqe = get_rwqe_ptr(&srq->rq, srq->rq.tail);
226 p->wr_id = wqe->wr_id;
227 p->length = wqe->length;
228 p->num_sge = wqe->num_sge;
229 for (i = 0; i < wqe->num_sge; i++)
230 p->sg_list[i] = wqe->sg_list[i];
231 n++;
232 p = (struct ipath_rwqe *)((char *) p + sz);
233 if (++srq->rq.tail >= srq->rq.size)
234 srq->rq.tail = 0;
235 }
236 vfree(srq->rq.wq);
237 srq->rq.wq = wq;
238 srq->rq.size = size;
239 srq->rq.head = n;
240 srq->rq.tail = 0;
241 srq->rq.max_sge = attr->max_sge;
242 spin_unlock_irqrestore(&srq->rq.lock, flags);
243 }
244
245 ret = 0;
246
247bail:
248 return ret;
249}
250
251int ipath_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr)
252{
253 struct ipath_srq *srq = to_isrq(ibsrq);
254
255 attr->max_wr = srq->rq.size - 1;
256 attr->max_sge = srq->rq.max_sge;
257 attr->srq_limit = srq->limit;
258 return 0;
259}
260
261/**
262 * ipath_destroy_srq - destroy a shared receive queue
263 * @ibsrq: the SRQ to destroy
264 */
265int ipath_destroy_srq(struct ib_srq *ibsrq)
266{
267 struct ipath_srq *srq = to_isrq(ibsrq);
268
269 vfree(srq->rq.wq);
270 kfree(srq);
271
272 return 0;
273}
diff --git a/drivers/infiniband/hw/ipath/ipath_stats.c b/drivers/infiniband/hw/ipath/ipath_stats.c
new file mode 100644
index 000000000000..fe209137ee74
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_stats.c
@@ -0,0 +1,303 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/pci.h>
34
35#include "ipath_kernel.h"
36
37struct infinipath_stats ipath_stats;
38
39/**
40 * ipath_snap_cntr - snapshot a chip counter
41 * @dd: the infinipath device
42 * @creg: the counter to snapshot
43 *
44 * called from add_timer and user counter read calls, to deal with
45 * counters that wrap in "human time". The words sent and received, and
46 * the packets sent and received are all that we worry about. For now,
47 * at least, we don't worry about error counters, because if they wrap
48 * that quickly, we probably don't care. We may eventually just make this
49 * handle all the counters. word counters can wrap in about 20 seconds
50 * of full bandwidth traffic, packet counters in a few hours.
51 */
52
53u64 ipath_snap_cntr(struct ipath_devdata *dd, ipath_creg creg)
54{
55 u32 val, reg64 = 0;
56 u64 val64;
57 unsigned long t0, t1;
58 u64 ret;
59
60 t0 = jiffies;
61 /* If fast increment counters are only 32 bits, snapshot them,
62 * and maintain them as 64bit values in the driver */
63 if (!(dd->ipath_flags & IPATH_32BITCOUNTERS) &&
64 (creg == dd->ipath_cregs->cr_wordsendcnt ||
65 creg == dd->ipath_cregs->cr_wordrcvcnt ||
66 creg == dd->ipath_cregs->cr_pktsendcnt ||
67 creg == dd->ipath_cregs->cr_pktrcvcnt)) {
68 val64 = ipath_read_creg(dd, creg);
69 val = val64 == ~0ULL ? ~0U : 0;
70 reg64 = 1;
71 } else /* val64 just to keep gcc quiet... */
72 val64 = val = ipath_read_creg32(dd, creg);
73 /*
74 * See if a second has passed. This is just a way to detect things
75 * that are quite broken. Normally this should take just a few
76 * cycles (the check is for long enough that we don't care if we get
77 * pre-empted.) An Opteron HT O read timeout is 4 seconds with
78 * normal NB values
79 */
80 t1 = jiffies;
81 if (time_before(t0 + HZ, t1) && val == -1) {
82 ipath_dev_err(dd, "Error! Read counter 0x%x timed out\n",
83 creg);
84 ret = 0ULL;
85 goto bail;
86 }
87 if (reg64) {
88 ret = val64;
89 goto bail;
90 }
91
92 if (creg == dd->ipath_cregs->cr_wordsendcnt) {
93 if (val != dd->ipath_lastsword) {
94 dd->ipath_sword += val - dd->ipath_lastsword;
95 dd->ipath_lastsword = val;
96 }
97 val64 = dd->ipath_sword;
98 } else if (creg == dd->ipath_cregs->cr_wordrcvcnt) {
99 if (val != dd->ipath_lastrword) {
100 dd->ipath_rword += val - dd->ipath_lastrword;
101 dd->ipath_lastrword = val;
102 }
103 val64 = dd->ipath_rword;
104 } else if (creg == dd->ipath_cregs->cr_pktsendcnt) {
105 if (val != dd->ipath_lastspkts) {
106 dd->ipath_spkts += val - dd->ipath_lastspkts;
107 dd->ipath_lastspkts = val;
108 }
109 val64 = dd->ipath_spkts;
110 } else if (creg == dd->ipath_cregs->cr_pktrcvcnt) {
111 if (val != dd->ipath_lastrpkts) {
112 dd->ipath_rpkts += val - dd->ipath_lastrpkts;
113 dd->ipath_lastrpkts = val;
114 }
115 val64 = dd->ipath_rpkts;
116 } else
117 val64 = (u64) val;
118
119 ret = val64;
120
121bail:
122 return ret;
123}
124
125/**
126 * ipath_qcheck - print delta of egrfull/hdrqfull errors for kernel ports
127 * @dd: the infinipath device
128 *
129 * print the delta of egrfull/hdrqfull errors for kernel ports no more than
130 * every 5 seconds. User processes are printed at close, but kernel doesn't
131 * close, so... Separate routine so may call from other places someday, and
132 * so function name when printed by _IPATH_INFO is meaningfull
133 */
134static void ipath_qcheck(struct ipath_devdata *dd)
135{
136 static u64 last_tot_hdrqfull;
137 size_t blen = 0;
138 char buf[128];
139
140 *buf = 0;
141 if (dd->ipath_pd[0]->port_hdrqfull != dd->ipath_p0_hdrqfull) {
142 blen = snprintf(buf, sizeof buf, "port 0 hdrqfull %u",
143 dd->ipath_pd[0]->port_hdrqfull -
144 dd->ipath_p0_hdrqfull);
145 dd->ipath_p0_hdrqfull = dd->ipath_pd[0]->port_hdrqfull;
146 }
147 if (ipath_stats.sps_etidfull != dd->ipath_last_tidfull) {
148 blen += snprintf(buf + blen, sizeof buf - blen,
149 "%srcvegrfull %llu",
150 blen ? ", " : "",
151 (unsigned long long)
152 (ipath_stats.sps_etidfull -
153 dd->ipath_last_tidfull));
154 dd->ipath_last_tidfull = ipath_stats.sps_etidfull;
155 }
156
157 /*
158 * this is actually the number of hdrq full interrupts, not actual
159 * events, but at the moment that's mostly what I'm interested in.
160 * Actual count, etc. is in the counters, if needed. For production
161 * users this won't ordinarily be printed.
162 */
163
164 if ((ipath_debug & (__IPATH_PKTDBG | __IPATH_DBG)) &&
165 ipath_stats.sps_hdrqfull != last_tot_hdrqfull) {
166 blen += snprintf(buf + blen, sizeof buf - blen,
167 "%shdrqfull %llu (all ports)",
168 blen ? ", " : "",
169 (unsigned long long)
170 (ipath_stats.sps_hdrqfull -
171 last_tot_hdrqfull));
172 last_tot_hdrqfull = ipath_stats.sps_hdrqfull;
173 }
174 if (blen)
175 ipath_dbg("%s\n", buf);
176
177 if (dd->ipath_port0head != (u32)
178 le64_to_cpu(*dd->ipath_hdrqtailptr)) {
179 if (dd->ipath_lastport0rcv_cnt ==
180 ipath_stats.sps_port0pkts) {
181 ipath_cdbg(PKT, "missing rcv interrupts? "
182 "port0 hd=%llx tl=%x; port0pkts %llx\n",
183 (unsigned long long)
184 le64_to_cpu(*dd->ipath_hdrqtailptr),
185 dd->ipath_port0head,
186 (unsigned long long)
187 ipath_stats.sps_port0pkts);
188 ipath_kreceive(dd);
189 }
190 dd->ipath_lastport0rcv_cnt = ipath_stats.sps_port0pkts;
191 }
192}
193
194/**
195 * ipath_get_faststats - get word counters from chip before they overflow
196 * @opaque - contains a pointer to the infinipath device ipath_devdata
197 *
198 * called from add_timer
199 */
200void ipath_get_faststats(unsigned long opaque)
201{
202 struct ipath_devdata *dd = (struct ipath_devdata *) opaque;
203 u32 val;
204 static unsigned cnt;
205
206 /*
207 * don't access the chip while running diags, or memory diags can
208 * fail
209 */
210 if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT) ||
211 ipath_diag_inuse)
212 /* but re-arm the timer, for diags case; won't hurt other */
213 goto done;
214
215 if (dd->ipath_flags & IPATH_32BITCOUNTERS) {
216 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordsendcnt);
217 ipath_snap_cntr(dd, dd->ipath_cregs->cr_wordrcvcnt);
218 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktsendcnt);
219 ipath_snap_cntr(dd, dd->ipath_cregs->cr_pktrcvcnt);
220 }
221
222 ipath_qcheck(dd);
223
224 /*
225 * deal with repeat error suppression. Doesn't really matter if
226 * last error was almost a full interval ago, or just a few usecs
227 * ago; still won't get more than 2 per interval. We may want
228 * longer intervals for this eventually, could do with mod, counter
229 * or separate timer. Also see code in ipath_handle_errors() and
230 * ipath_handle_hwerrors().
231 */
232
233 if (dd->ipath_lasterror)
234 dd->ipath_lasterror = 0;
235 if (dd->ipath_lasthwerror)
236 dd->ipath_lasthwerror = 0;
237 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs)
238 && time_after(jiffies, dd->ipath_unmasktime)) {
239 char ebuf[256];
240 ipath_decode_err(ebuf, sizeof ebuf,
241 (dd->ipath_maskederrs & ~dd->
242 ipath_ignorederrs));
243 if ((dd->ipath_maskederrs & ~dd->ipath_ignorederrs) &
244 ~(INFINIPATH_E_RRCVEGRFULL | INFINIPATH_E_RRCVHDRFULL))
245 ipath_dev_err(dd, "Re-enabling masked errors "
246 "(%s)\n", ebuf);
247 else {
248 /*
249 * rcvegrfull and rcvhdrqfull are "normal", for some
250 * types of processes (mostly benchmarks) that send
251 * huge numbers of messages, while not processing
252 * them. So only complain about these at debug
253 * level.
254 */
255 ipath_dbg("Disabling frequent queue full errors "
256 "(%s)\n", ebuf);
257 }
258 dd->ipath_maskederrs = dd->ipath_ignorederrs;
259 ipath_write_kreg(dd, dd->ipath_kregs->kr_errormask,
260 ~dd->ipath_maskederrs);
261 }
262
263 /* limit qfull messages to ~one per minute per port */
264 if ((++cnt & 0x10)) {
265 for (val = dd->ipath_cfgports - 1; ((int)val) >= 0;
266 val--) {
267 if (dd->ipath_lastegrheads[val] != -1)
268 dd->ipath_lastegrheads[val] = -1;
269 if (dd->ipath_lastrcvhdrqtails[val] != -1)
270 dd->ipath_lastrcvhdrqtails[val] = -1;
271 }
272 }
273
274 if (dd->ipath_nosma_bufs) {
275 dd->ipath_nosma_secs += 5;
276 if (dd->ipath_nosma_secs >= 30) {
277 ipath_cdbg(SMA, "No SMA bufs avail %u seconds; "
278 "cancelling pending sends\n",
279 dd->ipath_nosma_secs);
280 /*
281 * issue an abort as well, in case we have a packet
282 * stuck in launch fifo. This could corrupt an
283 * outgoing user packet in the worst case,
284 * but this is a pretty catastrophic, anyway.
285 */
286 ipath_write_kreg(dd, dd->ipath_kregs->kr_sendctrl,
287 INFINIPATH_S_ABORT);
288 ipath_disarm_piobufs(dd, dd->ipath_lastport_piobuf,
289 dd->ipath_piobcnt2k +
290 dd->ipath_piobcnt4k -
291 dd->ipath_lastport_piobuf);
292 /* start again, if necessary */
293 dd->ipath_nosma_secs = 0;
294 } else
295 ipath_cdbg(SMA, "No SMA bufs avail %u tries, "
296 "after %u seconds\n",
297 dd->ipath_nosma_bufs,
298 dd->ipath_nosma_secs);
299 }
300
301done:
302 mod_timer(&dd->ipath_stats_timer, jiffies + HZ * 5);
303}
diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c
new file mode 100644
index 000000000000..32acd8048b49
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c
@@ -0,0 +1,778 @@
1/*
2 * Copyright (c) 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/ctype.h>
34#include <linux/pci.h>
35
36#include "ipath_kernel.h"
37#include "ips_common.h"
38#include "ipath_layer.h"
39
40/**
41 * ipath_parse_ushort - parse an unsigned short value in an arbitrary base
42 * @str: the string containing the number
43 * @valp: where to put the result
44 *
45 * returns the number of bytes consumed, or negative value on error
46 */
47int ipath_parse_ushort(const char *str, unsigned short *valp)
48{
49 unsigned long val;
50 char *end;
51 int ret;
52
53 if (!isdigit(str[0])) {
54 ret = -EINVAL;
55 goto bail;
56 }
57
58 val = simple_strtoul(str, &end, 0);
59
60 if (val > 0xffff) {
61 ret = -EINVAL;
62 goto bail;
63 }
64
65 *valp = val;
66
67 ret = end + 1 - str;
68 if (ret == 0)
69 ret = -EINVAL;
70
71bail:
72 return ret;
73}
74
75static ssize_t show_version(struct device_driver *dev, char *buf)
76{
77 /* The string printed here is already newline-terminated. */
78 return scnprintf(buf, PAGE_SIZE, "%s", ipath_core_version);
79}
80
81static ssize_t show_num_units(struct device_driver *dev, char *buf)
82{
83 return scnprintf(buf, PAGE_SIZE, "%d\n",
84 ipath_count_units(NULL, NULL, NULL));
85}
86
87#define DRIVER_STAT(name, attr) \
88 static ssize_t show_stat_##name(struct device_driver *dev, \
89 char *buf) \
90 { \
91 return scnprintf( \
92 buf, PAGE_SIZE, "%llu\n", \
93 (unsigned long long) ipath_stats.sps_ ##attr); \
94 } \
95 static DRIVER_ATTR(name, S_IRUGO, show_stat_##name, NULL)
96
97DRIVER_STAT(intrs, ints);
98DRIVER_STAT(err_intrs, errints);
99DRIVER_STAT(errs, errs);
100DRIVER_STAT(pkt_errs, pkterrs);
101DRIVER_STAT(crc_errs, crcerrs);
102DRIVER_STAT(hw_errs, hwerrs);
103DRIVER_STAT(ib_link, iblink);
104DRIVER_STAT(port0_pkts, port0pkts);
105DRIVER_STAT(ether_spkts, ether_spkts);
106DRIVER_STAT(ether_rpkts, ether_rpkts);
107DRIVER_STAT(sma_spkts, sma_spkts);
108DRIVER_STAT(sma_rpkts, sma_rpkts);
109DRIVER_STAT(hdrq_full, hdrqfull);
110DRIVER_STAT(etid_full, etidfull);
111DRIVER_STAT(no_piobufs, nopiobufs);
112DRIVER_STAT(ports, ports);
113DRIVER_STAT(pkey0, pkeys[0]);
114DRIVER_STAT(pkey1, pkeys[1]);
115DRIVER_STAT(pkey2, pkeys[2]);
116DRIVER_STAT(pkey3, pkeys[3]);
117/* XXX fix the following when dynamic table of devices used */
118DRIVER_STAT(lid0, lid[0]);
119DRIVER_STAT(lid1, lid[1]);
120DRIVER_STAT(lid2, lid[2]);
121DRIVER_STAT(lid3, lid[3]);
122
123DRIVER_STAT(nports, nports);
124DRIVER_STAT(null_intr, nullintr);
125DRIVER_STAT(max_pkts_call, maxpkts_call);
126DRIVER_STAT(avg_pkts_call, avgpkts_call);
127DRIVER_STAT(page_locks, pagelocks);
128DRIVER_STAT(page_unlocks, pageunlocks);
129DRIVER_STAT(krdrops, krdrops);
130/* XXX fix the following when dynamic table of devices used */
131DRIVER_STAT(mlid0, mlid[0]);
132DRIVER_STAT(mlid1, mlid[1]);
133DRIVER_STAT(mlid2, mlid[2]);
134DRIVER_STAT(mlid3, mlid[3]);
135
136static struct attribute *driver_stat_attributes[] = {
137 &driver_attr_intrs.attr,
138 &driver_attr_err_intrs.attr,
139 &driver_attr_errs.attr,
140 &driver_attr_pkt_errs.attr,
141 &driver_attr_crc_errs.attr,
142 &driver_attr_hw_errs.attr,
143 &driver_attr_ib_link.attr,
144 &driver_attr_port0_pkts.attr,
145 &driver_attr_ether_spkts.attr,
146 &driver_attr_ether_rpkts.attr,
147 &driver_attr_sma_spkts.attr,
148 &driver_attr_sma_rpkts.attr,
149 &driver_attr_hdrq_full.attr,
150 &driver_attr_etid_full.attr,
151 &driver_attr_no_piobufs.attr,
152 &driver_attr_ports.attr,
153 &driver_attr_pkey0.attr,
154 &driver_attr_pkey1.attr,
155 &driver_attr_pkey2.attr,
156 &driver_attr_pkey3.attr,
157 &driver_attr_lid0.attr,
158 &driver_attr_lid1.attr,
159 &driver_attr_lid2.attr,
160 &driver_attr_lid3.attr,
161 &driver_attr_nports.attr,
162 &driver_attr_null_intr.attr,
163 &driver_attr_max_pkts_call.attr,
164 &driver_attr_avg_pkts_call.attr,
165 &driver_attr_page_locks.attr,
166 &driver_attr_page_unlocks.attr,
167 &driver_attr_krdrops.attr,
168 &driver_attr_mlid0.attr,
169 &driver_attr_mlid1.attr,
170 &driver_attr_mlid2.attr,
171 &driver_attr_mlid3.attr,
172 NULL
173};
174
175static struct attribute_group driver_stat_attr_group = {
176 .name = "stats",
177 .attrs = driver_stat_attributes
178};
179
180static ssize_t show_status(struct device *dev,
181 struct device_attribute *attr,
182 char *buf)
183{
184 struct ipath_devdata *dd = dev_get_drvdata(dev);
185 ssize_t ret;
186
187 if (!dd->ipath_statusp) {
188 ret = -EINVAL;
189 goto bail;
190 }
191
192 ret = scnprintf(buf, PAGE_SIZE, "0x%llx\n",
193 (unsigned long long) *(dd->ipath_statusp));
194
195bail:
196 return ret;
197}
198
199static const char *ipath_status_str[] = {
200 "Initted",
201 "Disabled",
202 "Admin_Disabled",
203 "OIB_SMA",
204 "SMA",
205 "Present",
206 "IB_link_up",
207 "IB_configured",
208 "NoIBcable",
209 "Fatal_Hardware_Error",
210 NULL,
211};
212
213static ssize_t show_status_str(struct device *dev,
214 struct device_attribute *attr,
215 char *buf)
216{
217 struct ipath_devdata *dd = dev_get_drvdata(dev);
218 int i, any;
219 u64 s;
220 ssize_t ret;
221
222 if (!dd->ipath_statusp) {
223 ret = -EINVAL;
224 goto bail;
225 }
226
227 s = *(dd->ipath_statusp);
228 *buf = '\0';
229 for (any = i = 0; s && ipath_status_str[i]; i++) {
230 if (s & 1) {
231 if (any && strlcat(buf, " ", PAGE_SIZE) >=
232 PAGE_SIZE)
233 /* overflow */
234 break;
235 if (strlcat(buf, ipath_status_str[i],
236 PAGE_SIZE) >= PAGE_SIZE)
237 break;
238 any = 1;
239 }
240 s >>= 1;
241 }
242 if (any)
243 strlcat(buf, "\n", PAGE_SIZE);
244
245 ret = strlen(buf);
246
247bail:
248 return ret;
249}
250
251static ssize_t show_boardversion(struct device *dev,
252 struct device_attribute *attr,
253 char *buf)
254{
255 struct ipath_devdata *dd = dev_get_drvdata(dev);
256 /* The string printed here is already newline-terminated. */
257 return scnprintf(buf, PAGE_SIZE, "%s", dd->ipath_boardversion);
258}
259
260static ssize_t show_lid(struct device *dev,
261 struct device_attribute *attr,
262 char *buf)
263{
264 struct ipath_devdata *dd = dev_get_drvdata(dev);
265
266 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_lid);
267}
268
269static ssize_t store_lid(struct device *dev,
270 struct device_attribute *attr,
271 const char *buf,
272 size_t count)
273{
274 struct ipath_devdata *dd = dev_get_drvdata(dev);
275 u16 lid;
276 int ret;
277
278 ret = ipath_parse_ushort(buf, &lid);
279 if (ret < 0)
280 goto invalid;
281
282 if (lid == 0 || lid >= 0xc000) {
283 ret = -EINVAL;
284 goto invalid;
285 }
286
287 ipath_set_sps_lid(dd, lid, 0);
288
289 goto bail;
290invalid:
291 ipath_dev_err(dd, "attempt to set invalid LID\n");
292bail:
293 return ret;
294}
295
296static ssize_t show_mlid(struct device *dev,
297 struct device_attribute *attr,
298 char *buf)
299{
300 struct ipath_devdata *dd = dev_get_drvdata(dev);
301
302 return scnprintf(buf, PAGE_SIZE, "0x%x\n", dd->ipath_mlid);
303}
304
305static ssize_t store_mlid(struct device *dev,
306 struct device_attribute *attr,
307 const char *buf,
308 size_t count)
309{
310 struct ipath_devdata *dd = dev_get_drvdata(dev);
311 int unit;
312 u16 mlid;
313 int ret;
314
315 ret = ipath_parse_ushort(buf, &mlid);
316 if (ret < 0)
317 goto invalid;
318
319 unit = dd->ipath_unit;
320
321 dd->ipath_mlid = mlid;
322 ipath_stats.sps_mlid[unit] = mlid;
323 ipath_layer_intr(dd, IPATH_LAYER_INT_BCAST);
324
325 goto bail;
326invalid:
327 ipath_dev_err(dd, "attempt to set invalid MLID\n");
328bail:
329 return ret;
330}
331
332static ssize_t show_guid(struct device *dev,
333 struct device_attribute *attr,
334 char *buf)
335{
336 struct ipath_devdata *dd = dev_get_drvdata(dev);
337 u8 *guid;
338
339 guid = (u8 *) & (dd->ipath_guid);
340
341 return scnprintf(buf, PAGE_SIZE,
342 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
343 guid[0], guid[1], guid[2], guid[3],
344 guid[4], guid[5], guid[6], guid[7]);
345}
346
347static ssize_t store_guid(struct device *dev,
348 struct device_attribute *attr,
349 const char *buf,
350 size_t count)
351{
352 struct ipath_devdata *dd = dev_get_drvdata(dev);
353 ssize_t ret;
354 unsigned short guid[8];
355 __be64 nguid;
356 u8 *ng;
357 int i;
358
359 if (sscanf(buf, "%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
360 &guid[0], &guid[1], &guid[2], &guid[3],
361 &guid[4], &guid[5], &guid[6], &guid[7]) != 8)
362 goto invalid;
363
364 ng = (u8 *) &nguid;
365
366 for (i = 0; i < 8; i++) {
367 if (guid[i] > 0xff)
368 goto invalid;
369 ng[i] = guid[i];
370 }
371
372 dd->ipath_guid = nguid;
373 dd->ipath_nguid = 1;
374
375 ret = strlen(buf);
376 goto bail;
377
378invalid:
379 ipath_dev_err(dd, "attempt to set invalid GUID\n");
380 ret = -EINVAL;
381
382bail:
383 return ret;
384}
385
386static ssize_t show_nguid(struct device *dev,
387 struct device_attribute *attr,
388 char *buf)
389{
390 struct ipath_devdata *dd = dev_get_drvdata(dev);
391
392 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_nguid);
393}
394
395static ssize_t show_serial(struct device *dev,
396 struct device_attribute *attr,
397 char *buf)
398{
399 struct ipath_devdata *dd = dev_get_drvdata(dev);
400
401 buf[sizeof dd->ipath_serial] = '\0';
402 memcpy(buf, dd->ipath_serial, sizeof dd->ipath_serial);
403 strcat(buf, "\n");
404 return strlen(buf);
405}
406
407static ssize_t show_unit(struct device *dev,
408 struct device_attribute *attr,
409 char *buf)
410{
411 struct ipath_devdata *dd = dev_get_drvdata(dev);
412
413 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_unit);
414}
415
416#define DEVICE_COUNTER(name, attr) \
417 static ssize_t show_counter_##name(struct device *dev, \
418 struct device_attribute *attr, \
419 char *buf) \
420 { \
421 struct ipath_devdata *dd = dev_get_drvdata(dev); \
422 return scnprintf(\
423 buf, PAGE_SIZE, "%llu\n", (unsigned long long) \
424 ipath_snap_cntr( \
425 dd, offsetof(struct infinipath_counters, \
426 attr) / sizeof(u64))); \
427 } \
428 static DEVICE_ATTR(name, S_IRUGO, show_counter_##name, NULL);
429
430DEVICE_COUNTER(ib_link_downeds, IBLinkDownedCnt);
431DEVICE_COUNTER(ib_link_err_recoveries, IBLinkErrRecoveryCnt);
432DEVICE_COUNTER(ib_status_changes, IBStatusChangeCnt);
433DEVICE_COUNTER(ib_symbol_errs, IBSymbolErrCnt);
434DEVICE_COUNTER(lb_flow_stalls, LBFlowStallCnt);
435DEVICE_COUNTER(lb_ints, LBIntCnt);
436DEVICE_COUNTER(rx_bad_formats, RxBadFormatCnt);
437DEVICE_COUNTER(rx_buf_ovfls, RxBufOvflCnt);
438DEVICE_COUNTER(rx_data_pkts, RxDataPktCnt);
439DEVICE_COUNTER(rx_dropped_pkts, RxDroppedPktCnt);
440DEVICE_COUNTER(rx_dwords, RxDwordCnt);
441DEVICE_COUNTER(rx_ebps, RxEBPCnt);
442DEVICE_COUNTER(rx_flow_ctrl_errs, RxFlowCtrlErrCnt);
443DEVICE_COUNTER(rx_flow_pkts, RxFlowPktCnt);
444DEVICE_COUNTER(rx_icrc_errs, RxICRCErrCnt);
445DEVICE_COUNTER(rx_len_errs, RxLenErrCnt);
446DEVICE_COUNTER(rx_link_problems, RxLinkProblemCnt);
447DEVICE_COUNTER(rx_lpcrc_errs, RxLPCRCErrCnt);
448DEVICE_COUNTER(rx_max_min_len_errs, RxMaxMinLenErrCnt);
449DEVICE_COUNTER(rx_p0_hdr_egr_ovfls, RxP0HdrEgrOvflCnt);
450DEVICE_COUNTER(rx_p1_hdr_egr_ovfls, RxP1HdrEgrOvflCnt);
451DEVICE_COUNTER(rx_p2_hdr_egr_ovfls, RxP2HdrEgrOvflCnt);
452DEVICE_COUNTER(rx_p3_hdr_egr_ovfls, RxP3HdrEgrOvflCnt);
453DEVICE_COUNTER(rx_p4_hdr_egr_ovfls, RxP4HdrEgrOvflCnt);
454DEVICE_COUNTER(rx_p5_hdr_egr_ovfls, RxP5HdrEgrOvflCnt);
455DEVICE_COUNTER(rx_p6_hdr_egr_ovfls, RxP6HdrEgrOvflCnt);
456DEVICE_COUNTER(rx_p7_hdr_egr_ovfls, RxP7HdrEgrOvflCnt);
457DEVICE_COUNTER(rx_p8_hdr_egr_ovfls, RxP8HdrEgrOvflCnt);
458DEVICE_COUNTER(rx_pkey_mismatches, RxPKeyMismatchCnt);
459DEVICE_COUNTER(rx_tid_full_errs, RxTIDFullErrCnt);
460DEVICE_COUNTER(rx_tid_valid_errs, RxTIDValidErrCnt);
461DEVICE_COUNTER(rx_vcrc_errs, RxVCRCErrCnt);
462DEVICE_COUNTER(tx_data_pkts, TxDataPktCnt);
463DEVICE_COUNTER(tx_dropped_pkts, TxDroppedPktCnt);
464DEVICE_COUNTER(tx_dwords, TxDwordCnt);
465DEVICE_COUNTER(tx_flow_pkts, TxFlowPktCnt);
466DEVICE_COUNTER(tx_flow_stalls, TxFlowStallCnt);
467DEVICE_COUNTER(tx_len_errs, TxLenErrCnt);
468DEVICE_COUNTER(tx_max_min_len_errs, TxMaxMinLenErrCnt);
469DEVICE_COUNTER(tx_underruns, TxUnderrunCnt);
470DEVICE_COUNTER(tx_unsup_vl_errs, TxUnsupVLErrCnt);
471
472static struct attribute *dev_counter_attributes[] = {
473 &dev_attr_ib_link_downeds.attr,
474 &dev_attr_ib_link_err_recoveries.attr,
475 &dev_attr_ib_status_changes.attr,
476 &dev_attr_ib_symbol_errs.attr,
477 &dev_attr_lb_flow_stalls.attr,
478 &dev_attr_lb_ints.attr,
479 &dev_attr_rx_bad_formats.attr,
480 &dev_attr_rx_buf_ovfls.attr,
481 &dev_attr_rx_data_pkts.attr,
482 &dev_attr_rx_dropped_pkts.attr,
483 &dev_attr_rx_dwords.attr,
484 &dev_attr_rx_ebps.attr,
485 &dev_attr_rx_flow_ctrl_errs.attr,
486 &dev_attr_rx_flow_pkts.attr,
487 &dev_attr_rx_icrc_errs.attr,
488 &dev_attr_rx_len_errs.attr,
489 &dev_attr_rx_link_problems.attr,
490 &dev_attr_rx_lpcrc_errs.attr,
491 &dev_attr_rx_max_min_len_errs.attr,
492 &dev_attr_rx_p0_hdr_egr_ovfls.attr,
493 &dev_attr_rx_p1_hdr_egr_ovfls.attr,
494 &dev_attr_rx_p2_hdr_egr_ovfls.attr,
495 &dev_attr_rx_p3_hdr_egr_ovfls.attr,
496 &dev_attr_rx_p4_hdr_egr_ovfls.attr,
497 &dev_attr_rx_p5_hdr_egr_ovfls.attr,
498 &dev_attr_rx_p6_hdr_egr_ovfls.attr,
499 &dev_attr_rx_p7_hdr_egr_ovfls.attr,
500 &dev_attr_rx_p8_hdr_egr_ovfls.attr,
501 &dev_attr_rx_pkey_mismatches.attr,
502 &dev_attr_rx_tid_full_errs.attr,
503 &dev_attr_rx_tid_valid_errs.attr,
504 &dev_attr_rx_vcrc_errs.attr,
505 &dev_attr_tx_data_pkts.attr,
506 &dev_attr_tx_dropped_pkts.attr,
507 &dev_attr_tx_dwords.attr,
508 &dev_attr_tx_flow_pkts.attr,
509 &dev_attr_tx_flow_stalls.attr,
510 &dev_attr_tx_len_errs.attr,
511 &dev_attr_tx_max_min_len_errs.attr,
512 &dev_attr_tx_underruns.attr,
513 &dev_attr_tx_unsup_vl_errs.attr,
514 NULL
515};
516
517static struct attribute_group dev_counter_attr_group = {
518 .name = "counters",
519 .attrs = dev_counter_attributes
520};
521
522static ssize_t store_reset(struct device *dev,
523 struct device_attribute *attr,
524 const char *buf,
525 size_t count)
526{
527 struct ipath_devdata *dd = dev_get_drvdata(dev);
528 int ret;
529
530 if (count < 5 || memcmp(buf, "reset", 5)) {
531 ret = -EINVAL;
532 goto bail;
533 }
534
535 if (dd->ipath_flags & IPATH_DISABLED) {
536 /*
537 * post-reset init would re-enable interrupts, etc.
538 * so don't allow reset on disabled devices. Not
539 * perfect error, but about the best choice.
540 */
541 dev_info(dev,"Unit %d is disabled, can't reset\n",
542 dd->ipath_unit);
543 ret = -EINVAL;
544 }
545 ret = ipath_reset_device(dd->ipath_unit);
546bail:
547 return ret<0 ? ret : count;
548}
549
550static ssize_t store_link_state(struct device *dev,
551 struct device_attribute *attr,
552 const char *buf,
553 size_t count)
554{
555 struct ipath_devdata *dd = dev_get_drvdata(dev);
556 int ret, r;
557 u16 state;
558
559 ret = ipath_parse_ushort(buf, &state);
560 if (ret < 0)
561 goto invalid;
562
563 r = ipath_layer_set_linkstate(dd, state);
564 if (r < 0) {
565 ret = r;
566 goto bail;
567 }
568
569 goto bail;
570invalid:
571 ipath_dev_err(dd, "attempt to set invalid link state\n");
572bail:
573 return ret;
574}
575
576static ssize_t show_mtu(struct device *dev,
577 struct device_attribute *attr,
578 char *buf)
579{
580 struct ipath_devdata *dd = dev_get_drvdata(dev);
581 return scnprintf(buf, PAGE_SIZE, "%u\n", dd->ipath_ibmtu);
582}
583
584static ssize_t store_mtu(struct device *dev,
585 struct device_attribute *attr,
586 const char *buf,
587 size_t count)
588{
589 struct ipath_devdata *dd = dev_get_drvdata(dev);
590 ssize_t ret;
591 u16 mtu = 0;
592 int r;
593
594 ret = ipath_parse_ushort(buf, &mtu);
595 if (ret < 0)
596 goto invalid;
597
598 r = ipath_layer_set_mtu(dd, mtu);
599 if (r < 0)
600 ret = r;
601
602 goto bail;
603invalid:
604 ipath_dev_err(dd, "attempt to set invalid MTU\n");
605bail:
606 return ret;
607}
608
609static ssize_t show_enabled(struct device *dev,
610 struct device_attribute *attr,
611 char *buf)
612{
613 struct ipath_devdata *dd = dev_get_drvdata(dev);
614 return scnprintf(buf, PAGE_SIZE, "%u\n",
615 (dd->ipath_flags & IPATH_DISABLED) ? 0 : 1);
616}
617
618static ssize_t store_enabled(struct device *dev,
619 struct device_attribute *attr,
620 const char *buf,
621 size_t count)
622{
623 struct ipath_devdata *dd = dev_get_drvdata(dev);
624 ssize_t ret;
625 u16 enable = 0;
626
627 ret = ipath_parse_ushort(buf, &enable);
628 if (ret < 0) {
629 ipath_dev_err(dd, "attempt to use non-numeric on enable\n");
630 goto bail;
631 }
632
633 if (enable) {
634 if (!(dd->ipath_flags & IPATH_DISABLED))
635 goto bail;
636
637 dev_info(dev, "Enabling unit %d\n", dd->ipath_unit);
638 /* same as post-reset */
639 ret = ipath_init_chip(dd, 1);
640 if (ret)
641 ipath_dev_err(dd, "Failed to enable unit %d\n",
642 dd->ipath_unit);
643 else {
644 dd->ipath_flags &= ~IPATH_DISABLED;
645 *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
646 }
647 }
648 else if (!(dd->ipath_flags & IPATH_DISABLED)) {
649 dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
650 ipath_shutdown_device(dd);
651 dd->ipath_flags |= IPATH_DISABLED;
652 *dd->ipath_statusp |= IPATH_STATUS_ADMIN_DISABLED;
653 }
654
655bail:
656 return ret;
657}
658
659static DRIVER_ATTR(num_units, S_IRUGO, show_num_units, NULL);
660static DRIVER_ATTR(version, S_IRUGO, show_version, NULL);
661
662static struct attribute *driver_attributes[] = {
663 &driver_attr_num_units.attr,
664 &driver_attr_version.attr,
665 NULL
666};
667
668static struct attribute_group driver_attr_group = {
669 .attrs = driver_attributes
670};
671
672static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
673static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
674static DEVICE_ATTR(link_state, S_IWUSR, NULL, store_link_state);
675static DEVICE_ATTR(mlid, S_IWUSR | S_IRUGO, show_mlid, store_mlid);
676static DEVICE_ATTR(mtu, S_IWUSR | S_IRUGO, show_mtu, store_mtu);
677static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO, show_enabled, store_enabled);
678static DEVICE_ATTR(nguid, S_IRUGO, show_nguid, NULL);
679static DEVICE_ATTR(reset, S_IWUSR, NULL, store_reset);
680static DEVICE_ATTR(serial, S_IRUGO, show_serial, NULL);
681static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
682static DEVICE_ATTR(status_str, S_IRUGO, show_status_str, NULL);
683static DEVICE_ATTR(boardversion, S_IRUGO, show_boardversion, NULL);
684static DEVICE_ATTR(unit, S_IRUGO, show_unit, NULL);
685
686static struct attribute *dev_attributes[] = {
687 &dev_attr_guid.attr,
688 &dev_attr_lid.attr,
689 &dev_attr_link_state.attr,
690 &dev_attr_mlid.attr,
691 &dev_attr_mtu.attr,
692 &dev_attr_nguid.attr,
693 &dev_attr_serial.attr,
694 &dev_attr_status.attr,
695 &dev_attr_status_str.attr,
696 &dev_attr_boardversion.attr,
697 &dev_attr_unit.attr,
698 &dev_attr_enabled.attr,
699 NULL
700};
701
702static struct attribute_group dev_attr_group = {
703 .attrs = dev_attributes
704};
705
706/**
707 * ipath_expose_reset - create a device reset file
708 * @dev: the device structure
709 *
710 * Only expose a file that lets us reset the device after someone
711 * enters diag mode. A device reset is quite likely to crash the
712 * machine entirely, so we don't want to normally make it
713 * available.
714 */
715int ipath_expose_reset(struct device *dev)
716{
717 return device_create_file(dev, &dev_attr_reset);
718}
719
720int ipath_driver_create_group(struct device_driver *drv)
721{
722 int ret;
723
724 ret = sysfs_create_group(&drv->kobj, &driver_attr_group);
725 if (ret)
726 goto bail;
727
728 ret = sysfs_create_group(&drv->kobj, &driver_stat_attr_group);
729 if (ret)
730 sysfs_remove_group(&drv->kobj, &driver_attr_group);
731
732bail:
733 return ret;
734}
735
736void ipath_driver_remove_group(struct device_driver *drv)
737{
738 sysfs_remove_group(&drv->kobj, &driver_stat_attr_group);
739 sysfs_remove_group(&drv->kobj, &driver_attr_group);
740}
741
742int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
743{
744 int ret;
745 char unit[5];
746
747 ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
748 if (ret)
749 goto bail;
750
751 ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
752 if (ret)
753 goto bail_attrs;
754
755 snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
756 ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
757 if (ret == 0)
758 goto bail;
759
760 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
761bail_attrs:
762 sysfs_remove_group(&dev->kobj, &dev_attr_group);
763bail:
764 return ret;
765}
766
767void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
768{
769 char unit[5];
770
771 snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
772 sysfs_remove_link(&dev->driver->kobj, unit);
773
774 sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
775 sysfs_remove_group(&dev->kobj, &dev_attr_group);
776
777 device_remove_file(dev, &dev_attr_reset);
778}
diff --git a/drivers/infiniband/hw/ipath/ipath_uc.c b/drivers/infiniband/hw/ipath/ipath_uc.c
new file mode 100644
index 000000000000..0d6dbc0a541e
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_uc.c
@@ -0,0 +1,645 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include "ipath_verbs.h"
34#include "ips_common.h"
35
36/* cut down ridiculously long IB macro names */
37#define OP(x) IB_OPCODE_UC_##x
38
39static void complete_last_send(struct ipath_qp *qp, struct ipath_swqe *wqe,
40 struct ib_wc *wc)
41{
42 if (++qp->s_last == qp->s_size)
43 qp->s_last = 0;
44 if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) ||
45 (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
46 wc->wr_id = wqe->wr.wr_id;
47 wc->status = IB_WC_SUCCESS;
48 wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
49 wc->vendor_err = 0;
50 wc->byte_len = wqe->length;
51 wc->qp_num = qp->ibqp.qp_num;
52 wc->src_qp = qp->remote_qpn;
53 wc->pkey_index = 0;
54 wc->slid = qp->remote_ah_attr.dlid;
55 wc->sl = qp->remote_ah_attr.sl;
56 wc->dlid_path_bits = 0;
57 wc->port_num = 0;
58 ipath_cq_enter(to_icq(qp->ibqp.send_cq), wc, 0);
59 }
60 wqe = get_swqe_ptr(qp, qp->s_last);
61}
62
63/**
64 * ipath_do_uc_send - do a send on a UC queue
65 * @data: contains a pointer to the QP to send on
66 *
67 * Process entries in the send work queue until the queue is exhausted.
68 * Only allow one CPU to send a packet per QP (tasklet).
69 * Otherwise, after we drop the QP lock, two threads could send
70 * packets out of order.
71 * This is similar to ipath_do_rc_send() below except we don't have
72 * timeouts or resends.
73 */
74void ipath_do_uc_send(unsigned long data)
75{
76 struct ipath_qp *qp = (struct ipath_qp *)data;
77 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
78 struct ipath_swqe *wqe;
79 unsigned long flags;
80 u16 lrh0;
81 u32 hwords;
82 u32 nwords;
83 u32 extra_bytes;
84 u32 bth0;
85 u32 bth2;
86 u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
87 u32 len;
88 struct ipath_other_headers *ohdr;
89 struct ib_wc wc;
90
91 if (test_and_set_bit(IPATH_S_BUSY, &qp->s_flags))
92 goto bail;
93
94 if (unlikely(qp->remote_ah_attr.dlid ==
95 ipath_layer_get_lid(dev->dd))) {
96 /* Pass in an uninitialized ib_wc to save stack space. */
97 ipath_ruc_loopback(qp, &wc);
98 clear_bit(IPATH_S_BUSY, &qp->s_flags);
99 goto bail;
100 }
101
102 ohdr = &qp->s_hdr.u.oth;
103 if (qp->remote_ah_attr.ah_flags & IB_AH_GRH)
104 ohdr = &qp->s_hdr.u.l.oth;
105
106again:
107 /* Check for a constructed packet to be sent. */
108 if (qp->s_hdrwords != 0) {
109 /*
110 * If no PIO bufs are available, return.
111 * An interrupt will call ipath_ib_piobufavail()
112 * when one is available.
113 */
114 if (ipath_verbs_send(dev->dd, qp->s_hdrwords,
115 (u32 *) &qp->s_hdr,
116 qp->s_cur_size,
117 qp->s_cur_sge)) {
118 ipath_no_bufs_available(qp, dev);
119 goto bail;
120 }
121 dev->n_unicast_xmit++;
122 /* Record that we sent the packet and s_hdr is empty. */
123 qp->s_hdrwords = 0;
124 }
125
126 lrh0 = IPS_LRH_BTH;
127 /* header size in 32-bit words LRH+BTH = (8+12)/4. */
128 hwords = 5;
129
130 /*
131 * The lock is needed to synchronize between
132 * setting qp->s_ack_state and post_send().
133 */
134 spin_lock_irqsave(&qp->s_lock, flags);
135
136 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK))
137 goto done;
138
139 bth0 = ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
140
141 /* Send a request. */
142 wqe = get_swqe_ptr(qp, qp->s_last);
143 switch (qp->s_state) {
144 default:
145 /*
146 * Signal the completion of the last send (if there is
147 * one).
148 */
149 if (qp->s_last != qp->s_tail)
150 complete_last_send(qp, wqe, &wc);
151
152 /* Check if send work queue is empty. */
153 if (qp->s_tail == qp->s_head)
154 goto done;
155 /*
156 * Start a new request.
157 */
158 qp->s_psn = wqe->psn = qp->s_next_psn;
159 qp->s_sge.sge = wqe->sg_list[0];
160 qp->s_sge.sg_list = wqe->sg_list + 1;
161 qp->s_sge.num_sge = wqe->wr.num_sge;
162 qp->s_len = len = wqe->length;
163 switch (wqe->wr.opcode) {
164 case IB_WR_SEND:
165 case IB_WR_SEND_WITH_IMM:
166 if (len > pmtu) {
167 qp->s_state = OP(SEND_FIRST);
168 len = pmtu;
169 break;
170 }
171 if (wqe->wr.opcode == IB_WR_SEND)
172 qp->s_state = OP(SEND_ONLY);
173 else {
174 qp->s_state =
175 OP(SEND_ONLY_WITH_IMMEDIATE);
176 /* Immediate data comes after the BTH */
177 ohdr->u.imm_data = wqe->wr.imm_data;
178 hwords += 1;
179 }
180 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
181 bth0 |= 1 << 23;
182 break;
183
184 case IB_WR_RDMA_WRITE:
185 case IB_WR_RDMA_WRITE_WITH_IMM:
186 ohdr->u.rc.reth.vaddr =
187 cpu_to_be64(wqe->wr.wr.rdma.remote_addr);
188 ohdr->u.rc.reth.rkey =
189 cpu_to_be32(wqe->wr.wr.rdma.rkey);
190 ohdr->u.rc.reth.length = cpu_to_be32(len);
191 hwords += sizeof(struct ib_reth) / 4;
192 if (len > pmtu) {
193 qp->s_state = OP(RDMA_WRITE_FIRST);
194 len = pmtu;
195 break;
196 }
197 if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
198 qp->s_state = OP(RDMA_WRITE_ONLY);
199 else {
200 qp->s_state =
201 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
202 /* Immediate data comes after the RETH */
203 ohdr->u.rc.imm_data = wqe->wr.imm_data;
204 hwords += 1;
205 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
206 bth0 |= 1 << 23;
207 }
208 break;
209
210 default:
211 goto done;
212 }
213 if (++qp->s_tail >= qp->s_size)
214 qp->s_tail = 0;
215 break;
216
217 case OP(SEND_FIRST):
218 qp->s_state = OP(SEND_MIDDLE);
219 /* FALLTHROUGH */
220 case OP(SEND_MIDDLE):
221 len = qp->s_len;
222 if (len > pmtu) {
223 len = pmtu;
224 break;
225 }
226 if (wqe->wr.opcode == IB_WR_SEND)
227 qp->s_state = OP(SEND_LAST);
228 else {
229 qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
230 /* Immediate data comes after the BTH */
231 ohdr->u.imm_data = wqe->wr.imm_data;
232 hwords += 1;
233 }
234 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
235 bth0 |= 1 << 23;
236 break;
237
238 case OP(RDMA_WRITE_FIRST):
239 qp->s_state = OP(RDMA_WRITE_MIDDLE);
240 /* FALLTHROUGH */
241 case OP(RDMA_WRITE_MIDDLE):
242 len = qp->s_len;
243 if (len > pmtu) {
244 len = pmtu;
245 break;
246 }
247 if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
248 qp->s_state = OP(RDMA_WRITE_LAST);
249 else {
250 qp->s_state =
251 OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
252 /* Immediate data comes after the BTH */
253 ohdr->u.imm_data = wqe->wr.imm_data;
254 hwords += 1;
255 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
256 bth0 |= 1 << 23;
257 }
258 break;
259 }
260 bth2 = qp->s_next_psn++ & IPS_PSN_MASK;
261 qp->s_len -= len;
262 bth0 |= qp->s_state << 24;
263
264 spin_unlock_irqrestore(&qp->s_lock, flags);
265
266 /* Construct the header. */
267 extra_bytes = (4 - len) & 3;
268 nwords = (len + extra_bytes) >> 2;
269 if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
270 /* Header size in 32-bit words. */
271 hwords += 10;
272 lrh0 = IPS_LRH_GRH;
273 qp->s_hdr.u.l.grh.version_tclass_flow =
274 cpu_to_be32((6 << 28) |
275 (qp->remote_ah_attr.grh.traffic_class
276 << 20) |
277 qp->remote_ah_attr.grh.flow_label);
278 qp->s_hdr.u.l.grh.paylen =
279 cpu_to_be16(((hwords - 12) + nwords +
280 SIZE_OF_CRC) << 2);
281 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
282 qp->s_hdr.u.l.grh.next_hdr = 0x1B;
283 qp->s_hdr.u.l.grh.hop_limit =
284 qp->remote_ah_attr.grh.hop_limit;
285 /* The SGID is 32-bit aligned. */
286 qp->s_hdr.u.l.grh.sgid.global.subnet_prefix =
287 dev->gid_prefix;
288 qp->s_hdr.u.l.grh.sgid.global.interface_id =
289 ipath_layer_get_guid(dev->dd);
290 qp->s_hdr.u.l.grh.dgid = qp->remote_ah_attr.grh.dgid;
291 }
292 qp->s_hdrwords = hwords;
293 qp->s_cur_sge = &qp->s_sge;
294 qp->s_cur_size = len;
295 lrh0 |= qp->remote_ah_attr.sl << 4;
296 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);
297 /* DEST LID */
298 qp->s_hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
299 qp->s_hdr.lrh[2] = cpu_to_be16(hwords + nwords + SIZE_OF_CRC);
300 qp->s_hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd));
301 bth0 |= extra_bytes << 20;
302 ohdr->bth[0] = cpu_to_be32(bth0);
303 ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
304 ohdr->bth[2] = cpu_to_be32(bth2);
305
306 /* Check for more work to do. */
307 goto again;
308
309done:
310 spin_unlock_irqrestore(&qp->s_lock, flags);
311 clear_bit(IPATH_S_BUSY, &qp->s_flags);
312
313bail:
314 return;
315}
316
317/**
318 * ipath_uc_rcv - handle an incoming UC packet
319 * @dev: the device the packet came in on
320 * @hdr: the header of the packet
321 * @has_grh: true if the packet has a GRH
322 * @data: the packet data
323 * @tlen: the length of the packet
324 * @qp: the QP for this packet.
325 *
326 * This is called from ipath_qp_rcv() to process an incoming UC packet
327 * for the given QP.
328 * Called at interrupt level.
329 */
330void ipath_uc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
331 int has_grh, void *data, u32 tlen, struct ipath_qp *qp)
332{
333 struct ipath_other_headers *ohdr;
334 int opcode;
335 u32 hdrsize;
336 u32 psn;
337 u32 pad;
338 unsigned long flags;
339 struct ib_wc wc;
340 u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
341 struct ib_reth *reth;
342 int header_in_data;
343
344 /* Check for GRH */
345 if (!has_grh) {
346 ohdr = &hdr->u.oth;
347 hdrsize = 8 + 12; /* LRH + BTH */
348 psn = be32_to_cpu(ohdr->bth[2]);
349 header_in_data = 0;
350 } else {
351 ohdr = &hdr->u.l.oth;
352 hdrsize = 8 + 40 + 12; /* LRH + GRH + BTH */
353 /*
354 * The header with GRH is 60 bytes and the
355 * core driver sets the eager header buffer
356 * size to 56 bytes so the last 4 bytes of
357 * the BTH header (PSN) is in the data buffer.
358 */
359 header_in_data =
360 ipath_layer_get_rcvhdrentsize(dev->dd) == 16;
361 if (header_in_data) {
362 psn = be32_to_cpu(((__be32 *) data)[0]);
363 data += sizeof(__be32);
364 } else
365 psn = be32_to_cpu(ohdr->bth[2]);
366 }
367 /*
368 * The opcode is in the low byte when its in network order
369 * (top byte when in host order).
370 */
371 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
372
373 wc.imm_data = 0;
374 wc.wc_flags = 0;
375
376 spin_lock_irqsave(&qp->r_rq.lock, flags);
377
378 /* Compare the PSN verses the expected PSN. */
379 if (unlikely(ipath_cmp24(psn, qp->r_psn) != 0)) {
380 /*
381 * Handle a sequence error.
382 * Silently drop any current message.
383 */
384 qp->r_psn = psn;
385 inv:
386 qp->r_state = OP(SEND_LAST);
387 switch (opcode) {
388 case OP(SEND_FIRST):
389 case OP(SEND_ONLY):
390 case OP(SEND_ONLY_WITH_IMMEDIATE):
391 goto send_first;
392
393 case OP(RDMA_WRITE_FIRST):
394 case OP(RDMA_WRITE_ONLY):
395 case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
396 goto rdma_first;
397
398 default:
399 dev->n_pkt_drops++;
400 goto done;
401 }
402 }
403
404 /* Check for opcode sequence errors. */
405 switch (qp->r_state) {
406 case OP(SEND_FIRST):
407 case OP(SEND_MIDDLE):
408 if (opcode == OP(SEND_MIDDLE) ||
409 opcode == OP(SEND_LAST) ||
410 opcode == OP(SEND_LAST_WITH_IMMEDIATE))
411 break;
412 goto inv;
413
414 case OP(RDMA_WRITE_FIRST):
415 case OP(RDMA_WRITE_MIDDLE):
416 if (opcode == OP(RDMA_WRITE_MIDDLE) ||
417 opcode == OP(RDMA_WRITE_LAST) ||
418 opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
419 break;
420 goto inv;
421
422 default:
423 if (opcode == OP(SEND_FIRST) ||
424 opcode == OP(SEND_ONLY) ||
425 opcode == OP(SEND_ONLY_WITH_IMMEDIATE) ||
426 opcode == OP(RDMA_WRITE_FIRST) ||
427 opcode == OP(RDMA_WRITE_ONLY) ||
428 opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE))
429 break;
430 goto inv;
431 }
432
433 /* OK, process the packet. */
434 switch (opcode) {
435 case OP(SEND_FIRST):
436 case OP(SEND_ONLY):
437 case OP(SEND_ONLY_WITH_IMMEDIATE):
438 send_first:
439 if (qp->r_reuse_sge) {
440 qp->r_reuse_sge = 0;
441 qp->r_sge = qp->s_rdma_sge;
442 } else if (!ipath_get_rwqe(qp, 0)) {
443 dev->n_pkt_drops++;
444 goto done;
445 }
446 /* Save the WQE so we can reuse it in case of an error. */
447 qp->s_rdma_sge = qp->r_sge;
448 qp->r_rcv_len = 0;
449 if (opcode == OP(SEND_ONLY))
450 goto send_last;
451 else if (opcode == OP(SEND_ONLY_WITH_IMMEDIATE))
452 goto send_last_imm;
453 /* FALLTHROUGH */
454 case OP(SEND_MIDDLE):
455 /* Check for invalid length PMTU or posted rwqe len. */
456 if (unlikely(tlen != (hdrsize + pmtu + 4))) {
457 qp->r_reuse_sge = 1;
458 dev->n_pkt_drops++;
459 goto done;
460 }
461 qp->r_rcv_len += pmtu;
462 if (unlikely(qp->r_rcv_len > qp->r_len)) {
463 qp->r_reuse_sge = 1;
464 dev->n_pkt_drops++;
465 goto done;
466 }
467 ipath_copy_sge(&qp->r_sge, data, pmtu);
468 break;
469
470 case OP(SEND_LAST_WITH_IMMEDIATE):
471 send_last_imm:
472 if (header_in_data) {
473 wc.imm_data = *(__be32 *) data;
474 data += sizeof(__be32);
475 } else {
476 /* Immediate data comes after BTH */
477 wc.imm_data = ohdr->u.imm_data;
478 }
479 hdrsize += 4;
480 wc.wc_flags = IB_WC_WITH_IMM;
481 /* FALLTHROUGH */
482 case OP(SEND_LAST):
483 send_last:
484 /* Get the number of bytes the message was padded by. */
485 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
486 /* Check for invalid length. */
487 /* XXX LAST len should be >= 1 */
488 if (unlikely(tlen < (hdrsize + pad + 4))) {
489 qp->r_reuse_sge = 1;
490 dev->n_pkt_drops++;
491 goto done;
492 }
493 /* Don't count the CRC. */
494 tlen -= (hdrsize + pad + 4);
495 wc.byte_len = tlen + qp->r_rcv_len;
496 if (unlikely(wc.byte_len > qp->r_len)) {
497 qp->r_reuse_sge = 1;
498 dev->n_pkt_drops++;
499 goto done;
500 }
501 /* XXX Need to free SGEs */
502 last_imm:
503 ipath_copy_sge(&qp->r_sge, data, tlen);
504 wc.wr_id = qp->r_wr_id;
505 wc.status = IB_WC_SUCCESS;
506 wc.opcode = IB_WC_RECV;
507 wc.vendor_err = 0;
508 wc.qp_num = qp->ibqp.qp_num;
509 wc.src_qp = qp->remote_qpn;
510 wc.pkey_index = 0;
511 wc.slid = qp->remote_ah_attr.dlid;
512 wc.sl = qp->remote_ah_attr.sl;
513 wc.dlid_path_bits = 0;
514 wc.port_num = 0;
515 /* Signal completion event if the solicited bit is set. */
516 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
517 (ohdr->bth[0] &
518 __constant_cpu_to_be32(1 << 23)) != 0);
519 break;
520
521 case OP(RDMA_WRITE_FIRST):
522 case OP(RDMA_WRITE_ONLY):
523 case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE): /* consume RWQE */
524 rdma_first:
525 /* RETH comes after BTH */
526 if (!header_in_data)
527 reth = &ohdr->u.rc.reth;
528 else {
529 reth = (struct ib_reth *)data;
530 data += sizeof(*reth);
531 }
532 hdrsize += sizeof(*reth);
533 qp->r_len = be32_to_cpu(reth->length);
534 qp->r_rcv_len = 0;
535 if (qp->r_len != 0) {
536 u32 rkey = be32_to_cpu(reth->rkey);
537 u64 vaddr = be64_to_cpu(reth->vaddr);
538
539 /* Check rkey */
540 if (unlikely(!ipath_rkey_ok(
541 dev, &qp->r_sge, qp->r_len,
542 vaddr, rkey,
543 IB_ACCESS_REMOTE_WRITE))) {
544 dev->n_pkt_drops++;
545 goto done;
546 }
547 } else {
548 qp->r_sge.sg_list = NULL;
549 qp->r_sge.sge.mr = NULL;
550 qp->r_sge.sge.vaddr = NULL;
551 qp->r_sge.sge.length = 0;
552 qp->r_sge.sge.sge_length = 0;
553 }
554 if (unlikely(!(qp->qp_access_flags &
555 IB_ACCESS_REMOTE_WRITE))) {
556 dev->n_pkt_drops++;
557 goto done;
558 }
559 if (opcode == OP(RDMA_WRITE_ONLY))
560 goto rdma_last;
561 else if (opcode ==
562 OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE))
563 goto rdma_last_imm;
564 /* FALLTHROUGH */
565 case OP(RDMA_WRITE_MIDDLE):
566 /* Check for invalid length PMTU or posted rwqe len. */
567 if (unlikely(tlen != (hdrsize + pmtu + 4))) {
568 dev->n_pkt_drops++;
569 goto done;
570 }
571 qp->r_rcv_len += pmtu;
572 if (unlikely(qp->r_rcv_len > qp->r_len)) {
573 dev->n_pkt_drops++;
574 goto done;
575 }
576 ipath_copy_sge(&qp->r_sge, data, pmtu);
577 break;
578
579 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
580 rdma_last_imm:
581 /* Get the number of bytes the message was padded by. */
582 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
583 /* Check for invalid length. */
584 /* XXX LAST len should be >= 1 */
585 if (unlikely(tlen < (hdrsize + pad + 4))) {
586 dev->n_pkt_drops++;
587 goto done;
588 }
589 /* Don't count the CRC. */
590 tlen -= (hdrsize + pad + 4);
591 if (unlikely(tlen + qp->r_rcv_len != qp->r_len)) {
592 dev->n_pkt_drops++;
593 goto done;
594 }
595 if (qp->r_reuse_sge) {
596 qp->r_reuse_sge = 0;
597 } else if (!ipath_get_rwqe(qp, 1)) {
598 dev->n_pkt_drops++;
599 goto done;
600 }
601 if (header_in_data) {
602 wc.imm_data = *(__be32 *) data;
603 data += sizeof(__be32);
604 } else {
605 /* Immediate data comes after BTH */
606 wc.imm_data = ohdr->u.imm_data;
607 }
608 hdrsize += 4;
609 wc.wc_flags = IB_WC_WITH_IMM;
610 wc.byte_len = 0;
611 goto last_imm;
612
613 case OP(RDMA_WRITE_LAST):
614 rdma_last:
615 /* Get the number of bytes the message was padded by. */
616 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
617 /* Check for invalid length. */
618 /* XXX LAST len should be >= 1 */
619 if (unlikely(tlen < (hdrsize + pad + 4))) {
620 dev->n_pkt_drops++;
621 goto done;
622 }
623 /* Don't count the CRC. */
624 tlen -= (hdrsize + pad + 4);
625 if (unlikely(tlen + qp->r_rcv_len != qp->r_len)) {
626 dev->n_pkt_drops++;
627 goto done;
628 }
629 ipath_copy_sge(&qp->r_sge, data, tlen);
630 break;
631
632 default:
633 /* Drop packet for unknown opcodes. */
634 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
635 dev->n_pkt_drops++;
636 goto bail;
637 }
638 qp->r_psn++;
639 qp->r_state = opcode;
640done:
641 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
642
643bail:
644 return;
645}
diff --git a/drivers/infiniband/hw/ipath/ipath_ud.c b/drivers/infiniband/hw/ipath/ipath_ud.c
new file mode 100644
index 000000000000..5ff3de6128b2
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_ud.c
@@ -0,0 +1,621 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/ib_smi.h>
34
35#include "ipath_verbs.h"
36#include "ips_common.h"
37
38/**
39 * ipath_ud_loopback - handle send on loopback QPs
40 * @sqp: the QP
41 * @ss: the SGE state
42 * @length: the length of the data to send
43 * @wr: the work request
44 * @wc: the work completion entry
45 *
46 * This is called from ipath_post_ud_send() to forward a WQE addressed
47 * to the same HCA.
48 */
49void ipath_ud_loopback(struct ipath_qp *sqp, struct ipath_sge_state *ss,
50 u32 length, struct ib_send_wr *wr, struct ib_wc *wc)
51{
52 struct ipath_ibdev *dev = to_idev(sqp->ibqp.device);
53 struct ipath_qp *qp;
54 struct ib_ah_attr *ah_attr;
55 unsigned long flags;
56 struct ipath_rq *rq;
57 struct ipath_srq *srq;
58 struct ipath_sge_state rsge;
59 struct ipath_sge *sge;
60 struct ipath_rwqe *wqe;
61
62 qp = ipath_lookup_qpn(&dev->qp_table, wr->wr.ud.remote_qpn);
63 if (!qp)
64 return;
65
66 /*
67 * Check that the qkey matches (except for QP0, see 9.6.1.4.1).
68 * Qkeys with the high order bit set mean use the
69 * qkey from the QP context instead of the WR (see 10.2.5).
70 */
71 if (unlikely(qp->ibqp.qp_num &&
72 ((int) wr->wr.ud.remote_qkey < 0
73 ? qp->qkey : wr->wr.ud.remote_qkey) != qp->qkey)) {
74 /* XXX OK to lose a count once in a while. */
75 dev->qkey_violations++;
76 dev->n_pkt_drops++;
77 goto done;
78 }
79
80 /*
81 * A GRH is expected to preceed the data even if not
82 * present on the wire.
83 */
84 wc->byte_len = length + sizeof(struct ib_grh);
85
86 if (wr->opcode == IB_WR_SEND_WITH_IMM) {
87 wc->wc_flags = IB_WC_WITH_IMM;
88 wc->imm_data = wr->imm_data;
89 } else {
90 wc->wc_flags = 0;
91 wc->imm_data = 0;
92 }
93
94 /*
95 * Get the next work request entry to find where to put the data.
96 * Note that it is safe to drop the lock after changing rq->tail
97 * since ipath_post_receive() won't fill the empty slot.
98 */
99 if (qp->ibqp.srq) {
100 srq = to_isrq(qp->ibqp.srq);
101 rq = &srq->rq;
102 } else {
103 srq = NULL;
104 rq = &qp->r_rq;
105 }
106 spin_lock_irqsave(&rq->lock, flags);
107 if (rq->tail == rq->head) {
108 spin_unlock_irqrestore(&rq->lock, flags);
109 dev->n_pkt_drops++;
110 goto done;
111 }
112 /* Silently drop packets which are too big. */
113 wqe = get_rwqe_ptr(rq, rq->tail);
114 if (wc->byte_len > wqe->length) {
115 spin_unlock_irqrestore(&rq->lock, flags);
116 dev->n_pkt_drops++;
117 goto done;
118 }
119 wc->wr_id = wqe->wr_id;
120 rsge.sge = wqe->sg_list[0];
121 rsge.sg_list = wqe->sg_list + 1;
122 rsge.num_sge = wqe->num_sge;
123 if (++rq->tail >= rq->size)
124 rq->tail = 0;
125 if (srq && srq->ibsrq.event_handler) {
126 u32 n;
127
128 if (rq->head < rq->tail)
129 n = rq->size + rq->head - rq->tail;
130 else
131 n = rq->head - rq->tail;
132 if (n < srq->limit) {
133 struct ib_event ev;
134
135 srq->limit = 0;
136 spin_unlock_irqrestore(&rq->lock, flags);
137 ev.device = qp->ibqp.device;
138 ev.element.srq = qp->ibqp.srq;
139 ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
140 srq->ibsrq.event_handler(&ev,
141 srq->ibsrq.srq_context);
142 } else
143 spin_unlock_irqrestore(&rq->lock, flags);
144 } else
145 spin_unlock_irqrestore(&rq->lock, flags);
146 ah_attr = &to_iah(wr->wr.ud.ah)->attr;
147 if (ah_attr->ah_flags & IB_AH_GRH) {
148 ipath_copy_sge(&rsge, &ah_attr->grh, sizeof(struct ib_grh));
149 wc->wc_flags |= IB_WC_GRH;
150 } else
151 ipath_skip_sge(&rsge, sizeof(struct ib_grh));
152 sge = &ss->sge;
153 while (length) {
154 u32 len = sge->length;
155
156 if (len > length)
157 len = length;
158 BUG_ON(len == 0);
159 ipath_copy_sge(&rsge, sge->vaddr, len);
160 sge->vaddr += len;
161 sge->length -= len;
162 sge->sge_length -= len;
163 if (sge->sge_length == 0) {
164 if (--ss->num_sge)
165 *sge = *ss->sg_list++;
166 } else if (sge->length == 0 && sge->mr != NULL) {
167 if (++sge->n >= IPATH_SEGSZ) {
168 if (++sge->m >= sge->mr->mapsz)
169 break;
170 sge->n = 0;
171 }
172 sge->vaddr =
173 sge->mr->map[sge->m]->segs[sge->n].vaddr;
174 sge->length =
175 sge->mr->map[sge->m]->segs[sge->n].length;
176 }
177 length -= len;
178 }
179 wc->status = IB_WC_SUCCESS;
180 wc->opcode = IB_WC_RECV;
181 wc->vendor_err = 0;
182 wc->qp_num = qp->ibqp.qp_num;
183 wc->src_qp = sqp->ibqp.qp_num;
184 /* XXX do we know which pkey matched? Only needed for GSI. */
185 wc->pkey_index = 0;
186 wc->slid = ipath_layer_get_lid(dev->dd) |
187 (ah_attr->src_path_bits &
188 ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1));
189 wc->sl = ah_attr->sl;
190 wc->dlid_path_bits =
191 ah_attr->dlid & ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
192 /* Signal completion event if the solicited bit is set. */
193 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), wc,
194 wr->send_flags & IB_SEND_SOLICITED);
195
196done:
197 if (atomic_dec_and_test(&qp->refcount))
198 wake_up(&qp->wait);
199}
200
201/**
202 * ipath_post_ud_send - post a UD send on QP
203 * @qp: the QP
204 * @wr: the work request
205 *
206 * Note that we actually send the data as it is posted instead of putting
207 * the request into a ring buffer. If we wanted to use a ring buffer,
208 * we would need to save a reference to the destination address in the SWQE.
209 */
210int ipath_post_ud_send(struct ipath_qp *qp, struct ib_send_wr *wr)
211{
212 struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
213 struct ipath_other_headers *ohdr;
214 struct ib_ah_attr *ah_attr;
215 struct ipath_sge_state ss;
216 struct ipath_sge *sg_list;
217 struct ib_wc wc;
218 u32 hwords;
219 u32 nwords;
220 u32 len;
221 u32 extra_bytes;
222 u32 bth0;
223 u16 lrh0;
224 u16 lid;
225 int i;
226 int ret;
227
228 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK)) {
229 ret = 0;
230 goto bail;
231 }
232
233 /* IB spec says that num_sge == 0 is OK. */
234 if (wr->num_sge > qp->s_max_sge) {
235 ret = -EINVAL;
236 goto bail;
237 }
238
239 if (wr->num_sge > 1) {
240 sg_list = kmalloc((qp->s_max_sge - 1) * sizeof(*sg_list),
241 GFP_ATOMIC);
242 if (!sg_list) {
243 ret = -ENOMEM;
244 goto bail;
245 }
246 } else
247 sg_list = NULL;
248
249 /* Check the buffer to send. */
250 ss.sg_list = sg_list;
251 ss.sge.mr = NULL;
252 ss.sge.vaddr = NULL;
253 ss.sge.length = 0;
254 ss.sge.sge_length = 0;
255 ss.num_sge = 0;
256 len = 0;
257 for (i = 0; i < wr->num_sge; i++) {
258 /* Check LKEY */
259 if (to_ipd(qp->ibqp.pd)->user && wr->sg_list[i].lkey == 0) {
260 ret = -EINVAL;
261 goto bail;
262 }
263
264 if (wr->sg_list[i].length == 0)
265 continue;
266 if (!ipath_lkey_ok(&dev->lk_table, ss.num_sge ?
267 sg_list + ss.num_sge - 1 : &ss.sge,
268 &wr->sg_list[i], 0)) {
269 ret = -EINVAL;
270 goto bail;
271 }
272 len += wr->sg_list[i].length;
273 ss.num_sge++;
274 }
275 extra_bytes = (4 - len) & 3;
276 nwords = (len + extra_bytes) >> 2;
277
278 /* Construct the header. */
279 ah_attr = &to_iah(wr->wr.ud.ah)->attr;
280 if (ah_attr->dlid == 0) {
281 ret = -EINVAL;
282 goto bail;
283 }
284 if (ah_attr->dlid >= IPS_MULTICAST_LID_BASE) {
285 if (ah_attr->dlid != IPS_PERMISSIVE_LID)
286 dev->n_multicast_xmit++;
287 else
288 dev->n_unicast_xmit++;
289 } else {
290 dev->n_unicast_xmit++;
291 lid = ah_attr->dlid &
292 ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
293 if (unlikely(lid == ipath_layer_get_lid(dev->dd))) {
294 /*
295 * Pass in an uninitialized ib_wc to save stack
296 * space.
297 */
298 ipath_ud_loopback(qp, &ss, len, wr, &wc);
299 goto done;
300 }
301 }
302 if (ah_attr->ah_flags & IB_AH_GRH) {
303 /* Header size in 32-bit words. */
304 hwords = 17;
305 lrh0 = IPS_LRH_GRH;
306 ohdr = &qp->s_hdr.u.l.oth;
307 qp->s_hdr.u.l.grh.version_tclass_flow =
308 cpu_to_be32((6 << 28) |
309 (ah_attr->grh.traffic_class << 20) |
310 ah_attr->grh.flow_label);
311 qp->s_hdr.u.l.grh.paylen =
312 cpu_to_be16(((wr->opcode ==
313 IB_WR_SEND_WITH_IMM ? 6 : 5) +
314 nwords + SIZE_OF_CRC) << 2);
315 /* next_hdr is defined by C8-7 in ch. 8.4.1 */
316 qp->s_hdr.u.l.grh.next_hdr = 0x1B;
317 qp->s_hdr.u.l.grh.hop_limit = ah_attr->grh.hop_limit;
318 /* The SGID is 32-bit aligned. */
319 qp->s_hdr.u.l.grh.sgid.global.subnet_prefix =
320 dev->gid_prefix;
321 qp->s_hdr.u.l.grh.sgid.global.interface_id =
322 ipath_layer_get_guid(dev->dd);
323 qp->s_hdr.u.l.grh.dgid = ah_attr->grh.dgid;
324 /*
325 * Don't worry about sending to locally attached multicast
326 * QPs. It is unspecified by the spec. what happens.
327 */
328 } else {
329 /* Header size in 32-bit words. */
330 hwords = 7;
331 lrh0 = IPS_LRH_BTH;
332 ohdr = &qp->s_hdr.u.oth;
333 }
334 if (wr->opcode == IB_WR_SEND_WITH_IMM) {
335 ohdr->u.ud.imm_data = wr->imm_data;
336 wc.imm_data = wr->imm_data;
337 hwords += 1;
338 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
339 } else if (wr->opcode == IB_WR_SEND) {
340 wc.imm_data = 0;
341 bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
342 } else {
343 ret = -EINVAL;
344 goto bail;
345 }
346 lrh0 |= ah_attr->sl << 4;
347 if (qp->ibqp.qp_type == IB_QPT_SMI)
348 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
349 qp->s_hdr.lrh[0] = cpu_to_be16(lrh0);
350 qp->s_hdr.lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */
351 qp->s_hdr.lrh[2] = cpu_to_be16(hwords + nwords + SIZE_OF_CRC);
352 lid = ipath_layer_get_lid(dev->dd);
353 if (lid) {
354 lid |= ah_attr->src_path_bits &
355 ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
356 qp->s_hdr.lrh[3] = cpu_to_be16(lid);
357 } else
358 qp->s_hdr.lrh[3] = IB_LID_PERMISSIVE;
359 if (wr->send_flags & IB_SEND_SOLICITED)
360 bth0 |= 1 << 23;
361 bth0 |= extra_bytes << 20;
362 bth0 |= qp->ibqp.qp_type == IB_QPT_SMI ? IPS_DEFAULT_P_KEY :
363 ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
364 ohdr->bth[0] = cpu_to_be32(bth0);
365 /*
366 * Use the multicast QP if the destination LID is a multicast LID.
367 */
368 ohdr->bth[1] = ah_attr->dlid >= IPS_MULTICAST_LID_BASE &&
369 ah_attr->dlid != IPS_PERMISSIVE_LID ?
370 __constant_cpu_to_be32(IPS_MULTICAST_QPN) :
371 cpu_to_be32(wr->wr.ud.remote_qpn);
372 /* XXX Could lose a PSN count but not worth locking */
373 ohdr->bth[2] = cpu_to_be32(qp->s_next_psn++ & IPS_PSN_MASK);
374 /*
375 * Qkeys with the high order bit set mean use the
376 * qkey from the QP context instead of the WR (see 10.2.5).
377 */
378 ohdr->u.ud.deth[0] = cpu_to_be32((int)wr->wr.ud.remote_qkey < 0 ?
379 qp->qkey : wr->wr.ud.remote_qkey);
380 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
381 if (ipath_verbs_send(dev->dd, hwords, (u32 *) &qp->s_hdr,
382 len, &ss))
383 dev->n_no_piobuf++;
384
385done:
386 /* Queue the completion status entry. */
387 if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) ||
388 (wr->send_flags & IB_SEND_SIGNALED)) {
389 wc.wr_id = wr->wr_id;
390 wc.status = IB_WC_SUCCESS;
391 wc.vendor_err = 0;
392 wc.opcode = IB_WC_SEND;
393 wc.byte_len = len;
394 wc.qp_num = qp->ibqp.qp_num;
395 wc.src_qp = 0;
396 wc.wc_flags = 0;
397 /* XXX initialize other fields? */
398 ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0);
399 }
400 kfree(sg_list);
401
402 ret = 0;
403
404bail:
405 return ret;
406}
407
408/**
409 * ipath_ud_rcv - receive an incoming UD packet
410 * @dev: the device the packet came in on
411 * @hdr: the packet header
412 * @has_grh: true if the packet has a GRH
413 * @data: the packet data
414 * @tlen: the packet length
415 * @qp: the QP the packet came on
416 *
417 * This is called from ipath_qp_rcv() to process an incoming UD packet
418 * for the given QP.
419 * Called at interrupt level.
420 */
421void ipath_ud_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
422 int has_grh, void *data, u32 tlen, struct ipath_qp *qp)
423{
424 struct ipath_other_headers *ohdr;
425 int opcode;
426 u32 hdrsize;
427 u32 pad;
428 unsigned long flags;
429 struct ib_wc wc;
430 u32 qkey;
431 u32 src_qp;
432 struct ipath_rq *rq;
433 struct ipath_srq *srq;
434 struct ipath_rwqe *wqe;
435 u16 dlid;
436 int header_in_data;
437
438 /* Check for GRH */
439 if (!has_grh) {
440 ohdr = &hdr->u.oth;
441 hdrsize = 8 + 12 + 8; /* LRH + BTH + DETH */
442 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
443 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]);
444 header_in_data = 0;
445 } else {
446 ohdr = &hdr->u.l.oth;
447 hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */
448 /*
449 * The header with GRH is 68 bytes and the core driver sets
450 * the eager header buffer size to 56 bytes so the last 12
451 * bytes of the IB header is in the data buffer.
452 */
453 header_in_data =
454 ipath_layer_get_rcvhdrentsize(dev->dd) == 16;
455 if (header_in_data) {
456 qkey = be32_to_cpu(((__be32 *) data)[1]);
457 src_qp = be32_to_cpu(((__be32 *) data)[2]);
458 data += 12;
459 } else {
460 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
461 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]);
462 }
463 }
464 src_qp &= IPS_QPN_MASK;
465
466 /*
467 * Check that the permissive LID is only used on QP0
468 * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
469 */
470 if (qp->ibqp.qp_num) {
471 if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
472 hdr->lrh[3] == IB_LID_PERMISSIVE)) {
473 dev->n_pkt_drops++;
474 goto bail;
475 }
476 if (unlikely(qkey != qp->qkey)) {
477 /* XXX OK to lose a count once in a while. */
478 dev->qkey_violations++;
479 dev->n_pkt_drops++;
480 goto bail;
481 }
482 } else if (hdr->lrh[1] == IB_LID_PERMISSIVE ||
483 hdr->lrh[3] == IB_LID_PERMISSIVE) {
484 struct ib_smp *smp = (struct ib_smp *) data;
485
486 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
487 dev->n_pkt_drops++;
488 goto bail;
489 }
490 }
491
492 /* Get the number of bytes the message was padded by. */
493 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
494 if (unlikely(tlen < (hdrsize + pad + 4))) {
495 /* Drop incomplete packets. */
496 dev->n_pkt_drops++;
497 goto bail;
498 }
499 tlen -= hdrsize + pad + 4;
500
501 /* Drop invalid MAD packets (see 13.5.3.1). */
502 if (unlikely((qp->ibqp.qp_num == 0 &&
503 (tlen != 256 ||
504 (be16_to_cpu(hdr->lrh[0]) >> 12) != 15)) ||
505 (qp->ibqp.qp_num == 1 &&
506 (tlen != 256 ||
507 (be16_to_cpu(hdr->lrh[0]) >> 12) == 15)))) {
508 dev->n_pkt_drops++;
509 goto bail;
510 }
511
512 /*
513 * A GRH is expected to preceed the data even if not
514 * present on the wire.
515 */
516 wc.byte_len = tlen + sizeof(struct ib_grh);
517
518 /*
519 * The opcode is in the low byte when its in network order
520 * (top byte when in host order).
521 */
522 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
523 if (qp->ibqp.qp_num > 1 &&
524 opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
525 if (header_in_data) {
526 wc.imm_data = *(__be32 *) data;
527 data += sizeof(__be32);
528 } else
529 wc.imm_data = ohdr->u.ud.imm_data;
530 wc.wc_flags = IB_WC_WITH_IMM;
531 hdrsize += sizeof(u32);
532 } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
533 wc.imm_data = 0;
534 wc.wc_flags = 0;
535 } else {
536 dev->n_pkt_drops++;
537 goto bail;
538 }
539
540 /*
541 * Get the next work request entry to find where to put the data.
542 * Note that it is safe to drop the lock after changing rq->tail
543 * since ipath_post_receive() won't fill the empty slot.
544 */
545 if (qp->ibqp.srq) {
546 srq = to_isrq(qp->ibqp.srq);
547 rq = &srq->rq;
548 } else {
549 srq = NULL;
550 rq = &qp->r_rq;
551 }
552 spin_lock_irqsave(&rq->lock, flags);
553 if (rq->tail == rq->head) {
554 spin_unlock_irqrestore(&rq->lock, flags);
555 dev->n_pkt_drops++;
556 goto bail;
557 }
558 /* Silently drop packets which are too big. */
559 wqe = get_rwqe_ptr(rq, rq->tail);
560 if (wc.byte_len > wqe->length) {
561 spin_unlock_irqrestore(&rq->lock, flags);
562 dev->n_pkt_drops++;
563 goto bail;
564 }
565 wc.wr_id = wqe->wr_id;
566 qp->r_sge.sge = wqe->sg_list[0];
567 qp->r_sge.sg_list = wqe->sg_list + 1;
568 qp->r_sge.num_sge = wqe->num_sge;
569 if (++rq->tail >= rq->size)
570 rq->tail = 0;
571 if (srq && srq->ibsrq.event_handler) {
572 u32 n;
573
574 if (rq->head < rq->tail)
575 n = rq->size + rq->head - rq->tail;
576 else
577 n = rq->head - rq->tail;
578 if (n < srq->limit) {
579 struct ib_event ev;
580
581 srq->limit = 0;
582 spin_unlock_irqrestore(&rq->lock, flags);
583 ev.device = qp->ibqp.device;
584 ev.element.srq = qp->ibqp.srq;
585 ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
586 srq->ibsrq.event_handler(&ev,
587 srq->ibsrq.srq_context);
588 } else
589 spin_unlock_irqrestore(&rq->lock, flags);
590 } else
591 spin_unlock_irqrestore(&rq->lock, flags);
592 if (has_grh) {
593 ipath_copy_sge(&qp->r_sge, &hdr->u.l.grh,
594 sizeof(struct ib_grh));
595 wc.wc_flags |= IB_WC_GRH;
596 } else
597 ipath_skip_sge(&qp->r_sge, sizeof(struct ib_grh));
598 ipath_copy_sge(&qp->r_sge, data,
599 wc.byte_len - sizeof(struct ib_grh));
600 wc.status = IB_WC_SUCCESS;
601 wc.opcode = IB_WC_RECV;
602 wc.vendor_err = 0;
603 wc.qp_num = qp->ibqp.qp_num;
604 wc.src_qp = src_qp;
605 /* XXX do we know which pkey matched? Only needed for GSI. */
606 wc.pkey_index = 0;
607 wc.slid = be16_to_cpu(hdr->lrh[3]);
608 wc.sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF;
609 dlid = be16_to_cpu(hdr->lrh[1]);
610 /*
611 * Save the LMC lower bits if the destination LID is a unicast LID.
612 */
613 wc.dlid_path_bits = dlid >= IPS_MULTICAST_LID_BASE ? 0 :
614 dlid & ((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
615 /* Signal completion event if the solicited bit is set. */
616 ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
617 (ohdr->bth[0] &
618 __constant_cpu_to_be32(1 << 23)) != 0);
619
620bail:;
621}
diff --git a/drivers/infiniband/hw/ipath/ipath_user_pages.c b/drivers/infiniband/hw/ipath/ipath_user_pages.c
new file mode 100644
index 000000000000..2bb08afc86d0
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_user_pages.c
@@ -0,0 +1,207 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/mm.h>
34#include <linux/device.h>
35
36#include "ipath_kernel.h"
37
38static void __ipath_release_user_pages(struct page **p, size_t num_pages,
39 int dirty)
40{
41 size_t i;
42
43 for (i = 0; i < num_pages; i++) {
44 ipath_cdbg(MM, "%lu/%lu put_page %p\n", (unsigned long) i,
45 (unsigned long) num_pages, p[i]);
46 if (dirty)
47 set_page_dirty_lock(p[i]);
48 put_page(p[i]);
49 }
50}
51
52/* call with current->mm->mmap_sem held */
53static int __get_user_pages(unsigned long start_page, size_t num_pages,
54 struct page **p, struct vm_area_struct **vma)
55{
56 unsigned long lock_limit;
57 size_t got;
58 int ret;
59
60#if 0
61 /*
62 * XXX - causes MPI programs to fail, haven't had time to check
63 * yet
64 */
65 if (!capable(CAP_IPC_LOCK)) {
66 ret = -EPERM;
67 goto bail;
68 }
69#endif
70
71 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
72 PAGE_SHIFT;
73
74 if (num_pages > lock_limit) {
75 ret = -ENOMEM;
76 goto bail;
77 }
78
79 ipath_cdbg(VERBOSE, "pin %lx pages from vaddr %lx\n",
80 (unsigned long) num_pages, start_page);
81
82 for (got = 0; got < num_pages; got += ret) {
83 ret = get_user_pages(current, current->mm,
84 start_page + got * PAGE_SIZE,
85 num_pages - got, 1, 1,
86 p + got, vma);
87 if (ret < 0)
88 goto bail_release;
89 }
90
91 current->mm->locked_vm += num_pages;
92
93 ret = 0;
94 goto bail;
95
96bail_release:
97 __ipath_release_user_pages(p, got, 0);
98bail:
99 return ret;
100}
101
102/**
103 * ipath_get_user_pages - lock user pages into memory
104 * @start_page: the start page
105 * @num_pages: the number of pages
106 * @p: the output page structures
107 *
108 * This function takes a given start page (page aligned user virtual
109 * address) and pins it and the following specified number of pages. For
110 * now, num_pages is always 1, but that will probably change at some point
111 * (because caller is doing expected sends on a single virtually contiguous
112 * buffer, so we can do all pages at once).
113 */
114int ipath_get_user_pages(unsigned long start_page, size_t num_pages,
115 struct page **p)
116{
117 int ret;
118
119 down_write(&current->mm->mmap_sem);
120
121 ret = __get_user_pages(start_page, num_pages, p, NULL);
122
123 up_write(&current->mm->mmap_sem);
124
125 return ret;
126}
127
128/**
129 * ipath_get_user_pages_nocopy - lock a single page for I/O and mark shared
130 * @start_page: the page to lock
131 * @p: the output page structure
132 *
133 * This is similar to ipath_get_user_pages, but it's always one page, and we
134 * mark the page as locked for I/O, and shared. This is used for the user
135 * process page that contains the destination address for the rcvhdrq tail
136 * update, so we need to have the vma. If we don't do this, the page can be
137 * taken away from us on fork, even if the child never touches it, and then
138 * the user process never sees the tail register updates.
139 */
140int ipath_get_user_pages_nocopy(unsigned long page, struct page **p)
141{
142 struct vm_area_struct *vma;
143 int ret;
144
145 down_write(&current->mm->mmap_sem);
146
147 ret = __get_user_pages(page, 1, p, &vma);
148
149 up_write(&current->mm->mmap_sem);
150
151 return ret;
152}
153
154void ipath_release_user_pages(struct page **p, size_t num_pages)
155{
156 down_write(&current->mm->mmap_sem);
157
158 __ipath_release_user_pages(p, num_pages, 1);
159
160 current->mm->locked_vm -= num_pages;
161
162 up_write(&current->mm->mmap_sem);
163}
164
165struct ipath_user_pages_work {
166 struct work_struct work;
167 struct mm_struct *mm;
168 unsigned long num_pages;
169};
170
171static void user_pages_account(void *ptr)
172{
173 struct ipath_user_pages_work *work = ptr;
174
175 down_write(&work->mm->mmap_sem);
176 work->mm->locked_vm -= work->num_pages;
177 up_write(&work->mm->mmap_sem);
178 mmput(work->mm);
179 kfree(work);
180}
181
182void ipath_release_user_pages_on_close(struct page **p, size_t num_pages)
183{
184 struct ipath_user_pages_work *work;
185 struct mm_struct *mm;
186
187 __ipath_release_user_pages(p, num_pages, 1);
188
189 mm = get_task_mm(current);
190 if (!mm)
191 goto bail;
192
193 work = kmalloc(sizeof(*work), GFP_KERNEL);
194 if (!work)
195 goto bail_mm;
196
197 goto bail;
198
199 INIT_WORK(&work->work, user_pages_account, work);
200 work->mm = mm;
201 work->num_pages = num_pages;
202
203bail_mm:
204 mmput(mm);
205bail:
206 return;
207}
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
new file mode 100644
index 000000000000..9f27fd35cdbb
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -0,0 +1,1222 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/ib_mad.h>
34#include <rdma/ib_user_verbs.h>
35#include <linux/utsname.h>
36
37#include "ipath_kernel.h"
38#include "ipath_verbs.h"
39#include "ips_common.h"
40
41/* Not static, because we don't want the compiler removing it */
42const char ipath_verbs_version[] = "ipath_verbs " IPATH_IDSTR;
43
44unsigned int ib_ipath_qp_table_size = 251;
45module_param_named(qp_table_size, ib_ipath_qp_table_size, uint, S_IRUGO);
46MODULE_PARM_DESC(qp_table_size, "QP table size");
47
48unsigned int ib_ipath_lkey_table_size = 12;
49module_param_named(lkey_table_size, ib_ipath_lkey_table_size, uint,
50 S_IRUGO);
51MODULE_PARM_DESC(lkey_table_size,
52 "LKEY table size in bits (2^n, 1 <= n <= 23)");
53
54unsigned int ib_ipath_debug; /* debug mask */
55module_param_named(debug, ib_ipath_debug, uint, S_IWUSR | S_IRUGO);
56MODULE_PARM_DESC(debug, "Verbs debug mask");
57
58MODULE_LICENSE("GPL");
59MODULE_AUTHOR("PathScale <support@pathscale.com>");
60MODULE_DESCRIPTION("Pathscale InfiniPath driver");
61
62const int ib_ipath_state_ops[IB_QPS_ERR + 1] = {
63 [IB_QPS_RESET] = 0,
64 [IB_QPS_INIT] = IPATH_POST_RECV_OK,
65 [IB_QPS_RTR] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
66 [IB_QPS_RTS] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
67 IPATH_POST_SEND_OK | IPATH_PROCESS_SEND_OK,
68 [IB_QPS_SQD] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK |
69 IPATH_POST_SEND_OK,
70 [IB_QPS_SQE] = IPATH_POST_RECV_OK | IPATH_PROCESS_RECV_OK,
71 [IB_QPS_ERR] = 0,
72};
73
74/*
75 * Translate ib_wr_opcode into ib_wc_opcode.
76 */
77const enum ib_wc_opcode ib_ipath_wc_opcode[] = {
78 [IB_WR_RDMA_WRITE] = IB_WC_RDMA_WRITE,
79 [IB_WR_RDMA_WRITE_WITH_IMM] = IB_WC_RDMA_WRITE,
80 [IB_WR_SEND] = IB_WC_SEND,
81 [IB_WR_SEND_WITH_IMM] = IB_WC_SEND,
82 [IB_WR_RDMA_READ] = IB_WC_RDMA_READ,
83 [IB_WR_ATOMIC_CMP_AND_SWP] = IB_WC_COMP_SWAP,
84 [IB_WR_ATOMIC_FETCH_AND_ADD] = IB_WC_FETCH_ADD
85};
86
87/*
88 * System image GUID.
89 */
90__be64 sys_image_guid;
91
92/**
93 * ipath_copy_sge - copy data to SGE memory
94 * @ss: the SGE state
95 * @data: the data to copy
96 * @length: the length of the data
97 */
98void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length)
99{
100 struct ipath_sge *sge = &ss->sge;
101
102 while (length) {
103 u32 len = sge->length;
104
105 BUG_ON(len == 0);
106 if (len > length)
107 len = length;
108 memcpy(sge->vaddr, data, len);
109 sge->vaddr += len;
110 sge->length -= len;
111 sge->sge_length -= len;
112 if (sge->sge_length == 0) {
113 if (--ss->num_sge)
114 *sge = *ss->sg_list++;
115 } else if (sge->length == 0 && sge->mr != NULL) {
116 if (++sge->n >= IPATH_SEGSZ) {
117 if (++sge->m >= sge->mr->mapsz)
118 break;
119 sge->n = 0;
120 }
121 sge->vaddr =
122 sge->mr->map[sge->m]->segs[sge->n].vaddr;
123 sge->length =
124 sge->mr->map[sge->m]->segs[sge->n].length;
125 }
126 data += len;
127 length -= len;
128 }
129}
130
131/**
132 * ipath_skip_sge - skip over SGE memory - XXX almost dup of prev func
133 * @ss: the SGE state
134 * @length: the number of bytes to skip
135 */
136void ipath_skip_sge(struct ipath_sge_state *ss, u32 length)
137{
138 struct ipath_sge *sge = &ss->sge;
139
140 while (length > sge->sge_length) {
141 length -= sge->sge_length;
142 ss->sge = *ss->sg_list++;
143 }
144 while (length) {
145 u32 len = sge->length;
146
147 BUG_ON(len == 0);
148 if (len > length)
149 len = length;
150 sge->vaddr += len;
151 sge->length -= len;
152 sge->sge_length -= len;
153 if (sge->sge_length == 0) {
154 if (--ss->num_sge)
155 *sge = *ss->sg_list++;
156 } else if (sge->length == 0 && sge->mr != NULL) {
157 if (++sge->n >= IPATH_SEGSZ) {
158 if (++sge->m >= sge->mr->mapsz)
159 break;
160 sge->n = 0;
161 }
162 sge->vaddr =
163 sge->mr->map[sge->m]->segs[sge->n].vaddr;
164 sge->length =
165 sge->mr->map[sge->m]->segs[sge->n].length;
166 }
167 length -= len;
168 }
169}
170
171/**
172 * ipath_post_send - post a send on a QP
173 * @ibqp: the QP to post the send on
174 * @wr: the list of work requests to post
175 * @bad_wr: the first bad WR is put here
176 *
177 * This may be called from interrupt context.
178 */
179static int ipath_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
180 struct ib_send_wr **bad_wr)
181{
182 struct ipath_qp *qp = to_iqp(ibqp);
183 int err = 0;
184
185 /* Check that state is OK to post send. */
186 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_SEND_OK)) {
187 *bad_wr = wr;
188 err = -EINVAL;
189 goto bail;
190 }
191
192 for (; wr; wr = wr->next) {
193 switch (qp->ibqp.qp_type) {
194 case IB_QPT_UC:
195 case IB_QPT_RC:
196 err = ipath_post_rc_send(qp, wr);
197 break;
198
199 case IB_QPT_SMI:
200 case IB_QPT_GSI:
201 case IB_QPT_UD:
202 err = ipath_post_ud_send(qp, wr);
203 break;
204
205 default:
206 err = -EINVAL;
207 }
208 if (err) {
209 *bad_wr = wr;
210 break;
211 }
212 }
213
214bail:
215 return err;
216}
217
218/**
219 * ipath_post_receive - post a receive on a QP
220 * @ibqp: the QP to post the receive on
221 * @wr: the WR to post
222 * @bad_wr: the first bad WR is put here
223 *
224 * This may be called from interrupt context.
225 */
226static int ipath_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
227 struct ib_recv_wr **bad_wr)
228{
229 struct ipath_qp *qp = to_iqp(ibqp);
230 unsigned long flags;
231 int ret;
232
233 /* Check that state is OK to post receive. */
234 if (!(ib_ipath_state_ops[qp->state] & IPATH_POST_RECV_OK)) {
235 *bad_wr = wr;
236 ret = -EINVAL;
237 goto bail;
238 }
239
240 for (; wr; wr = wr->next) {
241 struct ipath_rwqe *wqe;
242 u32 next;
243 int i, j;
244
245 if (wr->num_sge > qp->r_rq.max_sge) {
246 *bad_wr = wr;
247 ret = -ENOMEM;
248 goto bail;
249 }
250
251 spin_lock_irqsave(&qp->r_rq.lock, flags);
252 next = qp->r_rq.head + 1;
253 if (next >= qp->r_rq.size)
254 next = 0;
255 if (next == qp->r_rq.tail) {
256 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
257 *bad_wr = wr;
258 ret = -ENOMEM;
259 goto bail;
260 }
261
262 wqe = get_rwqe_ptr(&qp->r_rq, qp->r_rq.head);
263 wqe->wr_id = wr->wr_id;
264 wqe->sg_list[0].mr = NULL;
265 wqe->sg_list[0].vaddr = NULL;
266 wqe->sg_list[0].length = 0;
267 wqe->sg_list[0].sge_length = 0;
268 wqe->length = 0;
269 for (i = 0, j = 0; i < wr->num_sge; i++) {
270 /* Check LKEY */
271 if (to_ipd(qp->ibqp.pd)->user &&
272 wr->sg_list[i].lkey == 0) {
273 spin_unlock_irqrestore(&qp->r_rq.lock,
274 flags);
275 *bad_wr = wr;
276 ret = -EINVAL;
277 goto bail;
278 }
279 if (wr->sg_list[i].length == 0)
280 continue;
281 if (!ipath_lkey_ok(
282 &to_idev(qp->ibqp.device)->lk_table,
283 &wqe->sg_list[j], &wr->sg_list[i],
284 IB_ACCESS_LOCAL_WRITE)) {
285 spin_unlock_irqrestore(&qp->r_rq.lock,
286 flags);
287 *bad_wr = wr;
288 ret = -EINVAL;
289 goto bail;
290 }
291 wqe->length += wr->sg_list[i].length;
292 j++;
293 }
294 wqe->num_sge = j;
295 qp->r_rq.head = next;
296 spin_unlock_irqrestore(&qp->r_rq.lock, flags);
297 }
298 ret = 0;
299
300bail:
301 return ret;
302}
303
304/**
305 * ipath_qp_rcv - processing an incoming packet on a QP
306 * @dev: the device the packet came on
307 * @hdr: the packet header
308 * @has_grh: true if the packet has a GRH
309 * @data: the packet data
310 * @tlen: the packet length
311 * @qp: the QP the packet came on
312 *
313 * This is called from ipath_ib_rcv() to process an incoming packet
314 * for the given QP.
315 * Called at interrupt level.
316 */
317static void ipath_qp_rcv(struct ipath_ibdev *dev,
318 struct ipath_ib_header *hdr, int has_grh,
319 void *data, u32 tlen, struct ipath_qp *qp)
320{
321 /* Check for valid receive state. */
322 if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_RECV_OK)) {
323 dev->n_pkt_drops++;
324 return;
325 }
326
327 switch (qp->ibqp.qp_type) {
328 case IB_QPT_SMI:
329 case IB_QPT_GSI:
330 case IB_QPT_UD:
331 ipath_ud_rcv(dev, hdr, has_grh, data, tlen, qp);
332 break;
333
334 case IB_QPT_RC:
335 ipath_rc_rcv(dev, hdr, has_grh, data, tlen, qp);
336 break;
337
338 case IB_QPT_UC:
339 ipath_uc_rcv(dev, hdr, has_grh, data, tlen, qp);
340 break;
341
342 default:
343 break;
344 }
345}
346
347/**
348 * ipath_ib_rcv - process and incoming packet
349 * @arg: the device pointer
350 * @rhdr: the header of the packet
351 * @data: the packet data
352 * @tlen: the packet length
353 *
354 * This is called from ipath_kreceive() to process an incoming packet at
355 * interrupt level. Tlen is the length of the header + data + CRC in bytes.
356 */
357static void ipath_ib_rcv(void *arg, void *rhdr, void *data, u32 tlen)
358{
359 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
360 struct ipath_ib_header *hdr = rhdr;
361 struct ipath_other_headers *ohdr;
362 struct ipath_qp *qp;
363 u32 qp_num;
364 int lnh;
365 u8 opcode;
366 u16 lid;
367
368 if (unlikely(dev == NULL))
369 goto bail;
370
371 if (unlikely(tlen < 24)) { /* LRH+BTH+CRC */
372 dev->rcv_errors++;
373 goto bail;
374 }
375
376 /* Check for a valid destination LID (see ch. 7.11.1). */
377 lid = be16_to_cpu(hdr->lrh[1]);
378 if (lid < IPS_MULTICAST_LID_BASE) {
379 lid &= ~((1 << (dev->mkeyprot_resv_lmc & 7)) - 1);
380 if (unlikely(lid != ipath_layer_get_lid(dev->dd))) {
381 dev->rcv_errors++;
382 goto bail;
383 }
384 }
385
386 /* Check for GRH */
387 lnh = be16_to_cpu(hdr->lrh[0]) & 3;
388 if (lnh == IPS_LRH_BTH)
389 ohdr = &hdr->u.oth;
390 else if (lnh == IPS_LRH_GRH)
391 ohdr = &hdr->u.l.oth;
392 else {
393 dev->rcv_errors++;
394 goto bail;
395 }
396
397 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
398 dev->opstats[opcode].n_bytes += tlen;
399 dev->opstats[opcode].n_packets++;
400
401 /* Get the destination QP number. */
402 qp_num = be32_to_cpu(ohdr->bth[1]) & IPS_QPN_MASK;
403 if (qp_num == IPS_MULTICAST_QPN) {
404 struct ipath_mcast *mcast;
405 struct ipath_mcast_qp *p;
406
407 mcast = ipath_mcast_find(&hdr->u.l.grh.dgid);
408 if (mcast == NULL) {
409 dev->n_pkt_drops++;
410 goto bail;
411 }
412 dev->n_multicast_rcv++;
413 list_for_each_entry_rcu(p, &mcast->qp_list, list)
414 ipath_qp_rcv(dev, hdr, lnh == IPS_LRH_GRH, data,
415 tlen, p->qp);
416 /*
417 * Notify ipath_multicast_detach() if it is waiting for us
418 * to finish.
419 */
420 if (atomic_dec_return(&mcast->refcount) <= 1)
421 wake_up(&mcast->wait);
422 } else {
423 qp = ipath_lookup_qpn(&dev->qp_table, qp_num);
424 if (qp) {
425 dev->n_unicast_rcv++;
426 ipath_qp_rcv(dev, hdr, lnh == IPS_LRH_GRH, data,
427 tlen, qp);
428 /*
429 * Notify ipath_destroy_qp() if it is waiting
430 * for us to finish.
431 */
432 if (atomic_dec_and_test(&qp->refcount))
433 wake_up(&qp->wait);
434 } else
435 dev->n_pkt_drops++;
436 }
437
438bail:;
439}
440
441/**
442 * ipath_ib_timer - verbs timer
443 * @arg: the device pointer
444 *
445 * This is called from ipath_do_rcv_timer() at interrupt level to check for
446 * QPs which need retransmits and to collect performance numbers.
447 */
448static void ipath_ib_timer(void *arg)
449{
450 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
451 struct ipath_qp *resend = NULL;
452 struct ipath_qp *rnr = NULL;
453 struct list_head *last;
454 struct ipath_qp *qp;
455 unsigned long flags;
456
457 if (dev == NULL)
458 return;
459
460 spin_lock_irqsave(&dev->pending_lock, flags);
461 /* Start filling the next pending queue. */
462 if (++dev->pending_index >= ARRAY_SIZE(dev->pending))
463 dev->pending_index = 0;
464 /* Save any requests still in the new queue, they have timed out. */
465 last = &dev->pending[dev->pending_index];
466 while (!list_empty(last)) {
467 qp = list_entry(last->next, struct ipath_qp, timerwait);
468 if (last->next == LIST_POISON1 ||
469 last->next != &qp->timerwait ||
470 qp->timerwait.prev != last) {
471 INIT_LIST_HEAD(last);
472 } else {
473 list_del(&qp->timerwait);
474 qp->timerwait.prev = (struct list_head *) resend;
475 resend = qp;
476 atomic_inc(&qp->refcount);
477 }
478 }
479 last = &dev->rnrwait;
480 if (!list_empty(last)) {
481 qp = list_entry(last->next, struct ipath_qp, timerwait);
482 if (--qp->s_rnr_timeout == 0) {
483 do {
484 if (last->next == LIST_POISON1 ||
485 last->next != &qp->timerwait ||
486 qp->timerwait.prev != last) {
487 INIT_LIST_HEAD(last);
488 break;
489 }
490 list_del(&qp->timerwait);
491 qp->timerwait.prev =
492 (struct list_head *) rnr;
493 rnr = qp;
494 if (list_empty(last))
495 break;
496 qp = list_entry(last->next, struct ipath_qp,
497 timerwait);
498 } while (qp->s_rnr_timeout == 0);
499 }
500 }
501 /*
502 * We should only be in the started state if pma_sample_start != 0
503 */
504 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_STARTED &&
505 --dev->pma_sample_start == 0) {
506 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_RUNNING;
507 ipath_layer_snapshot_counters(dev->dd, &dev->ipath_sword,
508 &dev->ipath_rword,
509 &dev->ipath_spkts,
510 &dev->ipath_rpkts,
511 &dev->ipath_xmit_wait);
512 }
513 if (dev->pma_sample_status == IB_PMA_SAMPLE_STATUS_RUNNING) {
514 if (dev->pma_sample_interval == 0) {
515 u64 ta, tb, tc, td, te;
516
517 dev->pma_sample_status = IB_PMA_SAMPLE_STATUS_DONE;
518 ipath_layer_snapshot_counters(dev->dd, &ta, &tb,
519 &tc, &td, &te);
520
521 dev->ipath_sword = ta - dev->ipath_sword;
522 dev->ipath_rword = tb - dev->ipath_rword;
523 dev->ipath_spkts = tc - dev->ipath_spkts;
524 dev->ipath_rpkts = td - dev->ipath_rpkts;
525 dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
526 }
527 else
528 dev->pma_sample_interval--;
529 }
530 spin_unlock_irqrestore(&dev->pending_lock, flags);
531
532 /* XXX What if timer fires again while this is running? */
533 for (qp = resend; qp != NULL;
534 qp = (struct ipath_qp *) qp->timerwait.prev) {
535 struct ib_wc wc;
536
537 spin_lock_irqsave(&qp->s_lock, flags);
538 if (qp->s_last != qp->s_tail && qp->state == IB_QPS_RTS) {
539 dev->n_timeouts++;
540 ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
541 }
542 spin_unlock_irqrestore(&qp->s_lock, flags);
543
544 /* Notify ipath_destroy_qp() if it is waiting. */
545 if (atomic_dec_and_test(&qp->refcount))
546 wake_up(&qp->wait);
547 }
548 for (qp = rnr; qp != NULL;
549 qp = (struct ipath_qp *) qp->timerwait.prev)
550 tasklet_hi_schedule(&qp->s_task);
551}
552
553/**
554 * ipath_ib_piobufavail - callback when a PIO buffer is available
555 * @arg: the device pointer
556 *
557 * This is called from ipath_intr() at interrupt level when a PIO buffer is
558 * available after ipath_verbs_send() returned an error that no buffers were
559 * available. Return 0 if we consumed all the PIO buffers and we still have
560 * QPs waiting for buffers (for now, just do a tasklet_hi_schedule and
561 * return one).
562 */
563static int ipath_ib_piobufavail(void *arg)
564{
565 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
566 struct ipath_qp *qp;
567 unsigned long flags;
568
569 if (dev == NULL)
570 goto bail;
571
572 spin_lock_irqsave(&dev->pending_lock, flags);
573 while (!list_empty(&dev->piowait)) {
574 qp = list_entry(dev->piowait.next, struct ipath_qp,
575 piowait);
576 list_del(&qp->piowait);
577 tasklet_hi_schedule(&qp->s_task);
578 }
579 spin_unlock_irqrestore(&dev->pending_lock, flags);
580
581bail:
582 return 1;
583}
584
585static int ipath_query_device(struct ib_device *ibdev,
586 struct ib_device_attr *props)
587{
588 struct ipath_ibdev *dev = to_idev(ibdev);
589 u32 vendor, boardrev, majrev, minrev;
590
591 memset(props, 0, sizeof(*props));
592
593 props->device_cap_flags = IB_DEVICE_BAD_PKEY_CNTR |
594 IB_DEVICE_BAD_QKEY_CNTR | IB_DEVICE_SHUTDOWN_PORT |
595 IB_DEVICE_SYS_IMAGE_GUID;
596 ipath_layer_query_device(dev->dd, &vendor, &boardrev,
597 &majrev, &minrev);
598 props->vendor_id = vendor;
599 props->vendor_part_id = boardrev;
600 props->hw_ver = boardrev << 16 | majrev << 8 | minrev;
601
602 props->sys_image_guid = dev->sys_image_guid;
603
604 props->max_mr_size = ~0ull;
605 props->max_qp = 0xffff;
606 props->max_qp_wr = 0xffff;
607 props->max_sge = 255;
608 props->max_cq = 0xffff;
609 props->max_cqe = 0xffff;
610 props->max_mr = 0xffff;
611 props->max_pd = 0xffff;
612 props->max_qp_rd_atom = 1;
613 props->max_qp_init_rd_atom = 1;
614 /* props->max_res_rd_atom */
615 props->max_srq = 0xffff;
616 props->max_srq_wr = 0xffff;
617 props->max_srq_sge = 255;
618 /* props->local_ca_ack_delay */
619 props->atomic_cap = IB_ATOMIC_HCA;
620 props->max_pkeys = ipath_layer_get_npkeys(dev->dd);
621 props->max_mcast_grp = 0xffff;
622 props->max_mcast_qp_attach = 0xffff;
623 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
624 props->max_mcast_grp;
625
626 return 0;
627}
628
629const u8 ipath_cvt_physportstate[16] = {
630 [INFINIPATH_IBCS_LT_STATE_DISABLED] = 3,
631 [INFINIPATH_IBCS_LT_STATE_LINKUP] = 5,
632 [INFINIPATH_IBCS_LT_STATE_POLLACTIVE] = 2,
633 [INFINIPATH_IBCS_LT_STATE_POLLQUIET] = 2,
634 [INFINIPATH_IBCS_LT_STATE_SLEEPDELAY] = 1,
635 [INFINIPATH_IBCS_LT_STATE_SLEEPQUIET] = 1,
636 [INFINIPATH_IBCS_LT_STATE_CFGDEBOUNCE] = 4,
637 [INFINIPATH_IBCS_LT_STATE_CFGRCVFCFG] = 4,
638 [INFINIPATH_IBCS_LT_STATE_CFGWAITRMT] = 4,
639 [INFINIPATH_IBCS_LT_STATE_CFGIDLE] = 4,
640 [INFINIPATH_IBCS_LT_STATE_RECOVERRETRAIN] = 6,
641 [INFINIPATH_IBCS_LT_STATE_RECOVERWAITRMT] = 6,
642 [INFINIPATH_IBCS_LT_STATE_RECOVERIDLE] = 6,
643};
644
645static int ipath_query_port(struct ib_device *ibdev,
646 u8 port, struct ib_port_attr *props)
647{
648 struct ipath_ibdev *dev = to_idev(ibdev);
649 enum ib_mtu mtu;
650 u16 lid = ipath_layer_get_lid(dev->dd);
651 u64 ibcstat;
652
653 memset(props, 0, sizeof(*props));
654 props->lid = lid ? lid : __constant_be16_to_cpu(IB_LID_PERMISSIVE);
655 props->lmc = dev->mkeyprot_resv_lmc & 7;
656 props->sm_lid = dev->sm_lid;
657 props->sm_sl = dev->sm_sl;
658 ibcstat = ipath_layer_get_lastibcstat(dev->dd);
659 props->state = ((ibcstat >> 4) & 0x3) + 1;
660 /* See phys_state_show() */
661 props->phys_state = ipath_cvt_physportstate[
662 ipath_layer_get_lastibcstat(dev->dd) & 0xf];
663 props->port_cap_flags = dev->port_cap_flags;
664 props->gid_tbl_len = 1;
665 props->max_msg_sz = 4096;
666 props->pkey_tbl_len = ipath_layer_get_npkeys(dev->dd);
667 props->bad_pkey_cntr = ipath_layer_get_cr_errpkey(dev->dd) -
668 dev->n_pkey_violations;
669 props->qkey_viol_cntr = dev->qkey_violations;
670 props->active_width = IB_WIDTH_4X;
671 /* See rate_show() */
672 props->active_speed = 1; /* Regular 10Mbs speed. */
673 props->max_vl_num = 1; /* VLCap = VL0 */
674 props->init_type_reply = 0;
675
676 props->max_mtu = IB_MTU_4096;
677 switch (ipath_layer_get_ibmtu(dev->dd)) {
678 case 4096:
679 mtu = IB_MTU_4096;
680 break;
681 case 2048:
682 mtu = IB_MTU_2048;
683 break;
684 case 1024:
685 mtu = IB_MTU_1024;
686 break;
687 case 512:
688 mtu = IB_MTU_512;
689 break;
690 case 256:
691 mtu = IB_MTU_256;
692 break;
693 default:
694 mtu = IB_MTU_2048;
695 }
696 props->active_mtu = mtu;
697 props->subnet_timeout = dev->subnet_timeout;
698
699 return 0;
700}
701
702static int ipath_modify_device(struct ib_device *device,
703 int device_modify_mask,
704 struct ib_device_modify *device_modify)
705{
706 int ret;
707
708 if (device_modify_mask & ~(IB_DEVICE_MODIFY_SYS_IMAGE_GUID |
709 IB_DEVICE_MODIFY_NODE_DESC)) {
710 ret = -EOPNOTSUPP;
711 goto bail;
712 }
713
714 if (device_modify_mask & IB_DEVICE_MODIFY_NODE_DESC)
715 memcpy(device->node_desc, device_modify->node_desc, 64);
716
717 if (device_modify_mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
718 to_idev(device)->sys_image_guid =
719 cpu_to_be64(device_modify->sys_image_guid);
720
721 ret = 0;
722
723bail:
724 return ret;
725}
726
727static int ipath_modify_port(struct ib_device *ibdev,
728 u8 port, int port_modify_mask,
729 struct ib_port_modify *props)
730{
731 struct ipath_ibdev *dev = to_idev(ibdev);
732
733 dev->port_cap_flags |= props->set_port_cap_mask;
734 dev->port_cap_flags &= ~props->clr_port_cap_mask;
735 if (port_modify_mask & IB_PORT_SHUTDOWN)
736 ipath_layer_set_linkstate(dev->dd, IPATH_IB_LINKDOWN);
737 if (port_modify_mask & IB_PORT_RESET_QKEY_CNTR)
738 dev->qkey_violations = 0;
739 return 0;
740}
741
742static int ipath_query_gid(struct ib_device *ibdev, u8 port,
743 int index, union ib_gid *gid)
744{
745 struct ipath_ibdev *dev = to_idev(ibdev);
746 int ret;
747
748 if (index >= 1) {
749 ret = -EINVAL;
750 goto bail;
751 }
752 gid->global.subnet_prefix = dev->gid_prefix;
753 gid->global.interface_id = ipath_layer_get_guid(dev->dd);
754
755 ret = 0;
756
757bail:
758 return ret;
759}
760
761static struct ib_pd *ipath_alloc_pd(struct ib_device *ibdev,
762 struct ib_ucontext *context,
763 struct ib_udata *udata)
764{
765 struct ipath_pd *pd;
766 struct ib_pd *ret;
767
768 pd = kmalloc(sizeof *pd, GFP_KERNEL);
769 if (!pd) {
770 ret = ERR_PTR(-ENOMEM);
771 goto bail;
772 }
773
774 /* ib_alloc_pd() will initialize pd->ibpd. */
775 pd->user = udata != NULL;
776
777 ret = &pd->ibpd;
778
779bail:
780 return ret;
781}
782
783static int ipath_dealloc_pd(struct ib_pd *ibpd)
784{
785 struct ipath_pd *pd = to_ipd(ibpd);
786
787 kfree(pd);
788
789 return 0;
790}
791
792/**
793 * ipath_create_ah - create an address handle
794 * @pd: the protection domain
795 * @ah_attr: the attributes of the AH
796 *
797 * This may be called from interrupt context.
798 */
799static struct ib_ah *ipath_create_ah(struct ib_pd *pd,
800 struct ib_ah_attr *ah_attr)
801{
802 struct ipath_ah *ah;
803 struct ib_ah *ret;
804
805 /* A multicast address requires a GRH (see ch. 8.4.1). */
806 if (ah_attr->dlid >= IPS_MULTICAST_LID_BASE &&
807 ah_attr->dlid != IPS_PERMISSIVE_LID &&
808 !(ah_attr->ah_flags & IB_AH_GRH)) {
809 ret = ERR_PTR(-EINVAL);
810 goto bail;
811 }
812
813 ah = kmalloc(sizeof *ah, GFP_ATOMIC);
814 if (!ah) {
815 ret = ERR_PTR(-ENOMEM);
816 goto bail;
817 }
818
819 /* ib_create_ah() will initialize ah->ibah. */
820 ah->attr = *ah_attr;
821
822 ret = &ah->ibah;
823
824bail:
825 return ret;
826}
827
828/**
829 * ipath_destroy_ah - destroy an address handle
830 * @ibah: the AH to destroy
831 *
832 * This may be called from interrupt context.
833 */
834static int ipath_destroy_ah(struct ib_ah *ibah)
835{
836 struct ipath_ah *ah = to_iah(ibah);
837
838 kfree(ah);
839
840 return 0;
841}
842
843static int ipath_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
844{
845 struct ipath_ah *ah = to_iah(ibah);
846
847 *ah_attr = ah->attr;
848
849 return 0;
850}
851
852static int ipath_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
853 u16 *pkey)
854{
855 struct ipath_ibdev *dev = to_idev(ibdev);
856 int ret;
857
858 if (index >= ipath_layer_get_npkeys(dev->dd)) {
859 ret = -EINVAL;
860 goto bail;
861 }
862
863 *pkey = ipath_layer_get_pkey(dev->dd, index);
864 ret = 0;
865
866bail:
867 return ret;
868}
869
870
871/**
872 * ipath_alloc_ucontext - allocate a ucontest
873 * @ibdev: the infiniband device
874 * @udata: not used by the InfiniPath driver
875 */
876
877static struct ib_ucontext *ipath_alloc_ucontext(struct ib_device *ibdev,
878 struct ib_udata *udata)
879{
880 struct ipath_ucontext *context;
881 struct ib_ucontext *ret;
882
883 context = kmalloc(sizeof *context, GFP_KERNEL);
884 if (!context) {
885 ret = ERR_PTR(-ENOMEM);
886 goto bail;
887 }
888
889 ret = &context->ibucontext;
890
891bail:
892 return ret;
893}
894
895static int ipath_dealloc_ucontext(struct ib_ucontext *context)
896{
897 kfree(to_iucontext(context));
898 return 0;
899}
900
901static int ipath_verbs_register_sysfs(struct ib_device *dev);
902
903/**
904 * ipath_register_ib_device - register our device with the infiniband core
905 * @unit: the device number to register
906 * @dd: the device data structure
907 * Return the allocated ipath_ibdev pointer or NULL on error.
908 */
909static void *ipath_register_ib_device(int unit, struct ipath_devdata *dd)
910{
911 struct ipath_ibdev *idev;
912 struct ib_device *dev;
913 int ret;
914
915 idev = (struct ipath_ibdev *)ib_alloc_device(sizeof *idev);
916 if (idev == NULL)
917 goto bail;
918
919 dev = &idev->ibdev;
920
921 /* Only need to initialize non-zero fields. */
922 spin_lock_init(&idev->qp_table.lock);
923 spin_lock_init(&idev->lk_table.lock);
924 idev->sm_lid = __constant_be16_to_cpu(IB_LID_PERMISSIVE);
925 /* Set the prefix to the default value (see ch. 4.1.1) */
926 idev->gid_prefix = __constant_cpu_to_be64(0xfe80000000000000ULL);
927
928 ret = ipath_init_qp_table(idev, ib_ipath_qp_table_size);
929 if (ret)
930 goto err_qp;
931
932 /*
933 * The top ib_ipath_lkey_table_size bits are used to index the
934 * table. The lower 8 bits can be owned by the user (copied from
935 * the LKEY). The remaining bits act as a generation number or tag.
936 */
937 idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
938 idev->lk_table.table = kzalloc(idev->lk_table.max *
939 sizeof(*idev->lk_table.table),
940 GFP_KERNEL);
941 if (idev->lk_table.table == NULL) {
942 ret = -ENOMEM;
943 goto err_lk;
944 }
945 spin_lock_init(&idev->pending_lock);
946 INIT_LIST_HEAD(&idev->pending[0]);
947 INIT_LIST_HEAD(&idev->pending[1]);
948 INIT_LIST_HEAD(&idev->pending[2]);
949 INIT_LIST_HEAD(&idev->piowait);
950 INIT_LIST_HEAD(&idev->rnrwait);
951 idev->pending_index = 0;
952 idev->port_cap_flags =
953 IB_PORT_SYS_IMAGE_GUID_SUP | IB_PORT_CLIENT_REG_SUP;
954 idev->pma_counter_select[0] = IB_PMA_PORT_XMIT_DATA;
955 idev->pma_counter_select[1] = IB_PMA_PORT_RCV_DATA;
956 idev->pma_counter_select[2] = IB_PMA_PORT_XMIT_PKTS;
957 idev->pma_counter_select[3] = IB_PMA_PORT_RCV_PKTS;
958 idev->pma_counter_select[5] = IB_PMA_PORT_XMIT_WAIT;
959 idev->link_width_enabled = 3; /* 1x or 4x */
960
961 /*
962 * The system image GUID is supposed to be the same for all
963 * IB HCAs in a single system but since there can be other
964 * device types in the system, we can't be sure this is unique.
965 */
966 if (!sys_image_guid)
967 sys_image_guid = ipath_layer_get_guid(dd);
968 idev->sys_image_guid = sys_image_guid;
969 idev->ib_unit = unit;
970 idev->dd = dd;
971
972 strlcpy(dev->name, "ipath%d", IB_DEVICE_NAME_MAX);
973 dev->node_guid = ipath_layer_get_guid(dd);
974 dev->uverbs_abi_ver = IPATH_UVERBS_ABI_VERSION;
975 dev->uverbs_cmd_mask =
976 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
977 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
978 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
979 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
980 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
981 (1ull << IB_USER_VERBS_CMD_CREATE_AH) |
982 (1ull << IB_USER_VERBS_CMD_DESTROY_AH) |
983 (1ull << IB_USER_VERBS_CMD_QUERY_AH) |
984 (1ull << IB_USER_VERBS_CMD_REG_MR) |
985 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
986 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
987 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
988 (1ull << IB_USER_VERBS_CMD_RESIZE_CQ) |
989 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
990 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
991 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
992 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
993 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
994 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
995 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
996 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
997 (1ull << IB_USER_VERBS_CMD_POST_RECV) |
998 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
999 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
1000 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
1001 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
1002 (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |
1003 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ) |
1004 (1ull << IB_USER_VERBS_CMD_POST_SRQ_RECV);
1005 dev->node_type = IB_NODE_CA;
1006 dev->phys_port_cnt = 1;
1007 dev->dma_device = ipath_layer_get_device(dd);
1008 dev->class_dev.dev = dev->dma_device;
1009 dev->query_device = ipath_query_device;
1010 dev->modify_device = ipath_modify_device;
1011 dev->query_port = ipath_query_port;
1012 dev->modify_port = ipath_modify_port;
1013 dev->query_pkey = ipath_query_pkey;
1014 dev->query_gid = ipath_query_gid;
1015 dev->alloc_ucontext = ipath_alloc_ucontext;
1016 dev->dealloc_ucontext = ipath_dealloc_ucontext;
1017 dev->alloc_pd = ipath_alloc_pd;
1018 dev->dealloc_pd = ipath_dealloc_pd;
1019 dev->create_ah = ipath_create_ah;
1020 dev->destroy_ah = ipath_destroy_ah;
1021 dev->query_ah = ipath_query_ah;
1022 dev->create_srq = ipath_create_srq;
1023 dev->modify_srq = ipath_modify_srq;
1024 dev->query_srq = ipath_query_srq;
1025 dev->destroy_srq = ipath_destroy_srq;
1026 dev->create_qp = ipath_create_qp;
1027 dev->modify_qp = ipath_modify_qp;
1028 dev->query_qp = ipath_query_qp;
1029 dev->destroy_qp = ipath_destroy_qp;
1030 dev->post_send = ipath_post_send;
1031 dev->post_recv = ipath_post_receive;
1032 dev->post_srq_recv = ipath_post_srq_receive;
1033 dev->create_cq = ipath_create_cq;
1034 dev->destroy_cq = ipath_destroy_cq;
1035 dev->resize_cq = ipath_resize_cq;
1036 dev->poll_cq = ipath_poll_cq;
1037 dev->req_notify_cq = ipath_req_notify_cq;
1038 dev->get_dma_mr = ipath_get_dma_mr;
1039 dev->reg_phys_mr = ipath_reg_phys_mr;
1040 dev->reg_user_mr = ipath_reg_user_mr;
1041 dev->dereg_mr = ipath_dereg_mr;
1042 dev->alloc_fmr = ipath_alloc_fmr;
1043 dev->map_phys_fmr = ipath_map_phys_fmr;
1044 dev->unmap_fmr = ipath_unmap_fmr;
1045 dev->dealloc_fmr = ipath_dealloc_fmr;
1046 dev->attach_mcast = ipath_multicast_attach;
1047 dev->detach_mcast = ipath_multicast_detach;
1048 dev->process_mad = ipath_process_mad;
1049
1050 snprintf(dev->node_desc, sizeof(dev->node_desc),
1051 IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
1052
1053 ret = ib_register_device(dev);
1054 if (ret)
1055 goto err_reg;
1056
1057 if (ipath_verbs_register_sysfs(dev))
1058 goto err_class;
1059
1060 ipath_layer_enable_timer(dd);
1061
1062 goto bail;
1063
1064err_class:
1065 ib_unregister_device(dev);
1066err_reg:
1067 kfree(idev->lk_table.table);
1068err_lk:
1069 kfree(idev->qp_table.table);
1070err_qp:
1071 ib_dealloc_device(dev);
1072 _VERBS_ERROR("ib_ipath%d cannot register verbs (%d)!\n",
1073 unit, -ret);
1074 idev = NULL;
1075
1076bail:
1077 return idev;
1078}
1079
1080static void ipath_unregister_ib_device(void *arg)
1081{
1082 struct ipath_ibdev *dev = (struct ipath_ibdev *) arg;
1083 struct ib_device *ibdev = &dev->ibdev;
1084
1085 ipath_layer_disable_timer(dev->dd);
1086
1087 ib_unregister_device(ibdev);
1088
1089 if (!list_empty(&dev->pending[0]) ||
1090 !list_empty(&dev->pending[1]) ||
1091 !list_empty(&dev->pending[2]))
1092 _VERBS_ERROR("ipath%d pending list not empty!\n",
1093 dev->ib_unit);
1094 if (!list_empty(&dev->piowait))
1095 _VERBS_ERROR("ipath%d piowait list not empty!\n",
1096 dev->ib_unit);
1097 if (!list_empty(&dev->rnrwait))
1098 _VERBS_ERROR("ipath%d rnrwait list not empty!\n",
1099 dev->ib_unit);
1100 if (!ipath_mcast_tree_empty())
1101 _VERBS_ERROR("ipath%d multicast table memory leak!\n",
1102 dev->ib_unit);
1103 /*
1104 * Note that ipath_unregister_ib_device() can be called before all
1105 * the QPs are destroyed!
1106 */
1107 ipath_free_all_qps(&dev->qp_table);
1108 kfree(dev->qp_table.table);
1109 kfree(dev->lk_table.table);
1110 ib_dealloc_device(ibdev);
1111}
1112
1113int __init ipath_verbs_init(void)
1114{
1115 return ipath_verbs_register(ipath_register_ib_device,
1116 ipath_unregister_ib_device,
1117 ipath_ib_piobufavail, ipath_ib_rcv,
1118 ipath_ib_timer);
1119}
1120
1121void __exit ipath_verbs_cleanup(void)
1122{
1123 ipath_verbs_unregister();
1124}
1125
1126static ssize_t show_rev(struct class_device *cdev, char *buf)
1127{
1128 struct ipath_ibdev *dev =
1129 container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
1130 int vendor, boardrev, majrev, minrev;
1131
1132 ipath_layer_query_device(dev->dd, &vendor, &boardrev,
1133 &majrev, &minrev);
1134 return sprintf(buf, "%d.%d\n", majrev, minrev);
1135}
1136
1137static ssize_t show_hca(struct class_device *cdev, char *buf)
1138{
1139 struct ipath_ibdev *dev =
1140 container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
1141 int ret;
1142
1143 ret = ipath_layer_get_boardname(dev->dd, buf, 128);
1144 if (ret < 0)
1145 goto bail;
1146 strcat(buf, "\n");
1147 ret = strlen(buf);
1148
1149bail:
1150 return ret;
1151}
1152
1153static ssize_t show_stats(struct class_device *cdev, char *buf)
1154{
1155 struct ipath_ibdev *dev =
1156 container_of(cdev, struct ipath_ibdev, ibdev.class_dev);
1157 int i;
1158 int len;
1159
1160 len = sprintf(buf,
1161 "RC resends %d\n"
1162 "RC QACKs %d\n"
1163 "RC ACKs %d\n"
1164 "RC SEQ NAKs %d\n"
1165 "RC RDMA seq %d\n"
1166 "RC RNR NAKs %d\n"
1167 "RC OTH NAKs %d\n"
1168 "RC timeouts %d\n"
1169 "RC RDMA dup %d\n"
1170 "piobuf wait %d\n"
1171 "no piobuf %d\n"
1172 "PKT drops %d\n"
1173 "WQE errs %d\n",
1174 dev->n_rc_resends, dev->n_rc_qacks, dev->n_rc_acks,
1175 dev->n_seq_naks, dev->n_rdma_seq, dev->n_rnr_naks,
1176 dev->n_other_naks, dev->n_timeouts,
1177 dev->n_rdma_dup_busy, dev->n_piowait,
1178 dev->n_no_piobuf, dev->n_pkt_drops, dev->n_wqe_errs);
1179 for (i = 0; i < ARRAY_SIZE(dev->opstats); i++) {
1180 const struct ipath_opcode_stats *si = &dev->opstats[i];
1181
1182 if (!si->n_packets && !si->n_bytes)
1183 continue;
1184 len += sprintf(buf + len, "%02x %llu/%llu\n", i,
1185 (unsigned long long) si->n_packets,
1186 (unsigned long long) si->n_bytes);
1187 }
1188 return len;
1189}
1190
1191static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
1192static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
1193static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_hca, NULL);
1194static CLASS_DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
1195
1196static struct class_device_attribute *ipath_class_attributes[] = {
1197 &class_device_attr_hw_rev,
1198 &class_device_attr_hca_type,
1199 &class_device_attr_board_id,
1200 &class_device_attr_stats
1201};
1202
1203static int ipath_verbs_register_sysfs(struct ib_device *dev)
1204{
1205 int i;
1206 int ret;
1207
1208 for (i = 0; i < ARRAY_SIZE(ipath_class_attributes); ++i)
1209 if (class_device_create_file(&dev->class_dev,
1210 ipath_class_attributes[i])) {
1211 ret = 1;
1212 goto bail;
1213 }
1214
1215 ret = 0;
1216
1217bail:
1218 return ret;
1219}
1220
1221module_init(ipath_verbs_init);
1222module_exit(ipath_verbs_cleanup);
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.h b/drivers/infiniband/hw/ipath/ipath_verbs.h
new file mode 100644
index 000000000000..b824632b2a8c
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.h
@@ -0,0 +1,697 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef IPATH_VERBS_H
34#define IPATH_VERBS_H
35
36#include <linux/types.h>
37#include <linux/spinlock.h>
38#include <linux/kernel.h>
39#include <linux/interrupt.h>
40#include <rdma/ib_pack.h>
41
42#include "ipath_layer.h"
43#include "verbs_debug.h"
44
45#define QPN_MAX (1 << 24)
46#define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
47
48/*
49 * Increment this value if any changes that break userspace ABI
50 * compatibility are made.
51 */
52#define IPATH_UVERBS_ABI_VERSION 1
53
54/*
55 * Define an ib_cq_notify value that is not valid so we know when CQ
56 * notifications are armed.
57 */
58#define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
59
60#define IB_RNR_NAK 0x20
61#define IB_NAK_PSN_ERROR 0x60
62#define IB_NAK_INVALID_REQUEST 0x61
63#define IB_NAK_REMOTE_ACCESS_ERROR 0x62
64#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
65#define IB_NAK_INVALID_RD_REQUEST 0x64
66
67#define IPATH_POST_SEND_OK 0x01
68#define IPATH_POST_RECV_OK 0x02
69#define IPATH_PROCESS_RECV_OK 0x04
70#define IPATH_PROCESS_SEND_OK 0x08
71
72/* IB Performance Manager status values */
73#define IB_PMA_SAMPLE_STATUS_DONE 0x00
74#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
75#define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
76
77/* Mandatory IB performance counter select values. */
78#define IB_PMA_PORT_XMIT_DATA __constant_htons(0x0001)
79#define IB_PMA_PORT_RCV_DATA __constant_htons(0x0002)
80#define IB_PMA_PORT_XMIT_PKTS __constant_htons(0x0003)
81#define IB_PMA_PORT_RCV_PKTS __constant_htons(0x0004)
82#define IB_PMA_PORT_XMIT_WAIT __constant_htons(0x0005)
83
84struct ib_reth {
85 __be64 vaddr;
86 __be32 rkey;
87 __be32 length;
88} __attribute__ ((packed));
89
90struct ib_atomic_eth {
91 __be64 vaddr;
92 __be32 rkey;
93 __be64 swap_data;
94 __be64 compare_data;
95} __attribute__ ((packed));
96
97struct ipath_other_headers {
98 __be32 bth[3];
99 union {
100 struct {
101 __be32 deth[2];
102 __be32 imm_data;
103 } ud;
104 struct {
105 struct ib_reth reth;
106 __be32 imm_data;
107 } rc;
108 struct {
109 __be32 aeth;
110 __be64 atomic_ack_eth;
111 } at;
112 __be32 imm_data;
113 __be32 aeth;
114 struct ib_atomic_eth atomic_eth;
115 } u;
116} __attribute__ ((packed));
117
118/*
119 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
120 * long (72 w/ imm_data). Only the first 56 bytes of the IB header
121 * will be in the eager header buffer. The remaining 12 or 16 bytes
122 * are in the data buffer.
123 */
124struct ipath_ib_header {
125 __be16 lrh[4];
126 union {
127 struct {
128 struct ib_grh grh;
129 struct ipath_other_headers oth;
130 } l;
131 struct ipath_other_headers oth;
132 } u;
133} __attribute__ ((packed));
134
135/*
136 * There is one struct ipath_mcast for each multicast GID.
137 * All attached QPs are then stored as a list of
138 * struct ipath_mcast_qp.
139 */
140struct ipath_mcast_qp {
141 struct list_head list;
142 struct ipath_qp *qp;
143};
144
145struct ipath_mcast {
146 struct rb_node rb_node;
147 union ib_gid mgid;
148 struct list_head qp_list;
149 wait_queue_head_t wait;
150 atomic_t refcount;
151};
152
153/* Memory region */
154struct ipath_mr {
155 struct ib_mr ibmr;
156 struct ipath_mregion mr; /* must be last */
157};
158
159/* Fast memory region */
160struct ipath_fmr {
161 struct ib_fmr ibfmr;
162 u8 page_shift;
163 struct ipath_mregion mr; /* must be last */
164};
165
166/* Protection domain */
167struct ipath_pd {
168 struct ib_pd ibpd;
169 int user; /* non-zero if created from user space */
170};
171
172/* Address Handle */
173struct ipath_ah {
174 struct ib_ah ibah;
175 struct ib_ah_attr attr;
176};
177
178/*
179 * Quick description of our CQ/QP locking scheme:
180 *
181 * We have one global lock that protects dev->cq/qp_table. Each
182 * struct ipath_cq/qp also has its own lock. An individual qp lock
183 * may be taken inside of an individual cq lock. Both cqs attached to
184 * a qp may be locked, with the send cq locked first. No other
185 * nesting should be done.
186 *
187 * Each struct ipath_cq/qp also has an atomic_t ref count. The
188 * pointer from the cq/qp_table to the struct counts as one reference.
189 * This reference also is good for access through the consumer API, so
190 * modifying the CQ/QP etc doesn't need to take another reference.
191 * Access because of a completion being polled does need a reference.
192 *
193 * Finally, each struct ipath_cq/qp has a wait_queue_head_t for the
194 * destroy function to sleep on.
195 *
196 * This means that access from the consumer API requires nothing but
197 * taking the struct's lock.
198 *
199 * Access because of a completion event should go as follows:
200 * - lock cq/qp_table and look up struct
201 * - increment ref count in struct
202 * - drop cq/qp_table lock
203 * - lock struct, do your thing, and unlock struct
204 * - decrement ref count; if zero, wake up waiters
205 *
206 * To destroy a CQ/QP, we can do the following:
207 * - lock cq/qp_table, remove pointer, unlock cq/qp_table lock
208 * - decrement ref count
209 * - wait_event until ref count is zero
210 *
211 * It is the consumer's responsibilty to make sure that no QP
212 * operations (WQE posting or state modification) are pending when the
213 * QP is destroyed. Also, the consumer must make sure that calls to
214 * qp_modify are serialized.
215 *
216 * Possible optimizations (wait for profile data to see if/where we
217 * have locks bouncing between CPUs):
218 * - split cq/qp table lock into n separate (cache-aligned) locks,
219 * indexed (say) by the page in the table
220 */
221
222struct ipath_cq {
223 struct ib_cq ibcq;
224 struct tasklet_struct comptask;
225 spinlock_t lock;
226 u8 notify;
227 u8 triggered;
228 u32 head; /* new records added to the head */
229 u32 tail; /* poll_cq() reads from here. */
230 struct ib_wc *queue; /* this is actually ibcq.cqe + 1 */
231};
232
233/*
234 * Send work request queue entry.
235 * The size of the sg_list is determined when the QP is created and stored
236 * in qp->s_max_sge.
237 */
238struct ipath_swqe {
239 struct ib_send_wr wr; /* don't use wr.sg_list */
240 u32 psn; /* first packet sequence number */
241 u32 lpsn; /* last packet sequence number */
242 u32 ssn; /* send sequence number */
243 u32 length; /* total length of data in sg_list */
244 struct ipath_sge sg_list[0];
245};
246
247/*
248 * Receive work request queue entry.
249 * The size of the sg_list is determined when the QP is created and stored
250 * in qp->r_max_sge.
251 */
252struct ipath_rwqe {
253 u64 wr_id;
254 u32 length; /* total length of data in sg_list */
255 u8 num_sge;
256 struct ipath_sge sg_list[0];
257};
258
259struct ipath_rq {
260 spinlock_t lock;
261 u32 head; /* new work requests posted to the head */
262 u32 tail; /* receives pull requests from here. */
263 u32 size; /* size of RWQE array */
264 u8 max_sge;
265 struct ipath_rwqe *wq; /* RWQE array */
266};
267
268struct ipath_srq {
269 struct ib_srq ibsrq;
270 struct ipath_rq rq;
271 /* send signal when number of RWQEs < limit */
272 u32 limit;
273};
274
275/*
276 * Variables prefixed with s_ are for the requester (sender).
277 * Variables prefixed with r_ are for the responder (receiver).
278 * Variables prefixed with ack_ are for responder replies.
279 *
280 * Common variables are protected by both r_rq.lock and s_lock in that order
281 * which only happens in modify_qp() or changing the QP 'state'.
282 */
283struct ipath_qp {
284 struct ib_qp ibqp;
285 struct ipath_qp *next; /* link list for QPN hash table */
286 struct list_head piowait; /* link for wait PIO buf */
287 struct list_head timerwait; /* link for waiting for timeouts */
288 struct ib_ah_attr remote_ah_attr;
289 struct ipath_ib_header s_hdr; /* next packet header to send */
290 atomic_t refcount;
291 wait_queue_head_t wait;
292 struct tasklet_struct s_task;
293 struct ipath_sge_state *s_cur_sge;
294 struct ipath_sge_state s_sge; /* current send request data */
295 /* current RDMA read send data */
296 struct ipath_sge_state s_rdma_sge;
297 struct ipath_sge_state r_sge; /* current receive data */
298 spinlock_t s_lock;
299 unsigned long s_flags;
300 u32 s_hdrwords; /* size of s_hdr in 32 bit words */
301 u32 s_cur_size; /* size of send packet in bytes */
302 u32 s_len; /* total length of s_sge */
303 u32 s_rdma_len; /* total length of s_rdma_sge */
304 u32 s_next_psn; /* PSN for next request */
305 u32 s_last_psn; /* last response PSN processed */
306 u32 s_psn; /* current packet sequence number */
307 u32 s_rnr_timeout; /* number of milliseconds for RNR timeout */
308 u32 s_ack_psn; /* PSN for next ACK or RDMA_READ */
309 u64 s_ack_atomic; /* data for atomic ACK */
310 u64 r_wr_id; /* ID for current receive WQE */
311 u64 r_atomic_data; /* data for last atomic op */
312 u32 r_atomic_psn; /* PSN of last atomic op */
313 u32 r_len; /* total length of r_sge */
314 u32 r_rcv_len; /* receive data len processed */
315 u32 r_psn; /* expected rcv packet sequence number */
316 u8 state; /* QP state */
317 u8 s_state; /* opcode of last packet sent */
318 u8 s_ack_state; /* opcode of packet to ACK */
319 u8 s_nak_state; /* non-zero if NAK is pending */
320 u8 r_state; /* opcode of last packet received */
321 u8 r_reuse_sge; /* for UC receive errors */
322 u8 r_sge_inx; /* current index into sg_list */
323 u8 s_max_sge; /* size of s_wq->sg_list */
324 u8 qp_access_flags;
325 u8 s_retry_cnt; /* number of times to retry */
326 u8 s_rnr_retry_cnt;
327 u8 s_min_rnr_timer;
328 u8 s_retry; /* requester retry counter */
329 u8 s_rnr_retry; /* requester RNR retry counter */
330 u8 s_pkey_index; /* PKEY index to use */
331 enum ib_mtu path_mtu;
332 atomic_t msn; /* message sequence number */
333 u32 remote_qpn;
334 u32 qkey; /* QKEY for this QP (for UD or RD) */
335 u32 s_size; /* send work queue size */
336 u32 s_head; /* new entries added here */
337 u32 s_tail; /* next entry to process */
338 u32 s_cur; /* current work queue entry */
339 u32 s_last; /* last un-ACK'ed entry */
340 u32 s_ssn; /* SSN of tail entry */
341 u32 s_lsn; /* limit sequence number (credit) */
342 struct ipath_swqe *s_wq; /* send work queue */
343 struct ipath_rq r_rq; /* receive work queue */
344};
345
346/*
347 * Bit definitions for s_flags.
348 */
349#define IPATH_S_BUSY 0
350#define IPATH_S_SIGNAL_REQ_WR 1
351
352/*
353 * Since struct ipath_swqe is not a fixed size, we can't simply index into
354 * struct ipath_qp.s_wq. This function does the array index computation.
355 */
356static inline struct ipath_swqe *get_swqe_ptr(struct ipath_qp *qp,
357 unsigned n)
358{
359 return (struct ipath_swqe *)((char *)qp->s_wq +
360 (sizeof(struct ipath_swqe) +
361 qp->s_max_sge *
362 sizeof(struct ipath_sge)) * n);
363}
364
365/*
366 * Since struct ipath_rwqe is not a fixed size, we can't simply index into
367 * struct ipath_rq.wq. This function does the array index computation.
368 */
369static inline struct ipath_rwqe *get_rwqe_ptr(struct ipath_rq *rq,
370 unsigned n)
371{
372 return (struct ipath_rwqe *)
373 ((char *) rq->wq +
374 (sizeof(struct ipath_rwqe) +
375 rq->max_sge * sizeof(struct ipath_sge)) * n);
376}
377
378/*
379 * QPN-map pages start out as NULL, they get allocated upon
380 * first use and are never deallocated. This way,
381 * large bitmaps are not allocated unless large numbers of QPs are used.
382 */
383struct qpn_map {
384 atomic_t n_free;
385 void *page;
386};
387
388struct ipath_qp_table {
389 spinlock_t lock;
390 u32 last; /* last QP number allocated */
391 u32 max; /* size of the hash table */
392 u32 nmaps; /* size of the map table */
393 struct ipath_qp **table;
394 /* bit map of free numbers */
395 struct qpn_map map[QPNMAP_ENTRIES];
396};
397
398struct ipath_lkey_table {
399 spinlock_t lock;
400 u32 next; /* next unused index (speeds search) */
401 u32 gen; /* generation count */
402 u32 max; /* size of the table */
403 struct ipath_mregion **table;
404};
405
406struct ipath_opcode_stats {
407 u64 n_packets; /* number of packets */
408 u64 n_bytes; /* total number of bytes */
409};
410
411struct ipath_ibdev {
412 struct ib_device ibdev;
413 struct list_head dev_list;
414 struct ipath_devdata *dd;
415 int ib_unit; /* This is the device number */
416 u16 sm_lid; /* in host order */
417 u8 sm_sl;
418 u8 mkeyprot_resv_lmc;
419 /* non-zero when timer is set */
420 unsigned long mkey_lease_timeout;
421
422 /* The following fields are really per port. */
423 struct ipath_qp_table qp_table;
424 struct ipath_lkey_table lk_table;
425 struct list_head pending[3]; /* FIFO of QPs waiting for ACKs */
426 struct list_head piowait; /* list for wait PIO buf */
427 /* list of QPs waiting for RNR timer */
428 struct list_head rnrwait;
429 spinlock_t pending_lock;
430 __be64 sys_image_guid; /* in network order */
431 __be64 gid_prefix; /* in network order */
432 __be64 mkey;
433 u64 ipath_sword; /* total dwords sent (sample result) */
434 u64 ipath_rword; /* total dwords received (sample result) */
435 u64 ipath_spkts; /* total packets sent (sample result) */
436 u64 ipath_rpkts; /* total packets received (sample result) */
437 /* # of ticks no data sent (sample result) */
438 u64 ipath_xmit_wait;
439 u64 rcv_errors; /* # of packets with SW detected rcv errs */
440 u64 n_unicast_xmit; /* total unicast packets sent */
441 u64 n_unicast_rcv; /* total unicast packets received */
442 u64 n_multicast_xmit; /* total multicast packets sent */
443 u64 n_multicast_rcv; /* total multicast packets received */
444 u64 n_symbol_error_counter; /* starting count for PMA */
445 u64 n_link_error_recovery_counter; /* starting count for PMA */
446 u64 n_link_downed_counter; /* starting count for PMA */
447 u64 n_port_rcv_errors; /* starting count for PMA */
448 u64 n_port_rcv_remphys_errors; /* starting count for PMA */
449 u64 n_port_xmit_discards; /* starting count for PMA */
450 u64 n_port_xmit_data; /* starting count for PMA */
451 u64 n_port_rcv_data; /* starting count for PMA */
452 u64 n_port_xmit_packets; /* starting count for PMA */
453 u64 n_port_rcv_packets; /* starting count for PMA */
454 u32 n_pkey_violations; /* starting count for PMA */
455 u32 n_rc_resends;
456 u32 n_rc_acks;
457 u32 n_rc_qacks;
458 u32 n_seq_naks;
459 u32 n_rdma_seq;
460 u32 n_rnr_naks;
461 u32 n_other_naks;
462 u32 n_timeouts;
463 u32 n_pkt_drops;
464 u32 n_wqe_errs;
465 u32 n_rdma_dup_busy;
466 u32 n_piowait;
467 u32 n_no_piobuf;
468 u32 port_cap_flags;
469 u32 pma_sample_start;
470 u32 pma_sample_interval;
471 __be16 pma_counter_select[5];
472 u16 pma_tag;
473 u16 qkey_violations;
474 u16 mkey_violations;
475 u16 mkey_lease_period;
476 u16 pending_index; /* which pending queue is active */
477 u8 pma_sample_status;
478 u8 subnet_timeout;
479 u8 link_width_enabled;
480 u8 vl_high_limit;
481 struct ipath_opcode_stats opstats[128];
482};
483
484struct ipath_ucontext {
485 struct ib_ucontext ibucontext;
486};
487
488static inline struct ipath_mr *to_imr(struct ib_mr *ibmr)
489{
490 return container_of(ibmr, struct ipath_mr, ibmr);
491}
492
493static inline struct ipath_fmr *to_ifmr(struct ib_fmr *ibfmr)
494{
495 return container_of(ibfmr, struct ipath_fmr, ibfmr);
496}
497
498static inline struct ipath_pd *to_ipd(struct ib_pd *ibpd)
499{
500 return container_of(ibpd, struct ipath_pd, ibpd);
501}
502
503static inline struct ipath_ah *to_iah(struct ib_ah *ibah)
504{
505 return container_of(ibah, struct ipath_ah, ibah);
506}
507
508static inline struct ipath_cq *to_icq(struct ib_cq *ibcq)
509{
510 return container_of(ibcq, struct ipath_cq, ibcq);
511}
512
513static inline struct ipath_srq *to_isrq(struct ib_srq *ibsrq)
514{
515 return container_of(ibsrq, struct ipath_srq, ibsrq);
516}
517
518static inline struct ipath_qp *to_iqp(struct ib_qp *ibqp)
519{
520 return container_of(ibqp, struct ipath_qp, ibqp);
521}
522
523static inline struct ipath_ibdev *to_idev(struct ib_device *ibdev)
524{
525 return container_of(ibdev, struct ipath_ibdev, ibdev);
526}
527
528int ipath_process_mad(struct ib_device *ibdev,
529 int mad_flags,
530 u8 port_num,
531 struct ib_wc *in_wc,
532 struct ib_grh *in_grh,
533 struct ib_mad *in_mad, struct ib_mad *out_mad);
534
535static inline struct ipath_ucontext *to_iucontext(struct ib_ucontext
536 *ibucontext)
537{
538 return container_of(ibucontext, struct ipath_ucontext, ibucontext);
539}
540
541/*
542 * Compare the lower 24 bits of the two values.
543 * Returns an integer <, ==, or > than zero.
544 */
545static inline int ipath_cmp24(u32 a, u32 b)
546{
547 return (((int) a) - ((int) b)) << 8;
548}
549
550struct ipath_mcast *ipath_mcast_find(union ib_gid *mgid);
551
552int ipath_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
553
554int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
555
556int ipath_mcast_tree_empty(void);
557
558__be32 ipath_compute_aeth(struct ipath_qp *qp);
559
560struct ipath_qp *ipath_lookup_qpn(struct ipath_qp_table *qpt, u32 qpn);
561
562struct ib_qp *ipath_create_qp(struct ib_pd *ibpd,
563 struct ib_qp_init_attr *init_attr,
564 struct ib_udata *udata);
565
566int ipath_destroy_qp(struct ib_qp *ibqp);
567
568int ipath_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
569 int attr_mask);
570
571int ipath_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
572 int attr_mask, struct ib_qp_init_attr *init_attr);
573
574void ipath_free_all_qps(struct ipath_qp_table *qpt);
575
576int ipath_init_qp_table(struct ipath_ibdev *idev, int size);
577
578void ipath_sqerror_qp(struct ipath_qp *qp, struct ib_wc *wc);
579
580void ipath_error_qp(struct ipath_qp *qp);
581
582void ipath_get_credit(struct ipath_qp *qp, u32 aeth);
583
584void ipath_do_rc_send(unsigned long data);
585
586void ipath_do_uc_send(unsigned long data);
587
588void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int sig);
589
590int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss,
591 u32 len, u64 vaddr, u32 rkey, int acc);
592
593int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge,
594 struct ib_sge *sge, int acc);
595
596void ipath_copy_sge(struct ipath_sge_state *ss, void *data, u32 length);
597
598void ipath_skip_sge(struct ipath_sge_state *ss, u32 length);
599
600int ipath_post_rc_send(struct ipath_qp *qp, struct ib_send_wr *wr);
601
602void ipath_uc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
603 int has_grh, void *data, u32 tlen, struct ipath_qp *qp);
604
605void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
606 int has_grh, void *data, u32 tlen, struct ipath_qp *qp);
607
608void ipath_restart_rc(struct ipath_qp *qp, u32 psn, struct ib_wc *wc);
609
610void ipath_ud_loopback(struct ipath_qp *sqp, struct ipath_sge_state *ss,
611 u32 length, struct ib_send_wr *wr, struct ib_wc *wc);
612
613int ipath_post_ud_send(struct ipath_qp *qp, struct ib_send_wr *wr);
614
615void ipath_ud_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
616 int has_grh, void *data, u32 tlen, struct ipath_qp *qp);
617
618int ipath_alloc_lkey(struct ipath_lkey_table *rkt,
619 struct ipath_mregion *mr);
620
621void ipath_free_lkey(struct ipath_lkey_table *rkt, u32 lkey);
622
623int ipath_lkey_ok(struct ipath_lkey_table *rkt, struct ipath_sge *isge,
624 struct ib_sge *sge, int acc);
625
626int ipath_rkey_ok(struct ipath_ibdev *dev, struct ipath_sge_state *ss,
627 u32 len, u64 vaddr, u32 rkey, int acc);
628
629int ipath_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
630 struct ib_recv_wr **bad_wr);
631
632struct ib_srq *ipath_create_srq(struct ib_pd *ibpd,
633 struct ib_srq_init_attr *srq_init_attr,
634 struct ib_udata *udata);
635
636int ipath_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
637 enum ib_srq_attr_mask attr_mask);
638
639int ipath_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
640
641int ipath_destroy_srq(struct ib_srq *ibsrq);
642
643void ipath_cq_enter(struct ipath_cq *cq, struct ib_wc *entry, int sig);
644
645int ipath_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
646
647struct ib_cq *ipath_create_cq(struct ib_device *ibdev, int entries,
648 struct ib_ucontext *context,
649 struct ib_udata *udata);
650
651int ipath_destroy_cq(struct ib_cq *ibcq);
652
653int ipath_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify notify);
654
655int ipath_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
656
657struct ib_mr *ipath_get_dma_mr(struct ib_pd *pd, int acc);
658
659struct ib_mr *ipath_reg_phys_mr(struct ib_pd *pd,
660 struct ib_phys_buf *buffer_list,
661 int num_phys_buf, int acc, u64 *iova_start);
662
663struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
664 int mr_access_flags,
665 struct ib_udata *udata);
666
667int ipath_dereg_mr(struct ib_mr *ibmr);
668
669struct ib_fmr *ipath_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
670 struct ib_fmr_attr *fmr_attr);
671
672int ipath_map_phys_fmr(struct ib_fmr *ibfmr, u64 * page_list,
673 int list_len, u64 iova);
674
675int ipath_unmap_fmr(struct list_head *fmr_list);
676
677int ipath_dealloc_fmr(struct ib_fmr *ibfmr);
678
679void ipath_no_bufs_available(struct ipath_qp *qp, struct ipath_ibdev *dev);
680
681void ipath_insert_rnr_queue(struct ipath_qp *qp);
682
683int ipath_get_rwqe(struct ipath_qp *qp, int wr_id_only);
684
685void ipath_ruc_loopback(struct ipath_qp *sqp, struct ib_wc *wc);
686
687extern const enum ib_wc_opcode ib_ipath_wc_opcode[];
688
689extern const u8 ipath_cvt_physportstate[];
690
691extern const int ib_ipath_state_ops[];
692
693extern unsigned int ib_ipath_lkey_table_size;
694
695extern const u32 ib_ipath_rnr_table[];
696
697#endif /* IPATH_VERBS_H */
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c b/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c
new file mode 100644
index 000000000000..10b31d2c4f20
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c
@@ -0,0 +1,333 @@
1/*
2 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/list.h>
34#include <linux/rcupdate.h>
35
36#include "ipath_verbs.h"
37
38/*
39 * Global table of GID to attached QPs.
40 * The table is global to all ipath devices since a send from one QP/device
41 * needs to be locally routed to any locally attached QPs on the same
42 * or different device.
43 */
44static struct rb_root mcast_tree;
45static DEFINE_SPINLOCK(mcast_lock);
46
47/**
48 * ipath_mcast_qp_alloc - alloc a struct to link a QP to mcast GID struct
49 * @qp: the QP to link
50 */
51static struct ipath_mcast_qp *ipath_mcast_qp_alloc(struct ipath_qp *qp)
52{
53 struct ipath_mcast_qp *mqp;
54
55 mqp = kmalloc(sizeof *mqp, GFP_KERNEL);
56 if (!mqp)
57 goto bail;
58
59 mqp->qp = qp;
60 atomic_inc(&qp->refcount);
61
62bail:
63 return mqp;
64}
65
66static void ipath_mcast_qp_free(struct ipath_mcast_qp *mqp)
67{
68 struct ipath_qp *qp = mqp->qp;
69
70 /* Notify ipath_destroy_qp() if it is waiting. */
71 if (atomic_dec_and_test(&qp->refcount))
72 wake_up(&qp->wait);
73
74 kfree(mqp);
75}
76
77/**
78 * ipath_mcast_alloc - allocate the multicast GID structure
79 * @mgid: the multicast GID
80 *
81 * A list of QPs will be attached to this structure.
82 */
83static struct ipath_mcast *ipath_mcast_alloc(union ib_gid *mgid)
84{
85 struct ipath_mcast *mcast;
86
87 mcast = kmalloc(sizeof *mcast, GFP_KERNEL);
88 if (!mcast)
89 goto bail;
90
91 mcast->mgid = *mgid;
92 INIT_LIST_HEAD(&mcast->qp_list);
93 init_waitqueue_head(&mcast->wait);
94 atomic_set(&mcast->refcount, 0);
95
96bail:
97 return mcast;
98}
99
100static void ipath_mcast_free(struct ipath_mcast *mcast)
101{
102 struct ipath_mcast_qp *p, *tmp;
103
104 list_for_each_entry_safe(p, tmp, &mcast->qp_list, list)
105 ipath_mcast_qp_free(p);
106
107 kfree(mcast);
108}
109
110/**
111 * ipath_mcast_find - search the global table for the given multicast GID
112 * @mgid: the multicast GID to search for
113 *
114 * Returns NULL if not found.
115 *
116 * The caller is responsible for decrementing the reference count if found.
117 */
118struct ipath_mcast *ipath_mcast_find(union ib_gid *mgid)
119{
120 struct rb_node *n;
121 unsigned long flags;
122 struct ipath_mcast *mcast;
123
124 spin_lock_irqsave(&mcast_lock, flags);
125 n = mcast_tree.rb_node;
126 while (n) {
127 int ret;
128
129 mcast = rb_entry(n, struct ipath_mcast, rb_node);
130
131 ret = memcmp(mgid->raw, mcast->mgid.raw,
132 sizeof(union ib_gid));
133 if (ret < 0)
134 n = n->rb_left;
135 else if (ret > 0)
136 n = n->rb_right;
137 else {
138 atomic_inc(&mcast->refcount);
139 spin_unlock_irqrestore(&mcast_lock, flags);
140 goto bail;
141 }
142 }
143 spin_unlock_irqrestore(&mcast_lock, flags);
144
145 mcast = NULL;
146
147bail:
148 return mcast;
149}
150
151/**
152 * ipath_mcast_add - insert mcast GID into table and attach QP struct
153 * @mcast: the mcast GID table
154 * @mqp: the QP to attach
155 *
156 * Return zero if both were added. Return EEXIST if the GID was already in
157 * the table but the QP was added. Return ESRCH if the QP was already
158 * attached and neither structure was added.
159 */
160static int ipath_mcast_add(struct ipath_mcast *mcast,
161 struct ipath_mcast_qp *mqp)
162{
163 struct rb_node **n = &mcast_tree.rb_node;
164 struct rb_node *pn = NULL;
165 unsigned long flags;
166 int ret;
167
168 spin_lock_irqsave(&mcast_lock, flags);
169
170 while (*n) {
171 struct ipath_mcast *tmcast;
172 struct ipath_mcast_qp *p;
173
174 pn = *n;
175 tmcast = rb_entry(pn, struct ipath_mcast, rb_node);
176
177 ret = memcmp(mcast->mgid.raw, tmcast->mgid.raw,
178 sizeof(union ib_gid));
179 if (ret < 0) {
180 n = &pn->rb_left;
181 continue;
182 }
183 if (ret > 0) {
184 n = &pn->rb_right;
185 continue;
186 }
187
188 /* Search the QP list to see if this is already there. */
189 list_for_each_entry_rcu(p, &tmcast->qp_list, list) {
190 if (p->qp == mqp->qp) {
191 spin_unlock_irqrestore(&mcast_lock, flags);
192 ret = ESRCH;
193 goto bail;
194 }
195 }
196 list_add_tail_rcu(&mqp->list, &tmcast->qp_list);
197 spin_unlock_irqrestore(&mcast_lock, flags);
198 ret = EEXIST;
199 goto bail;
200 }
201
202 list_add_tail_rcu(&mqp->list, &mcast->qp_list);
203
204 atomic_inc(&mcast->refcount);
205 rb_link_node(&mcast->rb_node, pn, n);
206 rb_insert_color(&mcast->rb_node, &mcast_tree);
207
208 spin_unlock_irqrestore(&mcast_lock, flags);
209
210 ret = 0;
211
212bail:
213 return ret;
214}
215
216int ipath_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
217{
218 struct ipath_qp *qp = to_iqp(ibqp);
219 struct ipath_mcast *mcast;
220 struct ipath_mcast_qp *mqp;
221 int ret;
222
223 /*
224 * Allocate data structures since its better to do this outside of
225 * spin locks and it will most likely be needed.
226 */
227 mcast = ipath_mcast_alloc(gid);
228 if (mcast == NULL) {
229 ret = -ENOMEM;
230 goto bail;
231 }
232 mqp = ipath_mcast_qp_alloc(qp);
233 if (mqp == NULL) {
234 ipath_mcast_free(mcast);
235 ret = -ENOMEM;
236 goto bail;
237 }
238 switch (ipath_mcast_add(mcast, mqp)) {
239 case ESRCH:
240 /* Neither was used: can't attach the same QP twice. */
241 ipath_mcast_qp_free(mqp);
242 ipath_mcast_free(mcast);
243 ret = -EINVAL;
244 goto bail;
245 case EEXIST: /* The mcast wasn't used */
246 ipath_mcast_free(mcast);
247 break;
248 default:
249 break;
250 }
251
252 ret = 0;
253
254bail:
255 return ret;
256}
257
258int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
259{
260 struct ipath_qp *qp = to_iqp(ibqp);
261 struct ipath_mcast *mcast = NULL;
262 struct ipath_mcast_qp *p, *tmp;
263 struct rb_node *n;
264 unsigned long flags;
265 int last = 0;
266 int ret;
267
268 spin_lock_irqsave(&mcast_lock, flags);
269
270 /* Find the GID in the mcast table. */
271 n = mcast_tree.rb_node;
272 while (1) {
273 if (n == NULL) {
274 spin_unlock_irqrestore(&mcast_lock, flags);
275 ret = 0;
276 goto bail;
277 }
278
279 mcast = rb_entry(n, struct ipath_mcast, rb_node);
280 ret = memcmp(gid->raw, mcast->mgid.raw,
281 sizeof(union ib_gid));
282 if (ret < 0)
283 n = n->rb_left;
284 else if (ret > 0)
285 n = n->rb_right;
286 else
287 break;
288 }
289
290 /* Search the QP list. */
291 list_for_each_entry_safe(p, tmp, &mcast->qp_list, list) {
292 if (p->qp != qp)
293 continue;
294 /*
295 * We found it, so remove it, but don't poison the forward
296 * link until we are sure there are no list walkers.
297 */
298 list_del_rcu(&p->list);
299
300 /* If this was the last attached QP, remove the GID too. */
301 if (list_empty(&mcast->qp_list)) {
302 rb_erase(&mcast->rb_node, &mcast_tree);
303 last = 1;
304 }
305 break;
306 }
307
308 spin_unlock_irqrestore(&mcast_lock, flags);
309
310 if (p) {
311 /*
312 * Wait for any list walkers to finish before freeing the
313 * list element.
314 */
315 wait_event(mcast->wait, atomic_read(&mcast->refcount) <= 1);
316 ipath_mcast_qp_free(p);
317 }
318 if (last) {
319 atomic_dec(&mcast->refcount);
320 wait_event(mcast->wait, !atomic_read(&mcast->refcount));
321 ipath_mcast_free(mcast);
322 }
323
324 ret = 0;
325
326bail:
327 return ret;
328}
329
330int ipath_mcast_tree_empty(void)
331{
332 return mcast_tree.rb_node == NULL;
333}
diff --git a/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c b/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
new file mode 100644
index 000000000000..adc5322f15c1
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ipath_wc_x86_64.c
@@ -0,0 +1,157 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33/*
34 * This file is conditionally built on x86_64 only. Otherwise weak symbol
35 * versions of the functions exported from here are used.
36 */
37
38#include <linux/pci.h>
39#include <asm/mtrr.h>
40#include <asm/processor.h>
41
42#include "ipath_kernel.h"
43
44/**
45 * ipath_enable_wc - enable write combining for MMIO writes to the device
46 * @dd: infinipath device
47 *
48 * This routine is x86_64-specific; it twiddles the CPU's MTRRs to enable
49 * write combining.
50 */
51int ipath_enable_wc(struct ipath_devdata *dd)
52{
53 int ret = 0;
54 u64 pioaddr, piolen;
55 unsigned bits;
56 const unsigned long addr = pci_resource_start(dd->pcidev, 0);
57 const size_t len = pci_resource_len(dd->pcidev, 0);
58
59 /*
60 * Set the PIO buffers to be WCCOMB, so we get HT bursts to the
61 * chip. Linux (possibly the hardware) requires it to be on a power
62 * of 2 address matching the length (which has to be a power of 2).
63 * For rev1, that means the base address, for rev2, it will be just
64 * the PIO buffers themselves.
65 */
66 pioaddr = addr + dd->ipath_piobufbase;
67 piolen = (dd->ipath_piobcnt2k +
68 dd->ipath_piobcnt4k) *
69 ALIGN(dd->ipath_piobcnt2k +
70 dd->ipath_piobcnt4k, dd->ipath_palign);
71
72 for (bits = 0; !(piolen & (1ULL << bits)); bits++)
73 /* do nothing */ ;
74
75 if (piolen != (1ULL << bits)) {
76 piolen >>= bits;
77 while (piolen >>= 1)
78 bits++;
79 piolen = 1ULL << (bits + 1);
80 }
81 if (pioaddr & (piolen - 1)) {
82 u64 atmp;
83 ipath_dbg("pioaddr %llx not on right boundary for size "
84 "%llx, fixing\n",
85 (unsigned long long) pioaddr,
86 (unsigned long long) piolen);
87 atmp = pioaddr & ~(piolen - 1);
88 if (atmp < addr || (atmp + piolen) > (addr + len)) {
89 ipath_dev_err(dd, "No way to align address/size "
90 "(%llx/%llx), no WC mtrr\n",
91 (unsigned long long) atmp,
92 (unsigned long long) piolen << 1);
93 ret = -ENODEV;
94 } else {
95 ipath_dbg("changing WC base from %llx to %llx, "
96 "len from %llx to %llx\n",
97 (unsigned long long) pioaddr,
98 (unsigned long long) atmp,
99 (unsigned long long) piolen,
100 (unsigned long long) piolen << 1);
101 pioaddr = atmp;
102 piolen <<= 1;
103 }
104 }
105
106 if (!ret) {
107 int cookie;
108 ipath_cdbg(VERBOSE, "Setting mtrr for chip to WC "
109 "(addr %llx, len=0x%llx)\n",
110 (unsigned long long) pioaddr,
111 (unsigned long long) piolen);
112 cookie = mtrr_add(pioaddr, piolen, MTRR_TYPE_WRCOMB, 0);
113 if (cookie < 0) {
114 {
115 dev_info(&dd->pcidev->dev,
116 "mtrr_add() WC for PIO bufs "
117 "failed (%d)\n",
118 cookie);
119 ret = -EINVAL;
120 }
121 } else {
122 ipath_cdbg(VERBOSE, "Set mtrr for chip to WC, "
123 "cookie is %d\n", cookie);
124 dd->ipath_wc_cookie = cookie;
125 }
126 }
127
128 return ret;
129}
130
131/**
132 * ipath_disable_wc - disable write combining for MMIO writes to the device
133 * @dd: infinipath device
134 */
135void ipath_disable_wc(struct ipath_devdata *dd)
136{
137 if (dd->ipath_wc_cookie) {
138 ipath_cdbg(VERBOSE, "undoing WCCOMB on pio buffers\n");
139 mtrr_del(dd->ipath_wc_cookie, 0, 0);
140 dd->ipath_wc_cookie = 0;
141 }
142}
143
144/**
145 * ipath_unordered_wc - indicate whether write combining is ordered
146 *
147 * Because our performance depends on our ability to do write combining mmio
148 * writes in the most efficient way, we need to know if we are on an Intel
149 * or AMD x86_64 processor. AMD x86_64 processors flush WC buffers out in
150 * the order completed, and so no special flushing is required to get
151 * correct ordering. Intel processors, however, will flush write buffers
152 * out in "random" orders, and so explicit ordering is needed at times.
153 */
154int ipath_unordered_wc(void)
155{
156 return boot_cpu_data.x86_vendor != X86_VENDOR_AMD;
157}
diff --git a/drivers/infiniband/hw/ipath/ips_common.h b/drivers/infiniband/hw/ipath/ips_common.h
new file mode 100644
index 000000000000..410a764dfcef
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/ips_common.h
@@ -0,0 +1,263 @@
1#ifndef IPS_COMMON_H
2#define IPS_COMMON_H
3/*
4 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include "ipath_common.h"
36
37struct ipath_header {
38 /*
39 * Version - 4 bits, Port - 4 bits, TID - 10 bits and Offset -
40 * 14 bits before ECO change ~28 Dec 03. After that, Vers 4,
41 * Port 3, TID 11, offset 14.
42 */
43 __le32 ver_port_tid_offset;
44 __le16 chksum;
45 __le16 pkt_flags;
46};
47
48struct ips_message_header {
49 __be16 lrh[4];
50 __be32 bth[3];
51 /* fields below this point are in host byte order */
52 struct ipath_header iph;
53 __u8 sub_opcode;
54 __u8 flags;
55 __u16 src_rank;
56 /* 24 bits. The upper 8 bit is available for other use */
57 union {
58 struct {
59 unsigned ack_seq_num:24;
60 unsigned port:4;
61 unsigned unused:4;
62 };
63 __u32 ack_seq_num_org;
64 };
65 __u8 expected_tid_session_id;
66 __u8 tinylen; /* to aid MPI */
67 union {
68 __u16 tag; /* to aid MPI */
69 __u16 mqhdr; /* for PSM MQ */
70 };
71 union {
72 __u32 mpi[4]; /* to aid MPI */
73 __u32 data[4];
74 __u64 mq[2]; /* for PSM MQ */
75 struct {
76 __u16 mtu;
77 __u8 major_ver;
78 __u8 minor_ver;
79 __u32 not_used; //free
80 __u32 run_id;
81 __u32 client_ver;
82 };
83 };
84};
85
86struct ether_header {
87 __be16 lrh[4];
88 __be32 bth[3];
89 struct ipath_header iph;
90 __u8 sub_opcode;
91 __u8 cmd;
92 __be16 lid;
93 __u16 mac[3];
94 __u8 frag_num;
95 __u8 seq_num;
96 __le32 len;
97 /* MUST be of word size due to PIO write requirements */
98 __u32 csum;
99 __le16 csum_offset;
100 __le16 flags;
101 __u16 first_2_bytes;
102 __u8 unused[2]; /* currently unused */
103};
104
105/*
106 * The PIO buffer used for sending infinipath messages must only be written
107 * in 32-bit words, all the data must be written, and no writes can occur
108 * after the last word is written (which transfers "ownership" of the buffer
109 * to the chip and triggers the message to be sent).
110 * Since the Linux sk_buff structure can be recursive, non-aligned, and
111 * any number of bytes in each segment, we use the following structure
112 * to keep information about the overall state of the copy operation.
113 * This is used to save the information needed to store the checksum
114 * in the right place before sending the last word to the hardware and
115 * to buffer the last 0-3 bytes of non-word sized segments.
116 */
117struct copy_data_s {
118 struct ether_header *hdr;
119 /* addr of PIO buf to write csum to */
120 __u32 __iomem *csum_pio;
121 __u32 __iomem *to; /* addr of PIO buf to write data to */
122 __u32 device; /* which device to allocate PIO bufs from */
123 __s32 error; /* set if there is an error. */
124 __s32 extra; /* amount of data saved in u.buf below */
125 __u32 len; /* total length to send in bytes */
126 __u32 flen; /* frament length in words */
127 __u32 csum; /* partial IP checksum */
128 __u32 pos; /* position for partial checksum */
129 __u32 offset; /* offset to where data currently starts */
130 __s32 checksum_calc; /* set to 1 when csum has been calculated */
131 struct sk_buff *skb;
132 union {
133 __u32 w;
134 __u8 buf[4];
135 } u;
136};
137
138/* IB - LRH header consts */
139#define IPS_LRH_GRH 0x0003 /* 1. word of IB LRH - next header: GRH */
140#define IPS_LRH_BTH 0x0002 /* 1. word of IB LRH - next header: BTH */
141
142#define IPS_OFFSET 0
143
144/*
145 * defines the cut-off point between the header queue and eager/expected
146 * TID queue
147 */
148#define NUM_OF_EXTRA_WORDS_IN_HEADER_QUEUE \
149 ((sizeof(struct ips_message_header) - \
150 offsetof(struct ips_message_header, iph)) >> 2)
151
152/* OpCodes */
153#define OPCODE_IPS 0xC0
154#define OPCODE_ITH4X 0xC1
155
156/* OpCode 30 is use by stand-alone test programs */
157#define OPCODE_RAW_DATA 0xDE
158/* last OpCode (31) is reserved for test */
159#define OPCODE_TEST 0xDF
160
161/* sub OpCodes - ips */
162#define OPCODE_SEQ_DATA 0x01
163#define OPCODE_SEQ_CTRL 0x02
164
165#define OPCODE_SEQ_MQ_DATA 0x03
166#define OPCODE_SEQ_MQ_CTRL 0x04
167
168#define OPCODE_ACK 0x10
169#define OPCODE_NAK 0x11
170
171#define OPCODE_ERR_CHK 0x20
172#define OPCODE_ERR_CHK_PLS 0x21
173
174#define OPCODE_STARTUP 0x30
175#define OPCODE_STARTUP_ACK 0x31
176#define OPCODE_STARTUP_NAK 0x32
177
178#define OPCODE_STARTUP_EXT 0x34
179#define OPCODE_STARTUP_ACK_EXT 0x35
180#define OPCODE_STARTUP_NAK_EXT 0x36
181
182#define OPCODE_TIDS_RELEASE 0x40
183#define OPCODE_TIDS_RELEASE_CONFIRM 0x41
184
185#define OPCODE_CLOSE 0x50
186#define OPCODE_CLOSE_ACK 0x51
187/*
188 * like OPCODE_CLOSE, but no complaint if other side has already closed.
189 * Used when doing abort(), MPI_Abort(), etc.
190 */
191#define OPCODE_ABORT 0x52
192
193/* sub OpCodes - ith4x */
194#define OPCODE_ENCAP 0x81
195#define OPCODE_LID_ARP 0x82
196
197/* Receive Header Queue: receive type (from infinipath) */
198#define RCVHQ_RCV_TYPE_EXPECTED 0
199#define RCVHQ_RCV_TYPE_EAGER 1
200#define RCVHQ_RCV_TYPE_NON_KD 2
201#define RCVHQ_RCV_TYPE_ERROR 3
202
203/* misc. */
204#define SIZE_OF_CRC 1
205
206#define EAGER_TID_ID INFINIPATH_I_TID_MASK
207
208#define IPS_DEFAULT_P_KEY 0xFFFF
209
210#define IPS_PERMISSIVE_LID 0xFFFF
211#define IPS_MULTICAST_LID_BASE 0xC000
212
213#define IPS_AETH_CREDIT_SHIFT 24
214#define IPS_AETH_CREDIT_MASK 0x1F
215#define IPS_AETH_CREDIT_INVAL 0x1F
216
217#define IPS_PSN_MASK 0xFFFFFF
218#define IPS_MSN_MASK 0xFFFFFF
219#define IPS_QPN_MASK 0xFFFFFF
220#define IPS_MULTICAST_QPN 0xFFFFFF
221
222/* functions for extracting fields from rcvhdrq entries */
223static inline __u32 ips_get_hdr_err_flags(const __le32 * rbuf)
224{
225 return __le32_to_cpu(rbuf[1]);
226}
227
228static inline __u32 ips_get_index(const __le32 * rbuf)
229{
230 return (__le32_to_cpu(rbuf[0]) >> INFINIPATH_RHF_EGRINDEX_SHIFT)
231 & INFINIPATH_RHF_EGRINDEX_MASK;
232}
233
234static inline __u32 ips_get_rcv_type(const __le32 * rbuf)
235{
236 return (__le32_to_cpu(rbuf[0]) >> INFINIPATH_RHF_RCVTYPE_SHIFT)
237 & INFINIPATH_RHF_RCVTYPE_MASK;
238}
239
240static inline __u32 ips_get_length_in_bytes(const __le32 * rbuf)
241{
242 return ((__le32_to_cpu(rbuf[0]) >> INFINIPATH_RHF_LENGTH_SHIFT)
243 & INFINIPATH_RHF_LENGTH_MASK) << 2;
244}
245
246static inline void *ips_get_first_protocol_header(const __u32 * rbuf)
247{
248 return (void *)&rbuf[2];
249}
250
251static inline struct ips_message_header *ips_get_ips_header(const __u32 *
252 rbuf)
253{
254 return (struct ips_message_header *)&rbuf[2];
255}
256
257static inline __u32 ips_get_ipath_ver(__le32 hdrword)
258{
259 return (__le32_to_cpu(hdrword) >> INFINIPATH_I_VERS_SHIFT)
260 & INFINIPATH_I_VERS_MASK;
261}
262
263#endif /* IPS_COMMON_H */
diff --git a/drivers/infiniband/hw/ipath/verbs_debug.h b/drivers/infiniband/hw/ipath/verbs_debug.h
new file mode 100644
index 000000000000..40d693cf3f94
--- /dev/null
+++ b/drivers/infiniband/hw/ipath/verbs_debug.h
@@ -0,0 +1,107 @@
1/*
2 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef _VERBS_DEBUG_H
34#define _VERBS_DEBUG_H
35
36/*
37 * This file contains tracing code for the ib_ipath kernel module.
38 */
39#ifndef _VERBS_DEBUGGING /* tracing enabled or not */
40#define _VERBS_DEBUGGING 1
41#endif
42
43extern unsigned ib_ipath_debug;
44
45#define _VERBS_ERROR(fmt,...) \
46 do { \
47 printk(KERN_ERR "%s: " fmt, "ib_ipath", ##__VA_ARGS__); \
48 } while(0)
49
50#define _VERBS_UNIT_ERROR(unit,fmt,...) \
51 do { \
52 printk(KERN_ERR "%s: " fmt, "ib_ipath", ##__VA_ARGS__); \
53 } while(0)
54
55#if _VERBS_DEBUGGING
56
57/*
58 * Mask values for debugging. The scheme allows us to compile out any
59 * of the debug tracing stuff, and if compiled in, to enable or
60 * disable dynamically.
61 * This can be set at modprobe time also:
62 * modprobe ib_path ib_ipath_debug=3
63 */
64
65#define __VERBS_INFO 0x1 /* generic low verbosity stuff */
66#define __VERBS_DBG 0x2 /* generic debug */
67#define __VERBS_VDBG 0x4 /* verbose debug */
68#define __VERBS_SMADBG 0x8000 /* sma packet debug */
69
70#define _VERBS_INFO(fmt,...) \
71 do { \
72 if (unlikely(ib_ipath_debug&__VERBS_INFO)) \
73 printk(KERN_INFO "%s: " fmt,"ib_ipath", \
74 ##__VA_ARGS__); \
75 } while(0)
76
77#define _VERBS_DBG(fmt,...) \
78 do { \
79 if (unlikely(ib_ipath_debug&__VERBS_DBG)) \
80 printk(KERN_DEBUG "%s: " fmt, __func__, \
81 ##__VA_ARGS__); \
82 } while(0)
83
84#define _VERBS_VDBG(fmt,...) \
85 do { \
86 if (unlikely(ib_ipath_debug&__VERBS_VDBG)) \
87 printk(KERN_DEBUG "%s: " fmt, __func__, \
88 ##__VA_ARGS__); \
89 } while(0)
90
91#define _VERBS_SMADBG(fmt,...) \
92 do { \
93 if (unlikely(ib_ipath_debug&__VERBS_SMADBG)) \
94 printk(KERN_DEBUG "%s: " fmt, __func__, \
95 ##__VA_ARGS__); \
96 } while(0)
97
98#else /* ! _VERBS_DEBUGGING */
99
100#define _VERBS_INFO(fmt,...)
101#define _VERBS_DBG(fmt,...)
102#define _VERBS_VDBG(fmt,...)
103#define _VERBS_SMADBG(fmt,...)
104
105#endif /* _VERBS_DEBUGGING */
106
107#endif /* _VERBS_DEBUG_H */
diff --git a/drivers/infiniband/hw/mthca/Kconfig b/drivers/infiniband/hw/mthca/Kconfig
index e88be85b3d5c..9aa5a4468a75 100644
--- a/drivers/infiniband/hw/mthca/Kconfig
+++ b/drivers/infiniband/hw/mthca/Kconfig
@@ -7,10 +7,11 @@ config INFINIBAND_MTHCA
7 ("Tavor") and the MT25208 PCI Express HCA ("Arbel"). 7 ("Tavor") and the MT25208 PCI Express HCA ("Arbel").
8 8
9config INFINIBAND_MTHCA_DEBUG 9config INFINIBAND_MTHCA_DEBUG
10 bool "Verbose debugging output" 10 bool "Verbose debugging output" if EMBEDDED
11 depends on INFINIBAND_MTHCA 11 depends on INFINIBAND_MTHCA
12 default n 12 default y
13 ---help--- 13 ---help---
14 This option causes the mthca driver produce a bunch of debug 14 This option causes debugging code to be compiled into the
15 messages. Select this is you are developing the driver or 15 mthca driver. The output can be turned on via the
16 trying to diagnose a problem. 16 debug_level module parameter (which can also be set after
17 the driver is loaded through sysfs).
diff --git a/drivers/infiniband/hw/mthca/Makefile b/drivers/infiniband/hw/mthca/Makefile
index 47ec5a7cba0b..e388d95d0cf1 100644
--- a/drivers/infiniband/hw/mthca/Makefile
+++ b/drivers/infiniband/hw/mthca/Makefile
@@ -1,7 +1,3 @@
1ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
2EXTRA_CFLAGS += -DDEBUG
3endif
4
5obj-$(CONFIG_INFINIBAND_MTHCA) += ib_mthca.o 1obj-$(CONFIG_INFINIBAND_MTHCA) += ib_mthca.o
6 2
7ib_mthca-y := mthca_main.o mthca_cmd.o mthca_profile.o mthca_reset.o \ 3ib_mthca-y := mthca_main.o mthca_cmd.o mthca_profile.o mthca_reset.o \
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index f023d3936518..b12aa03be251 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -42,6 +42,20 @@
42 42
43#include "mthca_dev.h" 43#include "mthca_dev.h"
44 44
45enum {
46 MTHCA_RATE_TAVOR_FULL = 0,
47 MTHCA_RATE_TAVOR_1X = 1,
48 MTHCA_RATE_TAVOR_4X = 2,
49 MTHCA_RATE_TAVOR_1X_DDR = 3
50};
51
52enum {
53 MTHCA_RATE_MEMFREE_FULL = 0,
54 MTHCA_RATE_MEMFREE_QUARTER = 1,
55 MTHCA_RATE_MEMFREE_EIGHTH = 2,
56 MTHCA_RATE_MEMFREE_HALF = 3
57};
58
45struct mthca_av { 59struct mthca_av {
46 __be32 port_pd; 60 __be32 port_pd;
47 u8 reserved1; 61 u8 reserved1;
@@ -55,6 +69,90 @@ struct mthca_av {
55 __be32 dgid[4]; 69 __be32 dgid[4];
56}; 70};
57 71
72static enum ib_rate memfree_rate_to_ib(u8 mthca_rate, u8 port_rate)
73{
74 switch (mthca_rate) {
75 case MTHCA_RATE_MEMFREE_EIGHTH:
76 return mult_to_ib_rate(port_rate >> 3);
77 case MTHCA_RATE_MEMFREE_QUARTER:
78 return mult_to_ib_rate(port_rate >> 2);
79 case MTHCA_RATE_MEMFREE_HALF:
80 return mult_to_ib_rate(port_rate >> 1);
81 case MTHCA_RATE_MEMFREE_FULL:
82 default:
83 return mult_to_ib_rate(port_rate);
84 }
85}
86
87static enum ib_rate tavor_rate_to_ib(u8 mthca_rate, u8 port_rate)
88{
89 switch (mthca_rate) {
90 case MTHCA_RATE_TAVOR_1X: return IB_RATE_2_5_GBPS;
91 case MTHCA_RATE_TAVOR_1X_DDR: return IB_RATE_5_GBPS;
92 case MTHCA_RATE_TAVOR_4X: return IB_RATE_10_GBPS;
93 default: return port_rate;
94 }
95}
96
97enum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port)
98{
99 if (mthca_is_memfree(dev)) {
100 /* Handle old Arbel FW */
101 if (dev->limits.stat_rate_support == 0x3 && mthca_rate)
102 return IB_RATE_2_5_GBPS;
103
104 return memfree_rate_to_ib(mthca_rate, dev->rate[port - 1]);
105 } else
106 return tavor_rate_to_ib(mthca_rate, dev->rate[port - 1]);
107}
108
109static u8 ib_rate_to_memfree(u8 req_rate, u8 cur_rate)
110{
111 if (cur_rate <= req_rate)
112 return 0;
113
114 /*
115 * Inter-packet delay (IPD) to get from rate X down to a rate
116 * no more than Y is (X - 1) / Y.
117 */
118 switch ((cur_rate - 1) / req_rate) {
119 case 0: return MTHCA_RATE_MEMFREE_FULL;
120 case 1: return MTHCA_RATE_MEMFREE_HALF;
121 case 2: /* fall through */
122 case 3: return MTHCA_RATE_MEMFREE_QUARTER;
123 default: return MTHCA_RATE_MEMFREE_EIGHTH;
124 }
125}
126
127static u8 ib_rate_to_tavor(u8 static_rate)
128{
129 switch (static_rate) {
130 case IB_RATE_2_5_GBPS: return MTHCA_RATE_TAVOR_1X;
131 case IB_RATE_5_GBPS: return MTHCA_RATE_TAVOR_1X_DDR;
132 case IB_RATE_10_GBPS: return MTHCA_RATE_TAVOR_4X;
133 default: return MTHCA_RATE_TAVOR_FULL;
134 }
135}
136
137u8 mthca_get_rate(struct mthca_dev *dev, int static_rate, u8 port)
138{
139 u8 rate;
140
141 if (!static_rate || ib_rate_to_mult(static_rate) >= dev->rate[port - 1])
142 return 0;
143
144 if (mthca_is_memfree(dev))
145 rate = ib_rate_to_memfree(ib_rate_to_mult(static_rate),
146 dev->rate[port - 1]);
147 else
148 rate = ib_rate_to_tavor(static_rate);
149
150 if (!(dev->limits.stat_rate_support & (1 << rate)))
151 rate = 1;
152
153 return rate;
154}
155
58int mthca_create_ah(struct mthca_dev *dev, 156int mthca_create_ah(struct mthca_dev *dev,
59 struct mthca_pd *pd, 157 struct mthca_pd *pd,
60 struct ib_ah_attr *ah_attr, 158 struct ib_ah_attr *ah_attr,
@@ -107,7 +205,7 @@ on_hca_fail:
107 av->g_slid = ah_attr->src_path_bits; 205 av->g_slid = ah_attr->src_path_bits;
108 av->dlid = cpu_to_be16(ah_attr->dlid); 206 av->dlid = cpu_to_be16(ah_attr->dlid);
109 av->msg_sr = (3 << 4) | /* 2K message */ 207 av->msg_sr = (3 << 4) | /* 2K message */
110 ah_attr->static_rate; 208 mthca_get_rate(dev, ah_attr->static_rate, ah_attr->port_num);
111 av->sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28); 209 av->sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28);
112 if (ah_attr->ah_flags & IB_AH_GRH) { 210 if (ah_attr->ah_flags & IB_AH_GRH) {
113 av->g_slid |= 0x80; 211 av->g_slid |= 0x80;
@@ -265,7 +363,7 @@ int __devinit mthca_init_av_table(struct mthca_dev *dev)
265 return -ENOMEM; 363 return -ENOMEM;
266} 364}
267 365
268void __devexit mthca_cleanup_av_table(struct mthca_dev *dev) 366void mthca_cleanup_av_table(struct mthca_dev *dev)
269{ 367{
270 if (mthca_is_memfree(dev)) 368 if (mthca_is_memfree(dev))
271 return; 369 return;
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index 343eca507870..1985b5dfa481 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -965,6 +965,7 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
965 u32 *outbox; 965 u32 *outbox;
966 u8 field; 966 u8 field;
967 u16 size; 967 u16 size;
968 u16 stat_rate;
968 int err; 969 int err;
969 970
970#define QUERY_DEV_LIM_OUT_SIZE 0x100 971#define QUERY_DEV_LIM_OUT_SIZE 0x100
@@ -995,6 +996,7 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
995#define QUERY_DEV_LIM_MTU_WIDTH_OFFSET 0x36 996#define QUERY_DEV_LIM_MTU_WIDTH_OFFSET 0x36
996#define QUERY_DEV_LIM_VL_PORT_OFFSET 0x37 997#define QUERY_DEV_LIM_VL_PORT_OFFSET 0x37
997#define QUERY_DEV_LIM_MAX_GID_OFFSET 0x3b 998#define QUERY_DEV_LIM_MAX_GID_OFFSET 0x3b
999#define QUERY_DEV_LIM_RATE_SUPPORT_OFFSET 0x3c
998#define QUERY_DEV_LIM_MAX_PKEY_OFFSET 0x3f 1000#define QUERY_DEV_LIM_MAX_PKEY_OFFSET 0x3f
999#define QUERY_DEV_LIM_FLAGS_OFFSET 0x44 1001#define QUERY_DEV_LIM_FLAGS_OFFSET 0x44
1000#define QUERY_DEV_LIM_RSVD_UAR_OFFSET 0x48 1002#define QUERY_DEV_LIM_RSVD_UAR_OFFSET 0x48
@@ -1086,6 +1088,8 @@ int mthca_QUERY_DEV_LIM(struct mthca_dev *dev,
1086 dev_lim->num_ports = field & 0xf; 1088 dev_lim->num_ports = field & 0xf;
1087 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_GID_OFFSET); 1089 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_GID_OFFSET);
1088 dev_lim->max_gids = 1 << (field & 0xf); 1090 dev_lim->max_gids = 1 << (field & 0xf);
1091 MTHCA_GET(stat_rate, outbox, QUERY_DEV_LIM_RATE_SUPPORT_OFFSET);
1092 dev_lim->stat_rate_support = stat_rate;
1089 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PKEY_OFFSET); 1093 MTHCA_GET(field, outbox, QUERY_DEV_LIM_MAX_PKEY_OFFSET);
1090 dev_lim->max_pkeys = 1 << (field & 0xf); 1094 dev_lim->max_pkeys = 1 << (field & 0xf);
1091 MTHCA_GET(dev_lim->flags, outbox, QUERY_DEV_LIM_FLAGS_OFFSET); 1095 MTHCA_GET(dev_lim->flags, outbox, QUERY_DEV_LIM_FLAGS_OFFSET);
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.h b/drivers/infiniband/hw/mthca/mthca_cmd.h
index e4ec35c40dd3..2f976f2051d6 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.h
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.h
@@ -146,6 +146,7 @@ struct mthca_dev_lim {
146 int max_vl; 146 int max_vl;
147 int num_ports; 147 int num_ports;
148 int max_gids; 148 int max_gids;
149 u16 stat_rate_support;
149 int max_pkeys; 150 int max_pkeys;
150 u32 flags; 151 u32 flags;
151 int reserved_uars; 152 int reserved_uars;
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index 76aabc5bf371..312cf90731ea 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -973,7 +973,7 @@ int __devinit mthca_init_cq_table(struct mthca_dev *dev)
973 return err; 973 return err;
974} 974}
975 975
976void __devexit mthca_cleanup_cq_table(struct mthca_dev *dev) 976void mthca_cleanup_cq_table(struct mthca_dev *dev)
977{ 977{
978 mthca_array_cleanup(&dev->cq_table.cq, dev->limits.num_cqs); 978 mthca_array_cleanup(&dev->cq_table.cq, dev->limits.num_cqs);
979 mthca_alloc_cleanup(&dev->cq_table.alloc); 979 mthca_alloc_cleanup(&dev->cq_table.alloc);
diff --git a/drivers/infiniband/hw/mthca/mthca_dev.h b/drivers/infiniband/hw/mthca/mthca_dev.h
index ad52edbefe98..4c1dcb4c1822 100644
--- a/drivers/infiniband/hw/mthca/mthca_dev.h
+++ b/drivers/infiniband/hw/mthca/mthca_dev.h
@@ -151,6 +151,7 @@ struct mthca_limits {
151 int reserved_qps; 151 int reserved_qps;
152 int num_srqs; 152 int num_srqs;
153 int max_srq_wqes; 153 int max_srq_wqes;
154 int max_srq_sge;
154 int reserved_srqs; 155 int reserved_srqs;
155 int num_eecs; 156 int num_eecs;
156 int reserved_eecs; 157 int reserved_eecs;
@@ -172,6 +173,7 @@ struct mthca_limits {
172 int reserved_pds; 173 int reserved_pds;
173 u32 page_size_cap; 174 u32 page_size_cap;
174 u32 flags; 175 u32 flags;
176 u16 stat_rate_support;
175 u8 port_width_cap; 177 u8 port_width_cap;
176}; 178};
177 179
@@ -353,10 +355,24 @@ struct mthca_dev {
353 struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2]; 355 struct ib_mad_agent *send_agent[MTHCA_MAX_PORTS][2];
354 struct ib_ah *sm_ah[MTHCA_MAX_PORTS]; 356 struct ib_ah *sm_ah[MTHCA_MAX_PORTS];
355 spinlock_t sm_lock; 357 spinlock_t sm_lock;
358 u8 rate[MTHCA_MAX_PORTS];
356}; 359};
357 360
358#define mthca_dbg(mdev, format, arg...) \ 361#ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
359 dev_dbg(&mdev->pdev->dev, format, ## arg) 362extern int mthca_debug_level;
363
364#define mthca_dbg(mdev, format, arg...) \
365 do { \
366 if (mthca_debug_level) \
367 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
368 } while (0)
369
370#else /* CONFIG_INFINIBAND_MTHCA_DEBUG */
371
372#define mthca_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
373
374#endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
375
360#define mthca_err(mdev, format, arg...) \ 376#define mthca_err(mdev, format, arg...) \
361 dev_err(&mdev->pdev->dev, format, ## arg) 377 dev_err(&mdev->pdev->dev, format, ## arg)
362#define mthca_info(mdev, format, arg...) \ 378#define mthca_info(mdev, format, arg...) \
@@ -492,6 +508,7 @@ void mthca_free_srq(struct mthca_dev *dev, struct mthca_srq *srq);
492int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 508int mthca_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
493 enum ib_srq_attr_mask attr_mask); 509 enum ib_srq_attr_mask attr_mask);
494int mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr); 510int mthca_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
511int mthca_max_srq_sge(struct mthca_dev *dev);
495void mthca_srq_event(struct mthca_dev *dev, u32 srqn, 512void mthca_srq_event(struct mthca_dev *dev, u32 srqn,
496 enum ib_event_type event_type); 513 enum ib_event_type event_type);
497void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr); 514void mthca_free_srq_wqe(struct mthca_srq *srq, u32 wqe_addr);
@@ -542,6 +559,8 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
542 struct ib_ud_header *header); 559 struct ib_ud_header *header);
543int mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr); 560int mthca_ah_query(struct ib_ah *ibah, struct ib_ah_attr *attr);
544int mthca_ah_grh_present(struct mthca_ah *ah); 561int mthca_ah_grh_present(struct mthca_ah *ah);
562u8 mthca_get_rate(struct mthca_dev *dev, int static_rate, u8 port);
563enum ib_rate mthca_rate_to_ib(struct mthca_dev *dev, u8 mthca_rate, u8 port);
545 564
546int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 565int mthca_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
547int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid); 566int mthca_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
diff --git a/drivers/infiniband/hw/mthca/mthca_eq.c b/drivers/infiniband/hw/mthca/mthca_eq.c
index cbdc348fb689..99f109c3815d 100644
--- a/drivers/infiniband/hw/mthca/mthca_eq.c
+++ b/drivers/infiniband/hw/mthca/mthca_eq.c
@@ -765,7 +765,7 @@ static int __devinit mthca_map_eq_regs(struct mthca_dev *dev)
765 765
766} 766}
767 767
768static void __devexit mthca_unmap_eq_regs(struct mthca_dev *dev) 768static void mthca_unmap_eq_regs(struct mthca_dev *dev)
769{ 769{
770 if (mthca_is_memfree(dev)) { 770 if (mthca_is_memfree(dev)) {
771 mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) & 771 mthca_unmap_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
@@ -821,7 +821,7 @@ int __devinit mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt)
821 return ret; 821 return ret;
822} 822}
823 823
824void __devexit mthca_unmap_eq_icm(struct mthca_dev *dev) 824void mthca_unmap_eq_icm(struct mthca_dev *dev)
825{ 825{
826 u8 status; 826 u8 status;
827 827
@@ -954,7 +954,7 @@ err_out_free:
954 return err; 954 return err;
955} 955}
956 956
957void __devexit mthca_cleanup_eq_table(struct mthca_dev *dev) 957void mthca_cleanup_eq_table(struct mthca_dev *dev)
958{ 958{
959 u8 status; 959 u8 status;
960 int i; 960 int i;
diff --git a/drivers/infiniband/hw/mthca/mthca_mad.c b/drivers/infiniband/hw/mthca/mthca_mad.c
index 4ace6a392f41..f235c7ea42f0 100644
--- a/drivers/infiniband/hw/mthca/mthca_mad.c
+++ b/drivers/infiniband/hw/mthca/mthca_mad.c
@@ -49,6 +49,30 @@ enum {
49 MTHCA_VENDOR_CLASS2 = 0xa 49 MTHCA_VENDOR_CLASS2 = 0xa
50}; 50};
51 51
52int mthca_update_rate(struct mthca_dev *dev, u8 port_num)
53{
54 struct ib_port_attr *tprops = NULL;
55 int ret;
56
57 tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
58 if (!tprops)
59 return -ENOMEM;
60
61 ret = ib_query_port(&dev->ib_dev, port_num, tprops);
62 if (ret) {
63 printk(KERN_WARNING "ib_query_port failed (%d) for %s port %d\n",
64 ret, dev->ib_dev.name, port_num);
65 goto out;
66 }
67
68 dev->rate[port_num - 1] = tprops->active_speed *
69 ib_width_enum_to_int(tprops->active_width);
70
71out:
72 kfree(tprops);
73 return ret;
74}
75
52static void update_sm_ah(struct mthca_dev *dev, 76static void update_sm_ah(struct mthca_dev *dev,
53 u8 port_num, u16 lid, u8 sl) 77 u8 port_num, u16 lid, u8 sl)
54{ 78{
@@ -90,6 +114,7 @@ static void smp_snoop(struct ib_device *ibdev,
90 mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) && 114 mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
91 mad->mad_hdr.method == IB_MGMT_METHOD_SET) { 115 mad->mad_hdr.method == IB_MGMT_METHOD_SET) {
92 if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO) { 116 if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO) {
117 mthca_update_rate(to_mdev(ibdev), port_num);
93 update_sm_ah(to_mdev(ibdev), port_num, 118 update_sm_ah(to_mdev(ibdev), port_num,
94 be16_to_cpup((__be16 *) (mad->data + 58)), 119 be16_to_cpup((__be16 *) (mad->data + 58)),
95 (*(u8 *) (mad->data + 76)) & 0xf); 120 (*(u8 *) (mad->data + 76)) & 0xf);
@@ -246,6 +271,7 @@ int mthca_create_agents(struct mthca_dev *dev)
246{ 271{
247 struct ib_mad_agent *agent; 272 struct ib_mad_agent *agent;
248 int p, q; 273 int p, q;
274 int ret;
249 275
250 spin_lock_init(&dev->sm_lock); 276 spin_lock_init(&dev->sm_lock);
251 277
@@ -255,11 +281,23 @@ int mthca_create_agents(struct mthca_dev *dev)
255 q ? IB_QPT_GSI : IB_QPT_SMI, 281 q ? IB_QPT_GSI : IB_QPT_SMI,
256 NULL, 0, send_handler, 282 NULL, 0, send_handler,
257 NULL, NULL); 283 NULL, NULL);
258 if (IS_ERR(agent)) 284 if (IS_ERR(agent)) {
285 ret = PTR_ERR(agent);
259 goto err; 286 goto err;
287 }
260 dev->send_agent[p][q] = agent; 288 dev->send_agent[p][q] = agent;
261 } 289 }
262 290
291
292 for (p = 1; p <= dev->limits.num_ports; ++p) {
293 ret = mthca_update_rate(dev, p);
294 if (ret) {
295 mthca_err(dev, "Failed to obtain port %d rate."
296 " aborting.\n", p);
297 goto err;
298 }
299 }
300
263 return 0; 301 return 0;
264 302
265err: 303err:
@@ -268,10 +306,10 @@ err:
268 if (dev->send_agent[p][q]) 306 if (dev->send_agent[p][q])
269 ib_unregister_mad_agent(dev->send_agent[p][q]); 307 ib_unregister_mad_agent(dev->send_agent[p][q]);
270 308
271 return PTR_ERR(agent); 309 return ret;
272} 310}
273 311
274void mthca_free_agents(struct mthca_dev *dev) 312void __devexit mthca_free_agents(struct mthca_dev *dev)
275{ 313{
276 struct ib_mad_agent *agent; 314 struct ib_mad_agent *agent;
277 int p, q; 315 int p, q;
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 266f347c6707..9b9ff7bff357 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -52,6 +52,14 @@ MODULE_DESCRIPTION("Mellanox InfiniBand HCA low-level driver");
52MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_VERSION(DRV_VERSION); 53MODULE_VERSION(DRV_VERSION);
54 54
55#ifdef CONFIG_INFINIBAND_MTHCA_DEBUG
56
57int mthca_debug_level = 0;
58module_param_named(debug_level, mthca_debug_level, int, 0644);
59MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
60
61#endif /* CONFIG_INFINIBAND_MTHCA_DEBUG */
62
55#ifdef CONFIG_PCI_MSI 63#ifdef CONFIG_PCI_MSI
56 64
57static int msi_x = 0; 65static int msi_x = 0;
@@ -69,6 +77,10 @@ MODULE_PARM_DESC(msi, "attempt to use MSI if nonzero");
69 77
70#endif /* CONFIG_PCI_MSI */ 78#endif /* CONFIG_PCI_MSI */
71 79
80static int tune_pci = 0;
81module_param(tune_pci, int, 0444);
82MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
83
72static const char mthca_version[] __devinitdata = 84static const char mthca_version[] __devinitdata =
73 DRV_NAME ": Mellanox InfiniBand HCA driver v" 85 DRV_NAME ": Mellanox InfiniBand HCA driver v"
74 DRV_VERSION " (" DRV_RELDATE ")\n"; 86 DRV_VERSION " (" DRV_RELDATE ")\n";
@@ -90,6 +102,9 @@ static int __devinit mthca_tune_pci(struct mthca_dev *mdev)
90 int cap; 102 int cap;
91 u16 val; 103 u16 val;
92 104
105 if (!tune_pci)
106 return 0;
107
93 /* First try to max out Read Byte Count */ 108 /* First try to max out Read Byte Count */
94 cap = pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX); 109 cap = pci_find_capability(mdev->pdev, PCI_CAP_ID_PCIX);
95 if (cap) { 110 if (cap) {
@@ -176,6 +191,7 @@ static int __devinit mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim
176 mdev->limits.reserved_srqs = dev_lim->reserved_srqs; 191 mdev->limits.reserved_srqs = dev_lim->reserved_srqs;
177 mdev->limits.reserved_eecs = dev_lim->reserved_eecs; 192 mdev->limits.reserved_eecs = dev_lim->reserved_eecs;
178 mdev->limits.max_desc_sz = dev_lim->max_desc_sz; 193 mdev->limits.max_desc_sz = dev_lim->max_desc_sz;
194 mdev->limits.max_srq_sge = mthca_max_srq_sge(mdev);
179 /* 195 /*
180 * Subtract 1 from the limit because we need to allocate a 196 * Subtract 1 from the limit because we need to allocate a
181 * spare CQE so the HCA HW can tell the difference between an 197 * spare CQE so the HCA HW can tell the difference between an
@@ -191,6 +207,18 @@ static int __devinit mthca_dev_lim(struct mthca_dev *mdev, struct mthca_dev_lim
191 mdev->limits.port_width_cap = dev_lim->max_port_width; 207 mdev->limits.port_width_cap = dev_lim->max_port_width;
192 mdev->limits.page_size_cap = ~(u32) (dev_lim->min_page_sz - 1); 208 mdev->limits.page_size_cap = ~(u32) (dev_lim->min_page_sz - 1);
193 mdev->limits.flags = dev_lim->flags; 209 mdev->limits.flags = dev_lim->flags;
210 /*
211 * For old FW that doesn't return static rate support, use a
212 * value of 0x3 (only static rate values of 0 or 1 are handled),
213 * except on Sinai, where even old FW can handle static rate
214 * values of 2 and 3.
215 */
216 if (dev_lim->stat_rate_support)
217 mdev->limits.stat_rate_support = dev_lim->stat_rate_support;
218 else if (mdev->mthca_flags & MTHCA_FLAG_SINAI_OPT)
219 mdev->limits.stat_rate_support = 0xf;
220 else
221 mdev->limits.stat_rate_support = 0x3;
194 222
195 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver. 223 /* IB_DEVICE_RESIZE_MAX_WR not supported by driver.
196 May be doable since hardware supports it for SRQ. 224 May be doable since hardware supports it for SRQ.
diff --git a/drivers/infiniband/hw/mthca/mthca_mcg.c b/drivers/infiniband/hw/mthca/mthca_mcg.c
index 9965bda9afed..47ca8a9b7247 100644
--- a/drivers/infiniband/hw/mthca/mthca_mcg.c
+++ b/drivers/infiniband/hw/mthca/mthca_mcg.c
@@ -388,7 +388,7 @@ int __devinit mthca_init_mcg_table(struct mthca_dev *dev)
388 return 0; 388 return 0;
389} 389}
390 390
391void __devexit mthca_cleanup_mcg_table(struct mthca_dev *dev) 391void mthca_cleanup_mcg_table(struct mthca_dev *dev)
392{ 392{
393 mthca_alloc_cleanup(&dev->mcg_table.alloc); 393 mthca_alloc_cleanup(&dev->mcg_table.alloc);
394} 394}
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index 698b62125765..25e1c1db9a40 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -170,7 +170,7 @@ err_out:
170 return -ENOMEM; 170 return -ENOMEM;
171} 171}
172 172
173static void __devexit mthca_buddy_cleanup(struct mthca_buddy *buddy) 173static void mthca_buddy_cleanup(struct mthca_buddy *buddy)
174{ 174{
175 int i; 175 int i;
176 176
@@ -866,7 +866,7 @@ err_mtt_buddy:
866 return err; 866 return err;
867} 867}
868 868
869void __devexit mthca_cleanup_mr_table(struct mthca_dev *dev) 869void mthca_cleanup_mr_table(struct mthca_dev *dev)
870{ 870{
871 /* XXX check if any MRs are still allocated? */ 871 /* XXX check if any MRs are still allocated? */
872 if (dev->limits.fmr_reserved_mtts) 872 if (dev->limits.fmr_reserved_mtts)
diff --git a/drivers/infiniband/hw/mthca/mthca_pd.c b/drivers/infiniband/hw/mthca/mthca_pd.c
index 105fc5faaddf..59df51614c85 100644
--- a/drivers/infiniband/hw/mthca/mthca_pd.c
+++ b/drivers/infiniband/hw/mthca/mthca_pd.c
@@ -77,7 +77,7 @@ int __devinit mthca_init_pd_table(struct mthca_dev *dev)
77 dev->limits.reserved_pds); 77 dev->limits.reserved_pds);
78} 78}
79 79
80void __devexit mthca_cleanup_pd_table(struct mthca_dev *dev) 80void mthca_cleanup_pd_table(struct mthca_dev *dev)
81{ 81{
82 /* XXX check if any PDs are still allocated? */ 82 /* XXX check if any PDs are still allocated? */
83 mthca_alloc_cleanup(&dev->pd_table.alloc); 83 mthca_alloc_cleanup(&dev->pd_table.alloc);
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 2c250bc11c33..565a24b1756f 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -106,7 +106,7 @@ static int mthca_query_device(struct ib_device *ibdev,
106 props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp; 106 props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
107 props->max_srq = mdev->limits.num_srqs - mdev->limits.reserved_srqs; 107 props->max_srq = mdev->limits.num_srqs - mdev->limits.reserved_srqs;
108 props->max_srq_wr = mdev->limits.max_srq_wqes; 108 props->max_srq_wr = mdev->limits.max_srq_wqes;
109 props->max_srq_sge = mdev->limits.max_sg; 109 props->max_srq_sge = mdev->limits.max_srq_sge;
110 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay; 110 props->local_ca_ack_delay = mdev->limits.local_ca_ack_delay;
111 props->atomic_cap = mdev->limits.flags & DEV_LIM_FLAG_ATOMIC ? 111 props->atomic_cap = mdev->limits.flags & DEV_LIM_FLAG_ATOMIC ?
112 IB_ATOMIC_HCA : IB_ATOMIC_NONE; 112 IB_ATOMIC_HCA : IB_ATOMIC_NONE;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 2e7f52136965..6676a786d690 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -257,6 +257,8 @@ struct mthca_qp {
257 atomic_t refcount; 257 atomic_t refcount;
258 u32 qpn; 258 u32 qpn;
259 int is_direct; 259 int is_direct;
260 u8 port; /* for SQP and memfree use only */
261 u8 alt_port; /* for memfree use only */
260 u8 transport; 262 u8 transport;
261 u8 state; 263 u8 state;
262 u8 atomic_rd_en; 264 u8 atomic_rd_en;
@@ -278,7 +280,6 @@ struct mthca_qp {
278 280
279struct mthca_sqp { 281struct mthca_sqp {
280 struct mthca_qp qp; 282 struct mthca_qp qp;
281 int port;
282 int pkey_index; 283 int pkey_index;
283 u32 qkey; 284 u32 qkey;
284 u32 send_psn; 285 u32 send_psn;
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 1bc2678c2fae..f37b0e367323 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -248,6 +248,9 @@ void mthca_qp_event(struct mthca_dev *dev, u32 qpn,
248 return; 248 return;
249 } 249 }
250 250
251 if (event_type == IB_EVENT_PATH_MIG)
252 qp->port = qp->alt_port;
253
251 event.device = &dev->ib_dev; 254 event.device = &dev->ib_dev;
252 event.event = event_type; 255 event.event = event_type;
253 event.element.qp = &qp->ibqp; 256 event.element.qp = &qp->ibqp;
@@ -392,10 +395,16 @@ static void to_ib_ah_attr(struct mthca_dev *dev, struct ib_ah_attr *ib_ah_attr,
392{ 395{
393 memset(ib_ah_attr, 0, sizeof *path); 396 memset(ib_ah_attr, 0, sizeof *path);
394 ib_ah_attr->port_num = (be32_to_cpu(path->port_pkey) >> 24) & 0x3; 397 ib_ah_attr->port_num = (be32_to_cpu(path->port_pkey) >> 24) & 0x3;
398
399 if (ib_ah_attr->port_num == 0 || ib_ah_attr->port_num > dev->limits.num_ports)
400 return;
401
395 ib_ah_attr->dlid = be16_to_cpu(path->rlid); 402 ib_ah_attr->dlid = be16_to_cpu(path->rlid);
396 ib_ah_attr->sl = be32_to_cpu(path->sl_tclass_flowlabel) >> 28; 403 ib_ah_attr->sl = be32_to_cpu(path->sl_tclass_flowlabel) >> 28;
397 ib_ah_attr->src_path_bits = path->g_mylmc & 0x7f; 404 ib_ah_attr->src_path_bits = path->g_mylmc & 0x7f;
398 ib_ah_attr->static_rate = path->static_rate & 0x7; 405 ib_ah_attr->static_rate = mthca_rate_to_ib(dev,
406 path->static_rate & 0x7,
407 ib_ah_attr->port_num);
399 ib_ah_attr->ah_flags = (path->g_mylmc & (1 << 7)) ? IB_AH_GRH : 0; 408 ib_ah_attr->ah_flags = (path->g_mylmc & (1 << 7)) ? IB_AH_GRH : 0;
400 if (ib_ah_attr->ah_flags) { 409 if (ib_ah_attr->ah_flags) {
401 ib_ah_attr->grh.sgid_index = path->mgid_index & (dev->limits.gid_table_len - 1); 410 ib_ah_attr->grh.sgid_index = path->mgid_index & (dev->limits.gid_table_len - 1);
@@ -455,8 +464,10 @@ int mthca_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_m
455 qp_attr->cap.max_recv_sge = qp->rq.max_gs; 464 qp_attr->cap.max_recv_sge = qp->rq.max_gs;
456 qp_attr->cap.max_inline_data = qp->max_inline_data; 465 qp_attr->cap.max_inline_data = qp->max_inline_data;
457 466
458 to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path); 467 if (qp->transport == RC || qp->transport == UC) {
459 to_ib_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path); 468 to_ib_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path);
469 to_ib_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path);
470 }
460 471
461 qp_attr->pkey_index = be32_to_cpu(context->pri_path.port_pkey) & 0x7f; 472 qp_attr->pkey_index = be32_to_cpu(context->pri_path.port_pkey) & 0x7f;
462 qp_attr->alt_pkey_index = be32_to_cpu(context->alt_path.port_pkey) & 0x7f; 473 qp_attr->alt_pkey_index = be32_to_cpu(context->alt_path.port_pkey) & 0x7f;
@@ -484,11 +495,11 @@ out:
484} 495}
485 496
486static int mthca_path_set(struct mthca_dev *dev, struct ib_ah_attr *ah, 497static int mthca_path_set(struct mthca_dev *dev, struct ib_ah_attr *ah,
487 struct mthca_qp_path *path) 498 struct mthca_qp_path *path, u8 port)
488{ 499{
489 path->g_mylmc = ah->src_path_bits & 0x7f; 500 path->g_mylmc = ah->src_path_bits & 0x7f;
490 path->rlid = cpu_to_be16(ah->dlid); 501 path->rlid = cpu_to_be16(ah->dlid);
491 path->static_rate = !!ah->static_rate; 502 path->static_rate = mthca_get_rate(dev, ah->static_rate, port);
492 503
493 if (ah->ah_flags & IB_AH_GRH) { 504 if (ah->ah_flags & IB_AH_GRH) {
494 if (ah->grh.sgid_index >= dev->limits.gid_table_len) { 505 if (ah->grh.sgid_index >= dev->limits.gid_table_len) {
@@ -634,7 +645,7 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
634 645
635 if (qp->transport == MLX) 646 if (qp->transport == MLX)
636 qp_context->pri_path.port_pkey |= 647 qp_context->pri_path.port_pkey |=
637 cpu_to_be32(to_msqp(qp)->port << 24); 648 cpu_to_be32(qp->port << 24);
638 else { 649 else {
639 if (attr_mask & IB_QP_PORT) { 650 if (attr_mask & IB_QP_PORT) {
640 qp_context->pri_path.port_pkey |= 651 qp_context->pri_path.port_pkey |=
@@ -657,7 +668,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
657 } 668 }
658 669
659 if (attr_mask & IB_QP_AV) { 670 if (attr_mask & IB_QP_AV) {
660 if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path)) 671 if (mthca_path_set(dev, &attr->ah_attr, &qp_context->pri_path,
672 attr_mask & IB_QP_PORT ? attr->port_num : qp->port))
661 return -EINVAL; 673 return -EINVAL;
662 674
663 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH); 675 qp_param->opt_param_mask |= cpu_to_be32(MTHCA_QP_OPTPAR_PRIMARY_ADDR_PATH);
@@ -681,7 +693,8 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
681 return -EINVAL; 693 return -EINVAL;
682 } 694 }
683 695
684 if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path)) 696 if (mthca_path_set(dev, &attr->alt_ah_attr, &qp_context->alt_path,
697 attr->alt_ah_attr.port_num))
685 return -EINVAL; 698 return -EINVAL;
686 699
687 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index | 700 qp_context->alt_path.port_pkey |= cpu_to_be32(attr->alt_pkey_index |
@@ -791,6 +804,10 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
791 qp->atomic_rd_en = attr->qp_access_flags; 804 qp->atomic_rd_en = attr->qp_access_flags;
792 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) 805 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
793 qp->resp_depth = attr->max_dest_rd_atomic; 806 qp->resp_depth = attr->max_dest_rd_atomic;
807 if (attr_mask & IB_QP_PORT)
808 qp->port = attr->port_num;
809 if (attr_mask & IB_QP_ALT_PATH)
810 qp->alt_port = attr->alt_port_num;
794 811
795 if (is_sqp(dev, qp)) 812 if (is_sqp(dev, qp))
796 store_attrs(to_msqp(qp), attr, attr_mask); 813 store_attrs(to_msqp(qp), attr, attr_mask);
@@ -802,13 +819,13 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask)
802 if (is_qp0(dev, qp)) { 819 if (is_qp0(dev, qp)) {
803 if (cur_state != IB_QPS_RTR && 820 if (cur_state != IB_QPS_RTR &&
804 new_state == IB_QPS_RTR) 821 new_state == IB_QPS_RTR)
805 init_port(dev, to_msqp(qp)->port); 822 init_port(dev, qp->port);
806 823
807 if (cur_state != IB_QPS_RESET && 824 if (cur_state != IB_QPS_RESET &&
808 cur_state != IB_QPS_ERR && 825 cur_state != IB_QPS_ERR &&
809 (new_state == IB_QPS_RESET || 826 (new_state == IB_QPS_RESET ||
810 new_state == IB_QPS_ERR)) 827 new_state == IB_QPS_ERR))
811 mthca_CLOSE_IB(dev, to_msqp(qp)->port, &status); 828 mthca_CLOSE_IB(dev, qp->port, &status);
812 } 829 }
813 830
814 /* 831 /*
@@ -1212,6 +1229,9 @@ int mthca_alloc_qp(struct mthca_dev *dev,
1212 if (qp->qpn == -1) 1229 if (qp->qpn == -1)
1213 return -ENOMEM; 1230 return -ENOMEM;
1214 1231
1232 /* initialize port to zero for error-catching. */
1233 qp->port = 0;
1234
1215 err = mthca_alloc_qp_common(dev, pd, send_cq, recv_cq, 1235 err = mthca_alloc_qp_common(dev, pd, send_cq, recv_cq,
1216 send_policy, qp); 1236 send_policy, qp);
1217 if (err) { 1237 if (err) {
@@ -1261,7 +1281,7 @@ int mthca_alloc_sqp(struct mthca_dev *dev,
1261 if (err) 1281 if (err)
1262 goto err_out; 1282 goto err_out;
1263 1283
1264 sqp->port = port; 1284 sqp->qp.port = port;
1265 sqp->qp.qpn = mqpn; 1285 sqp->qp.qpn = mqpn;
1266 sqp->qp.transport = MLX; 1286 sqp->qp.transport = MLX;
1267 1287
@@ -1404,10 +1424,10 @@ static int build_mlx_header(struct mthca_dev *dev, struct mthca_sqp *sqp,
1404 sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE; 1424 sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;
1405 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED); 1425 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);
1406 if (!sqp->qp.ibqp.qp_num) 1426 if (!sqp->qp.ibqp.qp_num)
1407 ib_get_cached_pkey(&dev->ib_dev, sqp->port, 1427 ib_get_cached_pkey(&dev->ib_dev, sqp->qp.port,
1408 sqp->pkey_index, &pkey); 1428 sqp->pkey_index, &pkey);
1409 else 1429 else
1410 ib_get_cached_pkey(&dev->ib_dev, sqp->port, 1430 ib_get_cached_pkey(&dev->ib_dev, sqp->qp.port,
1411 wr->wr.ud.pkey_index, &pkey); 1431 wr->wr.ud.pkey_index, &pkey);
1412 sqp->ud_header.bth.pkey = cpu_to_be16(pkey); 1432 sqp->ud_header.bth.pkey = cpu_to_be16(pkey);
1413 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn); 1433 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);
@@ -2204,7 +2224,7 @@ int __devinit mthca_init_qp_table(struct mthca_dev *dev)
2204 return err; 2224 return err;
2205} 2225}
2206 2226
2207void __devexit mthca_cleanup_qp_table(struct mthca_dev *dev) 2227void mthca_cleanup_qp_table(struct mthca_dev *dev)
2208{ 2228{
2209 int i; 2229 int i;
2210 u8 status; 2230 u8 status;
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index 0cfd15802217..adcaf85355ae 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -192,7 +192,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
192 192
193 /* Sanity check SRQ size before proceeding */ 193 /* Sanity check SRQ size before proceeding */
194 if (attr->max_wr > dev->limits.max_srq_wqes || 194 if (attr->max_wr > dev->limits.max_srq_wqes ||
195 attr->max_sge > dev->limits.max_sg) 195 attr->max_sge > dev->limits.max_srq_sge)
196 return -EINVAL; 196 return -EINVAL;
197 197
198 srq->max = attr->max_wr; 198 srq->max = attr->max_wr;
@@ -206,7 +206,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
206 roundup_pow_of_two(sizeof (struct mthca_next_seg) + 206 roundup_pow_of_two(sizeof (struct mthca_next_seg) +
207 srq->max_gs * sizeof (struct mthca_data_seg))); 207 srq->max_gs * sizeof (struct mthca_data_seg)));
208 208
209 if (ds > dev->limits.max_desc_sz) 209 if (!mthca_is_memfree(dev) && (ds > dev->limits.max_desc_sz))
210 return -EINVAL; 210 return -EINVAL;
211 211
212 srq->wqe_shift = long_log2(ds); 212 srq->wqe_shift = long_log2(ds);
@@ -660,6 +660,31 @@ int mthca_arbel_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
660 return err; 660 return err;
661} 661}
662 662
663int mthca_max_srq_sge(struct mthca_dev *dev)
664{
665 if (mthca_is_memfree(dev))
666 return dev->limits.max_sg;
667
668 /*
669 * SRQ allocations are based on powers of 2 for Tavor,
670 * (although they only need to be multiples of 16 bytes).
671 *
672 * Therefore, we need to base the max number of sg entries on
673 * the largest power of 2 descriptor size that is <= to the
674 * actual max WQE descriptor size, rather than return the
675 * max_sg value given by the firmware (which is based on WQE
676 * sizes as multiples of 16, not powers of 2).
677 *
678 * If SRQ implementation is changed for Tavor to be based on
679 * multiples of 16, the calculation below can be deleted and
680 * the FW max_sg value returned.
681 */
682 return min_t(int, dev->limits.max_sg,
683 ((1 << (fls(dev->limits.max_desc_sz) - 1)) -
684 sizeof (struct mthca_next_seg)) /
685 sizeof (struct mthca_data_seg));
686}
687
663int __devinit mthca_init_srq_table(struct mthca_dev *dev) 688int __devinit mthca_init_srq_table(struct mthca_dev *dev)
664{ 689{
665 int err; 690 int err;
@@ -684,7 +709,7 @@ int __devinit mthca_init_srq_table(struct mthca_dev *dev)
684 return err; 709 return err;
685} 710}
686 711
687void __devexit mthca_cleanup_srq_table(struct mthca_dev *dev) 712void mthca_cleanup_srq_table(struct mthca_dev *dev)
688{ 713{
689 if (!(dev->mthca_flags & MTHCA_FLAG_SRQ)) 714 if (!(dev->mthca_flags & MTHCA_FLAG_SRQ))
690 return; 715 return;
diff --git a/drivers/infiniband/ulp/ipoib/Kconfig b/drivers/infiniband/ulp/ipoib/Kconfig
index 8d2e04cac68e..13d6d01c72c0 100644
--- a/drivers/infiniband/ulp/ipoib/Kconfig
+++ b/drivers/infiniband/ulp/ipoib/Kconfig
@@ -10,8 +10,9 @@ config INFINIBAND_IPOIB
10 group: <http://www.ietf.org/html.charters/ipoib-charter.html>. 10 group: <http://www.ietf.org/html.charters/ipoib-charter.html>.
11 11
12config INFINIBAND_IPOIB_DEBUG 12config INFINIBAND_IPOIB_DEBUG
13 bool "IP-over-InfiniBand debugging" 13 bool "IP-over-InfiniBand debugging" if EMBEDDED
14 depends on INFINIBAND_IPOIB 14 depends on INFINIBAND_IPOIB
15 default y
15 ---help--- 16 ---help---
16 This option causes debugging code to be compiled into the 17 This option causes debugging code to be compiled into the
17 IPoIB driver. The output can be turned on via the 18 IPoIB driver. The output can be turned on via the
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index b640107fb732..12a1e0572ef2 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -65,6 +65,8 @@ enum {
65 65
66 IPOIB_RX_RING_SIZE = 128, 66 IPOIB_RX_RING_SIZE = 128,
67 IPOIB_TX_RING_SIZE = 64, 67 IPOIB_TX_RING_SIZE = 64,
68 IPOIB_MAX_QUEUE_SIZE = 8192,
69 IPOIB_MIN_QUEUE_SIZE = 2,
68 70
69 IPOIB_NUM_WC = 4, 71 IPOIB_NUM_WC = 4,
70 72
@@ -230,6 +232,9 @@ static inline struct ipoib_neigh **to_ipoib_neigh(struct neighbour *neigh)
230 INFINIBAND_ALEN, sizeof(void *)); 232 INFINIBAND_ALEN, sizeof(void *));
231} 233}
232 234
235struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neigh);
236void ipoib_neigh_free(struct ipoib_neigh *neigh);
237
233extern struct workqueue_struct *ipoib_workqueue; 238extern struct workqueue_struct *ipoib_workqueue;
234 239
235/* functions */ 240/* functions */
@@ -329,6 +334,8 @@ static inline void ipoib_unregister_debugfs(void) { }
329#define ipoib_warn(priv, format, arg...) \ 334#define ipoib_warn(priv, format, arg...) \
330 ipoib_printk(KERN_WARNING, priv, format , ## arg) 335 ipoib_printk(KERN_WARNING, priv, format , ## arg)
331 336
337extern int ipoib_sendq_size;
338extern int ipoib_recvq_size;
332 339
333#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 340#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
334extern int ipoib_debug_level; 341extern int ipoib_debug_level;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_fs.c b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
index 685258e34034..5dde380e8dbe 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_fs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
@@ -213,7 +213,7 @@ static int ipoib_path_seq_show(struct seq_file *file, void *iter_ptr)
213 gid_buf, path.pathrec.dlid ? "yes" : "no"); 213 gid_buf, path.pathrec.dlid ? "yes" : "no");
214 214
215 if (path.pathrec.dlid) { 215 if (path.pathrec.dlid) {
216 rate = ib_sa_rate_enum_to_int(path.pathrec.rate) * 25; 216 rate = ib_rate_to_mult(path.pathrec.rate) * 25;
217 217
218 seq_printf(file, 218 seq_printf(file,
219 " DLID: 0x%04x\n" 219 " DLID: 0x%04x\n"
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index ed65202878d8..a54da42849ae 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -161,7 +161,7 @@ static int ipoib_ib_post_receives(struct net_device *dev)
161 struct ipoib_dev_priv *priv = netdev_priv(dev); 161 struct ipoib_dev_priv *priv = netdev_priv(dev);
162 int i; 162 int i;
163 163
164 for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) { 164 for (i = 0; i < ipoib_recvq_size; ++i) {
165 if (ipoib_alloc_rx_skb(dev, i)) { 165 if (ipoib_alloc_rx_skb(dev, i)) {
166 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i); 166 ipoib_warn(priv, "failed to allocate receive buffer %d\n", i);
167 return -ENOMEM; 167 return -ENOMEM;
@@ -187,7 +187,7 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
187 if (wr_id & IPOIB_OP_RECV) { 187 if (wr_id & IPOIB_OP_RECV) {
188 wr_id &= ~IPOIB_OP_RECV; 188 wr_id &= ~IPOIB_OP_RECV;
189 189
190 if (wr_id < IPOIB_RX_RING_SIZE) { 190 if (wr_id < ipoib_recvq_size) {
191 struct sk_buff *skb = priv->rx_ring[wr_id].skb; 191 struct sk_buff *skb = priv->rx_ring[wr_id].skb;
192 dma_addr_t addr = priv->rx_ring[wr_id].mapping; 192 dma_addr_t addr = priv->rx_ring[wr_id].mapping;
193 193
@@ -252,9 +252,9 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
252 struct ipoib_tx_buf *tx_req; 252 struct ipoib_tx_buf *tx_req;
253 unsigned long flags; 253 unsigned long flags;
254 254
255 if (wr_id >= IPOIB_TX_RING_SIZE) { 255 if (wr_id >= ipoib_sendq_size) {
256 ipoib_warn(priv, "completion event with wrid %d (> %d)\n", 256 ipoib_warn(priv, "completion event with wrid %d (> %d)\n",
257 wr_id, IPOIB_TX_RING_SIZE); 257 wr_id, ipoib_sendq_size);
258 return; 258 return;
259 } 259 }
260 260
@@ -275,7 +275,7 @@ static void ipoib_ib_handle_wc(struct net_device *dev,
275 spin_lock_irqsave(&priv->tx_lock, flags); 275 spin_lock_irqsave(&priv->tx_lock, flags);
276 ++priv->tx_tail; 276 ++priv->tx_tail;
277 if (netif_queue_stopped(dev) && 277 if (netif_queue_stopped(dev) &&
278 priv->tx_head - priv->tx_tail <= IPOIB_TX_RING_SIZE / 2) 278 priv->tx_head - priv->tx_tail <= ipoib_sendq_size >> 1)
279 netif_wake_queue(dev); 279 netif_wake_queue(dev);
280 spin_unlock_irqrestore(&priv->tx_lock, flags); 280 spin_unlock_irqrestore(&priv->tx_lock, flags);
281 281
@@ -344,13 +344,13 @@ void ipoib_send(struct net_device *dev, struct sk_buff *skb,
344 * means we have to make sure everything is properly recorded and 344 * means we have to make sure everything is properly recorded and
345 * our state is consistent before we call post_send(). 345 * our state is consistent before we call post_send().
346 */ 346 */
347 tx_req = &priv->tx_ring[priv->tx_head & (IPOIB_TX_RING_SIZE - 1)]; 347 tx_req = &priv->tx_ring[priv->tx_head & (ipoib_sendq_size - 1)];
348 tx_req->skb = skb; 348 tx_req->skb = skb;
349 addr = dma_map_single(priv->ca->dma_device, skb->data, skb->len, 349 addr = dma_map_single(priv->ca->dma_device, skb->data, skb->len,
350 DMA_TO_DEVICE); 350 DMA_TO_DEVICE);
351 pci_unmap_addr_set(tx_req, mapping, addr); 351 pci_unmap_addr_set(tx_req, mapping, addr);
352 352
353 if (unlikely(post_send(priv, priv->tx_head & (IPOIB_TX_RING_SIZE - 1), 353 if (unlikely(post_send(priv, priv->tx_head & (ipoib_sendq_size - 1),
354 address->ah, qpn, addr, skb->len))) { 354 address->ah, qpn, addr, skb->len))) {
355 ipoib_warn(priv, "post_send failed\n"); 355 ipoib_warn(priv, "post_send failed\n");
356 ++priv->stats.tx_errors; 356 ++priv->stats.tx_errors;
@@ -363,7 +363,7 @@ void ipoib_send(struct net_device *dev, struct sk_buff *skb,
363 address->last_send = priv->tx_head; 363 address->last_send = priv->tx_head;
364 ++priv->tx_head; 364 ++priv->tx_head;
365 365
366 if (priv->tx_head - priv->tx_tail == IPOIB_TX_RING_SIZE) { 366 if (priv->tx_head - priv->tx_tail == ipoib_sendq_size) {
367 ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n"); 367 ipoib_dbg(priv, "TX ring full, stopping kernel net queue\n");
368 netif_stop_queue(dev); 368 netif_stop_queue(dev);
369 } 369 }
@@ -488,7 +488,7 @@ static int recvs_pending(struct net_device *dev)
488 int pending = 0; 488 int pending = 0;
489 int i; 489 int i;
490 490
491 for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) 491 for (i = 0; i < ipoib_recvq_size; ++i)
492 if (priv->rx_ring[i].skb) 492 if (priv->rx_ring[i].skb)
493 ++pending; 493 ++pending;
494 494
@@ -527,7 +527,7 @@ int ipoib_ib_dev_stop(struct net_device *dev)
527 */ 527 */
528 while ((int) priv->tx_tail - (int) priv->tx_head < 0) { 528 while ((int) priv->tx_tail - (int) priv->tx_head < 0) {
529 tx_req = &priv->tx_ring[priv->tx_tail & 529 tx_req = &priv->tx_ring[priv->tx_tail &
530 (IPOIB_TX_RING_SIZE - 1)]; 530 (ipoib_sendq_size - 1)];
531 dma_unmap_single(priv->ca->dma_device, 531 dma_unmap_single(priv->ca->dma_device,
532 pci_unmap_addr(tx_req, mapping), 532 pci_unmap_addr(tx_req, mapping),
533 tx_req->skb->len, 533 tx_req->skb->len,
@@ -536,7 +536,7 @@ int ipoib_ib_dev_stop(struct net_device *dev)
536 ++priv->tx_tail; 536 ++priv->tx_tail;
537 } 537 }
538 538
539 for (i = 0; i < IPOIB_RX_RING_SIZE; ++i) 539 for (i = 0; i < ipoib_recvq_size; ++i)
540 if (priv->rx_ring[i].skb) { 540 if (priv->rx_ring[i].skb) {
541 dma_unmap_single(priv->ca->dma_device, 541 dma_unmap_single(priv->ca->dma_device,
542 pci_unmap_addr(&priv->rx_ring[i], 542 pci_unmap_addr(&priv->rx_ring[i],
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 53a32f65788d..cb078a7d0bf5 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -41,6 +41,7 @@
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/kernel.h>
44 45
45#include <linux/if_arp.h> /* For ARPHRD_xxx */ 46#include <linux/if_arp.h> /* For ARPHRD_xxx */
46 47
@@ -53,6 +54,14 @@ MODULE_AUTHOR("Roland Dreier");
53MODULE_DESCRIPTION("IP-over-InfiniBand net driver"); 54MODULE_DESCRIPTION("IP-over-InfiniBand net driver");
54MODULE_LICENSE("Dual BSD/GPL"); 55MODULE_LICENSE("Dual BSD/GPL");
55 56
57int ipoib_sendq_size __read_mostly = IPOIB_TX_RING_SIZE;
58int ipoib_recvq_size __read_mostly = IPOIB_RX_RING_SIZE;
59
60module_param_named(send_queue_size, ipoib_sendq_size, int, 0444);
61MODULE_PARM_DESC(send_queue_size, "Number of descriptors in send queue");
62module_param_named(recv_queue_size, ipoib_recvq_size, int, 0444);
63MODULE_PARM_DESC(recv_queue_size, "Number of descriptors in receive queue");
64
56#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG 65#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG
57int ipoib_debug_level; 66int ipoib_debug_level;
58 67
@@ -252,8 +261,8 @@ static void path_free(struct net_device *dev, struct ipoib_path *path)
252 */ 261 */
253 if (neigh->ah) 262 if (neigh->ah)
254 ipoib_put_ah(neigh->ah); 263 ipoib_put_ah(neigh->ah);
255 *to_ipoib_neigh(neigh->neighbour) = NULL; 264
256 kfree(neigh); 265 ipoib_neigh_free(neigh);
257 } 266 }
258 267
259 spin_unlock_irqrestore(&priv->lock, flags); 268 spin_unlock_irqrestore(&priv->lock, flags);
@@ -327,9 +336,8 @@ void ipoib_flush_paths(struct net_device *dev)
327 struct ipoib_dev_priv *priv = netdev_priv(dev); 336 struct ipoib_dev_priv *priv = netdev_priv(dev);
328 struct ipoib_path *path, *tp; 337 struct ipoib_path *path, *tp;
329 LIST_HEAD(remove_list); 338 LIST_HEAD(remove_list);
330 unsigned long flags;
331 339
332 spin_lock_irqsave(&priv->lock, flags); 340 spin_lock_irq(&priv->lock);
333 341
334 list_splice(&priv->path_list, &remove_list); 342 list_splice(&priv->path_list, &remove_list);
335 INIT_LIST_HEAD(&priv->path_list); 343 INIT_LIST_HEAD(&priv->path_list);
@@ -337,14 +345,15 @@ void ipoib_flush_paths(struct net_device *dev)
337 list_for_each_entry(path, &remove_list, list) 345 list_for_each_entry(path, &remove_list, list)
338 rb_erase(&path->rb_node, &priv->path_tree); 346 rb_erase(&path->rb_node, &priv->path_tree);
339 347
340 spin_unlock_irqrestore(&priv->lock, flags);
341
342 list_for_each_entry_safe(path, tp, &remove_list, list) { 348 list_for_each_entry_safe(path, tp, &remove_list, list) {
343 if (path->query) 349 if (path->query)
344 ib_sa_cancel_query(path->query_id, path->query); 350 ib_sa_cancel_query(path->query_id, path->query);
351 spin_unlock_irq(&priv->lock);
345 wait_for_completion(&path->done); 352 wait_for_completion(&path->done);
346 path_free(dev, path); 353 path_free(dev, path);
354 spin_lock_irq(&priv->lock);
347 } 355 }
356 spin_unlock_irq(&priv->lock);
348} 357}
349 358
350static void path_rec_completion(int status, 359static void path_rec_completion(int status,
@@ -373,16 +382,9 @@ static void path_rec_completion(int status,
373 struct ib_ah_attr av = { 382 struct ib_ah_attr av = {
374 .dlid = be16_to_cpu(pathrec->dlid), 383 .dlid = be16_to_cpu(pathrec->dlid),
375 .sl = pathrec->sl, 384 .sl = pathrec->sl,
376 .port_num = priv->port 385 .port_num = priv->port,
386 .static_rate = pathrec->rate
377 }; 387 };
378 int path_rate = ib_sa_rate_enum_to_int(pathrec->rate);
379
380 if (path_rate > 0 && priv->local_rate > path_rate)
381 av.static_rate = (priv->local_rate - 1) / path_rate;
382
383 ipoib_dbg(priv, "static_rate %d for local port %dX, path %dX\n",
384 av.static_rate, priv->local_rate,
385 ib_sa_rate_enum_to_int(pathrec->rate));
386 388
387 ah = ipoib_create_ah(dev, priv->pd, &av); 389 ah = ipoib_create_ah(dev, priv->pd, &av);
388 } 390 }
@@ -481,7 +483,7 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
481 struct ipoib_path *path; 483 struct ipoib_path *path;
482 struct ipoib_neigh *neigh; 484 struct ipoib_neigh *neigh;
483 485
484 neigh = kmalloc(sizeof *neigh, GFP_ATOMIC); 486 neigh = ipoib_neigh_alloc(skb->dst->neighbour);
485 if (!neigh) { 487 if (!neigh) {
486 ++priv->stats.tx_dropped; 488 ++priv->stats.tx_dropped;
487 dev_kfree_skb_any(skb); 489 dev_kfree_skb_any(skb);
@@ -489,8 +491,6 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
489 } 491 }
490 492
491 skb_queue_head_init(&neigh->queue); 493 skb_queue_head_init(&neigh->queue);
492 neigh->neighbour = skb->dst->neighbour;
493 *to_ipoib_neigh(skb->dst->neighbour) = neigh;
494 494
495 /* 495 /*
496 * We can only be called from ipoib_start_xmit, so we're 496 * We can only be called from ipoib_start_xmit, so we're
@@ -503,7 +503,7 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
503 path = path_rec_create(dev, 503 path = path_rec_create(dev,
504 (union ib_gid *) (skb->dst->neighbour->ha + 4)); 504 (union ib_gid *) (skb->dst->neighbour->ha + 4));
505 if (!path) 505 if (!path)
506 goto err; 506 goto err_path;
507 507
508 __path_add(dev, path); 508 __path_add(dev, path);
509 } 509 }
@@ -521,17 +521,17 @@ static void neigh_add_path(struct sk_buff *skb, struct net_device *dev)
521 __skb_queue_tail(&neigh->queue, skb); 521 __skb_queue_tail(&neigh->queue, skb);
522 522
523 if (!path->query && path_rec_start(dev, path)) 523 if (!path->query && path_rec_start(dev, path))
524 goto err; 524 goto err_list;
525 } 525 }
526 526
527 spin_unlock(&priv->lock); 527 spin_unlock(&priv->lock);
528 return; 528 return;
529 529
530err: 530err_list:
531 *to_ipoib_neigh(skb->dst->neighbour) = NULL;
532 list_del(&neigh->list); 531 list_del(&neigh->list);
533 kfree(neigh);
534 532
533err_path:
534 ipoib_neigh_free(neigh);
535 ++priv->stats.tx_dropped; 535 ++priv->stats.tx_dropped;
536 dev_kfree_skb_any(skb); 536 dev_kfree_skb_any(skb);
537 537
@@ -723,7 +723,7 @@ static int ipoib_hard_header(struct sk_buff *skb,
723 * destination address onto the front of the skb so we can 723 * destination address onto the front of the skb so we can
724 * figure out where to send the packet later. 724 * figure out where to send the packet later.
725 */ 725 */
726 if (!skb->dst || !skb->dst->neighbour) { 726 if ((!skb->dst || !skb->dst->neighbour) && daddr) {
727 struct ipoib_pseudoheader *phdr = 727 struct ipoib_pseudoheader *phdr =
728 (struct ipoib_pseudoheader *) skb_push(skb, sizeof *phdr); 728 (struct ipoib_pseudoheader *) skb_push(skb, sizeof *phdr);
729 memcpy(phdr->hwaddr, daddr, INFINIBAND_ALEN); 729 memcpy(phdr->hwaddr, daddr, INFINIBAND_ALEN);
@@ -763,8 +763,7 @@ static void ipoib_neigh_destructor(struct neighbour *n)
763 if (neigh->ah) 763 if (neigh->ah)
764 ah = neigh->ah; 764 ah = neigh->ah;
765 list_del(&neigh->list); 765 list_del(&neigh->list);
766 *to_ipoib_neigh(n) = NULL; 766 ipoib_neigh_free(neigh);
767 kfree(neigh);
768 } 767 }
769 768
770 spin_unlock_irqrestore(&priv->lock, flags); 769 spin_unlock_irqrestore(&priv->lock, flags);
@@ -773,6 +772,26 @@ static void ipoib_neigh_destructor(struct neighbour *n)
773 ipoib_put_ah(ah); 772 ipoib_put_ah(ah);
774} 773}
775 774
775struct ipoib_neigh *ipoib_neigh_alloc(struct neighbour *neighbour)
776{
777 struct ipoib_neigh *neigh;
778
779 neigh = kmalloc(sizeof *neigh, GFP_ATOMIC);
780 if (!neigh)
781 return NULL;
782
783 neigh->neighbour = neighbour;
784 *to_ipoib_neigh(neighbour) = neigh;
785
786 return neigh;
787}
788
789void ipoib_neigh_free(struct ipoib_neigh *neigh)
790{
791 *to_ipoib_neigh(neigh->neighbour) = NULL;
792 kfree(neigh);
793}
794
776static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms) 795static int ipoib_neigh_setup_dev(struct net_device *dev, struct neigh_parms *parms)
777{ 796{
778 parms->neigh_destructor = ipoib_neigh_destructor; 797 parms->neigh_destructor = ipoib_neigh_destructor;
@@ -785,20 +804,19 @@ int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
785 struct ipoib_dev_priv *priv = netdev_priv(dev); 804 struct ipoib_dev_priv *priv = netdev_priv(dev);
786 805
787 /* Allocate RX/TX "rings" to hold queued skbs */ 806 /* Allocate RX/TX "rings" to hold queued skbs */
788 807 priv->rx_ring = kzalloc(ipoib_recvq_size * sizeof *priv->rx_ring,
789 priv->rx_ring = kzalloc(IPOIB_RX_RING_SIZE * sizeof (struct ipoib_rx_buf),
790 GFP_KERNEL); 808 GFP_KERNEL);
791 if (!priv->rx_ring) { 809 if (!priv->rx_ring) {
792 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n", 810 printk(KERN_WARNING "%s: failed to allocate RX ring (%d entries)\n",
793 ca->name, IPOIB_RX_RING_SIZE); 811 ca->name, ipoib_recvq_size);
794 goto out; 812 goto out;
795 } 813 }
796 814
797 priv->tx_ring = kzalloc(IPOIB_TX_RING_SIZE * sizeof (struct ipoib_tx_buf), 815 priv->tx_ring = kzalloc(ipoib_sendq_size * sizeof *priv->tx_ring,
798 GFP_KERNEL); 816 GFP_KERNEL);
799 if (!priv->tx_ring) { 817 if (!priv->tx_ring) {
800 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n", 818 printk(KERN_WARNING "%s: failed to allocate TX ring (%d entries)\n",
801 ca->name, IPOIB_TX_RING_SIZE); 819 ca->name, ipoib_sendq_size);
802 goto out_rx_ring_cleanup; 820 goto out_rx_ring_cleanup;
803 } 821 }
804 822
@@ -866,7 +884,7 @@ static void ipoib_setup(struct net_device *dev)
866 dev->hard_header_len = IPOIB_ENCAP_LEN + INFINIBAND_ALEN; 884 dev->hard_header_len = IPOIB_ENCAP_LEN + INFINIBAND_ALEN;
867 dev->addr_len = INFINIBAND_ALEN; 885 dev->addr_len = INFINIBAND_ALEN;
868 dev->type = ARPHRD_INFINIBAND; 886 dev->type = ARPHRD_INFINIBAND;
869 dev->tx_queue_len = IPOIB_TX_RING_SIZE * 2; 887 dev->tx_queue_len = ipoib_sendq_size * 2;
870 dev->features = NETIF_F_VLAN_CHALLENGED | NETIF_F_LLTX; 888 dev->features = NETIF_F_VLAN_CHALLENGED | NETIF_F_LLTX;
871 889
872 /* MTU will be reset when mcast join happens */ 890 /* MTU will be reset when mcast join happens */
@@ -1118,6 +1136,14 @@ static int __init ipoib_init_module(void)
1118{ 1136{
1119 int ret; 1137 int ret;
1120 1138
1139 ipoib_recvq_size = roundup_pow_of_two(ipoib_recvq_size);
1140 ipoib_recvq_size = min(ipoib_recvq_size, IPOIB_MAX_QUEUE_SIZE);
1141 ipoib_recvq_size = max(ipoib_recvq_size, IPOIB_MIN_QUEUE_SIZE);
1142
1143 ipoib_sendq_size = roundup_pow_of_two(ipoib_sendq_size);
1144 ipoib_sendq_size = min(ipoib_sendq_size, IPOIB_MAX_QUEUE_SIZE);
1145 ipoib_sendq_size = max(ipoib_sendq_size, IPOIB_MIN_QUEUE_SIZE);
1146
1121 ret = ipoib_register_debugfs(); 1147 ret = ipoib_register_debugfs();
1122 if (ret) 1148 if (ret)
1123 return ret; 1149 return ret;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index 93c462eaf4fd..1dae4b238252 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -114,8 +114,7 @@ static void ipoib_mcast_free(struct ipoib_mcast *mcast)
114 */ 114 */
115 if (neigh->ah) 115 if (neigh->ah)
116 ipoib_put_ah(neigh->ah); 116 ipoib_put_ah(neigh->ah);
117 *to_ipoib_neigh(neigh->neighbour) = NULL; 117 ipoib_neigh_free(neigh);
118 kfree(neigh);
119 } 118 }
120 119
121 spin_unlock_irqrestore(&priv->lock, flags); 120 spin_unlock_irqrestore(&priv->lock, flags);
@@ -251,6 +250,7 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
251 .port_num = priv->port, 250 .port_num = priv->port,
252 .sl = mcast->mcmember.sl, 251 .sl = mcast->mcmember.sl,
253 .ah_flags = IB_AH_GRH, 252 .ah_flags = IB_AH_GRH,
253 .static_rate = mcast->mcmember.rate,
254 .grh = { 254 .grh = {
255 .flow_label = be32_to_cpu(mcast->mcmember.flow_label), 255 .flow_label = be32_to_cpu(mcast->mcmember.flow_label),
256 .hop_limit = mcast->mcmember.hop_limit, 256 .hop_limit = mcast->mcmember.hop_limit,
@@ -258,17 +258,8 @@ static int ipoib_mcast_join_finish(struct ipoib_mcast *mcast,
258 .traffic_class = mcast->mcmember.traffic_class 258 .traffic_class = mcast->mcmember.traffic_class
259 } 259 }
260 }; 260 };
261 int path_rate = ib_sa_rate_enum_to_int(mcast->mcmember.rate);
262
263 av.grh.dgid = mcast->mcmember.mgid; 261 av.grh.dgid = mcast->mcmember.mgid;
264 262
265 if (path_rate > 0 && priv->local_rate > path_rate)
266 av.static_rate = (priv->local_rate - 1) / path_rate;
267
268 ipoib_dbg_mcast(priv, "static_rate %d for local port %dX, mcmember %dX\n",
269 av.static_rate, priv->local_rate,
270 ib_sa_rate_enum_to_int(mcast->mcmember.rate));
271
272 ah = ipoib_create_ah(dev, priv->pd, &av); 263 ah = ipoib_create_ah(dev, priv->pd, &av);
273 if (!ah) { 264 if (!ah) {
274 ipoib_warn(priv, "ib_address_create failed\n"); 265 ipoib_warn(priv, "ib_address_create failed\n");
@@ -618,6 +609,22 @@ int ipoib_mcast_start_thread(struct net_device *dev)
618 return 0; 609 return 0;
619} 610}
620 611
612static void wait_for_mcast_join(struct ipoib_dev_priv *priv,
613 struct ipoib_mcast *mcast)
614{
615 spin_lock_irq(&priv->lock);
616 if (mcast && mcast->query) {
617 ib_sa_cancel_query(mcast->query_id, mcast->query);
618 mcast->query = NULL;
619 spin_unlock_irq(&priv->lock);
620 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n",
621 IPOIB_GID_ARG(mcast->mcmember.mgid));
622 wait_for_completion(&mcast->done);
623 }
624 else
625 spin_unlock_irq(&priv->lock);
626}
627
621int ipoib_mcast_stop_thread(struct net_device *dev, int flush) 628int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
622{ 629{
623 struct ipoib_dev_priv *priv = netdev_priv(dev); 630 struct ipoib_dev_priv *priv = netdev_priv(dev);
@@ -637,28 +644,10 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
637 if (flush) 644 if (flush)
638 flush_workqueue(ipoib_workqueue); 645 flush_workqueue(ipoib_workqueue);
639 646
640 spin_lock_irq(&priv->lock); 647 wait_for_mcast_join(priv, priv->broadcast);
641 if (priv->broadcast && priv->broadcast->query) {
642 ib_sa_cancel_query(priv->broadcast->query_id, priv->broadcast->query);
643 priv->broadcast->query = NULL;
644 spin_unlock_irq(&priv->lock);
645 ipoib_dbg_mcast(priv, "waiting for bcast\n");
646 wait_for_completion(&priv->broadcast->done);
647 } else
648 spin_unlock_irq(&priv->lock);
649 648
650 list_for_each_entry(mcast, &priv->multicast_list, list) { 649 list_for_each_entry(mcast, &priv->multicast_list, list)
651 spin_lock_irq(&priv->lock); 650 wait_for_mcast_join(priv, mcast);
652 if (mcast->query) {
653 ib_sa_cancel_query(mcast->query_id, mcast->query);
654 mcast->query = NULL;
655 spin_unlock_irq(&priv->lock);
656 ipoib_dbg_mcast(priv, "waiting for MGID " IPOIB_GID_FMT "\n",
657 IPOIB_GID_ARG(mcast->mcmember.mgid));
658 wait_for_completion(&mcast->done);
659 } else
660 spin_unlock_irq(&priv->lock);
661 }
662 651
663 return 0; 652 return 0;
664} 653}
@@ -772,13 +761,11 @@ out:
772 if (skb->dst && 761 if (skb->dst &&
773 skb->dst->neighbour && 762 skb->dst->neighbour &&
774 !*to_ipoib_neigh(skb->dst->neighbour)) { 763 !*to_ipoib_neigh(skb->dst->neighbour)) {
775 struct ipoib_neigh *neigh = kmalloc(sizeof *neigh, GFP_ATOMIC); 764 struct ipoib_neigh *neigh = ipoib_neigh_alloc(skb->dst->neighbour);
776 765
777 if (neigh) { 766 if (neigh) {
778 kref_get(&mcast->ah->ref); 767 kref_get(&mcast->ah->ref);
779 neigh->ah = mcast->ah; 768 neigh->ah = mcast->ah;
780 neigh->neighbour = skb->dst->neighbour;
781 *to_ipoib_neigh(skb->dst->neighbour) = neigh;
782 list_add_tail(&neigh->list, &mcast->neigh_list); 769 list_add_tail(&neigh->list, &mcast->neigh_list);
783 } 770 }
784 } 771 }
@@ -913,6 +900,7 @@ void ipoib_mcast_restart_task(void *dev_ptr)
913 900
914 /* We have to cancel outside of the spinlock */ 901 /* We have to cancel outside of the spinlock */
915 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) { 902 list_for_each_entry_safe(mcast, tmcast, &remove_list, list) {
903 wait_for_mcast_join(priv, mcast);
916 ipoib_mcast_leave(mcast->dev, mcast); 904 ipoib_mcast_leave(mcast->dev, mcast);
917 ipoib_mcast_free(mcast); 905 ipoib_mcast_free(mcast);
918 } 906 }
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index 5f0388027b25..1d49d1643c59 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -159,8 +159,8 @@ int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)
159 struct ipoib_dev_priv *priv = netdev_priv(dev); 159 struct ipoib_dev_priv *priv = netdev_priv(dev);
160 struct ib_qp_init_attr init_attr = { 160 struct ib_qp_init_attr init_attr = {
161 .cap = { 161 .cap = {
162 .max_send_wr = IPOIB_TX_RING_SIZE, 162 .max_send_wr = ipoib_sendq_size,
163 .max_recv_wr = IPOIB_RX_RING_SIZE, 163 .max_recv_wr = ipoib_recvq_size,
164 .max_send_sge = 1, 164 .max_send_sge = 1,
165 .max_recv_sge = 1 165 .max_recv_sge = 1
166 }, 166 },
@@ -175,7 +175,7 @@ int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)
175 } 175 }
176 176
177 priv->cq = ib_create_cq(priv->ca, ipoib_ib_completion, NULL, dev, 177 priv->cq = ib_create_cq(priv->ca, ipoib_ib_completion, NULL, dev,
178 IPOIB_TX_RING_SIZE + IPOIB_RX_RING_SIZE + 1); 178 ipoib_sendq_size + ipoib_recvq_size + 1);
179 if (IS_ERR(priv->cq)) { 179 if (IS_ERR(priv->cq)) {
180 printk(KERN_WARNING "%s: failed to create CQ\n", ca->name); 180 printk(KERN_WARNING "%s: failed to create CQ\n", ca->name);
181 goto out_free_pd; 181 goto out_free_pd;
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 61924cc30e55..5f2b3f6e4c47 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -607,10 +607,10 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
607 */ 607 */
608 if (likely(scmnd->use_sg)) { 608 if (likely(scmnd->use_sg)) {
609 nents = scmnd->use_sg; 609 nents = scmnd->use_sg;
610 scat = (struct scatterlist *) scmnd->request_buffer; 610 scat = scmnd->request_buffer;
611 } else { 611 } else {
612 nents = 1; 612 nents = 1;
613 scat = (struct scatterlist *) scmnd->request_buffer; 613 scat = &req->fake_sg;
614 } 614 }
615 615
616 dma_unmap_sg(target->srp_host->dev->dma_device, scat, nents, 616 dma_unmap_sg(target->srp_host->dev->dma_device, scat, nents,
@@ -1434,6 +1434,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1434 p = match_strdup(args); 1434 p = match_strdup(args);
1435 if (strlen(p) != 32) { 1435 if (strlen(p) != 32) {
1436 printk(KERN_WARNING PFX "bad dest GID parameter '%s'\n", p); 1436 printk(KERN_WARNING PFX "bad dest GID parameter '%s'\n", p);
1437 kfree(p);
1437 goto out; 1438 goto out;
1438 } 1439 }
1439 1440
diff --git a/drivers/input/evbug.c b/drivers/input/evbug.c
index d7828936fd8f..07358fb51b82 100644
--- a/drivers/input/evbug.c
+++ b/drivers/input/evbug.c
@@ -49,9 +49,8 @@ static struct input_handle *evbug_connect(struct input_handler *handler, struct
49{ 49{
50 struct input_handle *handle; 50 struct input_handle *handle;
51 51
52 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) 52 if (!(handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL)))
53 return NULL; 53 return NULL;
54 memset(handle, 0, sizeof(struct input_handle));
55 54
56 handle->dev = dev; 55 handle->dev = dev;
57 handle->handler = handler; 56 handle->handler = handler;
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 745979f33dc2..a34e3d91d9ed 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -130,9 +130,8 @@ static int evdev_open(struct inode * inode, struct file * file)
130 if ((accept_err = input_accept_process(&(evdev_table[i]->handle), file))) 130 if ((accept_err = input_accept_process(&(evdev_table[i]->handle), file)))
131 return accept_err; 131 return accept_err;
132 132
133 if (!(list = kmalloc(sizeof(struct evdev_list), GFP_KERNEL))) 133 if (!(list = kzalloc(sizeof(struct evdev_list), GFP_KERNEL)))
134 return -ENOMEM; 134 return -ENOMEM;
135 memset(list, 0, sizeof(struct evdev_list));
136 135
137 list->evdev = evdev_table[i]; 136 list->evdev = evdev_table[i];
138 list_add_tail(&list->node, &evdev_table[i]->list); 137 list_add_tail(&list->node, &evdev_table[i]->list);
@@ -609,9 +608,8 @@ static struct input_handle *evdev_connect(struct input_handler *handler, struct
609 return NULL; 608 return NULL;
610 } 609 }
611 610
612 if (!(evdev = kmalloc(sizeof(struct evdev), GFP_KERNEL))) 611 if (!(evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL)))
613 return NULL; 612 return NULL;
614 memset(evdev, 0, sizeof(struct evdev));
615 613
616 INIT_LIST_HEAD(&evdev->list); 614 INIT_LIST_HEAD(&evdev->list);
617 init_waitqueue_head(&evdev->wait); 615 init_waitqueue_head(&evdev->wait);
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index b765a155c008..36644bff379d 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -22,6 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/kthread.h> 23#include <linux/kthread.h>
24#include <linux/sched.h> /* HZ */ 24#include <linux/sched.h> /* HZ */
25#include <linux/mutex.h>
25 26
26/*#include <asm/io.h>*/ 27/*#include <asm/io.h>*/
27 28
@@ -43,10 +44,10 @@ EXPORT_SYMBOL(gameport_start_polling);
43EXPORT_SYMBOL(gameport_stop_polling); 44EXPORT_SYMBOL(gameport_stop_polling);
44 45
45/* 46/*
46 * gameport_sem protects entire gameport subsystem and is taken 47 * gameport_mutex protects entire gameport subsystem and is taken
47 * every time gameport port or driver registrered or unregistered. 48 * every time gameport port or driver registrered or unregistered.
48 */ 49 */
49static DECLARE_MUTEX(gameport_sem); 50static DEFINE_MUTEX(gameport_mutex);
50 51
51static LIST_HEAD(gameport_list); 52static LIST_HEAD(gameport_list);
52 53
@@ -265,6 +266,7 @@ static void gameport_queue_event(void *object, struct module *owner,
265 if ((event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC))) { 266 if ((event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC))) {
266 if (!try_module_get(owner)) { 267 if (!try_module_get(owner)) {
267 printk(KERN_WARNING "gameport: Can't get module reference, dropping event %d\n", event_type); 268 printk(KERN_WARNING "gameport: Can't get module reference, dropping event %d\n", event_type);
269 kfree(event);
268 goto out; 270 goto out;
269 } 271 }
270 272
@@ -342,7 +344,7 @@ static void gameport_handle_event(void)
342 struct gameport_event *event; 344 struct gameport_event *event;
343 struct gameport_driver *gameport_drv; 345 struct gameport_driver *gameport_drv;
344 346
345 down(&gameport_sem); 347 mutex_lock(&gameport_mutex);
346 348
347 /* 349 /*
348 * Note that we handle only one event here to give swsusp 350 * Note that we handle only one event here to give swsusp
@@ -379,7 +381,7 @@ static void gameport_handle_event(void)
379 gameport_free_event(event); 381 gameport_free_event(event);
380 } 382 }
381 383
382 up(&gameport_sem); 384 mutex_unlock(&gameport_mutex);
383} 385}
384 386
385/* 387/*
@@ -464,7 +466,7 @@ static ssize_t gameport_rebind_driver(struct device *dev, struct device_attribut
464 struct device_driver *drv; 466 struct device_driver *drv;
465 int retval; 467 int retval;
466 468
467 retval = down_interruptible(&gameport_sem); 469 retval = mutex_lock_interruptible(&gameport_mutex);
468 if (retval) 470 if (retval)
469 return retval; 471 return retval;
470 472
@@ -484,7 +486,7 @@ static ssize_t gameport_rebind_driver(struct device *dev, struct device_attribut
484 retval = -EINVAL; 486 retval = -EINVAL;
485 } 487 }
486 488
487 up(&gameport_sem); 489 mutex_unlock(&gameport_mutex);
488 490
489 return retval; 491 return retval;
490} 492}
@@ -521,7 +523,7 @@ static void gameport_init_port(struct gameport *gameport)
521 523
522 __module_get(THIS_MODULE); 524 __module_get(THIS_MODULE);
523 525
524 init_MUTEX(&gameport->drv_sem); 526 mutex_init(&gameport->drv_mutex);
525 device_initialize(&gameport->dev); 527 device_initialize(&gameport->dev);
526 snprintf(gameport->dev.bus_id, sizeof(gameport->dev.bus_id), 528 snprintf(gameport->dev.bus_id, sizeof(gameport->dev.bus_id),
527 "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1); 529 "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
@@ -661,10 +663,10 @@ void __gameport_register_port(struct gameport *gameport, struct module *owner)
661 */ 663 */
662void gameport_unregister_port(struct gameport *gameport) 664void gameport_unregister_port(struct gameport *gameport)
663{ 665{
664 down(&gameport_sem); 666 mutex_lock(&gameport_mutex);
665 gameport_disconnect_port(gameport); 667 gameport_disconnect_port(gameport);
666 gameport_destroy_port(gameport); 668 gameport_destroy_port(gameport);
667 up(&gameport_sem); 669 mutex_unlock(&gameport_mutex);
668} 670}
669 671
670 672
@@ -717,7 +719,7 @@ void gameport_unregister_driver(struct gameport_driver *drv)
717{ 719{
718 struct gameport *gameport; 720 struct gameport *gameport;
719 721
720 down(&gameport_sem); 722 mutex_lock(&gameport_mutex);
721 drv->ignore = 1; /* so gameport_find_driver ignores it */ 723 drv->ignore = 1; /* so gameport_find_driver ignores it */
722 724
723start_over: 725start_over:
@@ -731,7 +733,7 @@ start_over:
731 } 733 }
732 734
733 driver_unregister(&drv->driver); 735 driver_unregister(&drv->driver);
734 up(&gameport_sem); 736 mutex_unlock(&gameport_mutex);
735} 737}
736 738
737static int gameport_bus_match(struct device *dev, struct device_driver *drv) 739static int gameport_bus_match(struct device *dev, struct device_driver *drv)
@@ -743,9 +745,9 @@ static int gameport_bus_match(struct device *dev, struct device_driver *drv)
743 745
744static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv) 746static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv)
745{ 747{
746 down(&gameport->drv_sem); 748 mutex_lock(&gameport->drv_mutex);
747 gameport->drv = drv; 749 gameport->drv = drv;
748 up(&gameport->drv_sem); 750 mutex_unlock(&gameport->drv_mutex);
749} 751}
750 752
751int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode) 753int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode)
@@ -796,5 +798,5 @@ static void __exit gameport_exit(void)
796 kthread_stop(gameport_task); 798 kthread_stop(gameport_task);
797} 799}
798 800
799module_init(gameport_init); 801subsys_initcall(gameport_init);
800module_exit(gameport_exit); 802module_exit(gameport_exit);
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index d2e55dc956ba..3e2d28f263e9 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -252,14 +252,14 @@ static struct pnp_driver ns558_pnp_driver;
252 252
253#endif 253#endif
254 254
255static int pnp_registered = 0;
256
257static int __init ns558_init(void) 255static int __init ns558_init(void)
258{ 256{
259 int i = 0; 257 int i = 0;
258 int error;
260 259
261 if (pnp_register_driver(&ns558_pnp_driver) >= 0) 260 error = pnp_register_driver(&ns558_pnp_driver);
262 pnp_registered = 1; 261 if (error && error != -ENODEV) /* should be ENOSYS really */
262 return error;
263 263
264/* 264/*
265 * Probe ISA ports after PnP, so that PnP ports that are already 265 * Probe ISA ports after PnP, so that PnP ports that are already
@@ -270,7 +270,7 @@ static int __init ns558_init(void)
270 while (ns558_isa_portlist[i]) 270 while (ns558_isa_portlist[i])
271 ns558_isa_probe(ns558_isa_portlist[i++]); 271 ns558_isa_probe(ns558_isa_portlist[i++]);
272 272
273 return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0; 273 return list_empty(&ns558_list) && error ? -ENODEV : 0;
274} 274}
275 275
276static void __exit ns558_exit(void) 276static void __exit ns558_exit(void)
@@ -283,8 +283,7 @@ static void __exit ns558_exit(void)
283 kfree(ns558); 283 kfree(ns558);
284 } 284 }
285 285
286 if (pnp_registered) 286 pnp_unregister_driver(&ns558_pnp_driver);
287 pnp_unregister_driver(&ns558_pnp_driver);
288} 287}
289 288
290module_init(ns558_init); 289module_init(ns558_init);
diff --git a/drivers/input/input.c b/drivers/input/input.c
index f8af0945964e..a935abeffffc 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -18,9 +18,11 @@
18#include <linux/random.h> 18#include <linux/random.h>
19#include <linux/major.h> 19#include <linux/major.h>
20#include <linux/proc_fs.h> 20#include <linux/proc_fs.h>
21#include <linux/seq_file.h>
21#include <linux/interrupt.h> 22#include <linux/interrupt.h>
22#include <linux/poll.h> 23#include <linux/poll.h>
23#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/mutex.h>
24 26
25MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>"); 27MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
26MODULE_DESCRIPTION("Input core"); 28MODULE_DESCRIPTION("Input core");
@@ -224,7 +226,7 @@ int input_open_device(struct input_handle *handle)
224 struct input_dev *dev = handle->dev; 226 struct input_dev *dev = handle->dev;
225 int err; 227 int err;
226 228
227 err = down_interruptible(&dev->sem); 229 err = mutex_lock_interruptible(&dev->mutex);
228 if (err) 230 if (err)
229 return err; 231 return err;
230 232
@@ -236,7 +238,7 @@ int input_open_device(struct input_handle *handle)
236 if (err) 238 if (err)
237 handle->open--; 239 handle->open--;
238 240
239 up(&dev->sem); 241 mutex_unlock(&dev->mutex);
240 242
241 return err; 243 return err;
242} 244}
@@ -255,13 +257,13 @@ void input_close_device(struct input_handle *handle)
255 257
256 input_release_device(handle); 258 input_release_device(handle);
257 259
258 down(&dev->sem); 260 mutex_lock(&dev->mutex);
259 261
260 if (!--dev->users && dev->close) 262 if (!--dev->users && dev->close)
261 dev->close(dev); 263 dev->close(dev);
262 handle->open--; 264 handle->open--;
263 265
264 up(&dev->sem); 266 mutex_unlock(&dev->mutex);
265} 267}
266 268
267static void input_link_handle(struct input_handle *handle) 269static void input_link_handle(struct input_handle *handle)
@@ -315,21 +317,6 @@ static struct input_device_id *input_match_device(struct input_device_id *id, st
315 return NULL; 317 return NULL;
316} 318}
317 319
318static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap, int max)
319{
320 int i;
321 int len = 0;
322
323 for (i = NBITS(max) - 1; i > 0; i--)
324 if (bitmap[i])
325 break;
326
327 for (; i >= 0; i--)
328 len += snprintf(buf + len, max(buf_size - len, 0),
329 "%lx%s", bitmap[i], i > 0 ? " " : "");
330 return len;
331}
332
333#ifdef CONFIG_PROC_FS 320#ifdef CONFIG_PROC_FS
334 321
335static struct proc_dir_entry *proc_bus_input_dir; 322static struct proc_dir_entry *proc_bus_input_dir;
@@ -342,7 +329,7 @@ static inline void input_wakeup_procfs_readers(void)
342 wake_up(&input_devices_poll_wait); 329 wake_up(&input_devices_poll_wait);
343} 330}
344 331
345static unsigned int input_devices_poll(struct file *file, poll_table *wait) 332static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
346{ 333{
347 int state = input_devices_state; 334 int state = input_devices_state;
348 poll_wait(file, &input_devices_poll_wait, wait); 335 poll_wait(file, &input_devices_poll_wait, wait);
@@ -351,115 +338,171 @@ static unsigned int input_devices_poll(struct file *file, poll_table *wait)
351 return 0; 338 return 0;
352} 339}
353 340
354#define SPRINTF_BIT(ev, bm) \ 341static struct list_head *list_get_nth_element(struct list_head *list, loff_t *pos)
355 do { \ 342{
356 len += sprintf(buf + len, "B: %s=", #ev); \ 343 struct list_head *node;
357 len += input_print_bitmap(buf + len, INT_MAX, \ 344 loff_t i = 0;
358 dev->bm##bit, ev##_MAX); \
359 len += sprintf(buf + len, "\n"); \
360 } while (0)
361 345
362#define TEST_AND_SPRINTF_BIT(ev, bm) \ 346 list_for_each(node, list)
363 do { \ 347 if (i++ == *pos)
364 if (test_bit(EV_##ev, dev->evbit)) \ 348 return node;
365 SPRINTF_BIT(ev, bm); \ 349
366 } while (0) 350 return NULL;
351}
367 352
368static int input_devices_read(char *buf, char **start, off_t pos, int count, int *eof, void *data) 353static struct list_head *list_get_next_element(struct list_head *list, struct list_head *element, loff_t *pos)
369{ 354{
370 struct input_dev *dev; 355 if (element->next == list)
371 struct input_handle *handle; 356 return NULL;
372 const char *path; 357
358 ++(*pos);
359 return element->next;
360}
361
362static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
363{
364 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
365
366 return list_get_nth_element(&input_dev_list, pos);
367}
373 368
374 off_t at = 0; 369static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
375 int len, cnt = 0; 370{
371 return list_get_next_element(&input_dev_list, v, pos);
372}
376 373
377 list_for_each_entry(dev, &input_dev_list, node) { 374static void input_devices_seq_stop(struct seq_file *seq, void *v)
375{
376 /* release lock here */
377}
378 378
379 path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL); 379static void input_seq_print_bitmap(struct seq_file *seq, const char *name,
380 unsigned long *bitmap, int max)
381{
382 int i;
380 383
381 len = sprintf(buf, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n", 384 for (i = NBITS(max) - 1; i > 0; i--)
382 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); 385 if (bitmap[i])
386 break;
383 387
384 len += sprintf(buf + len, "N: Name=\"%s\"\n", dev->name ? dev->name : ""); 388 seq_printf(seq, "B: %s=", name);
385 len += sprintf(buf + len, "P: Phys=%s\n", dev->phys ? dev->phys : ""); 389 for (; i >= 0; i--)
386 len += sprintf(buf + len, "S: Sysfs=%s\n", path ? path : ""); 390 seq_printf(seq, "%lx%s", bitmap[i], i > 0 ? " " : "");
387 len += sprintf(buf + len, "H: Handlers="); 391 seq_putc(seq, '\n');
392}
388 393
389 list_for_each_entry(handle, &dev->h_list, d_node) 394static int input_devices_seq_show(struct seq_file *seq, void *v)
390 len += sprintf(buf + len, "%s ", handle->name); 395{
391 396 struct input_dev *dev = container_of(v, struct input_dev, node);
392 len += sprintf(buf + len, "\n"); 397 const char *path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
393 398 struct input_handle *handle;
394 SPRINTF_BIT(EV, ev);
395 TEST_AND_SPRINTF_BIT(KEY, key);
396 TEST_AND_SPRINTF_BIT(REL, rel);
397 TEST_AND_SPRINTF_BIT(ABS, abs);
398 TEST_AND_SPRINTF_BIT(MSC, msc);
399 TEST_AND_SPRINTF_BIT(LED, led);
400 TEST_AND_SPRINTF_BIT(SND, snd);
401 TEST_AND_SPRINTF_BIT(FF, ff);
402 TEST_AND_SPRINTF_BIT(SW, sw);
403
404 len += sprintf(buf + len, "\n");
405
406 at += len;
407
408 if (at >= pos) {
409 if (!*start) {
410 *start = buf + (pos - (at - len));
411 cnt = at - pos;
412 } else cnt += len;
413 buf += len;
414 if (cnt >= count)
415 break;
416 }
417 399
418 kfree(path); 400 seq_printf(seq, "I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n",
419 } 401 dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
420 402
421 if (&dev->node == &input_dev_list) 403 seq_printf(seq, "N: Name=\"%s\"\n", dev->name ? dev->name : "");
422 *eof = 1; 404 seq_printf(seq, "P: Phys=%s\n", dev->phys ? dev->phys : "");
405 seq_printf(seq, "S: Sysfs=%s\n", path ? path : "");
406 seq_printf(seq, "H: Handlers=");
423 407
424 return (count > cnt) ? cnt : count; 408 list_for_each_entry(handle, &dev->h_list, d_node)
409 seq_printf(seq, "%s ", handle->name);
410 seq_putc(seq, '\n');
411
412 input_seq_print_bitmap(seq, "EV", dev->evbit, EV_MAX);
413 if (test_bit(EV_KEY, dev->evbit))
414 input_seq_print_bitmap(seq, "KEY", dev->keybit, KEY_MAX);
415 if (test_bit(EV_REL, dev->evbit))
416 input_seq_print_bitmap(seq, "REL", dev->relbit, REL_MAX);
417 if (test_bit(EV_ABS, dev->evbit))
418 input_seq_print_bitmap(seq, "ABS", dev->absbit, ABS_MAX);
419 if (test_bit(EV_MSC, dev->evbit))
420 input_seq_print_bitmap(seq, "MSC", dev->mscbit, MSC_MAX);
421 if (test_bit(EV_LED, dev->evbit))
422 input_seq_print_bitmap(seq, "LED", dev->ledbit, LED_MAX);
423 if (test_bit(EV_SND, dev->evbit))
424 input_seq_print_bitmap(seq, "SND", dev->sndbit, SND_MAX);
425 if (test_bit(EV_FF, dev->evbit))
426 input_seq_print_bitmap(seq, "FF", dev->ffbit, FF_MAX);
427 if (test_bit(EV_SW, dev->evbit))
428 input_seq_print_bitmap(seq, "SW", dev->swbit, SW_MAX);
429
430 seq_putc(seq, '\n');
431
432 kfree(path);
433 return 0;
425} 434}
426 435
427static int input_handlers_read(char *buf, char **start, off_t pos, int count, int *eof, void *data) 436static struct seq_operations input_devices_seq_ops = {
437 .start = input_devices_seq_start,
438 .next = input_devices_seq_next,
439 .stop = input_devices_seq_stop,
440 .show = input_devices_seq_show,
441};
442
443static int input_proc_devices_open(struct inode *inode, struct file *file)
428{ 444{
429 struct input_handler *handler; 445 return seq_open(file, &input_devices_seq_ops);
446}
430 447
431 off_t at = 0; 448static struct file_operations input_devices_fileops = {
432 int len = 0, cnt = 0; 449 .owner = THIS_MODULE,
433 int i = 0; 450 .open = input_proc_devices_open,
451 .poll = input_proc_devices_poll,
452 .read = seq_read,
453 .llseek = seq_lseek,
454 .release = seq_release,
455};
434 456
435 list_for_each_entry(handler, &input_handler_list, node) { 457static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
458{
459 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
460 seq->private = (void *)(unsigned long)*pos;
461 return list_get_nth_element(&input_handler_list, pos);
462}
463
464static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
465{
466 seq->private = (void *)(unsigned long)(*pos + 1);
467 return list_get_next_element(&input_handler_list, v, pos);
468}
436 469
437 if (handler->fops) 470static void input_handlers_seq_stop(struct seq_file *seq, void *v)
438 len = sprintf(buf, "N: Number=%d Name=%s Minor=%d\n", 471{
439 i++, handler->name, handler->minor); 472 /* release lock here */
440 else 473}
441 len = sprintf(buf, "N: Number=%d Name=%s\n",
442 i++, handler->name);
443 474
444 at += len; 475static int input_handlers_seq_show(struct seq_file *seq, void *v)
476{
477 struct input_handler *handler = container_of(v, struct input_handler, node);
445 478
446 if (at >= pos) { 479 seq_printf(seq, "N: Number=%ld Name=%s",
447 if (!*start) { 480 (unsigned long)seq->private, handler->name);
448 *start = buf + (pos - (at - len)); 481 if (handler->fops)
449 cnt = at - pos; 482 seq_printf(seq, " Minor=%d", handler->minor);
450 } else cnt += len; 483 seq_putc(seq, '\n');
451 buf += len;
452 if (cnt >= count)
453 break;
454 }
455 }
456 if (&handler->node == &input_handler_list)
457 *eof = 1;
458 484
459 return (count > cnt) ? cnt : count; 485 return 0;
460} 486}
487static struct seq_operations input_handlers_seq_ops = {
488 .start = input_handlers_seq_start,
489 .next = input_handlers_seq_next,
490 .stop = input_handlers_seq_stop,
491 .show = input_handlers_seq_show,
492};
461 493
462static struct file_operations input_fileops; 494static int input_proc_handlers_open(struct inode *inode, struct file *file)
495{
496 return seq_open(file, &input_handlers_seq_ops);
497}
498
499static struct file_operations input_handlers_fileops = {
500 .owner = THIS_MODULE,
501 .open = input_proc_handlers_open,
502 .read = seq_read,
503 .llseek = seq_lseek,
504 .release = seq_release,
505};
463 506
464static int __init input_proc_init(void) 507static int __init input_proc_init(void)
465{ 508{
@@ -471,20 +514,19 @@ static int __init input_proc_init(void)
471 514
472 proc_bus_input_dir->owner = THIS_MODULE; 515 proc_bus_input_dir->owner = THIS_MODULE;
473 516
474 entry = create_proc_read_entry("devices", 0, proc_bus_input_dir, input_devices_read, NULL); 517 entry = create_proc_entry("devices", 0, proc_bus_input_dir);
475 if (!entry) 518 if (!entry)
476 goto fail1; 519 goto fail1;
477 520
478 entry->owner = THIS_MODULE; 521 entry->owner = THIS_MODULE;
479 input_fileops = *entry->proc_fops; 522 entry->proc_fops = &input_devices_fileops;
480 input_fileops.poll = input_devices_poll;
481 entry->proc_fops = &input_fileops;
482 523
483 entry = create_proc_read_entry("handlers", 0, proc_bus_input_dir, input_handlers_read, NULL); 524 entry = create_proc_entry("handlers", 0, proc_bus_input_dir);
484 if (!entry) 525 if (!entry)
485 goto fail2; 526 goto fail2;
486 527
487 entry->owner = THIS_MODULE; 528 entry->owner = THIS_MODULE;
529 entry->proc_fops = &input_handlers_fileops;
488 530
489 return 0; 531 return 0;
490 532
@@ -512,13 +554,14 @@ static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \
512 struct input_dev *input_dev = to_input_dev(dev); \ 554 struct input_dev *input_dev = to_input_dev(dev); \
513 int retval; \ 555 int retval; \
514 \ 556 \
515 retval = down_interruptible(&input_dev->sem); \ 557 retval = mutex_lock_interruptible(&input_dev->mutex); \
516 if (retval) \ 558 if (retval) \
517 return retval; \ 559 return retval; \
518 \ 560 \
519 retval = sprintf(buf, "%s\n", input_dev->name ? input_dev->name : ""); \ 561 retval = scnprintf(buf, PAGE_SIZE, \
562 "%s\n", input_dev->name ? input_dev->name : ""); \
520 \ 563 \
521 up(&input_dev->sem); \ 564 mutex_unlock(&input_dev->mutex); \
522 \ 565 \
523 return retval; \ 566 return retval; \
524} \ 567} \
@@ -528,46 +571,51 @@ INPUT_DEV_STRING_ATTR_SHOW(name);
528INPUT_DEV_STRING_ATTR_SHOW(phys); 571INPUT_DEV_STRING_ATTR_SHOW(phys);
529INPUT_DEV_STRING_ATTR_SHOW(uniq); 572INPUT_DEV_STRING_ATTR_SHOW(uniq);
530 573
531static int print_modalias_bits(char *buf, int size, char prefix, unsigned long *arr, 574static int input_print_modalias_bits(char *buf, int size,
532 unsigned int min, unsigned int max) 575 char name, unsigned long *bm,
576 unsigned int min_bit, unsigned int max_bit)
533{ 577{
534 int len, i; 578 int len = 0, i;
535 579
536 len = snprintf(buf, size, "%c", prefix); 580 len += snprintf(buf, max(size, 0), "%c", name);
537 for (i = min; i < max; i++) 581 for (i = min_bit; i < max_bit; i++)
538 if (arr[LONG(i)] & BIT(i)) 582 if (bm[LONG(i)] & BIT(i))
539 len += snprintf(buf + len, size - len, "%X,", i); 583 len += snprintf(buf + len, max(size - len, 0), "%X,", i);
540 return len; 584 return len;
541} 585}
542 586
543static int print_modalias(char *buf, int size, struct input_dev *id) 587static int input_print_modalias(char *buf, int size, struct input_dev *id,
588 int add_cr)
544{ 589{
545 int len; 590 int len;
546 591
547 len = snprintf(buf, size, "input:b%04Xv%04Xp%04Xe%04X-", 592 len = snprintf(buf, max(size, 0),
548 id->id.bustype, 593 "input:b%04Xv%04Xp%04Xe%04X-",
549 id->id.vendor, 594 id->id.bustype, id->id.vendor,
550 id->id.product, 595 id->id.product, id->id.version);
551 id->id.version); 596
552 597 len += input_print_modalias_bits(buf + len, size - len,
553 len += print_modalias_bits(buf + len, size - len, 'e', id->evbit, 598 'e', id->evbit, 0, EV_MAX);
554 0, EV_MAX); 599 len += input_print_modalias_bits(buf + len, size - len,
555 len += print_modalias_bits(buf + len, size - len, 'k', id->keybit, 600 'k', id->keybit, KEY_MIN_INTERESTING, KEY_MAX);
556 KEY_MIN_INTERESTING, KEY_MAX); 601 len += input_print_modalias_bits(buf + len, size - len,
557 len += print_modalias_bits(buf + len, size - len, 'r', id->relbit, 602 'r', id->relbit, 0, REL_MAX);
558 0, REL_MAX); 603 len += input_print_modalias_bits(buf + len, size - len,
559 len += print_modalias_bits(buf + len, size - len, 'a', id->absbit, 604 'a', id->absbit, 0, ABS_MAX);
560 0, ABS_MAX); 605 len += input_print_modalias_bits(buf + len, size - len,
561 len += print_modalias_bits(buf + len, size - len, 'm', id->mscbit, 606 'm', id->mscbit, 0, MSC_MAX);
562 0, MSC_MAX); 607 len += input_print_modalias_bits(buf + len, size - len,
563 len += print_modalias_bits(buf + len, size - len, 'l', id->ledbit, 608 'l', id->ledbit, 0, LED_MAX);
564 0, LED_MAX); 609 len += input_print_modalias_bits(buf + len, size - len,
565 len += print_modalias_bits(buf + len, size - len, 's', id->sndbit, 610 's', id->sndbit, 0, SND_MAX);
566 0, SND_MAX); 611 len += input_print_modalias_bits(buf + len, size - len,
567 len += print_modalias_bits(buf + len, size - len, 'f', id->ffbit, 612 'f', id->ffbit, 0, FF_MAX);
568 0, FF_MAX); 613 len += input_print_modalias_bits(buf + len, size - len,
569 len += print_modalias_bits(buf + len, size - len, 'w', id->swbit, 614 'w', id->swbit, 0, SW_MAX);
570 0, SW_MAX); 615
616 if (add_cr)
617 len += snprintf(buf + len, max(size - len, 0), "\n");
618
571 return len; 619 return len;
572} 620}
573 621
@@ -576,9 +624,9 @@ static ssize_t input_dev_show_modalias(struct class_device *dev, char *buf)
576 struct input_dev *id = to_input_dev(dev); 624 struct input_dev *id = to_input_dev(dev);
577 ssize_t len; 625 ssize_t len;
578 626
579 len = print_modalias(buf, PAGE_SIZE, id); 627 len = input_print_modalias(buf, PAGE_SIZE, id, 1);
580 len += snprintf(buf + len, PAGE_SIZE-len, "\n"); 628
581 return len; 629 return max_t(int, len, PAGE_SIZE);
582} 630}
583static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL); 631static CLASS_DEVICE_ATTR(modalias, S_IRUGO, input_dev_show_modalias, NULL);
584 632
@@ -598,7 +646,7 @@ static struct attribute_group input_dev_attr_group = {
598static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf) \ 646static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf) \
599{ \ 647{ \
600 struct input_dev *input_dev = to_input_dev(dev); \ 648 struct input_dev *input_dev = to_input_dev(dev); \
601 return sprintf(buf, "%04x\n", input_dev->id.name); \ 649 return scnprintf(buf, PAGE_SIZE, "%04x\n", input_dev->id.name); \
602} \ 650} \
603static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL); 651static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL);
604 652
@@ -620,11 +668,33 @@ static struct attribute_group input_dev_id_attr_group = {
620 .attrs = input_dev_id_attrs, 668 .attrs = input_dev_id_attrs,
621}; 669};
622 670
671static int input_print_bitmap(char *buf, int buf_size, unsigned long *bitmap,
672 int max, int add_cr)
673{
674 int i;
675 int len = 0;
676
677 for (i = NBITS(max) - 1; i > 0; i--)
678 if (bitmap[i])
679 break;
680
681 for (; i >= 0; i--)
682 len += snprintf(buf + len, max(buf_size - len, 0),
683 "%lx%s", bitmap[i], i > 0 ? " " : "");
684
685 if (add_cr)
686 len += snprintf(buf + len, max(buf_size - len, 0), "\n");
687
688 return len;
689}
690
623#define INPUT_DEV_CAP_ATTR(ev, bm) \ 691#define INPUT_DEV_CAP_ATTR(ev, bm) \
624static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \ 692static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \
625{ \ 693{ \
626 struct input_dev *input_dev = to_input_dev(dev); \ 694 struct input_dev *input_dev = to_input_dev(dev); \
627 return input_print_bitmap(buf, PAGE_SIZE, input_dev->bm##bit, ev##_MAX);\ 695 int len = input_print_bitmap(buf, PAGE_SIZE, \
696 input_dev->bm##bit, ev##_MAX, 1); \
697 return min_t(int, len, PAGE_SIZE); \
628} \ 698} \
629static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL); 699static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
630 700
@@ -669,8 +739,8 @@ static void input_dev_release(struct class_device *class_dev)
669 * device bitfields. 739 * device bitfields.
670 */ 740 */
671static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index, 741static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
672 char *buffer, int buffer_size, int *cur_len, 742 char *buffer, int buffer_size, int *cur_len,
673 const char *name, unsigned long *bitmap, int max) 743 const char *name, unsigned long *bitmap, int max)
674{ 744{
675 if (*cur_index >= num_envp - 1) 745 if (*cur_index >= num_envp - 1)
676 return -ENOMEM; 746 return -ENOMEM;
@@ -678,12 +748,36 @@ static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
678 envp[*cur_index] = buffer + *cur_len; 748 envp[*cur_index] = buffer + *cur_len;
679 749
680 *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name); 750 *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0), name);
681 if (*cur_len > buffer_size) 751 if (*cur_len >= buffer_size)
682 return -ENOMEM; 752 return -ENOMEM;
683 753
684 *cur_len += input_print_bitmap(buffer + *cur_len, 754 *cur_len += input_print_bitmap(buffer + *cur_len,
685 max(buffer_size - *cur_len, 0), 755 max(buffer_size - *cur_len, 0),
686 bitmap, max) + 1; 756 bitmap, max, 0) + 1;
757 if (*cur_len > buffer_size)
758 return -ENOMEM;
759
760 (*cur_index)++;
761 return 0;
762}
763
764static int input_add_uevent_modalias_var(char **envp, int num_envp, int *cur_index,
765 char *buffer, int buffer_size, int *cur_len,
766 struct input_dev *dev)
767{
768 if (*cur_index >= num_envp - 1)
769 return -ENOMEM;
770
771 envp[*cur_index] = buffer + *cur_len;
772
773 *cur_len += snprintf(buffer + *cur_len, max(buffer_size - *cur_len, 0),
774 "MODALIAS=");
775 if (*cur_len >= buffer_size)
776 return -ENOMEM;
777
778 *cur_len += input_print_modalias(buffer + *cur_len,
779 max(buffer_size - *cur_len, 0),
780 dev, 0) + 1;
687 if (*cur_len > buffer_size) 781 if (*cur_len > buffer_size)
688 return -ENOMEM; 782 return -ENOMEM;
689 783
@@ -693,7 +787,7 @@ static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
693 787
694#define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \ 788#define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \
695 do { \ 789 do { \
696 int err = add_uevent_var(envp, num_envp, &i, \ 790 int err = add_uevent_var(envp, num_envp, &i, \
697 buffer, buffer_size, &len, \ 791 buffer, buffer_size, &len, \
698 fmt, val); \ 792 fmt, val); \
699 if (err) \ 793 if (err) \
@@ -709,6 +803,16 @@ static int input_add_uevent_bm_var(char **envp, int num_envp, int *cur_index,
709 return err; \ 803 return err; \
710 } while (0) 804 } while (0)
711 805
806#define INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev) \
807 do { \
808 int err = input_add_uevent_modalias_var(envp, \
809 num_envp, &i, \
810 buffer, buffer_size, &len, \
811 dev); \
812 if (err) \
813 return err; \
814 } while (0)
815
712static int input_dev_uevent(struct class_device *cdev, char **envp, 816static int input_dev_uevent(struct class_device *cdev, char **envp,
713 int num_envp, char *buffer, int buffer_size) 817 int num_envp, char *buffer, int buffer_size)
714{ 818{
@@ -744,9 +848,7 @@ static int input_dev_uevent(struct class_device *cdev, char **envp,
744 if (test_bit(EV_SW, dev->evbit)) 848 if (test_bit(EV_SW, dev->evbit))
745 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX); 849 INPUT_ADD_HOTPLUG_BM_VAR("SW=", dev->swbit, SW_MAX);
746 850
747 envp[i++] = buffer + len; 851 INPUT_ADD_HOTPLUG_MODALIAS_VAR(dev);
748 len += snprintf(buffer + len, buffer_size - len, "MODALIAS=");
749 len += print_modalias(buffer + len, buffer_size - len, dev) + 1;
750 852
751 envp[i] = NULL; 853 envp[i] = NULL;
752 return 0; 854 return 0;
@@ -790,7 +892,7 @@ int input_register_device(struct input_dev *dev)
790 return -EINVAL; 892 return -EINVAL;
791 } 893 }
792 894
793 init_MUTEX(&dev->sem); 895 mutex_init(&dev->mutex);
794 set_bit(EV_SYN, dev->evbit); 896 set_bit(EV_SYN, dev->evbit);
795 897
796 /* 898 /*
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 20e2972b9204..949bdcef8c2b 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -171,9 +171,8 @@ static int joydev_open(struct inode *inode, struct file *file)
171 if (i >= JOYDEV_MINORS || !joydev_table[i]) 171 if (i >= JOYDEV_MINORS || !joydev_table[i])
172 return -ENODEV; 172 return -ENODEV;
173 173
174 if (!(list = kmalloc(sizeof(struct joydev_list), GFP_KERNEL))) 174 if (!(list = kzalloc(sizeof(struct joydev_list), GFP_KERNEL)))
175 return -ENOMEM; 175 return -ENOMEM;
176 memset(list, 0, sizeof(struct joydev_list));
177 176
178 list->joydev = joydev_table[i]; 177 list->joydev = joydev_table[i];
179 list_add_tail(&list->node, &joydev_table[i]->list); 178 list_add_tail(&list->node, &joydev_table[i]->list);
@@ -457,9 +456,8 @@ static struct input_handle *joydev_connect(struct input_handler *handler, struct
457 return NULL; 456 return NULL;
458 } 457 }
459 458
460 if (!(joydev = kmalloc(sizeof(struct joydev), GFP_KERNEL))) 459 if (!(joydev = kzalloc(sizeof(struct joydev), GFP_KERNEL)))
461 return NULL; 460 return NULL;
462 memset(joydev, 0, sizeof(struct joydev));
463 461
464 INIT_LIST_HEAD(&joydev->list); 462 INIT_LIST_HEAD(&joydev->list);
465 init_waitqueue_head(&joydev->wait); 463 init_waitqueue_head(&joydev->wait);
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index ec55a29fc861..7249d324297b 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -36,6 +36,7 @@
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/input.h> 37#include <linux/input.h>
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/mutex.h>
39 40
40#include <asm/system.h> 41#include <asm/system.h>
41#include <asm/amigahw.h> 42#include <asm/amigahw.h>
@@ -52,7 +53,7 @@ MODULE_PARM_DESC(map, "Map of attached joysticks in form of <a>,<b> (default is
52__obsolete_setup("amijoy="); 53__obsolete_setup("amijoy=");
53 54
54static int amijoy_used; 55static int amijoy_used;
55static DECLARE_MUTEX(amijoy_sem); 56static DEFINE_MUTEX(amijoy_mutex);
56static struct input_dev *amijoy_dev[2]; 57static struct input_dev *amijoy_dev[2];
57static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" }; 58static char *amijoy_phys[2] = { "amijoy/input0", "amijoy/input1" };
58 59
@@ -85,7 +86,7 @@ static int amijoy_open(struct input_dev *dev)
85{ 86{
86 int err; 87 int err;
87 88
88 err = down_interruptible(&amijoy_sem); 89 err = mutex_lock_interruptible(&amijoy_mutex);
89 if (err) 90 if (err)
90 return err; 91 return err;
91 92
@@ -97,16 +98,16 @@ static int amijoy_open(struct input_dev *dev)
97 98
98 amijoy_used++; 99 amijoy_used++;
99out: 100out:
100 up(&amijoy_sem); 101 mutex_unlock(&amijoy_mutex);
101 return err; 102 return err;
102} 103}
103 104
104static void amijoy_close(struct input_dev *dev) 105static void amijoy_close(struct input_dev *dev)
105{ 106{
106 down(&amijoy_sem); 107 mutex_lock(&amijoy_mutex);
107 if (!--amijoy_used) 108 if (!--amijoy_used)
108 free_irq(IRQ_AMIGA_VERTB, amijoy_interrupt); 109 free_irq(IRQ_AMIGA_VERTB, amijoy_interrupt);
109 up(&amijoy_sem); 110 mutex_unlock(&amijoy_mutex);
110} 111}
111 112
112static int __init amijoy_init(void) 113static int __init amijoy_init(void)
diff --git a/drivers/input/joystick/db9.c b/drivers/input/joystick/db9.c
index dcffc34f30c3..e61894685cb1 100644
--- a/drivers/input/joystick/db9.c
+++ b/drivers/input/joystick/db9.c
@@ -38,6 +38,7 @@
38#include <linux/init.h> 38#include <linux/init.h>
39#include <linux/parport.h> 39#include <linux/parport.h>
40#include <linux/input.h> 40#include <linux/input.h>
41#include <linux/mutex.h>
41 42
42MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 43MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); 44MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver");
@@ -111,7 +112,7 @@ struct db9 {
111 struct pardevice *pd; 112 struct pardevice *pd;
112 int mode; 113 int mode;
113 int used; 114 int used;
114 struct semaphore sem; 115 struct mutex mutex;
115 char phys[DB9_MAX_DEVICES][32]; 116 char phys[DB9_MAX_DEVICES][32];
116}; 117};
117 118
@@ -525,7 +526,7 @@ static int db9_open(struct input_dev *dev)
525 struct parport *port = db9->pd->port; 526 struct parport *port = db9->pd->port;
526 int err; 527 int err;
527 528
528 err = down_interruptible(&db9->sem); 529 err = mutex_lock_interruptible(&db9->mutex);
529 if (err) 530 if (err)
530 return err; 531 return err;
531 532
@@ -539,7 +540,7 @@ static int db9_open(struct input_dev *dev)
539 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); 540 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME);
540 } 541 }
541 542
542 up(&db9->sem); 543 mutex_unlock(&db9->mutex);
543 return 0; 544 return 0;
544} 545}
545 546
@@ -548,14 +549,14 @@ static void db9_close(struct input_dev *dev)
548 struct db9 *db9 = dev->private; 549 struct db9 *db9 = dev->private;
549 struct parport *port = db9->pd->port; 550 struct parport *port = db9->pd->port;
550 551
551 down(&db9->sem); 552 mutex_lock(&db9->mutex);
552 if (!--db9->used) { 553 if (!--db9->used) {
553 del_timer_sync(&db9->timer); 554 del_timer_sync(&db9->timer);
554 parport_write_control(port, 0x00); 555 parport_write_control(port, 0x00);
555 parport_data_forward(port); 556 parport_data_forward(port);
556 parport_release(db9->pd); 557 parport_release(db9->pd);
557 } 558 }
558 up(&db9->sem); 559 mutex_unlock(&db9->mutex);
559} 560}
560 561
561static struct db9 __init *db9_probe(int parport, int mode) 562static struct db9 __init *db9_probe(int parport, int mode)
@@ -603,7 +604,7 @@ static struct db9 __init *db9_probe(int parport, int mode)
603 goto err_unreg_pardev; 604 goto err_unreg_pardev;
604 } 605 }
605 606
606 init_MUTEX(&db9->sem); 607 mutex_init(&db9->mutex);
607 db9->pd = pd; 608 db9->pd = pd;
608 db9->mode = mode; 609 db9->mode = mode;
609 init_timer(&db9->timer); 610 init_timer(&db9->timer);
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 900587acdb47..ecbdb6b9bbd6 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -7,6 +7,7 @@
7 * Based on the work of: 7 * Based on the work of:
8 * Andree Borrmann John Dahlstrom 8 * Andree Borrmann John Dahlstrom
9 * David Kuder Nathan Hand 9 * David Kuder Nathan Hand
10 * Raphael Assenat
10 */ 11 */
11 12
12/* 13/*
@@ -36,6 +37,7 @@
36#include <linux/init.h> 37#include <linux/init.h>
37#include <linux/parport.h> 38#include <linux/parport.h>
38#include <linux/input.h> 39#include <linux/input.h>
40#include <linux/mutex.h>
39 41
40MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 42MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); 43MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
@@ -72,8 +74,9 @@ __obsolete_setup("gc_3=");
72#define GC_N64 6 74#define GC_N64 6
73#define GC_PSX 7 75#define GC_PSX 7
74#define GC_DDR 8 76#define GC_DDR 8
77#define GC_SNESMOUSE 9
75 78
76#define GC_MAX 8 79#define GC_MAX 9
77 80
78#define GC_REFRESH_TIME HZ/100 81#define GC_REFRESH_TIME HZ/100
79 82
@@ -83,7 +86,7 @@ struct gc {
83 struct timer_list timer; 86 struct timer_list timer;
84 unsigned char pads[GC_MAX + 1]; 87 unsigned char pads[GC_MAX + 1];
85 int used; 88 int used;
86 struct semaphore sem; 89 struct mutex mutex;
87 char phys[GC_MAX_DEVICES][32]; 90 char phys[GC_MAX_DEVICES][32];
88}; 91};
89 92
@@ -93,7 +96,7 @@ static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
93 96
94static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick", 97static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
95 "Multisystem 2-button joystick", "N64 controller", "PSX controller", 98 "Multisystem 2-button joystick", "N64 controller", "PSX controller",
96 "PSX DDR controller" }; 99 "PSX DDR controller", "SNES mouse" };
97/* 100/*
98 * N64 support. 101 * N64 support.
99 */ 102 */
@@ -205,9 +208,12 @@ static void gc_n64_process_packet(struct gc *gc)
205 * NES/SNES support. 208 * NES/SNES support.
206 */ 209 */
207 210
208#define GC_NES_DELAY 6 /* Delay between bits - 6us */ 211#define GC_NES_DELAY 6 /* Delay between bits - 6us */
209#define GC_NES_LENGTH 8 /* The NES pads use 8 bits of data */ 212#define GC_NES_LENGTH 8 /* The NES pads use 8 bits of data */
210#define GC_SNES_LENGTH 12 /* The SNES true length is 16, but the last 4 bits are unused */ 213#define GC_SNES_LENGTH 12 /* The SNES true length is 16, but the
214 last 4 bits are unused */
215#define GC_SNESMOUSE_LENGTH 32 /* The SNES mouse uses 32 bits, the first
216 16 bits are equivalent to a gamepad */
211 217
212#define GC_NES_POWER 0xfc 218#define GC_NES_POWER 0xfc
213#define GC_NES_CLOCK 0x01 219#define GC_NES_CLOCK 0x01
@@ -242,11 +248,15 @@ static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data)
242 248
243static void gc_nes_process_packet(struct gc *gc) 249static void gc_nes_process_packet(struct gc *gc)
244{ 250{
245 unsigned char data[GC_SNES_LENGTH]; 251 unsigned char data[GC_SNESMOUSE_LENGTH];
246 struct input_dev *dev; 252 struct input_dev *dev;
247 int i, j, s; 253 int i, j, s, len;
254 char x_rel, y_rel;
255
256 len = gc->pads[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH :
257 (gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH);
248 258
249 gc_nes_read_packet(gc, gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH, data); 259 gc_nes_read_packet(gc, len, data);
250 260
251 for (i = 0; i < GC_MAX_DEVICES; i++) { 261 for (i = 0; i < GC_MAX_DEVICES; i++) {
252 262
@@ -269,6 +279,44 @@ static void gc_nes_process_packet(struct gc *gc)
269 for (j = 0; j < 8; j++) 279 for (j = 0; j < 8; j++)
270 input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 280 input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]);
271 281
282 if (s & gc->pads[GC_SNESMOUSE]) {
283 /*
284 * The 4 unused bits from SNES controllers appear to be ID bits
285 * so use them to make sure iwe are dealing with a mouse.
286 * gamepad is connected. This is important since
287 * my SNES gamepad sends 1's for bits 16-31, which
288 * cause the mouse pointer to quickly move to the
289 * upper left corner of the screen.
290 */
291 if (!(s & data[12]) && !(s & data[13]) &&
292 !(s & data[14]) && (s & data[15])) {
293 input_report_key(dev, BTN_LEFT, s & data[9]);
294 input_report_key(dev, BTN_RIGHT, s & data[8]);
295
296 x_rel = y_rel = 0;
297 for (j = 0; j < 7; j++) {
298 x_rel <<= 1;
299 if (data[25 + j] & s)
300 x_rel |= 1;
301
302 y_rel <<= 1;
303 if (data[17 + j] & s)
304 y_rel |= 1;
305 }
306
307 if (x_rel) {
308 if (data[24] & s)
309 x_rel = -x_rel;
310 input_report_rel(dev, REL_X, x_rel);
311 }
312
313 if (y_rel) {
314 if (data[16] & s)
315 y_rel = -y_rel;
316 input_report_rel(dev, REL_Y, y_rel);
317 }
318 }
319 }
272 input_sync(dev); 320 input_sync(dev);
273 } 321 }
274} 322}
@@ -524,10 +572,10 @@ static void gc_timer(unsigned long private)
524 gc_n64_process_packet(gc); 572 gc_n64_process_packet(gc);
525 573
526/* 574/*
527 * NES and SNES pads 575 * NES and SNES pads or mouse
528 */ 576 */
529 577
530 if (gc->pads[GC_NES] || gc->pads[GC_SNES]) 578 if (gc->pads[GC_NES] || gc->pads[GC_SNES] || gc->pads[GC_SNESMOUSE])
531 gc_nes_process_packet(gc); 579 gc_nes_process_packet(gc);
532 580
533/* 581/*
@@ -552,7 +600,7 @@ static int gc_open(struct input_dev *dev)
552 struct gc *gc = dev->private; 600 struct gc *gc = dev->private;
553 int err; 601 int err;
554 602
555 err = down_interruptible(&gc->sem); 603 err = mutex_lock_interruptible(&gc->mutex);
556 if (err) 604 if (err)
557 return err; 605 return err;
558 606
@@ -562,7 +610,7 @@ static int gc_open(struct input_dev *dev)
562 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 610 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
563 } 611 }
564 612
565 up(&gc->sem); 613 mutex_unlock(&gc->mutex);
566 return 0; 614 return 0;
567} 615}
568 616
@@ -570,13 +618,13 @@ static void gc_close(struct input_dev *dev)
570{ 618{
571 struct gc *gc = dev->private; 619 struct gc *gc = dev->private;
572 620
573 down(&gc->sem); 621 mutex_lock(&gc->mutex);
574 if (!--gc->used) { 622 if (!--gc->used) {
575 del_timer_sync(&gc->timer); 623 del_timer_sync(&gc->timer);
576 parport_write_control(gc->pd->port, 0x00); 624 parport_write_control(gc->pd->port, 0x00);
577 parport_release(gc->pd); 625 parport_release(gc->pd);
578 } 626 }
579 up(&gc->sem); 627 mutex_unlock(&gc->mutex);
580} 628}
581 629
582static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type) 630static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
@@ -609,10 +657,13 @@ static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
609 input_dev->open = gc_open; 657 input_dev->open = gc_open;
610 input_dev->close = gc_close; 658 input_dev->close = gc_close;
611 659
612 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 660 if (pad_type != GC_SNESMOUSE) {
661 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
613 662
614 for (i = 0; i < 2; i++) 663 for (i = 0; i < 2; i++)
615 input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0); 664 input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0);
665 } else
666 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
616 667
617 gc->pads[0] |= gc_status_bit[idx]; 668 gc->pads[0] |= gc_status_bit[idx];
618 gc->pads[pad_type] |= gc_status_bit[idx]; 669 gc->pads[pad_type] |= gc_status_bit[idx];
@@ -630,6 +681,13 @@ static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
630 681
631 break; 682 break;
632 683
684 case GC_SNESMOUSE:
685 set_bit(BTN_LEFT, input_dev->keybit);
686 set_bit(BTN_RIGHT, input_dev->keybit);
687 set_bit(REL_X, input_dev->relbit);
688 set_bit(REL_Y, input_dev->relbit);
689 break;
690
633 case GC_SNES: 691 case GC_SNES:
634 for (i = 4; i < 8; i++) 692 for (i = 4; i < 8; i++)
635 set_bit(gc_snes_btn[i], input_dev->keybit); 693 set_bit(gc_snes_btn[i], input_dev->keybit);
@@ -693,7 +751,7 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
693 goto err_unreg_pardev; 751 goto err_unreg_pardev;
694 } 752 }
695 753
696 init_MUTEX(&gc->sem); 754 mutex_init(&gc->mutex);
697 gc->pd = pd; 755 gc->pd = pd;
698 init_timer(&gc->timer); 756 init_timer(&gc->timer);
699 gc->timer.data = (long) gc; 757 gc->timer.data = (long) gc;
diff --git a/drivers/input/joystick/iforce/iforce-ff.c b/drivers/input/joystick/iforce/iforce-ff.c
index 4678b6dab43b..2b8e8456c9fa 100644
--- a/drivers/input/joystick/iforce/iforce-ff.c
+++ b/drivers/input/joystick/iforce/iforce-ff.c
@@ -42,14 +42,14 @@ static int make_magnitude_modifier(struct iforce* iforce,
42 unsigned char data[3]; 42 unsigned char data[3];
43 43
44 if (!no_alloc) { 44 if (!no_alloc) {
45 down(&iforce->mem_mutex); 45 mutex_lock(&iforce->mem_mutex);
46 if (allocate_resource(&(iforce->device_memory), mod_chunk, 2, 46 if (allocate_resource(&(iforce->device_memory), mod_chunk, 2,
47 iforce->device_memory.start, iforce->device_memory.end, 2L, 47 iforce->device_memory.start, iforce->device_memory.end, 2L,
48 NULL, NULL)) { 48 NULL, NULL)) {
49 up(&iforce->mem_mutex); 49 mutex_unlock(&iforce->mem_mutex);
50 return -ENOMEM; 50 return -ENOMEM;
51 } 51 }
52 up(&iforce->mem_mutex); 52 mutex_unlock(&iforce->mem_mutex);
53 } 53 }
54 54
55 data[0] = LO(mod_chunk->start); 55 data[0] = LO(mod_chunk->start);
@@ -75,14 +75,14 @@ static int make_period_modifier(struct iforce* iforce,
75 period = TIME_SCALE(period); 75 period = TIME_SCALE(period);
76 76
77 if (!no_alloc) { 77 if (!no_alloc) {
78 down(&iforce->mem_mutex); 78 mutex_lock(&iforce->mem_mutex);
79 if (allocate_resource(&(iforce->device_memory), mod_chunk, 0x0c, 79 if (allocate_resource(&(iforce->device_memory), mod_chunk, 0x0c,
80 iforce->device_memory.start, iforce->device_memory.end, 2L, 80 iforce->device_memory.start, iforce->device_memory.end, 2L,
81 NULL, NULL)) { 81 NULL, NULL)) {
82 up(&iforce->mem_mutex); 82 mutex_unlock(&iforce->mem_mutex);
83 return -ENOMEM; 83 return -ENOMEM;
84 } 84 }
85 up(&iforce->mem_mutex); 85 mutex_unlock(&iforce->mem_mutex);
86 } 86 }
87 87
88 data[0] = LO(mod_chunk->start); 88 data[0] = LO(mod_chunk->start);
@@ -115,14 +115,14 @@ static int make_envelope_modifier(struct iforce* iforce,
115 fade_duration = TIME_SCALE(fade_duration); 115 fade_duration = TIME_SCALE(fade_duration);
116 116
117 if (!no_alloc) { 117 if (!no_alloc) {
118 down(&iforce->mem_mutex); 118 mutex_lock(&iforce->mem_mutex);
119 if (allocate_resource(&(iforce->device_memory), mod_chunk, 0x0e, 119 if (allocate_resource(&(iforce->device_memory), mod_chunk, 0x0e,
120 iforce->device_memory.start, iforce->device_memory.end, 2L, 120 iforce->device_memory.start, iforce->device_memory.end, 2L,
121 NULL, NULL)) { 121 NULL, NULL)) {
122 up(&iforce->mem_mutex); 122 mutex_unlock(&iforce->mem_mutex);
123 return -ENOMEM; 123 return -ENOMEM;
124 } 124 }
125 up(&iforce->mem_mutex); 125 mutex_unlock(&iforce->mem_mutex);
126 } 126 }
127 127
128 data[0] = LO(mod_chunk->start); 128 data[0] = LO(mod_chunk->start);
@@ -152,14 +152,14 @@ static int make_condition_modifier(struct iforce* iforce,
152 unsigned char data[10]; 152 unsigned char data[10];
153 153
154 if (!no_alloc) { 154 if (!no_alloc) {
155 down(&iforce->mem_mutex); 155 mutex_lock(&iforce->mem_mutex);
156 if (allocate_resource(&(iforce->device_memory), mod_chunk, 8, 156 if (allocate_resource(&(iforce->device_memory), mod_chunk, 8,
157 iforce->device_memory.start, iforce->device_memory.end, 2L, 157 iforce->device_memory.start, iforce->device_memory.end, 2L,
158 NULL, NULL)) { 158 NULL, NULL)) {
159 up(&iforce->mem_mutex); 159 mutex_unlock(&iforce->mem_mutex);
160 return -ENOMEM; 160 return -ENOMEM;
161 } 161 }
162 up(&iforce->mem_mutex); 162 mutex_unlock(&iforce->mem_mutex);
163 } 163 }
164 164
165 data[0] = LO(mod_chunk->start); 165 data[0] = LO(mod_chunk->start);
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index b6bc04998047..ab0a26b924ca 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -350,7 +350,7 @@ int iforce_init_device(struct iforce *iforce)
350 350
351 init_waitqueue_head(&iforce->wait); 351 init_waitqueue_head(&iforce->wait);
352 spin_lock_init(&iforce->xmit_lock); 352 spin_lock_init(&iforce->xmit_lock);
353 init_MUTEX(&iforce->mem_mutex); 353 mutex_init(&iforce->mem_mutex);
354 iforce->xmit.buf = iforce->xmit_data; 354 iforce->xmit.buf = iforce->xmit_data;
355 iforce->dev = input_dev; 355 iforce->dev = input_dev;
356 356
diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h
index 146f406b8f8a..668f24535ba0 100644
--- a/drivers/input/joystick/iforce/iforce.h
+++ b/drivers/input/joystick/iforce/iforce.h
@@ -37,7 +37,7 @@
37#include <linux/serio.h> 37#include <linux/serio.h>
38#include <linux/config.h> 38#include <linux/config.h>
39#include <linux/circ_buf.h> 39#include <linux/circ_buf.h>
40#include <asm/semaphore.h> 40#include <linux/mutex.h>
41 41
42/* This module provides arbitrary resource management routines. 42/* This module provides arbitrary resource management routines.
43 * I use it to manage the device's memory. 43 * I use it to manage the device's memory.
@@ -45,6 +45,7 @@
45 */ 45 */
46#include <linux/ioport.h> 46#include <linux/ioport.h>
47 47
48
48#define IFORCE_MAX_LENGTH 16 49#define IFORCE_MAX_LENGTH 16
49 50
50/* iforce::bus */ 51/* iforce::bus */
@@ -146,7 +147,7 @@ struct iforce {
146 wait_queue_head_t wait; 147 wait_queue_head_t wait;
147 struct resource device_memory; 148 struct resource device_memory;
148 struct iforce_core_effect core_effects[FF_EFFECTS_MAX]; 149 struct iforce_core_effect core_effects[FF_EFFECTS_MAX];
149 struct semaphore mem_mutex; 150 struct mutex mem_mutex;
150}; 151};
151 152
152/* Get hi and low bytes of a 16-bits int */ 153/* Get hi and low bytes of a 16-bits int */
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c
index b154938e88a4..5570fd5487c7 100644
--- a/drivers/input/joystick/turbografx.c
+++ b/drivers/input/joystick/turbografx.c
@@ -37,6 +37,7 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/mutex.h>
40 41
41MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 42MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
42MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); 43MODULE_DESCRIPTION("TurboGraFX parallel port interface driver");
@@ -86,7 +87,7 @@ static struct tgfx {
86 char phys[TGFX_MAX_DEVICES][32]; 87 char phys[TGFX_MAX_DEVICES][32];
87 int sticks; 88 int sticks;
88 int used; 89 int used;
89 struct semaphore sem; 90 struct mutex sem;
90} *tgfx_base[TGFX_MAX_PORTS]; 91} *tgfx_base[TGFX_MAX_PORTS];
91 92
92/* 93/*
@@ -128,7 +129,7 @@ static int tgfx_open(struct input_dev *dev)
128 struct tgfx *tgfx = dev->private; 129 struct tgfx *tgfx = dev->private;
129 int err; 130 int err;
130 131
131 err = down_interruptible(&tgfx->sem); 132 err = mutex_lock_interruptible(&tgfx->sem);
132 if (err) 133 if (err)
133 return err; 134 return err;
134 135
@@ -138,7 +139,7 @@ static int tgfx_open(struct input_dev *dev)
138 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME); 139 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
139 } 140 }
140 141
141 up(&tgfx->sem); 142 mutex_unlock(&tgfx->sem);
142 return 0; 143 return 0;
143} 144}
144 145
@@ -146,13 +147,13 @@ static void tgfx_close(struct input_dev *dev)
146{ 147{
147 struct tgfx *tgfx = dev->private; 148 struct tgfx *tgfx = dev->private;
148 149
149 down(&tgfx->sem); 150 mutex_lock(&tgfx->sem);
150 if (!--tgfx->used) { 151 if (!--tgfx->used) {
151 del_timer_sync(&tgfx->timer); 152 del_timer_sync(&tgfx->timer);
152 parport_write_control(tgfx->pd->port, 0x00); 153 parport_write_control(tgfx->pd->port, 0x00);
153 parport_release(tgfx->pd); 154 parport_release(tgfx->pd);
154 } 155 }
155 up(&tgfx->sem); 156 mutex_unlock(&tgfx->sem);
156} 157}
157 158
158 159
@@ -191,7 +192,7 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs)
191 goto err_unreg_pardev; 192 goto err_unreg_pardev;
192 } 193 }
193 194
194 init_MUTEX(&tgfx->sem); 195 mutex_init(&tgfx->sem);
195 tgfx->pd = pd; 196 tgfx->pd = pd;
196 init_timer(&tgfx->timer); 197 init_timer(&tgfx->timer);
197 tgfx->timer.data = (long) tgfx; 198 tgfx->timer.data = (long) tgfx;
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 3b0ac3b43c54..a9dda56f62c4 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -13,7 +13,7 @@ menuconfig INPUT_KEYBOARD
13if INPUT_KEYBOARD 13if INPUT_KEYBOARD
14 14
15config KEYBOARD_ATKBD 15config KEYBOARD_ATKBD
16 tristate "AT keyboard" if !X86_PC 16 tristate "AT keyboard" if EMBEDDED || !X86_PC
17 default y 17 default y
18 select SERIO 18 select SERIO
19 select SERIO_LIBPS2 19 select SERIO_LIBPS2
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index ffacf6eca5f5..fad04b66d268 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -27,6 +27,7 @@
27#include <linux/serio.h> 27#include <linux/serio.h>
28#include <linux/workqueue.h> 28#include <linux/workqueue.h>
29#include <linux/libps2.h> 29#include <linux/libps2.h>
30#include <linux/mutex.h>
30 31
31#define DRIVER_DESC "AT and PS/2 keyboard driver" 32#define DRIVER_DESC "AT and PS/2 keyboard driver"
32 33
@@ -216,7 +217,7 @@ struct atkbd {
216 unsigned long time; 217 unsigned long time;
217 218
218 struct work_struct event_work; 219 struct work_struct event_work;
219 struct semaphore event_sem; 220 struct mutex event_mutex;
220 unsigned long event_mask; 221 unsigned long event_mask;
221}; 222};
222 223
@@ -302,19 +303,19 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
302 if (atkbd->translated) { 303 if (atkbd->translated) {
303 304
304 if (atkbd->emul || 305 if (atkbd->emul ||
305 !(code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1 || 306 (code != ATKBD_RET_EMUL0 && code != ATKBD_RET_EMUL1 &&
306 code == ATKBD_RET_HANGUEL || code == ATKBD_RET_HANJA || 307 code != ATKBD_RET_HANGUEL && code != ATKBD_RET_HANJA &&
307 (code == ATKBD_RET_ERR && !atkbd->err_xl) || 308 (code != ATKBD_RET_ERR || atkbd->err_xl) &&
308 (code == ATKBD_RET_BAT && !atkbd->bat_xl))) { 309 (code != ATKBD_RET_BAT || atkbd->bat_xl))) {
309 atkbd->release = code >> 7; 310 atkbd->release = code >> 7;
310 code &= 0x7f; 311 code &= 0x7f;
311 } 312 }
312 313
313 if (!atkbd->emul) { 314 if (!atkbd->emul) {
314 if ((code & 0x7f) == (ATKBD_RET_BAT & 0x7f)) 315 if ((code & 0x7f) == (ATKBD_RET_BAT & 0x7f))
315 atkbd->bat_xl = !atkbd->release; 316 atkbd->bat_xl = !(data >> 7);
316 if ((code & 0x7f) == (ATKBD_RET_ERR & 0x7f)) 317 if ((code & 0x7f) == (ATKBD_RET_ERR & 0x7f))
317 atkbd->err_xl = !atkbd->release; 318 atkbd->err_xl = !(data >> 7);
318 } 319 }
319 } 320 }
320 321
@@ -449,7 +450,7 @@ static void atkbd_event_work(void *data)
449 unsigned char param[2]; 450 unsigned char param[2];
450 int i, j; 451 int i, j;
451 452
452 down(&atkbd->event_sem); 453 mutex_lock(&atkbd->event_mutex);
453 454
454 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) { 455 if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) {
455 param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0) 456 param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0)
@@ -480,7 +481,7 @@ static void atkbd_event_work(void *data)
480 ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETREP); 481 ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETREP);
481 } 482 }
482 483
483 up(&atkbd->event_sem); 484 mutex_unlock(&atkbd->event_mutex);
484} 485}
485 486
486/* 487/*
@@ -846,7 +847,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
846 atkbd->dev = dev; 847 atkbd->dev = dev;
847 ps2_init(&atkbd->ps2dev, serio); 848 ps2_init(&atkbd->ps2dev, serio);
848 INIT_WORK(&atkbd->event_work, atkbd_event_work, atkbd); 849 INIT_WORK(&atkbd->event_work, atkbd_event_work, atkbd);
849 init_MUTEX(&atkbd->event_sem); 850 mutex_init(&atkbd->event_mutex);
850 851
851 switch (serio->id.type) { 852 switch (serio->id.type) {
852 853
@@ -862,9 +863,6 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
862 atkbd->softrepeat = atkbd_softrepeat; 863 atkbd->softrepeat = atkbd_softrepeat;
863 atkbd->scroll = atkbd_scroll; 864 atkbd->scroll = atkbd_scroll;
864 865
865 if (!atkbd->write)
866 atkbd->softrepeat = 1;
867
868 if (atkbd->softrepeat) 866 if (atkbd->softrepeat)
869 atkbd->softraw = 1; 867 atkbd->softraw = 1;
870 868
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index e301ee4ca264..96c6bf77248a 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -29,11 +29,11 @@
29#define KB_COLS 12 29#define KB_COLS 12
30#define KB_ROWMASK(r) (1 << (r)) 30#define KB_ROWMASK(r) (1 << (r))
31#define SCANCODE(r,c) ( ((r)<<4) + (c) + 1 ) 31#define SCANCODE(r,c) ( ((r)<<4) + (c) + 1 )
32/* zero code, 124 scancodes + 3 hinge combinations */ 32/* zero code, 124 scancodes */
33#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 +3 ) 33#define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 )
34#define SCAN_INTERVAL (HZ/10)
35 34
36#define HINGE_SCAN_INTERVAL (HZ/4) 35#define SCAN_INTERVAL (50) /* ms */
36#define HINGE_SCAN_INTERVAL (250) /* ms */
37 37
38#define CORGI_KEY_CALENDER KEY_F1 38#define CORGI_KEY_CALENDER KEY_F1
39#define CORGI_KEY_ADDRESS KEY_F2 39#define CORGI_KEY_ADDRESS KEY_F2
@@ -49,9 +49,6 @@
49#define CORGI_KEY_MAIL KEY_F10 49#define CORGI_KEY_MAIL KEY_F10
50#define CORGI_KEY_OK KEY_F11 50#define CORGI_KEY_OK KEY_F11
51#define CORGI_KEY_MENU KEY_F12 51#define CORGI_KEY_MENU KEY_F12
52#define CORGI_HINGE_0 KEY_KP0
53#define CORGI_HINGE_1 KEY_KP1
54#define CORGI_HINGE_2 KEY_KP2
55 52
56static unsigned char corgikbd_keycode[NR_SCANCODES] = { 53static unsigned char corgikbd_keycode[NR_SCANCODES] = {
57 0, /* 0 */ 54 0, /* 0 */
@@ -63,7 +60,6 @@ static unsigned char corgikbd_keycode[NR_SCANCODES] = {
63 CORGI_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */ 60 CORGI_KEY_MAIL, KEY_Z, KEY_X, KEY_MINUS, KEY_SPACE, KEY_COMMA, 0, KEY_UP, 0, 0, 0, CORGI_KEY_FN, 0, 0, 0, 0, /* 81-96 */
64 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, CORGI_KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */ 61 KEY_SYSRQ, CORGI_KEY_JAP1, CORGI_KEY_JAP2, CORGI_KEY_CANCEL, CORGI_KEY_OK, CORGI_KEY_MENU, KEY_LEFT, KEY_DOWN, KEY_RIGHT, 0, 0, 0, 0, 0, 0, 0, /* 97-112 */
65 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */ 62 CORGI_KEY_OFF, CORGI_KEY_EXOK, CORGI_KEY_EXCANCEL, CORGI_KEY_EXJOGDOWN, CORGI_KEY_EXJOGUP, 0, 0, 0, 0, 0, 0, 0, /* 113-124 */
66 CORGI_HINGE_0, CORGI_HINGE_1, CORGI_HINGE_2 /* 125-127 */
67}; 63};
68 64
69 65
@@ -187,7 +183,7 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs
187 183
188 /* if any keys are pressed, enable the timer */ 184 /* if any keys are pressed, enable the timer */
189 if (num_pressed) 185 if (num_pressed)
190 mod_timer(&corgikbd_data->timer, jiffies + SCAN_INTERVAL); 186 mod_timer(&corgikbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL));
191 187
192 spin_unlock_irqrestore(&corgikbd_data->lock, flags); 188 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
193} 189}
@@ -228,6 +224,7 @@ static void corgikbd_timer_callback(unsigned long data)
228 * 0x0c - Keyboard and Screen Closed 224 * 0x0c - Keyboard and Screen Closed
229 */ 225 */
230 226
227#define READ_GPIO_BIT(x) (GPLR(x) & GPIO_bit(x))
231#define HINGE_STABLE_COUNT 2 228#define HINGE_STABLE_COUNT 2
232static int sharpsl_hinge_state; 229static int sharpsl_hinge_state;
233static int hinge_count; 230static int hinge_count;
@@ -239,6 +236,7 @@ static void corgikbd_hinge_timer(unsigned long data)
239 unsigned long flags; 236 unsigned long flags;
240 237
241 gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB); 238 gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB);
239 gprr |= (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0);
242 if (gprr != sharpsl_hinge_state) { 240 if (gprr != sharpsl_hinge_state) {
243 hinge_count = 0; 241 hinge_count = 0;
244 sharpsl_hinge_state = gprr; 242 sharpsl_hinge_state = gprr;
@@ -249,27 +247,38 @@ static void corgikbd_hinge_timer(unsigned long data)
249 247
250 input_report_switch(corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0)); 248 input_report_switch(corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0));
251 input_report_switch(corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0)); 249 input_report_switch(corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0));
250 input_report_switch(corgikbd_data->input, SW_2, (READ_GPIO_BIT(CORGI_GPIO_AK_INT) != 0));
252 input_sync(corgikbd_data->input); 251 input_sync(corgikbd_data->input);
253 252
254 spin_unlock_irqrestore(&corgikbd_data->lock, flags); 253 spin_unlock_irqrestore(&corgikbd_data->lock, flags);
255 } 254 }
256 } 255 }
257 mod_timer(&corgikbd_data->htimer, jiffies + HINGE_SCAN_INTERVAL); 256 mod_timer(&corgikbd_data->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
258} 257}
259 258
260#ifdef CONFIG_PM 259#ifdef CONFIG_PM
261static int corgikbd_suspend(struct platform_device *dev, pm_message_t state) 260static int corgikbd_suspend(struct platform_device *dev, pm_message_t state)
262{ 261{
262 int i;
263 struct corgikbd *corgikbd = platform_get_drvdata(dev); 263 struct corgikbd *corgikbd = platform_get_drvdata(dev);
264
264 corgikbd->suspended = 1; 265 corgikbd->suspended = 1;
266 /* strobe 0 is the power key so this can't be made an input for
267 powersaving therefore i = 1 */
268 for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
269 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_IN);
265 270
266 return 0; 271 return 0;
267} 272}
268 273
269static int corgikbd_resume(struct platform_device *dev) 274static int corgikbd_resume(struct platform_device *dev)
270{ 275{
276 int i;
271 struct corgikbd *corgikbd = platform_get_drvdata(dev); 277 struct corgikbd *corgikbd = platform_get_drvdata(dev);
272 278
279 for (i = 1; i < CORGI_KEY_STROBE_NUM; i++)
280 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
281
273 /* Upon resume, ignore the suspend key for a short while */ 282 /* Upon resume, ignore the suspend key for a short while */
274 corgikbd->suspend_jiffies=jiffies; 283 corgikbd->suspend_jiffies=jiffies;
275 corgikbd->suspended = 0; 284 corgikbd->suspended = 0;
@@ -333,10 +342,11 @@ static int __init corgikbd_probe(struct platform_device *pdev)
333 clear_bit(0, input_dev->keybit); 342 clear_bit(0, input_dev->keybit);
334 set_bit(SW_0, input_dev->swbit); 343 set_bit(SW_0, input_dev->swbit);
335 set_bit(SW_1, input_dev->swbit); 344 set_bit(SW_1, input_dev->swbit);
345 set_bit(SW_2, input_dev->swbit);
336 346
337 input_register_device(corgikbd->input); 347 input_register_device(corgikbd->input);
338 348
339 mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL); 349 mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
340 350
341 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ 351 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
342 for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) { 352 for (i = 0; i < CORGI_KEY_SENSE_NUM; i++) {
@@ -351,6 +361,9 @@ static int __init corgikbd_probe(struct platform_device *pdev)
351 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++) 361 for (i = 0; i < CORGI_KEY_STROBE_NUM; i++)
352 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH); 362 pxa_gpio_mode(CORGI_GPIO_KEY_STROBE(i) | GPIO_OUT | GPIO_DFLT_HIGH);
353 363
364 /* Setup the headphone jack as an input */
365 pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
366
354 return 0; 367 return 0;
355} 368}
356 369
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index 0a90962c38e7..1dca3cf42a54 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -66,7 +66,7 @@ static unsigned int hil_kbd_set3[HIL_KEYCODES_SET3_TBLSIZE] =
66static char hil_language[][16] = { HIL_LOCALE_MAP }; 66static char hil_language[][16] = { HIL_LOCALE_MAP };
67 67
68struct hil_kbd { 68struct hil_kbd {
69 struct input_dev dev; 69 struct input_dev *dev;
70 struct serio *serio; 70 struct serio *serio;
71 71
72 /* Input buffer and index for packets from HIL bus. */ 72 /* Input buffer and index for packets from HIL bus. */
@@ -86,7 +86,7 @@ struct hil_kbd {
86/* Process a complete packet after transfer from the HIL */ 86/* Process a complete packet after transfer from the HIL */
87static void hil_kbd_process_record(struct hil_kbd *kbd) 87static void hil_kbd_process_record(struct hil_kbd *kbd)
88{ 88{
89 struct input_dev *dev = &kbd->dev; 89 struct input_dev *dev = kbd->dev;
90 hil_packet *data = kbd->data; 90 hil_packet *data = kbd->data;
91 hil_packet p; 91 hil_packet p;
92 int idx, i, cnt; 92 int idx, i, cnt;
@@ -240,8 +240,8 @@ static void hil_kbd_disconnect(struct serio *serio)
240 return; 240 return;
241 } 241 }
242 242
243 input_unregister_device(&kbd->dev);
244 serio_close(serio); 243 serio_close(serio);
244 input_unregister_device(kbd->dev);
245 kfree(kbd); 245 kfree(kbd);
246} 246}
247 247
@@ -250,17 +250,22 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
250 struct hil_kbd *kbd; 250 struct hil_kbd *kbd;
251 uint8_t did, *idd; 251 uint8_t did, *idd;
252 int i; 252 int i;
253 253
254 kbd = kmalloc(sizeof(*kbd), GFP_KERNEL); 254 kbd = kzalloc(sizeof(*kbd), GFP_KERNEL);
255 if (!kbd) 255 if (!kbd)
256 return -ENOMEM; 256 return -ENOMEM;
257 memset(kbd, 0, sizeof(struct hil_kbd));
258 257
259 if (serio_open(serio, drv)) goto bail0; 258 kbd->dev = input_allocate_device();
259 if (!kbd->dev)
260 goto bail0;
261
262 kbd->dev->private = kbd;
263
264 if (serio_open(serio, drv))
265 goto bail1;
260 266
261 serio_set_drvdata(serio, kbd); 267 serio_set_drvdata(serio, kbd);
262 kbd->serio = serio; 268 kbd->serio = serio;
263 kbd->dev.private = kbd;
264 269
265 init_MUTEX_LOCKED(&(kbd->sem)); 270 init_MUTEX_LOCKED(&(kbd->sem));
266 271
@@ -302,38 +307,38 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
302 did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]); 307 did, hil_language[did & HIL_IDD_DID_TYPE_KB_LANG_MASK]);
303 break; 308 break;
304 default: 309 default:
305 goto bail1; 310 goto bail2;
306 } 311 }
307 312
308 if(HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) { 313 if(HIL_IDD_NUM_BUTTONS(idd) || HIL_IDD_NUM_AXES_PER_SET(*idd)) {
309 printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n"); 314 printk(KERN_INFO PREFIX "keyboards only, no combo devices supported.\n");
310 goto bail1; 315 goto bail2;
311 } 316 }
312 317
313 318
314 kbd->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 319 kbd->dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
315 kbd->dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); 320 kbd->dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
316 kbd->dev.keycodemax = HIL_KEYCODES_SET1_TBLSIZE; 321 kbd->dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
317 kbd->dev.keycodesize = sizeof(hil_kbd_set1[0]); 322 kbd->dev->keycodesize = sizeof(hil_kbd_set1[0]);
318 kbd->dev.keycode = hil_kbd_set1; 323 kbd->dev->keycode = hil_kbd_set1;
319 kbd->dev.name = strlen(kbd->rnm) ? kbd->rnm : HIL_GENERIC_NAME; 324 kbd->dev->name = strlen(kbd->rnm) ? kbd->rnm : HIL_GENERIC_NAME;
320 kbd->dev.phys = "hpkbd/input0"; /* XXX */ 325 kbd->dev->phys = "hpkbd/input0"; /* XXX */
321 326
322 kbd->dev.id.bustype = BUS_HIL; 327 kbd->dev->id.bustype = BUS_HIL;
323 kbd->dev.id.vendor = PCI_VENDOR_ID_HP; 328 kbd->dev->id.vendor = PCI_VENDOR_ID_HP;
324 kbd->dev.id.product = 0x0001; /* TODO: get from kbd->rsc */ 329 kbd->dev->id.product = 0x0001; /* TODO: get from kbd->rsc */
325 kbd->dev.id.version = 0x0100; /* TODO: get from kbd->rsc */ 330 kbd->dev->id.version = 0x0100; /* TODO: get from kbd->rsc */
326 kbd->dev.dev = &serio->dev; 331 kbd->dev->dev = &serio->dev;
327 332
328 for (i = 0; i < 128; i++) { 333 for (i = 0; i < 128; i++) {
329 set_bit(hil_kbd_set1[i], kbd->dev.keybit); 334 set_bit(hil_kbd_set1[i], kbd->dev->keybit);
330 set_bit(hil_kbd_set3[i], kbd->dev.keybit); 335 set_bit(hil_kbd_set3[i], kbd->dev->keybit);
331 } 336 }
332 clear_bit(0, kbd->dev.keybit); 337 clear_bit(0, kbd->dev->keybit);
333 338
334 input_register_device(&kbd->dev); 339 input_register_device(kbd->dev);
335 printk(KERN_INFO "input: %s, ID: %d\n", 340 printk(KERN_INFO "input: %s, ID: %d\n",
336 kbd->dev.name, did); 341 kbd->dev->name, did);
337 342
338 serio->write(serio, 0); 343 serio->write(serio, 0);
339 serio->write(serio, 0); 344 serio->write(serio, 0);
@@ -343,8 +348,10 @@ static int hil_kbd_connect(struct serio *serio, struct serio_driver *drv)
343 up(&(kbd->sem)); 348 up(&(kbd->sem));
344 349
345 return 0; 350 return 0;
346 bail1: 351 bail2:
347 serio_close(serio); 352 serio_close(serio);
353 bail1:
354 input_free_device(kbd->dev);
348 bail0: 355 bail0:
349 kfree(kbd); 356 kfree(kbd);
350 serio_set_drvdata(serio, NULL); 357 serio_set_drvdata(serio, NULL);
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c
index e95bc052e32a..33edd030aa75 100644
--- a/drivers/input/keyboard/hilkbd.c
+++ b/drivers/input/keyboard/hilkbd.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 1998 Philip Blundell <philb@gnu.org> 4 * Copyright (C) 1998 Philip Blundell <philb@gnu.org>
5 * Copyright (C) 1999 Matthew Wilcox <willy@bofh.ai> 5 * Copyright (C) 1999 Matthew Wilcox <willy@bofh.ai>
6 * Copyright (C) 1999-2003 Helge Deller <deller@gmx.de> 6 * Copyright (C) 1999-2006 Helge Deller <deller@gmx.de>
7 * 7 *
8 * Very basic HP Human Interface Loop (HIL) driver. 8 * Very basic HP Human Interface Loop (HIL) driver.
9 * This driver handles the keyboard on HP300 (m68k) and on some 9 * This driver handles the keyboard on HP300 (m68k) and on some
@@ -90,7 +90,7 @@ static unsigned int hphilkeyb_keycode[HIL_KEYCODES_SET1_TBLSIZE] =
90 90
91/* HIL structure */ 91/* HIL structure */
92static struct { 92static struct {
93 struct input_dev dev; 93 struct input_dev *dev;
94 94
95 unsigned int curdev; 95 unsigned int curdev;
96 96
@@ -117,7 +117,7 @@ static void poll_finished(void)
117 down = (hil_dev.data[1] & 1) == 0; 117 down = (hil_dev.data[1] & 1) == 0;
118 scode = hil_dev.data[1] >> 1; 118 scode = hil_dev.data[1] >> 1;
119 key = hphilkeyb_keycode[scode]; 119 key = hphilkeyb_keycode[scode];
120 input_report_key(&hil_dev.dev, key, down); 120 input_report_key(hil_dev.dev, key, down);
121 break; 121 break;
122 } 122 }
123 hil_dev.curdev = 0; 123 hil_dev.curdev = 0;
@@ -207,9 +207,14 @@ hil_keyb_init(void)
207 unsigned int i, kbid; 207 unsigned int i, kbid;
208 wait_queue_head_t hil_wait; 208 wait_queue_head_t hil_wait;
209 209
210 if (hil_dev.dev.id.bustype) { 210 if (hil_dev.dev) {
211 return -ENODEV; /* already initialized */ 211 return -ENODEV; /* already initialized */
212 } 212 }
213
214 hil_dev.dev = input_allocate_device();
215 if (!hil_dev.dev)
216 return -ENOMEM;
217 hil_dev.dev->private = &hil_dev;
213 218
214#if defined(CONFIG_HP300) 219#if defined(CONFIG_HP300)
215 if (!hwreg_present((void *)(HILBASE + HIL_DATA))) 220 if (!hwreg_present((void *)(HILBASE + HIL_DATA)))
@@ -247,28 +252,26 @@ hil_keyb_init(void)
247 c = 0; 252 c = 0;
248 hil_do(HIL_WRITEKBDSADR, &c, 1); 253 hil_do(HIL_WRITEKBDSADR, &c, 1);
249 254
250 init_input_dev(&hil_dev.dev);
251
252 for (i = 0; i < HIL_KEYCODES_SET1_TBLSIZE; i++) 255 for (i = 0; i < HIL_KEYCODES_SET1_TBLSIZE; i++)
253 if (hphilkeyb_keycode[i] != KEY_RESERVED) 256 if (hphilkeyb_keycode[i] != KEY_RESERVED)
254 set_bit(hphilkeyb_keycode[i], hil_dev.dev.keybit); 257 set_bit(hphilkeyb_keycode[i], hil_dev.dev->keybit);
255 258
256 hil_dev.dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 259 hil_dev.dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
257 hil_dev.dev.ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); 260 hil_dev.dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
258 hil_dev.dev.keycodemax = HIL_KEYCODES_SET1_TBLSIZE; 261 hil_dev.dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
259 hil_dev.dev.keycodesize = sizeof(hphilkeyb_keycode[0]); 262 hil_dev.dev->keycodesize = sizeof(hphilkeyb_keycode[0]);
260 hil_dev.dev.keycode = hphilkeyb_keycode; 263 hil_dev.dev->keycode = hphilkeyb_keycode;
261 hil_dev.dev.name = "HIL keyboard"; 264 hil_dev.dev->name = "HIL keyboard";
262 hil_dev.dev.phys = "hpkbd/input0"; 265 hil_dev.dev->phys = "hpkbd/input0";
263 266
264 hil_dev.dev.id.bustype = BUS_HIL; 267 hil_dev.dev->id.bustype = BUS_HIL;
265 hil_dev.dev.id.vendor = PCI_VENDOR_ID_HP; 268 hil_dev.dev->id.vendor = PCI_VENDOR_ID_HP;
266 hil_dev.dev.id.product = 0x0001; 269 hil_dev.dev->id.product = 0x0001;
267 hil_dev.dev.id.version = 0x0010; 270 hil_dev.dev->id.version = 0x0010;
268 271
269 input_register_device(&hil_dev.dev); 272 input_register_device(hil_dev.dev);
270 printk(KERN_INFO "input: %s, ID %d at 0x%08lx (irq %d) found and attached\n", 273 printk(KERN_INFO "input: %s, ID %d at 0x%08lx (irq %d) found and attached\n",
271 hil_dev.dev.name, kbid, HILBASE, HIL_IRQ); 274 hil_dev.dev->name, kbid, HILBASE, HIL_IRQ);
272 275
273 return 0; 276 return 0;
274} 277}
@@ -329,7 +332,9 @@ static void __exit hil_exit(void)
329 /* Turn off interrupts */ 332 /* Turn off interrupts */
330 hil_do(HIL_INTOFF, NULL, 0); 333 hil_do(HIL_INTOFF, NULL, 0);
331 334
332 input_unregister_device(&hil_dev.dev); 335 input_unregister_device(hil_dev.dev);
336
337 hil_dev.dev = NULL;
333 338
334#if defined(CONFIG_PARISC) 339#if defined(CONFIG_PARISC)
335 unregister_parisc_driver(&hil_driver); 340 unregister_parisc_driver(&hil_driver);
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 83999d583122..bc61cf8cfc65 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -30,6 +30,7 @@
30#define SCANCODE(r,c) (((r)<<4) + (c) + 1) 30#define SCANCODE(r,c) (((r)<<4) + (c) + 1)
31#define NR_SCANCODES ((KB_ROWS<<4) + 1) 31#define NR_SCANCODES ((KB_ROWS<<4) + 1)
32 32
33#define SCAN_INTERVAL (50) /* ms */
33#define HINGE_SCAN_INTERVAL (150) /* ms */ 34#define HINGE_SCAN_INTERVAL (150) /* ms */
34 35
35#define SPITZ_KEY_CALENDER KEY_F1 36#define SPITZ_KEY_CALENDER KEY_F1
@@ -230,7 +231,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
230 231
231 /* if any keys are pressed, enable the timer */ 232 /* if any keys are pressed, enable the timer */
232 if (num_pressed) 233 if (num_pressed)
233 mod_timer(&spitzkbd_data->timer, jiffies + msecs_to_jiffies(100)); 234 mod_timer(&spitzkbd_data->timer, jiffies + msecs_to_jiffies(SCAN_INTERVAL));
234 235
235 spin_unlock_irqrestore(&spitzkbd_data->lock, flags); 236 spin_unlock_irqrestore(&spitzkbd_data->lock, flags);
236} 237}
@@ -287,6 +288,7 @@ static void spitzkbd_hinge_timer(unsigned long data)
287 unsigned long flags; 288 unsigned long flags;
288 289
289 state = GPLR(SPITZ_GPIO_SWA) & (GPIO_bit(SPITZ_GPIO_SWA)|GPIO_bit(SPITZ_GPIO_SWB)); 290 state = GPLR(SPITZ_GPIO_SWA) & (GPIO_bit(SPITZ_GPIO_SWA)|GPIO_bit(SPITZ_GPIO_SWB));
291 state |= (GPLR(SPITZ_GPIO_AK_INT) & GPIO_bit(SPITZ_GPIO_AK_INT));
290 if (state != sharpsl_hinge_state) { 292 if (state != sharpsl_hinge_state) {
291 hinge_count = 0; 293 hinge_count = 0;
292 sharpsl_hinge_state = state; 294 sharpsl_hinge_state = state;
@@ -299,6 +301,7 @@ static void spitzkbd_hinge_timer(unsigned long data)
299 301
300 input_report_switch(spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0)); 302 input_report_switch(spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0));
301 input_report_switch(spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0)); 303 input_report_switch(spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0));
304 input_report_switch(spitzkbd_data->input, SW_2, ((GPLR(SPITZ_GPIO_AK_INT) & GPIO_bit(SPITZ_GPIO_AK_INT)) != 0));
302 input_sync(spitzkbd_data->input); 305 input_sync(spitzkbd_data->input);
303 306
304 spin_unlock_irqrestore(&spitzkbd_data->lock, flags); 307 spin_unlock_irqrestore(&spitzkbd_data->lock, flags);
@@ -397,6 +400,7 @@ static int __init spitzkbd_probe(struct platform_device *dev)
397 clear_bit(0, input_dev->keybit); 400 clear_bit(0, input_dev->keybit);
398 set_bit(SW_0, input_dev->swbit); 401 set_bit(SW_0, input_dev->swbit);
399 set_bit(SW_1, input_dev->swbit); 402 set_bit(SW_1, input_dev->swbit);
403 set_bit(SW_2, input_dev->swbit);
400 404
401 input_register_device(input_dev); 405 input_register_device(input_dev);
402 406
@@ -432,6 +436,9 @@ static int __init spitzkbd_probe(struct platform_device *dev)
432 request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr, 436 request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr,
433 SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING, 437 SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING,
434 "Spitzkbd SWB", spitzkbd); 438 "Spitzkbd SWB", spitzkbd);
439 request_irq(SPITZ_IRQ_GPIO_AK_INT, spitzkbd_hinge_isr,
440 SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING,
441 "Spitzkbd HP", spitzkbd);
435 442
436 printk(KERN_INFO "input: Spitz Keyboard Registered\n"); 443 printk(KERN_INFO "input: Spitz Keyboard Registered\n");
437 444
@@ -450,6 +457,7 @@ static int spitzkbd_remove(struct platform_device *dev)
450 free_irq(SPITZ_IRQ_GPIO_ON_KEY, spitzkbd); 457 free_irq(SPITZ_IRQ_GPIO_ON_KEY, spitzkbd);
451 free_irq(SPITZ_IRQ_GPIO_SWA, spitzkbd); 458 free_irq(SPITZ_IRQ_GPIO_SWA, spitzkbd);
452 free_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd); 459 free_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd);
460 free_irq(SPITZ_IRQ_GPIO_AK_INT, spitzkbd);
453 461
454 del_timer_sync(&spitzkbd->htimer); 462 del_timer_sync(&spitzkbd->htimer);
455 del_timer_sync(&spitzkbd->timer); 463 del_timer_sync(&spitzkbd->timer);
diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c
index 1ef477f4469c..afd322185bbf 100644
--- a/drivers/input/misc/pcspkr.c
+++ b/drivers/input/misc/pcspkr.c
@@ -24,7 +24,6 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
24MODULE_DESCRIPTION("PC Speaker beeper driver"); 24MODULE_DESCRIPTION("PC Speaker beeper driver");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27static struct platform_device *pcspkr_platform_device;
28static DEFINE_SPINLOCK(i8253_beep_lock); 27static DEFINE_SPINLOCK(i8253_beep_lock);
29 28
30static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 29static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
@@ -135,35 +134,11 @@ static struct platform_driver pcspkr_platform_driver = {
135 134
136static int __init pcspkr_init(void) 135static int __init pcspkr_init(void)
137{ 136{
138 int err; 137 return platform_driver_register(&pcspkr_platform_driver);
139
140 err = platform_driver_register(&pcspkr_platform_driver);
141 if (err)
142 return err;
143
144 pcspkr_platform_device = platform_device_alloc("pcspkr", -1);
145 if (!pcspkr_platform_device) {
146 err = -ENOMEM;
147 goto err_unregister_driver;
148 }
149
150 err = platform_device_add(pcspkr_platform_device);
151 if (err)
152 goto err_free_device;
153
154 return 0;
155
156 err_free_device:
157 platform_device_put(pcspkr_platform_device);
158 err_unregister_driver:
159 platform_driver_unregister(&pcspkr_platform_driver);
160
161 return err;
162} 138}
163 139
164static void __exit pcspkr_exit(void) 140static void __exit pcspkr_exit(void)
165{ 141{
166 platform_device_unregister(pcspkr_platform_device);
167 platform_driver_unregister(&pcspkr_platform_driver); 142 platform_driver_unregister(&pcspkr_platform_driver);
168} 143}
169 144
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 546ed9b4901d..d723e9ad7c41 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -194,7 +194,7 @@ static int uinput_open(struct inode *inode, struct file *file)
194 if (!newdev) 194 if (!newdev)
195 return -ENOMEM; 195 return -ENOMEM;
196 196
197 init_MUTEX(&newdev->sem); 197 mutex_init(&newdev->mutex);
198 spin_lock_init(&newdev->requests_lock); 198 spin_lock_init(&newdev->requests_lock);
199 init_waitqueue_head(&newdev->requests_waitq); 199 init_waitqueue_head(&newdev->requests_waitq);
200 init_waitqueue_head(&newdev->waitq); 200 init_waitqueue_head(&newdev->waitq);
@@ -340,7 +340,7 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t
340 struct uinput_device *udev = file->private_data; 340 struct uinput_device *udev = file->private_data;
341 int retval; 341 int retval;
342 342
343 retval = down_interruptible(&udev->sem); 343 retval = mutex_lock_interruptible(&udev->mutex);
344 if (retval) 344 if (retval)
345 return retval; 345 return retval;
346 346
@@ -348,7 +348,7 @@ static ssize_t uinput_write(struct file *file, const char __user *buffer, size_t
348 uinput_inject_event(udev, buffer, count) : 348 uinput_inject_event(udev, buffer, count) :
349 uinput_setup_device(udev, buffer, count); 349 uinput_setup_device(udev, buffer, count);
350 350
351 up(&udev->sem); 351 mutex_unlock(&udev->mutex);
352 352
353 return retval; 353 return retval;
354} 354}
@@ -369,7 +369,7 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count,
369 if (retval) 369 if (retval)
370 return retval; 370 return retval;
371 371
372 retval = down_interruptible(&udev->sem); 372 retval = mutex_lock_interruptible(&udev->mutex);
373 if (retval) 373 if (retval)
374 return retval; 374 return retval;
375 375
@@ -388,7 +388,7 @@ static ssize_t uinput_read(struct file *file, char __user *buffer, size_t count,
388 } 388 }
389 389
390 out: 390 out:
391 up(&udev->sem); 391 mutex_unlock(&udev->mutex);
392 392
393 return retval; 393 return retval;
394} 394}
@@ -439,7 +439,7 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
439 439
440 udev = file->private_data; 440 udev = file->private_data;
441 441
442 retval = down_interruptible(&udev->sem); 442 retval = mutex_lock_interruptible(&udev->mutex);
443 if (retval) 443 if (retval)
444 return retval; 444 return retval;
445 445
@@ -589,7 +589,7 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
589 } 589 }
590 590
591 out: 591 out:
592 up(&udev->sem); 592 mutex_unlock(&udev->mutex);
593 return retval; 593 return retval;
594} 594}
595 595
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
index c2bf2ed07dc6..69f02178c528 100644
--- a/drivers/input/mouse/hil_ptr.c
+++ b/drivers/input/mouse/hil_ptr.c
@@ -55,7 +55,7 @@ MODULE_LICENSE("Dual BSD/GPL");
55#define HIL_PTR_MAX_LENGTH 16 55#define HIL_PTR_MAX_LENGTH 16
56 56
57struct hil_ptr { 57struct hil_ptr {
58 struct input_dev dev; 58 struct input_dev *dev;
59 struct serio *serio; 59 struct serio *serio;
60 60
61 /* Input buffer and index for packets from HIL bus. */ 61 /* Input buffer and index for packets from HIL bus. */
@@ -79,7 +79,7 @@ struct hil_ptr {
79/* Process a complete packet after transfer from the HIL */ 79/* Process a complete packet after transfer from the HIL */
80static void hil_ptr_process_record(struct hil_ptr *ptr) 80static void hil_ptr_process_record(struct hil_ptr *ptr)
81{ 81{
82 struct input_dev *dev = &ptr->dev; 82 struct input_dev *dev = ptr->dev;
83 hil_packet *data = ptr->data; 83 hil_packet *data = ptr->data;
84 hil_packet p; 84 hil_packet p;
85 int idx, i, cnt, laxis; 85 int idx, i, cnt, laxis;
@@ -148,12 +148,12 @@ static void hil_ptr_process_record(struct hil_ptr *ptr)
148 if (absdev) { 148 if (absdev) {
149 val = lo + (hi<<8); 149 val = lo + (hi<<8);
150#ifdef TABLET_AUTOADJUST 150#ifdef TABLET_AUTOADJUST
151 if (val < ptr->dev.absmin[ABS_X + i]) 151 if (val < dev->absmin[ABS_X + i])
152 ptr->dev.absmin[ABS_X + i] = val; 152 dev->absmin[ABS_X + i] = val;
153 if (val > ptr->dev.absmax[ABS_X + i]) 153 if (val > dev->absmax[ABS_X + i])
154 ptr->dev.absmax[ABS_X + i] = val; 154 dev->absmax[ABS_X + i] = val;
155#endif 155#endif
156 if (i%3) val = ptr->dev.absmax[ABS_X + i] - val; 156 if (i%3) val = dev->absmax[ABS_X + i] - val;
157 input_report_abs(dev, ABS_X + i, val); 157 input_report_abs(dev, ABS_X + i, val);
158 } else { 158 } else {
159 val = (int) (((int8_t)lo) | ((int8_t)hi<<8)); 159 val = (int) (((int8_t)lo) | ((int8_t)hi<<8));
@@ -233,26 +233,32 @@ static void hil_ptr_disconnect(struct serio *serio)
233 return; 233 return;
234 } 234 }
235 235
236 input_unregister_device(&ptr->dev);
237 serio_close(serio); 236 serio_close(serio);
237 input_unregister_device(ptr->dev);
238 kfree(ptr); 238 kfree(ptr);
239} 239}
240 240
241static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) 241static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
242{ 242{
243 struct hil_ptr *ptr; 243 struct hil_ptr *ptr;
244 char *txt; 244 char *txt;
245 unsigned int i, naxsets, btntype; 245 unsigned int i, naxsets, btntype;
246 uint8_t did, *idd; 246 uint8_t did, *idd;
247 247
248 if (!(ptr = kmalloc(sizeof(struct hil_ptr), GFP_KERNEL))) return -ENOMEM; 248 if (!(ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL)))
249 memset(ptr, 0, sizeof(struct hil_ptr)); 249 return -ENOMEM;
250 250
251 if (serio_open(serio, driver)) goto bail0; 251 ptr->dev = input_allocate_device();
252 if (!ptr->dev)
253 goto bail0;
254
255 ptr->dev->private = ptr;
256
257 if (serio_open(serio, driver))
258 goto bail1;
252 259
253 serio_set_drvdata(serio, ptr); 260 serio_set_drvdata(serio, ptr);
254 ptr->serio = serio; 261 ptr->serio = serio;
255 ptr->dev.private = ptr;
256 262
257 init_MUTEX_LOCKED(&(ptr->sem)); 263 init_MUTEX_LOCKED(&(ptr->sem));
258 264
@@ -283,25 +289,24 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
283 289
284 up(&(ptr->sem)); 290 up(&(ptr->sem));
285 291
286 init_input_dev(&ptr->dev);
287 did = ptr->idd[0]; 292 did = ptr->idd[0];
288 idd = ptr->idd + 1; 293 idd = ptr->idd + 1;
289 txt = "unknown"; 294 txt = "unknown";
290 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) { 295 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
291 ptr->dev.evbit[0] = BIT(EV_REL); 296 ptr->dev->evbit[0] = BIT(EV_REL);
292 txt = "relative"; 297 txt = "relative";
293 } 298 }
294 299
295 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_ABS) { 300 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_ABS) {
296 ptr->dev.evbit[0] = BIT(EV_ABS); 301 ptr->dev->evbit[0] = BIT(EV_ABS);
297 txt = "absolute"; 302 txt = "absolute";
298 } 303 }
299 if (!ptr->dev.evbit[0]) { 304 if (!ptr->dev->evbit[0]) {
300 goto bail1; 305 goto bail2;
301 } 306 }
302 307
303 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd); 308 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
304 if (ptr->nbtn) ptr->dev.evbit[0] |= BIT(EV_KEY); 309 if (ptr->nbtn) ptr->dev->evbit[0] |= BIT(EV_KEY);
305 310
306 naxsets = HIL_IDD_NUM_AXSETS(*idd); 311 naxsets = HIL_IDD_NUM_AXSETS(*idd);
307 ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd); 312 ptr->naxes = HIL_IDD_NUM_AXES_PER_SET(*idd);
@@ -325,7 +330,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
325 btntype = BTN_MOUSE; 330 btntype = BTN_MOUSE;
326 331
327 for (i = 0; i < ptr->nbtn; i++) { 332 for (i = 0; i < ptr->nbtn; i++) {
328 set_bit(btntype | i, ptr->dev.keybit); 333 set_bit(btntype | i, ptr->dev->keybit);
329 ptr->btnmap[i] = btntype | i; 334 ptr->btnmap[i] = btntype | i;
330 } 335 }
331 336
@@ -337,50 +342,52 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
337 342
338 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) { 343 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
339 for (i = 0; i < ptr->naxes; i++) { 344 for (i = 0; i < ptr->naxes; i++) {
340 set_bit(REL_X + i, ptr->dev.relbit); 345 set_bit(REL_X + i, ptr->dev->relbit);
341 } 346 }
342 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) { 347 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
343 set_bit(REL_X + i, ptr->dev.relbit); 348 set_bit(REL_X + i, ptr->dev->relbit);
344 } 349 }
345 } else { 350 } else {
346 for (i = 0; i < ptr->naxes; i++) { 351 for (i = 0; i < ptr->naxes; i++) {
347 set_bit(ABS_X + i, ptr->dev.absbit); 352 set_bit(ABS_X + i, ptr->dev->absbit);
348 ptr->dev.absmin[ABS_X + i] = 0; 353 ptr->dev->absmin[ABS_X + i] = 0;
349 ptr->dev.absmax[ABS_X + i] = 354 ptr->dev->absmax[ABS_X + i] =
350 HIL_IDD_AXIS_MAX((ptr->idd + 1), i); 355 HIL_IDD_AXIS_MAX((ptr->idd + 1), i);
351 } 356 }
352 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) { 357 for (i = 3; (i < ptr->naxes + 3) && (naxsets > 1); i++) {
353 set_bit(ABS_X + i, ptr->dev.absbit); 358 set_bit(ABS_X + i, ptr->dev->absbit);
354 ptr->dev.absmin[ABS_X + i] = 0; 359 ptr->dev->absmin[ABS_X + i] = 0;
355 ptr->dev.absmax[ABS_X + i] = 360 ptr->dev->absmax[ABS_X + i] =
356 HIL_IDD_AXIS_MAX((ptr->idd + 1), (i - 3)); 361 HIL_IDD_AXIS_MAX((ptr->idd + 1), (i - 3));
357 } 362 }
358#ifdef TABLET_AUTOADJUST 363#ifdef TABLET_AUTOADJUST
359 for (i = 0; i < ABS_MAX; i++) { 364 for (i = 0; i < ABS_MAX; i++) {
360 int diff = ptr->dev.absmax[ABS_X + i] / 10; 365 int diff = ptr->dev->absmax[ABS_X + i] / 10;
361 ptr->dev.absmin[ABS_X + i] += diff; 366 ptr->dev->absmin[ABS_X + i] += diff;
362 ptr->dev.absmax[ABS_X + i] -= diff; 367 ptr->dev->absmax[ABS_X + i] -= diff;
363 } 368 }
364#endif 369#endif
365 } 370 }
366 371
367 ptr->dev.name = strlen(ptr->rnm) ? ptr->rnm : HIL_GENERIC_NAME; 372 ptr->dev->name = strlen(ptr->rnm) ? ptr->rnm : HIL_GENERIC_NAME;
368 373
369 ptr->dev.id.bustype = BUS_HIL; 374 ptr->dev->id.bustype = BUS_HIL;
370 ptr->dev.id.vendor = PCI_VENDOR_ID_HP; 375 ptr->dev->id.vendor = PCI_VENDOR_ID_HP;
371 ptr->dev.id.product = 0x0001; /* TODO: get from ptr->rsc */ 376 ptr->dev->id.product = 0x0001; /* TODO: get from ptr->rsc */
372 ptr->dev.id.version = 0x0100; /* TODO: get from ptr->rsc */ 377 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */
373 ptr->dev.dev = &serio->dev; 378 ptr->dev->dev = &serio->dev;
374 379
375 input_register_device(&ptr->dev); 380 input_register_device(ptr->dev);
376 printk(KERN_INFO "input: %s (%s), ID: %d\n", 381 printk(KERN_INFO "input: %s (%s), ID: %d\n",
377 ptr->dev.name, 382 ptr->dev->name,
378 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad", 383 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
379 did); 384 did);
380 385
381 return 0; 386 return 0;
382 bail1: 387 bail2:
383 serio_close(serio); 388 serio_close(serio);
389 bail1:
390 input_free_device(ptr->dev);
384 bail0: 391 bail0:
385 kfree(ptr); 392 kfree(ptr);
386 serio_set_drvdata(serio, NULL); 393 serio_set_drvdata(serio, NULL);
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index ad6217467676..32d70ed8f41d 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -20,6 +20,8 @@
20#include <linux/serio.h> 20#include <linux/serio.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/libps2.h> 22#include <linux/libps2.h>
23#include <linux/mutex.h>
24
23#include "psmouse.h" 25#include "psmouse.h"
24#include "synaptics.h" 26#include "synaptics.h"
25#include "logips2pp.h" 27#include "logips2pp.h"
@@ -98,13 +100,13 @@ __obsolete_setup("psmouse_resetafter=");
98__obsolete_setup("psmouse_rate="); 100__obsolete_setup("psmouse_rate=");
99 101
100/* 102/*
101 * psmouse_sem protects all operations changing state of mouse 103 * psmouse_mutex protects all operations changing state of mouse
102 * (connecting, disconnecting, changing rate or resolution via 104 * (connecting, disconnecting, changing rate or resolution via
103 * sysfs). We could use a per-device semaphore but since there 105 * sysfs). We could use a per-device semaphore but since there
104 * rarely more than one PS/2 mouse connected and since semaphore 106 * rarely more than one PS/2 mouse connected and since semaphore
105 * is taken in "slow" paths it is not worth it. 107 * is taken in "slow" paths it is not worth it.
106 */ 108 */
107static DECLARE_MUTEX(psmouse_sem); 109static DEFINE_MUTEX(psmouse_mutex);
108 110
109static struct workqueue_struct *kpsmoused_wq; 111static struct workqueue_struct *kpsmoused_wq;
110 112
@@ -868,7 +870,7 @@ static void psmouse_resync(void *p)
868 int failed = 0, enabled = 0; 870 int failed = 0, enabled = 0;
869 int i; 871 int i;
870 872
871 down(&psmouse_sem); 873 mutex_lock(&psmouse_mutex);
872 874
873 if (psmouse->state != PSMOUSE_RESYNCING) 875 if (psmouse->state != PSMOUSE_RESYNCING)
874 goto out; 876 goto out;
@@ -948,7 +950,7 @@ static void psmouse_resync(void *p)
948 if (parent) 950 if (parent)
949 psmouse_activate(parent); 951 psmouse_activate(parent);
950 out: 952 out:
951 up(&psmouse_sem); 953 mutex_unlock(&psmouse_mutex);
952} 954}
953 955
954/* 956/*
@@ -974,14 +976,14 @@ static void psmouse_disconnect(struct serio *serio)
974 976
975 sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group); 977 sysfs_remove_group(&serio->dev.kobj, &psmouse_attribute_group);
976 978
977 down(&psmouse_sem); 979 mutex_lock(&psmouse_mutex);
978 980
979 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 981 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
980 982
981 /* make sure we don't have a resync in progress */ 983 /* make sure we don't have a resync in progress */
982 up(&psmouse_sem); 984 mutex_unlock(&psmouse_mutex);
983 flush_workqueue(kpsmoused_wq); 985 flush_workqueue(kpsmoused_wq);
984 down(&psmouse_sem); 986 mutex_lock(&psmouse_mutex);
985 987
986 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 988 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
987 parent = serio_get_drvdata(serio->parent); 989 parent = serio_get_drvdata(serio->parent);
@@ -1004,7 +1006,7 @@ static void psmouse_disconnect(struct serio *serio)
1004 if (parent) 1006 if (parent)
1005 psmouse_activate(parent); 1007 psmouse_activate(parent);
1006 1008
1007 up(&psmouse_sem); 1009 mutex_unlock(&psmouse_mutex);
1008} 1010}
1009 1011
1010static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto) 1012static int psmouse_switch_protocol(struct psmouse *psmouse, struct psmouse_protocol *proto)
@@ -1076,7 +1078,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1076 struct input_dev *input_dev; 1078 struct input_dev *input_dev;
1077 int retval = -ENOMEM; 1079 int retval = -ENOMEM;
1078 1080
1079 down(&psmouse_sem); 1081 mutex_lock(&psmouse_mutex);
1080 1082
1081 /* 1083 /*
1082 * If this is a pass-through port deactivate parent so the device 1084 * If this is a pass-through port deactivate parent so the device
@@ -1144,7 +1146,7 @@ out:
1144 if (parent) 1146 if (parent)
1145 psmouse_activate(parent); 1147 psmouse_activate(parent);
1146 1148
1147 up(&psmouse_sem); 1149 mutex_unlock(&psmouse_mutex);
1148 return retval; 1150 return retval;
1149} 1151}
1150 1152
@@ -1161,7 +1163,7 @@ static int psmouse_reconnect(struct serio *serio)
1161 return -1; 1163 return -1;
1162 } 1164 }
1163 1165
1164 down(&psmouse_sem); 1166 mutex_lock(&psmouse_mutex);
1165 1167
1166 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1168 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1167 parent = serio_get_drvdata(serio->parent); 1169 parent = serio_get_drvdata(serio->parent);
@@ -1195,7 +1197,7 @@ out:
1195 if (parent) 1197 if (parent)
1196 psmouse_activate(parent); 1198 psmouse_activate(parent);
1197 1199
1198 up(&psmouse_sem); 1200 mutex_unlock(&psmouse_mutex);
1199 return rc; 1201 return rc;
1200} 1202}
1201 1203
@@ -1273,7 +1275,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
1273 goto out_unpin; 1275 goto out_unpin;
1274 } 1276 }
1275 1277
1276 retval = down_interruptible(&psmouse_sem); 1278 retval = mutex_lock_interruptible(&psmouse_mutex);
1277 if (retval) 1279 if (retval)
1278 goto out_unpin; 1280 goto out_unpin;
1279 1281
@@ -1281,7 +1283,7 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
1281 1283
1282 if (psmouse->state == PSMOUSE_IGNORE) { 1284 if (psmouse->state == PSMOUSE_IGNORE) {
1283 retval = -ENODEV; 1285 retval = -ENODEV;
1284 goto out_up; 1286 goto out_unlock;
1285 } 1287 }
1286 1288
1287 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1289 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
@@ -1299,8 +1301,8 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
1299 if (parent) 1301 if (parent)
1300 psmouse_activate(parent); 1302 psmouse_activate(parent);
1301 1303
1302 out_up: 1304 out_unlock:
1303 up(&psmouse_sem); 1305 mutex_unlock(&psmouse_mutex);
1304 out_unpin: 1306 out_unpin:
1305 serio_unpin_driver(serio); 1307 serio_unpin_driver(serio);
1306 return retval; 1308 return retval;
@@ -1357,11 +1359,11 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1357 return -EIO; 1359 return -EIO;
1358 } 1360 }
1359 1361
1360 up(&psmouse_sem); 1362 mutex_unlock(&psmouse_mutex);
1361 serio_unpin_driver(serio); 1363 serio_unpin_driver(serio);
1362 serio_unregister_child_port(serio); 1364 serio_unregister_child_port(serio);
1363 serio_pin_driver_uninterruptible(serio); 1365 serio_pin_driver_uninterruptible(serio);
1364 down(&psmouse_sem); 1366 mutex_lock(&psmouse_mutex);
1365 1367
1366 if (serio->drv != &psmouse_drv) { 1368 if (serio->drv != &psmouse_drv) {
1367 input_free_device(new_dev); 1369 input_free_device(new_dev);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 2051bec2c394..ad5d0a85e960 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -247,14 +247,12 @@ static void synaptics_pt_create(struct psmouse *psmouse)
247{ 247{
248 struct serio *serio; 248 struct serio *serio;
249 249
250 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 250 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
251 if (!serio) { 251 if (!serio) {
252 printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n"); 252 printk(KERN_ERR "synaptics: not enough memory to allocate pass-through port\n");
253 return; 253 return;
254 } 254 }
255 255
256 memset(serio, 0, sizeof(struct serio));
257
258 serio->id.type = SERIO_PS_PSTHRU; 256 serio->id.type = SERIO_PS_PSTHRU;
259 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name)); 257 strlcpy(serio->name, "Synaptics pass-through", sizeof(serio->name));
260 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name)); 258 strlcpy(serio->phys, "synaptics-pt/serio0", sizeof(serio->name));
@@ -605,14 +603,21 @@ static struct dmi_system_id toshiba_dmi_table[] = {
605 .ident = "Toshiba Satellite", 603 .ident = "Toshiba Satellite",
606 .matches = { 604 .matches = {
607 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 605 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
608 DMI_MATCH(DMI_PRODUCT_NAME , "Satellite"), 606 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
609 }, 607 },
610 }, 608 },
611 { 609 {
612 .ident = "Toshiba Dynabook", 610 .ident = "Toshiba Dynabook",
613 .matches = { 611 .matches = {
614 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 612 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
615 DMI_MATCH(DMI_PRODUCT_NAME , "dynabook"), 613 DMI_MATCH(DMI_PRODUCT_NAME, "dynabook"),
614 },
615 },
616 {
617 .ident = "Toshiba Portege M300",
618 .matches = {
619 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
620 DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
616 }, 621 },
617 }, 622 },
618 { } 623 { }
@@ -623,10 +628,9 @@ int synaptics_init(struct psmouse *psmouse)
623{ 628{
624 struct synaptics_data *priv; 629 struct synaptics_data *priv;
625 630
626 psmouse->private = priv = kmalloc(sizeof(struct synaptics_data), GFP_KERNEL); 631 psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL);
627 if (!priv) 632 if (!priv)
628 return -1; 633 return -1;
629 memset(priv, 0, sizeof(struct synaptics_data));
630 634
631 if (synaptics_query_hardware(psmouse)) { 635 if (synaptics_query_hardware(psmouse)) {
632 printk(KERN_ERR "Unable to query Synaptics hardware.\n"); 636 printk(KERN_ERR "Unable to query Synaptics hardware.\n");
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 9abed18d2ecf..b685a507955d 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -412,9 +412,8 @@ static int mousedev_open(struct inode * inode, struct file * file)
412 if (i >= MOUSEDEV_MINORS || !mousedev_table[i]) 412 if (i >= MOUSEDEV_MINORS || !mousedev_table[i])
413 return -ENODEV; 413 return -ENODEV;
414 414
415 if (!(list = kmalloc(sizeof(struct mousedev_list), GFP_KERNEL))) 415 if (!(list = kzalloc(sizeof(struct mousedev_list), GFP_KERNEL)))
416 return -ENOMEM; 416 return -ENOMEM;
417 memset(list, 0, sizeof(struct mousedev_list));
418 417
419 spin_lock_init(&list->packet_lock); 418 spin_lock_init(&list->packet_lock);
420 list->pos_x = xres / 2; 419 list->pos_x = xres / 2;
@@ -626,9 +625,8 @@ static struct input_handle *mousedev_connect(struct input_handler *handler, stru
626 return NULL; 625 return NULL;
627 } 626 }
628 627
629 if (!(mousedev = kmalloc(sizeof(struct mousedev), GFP_KERNEL))) 628 if (!(mousedev = kzalloc(sizeof(struct mousedev), GFP_KERNEL)))
630 return NULL; 629 return NULL;
631 memset(mousedev, 0, sizeof(struct mousedev));
632 630
633 INIT_LIST_HEAD(&mousedev->list); 631 INIT_LIST_HEAD(&mousedev->list);
634 init_waitqueue_head(&mousedev->wait); 632 init_waitqueue_head(&mousedev->wait);
diff --git a/drivers/input/power.c b/drivers/input/power.c
index bfc5c63ebffe..526e6070600c 100644
--- a/drivers/input/power.c
+++ b/drivers/input/power.c
@@ -103,9 +103,8 @@ static struct input_handle *power_connect(struct input_handler *handler,
103{ 103{
104 struct input_handle *handle; 104 struct input_handle *handle;
105 105
106 if (!(handle = kmalloc(sizeof(struct input_handle), GFP_KERNEL))) 106 if (!(handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL)))
107 return NULL; 107 return NULL;
108 memset(handle, 0, sizeof(struct input_handle));
109 108
110 handle->dev = dev; 109 handle->dev = dev;
111 handle->handler = handler; 110 handle->handler = handler;
diff --git a/drivers/input/serio/gscps2.c b/drivers/input/serio/gscps2.c
index a7b0de0f92b2..c0b1e4becad3 100644
--- a/drivers/input/serio/gscps2.c
+++ b/drivers/input/serio/gscps2.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/input/serio/gscps2.c 2 * drivers/input/serio/gscps2.c
3 * 3 *
4 * Copyright (c) 2004 Helge Deller <deller@gmx.de> 4 * Copyright (c) 2004-2006 Helge Deller <deller@gmx.de>
5 * Copyright (c) 2002 Laurent Canet <canetl@esiee.fr> 5 * Copyright (c) 2002 Laurent Canet <canetl@esiee.fr>
6 * Copyright (c) 2002 Thibaut Varene <varenet@parisc-linux.org> 6 * Copyright (c) 2002 Thibaut Varene <varenet@parisc-linux.org>
7 * 7 *
@@ -354,7 +354,7 @@ static int __init gscps2_probe(struct parisc_device *dev)
354 memset(serio, 0, sizeof(struct serio)); 354 memset(serio, 0, sizeof(struct serio));
355 ps2port->port = serio; 355 ps2port->port = serio;
356 ps2port->padev = dev; 356 ps2port->padev = dev;
357 ps2port->addr = ioremap(hpa, GSC_STATUS + 4); 357 ps2port->addr = ioremap_nocache(hpa, GSC_STATUS + 4);
358 spin_lock_init(&ps2port->lock); 358 spin_lock_init(&ps2port->lock);
359 359
360 gscps2_reset(ps2port); 360 gscps2_reset(ps2port);
diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c
index ea499783fb12..bbbe15e21904 100644
--- a/drivers/input/serio/hil_mlc.c
+++ b/drivers/input/serio/hil_mlc.c
@@ -872,9 +872,8 @@ int hil_mlc_register(hil_mlc *mlc) {
872 for (i = 0; i < HIL_MLC_DEVMEM; i++) { 872 for (i = 0; i < HIL_MLC_DEVMEM; i++) {
873 struct serio *mlc_serio; 873 struct serio *mlc_serio;
874 hil_mlc_copy_di_scratch(mlc, i); 874 hil_mlc_copy_di_scratch(mlc, i);
875 mlc_serio = kmalloc(sizeof(*mlc_serio), GFP_KERNEL); 875 mlc_serio = kzalloc(sizeof(*mlc_serio), GFP_KERNEL);
876 mlc->serio[i] = mlc_serio; 876 mlc->serio[i] = mlc_serio;
877 memset(mlc_serio, 0, sizeof(*mlc_serio));
878 mlc_serio->id = hil_mlc_serio_id; 877 mlc_serio->id = hil_mlc_serio_id;
879 mlc_serio->write = hil_mlc_serio_write; 878 mlc_serio->write = hil_mlc_serio_write;
880 mlc_serio->open = hil_mlc_serio_open; 879 mlc_serio->open = hil_mlc_serio_open;
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index a4c6f3522723..f606e96bc2f4 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -192,7 +192,9 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
192#include <linux/pnp.h> 192#include <linux/pnp.h>
193 193
194static int i8042_pnp_kbd_registered; 194static int i8042_pnp_kbd_registered;
195static unsigned int i8042_pnp_kbd_devices;
195static int i8042_pnp_aux_registered; 196static int i8042_pnp_aux_registered;
197static unsigned int i8042_pnp_aux_devices;
196 198
197static int i8042_pnp_command_reg; 199static int i8042_pnp_command_reg;
198static int i8042_pnp_data_reg; 200static int i8042_pnp_data_reg;
@@ -219,6 +221,7 @@ static int i8042_pnp_kbd_probe(struct pnp_dev *dev, const struct pnp_device_id *
219 strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name)); 221 strncat(i8042_pnp_kbd_name, pnp_dev_name(dev), sizeof(i8042_pnp_kbd_name));
220 } 222 }
221 223
224 i8042_pnp_kbd_devices++;
222 return 0; 225 return 0;
223} 226}
224 227
@@ -239,6 +242,7 @@ static int i8042_pnp_aux_probe(struct pnp_dev *dev, const struct pnp_device_id *
239 strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name)); 242 strncat(i8042_pnp_aux_name, pnp_dev_name(dev), sizeof(i8042_pnp_aux_name));
240 } 243 }
241 244
245 i8042_pnp_aux_devices++;
242 return 0; 246 return 0;
243} 247}
244 248
@@ -287,21 +291,23 @@ static void i8042_pnp_exit(void)
287 291
288static int __init i8042_pnp_init(void) 292static int __init i8042_pnp_init(void)
289{ 293{
290 int result_kbd = 0, result_aux = 0;
291 char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 }; 294 char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 };
295 int err;
292 296
293 if (i8042_nopnp) { 297 if (i8042_nopnp) {
294 printk(KERN_INFO "i8042: PNP detection disabled\n"); 298 printk(KERN_INFO "i8042: PNP detection disabled\n");
295 return 0; 299 return 0;
296 } 300 }
297 301
298 if ((result_kbd = pnp_register_driver(&i8042_pnp_kbd_driver)) >= 0) 302 err = pnp_register_driver(&i8042_pnp_kbd_driver);
303 if (!err)
299 i8042_pnp_kbd_registered = 1; 304 i8042_pnp_kbd_registered = 1;
300 305
301 if ((result_aux = pnp_register_driver(&i8042_pnp_aux_driver)) >= 0) 306 err = pnp_register_driver(&i8042_pnp_aux_driver);
307 if (!err)
302 i8042_pnp_aux_registered = 1; 308 i8042_pnp_aux_registered = 1;
303 309
304 if (result_kbd <= 0 && result_aux <= 0) { 310 if (!i8042_pnp_kbd_devices && !i8042_pnp_aux_devices) {
305 i8042_pnp_exit(); 311 i8042_pnp_exit();
306#if defined(__ia64__) 312#if defined(__ia64__)
307 return -ENODEV; 313 return -ENODEV;
@@ -311,24 +317,24 @@ static int __init i8042_pnp_init(void)
311#endif 317#endif
312 } 318 }
313 319
314 if (result_kbd > 0) 320 if (i8042_pnp_kbd_devices)
315 snprintf(kbd_irq_str, sizeof(kbd_irq_str), 321 snprintf(kbd_irq_str, sizeof(kbd_irq_str),
316 "%d", i8042_pnp_kbd_irq); 322 "%d", i8042_pnp_kbd_irq);
317 if (result_aux > 0) 323 if (i8042_pnp_aux_devices)
318 snprintf(aux_irq_str, sizeof(aux_irq_str), 324 snprintf(aux_irq_str, sizeof(aux_irq_str),
319 "%d", i8042_pnp_aux_irq); 325 "%d", i8042_pnp_aux_irq);
320 326
321 printk(KERN_INFO "PNP: PS/2 Controller [%s%s%s] at %#x,%#x irq %s%s%s\n", 327 printk(KERN_INFO "PNP: PS/2 Controller [%s%s%s] at %#x,%#x irq %s%s%s\n",
322 i8042_pnp_kbd_name, (result_kbd > 0 && result_aux > 0) ? "," : "", 328 i8042_pnp_kbd_name, (i8042_pnp_kbd_devices && i8042_pnp_aux_devices) ? "," : "",
323 i8042_pnp_aux_name, 329 i8042_pnp_aux_name,
324 i8042_pnp_data_reg, i8042_pnp_command_reg, 330 i8042_pnp_data_reg, i8042_pnp_command_reg,
325 kbd_irq_str, (result_kbd > 0 && result_aux > 0) ? "," : "", 331 kbd_irq_str, (i8042_pnp_kbd_devices && i8042_pnp_aux_devices) ? "," : "",
326 aux_irq_str); 332 aux_irq_str);
327 333
328#if defined(__ia64__) 334#if defined(__ia64__)
329 if (result_kbd <= 0) 335 if (!i8042_pnp_kbd_devices)
330 i8042_nokbd = 1; 336 i8042_nokbd = 1;
331 if (result_aux <= 0) 337 if (!i8042_pnp_aux_devices)
332 i8042_noaux = 1; 338 i8042_noaux = 1;
333#endif 339#endif
334 340
diff --git a/drivers/input/serio/libps2.c b/drivers/input/serio/libps2.c
index d4c990f7c85e..79c97f94bcbd 100644
--- a/drivers/input/serio/libps2.c
+++ b/drivers/input/serio/libps2.c
@@ -84,7 +84,7 @@ void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
84 maxbytes = sizeof(ps2dev->cmdbuf); 84 maxbytes = sizeof(ps2dev->cmdbuf);
85 } 85 }
86 86
87 down(&ps2dev->cmd_sem); 87 mutex_lock(&ps2dev->cmd_mutex);
88 88
89 serio_pause_rx(ps2dev->serio); 89 serio_pause_rx(ps2dev->serio);
90 ps2dev->flags = PS2_FLAG_CMD; 90 ps2dev->flags = PS2_FLAG_CMD;
@@ -94,7 +94,7 @@ void ps2_drain(struct ps2dev *ps2dev, int maxbytes, int timeout)
94 wait_event_timeout(ps2dev->wait, 94 wait_event_timeout(ps2dev->wait,
95 !(ps2dev->flags & PS2_FLAG_CMD), 95 !(ps2dev->flags & PS2_FLAG_CMD),
96 msecs_to_jiffies(timeout)); 96 msecs_to_jiffies(timeout));
97 up(&ps2dev->cmd_sem); 97 mutex_unlock(&ps2dev->cmd_mutex);
98} 98}
99 99
100/* 100/*
@@ -177,7 +177,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
177 return -1; 177 return -1;
178 } 178 }
179 179
180 down(&ps2dev->cmd_sem); 180 mutex_lock(&ps2dev->cmd_mutex);
181 181
182 serio_pause_rx(ps2dev->serio); 182 serio_pause_rx(ps2dev->serio);
183 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0; 183 ps2dev->flags = command == PS2_CMD_GETID ? PS2_FLAG_WAITID : 0;
@@ -229,7 +229,7 @@ int ps2_command(struct ps2dev *ps2dev, unsigned char *param, int command)
229 ps2dev->flags = 0; 229 ps2dev->flags = 0;
230 serio_continue_rx(ps2dev->serio); 230 serio_continue_rx(ps2dev->serio);
231 231
232 up(&ps2dev->cmd_sem); 232 mutex_unlock(&ps2dev->cmd_mutex);
233 return rc; 233 return rc;
234} 234}
235 235
@@ -281,7 +281,7 @@ int ps2_schedule_command(struct ps2dev *ps2dev, unsigned char *param, int comman
281 281
282void ps2_init(struct ps2dev *ps2dev, struct serio *serio) 282void ps2_init(struct ps2dev *ps2dev, struct serio *serio)
283{ 283{
284 init_MUTEX(&ps2dev->cmd_sem); 284 mutex_init(&ps2dev->cmd_mutex);
285 init_waitqueue_head(&ps2dev->wait); 285 init_waitqueue_head(&ps2dev->wait);
286 ps2dev->serio = serio; 286 ps2dev->serio = serio;
287} 287}
diff --git a/drivers/input/serio/parkbd.c b/drivers/input/serio/parkbd.c
index 1d15c2819818..a5c1fb3a4a51 100644
--- a/drivers/input/serio/parkbd.c
+++ b/drivers/input/serio/parkbd.c
@@ -171,9 +171,8 @@ static struct serio * __init parkbd_allocate_serio(void)
171{ 171{
172 struct serio *serio; 172 struct serio *serio;
173 173
174 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 174 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
175 if (serio) { 175 if (serio) {
176 memset(serio, 0, sizeof(struct serio));
177 serio->id.type = parkbd_mode; 176 serio->id.type = parkbd_mode;
178 serio->write = parkbd_write, 177 serio->write = parkbd_write,
179 strlcpy(serio->name, "PARKBD AT/XT keyboard adapter", sizeof(serio->name)); 178 strlcpy(serio->name, "PARKBD AT/XT keyboard adapter", sizeof(serio->name));
diff --git a/drivers/input/serio/rpckbd.c b/drivers/input/serio/rpckbd.c
index a3bd11589bc3..513d37fc1acf 100644
--- a/drivers/input/serio/rpckbd.c
+++ b/drivers/input/serio/rpckbd.c
@@ -111,11 +111,10 @@ static int __devinit rpckbd_probe(struct platform_device *dev)
111{ 111{
112 struct serio *serio; 112 struct serio *serio;
113 113
114 serio = kmalloc(sizeof(struct serio), GFP_KERNEL); 114 serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
115 if (!serio) 115 if (!serio)
116 return -ENOMEM; 116 return -ENOMEM;
117 117
118 memset(serio, 0, sizeof(struct serio));
119 serio->id.type = SERIO_8042; 118 serio->id.type = SERIO_8042;
120 serio->write = rpckbd_write; 119 serio->write = rpckbd_write;
121 serio->open = rpckbd_open; 120 serio->open = rpckbd_open;
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 2f76813c3a64..6521034bc933 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -34,6 +34,7 @@
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/kthread.h> 36#include <linux/kthread.h>
37#include <linux/mutex.h>
37 38
38MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 39MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
39MODULE_DESCRIPTION("Serio abstraction core"); 40MODULE_DESCRIPTION("Serio abstraction core");
@@ -52,10 +53,10 @@ EXPORT_SYMBOL(serio_rescan);
52EXPORT_SYMBOL(serio_reconnect); 53EXPORT_SYMBOL(serio_reconnect);
53 54
54/* 55/*
55 * serio_sem protects entire serio subsystem and is taken every time 56 * serio_mutex protects entire serio subsystem and is taken every time
56 * serio port or driver registrered or unregistered. 57 * serio port or driver registrered or unregistered.
57 */ 58 */
58static DECLARE_MUTEX(serio_sem); 59static DEFINE_MUTEX(serio_mutex);
59 60
60static LIST_HEAD(serio_list); 61static LIST_HEAD(serio_list);
61 62
@@ -70,9 +71,9 @@ static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
70{ 71{
71 int retval; 72 int retval;
72 73
73 down(&serio->drv_sem); 74 mutex_lock(&serio->drv_mutex);
74 retval = drv->connect(serio, drv); 75 retval = drv->connect(serio, drv);
75 up(&serio->drv_sem); 76 mutex_unlock(&serio->drv_mutex);
76 77
77 return retval; 78 return retval;
78} 79}
@@ -81,20 +82,20 @@ static int serio_reconnect_driver(struct serio *serio)
81{ 82{
82 int retval = -1; 83 int retval = -1;
83 84
84 down(&serio->drv_sem); 85 mutex_lock(&serio->drv_mutex);
85 if (serio->drv && serio->drv->reconnect) 86 if (serio->drv && serio->drv->reconnect)
86 retval = serio->drv->reconnect(serio); 87 retval = serio->drv->reconnect(serio);
87 up(&serio->drv_sem); 88 mutex_unlock(&serio->drv_mutex);
88 89
89 return retval; 90 return retval;
90} 91}
91 92
92static void serio_disconnect_driver(struct serio *serio) 93static void serio_disconnect_driver(struct serio *serio)
93{ 94{
94 down(&serio->drv_sem); 95 mutex_lock(&serio->drv_mutex);
95 if (serio->drv) 96 if (serio->drv)
96 serio->drv->disconnect(serio); 97 serio->drv->disconnect(serio);
97 up(&serio->drv_sem); 98 mutex_unlock(&serio->drv_mutex);
98} 99}
99 100
100static int serio_match_port(const struct serio_device_id *ids, struct serio *serio) 101static int serio_match_port(const struct serio_device_id *ids, struct serio *serio)
@@ -195,6 +196,7 @@ static void serio_queue_event(void *object, struct module *owner,
195 if ((event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC))) { 196 if ((event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC))) {
196 if (!try_module_get(owner)) { 197 if (!try_module_get(owner)) {
197 printk(KERN_WARNING "serio: Can't get module reference, dropping event %d\n", event_type); 198 printk(KERN_WARNING "serio: Can't get module reference, dropping event %d\n", event_type);
199 kfree(event);
198 goto out; 200 goto out;
199 } 201 }
200 202
@@ -272,7 +274,7 @@ static void serio_handle_event(void)
272 struct serio_event *event; 274 struct serio_event *event;
273 struct serio_driver *serio_drv; 275 struct serio_driver *serio_drv;
274 276
275 down(&serio_sem); 277 mutex_lock(&serio_mutex);
276 278
277 /* 279 /*
278 * Note that we handle only one event here to give swsusp 280 * Note that we handle only one event here to give swsusp
@@ -314,7 +316,7 @@ static void serio_handle_event(void)
314 serio_free_event(event); 316 serio_free_event(event);
315 } 317 }
316 318
317 up(&serio_sem); 319 mutex_unlock(&serio_mutex);
318} 320}
319 321
320/* 322/*
@@ -449,7 +451,7 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
449 struct device_driver *drv; 451 struct device_driver *drv;
450 int retval; 452 int retval;
451 453
452 retval = down_interruptible(&serio_sem); 454 retval = mutex_lock_interruptible(&serio_mutex);
453 if (retval) 455 if (retval)
454 return retval; 456 return retval;
455 457
@@ -469,7 +471,7 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
469 retval = -EINVAL; 471 retval = -EINVAL;
470 } 472 }
471 473
472 up(&serio_sem); 474 mutex_unlock(&serio_mutex);
473 475
474 return retval; 476 return retval;
475} 477}
@@ -524,7 +526,7 @@ static void serio_init_port(struct serio *serio)
524 __module_get(THIS_MODULE); 526 __module_get(THIS_MODULE);
525 527
526 spin_lock_init(&serio->lock); 528 spin_lock_init(&serio->lock);
527 init_MUTEX(&serio->drv_sem); 529 mutex_init(&serio->drv_mutex);
528 device_initialize(&serio->dev); 530 device_initialize(&serio->dev);
529 snprintf(serio->dev.bus_id, sizeof(serio->dev.bus_id), 531 snprintf(serio->dev.bus_id, sizeof(serio->dev.bus_id),
530 "serio%ld", (long)atomic_inc_return(&serio_no) - 1); 532 "serio%ld", (long)atomic_inc_return(&serio_no) - 1);
@@ -661,10 +663,10 @@ void __serio_register_port(struct serio *serio, struct module *owner)
661 */ 663 */
662void serio_unregister_port(struct serio *serio) 664void serio_unregister_port(struct serio *serio)
663{ 665{
664 down(&serio_sem); 666 mutex_lock(&serio_mutex);
665 serio_disconnect_port(serio); 667 serio_disconnect_port(serio);
666 serio_destroy_port(serio); 668 serio_destroy_port(serio);
667 up(&serio_sem); 669 mutex_unlock(&serio_mutex);
668} 670}
669 671
670/* 672/*
@@ -672,17 +674,17 @@ void serio_unregister_port(struct serio *serio)
672 */ 674 */
673void serio_unregister_child_port(struct serio *serio) 675void serio_unregister_child_port(struct serio *serio)
674{ 676{
675 down(&serio_sem); 677 mutex_lock(&serio_mutex);
676 if (serio->child) { 678 if (serio->child) {
677 serio_disconnect_port(serio->child); 679 serio_disconnect_port(serio->child);
678 serio_destroy_port(serio->child); 680 serio_destroy_port(serio->child);
679 } 681 }
680 up(&serio_sem); 682 mutex_unlock(&serio_mutex);
681} 683}
682 684
683/* 685/*
684 * Submits register request to kseriod for subsequent execution. 686 * Submits register request to kseriod for subsequent execution.
685 * Can be used when it is not obvious whether the serio_sem is 687 * Can be used when it is not obvious whether the serio_mutex is
686 * taken or not and when delayed execution is feasible. 688 * taken or not and when delayed execution is feasible.
687 */ 689 */
688void __serio_unregister_port_delayed(struct serio *serio, struct module *owner) 690void __serio_unregister_port_delayed(struct serio *serio, struct module *owner)
@@ -765,7 +767,7 @@ void serio_unregister_driver(struct serio_driver *drv)
765{ 767{
766 struct serio *serio; 768 struct serio *serio;
767 769
768 down(&serio_sem); 770 mutex_lock(&serio_mutex);
769 drv->manual_bind = 1; /* so serio_find_driver ignores it */ 771 drv->manual_bind = 1; /* so serio_find_driver ignores it */
770 772
771start_over: 773start_over:
@@ -779,7 +781,7 @@ start_over:
779 } 781 }
780 782
781 driver_unregister(&drv->driver); 783 driver_unregister(&drv->driver);
782 up(&serio_sem); 784 mutex_unlock(&serio_mutex);
783} 785}
784 786
785static void serio_set_drv(struct serio *serio, struct serio_driver *drv) 787static void serio_set_drv(struct serio *serio, struct serio_driver *drv)
@@ -858,7 +860,7 @@ static int serio_resume(struct device *dev)
858 return 0; 860 return 0;
859} 861}
860 862
861/* called from serio_driver->connect/disconnect methods under serio_sem */ 863/* called from serio_driver->connect/disconnect methods under serio_mutex */
862int serio_open(struct serio *serio, struct serio_driver *drv) 864int serio_open(struct serio *serio, struct serio_driver *drv)
863{ 865{
864 serio_set_drv(serio, drv); 866 serio_set_drv(serio, drv);
@@ -870,7 +872,7 @@ int serio_open(struct serio *serio, struct serio_driver *drv)
870 return 0; 872 return 0;
871} 873}
872 874
873/* called from serio_driver->connect/disconnect methods under serio_sem */ 875/* called from serio_driver->connect/disconnect methods under serio_mutex */
874void serio_close(struct serio *serio) 876void serio_close(struct serio *serio)
875{ 877{
876 if (serio->close) 878 if (serio->close)
@@ -923,5 +925,5 @@ static void __exit serio_exit(void)
923 kthread_stop(serio_task); 925 kthread_stop(serio_task);
924} 926}
925 927
926module_init(serio_init); 928subsys_initcall(serio_init);
927module_exit(serio_exit); 929module_exit(serio_exit);
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index 47e08de18d07..5a2703b536dc 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -19,6 +19,7 @@
19#include <linux/devfs_fs_kernel.h> 19#include <linux/devfs_fs_kernel.h>
20#include <linux/miscdevice.h> 20#include <linux/miscdevice.h>
21#include <linux/wait.h> 21#include <linux/wait.h>
22#include <linux/mutex.h>
22 23
23#define DRIVER_DESC "Raw serio driver" 24#define DRIVER_DESC "Raw serio driver"
24 25
@@ -46,7 +47,7 @@ struct serio_raw_list {
46 struct list_head node; 47 struct list_head node;
47}; 48};
48 49
49static DECLARE_MUTEX(serio_raw_sem); 50static DEFINE_MUTEX(serio_raw_mutex);
50static LIST_HEAD(serio_raw_list); 51static LIST_HEAD(serio_raw_list);
51static unsigned int serio_raw_no; 52static unsigned int serio_raw_no;
52 53
@@ -81,7 +82,7 @@ static int serio_raw_open(struct inode *inode, struct file *file)
81 struct serio_raw_list *list; 82 struct serio_raw_list *list;
82 int retval = 0; 83 int retval = 0;
83 84
84 retval = down_interruptible(&serio_raw_sem); 85 retval = mutex_lock_interruptible(&serio_raw_mutex);
85 if (retval) 86 if (retval)
86 return retval; 87 return retval;
87 88
@@ -95,12 +96,11 @@ static int serio_raw_open(struct inode *inode, struct file *file)
95 goto out; 96 goto out;
96 } 97 }
97 98
98 if (!(list = kmalloc(sizeof(struct serio_raw_list), GFP_KERNEL))) { 99 if (!(list = kzalloc(sizeof(struct serio_raw_list), GFP_KERNEL))) {
99 retval = -ENOMEM; 100 retval = -ENOMEM;
100 goto out; 101 goto out;
101 } 102 }
102 103
103 memset(list, 0, sizeof(struct serio_raw_list));
104 list->serio_raw = serio_raw; 104 list->serio_raw = serio_raw;
105 file->private_data = list; 105 file->private_data = list;
106 106
@@ -108,7 +108,7 @@ static int serio_raw_open(struct inode *inode, struct file *file)
108 list_add_tail(&list->node, &serio_raw->list); 108 list_add_tail(&list->node, &serio_raw->list);
109 109
110out: 110out:
111 up(&serio_raw_sem); 111 mutex_unlock(&serio_raw_mutex);
112 return retval; 112 return retval;
113} 113}
114 114
@@ -130,12 +130,12 @@ static int serio_raw_release(struct inode *inode, struct file *file)
130 struct serio_raw_list *list = file->private_data; 130 struct serio_raw_list *list = file->private_data;
131 struct serio_raw *serio_raw = list->serio_raw; 131 struct serio_raw *serio_raw = list->serio_raw;
132 132
133 down(&serio_raw_sem); 133 mutex_lock(&serio_raw_mutex);
134 134
135 serio_raw_fasync(-1, file, 0); 135 serio_raw_fasync(-1, file, 0);
136 serio_raw_cleanup(serio_raw); 136 serio_raw_cleanup(serio_raw);
137 137
138 up(&serio_raw_sem); 138 mutex_unlock(&serio_raw_mutex);
139 return 0; 139 return 0;
140} 140}
141 141
@@ -194,7 +194,7 @@ static ssize_t serio_raw_write(struct file *file, const char __user *buffer, siz
194 int retval; 194 int retval;
195 unsigned char c; 195 unsigned char c;
196 196
197 retval = down_interruptible(&serio_raw_sem); 197 retval = mutex_lock_interruptible(&serio_raw_mutex);
198 if (retval) 198 if (retval)
199 return retval; 199 return retval;
200 200
@@ -219,7 +219,7 @@ static ssize_t serio_raw_write(struct file *file, const char __user *buffer, siz
219 }; 219 };
220 220
221out: 221out:
222 up(&serio_raw_sem); 222 mutex_unlock(&serio_raw_mutex);
223 return written; 223 return written;
224} 224}
225 225
@@ -275,14 +275,13 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
275 struct serio_raw *serio_raw; 275 struct serio_raw *serio_raw;
276 int err; 276 int err;
277 277
278 if (!(serio_raw = kmalloc(sizeof(struct serio_raw), GFP_KERNEL))) { 278 if (!(serio_raw = kzalloc(sizeof(struct serio_raw), GFP_KERNEL))) {
279 printk(KERN_ERR "serio_raw.c: can't allocate memory for a device\n"); 279 printk(KERN_ERR "serio_raw.c: can't allocate memory for a device\n");
280 return -ENOMEM; 280 return -ENOMEM;
281 } 281 }
282 282
283 down(&serio_raw_sem); 283 mutex_lock(&serio_raw_mutex);
284 284
285 memset(serio_raw, 0, sizeof(struct serio_raw));
286 snprintf(serio_raw->name, sizeof(serio_raw->name), "serio_raw%d", serio_raw_no++); 285 snprintf(serio_raw->name, sizeof(serio_raw->name), "serio_raw%d", serio_raw_no++);
287 serio_raw->refcnt = 1; 286 serio_raw->refcnt = 1;
288 serio_raw->serio = serio; 287 serio_raw->serio = serio;
@@ -325,7 +324,7 @@ out_free:
325 serio_set_drvdata(serio, NULL); 324 serio_set_drvdata(serio, NULL);
326 kfree(serio_raw); 325 kfree(serio_raw);
327out: 326out:
328 up(&serio_raw_sem); 327 mutex_unlock(&serio_raw_mutex);
329 return err; 328 return err;
330} 329}
331 330
@@ -350,7 +349,7 @@ static void serio_raw_disconnect(struct serio *serio)
350{ 349{
351 struct serio_raw *serio_raw; 350 struct serio_raw *serio_raw;
352 351
353 down(&serio_raw_sem); 352 mutex_lock(&serio_raw_mutex);
354 353
355 serio_raw = serio_get_drvdata(serio); 354 serio_raw = serio_get_drvdata(serio);
356 355
@@ -361,7 +360,7 @@ static void serio_raw_disconnect(struct serio *serio)
361 if (!serio_raw_cleanup(serio_raw)) 360 if (!serio_raw_cleanup(serio_raw))
362 wake_up_interruptible(&serio_raw->wait); 361 wake_up_interruptible(&serio_raw->wait);
363 362
364 up(&serio_raw_sem); 363 mutex_unlock(&serio_raw_mutex);
365} 364}
366 365
367static struct serio_device_id serio_raw_serio_ids[] = { 366static struct serio_device_id serio_raw_serio_ids[] = {
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index ca1547929d62..d678d144bbf8 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -157,9 +157,8 @@ static int tsdev_open(struct inode *inode, struct file *file)
157 if (i >= TSDEV_MINORS || !tsdev_table[i & TSDEV_MINOR_MASK]) 157 if (i >= TSDEV_MINORS || !tsdev_table[i & TSDEV_MINOR_MASK])
158 return -ENODEV; 158 return -ENODEV;
159 159
160 if (!(list = kmalloc(sizeof(struct tsdev_list), GFP_KERNEL))) 160 if (!(list = kzalloc(sizeof(struct tsdev_list), GFP_KERNEL)))
161 return -ENOMEM; 161 return -ENOMEM;
162 memset(list, 0, sizeof(struct tsdev_list));
163 162
164 list->raw = (i >= TSDEV_MINORS/2) ? 1 : 0; 163 list->raw = (i >= TSDEV_MINORS/2) ? 1 : 0;
165 164
@@ -379,9 +378,8 @@ static struct input_handle *tsdev_connect(struct input_handler *handler,
379 return NULL; 378 return NULL;
380 } 379 }
381 380
382 if (!(tsdev = kmalloc(sizeof(struct tsdev), GFP_KERNEL))) 381 if (!(tsdev = kzalloc(sizeof(struct tsdev), GFP_KERNEL)))
383 return NULL; 382 return NULL;
384 memset(tsdev, 0, sizeof(struct tsdev));
385 383
386 INIT_LIST_HEAD(&tsdev->list); 384 INIT_LIST_HEAD(&tsdev->list);
387 init_waitqueue_head(&tsdev->wait); 385 init_waitqueue_head(&tsdev->wait);
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
index 53c4fb62ed85..5b203fe21dcd 100644
--- a/drivers/isdn/gigaset/Kconfig
+++ b/drivers/isdn/gigaset/Kconfig
@@ -3,8 +3,8 @@ menu "Siemens Gigaset"
3 3
4config ISDN_DRV_GIGASET 4config ISDN_DRV_GIGASET
5 tristate "Siemens Gigaset support (isdn)" 5 tristate "Siemens Gigaset support (isdn)"
6 depends on ISDN_I4L && m 6 depends on ISDN_I4L
7# depends on ISDN_I4L && MODULES 7 select CRC_CCITT
8 help 8 help
9 Say m here if you have a Gigaset or Sinus isdn device. 9 Say m here if you have a Gigaset or Sinus isdn device.
10 10
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index 171f8b703d61..ce3cd77094b3 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2005 by Tilman Schmidt <tilman@imap.cc>, 4 * Copyright (c) 2005 by Tilman Schmidt <tilman@imap.cc>,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Stefan Eilers <Eilers.Stefan@epost.de>. 6 * Stefan Eilers.
7 * 7 *
8 * ===================================================================== 8 * =====================================================================
9 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -11,10 +11,6 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: asyncdata.c,v 1.2.2.7 2005/11/13 23:05:18 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
@@ -45,7 +41,7 @@ static inline int muststuff(unsigned char c)
45 * number of processed bytes 41 * number of processed bytes
46 */ 42 */
47static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes, 43static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
48 struct inbuf_t *inbuf) 44 struct inbuf_t *inbuf)
49{ 45{
50 struct cardstate *cs = inbuf->cs; 46 struct cardstate *cs = inbuf->cs;
51 unsigned cbytes = cs->cbytes; 47 unsigned cbytes = cs->cbytes;
@@ -55,10 +51,11 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
55 for (;;) { 51 for (;;) {
56 cs->respdata[cbytes] = c; 52 cs->respdata[cbytes] = c;
57 if (c == 10 || c == 13) { 53 if (c == 10 || c == 13) {
58 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", 54 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
59 __func__, cbytes); 55 __func__, cbytes);
60 cs->cbytes = cbytes; 56 cs->cbytes = cbytes;
61 gigaset_handle_modem_response(cs); /* can change cs->dle */ 57 gigaset_handle_modem_response(cs); /* can change
58 cs->dle */
62 cbytes = 0; 59 cbytes = 0;
63 60
64 if (cs->dle && 61 if (cs->dle &&
@@ -71,7 +68,7 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
71 if (cbytes < MAX_RESP_SIZE - 1) 68 if (cbytes < MAX_RESP_SIZE - 1)
72 cbytes++; 69 cbytes++;
73 else 70 else
74 warn("response too large"); 71 dev_warn(cs->dev, "response too large\n");
75 } 72 }
76 73
77 if (!numbytes) 74 if (!numbytes)
@@ -96,11 +93,12 @@ static inline int cmd_loop(unsigned char c, unsigned char *src, int numbytes,
96 * number of processed bytes 93 * number of processed bytes
97 */ 94 */
98static inline int lock_loop(unsigned char *src, int numbytes, 95static inline int lock_loop(unsigned char *src, int numbytes,
99 struct inbuf_t *inbuf) 96 struct inbuf_t *inbuf)
100{ 97{
101 struct cardstate *cs = inbuf->cs; 98 struct cardstate *cs = inbuf->cs;
102 99
103 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response", numbytes, src, 0); 100 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
101 numbytes, src);
104 gigaset_if_receive(cs, src, numbytes); 102 gigaset_if_receive(cs, src, numbytes);
105 103
106 return numbytes; 104 return numbytes;
@@ -115,24 +113,18 @@ static inline int lock_loop(unsigned char *src, int numbytes,
115 * numbytes (all bytes processed) on error --FIXME 113 * numbytes (all bytes processed) on error --FIXME
116 */ 114 */
117static inline int hdlc_loop(unsigned char c, unsigned char *src, int numbytes, 115static inline int hdlc_loop(unsigned char c, unsigned char *src, int numbytes,
118 struct inbuf_t *inbuf) 116 struct inbuf_t *inbuf)
119{ 117{
120 struct cardstate *cs = inbuf->cs; 118 struct cardstate *cs = inbuf->cs;
121 struct bc_state *bcs = inbuf->bcs; 119 struct bc_state *bcs = inbuf->bcs;
122 int inputstate; 120 int inputstate = bcs->inputstate;
123 __u16 fcs; 121 __u16 fcs = bcs->fcs;
124 struct sk_buff *skb; 122 struct sk_buff *skb = bcs->skb;
125 unsigned char error; 123 unsigned char error;
126 struct sk_buff *compskb; 124 struct sk_buff *compskb;
127 int startbytes = numbytes; 125 int startbytes = numbytes;
128 int l; 126 int l;
129 127
130 IFNULLRETVAL(bcs, numbytes);
131 inputstate = bcs->inputstate;
132 fcs = bcs->fcs;
133 skb = bcs->skb;
134 IFNULLRETVAL(skb, numbytes);
135
136 if (unlikely(inputstate & INS_byte_stuff)) { 128 if (unlikely(inputstate & INS_byte_stuff)) {
137 inputstate &= ~INS_byte_stuff; 129 inputstate &= ~INS_byte_stuff;
138 goto byte_stuff; 130 goto byte_stuff;
@@ -156,39 +148,37 @@ byte_stuff:
156 c ^= PPP_TRANS; 148 c ^= PPP_TRANS;
157#ifdef CONFIG_GIGASET_DEBUG 149#ifdef CONFIG_GIGASET_DEBUG
158 if (unlikely(!muststuff(c))) 150 if (unlikely(!muststuff(c)))
159 dbg(DEBUG_HDLC, 151 gig_dbg(DEBUG_HDLC, "byte stuffed: 0x%02x", c);
160 "byte stuffed: 0x%02x", c);
161#endif 152#endif
162 } else if (unlikely(c == PPP_FLAG)) { 153 } else if (unlikely(c == PPP_FLAG)) {
163 if (unlikely(inputstate & INS_skip_frame)) { 154 if (unlikely(inputstate & INS_skip_frame)) {
164 if (!(inputstate & INS_have_data)) { /* 7E 7E */ 155 if (!(inputstate & INS_have_data)) { /* 7E 7E */
165 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
166#ifdef CONFIG_GIGASET_DEBUG 156#ifdef CONFIG_GIGASET_DEBUG
167 ++bcs->emptycount; 157 ++bcs->emptycount;
168#endif 158#endif
169 } else 159 } else
170 dbg(DEBUG_HDLC, 160 gig_dbg(DEBUG_HDLC,
171 "7e----------------------------"); 161 "7e----------------------------");
172 162
173 /* end of frame */ 163 /* end of frame */
174 error = 1; 164 error = 1;
175 gigaset_rcv_error(NULL, cs, bcs); 165 gigaset_rcv_error(NULL, cs, bcs);
176 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */ 166 } else if (!(inputstate & INS_have_data)) { /* 7E 7E */
177 //dbg(DEBUG_HDLC, "(7e)7e------------------------");
178#ifdef CONFIG_GIGASET_DEBUG 167#ifdef CONFIG_GIGASET_DEBUG
179 ++bcs->emptycount; 168 ++bcs->emptycount;
180#endif 169#endif
181 break; 170 break;
182 } else { 171 } else {
183 dbg(DEBUG_HDLC, 172 gig_dbg(DEBUG_HDLC,
184 "7e----------------------------"); 173 "7e----------------------------");
185 174
186 /* end of frame */ 175 /* end of frame */
187 error = 0; 176 error = 0;
188 177
189 if (unlikely(fcs != PPP_GOODFCS)) { 178 if (unlikely(fcs != PPP_GOODFCS)) {
190 err("Packet checksum at %lu failed, " 179 dev_err(cs->dev,
191 "packet is corrupted (%u bytes)!", 180 "Packet checksum at %lu failed, "
181 "packet is corrupted (%u bytes)!\n",
192 bcs->rcvbytes, skb->len); 182 bcs->rcvbytes, skb->len);
193 compskb = NULL; 183 compskb = NULL;
194 gigaset_rcv_error(compskb, cs, bcs); 184 gigaset_rcv_error(compskb, cs, bcs);
@@ -202,9 +192,11 @@ byte_stuff:
202 skb = NULL; 192 skb = NULL;
203 inputstate |= INS_skip_frame; 193 inputstate |= INS_skip_frame;
204 if (l == 1) { 194 if (l == 1) {
205 err("invalid packet size (1)!"); 195 dev_err(cs->dev,
196 "invalid packet size (1)!\n");
206 error = 1; 197 error = 1;
207 gigaset_rcv_error(NULL, cs, bcs); 198 gigaset_rcv_error(NULL,
199 cs, bcs);
208 } 200 }
209 } 201 }
210 if (likely(!(error || 202 if (likely(!(error ||
@@ -227,7 +219,8 @@ byte_stuff:
227 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) { 219 } else if (likely((skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)) {
228 skb_reserve(skb, HW_HDR_LEN); 220 skb_reserve(skb, HW_HDR_LEN);
229 } else { 221 } else {
230 warn("could not allocate new skb"); 222 dev_warn(cs->dev,
223 "could not allocate new skb\n");
231 inputstate |= INS_skip_frame; 224 inputstate |= INS_skip_frame;
232 } 225 }
233 226
@@ -235,7 +228,7 @@ byte_stuff:
235#ifdef CONFIG_GIGASET_DEBUG 228#ifdef CONFIG_GIGASET_DEBUG
236 } else if (unlikely(muststuff(c))) { 229 } else if (unlikely(muststuff(c))) {
237 /* Should not happen. Possible after ZDLE=1<CR><LF>. */ 230 /* Should not happen. Possible after ZDLE=1<CR><LF>. */
238 dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c); 231 gig_dbg(DEBUG_HDLC, "not byte stuffed: 0x%02x", c);
239#endif 232#endif
240 } 233 }
241 234
@@ -243,8 +236,8 @@ byte_stuff:
243 236
244#ifdef CONFIG_GIGASET_DEBUG 237#ifdef CONFIG_GIGASET_DEBUG
245 if (unlikely(!(inputstate & INS_have_data))) { 238 if (unlikely(!(inputstate & INS_have_data))) {
246 dbg(DEBUG_HDLC, 239 gig_dbg(DEBUG_HDLC, "7e (%d x) ================",
247 "7e (%d x) ================", bcs->emptycount); 240 bcs->emptycount);
248 bcs->emptycount = 0; 241 bcs->emptycount = 0;
249 } 242 }
250#endif 243#endif
@@ -253,14 +246,13 @@ byte_stuff:
253 246
254 if (likely(!(inputstate & INS_skip_frame))) { 247 if (likely(!(inputstate & INS_skip_frame))) {
255 if (unlikely(skb->len == SBUFSIZE)) { 248 if (unlikely(skb->len == SBUFSIZE)) {
256 warn("received packet too long"); 249 dev_warn(cs->dev, "received packet too long\n");
257 dev_kfree_skb_any(skb); 250 dev_kfree_skb_any(skb);
258 skb = NULL; 251 skb = NULL;
259 inputstate |= INS_skip_frame; 252 inputstate |= INS_skip_frame;
260 break; 253 break;
261 } 254 }
262 *gigaset_skb_put_quick(skb, 1) = c; 255 *__skb_put(skb, 1) = c;
263 /* *__skb_put (skb, 1) = c; */
264 fcs = crc_ccitt_byte(fcs, c); 256 fcs = crc_ccitt_byte(fcs, c);
265 } 257 }
266 258
@@ -289,19 +281,14 @@ byte_stuff:
289 * numbytes (all bytes processed) on error --FIXME 281 * numbytes (all bytes processed) on error --FIXME
290 */ 282 */
291static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes, 283static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
292 struct inbuf_t *inbuf) 284 struct inbuf_t *inbuf)
293{ 285{
294 struct cardstate *cs = inbuf->cs; 286 struct cardstate *cs = inbuf->cs;
295 struct bc_state *bcs = inbuf->bcs; 287 struct bc_state *bcs = inbuf->bcs;
296 int inputstate; 288 int inputstate = bcs->inputstate;
297 struct sk_buff *skb; 289 struct sk_buff *skb = bcs->skb;
298 int startbytes = numbytes; 290 int startbytes = numbytes;
299 291
300 IFNULLRETVAL(bcs, numbytes);
301 inputstate = bcs->inputstate;
302 skb = bcs->skb;
303 IFNULLRETVAL(skb, numbytes);
304
305 for (;;) { 292 for (;;) {
306 /* add character */ 293 /* add character */
307 inputstate |= INS_have_data; 294 inputstate |= INS_have_data;
@@ -309,13 +296,13 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
309 if (likely(!(inputstate & INS_skip_frame))) { 296 if (likely(!(inputstate & INS_skip_frame))) {
310 if (unlikely(skb->len == SBUFSIZE)) { 297 if (unlikely(skb->len == SBUFSIZE)) {
311 //FIXME just pass skb up and allocate a new one 298 //FIXME just pass skb up and allocate a new one
312 warn("received packet too long"); 299 dev_warn(cs->dev, "received packet too long\n");
313 dev_kfree_skb_any(skb); 300 dev_kfree_skb_any(skb);
314 skb = NULL; 301 skb = NULL;
315 inputstate |= INS_skip_frame; 302 inputstate |= INS_skip_frame;
316 break; 303 break;
317 } 304 }
318 *gigaset_skb_put_quick(skb, 1) = gigaset_invtab[c]; 305 *__skb_put(skb, 1) = gigaset_invtab[c];
319 } 306 }
320 307
321 if (unlikely(!numbytes)) 308 if (unlikely(!numbytes))
@@ -343,7 +330,7 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
343 != NULL)) { 330 != NULL)) {
344 skb_reserve(skb, HW_HDR_LEN); 331 skb_reserve(skb, HW_HDR_LEN);
345 } else { 332 } else {
346 warn("could not allocate new skb"); 333 dev_warn(cs->dev, "could not allocate new skb\n");
347 inputstate |= INS_skip_frame; 334 inputstate |= INS_skip_frame;
348 } 335 }
349 } 336 }
@@ -364,13 +351,13 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
364 351
365 head = atomic_read(&inbuf->head); 352 head = atomic_read(&inbuf->head);
366 tail = atomic_read(&inbuf->tail); 353 tail = atomic_read(&inbuf->tail);
367 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); 354 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
368 355
369 if (head != tail) { 356 if (head != tail) {
370 cs = inbuf->cs; 357 cs = inbuf->cs;
371 src = inbuf->data + head; 358 src = inbuf->data + head;
372 numbytes = (head > tail ? RBUFSIZE : tail) - head; 359 numbytes = (head > tail ? RBUFSIZE : tail) - head;
373 dbg(DEBUG_INTR, "processing %u bytes", numbytes); 360 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
374 361
375 while (numbytes) { 362 while (numbytes) {
376 if (atomic_read(&cs->mstate) == MS_LOCKED) { 363 if (atomic_read(&cs->mstate) == MS_LOCKED) {
@@ -392,8 +379,7 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
392 379
393 if (!(inbuf->inputstate & INS_DLE_char)) { 380 if (!(inbuf->inputstate & INS_DLE_char)) {
394 381
395 /* FIXME Einfach je nach Modus Funktionszeiger in cs setzen [hier+hdlc_loop]? */ 382 /* FIXME use function pointers? */
396 /* FIXME Spart folgendes "if" und ermoeglicht andere Protokolle */
397 if (inbuf->inputstate & INS_command) 383 if (inbuf->inputstate & INS_command)
398 procbytes = cmd_loop(c, src, numbytes, inbuf); 384 procbytes = cmd_loop(c, src, numbytes, inbuf);
399 else if (inbuf->bcs->proto2 == ISDN_PROTO_L2_HDLC) 385 else if (inbuf->bcs->proto2 == ISDN_PROTO_L2_HDLC)
@@ -403,13 +389,14 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
403 389
404 src += procbytes; 390 src += procbytes;
405 numbytes -= procbytes; 391 numbytes -= procbytes;
406 } else { /* DLE-char */ 392 } else { /* DLE char */
407 inbuf->inputstate &= ~INS_DLE_char; 393 inbuf->inputstate &= ~INS_DLE_char;
408 switch (c) { 394 switch (c) {
409 case 'X': /*begin of command*/ 395 case 'X': /*begin of command*/
410#ifdef CONFIG_GIGASET_DEBUG 396#ifdef CONFIG_GIGASET_DEBUG
411 if (inbuf->inputstate & INS_command) 397 if (inbuf->inputstate & INS_command)
412 err("received <DLE> 'X' in command mode"); 398 dev_err(cs->dev,
399 "received <DLE> 'X' in command mode\n");
413#endif 400#endif
414 inbuf->inputstate |= 401 inbuf->inputstate |=
415 INS_command | INS_DLE_command; 402 INS_command | INS_DLE_command;
@@ -417,7 +404,8 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
417 case '.': /*end of command*/ 404 case '.': /*end of command*/
418#ifdef CONFIG_GIGASET_DEBUG 405#ifdef CONFIG_GIGASET_DEBUG
419 if (!(inbuf->inputstate & INS_command)) 406 if (!(inbuf->inputstate & INS_command))
420 err("received <DLE> '.' in hdlc mode"); 407 dev_err(cs->dev,
408 "received <DLE> '.' in hdlc mode\n");
421#endif 409#endif
422 inbuf->inputstate &= cs->dle ? 410 inbuf->inputstate &= cs->dle ?
423 ~(INS_DLE_command|INS_command) 411 ~(INS_DLE_command|INS_command)
@@ -425,7 +413,9 @@ void gigaset_m10x_input(struct inbuf_t *inbuf)
425 break; 413 break;
426 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */ 414 //case DLE_FLAG: /*DLE_FLAG in data stream*/ /* schon oben behandelt! */
427 default: 415 default:
428 err("received 0x10 0x%02x!", (int) c); 416 dev_err(cs->dev,
417 "received 0x10 0x%02x!\n",
418 (int) c);
429 /* FIXME: reset driver?? */ 419 /* FIXME: reset driver?? */
430 } 420 }
431 } 421 }
@@ -444,7 +434,7 @@ nextbyte:
444 } 434 }
445 } 435 }
446 436
447 dbg(DEBUG_INTR, "setting head to %u", head); 437 gig_dbg(DEBUG_INTR, "setting head to %u", head);
448 atomic_set(&inbuf->head, head); 438 atomic_set(&inbuf->head, head);
449 } 439 }
450} 440}
@@ -479,14 +469,13 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
479 stuf_cnt++; 469 stuf_cnt++;
480 fcs = crc_ccitt_byte(fcs, *cp++); 470 fcs = crc_ccitt_byte(fcs, *cp++);
481 } 471 }
482 fcs ^= 0xffff; /* complement */ 472 fcs ^= 0xffff; /* complement */
483 473
484 /* size of new buffer: original size + number of stuffing bytes 474 /* size of new buffer: original size + number of stuffing bytes
485 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes 475 * + 2 bytes FCS + 2 stuffing bytes for FCS (if needed) + 2 flag bytes
486 */ 476 */
487 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head); 477 hdlc_skb = dev_alloc_skb(skb->len + stuf_cnt + 6 + tail + head);
488 if (!hdlc_skb) { 478 if (!hdlc_skb) {
489 err("unable to allocate memory for HDLC encoding!");
490 dev_kfree_skb(skb); 479 dev_kfree_skb(skb);
491 return NULL; 480 return NULL;
492 } 481 }
@@ -508,7 +497,7 @@ static struct sk_buff *HDLC_Encode(struct sk_buff *skb, int head, int tail)
508 } 497 }
509 498
510 /* Finally add FCS (byte stuffed) and flag sequence */ 499 /* Finally add FCS (byte stuffed) and flag sequence */
511 c = (fcs & 0x00ff); /* least significant byte first */ 500 c = (fcs & 0x00ff); /* least significant byte first */
512 if (muststuff(c)) { 501 if (muststuff(c)) {
513 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE; 502 *(skb_put(hdlc_skb, 1)) = PPP_ESCAPE;
514 c ^= PPP_TRANS; 503 c ^= PPP_TRANS;
@@ -546,7 +535,6 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
546 /* worst case: every byte must be stuffed */ 535 /* worst case: every byte must be stuffed */
547 iraw_skb = dev_alloc_skb(2*skb->len + tail + head); 536 iraw_skb = dev_alloc_skb(2*skb->len + tail + head);
548 if (!iraw_skb) { 537 if (!iraw_skb) {
549 err("unable to allocate memory for HDLC encoding!");
550 dev_kfree_skb(skb); 538 dev_kfree_skb(skb);
551 return NULL; 539 return NULL;
552 } 540 }
@@ -577,21 +565,23 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
577 */ 565 */
578int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb) 566int gigaset_m10x_send_skb(struct bc_state *bcs, struct sk_buff *skb)
579{ 567{
580 unsigned len; 568 unsigned len = skb->len;
581 569 unsigned long flags;
582 IFNULLRETVAL(bcs, -EFAULT);
583 IFNULLRETVAL(skb, -EFAULT);
584 len = skb->len;
585 570
586 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 571 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
587 skb = HDLC_Encode(skb, HW_HDR_LEN, 0); 572 skb = HDLC_Encode(skb, HW_HDR_LEN, 0);
588 else 573 else
589 skb = iraw_encode(skb, HW_HDR_LEN, 0); 574 skb = iraw_encode(skb, HW_HDR_LEN, 0);
590 if (!skb) 575 if (!skb) {
576 err("unable to allocate memory for encoding!\n");
591 return -ENOMEM; 577 return -ENOMEM;
578 }
592 579
593 skb_queue_tail(&bcs->squeue, skb); 580 skb_queue_tail(&bcs->squeue, skb);
594 tasklet_schedule(&bcs->cs->write_tasklet); 581 spin_lock_irqsave(&bcs->cs->lock, flags);
582 if (bcs->cs->connected)
583 tasklet_schedule(&bcs->cs->write_tasklet);
584 spin_unlock_irqrestore(&bcs->cs->lock, flags);
595 585
596 return len; /* ok so far */ 586 return len; /* ok so far */
597} 587}
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 31f0f07832bc..f86ed6af3aa2 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>, 4 * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>,
5 * Tilman Schmidt <tilman@imap.cc>, 5 * Tilman Schmidt <tilman@imap.cc>,
6 * Stefan Eilers <Eilers.Stefan@epost.de>. 6 * Stefan Eilers.
7 * 7 *
8 * Based on usb-gigaset.c. 8 * Based on usb-gigaset.c.
9 * 9 *
@@ -13,10 +13,6 @@
13 * published by the Free Software Foundation; either version 2 of 13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version. 14 * the License, or (at your option) any later version.
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: bas-gigaset.c,v 1.52.4.19 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */ 16 */
21 17
22#include "gigaset.h" 18#include "gigaset.h"
@@ -30,7 +26,7 @@
30#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
31 27
32/* Version Information */ 28/* Version Information */
33#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>" 29#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
34#define DRIVER_DESC "USB Driver for Gigaset 307x" 30#define DRIVER_DESC "USB Driver for Gigaset 307x"
35 31
36 32
@@ -70,9 +66,6 @@ static struct usb_device_id gigaset_table [] = {
70 66
71MODULE_DEVICE_TABLE(usb, gigaset_table); 67MODULE_DEVICE_TABLE(usb, gigaset_table);
72 68
73/* Get a minor range for your devices from the usb maintainer */
74#define USB_SKEL_MINOR_BASE 200
75
76/*======================= local function prototypes =============================*/ 69/*======================= local function prototypes =============================*/
77 70
78/* This function is called if a new device is connected to the USB port. It 71/* This function is called if a new device is connected to the USB port. It
@@ -88,25 +81,25 @@ static void gigaset_disconnect(struct usb_interface *interface);
88/*==============================================================================*/ 81/*==============================================================================*/
89 82
90struct bas_cardstate { 83struct bas_cardstate {
91 struct usb_device *udev; /* USB device pointer */ 84 struct usb_device *udev; /* USB device pointer */
92 struct usb_interface *interface; /* interface for this device */ 85 struct usb_interface *interface; /* interface for this device */
93 unsigned char minor; /* starting minor number */ 86 unsigned char minor; /* starting minor number */
94 87
95 struct urb *urb_ctrl; /* control pipe default URB */ 88 struct urb *urb_ctrl; /* control pipe default URB */
96 struct usb_ctrlrequest dr_ctrl; 89 struct usb_ctrlrequest dr_ctrl;
97 struct timer_list timer_ctrl; /* control request timeout */ 90 struct timer_list timer_ctrl; /* control request timeout */
98 91
99 struct timer_list timer_atrdy; /* AT command ready timeout */ 92 struct timer_list timer_atrdy; /* AT command ready timeout */
100 struct urb *urb_cmd_out; /* for sending AT commands */ 93 struct urb *urb_cmd_out; /* for sending AT commands */
101 struct usb_ctrlrequest dr_cmd_out; 94 struct usb_ctrlrequest dr_cmd_out;
102 int retry_cmd_out; 95 int retry_cmd_out;
103 96
104 struct urb *urb_cmd_in; /* for receiving AT replies */ 97 struct urb *urb_cmd_in; /* for receiving AT replies */
105 struct usb_ctrlrequest dr_cmd_in; 98 struct usb_ctrlrequest dr_cmd_in;
106 struct timer_list timer_cmd_in; /* receive request timeout */ 99 struct timer_list timer_cmd_in; /* receive request timeout */
107 unsigned char *rcvbuf; /* AT reply receive buffer */ 100 unsigned char *rcvbuf; /* AT reply receive buffer */
108 101
109 struct urb *urb_int_in; /* URB for interrupt pipe */ 102 struct urb *urb_int_in; /* URB for interrupt pipe */
110 unsigned char int_in_buf[3]; 103 unsigned char int_in_buf[3];
111 104
112 spinlock_t lock; /* locks all following */ 105 spinlock_t lock; /* locks all following */
@@ -208,53 +201,54 @@ static inline char *usb_pipetype_str(int pipe)
208 * write content of URB to syslog for debugging 201 * write content of URB to syslog for debugging
209 */ 202 */
210static inline void dump_urb(enum debuglevel level, const char *tag, 203static inline void dump_urb(enum debuglevel level, const char *tag,
211 struct urb *urb) 204 struct urb *urb)
212{ 205{
213#ifdef CONFIG_GIGASET_DEBUG 206#ifdef CONFIG_GIGASET_DEBUG
214 int i; 207 int i;
215 IFNULLRET(tag); 208 gig_dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
216 dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
217 if (urb) { 209 if (urb) {
218 dbg(level, 210 gig_dbg(level,
219 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, " 211 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
220 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,", 212 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,",
221 (unsigned long) urb->dev, 213 (unsigned long) urb->dev,
222 usb_pipetype_str(urb->pipe), 214 usb_pipetype_str(urb->pipe),
223 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe), 215 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
224 usb_pipein(urb->pipe) ? "in" : "out", 216 usb_pipein(urb->pipe) ? "in" : "out",
225 urb->status, (unsigned long) urb->hcpriv, 217 urb->status, (unsigned long) urb->hcpriv,
226 urb->transfer_flags); 218 urb->transfer_flags);
227 dbg(level, 219 gig_dbg(level,
228 " transfer_buffer=0x%08lx[%d], actual_length=%d, " 220 " transfer_buffer=0x%08lx[%d], actual_length=%d, "
229 "bandwidth=%d, setup_packet=0x%08lx,", 221 "bandwidth=%d, setup_packet=0x%08lx,",
230 (unsigned long) urb->transfer_buffer, 222 (unsigned long) urb->transfer_buffer,
231 urb->transfer_buffer_length, urb->actual_length, 223 urb->transfer_buffer_length, urb->actual_length,
232 urb->bandwidth, (unsigned long) urb->setup_packet); 224 urb->bandwidth, (unsigned long) urb->setup_packet);
233 dbg(level, 225 gig_dbg(level,
234 " start_frame=%d, number_of_packets=%d, interval=%d, " 226 " start_frame=%d, number_of_packets=%d, interval=%d, "
235 "error_count=%d,", 227 "error_count=%d,",
236 urb->start_frame, urb->number_of_packets, urb->interval, 228 urb->start_frame, urb->number_of_packets, urb->interval,
237 urb->error_count); 229 urb->error_count);
238 dbg(level, 230 gig_dbg(level,
239 " context=0x%08lx, complete=0x%08lx, iso_frame_desc[]={", 231 " context=0x%08lx, complete=0x%08lx, "
240 (unsigned long) urb->context, 232 "iso_frame_desc[]={",
241 (unsigned long) urb->complete); 233 (unsigned long) urb->context,
234 (unsigned long) urb->complete);
242 for (i = 0; i < urb->number_of_packets; i++) { 235 for (i = 0; i < urb->number_of_packets; i++) {
243 struct usb_iso_packet_descriptor *pifd = &urb->iso_frame_desc[i]; 236 struct usb_iso_packet_descriptor *pifd
244 dbg(level, 237 = &urb->iso_frame_desc[i];
245 " {offset=%u, length=%u, actual_length=%u, " 238 gig_dbg(level,
246 "status=%u}", 239 " {offset=%u, length=%u, actual_length=%u, "
247 pifd->offset, pifd->length, pifd->actual_length, 240 "status=%u}",
248 pifd->status); 241 pifd->offset, pifd->length, pifd->actual_length,
242 pifd->status);
249 } 243 }
250 } 244 }
251 dbg(level, "}}"); 245 gig_dbg(level, "}}");
252#endif 246#endif
253} 247}
254 248
255/* read/set modem control bits etc. (m10x only) */ 249/* read/set modem control bits etc. (m10x only) */
256static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 250static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
257 unsigned new_state) 251 unsigned new_state)
258{ 252{
259 return -EINVAL; 253 return -EINVAL;
260} 254}
@@ -280,8 +274,8 @@ static inline void error_hangup(struct bc_state *bcs)
280{ 274{
281 struct cardstate *cs = bcs->cs; 275 struct cardstate *cs = bcs->cs;
282 276
283 dbg(DEBUG_ANY, 277 gig_dbg(DEBUG_ANY, "%s: scheduling HUP for channel %d",
284 "%s: scheduling HUP for channel %d", __func__, bcs->channel); 278 __func__, bcs->channel);
285 279
286 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) { 280 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
287 //FIXME what should we do? 281 //FIXME what should we do?
@@ -301,22 +295,19 @@ static inline void error_hangup(struct bc_state *bcs)
301static inline void error_reset(struct cardstate *cs) 295static inline void error_reset(struct cardstate *cs)
302{ 296{
303 //FIXME try to recover without bothering the user 297 //FIXME try to recover without bothering the user
304 err("unrecoverable error - please disconnect the Gigaset base to reset"); 298 dev_err(cs->dev,
299 "unrecoverable error - please disconnect Gigaset base to reset\n");
305} 300}
306 301
307/* check_pending 302/* check_pending
308 * check for completion of pending control request 303 * check for completion of pending control request
309 * parameter: 304 * parameter:
310 * urb USB request block of completed request 305 * ucs hardware specific controller state structure
311 * urb->context = hardware specific controller state structure
312 */ 306 */
313static void check_pending(struct bas_cardstate *ucs) 307static void check_pending(struct bas_cardstate *ucs)
314{ 308{
315 unsigned long flags; 309 unsigned long flags;
316 310
317 IFNULLRET(ucs);
318 IFNULLRET(cardstate);
319
320 spin_lock_irqsave(&ucs->lock, flags); 311 spin_lock_irqsave(&ucs->lock, flags);
321 switch (ucs->pending) { 312 switch (ucs->pending) {
322 case 0: 313 case 0:
@@ -336,8 +327,6 @@ static void check_pending(struct bas_cardstate *ucs)
336 case HD_CLOSE_ATCHANNEL: 327 case HD_CLOSE_ATCHANNEL:
337 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) 328 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
338 ucs->pending = 0; 329 ucs->pending = 0;
339 //wake_up_interruptible(cs->initwait);
340 //FIXME need own wait queue?
341 break; 330 break;
342 case HD_CLOSE_B1CHANNEL: 331 case HD_CLOSE_B1CHANNEL:
343 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN)) 332 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
@@ -354,7 +343,9 @@ static void check_pending(struct bas_cardstate *ucs)
354 * are handled separately and should never end up here 343 * are handled separately and should never end up here
355 */ 344 */
356 default: 345 default:
357 warn("unknown pending request 0x%02x cleared", ucs->pending); 346 dev_warn(&ucs->interface->dev,
347 "unknown pending request 0x%02x cleared\n",
348 ucs->pending);
358 ucs->pending = 0; 349 ucs->pending = 0;
359 } 350 }
360 351
@@ -372,27 +363,23 @@ static void check_pending(struct bas_cardstate *ucs)
372static void cmd_in_timeout(unsigned long data) 363static void cmd_in_timeout(unsigned long data)
373{ 364{
374 struct cardstate *cs = (struct cardstate *) data; 365 struct cardstate *cs = (struct cardstate *) data;
375 struct bas_cardstate *ucs; 366 struct bas_cardstate *ucs = cs->hw.bas;
376 unsigned long flags; 367 unsigned long flags;
377 368
378 IFNULLRET(cs);
379 ucs = cs->hw.bas;
380 IFNULLRET(ucs);
381
382 spin_lock_irqsave(&cs->lock, flags); 369 spin_lock_irqsave(&cs->lock, flags);
383 if (!atomic_read(&cs->connected)) { 370 if (unlikely(!cs->connected)) {
384 dbg(DEBUG_USBREQ, "%s: disconnected", __func__); 371 gig_dbg(DEBUG_USBREQ, "%s: disconnected", __func__);
385 spin_unlock_irqrestore(&cs->lock, flags); 372 spin_unlock_irqrestore(&cs->lock, flags);
386 return; 373 return;
387 } 374 }
388 if (!ucs->rcvbuf_size) { 375 if (!ucs->rcvbuf_size) {
389 dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__); 376 gig_dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__);
390 spin_unlock_irqrestore(&cs->lock, flags); 377 spin_unlock_irqrestore(&cs->lock, flags);
391 return; 378 return;
392 } 379 }
393 spin_unlock_irqrestore(&cs->lock, flags); 380 spin_unlock_irqrestore(&cs->lock, flags);
394 381
395 err("timeout reading AT response"); 382 dev_err(cs->dev, "timeout reading AT response\n");
396 error_reset(cs); //FIXME retry? 383 error_reset(cs); //FIXME retry?
397} 384}
398 385
@@ -412,18 +399,15 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs);
412 */ 399 */
413static int atread_submit(struct cardstate *cs, int timeout) 400static int atread_submit(struct cardstate *cs, int timeout)
414{ 401{
415 struct bas_cardstate *ucs; 402 struct bas_cardstate *ucs = cs->hw.bas;
416 int ret; 403 int ret;
417 404
418 IFNULLRETVAL(cs, -EINVAL); 405 gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)",
419 ucs = cs->hw.bas; 406 ucs->rcvbuf_size);
420 IFNULLRETVAL(ucs, -EINVAL);
421 IFNULLRETVAL(ucs->urb_cmd_in, -EINVAL);
422
423 dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)", ucs->rcvbuf_size);
424 407
425 if (ucs->urb_cmd_in->status == -EINPROGRESS) { 408 if (ucs->urb_cmd_in->status == -EINPROGRESS) {
426 err("could not submit HD_READ_ATMESSAGE: URB busy"); 409 dev_err(cs->dev,
410 "could not submit HD_READ_ATMESSAGE: URB busy\n");
427 return -EBUSY; 411 return -EBUSY;
428 } 412 }
429 413
@@ -433,19 +417,19 @@ static int atread_submit(struct cardstate *cs, int timeout)
433 ucs->dr_cmd_in.wIndex = 0; 417 ucs->dr_cmd_in.wIndex = 0;
434 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size); 418 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size);
435 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev, 419 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev,
436 usb_rcvctrlpipe(ucs->udev, 0), 420 usb_rcvctrlpipe(ucs->udev, 0),
437 (unsigned char*) & ucs->dr_cmd_in, 421 (unsigned char*) & ucs->dr_cmd_in,
438 ucs->rcvbuf, ucs->rcvbuf_size, 422 ucs->rcvbuf, ucs->rcvbuf_size,
439 read_ctrl_callback, cs->inbuf); 423 read_ctrl_callback, cs->inbuf);
440 424
441 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) { 425 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) {
442 err("could not submit HD_READ_ATMESSAGE: %s", 426 dev_err(cs->dev, "could not submit HD_READ_ATMESSAGE: %s\n",
443 get_usb_statmsg(ret)); 427 get_usb_statmsg(ret));
444 return ret; 428 return ret;
445 } 429 }
446 430
447 if (timeout > 0) { 431 if (timeout > 0) {
448 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 432 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
449 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10; 433 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10;
450 ucs->timer_cmd_in.data = (unsigned long) cs; 434 ucs->timer_cmd_in.data = (unsigned long) cs;
451 ucs->timer_cmd_in.function = cmd_in_timeout; 435 ucs->timer_cmd_in.function = cmd_in_timeout;
@@ -483,25 +467,14 @@ inline static void update_basstate(struct bas_cardstate *ucs,
483 */ 467 */
484static void read_int_callback(struct urb *urb, struct pt_regs *regs) 468static void read_int_callback(struct urb *urb, struct pt_regs *regs)
485{ 469{
486 struct cardstate *cs; 470 struct cardstate *cs = urb->context;
487 struct bas_cardstate *ucs; 471 struct bas_cardstate *ucs = cs->hw.bas;
488 struct bc_state *bcs; 472 struct bc_state *bcs;
489 unsigned long flags; 473 unsigned long flags;
490 int status; 474 int status;
491 unsigned l; 475 unsigned l;
492 int channel; 476 int channel;
493 477
494 IFNULLRET(urb);
495 cs = (struct cardstate *) urb->context;
496 IFNULLRET(cs);
497 ucs = cs->hw.bas;
498 IFNULLRET(ucs);
499
500 if (unlikely(!atomic_read(&cs->connected))) {
501 warn("%s: disconnected", __func__);
502 return;
503 }
504
505 switch (urb->status) { 478 switch (urb->status) {
506 case 0: /* success */ 479 case 0: /* success */
507 break; 480 break;
@@ -509,11 +482,12 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
509 case -ECONNRESET: /* canceled (async) */ 482 case -ECONNRESET: /* canceled (async) */
510 case -EINPROGRESS: /* pending */ 483 case -EINPROGRESS: /* pending */
511 /* ignore silently */ 484 /* ignore silently */
512 dbg(DEBUG_USBREQ, 485 gig_dbg(DEBUG_USBREQ, "%s: %s",
513 "%s: %s", __func__, get_usb_statmsg(urb->status)); 486 __func__, get_usb_statmsg(urb->status));
514 return; 487 return;
515 default: /* severe trouble */ 488 default: /* severe trouble */
516 warn("interrupt read: %s", get_usb_statmsg(urb->status)); 489 dev_warn(cs->dev, "interrupt read: %s\n",
490 get_usb_statmsg(urb->status));
517 //FIXME corrective action? resubmission always ok? 491 //FIXME corrective action? resubmission always ok?
518 goto resubmit; 492 goto resubmit;
519 } 493 }
@@ -521,10 +495,9 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
521 l = (unsigned) ucs->int_in_buf[1] + 495 l = (unsigned) ucs->int_in_buf[1] +
522 (((unsigned) ucs->int_in_buf[2]) << 8); 496 (((unsigned) ucs->int_in_buf[2]) << 8);
523 497
524 dbg(DEBUG_USBREQ, 498 gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])",
525 "<-------%d: 0x%02x (%u [0x%02x 0x%02x])", urb->actual_length, 499 urb->actual_length, (int)ucs->int_in_buf[0], l,
526 (int)ucs->int_in_buf[0], l, 500 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
527 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
528 501
529 channel = 0; 502 channel = 0;
530 503
@@ -570,28 +543,30 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
570 case HD_B1_FLOW_CONTROL: 543 case HD_B1_FLOW_CONTROL:
571 bcs = cs->bcs + channel; 544 bcs = cs->bcs + channel;
572 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES, 545 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
573 &bcs->hw.bas->corrbytes); 546 &bcs->hw.bas->corrbytes);
574 dbg(DEBUG_ISO, 547 gig_dbg(DEBUG_ISO,
575 "Flow control (channel %d, sub %d): 0x%02x => %d", 548 "Flow control (channel %d, sub %d): 0x%02x => %d",
576 channel, bcs->hw.bas->numsub, l, 549 channel, bcs->hw.bas->numsub, l,
577 atomic_read(&bcs->hw.bas->corrbytes)); 550 atomic_read(&bcs->hw.bas->corrbytes));
578 break; 551 break;
579 552
580 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */ 553 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
581 if (!l) { 554 if (!l) {
582 warn("HD_RECEIVEATDATA_ACK with length 0 ignored"); 555 dev_warn(cs->dev,
556 "HD_RECEIVEATDATA_ACK with length 0 ignored\n");
583 break; 557 break;
584 } 558 }
585 spin_lock_irqsave(&cs->lock, flags); 559 spin_lock_irqsave(&cs->lock, flags);
586 if (ucs->rcvbuf_size) { 560 if (ucs->rcvbuf_size) {
587 spin_unlock_irqrestore(&cs->lock, flags); 561 spin_unlock_irqrestore(&cs->lock, flags);
588 err("receive AT data overrun, %d bytes lost", l); 562 dev_err(cs->dev,
563 "receive AT data overrun, %d bytes lost\n", l);
589 error_reset(cs); //FIXME reschedule 564 error_reset(cs); //FIXME reschedule
590 break; 565 break;
591 } 566 }
592 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) { 567 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
593 spin_unlock_irqrestore(&cs->lock, flags); 568 spin_unlock_irqrestore(&cs->lock, flags);
594 err("%s: out of memory, %d bytes lost", __func__, l); 569 dev_err(cs->dev, "out of memory, %d bytes lost\n", l);
595 error_reset(cs); //FIXME reschedule 570 error_reset(cs); //FIXME reschedule
596 break; 571 break;
597 } 572 }
@@ -607,25 +582,28 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
607 break; 582 break;
608 583
609 case HD_RESET_INTERRUPT_PIPE_ACK: 584 case HD_RESET_INTERRUPT_PIPE_ACK:
610 dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK"); 585 gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
611 break; 586 break;
612 587
613 case HD_SUSPEND_END: 588 case HD_SUSPEND_END:
614 dbg(DEBUG_USBREQ, "HD_SUSPEND_END"); 589 gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
615 break; 590 break;
616 591
617 default: 592 default:
618 warn("unknown Gigaset signal 0x%02x (%u) ignored", 593 dev_warn(cs->dev,
619 (int) ucs->int_in_buf[0], l); 594 "unknown Gigaset signal 0x%02x (%u) ignored\n",
595 (int) ucs->int_in_buf[0], l);
620 } 596 }
621 597
622 check_pending(ucs); 598 check_pending(ucs);
623 599
624resubmit: 600resubmit:
625 status = usb_submit_urb(urb, SLAB_ATOMIC); 601 spin_lock_irqsave(&cs->lock, flags);
602 status = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
603 spin_unlock_irqrestore(&cs->lock, flags);
626 if (unlikely(status)) { 604 if (unlikely(status)) {
627 err("could not resubmit interrupt URB: %s", 605 dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
628 get_usb_statmsg(status)); 606 get_usb_statmsg(status));
629 error_reset(cs); 607 error_reset(cs);
630 } 608 }
631} 609}
@@ -639,30 +617,22 @@ resubmit:
639 */ 617 */
640static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs) 618static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
641{ 619{
642 struct cardstate *cs; 620 struct inbuf_t *inbuf = urb->context;
643 struct bas_cardstate *ucs; 621 struct cardstate *cs = inbuf->cs;
622 struct bas_cardstate *ucs = cs->hw.bas;
623 int have_data = 0;
644 unsigned numbytes; 624 unsigned numbytes;
645 unsigned long flags; 625 unsigned long flags;
646 struct inbuf_t *inbuf;
647 int have_data = 0;
648
649 IFNULLRET(urb);
650 inbuf = (struct inbuf_t *) urb->context;
651 IFNULLRET(inbuf);
652 cs = inbuf->cs;
653 IFNULLRET(cs);
654 ucs = cs->hw.bas;
655 IFNULLRET(ucs);
656 626
657 spin_lock_irqsave(&cs->lock, flags); 627 spin_lock_irqsave(&cs->lock, flags);
658 if (!atomic_read(&cs->connected)) { 628 if (unlikely(!cs->connected)) {
659 warn("%s: disconnected", __func__); 629 warn("%s: disconnected", __func__);
660 spin_unlock_irqrestore(&cs->lock, flags); 630 spin_unlock_irqrestore(&cs->lock, flags);
661 return; 631 return;
662 } 632 }
663 633
664 if (!ucs->rcvbuf_size) { 634 if (!ucs->rcvbuf_size) {
665 warn("%s: no receive in progress", __func__); 635 dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
666 spin_unlock_irqrestore(&cs->lock, flags); 636 spin_unlock_irqrestore(&cs->lock, flags);
667 return; 637 return;
668 } 638 }
@@ -673,12 +643,14 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
673 case 0: /* normal completion */ 643 case 0: /* normal completion */
674 numbytes = urb->actual_length; 644 numbytes = urb->actual_length;
675 if (unlikely(numbytes == 0)) { 645 if (unlikely(numbytes == 0)) {
676 warn("control read: empty block received"); 646 dev_warn(cs->dev,
647 "control read: empty block received\n");
677 goto retry; 648 goto retry;
678 } 649 }
679 if (unlikely(numbytes != ucs->rcvbuf_size)) { 650 if (unlikely(numbytes != ucs->rcvbuf_size)) {
680 warn("control read: received %d chars, expected %d", 651 dev_warn(cs->dev,
681 numbytes, ucs->rcvbuf_size); 652 "control read: received %d chars, expected %d\n",
653 numbytes, ucs->rcvbuf_size);
682 if (numbytes > ucs->rcvbuf_size) 654 if (numbytes > ucs->rcvbuf_size)
683 numbytes = ucs->rcvbuf_size; 655 numbytes = ucs->rcvbuf_size;
684 } 656 }
@@ -698,23 +670,26 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
698 case -ECONNRESET: /* canceled (async) */ 670 case -ECONNRESET: /* canceled (async) */
699 case -EINPROGRESS: /* pending */ 671 case -EINPROGRESS: /* pending */
700 /* no action necessary */ 672 /* no action necessary */
701 dbg(DEBUG_USBREQ, 673 gig_dbg(DEBUG_USBREQ, "%s: %s",
702 "%s: %s", __func__, get_usb_statmsg(urb->status)); 674 __func__, get_usb_statmsg(urb->status));
703 break; 675 break;
704 676
705 default: /* severe trouble */ 677 default: /* severe trouble */
706 warn("control read: %s", get_usb_statmsg(urb->status)); 678 dev_warn(cs->dev, "control read: %s\n",
679 get_usb_statmsg(urb->status));
707 retry: 680 retry:
708 if (ucs->retry_cmd_in++ < BAS_RETRY) { 681 if (ucs->retry_cmd_in++ < BAS_RETRY) {
709 notice("control read: retry %d", ucs->retry_cmd_in); 682 dev_notice(cs->dev, "control read: retry %d\n",
683 ucs->retry_cmd_in);
710 if (atread_submit(cs, BAS_TIMEOUT) >= 0) { 684 if (atread_submit(cs, BAS_TIMEOUT) >= 0) {
711 /* resubmitted - bypass regular exit block */ 685 /* resubmitted - bypass regular exit block */
712 spin_unlock_irqrestore(&cs->lock, flags); 686 spin_unlock_irqrestore(&cs->lock, flags);
713 return; 687 return;
714 } 688 }
715 } else { 689 } else {
716 err("control read: giving up after %d tries", 690 dev_err(cs->dev,
717 ucs->retry_cmd_in); 691 "control read: giving up after %d tries\n",
692 ucs->retry_cmd_in);
718 } 693 }
719 error_reset(cs); 694 error_reset(cs);
720 } 695 }
@@ -724,7 +699,7 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
724 ucs->rcvbuf_size = 0; 699 ucs->rcvbuf_size = 0;
725 spin_unlock_irqrestore(&cs->lock, flags); 700 spin_unlock_irqrestore(&cs->lock, flags);
726 if (have_data) { 701 if (have_data) {
727 dbg(DEBUG_INTR, "%s-->BH", __func__); 702 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
728 gigaset_schedule_event(cs); 703 gigaset_schedule_event(cs);
729 } 704 }
730} 705}
@@ -743,21 +718,16 @@ static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
743 unsigned long flags; 718 unsigned long flags;
744 int i, rc; 719 int i, rc;
745 720
746 IFNULLRET(urb);
747 IFNULLRET(urb->context);
748 IFNULLRET(cardstate);
749
750 /* status codes not worth bothering the tasklet with */ 721 /* status codes not worth bothering the tasklet with */
751 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 722 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
752 urb->status == -EINPROGRESS)) { 723 urb->status == -EINPROGRESS)) {
753 dbg(DEBUG_ISO, 724 gig_dbg(DEBUG_ISO, "%s: %s",
754 "%s: %s", __func__, get_usb_statmsg(urb->status)); 725 __func__, get_usb_statmsg(urb->status));
755 return; 726 return;
756 } 727 }
757 728
758 bcs = (struct bc_state *) urb->context; 729 bcs = urb->context;
759 ubc = bcs->hw.bas; 730 ubc = bcs->hw.bas;
760 IFNULLRET(ubc);
761 731
762 spin_lock_irqsave(&ubc->isoinlock, flags); 732 spin_lock_irqsave(&ubc->isoinlock, flags);
763 if (likely(ubc->isoindone == NULL)) { 733 if (likely(ubc->isoindone == NULL)) {
@@ -777,14 +747,17 @@ static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
777 urb->iso_frame_desc[i].actual_length = 0; 747 urb->iso_frame_desc[i].actual_length = 0;
778 } 748 }
779 if (likely(atomic_read(&ubc->running))) { 749 if (likely(atomic_read(&ubc->running))) {
780 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */ 750 /* urb->dev is clobbered by USB subsystem */
751 urb->dev = bcs->cs->hw.bas->udev;
781 urb->transfer_flags = URB_ISO_ASAP; 752 urb->transfer_flags = URB_ISO_ASAP;
782 urb->number_of_packets = BAS_NUMFRAMES; 753 urb->number_of_packets = BAS_NUMFRAMES;
783 dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit", __func__); 754 gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
755 __func__);
784 rc = usb_submit_urb(urb, SLAB_ATOMIC); 756 rc = usb_submit_urb(urb, SLAB_ATOMIC);
785 if (unlikely(rc != 0)) { 757 if (unlikely(rc != 0)) {
786 err("could not resubmit isochronous read URB: %s", 758 dev_err(bcs->cs->dev,
787 get_usb_statmsg(rc)); 759 "could not resubmit isochronous read "
760 "URB: %s\n", get_usb_statmsg(rc));
788 dump_urb(DEBUG_ISO, "isoc read", urb); 761 dump_urb(DEBUG_ISO, "isoc read", urb);
789 error_hangup(bcs); 762 error_hangup(bcs);
790 } 763 }
@@ -806,23 +779,17 @@ static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
806 struct bas_bc_state *ubc; 779 struct bas_bc_state *ubc;
807 unsigned long flags; 780 unsigned long flags;
808 781
809 IFNULLRET(urb);
810 IFNULLRET(urb->context);
811 IFNULLRET(cardstate);
812
813 /* status codes not worth bothering the tasklet with */ 782 /* status codes not worth bothering the tasklet with */
814 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 783 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
815 urb->status == -EINPROGRESS)) { 784 urb->status == -EINPROGRESS)) {
816 dbg(DEBUG_ISO, 785 gig_dbg(DEBUG_ISO, "%s: %s",
817 "%s: %s", __func__, get_usb_statmsg(urb->status)); 786 __func__, get_usb_statmsg(urb->status));
818 return; 787 return;
819 } 788 }
820 789
821 /* pass URB context to tasklet */ 790 /* pass URB context to tasklet */
822 ucx = (struct isow_urbctx_t *) urb->context; 791 ucx = urb->context;
823 IFNULLRET(ucx->bcs);
824 ubc = ucx->bcs->hw.bas; 792 ubc = ucx->bcs->hw.bas;
825 IFNULLRET(ubc);
826 793
827 spin_lock_irqsave(&ubc->isooutlock, flags); 794 spin_lock_irqsave(&ubc->isooutlock, flags);
828 ubc->isooutovfl = ubc->isooutdone; 795 ubc->isooutovfl = ubc->isooutdone;
@@ -841,15 +808,11 @@ static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
841 */ 808 */
842static int starturbs(struct bc_state *bcs) 809static int starturbs(struct bc_state *bcs)
843{ 810{
811 struct bas_bc_state *ubc = bcs->hw.bas;
844 struct urb *urb; 812 struct urb *urb;
845 struct bas_bc_state *ubc;
846 int j, k; 813 int j, k;
847 int rc; 814 int rc;
848 815
849 IFNULLRETVAL(bcs, -EFAULT);
850 ubc = bcs->hw.bas;
851 IFNULLRETVAL(ubc, -EFAULT);
852
853 /* initialize L2 reception */ 816 /* initialize L2 reception */
854 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 817 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
855 bcs->inputstate |= INS_flag_hunt; 818 bcs->inputstate |= INS_flag_hunt;
@@ -859,7 +822,7 @@ static int starturbs(struct bc_state *bcs)
859 for (k = 0; k < BAS_INURBS; k++) { 822 for (k = 0; k < BAS_INURBS; k++) {
860 urb = ubc->isoinurbs[k]; 823 urb = ubc->isoinurbs[k];
861 if (!urb) { 824 if (!urb) {
862 err("isoinurbs[%d]==NULL", k); 825 dev_err(bcs->cs->dev, "isoinurbs[%d]==NULL\n", k);
863 rc = -EFAULT; 826 rc = -EFAULT;
864 goto error; 827 goto error;
865 } 828 }
@@ -882,8 +845,9 @@ static int starturbs(struct bc_state *bcs)
882 845
883 dump_urb(DEBUG_ISO, "Initial isoc read", urb); 846 dump_urb(DEBUG_ISO, "Initial isoc read", urb);
884 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 847 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
885 err("could not submit isochronous read URB %d: %s", 848 dev_err(bcs->cs->dev,
886 k, get_usb_statmsg(rc)); 849 "could not submit isochronous read URB %d: %s\n",
850 k, get_usb_statmsg(rc));
887 goto error; 851 goto error;
888 } 852 }
889 } 853 }
@@ -895,7 +859,7 @@ static int starturbs(struct bc_state *bcs)
895 for (k = 0; k < BAS_OUTURBS; ++k) { 859 for (k = 0; k < BAS_OUTURBS; ++k) {
896 urb = ubc->isoouturbs[k].urb; 860 urb = ubc->isoouturbs[k].urb;
897 if (!urb) { 861 if (!urb) {
898 err("isoouturbs[%d].urb==NULL", k); 862 dev_err(bcs->cs->dev, "isoouturbs[%d].urb==NULL\n", k);
899 rc = -EFAULT; 863 rc = -EFAULT;
900 goto error; 864 goto error;
901 } 865 }
@@ -922,8 +886,9 @@ static int starturbs(struct bc_state *bcs)
922 dump_urb(DEBUG_ISO, "Initial isoc write", urb); 886 dump_urb(DEBUG_ISO, "Initial isoc write", urb);
923 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC); 887 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC);
924 if (rc != 0) { 888 if (rc != 0) {
925 err("could not submit isochronous write URB %d: %s", 889 dev_err(bcs->cs->dev,
926 k, get_usb_statmsg(rc)); 890 "could not submit isochronous write URB %d: %s\n",
891 k, get_usb_statmsg(rc));
927 goto error; 892 goto error;
928 } 893 }
929 } 894 }
@@ -946,20 +911,20 @@ static void stopurbs(struct bas_bc_state *ubc)
946{ 911{
947 int k, rc; 912 int k, rc;
948 913
949 IFNULLRET(ubc);
950
951 atomic_set(&ubc->running, 0); 914 atomic_set(&ubc->running, 0);
952 915
953 for (k = 0; k < BAS_INURBS; ++k) { 916 for (k = 0; k < BAS_INURBS; ++k) {
954 rc = usb_unlink_urb(ubc->isoinurbs[k]); 917 rc = usb_unlink_urb(ubc->isoinurbs[k]);
955 dbg(DEBUG_ISO, "%s: isoc input URB %d unlinked, result = %d", 918 gig_dbg(DEBUG_ISO,
956 __func__, k, rc); 919 "%s: isoc input URB %d unlinked, result = %d",
920 __func__, k, rc);
957 } 921 }
958 922
959 for (k = 0; k < BAS_OUTURBS; ++k) { 923 for (k = 0; k < BAS_OUTURBS; ++k) {
960 rc = usb_unlink_urb(ubc->isoouturbs[k].urb); 924 rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
961 dbg(DEBUG_ISO, "%s: isoc output URB %d unlinked, result = %d", 925 gig_dbg(DEBUG_ISO,
962 __func__, k, rc); 926 "%s: isoc output URB %d unlinked, result = %d",
927 __func__, k, rc);
963 } 928 }
964} 929}
965 930
@@ -977,19 +942,14 @@ static void stopurbs(struct bas_bc_state *ubc)
977 */ 942 */
978static int submit_iso_write_urb(struct isow_urbctx_t *ucx) 943static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
979{ 944{
980 struct urb *urb; 945 struct urb *urb = ucx->urb;
981 struct bas_bc_state *ubc; 946 struct bas_bc_state *ubc = ucx->bcs->hw.bas;
982 struct usb_iso_packet_descriptor *ifd; 947 struct usb_iso_packet_descriptor *ifd;
983 int corrbytes, nframe, rc; 948 int corrbytes, nframe, rc;
949 unsigned long flags;
984 950
985 IFNULLRETVAL(ucx, -EFAULT); 951 /* urb->dev is clobbered by USB subsystem */
986 urb = ucx->urb; 952 urb->dev = ucx->bcs->cs->hw.bas->udev;
987 IFNULLRETVAL(urb, -EFAULT);
988 IFNULLRETVAL(ucx->bcs, -EFAULT);
989 ubc = ucx->bcs->hw.bas;
990 IFNULLRETVAL(ubc, -EFAULT);
991
992 urb->dev = ucx->bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */
993 urb->transfer_flags = URB_ISO_ASAP; 953 urb->transfer_flags = URB_ISO_ASAP;
994 urb->transfer_buffer = ubc->isooutbuf->data; 954 urb->transfer_buffer = ubc->isooutbuf->data;
995 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data); 955 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
@@ -1000,7 +960,8 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1000 /* compute frame length according to flow control */ 960 /* compute frame length according to flow control */
1001 ifd->length = BAS_NORMFRAME; 961 ifd->length = BAS_NORMFRAME;
1002 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) { 962 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
1003 dbg(DEBUG_ISO, "%s: corrbytes=%d", __func__, corrbytes); 963 gig_dbg(DEBUG_ISO, "%s: corrbytes=%d",
964 __func__, corrbytes);
1004 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME) 965 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
1005 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME; 966 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
1006 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME) 967 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
@@ -1008,18 +969,21 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1008 ifd->length += corrbytes; 969 ifd->length += corrbytes;
1009 atomic_add(-corrbytes, &ubc->corrbytes); 970 atomic_add(-corrbytes, &ubc->corrbytes);
1010 } 971 }
1011 //dbg(DEBUG_ISO, "%s: frame %d length=%d", __func__, nframe, ifd->length);
1012 972
1013 /* retrieve block of data to send */ 973 /* retrieve block of data to send */
1014 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf, ifd->length); 974 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf,
975 ifd->length);
1015 if (ifd->offset < 0) { 976 if (ifd->offset < 0) {
1016 if (ifd->offset == -EBUSY) { 977 if (ifd->offset == -EBUSY) {
1017 dbg(DEBUG_ISO, "%s: buffer busy at frame %d", 978 gig_dbg(DEBUG_ISO,
1018 __func__, nframe); 979 "%s: buffer busy at frame %d",
1019 /* tasklet will be restarted from gigaset_send_skb() */ 980 __func__, nframe);
981 /* tasklet will be restarted from
982 gigaset_send_skb() */
1020 } else { 983 } else {
1021 err("%s: buffer error %d at frame %d", 984 dev_err(ucx->bcs->cs->dev,
1022 __func__, ifd->offset, nframe); 985 "%s: buffer error %d at frame %d\n",
986 __func__, ifd->offset, nframe);
1023 return ifd->offset; 987 return ifd->offset;
1024 } 988 }
1025 break; 989 break;
@@ -1029,9 +993,14 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1029 ifd->actual_length = 0; 993 ifd->actual_length = 0;
1030 } 994 }
1031 if ((urb->number_of_packets = nframe) > 0) { 995 if ((urb->number_of_packets = nframe) > 0) {
1032 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 996 spin_lock_irqsave(&ucx->bcs->cs->lock, flags);
1033 err("could not submit isochronous write URB: %s", 997 rc = ucx->bcs->cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
1034 get_usb_statmsg(rc)); 998 spin_unlock_irqrestore(&ucx->bcs->cs->lock, flags);
999
1000 if (rc) {
1001 dev_err(ucx->bcs->cs->dev,
1002 "could not submit isochronous write URB: %s\n",
1003 get_usb_statmsg(rc));
1035 dump_urb(DEBUG_ISO, "isoc write", urb); 1004 dump_urb(DEBUG_ISO, "isoc write", urb);
1036 return rc; 1005 return rc;
1037 } 1006 }
@@ -1048,9 +1017,9 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1048 */ 1017 */
1049static void write_iso_tasklet(unsigned long data) 1018static void write_iso_tasklet(unsigned long data)
1050{ 1019{
1051 struct bc_state *bcs; 1020 struct bc_state *bcs = (struct bc_state *) data;
1052 struct bas_bc_state *ubc; 1021 struct bas_bc_state *ubc = bcs->hw.bas;
1053 struct cardstate *cs; 1022 struct cardstate *cs = bcs->cs;
1054 struct isow_urbctx_t *done, *next, *ovfl; 1023 struct isow_urbctx_t *done, *next, *ovfl;
1055 struct urb *urb; 1024 struct urb *urb;
1056 struct usb_iso_packet_descriptor *ifd; 1025 struct usb_iso_packet_descriptor *ifd;
@@ -1060,22 +1029,10 @@ static void write_iso_tasklet(unsigned long data)
1060 struct sk_buff *skb; 1029 struct sk_buff *skb;
1061 int len; 1030 int len;
1062 1031
1063 bcs = (struct bc_state *) data;
1064 IFNULLRET(bcs);
1065 ubc = bcs->hw.bas;
1066 IFNULLRET(ubc);
1067 cs = bcs->cs;
1068 IFNULLRET(cs);
1069
1070 /* loop while completed URBs arrive in time */ 1032 /* loop while completed URBs arrive in time */
1071 for (;;) { 1033 for (;;) {
1072 if (unlikely(!atomic_read(&cs->connected))) {
1073 warn("%s: disconnected", __func__);
1074 return;
1075 }
1076
1077 if (unlikely(!(atomic_read(&ubc->running)))) { 1034 if (unlikely(!(atomic_read(&ubc->running)))) {
1078 dbg(DEBUG_ISO, "%s: not running", __func__); 1035 gig_dbg(DEBUG_ISO, "%s: not running", __func__);
1079 return; 1036 return;
1080 } 1037 }
1081 1038
@@ -1087,7 +1044,7 @@ static void write_iso_tasklet(unsigned long data)
1087 ubc->isooutovfl = NULL; 1044 ubc->isooutovfl = NULL;
1088 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1045 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1089 if (ovfl) { 1046 if (ovfl) {
1090 err("isochronous write buffer underrun - buy a faster machine :-)"); 1047 dev_err(cs->dev, "isochronous write buffer underrun\n");
1091 error_hangup(bcs); 1048 error_hangup(bcs);
1092 break; 1049 break;
1093 } 1050 }
@@ -1110,7 +1067,8 @@ static void write_iso_tasklet(unsigned long data)
1110 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1067 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1111 if (next) { 1068 if (next) {
1112 /* couldn't put it back */ 1069 /* couldn't put it back */
1113 err("losing isochronous write URB"); 1070 dev_err(cs->dev,
1071 "losing isochronous write URB\n");
1114 error_hangup(bcs); 1072 error_hangup(bcs);
1115 } 1073 }
1116 } 1074 }
@@ -1123,22 +1081,25 @@ static void write_iso_tasklet(unsigned long data)
1123 break; 1081 break;
1124 case -EXDEV: /* inspect individual frames */ 1082 case -EXDEV: /* inspect individual frames */
1125 /* assumptions (for lack of documentation): 1083 /* assumptions (for lack of documentation):
1126 * - actual_length bytes of the frame in error are successfully sent 1084 * - actual_length bytes of the frame in error are
1085 * successfully sent
1127 * - all following frames are not sent at all 1086 * - all following frames are not sent at all
1128 */ 1087 */
1129 dbg(DEBUG_ISO, "%s: URB partially completed", __func__); 1088 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1089 __func__);
1130 offset = done->limit; /* just in case */ 1090 offset = done->limit; /* just in case */
1131 for (i = 0; i < BAS_NUMFRAMES; i++) { 1091 for (i = 0; i < BAS_NUMFRAMES; i++) {
1132 ifd = &urb->iso_frame_desc[i]; 1092 ifd = &urb->iso_frame_desc[i];
1133 if (ifd->status || 1093 if (ifd->status ||
1134 ifd->actual_length != ifd->length) { 1094 ifd->actual_length != ifd->length) {
1135 warn("isochronous write: frame %d: %s, " 1095 dev_warn(cs->dev,
1136 "only %d of %d bytes sent", 1096 "isochronous write: frame %d: %s, "
1097 "only %d of %d bytes sent\n",
1137 i, get_usb_statmsg(ifd->status), 1098 i, get_usb_statmsg(ifd->status),
1138 ifd->actual_length, ifd->length); 1099 ifd->actual_length, ifd->length);
1139 offset = (ifd->offset + 1100 offset = (ifd->offset +
1140 ifd->actual_length) 1101 ifd->actual_length)
1141 % BAS_OUTBUFSIZE; 1102 % BAS_OUTBUFSIZE;
1142 break; 1103 break;
1143 } 1104 }
1144 } 1105 }
@@ -1148,25 +1109,26 @@ static void write_iso_tasklet(unsigned long data)
1148 ifd = &urb->iso_frame_desc[i]; 1109 ifd = &urb->iso_frame_desc[i];
1149 if (ifd->status != -EINPROGRESS 1110 if (ifd->status != -EINPROGRESS
1150 || ifd->actual_length != 0) { 1111 || ifd->actual_length != 0) {
1151 warn("isochronous write: frame %d: %s, " 1112 dev_warn(cs->dev,
1152 "%d of %d bytes sent", 1113 "isochronous write: frame %d: %s, "
1114 "%d of %d bytes sent\n",
1153 i, get_usb_statmsg(ifd->status), 1115 i, get_usb_statmsg(ifd->status),
1154 ifd->actual_length, ifd->length); 1116 ifd->actual_length, ifd->length);
1155 offset = (ifd->offset + 1117 offset = (ifd->offset +
1156 ifd->actual_length) 1118 ifd->actual_length)
1157 % BAS_OUTBUFSIZE; 1119 % BAS_OUTBUFSIZE;
1158 break; 1120 break;
1159 } 1121 }
1160 } 1122 }
1161#endif 1123#endif
1162 break; 1124 break;
1163 case -EPIPE: //FIXME is this the code for "underrun"? 1125 case -EPIPE: //FIXME is this the code for "underrun"?
1164 err("isochronous write stalled"); 1126 dev_err(cs->dev, "isochronous write stalled\n");
1165 error_hangup(bcs); 1127 error_hangup(bcs);
1166 break; 1128 break;
1167 default: /* severe trouble */ 1129 default: /* severe trouble */
1168 warn("isochronous write: %s", 1130 dev_warn(cs->dev, "isochronous write: %s\n",
1169 get_usb_statmsg(urb->status)); 1131 get_usb_statmsg(urb->status));
1170 } 1132 }
1171 1133
1172 /* mark the write buffer area covered by this URB as free */ 1134 /* mark the write buffer area covered by this URB as free */
@@ -1194,8 +1156,8 @@ static void write_iso_tasklet(unsigned long data)
1194 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) { 1156 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
1195 /* insufficient buffer space, push back onto queue */ 1157 /* insufficient buffer space, push back onto queue */
1196 skb_queue_head(&bcs->squeue, skb); 1158 skb_queue_head(&bcs->squeue, skb);
1197 dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d", 1159 gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
1198 __func__, skb_queue_len(&bcs->squeue)); 1160 __func__, skb_queue_len(&bcs->squeue));
1199 break; 1161 break;
1200 } 1162 }
1201 skb_pull(skb, len); 1163 skb_pull(skb, len);
@@ -1215,28 +1177,16 @@ static void write_iso_tasklet(unsigned long data)
1215 */ 1177 */
1216static void read_iso_tasklet(unsigned long data) 1178static void read_iso_tasklet(unsigned long data)
1217{ 1179{
1218 struct bc_state *bcs; 1180 struct bc_state *bcs = (struct bc_state *) data;
1219 struct bas_bc_state *ubc; 1181 struct bas_bc_state *ubc = bcs->hw.bas;
1220 struct cardstate *cs; 1182 struct cardstate *cs = bcs->cs;
1221 struct urb *urb; 1183 struct urb *urb;
1222 char *rcvbuf; 1184 char *rcvbuf;
1223 unsigned long flags; 1185 unsigned long flags;
1224 int totleft, numbytes, offset, frame, rc; 1186 int totleft, numbytes, offset, frame, rc;
1225 1187
1226 bcs = (struct bc_state *) data;
1227 IFNULLRET(bcs);
1228 ubc = bcs->hw.bas;
1229 IFNULLRET(ubc);
1230 cs = bcs->cs;
1231 IFNULLRET(cs);
1232
1233 /* loop while more completed URBs arrive in the meantime */ 1188 /* loop while more completed URBs arrive in the meantime */
1234 for (;;) { 1189 for (;;) {
1235 if (!atomic_read(&cs->connected)) {
1236 warn("%s: disconnected", __func__);
1237 return;
1238 }
1239
1240 /* retrieve URB */ 1190 /* retrieve URB */
1241 spin_lock_irqsave(&ubc->isoinlock, flags); 1191 spin_lock_irqsave(&ubc->isoinlock, flags);
1242 if (!(urb = ubc->isoindone)) { 1192 if (!(urb = ubc->isoindone)) {
@@ -1245,38 +1195,45 @@ static void read_iso_tasklet(unsigned long data)
1245 } 1195 }
1246 ubc->isoindone = NULL; 1196 ubc->isoindone = NULL;
1247 if (unlikely(ubc->loststatus != -EINPROGRESS)) { 1197 if (unlikely(ubc->loststatus != -EINPROGRESS)) {
1248 warn("isochronous read overrun, dropped URB with status: %s, %d bytes lost", 1198 dev_warn(cs->dev,
1249 get_usb_statmsg(ubc->loststatus), ubc->isoinlost); 1199 "isochronous read overrun, "
1200 "dropped URB with status: %s, %d bytes lost\n",
1201 get_usb_statmsg(ubc->loststatus),
1202 ubc->isoinlost);
1250 ubc->loststatus = -EINPROGRESS; 1203 ubc->loststatus = -EINPROGRESS;
1251 } 1204 }
1252 spin_unlock_irqrestore(&ubc->isoinlock, flags); 1205 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1253 1206
1254 if (unlikely(!(atomic_read(&ubc->running)))) { 1207 if (unlikely(!(atomic_read(&ubc->running)))) {
1255 dbg(DEBUG_ISO, "%s: channel not running, dropped URB with status: %s", 1208 gig_dbg(DEBUG_ISO,
1256 __func__, get_usb_statmsg(urb->status)); 1209 "%s: channel not running, "
1210 "dropped URB with status: %s",
1211 __func__, get_usb_statmsg(urb->status));
1257 return; 1212 return;
1258 } 1213 }
1259 1214
1260 switch (urb->status) { 1215 switch (urb->status) {
1261 case 0: /* normal completion */ 1216 case 0: /* normal completion */
1262 break; 1217 break;
1263 case -EXDEV: /* inspect individual frames (we do that anyway) */ 1218 case -EXDEV: /* inspect individual frames
1264 dbg(DEBUG_ISO, "%s: URB partially completed", __func__); 1219 (we do that anyway) */
1220 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1221 __func__);
1265 break; 1222 break;
1266 case -ENOENT: 1223 case -ENOENT:
1267 case -ECONNRESET: 1224 case -ECONNRESET:
1268 dbg(DEBUG_ISO, "%s: URB canceled", __func__); 1225 gig_dbg(DEBUG_ISO, "%s: URB canceled", __func__);
1269 continue; /* -> skip */ 1226 continue; /* -> skip */
1270 case -EINPROGRESS: /* huh? */ 1227 case -EINPROGRESS: /* huh? */
1271 dbg(DEBUG_ISO, "%s: URB still pending", __func__); 1228 gig_dbg(DEBUG_ISO, "%s: URB still pending", __func__);
1272 continue; /* -> skip */ 1229 continue; /* -> skip */
1273 case -EPIPE: 1230 case -EPIPE:
1274 err("isochronous read stalled"); 1231 dev_err(cs->dev, "isochronous read stalled\n");
1275 error_hangup(bcs); 1232 error_hangup(bcs);
1276 continue; /* -> skip */ 1233 continue; /* -> skip */
1277 default: /* severe trouble */ 1234 default: /* severe trouble */
1278 warn("isochronous read: %s", 1235 dev_warn(cs->dev, "isochronous read: %s\n",
1279 get_usb_statmsg(urb->status)); 1236 get_usb_statmsg(urb->status));
1280 goto error; 1237 goto error;
1281 } 1238 }
1282 1239
@@ -1284,33 +1241,44 @@ static void read_iso_tasklet(unsigned long data)
1284 totleft = urb->actual_length; 1241 totleft = urb->actual_length;
1285 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) { 1242 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1286 if (unlikely(urb->iso_frame_desc[frame].status)) { 1243 if (unlikely(urb->iso_frame_desc[frame].status)) {
1287 warn("isochronous read: frame %d: %s", 1244 dev_warn(cs->dev,
1288 frame, get_usb_statmsg(urb->iso_frame_desc[frame].status)); 1245 "isochronous read: frame %d: %s\n",
1246 frame,
1247 get_usb_statmsg(
1248 urb->iso_frame_desc[frame].status));
1289 break; 1249 break;
1290 } 1250 }
1291 numbytes = urb->iso_frame_desc[frame].actual_length; 1251 numbytes = urb->iso_frame_desc[frame].actual_length;
1292 if (unlikely(numbytes > BAS_MAXFRAME)) { 1252 if (unlikely(numbytes > BAS_MAXFRAME)) {
1293 warn("isochronous read: frame %d: numbytes (%d) > BAS_MAXFRAME", 1253 dev_warn(cs->dev,
1294 frame, numbytes); 1254 "isochronous read: frame %d: "
1255 "numbytes (%d) > BAS_MAXFRAME\n",
1256 frame, numbytes);
1295 break; 1257 break;
1296 } 1258 }
1297 if (unlikely(numbytes > totleft)) { 1259 if (unlikely(numbytes > totleft)) {
1298 warn("isochronous read: frame %d: numbytes (%d) > totleft (%d)", 1260 dev_warn(cs->dev,
1299 frame, numbytes, totleft); 1261 "isochronous read: frame %d: "
1262 "numbytes (%d) > totleft (%d)\n",
1263 frame, numbytes, totleft);
1300 break; 1264 break;
1301 } 1265 }
1302 offset = urb->iso_frame_desc[frame].offset; 1266 offset = urb->iso_frame_desc[frame].offset;
1303 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) { 1267 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
1304 warn("isochronous read: frame %d: offset (%d) + numbytes (%d) > BAS_INBUFSIZE", 1268 dev_warn(cs->dev,
1305 frame, offset, numbytes); 1269 "isochronous read: frame %d: "
1270 "offset (%d) + numbytes (%d) "
1271 "> BAS_INBUFSIZE\n",
1272 frame, offset, numbytes);
1306 break; 1273 break;
1307 } 1274 }
1308 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs); 1275 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1309 totleft -= numbytes; 1276 totleft -= numbytes;
1310 } 1277 }
1311 if (unlikely(totleft > 0)) 1278 if (unlikely(totleft > 0))
1312 warn("isochronous read: %d data bytes missing", 1279 dev_warn(cs->dev,
1313 totleft); 1280 "isochronous read: %d data bytes missing\n",
1281 totleft);
1314 1282
1315 error: 1283 error:
1316 /* URB processed, resubmit */ 1284 /* URB processed, resubmit */
@@ -1318,12 +1286,17 @@ static void read_iso_tasklet(unsigned long data)
1318 urb->iso_frame_desc[frame].status = 0; 1286 urb->iso_frame_desc[frame].status = 0;
1319 urb->iso_frame_desc[frame].actual_length = 0; 1287 urb->iso_frame_desc[frame].actual_length = 0;
1320 } 1288 }
1321 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */ 1289 /* urb->dev is clobbered by USB subsystem */
1290 urb->dev = bcs->cs->hw.bas->udev;
1322 urb->transfer_flags = URB_ISO_ASAP; 1291 urb->transfer_flags = URB_ISO_ASAP;
1323 urb->number_of_packets = BAS_NUMFRAMES; 1292 urb->number_of_packets = BAS_NUMFRAMES;
1324 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 1293 spin_lock_irqsave(&cs->lock, flags);
1325 err("could not resubmit isochronous read URB: %s", 1294 rc = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
1326 get_usb_statmsg(rc)); 1295 spin_unlock_irqrestore(&cs->lock, flags);
1296 if (rc) {
1297 dev_err(cs->dev,
1298 "could not resubmit isochronous read URB: %s\n",
1299 get_usb_statmsg(rc));
1327 dump_urb(DEBUG_ISO, "resubmit iso read", urb); 1300 dump_urb(DEBUG_ISO, "resubmit iso read", urb);
1328 error_hangup(bcs); 1301 error_hangup(bcs);
1329 } 1302 }
@@ -1341,15 +1314,10 @@ static void read_iso_tasklet(unsigned long data)
1341static void req_timeout(unsigned long data) 1314static void req_timeout(unsigned long data)
1342{ 1315{
1343 struct bc_state *bcs = (struct bc_state *) data; 1316 struct bc_state *bcs = (struct bc_state *) data;
1344 struct bas_cardstate *ucs; 1317 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1345 int pending; 1318 int pending;
1346 unsigned long flags; 1319 unsigned long flags;
1347 1320
1348 IFNULLRET(bcs);
1349 IFNULLRET(bcs->cs);
1350 ucs = bcs->cs->hw.bas;
1351 IFNULLRET(ucs);
1352
1353 check_pending(ucs); 1321 check_pending(ucs);
1354 1322
1355 spin_lock_irqsave(&ucs->lock, flags); 1323 spin_lock_irqsave(&ucs->lock, flags);
@@ -1359,33 +1327,34 @@ static void req_timeout(unsigned long data)
1359 1327
1360 switch (pending) { 1328 switch (pending) {
1361 case 0: /* no pending request */ 1329 case 0: /* no pending request */
1362 dbg(DEBUG_USBREQ, "%s: no request pending", __func__); 1330 gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
1363 break; 1331 break;
1364 1332
1365 case HD_OPEN_ATCHANNEL: 1333 case HD_OPEN_ATCHANNEL:
1366 err("timeout opening AT channel"); 1334 dev_err(bcs->cs->dev, "timeout opening AT channel\n");
1367 error_reset(bcs->cs); 1335 error_reset(bcs->cs);
1368 break; 1336 break;
1369 1337
1370 case HD_OPEN_B2CHANNEL: 1338 case HD_OPEN_B2CHANNEL:
1371 case HD_OPEN_B1CHANNEL: 1339 case HD_OPEN_B1CHANNEL:
1372 err("timeout opening channel %d", bcs->channel + 1); 1340 dev_err(bcs->cs->dev, "timeout opening channel %d\n",
1341 bcs->channel + 1);
1373 error_hangup(bcs); 1342 error_hangup(bcs);
1374 break; 1343 break;
1375 1344
1376 case HD_CLOSE_ATCHANNEL: 1345 case HD_CLOSE_ATCHANNEL:
1377 err("timeout closing AT channel"); 1346 dev_err(bcs->cs->dev, "timeout closing AT channel\n");
1378 //wake_up_interruptible(cs->initwait);
1379 //FIXME need own wait queue?
1380 break; 1347 break;
1381 1348
1382 case HD_CLOSE_B2CHANNEL: 1349 case HD_CLOSE_B2CHANNEL:
1383 case HD_CLOSE_B1CHANNEL: 1350 case HD_CLOSE_B1CHANNEL:
1384 err("timeout closing channel %d", bcs->channel + 1); 1351 dev_err(bcs->cs->dev, "timeout closing channel %d\n",
1352 bcs->channel + 1);
1385 break; 1353 break;
1386 1354
1387 default: 1355 default:
1388 warn("request 0x%02x timed out, clearing", pending); 1356 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
1357 pending);
1389 } 1358 }
1390} 1359}
1391 1360
@@ -1398,18 +1367,14 @@ static void req_timeout(unsigned long data)
1398 */ 1367 */
1399static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs) 1368static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1400{ 1369{
1401 struct bas_cardstate *ucs; 1370 struct bas_cardstate *ucs = urb->context;
1402 unsigned long flags; 1371 unsigned long flags;
1403 1372
1404 IFNULLRET(urb);
1405 IFNULLRET(urb->context);
1406 IFNULLRET(cardstate);
1407
1408 ucs = (struct bas_cardstate *) urb->context;
1409 spin_lock_irqsave(&ucs->lock, flags); 1373 spin_lock_irqsave(&ucs->lock, flags);
1410 if (urb->status && ucs->pending) { 1374 if (urb->status && ucs->pending) {
1411 err("control request 0x%02x failed: %s", 1375 dev_err(&ucs->interface->dev,
1412 ucs->pending, get_usb_statmsg(urb->status)); 1376 "control request 0x%02x failed: %s\n",
1377 ucs->pending, get_usb_statmsg(urb->status));
1413 del_timer(&ucs->timer_ctrl); 1378 del_timer(&ucs->timer_ctrl);
1414 ucs->pending = 0; 1379 ucs->pending = 0;
1415 } 1380 }
@@ -1438,28 +1403,25 @@ static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1438 */ 1403 */
1439static int req_submit(struct bc_state *bcs, int req, int val, int timeout) 1404static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1440{ 1405{
1441 struct bas_cardstate *ucs; 1406 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1442 int ret; 1407 int ret;
1443 unsigned long flags; 1408 unsigned long flags;
1444 1409
1445 IFNULLRETVAL(bcs, -EINVAL); 1410 gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1446 IFNULLRETVAL(bcs->cs, -EINVAL);
1447 ucs = bcs->cs->hw.bas;
1448 IFNULLRETVAL(ucs, -EINVAL);
1449 IFNULLRETVAL(ucs->urb_ctrl, -EINVAL);
1450
1451 dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1452 1411
1453 spin_lock_irqsave(&ucs->lock, flags); 1412 spin_lock_irqsave(&ucs->lock, flags);
1454 if (ucs->pending) { 1413 if (ucs->pending) {
1455 spin_unlock_irqrestore(&ucs->lock, flags); 1414 spin_unlock_irqrestore(&ucs->lock, flags);
1456 err("submission of request 0x%02x failed: request 0x%02x still pending", 1415 dev_err(bcs->cs->dev,
1457 req, ucs->pending); 1416 "submission of request 0x%02x failed: "
1417 "request 0x%02x still pending\n",
1418 req, ucs->pending);
1458 return -EBUSY; 1419 return -EBUSY;
1459 } 1420 }
1460 if (ucs->urb_ctrl->status == -EINPROGRESS) { 1421 if (ucs->urb_ctrl->status == -EINPROGRESS) {
1461 spin_unlock_irqrestore(&ucs->lock, flags); 1422 spin_unlock_irqrestore(&ucs->lock, flags);
1462 err("could not submit request 0x%02x: URB busy", req); 1423 dev_err(bcs->cs->dev,
1424 "could not submit request 0x%02x: URB busy\n", req);
1463 return -EBUSY; 1425 return -EBUSY;
1464 } 1426 }
1465 1427
@@ -1469,19 +1431,19 @@ static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1469 ucs->dr_ctrl.wIndex = 0; 1431 ucs->dr_ctrl.wIndex = 0;
1470 ucs->dr_ctrl.wLength = 0; 1432 ucs->dr_ctrl.wLength = 0;
1471 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev, 1433 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
1472 usb_sndctrlpipe(ucs->udev, 0), 1434 usb_sndctrlpipe(ucs->udev, 0),
1473 (unsigned char*) &ucs->dr_ctrl, NULL, 0, 1435 (unsigned char*) &ucs->dr_ctrl, NULL, 0,
1474 write_ctrl_callback, ucs); 1436 write_ctrl_callback, ucs);
1475 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) { 1437 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) {
1476 err("could not submit request 0x%02x: %s", 1438 dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n",
1477 req, get_usb_statmsg(ret)); 1439 req, get_usb_statmsg(ret));
1478 spin_unlock_irqrestore(&ucs->lock, flags); 1440 spin_unlock_irqrestore(&ucs->lock, flags);
1479 return ret; 1441 return ret;
1480 } 1442 }
1481 ucs->pending = req; 1443 ucs->pending = req;
1482 1444
1483 if (timeout > 0) { 1445 if (timeout > 0) {
1484 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 1446 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
1485 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10; 1447 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
1486 ucs->timer_ctrl.data = (unsigned long) bcs; 1448 ucs->timer_ctrl.data = (unsigned long) bcs;
1487 ucs->timer_ctrl.function = req_timeout; 1449 ucs->timer_ctrl.function = req_timeout;
@@ -1504,19 +1466,18 @@ static int gigaset_init_bchannel(struct bc_state *bcs)
1504{ 1466{
1505 int req, ret; 1467 int req, ret;
1506 1468
1507 IFNULLRETVAL(bcs, -EINVAL);
1508
1509 if ((ret = starturbs(bcs)) < 0) { 1469 if ((ret = starturbs(bcs)) < 0) {
1510 err("could not start isochronous I/O for channel %d", 1470 dev_err(bcs->cs->dev,
1511 bcs->channel + 1); 1471 "could not start isochronous I/O for channel %d\n",
1472 bcs->channel + 1);
1512 error_hangup(bcs); 1473 error_hangup(bcs);
1513 return ret; 1474 return ret;
1514 } 1475 }
1515 1476
1516 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL; 1477 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
1517 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) { 1478 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
1518 err("could not open channel %d: %s", 1479 dev_err(bcs->cs->dev, "could not open channel %d: %s\n",
1519 bcs->channel + 1, get_usb_statmsg(ret)); 1480 bcs->channel + 1, get_usb_statmsg(ret));
1520 stopurbs(bcs->hw.bas); 1481 stopurbs(bcs->hw.bas);
1521 error_hangup(bcs); 1482 error_hangup(bcs);
1522 } 1483 }
@@ -1537,8 +1498,6 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1537{ 1498{
1538 int req, ret; 1499 int req, ret;
1539 1500
1540 IFNULLRETVAL(bcs, -EINVAL);
1541
1542 if (!(atomic_read(&bcs->cs->hw.bas->basstate) & 1501 if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
1543 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) { 1502 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
1544 /* channel not running: just signal common.c */ 1503 /* channel not running: just signal common.c */
@@ -1548,8 +1507,9 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1548 1507
1549 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL; 1508 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
1550 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) 1509 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
1551 err("could not submit HD_CLOSE_BxCHANNEL request: %s", 1510 dev_err(bcs->cs->dev,
1552 get_usb_statmsg(ret)); 1511 "could not submit HD_CLOSE_BxCHANNEL request: %s\n",
1512 get_usb_statmsg(ret));
1553 return ret; 1513 return ret;
1554} 1514}
1555 1515
@@ -1564,17 +1524,13 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1564 */ 1524 */
1565static void complete_cb(struct cardstate *cs) 1525static void complete_cb(struct cardstate *cs)
1566{ 1526{
1567 struct cmdbuf_t *cb; 1527 struct cmdbuf_t *cb = cs->cmdbuf;
1568
1569 IFNULLRET(cs);
1570 cb = cs->cmdbuf;
1571 IFNULLRET(cb);
1572 1528
1573 /* unqueue completed buffer */ 1529 /* unqueue completed buffer */
1574 cs->cmdbytes -= cs->curlen; 1530 cs->cmdbytes -= cs->curlen;
1575 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, 1531 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD,
1576 "write_command: sent %u bytes, %u left", 1532 "write_command: sent %u bytes, %u left",
1577 cs->curlen, cs->cmdbytes); 1533 cs->curlen, cs->cmdbytes);
1578 if ((cs->cmdbuf = cb->next) != NULL) { 1534 if ((cs->cmdbuf = cb->next) != NULL) {
1579 cs->cmdbuf->prev = NULL; 1535 cs->cmdbuf->prev = NULL;
1580 cs->curlen = cs->cmdbuf->len; 1536 cs->curlen = cs->cmdbuf->len;
@@ -1600,15 +1556,9 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
1600 */ 1556 */
1601static void write_command_callback(struct urb *urb, struct pt_regs *regs) 1557static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1602{ 1558{
1603 struct cardstate *cs; 1559 struct cardstate *cs = urb->context;
1560 struct bas_cardstate *ucs = cs->hw.bas;
1604 unsigned long flags; 1561 unsigned long flags;
1605 struct bas_cardstate *ucs;
1606
1607 IFNULLRET(urb);
1608 cs = (struct cardstate *) urb->context;
1609 IFNULLRET(cs);
1610 ucs = cs->hw.bas;
1611 IFNULLRET(ucs);
1612 1562
1613 /* check status */ 1563 /* check status */
1614 switch (urb->status) { 1564 switch (urb->status) {
@@ -1618,22 +1568,27 @@ static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1618 case -ECONNRESET: /* canceled (async) */ 1568 case -ECONNRESET: /* canceled (async) */
1619 case -EINPROGRESS: /* pending */ 1569 case -EINPROGRESS: /* pending */
1620 /* ignore silently */ 1570 /* ignore silently */
1621 dbg(DEBUG_USBREQ, 1571 gig_dbg(DEBUG_USBREQ, "%s: %s",
1622 "%s: %s", __func__, get_usb_statmsg(urb->status)); 1572 __func__, get_usb_statmsg(urb->status));
1623 return; 1573 return;
1624 default: /* any failure */ 1574 default: /* any failure */
1625 if (++ucs->retry_cmd_out > BAS_RETRY) { 1575 if (++ucs->retry_cmd_out > BAS_RETRY) {
1626 warn("command write: %s, giving up after %d retries", 1576 dev_warn(cs->dev,
1627 get_usb_statmsg(urb->status), ucs->retry_cmd_out); 1577 "command write: %s, "
1578 "giving up after %d retries\n",
1579 get_usb_statmsg(urb->status),
1580 ucs->retry_cmd_out);
1628 break; 1581 break;
1629 } 1582 }
1630 if (cs->cmdbuf == NULL) { 1583 if (cs->cmdbuf == NULL) {
1631 warn("command write: %s, cannot retry - cmdbuf gone", 1584 dev_warn(cs->dev,
1632 get_usb_statmsg(urb->status)); 1585 "command write: %s, "
1586 "cannot retry - cmdbuf gone\n",
1587 get_usb_statmsg(urb->status));
1633 break; 1588 break;
1634 } 1589 }
1635 notice("command write: %s, retry %d", 1590 dev_notice(cs->dev, "command write: %s, retry %d\n",
1636 get_usb_statmsg(urb->status), ucs->retry_cmd_out); 1591 get_usb_statmsg(urb->status), ucs->retry_cmd_out);
1637 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0) 1592 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
1638 /* resubmitted - bypass regular exit block */ 1593 /* resubmitted - bypass regular exit block */
1639 return; 1594 return;
@@ -1655,13 +1610,9 @@ static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1655static void atrdy_timeout(unsigned long data) 1610static void atrdy_timeout(unsigned long data)
1656{ 1611{
1657 struct cardstate *cs = (struct cardstate *) data; 1612 struct cardstate *cs = (struct cardstate *) data;
1658 struct bas_cardstate *ucs; 1613 struct bas_cardstate *ucs = cs->hw.bas;
1659
1660 IFNULLRET(cs);
1661 ucs = cs->hw.bas;
1662 IFNULLRET(ucs);
1663 1614
1664 warn("timeout waiting for HD_READY_SEND_ATDATA"); 1615 dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
1665 1616
1666 /* fake the missing signal - what else can I do? */ 1617 /* fake the missing signal - what else can I do? */
1667 update_basstate(ucs, BS_ATREADY, BS_ATTIMER); 1618 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
@@ -1682,18 +1633,15 @@ static void atrdy_timeout(unsigned long data)
1682 */ 1633 */
1683static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len) 1634static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1684{ 1635{
1685 struct bas_cardstate *ucs; 1636 struct bas_cardstate *ucs = cs->hw.bas;
1637 unsigned long flags;
1686 int ret; 1638 int ret;
1687 1639
1688 IFNULLRETVAL(cs, -EFAULT); 1640 gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1689 ucs = cs->hw.bas;
1690 IFNULLRETVAL(ucs, -EFAULT);
1691 IFNULLRETVAL(ucs->urb_cmd_out, -EFAULT);
1692
1693 dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1694 1641
1695 if (ucs->urb_cmd_out->status == -EINPROGRESS) { 1642 if (ucs->urb_cmd_out->status == -EINPROGRESS) {
1696 err("could not submit HD_WRITE_ATMESSAGE: URB busy"); 1643 dev_err(cs->dev,
1644 "could not submit HD_WRITE_ATMESSAGE: URB busy\n");
1697 return -EBUSY; 1645 return -EBUSY;
1698 } 1646 }
1699 1647
@@ -1707,9 +1655,13 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1707 (unsigned char*) &ucs->dr_cmd_out, buf, len, 1655 (unsigned char*) &ucs->dr_cmd_out, buf, len,
1708 write_command_callback, cs); 1656 write_command_callback, cs);
1709 1657
1710 if ((ret = usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC)) != 0) { 1658 spin_lock_irqsave(&cs->lock, flags);
1711 err("could not submit HD_WRITE_ATMESSAGE: %s", 1659 ret = cs->connected ? usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC) : -ENODEV;
1712 get_usb_statmsg(ret)); 1660 spin_unlock_irqrestore(&cs->lock, flags);
1661
1662 if (ret) {
1663 dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n",
1664 get_usb_statmsg(ret));
1713 return ret; 1665 return ret;
1714 } 1666 }
1715 1667
@@ -1718,8 +1670,8 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1718 1670
1719 /* start timeout if necessary */ 1671 /* start timeout if necessary */
1720 if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) { 1672 if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) {
1721 dbg(DEBUG_OUTPUT, 1673 gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
1722 "setting ATREADY timeout of %d/10 secs", ATRDY_TIMEOUT); 1674 ATRDY_TIMEOUT);
1723 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10; 1675 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
1724 ucs->timer_atrdy.data = (unsigned long) cs; 1676 ucs->timer_atrdy.data = (unsigned long) cs;
1725 ucs->timer_atrdy.function = atrdy_timeout; 1677 ucs->timer_atrdy.function = atrdy_timeout;
@@ -1740,21 +1692,17 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1740static int start_cbsend(struct cardstate *cs) 1692static int start_cbsend(struct cardstate *cs)
1741{ 1693{
1742 struct cmdbuf_t *cb; 1694 struct cmdbuf_t *cb;
1743 struct bas_cardstate *ucs; 1695 struct bas_cardstate *ucs = cs->hw.bas;
1744 unsigned long flags; 1696 unsigned long flags;
1745 int rc; 1697 int rc;
1746 int retval = 0; 1698 int retval = 0;
1747 1699
1748 IFNULLRETVAL(cs, -EFAULT);
1749 ucs = cs->hw.bas;
1750 IFNULLRETVAL(ucs, -EFAULT);
1751
1752 /* check if AT channel is open */ 1700 /* check if AT channel is open */
1753 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) { 1701 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
1754 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, "AT channel not open"); 1702 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
1755 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT); 1703 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
1756 if (rc < 0) { 1704 if (rc < 0) {
1757 err("could not open AT channel"); 1705 dev_err(cs->dev, "could not open AT channel\n");
1758 /* flush command queue */ 1706 /* flush command queue */
1759 spin_lock_irqsave(&cs->cmdlock, flags); 1707 spin_lock_irqsave(&cs->cmdlock, flags);
1760 while (cs->cmdbuf != NULL) 1708 while (cs->cmdbuf != NULL)
@@ -1792,27 +1740,23 @@ static int start_cbsend(struct cardstate *cs)
1792 * cs controller state structure 1740 * cs controller state structure
1793 * buf command string to send 1741 * buf command string to send
1794 * len number of bytes to send (max. IF_WRITEBUF) 1742 * len number of bytes to send (max. IF_WRITEBUF)
1795 * wake_tasklet tasklet to run when transmission is completed (NULL if none) 1743 * wake_tasklet tasklet to run when transmission is completed
1744 * (NULL if none)
1796 * return value: 1745 * return value:
1797 * number of bytes queued on success 1746 * number of bytes queued on success
1798 * error code < 0 on error 1747 * error code < 0 on error
1799 */ 1748 */
1800static int gigaset_write_cmd(struct cardstate *cs, 1749static int gigaset_write_cmd(struct cardstate *cs,
1801 const unsigned char *buf, int len, 1750 const unsigned char *buf, int len,
1802 struct tasklet_struct *wake_tasklet) 1751 struct tasklet_struct *wake_tasklet)
1803{ 1752{
1804 struct cmdbuf_t *cb; 1753 struct cmdbuf_t *cb;
1805 unsigned long flags; 1754 unsigned long flags;
1806 int status; 1755 int status;
1807 1756
1808 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ? 1757 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
1809 DEBUG_TRANSCMD : DEBUG_LOCKCMD, 1758 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
1810 "CMD Transmit", len, buf, 0); 1759 "CMD Transmit", len, buf);
1811
1812 if (!atomic_read(&cs->connected)) {
1813 err("%s: not connected", __func__);
1814 return -ENODEV;
1815 }
1816 1760
1817 if (len <= 0) 1761 if (len <= 0)
1818 return 0; /* nothing to do */ 1762 return 0; /* nothing to do */
@@ -1820,7 +1764,7 @@ static int gigaset_write_cmd(struct cardstate *cs,
1820 if (len > IF_WRITEBUF) 1764 if (len > IF_WRITEBUF)
1821 len = IF_WRITEBUF; 1765 len = IF_WRITEBUF;
1822 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 1766 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
1823 err("%s: out of memory", __func__); 1767 dev_err(cs->dev, "%s: out of memory\n", __func__);
1824 return -ENOMEM; 1768 return -ENOMEM;
1825 } 1769 }
1826 1770
@@ -1849,7 +1793,8 @@ static int gigaset_write_cmd(struct cardstate *cs,
1849 1793
1850/* gigaset_write_room 1794/* gigaset_write_room
1851 * tty_driver.write_room interface routine 1795 * tty_driver.write_room interface routine
1852 * return number of characters the driver will accept to be written via gigaset_write_cmd 1796 * return number of characters the driver will accept to be written via
1797 * gigaset_write_cmd
1853 * parameter: 1798 * parameter:
1854 * controller state structure 1799 * controller state structure
1855 * return value: 1800 * return value:
@@ -1947,7 +1892,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
1947 return 0; 1892 return 0;
1948 } 1893 }
1949 tasklet_init(&ubc->sent_tasklet, 1894 tasklet_init(&ubc->sent_tasklet,
1950 &write_iso_tasklet, (unsigned long) bcs); 1895 &write_iso_tasklet, (unsigned long) bcs);
1951 1896
1952 spin_lock_init(&ubc->isoinlock); 1897 spin_lock_init(&ubc->isoinlock);
1953 for (i = 0; i < BAS_INURBS; ++i) 1898 for (i = 0; i < BAS_INURBS; ++i)
@@ -1968,7 +1913,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
1968 ubc->shared0s = 0; 1913 ubc->shared0s = 0;
1969 ubc->stolen0s = 0; 1914 ubc->stolen0s = 0;
1970 tasklet_init(&ubc->rcvd_tasklet, 1915 tasklet_init(&ubc->rcvd_tasklet,
1971 &read_iso_tasklet, (unsigned long) bcs); 1916 &read_iso_tasklet, (unsigned long) bcs);
1972 return 1; 1917 return 1;
1973} 1918}
1974 1919
@@ -2027,57 +1972,56 @@ static int gigaset_initcshw(struct cardstate *cs)
2027 */ 1972 */
2028static void freeurbs(struct cardstate *cs) 1973static void freeurbs(struct cardstate *cs)
2029{ 1974{
2030 struct bas_cardstate *ucs; 1975 struct bas_cardstate *ucs = cs->hw.bas;
2031 struct bas_bc_state *ubc; 1976 struct bas_bc_state *ubc;
2032 int i, j; 1977 int i, j;
2033 1978
2034 IFNULLRET(cs);
2035 ucs = cs->hw.bas;
2036 IFNULLRET(ucs);
2037
2038 for (j = 0; j < 2; ++j) { 1979 for (j = 0; j < 2; ++j) {
2039 ubc = cs->bcs[j].hw.bas; 1980 ubc = cs->bcs[j].hw.bas;
2040 IFNULLCONT(ubc);
2041 for (i = 0; i < BAS_OUTURBS; ++i) 1981 for (i = 0; i < BAS_OUTURBS; ++i)
2042 if (ubc->isoouturbs[i].urb) { 1982 if (ubc->isoouturbs[i].urb) {
2043 usb_kill_urb(ubc->isoouturbs[i].urb); 1983 usb_kill_urb(ubc->isoouturbs[i].urb);
2044 dbg(DEBUG_INIT, 1984 gig_dbg(DEBUG_INIT,
2045 "%s: isoc output URB %d/%d unlinked", 1985 "%s: isoc output URB %d/%d unlinked",
2046 __func__, j, i); 1986 __func__, j, i);
2047 usb_free_urb(ubc->isoouturbs[i].urb); 1987 usb_free_urb(ubc->isoouturbs[i].urb);
2048 ubc->isoouturbs[i].urb = NULL; 1988 ubc->isoouturbs[i].urb = NULL;
2049 } 1989 }
2050 for (i = 0; i < BAS_INURBS; ++i) 1990 for (i = 0; i < BAS_INURBS; ++i)
2051 if (ubc->isoinurbs[i]) { 1991 if (ubc->isoinurbs[i]) {
2052 usb_kill_urb(ubc->isoinurbs[i]); 1992 usb_kill_urb(ubc->isoinurbs[i]);
2053 dbg(DEBUG_INIT, 1993 gig_dbg(DEBUG_INIT,
2054 "%s: isoc input URB %d/%d unlinked", 1994 "%s: isoc input URB %d/%d unlinked",
2055 __func__, j, i); 1995 __func__, j, i);
2056 usb_free_urb(ubc->isoinurbs[i]); 1996 usb_free_urb(ubc->isoinurbs[i]);
2057 ubc->isoinurbs[i] = NULL; 1997 ubc->isoinurbs[i] = NULL;
2058 } 1998 }
2059 } 1999 }
2060 if (ucs->urb_int_in) { 2000 if (ucs->urb_int_in) {
2061 usb_kill_urb(ucs->urb_int_in); 2001 usb_kill_urb(ucs->urb_int_in);
2062 dbg(DEBUG_INIT, "%s: interrupt input URB unlinked", __func__); 2002 gig_dbg(DEBUG_INIT, "%s: interrupt input URB unlinked",
2003 __func__);
2063 usb_free_urb(ucs->urb_int_in); 2004 usb_free_urb(ucs->urb_int_in);
2064 ucs->urb_int_in = NULL; 2005 ucs->urb_int_in = NULL;
2065 } 2006 }
2066 if (ucs->urb_cmd_out) { 2007 if (ucs->urb_cmd_out) {
2067 usb_kill_urb(ucs->urb_cmd_out); 2008 usb_kill_urb(ucs->urb_cmd_out);
2068 dbg(DEBUG_INIT, "%s: command output URB unlinked", __func__); 2009 gig_dbg(DEBUG_INIT, "%s: command output URB unlinked",
2010 __func__);
2069 usb_free_urb(ucs->urb_cmd_out); 2011 usb_free_urb(ucs->urb_cmd_out);
2070 ucs->urb_cmd_out = NULL; 2012 ucs->urb_cmd_out = NULL;
2071 } 2013 }
2072 if (ucs->urb_cmd_in) { 2014 if (ucs->urb_cmd_in) {
2073 usb_kill_urb(ucs->urb_cmd_in); 2015 usb_kill_urb(ucs->urb_cmd_in);
2074 dbg(DEBUG_INIT, "%s: command input URB unlinked", __func__); 2016 gig_dbg(DEBUG_INIT, "%s: command input URB unlinked",
2017 __func__);
2075 usb_free_urb(ucs->urb_cmd_in); 2018 usb_free_urb(ucs->urb_cmd_in);
2076 ucs->urb_cmd_in = NULL; 2019 ucs->urb_cmd_in = NULL;
2077 } 2020 }
2078 if (ucs->urb_ctrl) { 2021 if (ucs->urb_ctrl) {
2079 usb_kill_urb(ucs->urb_ctrl); 2022 usb_kill_urb(ucs->urb_ctrl);
2080 dbg(DEBUG_INIT, "%s: control output URB unlinked", __func__); 2023 gig_dbg(DEBUG_INIT, "%s: control output URB unlinked",
2024 __func__);
2081 usb_free_urb(ucs->urb_ctrl); 2025 usb_free_urb(ucs->urb_ctrl);
2082 ucs->urb_ctrl = NULL; 2026 ucs->urb_ctrl = NULL;
2083 } 2027 }
@@ -2099,12 +2043,10 @@ static int gigaset_probe(struct usb_interface *interface,
2099 int i, j; 2043 int i, j;
2100 int ret; 2044 int ret;
2101 2045
2102 IFNULLRETVAL(udev, -ENODEV); 2046 gig_dbg(DEBUG_ANY,
2103 2047 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
2104 dbg(DEBUG_ANY, 2048 __func__, le16_to_cpu(udev->descriptor.idVendor),
2105 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)", 2049 le16_to_cpu(udev->descriptor.idProduct));
2106 __func__, le16_to_cpu(udev->descriptor.idVendor),
2107 le16_to_cpu(udev->descriptor.idProduct));
2108 2050
2109 /* See if the device offered us matches what we can accept */ 2051 /* See if the device offered us matches what we can accept */
2110 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) || 2052 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) ||
@@ -2112,20 +2054,21 @@ static int gigaset_probe(struct usb_interface *interface,
2112 le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID && 2054 le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID &&
2113 le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID && 2055 le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID &&
2114 le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) { 2056 le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) {
2115 dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__); 2057 gig_dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__);
2116 return -ENODEV; 2058 return -ENODEV;
2117 } 2059 }
2118 2060
2119 /* set required alternate setting */ 2061 /* set required alternate setting */
2120 hostif = interface->cur_altsetting; 2062 hostif = interface->cur_altsetting;
2121 if (hostif->desc.bAlternateSetting != 3) { 2063 if (hostif->desc.bAlternateSetting != 3) {
2122 dbg(DEBUG_ANY, 2064 gig_dbg(DEBUG_ANY,
2123 "%s: wrong alternate setting %d - trying to switch", 2065 "%s: wrong alternate setting %d - trying to switch",
2124 __func__, hostif->desc.bAlternateSetting); 2066 __func__, hostif->desc.bAlternateSetting);
2125 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) { 2067 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
2126 warn("usb_set_interface failed, device %d interface %d altsetting %d", 2068 dev_warn(&udev->dev, "usb_set_interface failed, "
2127 udev->devnum, hostif->desc.bInterfaceNumber, 2069 "device %d interface %d altsetting %d\n",
2128 hostif->desc.bAlternateSetting); 2070 udev->devnum, hostif->desc.bInterfaceNumber,
2071 hostif->desc.bAlternateSetting);
2129 return -ENODEV; 2072 return -ENODEV;
2130 } 2073 }
2131 hostif = interface->cur_altsetting; 2074 hostif = interface->cur_altsetting;
@@ -2134,23 +2077,28 @@ static int gigaset_probe(struct usb_interface *interface,
2134 /* Reject application specific interfaces 2077 /* Reject application specific interfaces
2135 */ 2078 */
2136 if (hostif->desc.bInterfaceClass != 255) { 2079 if (hostif->desc.bInterfaceClass != 255) {
2137 warn("%s: bInterfaceClass == %d", 2080 dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n",
2138 __func__, hostif->desc.bInterfaceClass); 2081 __func__, hostif->desc.bInterfaceClass);
2139 return -ENODEV; 2082 return -ENODEV;
2140 } 2083 }
2141 2084
2142 info("%s: Device matched (Vendor: 0x%x, Product: 0x%x)", 2085 dev_info(&udev->dev,
2143 __func__, le16_to_cpu(udev->descriptor.idVendor), 2086 "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
2144 le16_to_cpu(udev->descriptor.idProduct)); 2087 __func__, le16_to_cpu(udev->descriptor.idVendor),
2088 le16_to_cpu(udev->descriptor.idProduct));
2145 2089
2146 cs = gigaset_getunassignedcs(driver); 2090 cs = gigaset_getunassignedcs(driver);
2147 if (!cs) { 2091 if (!cs) {
2148 err("%s: no free cardstate", __func__); 2092 dev_err(&udev->dev, "no free cardstate\n");
2149 return -ENODEV; 2093 return -ENODEV;
2150 } 2094 }
2151 ucs = cs->hw.bas; 2095 ucs = cs->hw.bas;
2096
2097 /* save off device structure ptrs for later use */
2098 usb_get_dev(udev);
2152 ucs->udev = udev; 2099 ucs->udev = udev;
2153 ucs->interface = interface; 2100 ucs->interface = interface;
2101 cs->dev = &interface->dev;
2154 2102
2155 /* allocate URBs: 2103 /* allocate URBs:
2156 * - one for the interrupt pipe 2104 * - one for the interrupt pipe
@@ -2159,22 +2107,22 @@ static int gigaset_probe(struct usb_interface *interface,
2159 */ 2107 */
2160 ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL); 2108 ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL);
2161 if (!ucs->urb_int_in) { 2109 if (!ucs->urb_int_in) {
2162 err("No free urbs available"); 2110 dev_err(cs->dev, "no free urbs available\n");
2163 goto error; 2111 goto error;
2164 } 2112 }
2165 ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL); 2113 ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL);
2166 if (!ucs->urb_cmd_in) { 2114 if (!ucs->urb_cmd_in) {
2167 err("No free urbs available"); 2115 dev_err(cs->dev, "no free urbs available\n");
2168 goto error; 2116 goto error;
2169 } 2117 }
2170 ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL); 2118 ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL);
2171 if (!ucs->urb_cmd_out) { 2119 if (!ucs->urb_cmd_out) {
2172 err("No free urbs available"); 2120 dev_err(cs->dev, "no free urbs available\n");
2173 goto error; 2121 goto error;
2174 } 2122 }
2175 ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL); 2123 ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL);
2176 if (!ucs->urb_ctrl) { 2124 if (!ucs->urb_ctrl) {
2177 err("No free urbs available"); 2125 dev_err(cs->dev, "no free urbs available\n");
2178 goto error; 2126 goto error;
2179 } 2127 }
2180 2128
@@ -2184,7 +2132,7 @@ static int gigaset_probe(struct usb_interface *interface,
2184 ubc->isoouturbs[i].urb = 2132 ubc->isoouturbs[i].urb =
2185 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL); 2133 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2186 if (!ubc->isoouturbs[i].urb) { 2134 if (!ubc->isoouturbs[i].urb) {
2187 err("No free urbs available"); 2135 dev_err(cs->dev, "no free urbs available\n");
2188 goto error; 2136 goto error;
2189 } 2137 }
2190 } 2138 }
@@ -2192,7 +2140,7 @@ static int gigaset_probe(struct usb_interface *interface,
2192 ubc->isoinurbs[i] = 2140 ubc->isoinurbs[i] =
2193 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL); 2141 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2194 if (!ubc->isoinurbs[i]) { 2142 if (!ubc->isoinurbs[i]) {
2195 err("No free urbs available"); 2143 dev_err(cs->dev, "no free urbs available\n");
2196 goto error; 2144 goto error;
2197 } 2145 }
2198 } 2146 }
@@ -2204,13 +2152,14 @@ static int gigaset_probe(struct usb_interface *interface,
2204 /* Fill the interrupt urb and send it to the core */ 2152 /* Fill the interrupt urb and send it to the core */
2205 endpoint = &hostif->endpoint[0].desc; 2153 endpoint = &hostif->endpoint[0].desc;
2206 usb_fill_int_urb(ucs->urb_int_in, udev, 2154 usb_fill_int_urb(ucs->urb_int_in, udev,
2207 usb_rcvintpipe(udev, 2155 usb_rcvintpipe(udev,
2208 (endpoint->bEndpointAddress) & 0x0f), 2156 (endpoint->bEndpointAddress) & 0x0f),
2209 ucs->int_in_buf, 3, read_int_callback, cs, 2157 ucs->int_in_buf, 3, read_int_callback, cs,
2210 endpoint->bInterval); 2158 endpoint->bInterval);
2211 ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL); 2159 ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL);
2212 if (ret) { 2160 if (ret) {
2213 err("could not submit interrupt URB: %s", get_usb_statmsg(ret)); 2161 dev_err(cs->dev, "could not submit interrupt URB: %s\n",
2162 get_usb_statmsg(ret));
2214 goto error; 2163 goto error;
2215 } 2164 }
2216 2165
@@ -2221,18 +2170,18 @@ static int gigaset_probe(struct usb_interface *interface,
2221 /* tell common part that the device is ready */ 2170 /* tell common part that the device is ready */
2222 if (startmode == SM_LOCKED) 2171 if (startmode == SM_LOCKED)
2223 atomic_set(&cs->mstate, MS_LOCKED); 2172 atomic_set(&cs->mstate, MS_LOCKED);
2224 if (!gigaset_start(cs))
2225 goto error;
2226 2173
2227 /* save address of controller structure */ 2174 /* save address of controller structure */
2228 usb_set_intfdata(interface, cs); 2175 usb_set_intfdata(interface, cs);
2229 2176
2230 /* set up device sysfs */ 2177 if (!gigaset_start(cs))
2231 gigaset_init_dev_sysfs(interface); 2178 goto error;
2179
2232 return 0; 2180 return 0;
2233 2181
2234error: 2182error:
2235 freeurbs(cs); 2183 freeurbs(cs);
2184 usb_set_intfdata(interface, NULL);
2236 gigaset_unassign(cs); 2185 gigaset_unassign(cs);
2237 return -ENODEV; 2186 return -ENODEV;
2238} 2187}
@@ -2245,23 +2194,22 @@ static void gigaset_disconnect(struct usb_interface *interface)
2245 struct cardstate *cs; 2194 struct cardstate *cs;
2246 struct bas_cardstate *ucs; 2195 struct bas_cardstate *ucs;
2247 2196
2248 /* clear device sysfs */
2249 gigaset_free_dev_sysfs(interface);
2250
2251 cs = usb_get_intfdata(interface); 2197 cs = usb_get_intfdata(interface);
2252 usb_set_intfdata(interface, NULL);
2253 2198
2254 IFNULLRET(cs);
2255 ucs = cs->hw.bas; 2199 ucs = cs->hw.bas;
2256 IFNULLRET(ucs);
2257 2200
2258 info("disconnecting GigaSet base"); 2201 dev_info(cs->dev, "disconnecting Gigaset base\n");
2259 gigaset_stop(cs); 2202 gigaset_stop(cs);
2260 freeurbs(cs); 2203 freeurbs(cs);
2204 usb_set_intfdata(interface, NULL);
2261 kfree(ucs->rcvbuf); 2205 kfree(ucs->rcvbuf);
2262 ucs->rcvbuf = NULL; 2206 ucs->rcvbuf = NULL;
2263 ucs->rcvbuf_size = 0; 2207 ucs->rcvbuf_size = 0;
2264 atomic_set(&ucs->basstate, 0); 2208 atomic_set(&ucs->basstate, 0);
2209 usb_put_dev(ucs->udev);
2210 ucs->interface = NULL;
2211 ucs->udev = NULL;
2212 cs->dev = NULL;
2265 gigaset_unassign(cs); 2213 gigaset_unassign(cs);
2266} 2214}
2267 2215
@@ -2293,13 +2241,14 @@ static int __init bas_gigaset_init(void)
2293 2241
2294 /* allocate memory for our driver state and intialize it */ 2242 /* allocate memory for our driver state and intialize it */
2295 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 2243 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
2296 GIGASET_MODULENAME, GIGASET_DEVNAME, 2244 GIGASET_MODULENAME, GIGASET_DEVNAME,
2297 GIGASET_DEVFSNAME, &gigops, 2245 GIGASET_DEVFSNAME, &gigops,
2298 THIS_MODULE)) == NULL) 2246 THIS_MODULE)) == NULL)
2299 goto error; 2247 goto error;
2300 2248
2301 /* allocate memory for our device state and intialize it */ 2249 /* allocate memory for our device state and intialize it */
2302 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode, GIGASET_MODULENAME); 2250 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode,
2251 GIGASET_MODULENAME);
2303 if (!cardstate) 2252 if (!cardstate)
2304 goto error; 2253 goto error;
2305 2254
@@ -2329,19 +2278,18 @@ error: if (cardstate)
2329static void __exit bas_gigaset_exit(void) 2278static void __exit bas_gigaset_exit(void)
2330{ 2279{
2331 gigaset_blockdriver(driver); /* => probe will fail 2280 gigaset_blockdriver(driver); /* => probe will fail
2332 * => no gigaset_start any more 2281 * => no gigaset_start any more
2333 */ 2282 */
2334 2283
2335 gigaset_shutdown(cardstate); 2284 gigaset_shutdown(cardstate);
2336 /* from now on, no isdn callback should be possible */ 2285 /* from now on, no isdn callback should be possible */
2337 2286
2338 if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) { 2287 if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) {
2339 dbg(DEBUG_ANY, "closing AT channel"); 2288 gig_dbg(DEBUG_ANY, "closing AT channel");
2340 if (req_submit(cardstate->bcs, 2289 if (req_submit(cardstate->bcs,
2341 HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) { 2290 HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) {
2342 /* successfully submitted - wait for completion */ 2291 /* successfully submitted */
2343 //wait_event_interruptible(cs->initwait, !cs->hw.bas->pending); 2292 //FIXME wait for completion?
2344 //FIXME need own wait queue? wakeup?
2345 } 2293 }
2346 } 2294 }
2347 2295
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 64371995c1a9..749b3da1236e 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>. 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
@@ -11,10 +11,6 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: common.c,v 1.104.4.22 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
@@ -23,7 +19,7 @@
23#include <linux/moduleparam.h> 19#include <linux/moduleparam.h>
24 20
25/* Version Information */ 21/* Version Information */
26#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers <Eilers.Stefan@epost.de>" 22#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Tilman Schmidt <tilman@imap.cc>, Stefan Eilers"
27#define DRIVER_DESC "Driver for Gigaset 307x" 23#define DRIVER_DESC "Driver for Gigaset 307x"
28 24
29/* Module parameters */ 25/* Module parameters */
@@ -32,21 +28,10 @@ EXPORT_SYMBOL_GPL(gigaset_debuglevel);
32module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR); 28module_param_named(debug, gigaset_debuglevel, int, S_IRUGO|S_IWUSR);
33MODULE_PARM_DESC(debug, "debug level"); 29MODULE_PARM_DESC(debug, "debug level");
34 30
35/*====================================================================== 31/* driver state flags */
36 Prototypes of internal functions 32#define VALID_MINOR 0x01
37 */ 33#define VALID_ID 0x02
38 34#define ASSIGNED 0x04
39//static void gigaset_process_response(int resp_code, int parameter,
40// struct at_state_t *at_state,
41// unsigned char ** pstring);
42static struct cardstate *alloc_cs(struct gigaset_driver *drv);
43static void free_cs(struct cardstate *cs);
44static void make_valid(struct cardstate *cs, unsigned mask);
45static void make_invalid(struct cardstate *cs, unsigned mask);
46
47#define VALID_MINOR 0x01
48#define VALID_ID 0x02
49#define ASSIGNED 0x04
50 35
51/* bitwise byte inversion table */ 36/* bitwise byte inversion table */
52__u8 gigaset_invtab[256] = { 37__u8 gigaset_invtab[256] = {
@@ -86,42 +71,40 @@ __u8 gigaset_invtab[256] = {
86EXPORT_SYMBOL_GPL(gigaset_invtab); 71EXPORT_SYMBOL_GPL(gigaset_invtab);
87 72
88void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, 73void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
89 size_t len, const unsigned char *buf, int from_user) 74 size_t len, const unsigned char *buf)
90{ 75{
91 unsigned char outbuf[80]; 76 unsigned char outbuf[80];
92 unsigned char inbuf[80 - 1]; 77 unsigned char c;
93 size_t numin;
94 const unsigned char *in;
95 size_t space = sizeof outbuf - 1; 78 size_t space = sizeof outbuf - 1;
96 unsigned char *out = outbuf; 79 unsigned char *out = outbuf;
80 size_t numin = len;
97 81
98 if (!from_user) { 82 while (numin--) {
99 in = buf; 83 c = *buf++;
100 numin = len; 84 if (c == '~' || c == '^' || c == '\\') {
101 } else { 85 if (!space--)
102 numin = len < sizeof inbuf ? len : sizeof inbuf; 86 break;
103 in = inbuf; 87 *out++ = '\\';
104 if (copy_from_user(inbuf, (const unsigned char __user *) buf, numin)) {
105 strncpy(inbuf, "<FAULT>", sizeof inbuf);
106 numin = sizeof "<FAULT>" - 1;
107 } 88 }
108 } 89 if (c & 0x80) {
109 90 if (!space--)
110 for (; numin && space; --numin, ++in) { 91 break;
111 --space; 92 *out++ = '~';
112 if (*in >= 32) 93 c ^= 0x80;
113 *out++ = *in; 94 }
114 else { 95 if (c < 0x20 || c == 0x7f) {
96 if (!space--)
97 break;
115 *out++ = '^'; 98 *out++ = '^';
116 if (space) { 99 c ^= 0x40;
117 *out++ = '@' + *in;
118 --space;
119 }
120 } 100 }
101 if (!space--)
102 break;
103 *out++ = c;
121 } 104 }
122 *out = 0; 105 *out = 0;
123 106
124 dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf); 107 gig_dbg(level, "%s (%u bytes): %s", msg, (unsigned) len, outbuf);
125} 108}
126EXPORT_SYMBOL_GPL(gigaset_dbg_buffer); 109EXPORT_SYMBOL_GPL(gigaset_dbg_buffer);
127 110
@@ -146,11 +129,6 @@ int gigaset_enterconfigmode(struct cardstate *cs)
146{ 129{
147 int i, r; 130 int i, r;
148 131
149 if (!atomic_read(&cs->connected)) {
150 err("not connected!");
151 return -1;
152 }
153
154 cs->control_state = TIOCM_RTS; //FIXME 132 cs->control_state = TIOCM_RTS; //FIXME
155 133
156 r = setflags(cs, TIOCM_DTR, 200); 134 r = setflags(cs, TIOCM_DTR, 200);
@@ -174,7 +152,7 @@ int gigaset_enterconfigmode(struct cardstate *cs)
174 return 0; 152 return 0;
175 153
176error: 154error:
177 err("error %d on setuartbits!\n", -r); 155 dev_err(cs->dev, "error %d on setuartbits\n", -r);
178 cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value? 156 cs->control_state = TIOCM_RTS|TIOCM_DTR; // FIXME is this a good value?
179 cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR); 157 cs->ops->set_modem_ctrl(cs, 0, TIOCM_RTS|TIOCM_DTR);
180 158
@@ -187,13 +165,13 @@ static int test_timeout(struct at_state_t *at_state)
187 return 0; 165 return 0;
188 166
189 if (--at_state->timer_expires) { 167 if (--at_state->timer_expires) {
190 dbg(DEBUG_MCMD, "decreased timer of %p to %lu", 168 gig_dbg(DEBUG_MCMD, "decreased timer of %p to %lu",
191 at_state, at_state->timer_expires); 169 at_state, at_state->timer_expires);
192 return 0; 170 return 0;
193 } 171 }
194 172
195 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL, 173 if (!gigaset_add_event(at_state->cs, at_state, EV_TIMEOUT, NULL,
196 atomic_read(&at_state->timer_index), NULL)) { 174 at_state->timer_index, NULL)) {
197 //FIXME what should we do? 175 //FIXME what should we do?
198 } 176 }
199 177
@@ -221,10 +199,10 @@ static void timer_tick(unsigned long data)
221 if (test_timeout(at_state)) 199 if (test_timeout(at_state))
222 timeout = 1; 200 timeout = 1;
223 201
224 if (atomic_read(&cs->running)) { 202 if (cs->running) {
225 mod_timer(&cs->timer, jiffies + GIG_TICK); 203 mod_timer(&cs->timer, jiffies + msecs_to_jiffies(GIG_TICK));
226 if (timeout) { 204 if (timeout) {
227 dbg(DEBUG_CMD, "scheduling timeout"); 205 gig_dbg(DEBUG_CMD, "scheduling timeout");
228 tasklet_schedule(&cs->event_tasklet); 206 tasklet_schedule(&cs->event_tasklet);
229 } 207 }
230 } 208 }
@@ -238,13 +216,14 @@ int gigaset_get_channel(struct bc_state *bcs)
238 216
239 spin_lock_irqsave(&bcs->cs->lock, flags); 217 spin_lock_irqsave(&bcs->cs->lock, flags);
240 if (bcs->use_count) { 218 if (bcs->use_count) {
241 dbg(DEBUG_ANY, "could not allocate channel %d", bcs->channel); 219 gig_dbg(DEBUG_ANY, "could not allocate channel %d",
220 bcs->channel);
242 spin_unlock_irqrestore(&bcs->cs->lock, flags); 221 spin_unlock_irqrestore(&bcs->cs->lock, flags);
243 return 0; 222 return 0;
244 } 223 }
245 ++bcs->use_count; 224 ++bcs->use_count;
246 bcs->busy = 1; 225 bcs->busy = 1;
247 dbg(DEBUG_ANY, "allocated channel %d", bcs->channel); 226 gig_dbg(DEBUG_ANY, "allocated channel %d", bcs->channel);
248 spin_unlock_irqrestore(&bcs->cs->lock, flags); 227 spin_unlock_irqrestore(&bcs->cs->lock, flags);
249 return 1; 228 return 1;
250} 229}
@@ -255,13 +234,13 @@ void gigaset_free_channel(struct bc_state *bcs)
255 234
256 spin_lock_irqsave(&bcs->cs->lock, flags); 235 spin_lock_irqsave(&bcs->cs->lock, flags);
257 if (!bcs->busy) { 236 if (!bcs->busy) {
258 dbg(DEBUG_ANY, "could not free channel %d", bcs->channel); 237 gig_dbg(DEBUG_ANY, "could not free channel %d", bcs->channel);
259 spin_unlock_irqrestore(&bcs->cs->lock, flags); 238 spin_unlock_irqrestore(&bcs->cs->lock, flags);
260 return; 239 return;
261 } 240 }
262 --bcs->use_count; 241 --bcs->use_count;
263 bcs->busy = 0; 242 bcs->busy = 0;
264 dbg(DEBUG_ANY, "freed channel %d", bcs->channel); 243 gig_dbg(DEBUG_ANY, "freed channel %d", bcs->channel);
265 spin_unlock_irqrestore(&bcs->cs->lock, flags); 244 spin_unlock_irqrestore(&bcs->cs->lock, flags);
266} 245}
267 246
@@ -274,14 +253,14 @@ int gigaset_get_channels(struct cardstate *cs)
274 for (i = 0; i < cs->channels; ++i) 253 for (i = 0; i < cs->channels; ++i)
275 if (cs->bcs[i].use_count) { 254 if (cs->bcs[i].use_count) {
276 spin_unlock_irqrestore(&cs->lock, flags); 255 spin_unlock_irqrestore(&cs->lock, flags);
277 dbg(DEBUG_ANY, "could not allocated all channels"); 256 gig_dbg(DEBUG_ANY, "could not allocate all channels");
278 return 0; 257 return 0;
279 } 258 }
280 for (i = 0; i < cs->channels; ++i) 259 for (i = 0; i < cs->channels; ++i)
281 ++cs->bcs[i].use_count; 260 ++cs->bcs[i].use_count;
282 spin_unlock_irqrestore(&cs->lock, flags); 261 spin_unlock_irqrestore(&cs->lock, flags);
283 262
284 dbg(DEBUG_ANY, "allocated all channels"); 263 gig_dbg(DEBUG_ANY, "allocated all channels");
285 264
286 return 1; 265 return 1;
287} 266}
@@ -291,7 +270,7 @@ void gigaset_free_channels(struct cardstate *cs)
291 unsigned long flags; 270 unsigned long flags;
292 int i; 271 int i;
293 272
294 dbg(DEBUG_ANY, "unblocking all channels"); 273 gig_dbg(DEBUG_ANY, "unblocking all channels");
295 spin_lock_irqsave(&cs->lock, flags); 274 spin_lock_irqsave(&cs->lock, flags);
296 for (i = 0; i < cs->channels; ++i) 275 for (i = 0; i < cs->channels; ++i)
297 --cs->bcs[i].use_count; 276 --cs->bcs[i].use_count;
@@ -303,7 +282,7 @@ void gigaset_block_channels(struct cardstate *cs)
303 unsigned long flags; 282 unsigned long flags;
304 int i; 283 int i;
305 284
306 dbg(DEBUG_ANY, "blocking all channels"); 285 gig_dbg(DEBUG_ANY, "blocking all channels");
307 spin_lock_irqsave(&cs->lock, flags); 286 spin_lock_irqsave(&cs->lock, flags);
308 for (i = 0; i < cs->channels; ++i) 287 for (i = 0; i < cs->channels; ++i)
309 ++cs->bcs[i].use_count; 288 ++cs->bcs[i].use_count;
@@ -314,25 +293,27 @@ static void clear_events(struct cardstate *cs)
314{ 293{
315 struct event_t *ev; 294 struct event_t *ev;
316 unsigned head, tail; 295 unsigned head, tail;
296 unsigned long flags;
317 297
318 /* no locking needed (no reader/writer allowed) */ 298 spin_lock_irqsave(&cs->ev_lock, flags);
319 299
320 head = atomic_read(&cs->ev_head); 300 head = cs->ev_head;
321 tail = atomic_read(&cs->ev_tail); 301 tail = cs->ev_tail;
322 302
323 while (tail != head) { 303 while (tail != head) {
324 ev = cs->events + head; 304 ev = cs->events + head;
325 kfree(ev->ptr); 305 kfree(ev->ptr);
326
327 head = (head + 1) % MAX_EVENTS; 306 head = (head + 1) % MAX_EVENTS;
328 } 307 }
329 308
330 atomic_set(&cs->ev_head, tail); 309 cs->ev_head = tail;
310
311 spin_unlock_irqrestore(&cs->ev_lock, flags);
331} 312}
332 313
333struct event_t *gigaset_add_event(struct cardstate *cs, 314struct event_t *gigaset_add_event(struct cardstate *cs,
334 struct at_state_t *at_state, int type, 315 struct at_state_t *at_state, int type,
335 void *ptr, int parameter, void *arg) 316 void *ptr, int parameter, void *arg)
336{ 317{
337 unsigned long flags; 318 unsigned long flags;
338 unsigned next, tail; 319 unsigned next, tail;
@@ -340,9 +321,9 @@ struct event_t *gigaset_add_event(struct cardstate *cs,
340 321
341 spin_lock_irqsave(&cs->ev_lock, flags); 322 spin_lock_irqsave(&cs->ev_lock, flags);
342 323
343 tail = atomic_read(&cs->ev_tail); 324 tail = cs->ev_tail;
344 next = (tail + 1) % MAX_EVENTS; 325 next = (tail + 1) % MAX_EVENTS;
345 if (unlikely(next == atomic_read(&cs->ev_head))) 326 if (unlikely(next == cs->ev_head))
346 err("event queue full"); 327 err("event queue full");
347 else { 328 else {
348 event = cs->events + tail; 329 event = cs->events + tail;
@@ -352,7 +333,7 @@ struct event_t *gigaset_add_event(struct cardstate *cs,
352 event->ptr = ptr; 333 event->ptr = ptr;
353 event->arg = arg; 334 event->arg = arg;
354 event->parameter = parameter; 335 event->parameter = parameter;
355 atomic_set(&cs->ev_tail, next); 336 cs->ev_tail = next;
356 } 337 }
357 338
358 spin_unlock_irqrestore(&cs->ev_lock, flags); 339 spin_unlock_irqrestore(&cs->ev_lock, flags);
@@ -391,14 +372,14 @@ static void gigaset_freebcs(struct bc_state *bcs)
391{ 372{
392 int i; 373 int i;
393 374
394 dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel); 375 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->hw", bcs->channel);
395 if (!bcs->cs->ops->freebcshw(bcs)) { 376 if (!bcs->cs->ops->freebcshw(bcs)) {
396 dbg(DEBUG_INIT, "failed"); 377 gig_dbg(DEBUG_INIT, "failed");
397 } 378 }
398 379
399 dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel); 380 gig_dbg(DEBUG_INIT, "clearing bcs[%d]->at_state", bcs->channel);
400 clear_at_state(&bcs->at_state); 381 clear_at_state(&bcs->at_state);
401 dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel); 382 gig_dbg(DEBUG_INIT, "freeing bcs[%d]->skb", bcs->channel);
402 383
403 if (bcs->skb) 384 if (bcs->skb)
404 dev_kfree_skb(bcs->skb); 385 dev_kfree_skb(bcs->skb);
@@ -408,6 +389,52 @@ static void gigaset_freebcs(struct bc_state *bcs)
408 } 389 }
409} 390}
410 391
392static struct cardstate *alloc_cs(struct gigaset_driver *drv)
393{
394 unsigned long flags;
395 unsigned i;
396 static struct cardstate *ret = NULL;
397
398 spin_lock_irqsave(&drv->lock, flags);
399 for (i = 0; i < drv->minors; ++i) {
400 if (!(drv->flags[i] & VALID_MINOR)) {
401 drv->flags[i] = VALID_MINOR;
402 ret = drv->cs + i;
403 }
404 if (ret)
405 break;
406 }
407 spin_unlock_irqrestore(&drv->lock, flags);
408 return ret;
409}
410
411static void free_cs(struct cardstate *cs)
412{
413 unsigned long flags;
414 struct gigaset_driver *drv = cs->driver;
415 spin_lock_irqsave(&drv->lock, flags);
416 drv->flags[cs->minor_index] = 0;
417 spin_unlock_irqrestore(&drv->lock, flags);
418}
419
420static void make_valid(struct cardstate *cs, unsigned mask)
421{
422 unsigned long flags;
423 struct gigaset_driver *drv = cs->driver;
424 spin_lock_irqsave(&drv->lock, flags);
425 drv->flags[cs->minor_index] |= mask;
426 spin_unlock_irqrestore(&drv->lock, flags);
427}
428
429static void make_invalid(struct cardstate *cs, unsigned mask)
430{
431 unsigned long flags;
432 struct gigaset_driver *drv = cs->driver;
433 spin_lock_irqsave(&drv->lock, flags);
434 drv->flags[cs->minor_index] &= ~mask;
435 spin_unlock_irqrestore(&drv->lock, flags);
436}
437
411void gigaset_freecs(struct cardstate *cs) 438void gigaset_freecs(struct cardstate *cs)
412{ 439{
413 int i; 440 int i;
@@ -416,7 +443,7 @@ void gigaset_freecs(struct cardstate *cs)
416 if (!cs) 443 if (!cs)
417 return; 444 return;
418 445
419 down(&cs->sem); 446 mutex_lock(&cs->mutex);
420 447
421 if (!cs->bcs) 448 if (!cs->bcs)
422 goto f_cs; 449 goto f_cs;
@@ -424,8 +451,9 @@ void gigaset_freecs(struct cardstate *cs)
424 goto f_bcs; 451 goto f_bcs;
425 452
426 spin_lock_irqsave(&cs->lock, flags); 453 spin_lock_irqsave(&cs->lock, flags);
427 atomic_set(&cs->running, 0); 454 cs->running = 0;
428 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are not rescheduled below */ 455 spin_unlock_irqrestore(&cs->lock, flags); /* event handler and timer are
456 not rescheduled below */
429 457
430 tasklet_kill(&cs->event_tasklet); 458 tasklet_kill(&cs->event_tasklet);
431 del_timer_sync(&cs->timer); 459 del_timer_sync(&cs->timer);
@@ -434,7 +462,7 @@ void gigaset_freecs(struct cardstate *cs)
434 default: 462 default:
435 gigaset_if_free(cs); 463 gigaset_if_free(cs);
436 464
437 dbg(DEBUG_INIT, "clearing hw"); 465 gig_dbg(DEBUG_INIT, "clearing hw");
438 cs->ops->freecshw(cs); 466 cs->ops->freecshw(cs);
439 467
440 //FIXME cmdbuf 468 //FIXME cmdbuf
@@ -443,36 +471,36 @@ void gigaset_freecs(struct cardstate *cs)
443 case 2: /* error in initcshw */ 471 case 2: /* error in initcshw */
444 /* Deregister from LL */ 472 /* Deregister from LL */
445 make_invalid(cs, VALID_ID); 473 make_invalid(cs, VALID_ID);
446 dbg(DEBUG_INIT, "clearing iif"); 474 gig_dbg(DEBUG_INIT, "clearing iif");
447 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD); 475 gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
448 476
449 /* fall through */ 477 /* fall through */
450 case 1: /* error when regestering to LL */ 478 case 1: /* error when regestering to LL */
451 dbg(DEBUG_INIT, "clearing at_state"); 479 gig_dbg(DEBUG_INIT, "clearing at_state");
452 clear_at_state(&cs->at_state); 480 clear_at_state(&cs->at_state);
453 dealloc_at_states(cs); 481 dealloc_at_states(cs);
454 482
455 /* fall through */ 483 /* fall through */
456 case 0: /* error in one call to initbcs */ 484 case 0: /* error in one call to initbcs */
457 for (i = 0; i < cs->channels; ++i) { 485 for (i = 0; i < cs->channels; ++i) {
458 dbg(DEBUG_INIT, "clearing bcs[%d]", i); 486 gig_dbg(DEBUG_INIT, "clearing bcs[%d]", i);
459 gigaset_freebcs(cs->bcs + i); 487 gigaset_freebcs(cs->bcs + i);
460 } 488 }
461 489
462 clear_events(cs); 490 clear_events(cs);
463 dbg(DEBUG_INIT, "freeing inbuf"); 491 gig_dbg(DEBUG_INIT, "freeing inbuf");
464 kfree(cs->inbuf); 492 kfree(cs->inbuf);
465 } 493 }
466f_bcs: dbg(DEBUG_INIT, "freeing bcs[]"); 494f_bcs: gig_dbg(DEBUG_INIT, "freeing bcs[]");
467 kfree(cs->bcs); 495 kfree(cs->bcs);
468f_cs: dbg(DEBUG_INIT, "freeing cs"); 496f_cs: gig_dbg(DEBUG_INIT, "freeing cs");
469 up(&cs->sem); 497 mutex_unlock(&cs->mutex);
470 free_cs(cs); 498 free_cs(cs);
471} 499}
472EXPORT_SYMBOL_GPL(gigaset_freecs); 500EXPORT_SYMBOL_GPL(gigaset_freecs);
473 501
474void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, 502void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
475 struct cardstate *cs, int cid) 503 struct cardstate *cs, int cid)
476{ 504{
477 int i; 505 int i;
478 506
@@ -482,8 +510,8 @@ void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
482 at_state->pending_commands = 0; 510 at_state->pending_commands = 0;
483 at_state->timer_expires = 0; 511 at_state->timer_expires = 0;
484 at_state->timer_active = 0; 512 at_state->timer_active = 0;
485 atomic_set(&at_state->timer_index, 0); 513 at_state->timer_index = 0;
486 atomic_set(&at_state->seq_index, 0); 514 at_state->seq_index = 0;
487 at_state->ConState = 0; 515 at_state->ConState = 0;
488 for (i = 0; i < STR_NUM; ++i) 516 for (i = 0; i < STR_NUM; ++i)
489 at_state->str_var[i] = NULL; 517 at_state->str_var[i] = NULL;
@@ -501,7 +529,7 @@ void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
501 529
502 530
503static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs, 531static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
504 struct cardstate *cs, int inputstate) 532 struct cardstate *cs, int inputstate)
505/* inbuf->read must be allocated before! */ 533/* inbuf->read must be allocated before! */
506{ 534{
507 atomic_set(&inbuf->head, 0); 535 atomic_set(&inbuf->head, 0);
@@ -512,9 +540,50 @@ static void gigaset_inbuf_init(struct inbuf_t *inbuf, struct bc_state *bcs,
512 inbuf->inputstate = inputstate; 540 inbuf->inputstate = inputstate;
513} 541}
514 542
543/* append received bytes to inbuf */
544int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
545 unsigned numbytes)
546{
547 unsigned n, head, tail, bytesleft;
548
549 gig_dbg(DEBUG_INTR, "received %u bytes", numbytes);
550
551 if (!numbytes)
552 return 0;
553
554 bytesleft = numbytes;
555 tail = atomic_read(&inbuf->tail);
556 head = atomic_read(&inbuf->head);
557 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
558
559 while (bytesleft) {
560 if (head > tail)
561 n = head - 1 - tail;
562 else if (head == 0)
563 n = (RBUFSIZE-1) - tail;
564 else
565 n = RBUFSIZE - tail;
566 if (!n) {
567 dev_err(inbuf->cs->dev,
568 "buffer overflow (%u bytes lost)", bytesleft);
569 break;
570 }
571 if (n > bytesleft)
572 n = bytesleft;
573 memcpy(inbuf->data + tail, src, n);
574 bytesleft -= n;
575 tail = (tail + n) % RBUFSIZE;
576 src += n;
577 }
578 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
579 atomic_set(&inbuf->tail, tail);
580 return numbytes != bytesleft;
581}
582EXPORT_SYMBOL_GPL(gigaset_fill_inbuf);
583
515/* Initialize the b-channel structure */ 584/* Initialize the b-channel structure */
516static struct bc_state *gigaset_initbcs(struct bc_state *bcs, 585static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
517 struct cardstate *cs, int channel) 586 struct cardstate *cs, int channel)
518{ 587{
519 int i; 588 int i;
520 589
@@ -526,7 +595,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
526 bcs->trans_down = 0; 595 bcs->trans_down = 0;
527 bcs->trans_up = 0; 596 bcs->trans_up = 0;
528 597
529 dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel); 598 gig_dbg(DEBUG_INIT, "setting up bcs[%d]->at_state", channel);
530 gigaset_at_init(&bcs->at_state, bcs, cs, -1); 599 gigaset_at_init(&bcs->at_state, bcs, cs, -1);
531 600
532 bcs->rcvbytes = 0; 601 bcs->rcvbytes = 0;
@@ -535,7 +604,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
535 bcs->emptycount = 0; 604 bcs->emptycount = 0;
536#endif 605#endif
537 606
538 dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel); 607 gig_dbg(DEBUG_INIT, "allocating bcs[%d]->skb", channel);
539 bcs->fcs = PPP_INITFCS; 608 bcs->fcs = PPP_INITFCS;
540 bcs->inputstate = 0; 609 bcs->inputstate = 0;
541 if (cs->ignoreframes) { 610 if (cs->ignoreframes) {
@@ -544,7 +613,7 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
544 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 613 } else if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
545 skb_reserve(bcs->skb, HW_HDR_LEN); 614 skb_reserve(bcs->skb, HW_HDR_LEN);
546 else { 615 else {
547 warn("could not allocate skb"); 616 dev_warn(cs->dev, "could not allocate skb\n");
548 bcs->inputstate |= INS_skip_frame; 617 bcs->inputstate |= INS_skip_frame;
549 } 618 }
550 619
@@ -559,14 +628,13 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
559 for (i = 0; i < AT_NUM; ++i) 628 for (i = 0; i < AT_NUM; ++i)
560 bcs->commands[i] = NULL; 629 bcs->commands[i] = NULL;
561 630
562 dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel); 631 gig_dbg(DEBUG_INIT, " setting up bcs[%d]->hw", channel);
563 if (cs->ops->initbcshw(bcs)) 632 if (cs->ops->initbcshw(bcs))
564 return bcs; 633 return bcs;
565 634
566//error: 635 gig_dbg(DEBUG_INIT, " failed");
567 dbg(DEBUG_INIT, " failed");
568 636
569 dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel); 637 gig_dbg(DEBUG_INIT, " freeing bcs[%d]->skb", channel);
570 if (bcs->skb) 638 if (bcs->skb)
571 dev_kfree_skb(bcs->skb); 639 dev_kfree_skb(bcs->skb);
572 640
@@ -578,9 +646,10 @@ static struct bc_state *gigaset_initbcs(struct bc_state *bcs,
578 * Calls hardware dependent gigaset_initcshw() function 646 * Calls hardware dependent gigaset_initcshw() function
579 * Calls B channel initialization function gigaset_initbcs() for each B channel 647 * Calls B channel initialization function gigaset_initbcs() for each B channel
580 * parameters: 648 * parameters:
581 * drv hardware driver the device belongs to 649 * drv hardware driver the device belongs to
582 * channels number of B channels supported by device 650 * channels number of B channels supported by device
583 * onechannel !=0: B channel data and AT commands share one communication channel 651 * onechannel !=0: B channel data and AT commands share one
652 * communication channel
584 * ==0: B channels have separate communication channels 653 * ==0: B channels have separate communication channels
585 * ignoreframes number of frames to ignore after setting up B channel 654 * ignoreframes number of frames to ignore after setting up B channel
586 * cidmode !=0: start in CallID mode 655 * cidmode !=0: start in CallID mode
@@ -593,17 +662,18 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
593 int cidmode, const char *modulename) 662 int cidmode, const char *modulename)
594{ 663{
595 struct cardstate *cs = NULL; 664 struct cardstate *cs = NULL;
665 unsigned long flags;
596 int i; 666 int i;
597 667
598 dbg(DEBUG_INIT, "allocating cs"); 668 gig_dbg(DEBUG_INIT, "allocating cs");
599 cs = alloc_cs(drv); 669 cs = alloc_cs(drv);
600 if (!cs) 670 if (!cs)
601 goto error; 671 goto error;
602 dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1); 672 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
603 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL); 673 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
604 if (!cs->bcs) 674 if (!cs->bcs)
605 goto error; 675 goto error;
606 dbg(DEBUG_INIT, "allocating inbuf"); 676 gig_dbg(DEBUG_INIT, "allocating inbuf");
607 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL); 677 cs->inbuf = kmalloc(sizeof(struct inbuf_t), GFP_KERNEL);
608 if (!cs->inbuf) 678 if (!cs->inbuf)
609 goto error; 679 goto error;
@@ -613,19 +683,23 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
613 cs->onechannel = onechannel; 683 cs->onechannel = onechannel;
614 cs->ignoreframes = ignoreframes; 684 cs->ignoreframes = ignoreframes;
615 INIT_LIST_HEAD(&cs->temp_at_states); 685 INIT_LIST_HEAD(&cs->temp_at_states);
616 atomic_set(&cs->running, 0); 686 cs->running = 0;
617 init_timer(&cs->timer); /* clear next & prev */ 687 init_timer(&cs->timer); /* clear next & prev */
618 spin_lock_init(&cs->ev_lock); 688 spin_lock_init(&cs->ev_lock);
619 atomic_set(&cs->ev_tail, 0); 689 cs->ev_tail = 0;
620 atomic_set(&cs->ev_head, 0); 690 cs->ev_head = 0;
621 init_MUTEX_LOCKED(&cs->sem); 691 mutex_init(&cs->mutex);
622 tasklet_init(&cs->event_tasklet, &gigaset_handle_event, (unsigned long) cs); 692 mutex_lock(&cs->mutex);
693
694 tasklet_init(&cs->event_tasklet, &gigaset_handle_event,
695 (unsigned long) cs);
623 atomic_set(&cs->commands_pending, 0); 696 atomic_set(&cs->commands_pending, 0);
624 cs->cur_at_seq = 0; 697 cs->cur_at_seq = 0;
625 cs->gotfwver = -1; 698 cs->gotfwver = -1;
626 cs->open_count = 0; 699 cs->open_count = 0;
700 cs->dev = NULL;
627 cs->tty = NULL; 701 cs->tty = NULL;
628 atomic_set(&cs->cidmode, cidmode != 0); 702 cs->cidmode = cidmode != 0;
629 703
630 //if(onechannel) { //FIXME 704 //if(onechannel) { //FIXME
631 cs->tabnocid = gigaset_tab_nocid_m10x; 705 cs->tabnocid = gigaset_tab_nocid_m10x;
@@ -642,50 +716,43 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
642 atomic_set(&cs->mstate, MS_UNINITIALIZED); 716 atomic_set(&cs->mstate, MS_UNINITIALIZED);
643 717
644 for (i = 0; i < channels; ++i) { 718 for (i = 0; i < channels; ++i) {
645 dbg(DEBUG_INIT, "setting up bcs[%d].read", i); 719 gig_dbg(DEBUG_INIT, "setting up bcs[%d].read", i);
646 if (!gigaset_initbcs(cs->bcs + i, cs, i)) 720 if (!gigaset_initbcs(cs->bcs + i, cs, i))
647 goto error; 721 goto error;
648 } 722 }
649 723
650 ++cs->cs_init; 724 ++cs->cs_init;
651 725
652 dbg(DEBUG_INIT, "setting up at_state"); 726 gig_dbg(DEBUG_INIT, "setting up at_state");
653 spin_lock_init(&cs->lock); 727 spin_lock_init(&cs->lock);
654 gigaset_at_init(&cs->at_state, NULL, cs, 0); 728 gigaset_at_init(&cs->at_state, NULL, cs, 0);
655 cs->dle = 0; 729 cs->dle = 0;
656 cs->cbytes = 0; 730 cs->cbytes = 0;
657 731
658 dbg(DEBUG_INIT, "setting up inbuf"); 732 gig_dbg(DEBUG_INIT, "setting up inbuf");
659 if (onechannel) { //FIXME distinction necessary? 733 if (onechannel) { //FIXME distinction necessary?
660 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command); 734 gigaset_inbuf_init(cs->inbuf, cs->bcs, cs, INS_command);
661 } else 735 } else
662 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command); 736 gigaset_inbuf_init(cs->inbuf, NULL, cs, INS_command);
663 737
664 atomic_set(&cs->connected, 0); 738 cs->connected = 0;
739 cs->isdn_up = 0;
665 740
666 dbg(DEBUG_INIT, "setting up cmdbuf"); 741 gig_dbg(DEBUG_INIT, "setting up cmdbuf");
667 cs->cmdbuf = cs->lastcmdbuf = NULL; 742 cs->cmdbuf = cs->lastcmdbuf = NULL;
668 spin_lock_init(&cs->cmdlock); 743 spin_lock_init(&cs->cmdlock);
669 cs->curlen = 0; 744 cs->curlen = 0;
670 cs->cmdbytes = 0; 745 cs->cmdbytes = 0;
671 746
672 /* 747 gig_dbg(DEBUG_INIT, "setting up iif");
673 * Tell the ISDN4Linux subsystem (the LL) that
674 * a driver for a USB-Device is available !
675 * If this is done, "isdnctrl" is able to bind a device for this driver even
676 * if no physical usb-device is currently connected.
677 * But this device will just be accessable if a physical USB device is connected
678 * (via "gigaset_probe") .
679 */
680 dbg(DEBUG_INIT, "setting up iif");
681 if (!gigaset_register_to_LL(cs, modulename)) { 748 if (!gigaset_register_to_LL(cs, modulename)) {
682 err("register_isdn=>error"); 749 err("register_isdn failed");
683 goto error; 750 goto error;
684 } 751 }
685 752
686 make_valid(cs, VALID_ID); 753 make_valid(cs, VALID_ID);
687 ++cs->cs_init; 754 ++cs->cs_init;
688 dbg(DEBUG_INIT, "setting up hw"); 755 gig_dbg(DEBUG_INIT, "setting up hw");
689 if (!cs->ops->initcshw(cs)) 756 if (!cs->ops->initcshw(cs))
690 goto error; 757 goto error;
691 758
@@ -693,27 +760,29 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
693 760
694 gigaset_if_init(cs); 761 gigaset_if_init(cs);
695 762
696 atomic_set(&cs->running, 1); 763 spin_lock_irqsave(&cs->lock, flags);
697 cs->timer.data = (unsigned long) cs; 764 cs->running = 1;
698 cs->timer.function = timer_tick; 765 spin_unlock_irqrestore(&cs->lock, flags);
699 cs->timer.expires = jiffies + GIG_TICK; 766 setup_timer(&cs->timer, timer_tick, (unsigned long) cs);
767 cs->timer.expires = jiffies + msecs_to_jiffies(GIG_TICK);
700 /* FIXME: can jiffies increase too much until the timer is added? 768 /* FIXME: can jiffies increase too much until the timer is added?
701 * Same problem(?) with mod_timer() in timer_tick(). */ 769 * Same problem(?) with mod_timer() in timer_tick(). */
702 add_timer(&cs->timer); 770 add_timer(&cs->timer);
703 771
704 dbg(DEBUG_INIT, "cs initialized!"); 772 gig_dbg(DEBUG_INIT, "cs initialized");
705 up(&cs->sem); 773 mutex_unlock(&cs->mutex);
706 return cs; 774 return cs;
707 775
708error: if (cs) 776error: if (cs)
709 up(&cs->sem); 777 mutex_unlock(&cs->mutex);
710 dbg(DEBUG_INIT, "failed"); 778 gig_dbg(DEBUG_INIT, "failed");
711 gigaset_freecs(cs); 779 gigaset_freecs(cs);
712 return NULL; 780 return NULL;
713} 781}
714EXPORT_SYMBOL_GPL(gigaset_initcs); 782EXPORT_SYMBOL_GPL(gigaset_initcs);
715 783
716/* ReInitialize the b-channel structure */ /* e.g. called on hangup, disconnect */ 784/* ReInitialize the b-channel structure */
785/* e.g. called on hangup, disconnect */
717void gigaset_bcs_reinit(struct bc_state *bcs) 786void gigaset_bcs_reinit(struct bc_state *bcs)
718{ 787{
719 struct sk_buff *skb; 788 struct sk_buff *skb;
@@ -723,12 +792,12 @@ void gigaset_bcs_reinit(struct bc_state *bcs)
723 while ((skb = skb_dequeue(&bcs->squeue)) != NULL) 792 while ((skb = skb_dequeue(&bcs->squeue)) != NULL)
724 dev_kfree_skb(skb); 793 dev_kfree_skb(skb);
725 794
726 spin_lock_irqsave(&cs->lock, flags); //FIXME 795 spin_lock_irqsave(&cs->lock, flags);
727 clear_at_state(&bcs->at_state); 796 clear_at_state(&bcs->at_state);
728 bcs->at_state.ConState = 0; 797 bcs->at_state.ConState = 0;
729 bcs->at_state.timer_active = 0; 798 bcs->at_state.timer_active = 0;
730 bcs->at_state.timer_expires = 0; 799 bcs->at_state.timer_expires = 0;
731 bcs->at_state.cid = -1; /* No CID defined */ 800 bcs->at_state.cid = -1; /* No CID defined */
732 spin_unlock_irqrestore(&cs->lock, flags); 801 spin_unlock_irqrestore(&cs->lock, flags);
733 802
734 bcs->inputstate = 0; 803 bcs->inputstate = 0;
@@ -803,11 +872,14 @@ static void cleanup_cs(struct cardstate *cs)
803 872
804int gigaset_start(struct cardstate *cs) 873int gigaset_start(struct cardstate *cs)
805{ 874{
806 if (down_interruptible(&cs->sem)) 875 unsigned long flags;
876
877 if (mutex_lock_interruptible(&cs->mutex))
807 return 0; 878 return 0;
808 //info("USB device for Gigaset 307x now attached to Dev %d", ucs->minor);
809 879
810 atomic_set(&cs->connected, 1); 880 spin_lock_irqsave(&cs->lock, flags);
881 cs->connected = 1;
882 spin_unlock_irqrestore(&cs->lock, flags);
811 883
812 if (atomic_read(&cs->mstate) != MS_LOCKED) { 884 if (atomic_read(&cs->mstate) != MS_LOCKED) {
813 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS); 885 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
@@ -826,23 +898,26 @@ int gigaset_start(struct cardstate *cs)
826 goto error; 898 goto error;
827 } 899 }
828 900
829 dbg(DEBUG_CMD, "scheduling START"); 901 gig_dbg(DEBUG_CMD, "scheduling START");
830 gigaset_schedule_event(cs); 902 gigaset_schedule_event(cs);
831 903
832 wait_event(cs->waitqueue, !cs->waiting); 904 wait_event(cs->waitqueue, !cs->waiting);
833 905
834 up(&cs->sem); 906 /* set up device sysfs */
907 gigaset_init_dev_sysfs(cs);
908
909 mutex_unlock(&cs->mutex);
835 return 1; 910 return 1;
836 911
837error: 912error:
838 up(&cs->sem); 913 mutex_unlock(&cs->mutex);
839 return 0; 914 return 0;
840} 915}
841EXPORT_SYMBOL_GPL(gigaset_start); 916EXPORT_SYMBOL_GPL(gigaset_start);
842 917
843void gigaset_shutdown(struct cardstate *cs) 918void gigaset_shutdown(struct cardstate *cs)
844{ 919{
845 down(&cs->sem); 920 mutex_lock(&cs->mutex);
846 921
847 cs->waiting = 1; 922 cs->waiting = 1;
848 923
@@ -851,11 +926,11 @@ void gigaset_shutdown(struct cardstate *cs)
851 goto exit; 926 goto exit;
852 } 927 }
853 928
854 dbg(DEBUG_CMD, "scheduling SHUTDOWN"); 929 gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN");
855 gigaset_schedule_event(cs); 930 gigaset_schedule_event(cs);
856 931
857 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { 932 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) {
858 warn("aborted"); 933 warn("%s: aborted", __func__);
859 //FIXME 934 //FIXME
860 } 935 }
861 936
@@ -872,15 +947,13 @@ void gigaset_shutdown(struct cardstate *cs)
872 cleanup_cs(cs); 947 cleanup_cs(cs);
873 948
874exit: 949exit:
875 up(&cs->sem); 950 mutex_unlock(&cs->mutex);
876} 951}
877EXPORT_SYMBOL_GPL(gigaset_shutdown); 952EXPORT_SYMBOL_GPL(gigaset_shutdown);
878 953
879void gigaset_stop(struct cardstate *cs) 954void gigaset_stop(struct cardstate *cs)
880{ 955{
881 down(&cs->sem); 956 mutex_lock(&cs->mutex);
882
883 atomic_set(&cs->connected, 0);
884 957
885 cs->waiting = 1; 958 cs->waiting = 1;
886 959
@@ -889,21 +962,21 @@ void gigaset_stop(struct cardstate *cs)
889 goto exit; 962 goto exit;
890 } 963 }
891 964
892 dbg(DEBUG_CMD, "scheduling STOP"); 965 gig_dbg(DEBUG_CMD, "scheduling STOP");
893 gigaset_schedule_event(cs); 966 gigaset_schedule_event(cs);
894 967
895 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { 968 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) {
896 warn("aborted"); 969 warn("%s: aborted", __func__);
897 //FIXME 970 //FIXME
898 } 971 }
899 972
900 /* Tell the LL that the device is not available .. */ 973 /* clear device sysfs */
901 gigaset_i4l_cmd(cs, ISDN_STAT_STOP); // FIXME move to event layer? 974 gigaset_free_dev_sysfs(cs);
902 975
903 cleanup_cs(cs); 976 cleanup_cs(cs);
904 977
905exit: 978exit:
906 up(&cs->sem); 979 mutex_unlock(&cs->mutex);
907} 980}
908EXPORT_SYMBOL_GPL(gigaset_stop); 981EXPORT_SYMBOL_GPL(gigaset_stop);
909 982
@@ -947,31 +1020,25 @@ void gigaset_debugdrivers(void)
947 1020
948 spin_lock_irqsave(&driver_lock, flags); 1021 spin_lock_irqsave(&driver_lock, flags);
949 list_for_each_entry(drv, &drivers, list) { 1022 list_for_each_entry(drv, &drivers, list) {
950 dbg(DEBUG_DRIVER, "driver %p", drv); 1023 gig_dbg(DEBUG_DRIVER, "driver %p", drv);
951 spin_lock(&drv->lock); 1024 spin_lock(&drv->lock);
952 for (i = 0; i < drv->minors; ++i) { 1025 for (i = 0; i < drv->minors; ++i) {
953 dbg(DEBUG_DRIVER, " index %u", i); 1026 gig_dbg(DEBUG_DRIVER, " index %u", i);
954 dbg(DEBUG_DRIVER, " flags 0x%02x", drv->flags[i]); 1027 gig_dbg(DEBUG_DRIVER, " flags 0x%02x",
1028 drv->flags[i]);
955 cs = drv->cs + i; 1029 cs = drv->cs + i;
956 dbg(DEBUG_DRIVER, " cardstate %p", cs); 1030 gig_dbg(DEBUG_DRIVER, " cardstate %p", cs);
957 dbg(DEBUG_DRIVER, " minor_index %u", cs->minor_index); 1031 gig_dbg(DEBUG_DRIVER, " minor_index %u",
958 dbg(DEBUG_DRIVER, " driver %p", cs->driver); 1032 cs->minor_index);
959 dbg(DEBUG_DRIVER, " i4l id %d", cs->myid); 1033 gig_dbg(DEBUG_DRIVER, " driver %p", cs->driver);
1034 gig_dbg(DEBUG_DRIVER, " i4l id %d", cs->myid);
960 } 1035 }
961 spin_unlock(&drv->lock); 1036 spin_unlock(&drv->lock);
962 } 1037 }
963 spin_unlock_irqrestore(&driver_lock, flags); 1038 spin_unlock_irqrestore(&driver_lock, flags);
964} 1039}
965EXPORT_SYMBOL_GPL(gigaset_debugdrivers);
966
967struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
968{
969 if (tty->index < 0 || tty->index >= tty->driver->num)
970 return NULL;
971 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
972}
973 1040
974struct cardstate *gigaset_get_cs_by_minor(unsigned minor) 1041static struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
975{ 1042{
976 unsigned long flags; 1043 unsigned long flags;
977 static struct cardstate *ret = NULL; 1044 static struct cardstate *ret = NULL;
@@ -994,6 +1061,13 @@ struct cardstate *gigaset_get_cs_by_minor(unsigned minor)
994 return ret; 1061 return ret;
995} 1062}
996 1063
1064struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty)
1065{
1066 if (tty->index < 0 || tty->index >= tty->driver->num)
1067 return NULL;
1068 return gigaset_get_cs_by_minor(tty->index + tty->driver->minor_start);
1069}
1070
997void gigaset_freedriver(struct gigaset_driver *drv) 1071void gigaset_freedriver(struct gigaset_driver *drv)
998{ 1072{
999 unsigned long flags; 1073 unsigned long flags;
@@ -1014,20 +1088,20 @@ EXPORT_SYMBOL_GPL(gigaset_freedriver);
1014/* gigaset_initdriver 1088/* gigaset_initdriver
1015 * Allocate and initialize gigaset_driver structure. Initialize interface. 1089 * Allocate and initialize gigaset_driver structure. Initialize interface.
1016 * parameters: 1090 * parameters:
1017 * minor First minor number 1091 * minor First minor number
1018 * minors Number of minors this driver can handle 1092 * minors Number of minors this driver can handle
1019 * procname Name of the driver (e.g. for /proc/tty/drivers, path in /proc/driver) 1093 * procname Name of the driver
1020 * devname Name of the device files (prefix without minor number) 1094 * devname Name of the device files (prefix without minor number)
1021 * devfsname Devfs name of the device files without %d 1095 * devfsname Devfs name of the device files without %d
1022 * return value: 1096 * return value:
1023 * Pointer to the gigaset_driver structure on success, NULL on failure. 1097 * Pointer to the gigaset_driver structure on success, NULL on failure.
1024 */ 1098 */
1025struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, 1099struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1026 const char *procname, 1100 const char *procname,
1027 const char *devname, 1101 const char *devname,
1028 const char *devfsname, 1102 const char *devfsname,
1029 const struct gigaset_ops *ops, 1103 const struct gigaset_ops *ops,
1030 struct module *owner) 1104 struct module *owner)
1031{ 1105{
1032 struct gigaset_driver *drv; 1106 struct gigaset_driver *drv;
1033 unsigned long flags; 1107 unsigned long flags;
@@ -1036,8 +1110,9 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1036 drv = kmalloc(sizeof *drv, GFP_KERNEL); 1110 drv = kmalloc(sizeof *drv, GFP_KERNEL);
1037 if (!drv) 1111 if (!drv)
1038 return NULL; 1112 return NULL;
1113
1039 if (!try_module_get(owner)) 1114 if (!try_module_get(owner))
1040 return NULL; 1115 goto out1;
1041 1116
1042 drv->cs = NULL; 1117 drv->cs = NULL;
1043 drv->have_tty = 0; 1118 drv->have_tty = 0;
@@ -1051,10 +1126,11 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1051 1126
1052 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL); 1127 drv->cs = kmalloc(minors * sizeof *drv->cs, GFP_KERNEL);
1053 if (!drv->cs) 1128 if (!drv->cs)
1054 goto out1; 1129 goto out2;
1130
1055 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL); 1131 drv->flags = kmalloc(minors * sizeof *drv->flags, GFP_KERNEL);
1056 if (!drv->flags) 1132 if (!drv->flags)
1057 goto out2; 1133 goto out3;
1058 1134
1059 for (i = 0; i < minors; ++i) { 1135 for (i = 0; i < minors; ++i) {
1060 drv->flags[i] = 0; 1136 drv->flags[i] = 0;
@@ -1071,61 +1147,16 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
1071 1147
1072 return drv; 1148 return drv;
1073 1149
1074out2: 1150out3:
1075 kfree(drv->cs); 1151 kfree(drv->cs);
1152out2:
1153 module_put(owner);
1076out1: 1154out1:
1077 kfree(drv); 1155 kfree(drv);
1078 module_put(owner);
1079 return NULL; 1156 return NULL;
1080} 1157}
1081EXPORT_SYMBOL_GPL(gigaset_initdriver); 1158EXPORT_SYMBOL_GPL(gigaset_initdriver);
1082 1159
1083static struct cardstate *alloc_cs(struct gigaset_driver *drv)
1084{
1085 unsigned long flags;
1086 unsigned i;
1087 static struct cardstate *ret = NULL;
1088
1089 spin_lock_irqsave(&drv->lock, flags);
1090 for (i = 0; i < drv->minors; ++i) {
1091 if (!(drv->flags[i] & VALID_MINOR)) {
1092 drv->flags[i] = VALID_MINOR;
1093 ret = drv->cs + i;
1094 }
1095 if (ret)
1096 break;
1097 }
1098 spin_unlock_irqrestore(&drv->lock, flags);
1099 return ret;
1100}
1101
1102static void free_cs(struct cardstate *cs)
1103{
1104 unsigned long flags;
1105 struct gigaset_driver *drv = cs->driver;
1106 spin_lock_irqsave(&drv->lock, flags);
1107 drv->flags[cs->minor_index] = 0;
1108 spin_unlock_irqrestore(&drv->lock, flags);
1109}
1110
1111static void make_valid(struct cardstate *cs, unsigned mask)
1112{
1113 unsigned long flags;
1114 struct gigaset_driver *drv = cs->driver;
1115 spin_lock_irqsave(&drv->lock, flags);
1116 drv->flags[cs->minor_index] |= mask;
1117 spin_unlock_irqrestore(&drv->lock, flags);
1118}
1119
1120static void make_invalid(struct cardstate *cs, unsigned mask)
1121{
1122 unsigned long flags;
1123 struct gigaset_driver *drv = cs->driver;
1124 spin_lock_irqsave(&drv->lock, flags);
1125 drv->flags[cs->minor_index] &= ~mask;
1126 spin_unlock_irqrestore(&drv->lock, flags);
1127}
1128
1129/* For drivers without fixed assignment device<->cardstate (usb) */ 1160/* For drivers without fixed assignment device<->cardstate (usb) */
1130struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv) 1161struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv)
1131{ 1162{
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index fdcb80bb21c7..1ba3424a286b 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>. 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
@@ -11,82 +11,78 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: ev-layer.c,v 1.4.2.18 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
21 17
22/* ========================================================== */ 18/* ========================================================== */
23/* bit masks for pending commands */ 19/* bit masks for pending commands */
24#define PC_INIT 0x004 20#define PC_DIAL 0x001
25#define PC_DLE0 0x008 21#define PC_HUP 0x002
26#define PC_DLE1 0x010 22#define PC_INIT 0x004
27#define PC_CID 0x080 23#define PC_DLE0 0x008
28#define PC_NOCID 0x100 24#define PC_DLE1 0x010
29#define PC_HUP 0x002 25#define PC_SHUTDOWN 0x020
30#define PC_DIAL 0x001 26#define PC_ACCEPT 0x040
31#define PC_ACCEPT 0x040 27#define PC_CID 0x080
32#define PC_SHUTDOWN 0x020 28#define PC_NOCID 0x100
33#define PC_CIDMODE 0x200 29#define PC_CIDMODE 0x200
34#define PC_UMMODE 0x400 30#define PC_UMMODE 0x400
35 31
36/* types of modem responses */ 32/* types of modem responses */
37#define RT_NOTHING 0 33#define RT_NOTHING 0
38#define RT_ZSAU 1 34#define RT_ZSAU 1
39#define RT_RING 2 35#define RT_RING 2
40#define RT_NUMBER 3 36#define RT_NUMBER 3
41#define RT_STRING 4 37#define RT_STRING 4
42#define RT_HEX 5 38#define RT_HEX 5
43#define RT_ZCAU 6 39#define RT_ZCAU 6
44 40
45/* Possible ASCII responses */ 41/* Possible ASCII responses */
46#define RSP_OK 0 42#define RSP_OK 0
47//#define RSP_BUSY 1 43//#define RSP_BUSY 1
48//#define RSP_CONNECT 2 44//#define RSP_CONNECT 2
49#define RSP_ZGCI 3 45#define RSP_ZGCI 3
50#define RSP_RING 4 46#define RSP_RING 4
51#define RSP_ZAOC 5 47#define RSP_ZAOC 5
52#define RSP_ZCSTR 6 48#define RSP_ZCSTR 6
53#define RSP_ZCFGT 7 49#define RSP_ZCFGT 7
54#define RSP_ZCFG 8 50#define RSP_ZCFG 8
55#define RSP_ZCCR 9 51#define RSP_ZCCR 9
56#define RSP_EMPTY 10 52#define RSP_EMPTY 10
57#define RSP_ZLOG 11 53#define RSP_ZLOG 11
58#define RSP_ZCAU 12 54#define RSP_ZCAU 12
59#define RSP_ZMWI 13 55#define RSP_ZMWI 13
60#define RSP_ZABINFO 14 56#define RSP_ZABINFO 14
61#define RSP_ZSMLSTCHG 15 57#define RSP_ZSMLSTCHG 15
62#define RSP_VAR 100 58#define RSP_VAR 100
63#define RSP_ZSAU (RSP_VAR + VAR_ZSAU) 59#define RSP_ZSAU (RSP_VAR + VAR_ZSAU)
64#define RSP_ZDLE (RSP_VAR + VAR_ZDLE) 60#define RSP_ZDLE (RSP_VAR + VAR_ZDLE)
65#define RSP_ZVLS (RSP_VAR + VAR_ZVLS) 61#define RSP_ZVLS (RSP_VAR + VAR_ZVLS)
66#define RSP_ZCTP (RSP_VAR + VAR_ZCTP) 62#define RSP_ZCTP (RSP_VAR + VAR_ZCTP)
67#define RSP_STR (RSP_VAR + VAR_NUM) 63#define RSP_STR (RSP_VAR + VAR_NUM)
68#define RSP_NMBR (RSP_STR + STR_NMBR) 64#define RSP_NMBR (RSP_STR + STR_NMBR)
69#define RSP_ZCPN (RSP_STR + STR_ZCPN) 65#define RSP_ZCPN (RSP_STR + STR_ZCPN)
70#define RSP_ZCON (RSP_STR + STR_ZCON) 66#define RSP_ZCON (RSP_STR + STR_ZCON)
71#define RSP_ZBC (RSP_STR + STR_ZBC) 67#define RSP_ZBC (RSP_STR + STR_ZBC)
72#define RSP_ZHLC (RSP_STR + STR_ZHLC) 68#define RSP_ZHLC (RSP_STR + STR_ZHLC)
73#define RSP_ERROR -1 /* ERROR */ 69#define RSP_ERROR -1 /* ERROR */
74#define RSP_WRONG_CID -2 /* unknown cid in cmd */ 70#define RSP_WRONG_CID -2 /* unknown cid in cmd */
75//#define RSP_EMPTY -3 71//#define RSP_EMPTY -3
76#define RSP_UNKNOWN -4 /* unknown response */ 72#define RSP_UNKNOWN -4 /* unknown response */
77#define RSP_FAIL -5 /* internal error */ 73#define RSP_FAIL -5 /* internal error */
78#define RSP_INVAL -6 /* invalid response */ 74#define RSP_INVAL -6 /* invalid response */
79 75
80#define RSP_NONE -19 76#define RSP_NONE -19
81#define RSP_STRING -20 77#define RSP_STRING -20
82#define RSP_NULL -21 78#define RSP_NULL -21
83//#define RSP_RETRYFAIL -22 79//#define RSP_RETRYFAIL -22
84//#define RSP_RETRY -23 80//#define RSP_RETRY -23
85//#define RSP_SKIP -24 81//#define RSP_SKIP -24
86#define RSP_INIT -27 82#define RSP_INIT -27
87#define RSP_ANY -26 83#define RSP_ANY -26
88#define RSP_LAST -28 84#define RSP_LAST -28
89#define RSP_NODEV -9 85#define RSP_NODEV -9
90 86
91/* actions for process_response */ 87/* actions for process_response */
92#define ACT_NOTHING 0 88#define ACT_NOTHING 0
@@ -112,7 +108,7 @@
112#define ACT_DISCONNECT 20 108#define ACT_DISCONNECT 20
113#define ACT_CONNECT 21 109#define ACT_CONNECT 21
114#define ACT_REMOTEREJECT 22 110#define ACT_REMOTEREJECT 22
115#define ACT_CONNTIMEOUT 23 111#define ACT_CONNTIMEOUT 23
116#define ACT_REMOTEHUP 24 112#define ACT_REMOTEHUP 24
117#define ACT_ABORTHUP 25 113#define ACT_ABORTHUP 25
118#define ACT_ICALL 26 114#define ACT_ICALL 26
@@ -127,40 +123,40 @@
127#define ACT_ERROR 35 123#define ACT_ERROR 35
128#define ACT_ABORTCID 36 124#define ACT_ABORTCID 36
129#define ACT_ZCAU 37 125#define ACT_ZCAU 37
130#define ACT_NOTIFY_BC_DOWN 38 126#define ACT_NOTIFY_BC_DOWN 38
131#define ACT_NOTIFY_BC_UP 39 127#define ACT_NOTIFY_BC_UP 39
132#define ACT_DIAL 40 128#define ACT_DIAL 40
133#define ACT_ACCEPT 41 129#define ACT_ACCEPT 41
134#define ACT_PROTO_L2 42 130#define ACT_PROTO_L2 42
135#define ACT_HUP 43 131#define ACT_HUP 43
136#define ACT_IF_LOCK 44 132#define ACT_IF_LOCK 44
137#define ACT_START 45 133#define ACT_START 45
138#define ACT_STOP 46 134#define ACT_STOP 46
139#define ACT_FAKEDLE0 47 135#define ACT_FAKEDLE0 47
140#define ACT_FAKEHUP 48 136#define ACT_FAKEHUP 48
141#define ACT_FAKESDOWN 49 137#define ACT_FAKESDOWN 49
142#define ACT_SHUTDOWN 50 138#define ACT_SHUTDOWN 50
143#define ACT_PROC_CIDMODE 51 139#define ACT_PROC_CIDMODE 51
144#define ACT_UMODESET 52 140#define ACT_UMODESET 52
145#define ACT_FAILUMODE 53 141#define ACT_FAILUMODE 53
146#define ACT_CMODESET 54 142#define ACT_CMODESET 54
147#define ACT_FAILCMODE 55 143#define ACT_FAILCMODE 55
148#define ACT_IF_VER 56 144#define ACT_IF_VER 56
149#define ACT_CMD 100 145#define ACT_CMD 100
150 146
151/* at command sequences */ 147/* at command sequences */
152#define SEQ_NONE 0 148#define SEQ_NONE 0
153#define SEQ_INIT 100 149#define SEQ_INIT 100
154#define SEQ_DLE0 200 150#define SEQ_DLE0 200
155#define SEQ_DLE1 250 151#define SEQ_DLE1 250
156#define SEQ_CID 300 152#define SEQ_CID 300
157#define SEQ_NOCID 350 153#define SEQ_NOCID 350
158#define SEQ_HUP 400 154#define SEQ_HUP 400
159#define SEQ_DIAL 600 155#define SEQ_DIAL 600
160#define SEQ_ACCEPT 720 156#define SEQ_ACCEPT 720
161#define SEQ_SHUTDOWN 500 157#define SEQ_SHUTDOWN 500
162#define SEQ_CIDMODE 10 158#define SEQ_CIDMODE 10
163#define SEQ_UMMODE 11 159#define SEQ_UMMODE 11
164 160
165 161
166// 100: init, 200: dle0, 250:dle1, 300: get cid (dial), 350: "hup" (no cid), 400: hup, 500: reset, 600: dial, 700: ring 162// 100: init, 200: dle0, 250:dle1, 300: get cid (dial), 350: "hup" (no cid), 400: hup, 500: reset, 600: dial, 700: ring
@@ -175,7 +171,7 @@ struct reply_t gigaset_tab_nocid_m10x[]= /* with dle mode */
175 // {ACT_TIMEOUT}}, 171 // {ACT_TIMEOUT}},
176 172
177 {RSP_INIT, -1, -1,SEQ_INIT, 100, INIT_TIMEOUT, 173 {RSP_INIT, -1, -1,SEQ_INIT, 100, INIT_TIMEOUT,
178 {ACT_TIMEOUT}}, /* wait until device is ready */ 174 {ACT_TIMEOUT}}, /* wait until device is ready */
179 175
180 {EV_TIMEOUT, 100,100, -1, 101, 3, {0}, "Z\r"}, /* device in transparent mode? try to initialize it. */ 176 {EV_TIMEOUT, 100,100, -1, 101, 3, {0}, "Z\r"}, /* device in transparent mode? try to initialize it. */
181 {RSP_OK, 101,103, -1, 120, 5, {ACT_GETSTRING}, "+GMR\r"}, /* get version */ 177 {RSP_OK, 101,103, -1, 120, 5, {ACT_GETSTRING}, "+GMR\r"}, /* get version */
@@ -190,8 +186,8 @@ struct reply_t gigaset_tab_nocid_m10x[]= /* with dle mode */
190 {RSP_ERROR, 108,108, -1, 0, 0, {ACT_FAILINIT}}, 186 {RSP_ERROR, 108,108, -1, 0, 0, {ACT_FAILINIT}},
191 187
192 {EV_TIMEOUT, 108,108, -1, 105, 2, {ACT_SETDLE0, 188 {EV_TIMEOUT, 108,108, -1, 105, 2, {ACT_SETDLE0,
193 ACT_HUPMODEM, 189 ACT_HUPMODEM,
194 ACT_TIMEOUT}}, /* still timeout => connection in unimodem mode? */ 190 ACT_TIMEOUT}}, /* still timeout => connection in unimodem mode? */
195 {EV_TIMEOUT, 105,105, -1, 103, 5, {0}, "Z\r"}, 191 {EV_TIMEOUT, 105,105, -1, 103, 5, {0}, "Z\r"},
196 192
197 {RSP_ERROR, 102,102, -1, 107, 5, {0}, "^GETPRE\r"}, /* ERROR on ATZ => maybe in config mode? */ 193 {RSP_ERROR, 102,102, -1, 107, 5, {0}, "^GETPRE\r"}, /* ERROR on ATZ => maybe in config mode? */
@@ -393,7 +389,7 @@ struct reply_t gigaset_tab_cid_m10x[] = /* for M10x */
393 389
394 390
395#if 0 391#if 0
396static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME aenderungen uebernehmen 392static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME
397{ 393{
398 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */ 394 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
399 395
@@ -401,7 +397,7 @@ static struct reply_t tab_nocid[]= /* no dle mode */ //FIXME aenderungen ueberne
401 {RSP_LAST,0,0,0,0,0,0} 397 {RSP_LAST,0,0,0,0,0,0}
402}; 398};
403 399
404static struct reply_t tab_cid[] = /* no dle mode */ //FIXME aenderungen uebernehmen 400static struct reply_t tab_cid[] = /* no dle mode */ //FIXME
405{ 401{
406 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */ 402 /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, action, command */
407 403
@@ -412,30 +408,30 @@ static struct reply_t tab_cid[] = /* no dle mode */ //FIXME aenderungen ueberneh
412 408
413static struct resp_type_t resp_type[]= 409static struct resp_type_t resp_type[]=
414{ 410{
415 /*{"", RSP_EMPTY, RT_NOTHING},*/ 411 /*{"", RSP_EMPTY, RT_NOTHING},*/
416 {"OK", RSP_OK, RT_NOTHING}, 412 {"OK", RSP_OK, RT_NOTHING},
417 {"ERROR", RSP_ERROR, RT_NOTHING}, 413 {"ERROR", RSP_ERROR, RT_NOTHING},
418 {"ZSAU", RSP_ZSAU, RT_ZSAU}, 414 {"ZSAU", RSP_ZSAU, RT_ZSAU},
419 {"ZCAU", RSP_ZCAU, RT_ZCAU}, 415 {"ZCAU", RSP_ZCAU, RT_ZCAU},
420 {"RING", RSP_RING, RT_RING}, 416 {"RING", RSP_RING, RT_RING},
421 {"ZGCI", RSP_ZGCI, RT_NUMBER}, 417 {"ZGCI", RSP_ZGCI, RT_NUMBER},
422 {"ZVLS", RSP_ZVLS, RT_NUMBER}, 418 {"ZVLS", RSP_ZVLS, RT_NUMBER},
423 {"ZCTP", RSP_ZCTP, RT_NUMBER}, 419 {"ZCTP", RSP_ZCTP, RT_NUMBER},
424 {"ZDLE", RSP_ZDLE, RT_NUMBER}, 420 {"ZDLE", RSP_ZDLE, RT_NUMBER},
425 {"ZCFGT", RSP_ZCFGT, RT_NUMBER}, 421 {"ZCFGT", RSP_ZCFGT, RT_NUMBER},
426 {"ZCCR", RSP_ZCCR, RT_NUMBER}, 422 {"ZCCR", RSP_ZCCR, RT_NUMBER},
427 {"ZMWI", RSP_ZMWI, RT_NUMBER}, 423 {"ZMWI", RSP_ZMWI, RT_NUMBER},
428 {"ZHLC", RSP_ZHLC, RT_STRING}, 424 {"ZHLC", RSP_ZHLC, RT_STRING},
429 {"ZBC", RSP_ZBC, RT_STRING}, 425 {"ZBC", RSP_ZBC, RT_STRING},
430 {"NMBR", RSP_NMBR, RT_STRING}, 426 {"NMBR", RSP_NMBR, RT_STRING},
431 {"ZCPN", RSP_ZCPN, RT_STRING}, 427 {"ZCPN", RSP_ZCPN, RT_STRING},
432 {"ZCON", RSP_ZCON, RT_STRING}, 428 {"ZCON", RSP_ZCON, RT_STRING},
433 {"ZAOC", RSP_ZAOC, RT_STRING}, 429 {"ZAOC", RSP_ZAOC, RT_STRING},
434 {"ZCSTR", RSP_ZCSTR, RT_STRING}, 430 {"ZCSTR", RSP_ZCSTR, RT_STRING},
435 {"ZCFG", RSP_ZCFG, RT_HEX}, 431 {"ZCFG", RSP_ZCFG, RT_HEX},
436 {"ZLOG", RSP_ZLOG, RT_NOTHING}, 432 {"ZLOG", RSP_ZLOG, RT_NOTHING},
437 {"ZABINFO", RSP_ZABINFO, RT_NOTHING}, 433 {"ZABINFO", RSP_ZABINFO, RT_NOTHING},
438 {"ZSMLSTCHG", RSP_ZSMLSTCHG, RT_NOTHING}, 434 {"ZSMLSTCHG", RSP_ZSMLSTCHG, RT_NOTHING},
439 {NULL,0,0} 435 {NULL,0,0}
440}; 436};
441 437
@@ -446,9 +442,7 @@ static int isdn_getnum(char *p)
446{ 442{
447 int v = -1; 443 int v = -1;
448 444
449 IFNULLRETVAL(p, -1); 445 gig_dbg(DEBUG_TRANSCMD, "string: %s", p);
450
451 dbg(DEBUG_TRANSCMD, "string: %s", p);
452 446
453 while (*p >= '0' && *p <= '9') 447 while (*p >= '0' && *p <= '9')
454 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0'); 448 v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0');
@@ -465,9 +459,7 @@ static int isdn_gethex(char *p)
465 int v = 0; 459 int v = 0;
466 int c; 460 int c;
467 461
468 IFNULLRETVAL(p, -1); 462 gig_dbg(DEBUG_TRANSCMD, "string: %s", p);
469
470 dbg(DEBUG_TRANSCMD, "string: %s", p);
471 463
472 if (!*p) 464 if (!*p)
473 return -1; 465 return -1;
@@ -490,14 +482,6 @@ static int isdn_gethex(char *p)
490 return v; 482 return v;
491} 483}
492 484
493static inline void new_index(atomic_t *index, int max)
494{
495 if (atomic_read(index) == max) //FIXME race?
496 atomic_set(index, 0);
497 else
498 atomic_inc(index);
499}
500
501/* retrieve CID from parsed response 485/* retrieve CID from parsed response
502 * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535 486 * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535
503 */ 487 */
@@ -536,16 +520,14 @@ void gigaset_handle_modem_response(struct cardstate *cs)
536 int cid; 520 int cid;
537 int rawstring; 521 int rawstring;
538 522
539 IFNULLRET(cs);
540
541 len = cs->cbytes; 523 len = cs->cbytes;
542 if (!len) { 524 if (!len) {
543 /* ignore additional LFs/CRs (M10x config mode or cx100) */ 525 /* ignore additional LFs/CRs (M10x config mode or cx100) */
544 dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[len]); 526 gig_dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[len]);
545 return; 527 return;
546 } 528 }
547 cs->respdata[len] = 0; 529 cs->respdata[len] = 0;
548 dbg(DEBUG_TRANSCMD, "raw string: '%s'", cs->respdata); 530 gig_dbg(DEBUG_TRANSCMD, "raw string: '%s'", cs->respdata);
549 argv[0] = cs->respdata; 531 argv[0] = cs->respdata;
550 params = 1; 532 params = 1;
551 if (cs->at_state.getstring) { 533 if (cs->at_state.getstring) {
@@ -561,7 +543,8 @@ void gigaset_handle_modem_response(struct cardstate *cs)
561 case ',': 543 case ',':
562 case '=': 544 case '=':
563 if (params > MAX_REC_PARAMS) { 545 if (params > MAX_REC_PARAMS) {
564 warn("too many parameters in response"); 546 dev_warn(cs->dev,
547 "too many parameters in response\n");
565 /* need last parameter (might be CID) */ 548 /* need last parameter (might be CID) */
566 params--; 549 params--;
567 } 550 }
@@ -572,33 +555,33 @@ void gigaset_handle_modem_response(struct cardstate *cs)
572 cid = params > 1 ? cid_of_response(argv[params-1]) : 0; 555 cid = params > 1 ? cid_of_response(argv[params-1]) : 0;
573 if (cid < 0) { 556 if (cid < 0) {
574 gigaset_add_event(cs, &cs->at_state, RSP_INVAL, 557 gigaset_add_event(cs, &cs->at_state, RSP_INVAL,
575 NULL, 0, NULL); 558 NULL, 0, NULL);
576 return; 559 return;
577 } 560 }
578 561
579 for (j = 1; j < params; ++j) 562 for (j = 1; j < params; ++j)
580 argv[j][-1] = 0; 563 argv[j][-1] = 0;
581 564
582 dbg(DEBUG_TRANSCMD, "CMD received: %s", argv[0]); 565 gig_dbg(DEBUG_TRANSCMD, "CMD received: %s", argv[0]);
583 if (cid) { 566 if (cid) {
584 --params; 567 --params;
585 dbg(DEBUG_TRANSCMD, "CID: %s", argv[params]); 568 gig_dbg(DEBUG_TRANSCMD, "CID: %s", argv[params]);
586 } 569 }
587 dbg(DEBUG_TRANSCMD, "available params: %d", params - 1); 570 gig_dbg(DEBUG_TRANSCMD, "available params: %d", params - 1);
588 for (j = 1; j < params; j++) 571 for (j = 1; j < params; j++)
589 dbg(DEBUG_TRANSCMD, "param %d: %s", j, argv[j]); 572 gig_dbg(DEBUG_TRANSCMD, "param %d: %s", j, argv[j]);
590 } 573 }
591 574
592 spin_lock_irqsave(&cs->ev_lock, flags); 575 spin_lock_irqsave(&cs->ev_lock, flags);
593 head = atomic_read(&cs->ev_head); 576 head = cs->ev_head;
594 tail = atomic_read(&cs->ev_tail); 577 tail = cs->ev_tail;
595 578
596 abort = 1; 579 abort = 1;
597 curarg = 0; 580 curarg = 0;
598 while (curarg < params) { 581 while (curarg < params) {
599 next = (tail + 1) % MAX_EVENTS; 582 next = (tail + 1) % MAX_EVENTS;
600 if (unlikely(next == head)) { 583 if (unlikely(next == head)) {
601 err("event queue full"); 584 dev_err(cs->dev, "event queue full\n");
602 break; 585 break;
603 } 586 }
604 587
@@ -619,8 +602,9 @@ void gigaset_handle_modem_response(struct cardstate *cs)
619 602
620 if (!rt->response) { 603 if (!rt->response) {
621 event->type = RSP_UNKNOWN; 604 event->type = RSP_UNKNOWN;
622 warn("unknown modem response: %s", 605 dev_warn(cs->dev,
623 argv[curarg]); 606 "unknown modem response: %s\n",
607 argv[curarg]);
624 break; 608 break;
625 } 609 }
626 610
@@ -636,7 +620,8 @@ void gigaset_handle_modem_response(struct cardstate *cs)
636 break; 620 break;
637 case RT_RING: 621 case RT_RING:
638 if (!cid) { 622 if (!cid) {
639 err("received RING without CID!"); 623 dev_err(cs->dev,
624 "received RING without CID!\n");
640 event->type = RSP_INVAL; 625 event->type = RSP_INVAL;
641 abort = 1; 626 abort = 1;
642 } else { 627 } else {
@@ -664,27 +649,25 @@ void gigaset_handle_modem_response(struct cardstate *cs)
664 event->parameter = ZSAU_DISCONNECT_REQ; 649 event->parameter = ZSAU_DISCONNECT_REQ;
665 else { 650 else {
666 event->parameter = ZSAU_UNKNOWN; 651 event->parameter = ZSAU_UNKNOWN;
667 warn("%s: unknown parameter %s after ZSAU", 652 dev_warn(cs->dev,
668 __func__, argv[curarg]); 653 "%s: unknown parameter %s after ZSAU\n",
654 __func__, argv[curarg]);
669 } 655 }
670 ++curarg; 656 ++curarg;
671 break; 657 break;
672 case RT_STRING: 658 case RT_STRING:
673 if (curarg < params) { 659 if (curarg < params) {
674 len = strlen(argv[curarg]) + 1; 660 event->ptr = kstrdup(argv[curarg], GFP_ATOMIC);
675 event->ptr = kmalloc(len, GFP_ATOMIC); 661 if (!event->ptr)
676 if (event->ptr) 662 dev_err(cs->dev, "out of memory\n");
677 memcpy(event->ptr, argv[curarg], len);
678 else
679 err("no memory for string!");
680 ++curarg; 663 ++curarg;
681 } 664 }
682#ifdef CONFIG_GIGASET_DEBUG 665#ifdef CONFIG_GIGASET_DEBUG
683 if (!event->ptr) 666 if (!event->ptr)
684 dbg(DEBUG_CMD, "string==NULL"); 667 gig_dbg(DEBUG_CMD, "string==NULL");
685 else 668 else
686 dbg(DEBUG_CMD, 669 gig_dbg(DEBUG_CMD, "string==%s",
687 "string==%s", (char *) event->ptr); 670 (char *) event->ptr);
688#endif 671#endif
689 break; 672 break;
690 case RT_ZCAU: 673 case RT_ZCAU:
@@ -694,7 +677,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
694 j = isdn_gethex(argv[curarg + 1]); 677 j = isdn_gethex(argv[curarg + 1]);
695 if (i >= 0 && i < 256 && j >= 0 && j < 256) 678 if (i >= 0 && i < 256 && j >= 0 && j < 256)
696 event->parameter = (unsigned) i << 8 679 event->parameter = (unsigned) i << 8
697 | j; 680 | j;
698 curarg += 2; 681 curarg += 2;
699 } else 682 } else
700 curarg = params - 1; 683 curarg = params - 1;
@@ -712,7 +695,7 @@ void gigaset_handle_modem_response(struct cardstate *cs)
712 } else 695 } else
713 event->parameter = -1; 696 event->parameter = -1;
714#ifdef CONFIG_GIGASET_DEBUG 697#ifdef CONFIG_GIGASET_DEBUG
715 dbg(DEBUG_CMD, "parameter==%d", event->parameter); 698 gig_dbg(DEBUG_CMD, "parameter==%d", event->parameter);
716#endif 699#endif
717 break; 700 break;
718 } 701 }
@@ -724,12 +707,13 @@ void gigaset_handle_modem_response(struct cardstate *cs)
724 break; 707 break;
725 } 708 }
726 709
727 atomic_set(&cs->ev_tail, tail); 710 cs->ev_tail = tail;
728 spin_unlock_irqrestore(&cs->ev_lock, flags); 711 spin_unlock_irqrestore(&cs->ev_lock, flags);
729 712
730 if (curarg != params) 713 if (curarg != params)
731 dbg(DEBUG_ANY, "invalid number of processed parameters: %d/%d", 714 gig_dbg(DEBUG_ANY,
732 curarg, params); 715 "invalid number of processed parameters: %d/%d",
716 curarg, params);
733} 717}
734EXPORT_SYMBOL_GPL(gigaset_handle_modem_response); 718EXPORT_SYMBOL_GPL(gigaset_handle_modem_response);
735 719
@@ -739,23 +723,19 @@ EXPORT_SYMBOL_GPL(gigaset_handle_modem_response);
739static void disconnect(struct at_state_t **at_state_p) 723static void disconnect(struct at_state_t **at_state_p)
740{ 724{
741 unsigned long flags; 725 unsigned long flags;
742 struct bc_state *bcs; 726 struct bc_state *bcs = (*at_state_p)->bcs;
743 struct cardstate *cs; 727 struct cardstate *cs = (*at_state_p)->cs;
744 728
745 IFNULLRET(at_state_p); 729 spin_lock_irqsave(&cs->lock, flags);
746 IFNULLRET(*at_state_p); 730 ++(*at_state_p)->seq_index;
747 bcs = (*at_state_p)->bcs;
748 cs = (*at_state_p)->cs;
749 IFNULLRET(cs);
750
751 new_index(&(*at_state_p)->seq_index, MAX_SEQ_INDEX);
752 731
753 /* revert to selected idle mode */ 732 /* revert to selected idle mode */
754 if (!atomic_read(&cs->cidmode)) { 733 if (!cs->cidmode) {
755 cs->at_state.pending_commands |= PC_UMMODE; 734 cs->at_state.pending_commands |= PC_UMMODE;
756 atomic_set(&cs->commands_pending, 1); //FIXME 735 atomic_set(&cs->commands_pending, 1); //FIXME
757 dbg(DEBUG_CMD, "Scheduling PC_UMMODE"); 736 gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
758 } 737 }
738 spin_unlock_irqrestore(&cs->lock, flags);
759 739
760 if (bcs) { 740 if (bcs) {
761 /* B channel assigned: invoke hardware specific handler */ 741 /* B channel assigned: invoke hardware specific handler */
@@ -777,7 +757,7 @@ static void disconnect(struct at_state_t **at_state_p)
777 * The structure should be freed by calling disconnect() after use. 757 * The structure should be freed by calling disconnect() after use.
778 */ 758 */
779static inline struct at_state_t *get_free_channel(struct cardstate *cs, 759static inline struct at_state_t *get_free_channel(struct cardstate *cs,
780 int cid) 760 int cid)
781/* cids: >0: siemens-cid 761/* cids: >0: siemens-cid
782 0: without cid 762 0: without cid
783 -1: no cid assigned yet 763 -1: no cid assigned yet
@@ -826,7 +806,7 @@ static void init_failed(struct cardstate *cs, int mode)
826static void schedule_init(struct cardstate *cs, int state) 806static void schedule_init(struct cardstate *cs, int state)
827{ 807{
828 if (cs->at_state.pending_commands & PC_INIT) { 808 if (cs->at_state.pending_commands & PC_INIT) {
829 dbg(DEBUG_CMD, "not scheduling PC_INIT again"); 809 gig_dbg(DEBUG_CMD, "not scheduling PC_INIT again");
830 return; 810 return;
831 } 811 }
832 atomic_set(&cs->mstate, state); 812 atomic_set(&cs->mstate, state);
@@ -834,52 +814,56 @@ static void schedule_init(struct cardstate *cs, int state)
834 gigaset_block_channels(cs); 814 gigaset_block_channels(cs);
835 cs->at_state.pending_commands |= PC_INIT; 815 cs->at_state.pending_commands |= PC_INIT;
836 atomic_set(&cs->commands_pending, 1); 816 atomic_set(&cs->commands_pending, 1);
837 dbg(DEBUG_CMD, "Scheduling PC_INIT"); 817 gig_dbg(DEBUG_CMD, "Scheduling PC_INIT");
838} 818}
839 819
840/* Add "AT" to a command, add the cid, dle encode it, send the result to the hardware. */ 820/* Add "AT" to a command, add the cid, dle encode it, send the result to the
821 hardware. */
841static void send_command(struct cardstate *cs, const char *cmd, int cid, 822static void send_command(struct cardstate *cs, const char *cmd, int cid,
842 int dle, gfp_t kmallocflags) 823 int dle, gfp_t kmallocflags)
843{ 824{
844 size_t cmdlen, buflen; 825 size_t cmdlen, buflen;
845 char *cmdpos, *cmdbuf, *cmdtail; 826 char *cmdpos, *cmdbuf, *cmdtail;
846 827
847 cmdlen = strlen(cmd); 828 cmdlen = strlen(cmd);
848 buflen = 11 + cmdlen; 829 buflen = 11 + cmdlen;
830 if (unlikely(buflen <= cmdlen)) {
831 dev_err(cs->dev, "integer overflow in buflen\n");
832 return;
833 }
849 834
850 if (likely(buflen > cmdlen)) { 835 cmdbuf = kmalloc(buflen, kmallocflags);
851 cmdbuf = kmalloc(buflen, kmallocflags); 836 if (unlikely(!cmdbuf)) {
852 if (likely(cmdbuf != NULL)) { 837 dev_err(cs->dev, "out of memory\n");
853 cmdpos = cmdbuf + 9; 838 return;
854 cmdtail = cmdpos + cmdlen; 839 }
855 memcpy(cmdpos, cmd, cmdlen);
856
857 if (cid > 0 && cid <= 65535) {
858 do {
859 *--cmdpos = '0' + cid % 10;
860 cid /= 10;
861 ++cmdlen;
862 } while (cid);
863 }
864 840
865 cmdlen += 2; 841 cmdpos = cmdbuf + 9;
866 *--cmdpos = 'T'; 842 cmdtail = cmdpos + cmdlen;
867 *--cmdpos = 'A'; 843 memcpy(cmdpos, cmd, cmdlen);
868 844
869 if (dle) { 845 if (cid > 0 && cid <= 65535) {
870 cmdlen += 4; 846 do {
871 *--cmdpos = '('; 847 *--cmdpos = '0' + cid % 10;
872 *--cmdpos = 0x10; 848 cid /= 10;
873 *cmdtail++ = 0x10; 849 ++cmdlen;
874 *cmdtail++ = ')'; 850 } while (cid);
875 } 851 }
876 852
877 cs->ops->write_cmd(cs, cmdpos, cmdlen, NULL); 853 cmdlen += 2;
878 kfree(cmdbuf); 854 *--cmdpos = 'T';
879 } else 855 *--cmdpos = 'A';
880 err("no memory for command buffer"); 856
881 } else 857 if (dle) {
882 err("overflow in buflen"); 858 cmdlen += 4;
859 *--cmdpos = '(';
860 *--cmdpos = 0x10;
861 *cmdtail++ = 0x10;
862 *cmdtail++ = ')';
863 }
864
865 cs->ops->write_cmd(cs, cmdpos, cmdlen, NULL);
866 kfree(cmdbuf);
883} 867}
884 868
885static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid) 869static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid)
@@ -910,9 +894,6 @@ static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid)
910 894
911static void bchannel_down(struct bc_state *bcs) 895static void bchannel_down(struct bc_state *bcs)
912{ 896{
913 IFNULLRET(bcs);
914 IFNULLRET(bcs->cs);
915
916 if (bcs->chstate & CHS_B_UP) { 897 if (bcs->chstate & CHS_B_UP) {
917 bcs->chstate &= ~CHS_B_UP; 898 bcs->chstate &= ~CHS_B_UP;
918 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP); 899 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BHUP);
@@ -930,16 +911,15 @@ static void bchannel_down(struct bc_state *bcs)
930 911
931static void bchannel_up(struct bc_state *bcs) 912static void bchannel_up(struct bc_state *bcs)
932{ 913{
933 IFNULLRET(bcs);
934
935 if (!(bcs->chstate & CHS_D_UP)) { 914 if (!(bcs->chstate & CHS_D_UP)) {
936 notice("%s: D channel not up", __func__); 915 dev_notice(bcs->cs->dev, "%s: D channel not up\n", __func__);
937 bcs->chstate |= CHS_D_UP; 916 bcs->chstate |= CHS_D_UP;
938 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN); 917 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_DCONN);
939 } 918 }
940 919
941 if (bcs->chstate & CHS_B_UP) { 920 if (bcs->chstate & CHS_B_UP) {
942 notice("%s: B channel already up", __func__); 921 dev_notice(bcs->cs->dev, "%s: B channel already up\n",
922 __func__);
943 return; 923 return;
944 } 924 }
945 925
@@ -947,17 +927,21 @@ static void bchannel_up(struct bc_state *bcs)
947 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN); 927 gigaset_i4l_channel_cmd(bcs, ISDN_STAT_BCONN);
948} 928}
949 929
950static void start_dial(struct at_state_t *at_state, void *data, int seq_index) 930static void start_dial(struct at_state_t *at_state, void *data, unsigned seq_index)
951{ 931{
952 struct bc_state *bcs = at_state->bcs; 932 struct bc_state *bcs = at_state->bcs;
953 struct cardstate *cs = at_state->cs; 933 struct cardstate *cs = at_state->cs;
954 int retval; 934 int retval;
935 unsigned long flags;
955 936
956 bcs->chstate |= CHS_NOTIFY_LL; 937 bcs->chstate |= CHS_NOTIFY_LL;
957 //atomic_set(&bcs->status, BCS_INIT);
958 938
959 if (atomic_read(&at_state->seq_index) != seq_index) 939 spin_lock_irqsave(&cs->lock, flags);
940 if (at_state->seq_index != seq_index) {
941 spin_unlock_irqrestore(&cs->lock, flags);
960 goto error; 942 goto error;
943 }
944 spin_unlock_irqrestore(&cs->lock, flags);
961 945
962 retval = gigaset_isdn_setup_dial(at_state, data); 946 retval = gigaset_isdn_setup_dial(at_state, data);
963 if (retval != 0) 947 if (retval != 0)
@@ -965,20 +949,14 @@ static void start_dial(struct at_state_t *at_state, void *data, int seq_index)
965 949
966 950
967 at_state->pending_commands |= PC_CID; 951 at_state->pending_commands |= PC_CID;
968 dbg(DEBUG_CMD, "Scheduling PC_CID"); 952 gig_dbg(DEBUG_CMD, "Scheduling PC_CID");
969//#ifdef GIG_MAYINITONDIAL 953 atomic_set(&cs->commands_pending, 1);
970// if (atomic_read(&cs->MState) == MS_UNKNOWN) {
971// cs->at_state.pending_commands |= PC_INIT;
972// dbg(DEBUG_CMD, "Scheduling PC_INIT");
973// }
974//#endif
975 atomic_set(&cs->commands_pending, 1); //FIXME
976 return; 954 return;
977 955
978error: 956error:
979 at_state->pending_commands |= PC_NOCID; 957 at_state->pending_commands |= PC_NOCID;
980 dbg(DEBUG_CMD, "Scheduling PC_NOCID"); 958 gig_dbg(DEBUG_CMD, "Scheduling PC_NOCID");
981 atomic_set(&cs->commands_pending, 1); //FIXME 959 atomic_set(&cs->commands_pending, 1);
982 return; 960 return;
983} 961}
984 962
@@ -991,13 +969,13 @@ static void start_accept(struct at_state_t *at_state)
991 969
992 if (retval == 0) { 970 if (retval == 0) {
993 at_state->pending_commands |= PC_ACCEPT; 971 at_state->pending_commands |= PC_ACCEPT;
994 dbg(DEBUG_CMD, "Scheduling PC_ACCEPT"); 972 gig_dbg(DEBUG_CMD, "Scheduling PC_ACCEPT");
995 atomic_set(&cs->commands_pending, 1); //FIXME 973 atomic_set(&cs->commands_pending, 1);
996 } else { 974 } else {
997 //FIXME 975 //FIXME
998 at_state->pending_commands |= PC_HUP; 976 at_state->pending_commands |= PC_HUP;
999 dbg(DEBUG_CMD, "Scheduling PC_HUP"); 977 gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
1000 atomic_set(&cs->commands_pending, 1); //FIXME 978 atomic_set(&cs->commands_pending, 1);
1001 } 979 }
1002} 980}
1003 981
@@ -1008,9 +986,10 @@ static void do_start(struct cardstate *cs)
1008 if (atomic_read(&cs->mstate) != MS_LOCKED) 986 if (atomic_read(&cs->mstate) != MS_LOCKED)
1009 schedule_init(cs, MS_INIT); 987 schedule_init(cs, MS_INIT);
1010 988
989 cs->isdn_up = 1;
1011 gigaset_i4l_cmd(cs, ISDN_STAT_RUN); 990 gigaset_i4l_cmd(cs, ISDN_STAT_RUN);
1012 // FIXME: not in locked mode 991 // FIXME: not in locked mode
1013 // FIXME 2: only after init sequence 992 // FIXME 2: only after init sequence
1014 993
1015 cs->waiting = 0; 994 cs->waiting = 0;
1016 wake_up(&cs->waitqueue); 995 wake_up(&cs->waitqueue);
@@ -1023,6 +1002,12 @@ static void finish_shutdown(struct cardstate *cs)
1023 atomic_set(&cs->mode, M_UNKNOWN); 1002 atomic_set(&cs->mode, M_UNKNOWN);
1024 } 1003 }
1025 1004
1005 /* Tell the LL that the device is not available .. */
1006 if (cs->isdn_up) {
1007 cs->isdn_up = 0;
1008 gigaset_i4l_cmd(cs, ISDN_STAT_STOP);
1009 }
1010
1026 /* The rest is done by cleanup_cs () in user mode. */ 1011 /* The rest is done by cleanup_cs () in user mode. */
1027 1012
1028 cs->cmd_result = -ENODEV; 1013 cs->cmd_result = -ENODEV;
@@ -1037,15 +1022,20 @@ static void do_shutdown(struct cardstate *cs)
1037 if (atomic_read(&cs->mstate) == MS_READY) { 1022 if (atomic_read(&cs->mstate) == MS_READY) {
1038 atomic_set(&cs->mstate, MS_SHUTDOWN); 1023 atomic_set(&cs->mstate, MS_SHUTDOWN);
1039 cs->at_state.pending_commands |= PC_SHUTDOWN; 1024 cs->at_state.pending_commands |= PC_SHUTDOWN;
1040 atomic_set(&cs->commands_pending, 1); //FIXME 1025 atomic_set(&cs->commands_pending, 1);
1041 dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN"); //FIXME 1026 gig_dbg(DEBUG_CMD, "Scheduling PC_SHUTDOWN");
1042 //gigaset_schedule_event(cs); //FIXME
1043 } else 1027 } else
1044 finish_shutdown(cs); 1028 finish_shutdown(cs);
1045} 1029}
1046 1030
1047static void do_stop(struct cardstate *cs) 1031static void do_stop(struct cardstate *cs)
1048{ 1032{
1033 unsigned long flags;
1034
1035 spin_lock_irqsave(&cs->lock, flags);
1036 cs->connected = 0;
1037 spin_unlock_irqrestore(&cs->lock, flags);
1038
1049 do_shutdown(cs); 1039 do_shutdown(cs);
1050} 1040}
1051 1041
@@ -1069,9 +1059,11 @@ static int reinit_and_retry(struct cardstate *cs, int channel)
1069 return 0; 1059 return 0;
1070 1060
1071 if (channel < 0) 1061 if (channel < 0)
1072 warn("Could not enter cid mode. Reinit device and try again."); 1062 dev_warn(cs->dev,
1063 "Could not enter cid mode. Reinit device and try again.\n");
1073 else { 1064 else {
1074 warn("Could not get a call id. Reinit device and try again."); 1065 dev_warn(cs->dev,
1066 "Could not get a call id. Reinit device and try again.\n");
1075 cs->bcs[channel].at_state.pending_commands |= PC_CID; 1067 cs->bcs[channel].at_state.pending_commands |= PC_CID;
1076 } 1068 }
1077 schedule_init(cs, MS_INIT); 1069 schedule_init(cs, MS_INIT);
@@ -1079,7 +1071,7 @@ static int reinit_and_retry(struct cardstate *cs, int channel)
1079} 1071}
1080 1072
1081static int at_state_invalid(struct cardstate *cs, 1073static int at_state_invalid(struct cardstate *cs,
1082 struct at_state_t *test_ptr) 1074 struct at_state_t *test_ptr)
1083{ 1075{
1084 unsigned long flags; 1076 unsigned long flags;
1085 unsigned channel; 1077 unsigned channel;
@@ -1116,7 +1108,7 @@ static void handle_icall(struct cardstate *cs, struct bc_state *bcs,
1116 case ICALL_ACCEPT: 1108 case ICALL_ACCEPT:
1117 break; 1109 break;
1118 default: 1110 default:
1119 err("internal error: disposition=%d", retval); 1111 dev_err(cs->dev, "internal error: disposition=%d\n", retval);
1120 /* --v-- fall through --v-- */ 1112 /* --v-- fall through --v-- */
1121 case ICALL_IGNORE: 1113 case ICALL_IGNORE:
1122 case ICALL_REJECT: 1114 case ICALL_REJECT:
@@ -1160,7 +1152,6 @@ static int do_lock(struct cardstate *cs)
1160 mode = atomic_read(&cs->mode); 1152 mode = atomic_read(&cs->mode);
1161 atomic_set(&cs->mstate, MS_LOCKED); 1153 atomic_set(&cs->mstate, MS_LOCKED);
1162 atomic_set(&cs->mode, M_UNKNOWN); 1154 atomic_set(&cs->mode, M_UNKNOWN);
1163 //FIXME reset card state / at states / bcs states
1164 1155
1165 return mode; 1156 return mode;
1166} 1157}
@@ -1173,8 +1164,7 @@ static int do_unlock(struct cardstate *cs)
1173 atomic_set(&cs->mstate, MS_UNINITIALIZED); 1164 atomic_set(&cs->mstate, MS_UNINITIALIZED);
1174 atomic_set(&cs->mode, M_UNKNOWN); 1165 atomic_set(&cs->mode, M_UNKNOWN);
1175 gigaset_free_channels(cs); 1166 gigaset_free_channels(cs);
1176 //FIXME reset card state / at states / bcs states 1167 if (cs->connected)
1177 if (atomic_read(&cs->connected))
1178 schedule_init(cs, MS_INIT); 1168 schedule_init(cs, MS_INIT);
1179 1169
1180 return 0; 1170 return 0;
@@ -1203,21 +1193,23 @@ static void do_action(int action, struct cardstate *cs,
1203 at_state->waiting = 1; 1193 at_state->waiting = 1;
1204 break; 1194 break;
1205 case ACT_INIT: 1195 case ACT_INIT:
1206 //FIXME setup everything
1207 cs->at_state.pending_commands &= ~PC_INIT; 1196 cs->at_state.pending_commands &= ~PC_INIT;
1208 cs->cur_at_seq = SEQ_NONE; 1197 cs->cur_at_seq = SEQ_NONE;
1209 atomic_set(&cs->mode, M_UNIMODEM); 1198 atomic_set(&cs->mode, M_UNIMODEM);
1210 if (!atomic_read(&cs->cidmode)) { 1199 spin_lock_irqsave(&cs->lock, flags);
1200 if (!cs->cidmode) {
1201 spin_unlock_irqrestore(&cs->lock, flags);
1211 gigaset_free_channels(cs); 1202 gigaset_free_channels(cs);
1212 atomic_set(&cs->mstate, MS_READY); 1203 atomic_set(&cs->mstate, MS_READY);
1213 break; 1204 break;
1214 } 1205 }
1206 spin_unlock_irqrestore(&cs->lock, flags);
1215 cs->at_state.pending_commands |= PC_CIDMODE; 1207 cs->at_state.pending_commands |= PC_CIDMODE;
1216 atomic_set(&cs->commands_pending, 1); //FIXME 1208 atomic_set(&cs->commands_pending, 1);
1217 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); 1209 gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1218 break; 1210 break;
1219 case ACT_FAILINIT: 1211 case ACT_FAILINIT:
1220 warn("Could not initialize the device."); 1212 dev_warn(cs->dev, "Could not initialize the device.\n");
1221 cs->dle = 0; 1213 cs->dle = 0;
1222 init_failed(cs, M_UNKNOWN); 1214 init_failed(cs, M_UNKNOWN);
1223 cs->cur_at_seq = SEQ_NONE; 1215 cs->cur_at_seq = SEQ_NONE;
@@ -1273,8 +1265,8 @@ static void do_action(int action, struct cardstate *cs,
1273 /* get fresh AT state structure for new CID */ 1265 /* get fresh AT state structure for new CID */
1274 at_state2 = get_free_channel(cs, ev->parameter); 1266 at_state2 = get_free_channel(cs, ev->parameter);
1275 if (!at_state2) { 1267 if (!at_state2) {
1276 warn("RING ignored: " 1268 dev_warn(cs->dev,
1277 "could not allocate channel structure"); 1269 "RING ignored: could not allocate channel structure\n");
1278 break; 1270 break;
1279 } 1271 }
1280 1272
@@ -1302,7 +1294,7 @@ static void do_action(int action, struct cardstate *cs,
1302 at_state = *p_at_state; 1294 at_state = *p_at_state;
1303 break; 1295 break;
1304 case ACT_FAILSDOWN: 1296 case ACT_FAILSDOWN:
1305 warn("Could not shut down the device."); 1297 dev_warn(cs->dev, "Could not shut down the device.\n");
1306 /* fall through */ 1298 /* fall through */
1307 case ACT_FAKESDOWN: 1299 case ACT_FAKESDOWN:
1308 case ACT_SDOWN: 1300 case ACT_SDOWN:
@@ -1355,7 +1347,7 @@ static void do_action(int action, struct cardstate *cs,
1355 break; 1347 break;
1356 case ACT_ABORTHUP: 1348 case ACT_ABORTHUP:
1357 cs->cur_at_seq = SEQ_NONE; 1349 cs->cur_at_seq = SEQ_NONE;
1358 warn("Could not hang up."); 1350 dev_warn(cs->dev, "Could not hang up.\n");
1359 at_state->cid = -1; 1351 at_state->cid = -1;
1360 if (bcs && cs->onechannel) 1352 if (bcs && cs->onechannel)
1361 at_state->pending_commands |= PC_DLE0; 1353 at_state->pending_commands |= PC_DLE0;
@@ -1367,14 +1359,15 @@ static void do_action(int action, struct cardstate *cs,
1367 break; 1359 break;
1368 case ACT_FAILDLE0: 1360 case ACT_FAILDLE0:
1369 cs->cur_at_seq = SEQ_NONE; 1361 cs->cur_at_seq = SEQ_NONE;
1370 warn("Could not leave DLE mode."); 1362 dev_warn(cs->dev, "Could not leave DLE mode.\n");
1371 at_state2 = &cs->bcs[cs->curchannel].at_state; 1363 at_state2 = &cs->bcs[cs->curchannel].at_state;
1372 disconnect(&at_state2); 1364 disconnect(&at_state2);
1373 schedule_init(cs, MS_RECOVER); 1365 schedule_init(cs, MS_RECOVER);
1374 break; 1366 break;
1375 case ACT_FAILDLE1: 1367 case ACT_FAILDLE1:
1376 cs->cur_at_seq = SEQ_NONE; 1368 cs->cur_at_seq = SEQ_NONE;
1377 warn("Could not enter DLE mode. Try to hang up."); 1369 dev_warn(cs->dev,
1370 "Could not enter DLE mode. Trying to hang up.\n");
1378 channel = cs->curchannel; 1371 channel = cs->curchannel;
1379 cs->bcs[channel].at_state.pending_commands |= PC_HUP; 1372 cs->bcs[channel].at_state.pending_commands |= PC_HUP;
1380 atomic_set(&cs->commands_pending, 1); 1373 atomic_set(&cs->commands_pending, 1);
@@ -1395,7 +1388,8 @@ static void do_action(int action, struct cardstate *cs,
1395 cs->cur_at_seq = SEQ_NONE; 1388 cs->cur_at_seq = SEQ_NONE;
1396 channel = cs->curchannel; 1389 channel = cs->curchannel;
1397 if (!reinit_and_retry(cs, channel)) { 1390 if (!reinit_and_retry(cs, channel)) {
1398 warn("Could not get a call id. Dialing not possible"); 1391 dev_warn(cs->dev,
1392 "Could not get a call ID. Cannot dial.\n");
1399 at_state2 = &cs->bcs[channel].at_state; 1393 at_state2 = &cs->bcs[channel].at_state;
1400 disconnect(&at_state2); 1394 disconnect(&at_state2);
1401 } 1395 }
@@ -1428,7 +1422,8 @@ static void do_action(int action, struct cardstate *cs,
1428 at_state->pending_commands |= PC_HUP; 1422 at_state->pending_commands |= PC_HUP;
1429 atomic_set(&cs->commands_pending, 1); 1423 atomic_set(&cs->commands_pending, 1);
1430 break; 1424 break;
1431 case ACT_GETSTRING: /* warning: RING, ZDLE, ... are not handled properly any more */ 1425 case ACT_GETSTRING: /* warning: RING, ZDLE, ...
1426 are not handled properly anymore */
1432 at_state->getstring = 1; 1427 at_state->getstring = 1;
1433 break; 1428 break;
1434 case ACT_SETVER: 1429 case ACT_SETVER:
@@ -1469,16 +1464,16 @@ static void do_action(int action, struct cardstate *cs,
1469 case ACT_GOTVER: 1464 case ACT_GOTVER:
1470 if (cs->gotfwver == 0) { 1465 if (cs->gotfwver == 0) {
1471 cs->gotfwver = 1; 1466 cs->gotfwver = 1;
1472 dbg(DEBUG_ANY, 1467 gig_dbg(DEBUG_ANY,
1473 "firmware version %02d.%03d.%02d.%02d", 1468 "firmware version %02d.%03d.%02d.%02d",
1474 cs->fwver[0], cs->fwver[1], 1469 cs->fwver[0], cs->fwver[1],
1475 cs->fwver[2], cs->fwver[3]); 1470 cs->fwver[2], cs->fwver[3]);
1476 break; 1471 break;
1477 } 1472 }
1478 /* fall through */ 1473 /* fall through */
1479 case ACT_FAILVER: 1474 case ACT_FAILVER:
1480 cs->gotfwver = -1; 1475 cs->gotfwver = -1;
1481 err("could not read firmware version."); 1476 dev_err(cs->dev, "could not read firmware version.\n");
1482 break; 1477 break;
1483#ifdef CONFIG_GIGASET_DEBUG 1478#ifdef CONFIG_GIGASET_DEBUG
1484 case ACT_ERROR: 1479 case ACT_ERROR:
@@ -1496,16 +1491,16 @@ static void do_action(int action, struct cardstate *cs,
1496 break; 1491 break;
1497#endif 1492#endif
1498 case ACT_DEBUG: 1493 case ACT_DEBUG:
1499 dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d", 1494 gig_dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d",
1500 __func__, ev->type, at_state->ConState); 1495 __func__, ev->type, at_state->ConState);
1501 break; 1496 break;
1502 case ACT_WARN: 1497 case ACT_WARN:
1503 warn("%s: resp_code %d in ConState %d!", 1498 dev_warn(cs->dev, "%s: resp_code %d in ConState %d!\n",
1504 __func__, ev->type, at_state->ConState); 1499 __func__, ev->type, at_state->ConState);
1505 break; 1500 break;
1506 case ACT_ZCAU: 1501 case ACT_ZCAU:
1507 warn("cause code %04x in connection state %d.", 1502 dev_warn(cs->dev, "cause code %04x in connection state %d.\n",
1508 ev->parameter, at_state->ConState); 1503 ev->parameter, at_state->ConState);
1509 break; 1504 break;
1510 1505
1511 /* events from the LL */ 1506 /* events from the LL */
@@ -1516,14 +1511,14 @@ static void do_action(int action, struct cardstate *cs,
1516 start_accept(at_state); 1511 start_accept(at_state);
1517 break; 1512 break;
1518 case ACT_PROTO_L2: 1513 case ACT_PROTO_L2:
1519 dbg(DEBUG_CMD, 1514 gig_dbg(DEBUG_CMD, "set protocol to %u",
1520 "set protocol to %u", (unsigned) ev->parameter); 1515 (unsigned) ev->parameter);
1521 at_state->bcs->proto2 = ev->parameter; 1516 at_state->bcs->proto2 = ev->parameter;
1522 break; 1517 break;
1523 case ACT_HUP: 1518 case ACT_HUP:
1524 at_state->pending_commands |= PC_HUP; 1519 at_state->pending_commands |= PC_HUP;
1525 atomic_set(&cs->commands_pending, 1); //FIXME 1520 atomic_set(&cs->commands_pending, 1);
1526 dbg(DEBUG_CMD, "Scheduling PC_HUP"); 1521 gig_dbg(DEBUG_CMD, "Scheduling PC_HUP");
1527 break; 1522 break;
1528 1523
1529 /* hotplug events */ 1524 /* hotplug events */
@@ -1555,17 +1550,19 @@ static void do_action(int action, struct cardstate *cs,
1555 1550
1556 /* events from the proc file system */ // FIXME without ACT_xxxx? 1551 /* events from the proc file system */ // FIXME without ACT_xxxx?
1557 case ACT_PROC_CIDMODE: 1552 case ACT_PROC_CIDMODE:
1558 if (ev->parameter != atomic_read(&cs->cidmode)) { 1553 spin_lock_irqsave(&cs->lock, flags);
1559 atomic_set(&cs->cidmode, ev->parameter); 1554 if (ev->parameter != cs->cidmode) {
1555 cs->cidmode = ev->parameter;
1560 if (ev->parameter) { 1556 if (ev->parameter) {
1561 cs->at_state.pending_commands |= PC_CIDMODE; 1557 cs->at_state.pending_commands |= PC_CIDMODE;
1562 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); 1558 gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1563 } else { 1559 } else {
1564 cs->at_state.pending_commands |= PC_UMMODE; 1560 cs->at_state.pending_commands |= PC_UMMODE;
1565 dbg(DEBUG_CMD, "Scheduling PC_UMMODE"); 1561 gig_dbg(DEBUG_CMD, "Scheduling PC_UMMODE");
1566 } 1562 }
1567 atomic_set(&cs->commands_pending, 1); 1563 atomic_set(&cs->commands_pending, 1);
1568 } 1564 }
1565 spin_unlock_irqrestore(&cs->lock, flags);
1569 cs->waiting = 0; 1566 cs->waiting = 0;
1570 wake_up(&cs->waitqueue); 1567 wake_up(&cs->waitqueue);
1571 break; 1568 break;
@@ -1590,7 +1587,7 @@ static void do_action(int action, struct cardstate *cs,
1590 *p_resp_code = RSP_NULL; 1587 *p_resp_code = RSP_NULL;
1591 } 1588 }
1592 } else 1589 } else
1593 err("%s: action==%d!", __func__, action); 1590 dev_err(cs->dev, "%s: action==%d!\n", __func__, action);
1594 } 1591 }
1595} 1592}
1596 1593
@@ -1609,47 +1606,46 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1609 int curact; 1606 int curact;
1610 unsigned long flags; 1607 unsigned long flags;
1611 1608
1612 IFNULLRET(cs);
1613 IFNULLRET(ev);
1614
1615 if (ev->cid >= 0) { 1609 if (ev->cid >= 0) {
1616 at_state = at_state_from_cid(cs, ev->cid); 1610 at_state = at_state_from_cid(cs, ev->cid);
1617 if (!at_state) { 1611 if (!at_state) {
1618 gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID, 1612 gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID,
1619 NULL, 0, NULL); 1613 NULL, 0, NULL);
1620 return; 1614 return;
1621 } 1615 }
1622 } else { 1616 } else {
1623 at_state = ev->at_state; 1617 at_state = ev->at_state;
1624 if (at_state_invalid(cs, at_state)) { 1618 if (at_state_invalid(cs, at_state)) {
1625 dbg(DEBUG_ANY, 1619 gig_dbg(DEBUG_ANY, "event for invalid at_state %p",
1626 "event for invalid at_state %p", at_state); 1620 at_state);
1627 return; 1621 return;
1628 } 1622 }
1629 } 1623 }
1630 1624
1631 dbg(DEBUG_CMD, 1625 gig_dbg(DEBUG_CMD, "connection state %d, event %d",
1632 "connection state %d, event %d", at_state->ConState, ev->type); 1626 at_state->ConState, ev->type);
1633 1627
1634 bcs = at_state->bcs; 1628 bcs = at_state->bcs;
1635 sendcid = at_state->cid; 1629 sendcid = at_state->cid;
1636 1630
1637 /* Setting the pointer to the dial array */ 1631 /* Setting the pointer to the dial array */
1638 rep = at_state->replystruct; 1632 rep = at_state->replystruct;
1639 IFNULLRET(rep);
1640 1633
1634 spin_lock_irqsave(&cs->lock, flags);
1641 if (ev->type == EV_TIMEOUT) { 1635 if (ev->type == EV_TIMEOUT) {
1642 if (ev->parameter != atomic_read(&at_state->timer_index) 1636 if (ev->parameter != at_state->timer_index
1643 || !at_state->timer_active) { 1637 || !at_state->timer_active) {
1644 ev->type = RSP_NONE; /* old timeout */ 1638 ev->type = RSP_NONE; /* old timeout */
1645 dbg(DEBUG_ANY, "old timeout"); 1639 gig_dbg(DEBUG_ANY, "old timeout");
1646 } else if (!at_state->waiting) 1640 } else if (!at_state->waiting)
1647 dbg(DEBUG_ANY, "timeout occured"); 1641 gig_dbg(DEBUG_ANY, "timeout occurred");
1648 else 1642 else
1649 dbg(DEBUG_ANY, "stopped waiting"); 1643 gig_dbg(DEBUG_ANY, "stopped waiting");
1650 } 1644 }
1645 spin_unlock_irqrestore(&cs->lock, flags);
1651 1646
1652 /* if the response belongs to a variable in at_state->int_var[VAR_XXXX] or at_state->str_var[STR_XXXX], set it */ 1647 /* if the response belongs to a variable in at_state->int_var[VAR_XXXX]
1648 or at_state->str_var[STR_XXXX], set it */
1653 if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) { 1649 if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) {
1654 index = ev->type - RSP_VAR; 1650 index = ev->type - RSP_VAR;
1655 at_state->int_var[index] = ev->parameter; 1651 at_state->int_var[index] = ev->parameter;
@@ -1657,20 +1653,22 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1657 index = ev->type - RSP_STR; 1653 index = ev->type - RSP_STR;
1658 kfree(at_state->str_var[index]); 1654 kfree(at_state->str_var[index]);
1659 at_state->str_var[index] = ev->ptr; 1655 at_state->str_var[index] = ev->ptr;
1660 ev->ptr = NULL; /* prevent process_events() from deallocating ptr */ 1656 ev->ptr = NULL; /* prevent process_events() from
1657 deallocating ptr */
1661 } 1658 }
1662 1659
1663 if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING) 1660 if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING)
1664 at_state->getstring = 0; 1661 at_state->getstring = 0;
1665 1662
1666 /* Search row in dial array which matches modem response and current constate */ 1663 /* Search row in dial array which matches modem response and current
1664 constate */
1667 for (;; rep++) { 1665 for (;; rep++) {
1668 rcode = rep->resp_code; 1666 rcode = rep->resp_code;
1669 /* dbg (DEBUG_ANY, "rcode %d", rcode); */
1670 if (rcode == RSP_LAST) { 1667 if (rcode == RSP_LAST) {
1671 /* found nothing...*/ 1668 /* found nothing...*/
1672 warn("%s: rcode=RSP_LAST: resp_code %d in ConState %d!", 1669 dev_warn(cs->dev, "%s: rcode=RSP_LAST: "
1673 __func__, ev->type, at_state->ConState); 1670 "resp_code %d in ConState %d!\n",
1671 __func__, ev->type, at_state->ConState);
1674 return; 1672 return;
1675 } 1673 }
1676 if ((rcode == RSP_ANY || rcode == ev->type) 1674 if ((rcode == RSP_ANY || rcode == ev->type)
@@ -1706,14 +1704,14 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1706 } else { 1704 } else {
1707 /* Send command to modem if not NULL... */ 1705 /* Send command to modem if not NULL... */
1708 if (p_command/*rep->command*/) { 1706 if (p_command/*rep->command*/) {
1709 if (atomic_read(&cs->connected)) 1707 if (cs->connected)
1710 send_command(cs, p_command, 1708 send_command(cs, p_command,
1711 sendcid, cs->dle, 1709 sendcid, cs->dle,
1712 GFP_ATOMIC); 1710 GFP_ATOMIC);
1713 else 1711 else
1714 gigaset_add_event(cs, at_state, 1712 gigaset_add_event(cs, at_state,
1715 RSP_NODEV, 1713 RSP_NODEV,
1716 NULL, 0, NULL); 1714 NULL, 0, NULL);
1717 } 1715 }
1718 1716
1719 spin_lock_irqsave(&cs->lock, flags); 1717 spin_lock_irqsave(&cs->lock, flags);
@@ -1723,8 +1721,7 @@ static void process_event(struct cardstate *cs, struct event_t *ev)
1723 } else if (rep->timeout > 0) { /* new timeout */ 1721 } else if (rep->timeout > 0) { /* new timeout */
1724 at_state->timer_expires = rep->timeout * 10; 1722 at_state->timer_expires = rep->timeout * 10;
1725 at_state->timer_active = 1; 1723 at_state->timer_active = 1;
1726 new_index(&at_state->timer_index, 1724 ++at_state->timer_index;
1727 MAX_TIMER_INDEX);
1728 } 1725 }
1729 spin_unlock_irqrestore(&cs->lock, flags); 1726 spin_unlock_irqrestore(&cs->lock, flags);
1730 } 1727 }
@@ -1744,17 +1741,16 @@ static void process_command_flags(struct cardstate *cs)
1744 struct bc_state *bcs; 1741 struct bc_state *bcs;
1745 int i; 1742 int i;
1746 int sequence; 1743 int sequence;
1747 1744 unsigned long flags;
1748 IFNULLRET(cs);
1749 1745
1750 atomic_set(&cs->commands_pending, 0); 1746 atomic_set(&cs->commands_pending, 0);
1751 1747
1752 if (cs->cur_at_seq) { 1748 if (cs->cur_at_seq) {
1753 dbg(DEBUG_CMD, "not searching scheduled commands: busy"); 1749 gig_dbg(DEBUG_CMD, "not searching scheduled commands: busy");
1754 return; 1750 return;
1755 } 1751 }
1756 1752
1757 dbg(DEBUG_CMD, "searching scheduled commands"); 1753 gig_dbg(DEBUG_CMD, "searching scheduled commands");
1758 1754
1759 sequence = SEQ_NONE; 1755 sequence = SEQ_NONE;
1760 1756
@@ -1795,8 +1791,9 @@ static void process_command_flags(struct cardstate *cs)
1795 } 1791 }
1796 1792
1797 /* only switch back to unimodem mode, if no commands are pending and no channels are up */ 1793 /* only switch back to unimodem mode, if no commands are pending and no channels are up */
1794 spin_lock_irqsave(&cs->lock, flags);
1798 if (cs->at_state.pending_commands == PC_UMMODE 1795 if (cs->at_state.pending_commands == PC_UMMODE
1799 && !atomic_read(&cs->cidmode) 1796 && !cs->cidmode
1800 && list_empty(&cs->temp_at_states) 1797 && list_empty(&cs->temp_at_states)
1801 && atomic_read(&cs->mode) == M_CID) { 1798 && atomic_read(&cs->mode) == M_CID) {
1802 sequence = SEQ_UMMODE; 1799 sequence = SEQ_UMMODE;
@@ -1810,6 +1807,7 @@ static void process_command_flags(struct cardstate *cs)
1810 } 1807 }
1811 } 1808 }
1812 } 1809 }
1810 spin_unlock_irqrestore(&cs->lock, flags);
1813 cs->at_state.pending_commands &= ~PC_UMMODE; 1811 cs->at_state.pending_commands &= ~PC_UMMODE;
1814 if (sequence != SEQ_NONE) { 1812 if (sequence != SEQ_NONE) {
1815 schedule_sequence(cs, at_state, sequence); 1813 schedule_sequence(cs, at_state, sequence);
@@ -1865,11 +1863,7 @@ static void process_command_flags(struct cardstate *cs)
1865 if (cs->at_state.pending_commands & PC_CIDMODE) { 1863 if (cs->at_state.pending_commands & PC_CIDMODE) {
1866 cs->at_state.pending_commands &= ~PC_CIDMODE; 1864 cs->at_state.pending_commands &= ~PC_CIDMODE;
1867 if (atomic_read(&cs->mode) == M_UNIMODEM) { 1865 if (atomic_read(&cs->mode) == M_UNIMODEM) {
1868#if 0
1869 cs->retry_count = 2;
1870#else
1871 cs->retry_count = 1; 1866 cs->retry_count = 1;
1872#endif
1873 schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE); 1867 schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE);
1874 return; 1868 return;
1875 } 1869 }
@@ -1897,7 +1891,7 @@ static void process_command_flags(struct cardstate *cs)
1897 switch (atomic_read(&cs->mode)) { 1891 switch (atomic_read(&cs->mode)) {
1898 case M_UNIMODEM: 1892 case M_UNIMODEM:
1899 cs->at_state.pending_commands |= PC_CIDMODE; 1893 cs->at_state.pending_commands |= PC_CIDMODE;
1900 dbg(DEBUG_CMD, "Scheduling PC_CIDMODE"); 1894 gig_dbg(DEBUG_CMD, "Scheduling PC_CIDMODE");
1901 atomic_set(&cs->commands_pending, 1); 1895 atomic_set(&cs->commands_pending, 1);
1902 return; 1896 return;
1903#ifdef GIG_MAYINITONDIAL 1897#ifdef GIG_MAYINITONDIAL
@@ -1926,18 +1920,21 @@ static void process_events(struct cardstate *cs)
1926 int i; 1920 int i;
1927 int check_flags = 0; 1921 int check_flags = 0;
1928 int was_busy; 1922 int was_busy;
1923 unsigned long flags;
1929 1924
1930 /* no locking needed (only one reader) */ 1925 spin_lock_irqsave(&cs->ev_lock, flags);
1931 head = atomic_read(&cs->ev_head); 1926 head = cs->ev_head;
1932 1927
1933 for (i = 0; i < 2 * MAX_EVENTS; ++i) { 1928 for (i = 0; i < 2 * MAX_EVENTS; ++i) {
1934 tail = atomic_read(&cs->ev_tail); 1929 tail = cs->ev_tail;
1935 if (tail == head) { 1930 if (tail == head) {
1936 if (!check_flags && !atomic_read(&cs->commands_pending)) 1931 if (!check_flags && !atomic_read(&cs->commands_pending))
1937 break; 1932 break;
1938 check_flags = 0; 1933 check_flags = 0;
1934 spin_unlock_irqrestore(&cs->ev_lock, flags);
1939 process_command_flags(cs); 1935 process_command_flags(cs);
1940 tail = atomic_read(&cs->ev_tail); 1936 spin_lock_irqsave(&cs->ev_lock, flags);
1937 tail = cs->ev_tail;
1941 if (tail == head) { 1938 if (tail == head) {
1942 if (!atomic_read(&cs->commands_pending)) 1939 if (!atomic_read(&cs->commands_pending))
1943 break; 1940 break;
@@ -1947,18 +1944,23 @@ static void process_events(struct cardstate *cs)
1947 1944
1948 ev = cs->events + head; 1945 ev = cs->events + head;
1949 was_busy = cs->cur_at_seq != SEQ_NONE; 1946 was_busy = cs->cur_at_seq != SEQ_NONE;
1947 spin_unlock_irqrestore(&cs->ev_lock, flags);
1950 process_event(cs, ev); 1948 process_event(cs, ev);
1949 spin_lock_irqsave(&cs->ev_lock, flags);
1951 kfree(ev->ptr); 1950 kfree(ev->ptr);
1952 ev->ptr = NULL; 1951 ev->ptr = NULL;
1953 if (was_busy && cs->cur_at_seq == SEQ_NONE) 1952 if (was_busy && cs->cur_at_seq == SEQ_NONE)
1954 check_flags = 1; 1953 check_flags = 1;
1955 1954
1956 head = (head + 1) % MAX_EVENTS; 1955 head = (head + 1) % MAX_EVENTS;
1957 atomic_set(&cs->ev_head, head); 1956 cs->ev_head = head;
1958 } 1957 }
1959 1958
1959 spin_unlock_irqrestore(&cs->ev_lock, flags);
1960
1960 if (i == 2 * MAX_EVENTS) { 1961 if (i == 2 * MAX_EVENTS) {
1961 err("infinite loop in process_events; aborting."); 1962 dev_err(cs->dev,
1963 "infinite loop in process_events; aborting.\n");
1962 } 1964 }
1963} 1965}
1964 1966
@@ -1970,12 +1972,9 @@ void gigaset_handle_event(unsigned long data)
1970{ 1972{
1971 struct cardstate *cs = (struct cardstate *) data; 1973 struct cardstate *cs = (struct cardstate *) data;
1972 1974
1973 IFNULLRET(cs);
1974 IFNULLRET(cs->inbuf);
1975
1976 /* handle incoming data on control/common channel */ 1975 /* handle incoming data on control/common channel */
1977 if (atomic_read(&cs->inbuf->head) != atomic_read(&cs->inbuf->tail)) { 1976 if (atomic_read(&cs->inbuf->head) != atomic_read(&cs->inbuf->tail)) {
1978 dbg(DEBUG_INTR, "processing new data"); 1977 gig_dbg(DEBUG_INTR, "processing new data");
1979 cs->ops->handle_input(cs->inbuf); 1978 cs->ops->handle_input(cs->inbuf);
1980 } 1979 }
1981 1980
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index 729edcdb6dac..9d21ba8757b0 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -1,11 +1,16 @@
1/* Siemens Gigaset 307x driver 1/*
2 * Siemens Gigaset 307x driver
2 * Common header file for all connection variants 3 * Common header file for all connection variants
3 * 4 *
4 * Written by Stefan Eilers <Eilers.Stefan@epost.de> 5 * Written by Stefan Eilers
5 * and Hansjoerg Lipp <hjlipp@web.de> 6 * and Hansjoerg Lipp <hjlipp@web.de>
6 * 7 *
7 * Version: $Id: gigaset.h,v 1.97.4.26 2006/02/04 18:28:16 hjlipp Exp $ 8 * =====================================================================
8 * =========================================================================== 9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
9 */ 14 */
10 15
11#ifndef GIGASET_H 16#ifndef GIGASET_H
@@ -15,7 +20,6 @@
15#include <linux/kernel.h> 20#include <linux/kernel.h>
16#include <linux/compiler.h> 21#include <linux/compiler.h>
17#include <linux/types.h> 22#include <linux/types.h>
18#include <asm/atomic.h>
19#include <linux/spinlock.h> 23#include <linux/spinlock.h>
20#include <linux/isdnif.h> 24#include <linux/isdnif.h>
21#include <linux/usb.h> 25#include <linux/usb.h>
@@ -27,21 +31,22 @@
27#include <linux/tty.h> 31#include <linux/tty.h>
28#include <linux/tty_driver.h> 32#include <linux/tty_driver.h>
29#include <linux/list.h> 33#include <linux/list.h>
34#include <asm/atomic.h>
30 35
31#define GIG_VERSION {0,5,0,0} 36#define GIG_VERSION {0,5,0,0}
32#define GIG_COMPAT {0,4,0,0} 37#define GIG_COMPAT {0,4,0,0}
33 38
34#define MAX_REC_PARAMS 10 /* Max. number of params in response string */ 39#define MAX_REC_PARAMS 10 /* Max. number of params in response string */
35#define MAX_RESP_SIZE 512 /* Max. size of a response string */ 40#define MAX_RESP_SIZE 512 /* Max. size of a response string */
36#define HW_HDR_LEN 2 /* Header size used to store ack info */ 41#define HW_HDR_LEN 2 /* Header size used to store ack info */
37 42
38#define MAX_EVENTS 64 /* size of event queue */ 43#define MAX_EVENTS 64 /* size of event queue */
39 44
40#define RBUFSIZE 8192 45#define RBUFSIZE 8192
41#define SBUFSIZE 4096 /* sk_buff payload size */ 46#define SBUFSIZE 4096 /* sk_buff payload size */
42 47
43#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */ 48#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */
44#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */ 49#define MAX_BUF_SIZE (SBUFSIZE - 2) /* Max. size of a data packet from LL */
45 50
46/* compile time options */ 51/* compile time options */
47#define GIG_MAJOR 0 52#define GIG_MAJOR 0
@@ -50,10 +55,7 @@
50#define GIG_RETRYCID 55#define GIG_RETRYCID
51#define GIG_X75 56#define GIG_X75
52 57
53#define MAX_TIMER_INDEX 1000 58#define GIG_TICK 100 /* in milliseconds */
54#define MAX_SEQ_INDEX 1000
55
56#define GIG_TICK (HZ / 10)
57 59
58/* timeout values (unit: 1 sec) */ 60/* timeout values (unit: 1 sec) */
59#define INIT_TIMEOUT 1 61#define INIT_TIMEOUT 1
@@ -67,74 +69,89 @@
67 69
68#define MAXACT 3 70#define MAXACT 3
69 71
70#define IFNULL(a) if (unlikely(!(a)))
71#define IFNULLRET(a) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); return; }
72#define IFNULLRETVAL(a,b) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); return (b); }
73#define IFNULLCONT(a) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); continue; }
74#define IFNULLGOTO(a,b) if (unlikely(!(a))) {err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); goto b; }
75
76extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */ 72extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
77 73
78/* any combination of these can be given with the 'debug=' parameter to insmod, e.g. 74/* any combination of these can be given with the 'debug=' parameter to insmod,
79 * 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and DEBUG_INTR. */ 75 * e.g. 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and
76 * DEBUG_INTR.
77 */
80enum debuglevel { /* up to 24 bits (atomic_t) */ 78enum debuglevel { /* up to 24 bits (atomic_t) */
81 DEBUG_REG = 0x0002, /* serial port I/O register operations */ 79 DEBUG_REG = 0x0002, /* serial port I/O register operations */
82 DEBUG_OPEN = 0x0004, /* open/close serial port */ 80 DEBUG_OPEN = 0x0004, /* open/close serial port */
83 DEBUG_INTR = 0x0008, /* interrupt processing */ 81 DEBUG_INTR = 0x0008, /* interrupt processing */
84 DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on interrupt 82 DEBUG_INTR_DUMP = 0x0010, /* Activating hexdump debug output on
85 requests, not available as run-time option */ 83 interrupt requests, not available as
84 run-time option */
86 DEBUG_CMD = 0x00020, /* sent/received LL commands */ 85 DEBUG_CMD = 0x00020, /* sent/received LL commands */
87 DEBUG_STREAM = 0x00040, /* application data stream I/O events */ 86 DEBUG_STREAM = 0x00040, /* application data stream I/O events */
88 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */ 87 DEBUG_STREAM_DUMP = 0x00080, /* application data stream content */
89 DEBUG_LLDATA = 0x00100, /* sent/received LL data */ 88 DEBUG_LLDATA = 0x00100, /* sent/received LL data */
90 DEBUG_INTR_0 = 0x00200, /* serial port output interrupt processing */ 89 DEBUG_INTR_0 = 0x00200, /* serial port interrupt processing */
91 DEBUG_DRIVER = 0x00400, /* driver structure */ 90 DEBUG_DRIVER = 0x00400, /* driver structure */
92 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */ 91 DEBUG_HDLC = 0x00800, /* M10x HDLC processing */
93 DEBUG_WRITE = 0x01000, /* M105 data write */ 92 DEBUG_WRITE = 0x01000, /* M105 data write */
94 DEBUG_TRANSCMD = 0x02000, /*AT-COMMANDS+RESPONSES*/ 93 DEBUG_TRANSCMD = 0x02000, /* AT-COMMANDS+RESPONSES */
95 DEBUG_MCMD = 0x04000, /*COMMANDS THAT ARE SENT VERY OFTEN*/ 94 DEBUG_MCMD = 0x04000, /* COMMANDS THAT ARE SENT VERY OFTEN */
96 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data structures */ 95 DEBUG_INIT = 0x08000, /* (de)allocation+initialization of data
96 structures */
97 DEBUG_LOCK = 0x10000, /* semaphore operations */ 97 DEBUG_LOCK = 0x10000, /* semaphore operations */
98 DEBUG_OUTPUT = 0x20000, /* output to device */ 98 DEBUG_OUTPUT = 0x20000, /* output to device */
99 DEBUG_ISO = 0x40000, /* isochronous transfers */ 99 DEBUG_ISO = 0x40000, /* isochronous transfers */
100 DEBUG_IF = 0x80000, /* character device operations */ 100 DEBUG_IF = 0x80000, /* character device operations */
101 DEBUG_USBREQ = 0x100000, /* USB communication (except payload data) */ 101 DEBUG_USBREQ = 0x100000, /* USB communication (except payload
102 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when MS_LOCKED */ 102 data) */
103 DEBUG_LOCKCMD = 0x200000, /* AT commands and responses when
104 MS_LOCKED */
103 105
104 DEBUG_ANY = 0x3fffff, /* print message if any of the others is activated */ 106 DEBUG_ANY = 0x3fffff, /* print message if any of the others is
107 activated */
105}; 108};
106 109
107#ifdef CONFIG_GIGASET_DEBUG 110/* missing from linux/device.h ... */
108#define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ) 111#ifndef dev_notice
109//#define DEBUG_DEFAULT (DEBUG_LOCK | DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUF_IF | DEBUG_DRIVER | DEBUG_OUTPUT | DEBUG_INTR) 112#define dev_notice(dev, format, arg...) \
110#else 113 dev_printk(KERN_NOTICE , dev , format , ## arg)
111#define DEBUG_DEFAULT 0
112#endif 114#endif
113 115
114/* redefine syslog macros to prepend module name instead of entire source path */ 116/* Kernel message macros for situations where dev_printk and friends cannot be
115/* The space before the comma in ", ##" is needed by gcc 2.95 */ 117 * used for lack of reliable access to a device structure.
118 * linux/usb.h already contains these but in an obsolete form which clutters
119 * the log needlessly, and according to the USB maintainer those should be
120 * removed rather than fixed anyway.
121 */
122#undef err
116#undef info 123#undef info
117#define info(format, arg...) printk(KERN_INFO "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
118
119#undef notice
120#define notice(format, arg...) printk(KERN_NOTICE "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg)
121
122#undef warn 124#undef warn
123#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) 125#undef notice
124 126
125#undef err 127#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
126#define err(format, arg...) printk(KERN_ERR "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg) 128 format "\n" , ## arg)
129#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
130 format "\n" , ## arg)
131#define warn(format, arg...) printk(KERN_WARNING KBUILD_MODNAME ": " \
132 format "\n" , ## arg)
133#define notice(format, arg...) printk(KERN_NOTICE KBUILD_MODNAME ": " \
134 format "\n" , ## arg)
127 135
128#undef dbg
129#ifdef CONFIG_GIGASET_DEBUG 136#ifdef CONFIG_GIGASET_DEBUG
130#define dbg(level, format, arg...) do { if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \ 137
131 printk(KERN_DEBUG "%s: " format "\n", THIS_MODULE ? THIS_MODULE->name : "gigaset_hw" , ## arg); } while (0) 138#define gig_dbg(level, format, arg...) \
139 do { \
140 if (unlikely(((enum debuglevel)gigaset_debuglevel) & (level))) \
141 printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
142 ## arg); \
143 } while (0)
144#define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
145
132#else 146#else
133#define dbg(level, format, arg...) do {} while (0) 147
148#define gig_dbg(level, format, arg...) do {} while (0)
149#define DEBUG_DEFAULT 0
150
134#endif 151#endif
135 152
136void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, 153void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
137 size_t len, const unsigned char *buf, int from_user); 154 size_t len, const unsigned char *buf);
138 155
139/* connection state */ 156/* connection state */
140#define ZSAU_NONE 0 157#define ZSAU_NONE 0
@@ -148,13 +165,14 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
148#define ZSAU_UNKNOWN -1 165#define ZSAU_UNKNOWN -1
149 166
150/* USB control transfer requests */ 167/* USB control transfer requests */
151#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) 168#define OUT_VENDOR_REQ (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
152#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT) 169#define IN_VENDOR_REQ (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT)
153 170
154/* int-in-events 3070 */ 171/* int-in-events 3070 */
155#define HD_B1_FLOW_CONTROL 0x80 172#define HD_B1_FLOW_CONTROL 0x80
156#define HD_B2_FLOW_CONTROL 0x81 173#define HD_B2_FLOW_CONTROL 0x81
157#define HD_RECEIVEATDATA_ACK (0x35) // 3070 // att: HD_RECEIVE>>AT<<DATA_ACK 174#define HD_RECEIVEATDATA_ACK (0x35) // 3070
175 // att: HD_RECEIVE>>AT<<DATA_ACK
158#define HD_READY_SEND_ATDATA (0x36) // 3070 176#define HD_READY_SEND_ATDATA (0x36) // 3070
159#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070 177#define HD_OPEN_ATCHANNEL_ACK (0x37) // 3070
160#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070 178#define HD_CLOSE_ATCHANNEL_ACK (0x38) // 3070
@@ -181,17 +199,18 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
181#define HD_CLOSE_ATCHANNEL (0x29) // 3070 199#define HD_CLOSE_ATCHANNEL (0x29) // 3070
182 200
183/* USB frames for isochronous transfer */ 201/* USB frames for isochronous transfer */
184#define BAS_FRAMETIME 1 /* number of milliseconds between frames */ 202#define BAS_FRAMETIME 1 /* number of milliseconds between frames */
185#define BAS_NUMFRAMES 8 /* number of frames per URB */ 203#define BAS_NUMFRAMES 8 /* number of frames per URB */
186#define BAS_MAXFRAME 16 /* allocated bytes per frame */ 204#define BAS_MAXFRAME 16 /* allocated bytes per frame */
187#define BAS_NORMFRAME 8 /* send size without flow control */ 205#define BAS_NORMFRAME 8 /* send size without flow control */
188#define BAS_HIGHFRAME 10 /* " " with positive flow control */ 206#define BAS_HIGHFRAME 10 /* " " with positive flow control */
189#define BAS_LOWFRAME 5 /* " " with negative flow control */ 207#define BAS_LOWFRAME 5 /* " " with negative flow control */
190#define BAS_CORRFRAMES 4 /* flow control multiplicator */ 208#define BAS_CORRFRAMES 4 /* flow control multiplicator */
191 209
192#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES) /* size of isochronous input buffer per URB */ 210#define BAS_INBUFSIZE (BAS_MAXFRAME * BAS_NUMFRAMES)
193#define BAS_OUTBUFSIZE 4096 /* size of common isochronous output buffer */ 211 /* size of isoc in buf per URB */
194#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isochronous output buffer */ 212#define BAS_OUTBUFSIZE 4096 /* size of common isoc out buffer */
213#define BAS_OUTBUFPAD BAS_MAXFRAME /* size of pad area for isoc out buf */
195 214
196#define BAS_INURBS 3 215#define BAS_INURBS 3
197#define BAS_OUTURBS 3 216#define BAS_OUTURBS 3
@@ -207,40 +226,40 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
207#define AT_NUM 7 226#define AT_NUM 7
208 227
209/* variables in struct at_state_t */ 228/* variables in struct at_state_t */
210#define VAR_ZSAU 0 229#define VAR_ZSAU 0
211#define VAR_ZDLE 1 230#define VAR_ZDLE 1
212#define VAR_ZVLS 2 231#define VAR_ZVLS 2
213#define VAR_ZCTP 3 232#define VAR_ZCTP 3
214#define VAR_NUM 4 233#define VAR_NUM 4
215 234
216#define STR_NMBR 0 235#define STR_NMBR 0
217#define STR_ZCPN 1 236#define STR_ZCPN 1
218#define STR_ZCON 2 237#define STR_ZCON 2
219#define STR_ZBC 3 238#define STR_ZBC 3
220#define STR_ZHLC 4 239#define STR_ZHLC 4
221#define STR_NUM 5 240#define STR_NUM 5
222 241
223#define EV_TIMEOUT -105 242#define EV_TIMEOUT -105
224#define EV_IF_VER -106 243#define EV_IF_VER -106
225#define EV_PROC_CIDMODE -107 244#define EV_PROC_CIDMODE -107
226#define EV_SHUTDOWN -108 245#define EV_SHUTDOWN -108
227#define EV_START -110 246#define EV_START -110
228#define EV_STOP -111 247#define EV_STOP -111
229#define EV_IF_LOCK -112 248#define EV_IF_LOCK -112
230#define EV_PROTO_L2 -113 249#define EV_PROTO_L2 -113
231#define EV_ACCEPT -114 250#define EV_ACCEPT -114
232#define EV_DIAL -115 251#define EV_DIAL -115
233#define EV_HUP -116 252#define EV_HUP -116
234#define EV_BC_OPEN -117 253#define EV_BC_OPEN -117
235#define EV_BC_CLOSED -118 254#define EV_BC_CLOSED -118
236 255
237/* input state */ 256/* input state */
238#define INS_command 0x0001 257#define INS_command 0x0001
239#define INS_DLE_char 0x0002 258#define INS_DLE_char 0x0002
240#define INS_byte_stuff 0x0004 259#define INS_byte_stuff 0x0004
241#define INS_have_data 0x0008 260#define INS_have_data 0x0008
242#define INS_skip_frame 0x0010 261#define INS_skip_frame 0x0010
243#define INS_DLE_command 0x0020 262#define INS_DLE_command 0x0020
244#define INS_flag_hunt 0x0040 263#define INS_flag_hunt 0x0040
245 264
246/* channel state */ 265/* channel state */
@@ -248,27 +267,27 @@ void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
248#define CHS_B_UP 0x02 267#define CHS_B_UP 0x02
249#define CHS_NOTIFY_LL 0x04 268#define CHS_NOTIFY_LL 0x04
250 269
251#define ICALL_REJECT 0 270#define ICALL_REJECT 0
252#define ICALL_ACCEPT 1 271#define ICALL_ACCEPT 1
253#define ICALL_IGNORE 2 272#define ICALL_IGNORE 2
254 273
255/* device state */ 274/* device state */
256#define MS_UNINITIALIZED 0 275#define MS_UNINITIALIZED 0
257#define MS_INIT 1 276#define MS_INIT 1
258#define MS_LOCKED 2 277#define MS_LOCKED 2
259#define MS_SHUTDOWN 3 278#define MS_SHUTDOWN 3
260#define MS_RECOVER 4 279#define MS_RECOVER 4
261#define MS_READY 5 280#define MS_READY 5
262 281
263/* mode */ 282/* mode */
264#define M_UNKNOWN 0 283#define M_UNKNOWN 0
265#define M_CONFIG 1 284#define M_CONFIG 1
266#define M_UNIMODEM 2 285#define M_UNIMODEM 2
267#define M_CID 3 286#define M_CID 3
268 287
269/* start mode */ 288/* start mode */
270#define SM_LOCKED 0 289#define SM_LOCKED 0
271#define SM_ISDN 1 /* default */ 290#define SM_ISDN 1 /* default */
272 291
273struct gigaset_ops; 292struct gigaset_ops;
274struct gigaset_driver; 293struct gigaset_driver;
@@ -283,27 +302,26 @@ struct ser_bc_state;
283struct bas_bc_state; 302struct bas_bc_state;
284 303
285struct reply_t { 304struct reply_t {
286 int resp_code; /* RSP_XXXX */ 305 int resp_code; /* RSP_XXXX */
287 int min_ConState; /* <0 => ignore */ 306 int min_ConState; /* <0 => ignore */
288 int max_ConState; /* <0 => ignore */ 307 int max_ConState; /* <0 => ignore */
289 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/ 308 int parameter; /* e.g. ZSAU_XXXX <0: ignore*/
290 int new_ConState; /* <0 => ignore */ 309 int new_ConState; /* <0 => ignore */
291 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/ 310 int timeout; /* >0 => *HZ; <=0 => TOUT_XXXX*/
292 int action[MAXACT]; /* ACT_XXXX */ 311 int action[MAXACT]; /* ACT_XXXX */
293 char *command; /* NULL==none */ 312 char *command; /* NULL==none */
294}; 313};
295 314
296extern struct reply_t gigaset_tab_cid_m10x[]; 315extern struct reply_t gigaset_tab_cid_m10x[];
297extern struct reply_t gigaset_tab_nocid_m10x[]; 316extern struct reply_t gigaset_tab_nocid_m10x[];
298 317
299struct inbuf_t { 318struct inbuf_t {
300 unsigned char *rcvbuf; /* usb-gigaset receive buffer */ 319 unsigned char *rcvbuf; /* usb-gigaset receive buffer */
301 struct bc_state *bcs; 320 struct bc_state *bcs;
302 struct cardstate *cs; 321 struct cardstate *cs;
303 int inputstate; 322 int inputstate;
304 323 atomic_t head, tail;
305 atomic_t head, tail; 324 unsigned char data[RBUFSIZE];
306 unsigned char data[RBUFSIZE];
307}; 325};
308 326
309/* isochronous write buffer structure 327/* isochronous write buffer structure
@@ -319,16 +337,9 @@ struct inbuf_t {
319 * if writesem <= 0, data[write..read-1] is currently being written to 337 * if writesem <= 0, data[write..read-1] is currently being written to
320 * - idle contains the byte value to repeat when the end of valid data is 338 * - idle contains the byte value to repeat when the end of valid data is
321 * reached; if nextread==write (buffer contains no data to send), either the 339 * reached; if nextread==write (buffer contains no data to send), either the
322 * BAS_OUTBUFPAD bytes immediately before data[write] (if write>=BAS_OUTBUFPAD) 340 * BAS_OUTBUFPAD bytes immediately before data[write] (if
323 * or those of the pad area (if write<BAS_OUTBUFPAD) are also filled with that 341 * write>=BAS_OUTBUFPAD) or those of the pad area (if write<BAS_OUTBUFPAD)
324 * value 342 * are also filled with that value
325 * - optionally, the following statistics on the buffer's usage can be collected:
326 * maxfill: maximum number of bytes occupied
327 * idlefills: number of times a frame of idle bytes is prepared
328 * emptygets: number of times the buffer was empty when a data frame was requested
329 * backtoback: number of times two data packets were entered into the buffer
330 * without intervening idle flags
331 * nakedback: set if no idle flags have been inserted since the last data packet
332 */ 343 */
333struct isowbuf_t { 344struct isowbuf_t {
334 atomic_t read; 345 atomic_t read;
@@ -358,34 +369,28 @@ struct isow_urbctx_t {
358 * it is currently assigned a B channel 369 * it is currently assigned a B channel
359 */ 370 */
360struct at_state_t { 371struct at_state_t {
361 struct list_head list; 372 struct list_head list;
362 int waiting; 373 int waiting;
363 int getstring; 374 int getstring;
364 atomic_t timer_index; 375 unsigned timer_index;
365 unsigned long timer_expires; 376 unsigned long timer_expires;
366 int timer_active; 377 int timer_active;
367 unsigned int ConState; /* State of connection */ 378 unsigned int ConState; /* State of connection */
368 struct reply_t *replystruct; 379 struct reply_t *replystruct;
369 int cid; 380 int cid;
370 int int_var[VAR_NUM]; /* see VAR_XXXX */ 381 int int_var[VAR_NUM]; /* see VAR_XXXX */
371 char *str_var[STR_NUM]; /* see STR_XXXX */ 382 char *str_var[STR_NUM]; /* see STR_XXXX */
372 unsigned pending_commands; /* see PC_XXXX */ 383 unsigned pending_commands; /* see PC_XXXX */
373 atomic_t seq_index; 384 unsigned seq_index;
374 385
375 struct cardstate *cs; 386 struct cardstate *cs;
376 struct bc_state *bcs; 387 struct bc_state *bcs;
377}; 388};
378 389
379struct resp_type_t { 390struct resp_type_t {
380 unsigned char *response; 391 unsigned char *response;
381 int resp_code; /* RSP_XXXX */ 392 int resp_code; /* RSP_XXXX */
382 int type; /* RT_XXXX */ 393 int type; /* RT_XXXX */
383};
384
385struct prot_skb {
386 atomic_t empty;
387 struct semaphore *sem;
388 struct sk_buff *skb;
389}; 394};
390 395
391struct event_t { 396struct event_t {
@@ -398,29 +403,29 @@ struct event_t {
398 403
399/* This buffer holds all information about the used B-Channel */ 404/* This buffer holds all information about the used B-Channel */
400struct bc_state { 405struct bc_state {
401 struct sk_buff *tx_skb; /* Current transfer buffer to modem */ 406 struct sk_buff *tx_skb; /* Current transfer buffer to modem */
402 struct sk_buff_head squeue; /* B-Channel send Queue */ 407 struct sk_buff_head squeue; /* B-Channel send Queue */
403 408
404 /* Variables for debugging .. */ 409 /* Variables for debugging .. */
405 int corrupted; /* Counter for corrupted packages */ 410 int corrupted; /* Counter for corrupted packages */
406 int trans_down; /* Counter of packages (downstream) */ 411 int trans_down; /* Counter of packages (downstream) */
407 int trans_up; /* Counter of packages (upstream) */ 412 int trans_up; /* Counter of packages (upstream) */
408 413
409 struct at_state_t at_state; 414 struct at_state_t at_state;
410 unsigned long rcvbytes; 415 unsigned long rcvbytes;
411 416
412 __u16 fcs; 417 __u16 fcs;
413 struct sk_buff *skb; 418 struct sk_buff *skb;
414 int inputstate; /* see INS_XXXX */ 419 int inputstate; /* see INS_XXXX */
415 420
416 int channel; 421 int channel;
417 422
418 struct cardstate *cs; 423 struct cardstate *cs;
419 424
420 unsigned chstate; /* bitmap (CHS_*) */ 425 unsigned chstate; /* bitmap (CHS_*) */
421 int ignore; 426 int ignore;
422 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */ 427 unsigned proto2; /* Layer 2 protocol (ISDN_PROTO_L2_*) */
423 char *commands[AT_NUM]; /* see AT_XXXX */ 428 char *commands[AT_NUM]; /* see AT_XXXX */
424 429
425#ifdef CONFIG_GIGASET_DEBUG 430#ifdef CONFIG_GIGASET_DEBUG
426 int emptycount; 431 int emptycount;
@@ -428,37 +433,39 @@ struct bc_state {
428 int busy; 433 int busy;
429 int use_count; 434 int use_count;
430 435
431 /* hardware drivers */ 436 /* private data of hardware drivers */
432 union { 437 union {
433 struct ser_bc_state *ser; /* private data of serial hardware driver */ 438 struct ser_bc_state *ser; /* serial hardware driver */
434 struct usb_bc_state *usb; /* private data of usb hardware driver */ 439 struct usb_bc_state *usb; /* usb hardware driver (m105) */
435 struct bas_bc_state *bas; 440 struct bas_bc_state *bas; /* usb hardware driver (base) */
436 } hw; 441 } hw;
437}; 442};
438 443
439struct cardstate { 444struct cardstate {
440 struct gigaset_driver *driver; 445 struct gigaset_driver *driver;
441 unsigned minor_index; 446 unsigned minor_index;
447 struct device *dev;
442 448
443 const struct gigaset_ops *ops; 449 const struct gigaset_ops *ops;
444 450
445 /* Stuff to handle communication */ 451 /* Stuff to handle communication */
446 //wait_queue_head_t initwait;
447 wait_queue_head_t waitqueue; 452 wait_queue_head_t waitqueue;
448 int waiting; 453 int waiting;
449 atomic_t mode; /* see M_XXXX */ 454 atomic_t mode; /* see M_XXXX */
450 atomic_t mstate; /* Modem state: see MS_XXXX */ 455 atomic_t mstate; /* Modem state: see MS_XXXX */
451 /* only changed by the event layer */ 456 /* only changed by the event layer */
452 int cmd_result; 457 int cmd_result;
453 458
454 int channels; 459 int channels;
455 struct bc_state *bcs; /* Array of struct bc_state */ 460 struct bc_state *bcs; /* Array of struct bc_state */
456 461
457 int onechannel; /* data and commands transmitted in one stream (M10x) */ 462 int onechannel; /* data and commands transmitted in one
463 stream (M10x) */
458 464
459 spinlock_t lock; 465 spinlock_t lock;
460 struct at_state_t at_state; /* at_state_t for cid == 0 */ 466 struct at_state_t at_state; /* at_state_t for cid == 0 */
461 struct list_head temp_at_states; /* list of temporary "struct at_state_t"s without B channel */ 467 struct list_head temp_at_states;/* list of temporary "struct
468 at_state_t"s without B channel */
462 469
463 struct inbuf_t *inbuf; 470 struct inbuf_t *inbuf;
464 471
@@ -474,58 +481,69 @@ struct cardstate {
474 unsigned fwver[4]; 481 unsigned fwver[4];
475 int gotfwver; 482 int gotfwver;
476 483
477 atomic_t running; /* !=0 if events are handled */ 484 unsigned running; /* !=0 if events are handled */
478 atomic_t connected; /* !=0 if hardware is connected */ 485 unsigned connected; /* !=0 if hardware is connected */
486 unsigned isdn_up; /* !=0 after ISDN_STAT_RUN */
479 487
480 atomic_t cidmode; 488 unsigned cidmode;
481 489
482 int myid; /* id for communication with LL */ 490 int myid; /* id for communication with LL */
483 isdn_if iif; 491 isdn_if iif;
484 492
485 struct reply_t *tabnocid; 493 struct reply_t *tabnocid;
486 struct reply_t *tabcid; 494 struct reply_t *tabcid;
487 int cs_init; 495 int cs_init;
488 int ignoreframes; /* frames to ignore after setting up the B channel */ 496 int ignoreframes; /* frames to ignore after setting up the
489 struct semaphore sem; /* locks this structure: */ 497 B channel */
490 /* connected is not changed, */ 498 struct mutex mutex; /* locks this structure:
491 /* hardware_up is not changed, */ 499 * connected is not changed,
492 /* MState is not changed to or from MS_LOCKED */ 500 * hardware_up is not changed,
501 * MState is not changed to or from
502 * MS_LOCKED */
493 503
494 struct timer_list timer; 504 struct timer_list timer;
495 int retry_count; 505 int retry_count;
496 int dle; /* !=0 if modem commands/responses are dle encoded */ 506 int dle; /* !=0 if modem commands/responses are
497 int cur_at_seq; /* sequence of AT commands being processed */ 507 dle encoded */
498 int curchannel; /* channel, those commands are meant for */ 508 int cur_at_seq; /* sequence of AT commands being
499 atomic_t commands_pending; /* flag(s) in xxx.commands_pending have been set */ 509 processed */
500 struct tasklet_struct event_tasklet; /* tasklet for serializing AT commands. Scheduled 510 int curchannel; /* channel those commands are meant
501 * -> for modem reponses (and incomming data for M10x) 511 for */
502 * -> on timeout 512 atomic_t commands_pending; /* flag(s) in xxx.commands_pending have
503 * -> after setting bits in xxx.at_state.pending_command 513 been set */
504 * (e.g. command from LL) */ 514 struct tasklet_struct event_tasklet;
505 struct tasklet_struct write_tasklet; /* tasklet for serial output 515 /* tasklet for serializing AT commands.
506 * (not used in base driver) */ 516 * Scheduled
517 * -> for modem reponses (and
518 * incoming data for M10x)
519 * -> on timeout
520 * -> after setting bits in
521 * xxx.at_state.pending_command
522 * (e.g. command from LL) */
523 struct tasklet_struct write_tasklet;
524 /* tasklet for serial output
525 * (not used in base driver) */
507 526
508 /* event queue */ 527 /* event queue */
509 struct event_t events[MAX_EVENTS]; 528 struct event_t events[MAX_EVENTS];
510 atomic_t ev_tail, ev_head; 529 unsigned ev_tail, ev_head;
511 spinlock_t ev_lock; 530 spinlock_t ev_lock;
512 531
513 /* current modem response */ 532 /* current modem response */
514 unsigned char respdata[MAX_RESP_SIZE]; 533 unsigned char respdata[MAX_RESP_SIZE];
515 unsigned cbytes; 534 unsigned cbytes;
516 535
517 /* hardware drivers */ 536 /* private data of hardware drivers */
518 union { 537 union {
519 struct usb_cardstate *usb; /* private data of USB hardware driver */ 538 struct usb_cardstate *usb; /* USB hardware driver (m105) */
520 struct ser_cardstate *ser; /* private data of serial hardware driver */ 539 struct ser_cardstate *ser; /* serial hardware driver */
521 struct bas_cardstate *bas; /* private data of base hardware driver */ 540 struct bas_cardstate *bas; /* USB hardware driver (base) */
522 } hw; 541 } hw;
523}; 542};
524 543
525struct gigaset_driver { 544struct gigaset_driver {
526 struct list_head list; 545 struct list_head list;
527 spinlock_t lock; /* locks minor tables and blocked */ 546 spinlock_t lock; /* locks minor tables and blocked */
528 //struct semaphore sem; /* locks this structure */
529 struct tty_driver *tty; 547 struct tty_driver *tty;
530 unsigned have_tty; 548 unsigned have_tty;
531 unsigned minor; 549 unsigned minor;
@@ -553,37 +571,42 @@ struct bas_bc_state {
553 struct isow_urbctx_t isoouturbs[BAS_OUTURBS]; 571 struct isow_urbctx_t isoouturbs[BAS_OUTURBS];
554 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl; 572 struct isow_urbctx_t *isooutdone, *isooutfree, *isooutovfl;
555 struct isowbuf_t *isooutbuf; 573 struct isowbuf_t *isooutbuf;
556 unsigned numsub; /* submitted URB counter (for diagnostic messages only) */ 574 unsigned numsub; /* submitted URB counter
575 (for diagnostic messages only) */
557 struct tasklet_struct sent_tasklet; 576 struct tasklet_struct sent_tasklet;
558 577
559 /* isochronous input state */ 578 /* isochronous input state */
560 spinlock_t isoinlock; 579 spinlock_t isoinlock;
561 struct urb *isoinurbs[BAS_INURBS]; 580 struct urb *isoinurbs[BAS_INURBS];
562 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS]; 581 unsigned char isoinbuf[BAS_INBUFSIZE * BAS_INURBS];
563 struct urb *isoindone; /* completed isoc read URB */ 582 struct urb *isoindone; /* completed isoc read URB */
564 int loststatus; /* status of dropped URB */ 583 int loststatus; /* status of dropped URB */
565 unsigned isoinlost; /* number of bytes lost */ 584 unsigned isoinlost; /* number of bytes lost */
566 /* state of bit unstuffing algorithm (in addition to BC_state.inputstate) */ 585 /* state of bit unstuffing algorithm
567 unsigned seqlen; /* number of '1' bits not yet unstuffed */ 586 (in addition to BC_state.inputstate) */
568 unsigned inbyte, inbits; /* collected bits for next byte */ 587 unsigned seqlen; /* number of '1' bits not yet
588 unstuffed */
589 unsigned inbyte, inbits; /* collected bits for next byte */
569 /* statistics */ 590 /* statistics */
570 unsigned goodbytes; /* bytes correctly received */ 591 unsigned goodbytes; /* bytes correctly received */
571 unsigned alignerrs; /* frames with incomplete byte at end */ 592 unsigned alignerrs; /* frames with incomplete byte at end */
572 unsigned fcserrs; /* FCS errors */ 593 unsigned fcserrs; /* FCS errors */
573 unsigned frameerrs; /* framing errors */ 594 unsigned frameerrs; /* framing errors */
574 unsigned giants; /* long frames */ 595 unsigned giants; /* long frames */
575 unsigned runts; /* short frames */ 596 unsigned runts; /* short frames */
576 unsigned aborts; /* HDLC aborts */ 597 unsigned aborts; /* HDLC aborts */
577 unsigned shared0s; /* '0' bits shared between flags */ 598 unsigned shared0s; /* '0' bits shared between flags */
578 unsigned stolen0s; /* '0' stuff bits also serving as leading flag bits */ 599 unsigned stolen0s; /* '0' stuff bits also serving as
600 leading flag bits */
579 struct tasklet_struct rcvd_tasklet; 601 struct tasklet_struct rcvd_tasklet;
580}; 602};
581 603
582struct gigaset_ops { 604struct gigaset_ops {
583 /* Called from ev-layer.c/interface.c for sending AT commands to the device */ 605 /* Called from ev-layer.c/interface.c for sending AT commands to the
606 device */
584 int (*write_cmd)(struct cardstate *cs, 607 int (*write_cmd)(struct cardstate *cs,
585 const unsigned char *buf, int len, 608 const unsigned char *buf, int len,
586 struct tasklet_struct *wake_tasklet); 609 struct tasklet_struct *wake_tasklet);
587 610
588 /* Called from interface.c for additional device control */ 611 /* Called from interface.c for additional device control */
589 int (*write_room)(struct cardstate *cs); 612 int (*write_room)(struct cardstate *cs);
@@ -604,7 +627,8 @@ struct gigaset_ops {
604 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */ 627 /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
605 int (*freebcshw)(struct bc_state *bcs); 628 int (*freebcshw)(struct bc_state *bcs);
606 629
607 /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting bcs->hw.xxx */ 630 /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting
631 bcs->hw.xxx */
608 void (*reinitbcshw)(struct bc_state *bcs); 632 void (*reinitbcshw)(struct bc_state *bcs);
609 633
610 /* Called by gigaset_initcs() for setting up cs->hw.xxx */ 634 /* Called by gigaset_initcs() for setting up cs->hw.xxx */
@@ -613,13 +637,10 @@ struct gigaset_ops {
613 /* Called by gigaset_freecs() for freeing cs->hw.xxx */ 637 /* Called by gigaset_freecs() for freeing cs->hw.xxx */
614 void (*freecshw)(struct cardstate *cs); 638 void (*freecshw)(struct cardstate *cs);
615 639
616 ///* Called by gigaset_stop() for killing URBs, shutting down the device, ... 640 /* Called from common.c/interface.c for additional serial port
617 // hardwareup: ==0: don't try to shut down the device, hardware is really not accessible 641 control */
618 // !=0: hardware still up */ 642 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state,
619 //void (*stophw)(struct cardstate *cs, int hardwareup); 643 unsigned new_state);
620
621 /* Called from common.c/interface.c for additional serial port control */
622 int (*set_modem_ctrl)(struct cardstate *cs, unsigned old_state, unsigned new_state);
623 int (*baud_rate)(struct cardstate *cs, unsigned cflag); 644 int (*baud_rate)(struct cardstate *cs, unsigned cflag);
624 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag); 645 int (*set_line_ctrl)(struct cardstate *cs, unsigned cflag);
625 646
@@ -639,7 +660,7 @@ struct gigaset_ops {
639 * <DLE_FLAG>: 0x10 660 * <DLE_FLAG>: 0x10
640 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+ 661 * <EVENT>: ((a-z)* | (A-Z)* | (0-10)*)+
641 */ 662 */
642#define DLE_FLAG 0x10 663#define DLE_FLAG 0x10
643 664
644/* =========================================================================== 665/* ===========================================================================
645 * Functions implemented in asyncdata.c 666 * Functions implemented in asyncdata.c
@@ -667,7 +688,8 @@ void gigaset_isoc_input(struct inbuf_t *inbuf);
667 688
668/* Called from bas-gigaset.c to process a block of data 689/* Called from bas-gigaset.c to process a block of data
669 * received through the isochronous channel */ 690 * received through the isochronous channel */
670void gigaset_isoc_receive(unsigned char *src, unsigned count, struct bc_state *bcs); 691void gigaset_isoc_receive(unsigned char *src, unsigned count,
692 struct bc_state *bcs);
671 693
672/* Called from bas-gigaset.c to put a block of data 694/* Called from bas-gigaset.c to put a block of data
673 * into the isochronous output buffer */ 695 * into the isochronous output buffer */
@@ -703,7 +725,7 @@ static inline void gigaset_isdn_rcv_err(struct bc_state *bcs)
703 isdn_ctrl response; 725 isdn_ctrl response;
704 726
705 /* error -> LL */ 727 /* error -> LL */
706 dbg(DEBUG_CMD, "sending L1ERR"); 728 gig_dbg(DEBUG_CMD, "sending L1ERR");
707 response.driver = bcs->cs->myid; 729 response.driver = bcs->cs->myid;
708 response.command = ISDN_STAT_L1ERR; 730 response.command = ISDN_STAT_L1ERR;
709 response.arg = bcs->channel; 731 response.arg = bcs->channel;
@@ -727,8 +749,8 @@ void gigaset_handle_modem_response(struct cardstate *cs);
727 */ 749 */
728 750
729/* initialize sysfs for device */ 751/* initialize sysfs for device */
730void gigaset_init_dev_sysfs(struct usb_interface *interface); 752void gigaset_init_dev_sysfs(struct cardstate *cs);
731void gigaset_free_dev_sysfs(struct usb_interface *interface); 753void gigaset_free_dev_sysfs(struct cardstate *cs);
732 754
733/* =========================================================================== 755/* ===========================================================================
734 * Functions implemented in common.c/gigaset.h 756 * Functions implemented in common.c/gigaset.h
@@ -736,7 +758,7 @@ void gigaset_free_dev_sysfs(struct usb_interface *interface);
736 758
737void gigaset_bcs_reinit(struct bc_state *bcs); 759void gigaset_bcs_reinit(struct bc_state *bcs);
738void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs, 760void gigaset_at_init(struct at_state_t *at_state, struct bc_state *bcs,
739 struct cardstate *cs, int cid); 761 struct cardstate *cs, int cid);
740int gigaset_get_channel(struct bc_state *bcs); 762int gigaset_get_channel(struct bc_state *bcs);
741void gigaset_free_channel(struct bc_state *bcs); 763void gigaset_free_channel(struct bc_state *bcs);
742int gigaset_get_channels(struct cardstate *cs); 764int gigaset_get_channels(struct cardstate *cs);
@@ -745,16 +767,15 @@ void gigaset_block_channels(struct cardstate *cs);
745 767
746/* Allocate and initialize driver structure. */ 768/* Allocate and initialize driver structure. */
747struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors, 769struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
748 const char *procname, 770 const char *procname,
749 const char *devname, 771 const char *devname,
750 const char *devfsname, 772 const char *devfsname,
751 const struct gigaset_ops *ops, 773 const struct gigaset_ops *ops,
752 struct module *owner); 774 struct module *owner);
753 775
754/* Deallocate driver structure. */ 776/* Deallocate driver structure. */
755void gigaset_freedriver(struct gigaset_driver *drv); 777void gigaset_freedriver(struct gigaset_driver *drv);
756void gigaset_debugdrivers(void); 778void gigaset_debugdrivers(void);
757struct cardstate *gigaset_get_cs_by_minor(unsigned minor);
758struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty); 779struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
759struct cardstate *gigaset_get_cs_by_id(int id); 780struct cardstate *gigaset_get_cs_by_id(int id);
760 781
@@ -763,7 +784,8 @@ struct cardstate *gigaset_getunassignedcs(struct gigaset_driver *drv);
763void gigaset_unassign(struct cardstate *cs); 784void gigaset_unassign(struct cardstate *cs);
764void gigaset_blockdriver(struct gigaset_driver *drv); 785void gigaset_blockdriver(struct gigaset_driver *drv);
765 786
766/* Allocate and initialize card state. Calls hardware dependent gigaset_init[b]cs(). */ 787/* Allocate and initialize card state. Calls hardware dependent
788 gigaset_init[b]cs(). */
767struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels, 789struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
768 int onechannel, int ignoreframes, 790 int onechannel, int ignoreframes,
769 int cidmode, const char *modulename); 791 int cidmode, const char *modulename);
@@ -788,8 +810,8 @@ void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb);
788 * ptr must be kmalloc()ed (and not be freed by the caller). 810 * ptr must be kmalloc()ed (and not be freed by the caller).
789 */ 811 */
790struct event_t *gigaset_add_event(struct cardstate *cs, 812struct event_t *gigaset_add_event(struct cardstate *cs,
791 struct at_state_t *at_state, int type, 813 struct at_state_t *at_state, int type,
792 void *ptr, int parameter, void *arg); 814 void *ptr, int parameter, void *arg);
793 815
794/* Called on CONFIG1 command from frontend. */ 816/* Called on CONFIG1 command from frontend. */
795int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode 817int gigaset_enterconfigmode(struct cardstate *cs); //0: success <0: errorcode
@@ -799,7 +821,7 @@ static inline void gigaset_schedule_event(struct cardstate *cs)
799{ 821{
800 unsigned long flags; 822 unsigned long flags;
801 spin_lock_irqsave(&cs->lock, flags); 823 spin_lock_irqsave(&cs->lock, flags);
802 if (atomic_read(&cs->running)) 824 if (cs->running)
803 tasklet_schedule(&cs->event_tasklet); 825 tasklet_schedule(&cs->event_tasklet);
804 spin_unlock_irqrestore(&cs->lock, flags); 826 spin_unlock_irqrestore(&cs->lock, flags);
805} 827}
@@ -810,7 +832,7 @@ static inline void gigaset_bchannel_down(struct bc_state *bcs)
810{ 832{
811 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL); 833 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_CLOSED, NULL, 0, NULL);
812 834
813 dbg(DEBUG_CMD, "scheduling BC_CLOSED"); 835 gig_dbg(DEBUG_CMD, "scheduling BC_CLOSED");
814 gigaset_schedule_event(bcs->cs); 836 gigaset_schedule_event(bcs->cs);
815} 837}
816 838
@@ -820,36 +842,19 @@ static inline void gigaset_bchannel_up(struct bc_state *bcs)
820{ 842{
821 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL); 843 gigaset_add_event(bcs->cs, &bcs->at_state, EV_BC_OPEN, NULL, 0, NULL);
822 844
823 dbg(DEBUG_CMD, "scheduling BC_OPEN"); 845 gig_dbg(DEBUG_CMD, "scheduling BC_OPEN");
824 gigaset_schedule_event(bcs->cs); 846 gigaset_schedule_event(bcs->cs);
825} 847}
826 848
827/* handling routines for sk_buff */ 849/* handling routines for sk_buff */
828/* ============================= */ 850/* ============================= */
829 851
830/* private version of __skb_put()
831 * append 'len' bytes to the content of 'skb', already knowing that the
832 * existing buffer can accomodate them
833 * returns a pointer to the location where the new bytes should be copied to
834 * This function does not take any locks so it must be called with the
835 * appropriate locks held only.
836 */
837static inline unsigned char *gigaset_skb_put_quick(struct sk_buff *skb,
838 unsigned int len)
839{
840 unsigned char *tmp = skb->tail;
841 /*SKB_LINEAR_ASSERT(skb);*/ /* not needed here */
842 skb->tail += len;
843 skb->len += len;
844 return tmp;
845}
846
847/* pass received skb to LL 852/* pass received skb to LL
848 * Warning: skb must not be accessed anymore! 853 * Warning: skb must not be accessed anymore!
849 */ 854 */
850static inline void gigaset_rcv_skb(struct sk_buff *skb, 855static inline void gigaset_rcv_skb(struct sk_buff *skb,
851 struct cardstate *cs, 856 struct cardstate *cs,
852 struct bc_state *bcs) 857 struct bc_state *bcs)
853{ 858{
854 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb); 859 cs->iif.rcvcallb_skb(cs->myid, bcs->channel, skb);
855 bcs->trans_down++; 860 bcs->trans_down++;
@@ -859,8 +864,8 @@ static inline void gigaset_rcv_skb(struct sk_buff *skb,
859 * Warning: skb must not be accessed anymore! 864 * Warning: skb must not be accessed anymore!
860 */ 865 */
861static inline void gigaset_rcv_error(struct sk_buff *procskb, 866static inline void gigaset_rcv_error(struct sk_buff *procskb,
862 struct cardstate *cs, 867 struct cardstate *cs,
863 struct bc_state *bcs) 868 struct bc_state *bcs)
864{ 869{
865 if (procskb) 870 if (procskb)
866 dev_kfree_skb(procskb); 871 dev_kfree_skb(procskb);
@@ -877,46 +882,9 @@ static inline void gigaset_rcv_error(struct sk_buff *procskb,
877/* bitwise byte inversion table */ 882/* bitwise byte inversion table */
878extern __u8 gigaset_invtab[]; /* in common.c */ 883extern __u8 gigaset_invtab[]; /* in common.c */
879 884
880
881/* append received bytes to inbuf */ 885/* append received bytes to inbuf */
882static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf, 886int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
883 const unsigned char *src, 887 unsigned numbytes);
884 unsigned numbytes)
885{
886 unsigned n, head, tail, bytesleft;
887
888 dbg(DEBUG_INTR, "received %u bytes", numbytes);
889
890 if (!numbytes)
891 return 0;
892
893 bytesleft = numbytes;
894 tail = atomic_read(&inbuf->tail);
895 head = atomic_read(&inbuf->head);
896 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
897
898 while (bytesleft) {
899 if (head > tail)
900 n = head - 1 - tail;
901 else if (head == 0)
902 n = (RBUFSIZE-1) - tail;
903 else
904 n = RBUFSIZE - tail;
905 if (!n) {
906 err("buffer overflow (%u bytes lost)", bytesleft);
907 break;
908 }
909 if (n > bytesleft)
910 n = bytesleft;
911 memcpy(inbuf->data + tail, src, n);
912 bytesleft -= n;
913 tail = (tail + n) % RBUFSIZE;
914 src += n;
915 }
916 dbg(DEBUG_INTR, "setting tail to %u", tail);
917 atomic_set(&inbuf->tail, tail);
918 return numbytes != bytesleft;
919}
920 888
921/* =========================================================================== 889/* ===========================================================================
922 * Functions implemented in interface.c 890 * Functions implemented in interface.c
@@ -924,7 +892,7 @@ static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf,
924 892
925/* initialize interface */ 893/* initialize interface */
926void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 894void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
927 const char *devname, const char *devfsname); 895 const char *devname, const char *devfsname);
928/* release interface */ 896/* release interface */
929void gigaset_if_freedriver(struct gigaset_driver *drv); 897void gigaset_if_freedriver(struct gigaset_driver *drv);
930/* add minor */ 898/* add minor */
@@ -933,6 +901,6 @@ void gigaset_if_init(struct cardstate *cs);
933void gigaset_if_free(struct cardstate *cs); 901void gigaset_if_free(struct cardstate *cs);
934/* device received data */ 902/* device received data */
935void gigaset_if_receive(struct cardstate *cs, 903void gigaset_if_receive(struct cardstate *cs,
936 unsigned char *buffer, size_t len); 904 unsigned char *buffer, size_t len);
937 905
938#endif 906#endif
diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c
index 731a675f21b0..0815dbfb8291 100644
--- a/drivers/isdn/gigaset/i4l.c
+++ b/drivers/isdn/gigaset/i4l.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers (Eilers.Stefan@epost.de), 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp (hjlipp@web.de), 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt (tilman@imap.cc). 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
8 * ===================================================================== 8 * =====================================================================
9 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
@@ -11,15 +11,11 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: i4l.c,v 1.3.2.9 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
21 17
22/* == Handling of I4L IO ============================================================================*/ 18/* == Handling of I4L IO =====================================================*/
23 19
24/* writebuf_from_LL 20/* writebuf_from_LL
25 * called by LL to transmit data on an open channel 21 * called by LL to transmit data on an open channel
@@ -29,14 +25,16 @@
29 * parameters: 25 * parameters:
30 * driverID driver ID as assigned by LL 26 * driverID driver ID as assigned by LL
31 * channel channel number 27 * channel channel number
32 * ack if != 0 LL wants to be notified on completion via statcallb(ISDN_STAT_BSENT) 28 * ack if != 0 LL wants to be notified on completion via
29 * statcallb(ISDN_STAT_BSENT)
33 * skb skb containing data to send 30 * skb skb containing data to send
34 * return value: 31 * return value:
35 * number of accepted bytes 32 * number of accepted bytes
36 * 0 if temporarily unable to accept data (out of buffer space) 33 * 0 if temporarily unable to accept data (out of buffer space)
37 * <0 on error (eg. -EINVAL) 34 * <0 on error (eg. -EINVAL)
38 */ 35 */
39static int writebuf_from_LL(int driverID, int channel, int ack, struct sk_buff *skb) 36static int writebuf_from_LL(int driverID, int channel, int ack,
37 struct sk_buff *skb)
40{ 38{
41 struct cardstate *cs; 39 struct cardstate *cs;
42 struct bc_state *bcs; 40 struct bc_state *bcs;
@@ -54,31 +52,28 @@ static int writebuf_from_LL(int driverID, int channel, int ack, struct sk_buff *
54 bcs = &cs->bcs[channel]; 52 bcs = &cs->bcs[channel];
55 len = skb->len; 53 len = skb->len;
56 54
57 dbg(DEBUG_LLDATA, 55 gig_dbg(DEBUG_LLDATA,
58 "Receiving data from LL (id: %d, channel: %d, ack: %d, size: %d)", 56 "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)",
59 driverID, channel, ack, len); 57 driverID, channel, ack, len);
60 58
61 if (!len) { 59 if (!len) {
62 if (ack) 60 if (ack)
63 warn("not ACKing empty packet from LL"); 61 notice("%s: not ACKing empty packet", __func__);
64 return 0; 62 return 0;
65 } 63 }
66 if (len > MAX_BUF_SIZE) { 64 if (len > MAX_BUF_SIZE) {
67 err("%s: packet too large (%d bytes)", __func__, channel); 65 err("%s: packet too large (%d bytes)", __func__, len);
68 return -EINVAL; 66 return -EINVAL;
69 } 67 }
70 68
71 if (!atomic_read(&cs->connected))
72 return -ENODEV;
73
74 skblen = ack ? len : 0; 69 skblen = ack ? len : 0;
75 skb->head[0] = skblen & 0xff; 70 skb->head[0] = skblen & 0xff;
76 skb->head[1] = skblen >> 8; 71 skb->head[1] = skblen >> 8;
77 dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x", len, skblen, 72 gig_dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x",
78 (unsigned) skb->head[0], (unsigned) skb->head[1]); 73 len, skblen, (unsigned) skb->head[0], (unsigned) skb->head[1]);
79 74
80 /* pass to device-specific module */ 75 /* pass to device-specific module */
81 return cs->ops->send_skb(bcs, skb); 76 return cs->ops->send_skb(bcs, skb); //FIXME cs->ops->send_skb() must handle !cs->connected correctly
82} 77}
83 78
84void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb) 79void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
@@ -89,14 +84,14 @@ void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
89 ++bcs->trans_up; 84 ++bcs->trans_up;
90 85
91 if (skb->len) 86 if (skb->len)
92 warn("%s: skb->len==%d", __func__, skb->len); 87 dev_warn(bcs->cs->dev, "%s: skb->len==%d\n",
88 __func__, skb->len);
93 89
94 len = (unsigned char) skb->head[0] | 90 len = (unsigned char) skb->head[0] |
95 (unsigned) (unsigned char) skb->head[1] << 8; 91 (unsigned) (unsigned char) skb->head[1] << 8;
96 if (len) { 92 if (len) {
97 dbg(DEBUG_MCMD, 93 gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)",
98 "Acknowledge sending to LL (id: %d, channel: %d size: %u)", 94 bcs->cs->myid, bcs->channel, len);
99 bcs->cs->myid, bcs->channel, len);
100 95
101 response.driver = bcs->cs->myid; 96 response.driver = bcs->cs->myid;
102 response.command = ISDN_STAT_BSENT; 97 response.command = ISDN_STAT_BSENT;
@@ -119,15 +114,12 @@ static int command_from_LL(isdn_ctrl *cntrl)
119 struct bc_state *bcs; 114 struct bc_state *bcs;
120 int retval = 0; 115 int retval = 0;
121 struct setup_parm *sp; 116 struct setup_parm *sp;
117 unsigned param;
118 unsigned long flags;
122 119
123 //dbg(DEBUG_ANY, "Gigaset_HW: Receiving command");
124 gigaset_debugdrivers(); 120 gigaset_debugdrivers();
125 121
126 /* Terminate this call if no device is present. Bt if the command is "ISDN_CMD_LOCK" or 122 if (!cs) {
127 * "ISDN_CMD_UNLOCK" then execute it due to the fact that they are device independent !
128 */
129 //FIXME "remove test for &connected"
130 if ((!cs || !atomic_read(&cs->connected))) {
131 warn("LL tried to access unknown device with nr. %d", 123 warn("LL tried to access unknown device with nr. %d",
132 cntrl->driver); 124 cntrl->driver);
133 return -ENODEV; 125 return -ENODEV;
@@ -135,29 +127,30 @@ static int command_from_LL(isdn_ctrl *cntrl)
135 127
136 switch (cntrl->command) { 128 switch (cntrl->command) {
137 case ISDN_CMD_IOCTL: 129 case ISDN_CMD_IOCTL:
138 130 gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)",
139 dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver:%d,arg: %ld)", 131 cntrl->driver, cntrl->arg);
140 cntrl->driver, cntrl->arg);
141 132
142 warn("ISDN_CMD_IOCTL is not supported."); 133 warn("ISDN_CMD_IOCTL is not supported.");
143 return -EINVAL; 134 return -EINVAL;
144 135
145 case ISDN_CMD_DIAL: 136 case ISDN_CMD_DIAL:
146 dbg(DEBUG_ANY, "ISDN_CMD_DIAL (driver: %d, channel: %ld, " 137 gig_dbg(DEBUG_ANY,
147 "phone: %s,ownmsn: %s, si1: %d, si2: %d)", 138 "ISDN_CMD_DIAL (driver: %d, ch: %ld, "
148 cntrl->driver, cntrl->arg, 139 "phone: %s, ownmsn: %s, si1: %d, si2: %d)",
149 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, 140 cntrl->driver, cntrl->arg,
150 cntrl->parm.setup.si1, cntrl->parm.setup.si2); 141 cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
142 cntrl->parm.setup.si1, cntrl->parm.setup.si2);
151 143
152 if (cntrl->arg >= cs->channels) { 144 if (cntrl->arg >= cs->channels) {
153 err("invalid channel (%d)", (int) cntrl->arg); 145 err("ISDN_CMD_DIAL: invalid channel (%d)",
146 (int) cntrl->arg);
154 return -EINVAL; 147 return -EINVAL;
155 } 148 }
156 149
157 bcs = cs->bcs + cntrl->arg; 150 bcs = cs->bcs + cntrl->arg;
158 151
159 if (!gigaset_get_channel(bcs)) { 152 if (!gigaset_get_channel(bcs)) {
160 err("channel not free"); 153 err("ISDN_CMD_DIAL: channel not free");
161 return -EBUSY; 154 return -EBUSY;
162 } 155 }
163 156
@@ -169,42 +162,46 @@ static int command_from_LL(isdn_ctrl *cntrl)
169 } 162 }
170 *sp = cntrl->parm.setup; 163 *sp = cntrl->parm.setup;
171 164
172 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, 165 spin_lock_irqsave(&cs->lock, flags);
173 atomic_read(&bcs->at_state.seq_index), 166 param = bcs->at_state.seq_index;
174 NULL)) { 167 spin_unlock_irqrestore(&cs->lock, flags);
168
169 if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, param,
170 NULL)) {
175 //FIXME what should we do? 171 //FIXME what should we do?
176 kfree(sp); 172 kfree(sp);
177 gigaset_free_channel(bcs); 173 gigaset_free_channel(bcs);
178 return -ENOMEM; 174 return -ENOMEM;
179 } 175 }
180 176
181 dbg(DEBUG_CMD, "scheduling DIAL"); 177 gig_dbg(DEBUG_CMD, "scheduling DIAL");
182 gigaset_schedule_event(cs); 178 gigaset_schedule_event(cs);
183 break; 179 break;
184 case ISDN_CMD_ACCEPTD: //FIXME 180 case ISDN_CMD_ACCEPTD: //FIXME
185 dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD"); 181 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD");
186 182
187 if (cntrl->arg >= cs->channels) { 183 if (cntrl->arg >= cs->channels) {
188 err("invalid channel (%d)", (int) cntrl->arg); 184 err("ISDN_CMD_ACCEPTD: invalid channel (%d)",
185 (int) cntrl->arg);
189 return -EINVAL; 186 return -EINVAL;
190 } 187 }
191 188
192 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, 189 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
193 EV_ACCEPT, NULL, 0, NULL)) { 190 EV_ACCEPT, NULL, 0, NULL)) {
194 //FIXME what should we do? 191 //FIXME what should we do?
195 return -ENOMEM; 192 return -ENOMEM;
196 } 193 }
197 194
198 dbg(DEBUG_CMD, "scheduling ACCEPT"); 195 gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
199 gigaset_schedule_event(cs); 196 gigaset_schedule_event(cs);
200 197
201 break; 198 break;
202 case ISDN_CMD_ACCEPTB: 199 case ISDN_CMD_ACCEPTB:
203 dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB"); 200 gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB");
204 break; 201 break;
205 case ISDN_CMD_HANGUP: 202 case ISDN_CMD_HANGUP:
206 dbg(DEBUG_ANY, 203 gig_dbg(DEBUG_ANY, "ISDN_CMD_HANGUP (ch: %d)",
207 "ISDN_CMD_HANGUP (channel: %d)", (int) cntrl->arg); 204 (int) cntrl->arg);
208 205
209 if (cntrl->arg >= cs->channels) { 206 if (cntrl->arg >= cs->channels) {
210 err("ISDN_CMD_HANGUP: invalid channel (%u)", 207 err("ISDN_CMD_HANGUP: invalid channel (%u)",
@@ -213,66 +210,68 @@ static int command_from_LL(isdn_ctrl *cntrl)
213 } 210 }
214 211
215 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, 212 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state,
216 EV_HUP, NULL, 0, NULL)) { 213 EV_HUP, NULL, 0, NULL)) {
217 //FIXME what should we do? 214 //FIXME what should we do?
218 return -ENOMEM; 215 return -ENOMEM;
219 } 216 }
220 217
221 dbg(DEBUG_CMD, "scheduling HUP"); 218 gig_dbg(DEBUG_CMD, "scheduling HUP");
222 gigaset_schedule_event(cs); 219 gigaset_schedule_event(cs);
223 220
224 break; 221 break;
225 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME 222 case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME
226 dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ"); 223 gig_dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ");
227 break; 224 break;
228 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME 225 case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME
229 dbg(DEBUG_ANY, 226 gig_dbg(DEBUG_ANY,
230 "ISDN_CMD_SETEAZ (id:%d, channel: %ld, number: %s)", 227 "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)",
231 cntrl->driver, cntrl->arg, cntrl->parm.num); 228 cntrl->driver, cntrl->arg, cntrl->parm.num);
232 break; 229 break;
233 case ISDN_CMD_SETL2: /* Set L2 to given protocol */ 230 case ISDN_CMD_SETL2: /* Set L2 to given protocol */
234 dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (Channel: %ld, Proto: %lx)", 231 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)",
235 cntrl->arg & 0xff, (cntrl->arg >> 8)); 232 cntrl->arg & 0xff, (cntrl->arg >> 8));
236 233
237 if ((cntrl->arg & 0xff) >= cs->channels) { 234 if ((cntrl->arg & 0xff) >= cs->channels) {
238 err("invalid channel (%u)", 235 err("ISDN_CMD_SETL2: invalid channel (%u)",
239 (unsigned) cntrl->arg & 0xff); 236 (unsigned) cntrl->arg & 0xff);
240 return -EINVAL; 237 return -EINVAL;
241 } 238 }
242 239
243 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state, 240 if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state,
244 EV_PROTO_L2, NULL, cntrl->arg >> 8, 241 EV_PROTO_L2, NULL, cntrl->arg >> 8,
245 NULL)) { 242 NULL)) {
246 //FIXME what should we do? 243 //FIXME what should we do?
247 return -ENOMEM; 244 return -ENOMEM;
248 } 245 }
249 246
250 dbg(DEBUG_CMD, "scheduling PROTO_L2"); 247 gig_dbg(DEBUG_CMD, "scheduling PROTO_L2");
251 gigaset_schedule_event(cs); 248 gigaset_schedule_event(cs);
252 break; 249 break;
253 case ISDN_CMD_SETL3: /* Set L3 to given protocol */ 250 case ISDN_CMD_SETL3: /* Set L3 to given protocol */
254 dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (Channel: %ld, Proto: %lx)", 251 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)",
255 cntrl->arg & 0xff, (cntrl->arg >> 8)); 252 cntrl->arg & 0xff, (cntrl->arg >> 8));
256 253
257 if ((cntrl->arg & 0xff) >= cs->channels) { 254 if ((cntrl->arg & 0xff) >= cs->channels) {
258 err("invalid channel (%u)", 255 err("ISDN_CMD_SETL3: invalid channel (%u)",
259 (unsigned) cntrl->arg & 0xff); 256 (unsigned) cntrl->arg & 0xff);
260 return -EINVAL; 257 return -EINVAL;
261 } 258 }
262 259
263 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { 260 if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) {
264 err("invalid protocol %lu", cntrl->arg >> 8); 261 err("ISDN_CMD_SETL3: invalid protocol %lu",
262 cntrl->arg >> 8);
265 return -EINVAL; 263 return -EINVAL;
266 } 264 }
267 265
268 break; 266 break;
269 case ISDN_CMD_PROCEED: 267 case ISDN_CMD_PROCEED:
270 dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME 268 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME
271 break; 269 break;
272 case ISDN_CMD_ALERT: 270 case ISDN_CMD_ALERT:
273 dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME 271 gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME
274 if (cntrl->arg >= cs->channels) { 272 if (cntrl->arg >= cs->channels) {
275 err("invalid channel (%d)", (int) cntrl->arg); 273 err("ISDN_CMD_ALERT: invalid channel (%d)",
274 (int) cntrl->arg);
276 return -EINVAL; 275 return -EINVAL;
277 } 276 }
278 //bcs = cs->bcs + cntrl->arg; 277 //bcs = cs->bcs + cntrl->arg;
@@ -280,32 +279,31 @@ static int command_from_LL(isdn_ctrl *cntrl)
280 // FIXME 279 // FIXME
281 break; 280 break;
282 case ISDN_CMD_REDIR: 281 case ISDN_CMD_REDIR:
283 dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME 282 gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME
284 break; 283 break;
285 case ISDN_CMD_PROT_IO: 284 case ISDN_CMD_PROT_IO:
286 dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO"); 285 gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO");
287 break; 286 break;
288 case ISDN_CMD_FAXCMD: 287 case ISDN_CMD_FAXCMD:
289 dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD"); 288 gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
290 break; 289 break;
291 case ISDN_CMD_GETL2: 290 case ISDN_CMD_GETL2:
292 dbg(DEBUG_ANY, "ISDN_CMD_GETL2"); 291 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
293 break; 292 break;
294 case ISDN_CMD_GETL3: 293 case ISDN_CMD_GETL3:
295 dbg(DEBUG_ANY, "ISDN_CMD_GETL3"); 294 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
296 break; 295 break;
297 case ISDN_CMD_GETEAZ: 296 case ISDN_CMD_GETEAZ:
298 dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ"); 297 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
299 break; 298 break;
300 case ISDN_CMD_SETSIL: 299 case ISDN_CMD_SETSIL:
301 dbg(DEBUG_ANY, "ISDN_CMD_SETSIL"); 300 gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
302 break; 301 break;
303 case ISDN_CMD_GETSIL: 302 case ISDN_CMD_GETSIL:
304 dbg(DEBUG_ANY, "ISDN_CMD_GETSIL"); 303 gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
305 break; 304 break;
306 default: 305 default:
307 err("unknown command %d from LL", 306 err("unknown command %d from LL", cntrl->command);
308 cntrl->command);
309 return -EINVAL; 307 return -EINVAL;
310 } 308 }
311 309
@@ -350,7 +348,8 @@ int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
350 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */ 348 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
351 break; 349 break;
352 default: 350 default:
353 err("invalid protocol: %u", bcs->proto2); 351 dev_err(bcs->cs->dev, "%s: invalid L2 protocol: %u\n",
352 __func__, bcs->proto2);
354 return -EINVAL; 353 return -EINVAL;
355 } 354 }
356 355
@@ -378,7 +377,7 @@ int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
378 bcs->commands[i] = NULL; 377 bcs->commands[i] = NULL;
379 if (length[i] && 378 if (length[i] &&
380 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) { 379 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
381 err("out of memory"); 380 dev_err(bcs->cs->dev, "out of memory\n");
382 return -ENOMEM; 381 return -ENOMEM;
383 } 382 }
384 } 383 }
@@ -396,10 +395,14 @@ int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data)
396 } 395 }
397 396
398 if (bcs->commands[AT_MSN]) 397 if (bcs->commands[AT_MSN])
399 snprintf(bcs->commands[AT_MSN], length[AT_MSN], "^SMSN=%s\r", sp->eazmsn); 398 snprintf(bcs->commands[AT_MSN], length[AT_MSN],
400 snprintf(bcs->commands[AT_BC ], length[AT_BC ], "^SBC=%s\r", bc); 399 "^SMSN=%s\r", sp->eazmsn);
401 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], "^SBPR=%u\r", proto); 400 snprintf(bcs->commands[AT_BC ], length[AT_BC ],
402 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], "^SISO=%u\r", (unsigned)bcs->channel + 1); 401 "^SBC=%s\r", bc);
402 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
403 "^SBPR=%u\r", proto);
404 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
405 "^SISO=%u\r", (unsigned)bcs->channel + 1);
403 406
404 return 0; 407 return 0;
405} 408}
@@ -419,7 +422,8 @@ int gigaset_isdn_setup_accept(struct at_state_t *at_state)
419 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */ 422 proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */
420 break; 423 break;
421 default: 424 default:
422 err("invalid protocol: %u", bcs->proto2); 425 dev_err(at_state->cs->dev, "%s: invalid protocol: %u\n",
426 __func__, bcs->proto2);
423 return -EINVAL; 427 return -EINVAL;
424 } 428 }
425 429
@@ -436,13 +440,15 @@ int gigaset_isdn_setup_accept(struct at_state_t *at_state)
436 bcs->commands[i] = NULL; 440 bcs->commands[i] = NULL;
437 if (length[i] && 441 if (length[i] &&
438 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) { 442 !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) {
439 err("out of memory"); 443 dev_err(at_state->cs->dev, "out of memory\n");
440 return -ENOMEM; 444 return -ENOMEM;
441 } 445 }
442 } 446 }
443 447
444 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], "^SBPR=%u\r", proto); 448 snprintf(bcs->commands[AT_PROTO], length[AT_PROTO],
445 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], "^SISO=%u\r", (unsigned) bcs->channel + 1); 449 "^SBPR=%u\r", proto);
450 snprintf(bcs->commands[AT_ISO ], length[AT_ISO ],
451 "^SISO=%u\r", (unsigned) bcs->channel + 1);
446 452
447 return 0; 453 return 0;
448} 454}
@@ -473,7 +479,7 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
473 response.parm.setup.si1 = 1; 479 response.parm.setup.si1 = 1;
474 response.parm.setup.si2 = 2; 480 response.parm.setup.si2 = 2;
475 } else { 481 } else {
476 warn("RING ignored - unsupported BC %s", 482 dev_warn(cs->dev, "RING ignored - unsupported BC %s\n",
477 at_state->str_var[STR_ZBC]); 483 at_state->str_var[STR_ZBC]);
478 return ICALL_IGNORE; 484 return ICALL_IGNORE;
479 } 485 }
@@ -491,18 +497,17 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
491 response.parm.setup.eazmsn[0] = 0; 497 response.parm.setup.eazmsn[0] = 0;
492 498
493 if (!bcs) { 499 if (!bcs) {
494 notice("no channel for incoming call"); 500 dev_notice(cs->dev, "no channel for incoming call\n");
495 dbg(DEBUG_CMD, "Sending ICALLW");
496 response.command = ISDN_STAT_ICALLW; 501 response.command = ISDN_STAT_ICALLW;
497 response.arg = 0; //FIXME 502 response.arg = 0; //FIXME
498 } else { 503 } else {
499 dbg(DEBUG_CMD, "Sending ICALL"); 504 gig_dbg(DEBUG_CMD, "Sending ICALL");
500 response.command = ISDN_STAT_ICALL; 505 response.command = ISDN_STAT_ICALL;
501 response.arg = bcs->channel; //FIXME 506 response.arg = bcs->channel; //FIXME
502 } 507 }
503 response.driver = cs->myid; 508 response.driver = cs->myid;
504 retval = cs->iif.statcallb(&response); 509 retval = cs->iif.statcallb(&response);
505 dbg(DEBUG_CMD, "Response: %d", retval); 510 gig_dbg(DEBUG_CMD, "Response: %d", retval);
506 switch (retval) { 511 switch (retval) {
507 case 0: /* no takers */ 512 case 0: /* no takers */
508 return ICALL_IGNORE; 513 return ICALL_IGNORE;
@@ -512,7 +517,8 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
512 case 2: /* reject */ 517 case 2: /* reject */
513 return ICALL_REJECT; 518 return ICALL_REJECT;
514 case 3: /* incomplete */ 519 case 3: /* incomplete */
515 warn("LL requested unsupported feature: Incomplete Number"); 520 dev_warn(cs->dev,
521 "LL requested unsupported feature: Incomplete Number\n");
516 return ICALL_IGNORE; 522 return ICALL_IGNORE;
517 case 4: /* proceeding */ 523 case 4: /* proceeding */
518 /* Gigaset will send ALERTING anyway. 524 /* Gigaset will send ALERTING anyway.
@@ -520,10 +526,11 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
520 */ 526 */
521 return ICALL_ACCEPT; 527 return ICALL_ACCEPT;
522 case 5: /* deflect */ 528 case 5: /* deflect */
523 warn("LL requested unsupported feature: Call Deflection"); 529 dev_warn(cs->dev,
530 "LL requested unsupported feature: Call Deflection\n");
524 return ICALL_IGNORE; 531 return ICALL_IGNORE;
525 default: 532 default:
526 err("LL error %d on ICALL", retval); 533 dev_err(cs->dev, "LL error %d on ICALL\n", retval);
527 return ICALL_IGNORE; 534 return ICALL_IGNORE;
528 } 535 }
529} 536}
@@ -533,7 +540,7 @@ int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
533{ 540{
534 isdn_if *iif = &cs->iif; 541 isdn_if *iif = &cs->iif;
535 542
536 dbg(DEBUG_ANY, "Register driver capabilities to LL"); 543 gig_dbg(DEBUG_ANY, "Register driver capabilities to LL");
537 544
538 //iif->id[sizeof(iif->id) - 1]=0; 545 //iif->id[sizeof(iif->id) - 1]=0;
539 //strncpy(iif->id, isdnid, sizeof(iif->id) - 1); 546 //strncpy(iif->id, isdnid, sizeof(iif->id) - 1);
@@ -542,26 +549,26 @@ int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid)
542 return -ENOMEM; //FIXME EINVAL/...?? 549 return -ENOMEM; //FIXME EINVAL/...??
543 550
544 iif->owner = THIS_MODULE; 551 iif->owner = THIS_MODULE;
545 iif->channels = cs->channels; /* I am supporting just one channel *//* I was supporting...*/ 552 iif->channels = cs->channels;
546 iif->maxbufsize = MAX_BUF_SIZE; 553 iif->maxbufsize = MAX_BUF_SIZE;
547 iif->features = ISDN_FEATURE_L2_TRANS | /* Our device is very advanced, therefore */ 554 iif->features = ISDN_FEATURE_L2_TRANS |
548 ISDN_FEATURE_L2_HDLC | 555 ISDN_FEATURE_L2_HDLC |
549#ifdef GIG_X75 556#ifdef GIG_X75
550 ISDN_FEATURE_L2_X75I | 557 ISDN_FEATURE_L2_X75I |
551#endif 558#endif
552 ISDN_FEATURE_L3_TRANS | 559 ISDN_FEATURE_L3_TRANS |
553 ISDN_FEATURE_P_EURO; 560 ISDN_FEATURE_P_EURO;
554 iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */ 561 iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */
555 iif->command = command_from_LL; 562 iif->command = command_from_LL;
556 iif->writebuf_skb = writebuf_from_LL; 563 iif->writebuf_skb = writebuf_from_LL;
557 iif->writecmd = NULL; /* Don't support isdnctrl */ 564 iif->writecmd = NULL; /* Don't support isdnctrl */
558 iif->readstat = NULL; /* Don't support isdnctrl */ 565 iif->readstat = NULL; /* Don't support isdnctrl */
559 iif->rcvcallb_skb = NULL; /* Will be set by LL */ 566 iif->rcvcallb_skb = NULL; /* Will be set by LL */
560 iif->statcallb = NULL; /* Will be set by LL */ 567 iif->statcallb = NULL; /* Will be set by LL */
561 568
562 if (!register_isdn(iif)) 569 if (!register_isdn(iif))
563 return 0; 570 return 0;
564 571
565 cs->myid = iif->channels; /* Set my device id */ 572 cs->myid = iif->channels; /* Set my device id */
566 return 1; 573 return 1;
567} 574}
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index 3a81d9c65141..08e4c4eea14d 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -9,8 +9,6 @@
9 * published by the Free Software Foundation; either version 2 of 9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version. 10 * the License, or (at your option) any later version.
11 * ===================================================================== 11 * =====================================================================
12 * Version: $Id: interface.c,v 1.14.4.15 2006/02/04 18:28:16 hjlipp Exp $
13 * =====================================================================
14 */ 12 */
15 13
16#include "gigaset.h" 14#include "gigaset.h"
@@ -24,7 +22,7 @@ static int if_lock(struct cardstate *cs, int *arg)
24{ 22{
25 int cmd = *arg; 23 int cmd = *arg;
26 24
27 dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd); 25 gig_dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd);
28 26
29 if (cmd > 1) 27 if (cmd > 1)
30 return -EINVAL; 28 return -EINVAL;
@@ -35,7 +33,7 @@ static int if_lock(struct cardstate *cs, int *arg)
35 } 33 }
36 34
37 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED 35 if (!cmd && atomic_read(&cs->mstate) == MS_LOCKED
38 && atomic_read(&cs->connected)) { 36 && cs->connected) {
39 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS); 37 cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR|TIOCM_RTS);
40 cs->ops->baud_rate(cs, B115200); 38 cs->ops->baud_rate(cs, B115200);
41 cs->ops->set_line_ctrl(cs, CS8); 39 cs->ops->set_line_ctrl(cs, CS8);
@@ -44,12 +42,12 @@ static int if_lock(struct cardstate *cs, int *arg)
44 42
45 cs->waiting = 1; 43 cs->waiting = 1;
46 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK, 44 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
47 NULL, cmd, NULL)) { 45 NULL, cmd, NULL)) {
48 cs->waiting = 0; 46 cs->waiting = 0;
49 return -ENOMEM; 47 return -ENOMEM;
50 } 48 }
51 49
52 dbg(DEBUG_CMD, "scheduling IF_LOCK"); 50 gig_dbg(DEBUG_CMD, "scheduling IF_LOCK");
53 gigaset_schedule_event(cs); 51 gigaset_schedule_event(cs);
54 52
55 wait_event(cs->waitqueue, !cs->waiting); 53 wait_event(cs->waitqueue, !cs->waiting);
@@ -68,7 +66,7 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
68 static const unsigned compat[4] = GIG_COMPAT; 66 static const unsigned compat[4] = GIG_COMPAT;
69 unsigned cmd = arg[0]; 67 unsigned cmd = arg[0];
70 68
71 dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd); 69 gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
72 70
73 switch (cmd) { 71 switch (cmd) {
74 case GIGVER_DRIVER: 72 case GIGVER_DRIVER:
@@ -80,12 +78,12 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
80 case GIGVER_FWBASE: 78 case GIGVER_FWBASE:
81 cs->waiting = 1; 79 cs->waiting = 1;
82 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER, 80 if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
83 NULL, 0, arg)) { 81 NULL, 0, arg)) {
84 cs->waiting = 0; 82 cs->waiting = 0;
85 return -ENOMEM; 83 return -ENOMEM;
86 } 84 }
87 85
88 dbg(DEBUG_CMD, "scheduling IF_VER"); 86 gig_dbg(DEBUG_CMD, "scheduling IF_VER");
89 gigaset_schedule_event(cs); 87 gigaset_schedule_event(cs);
90 88
91 wait_event(cs->waitqueue, !cs->waiting); 89 wait_event(cs->waitqueue, !cs->waiting);
@@ -101,7 +99,7 @@ static int if_version(struct cardstate *cs, unsigned arg[4])
101 99
102static int if_config(struct cardstate *cs, int *arg) 100static int if_config(struct cardstate *cs, int *arg)
103{ 101{
104 dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg); 102 gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
105 103
106 if (*arg != 1) 104 if (*arg != 1)
107 return -EINVAL; 105 return -EINVAL;
@@ -109,6 +107,11 @@ static int if_config(struct cardstate *cs, int *arg)
109 if (atomic_read(&cs->mstate) != MS_LOCKED) 107 if (atomic_read(&cs->mstate) != MS_LOCKED)
110 return -EBUSY; 108 return -EBUSY;
111 109
110 if (!cs->connected) {
111 err("not connected!");
112 return -ENODEV;
113 }
114
112 *arg = 0; 115 *arg = 0;
113 return gigaset_enterconfigmode(cs); 116 return gigaset_enterconfigmode(cs);
114} 117}
@@ -119,7 +122,7 @@ static int if_config(struct cardstate *cs, int *arg)
119static int if_open(struct tty_struct *tty, struct file *filp); 122static int if_open(struct tty_struct *tty, struct file *filp);
120static void if_close(struct tty_struct *tty, struct file *filp); 123static void if_close(struct tty_struct *tty, struct file *filp);
121static int if_ioctl(struct tty_struct *tty, struct file *file, 124static int if_ioctl(struct tty_struct *tty, struct file *file,
122 unsigned int cmd, unsigned long arg); 125 unsigned int cmd, unsigned long arg);
123static int if_write_room(struct tty_struct *tty); 126static int if_write_room(struct tty_struct *tty);
124static int if_chars_in_buffer(struct tty_struct *tty); 127static int if_chars_in_buffer(struct tty_struct *tty);
125static void if_throttle(struct tty_struct *tty); 128static void if_throttle(struct tty_struct *tty);
@@ -127,9 +130,9 @@ static void if_unthrottle(struct tty_struct *tty);
127static void if_set_termios(struct tty_struct *tty, struct termios *old); 130static void if_set_termios(struct tty_struct *tty, struct termios *old);
128static int if_tiocmget(struct tty_struct *tty, struct file *file); 131static int if_tiocmget(struct tty_struct *tty, struct file *file);
129static int if_tiocmset(struct tty_struct *tty, struct file *file, 132static int if_tiocmset(struct tty_struct *tty, struct file *file,
130 unsigned int set, unsigned int clear); 133 unsigned int set, unsigned int clear);
131static int if_write(struct tty_struct *tty, 134static int if_write(struct tty_struct *tty,
132 const unsigned char *buf, int count); 135 const unsigned char *buf, int count);
133 136
134static struct tty_operations if_ops = { 137static struct tty_operations if_ops = {
135 .open = if_open, 138 .open = if_open,
@@ -153,8 +156,8 @@ static int if_open(struct tty_struct *tty, struct file *filp)
153 struct cardstate *cs; 156 struct cardstate *cs;
154 unsigned long flags; 157 unsigned long flags;
155 158
156 dbg(DEBUG_IF, "%d+%d: %s()", tty->driver->minor_start, tty->index, 159 gig_dbg(DEBUG_IF, "%d+%d: %s()",
157 __FUNCTION__); 160 tty->driver->minor_start, tty->index, __func__);
158 161
159 tty->driver_data = NULL; 162 tty->driver_data = NULL;
160 163
@@ -162,7 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
162 if (!cs) 165 if (!cs)
163 return -ENODEV; 166 return -ENODEV;
164 167
165 if (down_interruptible(&cs->sem)) 168 if (mutex_lock_interruptible(&cs->mutex))
166 return -ERESTARTSYS; // FIXME -EINTR? 169 return -ERESTARTSYS; // FIXME -EINTR?
167 tty->driver_data = cs; 170 tty->driver_data = cs;
168 171
@@ -173,10 +176,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
173 cs->tty = tty; 176 cs->tty = tty;
174 spin_unlock_irqrestore(&cs->lock, flags); 177 spin_unlock_irqrestore(&cs->lock, flags);
175 tty->low_latency = 1; //FIXME test 178 tty->low_latency = 1; //FIXME test
176 //FIXME
177 } 179 }
178 180
179 up(&cs->sem); 181 mutex_unlock(&cs->mutex);
180 return 0; 182 return 0;
181} 183}
182 184
@@ -187,30 +189,29 @@ static void if_close(struct tty_struct *tty, struct file *filp)
187 189
188 cs = (struct cardstate *) tty->driver_data; 190 cs = (struct cardstate *) tty->driver_data;
189 if (!cs) { 191 if (!cs) {
190 err("cs==NULL in %s", __FUNCTION__); 192 err("cs==NULL in %s", __func__);
191 return; 193 return;
192 } 194 }
193 195
194 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 196 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
195 197
196 down(&cs->sem); 198 mutex_lock(&cs->mutex);
197 199
198 if (!cs->open_count) 200 if (!cs->open_count)
199 warn("%s: device not opened", __FUNCTION__); 201 warn("%s: device not opened", __func__);
200 else { 202 else {
201 if (!--cs->open_count) { 203 if (!--cs->open_count) {
202 spin_lock_irqsave(&cs->lock, flags); 204 spin_lock_irqsave(&cs->lock, flags);
203 cs->tty = NULL; 205 cs->tty = NULL;
204 spin_unlock_irqrestore(&cs->lock, flags); 206 spin_unlock_irqrestore(&cs->lock, flags);
205 //FIXME
206 } 207 }
207 } 208 }
208 209
209 up(&cs->sem); 210 mutex_unlock(&cs->mutex);
210} 211}
211 212
212static int if_ioctl(struct tty_struct *tty, struct file *file, 213static int if_ioctl(struct tty_struct *tty, struct file *file,
213 unsigned int cmd, unsigned long arg) 214 unsigned int cmd, unsigned long arg)
214{ 215{
215 struct cardstate *cs; 216 struct cardstate *cs;
216 int retval = -ENODEV; 217 int retval = -ENODEV;
@@ -220,17 +221,17 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
220 221
221 cs = (struct cardstate *) tty->driver_data; 222 cs = (struct cardstate *) tty->driver_data;
222 if (!cs) { 223 if (!cs) {
223 err("cs==NULL in %s", __FUNCTION__); 224 err("cs==NULL in %s", __func__);
224 return -ENODEV; 225 return -ENODEV;
225 } 226 }
226 227
227 dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __FUNCTION__, cmd); 228 gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
228 229
229 if (down_interruptible(&cs->sem)) 230 if (mutex_lock_interruptible(&cs->mutex))
230 return -ERESTARTSYS; // FIXME -EINTR? 231 return -ERESTARTSYS; // FIXME -EINTR?
231 232
232 if (!cs->open_count) 233 if (!cs->open_count)
233 warn("%s: device not opened", __FUNCTION__); 234 warn("%s: device not opened", __func__);
234 else { 235 else {
235 retval = 0; 236 retval = 0;
236 switch (cmd) { 237 switch (cmd) {
@@ -250,37 +251,40 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
250 break; 251 break;
251 case GIGASET_BRKCHARS: 252 case GIGASET_BRKCHARS:
252 //FIXME test if MS_LOCKED 253 //FIXME test if MS_LOCKED
253 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS", 254 if (!cs->connected) {
254 6, (const unsigned char *) arg, 1); 255 gig_dbg(DEBUG_ANY,
255 if (!atomic_read(&cs->connected)) { 256 "can't communicate with unplugged device");
256 dbg(DEBUG_ANY, "can't communicate with unplugged device");
257 retval = -ENODEV; 257 retval = -ENODEV;
258 break; 258 break;
259 } 259 }
260 retval = copy_from_user(&buf, 260 retval = copy_from_user(&buf,
261 (const unsigned char __user *) arg, 6) 261 (const unsigned char __user *) arg, 6)
262 ? -EFAULT : 0; 262 ? -EFAULT : 0;
263 if (retval >= 0) 263 if (retval >= 0) {
264 gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
265 6, (const unsigned char *) arg);
264 retval = cs->ops->brkchars(cs, buf); 266 retval = cs->ops->brkchars(cs, buf);
267 }
265 break; 268 break;
266 case GIGASET_VERSION: 269 case GIGASET_VERSION:
267 retval = copy_from_user(version, (unsigned __user *) arg, 270 retval = copy_from_user(version,
268 sizeof version) ? -EFAULT : 0; 271 (unsigned __user *) arg, sizeof version)
272 ? -EFAULT : 0;
269 if (retval >= 0) 273 if (retval >= 0)
270 retval = if_version(cs, version); 274 retval = if_version(cs, version);
271 if (retval >= 0) 275 if (retval >= 0)
272 retval = copy_to_user((unsigned __user *) arg, version, 276 retval = copy_to_user((unsigned __user *) arg,
273 sizeof version) 277 version, sizeof version)
274 ? -EFAULT : 0; 278 ? -EFAULT : 0;
275 break; 279 break;
276 default: 280 default:
277 dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x", 281 gig_dbg(DEBUG_ANY, "%s: arg not supported - 0x%04x",
278 __FUNCTION__, cmd); 282 __func__, cmd);
279 retval = -ENOIOCTLCMD; 283 retval = -ENOIOCTLCMD;
280 } 284 }
281 } 285 }
282 286
283 up(&cs->sem); 287 mutex_unlock(&cs->mutex);
284 288
285 return retval; 289 return retval;
286} 290}
@@ -292,25 +296,25 @@ static int if_tiocmget(struct tty_struct *tty, struct file *file)
292 296
293 cs = (struct cardstate *) tty->driver_data; 297 cs = (struct cardstate *) tty->driver_data;
294 if (!cs) { 298 if (!cs) {
295 err("cs==NULL in %s", __FUNCTION__); 299 err("cs==NULL in %s", __func__);
296 return -ENODEV; 300 return -ENODEV;
297 } 301 }
298 302
299 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 303 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
300 304
301 if (down_interruptible(&cs->sem)) 305 if (mutex_lock_interruptible(&cs->mutex))
302 return -ERESTARTSYS; // FIXME -EINTR? 306 return -ERESTARTSYS; // FIXME -EINTR?
303 307
304 // FIXME read from device? 308 // FIXME read from device?
305 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR); 309 retval = cs->control_state & (TIOCM_RTS|TIOCM_DTR);
306 310
307 up(&cs->sem); 311 mutex_unlock(&cs->mutex);
308 312
309 return retval; 313 return retval;
310} 314}
311 315
312static int if_tiocmset(struct tty_struct *tty, struct file *file, 316static int if_tiocmset(struct tty_struct *tty, struct file *file,
313 unsigned int set, unsigned int clear) 317 unsigned int set, unsigned int clear)
314{ 318{
315 struct cardstate *cs; 319 struct cardstate *cs;
316 int retval; 320 int retval;
@@ -318,18 +322,18 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
318 322
319 cs = (struct cardstate *) tty->driver_data; 323 cs = (struct cardstate *) tty->driver_data;
320 if (!cs) { 324 if (!cs) {
321 err("cs==NULL in %s", __FUNCTION__); 325 err("cs==NULL in %s", __func__);
322 return -ENODEV; 326 return -ENODEV;
323 } 327 }
324 328
325 dbg(DEBUG_IF, 329 gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
326 "%u: %s(0x%x, 0x%x)", cs->minor_index, __FUNCTION__, set, clear); 330 cs->minor_index, __func__, set, clear);
327 331
328 if (down_interruptible(&cs->sem)) 332 if (mutex_lock_interruptible(&cs->mutex))
329 return -ERESTARTSYS; // FIXME -EINTR? 333 return -ERESTARTSYS; // FIXME -EINTR?
330 334
331 if (!atomic_read(&cs->connected)) { 335 if (!cs->connected) {
332 dbg(DEBUG_ANY, "can't communicate with unplugged device"); 336 gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
333 retval = -ENODEV; 337 retval = -ENODEV;
334 } else { 338 } else {
335 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR); 339 mc = (cs->control_state | set) & ~clear & (TIOCM_RTS|TIOCM_DTR);
@@ -337,7 +341,7 @@ static int if_tiocmset(struct tty_struct *tty, struct file *file,
337 cs->control_state = mc; 341 cs->control_state = mc;
338 } 342 }
339 343
340 up(&cs->sem); 344 mutex_unlock(&cs->mutex);
341 345
342 return retval; 346 return retval;
343} 347}
@@ -349,29 +353,29 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
349 353
350 cs = (struct cardstate *) tty->driver_data; 354 cs = (struct cardstate *) tty->driver_data;
351 if (!cs) { 355 if (!cs) {
352 err("cs==NULL in %s", __FUNCTION__); 356 err("cs==NULL in %s", __func__);
353 return -ENODEV; 357 return -ENODEV;
354 } 358 }
355 359
356 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 360 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
357 361
358 if (down_interruptible(&cs->sem)) 362 if (mutex_lock_interruptible(&cs->mutex))
359 return -ERESTARTSYS; // FIXME -EINTR? 363 return -ERESTARTSYS; // FIXME -EINTR?
360 364
361 if (!cs->open_count) 365 if (!cs->open_count)
362 warn("%s: device not opened", __FUNCTION__); 366 warn("%s: device not opened", __func__);
363 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 367 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
364 warn("can't write to unlocked device"); 368 warn("can't write to unlocked device");
365 retval = -EBUSY; 369 retval = -EBUSY;
366 } else if (!atomic_read(&cs->connected)) { 370 } else if (!cs->connected) {
367 dbg(DEBUG_ANY, "can't write to unplugged device"); 371 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
368 retval = -EBUSY; //FIXME 372 retval = -EBUSY; //FIXME
369 } else { 373 } else {
370 retval = cs->ops->write_cmd(cs, buf, count, 374 retval = cs->ops->write_cmd(cs, buf, count,
371 &cs->if_wake_tasklet); 375 &cs->if_wake_tasklet);
372 } 376 }
373 377
374 up(&cs->sem); 378 mutex_unlock(&cs->mutex);
375 379
376 return retval; 380 return retval;
377} 381}
@@ -383,27 +387,27 @@ static int if_write_room(struct tty_struct *tty)
383 387
384 cs = (struct cardstate *) tty->driver_data; 388 cs = (struct cardstate *) tty->driver_data;
385 if (!cs) { 389 if (!cs) {
386 err("cs==NULL in %s", __FUNCTION__); 390 err("cs==NULL in %s", __func__);
387 return -ENODEV; 391 return -ENODEV;
388 } 392 }
389 393
390 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 394 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
391 395
392 if (down_interruptible(&cs->sem)) 396 if (mutex_lock_interruptible(&cs->mutex))
393 return -ERESTARTSYS; // FIXME -EINTR? 397 return -ERESTARTSYS; // FIXME -EINTR?
394 398
395 if (!cs->open_count) 399 if (!cs->open_count)
396 warn("%s: device not opened", __FUNCTION__); 400 warn("%s: device not opened", __func__);
397 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 401 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
398 warn("can't write to unlocked device"); 402 warn("can't write to unlocked device");
399 retval = -EBUSY; //FIXME 403 retval = -EBUSY; //FIXME
400 } else if (!atomic_read(&cs->connected)) { 404 } else if (!cs->connected) {
401 dbg(DEBUG_ANY, "can't write to unplugged device"); 405 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
402 retval = -EBUSY; //FIXME 406 retval = -EBUSY; //FIXME
403 } else 407 } else
404 retval = cs->ops->write_room(cs); 408 retval = cs->ops->write_room(cs);
405 409
406 up(&cs->sem); 410 mutex_unlock(&cs->mutex);
407 411
408 return retval; 412 return retval;
409} 413}
@@ -415,27 +419,27 @@ static int if_chars_in_buffer(struct tty_struct *tty)
415 419
416 cs = (struct cardstate *) tty->driver_data; 420 cs = (struct cardstate *) tty->driver_data;
417 if (!cs) { 421 if (!cs) {
418 err("cs==NULL in %s", __FUNCTION__); 422 err("cs==NULL in %s", __func__);
419 return -ENODEV; 423 return -ENODEV;
420 } 424 }
421 425
422 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 426 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
423 427
424 if (down_interruptible(&cs->sem)) 428 if (mutex_lock_interruptible(&cs->mutex))
425 return -ERESTARTSYS; // FIXME -EINTR? 429 return -ERESTARTSYS; // FIXME -EINTR?
426 430
427 if (!cs->open_count) 431 if (!cs->open_count)
428 warn("%s: device not opened", __FUNCTION__); 432 warn("%s: device not opened", __func__);
429 else if (atomic_read(&cs->mstate) != MS_LOCKED) { 433 else if (atomic_read(&cs->mstate) != MS_LOCKED) {
430 warn("can't write to unlocked device"); 434 warn("can't write to unlocked device");
431 retval = -EBUSY; 435 retval = -EBUSY;
432 } else if (!atomic_read(&cs->connected)) { 436 } else if (!cs->connected) {
433 dbg(DEBUG_ANY, "can't write to unplugged device"); 437 gig_dbg(DEBUG_ANY, "can't write to unplugged device");
434 retval = -EBUSY; //FIXME 438 retval = -EBUSY; //FIXME
435 } else 439 } else
436 retval = cs->ops->chars_in_buffer(cs); 440 retval = cs->ops->chars_in_buffer(cs);
437 441
438 up(&cs->sem); 442 mutex_unlock(&cs->mutex);
439 443
440 return retval; 444 return retval;
441} 445}
@@ -446,21 +450,21 @@ static void if_throttle(struct tty_struct *tty)
446 450
447 cs = (struct cardstate *) tty->driver_data; 451 cs = (struct cardstate *) tty->driver_data;
448 if (!cs) { 452 if (!cs) {
449 err("cs==NULL in %s", __FUNCTION__); 453 err("cs==NULL in %s", __func__);
450 return; 454 return;
451 } 455 }
452 456
453 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 457 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
454 458
455 down(&cs->sem); 459 mutex_lock(&cs->mutex);
456 460
457 if (!cs->open_count) 461 if (!cs->open_count)
458 warn("%s: device not opened", __FUNCTION__); 462 warn("%s: device not opened", __func__);
459 else { 463 else {
460 //FIXME 464 //FIXME
461 } 465 }
462 466
463 up(&cs->sem); 467 mutex_unlock(&cs->mutex);
464} 468}
465 469
466static void if_unthrottle(struct tty_struct *tty) 470static void if_unthrottle(struct tty_struct *tty)
@@ -469,21 +473,21 @@ static void if_unthrottle(struct tty_struct *tty)
469 473
470 cs = (struct cardstate *) tty->driver_data; 474 cs = (struct cardstate *) tty->driver_data;
471 if (!cs) { 475 if (!cs) {
472 err("cs==NULL in %s", __FUNCTION__); 476 err("cs==NULL in %s", __func__);
473 return; 477 return;
474 } 478 }
475 479
476 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 480 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
477 481
478 down(&cs->sem); 482 mutex_lock(&cs->mutex);
479 483
480 if (!cs->open_count) 484 if (!cs->open_count)
481 warn("%s: device not opened", __FUNCTION__); 485 warn("%s: device not opened", __func__);
482 else { 486 else {
483 //FIXME 487 //FIXME
484 } 488 }
485 489
486 up(&cs->sem); 490 mutex_unlock(&cs->mutex);
487} 491}
488 492
489static void if_set_termios(struct tty_struct *tty, struct termios *old) 493static void if_set_termios(struct tty_struct *tty, struct termios *old)
@@ -496,21 +500,21 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
496 500
497 cs = (struct cardstate *) tty->driver_data; 501 cs = (struct cardstate *) tty->driver_data;
498 if (!cs) { 502 if (!cs) {
499 err("cs==NULL in %s", __FUNCTION__); 503 err("cs==NULL in %s", __func__);
500 return; 504 return;
501 } 505 }
502 506
503 dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __FUNCTION__); 507 gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
504 508
505 down(&cs->sem); 509 mutex_lock(&cs->mutex);
506 510
507 if (!cs->open_count) { 511 if (!cs->open_count) {
508 warn("%s: device not opened", __FUNCTION__); 512 warn("%s: device not opened", __func__);
509 goto out; 513 goto out;
510 } 514 }
511 515
512 if (!atomic_read(&cs->connected)) { 516 if (!cs->connected) {
513 dbg(DEBUG_ANY, "can't communicate with unplugged device"); 517 gig_dbg(DEBUG_ANY, "can't communicate with unplugged device");
514 goto out; 518 goto out;
515 } 519 }
516 520
@@ -518,8 +522,8 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
518 iflag = tty->termios->c_iflag; 522 iflag = tty->termios->c_iflag;
519 cflag = tty->termios->c_cflag; 523 cflag = tty->termios->c_cflag;
520 old_cflag = old ? old->c_cflag : cflag; //FIXME? 524 old_cflag = old ? old->c_cflag : cflag; //FIXME?
521 dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x", cs->minor_index, 525 gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
522 iflag, cflag, old_cflag); 526 cs->minor_index, iflag, cflag, old_cflag);
523 527
524 /* get a local copy of the current port settings */ 528 /* get a local copy of the current port settings */
525 control_state = cs->control_state; 529 control_state = cs->control_state;
@@ -531,14 +535,15 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
531 * Premature optimization is the root of all evil. 535 * Premature optimization is the root of all evil.
532 */ 536 */
533 537
534 /* reassert DTR and (maybe) RTS on transition from B0 */ 538 /* reassert DTR and (maybe) RTS on transition from B0 */
535 if ((old_cflag & CBAUD) == B0) { 539 if ((old_cflag & CBAUD) == B0) {
536 new_state = control_state | TIOCM_DTR; 540 new_state = control_state | TIOCM_DTR;
537 /* don't set RTS if using hardware flow control */ 541 /* don't set RTS if using hardware flow control */
538 if (!(old_cflag & CRTSCTS)) 542 if (!(old_cflag & CRTSCTS))
539 new_state |= TIOCM_RTS; 543 new_state |= TIOCM_RTS;
540 dbg(DEBUG_IF, "%u: from B0 - set DTR%s", cs->minor_index, 544 gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
541 (new_state & TIOCM_RTS) ? " only" : "/RTS"); 545 cs->minor_index,
546 (new_state & TIOCM_RTS) ? " only" : "/RTS");
542 cs->ops->set_modem_ctrl(cs, control_state, new_state); 547 cs->ops->set_modem_ctrl(cs, control_state, new_state);
543 control_state = new_state; 548 control_state = new_state;
544 } 549 }
@@ -547,7 +552,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
547 552
548 if ((cflag & CBAUD) == B0) { 553 if ((cflag & CBAUD) == B0) {
549 /* Drop RTS and DTR */ 554 /* Drop RTS and DTR */
550 dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index); 555 gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
551 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS); 556 new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
552 cs->ops->set_modem_ctrl(cs, control_state, new_state); 557 cs->ops->set_modem_ctrl(cs, control_state, new_state);
553 control_state = new_state; 558 control_state = new_state;
@@ -567,15 +572,17 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
567 * Just do what we have seen with SniffUSB on Win98. 572 * Just do what we have seen with SniffUSB on Win98.
568 */ 573 */
569 /* Drop DTR/RTS if no flow control otherwise assert */ 574 /* Drop DTR/RTS if no flow control otherwise assert */
570 dbg(DEBUG_IF, "%u: control_state %x", cs->minor_index, control_state); 575 gig_dbg(DEBUG_IF, "%u: control_state %x",
576 cs->minor_index, control_state);
571 new_state = control_state; 577 new_state = control_state;
572 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS)) 578 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
573 new_state |= TIOCM_DTR | TIOCM_RTS; 579 new_state |= TIOCM_DTR | TIOCM_RTS;
574 else 580 else
575 new_state &= ~(TIOCM_DTR | TIOCM_RTS); 581 new_state &= ~(TIOCM_DTR | TIOCM_RTS);
576 if (new_state != control_state) { 582 if (new_state != control_state) {
577 dbg(DEBUG_IF, "%u: new_state %x", cs->minor_index, new_state); 583 gig_dbg(DEBUG_IF, "%u: new_state %x",
578 gigaset_set_modem_ctrl(cs, control_state, new_state); // FIXME: mct_u232.c sets the old state here. is this a bug? 584 cs->minor_index, new_state);
585 gigaset_set_modem_ctrl(cs, control_state, new_state);
579 control_state = new_state; 586 control_state = new_state;
580 } 587 }
581#endif 588#endif
@@ -584,7 +591,7 @@ static void if_set_termios(struct tty_struct *tty, struct termios *old)
584 cs->control_state = control_state; 591 cs->control_state = control_state;
585 592
586out: 593out:
587 up(&cs->sem); 594 mutex_unlock(&cs->mutex);
588} 595}
589 596
590 597
@@ -600,7 +607,7 @@ static void if_wake(unsigned long data)
600 607
601 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && 608 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
602 tty->ldisc.write_wakeup) { 609 tty->ldisc.write_wakeup) {
603 dbg(DEBUG_IF, "write wakeup call"); 610 gig_dbg(DEBUG_IF, "write wakeup call");
604 tty->ldisc.write_wakeup(tty); 611 tty->ldisc.write_wakeup(tty);
605 } 612 }
606 613
@@ -635,14 +642,14 @@ void gigaset_if_free(struct cardstate *cs)
635} 642}
636 643
637void gigaset_if_receive(struct cardstate *cs, 644void gigaset_if_receive(struct cardstate *cs,
638 unsigned char *buffer, size_t len) 645 unsigned char *buffer, size_t len)
639{ 646{
640 unsigned long flags; 647 unsigned long flags;
641 struct tty_struct *tty; 648 struct tty_struct *tty;
642 649
643 spin_lock_irqsave(&cs->lock, flags); 650 spin_lock_irqsave(&cs->lock, flags);
644 if ((tty = cs->tty) == NULL) 651 if ((tty = cs->tty) == NULL)
645 dbg(DEBUG_ANY, "receive on closed device"); 652 gig_dbg(DEBUG_ANY, "receive on closed device");
646 else { 653 else {
647 tty_buffer_request_room(tty, len); 654 tty_buffer_request_room(tty, len);
648 tty_insert_flip_string(tty, buffer, len); 655 tty_insert_flip_string(tty, buffer, len);
@@ -655,13 +662,13 @@ EXPORT_SYMBOL_GPL(gigaset_if_receive);
655/* gigaset_if_initdriver 662/* gigaset_if_initdriver
656 * Initialize tty interface. 663 * Initialize tty interface.
657 * parameters: 664 * parameters:
658 * drv Driver 665 * drv Driver
659 * procname Name of the driver (e.g. for /proc/tty/drivers) 666 * procname Name of the driver (e.g. for /proc/tty/drivers)
660 * devname Name of the device files (prefix without minor number) 667 * devname Name of the device files (prefix without minor number)
661 * devfsname Devfs name of the device files without %d 668 * devfsname Devfs name of the device files without %d
662 */ 669 */
663void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname, 670void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
664 const char *devname, const char *devfsname) 671 const char *devname, const char *devfsname)
665{ 672{
666 unsigned minors = drv->minors; 673 unsigned minors = drv->minors;
667 int ret; 674 int ret;
@@ -696,7 +703,7 @@ void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
696 warn("failed to register tty driver (error %d)", ret); 703 warn("failed to register tty driver (error %d)", ret);
697 goto error; 704 goto error;
698 } 705 }
699 dbg(DEBUG_IF, "tty driver initialized"); 706 gig_dbg(DEBUG_IF, "tty driver initialized");
700 drv->have_tty = 1; 707 drv->have_tty = 1;
701 return; 708 return;
702 709
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index 5744eb91b315..45f017ed6e8c 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -10,10 +10,6 @@
10 * published by the Free Software Foundation; either version 2 of 10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version. 11 * the License, or (at your option) any later version.
12 * ===================================================================== 12 * =====================================================================
13 * ToDo: ...
14 * =====================================================================
15 * Version: $Id: isocdata.c,v 1.2.2.5 2005/11/13 23:05:19 hjlipp Exp $
16 * =====================================================================
17 */ 13 */
18 14
19#include "gigaset.h" 15#include "gigaset.h"
@@ -87,14 +83,14 @@ static inline int isowbuf_startwrite(struct isowbuf_t *iwb)
87{ 83{
88 if (!atomic_dec_and_test(&iwb->writesem)) { 84 if (!atomic_dec_and_test(&iwb->writesem)) {
89 atomic_inc(&iwb->writesem); 85 atomic_inc(&iwb->writesem);
90 dbg(DEBUG_ISO, 86 gig_dbg(DEBUG_ISO, "%s: couldn't acquire iso write semaphore",
91 "%s: couldn't acquire iso write semaphore", __func__); 87 __func__);
92 return 0; 88 return 0;
93 } 89 }
94#ifdef CONFIG_GIGASET_DEBUG 90#ifdef CONFIG_GIGASET_DEBUG
95 dbg(DEBUG_ISO, 91 gig_dbg(DEBUG_ISO,
96 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d", 92 "%s: acquired iso write semaphore, data[write]=%02x, nbits=%d",
97 __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits); 93 __func__, iwb->data[atomic_read(&iwb->write)], iwb->wbits);
98#endif 94#endif
99 return 1; 95 return 1;
100} 96}
@@ -147,7 +143,7 @@ static inline void isowbuf_putflag(struct isowbuf_t *iwb)
147 /* recover the idle flag byte */ 143 /* recover the idle flag byte */
148 write = atomic_read(&iwb->write); 144 write = atomic_read(&iwb->write);
149 iwb->idle = iwb->data[write]; 145 iwb->idle = iwb->data[write];
150 dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle); 146 gig_dbg(DEBUG_ISO, "idle fill byte %02x", iwb->idle);
151 /* mask extraneous bits in buffer */ 147 /* mask extraneous bits in buffer */
152 iwb->data[write] &= (1 << iwb->wbits) - 1; 148 iwb->data[write] &= (1 << iwb->wbits) - 1;
153} 149}
@@ -166,15 +162,14 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
166 read = atomic_read(&iwb->nextread); 162 read = atomic_read(&iwb->nextread);
167 write = atomic_read(&iwb->write); 163 write = atomic_read(&iwb->write);
168 if (likely(read == write)) { 164 if (likely(read == write)) {
169 //dbg(DEBUG_STREAM, "%s: send buffer empty", __func__);
170 /* return idle frame */ 165 /* return idle frame */
171 return read < BAS_OUTBUFPAD ? 166 return read < BAS_OUTBUFPAD ?
172 BAS_OUTBUFSIZE : read - BAS_OUTBUFPAD; 167 BAS_OUTBUFSIZE : read - BAS_OUTBUFPAD;
173 } 168 }
174 169
175 limit = read + size; 170 limit = read + size;
176 dbg(DEBUG_STREAM, 171 gig_dbg(DEBUG_STREAM, "%s: read=%d write=%d limit=%d",
177 "%s: read=%d write=%d limit=%d", __func__, read, write, limit); 172 __func__, read, write, limit);
178#ifdef CONFIG_GIGASET_DEBUG 173#ifdef CONFIG_GIGASET_DEBUG
179 if (unlikely(size < 0 || size > BAS_OUTBUFPAD)) { 174 if (unlikely(size < 0 || size > BAS_OUTBUFPAD)) {
180 err("invalid size %d", size); 175 err("invalid size %d", size);
@@ -196,11 +191,12 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
196 return -EBUSY; 191 return -EBUSY;
197 /* write position could have changed */ 192 /* write position could have changed */
198 if (limit >= (write = atomic_read(&iwb->write))) { 193 if (limit >= (write = atomic_read(&iwb->write))) {
199 pbyte = iwb->data[write]; /* save partial byte */ 194 pbyte = iwb->data[write]; /* save
195 partial byte */
200 limit = write + BAS_OUTBUFPAD; 196 limit = write + BAS_OUTBUFPAD;
201 dbg(DEBUG_STREAM, 197 gig_dbg(DEBUG_STREAM,
202 "%s: filling %d->%d with %02x", 198 "%s: filling %d->%d with %02x",
203 __func__, write, limit, iwb->idle); 199 __func__, write, limit, iwb->idle);
204 if (write + BAS_OUTBUFPAD < BAS_OUTBUFSIZE) 200 if (write + BAS_OUTBUFPAD < BAS_OUTBUFSIZE)
205 memset(iwb->data + write, iwb->idle, 201 memset(iwb->data + write, iwb->idle,
206 BAS_OUTBUFPAD); 202 BAS_OUTBUFPAD);
@@ -211,9 +207,11 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
211 - write); 207 - write);
212 limit = 0; 208 limit = 0;
213 } 209 }
214 dbg(DEBUG_STREAM, "%s: restoring %02x at %d", 210 gig_dbg(DEBUG_STREAM,
215 __func__, pbyte, limit); 211 "%s: restoring %02x at %d",
216 iwb->data[limit] = pbyte; /* restore partial byte */ 212 __func__, pbyte, limit);
213 iwb->data[limit] = pbyte; /* restore
214 partial byte */
217 atomic_set(&iwb->write, limit); 215 atomic_set(&iwb->write, limit);
218 } 216 }
219 isowbuf_donewrite(iwb); 217 isowbuf_donewrite(iwb);
@@ -242,19 +240,17 @@ int gigaset_isowbuf_getbytes(struct isowbuf_t *iwb, int size)
242 * write hex bytes to syslog for debugging 240 * write hex bytes to syslog for debugging
243 */ 241 */
244static inline void dump_bytes(enum debuglevel level, const char *tag, 242static inline void dump_bytes(enum debuglevel level, const char *tag,
245 unsigned char *bytes, int count) 243 unsigned char *bytes, int count)
246{ 244{
247#ifdef CONFIG_GIGASET_DEBUG 245#ifdef CONFIG_GIGASET_DEBUG
248 unsigned char c; 246 unsigned char c;
249 static char dbgline[3 * 32 + 1]; 247 static char dbgline[3 * 32 + 1];
250 static const char hexdigit[] = "0123456789abcdef"; 248 static const char hexdigit[] = "0123456789abcdef";
251 int i = 0; 249 int i = 0;
252 IFNULLRET(tag);
253 IFNULLRET(bytes);
254 while (count-- > 0) { 250 while (count-- > 0) {
255 if (i > sizeof(dbgline) - 4) { 251 if (i > sizeof(dbgline) - 4) {
256 dbgline[i] = '\0'; 252 dbgline[i] = '\0';
257 dbg(level, "%s:%s", tag, dbgline); 253 gig_dbg(level, "%s:%s", tag, dbgline);
258 i = 0; 254 i = 0;
259 } 255 }
260 c = *bytes++; 256 c = *bytes++;
@@ -264,7 +260,7 @@ static inline void dump_bytes(enum debuglevel level, const char *tag,
264 dbgline[i++] = hexdigit[c & 0x0f]; 260 dbgline[i++] = hexdigit[c & 0x0f];
265 } 261 }
266 dbgline[i] = '\0'; 262 dbgline[i] = '\0';
267 dbg(level, "%s:%s", tag, dbgline); 263 gig_dbg(level, "%s:%s", tag, dbgline);
268#endif 264#endif
269} 265}
270 266
@@ -380,7 +376,7 @@ static u16 stufftab[5 * 256] = {
380 */ 376 */
381 377
382static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin, 378static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin,
383 int ones) 379 int ones)
384{ 380{
385 u16 stuff; 381 u16 stuff;
386 int shiftinc, newones; 382 int shiftinc, newones;
@@ -422,7 +418,7 @@ static inline int hdlc_bitstuff_byte(struct isowbuf_t *iwb, unsigned char cin,
422 */ 418 */
423 419
424static inline int hdlc_buildframe(struct isowbuf_t *iwb, 420static inline int hdlc_buildframe(struct isowbuf_t *iwb,
425 unsigned char *in, int count) 421 unsigned char *in, int count)
426{ 422{
427 int ones; 423 int ones;
428 u16 fcs; 424 u16 fcs;
@@ -431,8 +427,8 @@ static inline int hdlc_buildframe(struct isowbuf_t *iwb,
431 427
432 if (isowbuf_freebytes(iwb) < count + count / 5 + 6 || 428 if (isowbuf_freebytes(iwb) < count + count / 5 + 6 ||
433 !isowbuf_startwrite(iwb)) { 429 !isowbuf_startwrite(iwb)) {
434 dbg(DEBUG_ISO, "%s: %d bytes free -> -EAGAIN", 430 gig_dbg(DEBUG_ISO, "%s: %d bytes free -> -EAGAIN",
435 __func__, isowbuf_freebytes(iwb)); 431 __func__, isowbuf_freebytes(iwb));
436 return -EAGAIN; 432 return -EAGAIN;
437 } 433 }
438 434
@@ -484,11 +480,11 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
484 480
485 if (isowbuf_freebytes(iwb) < count || 481 if (isowbuf_freebytes(iwb) < count ||
486 !isowbuf_startwrite(iwb)) { 482 !isowbuf_startwrite(iwb)) {
487 dbg(DEBUG_ISO, "can't put %d bytes", count); 483 gig_dbg(DEBUG_ISO, "can't put %d bytes", count);
488 return -EAGAIN; 484 return -EAGAIN;
489 } 485 }
490 486
491 dbg(DEBUG_STREAM, "put %d bytes", count); 487 gig_dbg(DEBUG_STREAM, "put %d bytes", count);
492 write = atomic_read(&iwb->write); 488 write = atomic_read(&iwb->write);
493 do { 489 do {
494 c = gigaset_invtab[*in++]; 490 c = gigaset_invtab[*in++];
@@ -508,11 +504,13 @@ int gigaset_isoc_buildframe(struct bc_state *bcs, unsigned char *in, int len)
508 switch (bcs->proto2) { 504 switch (bcs->proto2) {
509 case ISDN_PROTO_L2_HDLC: 505 case ISDN_PROTO_L2_HDLC:
510 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len); 506 result = hdlc_buildframe(bcs->hw.bas->isooutbuf, in, len);
511 dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d", __func__, len, result); 507 gig_dbg(DEBUG_ISO, "%s: %d bytes HDLC -> %d",
508 __func__, len, result);
512 break; 509 break;
513 default: /* assume transparent */ 510 default: /* assume transparent */
514 result = trans_buildframe(bcs->hw.bas->isooutbuf, in, len); 511 result = trans_buildframe(bcs->hw.bas->isooutbuf, in, len);
515 dbg(DEBUG_ISO, "%s: %d bytes trans -> %d", __func__, len, result); 512 gig_dbg(DEBUG_ISO, "%s: %d bytes trans -> %d",
513 __func__, len, result);
516 } 514 }
517 return result; 515 return result;
518} 516}
@@ -528,13 +526,13 @@ static inline void hdlc_putbyte(unsigned char c, struct bc_state *bcs)
528 return; 526 return;
529 } 527 }
530 if (unlikely(bcs->skb->len == SBUFSIZE)) { 528 if (unlikely(bcs->skb->len == SBUFSIZE)) {
531 warn("received oversized packet discarded"); 529 dev_warn(bcs->cs->dev, "received oversized packet discarded\n");
532 bcs->hw.bas->giants++; 530 bcs->hw.bas->giants++;
533 dev_kfree_skb_any(bcs->skb); 531 dev_kfree_skb_any(bcs->skb);
534 bcs->skb = NULL; 532 bcs->skb = NULL;
535 return; 533 return;
536 } 534 }
537 *gigaset_skb_put_quick(bcs->skb, 1) = c; 535 *__skb_put(bcs->skb, 1) = c;
538} 536}
539 537
540/* hdlc_flush 538/* hdlc_flush
@@ -549,7 +547,7 @@ static inline void hdlc_flush(struct bc_state *bcs)
549 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 547 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
550 skb_reserve(bcs->skb, HW_HDR_LEN); 548 skb_reserve(bcs->skb, HW_HDR_LEN);
551 else 549 else
552 err("could not allocate skb"); 550 dev_err(bcs->cs->dev, "could not allocate skb\n");
553 } 551 }
554 552
555 /* reset packet state */ 553 /* reset packet state */
@@ -571,23 +569,25 @@ static inline void hdlc_done(struct bc_state *bcs)
571 569
572 if ((procskb = bcs->skb) == NULL) { 570 if ((procskb = bcs->skb) == NULL) {
573 /* previous error */ 571 /* previous error */
574 dbg(DEBUG_ISO, "%s: skb=NULL", __func__); 572 gig_dbg(DEBUG_ISO, "%s: skb=NULL", __func__);
575 gigaset_rcv_error(NULL, bcs->cs, bcs); 573 gigaset_rcv_error(NULL, bcs->cs, bcs);
576 } else if (procskb->len < 2) { 574 } else if (procskb->len < 2) {
577 notice("received short frame (%d octets)", procskb->len); 575 dev_notice(bcs->cs->dev, "received short frame (%d octets)\n",
576 procskb->len);
578 bcs->hw.bas->runts++; 577 bcs->hw.bas->runts++;
579 gigaset_rcv_error(procskb, bcs->cs, bcs); 578 gigaset_rcv_error(procskb, bcs->cs, bcs);
580 } else if (bcs->fcs != PPP_GOODFCS) { 579 } else if (bcs->fcs != PPP_GOODFCS) {
581 notice("frame check error (0x%04x)", bcs->fcs); 580 dev_notice(bcs->cs->dev, "frame check error (0x%04x)\n",
581 bcs->fcs);
582 bcs->hw.bas->fcserrs++; 582 bcs->hw.bas->fcserrs++;
583 gigaset_rcv_error(procskb, bcs->cs, bcs); 583 gigaset_rcv_error(procskb, bcs->cs, bcs);
584 } else { 584 } else {
585 procskb->len -= 2; /* subtract FCS */ 585 procskb->len -= 2; /* subtract FCS */
586 procskb->tail -= 2; 586 procskb->tail -= 2;
587 dbg(DEBUG_ISO, 587 gig_dbg(DEBUG_ISO, "%s: good frame (%d octets)",
588 "%s: good frame (%d octets)", __func__, procskb->len); 588 __func__, procskb->len);
589 dump_bytes(DEBUG_STREAM, 589 dump_bytes(DEBUG_STREAM,
590 "rcv data", procskb->data, procskb->len); 590 "rcv data", procskb->data, procskb->len);
591 bcs->hw.bas->goodbytes += procskb->len; 591 bcs->hw.bas->goodbytes += procskb->len;
592 gigaset_rcv_skb(procskb, bcs->cs, bcs); 592 gigaset_rcv_skb(procskb, bcs->cs, bcs);
593 } 593 }
@@ -595,7 +595,7 @@ static inline void hdlc_done(struct bc_state *bcs)
595 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 595 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
596 skb_reserve(bcs->skb, HW_HDR_LEN); 596 skb_reserve(bcs->skb, HW_HDR_LEN);
597 else 597 else
598 err("could not allocate skb"); 598 dev_err(bcs->cs->dev, "could not allocate skb\n");
599 bcs->fcs = PPP_INITFCS; 599 bcs->fcs = PPP_INITFCS;
600} 600}
601 601
@@ -610,14 +610,14 @@ static inline void hdlc_frag(struct bc_state *bcs, unsigned inbits)
610 return; 610 return;
611 } 611 }
612 612
613 notice("received partial byte (%d bits)", inbits); 613 dev_notice(bcs->cs->dev, "received partial byte (%d bits)\n", inbits);
614 bcs->hw.bas->alignerrs++; 614 bcs->hw.bas->alignerrs++;
615 gigaset_rcv_error(bcs->skb, bcs->cs, bcs); 615 gigaset_rcv_error(bcs->skb, bcs->cs, bcs);
616 616
617 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL) 617 if ((bcs->skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN)) != NULL)
618 skb_reserve(bcs->skb, HW_HDR_LEN); 618 skb_reserve(bcs->skb, HW_HDR_LEN);
619 else 619 else
620 err("could not allocate skb"); 620 dev_err(bcs->cs->dev, "could not allocate skb\n");
621 bcs->fcs = PPP_INITFCS; 621 bcs->fcs = PPP_INITFCS;
622} 622}
623 623
@@ -659,16 +659,12 @@ static unsigned char bitcounts[256] = {
659 * bcs receiving B channel structure 659 * bcs receiving B channel structure
660 */ 660 */
661static inline void hdlc_unpack(unsigned char *src, unsigned count, 661static inline void hdlc_unpack(unsigned char *src, unsigned count,
662 struct bc_state *bcs) 662 struct bc_state *bcs)
663{ 663{
664 struct bas_bc_state *ubc; 664 struct bas_bc_state *ubc = bcs->hw.bas;
665 int inputstate; 665 int inputstate;
666 unsigned seqlen, inbyte, inbits; 666 unsigned seqlen, inbyte, inbits;
667 667
668 IFNULLRET(bcs);
669 ubc = bcs->hw.bas;
670 IFNULLRET(ubc);
671
672 /* load previous state: 668 /* load previous state:
673 * inputstate = set of flag bits: 669 * inputstate = set of flag bits:
674 * - INS_flag_hunt: no complete opening flag received since connection setup or last abort 670 * - INS_flag_hunt: no complete opening flag received since connection setup or last abort
@@ -856,7 +852,7 @@ static inline void hdlc_unpack(unsigned char *src, unsigned count,
856 * bcs receiving B channel structure 852 * bcs receiving B channel structure
857 */ 853 */
858static inline void trans_receive(unsigned char *src, unsigned count, 854static inline void trans_receive(unsigned char *src, unsigned count,
859 struct bc_state *bcs) 855 struct bc_state *bcs)
860{ 856{
861 struct sk_buff *skb; 857 struct sk_buff *skb;
862 int dobytes; 858 int dobytes;
@@ -870,7 +866,7 @@ static inline void trans_receive(unsigned char *src, unsigned count,
870 if (unlikely((skb = bcs->skb) == NULL)) { 866 if (unlikely((skb = bcs->skb) == NULL)) {
871 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 867 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN);
872 if (!skb) { 868 if (!skb) {
873 err("could not allocate skb"); 869 dev_err(bcs->cs->dev, "could not allocate skb\n");
874 return; 870 return;
875 } 871 }
876 skb_reserve(skb, HW_HDR_LEN); 872 skb_reserve(skb, HW_HDR_LEN);
@@ -888,7 +884,8 @@ static inline void trans_receive(unsigned char *src, unsigned count,
888 gigaset_rcv_skb(skb, bcs->cs, bcs); 884 gigaset_rcv_skb(skb, bcs->cs, bcs);
889 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN); 885 bcs->skb = skb = dev_alloc_skb(SBUFSIZE + HW_HDR_LEN);
890 if (!skb) { 886 if (!skb) {
891 err("could not allocate skb"); 887 dev_err(bcs->cs->dev,
888 "could not allocate skb\n");
892 return; 889 return;
893 } 890 }
894 skb_reserve(bcs->skb, HW_HDR_LEN); 891 skb_reserve(bcs->skb, HW_HDR_LEN);
@@ -921,8 +918,8 @@ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
921 case '\r': 918 case '\r':
922 case '\n': 919 case '\n':
923 /* end of line */ 920 /* end of line */
924 dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", 921 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
925 __func__, cbytes); 922 __func__, cbytes);
926 cs->cbytes = cbytes; 923 cs->cbytes = cbytes;
927 gigaset_handle_modem_response(cs); 924 gigaset_handle_modem_response(cs);
928 cbytes = 0; 925 cbytes = 0;
@@ -932,7 +929,7 @@ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
932 if (cbytes < MAX_RESP_SIZE - 1) 929 if (cbytes < MAX_RESP_SIZE - 1)
933 cbytes++; 930 cbytes++;
934 else 931 else
935 warn("response too large"); 932 dev_warn(cs->dev, "response too large\n");
936 } 933 }
937 } 934 }
938 935
@@ -951,27 +948,27 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
951 948
952 head = atomic_read(&inbuf->head); 949 head = atomic_read(&inbuf->head);
953 while (head != (tail = atomic_read(&inbuf->tail))) { 950 while (head != (tail = atomic_read(&inbuf->tail))) {
954 dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail); 951 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
955 if (head > tail) 952 if (head > tail)
956 tail = RBUFSIZE; 953 tail = RBUFSIZE;
957 src = inbuf->data + head; 954 src = inbuf->data + head;
958 numbytes = tail - head; 955 numbytes = tail - head;
959 dbg(DEBUG_INTR, "processing %u bytes", numbytes); 956 gig_dbg(DEBUG_INTR, "processing %u bytes", numbytes);
960 957
961 if (atomic_read(&cs->mstate) == MS_LOCKED) { 958 if (atomic_read(&cs->mstate) == MS_LOCKED) {
962 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response", 959 gigaset_dbg_buffer(DEBUG_LOCKCMD, "received response",
963 numbytes, src, 0); 960 numbytes, src);
964 gigaset_if_receive(inbuf->cs, src, numbytes); 961 gigaset_if_receive(inbuf->cs, src, numbytes);
965 } else { 962 } else {
966 gigaset_dbg_buffer(DEBUG_CMD, "received response", 963 gigaset_dbg_buffer(DEBUG_CMD, "received response",
967 numbytes, src, 0); 964 numbytes, src);
968 cmd_loop(src, numbytes, inbuf); 965 cmd_loop(src, numbytes, inbuf);
969 } 966 }
970 967
971 head += numbytes; 968 head += numbytes;
972 if (head == RBUFSIZE) 969 if (head == RBUFSIZE)
973 head = 0; 970 head = 0;
974 dbg(DEBUG_INTR, "setting head to %u", head); 971 gig_dbg(DEBUG_INTR, "setting head to %u", head);
975 atomic_set(&inbuf->head, head); 972 atomic_set(&inbuf->head, head);
976 } 973 }
977} 974}
@@ -992,18 +989,18 @@ void gigaset_isoc_input(struct inbuf_t *inbuf)
992 */ 989 */
993int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb) 990int gigaset_isoc_send_skb(struct bc_state *bcs, struct sk_buff *skb)
994{ 991{
995 int len; 992 int len = skb->len;
996 993 unsigned long flags;
997 IFNULLRETVAL(bcs, -EFAULT);
998 IFNULLRETVAL(skb, -EFAULT);
999 len = skb->len;
1000 994
1001 skb_queue_tail(&bcs->squeue, skb); 995 skb_queue_tail(&bcs->squeue, skb);
1002 dbg(DEBUG_ISO, 996 gig_dbg(DEBUG_ISO, "%s: skb queued, qlen=%d",
1003 "%s: skb queued, qlen=%d", __func__, skb_queue_len(&bcs->squeue)); 997 __func__, skb_queue_len(&bcs->squeue));
1004 998
1005 /* tasklet submits URB if necessary */ 999 /* tasklet submits URB if necessary */
1006 tasklet_schedule(&bcs->hw.bas->sent_tasklet); 1000 spin_lock_irqsave(&bcs->cs->lock, flags);
1001 if (bcs->cs->connected)
1002 tasklet_schedule(&bcs->hw.bas->sent_tasklet);
1003 spin_unlock_irqrestore(&bcs->cs->lock, flags);
1007 1004
1008 return len; /* ok so far */ 1005 return len; /* ok so far */
1009} 1006}
diff --git a/drivers/isdn/gigaset/proc.c b/drivers/isdn/gigaset/proc.c
index c6915fa2be6c..d267a636b53c 100644
--- a/drivers/isdn/gigaset/proc.c
+++ b/drivers/isdn/gigaset/proc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Stuff used by all variants of the driver 2 * Stuff used by all variants of the driver
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>, 4 * Copyright (c) 2001 by Stefan Eilers,
5 * Hansjoerg Lipp <hjlipp@web.de>, 5 * Hansjoerg Lipp <hjlipp@web.de>,
6 * Tilman Schmidt <tilman@imap.cc>. 6 * Tilman Schmidt <tilman@imap.cc>.
7 * 7 *
@@ -11,26 +11,29 @@
11 * published by the Free Software Foundation; either version 2 of 11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
13 * ===================================================================== 13 * =====================================================================
14 * ToDo: ...
15 * =====================================================================
16 * Version: $Id: proc.c,v 1.5.2.13 2006/02/04 18:28:16 hjlipp Exp $
17 * =====================================================================
18 */ 14 */
19 15
20#include "gigaset.h" 16#include "gigaset.h"
21#include <linux/ctype.h> 17#include <linux/ctype.h>
22 18
23static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr, char *buf) 19static ssize_t show_cidmode(struct device *dev, struct device_attribute *attr,
20 char *buf)
24{ 21{
25 struct usb_interface *intf = to_usb_interface(dev); 22 int ret;
26 struct cardstate *cs = usb_get_intfdata(intf); 23 unsigned long flags;
27 return sprintf(buf, "%d\n", atomic_read(&cs->cidmode)); // FIXME use scnprintf for 13607 bit architectures (if PAGE_SIZE==4096) 24 struct cardstate *cs = dev_get_drvdata(dev);
25
26 spin_lock_irqsave(&cs->lock, flags);
27 ret = sprintf(buf, "%u\n", cs->cidmode);
28 spin_unlock_irqrestore(&cs->lock, flags);
29
30 return ret;
28} 31}
29 32
30static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 33static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr,
34 const char *buf, size_t count)
31{ 35{
32 struct usb_interface *intf = to_usb_interface(dev); 36 struct cardstate *cs = dev_get_drvdata(dev);
33 struct cardstate *cs = usb_get_intfdata(intf);
34 long int value; 37 long int value;
35 char *end; 38 char *end;
36 39
@@ -41,23 +44,23 @@ static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, co
41 if (value < 0 || value > 1) 44 if (value < 0 || value > 1)
42 return -EINVAL; 45 return -EINVAL;
43 46
44 if (down_interruptible(&cs->sem)) 47 if (mutex_lock_interruptible(&cs->mutex))
45 return -ERESTARTSYS; // FIXME -EINTR? 48 return -ERESTARTSYS; // FIXME -EINTR?
46 49
47 cs->waiting = 1; 50 cs->waiting = 1;
48 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE, 51 if (!gigaset_add_event(cs, &cs->at_state, EV_PROC_CIDMODE,
49 NULL, value, NULL)) { 52 NULL, value, NULL)) {
50 cs->waiting = 0; 53 cs->waiting = 0;
51 up(&cs->sem); 54 mutex_unlock(&cs->mutex);
52 return -ENOMEM; 55 return -ENOMEM;
53 } 56 }
54 57
55 dbg(DEBUG_CMD, "scheduling PROC_CIDMODE"); 58 gig_dbg(DEBUG_CMD, "scheduling PROC_CIDMODE");
56 gigaset_schedule_event(cs); 59 gigaset_schedule_event(cs);
57 60
58 wait_event(cs->waitqueue, !cs->waiting); 61 wait_event(cs->waitqueue, !cs->waiting);
59 62
60 up(&cs->sem); 63 mutex_unlock(&cs->mutex);
61 64
62 return count; 65 return count;
63} 66}
@@ -65,17 +68,15 @@ static ssize_t set_cidmode(struct device *dev, struct device_attribute *attr, co
65static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode); 68static DEVICE_ATTR(cidmode, S_IRUGO|S_IWUSR, show_cidmode, set_cidmode);
66 69
67/* free sysfs for device */ 70/* free sysfs for device */
68void gigaset_free_dev_sysfs(struct usb_interface *interface) 71void gigaset_free_dev_sysfs(struct cardstate *cs)
69{ 72{
70 dbg(DEBUG_INIT, "removing sysfs entries"); 73 gig_dbg(DEBUG_INIT, "removing sysfs entries");
71 device_remove_file(&interface->dev, &dev_attr_cidmode); 74 device_remove_file(cs->dev, &dev_attr_cidmode);
72} 75}
73EXPORT_SYMBOL_GPL(gigaset_free_dev_sysfs);
74 76
75/* initialize sysfs for device */ 77/* initialize sysfs for device */
76void gigaset_init_dev_sysfs(struct usb_interface *interface) 78void gigaset_init_dev_sysfs(struct cardstate *cs)
77{ 79{
78 dbg(DEBUG_INIT, "setting up sysfs"); 80 gig_dbg(DEBUG_INIT, "setting up sysfs");
79 device_create_file(&interface->dev, &dev_attr_cidmode); 81 device_create_file(cs->dev, &dev_attr_cidmode);
80} 82}
81EXPORT_SYMBOL_GPL(gigaset_init_dev_sysfs);
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index 323fc7349dec..bfb73fd5077e 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB driver for Gigaset 307x directly or using M105 Data. 2 * USB driver for Gigaset 307x directly or using M105 Data.
3 * 3 *
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de> 4 * Copyright (c) 2001 by Stefan Eilers
5 * and Hansjoerg Lipp <hjlipp@web.de>. 5 * and Hansjoerg Lipp <hjlipp@web.de>.
6 * 6 *
7 * This driver was derived from the USB skeleton driver by 7 * This driver was derived from the USB skeleton driver by
@@ -13,10 +13,6 @@
13 * published by the Free Software Foundation; either version 2 of 13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version. 14 * the License, or (at your option) any later version.
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: usb-gigaset.c,v 1.85.4.18 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */ 16 */
21 17
22#include "gigaset.h" 18#include "gigaset.h"
@@ -29,7 +25,7 @@
29#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
30 26
31/* Version Information */ 27/* Version Information */
32#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>" 28#define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
33#define DRIVER_DESC "USB Driver for Gigaset 307x using M105" 29#define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
34 30
35/* Module parameters */ 31/* Module parameters */
@@ -62,10 +58,6 @@ static struct usb_device_id gigaset_table [] = {
62 58
63MODULE_DEVICE_TABLE(usb, gigaset_table); 59MODULE_DEVICE_TABLE(usb, gigaset_table);
64 60
65/* Get a minor range for your devices from the usb maintainer */
66#define USB_SKEL_MINOR_BASE 200
67
68
69/* 61/*
70 * Control requests (empty fields: 00) 62 * Control requests (empty fields: 00)
71 * 63 *
@@ -114,7 +106,7 @@ MODULE_DEVICE_TABLE(usb, gigaset_table);
114 */ 106 */
115 107
116static int gigaset_probe(struct usb_interface *interface, 108static int gigaset_probe(struct usb_interface *interface,
117 const struct usb_device_id *id); 109 const struct usb_device_id *id);
118static void gigaset_disconnect(struct usb_interface *interface); 110static void gigaset_disconnect(struct usb_interface *interface);
119 111
120static struct gigaset_driver *driver = NULL; 112static struct gigaset_driver *driver = NULL;
@@ -122,29 +114,29 @@ static struct cardstate *cardstate = NULL;
122 114
123/* usb specific object needed to register this driver with the usb subsystem */ 115/* usb specific object needed to register this driver with the usb subsystem */
124static struct usb_driver gigaset_usb_driver = { 116static struct usb_driver gigaset_usb_driver = {
125 .name = GIGASET_MODULENAME, 117 .name = GIGASET_MODULENAME,
126 .probe = gigaset_probe, 118 .probe = gigaset_probe,
127 .disconnect = gigaset_disconnect, 119 .disconnect = gigaset_disconnect,
128 .id_table = gigaset_table, 120 .id_table = gigaset_table,
129}; 121};
130 122
131struct usb_cardstate { 123struct usb_cardstate {
132 struct usb_device *udev; /* save off the usb device pointer */ 124 struct usb_device *udev; /* usb device pointer */
133 struct usb_interface *interface; /* the interface for this device */ 125 struct usb_interface *interface; /* interface for this device */
134 atomic_t busy; /* bulk output in progress */ 126 atomic_t busy; /* bulk output in progress */
135 127
136 /* Output buffer for commands (M105: and data)*/ 128 /* Output buffer */
137 unsigned char *bulk_out_buffer; /* the buffer to send data */ 129 unsigned char *bulk_out_buffer;
138 int bulk_out_size; /* the size of the send buffer */ 130 int bulk_out_size;
139 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 131 __u8 bulk_out_endpointAddr;
140 struct urb *bulk_out_urb; /* the urb used to transmit data */ 132 struct urb *bulk_out_urb;
141 133
142 /* Input buffer for command responses (M105: and data)*/ 134 /* Input buffer */
143 int rcvbuf_size; /* the size of the receive buffer */ 135 int rcvbuf_size;
144 struct urb *read_urb; /* the urb used to receive data */ 136 struct urb *read_urb;
145 __u8 int_in_endpointAddr; /* the address of the bulk in endpoint */ 137 __u8 int_in_endpointAddr;
146 138
147 char bchars[6]; /* req. 0x19 */ 139 char bchars[6]; /* for request 0x19 */
148}; 140};
149 141
150struct usb_bc_state {}; 142struct usb_bc_state {};
@@ -157,19 +149,20 @@ static inline unsigned tiocm_to_gigaset(unsigned state)
157#ifdef CONFIG_GIGASET_UNDOCREQ 149#ifdef CONFIG_GIGASET_UNDOCREQ
158/* WARNING: EXPERIMENTAL! */ 150/* WARNING: EXPERIMENTAL! */
159static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 151static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
160 unsigned new_state) 152 unsigned new_state)
161{ 153{
154 struct usb_device *udev = cs->hw.usb->udev;
162 unsigned mask, val; 155 unsigned mask, val;
163 int r; 156 int r;
164 157
165 mask = tiocm_to_gigaset(old_state ^ new_state); 158 mask = tiocm_to_gigaset(old_state ^ new_state);
166 val = tiocm_to_gigaset(new_state); 159 val = tiocm_to_gigaset(new_state);
167 160
168 dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask); 161 gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
169 r = usb_control_msg(cs->hw.usb->udev, 162 // don't use this in an interrupt/BH
170 usb_sndctrlpipe(cs->hw.usb->udev, 0), 7, 0x41, 163 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41,
171 (val & 0xff) | ((mask & 0xff) << 8), 0, 164 (val & 0xff) | ((mask & 0xff) << 8), 0,
172 NULL, 0, 2000 /*timeout??*/); // don't use this in an interrupt/BH 165 NULL, 0, 2000 /* timeout? */);
173 if (r < 0) 166 if (r < 0)
174 return r; 167 return r;
175 //.. 168 //..
@@ -178,30 +171,29 @@ static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
178 171
179static int set_value(struct cardstate *cs, u8 req, u16 val) 172static int set_value(struct cardstate *cs, u8 req, u16 val)
180{ 173{
174 struct usb_device *udev = cs->hw.usb->udev;
181 int r, r2; 175 int r, r2;
182 176
183 dbg(DEBUG_USBREQ, "request %02x (%04x)", (unsigned)req, (unsigned)val); 177 gig_dbg(DEBUG_USBREQ, "request %02x (%04x)",
184 r = usb_control_msg(cs->hw.usb->udev, 178 (unsigned)req, (unsigned)val);
185 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x12, 0x41, 179 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x12, 0x41,
186 0xf /*?*/, 0, 180 0xf /*?*/, 0, NULL, 0, 2000 /*?*/);
187 NULL, 0, 2000 /*?*/); /* no idea, what this does */ 181 /* no idea what this does */
188 if (r < 0) { 182 if (r < 0) {
189 err("error %d on request 0x12", -r); 183 dev_err(&udev->dev, "error %d on request 0x12\n", -r);
190 return r; 184 return r;
191 } 185 }
192 186
193 r = usb_control_msg(cs->hw.usb->udev, 187 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), req, 0x41,
194 usb_sndctrlpipe(cs->hw.usb->udev, 0), req, 0x41, 188 val, 0, NULL, 0, 2000 /*?*/);
195 val, 0,
196 NULL, 0, 2000 /*?*/);
197 if (r < 0) 189 if (r < 0)
198 err("error %d on request 0x%02x", -r, (unsigned)req); 190 dev_err(&udev->dev, "error %d on request 0x%02x\n",
191 -r, (unsigned)req);
199 192
200 r2 = usb_control_msg(cs->hw.usb->udev, 193 r2 = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
201 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41, 194 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
202 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
203 if (r2 < 0) 195 if (r2 < 0)
204 err("error %d on request 0x19", -r2); 196 dev_err(&udev->dev, "error %d on request 0x19\n", -r2);
205 197
206 return r < 0 ? r : (r2 < 0 ? r2 : 0); 198 return r < 0 ? r : (r2 < 0 ? r2 : 0);
207} 199}
@@ -229,8 +221,8 @@ static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
229 case B115200: rate = 115200; break; 221 case B115200: rate = 115200; break;
230 default: 222 default:
231 rate = 9600; 223 rate = 9600;
232 err("unsupported baudrate request 0x%x," 224 dev_err(cs->dev, "unsupported baudrate request 0x%x,"
233 " using default of B9600", cflag); 225 " using default of B9600\n", cflag);
234 } 226 }
235 227
236 val = 0x383fff / rate + 1; 228 val = 0x383fff / rate + 1;
@@ -259,7 +251,7 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
259 case CS8: 251 case CS8:
260 val |= 8 << 8; break; 252 val |= 8 << 8; break;
261 default: 253 default:
262 err("CSIZE was not CS5-CS8, using default of 8"); 254 dev_err(cs->dev, "CSIZE was not CS5-CS8, using default of 8\n");
263 val |= 8 << 8; 255 val |= 8 << 8;
264 break; 256 break;
265 } 257 }
@@ -277,7 +269,7 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
277 269
278#else 270#else
279static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 271static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
280 unsigned new_state) 272 unsigned new_state)
281{ 273{
282 return -EINVAL; 274 return -EINVAL;
283} 275}
@@ -309,15 +301,12 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
309 return 0; 301 return 0;
310} 302}
311 303
312//void send_ack_to_LL(void *data);
313static int write_modem(struct cardstate *cs); 304static int write_modem(struct cardstate *cs);
314static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb); 305static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb);
315 306
316 307
317/* Handling of send queue. If there is already a skb opened, put data to 308/* Write tasklet handler: Continue sending current skb, or send command, or
318 * the transfer buffer by calling "write_modem". Otherwise take a new skb out of the queue. 309 * start sending an skb from the send queue.
319 * This function will be called by the ISR via "transmit_chars" (USB: B-Channel Bulk callback handler
320 * via immediate task queue) or by writebuf_from_LL if the LL wants to transmit data.
321 */ 310 */
322static void gigaset_modem_fill(unsigned long data) 311static void gigaset_modem_fill(unsigned long data)
323{ 312{
@@ -327,10 +316,10 @@ static void gigaset_modem_fill(unsigned long data)
327 unsigned long flags; 316 unsigned long flags;
328 int again; 317 int again;
329 318
330 dbg(DEBUG_OUTPUT, "modem_fill"); 319 gig_dbg(DEBUG_OUTPUT, "modem_fill");
331 320
332 if (atomic_read(&cs->hw.usb->busy)) { 321 if (atomic_read(&cs->hw.usb->busy)) {
333 dbg(DEBUG_OUTPUT, "modem_fill: busy"); 322 gig_dbg(DEBUG_OUTPUT, "modem_fill: busy");
334 return; 323 return;
335 } 324 }
336 325
@@ -341,26 +330,27 @@ static void gigaset_modem_fill(unsigned long data)
341 cb = cs->cmdbuf; 330 cb = cs->cmdbuf;
342 spin_unlock_irqrestore(&cs->cmdlock, flags); 331 spin_unlock_irqrestore(&cs->cmdlock, flags);
343 if (cb) { /* commands to send? */ 332 if (cb) { /* commands to send? */
344 dbg(DEBUG_OUTPUT, "modem_fill: cb"); 333 gig_dbg(DEBUG_OUTPUT, "modem_fill: cb");
345 if (send_cb(cs, cb) < 0) { 334 if (send_cb(cs, cb) < 0) {
346 dbg(DEBUG_OUTPUT, 335 gig_dbg(DEBUG_OUTPUT,
347 "modem_fill: send_cb failed"); 336 "modem_fill: send_cb failed");
348 again = 1; /* no callback will be called! */ 337 again = 1; /* no callback will be
338 called! */
349 } 339 }
350 } else { /* skbs to send? */ 340 } else { /* skbs to send? */
351 bcs->tx_skb = skb_dequeue(&bcs->squeue); 341 bcs->tx_skb = skb_dequeue(&bcs->squeue);
352 if (bcs->tx_skb) 342 if (bcs->tx_skb)
353 dbg(DEBUG_INTR, 343 gig_dbg(DEBUG_INTR,
354 "Dequeued skb (Adr: %lx)!", 344 "Dequeued skb (Adr: %lx)!",
355 (unsigned long) bcs->tx_skb); 345 (unsigned long) bcs->tx_skb);
356 } 346 }
357 } 347 }
358 348
359 if (bcs->tx_skb) { 349 if (bcs->tx_skb) {
360 dbg(DEBUG_OUTPUT, "modem_fill: tx_skb"); 350 gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb");
361 if (write_modem(cs) < 0) { 351 if (write_modem(cs) < 0) {
362 dbg(DEBUG_OUTPUT, 352 gig_dbg(DEBUG_OUTPUT,
363 "modem_fill: write_modem failed"); 353 "modem_fill: write_modem failed");
364 // FIXME should we tell the LL? 354 // FIXME should we tell the LL?
365 again = 1; /* no callback will be called! */ 355 again = 1; /* no callback will be called! */
366 } 356 }
@@ -371,88 +361,85 @@ static void gigaset_modem_fill(unsigned long data)
371/** 361/**
372 * gigaset_read_int_callback 362 * gigaset_read_int_callback
373 * 363 *
374 * It is called if the data was received from the device. This is almost similiar to 364 * It is called if the data was received from the device.
375 * the interrupt service routine in the serial device.
376 */ 365 */
377static void gigaset_read_int_callback(struct urb *urb, struct pt_regs *regs) 366static void gigaset_read_int_callback(struct urb *urb, struct pt_regs *regs)
378{ 367{
368 struct inbuf_t *inbuf = urb->context;
369 struct cardstate *cs = inbuf->cs;
379 int resubmit = 0; 370 int resubmit = 0;
380 int r; 371 int r;
381 struct cardstate *cs;
382 unsigned numbytes; 372 unsigned numbytes;
383 unsigned char *src; 373 unsigned char *src;
384 //unsigned long flags; 374 unsigned long flags;
385 struct inbuf_t *inbuf;
386
387 IFNULLRET(urb);
388 inbuf = (struct inbuf_t *) urb->context;
389 IFNULLRET(inbuf);
390 //spin_lock_irqsave(&inbuf->lock, flags);
391 cs = inbuf->cs;
392 IFNULLGOTO(cs, exit);
393 IFNULLGOTO(cardstate, exit);
394
395 if (!atomic_read(&cs->connected)) {
396 err("%s: disconnected", __func__);
397 goto exit;
398 }
399 375
400 if (!urb->status) { 376 if (!urb->status) {
377 if (!cs->connected) {
378 err("%s: disconnected", __func__); /* should never happen */
379 return;
380 }
381
401 numbytes = urb->actual_length; 382 numbytes = urb->actual_length;
402 383
403 if (numbytes) { 384 if (numbytes) {
404 src = inbuf->rcvbuf; 385 src = inbuf->rcvbuf;
405 if (unlikely(*src)) 386 if (unlikely(*src))
406 warn("%s: There was no leading 0, but 0x%02x!", 387 dev_warn(cs->dev,
407 __func__, (unsigned) *src); 388 "%s: There was no leading 0, but 0x%02x!\n",
389 __func__, (unsigned) *src);
408 ++src; /* skip leading 0x00 */ 390 ++src; /* skip leading 0x00 */
409 --numbytes; 391 --numbytes;
410 if (gigaset_fill_inbuf(inbuf, src, numbytes)) { 392 if (gigaset_fill_inbuf(inbuf, src, numbytes)) {
411 dbg(DEBUG_INTR, "%s-->BH", __func__); 393 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
412 gigaset_schedule_event(inbuf->cs); 394 gigaset_schedule_event(inbuf->cs);
413 } 395 }
414 } else 396 } else
415 dbg(DEBUG_INTR, "Received zero block length"); 397 gig_dbg(DEBUG_INTR, "Received zero block length");
416 resubmit = 1; 398 resubmit = 1;
417 } else { 399 } else {
418 /* The urb might have been killed. */ 400 /* The urb might have been killed. */
419 dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d", 401 gig_dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d",
420 __func__, urb->status); 402 __func__, urb->status);
421 if (urb->status != -ENOENT) /* not killed */ 403 if (urb->status != -ENOENT) { /* not killed */
404 if (!cs->connected) {
405 err("%s: disconnected", __func__); /* should never happen */
406 return;
407 }
422 resubmit = 1; 408 resubmit = 1;
409 }
423 } 410 }
424exit: 411
425 //spin_unlock_irqrestore(&inbuf->lock, flags);
426 if (resubmit) { 412 if (resubmit) {
427 r = usb_submit_urb(urb, SLAB_ATOMIC); 413 spin_lock_irqsave(&cs->lock, flags);
414 r = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
415 spin_unlock_irqrestore(&cs->lock, flags);
428 if (r) 416 if (r)
429 err("error %d when resubmitting urb.", -r); 417 dev_err(cs->dev, "error %d when resubmitting urb.\n",
418 -r);
430 } 419 }
431} 420}
432 421
433 422
434/* This callback routine is called when data was transmitted to a B-Channel. 423/* This callback routine is called when data was transmitted to the device. */
435 * Therefore it has to check if there is still data to transmit. This
436 * happens by calling modem_fill via task queue.
437 *
438 */
439static void gigaset_write_bulk_callback(struct urb *urb, struct pt_regs *regs) 424static void gigaset_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
440{ 425{
441 struct cardstate *cs = (struct cardstate *) urb->context; 426 struct cardstate *cs = urb->context;
427 unsigned long flags;
442 428
443 IFNULLRET(cs);
444#ifdef CONFIG_GIGASET_DEBUG
445 if (!atomic_read(&cs->connected)) {
446 err("%s:not connected", __func__);
447 return;
448 }
449#endif
450 if (urb->status) 429 if (urb->status)
451 err("bulk transfer failed (status %d)", -urb->status); /* That's all we can do. Communication problems 430 dev_err(cs->dev, "bulk transfer failed (status %d)\n",
452 are handeled by timeouts or network protocols */ 431 -urb->status);
432 /* That's all we can do. Communication problems
433 are handled by timeouts or network protocols. */
453 434
454 atomic_set(&cs->hw.usb->busy, 0); 435 spin_lock_irqsave(&cs->lock, flags);
455 tasklet_schedule(&cs->write_tasklet); 436 if (!cs->connected) {
437 err("%s: not connected", __func__);
438 } else {
439 atomic_set(&cs->hw.usb->busy, 0);
440 tasklet_schedule(&cs->write_tasklet);
441 }
442 spin_unlock_irqrestore(&cs->lock, flags);
456} 443}
457 444
458static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb) 445static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
@@ -469,8 +456,8 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
469 456
470 spin_lock_irqsave(&cs->cmdlock, flags); 457 spin_lock_irqsave(&cs->cmdlock, flags);
471 cs->cmdbytes -= cs->curlen; 458 cs->cmdbytes -= cs->curlen;
472 dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left", 459 gig_dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left",
473 cs->curlen, cs->cmdbytes); 460 cs->curlen, cs->cmdbytes);
474 cs->cmdbuf = cb = cb->next; 461 cs->cmdbuf = cb = cb->next;
475 if (cb) { 462 if (cb) {
476 cb->prev = NULL; 463 cb->prev = NULL;
@@ -487,52 +474,51 @@ static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
487 } 474 }
488 if (cb) { 475 if (cb) {
489 count = min(cb->len, ucs->bulk_out_size); 476 count = min(cb->len, ucs->bulk_out_size);
477 gig_dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
478
490 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev, 479 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
491 usb_sndbulkpipe(ucs->udev, 480 usb_sndbulkpipe(ucs->udev,
492 ucs->bulk_out_endpointAddr & 0x0f), 481 ucs->bulk_out_endpointAddr & 0x0f),
493 cb->buf + cb->offset, count, 482 cb->buf + cb->offset, count,
494 gigaset_write_bulk_callback, cs); 483 gigaset_write_bulk_callback, cs);
495 484
496 cb->offset += count; 485 cb->offset += count;
497 cb->len -= count; 486 cb->len -= count;
498 atomic_set(&ucs->busy, 1); 487 atomic_set(&ucs->busy, 1);
499 dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
500 488
501 status = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC); 489 spin_lock_irqsave(&cs->lock, flags);
490 status = cs->connected ? usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC) : -ENODEV;
491 spin_unlock_irqrestore(&cs->lock, flags);
492
502 if (status) { 493 if (status) {
503 atomic_set(&ucs->busy, 0); 494 atomic_set(&ucs->busy, 0);
504 err("could not submit urb (error %d).", 495 err("could not submit urb (error %d)\n",
505 -status); 496 -status);
506 cb->len = 0; /* skip urb => remove cb+wakeup in next loop cycle */ 497 cb->len = 0; /* skip urb => remove cb+wakeup
498 in next loop cycle */
507 } 499 }
508 } 500 }
509 } while (cb && status); /* bei Fehler naechster Befehl //FIXME: ist das OK? */ 501 } while (cb && status); /* next command on error */
510 502
511 return status; 503 return status;
512} 504}
513 505
514/* Write string into transbuf and send it to modem. 506/* Send command to device. */
515 */
516static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf, 507static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
517 int len, struct tasklet_struct *wake_tasklet) 508 int len, struct tasklet_struct *wake_tasklet)
518{ 509{
519 struct cmdbuf_t *cb; 510 struct cmdbuf_t *cb;
520 unsigned long flags; 511 unsigned long flags;
521 512
522 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ? 513 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
523 DEBUG_TRANSCMD : DEBUG_LOCKCMD, 514 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
524 "CMD Transmit", len, buf, 0); 515 "CMD Transmit", len, buf);
525
526 if (!atomic_read(&cs->connected)) {
527 err("%s: not connected", __func__);
528 return -ENODEV;
529 }
530 516
531 if (len <= 0) 517 if (len <= 0)
532 return 0; 518 return 0;
533 519
534 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 520 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
535 err("%s: out of memory", __func__); 521 dev_err(cs->dev, "%s: out of memory\n", __func__);
536 return -ENOMEM; 522 return -ENOMEM;
537 } 523 }
538 524
@@ -554,7 +540,10 @@ static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
554 cs->lastcmdbuf = cb; 540 cs->lastcmdbuf = cb;
555 spin_unlock_irqrestore(&cs->cmdlock, flags); 541 spin_unlock_irqrestore(&cs->cmdlock, flags);
556 542
557 tasklet_schedule(&cs->write_tasklet); 543 spin_lock_irqsave(&cs->lock, flags);
544 if (cs->connected)
545 tasklet_schedule(&cs->write_tasklet);
546 spin_unlock_irqrestore(&cs->lock, flags);
558 return len; 547 return len;
559} 548}
560 549
@@ -578,11 +567,12 @@ static int gigaset_chars_in_buffer(struct cardstate *cs)
578static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6]) 567static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
579{ 568{
580#ifdef CONFIG_GIGASET_UNDOCREQ 569#ifdef CONFIG_GIGASET_UNDOCREQ
581 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf, 0); 570 struct usb_device *udev = cs->hw.usb->udev;
571
572 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
582 memcpy(cs->hw.usb->bchars, buf, 6); 573 memcpy(cs->hw.usb->bchars, buf, 6);
583 return usb_control_msg(cs->hw.usb->udev, 574 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
584 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41, 575 0, 0, &buf, 6, 2000);
585 0, 0, &buf, 6, 2000);
586#else 576#else
587 return -EINVAL; 577 return -EINVAL;
588#endif 578#endif
@@ -604,7 +594,6 @@ static int gigaset_initbcshw(struct bc_state *bcs)
604 if (!bcs->hw.usb) 594 if (!bcs->hw.usb)
605 return 0; 595 return 0;
606 596
607 //bcs->hw.usb->trans_flg = READY_TO_TRNSMIT; /* B-Channel ready to transmit */
608 return 1; 597 return 1;
609} 598}
610 599
@@ -614,7 +603,6 @@ static void gigaset_reinitbcshw(struct bc_state *bcs)
614 603
615static void gigaset_freecshw(struct cardstate *cs) 604static void gigaset_freecshw(struct cardstate *cs)
616{ 605{
617 //FIXME
618 tasklet_kill(&cs->write_tasklet); 606 tasklet_kill(&cs->write_tasklet);
619 kfree(cs->hw.usb); 607 kfree(cs->hw.usb);
620} 608}
@@ -639,33 +627,21 @@ static int gigaset_initcshw(struct cardstate *cs)
639 //ucs->urb_cmd_out = NULL; 627 //ucs->urb_cmd_out = NULL;
640 ucs->read_urb = NULL; 628 ucs->read_urb = NULL;
641 tasklet_init(&cs->write_tasklet, 629 tasklet_init(&cs->write_tasklet,
642 &gigaset_modem_fill, (unsigned long) cs); 630 &gigaset_modem_fill, (unsigned long) cs);
643 631
644 return 1; 632 return 1;
645} 633}
646 634
647/* Writes the data of the current open skb into the modem. 635/* Send data from current skb to the device. */
648 * We have to protect against multiple calls until the
649 * callback handler () is called , due to the fact that we
650 * are just allowed to send data once to an endpoint. Therefore
651 * we using "trans_flg" to synchonize ...
652 */
653static int write_modem(struct cardstate *cs) 636static int write_modem(struct cardstate *cs)
654{ 637{
655 int ret; 638 int ret = 0;
656 int count; 639 int count;
657 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */ 640 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
658 struct usb_cardstate *ucs = cs->hw.usb; 641 struct usb_cardstate *ucs = cs->hw.usb;
659 //unsigned long flags; 642 unsigned long flags;
660
661 IFNULLRETVAL(bcs->tx_skb, -EINVAL);
662
663 dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len);
664 643
665 ret = -ENODEV; 644 gig_dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len);
666 IFNULLGOTO(ucs->bulk_out_buffer, error);
667 IFNULLGOTO(ucs->bulk_out_urb, error);
668 ret = 0;
669 645
670 if (!bcs->tx_skb->len) { 646 if (!bcs->tx_skb->len) {
671 dev_kfree_skb_any(bcs->tx_skb); 647 dev_kfree_skb_any(bcs->tx_skb);
@@ -679,40 +655,42 @@ static int write_modem(struct cardstate *cs)
679 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size); 655 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
680 memcpy(ucs->bulk_out_buffer, bcs->tx_skb->data, count); 656 memcpy(ucs->bulk_out_buffer, bcs->tx_skb->data, count);
681 skb_pull(bcs->tx_skb, count); 657 skb_pull(bcs->tx_skb, count);
682
683 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
684 usb_sndbulkpipe(ucs->udev,
685 ucs->bulk_out_endpointAddr & 0x0f),
686 ucs->bulk_out_buffer, count,
687 gigaset_write_bulk_callback, cs);
688 atomic_set(&ucs->busy, 1); 658 atomic_set(&ucs->busy, 1);
689 dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count); 659 gig_dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
660
661 spin_lock_irqsave(&cs->lock, flags);
662 if (cs->connected) {
663 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
664 usb_sndbulkpipe(ucs->udev,
665 ucs->bulk_out_endpointAddr & 0x0f),
666 ucs->bulk_out_buffer, count,
667 gigaset_write_bulk_callback, cs);
668 ret = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
669 } else {
670 ret = -ENODEV;
671 }
672 spin_unlock_irqrestore(&cs->lock, flags);
690 673
691 ret = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
692 if (ret) { 674 if (ret) {
693 err("could not submit urb (error %d).", -ret); 675 err("could not submit urb (error %d)\n", -ret);
694 atomic_set(&ucs->busy, 0); 676 atomic_set(&ucs->busy, 0);
695 } 677 }
678
696 if (!bcs->tx_skb->len) { 679 if (!bcs->tx_skb->len) {
697 /* skb sent completely */ 680 /* skb sent completely */
698 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0? 681 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0?
699 682
700 dbg(DEBUG_INTR, 683 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
701 "kfree skb (Adr: %lx)!", (unsigned long) bcs->tx_skb); 684 (unsigned long) bcs->tx_skb);
702 dev_kfree_skb_any(bcs->tx_skb); 685 dev_kfree_skb_any(bcs->tx_skb);
703 bcs->tx_skb = NULL; 686 bcs->tx_skb = NULL;
704 } 687 }
705 688
706 return ret; 689 return ret;
707error:
708 dev_kfree_skb_any(bcs->tx_skb);
709 bcs->tx_skb = NULL;
710 return ret;
711
712} 690}
713 691
714static int gigaset_probe(struct usb_interface *interface, 692static int gigaset_probe(struct usb_interface *interface,
715 const struct usb_device_id *id) 693 const struct usb_device_id *id)
716{ 694{
717 int retval; 695 int retval;
718 struct usb_device *udev = interface_to_usbdev(interface); 696 struct usb_device *udev = interface_to_usbdev(interface);
@@ -720,16 +698,14 @@ static int gigaset_probe(struct usb_interface *interface,
720 struct usb_host_interface *hostif; 698 struct usb_host_interface *hostif;
721 struct cardstate *cs = NULL; 699 struct cardstate *cs = NULL;
722 struct usb_cardstate *ucs = NULL; 700 struct usb_cardstate *ucs = NULL;
723 //struct usb_interface_descriptor *iface_desc;
724 struct usb_endpoint_descriptor *endpoint; 701 struct usb_endpoint_descriptor *endpoint;
725 //isdn_ctrl command;
726 int buffer_size; 702 int buffer_size;
727 int alt; 703 int alt;
728 //unsigned long flags;
729 704
730 info("%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)", 705 gig_dbg(DEBUG_ANY,
731 __func__, le16_to_cpu(udev->descriptor.idVendor), 706 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
732 le16_to_cpu(udev->descriptor.idProduct)); 707 __func__, le16_to_cpu(udev->descriptor.idVendor),
708 le16_to_cpu(udev->descriptor.idProduct));
733 709
734 retval = -ENODEV; //FIXME 710 retval = -ENODEV; //FIXME
735 711
@@ -744,7 +720,7 @@ static int gigaset_probe(struct usb_interface *interface,
744 ifnum = hostif->desc.bInterfaceNumber; // FIXME ? 720 ifnum = hostif->desc.bInterfaceNumber; // FIXME ?
745 721
746 if (alt != 0 || ifnum != 0) { 722 if (alt != 0 || ifnum != 0) {
747 warn("ifnum %d, alt %d", ifnum, alt); 723 dev_warn(&udev->dev, "ifnum %d, alt %d\n", ifnum, alt);
748 return -ENODEV; 724 return -ENODEV;
749 } 725 }
750 726
@@ -752,42 +728,29 @@ static int gigaset_probe(struct usb_interface *interface,
752 * 728 *
753 */ 729 */
754 if (hostif->desc.bInterfaceClass != 255) { 730 if (hostif->desc.bInterfaceClass != 255) {
755 info("%s: Device matched, but iface_desc[%d]->bInterfaceClass==%d !", 731 dev_info(&udev->dev,
756 __func__, ifnum, hostif->desc.bInterfaceClass); 732 "%s: Device matched but iface_desc[%d]->bInterfaceClass==%d!\n",
733 __func__, ifnum, hostif->desc.bInterfaceClass);
757 return -ENODEV; 734 return -ENODEV;
758 } 735 }
759 736
760 info("%s: Device matched ... !", __func__); 737 dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
761 738
762 cs = gigaset_getunassignedcs(driver); 739 cs = gigaset_getunassignedcs(driver);
763 if (!cs) { 740 if (!cs) {
764 warn("No free cardstate!"); 741 dev_warn(&udev->dev, "no free cardstate\n");
765 return -ENODEV; 742 return -ENODEV;
766 } 743 }
767 ucs = cs->hw.usb; 744 ucs = cs->hw.usb;
768 745
769#if 0 746 /* save off device structure ptrs for later use */
770 if (usb_set_configuration(udev, udev->config[0].desc.bConfigurationValue) < 0) { 747 usb_get_dev(udev);
771 warn("set_configuration failed"); 748 ucs->udev = udev;
772 goto error; 749 ucs->interface = interface;
773 } 750 cs->dev = &interface->dev;
774
775
776 if (usb_set_interface(udev, ifnum/*==0*/, alt/*==0*/) < 0) {
777 warn("usb_set_interface failed, device %d interface %d altsetting %d",
778 udev->devnum, ifnum, alt);
779 goto error;
780 }
781#endif
782 751
783 /* set up the endpoint information */ 752 /* save address of controller structure */
784 /* check out the endpoints */ 753 usb_set_intfdata(interface, cs); // dev_set_drvdata(&interface->dev, cs);
785 /* We will get 2 endpoints: One for sending commands to the device (bulk out) and one to
786 * poll messages from the device(int in).
787 * Therefore we will have an almost similiar situation as with our serial port handler.
788 * If an connection will be established, we will have to create data in/out pipes
789 * dynamically...
790 */
791 754
792 endpoint = &hostif->endpoint[0].desc; 755 endpoint = &hostif->endpoint[0].desc;
793 756
@@ -796,14 +759,14 @@ static int gigaset_probe(struct usb_interface *interface,
796 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress; 759 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;
797 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); 760 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
798 if (!ucs->bulk_out_buffer) { 761 if (!ucs->bulk_out_buffer) {
799 err("Couldn't allocate bulk_out_buffer"); 762 dev_err(cs->dev, "Couldn't allocate bulk_out_buffer\n");
800 retval = -ENOMEM; 763 retval = -ENOMEM;
801 goto error; 764 goto error;
802 } 765 }
803 766
804 ucs->bulk_out_urb = usb_alloc_urb(0, SLAB_KERNEL); 767 ucs->bulk_out_urb = usb_alloc_urb(0, SLAB_KERNEL);
805 if (!ucs->bulk_out_urb) { 768 if (!ucs->bulk_out_urb) {
806 err("Couldn't allocate bulk_out_buffer"); 769 dev_err(cs->dev, "Couldn't allocate bulk_out_urb\n");
807 retval = -ENOMEM; 770 retval = -ENOMEM;
808 goto error; 771 goto error;
809 } 772 }
@@ -811,12 +774,10 @@ static int gigaset_probe(struct usb_interface *interface,
811 endpoint = &hostif->endpoint[1].desc; 774 endpoint = &hostif->endpoint[1].desc;
812 775
813 atomic_set(&ucs->busy, 0); 776 atomic_set(&ucs->busy, 0);
814 ucs->udev = udev;
815 ucs->interface = interface;
816 777
817 ucs->read_urb = usb_alloc_urb(0, SLAB_KERNEL); 778 ucs->read_urb = usb_alloc_urb(0, SLAB_KERNEL);
818 if (!ucs->read_urb) { 779 if (!ucs->read_urb) {
819 err("No free urbs available"); 780 dev_err(cs->dev, "No free urbs available\n");
820 retval = -ENOMEM; 781 retval = -ENOMEM;
821 goto error; 782 goto error;
822 } 783 }
@@ -825,38 +786,33 @@ static int gigaset_probe(struct usb_interface *interface,
825 ucs->int_in_endpointAddr = endpoint->bEndpointAddress; 786 ucs->int_in_endpointAddr = endpoint->bEndpointAddress;
826 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL); 787 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
827 if (!cs->inbuf[0].rcvbuf) { 788 if (!cs->inbuf[0].rcvbuf) {
828 err("Couldn't allocate rcvbuf"); 789 dev_err(cs->dev, "Couldn't allocate rcvbuf\n");
829 retval = -ENOMEM; 790 retval = -ENOMEM;
830 goto error; 791 goto error;
831 } 792 }
832 /* Fill the interrupt urb and send it to the core */ 793 /* Fill the interrupt urb and send it to the core */
833 usb_fill_int_urb(ucs->read_urb, udev, 794 usb_fill_int_urb(ucs->read_urb, udev,
834 usb_rcvintpipe(udev, 795 usb_rcvintpipe(udev,
835 endpoint->bEndpointAddress & 0x0f), 796 endpoint->bEndpointAddress & 0x0f),
836 cs->inbuf[0].rcvbuf, buffer_size, 797 cs->inbuf[0].rcvbuf, buffer_size,
837 gigaset_read_int_callback, 798 gigaset_read_int_callback,
838 cs->inbuf + 0, endpoint->bInterval); 799 cs->inbuf + 0, endpoint->bInterval);
839 800
840 retval = usb_submit_urb(ucs->read_urb, SLAB_KERNEL); 801 retval = usb_submit_urb(ucs->read_urb, SLAB_KERNEL);
841 if (retval) { 802 if (retval) {
842 err("Could not submit URB!"); 803 dev_err(cs->dev, "Could not submit URB (error %d)\n", -retval);
843 goto error; 804 goto error;
844 } 805 }
845 806
846 /* tell common part that the device is ready */ 807 /* tell common part that the device is ready */
847 if (startmode == SM_LOCKED) 808 if (startmode == SM_LOCKED)
848 atomic_set(&cs->mstate, MS_LOCKED); 809 atomic_set(&cs->mstate, MS_LOCKED);
810
849 if (!gigaset_start(cs)) { 811 if (!gigaset_start(cs)) {
850 tasklet_kill(&cs->write_tasklet); 812 tasklet_kill(&cs->write_tasklet);
851 retval = -ENODEV; //FIXME 813 retval = -ENODEV; //FIXME
852 goto error; 814 goto error;
853 } 815 }
854
855 /* save address of controller structure */
856 usb_set_intfdata(interface, cs);
857
858 /* set up device sysfs */
859 gigaset_init_dev_sysfs(interface);
860 return 0; 816 return 0;
861 817
862error: 818error:
@@ -868,48 +824,45 @@ error:
868 kfree(cs->inbuf[0].rcvbuf); 824 kfree(cs->inbuf[0].rcvbuf);
869 if (ucs->read_urb != NULL) 825 if (ucs->read_urb != NULL)
870 usb_free_urb(ucs->read_urb); 826 usb_free_urb(ucs->read_urb);
827 usb_set_intfdata(interface, NULL);
871 ucs->read_urb = ucs->bulk_out_urb = NULL; 828 ucs->read_urb = ucs->bulk_out_urb = NULL;
872 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL; 829 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
830 usb_put_dev(ucs->udev);
831 ucs->udev = NULL;
832 ucs->interface = NULL;
873 gigaset_unassign(cs); 833 gigaset_unassign(cs);
874 return retval; 834 return retval;
875} 835}
876 836
877/**
878 * skel_disconnect
879 */
880static void gigaset_disconnect(struct usb_interface *interface) 837static void gigaset_disconnect(struct usb_interface *interface)
881{ 838{
882 struct cardstate *cs; 839 struct cardstate *cs;
883 struct usb_cardstate *ucs; 840 struct usb_cardstate *ucs;
884 841
885 cs = usb_get_intfdata(interface); 842 cs = usb_get_intfdata(interface);
886
887 /* clear device sysfs */
888 gigaset_free_dev_sysfs(interface);
889
890 usb_set_intfdata(interface, NULL);
891 ucs = cs->hw.usb; 843 ucs = cs->hw.usb;
892 usb_kill_urb(ucs->read_urb); 844 usb_kill_urb(ucs->read_urb);
893 //info("GigaSet USB device #%d will be disconnected", minor);
894 845
895 gigaset_stop(cs); 846 gigaset_stop(cs);
896 847
848 usb_set_intfdata(interface, NULL);
897 tasklet_kill(&cs->write_tasklet); 849 tasklet_kill(&cs->write_tasklet);
898 850
899 usb_kill_urb(ucs->bulk_out_urb); /* FIXME: nur, wenn noetig */ 851 usb_kill_urb(ucs->bulk_out_urb); /* FIXME: only if active? */
900 //usb_kill_urb(ucs->urb_cmd_out); /* FIXME: nur, wenn noetig */
901 852
902 kfree(ucs->bulk_out_buffer); 853 kfree(ucs->bulk_out_buffer);
903 if (ucs->bulk_out_urb != NULL) 854 if (ucs->bulk_out_urb != NULL)
904 usb_free_urb(ucs->bulk_out_urb); 855 usb_free_urb(ucs->bulk_out_urb);
905 //if(ucs->urb_cmd_out != NULL)
906 // usb_free_urb(ucs->urb_cmd_out);
907 kfree(cs->inbuf[0].rcvbuf); 856 kfree(cs->inbuf[0].rcvbuf);
908 if (ucs->read_urb != NULL) 857 if (ucs->read_urb != NULL)
909 usb_free_urb(ucs->read_urb); 858 usb_free_urb(ucs->read_urb);
910 ucs->read_urb = ucs->bulk_out_urb/*=ucs->urb_cmd_out*/=NULL; 859 ucs->read_urb = ucs->bulk_out_urb = NULL;
911 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL; 860 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
912 861
862 usb_put_dev(ucs->udev);
863 ucs->interface = NULL;
864 ucs->udev = NULL;
865 cs->dev = NULL;
913 gigaset_unassign(cs); 866 gigaset_unassign(cs);
914} 867}
915 868
@@ -942,9 +895,9 @@ static int __init usb_gigaset_init(void)
942 895
943 /* allocate memory for our driver state and intialize it */ 896 /* allocate memory for our driver state and intialize it */
944 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 897 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
945 GIGASET_MODULENAME, GIGASET_DEVNAME, 898 GIGASET_MODULENAME, GIGASET_DEVNAME,
946 GIGASET_DEVFSNAME, &ops, 899 GIGASET_DEVFSNAME, &ops,
947 THIS_MODULE)) == NULL) 900 THIS_MODULE)) == NULL)
948 goto error; 901 goto error;
949 902
950 /* allocate memory for our device state and intialize it */ 903 /* allocate memory for our device state and intialize it */
@@ -981,8 +934,8 @@ error: if (cardstate)
981static void __exit usb_gigaset_exit(void) 934static void __exit usb_gigaset_exit(void)
982{ 935{
983 gigaset_blockdriver(driver); /* => probe will fail 936 gigaset_blockdriver(driver); /* => probe will fail
984 * => no gigaset_start any more 937 * => no gigaset_start any more
985 */ 938 */
986 939
987 gigaset_shutdown(cardstate); 940 gigaset_shutdown(cardstate);
988 /* from now on, no isdn callback should be possible */ 941 /* from now on, no isdn callback should be possible */
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index 2a2b03ff096b..7bbfd85ab793 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -51,8 +51,8 @@ MODULE_LICENSE("GPL");
51 handler. 51 handler.
52*/ 52*/
53 53
54static void avmcs_config(dev_link_t *link); 54static int avmcs_config(struct pcmcia_device *link);
55static void avmcs_release(dev_link_t *link); 55static void avmcs_release(struct pcmcia_device *link);
56 56
57/* 57/*
58 The attach() and detach() entry points are used to create and destroy 58 The attach() and detach() entry points are used to create and destroy
@@ -65,10 +65,10 @@ static void avmcs_detach(struct pcmcia_device *p_dev);
65/* 65/*
66 A linked list of "instances" of the skeleton device. Each actual 66 A linked list of "instances" of the skeleton device. Each actual
67 PCMCIA card corresponds to one device instance, and is described 67 PCMCIA card corresponds to one device instance, and is described
68 by one dev_link_t structure (defined in ds.h). 68 by one struct pcmcia_device structure (defined in ds.h).
69 69
70 You may not want to use a linked list for this -- for example, the 70 You may not want to use a linked list for this -- for example, the
71 memory card driver uses an array of dev_link_t pointers, where minor 71 memory card driver uses an array of struct pcmcia_device pointers, where minor
72 device numbers are used to derive the corresponding array index. 72 device numbers are used to derive the corresponding array index.
73*/ 73*/
74 74
@@ -78,7 +78,7 @@ static void avmcs_detach(struct pcmcia_device *p_dev);
78 example, ethernet cards, modems). In other cases, there may be 78 example, ethernet cards, modems). In other cases, there may be
79 many actual or logical devices (SCSI adapters, memory cards with 79 many actual or logical devices (SCSI adapters, memory cards with
80 multiple partitions). The dev_node_t structures need to be kept 80 multiple partitions). The dev_node_t structures need to be kept
81 in a linked list starting at the 'dev' field of a dev_link_t 81 in a linked list starting at the 'dev' field of a struct pcmcia_device
82 structure. We allocate them in the card's private data structure, 82 structure. We allocate them in the card's private data structure,
83 because they generally can't be allocated dynamically. 83 because they generally can't be allocated dynamically.
84*/ 84*/
@@ -99,54 +99,38 @@ typedef struct local_info_t {
99 99
100======================================================================*/ 100======================================================================*/
101 101
102static int avmcs_attach(struct pcmcia_device *p_dev) 102static int avmcs_probe(struct pcmcia_device *p_dev)
103{ 103{
104 dev_link_t *link;
105 local_info_t *local; 104 local_info_t *local;
106 105
107 /* Initialize the dev_link_t structure */
108 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
109 if (!link)
110 goto err;
111 memset(link, 0, sizeof(struct dev_link_t));
112
113 /* The io structure describes IO port mapping */ 106 /* The io structure describes IO port mapping */
114 link->io.NumPorts1 = 16; 107 p_dev->io.NumPorts1 = 16;
115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 108 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
116 link->io.NumPorts2 = 0; 109 p_dev->io.NumPorts2 = 0;
117 110
118 /* Interrupt setup */ 111 /* Interrupt setup */
119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 112 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
120 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 113 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
114
115 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
121 116
122 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
123
124 /* General socket configuration */ 117 /* General socket configuration */
125 link->conf.Attributes = CONF_ENABLE_IRQ; 118 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
126 link->conf.Vcc = 50; 119 p_dev->conf.IntType = INT_MEMORY_AND_IO;
127 link->conf.IntType = INT_MEMORY_AND_IO; 120 p_dev->conf.ConfigIndex = 1;
128 link->conf.ConfigIndex = 1; 121 p_dev->conf.Present = PRESENT_OPTION;
129 link->conf.Present = PRESENT_OPTION;
130 122
131 /* Allocate space for private device-specific data */ 123 /* Allocate space for private device-specific data */
132 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 124 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
133 if (!local) 125 if (!local)
134 goto err_kfree; 126 goto err;
135 memset(local, 0, sizeof(local_info_t)); 127 memset(local, 0, sizeof(local_info_t));
136 link->priv = local; 128 p_dev->priv = local;
137 129
138 link->handle = p_dev; 130 return avmcs_config(p_dev);
139 p_dev->instance = link;
140 131
141 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
142 avmcs_config(link);
143
144 return 0;
145
146 err_kfree:
147 kfree(link);
148 err: 132 err:
149 return -EINVAL; 133 return -ENOMEM;
150} /* avmcs_attach */ 134} /* avmcs_attach */
151 135
152/*====================================================================== 136/*======================================================================
@@ -158,15 +142,10 @@ static int avmcs_attach(struct pcmcia_device *p_dev)
158 142
159======================================================================*/ 143======================================================================*/
160 144
161static void avmcs_detach(struct pcmcia_device *p_dev) 145static void avmcs_detach(struct pcmcia_device *link)
162{ 146{
163 dev_link_t *link = dev_to_instance(p_dev);
164
165 if (link->state & DEV_CONFIG)
166 avmcs_release(link); 147 avmcs_release(link);
167 148 kfree(link->priv);
168 kfree(link->priv);
169 kfree(link);
170} /* avmcs_detach */ 149} /* avmcs_detach */
171 150
172/*====================================================================== 151/*======================================================================
@@ -177,7 +156,7 @@ static void avmcs_detach(struct pcmcia_device *p_dev)
177 156
178======================================================================*/ 157======================================================================*/
179 158
180static int get_tuple(client_handle_t handle, tuple_t *tuple, 159static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
181 cisparse_t *parse) 160 cisparse_t *parse)
182{ 161{
183 int i = pcmcia_get_tuple_data(handle, tuple); 162 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -185,7 +164,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
185 return pcmcia_parse_tuple(handle, tuple, parse); 164 return pcmcia_parse_tuple(handle, tuple, parse);
186} 165}
187 166
188static int first_tuple(client_handle_t handle, tuple_t *tuple, 167static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
189 cisparse_t *parse) 168 cisparse_t *parse)
190{ 169{
191 int i = pcmcia_get_first_tuple(handle, tuple); 170 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -193,7 +172,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
193 return get_tuple(handle, tuple, parse); 172 return get_tuple(handle, tuple, parse);
194} 173}
195 174
196static int next_tuple(client_handle_t handle, tuple_t *tuple, 175static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
197 cisparse_t *parse) 176 cisparse_t *parse)
198{ 177{
199 int i = pcmcia_get_next_tuple(handle, tuple); 178 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -201,9 +180,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
201 return get_tuple(handle, tuple, parse); 180 return get_tuple(handle, tuple, parse);
202} 181}
203 182
204static void avmcs_config(dev_link_t *link) 183static int avmcs_config(struct pcmcia_device *link)
205{ 184{
206 client_handle_t handle;
207 tuple_t tuple; 185 tuple_t tuple;
208 cisparse_t parse; 186 cisparse_t parse;
209 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 187 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
@@ -213,8 +191,7 @@ static void avmcs_config(dev_link_t *link)
213 char devname[128]; 191 char devname[128];
214 int cardtype; 192 int cardtype;
215 int (*addcard)(unsigned int port, unsigned irq); 193 int (*addcard)(unsigned int port, unsigned irq);
216 194
217 handle = link->handle;
218 dev = link->priv; 195 dev = link->priv;
219 196
220 /* 197 /*
@@ -223,25 +200,21 @@ static void avmcs_config(dev_link_t *link)
223 */ 200 */
224 do { 201 do {
225 tuple.DesiredTuple = CISTPL_CONFIG; 202 tuple.DesiredTuple = CISTPL_CONFIG;
226 i = pcmcia_get_first_tuple(handle, &tuple); 203 i = pcmcia_get_first_tuple(link, &tuple);
227 if (i != CS_SUCCESS) break; 204 if (i != CS_SUCCESS) break;
228 tuple.TupleData = buf; 205 tuple.TupleData = buf;
229 tuple.TupleDataMax = 64; 206 tuple.TupleDataMax = 64;
230 tuple.TupleOffset = 0; 207 tuple.TupleOffset = 0;
231 i = pcmcia_get_tuple_data(handle, &tuple); 208 i = pcmcia_get_tuple_data(link, &tuple);
232 if (i != CS_SUCCESS) break; 209 if (i != CS_SUCCESS) break;
233 i = pcmcia_parse_tuple(handle, &tuple, &parse); 210 i = pcmcia_parse_tuple(link, &tuple, &parse);
234 if (i != CS_SUCCESS) break; 211 if (i != CS_SUCCESS) break;
235 link->conf.ConfigBase = parse.config.base; 212 link->conf.ConfigBase = parse.config.base;
236 } while (0); 213 } while (0);
237 if (i != CS_SUCCESS) { 214 if (i != CS_SUCCESS) {
238 cs_error(link->handle, ParseTuple, i); 215 cs_error(link, ParseTuple, i);
239 link->state &= ~DEV_CONFIG_PENDING; 216 return -ENODEV;
240 return;
241 } 217 }
242
243 /* Configure card */
244 link->state |= DEV_CONFIG;
245 218
246 do { 219 do {
247 220
@@ -252,7 +225,7 @@ static void avmcs_config(dev_link_t *link)
252 tuple.DesiredTuple = CISTPL_VERS_1; 225 tuple.DesiredTuple = CISTPL_VERS_1;
253 226
254 devname[0] = 0; 227 devname[0] = 0;
255 if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) { 228 if( !first_tuple(link, &tuple, &parse) && parse.version_1.ns > 1 ) {
256 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 229 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1],
257 sizeof(devname)); 230 sizeof(devname));
258 } 231 }
@@ -263,7 +236,7 @@ static void avmcs_config(dev_link_t *link)
263 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 236 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
264 tuple.Attributes = 0; 237 tuple.Attributes = 0;
265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 238 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
266 i = first_tuple(handle, &tuple, &parse); 239 i = first_tuple(link, &tuple, &parse);
267 while (i == CS_SUCCESS) { 240 while (i == CS_SUCCESS) {
268 if (cf->io.nwin > 0) { 241 if (cf->io.nwin > 0) {
269 link->conf.ConfigIndex = cf->index; 242 link->conf.ConfigIndex = cf->index;
@@ -273,36 +246,36 @@ static void avmcs_config(dev_link_t *link)
273 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n", 246 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
274 link->io.BasePort1, 247 link->io.BasePort1,
275 link->io.BasePort1+link->io.NumPorts1-1); 248 link->io.BasePort1+link->io.NumPorts1-1);
276 i = pcmcia_request_io(link->handle, &link->io); 249 i = pcmcia_request_io(link, &link->io);
277 if (i == CS_SUCCESS) goto found_port; 250 if (i == CS_SUCCESS) goto found_port;
278 } 251 }
279 i = next_tuple(handle, &tuple, &parse); 252 i = next_tuple(link, &tuple, &parse);
280 } 253 }
281 254
282found_port: 255found_port:
283 if (i != CS_SUCCESS) { 256 if (i != CS_SUCCESS) {
284 cs_error(link->handle, RequestIO, i); 257 cs_error(link, RequestIO, i);
285 break; 258 break;
286 } 259 }
287 260
288 /* 261 /*
289 * allocate an interrupt line 262 * allocate an interrupt line
290 */ 263 */
291 i = pcmcia_request_irq(link->handle, &link->irq); 264 i = pcmcia_request_irq(link, &link->irq);
292 if (i != CS_SUCCESS) { 265 if (i != CS_SUCCESS) {
293 cs_error(link->handle, RequestIRQ, i); 266 cs_error(link, RequestIRQ, i);
294 pcmcia_release_io(link->handle, &link->io); 267 /* undo */
268 pcmcia_disable_device(link);
295 break; 269 break;
296 } 270 }
297 271
298 /* 272 /*
299 * configure the PCMCIA socket 273 * configure the PCMCIA socket
300 */ 274 */
301 i = pcmcia_request_configuration(link->handle, &link->conf); 275 i = pcmcia_request_configuration(link, &link->conf);
302 if (i != CS_SUCCESS) { 276 if (i != CS_SUCCESS) {
303 cs_error(link->handle, RequestConfiguration, i); 277 cs_error(link, RequestConfiguration, i);
304 pcmcia_release_io(link->handle, &link->io); 278 pcmcia_disable_device(link);
305 pcmcia_release_irq(link->handle, &link->irq);
306 break; 279 break;
307 } 280 }
308 281
@@ -331,13 +304,12 @@ found_port:
331 304
332 dev->node.major = 64; 305 dev->node.major = 64;
333 dev->node.minor = 0; 306 dev->node.minor = 0;
334 link->dev = &dev->node; 307 link->dev_node = &dev->node;
335 308
336 link->state &= ~DEV_CONFIG_PENDING;
337 /* If any step failed, release any partially configured state */ 309 /* If any step failed, release any partially configured state */
338 if (i != 0) { 310 if (i != 0) {
339 avmcs_release(link); 311 avmcs_release(link);
340 return; 312 return -ENODEV;
341 } 313 }
342 314
343 315
@@ -351,9 +323,10 @@ found_port:
351 printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n", 323 printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n",
352 dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ); 324 dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ);
353 avmcs_release(link); 325 avmcs_release(link);
354 return; 326 return -ENODEV;
355 } 327 }
356 dev->node.minor = i; 328 dev->node.minor = i;
329 return 0;
357 330
358} /* avmcs_config */ 331} /* avmcs_config */
359 332
@@ -365,56 +338,12 @@ found_port:
365 338
366======================================================================*/ 339======================================================================*/
367 340
368static void avmcs_release(dev_link_t *link) 341static void avmcs_release(struct pcmcia_device *link)
369{ 342{
370 b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ); 343 b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ);
371 344 pcmcia_disable_device(link);
372 /* Unlink the device chain */
373 link->dev = NULL;
374
375 /* Don't bother checking to see if these succeed or not */
376 pcmcia_release_configuration(link->handle);
377 pcmcia_release_io(link->handle, &link->io);
378 pcmcia_release_irq(link->handle, &link->irq);
379 link->state &= ~DEV_CONFIG;
380} /* avmcs_release */ 345} /* avmcs_release */
381 346
382static int avmcs_suspend(struct pcmcia_device *dev)
383{
384 dev_link_t *link = dev_to_instance(dev);
385
386 link->state |= DEV_SUSPEND;
387 if (link->state & DEV_CONFIG)
388 pcmcia_release_configuration(link->handle);
389
390 return 0;
391}
392
393static int avmcs_resume(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state &= ~DEV_SUSPEND;
398 if (link->state & DEV_CONFIG)
399 pcmcia_request_configuration(link->handle, &link->conf);
400
401 return 0;
402}
403
404/*======================================================================
405
406 The card status event handler. Mostly, this schedules other
407 stuff to run after an event is received. A CARD_REMOVAL event
408 also sets some flags to discourage the net drivers from trying
409 to talk to the card any more.
410
411 When a CARD_REMOVAL event is received, we immediately set a flag
412 to block future accesses to this device. All the functions that
413 actually access the device should check this flag to make sure
414 the card is still present.
415
416======================================================================*/
417
418 347
419static struct pcmcia_device_id avmcs_ids[] = { 348static struct pcmcia_device_id avmcs_ids[] = {
420 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335), 349 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
@@ -429,11 +358,9 @@ static struct pcmcia_driver avmcs_driver = {
429 .drv = { 358 .drv = {
430 .name = "avm_cs", 359 .name = "avm_cs",
431 }, 360 },
432 .probe = avmcs_attach, 361 .probe = avmcs_probe,
433 .remove = avmcs_detach, 362 .remove = avmcs_detach,
434 .id_table = avmcs_ids, 363 .id_table = avmcs_ids,
435 .suspend= avmcs_suspend,
436 .resume = avmcs_resume,
437}; 364};
438 365
439static int __init avmcs_init(void) 366static int __init avmcs_init(void)
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 969da40c4248..ac28e3278ad9 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -67,8 +67,8 @@ module_param(isdnprot, int, 0);
67 handler. 67 handler.
68*/ 68*/
69 69
70static void avma1cs_config(dev_link_t *link); 70static int avma1cs_config(struct pcmcia_device *link);
71static void avma1cs_release(dev_link_t *link); 71static void avma1cs_release(struct pcmcia_device *link);
72 72
73/* 73/*
74 The attach() and detach() entry points are used to create and destroy 74 The attach() and detach() entry points are used to create and destroy
@@ -82,10 +82,10 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
82/* 82/*
83 A linked list of "instances" of the skeleton device. Each actual 83 A linked list of "instances" of the skeleton device. Each actual
84 PCMCIA card corresponds to one device instance, and is described 84 PCMCIA card corresponds to one device instance, and is described
85 by one dev_link_t structure (defined in ds.h). 85 by one struct pcmcia_device structure (defined in ds.h).
86 86
87 You may not want to use a linked list for this -- for example, the 87 You may not want to use a linked list for this -- for example, the
88 memory card driver uses an array of dev_link_t pointers, where minor 88 memory card driver uses an array of struct pcmcia_device pointers, where minor
89 device numbers are used to derive the corresponding array index. 89 device numbers are used to derive the corresponding array index.
90*/ 90*/
91 91
@@ -95,7 +95,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev);
95 example, ethernet cards, modems). In other cases, there may be 95 example, ethernet cards, modems). In other cases, there may be
96 many actual or logical devices (SCSI adapters, memory cards with 96 many actual or logical devices (SCSI adapters, memory cards with
97 multiple partitions). The dev_node_t structures need to be kept 97 multiple partitions). The dev_node_t structures need to be kept
98 in a linked list starting at the 'dev' field of a dev_link_t 98 in a linked list starting at the 'dev' field of a struct pcmcia_device
99 structure. We allocate them in the card's private data structure, 99 structure. We allocate them in the card's private data structure,
100 because they generally can't be allocated dynamically. 100 because they generally can't be allocated dynamically.
101*/ 101*/
@@ -116,55 +116,40 @@ typedef struct local_info_t {
116 116
117======================================================================*/ 117======================================================================*/
118 118
119static int avma1cs_attach(struct pcmcia_device *p_dev) 119static int avma1cs_probe(struct pcmcia_device *p_dev)
120{ 120{
121 dev_link_t *link;
122 local_info_t *local; 121 local_info_t *local;
123 122
124 DEBUG(0, "avma1cs_attach()\n"); 123 DEBUG(0, "avma1cs_attach()\n");
125 124
126 /* Initialize the dev_link_t structure */
127 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
128 if (!link)
129 return -ENOMEM;
130 memset(link, 0, sizeof(struct dev_link_t));
131
132 /* Allocate space for private device-specific data */ 125 /* Allocate space for private device-specific data */
133 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 126 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
134 if (!local) { 127 if (!local)
135 kfree(link);
136 return -ENOMEM; 128 return -ENOMEM;
137 } 129
138 memset(local, 0, sizeof(local_info_t)); 130 memset(local, 0, sizeof(local_info_t));
139 link->priv = local; 131 p_dev->priv = local;
140 132
141 /* The io structure describes IO port mapping */ 133 /* The io structure describes IO port mapping */
142 link->io.NumPorts1 = 16; 134 p_dev->io.NumPorts1 = 16;
143 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 135 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
144 link->io.NumPorts2 = 16; 136 p_dev->io.NumPorts2 = 16;
145 link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; 137 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
146 link->io.IOAddrLines = 5; 138 p_dev->io.IOAddrLines = 5;
147 139
148 /* Interrupt setup */ 140 /* Interrupt setup */
149 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 141 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
150 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 142 p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
151 143
152 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 144 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
153 145
154 /* General socket configuration */ 146 /* General socket configuration */
155 link->conf.Attributes = CONF_ENABLE_IRQ; 147 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
156 link->conf.Vcc = 50; 148 p_dev->conf.IntType = INT_MEMORY_AND_IO;
157 link->conf.IntType = INT_MEMORY_AND_IO; 149 p_dev->conf.ConfigIndex = 1;
158 link->conf.ConfigIndex = 1; 150 p_dev->conf.Present = PRESENT_OPTION;
159 link->conf.Present = PRESENT_OPTION;
160 151
161 link->handle = p_dev; 152 return avma1cs_config(p_dev);
162 p_dev->instance = link;
163
164 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
165 avma1cs_config(link);
166
167 return 0;
168} /* avma1cs_attach */ 153} /* avma1cs_attach */
169 154
170/*====================================================================== 155/*======================================================================
@@ -176,17 +161,11 @@ static int avma1cs_attach(struct pcmcia_device *p_dev)
176 161
177======================================================================*/ 162======================================================================*/
178 163
179static void avma1cs_detach(struct pcmcia_device *p_dev) 164static void avma1cs_detach(struct pcmcia_device *link)
180{ 165{
181 dev_link_t *link = dev_to_instance(p_dev); 166 DEBUG(0, "avma1cs_detach(0x%p)\n", link);
182 167 avma1cs_release(link);
183 DEBUG(0, "avma1cs_detach(0x%p)\n", link); 168 kfree(link->priv);
184
185 if (link->state & DEV_CONFIG)
186 avma1cs_release(link);
187
188 kfree(link->priv);
189 kfree(link);
190} /* avma1cs_detach */ 169} /* avma1cs_detach */
191 170
192/*====================================================================== 171/*======================================================================
@@ -197,7 +176,7 @@ static void avma1cs_detach(struct pcmcia_device *p_dev)
197 176
198======================================================================*/ 177======================================================================*/
199 178
200static int get_tuple(client_handle_t handle, tuple_t *tuple, 179static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
201 cisparse_t *parse) 180 cisparse_t *parse)
202{ 181{
203 int i = pcmcia_get_tuple_data(handle, tuple); 182 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -205,7 +184,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
205 return pcmcia_parse_tuple(handle, tuple, parse); 184 return pcmcia_parse_tuple(handle, tuple, parse);
206} 185}
207 186
208static int first_tuple(client_handle_t handle, tuple_t *tuple, 187static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
209 cisparse_t *parse) 188 cisparse_t *parse)
210{ 189{
211 int i = pcmcia_get_first_tuple(handle, tuple); 190 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -213,7 +192,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
213 return get_tuple(handle, tuple, parse); 192 return get_tuple(handle, tuple, parse);
214} 193}
215 194
216static int next_tuple(client_handle_t handle, tuple_t *tuple, 195static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
217 cisparse_t *parse) 196 cisparse_t *parse)
218{ 197{
219 int i = pcmcia_get_next_tuple(handle, tuple); 198 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -221,9 +200,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
221 return get_tuple(handle, tuple, parse); 200 return get_tuple(handle, tuple, parse);
222} 201}
223 202
224static void avma1cs_config(dev_link_t *link) 203static int avma1cs_config(struct pcmcia_device *link)
225{ 204{
226 client_handle_t handle;
227 tuple_t tuple; 205 tuple_t tuple;
228 cisparse_t parse; 206 cisparse_t parse;
229 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 207 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
@@ -233,8 +211,7 @@ static void avma1cs_config(dev_link_t *link)
233 char devname[128]; 211 char devname[128];
234 IsdnCard_t icard; 212 IsdnCard_t icard;
235 int busy = 0; 213 int busy = 0;
236 214
237 handle = link->handle;
238 dev = link->priv; 215 dev = link->priv;
239 216
240 DEBUG(0, "avma1cs_config(0x%p)\n", link); 217 DEBUG(0, "avma1cs_config(0x%p)\n", link);
@@ -245,25 +222,21 @@ static void avma1cs_config(dev_link_t *link)
245 */ 222 */
246 do { 223 do {
247 tuple.DesiredTuple = CISTPL_CONFIG; 224 tuple.DesiredTuple = CISTPL_CONFIG;
248 i = pcmcia_get_first_tuple(handle, &tuple); 225 i = pcmcia_get_first_tuple(link, &tuple);
249 if (i != CS_SUCCESS) break; 226 if (i != CS_SUCCESS) break;
250 tuple.TupleData = buf; 227 tuple.TupleData = buf;
251 tuple.TupleDataMax = 64; 228 tuple.TupleDataMax = 64;
252 tuple.TupleOffset = 0; 229 tuple.TupleOffset = 0;
253 i = pcmcia_get_tuple_data(handle, &tuple); 230 i = pcmcia_get_tuple_data(link, &tuple);
254 if (i != CS_SUCCESS) break; 231 if (i != CS_SUCCESS) break;
255 i = pcmcia_parse_tuple(handle, &tuple, &parse); 232 i = pcmcia_parse_tuple(link, &tuple, &parse);
256 if (i != CS_SUCCESS) break; 233 if (i != CS_SUCCESS) break;
257 link->conf.ConfigBase = parse.config.base; 234 link->conf.ConfigBase = parse.config.base;
258 } while (0); 235 } while (0);
259 if (i != CS_SUCCESS) { 236 if (i != CS_SUCCESS) {
260 cs_error(link->handle, ParseTuple, i); 237 cs_error(link, ParseTuple, i);
261 link->state &= ~DEV_CONFIG_PENDING; 238 return -ENODEV;
262 return;
263 } 239 }
264
265 /* Configure card */
266 link->state |= DEV_CONFIG;
267 240
268 do { 241 do {
269 242
@@ -274,7 +247,7 @@ static void avma1cs_config(dev_link_t *link)
274 tuple.DesiredTuple = CISTPL_VERS_1; 247 tuple.DesiredTuple = CISTPL_VERS_1;
275 248
276 devname[0] = 0; 249 devname[0] = 0;
277 if( !first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 1 ) { 250 if( !first_tuple(link, &tuple, &parse) && parse.version_1.ns > 1 ) {
278 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1], 251 strlcpy(devname,parse.version_1.str + parse.version_1.ofs[1],
279 sizeof(devname)); 252 sizeof(devname));
280 } 253 }
@@ -285,7 +258,7 @@ static void avma1cs_config(dev_link_t *link)
285 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 258 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
286 tuple.Attributes = 0; 259 tuple.Attributes = 0;
287 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 260 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
288 i = first_tuple(handle, &tuple, &parse); 261 i = first_tuple(link, &tuple, &parse);
289 while (i == CS_SUCCESS) { 262 while (i == CS_SUCCESS) {
290 if (cf->io.nwin > 0) { 263 if (cf->io.nwin > 0) {
291 link->conf.ConfigIndex = cf->index; 264 link->conf.ConfigIndex = cf->index;
@@ -295,36 +268,36 @@ static void avma1cs_config(dev_link_t *link)
295 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n", 268 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
296 link->io.BasePort1, 269 link->io.BasePort1,
297 link->io.BasePort1+link->io.NumPorts1 - 1); 270 link->io.BasePort1+link->io.NumPorts1 - 1);
298 i = pcmcia_request_io(link->handle, &link->io); 271 i = pcmcia_request_io(link, &link->io);
299 if (i == CS_SUCCESS) goto found_port; 272 if (i == CS_SUCCESS) goto found_port;
300 } 273 }
301 i = next_tuple(handle, &tuple, &parse); 274 i = next_tuple(link, &tuple, &parse);
302 } 275 }
303 276
304found_port: 277found_port:
305 if (i != CS_SUCCESS) { 278 if (i != CS_SUCCESS) {
306 cs_error(link->handle, RequestIO, i); 279 cs_error(link, RequestIO, i);
307 break; 280 break;
308 } 281 }
309 282
310 /* 283 /*
311 * allocate an interrupt line 284 * allocate an interrupt line
312 */ 285 */
313 i = pcmcia_request_irq(link->handle, &link->irq); 286 i = pcmcia_request_irq(link, &link->irq);
314 if (i != CS_SUCCESS) { 287 if (i != CS_SUCCESS) {
315 cs_error(link->handle, RequestIRQ, i); 288 cs_error(link, RequestIRQ, i);
316 pcmcia_release_io(link->handle, &link->io); 289 /* undo */
290 pcmcia_disable_device(link);
317 break; 291 break;
318 } 292 }
319 293
320 /* 294 /*
321 * configure the PCMCIA socket 295 * configure the PCMCIA socket
322 */ 296 */
323 i = pcmcia_request_configuration(link->handle, &link->conf); 297 i = pcmcia_request_configuration(link, &link->conf);
324 if (i != CS_SUCCESS) { 298 if (i != CS_SUCCESS) {
325 cs_error(link->handle, RequestConfiguration, i); 299 cs_error(link, RequestConfiguration, i);
326 pcmcia_release_io(link->handle, &link->io); 300 pcmcia_disable_device(link);
327 pcmcia_release_irq(link->handle, &link->irq);
328 break; 301 break;
329 } 302 }
330 303
@@ -336,13 +309,12 @@ found_port:
336 strcpy(dev->node.dev_name, "A1"); 309 strcpy(dev->node.dev_name, "A1");
337 dev->node.major = 45; 310 dev->node.major = 45;
338 dev->node.minor = 0; 311 dev->node.minor = 0;
339 link->dev = &dev->node; 312 link->dev_node = &dev->node;
340 313
341 link->state &= ~DEV_CONFIG_PENDING;
342 /* If any step failed, release any partially configured state */ 314 /* If any step failed, release any partially configured state */
343 if (i != 0) { 315 if (i != 0) {
344 avma1cs_release(link); 316 avma1cs_release(link);
345 return; 317 return -ENODEV;
346 } 318 }
347 319
348 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n", 320 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
@@ -357,10 +329,11 @@ found_port:
357 if (i < 0) { 329 if (i < 0) {
358 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1); 330 printk(KERN_ERR "avma1_cs: failed to initialize AVM A1 PCMCIA %d at i/o %#x\n", i, link->io.BasePort1);
359 avma1cs_release(link); 331 avma1cs_release(link);
360 return; 332 return -ENODEV;
361 } 333 }
362 dev->node.minor = i; 334 dev->node.minor = i;
363 335
336 return 0;
364} /* avma1cs_config */ 337} /* avma1cs_config */
365 338
366/*====================================================================== 339/*======================================================================
@@ -371,47 +344,18 @@ found_port:
371 344
372======================================================================*/ 345======================================================================*/
373 346
374static void avma1cs_release(dev_link_t *link) 347static void avma1cs_release(struct pcmcia_device *link)
375{ 348{
376 local_info_t *local = link->priv; 349 local_info_t *local = link->priv;
377 350
378 DEBUG(0, "avma1cs_release(0x%p)\n", link); 351 DEBUG(0, "avma1cs_release(0x%p)\n", link);
379 352
380 /* no unregister function with hisax */ 353 /* now unregister function with hisax */
381 HiSax_closecard(local->node.minor); 354 HiSax_closecard(local->node.minor);
382 355
383 /* Unlink the device chain */ 356 pcmcia_disable_device(link);
384 link->dev = NULL;
385
386 /* Don't bother checking to see if these succeed or not */
387 pcmcia_release_configuration(link->handle);
388 pcmcia_release_io(link->handle, &link->io);
389 pcmcia_release_irq(link->handle, &link->irq);
390 link->state &= ~DEV_CONFIG;
391} /* avma1cs_release */ 357} /* avma1cs_release */
392 358
393static int avma1cs_suspend(struct pcmcia_device *dev)
394{
395 dev_link_t *link = dev_to_instance(dev);
396
397 link->state |= DEV_SUSPEND;
398 if (link->state & DEV_CONFIG)
399 pcmcia_release_configuration(link->handle);
400
401 return 0;
402}
403
404static int avma1cs_resume(struct pcmcia_device *dev)
405{
406 dev_link_t *link = dev_to_instance(dev);
407
408 link->state &= ~DEV_SUSPEND;
409 if (link->state & DEV_CONFIG)
410 pcmcia_request_configuration(link->handle, &link->conf);
411
412 return 0;
413}
414
415 359
416static struct pcmcia_device_id avma1cs_ids[] = { 360static struct pcmcia_device_id avma1cs_ids[] = {
417 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), 361 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
@@ -425,13 +369,11 @@ static struct pcmcia_driver avma1cs_driver = {
425 .drv = { 369 .drv = {
426 .name = "avma1_cs", 370 .name = "avma1_cs",
427 }, 371 },
428 .probe = avma1cs_attach, 372 .probe = avma1cs_probe,
429 .remove = avma1cs_detach, 373 .remove = avma1cs_detach,
430 .id_table = avma1cs_ids, 374 .id_table = avma1cs_ids,
431 .suspend = avma1cs_suspend,
432 .resume = avma1cs_resume,
433}; 375};
434 376
435/*====================================================================*/ 377/*====================================================================*/
436 378
437static int __init init_avma1_cs(void) 379static int __init init_avma1_cs(void)
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index 062fb8f0739f..e18e75be8ed3 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -94,8 +94,8 @@ module_param(protocol, int, 0);
94 handler. 94 handler.
95*/ 95*/
96 96
97static void elsa_cs_config(dev_link_t *link); 97static int elsa_cs_config(struct pcmcia_device *link);
98static void elsa_cs_release(dev_link_t *link); 98static void elsa_cs_release(struct pcmcia_device *link);
99 99
100/* 100/*
101 The attach() and detach() entry points are used to create and destroy 101 The attach() and detach() entry points are used to create and destroy
@@ -111,7 +111,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev);
111 example, ethernet cards, modems). In other cases, there may be 111 example, ethernet cards, modems). In other cases, there may be
112 many actual or logical devices (SCSI adapters, memory cards with 112 many actual or logical devices (SCSI adapters, memory cards with
113 multiple partitions). The dev_node_t structures need to be kept 113 multiple partitions). The dev_node_t structures need to be kept
114 in a linked list starting at the 'dev' field of a dev_link_t 114 in a linked list starting at the 'dev' field of a struct pcmcia_device
115 structure. We allocate them in the card's private data structure, 115 structure. We allocate them in the card's private data structure,
116 because they generally shouldn't be allocated dynamically. 116 because they generally shouldn't be allocated dynamically.
117 In this case, we also provide a flag to indicate if a device is 117 In this case, we also provide a flag to indicate if a device is
@@ -121,7 +121,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev);
121*/ 121*/
122 122
123typedef struct local_info_t { 123typedef struct local_info_t {
124 dev_link_t link; 124 struct pcmcia_device *p_dev;
125 dev_node_t node; 125 dev_node_t node;
126 int busy; 126 int busy;
127 int cardnr; 127 int cardnr;
@@ -139,9 +139,8 @@ typedef struct local_info_t {
139 139
140======================================================================*/ 140======================================================================*/
141 141
142static int elsa_cs_attach(struct pcmcia_device *p_dev) 142static int elsa_cs_probe(struct pcmcia_device *link)
143{ 143{
144 dev_link_t *link;
145 local_info_t *local; 144 local_info_t *local;
146 145
147 DEBUG(0, "elsa_cs_attach()\n"); 146 DEBUG(0, "elsa_cs_attach()\n");
@@ -150,8 +149,11 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
150 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 149 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
151 if (!local) return -ENOMEM; 150 if (!local) return -ENOMEM;
152 memset(local, 0, sizeof(local_info_t)); 151 memset(local, 0, sizeof(local_info_t));
152
153 local->p_dev = link;
154 link->priv = local;
155
153 local->cardnr = -1; 156 local->cardnr = -1;
154 link = &local->link; link->priv = local;
155 157
156 /* Interrupt setup */ 158 /* Interrupt setup */
157 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 159 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
@@ -170,16 +172,9 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
170 link->io.IOAddrLines = 3; 172 link->io.IOAddrLines = 3;
171 173
172 link->conf.Attributes = CONF_ENABLE_IRQ; 174 link->conf.Attributes = CONF_ENABLE_IRQ;
173 link->conf.Vcc = 50;
174 link->conf.IntType = INT_MEMORY_AND_IO; 175 link->conf.IntType = INT_MEMORY_AND_IO;
175 176
176 link->handle = p_dev; 177 return elsa_cs_config(link);
177 p_dev->instance = link;
178
179 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
180 elsa_cs_config(link);
181
182 return 0;
183} /* elsa_cs_attach */ 178} /* elsa_cs_attach */
184 179
185/*====================================================================== 180/*======================================================================
@@ -191,20 +186,16 @@ static int elsa_cs_attach(struct pcmcia_device *p_dev)
191 186
192======================================================================*/ 187======================================================================*/
193 188
194static void elsa_cs_detach(struct pcmcia_device *p_dev) 189static void elsa_cs_detach(struct pcmcia_device *link)
195{ 190{
196 dev_link_t *link = dev_to_instance(p_dev); 191 local_info_t *info = link->priv;
197 local_info_t *info = link->priv;
198 192
199 DEBUG(0, "elsa_cs_detach(0x%p)\n", link); 193 DEBUG(0, "elsa_cs_detach(0x%p)\n", link);
200 194
201 if (link->state & DEV_CONFIG) { 195 info->busy = 1;
202 info->busy = 1; 196 elsa_cs_release(link);
203 elsa_cs_release(link);
204 }
205
206 kfree(info);
207 197
198 kfree(info);
208} /* elsa_cs_detach */ 199} /* elsa_cs_detach */
209 200
210/*====================================================================== 201/*======================================================================
@@ -214,7 +205,7 @@ static void elsa_cs_detach(struct pcmcia_device *p_dev)
214 device available to the system. 205 device available to the system.
215 206
216======================================================================*/ 207======================================================================*/
217static int get_tuple(client_handle_t handle, tuple_t *tuple, 208static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
218 cisparse_t *parse) 209 cisparse_t *parse)
219{ 210{
220 int i = pcmcia_get_tuple_data(handle, tuple); 211 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -222,7 +213,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
222 return pcmcia_parse_tuple(handle, tuple, parse); 213 return pcmcia_parse_tuple(handle, tuple, parse);
223} 214}
224 215
225static int first_tuple(client_handle_t handle, tuple_t *tuple, 216static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
226 cisparse_t *parse) 217 cisparse_t *parse)
227{ 218{
228 int i = pcmcia_get_first_tuple(handle, tuple); 219 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -230,7 +221,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
230 return get_tuple(handle, tuple, parse); 221 return get_tuple(handle, tuple, parse);
231} 222}
232 223
233static int next_tuple(client_handle_t handle, tuple_t *tuple, 224static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
234 cisparse_t *parse) 225 cisparse_t *parse)
235{ 226{
236 int i = pcmcia_get_next_tuple(handle, tuple); 227 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -238,9 +229,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
238 return get_tuple(handle, tuple, parse); 229 return get_tuple(handle, tuple, parse);
239} 230}
240 231
241static void elsa_cs_config(dev_link_t *link) 232static int elsa_cs_config(struct pcmcia_device *link)
242{ 233{
243 client_handle_t handle;
244 tuple_t tuple; 234 tuple_t tuple;
245 cisparse_t parse; 235 cisparse_t parse;
246 local_info_t *dev; 236 local_info_t *dev;
@@ -250,7 +240,6 @@ static void elsa_cs_config(dev_link_t *link)
250 IsdnCard_t icard; 240 IsdnCard_t icard;
251 241
252 DEBUG(0, "elsa_config(0x%p)\n", link); 242 DEBUG(0, "elsa_config(0x%p)\n", link);
253 handle = link->handle;
254 dev = link->priv; 243 dev = link->priv;
255 244
256 /* 245 /*
@@ -262,7 +251,7 @@ static void elsa_cs_config(dev_link_t *link)
262 tuple.TupleDataMax = 255; 251 tuple.TupleDataMax = 255;
263 tuple.TupleOffset = 0; 252 tuple.TupleOffset = 0;
264 tuple.Attributes = 0; 253 tuple.Attributes = 0;
265 i = first_tuple(handle, &tuple, &parse); 254 i = first_tuple(link, &tuple, &parse);
266 if (i != CS_SUCCESS) { 255 if (i != CS_SUCCESS) {
267 last_fn = ParseTuple; 256 last_fn = ParseTuple;
268 goto cs_failed; 257 goto cs_failed;
@@ -270,32 +259,29 @@ static void elsa_cs_config(dev_link_t *link)
270 link->conf.ConfigBase = parse.config.base; 259 link->conf.ConfigBase = parse.config.base;
271 link->conf.Present = parse.config.rmask[0]; 260 link->conf.Present = parse.config.rmask[0];
272 261
273 /* Configure card */
274 link->state |= DEV_CONFIG;
275
276 tuple.TupleData = (cisdata_t *)buf; 262 tuple.TupleData = (cisdata_t *)buf;
277 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 263 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
278 tuple.Attributes = 0; 264 tuple.Attributes = 0;
279 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
280 i = first_tuple(handle, &tuple, &parse); 266 i = first_tuple(link, &tuple, &parse);
281 while (i == CS_SUCCESS) { 267 while (i == CS_SUCCESS) {
282 if ( (cf->io.nwin > 0) && cf->io.win[0].base) { 268 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
283 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n"); 269 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
284 link->conf.ConfigIndex = cf->index; 270 link->conf.ConfigIndex = cf->index;
285 link->io.BasePort1 = cf->io.win[0].base; 271 link->io.BasePort1 = cf->io.win[0].base;
286 i = pcmcia_request_io(link->handle, &link->io); 272 i = pcmcia_request_io(link, &link->io);
287 if (i == CS_SUCCESS) break; 273 if (i == CS_SUCCESS) break;
288 } else { 274 } else {
289 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n"); 275 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
290 link->conf.ConfigIndex = cf->index; 276 link->conf.ConfigIndex = cf->index;
291 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) { 277 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
292 link->io.BasePort1 = j; 278 link->io.BasePort1 = j;
293 i = pcmcia_request_io(link->handle, &link->io); 279 i = pcmcia_request_io(link, &link->io);
294 if (i == CS_SUCCESS) break; 280 if (i == CS_SUCCESS) break;
295 } 281 }
296 break; 282 break;
297 } 283 }
298 i = next_tuple(handle, &tuple, &parse); 284 i = next_tuple(link, &tuple, &parse);
299 } 285 }
300 286
301 if (i != CS_SUCCESS) { 287 if (i != CS_SUCCESS) {
@@ -303,14 +289,14 @@ static void elsa_cs_config(dev_link_t *link)
303 goto cs_failed; 289 goto cs_failed;
304 } 290 }
305 291
306 i = pcmcia_request_irq(link->handle, &link->irq); 292 i = pcmcia_request_irq(link, &link->irq);
307 if (i != CS_SUCCESS) { 293 if (i != CS_SUCCESS) {
308 link->irq.AssignedIRQ = 0; 294 link->irq.AssignedIRQ = 0;
309 last_fn = RequestIRQ; 295 last_fn = RequestIRQ;
310 goto cs_failed; 296 goto cs_failed;
311 } 297 }
312 298
313 i = pcmcia_request_configuration(link->handle, &link->conf); 299 i = pcmcia_request_configuration(link, &link->conf);
314 if (i != CS_SUCCESS) { 300 if (i != CS_SUCCESS) {
315 last_fn = RequestConfiguration; 301 last_fn = RequestConfiguration;
316 goto cs_failed; 302 goto cs_failed;
@@ -321,14 +307,11 @@ static void elsa_cs_config(dev_link_t *link)
321 sprintf(dev->node.dev_name, "elsa"); 307 sprintf(dev->node.dev_name, "elsa");
322 dev->node.major = dev->node.minor = 0x0; 308 dev->node.major = dev->node.minor = 0x0;
323 309
324 link->dev = &dev->node; 310 link->dev_node = &dev->node;
325 311
326 /* Finally, report what we've done */ 312 /* Finally, report what we've done */
327 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 313 printk(KERN_INFO "%s: index 0x%02x: ",
328 dev->node.dev_name, link->conf.ConfigIndex, 314 dev->node.dev_name, link->conf.ConfigIndex);
329 link->conf.Vcc/10, link->conf.Vcc%10);
330 if (link->conf.Vpp1)
331 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
332 if (link->conf.Attributes & CONF_ENABLE_IRQ) 315 if (link->conf.Attributes & CONF_ENABLE_IRQ)
333 printk(", irq %d", link->irq.AssignedIRQ); 316 printk(", irq %d", link->irq.AssignedIRQ);
334 if (link->io.NumPorts1) 317 if (link->io.NumPorts1)
@@ -339,8 +322,6 @@ static void elsa_cs_config(dev_link_t *link)
339 link->io.BasePort2+link->io.NumPorts2-1); 322 link->io.BasePort2+link->io.NumPorts2-1);
340 printk("\n"); 323 printk("\n");
341 324
342 link->state &= ~DEV_CONFIG_PENDING;
343
344 icard.para[0] = link->irq.AssignedIRQ; 325 icard.para[0] = link->irq.AssignedIRQ;
345 icard.para[1] = link->io.BasePort1; 326 icard.para[1] = link->io.BasePort1;
346 icard.protocol = protocol; 327 icard.protocol = protocol;
@@ -354,10 +335,11 @@ static void elsa_cs_config(dev_link_t *link)
354 } else 335 } else
355 ((local_info_t*)link->priv)->cardnr = i; 336 ((local_info_t*)link->priv)->cardnr = i;
356 337
357 return; 338 return 0;
358cs_failed: 339cs_failed:
359 cs_error(link->handle, last_fn, i); 340 cs_error(link, last_fn, i);
360 elsa_cs_release(link); 341 elsa_cs_release(link);
342 return -ENODEV;
361} /* elsa_cs_config */ 343} /* elsa_cs_config */
362 344
363/*====================================================================== 345/*======================================================================
@@ -368,7 +350,7 @@ cs_failed:
368 350
369======================================================================*/ 351======================================================================*/
370 352
371static void elsa_cs_release(dev_link_t *link) 353static void elsa_cs_release(struct pcmcia_device *link)
372{ 354{
373 local_info_t *local = link->priv; 355 local_info_t *local = link->priv;
374 356
@@ -380,39 +362,23 @@ static void elsa_cs_release(dev_link_t *link)
380 HiSax_closecard(local->cardnr); 362 HiSax_closecard(local->cardnr);
381 } 363 }
382 } 364 }
383 /* Unlink the device chain */ 365
384 link->dev = NULL; 366 pcmcia_disable_device(link);
385
386 /* Don't bother checking to see if these succeed or not */
387 if (link->win)
388 pcmcia_release_window(link->win);
389 pcmcia_release_configuration(link->handle);
390 pcmcia_release_io(link->handle, &link->io);
391 pcmcia_release_irq(link->handle, &link->irq);
392 link->state &= ~DEV_CONFIG;
393} /* elsa_cs_release */ 367} /* elsa_cs_release */
394 368
395static int elsa_suspend(struct pcmcia_device *p_dev) 369static int elsa_suspend(struct pcmcia_device *link)
396{ 370{
397 dev_link_t *link = dev_to_instance(p_dev);
398 local_info_t *dev = link->priv; 371 local_info_t *dev = link->priv;
399 372
400 link->state |= DEV_SUSPEND;
401 dev->busy = 1; 373 dev->busy = 1;
402 if (link->state & DEV_CONFIG)
403 pcmcia_release_configuration(link->handle);
404 374
405 return 0; 375 return 0;
406} 376}
407 377
408static int elsa_resume(struct pcmcia_device *p_dev) 378static int elsa_resume(struct pcmcia_device *link)
409{ 379{
410 dev_link_t *link = dev_to_instance(p_dev);
411 local_info_t *dev = link->priv; 380 local_info_t *dev = link->priv;
412 381
413 link->state &= ~DEV_SUSPEND;
414 if (link->state & DEV_CONFIG)
415 pcmcia_request_configuration(link->handle, &link->conf);
416 dev->busy = 0; 382 dev->busy = 0;
417 383
418 return 0; 384 return 0;
@@ -430,7 +396,7 @@ static struct pcmcia_driver elsa_cs_driver = {
430 .drv = { 396 .drv = {
431 .name = "elsa_cs", 397 .name = "elsa_cs",
432 }, 398 },
433 .probe = elsa_cs_attach, 399 .probe = elsa_cs_probe,
434 .remove = elsa_cs_detach, 400 .remove = elsa_cs_detach,
435 .id_table = elsa_ids, 401 .id_table = elsa_ids,
436 .suspend = elsa_suspend, 402 .suspend = elsa_suspend,
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 6f5213a18a8d..9bb18f3f7829 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -95,8 +95,8 @@ module_param(protocol, int, 0);
95 event handler. 95 event handler.
96*/ 96*/
97 97
98static void sedlbauer_config(dev_link_t *link); 98static int sedlbauer_config(struct pcmcia_device *link);
99static void sedlbauer_release(dev_link_t *link); 99static void sedlbauer_release(struct pcmcia_device *link);
100 100
101/* 101/*
102 The attach() and detach() entry points are used to create and destroy 102 The attach() and detach() entry points are used to create and destroy
@@ -119,7 +119,7 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev);
119 example, ethernet cards, modems). In other cases, there may be 119 example, ethernet cards, modems). In other cases, there may be
120 many actual or logical devices (SCSI adapters, memory cards with 120 many actual or logical devices (SCSI adapters, memory cards with
121 multiple partitions). The dev_node_t structures need to be kept 121 multiple partitions). The dev_node_t structures need to be kept
122 in a linked list starting at the 'dev' field of a dev_link_t 122 in a linked list starting at the 'dev' field of a struct pcmcia_device
123 structure. We allocate them in the card's private data structure, 123 structure. We allocate them in the card's private data structure,
124 because they generally shouldn't be allocated dynamically. 124 because they generally shouldn't be allocated dynamically.
125 125
@@ -130,7 +130,7 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev);
130*/ 130*/
131 131
132typedef struct local_info_t { 132typedef struct local_info_t {
133 dev_link_t link; 133 struct pcmcia_device *p_dev;
134 dev_node_t node; 134 dev_node_t node;
135 int stop; 135 int stop;
136 int cardnr; 136 int cardnr;
@@ -148,11 +148,10 @@ typedef struct local_info_t {
148 148
149======================================================================*/ 149======================================================================*/
150 150
151static int sedlbauer_attach(struct pcmcia_device *p_dev) 151static int sedlbauer_probe(struct pcmcia_device *link)
152{ 152{
153 local_info_t *local; 153 local_info_t *local;
154 dev_link_t *link; 154
155
156 DEBUG(0, "sedlbauer_attach()\n"); 155 DEBUG(0, "sedlbauer_attach()\n");
157 156
158 /* Allocate space for private device-specific data */ 157 /* Allocate space for private device-specific data */
@@ -160,8 +159,10 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
160 if (!local) return -ENOMEM; 159 if (!local) return -ENOMEM;
161 memset(local, 0, sizeof(local_info_t)); 160 memset(local, 0, sizeof(local_info_t));
162 local->cardnr = -1; 161 local->cardnr = -1;
163 link = &local->link; link->priv = local; 162
164 163 local->p_dev = link;
164 link->priv = local;
165
165 /* Interrupt setup */ 166 /* Interrupt setup */
166 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 167 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
167 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 168 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
@@ -182,18 +183,10 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
182 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 183 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
183 link->io.IOAddrLines = 3; 184 link->io.IOAddrLines = 3;
184 185
185
186 link->conf.Attributes = 0; 186 link->conf.Attributes = 0;
187 link->conf.Vcc = 50;
188 link->conf.IntType = INT_MEMORY_AND_IO; 187 link->conf.IntType = INT_MEMORY_AND_IO;
189 188
190 link->handle = p_dev; 189 return sedlbauer_config(link);
191 p_dev->instance = link;
192
193 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
194 sedlbauer_config(link);
195
196 return 0;
197} /* sedlbauer_attach */ 190} /* sedlbauer_attach */
198 191
199/*====================================================================== 192/*======================================================================
@@ -205,19 +198,15 @@ static int sedlbauer_attach(struct pcmcia_device *p_dev)
205 198
206======================================================================*/ 199======================================================================*/
207 200
208static void sedlbauer_detach(struct pcmcia_device *p_dev) 201static void sedlbauer_detach(struct pcmcia_device *link)
209{ 202{
210 dev_link_t *link = dev_to_instance(p_dev); 203 DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
211
212 DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
213 204
214 if (link->state & DEV_CONFIG) { 205 ((local_info_t *)link->priv)->stop = 1;
215 ((local_info_t *)link->priv)->stop = 1; 206 sedlbauer_release(link);
216 sedlbauer_release(link);
217 }
218 207
219 /* This points to the parent local_info_t struct */ 208 /* This points to the parent local_info_t struct */
220 kfree(link->priv); 209 kfree(link->priv);
221} /* sedlbauer_detach */ 210} /* sedlbauer_detach */
222 211
223/*====================================================================== 212/*======================================================================
@@ -230,9 +219,8 @@ static void sedlbauer_detach(struct pcmcia_device *p_dev)
230#define CS_CHECK(fn, ret) \ 219#define CS_CHECK(fn, ret) \
231do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 220do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
232 221
233static void sedlbauer_config(dev_link_t *link) 222static int sedlbauer_config(struct pcmcia_device *link)
234{ 223{
235 client_handle_t handle = link->handle;
236 local_info_t *dev = link->priv; 224 local_info_t *dev = link->priv;
237 tuple_t tuple; 225 tuple_t tuple;
238 cisparse_t parse; 226 cisparse_t parse;
@@ -254,18 +242,13 @@ static void sedlbauer_config(dev_link_t *link)
254 tuple.TupleData = buf; 242 tuple.TupleData = buf;
255 tuple.TupleDataMax = sizeof(buf); 243 tuple.TupleDataMax = sizeof(buf);
256 tuple.TupleOffset = 0; 244 tuple.TupleOffset = 0;
257 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 245 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
258 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 246 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
259 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 247 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
260 link->conf.ConfigBase = parse.config.base; 248 link->conf.ConfigBase = parse.config.base;
261 link->conf.Present = parse.config.rmask[0]; 249 link->conf.Present = parse.config.rmask[0];
262
263 /* Configure card */
264 link->state |= DEV_CONFIG;
265 250
266 /* Look up the current Vcc */ 251 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
267 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
268 link->conf.Vcc = conf.Vcc;
269 252
270 /* 253 /*
271 In this loop, we scan the CIS for configuration table entries, 254 In this loop, we scan the CIS for configuration table entries,
@@ -280,12 +263,12 @@ static void sedlbauer_config(dev_link_t *link)
280 will only use the CIS to fill in implementation-defined details. 263 will only use the CIS to fill in implementation-defined details.
281 */ 264 */
282 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 265 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
283 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 266 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
284 while (1) { 267 while (1) {
285 cistpl_cftable_entry_t dflt = { 0 }; 268 cistpl_cftable_entry_t dflt = { 0 };
286 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 269 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
287 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 270 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
288 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 271 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
289 goto next_entry; 272 goto next_entry;
290 273
291 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 274 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -309,10 +292,10 @@ static void sedlbauer_config(dev_link_t *link)
309 } 292 }
310 293
311 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 294 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
312 link->conf.Vpp1 = link->conf.Vpp2 = 295 link->conf.Vpp =
313 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 296 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
314 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 297 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
315 link->conf.Vpp1 = link->conf.Vpp2 = 298 link->conf.Vpp =
316 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 299 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
317 300
318 /* Do we need to allocate an interrupt? */ 301 /* Do we need to allocate an interrupt? */
@@ -339,13 +322,13 @@ static void sedlbauer_config(dev_link_t *link)
339 link->io.NumPorts2 = io->win[1].len; 322 link->io.NumPorts2 = io->win[1].len;
340 } 323 }
341 /* This reserves IO space but doesn't actually enable it */ 324 /* This reserves IO space but doesn't actually enable it */
342 if (pcmcia_request_io(link->handle, &link->io) != 0) 325 if (pcmcia_request_io(link, &link->io) != 0)
343 goto next_entry; 326 goto next_entry;
344 } 327 }
345 328
346 /* 329 /*
347 Now set up a common memory window, if needed. There is room 330 Now set up a common memory window, if needed. There is room
348 in the dev_link_t structure for one memory window handle, 331 in the struct pcmcia_device structure for one memory window handle,
349 but if the base addresses need to be saved, or if multiple 332 but if the base addresses need to be saved, or if multiple
350 windows are needed, the info should go in the private data 333 windows are needed, the info should go in the private data
351 structure for this device. 334 structure for this device.
@@ -366,7 +349,7 @@ static void sedlbauer_config(dev_link_t *link)
366 req.Size = 0x1000; 349 req.Size = 0x1000;
367*/ 350*/
368 req.AccessSpeed = 0; 351 req.AccessSpeed = 0;
369 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 352 if (pcmcia_request_window(&link, &req, &link->win) != 0)
370 goto next_entry; 353 goto next_entry;
371 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 354 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
372 if (pcmcia_map_mem_page(link->win, &map) != 0) 355 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -374,29 +357,25 @@ static void sedlbauer_config(dev_link_t *link)
374 } 357 }
375 /* If we got this far, we're cool! */ 358 /* If we got this far, we're cool! */
376 break; 359 break;
377 360
378 next_entry: 361 next_entry:
379/* new in dummy.cs 2001/01/28 MN 362 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
380 if (link->io.NumPorts1)
381 pcmcia_release_io(link->handle, &link->io);
382*/
383 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
384 } 363 }
385 364
386 /* 365 /*
387 Allocate an interrupt line. Note that this does not assign a 366 Allocate an interrupt line. Note that this does not assign a
388 handler to the interrupt, unless the 'Handler' member of the 367 handler to the interrupt, unless the 'Handler' member of the
389 irq structure is initialized. 368 irq structure is initialized.
390 */ 369 */
391 if (link->conf.Attributes & CONF_ENABLE_IRQ) 370 if (link->conf.Attributes & CONF_ENABLE_IRQ)
392 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 371 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
393 372
394 /* 373 /*
395 This actually configures the PCMCIA socket -- setting up 374 This actually configures the PCMCIA socket -- setting up
396 the I/O windows and the interrupt mapping, and putting the 375 the I/O windows and the interrupt mapping, and putting the
397 card and host interface into "Memory and IO" mode. 376 card and host interface into "Memory and IO" mode.
398 */ 377 */
399 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 378 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
400 379
401 /* 380 /*
402 At this point, the dev_node_t structure(s) need to be 381 At this point, the dev_node_t structure(s) need to be
@@ -404,14 +383,13 @@ static void sedlbauer_config(dev_link_t *link)
404 */ 383 */
405 sprintf(dev->node.dev_name, "sedlbauer"); 384 sprintf(dev->node.dev_name, "sedlbauer");
406 dev->node.major = dev->node.minor = 0; 385 dev->node.major = dev->node.minor = 0;
407 link->dev = &dev->node; 386 link->dev_node = &dev->node;
408 387
409 /* Finally, report what we've done */ 388 /* Finally, report what we've done */
410 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 389 printk(KERN_INFO "%s: index 0x%02x:",
411 dev->node.dev_name, link->conf.ConfigIndex, 390 dev->node.dev_name, link->conf.ConfigIndex);
412 link->conf.Vcc/10, link->conf.Vcc%10); 391 if (link->conf.Vpp)
413 if (link->conf.Vpp1) 392 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
414 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
415 if (link->conf.Attributes & CONF_ENABLE_IRQ) 393 if (link->conf.Attributes & CONF_ENABLE_IRQ)
416 printk(", irq %d", link->irq.AssignedIRQ); 394 printk(", irq %d", link->irq.AssignedIRQ);
417 if (link->io.NumPorts1) 395 if (link->io.NumPorts1)
@@ -424,8 +402,6 @@ static void sedlbauer_config(dev_link_t *link)
424 printk(", mem 0x%06lx-0x%06lx", req.Base, 402 printk(", mem 0x%06lx-0x%06lx", req.Base,
425 req.Base+req.Size-1); 403 req.Base+req.Size-1);
426 printk("\n"); 404 printk("\n");
427
428 link->state &= ~DEV_CONFIG_PENDING;
429 405
430 icard.para[0] = link->irq.AssignedIRQ; 406 icard.para[0] = link->irq.AssignedIRQ;
431 icard.para[1] = link->io.BasePort1; 407 icard.para[1] = link->io.BasePort1;
@@ -437,14 +413,16 @@ static void sedlbauer_config(dev_link_t *link)
437 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n", 413 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
438 last_ret, link->io.BasePort1); 414 last_ret, link->io.BasePort1);
439 sedlbauer_release(link); 415 sedlbauer_release(link);
416 return -ENODEV;
440 } else 417 } else
441 ((local_info_t*)link->priv)->cardnr = last_ret; 418 ((local_info_t*)link->priv)->cardnr = last_ret;
442 419
443 return; 420 return 0;
444 421
445cs_failed: 422cs_failed:
446 cs_error(link->handle, last_fn, last_ret); 423 cs_error(link, last_fn, last_ret);
447 sedlbauer_release(link); 424 sedlbauer_release(link);
425 return -ENODEV;
448 426
449} /* sedlbauer_config */ 427} /* sedlbauer_config */
450 428
@@ -456,7 +434,7 @@ cs_failed:
456 434
457======================================================================*/ 435======================================================================*/
458 436
459static void sedlbauer_release(dev_link_t *link) 437static void sedlbauer_release(struct pcmcia_device *link)
460{ 438{
461 local_info_t *local = link->priv; 439 local_info_t *local = link->priv;
462 DEBUG(0, "sedlbauer_release(0x%p)\n", link); 440 DEBUG(0, "sedlbauer_release(0x%p)\n", link);
@@ -467,46 +445,23 @@ static void sedlbauer_release(dev_link_t *link)
467 HiSax_closecard(local->cardnr); 445 HiSax_closecard(local->cardnr);
468 } 446 }
469 } 447 }
470 /* Unlink the device chain */
471 link->dev = NULL;
472 448
473 /* 449 pcmcia_disable_device(link);
474 In a normal driver, additional code may be needed to release
475 other kernel data structures associated with this device.
476 */
477
478 /* Don't bother checking to see if these succeed or not */
479 if (link->win)
480 pcmcia_release_window(link->win);
481 pcmcia_release_configuration(link->handle);
482 if (link->io.NumPorts1)
483 pcmcia_release_io(link->handle, &link->io);
484 if (link->irq.AssignedIRQ)
485 pcmcia_release_irq(link->handle, &link->irq);
486 link->state &= ~DEV_CONFIG;
487} /* sedlbauer_release */ 450} /* sedlbauer_release */
488 451
489static int sedlbauer_suspend(struct pcmcia_device *p_dev) 452static int sedlbauer_suspend(struct pcmcia_device *link)
490{ 453{
491 dev_link_t *link = dev_to_instance(p_dev);
492 local_info_t *dev = link->priv; 454 local_info_t *dev = link->priv;
493 455
494 link->state |= DEV_SUSPEND;
495 dev->stop = 1; 456 dev->stop = 1;
496 if (link->state & DEV_CONFIG)
497 pcmcia_release_configuration(link->handle);
498 457
499 return 0; 458 return 0;
500} 459}
501 460
502static int sedlbauer_resume(struct pcmcia_device *p_dev) 461static int sedlbauer_resume(struct pcmcia_device *link)
503{ 462{
504 dev_link_t *link = dev_to_instance(p_dev);
505 local_info_t *dev = link->priv; 463 local_info_t *dev = link->priv;
506 464
507 link->state &= ~DEV_SUSPEND;
508 if (link->state & DEV_CONFIG)
509 pcmcia_request_configuration(link->handle, &link->conf);
510 dev->stop = 0; 465 dev->stop = 0;
511 466
512 return 0; 467 return 0;
@@ -530,7 +485,7 @@ static struct pcmcia_driver sedlbauer_driver = {
530 .drv = { 485 .drv = {
531 .name = "sedlbauer_cs", 486 .name = "sedlbauer_cs",
532 }, 487 },
533 .probe = sedlbauer_attach, 488 .probe = sedlbauer_probe,
534 .remove = sedlbauer_detach, 489 .remove = sedlbauer_detach,
535 .id_table = sedlbauer_ids, 490 .id_table = sedlbauer_ids,
536 .suspend = sedlbauer_suspend, 491 .suspend = sedlbauer_suspend,
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 4e5c14c7240e..afcc2aeadb34 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -75,8 +75,8 @@ module_param(protocol, int, 0);
75 handler. 75 handler.
76*/ 76*/
77 77
78static void teles_cs_config(dev_link_t *link); 78static int teles_cs_config(struct pcmcia_device *link);
79static void teles_cs_release(dev_link_t *link); 79static void teles_cs_release(struct pcmcia_device *link);
80 80
81/* 81/*
82 The attach() and detach() entry points are used to create and destroy 82 The attach() and detach() entry points are used to create and destroy
@@ -89,10 +89,10 @@ static void teles_detach(struct pcmcia_device *p_dev);
89/* 89/*
90 A linked list of "instances" of the teles_cs device. Each actual 90 A linked list of "instances" of the teles_cs device. Each actual
91 PCMCIA card corresponds to one device instance, and is described 91 PCMCIA card corresponds to one device instance, and is described
92 by one dev_link_t structure (defined in ds.h). 92 by one struct pcmcia_device structure (defined in ds.h).
93 93
94 You may not want to use a linked list for this -- for example, the 94 You may not want to use a linked list for this -- for example, the
95 memory card driver uses an array of dev_link_t pointers, where minor 95 memory card driver uses an array of struct pcmcia_device pointers, where minor
96 device numbers are used to derive the corresponding array index. 96 device numbers are used to derive the corresponding array index.
97*/ 97*/
98 98
@@ -102,7 +102,7 @@ static void teles_detach(struct pcmcia_device *p_dev);
102 example, ethernet cards, modems). In other cases, there may be 102 example, ethernet cards, modems). In other cases, there may be
103 many actual or logical devices (SCSI adapters, memory cards with 103 many actual or logical devices (SCSI adapters, memory cards with
104 multiple partitions). The dev_node_t structures need to be kept 104 multiple partitions). The dev_node_t structures need to be kept
105 in a linked list starting at the 'dev' field of a dev_link_t 105 in a linked list starting at the 'dev' field of a struct pcmcia_device
106 structure. We allocate them in the card's private data structure, 106 structure. We allocate them in the card's private data structure,
107 because they generally shouldn't be allocated dynamically. 107 because they generally shouldn't be allocated dynamically.
108 In this case, we also provide a flag to indicate if a device is 108 In this case, we also provide a flag to indicate if a device is
@@ -112,7 +112,7 @@ static void teles_detach(struct pcmcia_device *p_dev);
112*/ 112*/
113 113
114typedef struct local_info_t { 114typedef struct local_info_t {
115 dev_link_t link; 115 struct pcmcia_device *p_dev;
116 dev_node_t node; 116 dev_node_t node;
117 int busy; 117 int busy;
118 int cardnr; 118 int cardnr;
@@ -130,9 +130,8 @@ typedef struct local_info_t {
130 130
131======================================================================*/ 131======================================================================*/
132 132
133static int teles_attach(struct pcmcia_device *p_dev) 133static int teles_probe(struct pcmcia_device *link)
134{ 134{
135 dev_link_t *link;
136 local_info_t *local; 135 local_info_t *local;
137 136
138 DEBUG(0, "teles_attach()\n"); 137 DEBUG(0, "teles_attach()\n");
@@ -142,7 +141,9 @@ static int teles_attach(struct pcmcia_device *p_dev)
142 if (!local) return -ENOMEM; 141 if (!local) return -ENOMEM;
143 memset(local, 0, sizeof(local_info_t)); 142 memset(local, 0, sizeof(local_info_t));
144 local->cardnr = -1; 143 local->cardnr = -1;
145 link = &local->link; link->priv = local; 144
145 local->p_dev = link;
146 link->priv = local;
146 147
147 /* Interrupt setup */ 148 /* Interrupt setup */
148 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 149 link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
@@ -161,16 +162,9 @@ static int teles_attach(struct pcmcia_device *p_dev)
161 link->io.IOAddrLines = 5; 162 link->io.IOAddrLines = 5;
162 163
163 link->conf.Attributes = CONF_ENABLE_IRQ; 164 link->conf.Attributes = CONF_ENABLE_IRQ;
164 link->conf.Vcc = 50;
165 link->conf.IntType = INT_MEMORY_AND_IO; 165 link->conf.IntType = INT_MEMORY_AND_IO;
166 166
167 link->handle = p_dev; 167 return teles_cs_config(link);
168 p_dev->instance = link;
169
170 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
171 teles_cs_config(link);
172
173 return 0;
174} /* teles_attach */ 168} /* teles_attach */
175 169
176/*====================================================================== 170/*======================================================================
@@ -182,20 +176,16 @@ static int teles_attach(struct pcmcia_device *p_dev)
182 176
183======================================================================*/ 177======================================================================*/
184 178
185static void teles_detach(struct pcmcia_device *p_dev) 179static void teles_detach(struct pcmcia_device *link)
186{ 180{
187 dev_link_t *link = dev_to_instance(p_dev); 181 local_info_t *info = link->priv;
188 local_info_t *info = link->priv;
189
190 DEBUG(0, "teles_detach(0x%p)\n", link);
191 182
192 if (link->state & DEV_CONFIG) { 183 DEBUG(0, "teles_detach(0x%p)\n", link);
193 info->busy = 1;
194 teles_cs_release(link);
195 }
196 184
197 kfree(info); 185 info->busy = 1;
186 teles_cs_release(link);
198 187
188 kfree(info);
199} /* teles_detach */ 189} /* teles_detach */
200 190
201/*====================================================================== 191/*======================================================================
@@ -205,7 +195,7 @@ static void teles_detach(struct pcmcia_device *p_dev)
205 device available to the system. 195 device available to the system.
206 196
207======================================================================*/ 197======================================================================*/
208static int get_tuple(client_handle_t handle, tuple_t *tuple, 198static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
209 cisparse_t *parse) 199 cisparse_t *parse)
210{ 200{
211 int i = pcmcia_get_tuple_data(handle, tuple); 201 int i = pcmcia_get_tuple_data(handle, tuple);
@@ -213,7 +203,7 @@ static int get_tuple(client_handle_t handle, tuple_t *tuple,
213 return pcmcia_parse_tuple(handle, tuple, parse); 203 return pcmcia_parse_tuple(handle, tuple, parse);
214} 204}
215 205
216static int first_tuple(client_handle_t handle, tuple_t *tuple, 206static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
217 cisparse_t *parse) 207 cisparse_t *parse)
218{ 208{
219 int i = pcmcia_get_first_tuple(handle, tuple); 209 int i = pcmcia_get_first_tuple(handle, tuple);
@@ -221,7 +211,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
221 return get_tuple(handle, tuple, parse); 211 return get_tuple(handle, tuple, parse);
222} 212}
223 213
224static int next_tuple(client_handle_t handle, tuple_t *tuple, 214static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
225 cisparse_t *parse) 215 cisparse_t *parse)
226{ 216{
227 int i = pcmcia_get_next_tuple(handle, tuple); 217 int i = pcmcia_get_next_tuple(handle, tuple);
@@ -229,9 +219,8 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
229 return get_tuple(handle, tuple, parse); 219 return get_tuple(handle, tuple, parse);
230} 220}
231 221
232static void teles_cs_config(dev_link_t *link) 222static int teles_cs_config(struct pcmcia_device *link)
233{ 223{
234 client_handle_t handle;
235 tuple_t tuple; 224 tuple_t tuple;
236 cisparse_t parse; 225 cisparse_t parse;
237 local_info_t *dev; 226 local_info_t *dev;
@@ -241,7 +230,6 @@ static void teles_cs_config(dev_link_t *link)
241 IsdnCard_t icard; 230 IsdnCard_t icard;
242 231
243 DEBUG(0, "teles_config(0x%p)\n", link); 232 DEBUG(0, "teles_config(0x%p)\n", link);
244 handle = link->handle;
245 dev = link->priv; 233 dev = link->priv;
246 234
247 /* 235 /*
@@ -253,7 +241,7 @@ static void teles_cs_config(dev_link_t *link)
253 tuple.TupleDataMax = 255; 241 tuple.TupleDataMax = 255;
254 tuple.TupleOffset = 0; 242 tuple.TupleOffset = 0;
255 tuple.Attributes = 0; 243 tuple.Attributes = 0;
256 i = first_tuple(handle, &tuple, &parse); 244 i = first_tuple(link, &tuple, &parse);
257 if (i != CS_SUCCESS) { 245 if (i != CS_SUCCESS) {
258 last_fn = ParseTuple; 246 last_fn = ParseTuple;
259 goto cs_failed; 247 goto cs_failed;
@@ -261,32 +249,29 @@ static void teles_cs_config(dev_link_t *link)
261 link->conf.ConfigBase = parse.config.base; 249 link->conf.ConfigBase = parse.config.base;
262 link->conf.Present = parse.config.rmask[0]; 250 link->conf.Present = parse.config.rmask[0];
263 251
264 /* Configure card */
265 link->state |= DEV_CONFIG;
266
267 tuple.TupleData = (cisdata_t *)buf; 252 tuple.TupleData = (cisdata_t *)buf;
268 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 253 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
269 tuple.Attributes = 0; 254 tuple.Attributes = 0;
270 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 255 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
271 i = first_tuple(handle, &tuple, &parse); 256 i = first_tuple(link, &tuple, &parse);
272 while (i == CS_SUCCESS) { 257 while (i == CS_SUCCESS) {
273 if ( (cf->io.nwin > 0) && cf->io.win[0].base) { 258 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
274 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n"); 259 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
275 link->conf.ConfigIndex = cf->index; 260 link->conf.ConfigIndex = cf->index;
276 link->io.BasePort1 = cf->io.win[0].base; 261 link->io.BasePort1 = cf->io.win[0].base;
277 i = pcmcia_request_io(link->handle, &link->io); 262 i = pcmcia_request_io(link, &link->io);
278 if (i == CS_SUCCESS) break; 263 if (i == CS_SUCCESS) break;
279 } else { 264 } else {
280 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n"); 265 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
281 link->conf.ConfigIndex = cf->index; 266 link->conf.ConfigIndex = cf->index;
282 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) { 267 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
283 link->io.BasePort1 = j; 268 link->io.BasePort1 = j;
284 i = pcmcia_request_io(link->handle, &link->io); 269 i = pcmcia_request_io(link, &link->io);
285 if (i == CS_SUCCESS) break; 270 if (i == CS_SUCCESS) break;
286 } 271 }
287 break; 272 break;
288 } 273 }
289 i = next_tuple(handle, &tuple, &parse); 274 i = next_tuple(link, &tuple, &parse);
290 } 275 }
291 276
292 if (i != CS_SUCCESS) { 277 if (i != CS_SUCCESS) {
@@ -294,14 +279,14 @@ static void teles_cs_config(dev_link_t *link)
294 goto cs_failed; 279 goto cs_failed;
295 } 280 }
296 281
297 i = pcmcia_request_irq(link->handle, &link->irq); 282 i = pcmcia_request_irq(link, &link->irq);
298 if (i != CS_SUCCESS) { 283 if (i != CS_SUCCESS) {
299 link->irq.AssignedIRQ = 0; 284 link->irq.AssignedIRQ = 0;
300 last_fn = RequestIRQ; 285 last_fn = RequestIRQ;
301 goto cs_failed; 286 goto cs_failed;
302 } 287 }
303 288
304 i = pcmcia_request_configuration(link->handle, &link->conf); 289 i = pcmcia_request_configuration(link, &link->conf);
305 if (i != CS_SUCCESS) { 290 if (i != CS_SUCCESS) {
306 last_fn = RequestConfiguration; 291 last_fn = RequestConfiguration;
307 goto cs_failed; 292 goto cs_failed;
@@ -312,14 +297,11 @@ static void teles_cs_config(dev_link_t *link)
312 sprintf(dev->node.dev_name, "teles"); 297 sprintf(dev->node.dev_name, "teles");
313 dev->node.major = dev->node.minor = 0x0; 298 dev->node.major = dev->node.minor = 0x0;
314 299
315 link->dev = &dev->node; 300 link->dev_node = &dev->node;
316 301
317 /* Finally, report what we've done */ 302 /* Finally, report what we've done */
318 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 303 printk(KERN_INFO "%s: index 0x%02x:",
319 dev->node.dev_name, link->conf.ConfigIndex, 304 dev->node.dev_name, link->conf.ConfigIndex);
320 link->conf.Vcc/10, link->conf.Vcc%10);
321 if (link->conf.Vpp1)
322 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
323 if (link->conf.Attributes & CONF_ENABLE_IRQ) 305 if (link->conf.Attributes & CONF_ENABLE_IRQ)
324 printk(", irq %d", link->irq.AssignedIRQ); 306 printk(", irq %d", link->irq.AssignedIRQ);
325 if (link->io.NumPorts1) 307 if (link->io.NumPorts1)
@@ -330,8 +312,6 @@ static void teles_cs_config(dev_link_t *link)
330 link->io.BasePort2+link->io.NumPorts2-1); 312 link->io.BasePort2+link->io.NumPorts2-1);
331 printk("\n"); 313 printk("\n");
332 314
333 link->state &= ~DEV_CONFIG_PENDING;
334
335 icard.para[0] = link->irq.AssignedIRQ; 315 icard.para[0] = link->irq.AssignedIRQ;
336 icard.para[1] = link->io.BasePort1; 316 icard.para[1] = link->io.BasePort1;
337 icard.protocol = protocol; 317 icard.protocol = protocol;
@@ -342,13 +322,16 @@ static void teles_cs_config(dev_link_t *link)
342 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n", 322 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
343 i, link->io.BasePort1); 323 i, link->io.BasePort1);
344 teles_cs_release(link); 324 teles_cs_release(link);
345 } else 325 return -ENODEV;
346 ((local_info_t*)link->priv)->cardnr = i; 326 }
327
328 ((local_info_t*)link->priv)->cardnr = i;
329 return 0;
347 330
348 return;
349cs_failed: 331cs_failed:
350 cs_error(link->handle, last_fn, i); 332 cs_error(link, last_fn, i);
351 teles_cs_release(link); 333 teles_cs_release(link);
334 return -ENODEV;
352} /* teles_cs_config */ 335} /* teles_cs_config */
353 336
354/*====================================================================== 337/*======================================================================
@@ -359,7 +342,7 @@ cs_failed:
359 342
360======================================================================*/ 343======================================================================*/
361 344
362static void teles_cs_release(dev_link_t *link) 345static void teles_cs_release(struct pcmcia_device *link)
363{ 346{
364 local_info_t *local = link->priv; 347 local_info_t *local = link->priv;
365 348
@@ -371,39 +354,23 @@ static void teles_cs_release(dev_link_t *link)
371 HiSax_closecard(local->cardnr); 354 HiSax_closecard(local->cardnr);
372 } 355 }
373 } 356 }
374 /* Unlink the device chain */ 357
375 link->dev = NULL; 358 pcmcia_disable_device(link);
376
377 /* Don't bother checking to see if these succeed or not */
378 if (link->win)
379 pcmcia_release_window(link->win);
380 pcmcia_release_configuration(link->handle);
381 pcmcia_release_io(link->handle, &link->io);
382 pcmcia_release_irq(link->handle, &link->irq);
383 link->state &= ~DEV_CONFIG;
384} /* teles_cs_release */ 359} /* teles_cs_release */
385 360
386static int teles_suspend(struct pcmcia_device *p_dev) 361static int teles_suspend(struct pcmcia_device *link)
387{ 362{
388 dev_link_t *link = dev_to_instance(p_dev);
389 local_info_t *dev = link->priv; 363 local_info_t *dev = link->priv;
390 364
391 link->state |= DEV_SUSPEND;
392 dev->busy = 1; 365 dev->busy = 1;
393 if (link->state & DEV_CONFIG)
394 pcmcia_release_configuration(link->handle);
395 366
396 return 0; 367 return 0;
397} 368}
398 369
399static int teles_resume(struct pcmcia_device *p_dev) 370static int teles_resume(struct pcmcia_device *link)
400{ 371{
401 dev_link_t *link = dev_to_instance(p_dev);
402 local_info_t *dev = link->priv; 372 local_info_t *dev = link->priv;
403 373
404 link->state &= ~DEV_SUSPEND;
405 if (link->state & DEV_CONFIG)
406 pcmcia_request_configuration(link->handle, &link->conf);
407 dev->busy = 0; 374 dev->busy = 0;
408 375
409 return 0; 376 return 0;
@@ -421,7 +388,7 @@ static struct pcmcia_driver teles_cs_driver = {
421 .drv = { 388 .drv = {
422 .name = "teles_cs", 389 .name = "teles_cs",
423 }, 390 },
424 .probe = teles_attach, 391 .probe = teles_probe,
425 .remove = teles_detach, 392 .remove = teles_detach,
426 .id_table = teles_ids, 393 .id_table = teles_ids,
427 .suspend = teles_suspend, 394 .suspend = teles_suspend,
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index a0927d1b7a0c..918742271c79 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -109,7 +109,7 @@ isdn_ppp_free(isdn_net_local * lp)
109{ 109{
110 struct ippp_struct *is; 110 struct ippp_struct *is;
111 111
112 if (lp->ppp_slot < 0 || lp->ppp_slot > ISDN_MAX_CHANNELS) { 112 if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
113 printk(KERN_ERR "%s: ppp_slot(%d) out of range\n", 113 printk(KERN_ERR "%s: ppp_slot(%d) out of range\n",
114 __FUNCTION__, lp->ppp_slot); 114 __FUNCTION__, lp->ppp_slot);
115 return 0; 115 return 0;
@@ -126,7 +126,7 @@ isdn_ppp_free(isdn_net_local * lp)
126 lp->netdev->pb->ref_ct--; 126 lp->netdev->pb->ref_ct--;
127 spin_unlock(&lp->netdev->pb->lock); 127 spin_unlock(&lp->netdev->pb->lock);
128#endif /* CONFIG_ISDN_MPP */ 128#endif /* CONFIG_ISDN_MPP */
129 if (lp->ppp_slot < 0 || lp->ppp_slot > ISDN_MAX_CHANNELS) { 129 if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
130 printk(KERN_ERR "%s: ppp_slot(%d) now invalid\n", 130 printk(KERN_ERR "%s: ppp_slot(%d) now invalid\n",
131 __FUNCTION__, lp->ppp_slot); 131 __FUNCTION__, lp->ppp_slot);
132 return 0; 132 return 0;
@@ -279,7 +279,7 @@ isdn_ppp_open(int min, struct file *file)
279 int slot; 279 int slot;
280 struct ippp_struct *is; 280 struct ippp_struct *is;
281 281
282 if (min < 0 || min > ISDN_MAX_CHANNELS) 282 if (min < 0 || min >= ISDN_MAX_CHANNELS)
283 return -ENODEV; 283 return -ENODEV;
284 284
285 slot = isdn_ppp_get_slot(); 285 slot = isdn_ppp_get_slot();
@@ -1042,7 +1042,7 @@ isdn_ppp_push_higher(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buff
1042 if (lp->master) { // FIXME? 1042 if (lp->master) { // FIXME?
1043 mlp = (isdn_net_local *) lp->master->priv; 1043 mlp = (isdn_net_local *) lp->master->priv;
1044 slot = mlp->ppp_slot; 1044 slot = mlp->ppp_slot;
1045 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1045 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1046 printk(KERN_ERR "isdn_ppp_push_higher: master->ppp_slot(%d)\n", 1046 printk(KERN_ERR "isdn_ppp_push_higher: master->ppp_slot(%d)\n",
1047 lp->ppp_slot); 1047 lp->ppp_slot);
1048 goto drop_packet; 1048 goto drop_packet;
@@ -1264,7 +1264,7 @@ isdn_ppp_xmit(struct sk_buff *skb, struct net_device *netdev)
1264 /* we have our lp locked from now on */ 1264 /* we have our lp locked from now on */
1265 1265
1266 slot = lp->ppp_slot; 1266 slot = lp->ppp_slot;
1267 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1267 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1268 printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n", 1268 printk(KERN_ERR "isdn_ppp_xmit: lp->ppp_slot(%d)\n",
1269 lp->ppp_slot); 1269 lp->ppp_slot);
1270 kfree_skb(skb); 1270 kfree_skb(skb);
@@ -1603,7 +1603,7 @@ static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
1603 mp = net_dev->pb; 1603 mp = net_dev->pb;
1604 stats = &mp->stats; 1604 stats = &mp->stats;
1605 slot = lp->ppp_slot; 1605 slot = lp->ppp_slot;
1606 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1606 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1607 printk(KERN_ERR "%s: lp->ppp_slot(%d)\n", 1607 printk(KERN_ERR "%s: lp->ppp_slot(%d)\n",
1608 __FUNCTION__, lp->ppp_slot); 1608 __FUNCTION__, lp->ppp_slot);
1609 stats->frame_drops++; 1609 stats->frame_drops++;
@@ -1640,7 +1640,7 @@ static void isdn_ppp_mp_receive(isdn_net_dev * net_dev, isdn_net_local * lp,
1640 is->last_link_seqno = minseq = newseq; 1640 is->last_link_seqno = minseq = newseq;
1641 for (lpq = net_dev->queue;;) { 1641 for (lpq = net_dev->queue;;) {
1642 slot = lpq->ppp_slot; 1642 slot = lpq->ppp_slot;
1643 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 1643 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
1644 printk(KERN_ERR "%s: lpq->ppp_slot(%d)\n", 1644 printk(KERN_ERR "%s: lpq->ppp_slot(%d)\n",
1645 __FUNCTION__, lpq->ppp_slot); 1645 __FUNCTION__, lpq->ppp_slot);
1646 } else { 1646 } else {
@@ -2648,7 +2648,7 @@ static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
2648 2648
2649 printk(KERN_DEBUG "Received CCP frame from peer slot(%d)\n", 2649 printk(KERN_DEBUG "Received CCP frame from peer slot(%d)\n",
2650 lp->ppp_slot); 2650 lp->ppp_slot);
2651 if (lp->ppp_slot < 0 || lp->ppp_slot > ISDN_MAX_CHANNELS) { 2651 if (lp->ppp_slot < 0 || lp->ppp_slot >= ISDN_MAX_CHANNELS) {
2652 printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n", 2652 printk(KERN_ERR "%s: lp->ppp_slot(%d) out of range\n",
2653 __FUNCTION__, lp->ppp_slot); 2653 __FUNCTION__, lp->ppp_slot);
2654 return; 2654 return;
@@ -2658,7 +2658,7 @@ static void isdn_ppp_receive_ccp(isdn_net_dev *net_dev, isdn_net_local *lp,
2658 2658
2659 if(lp->master) { 2659 if(lp->master) {
2660 int slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot; 2660 int slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot;
2661 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 2661 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
2662 printk(KERN_ERR "%s: slot(%d) out of range\n", 2662 printk(KERN_ERR "%s: slot(%d) out of range\n",
2663 __FUNCTION__, slot); 2663 __FUNCTION__, slot);
2664 return; 2664 return;
@@ -2845,7 +2845,7 @@ static void isdn_ppp_send_ccp(isdn_net_dev *net_dev, isdn_net_local *lp, struct
2845 2845
2846 if (lp->master) { 2846 if (lp->master) {
2847 slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot; 2847 slot = ((isdn_net_local *) (lp->master->priv))->ppp_slot;
2848 if (slot < 0 || slot > ISDN_MAX_CHANNELS) { 2848 if (slot < 0 || slot >= ISDN_MAX_CHANNELS) {
2849 printk(KERN_ERR "%s: slot(%d) out of range\n", 2849 printk(KERN_ERR "%s: slot(%d) out of range\n",
2850 __FUNCTION__, slot); 2850 __FUNCTION__, slot);
2851 return; 2851 return;
diff --git a/drivers/isdn/sc/ioctl.c b/drivers/isdn/sc/ioctl.c
index 94c9afb7017c..f4f71226a078 100644
--- a/drivers/isdn/sc/ioctl.c
+++ b/drivers/isdn/sc/ioctl.c
@@ -46,7 +46,8 @@ int sc_ioctl(int card, scs_ioctl *data)
46 pr_debug("%s: SCIOCRESET: ioctl received\n", 46 pr_debug("%s: SCIOCRESET: ioctl received\n",
47 sc_adapter[card]->devicename); 47 sc_adapter[card]->devicename);
48 sc_adapter[card]->StartOnReset = 0; 48 sc_adapter[card]->StartOnReset = 0;
49 return (reset(card)); 49 kfree(rcvmsg);
50 return reset(card);
50 } 51 }
51 52
52 case SCIOCLOAD: 53 case SCIOCLOAD:
@@ -183,7 +184,7 @@ int sc_ioctl(int card, scs_ioctl *data)
183 sc_adapter[card]->devicename); 184 sc_adapter[card]->devicename);
184 185
185 spid = kmalloc(SCIOC_SPIDSIZE, GFP_KERNEL); 186 spid = kmalloc(SCIOC_SPIDSIZE, GFP_KERNEL);
186 if(!spid) { 187 if (!spid) {
187 kfree(rcvmsg); 188 kfree(rcvmsg);
188 return -ENOMEM; 189 return -ENOMEM;
189 } 190 }
@@ -195,10 +196,10 @@ int sc_ioctl(int card, scs_ioctl *data)
195 if (!status) { 196 if (!status) {
196 pr_debug("%s: SCIOCGETSPID: command successful\n", 197 pr_debug("%s: SCIOCGETSPID: command successful\n",
197 sc_adapter[card]->devicename); 198 sc_adapter[card]->devicename);
198 } 199 } else {
199 else {
200 pr_debug("%s: SCIOCGETSPID: command failed (status = %d)\n", 200 pr_debug("%s: SCIOCGETSPID: command failed (status = %d)\n",
201 sc_adapter[card]->devicename, status); 201 sc_adapter[card]->devicename, status);
202 kfree(spid);
202 kfree(rcvmsg); 203 kfree(rcvmsg);
203 return status; 204 return status;
204 } 205 }
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
new file mode 100644
index 000000000000..3f5b64794542
--- /dev/null
+++ b/drivers/leds/Kconfig
@@ -0,0 +1,88 @@
1
2menu "LED devices"
3
4config NEW_LEDS
5 bool "LED Support"
6 help
7 Say Y to enable Linux LED support. This is not related to standard
8 keyboard LEDs which are controlled via the input system.
9
10config LEDS_CLASS
11 tristate "LED Class Support"
12 depends NEW_LEDS
13 help
14 This option enables the led sysfs class in /sys/class/leds. You'll
15 need this to do anything useful with LEDs. If unsure, say N.
16
17comment "LED drivers"
18
19config LEDS_CORGI
20 tristate "LED Support for the Sharp SL-C7x0 series"
21 depends LEDS_CLASS && PXA_SHARP_C7xx
22 help
23 This option enables support for the LEDs on Sharp Zaurus
24 SL-C7x0 series (C700, C750, C760, C860).
25
26config LEDS_LOCOMO
27 tristate "LED Support for Locomo device"
28 depends LEDS_CLASS && SHARP_LOCOMO
29 help
30 This option enables support for the LEDs on Sharp Locomo.
31 Zaurus models SL-5500 and SL-5600.
32
33config LEDS_SPITZ
34 tristate "LED Support for the Sharp SL-Cxx00 series"
35 depends LEDS_CLASS && PXA_SHARP_Cxx00
36 help
37 This option enables support for the LEDs on Sharp Zaurus
38 SL-Cxx00 series (C1000, C3000, C3100).
39
40config LEDS_IXP4XX
41 tristate "LED Support for GPIO connected LEDs on IXP4XX processors"
42 depends LEDS_CLASS && ARCH_IXP4XX
43 help
44 This option enables support for the LEDs connected to GPIO
45 outputs of the Intel IXP4XX processors. To be useful the
46 particular board must have LEDs and they must be connected
47 to the GPIO lines. If unsure, say Y.
48
49config LEDS_TOSA
50 tristate "LED Support for the Sharp SL-6000 series"
51 depends LEDS_CLASS && PXA_SHARPSL
52 help
53 This option enables support for the LEDs on Sharp Zaurus
54 SL-6000 series.
55
56config LEDS_S3C24XX
57 tristate "LED Support for Samsung S3C24XX GPIO LEDs"
58 depends on LEDS_CLASS && ARCH_S3C2410
59 help
60 This option enables support for LEDs connected to GPIO lines
61 on Samsung S3C24XX series CPUs, such as the S3C2410 and S3C2440.
62
63comment "LED Triggers"
64
65config LEDS_TRIGGERS
66 bool "LED Trigger support"
67 depends NEW_LEDS
68 help
69 This option enables trigger support for the leds class.
70 These triggers allow kernel events to drive the LEDs and can
71 be configured via sysfs. If unsure, say Y.
72
73config LEDS_TRIGGER_TIMER
74 tristate "LED Timer Trigger"
75 depends LEDS_TRIGGERS
76 help
77 This allows LEDs to be controlled by a programmable timer
78 via sysfs. If unsure, say Y.
79
80config LEDS_TRIGGER_IDE_DISK
81 bool "LED IDE Disk Trigger"
82 depends LEDS_TRIGGERS && BLK_DEV_IDEDISK
83 help
84 This allows LEDs to be controlled by IDE disk activity.
85 If unsure, say Y.
86
87endmenu
88
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
new file mode 100644
index 000000000000..40f042633bf5
--- /dev/null
+++ b/drivers/leds/Makefile
@@ -0,0 +1,17 @@
1
2# LED Core
3obj-$(CONFIG_NEW_LEDS) += led-core.o
4obj-$(CONFIG_LEDS_CLASS) += led-class.o
5obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o
6
7# LED Platform Drivers
8obj-$(CONFIG_LEDS_CORGI) += leds-corgi.o
9obj-$(CONFIG_LEDS_LOCOMO) += leds-locomo.o
10obj-$(CONFIG_LEDS_SPITZ) += leds-spitz.o
11obj-$(CONFIG_LEDS_IXP4XX) += leds-ixp4xx-gpio.o
12obj-$(CONFIG_LEDS_TOSA) += leds-tosa.o
13obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
14
15# LED Triggers
16obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
17obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
new file mode 100644
index 000000000000..b0b5d05fadd6
--- /dev/null
+++ b/drivers/leds/led-class.c
@@ -0,0 +1,167 @@
1/*
2 * LED Class Core
3 *
4 * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
5 * Copyright (C) 2005-2006 Richard Purdie <rpurdie@openedhand.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/config.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/list.h>
17#include <linux/spinlock.h>
18#include <linux/device.h>
19#include <linux/sysdev.h>
20#include <linux/timer.h>
21#include <linux/err.h>
22#include <linux/leds.h>
23#include "leds.h"
24
25static struct class *leds_class;
26
27static ssize_t led_brightness_show(struct class_device *dev, char *buf)
28{
29 struct led_classdev *led_cdev = class_get_devdata(dev);
30 ssize_t ret = 0;
31
32 /* no lock needed for this */
33 sprintf(buf, "%u\n", led_cdev->brightness);
34 ret = strlen(buf) + 1;
35
36 return ret;
37}
38
39static ssize_t led_brightness_store(struct class_device *dev,
40 const char *buf, size_t size)
41{
42 struct led_classdev *led_cdev = class_get_devdata(dev);
43 ssize_t ret = -EINVAL;
44 char *after;
45 unsigned long state = simple_strtoul(buf, &after, 10);
46
47 if (after - buf > 0) {
48 ret = after - buf;
49 led_set_brightness(led_cdev, state);
50 }
51
52 return ret;
53}
54
55static CLASS_DEVICE_ATTR(brightness, 0644, led_brightness_show,
56 led_brightness_store);
57#ifdef CONFIG_LEDS_TRIGGERS
58static CLASS_DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);
59#endif
60
61/**
62 * led_classdev_suspend - suspend an led_classdev.
63 * @led_cdev: the led_classdev to suspend.
64 */
65void led_classdev_suspend(struct led_classdev *led_cdev)
66{
67 led_cdev->flags |= LED_SUSPENDED;
68 led_cdev->brightness_set(led_cdev, 0);
69}
70EXPORT_SYMBOL_GPL(led_classdev_suspend);
71
72/**
73 * led_classdev_resume - resume an led_classdev.
74 * @led_cdev: the led_classdev to resume.
75 */
76void led_classdev_resume(struct led_classdev *led_cdev)
77{
78 led_cdev->brightness_set(led_cdev, led_cdev->brightness);
79 led_cdev->flags &= ~LED_SUSPENDED;
80}
81EXPORT_SYMBOL_GPL(led_classdev_resume);
82
83/**
84 * led_classdev_register - register a new object of led_classdev class.
85 * @dev: The device to register.
86 * @led_cdev: the led_classdev structure for this device.
87 */
88int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
89{
90 led_cdev->class_dev = class_device_create(leds_class, NULL, 0,
91 parent, "%s", led_cdev->name);
92 if (unlikely(IS_ERR(led_cdev->class_dev)))
93 return PTR_ERR(led_cdev->class_dev);
94
95 class_set_devdata(led_cdev->class_dev, led_cdev);
96
97 /* register the attributes */
98 class_device_create_file(led_cdev->class_dev,
99 &class_device_attr_brightness);
100
101 /* add to the list of leds */
102 write_lock(&leds_list_lock);
103 list_add_tail(&led_cdev->node, &leds_list);
104 write_unlock(&leds_list_lock);
105
106#ifdef CONFIG_LEDS_TRIGGERS
107 rwlock_init(&led_cdev->trigger_lock);
108
109 led_trigger_set_default(led_cdev);
110
111 class_device_create_file(led_cdev->class_dev,
112 &class_device_attr_trigger);
113#endif
114
115 printk(KERN_INFO "Registered led device: %s\n",
116 led_cdev->class_dev->class_id);
117
118 return 0;
119}
120EXPORT_SYMBOL_GPL(led_classdev_register);
121
122/**
123 * led_classdev_unregister - unregisters a object of led_properties class.
124 * @led_cdev: the led device to unreigister
125 *
126 * Unregisters a previously registered via led_classdev_register object.
127 */
128void led_classdev_unregister(struct led_classdev *led_cdev)
129{
130 class_device_remove_file(led_cdev->class_dev,
131 &class_device_attr_brightness);
132#ifdef CONFIG_LEDS_TRIGGERS
133 class_device_remove_file(led_cdev->class_dev,
134 &class_device_attr_trigger);
135 write_lock(&led_cdev->trigger_lock);
136 if (led_cdev->trigger)
137 led_trigger_set(led_cdev, NULL);
138 write_unlock(&led_cdev->trigger_lock);
139#endif
140
141 class_device_unregister(led_cdev->class_dev);
142
143 write_lock(&leds_list_lock);
144 list_del(&led_cdev->node);
145 write_unlock(&leds_list_lock);
146}
147EXPORT_SYMBOL_GPL(led_classdev_unregister);
148
149static int __init leds_init(void)
150{
151 leds_class = class_create(THIS_MODULE, "leds");
152 if (IS_ERR(leds_class))
153 return PTR_ERR(leds_class);
154 return 0;
155}
156
157static void __exit leds_exit(void)
158{
159 class_destroy(leds_class);
160}
161
162subsys_initcall(leds_init);
163module_exit(leds_exit);
164
165MODULE_AUTHOR("John Lenz, Richard Purdie");
166MODULE_LICENSE("GPL");
167MODULE_DESCRIPTION("LED Class Interface");
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
new file mode 100644
index 000000000000..fe6541326c71
--- /dev/null
+++ b/drivers/leds/led-core.c
@@ -0,0 +1,25 @@
1/*
2 * LED Class Core
3 *
4 * Copyright 2005-2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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
14#include <linux/kernel.h>
15#include <linux/list.h>
16#include <linux/module.h>
17#include <linux/spinlock.h>
18#include <linux/leds.h>
19#include "leds.h"
20
21rwlock_t leds_list_lock = RW_LOCK_UNLOCKED;
22LIST_HEAD(leds_list);
23
24EXPORT_SYMBOL_GPL(leds_list);
25EXPORT_SYMBOL_GPL(leds_list_lock);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
new file mode 100644
index 000000000000..5e2cd8be1191
--- /dev/null
+++ b/drivers/leds/led-triggers.c
@@ -0,0 +1,239 @@
1/*
2 * LED Triggers Core
3 *
4 * Copyright 2005-2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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
14#include <linux/config.h>
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/list.h>
19#include <linux/spinlock.h>
20#include <linux/device.h>
21#include <linux/sysdev.h>
22#include <linux/timer.h>
23#include <linux/leds.h>
24#include "leds.h"
25
26/*
27 * Nests outside led_cdev->trigger_lock
28 */
29static rwlock_t triggers_list_lock = RW_LOCK_UNLOCKED;
30static LIST_HEAD(trigger_list);
31
32ssize_t led_trigger_store(struct class_device *dev, const char *buf,
33 size_t count)
34{
35 struct led_classdev *led_cdev = class_get_devdata(dev);
36 char trigger_name[TRIG_NAME_MAX];
37 struct led_trigger *trig;
38 size_t len;
39
40 trigger_name[sizeof(trigger_name) - 1] = '\0';
41 strncpy(trigger_name, buf, sizeof(trigger_name) - 1);
42 len = strlen(trigger_name);
43
44 if (len && trigger_name[len - 1] == '\n')
45 trigger_name[len - 1] = '\0';
46
47 if (!strcmp(trigger_name, "none")) {
48 write_lock(&led_cdev->trigger_lock);
49 led_trigger_set(led_cdev, NULL);
50 write_unlock(&led_cdev->trigger_lock);
51 return count;
52 }
53
54 read_lock(&triggers_list_lock);
55 list_for_each_entry(trig, &trigger_list, next_trig) {
56 if (!strcmp(trigger_name, trig->name)) {
57 write_lock(&led_cdev->trigger_lock);
58 led_trigger_set(led_cdev, trig);
59 write_unlock(&led_cdev->trigger_lock);
60
61 read_unlock(&triggers_list_lock);
62 return count;
63 }
64 }
65 read_unlock(&triggers_list_lock);
66
67 return -EINVAL;
68}
69
70
71ssize_t led_trigger_show(struct class_device *dev, char *buf)
72{
73 struct led_classdev *led_cdev = class_get_devdata(dev);
74 struct led_trigger *trig;
75 int len = 0;
76
77 read_lock(&triggers_list_lock);
78 read_lock(&led_cdev->trigger_lock);
79
80 if (!led_cdev->trigger)
81 len += sprintf(buf+len, "[none] ");
82 else
83 len += sprintf(buf+len, "none ");
84
85 list_for_each_entry(trig, &trigger_list, next_trig) {
86 if (led_cdev->trigger && !strcmp(led_cdev->trigger->name,
87 trig->name))
88 len += sprintf(buf+len, "[%s] ", trig->name);
89 else
90 len += sprintf(buf+len, "%s ", trig->name);
91 }
92 read_unlock(&led_cdev->trigger_lock);
93 read_unlock(&triggers_list_lock);
94
95 len += sprintf(len+buf, "\n");
96 return len;
97}
98
99void led_trigger_event(struct led_trigger *trigger,
100 enum led_brightness brightness)
101{
102 struct list_head *entry;
103
104 if (!trigger)
105 return;
106
107 read_lock(&trigger->leddev_list_lock);
108 list_for_each(entry, &trigger->led_cdevs) {
109 struct led_classdev *led_cdev;
110
111 led_cdev = list_entry(entry, struct led_classdev, trig_list);
112 led_set_brightness(led_cdev, brightness);
113 }
114 read_unlock(&trigger->leddev_list_lock);
115}
116
117/* Caller must ensure led_cdev->trigger_lock held */
118void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger)
119{
120 unsigned long flags;
121
122 /* Remove any existing trigger */
123 if (led_cdev->trigger) {
124 write_lock_irqsave(&led_cdev->trigger->leddev_list_lock, flags);
125 list_del(&led_cdev->trig_list);
126 write_unlock_irqrestore(&led_cdev->trigger->leddev_list_lock, flags);
127 if (led_cdev->trigger->deactivate)
128 led_cdev->trigger->deactivate(led_cdev);
129 }
130 if (trigger) {
131 write_lock_irqsave(&trigger->leddev_list_lock, flags);
132 list_add_tail(&led_cdev->trig_list, &trigger->led_cdevs);
133 write_unlock_irqrestore(&trigger->leddev_list_lock, flags);
134 if (trigger->activate)
135 trigger->activate(led_cdev);
136 }
137 led_cdev->trigger = trigger;
138}
139
140void led_trigger_set_default(struct led_classdev *led_cdev)
141{
142 struct led_trigger *trig;
143
144 if (!led_cdev->default_trigger)
145 return;
146
147 read_lock(&triggers_list_lock);
148 write_lock(&led_cdev->trigger_lock);
149 list_for_each_entry(trig, &trigger_list, next_trig) {
150 if (!strcmp(led_cdev->default_trigger, trig->name))
151 led_trigger_set(led_cdev, trig);
152 }
153 write_unlock(&led_cdev->trigger_lock);
154 read_unlock(&triggers_list_lock);
155}
156
157int led_trigger_register(struct led_trigger *trigger)
158{
159 struct led_classdev *led_cdev;
160
161 rwlock_init(&trigger->leddev_list_lock);
162 INIT_LIST_HEAD(&trigger->led_cdevs);
163
164 /* Add to the list of led triggers */
165 write_lock(&triggers_list_lock);
166 list_add_tail(&trigger->next_trig, &trigger_list);
167 write_unlock(&triggers_list_lock);
168
169 /* Register with any LEDs that have this as a default trigger */
170 read_lock(&leds_list_lock);
171 list_for_each_entry(led_cdev, &leds_list, node) {
172 write_lock(&led_cdev->trigger_lock);
173 if (!led_cdev->trigger && led_cdev->default_trigger &&
174 !strcmp(led_cdev->default_trigger, trigger->name))
175 led_trigger_set(led_cdev, trigger);
176 write_unlock(&led_cdev->trigger_lock);
177 }
178 read_unlock(&leds_list_lock);
179
180 return 0;
181}
182
183void led_trigger_register_simple(const char *name, struct led_trigger **tp)
184{
185 struct led_trigger *trigger;
186
187 trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
188
189 if (trigger) {
190 trigger->name = name;
191 led_trigger_register(trigger);
192 }
193 *tp = trigger;
194}
195
196void led_trigger_unregister(struct led_trigger *trigger)
197{
198 struct led_classdev *led_cdev;
199
200 /* Remove from the list of led triggers */
201 write_lock(&triggers_list_lock);
202 list_del(&trigger->next_trig);
203 write_unlock(&triggers_list_lock);
204
205 /* Remove anyone actively using this trigger */
206 read_lock(&leds_list_lock);
207 list_for_each_entry(led_cdev, &leds_list, node) {
208 write_lock(&led_cdev->trigger_lock);
209 if (led_cdev->trigger == trigger)
210 led_trigger_set(led_cdev, NULL);
211 write_unlock(&led_cdev->trigger_lock);
212 }
213 read_unlock(&leds_list_lock);
214}
215
216void led_trigger_unregister_simple(struct led_trigger *trigger)
217{
218 led_trigger_unregister(trigger);
219 kfree(trigger);
220}
221
222/* Used by LED Class */
223EXPORT_SYMBOL_GPL(led_trigger_set);
224EXPORT_SYMBOL_GPL(led_trigger_set_default);
225EXPORT_SYMBOL_GPL(led_trigger_show);
226EXPORT_SYMBOL_GPL(led_trigger_store);
227
228/* LED Trigger Interface */
229EXPORT_SYMBOL_GPL(led_trigger_register);
230EXPORT_SYMBOL_GPL(led_trigger_unregister);
231
232/* Simple LED Tigger Interface */
233EXPORT_SYMBOL_GPL(led_trigger_register_simple);
234EXPORT_SYMBOL_GPL(led_trigger_unregister_simple);
235EXPORT_SYMBOL_GPL(led_trigger_event);
236
237MODULE_AUTHOR("Richard Purdie");
238MODULE_LICENSE("GPL");
239MODULE_DESCRIPTION("LED Triggers Core");
diff --git a/drivers/leds/leds-corgi.c b/drivers/leds/leds-corgi.c
new file mode 100644
index 000000000000..bb7d84df0121
--- /dev/null
+++ b/drivers/leds/leds-corgi.c
@@ -0,0 +1,121 @@
1/*
2 * LED Triggers Core
3 *
4 * Copyright 2005-2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/leds.h>
19#include <asm/mach-types.h>
20#include <asm/arch/corgi.h>
21#include <asm/arch/hardware.h>
22#include <asm/arch/pxa-regs.h>
23#include <asm/hardware/scoop.h>
24
25static void corgiled_amber_set(struct led_classdev *led_cdev, enum led_brightness value)
26{
27 if (value)
28 GPSR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
29 else
30 GPCR0 = GPIO_bit(CORGI_GPIO_LED_ORANGE);
31}
32
33static void corgiled_green_set(struct led_classdev *led_cdev, enum led_brightness value)
34{
35 if (value)
36 set_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
37 else
38 reset_scoop_gpio(&corgiscoop_device.dev, CORGI_SCP_LED_GREEN);
39}
40
41static struct led_classdev corgi_amber_led = {
42 .name = "corgi:amber",
43 .default_trigger = "sharpsl-charge",
44 .brightness_set = corgiled_amber_set,
45};
46
47static struct led_classdev corgi_green_led = {
48 .name = "corgi:green",
49 .default_trigger = "nand-disk",
50 .brightness_set = corgiled_green_set,
51};
52
53#ifdef CONFIG_PM
54static int corgiled_suspend(struct platform_device *dev, pm_message_t state)
55{
56#ifdef CONFIG_LEDS_TRIGGERS
57 if (corgi_amber_led.trigger && strcmp(corgi_amber_led.trigger->name, "sharpsl-charge"))
58#endif
59 led_classdev_suspend(&corgi_amber_led);
60 led_classdev_suspend(&corgi_green_led);
61 return 0;
62}
63
64static int corgiled_resume(struct platform_device *dev)
65{
66 led_classdev_resume(&corgi_amber_led);
67 led_classdev_resume(&corgi_green_led);
68 return 0;
69}
70#endif
71
72static int corgiled_probe(struct platform_device *pdev)
73{
74 int ret;
75
76 ret = led_classdev_register(&pdev->dev, &corgi_amber_led);
77 if (ret < 0)
78 return ret;
79
80 ret = led_classdev_register(&pdev->dev, &corgi_green_led);
81 if (ret < 0)
82 led_classdev_unregister(&corgi_amber_led);
83
84 return ret;
85}
86
87static int corgiled_remove(struct platform_device *pdev)
88{
89 led_classdev_unregister(&corgi_amber_led);
90 led_classdev_unregister(&corgi_green_led);
91 return 0;
92}
93
94static struct platform_driver corgiled_driver = {
95 .probe = corgiled_probe,
96 .remove = corgiled_remove,
97#ifdef CONFIG_PM
98 .suspend = corgiled_suspend,
99 .resume = corgiled_resume,
100#endif
101 .driver = {
102 .name = "corgi-led",
103 },
104};
105
106static int __init corgiled_init(void)
107{
108 return platform_driver_register(&corgiled_driver);
109}
110
111static void __exit corgiled_exit(void)
112{
113 platform_driver_unregister(&corgiled_driver);
114}
115
116module_init(corgiled_init);
117module_exit(corgiled_exit);
118
119MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
120MODULE_DESCRIPTION("Corgi LED driver");
121MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-ixp4xx-gpio.c b/drivers/leds/leds-ixp4xx-gpio.c
new file mode 100644
index 000000000000..30ced150e4cf
--- /dev/null
+++ b/drivers/leds/leds-ixp4xx-gpio.c
@@ -0,0 +1,215 @@
1/*
2 * IXP4XX GPIO driver LED driver
3 *
4 * Author: John Bowler <jbowler@acm.org>
5 *
6 * Copyright (c) 2006 John Bowler
7 *
8 * Permission is hereby granted, free of charge, to any
9 * person obtaining a copy of this software and associated
10 * documentation files (the "Software"), to deal in the
11 * Software without restriction, including without
12 * limitation the rights to use, copy, modify, merge,
13 * publish, distribute, sublicense, and/or sell copies of
14 * the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the
16 * following conditions:
17 *
18 * The above copyright notice and this permission notice
19 * shall be included in all copies or substantial portions
20 * of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
23 * ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
24 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
26 * SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
27 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <linux/config.h>
35#include <linux/kernel.h>
36#include <linux/init.h>
37#include <linux/platform_device.h>
38#include <linux/spinlock.h>
39#include <linux/leds.h>
40#include <asm/arch/hardware.h>
41
42extern spinlock_t gpio_lock;
43
44/* Up to 16 gpio lines are possible. */
45#define GPIO_MAX 16
46static struct ixp4xxgpioled_device {
47 struct led_classdev ancestor;
48 int flags;
49} ixp4xxgpioled_devices[GPIO_MAX];
50
51void ixp4xxgpioled_brightness_set(struct led_classdev *pled,
52 enum led_brightness value)
53{
54 const struct ixp4xxgpioled_device *const ixp4xx_dev =
55 container_of(pled, struct ixp4xxgpioled_device, ancestor);
56 const u32 gpio_pin = ixp4xx_dev - ixp4xxgpioled_devices;
57
58 if (gpio_pin < GPIO_MAX && ixp4xx_dev->ancestor.name != 0) {
59 /* Set or clear the 'gpio_pin' bit according to the style
60 * and the required setting (value > 0 == on)
61 */
62 const int gpio_value =
63 (value > 0) == (ixp4xx_dev->flags != IXP4XX_GPIO_LOW) ?
64 IXP4XX_GPIO_HIGH : IXP4XX_GPIO_LOW;
65
66 {
67 unsigned long flags;
68 spin_lock_irqsave(&gpio_lock, flags);
69 gpio_line_set(gpio_pin, gpio_value);
70 spin_unlock_irqrestore(&gpio_lock, flags);
71 }
72 }
73}
74
75/* LEDs are described in resources, the following iterates over the valid
76 * LED resources.
77 */
78#define for_all_leds(i, pdev) \
79 for (i=0; i<pdev->num_resources; ++i) \
80 if (pdev->resource[i].start < GPIO_MAX && \
81 pdev->resource[i].name != 0)
82
83/* The following applies 'operation' to each LED from the given platform,
84 * the function always returns 0 to allow tail call elimination.
85 */
86static int apply_to_all_leds(struct platform_device *pdev,
87 void (*operation)(struct led_classdev *pled))
88{
89 int i;
90
91 for_all_leds(i, pdev)
92 operation(&ixp4xxgpioled_devices[pdev->resource[i].start].ancestor);
93 return 0;
94}
95
96#ifdef CONFIG_PM
97static int ixp4xxgpioled_suspend(struct platform_device *pdev,
98 pm_message_t state)
99{
100 return apply_to_all_leds(pdev, led_classdev_suspend);
101}
102
103static int ixp4xxgpioled_resume(struct platform_device *pdev)
104{
105 return apply_to_all_leds(pdev, led_classdev_resume);
106}
107#endif
108
109static void ixp4xxgpioled_remove_one_led(struct led_classdev *pled)
110{
111 led_classdev_unregister(pled);
112 pled->name = 0;
113}
114
115static int ixp4xxgpioled_remove(struct platform_device *pdev)
116{
117 return apply_to_all_leds(pdev, ixp4xxgpioled_remove_one_led);
118}
119
120static int ixp4xxgpioled_probe(struct platform_device *pdev)
121{
122 /* The board level has to tell the driver where the
123 * LEDs are connected - there is no way to find out
124 * electrically. It must also say whether the GPIO
125 * lines are active high or active low.
126 *
127 * To do this read the num_resources (the number of
128 * LEDs) and the struct resource (the data for each
129 * LED). The name comes from the resource, and it
130 * isn't copied.
131 */
132 int i;
133
134 for_all_leds(i, pdev) {
135 const u8 gpio_pin = pdev->resource[i].start;
136 int rc;
137
138 if (ixp4xxgpioled_devices[gpio_pin].ancestor.name == 0) {
139 unsigned long flags;
140
141 spin_lock_irqsave(&gpio_lock, flags);
142 gpio_line_config(gpio_pin, IXP4XX_GPIO_OUT);
143 /* The config can, apparently, reset the state,
144 * I suspect the gpio line may be an input and
145 * the config may cause the line to be latched,
146 * so the setting depends on how the LED is
147 * connected to the line (which affects how it
148 * floats if not driven).
149 */
150 gpio_line_set(gpio_pin, IXP4XX_GPIO_HIGH);
151 spin_unlock_irqrestore(&gpio_lock, flags);
152
153 ixp4xxgpioled_devices[gpio_pin].flags =
154 pdev->resource[i].flags & IORESOURCE_BITS;
155
156 ixp4xxgpioled_devices[gpio_pin].ancestor.name =
157 pdev->resource[i].name;
158
159 /* This is how a board manufacturer makes the LED
160 * come on on reset - the GPIO line will be high, so
161 * make the LED light when the line is low...
162 */
163 if (ixp4xxgpioled_devices[gpio_pin].flags != IXP4XX_GPIO_LOW)
164 ixp4xxgpioled_devices[gpio_pin].ancestor.brightness = 100;
165 else
166 ixp4xxgpioled_devices[gpio_pin].ancestor.brightness = 0;
167
168 ixp4xxgpioled_devices[gpio_pin].ancestor.flags = 0;
169
170 ixp4xxgpioled_devices[gpio_pin].ancestor.brightness_set =
171 ixp4xxgpioled_brightness_set;
172
173 ixp4xxgpioled_devices[gpio_pin].ancestor.default_trigger = 0;
174 }
175
176 rc = led_classdev_register(&pdev->dev,
177 &ixp4xxgpioled_devices[gpio_pin].ancestor);
178 if (rc < 0) {
179 ixp4xxgpioled_devices[gpio_pin].ancestor.name = 0;
180 ixp4xxgpioled_remove(pdev);
181 return rc;
182 }
183 }
184
185 return 0;
186}
187
188static struct platform_driver ixp4xxgpioled_driver = {
189 .probe = ixp4xxgpioled_probe,
190 .remove = ixp4xxgpioled_remove,
191#ifdef CONFIG_PM
192 .suspend = ixp4xxgpioled_suspend,
193 .resume = ixp4xxgpioled_resume,
194#endif
195 .driver = {
196 .name = "IXP4XX-GPIO-LED",
197 },
198};
199
200static int __init ixp4xxgpioled_init(void)
201{
202 return platform_driver_register(&ixp4xxgpioled_driver);
203}
204
205static void __exit ixp4xxgpioled_exit(void)
206{
207 platform_driver_unregister(&ixp4xxgpioled_driver);
208}
209
210module_init(ixp4xxgpioled_init);
211module_exit(ixp4xxgpioled_exit);
212
213MODULE_AUTHOR("John Bowler <jbowler@acm.org>");
214MODULE_DESCRIPTION("IXP4XX GPIO LED driver");
215MODULE_LICENSE("Dual MIT/GPL");
diff --git a/drivers/leds/leds-locomo.c b/drivers/leds/leds-locomo.c
new file mode 100644
index 000000000000..749a86c2adb6
--- /dev/null
+++ b/drivers/leds/leds-locomo.c
@@ -0,0 +1,95 @@
1/*
2 * linux/drivers/leds/locomo.c
3 *
4 * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/config.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/device.h>
15#include <linux/leds.h>
16
17#include <asm/hardware.h>
18#include <asm/hardware/locomo.h>
19
20static void locomoled_brightness_set(struct led_classdev *led_cdev,
21 enum led_brightness value, int offset)
22{
23 struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->class_dev->dev);
24 unsigned long flags;
25
26 local_irq_save(flags);
27 if (value)
28 locomo_writel(LOCOMO_LPT_TOFH, locomo_dev->mapbase + offset);
29 else
30 locomo_writel(LOCOMO_LPT_TOFL, locomo_dev->mapbase + offset);
31 local_irq_restore(flags);
32}
33
34static void locomoled_brightness_set0(struct led_classdev *led_cdev,
35 enum led_brightness value)
36{
37 locomoled_brightness_set(led_cdev, value, LOCOMO_LPT0);
38}
39
40static void locomoled_brightness_set1(struct led_classdev *led_cdev,
41 enum led_brightness value)
42{
43 locomoled_brightness_set(led_cdev, value, LOCOMO_LPT1);
44}
45
46static struct led_classdev locomo_led0 = {
47 .name = "locomo:amber",
48 .brightness_set = locomoled_brightness_set0,
49};
50
51static struct led_classdev locomo_led1 = {
52 .name = "locomo:green",
53 .brightness_set = locomoled_brightness_set1,
54};
55
56static int locomoled_probe(struct locomo_dev *ldev)
57{
58 int ret;
59
60 ret = led_classdev_register(&ldev->dev, &locomo_led0);
61 if (ret < 0)
62 return ret;
63
64 ret = led_classdev_register(&ldev->dev, &locomo_led1);
65 if (ret < 0)
66 led_classdev_unregister(&locomo_led0);
67
68 return ret;
69}
70
71static int locomoled_remove(struct locomo_dev *dev)
72{
73 led_classdev_unregister(&locomo_led0);
74 led_classdev_unregister(&locomo_led1);
75 return 0;
76}
77
78static struct locomo_driver locomoled_driver = {
79 .drv = {
80 .name = "locomoled"
81 },
82 .devid = LOCOMO_DEVID_LED,
83 .probe = locomoled_probe,
84 .remove = locomoled_remove,
85};
86
87static int __init locomoled_init(void)
88{
89 return locomo_driver_register(&locomoled_driver);
90}
91module_init(locomoled_init);
92
93MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
94MODULE_DESCRIPTION("Locomo LED driver");
95MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
new file mode 100644
index 000000000000..650cf72dc675
--- /dev/null
+++ b/drivers/leds/leds-s3c24xx.c
@@ -0,0 +1,163 @@
1/* drivers/leds/leds-s3c24xx.c
2 *
3 * (c) 2006 Simtec Electronics
4 * http://armlinux.simtec.co.uk/
5 * Ben Dooks <ben@simtec.co.uk>
6 *
7 * S3C24XX - LEDs GPIO driver
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/leds.h>
19
20#include <asm/arch/hardware.h>
21#include <asm/arch/regs-gpio.h>
22#include <asm/arch/leds-gpio.h>
23
24/* our context */
25
26struct s3c24xx_gpio_led {
27 struct led_classdev cdev;
28 struct s3c24xx_led_platdata *pdata;
29};
30
31static inline struct s3c24xx_gpio_led *pdev_to_gpio(struct platform_device *dev)
32{
33 return platform_get_drvdata(dev);
34}
35
36static inline struct s3c24xx_gpio_led *to_gpio(struct led_classdev *led_cdev)
37{
38 return container_of(led_cdev, struct s3c24xx_gpio_led, cdev);
39}
40
41static void s3c24xx_led_set(struct led_classdev *led_cdev,
42 enum led_brightness value)
43{
44 struct s3c24xx_gpio_led *led = to_gpio(led_cdev);
45 struct s3c24xx_led_platdata *pd = led->pdata;
46
47 /* there will be a sort delay between setting the output and
48 * going from output to input when using tristate. */
49
50 s3c2410_gpio_setpin(pd->gpio, (value ? 1 : 0) ^
51 (pd->flags & S3C24XX_LEDF_ACTLOW));
52
53 if (pd->flags & S3C24XX_LEDF_TRISTATE)
54 s3c2410_gpio_cfgpin(pd->gpio,
55 value ? S3C2410_GPIO_OUTPUT : S3C2410_GPIO_INPUT);
56
57}
58
59static int s3c24xx_led_remove(struct platform_device *dev)
60{
61 struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
62
63 led_classdev_unregister(&led->cdev);
64 kfree(led);
65
66 return 0;
67}
68
69static int s3c24xx_led_probe(struct platform_device *dev)
70{
71 struct s3c24xx_led_platdata *pdata = dev->dev.platform_data;
72 struct s3c24xx_gpio_led *led;
73 int ret;
74
75 led = kzalloc(sizeof(struct s3c24xx_gpio_led), GFP_KERNEL);
76 if (led == NULL) {
77 dev_err(&dev->dev, "No memory for device\n");
78 return -ENOMEM;
79 }
80
81 platform_set_drvdata(dev, led);
82
83 led->cdev.brightness_set = s3c24xx_led_set;
84 led->cdev.default_trigger = pdata->def_trigger;
85 led->cdev.name = pdata->name;
86
87 led->pdata = pdata;
88
89 /* no point in having a pull-up if we are always driving */
90
91 if (pdata->flags & S3C24XX_LEDF_TRISTATE) {
92 s3c2410_gpio_setpin(pdata->gpio, 0);
93 s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_INPUT);
94 } else {
95 s3c2410_gpio_pullup(pdata->gpio, 0);
96 s3c2410_gpio_setpin(pdata->gpio, 0);
97 s3c2410_gpio_cfgpin(pdata->gpio, S3C2410_GPIO_OUTPUT);
98 }
99
100 /* register our new led device */
101
102 ret = led_classdev_register(&dev->dev, &led->cdev);
103 if (ret < 0) {
104 dev_err(&dev->dev, "led_classdev_register failed\n");
105 goto exit_err1;
106 }
107
108 return 0;
109
110 exit_err1:
111 kfree(led);
112 return ret;
113}
114
115
116#ifdef CONFIG_PM
117static int s3c24xx_led_suspend(struct platform_device *dev, pm_message_t state)
118{
119 struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
120
121 led_classdev_suspend(&led->cdev);
122 return 0;
123}
124
125static int s3c24xx_led_resume(struct platform_device *dev)
126{
127 struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
128
129 led_classdev_resume(&led->cdev);
130 return 0;
131}
132#else
133#define s3c24xx_led_suspend NULL
134#define s3c24xx_led_resume NULL
135#endif
136
137static struct platform_driver s3c24xx_led_driver = {
138 .probe = s3c24xx_led_probe,
139 .remove = s3c24xx_led_remove,
140 .suspend = s3c24xx_led_suspend,
141 .resume = s3c24xx_led_resume,
142 .driver = {
143 .name = "s3c24xx_led",
144 .owner = THIS_MODULE,
145 },
146};
147
148static int __init s3c24xx_led_init(void)
149{
150 return platform_driver_register(&s3c24xx_led_driver);
151}
152
153static void __exit s3c24xx_led_exit(void)
154{
155 platform_driver_unregister(&s3c24xx_led_driver);
156}
157
158module_init(s3c24xx_led_init);
159module_exit(s3c24xx_led_exit);
160
161MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
162MODULE_DESCRIPTION("S3C24XX LED driver");
163MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-spitz.c b/drivers/leds/leds-spitz.c
new file mode 100644
index 000000000000..65bbef4a5e09
--- /dev/null
+++ b/drivers/leds/leds-spitz.c
@@ -0,0 +1,125 @@
1/*
2 * LED Triggers Core
3 *
4 * Copyright 2005-2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/leds.h>
19#include <asm/hardware/scoop.h>
20#include <asm/mach-types.h>
21#include <asm/arch/hardware.h>
22#include <asm/arch/pxa-regs.h>
23#include <asm/arch/spitz.h>
24
25static void spitzled_amber_set(struct led_classdev *led_cdev, enum led_brightness value)
26{
27 if (value)
28 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
29 else
30 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_ORANGE);
31}
32
33static void spitzled_green_set(struct led_classdev *led_cdev, enum led_brightness value)
34{
35 if (value)
36 set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
37 else
38 reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_LED_GREEN);
39}
40
41static struct led_classdev spitz_amber_led = {
42 .name = "spitz:amber",
43 .default_trigger = "sharpsl-charge",
44 .brightness_set = spitzled_amber_set,
45};
46
47static struct led_classdev spitz_green_led = {
48 .name = "spitz:green",
49 .default_trigger = "ide-disk",
50 .brightness_set = spitzled_green_set,
51};
52
53#ifdef CONFIG_PM
54static int spitzled_suspend(struct platform_device *dev, pm_message_t state)
55{
56#ifdef CONFIG_LEDS_TRIGGERS
57 if (spitz_amber_led.trigger && strcmp(spitz_amber_led.trigger->name, "sharpsl-charge"))
58#endif
59 led_classdev_suspend(&spitz_amber_led);
60 led_classdev_suspend(&spitz_green_led);
61 return 0;
62}
63
64static int spitzled_resume(struct platform_device *dev)
65{
66 led_classdev_resume(&spitz_amber_led);
67 led_classdev_resume(&spitz_green_led);
68 return 0;
69}
70#endif
71
72static int spitzled_probe(struct platform_device *pdev)
73{
74 int ret;
75
76 if (machine_is_akita())
77 spitz_green_led.default_trigger = "nand-disk";
78
79 ret = led_classdev_register(&pdev->dev, &spitz_amber_led);
80 if (ret < 0)
81 return ret;
82
83 ret = led_classdev_register(&pdev->dev, &spitz_green_led);
84 if (ret < 0)
85 led_classdev_unregister(&spitz_amber_led);
86
87 return ret;
88}
89
90static int spitzled_remove(struct platform_device *pdev)
91{
92 led_classdev_unregister(&spitz_amber_led);
93 led_classdev_unregister(&spitz_green_led);
94
95 return 0;
96}
97
98static struct platform_driver spitzled_driver = {
99 .probe = spitzled_probe,
100 .remove = spitzled_remove,
101#ifdef CONFIG_PM
102 .suspend = spitzled_suspend,
103 .resume = spitzled_resume,
104#endif
105 .driver = {
106 .name = "spitz-led",
107 },
108};
109
110static int __init spitzled_init(void)
111{
112 return platform_driver_register(&spitzled_driver);
113}
114
115static void __exit spitzled_exit(void)
116{
117 platform_driver_unregister(&spitzled_driver);
118}
119
120module_init(spitzled_init);
121module_exit(spitzled_exit);
122
123MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
124MODULE_DESCRIPTION("Spitz LED driver");
125MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-tosa.c b/drivers/leds/leds-tosa.c
new file mode 100644
index 000000000000..c9e8cc1ec481
--- /dev/null
+++ b/drivers/leds/leds-tosa.c
@@ -0,0 +1,131 @@
1/*
2 * LED Triggers Core
3 *
4 * Copyright 2005 Dirk Opfer
5 *
6 * Author: Dirk Opfer <Dirk@Opfer-Online.de>
7 * based on spitz.c
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 */
14
15#include <linux/config.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/leds.h>
20#include <asm/hardware/scoop.h>
21#include <asm/mach-types.h>
22#include <asm/arch/hardware.h>
23#include <asm/arch/pxa-regs.h>
24#include <asm/arch/tosa.h>
25
26static void tosaled_amber_set(struct led_classdev *led_cdev,
27 enum led_brightness value)
28{
29 if (value)
30 set_scoop_gpio(&tosascoop_jc_device.dev,
31 TOSA_SCOOP_JC_CHRG_ERR_LED);
32 else
33 reset_scoop_gpio(&tosascoop_jc_device.dev,
34 TOSA_SCOOP_JC_CHRG_ERR_LED);
35}
36
37static void tosaled_green_set(struct led_classdev *led_cdev,
38 enum led_brightness value)
39{
40 if (value)
41 set_scoop_gpio(&tosascoop_jc_device.dev,
42 TOSA_SCOOP_JC_NOTE_LED);
43 else
44 reset_scoop_gpio(&tosascoop_jc_device.dev,
45 TOSA_SCOOP_JC_NOTE_LED);
46}
47
48static struct led_classdev tosa_amber_led = {
49 .name = "tosa:amber",
50 .default_trigger = "sharpsl-charge",
51 .brightness_set = tosaled_amber_set,
52};
53
54static struct led_classdev tosa_green_led = {
55 .name = "tosa:green",
56 .default_trigger = "nand-disk",
57 .brightness_set = tosaled_green_set,
58};
59
60#ifdef CONFIG_PM
61static int tosaled_suspend(struct platform_device *dev, pm_message_t state)
62{
63#ifdef CONFIG_LEDS_TRIGGERS
64 if (tosa_amber_led.trigger && strcmp(tosa_amber_led.trigger->name,
65 "sharpsl-charge"))
66#endif
67 led_classdev_suspend(&tosa_amber_led);
68 led_classdev_suspend(&tosa_green_led);
69 return 0;
70}
71
72static int tosaled_resume(struct platform_device *dev)
73{
74 led_classdev_resume(&tosa_amber_led);
75 led_classdev_resume(&tosa_green_led);
76 return 0;
77}
78#else
79#define tosaled_suspend NULL
80#define tosaled_resume NULL
81#endif
82
83static int tosaled_probe(struct platform_device *pdev)
84{
85 int ret;
86
87 ret = led_classdev_register(&pdev->dev, &tosa_amber_led);
88 if (ret < 0)
89 return ret;
90
91 ret = led_classdev_register(&pdev->dev, &tosa_green_led);
92 if (ret < 0)
93 led_classdev_unregister(&tosa_amber_led);
94
95 return ret;
96}
97
98static int tosaled_remove(struct platform_device *pdev)
99{
100 led_classdev_unregister(&tosa_amber_led);
101 led_classdev_unregister(&tosa_green_led);
102
103 return 0;
104}
105
106static struct platform_driver tosaled_driver = {
107 .probe = tosaled_probe,
108 .remove = tosaled_remove,
109 .suspend = tosaled_suspend,
110 .resume = tosaled_resume,
111 .driver = {
112 .name = "tosa-led",
113 },
114};
115
116static int __init tosaled_init(void)
117{
118 return platform_driver_register(&tosaled_driver);
119}
120
121static void __exit tosaled_exit(void)
122{
123 platform_driver_unregister(&tosaled_driver);
124}
125
126module_init(tosaled_init);
127module_exit(tosaled_exit);
128
129MODULE_AUTHOR("Dirk Opfer <Dirk@Opfer-Online.de>");
130MODULE_DESCRIPTION("Tosa LED driver");
131MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
new file mode 100644
index 000000000000..a715c4ed93ff
--- /dev/null
+++ b/drivers/leds/leds.h
@@ -0,0 +1,44 @@
1/*
2 * LED Core
3 *
4 * Copyright 2005 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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#ifndef __LEDS_H_INCLUDED
14#define __LEDS_H_INCLUDED
15
16#include <linux/leds.h>
17
18static inline void led_set_brightness(struct led_classdev *led_cdev,
19 enum led_brightness value)
20{
21 if (value > LED_FULL)
22 value = LED_FULL;
23 led_cdev->brightness = value;
24 if (!(led_cdev->flags & LED_SUSPENDED))
25 led_cdev->brightness_set(led_cdev, value);
26}
27
28extern rwlock_t leds_list_lock;
29extern struct list_head leds_list;
30
31#ifdef CONFIG_LEDS_TRIGGERS
32void led_trigger_set_default(struct led_classdev *led_cdev);
33void led_trigger_set(struct led_classdev *led_cdev,
34 struct led_trigger *trigger);
35#else
36#define led_trigger_set_default(x) do {} while(0)
37#define led_trigger_set(x, y) do {} while(0)
38#endif
39
40ssize_t led_trigger_store(struct class_device *dev, const char *buf,
41 size_t count);
42ssize_t led_trigger_show(struct class_device *dev, char *buf);
43
44#endif /* __LEDS_H_INCLUDED */
diff --git a/drivers/leds/ledtrig-ide-disk.c b/drivers/leds/ledtrig-ide-disk.c
new file mode 100644
index 000000000000..fa651886ab4f
--- /dev/null
+++ b/drivers/leds/ledtrig-ide-disk.c
@@ -0,0 +1,62 @@
1/*
2 * LED IDE-Disk Activity Trigger
3 *
4 * Copyright 2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/timer.h>
18#include <linux/leds.h>
19
20static void ledtrig_ide_timerfunc(unsigned long data);
21
22DEFINE_LED_TRIGGER(ledtrig_ide);
23static DEFINE_TIMER(ledtrig_ide_timer, ledtrig_ide_timerfunc, 0, 0);
24static int ide_activity;
25static int ide_lastactivity;
26
27void ledtrig_ide_activity(void)
28{
29 ide_activity++;
30 if (!timer_pending(&ledtrig_ide_timer))
31 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
32}
33EXPORT_SYMBOL(ledtrig_ide_activity);
34
35static void ledtrig_ide_timerfunc(unsigned long data)
36{
37 if (ide_lastactivity != ide_activity) {
38 ide_lastactivity = ide_activity;
39 led_trigger_event(ledtrig_ide, LED_FULL);
40 mod_timer(&ledtrig_ide_timer, jiffies + msecs_to_jiffies(10));
41 } else {
42 led_trigger_event(ledtrig_ide, LED_OFF);
43 }
44}
45
46static int __init ledtrig_ide_init(void)
47{
48 led_trigger_register_simple("ide-disk", &ledtrig_ide);
49 return 0;
50}
51
52static void __exit ledtrig_ide_exit(void)
53{
54 led_trigger_unregister_simple(ledtrig_ide);
55}
56
57module_init(ledtrig_ide_init);
58module_exit(ledtrig_ide_exit);
59
60MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
61MODULE_DESCRIPTION("LED IDE Disk Activity Trigger");
62MODULE_LICENSE("GPL");
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
new file mode 100644
index 000000000000..f484b5d6dbf8
--- /dev/null
+++ b/drivers/leds/ledtrig-timer.c
@@ -0,0 +1,170 @@
1/*
2 * LED Kernel Timer Trigger
3 *
4 * Copyright 2005-2006 Openedhand Ltd.
5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com>
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
14#include <linux/config.h>
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/list.h>
19#include <linux/spinlock.h>
20#include <linux/device.h>
21#include <linux/sysdev.h>
22#include <linux/timer.h>
23#include <linux/leds.h>
24#include "leds.h"
25
26struct timer_trig_data {
27 unsigned long delay_on; /* milliseconds on */
28 unsigned long delay_off; /* milliseconds off */
29 struct timer_list timer;
30};
31
32static void led_timer_function(unsigned long data)
33{
34 struct led_classdev *led_cdev = (struct led_classdev *) data;
35 struct timer_trig_data *timer_data = led_cdev->trigger_data;
36 unsigned long brightness = LED_OFF;
37 unsigned long delay = timer_data->delay_off;
38
39 if (!timer_data->delay_on || !timer_data->delay_off) {
40 led_set_brightness(led_cdev, LED_OFF);
41 return;
42 }
43
44 if (!led_cdev->brightness) {
45 brightness = LED_FULL;
46 delay = timer_data->delay_on;
47 }
48
49 led_set_brightness(led_cdev, brightness);
50
51 mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay));
52}
53
54static ssize_t led_delay_on_show(struct class_device *dev, char *buf)
55{
56 struct led_classdev *led_cdev = class_get_devdata(dev);
57 struct timer_trig_data *timer_data = led_cdev->trigger_data;
58
59 sprintf(buf, "%lu\n", timer_data->delay_on);
60
61 return strlen(buf) + 1;
62}
63
64static ssize_t led_delay_on_store(struct class_device *dev, const char *buf,
65 size_t size)
66{
67 struct led_classdev *led_cdev = class_get_devdata(dev);
68 struct timer_trig_data *timer_data = led_cdev->trigger_data;
69 int ret = -EINVAL;
70 char *after;
71 unsigned long state = simple_strtoul(buf, &after, 10);
72
73 if (after - buf > 0) {
74 timer_data->delay_on = state;
75 mod_timer(&timer_data->timer, jiffies + 1);
76 ret = after - buf;
77 }
78
79 return ret;
80}
81
82static ssize_t led_delay_off_show(struct class_device *dev, char *buf)
83{
84 struct led_classdev *led_cdev = class_get_devdata(dev);
85 struct timer_trig_data *timer_data = led_cdev->trigger_data;
86
87 sprintf(buf, "%lu\n", timer_data->delay_off);
88
89 return strlen(buf) + 1;
90}
91
92static ssize_t led_delay_off_store(struct class_device *dev, const char *buf,
93 size_t size)
94{
95 struct led_classdev *led_cdev = class_get_devdata(dev);
96 struct timer_trig_data *timer_data = led_cdev->trigger_data;
97 int ret = -EINVAL;
98 char *after;
99 unsigned long state = simple_strtoul(buf, &after, 10);
100
101 if (after - buf > 0) {
102 timer_data->delay_off = state;
103 mod_timer(&timer_data->timer, jiffies + 1);
104 ret = after - buf;
105 }
106
107 return ret;
108}
109
110static CLASS_DEVICE_ATTR(delay_on, 0644, led_delay_on_show,
111 led_delay_on_store);
112static CLASS_DEVICE_ATTR(delay_off, 0644, led_delay_off_show,
113 led_delay_off_store);
114
115static void timer_trig_activate(struct led_classdev *led_cdev)
116{
117 struct timer_trig_data *timer_data;
118
119 timer_data = kzalloc(sizeof(struct timer_trig_data), GFP_KERNEL);
120 if (!timer_data)
121 return;
122
123 led_cdev->trigger_data = timer_data;
124
125 init_timer(&timer_data->timer);
126 timer_data->timer.function = led_timer_function;
127 timer_data->timer.data = (unsigned long) led_cdev;
128
129 class_device_create_file(led_cdev->class_dev,
130 &class_device_attr_delay_on);
131 class_device_create_file(led_cdev->class_dev,
132 &class_device_attr_delay_off);
133}
134
135static void timer_trig_deactivate(struct led_classdev *led_cdev)
136{
137 struct timer_trig_data *timer_data = led_cdev->trigger_data;
138
139 if (timer_data) {
140 class_device_remove_file(led_cdev->class_dev,
141 &class_device_attr_delay_on);
142 class_device_remove_file(led_cdev->class_dev,
143 &class_device_attr_delay_off);
144 del_timer_sync(&timer_data->timer);
145 kfree(timer_data);
146 }
147}
148
149static struct led_trigger timer_led_trigger = {
150 .name = "timer",
151 .activate = timer_trig_activate,
152 .deactivate = timer_trig_deactivate,
153};
154
155static int __init timer_trig_init(void)
156{
157 return led_trigger_register(&timer_led_trigger);
158}
159
160static void __exit timer_trig_exit(void)
161{
162 led_trigger_unregister(&timer_led_trigger);
163}
164
165module_init(timer_trig_init);
166module_exit(timer_trig_exit);
167
168MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
169MODULE_DESCRIPTION("Timer LED trigger");
170MODULE_LICENSE("GPL");
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 34fcabac5fdb..259fd8973ce9 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -42,6 +42,7 @@
42#include <asm/semaphore.h> 42#include <asm/semaphore.h>
43#ifdef CONFIG_PPC 43#ifdef CONFIG_PPC
44#include <asm/prom.h> 44#include <asm/prom.h>
45#include <asm/machdep.h>
45#endif 46#endif
46 47
47 48
@@ -294,7 +295,7 @@ int __init adb_init(void)
294 int i; 295 int i;
295 296
296#ifdef CONFIG_PPC32 297#ifdef CONFIG_PPC32
297 if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) ) 298 if (!machine_is(chrp) && !machine_is(powermac))
298 return 0; 299 return 0;
299#endif 300#endif
300#ifdef CONFIG_MAC 301#ifdef CONFIG_MAC
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index f5779a73184d..394334ec5765 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -1206,8 +1206,8 @@ init_ms_a3(int id)
1206static int __init adbhid_init(void) 1206static int __init adbhid_init(void)
1207{ 1207{
1208#ifndef CONFIG_MAC 1208#ifndef CONFIG_MAC
1209 if ( (_machine != _MACH_chrp) && (_machine != _MACH_Pmac) ) 1209 if (!machine_is(chrp) && !machine_is(powermac))
1210 return 0; 1210 return 0;
1211#endif 1211#endif
1212 1212
1213 led_request.complete = 1; 1213 led_request.complete = 1;
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index 8dbf2852bae0..53c1c7909413 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -839,8 +839,8 @@ static int __init media_bay_init(void)
839 media_bays[i].cd_index = -1; 839 media_bays[i].cd_index = -1;
840#endif 840#endif
841 } 841 }
842 if (_machine != _MACH_Pmac) 842 if (!machine_is(powermac))
843 return -ENODEV; 843 return 0;
844 844
845 macio_register_driver(&media_bay_driver); 845 macio_register_driver(&media_bay_driver);
846 846
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index fd2aae150ccc..ac25a48362ac 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -139,11 +139,12 @@ config MD_RAID5_RESHAPE
139 is online. However it is still EXPERIMENTAL code. It should 139 is online. However it is still EXPERIMENTAL code. It should
140 work, but please be sure that you have backups. 140 work, but please be sure that you have backups.
141 141
142 You will need a version of mdadm newer than 2.3.1. During the 142 You will need mdadm verion 2.4.1 or later to use this
143 early stage of reshape there is a critical section where live data 143 feature safely. During the early stage of reshape there is
144 is being over-written. A crash during this time needs extra care 144 a critical section where live data is being over-written. A
145 for recovery. The newer mdadm takes a copy of the data in the 145 crash during this time needs extra care for recovery. The
146 critical section and will restore it, if necessary, after a crash. 146 newer mdadm takes a copy of the data in the critical section
147 and will restore it, if necessary, after a crash.
147 148
148 The mdadm usage is e.g. 149 The mdadm usage is e.g.
149 mdadm --grow /dev/md1 --raid-disks=6 150 mdadm --grow /dev/md1 --raid-disks=6
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c
index aecd9e0c2616..64fd8e79ea4c 100644
--- a/drivers/md/dm-target.c
+++ b/drivers/md/dm-target.c
@@ -78,8 +78,7 @@ void dm_put_target_type(struct target_type *t)
78 if (--ti->use == 0) 78 if (--ti->use == 0)
79 module_put(ti->tt.module); 79 module_put(ti->tt.module);
80 80
81 if (ti->use < 0) 81 BUG_ON(ti->use < 0);
82 BUG();
83 up_read(&_lock); 82 up_read(&_lock);
84 83
85 return; 84 return;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 039e071c1007..434ca39d19c1 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -163,6 +163,7 @@ void md_new_event(mddev_t *mddev)
163{ 163{
164 atomic_inc(&md_event_count); 164 atomic_inc(&md_event_count);
165 wake_up(&md_event_waiters); 165 wake_up(&md_event_waiters);
166 sysfs_notify(&mddev->kobj, NULL, "sync_action");
166} 167}
167EXPORT_SYMBOL_GPL(md_new_event); 168EXPORT_SYMBOL_GPL(md_new_event);
168 169
@@ -215,13 +216,11 @@ static void mddev_put(mddev_t *mddev)
215 return; 216 return;
216 if (!mddev->raid_disks && list_empty(&mddev->disks)) { 217 if (!mddev->raid_disks && list_empty(&mddev->disks)) {
217 list_del(&mddev->all_mddevs); 218 list_del(&mddev->all_mddevs);
218 /* that blocks */ 219 spin_unlock(&all_mddevs_lock);
219 blk_cleanup_queue(mddev->queue); 220 blk_cleanup_queue(mddev->queue);
220 /* that also blocks */
221 kobject_unregister(&mddev->kobj); 221 kobject_unregister(&mddev->kobj);
222 /* result blows... */ 222 } else
223 } 223 spin_unlock(&all_mddevs_lock);
224 spin_unlock(&all_mddevs_lock);
225} 224}
226 225
227static mddev_t * mddev_find(dev_t unit) 226static mddev_t * mddev_find(dev_t unit)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 3cb0872a845d..6081941de1b3 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1135,8 +1135,19 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
1135 mirror = i; 1135 mirror = i;
1136 break; 1136 break;
1137 } 1137 }
1138 if (!uptodate) 1138 if (!uptodate) {
1139 int sync_blocks = 0;
1140 sector_t s = r1_bio->sector;
1141 long sectors_to_go = r1_bio->sectors;
1142 /* make sure these bits doesn't get cleared. */
1143 do {
1144 bitmap_end_sync(mddev->bitmap, r1_bio->sector,
1145 &sync_blocks, 1);
1146 s += sync_blocks;
1147 sectors_to_go -= sync_blocks;
1148 } while (sectors_to_go > 0);
1139 md_error(mddev, conf->mirrors[mirror].rdev); 1149 md_error(mddev, conf->mirrors[mirror].rdev);
1150 }
1140 1151
1141 update_head_pos(mirror, r1_bio); 1152 update_head_pos(mirror, r1_bio);
1142 1153
@@ -1547,8 +1558,7 @@ static int init_resync(conf_t *conf)
1547 int buffs; 1558 int buffs;
1548 1559
1549 buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE; 1560 buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
1550 if (conf->r1buf_pool) 1561 BUG_ON(conf->r1buf_pool);
1551 BUG();
1552 conf->r1buf_pool = mempool_create(buffs, r1buf_pool_alloc, r1buf_pool_free, 1562 conf->r1buf_pool = mempool_create(buffs, r1buf_pool_alloc, r1buf_pool_free,
1553 conf->poolinfo); 1563 conf->poolinfo);
1554 if (!conf->r1buf_pool) 1564 if (!conf->r1buf_pool)
@@ -1721,8 +1731,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1721 !conf->fullsync && 1731 !conf->fullsync &&
1722 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 1732 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
1723 break; 1733 break;
1724 if (sync_blocks < (PAGE_SIZE>>9)) 1734 BUG_ON(sync_blocks < (PAGE_SIZE>>9));
1725 BUG();
1726 if (len > (sync_blocks<<9)) 1735 if (len > (sync_blocks<<9))
1727 len = sync_blocks<<9; 1736 len = sync_blocks<<9;
1728 } 1737 }
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index ab90a6d12020..617012bc107a 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1117,8 +1117,7 @@ static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
1117 for (i=0; i<conf->copies; i++) 1117 for (i=0; i<conf->copies; i++)
1118 if (r10_bio->devs[i].bio == bio) 1118 if (r10_bio->devs[i].bio == bio)
1119 break; 1119 break;
1120 if (i == conf->copies) 1120 BUG_ON(i == conf->copies);
1121 BUG();
1122 update_head_pos(i, r10_bio); 1121 update_head_pos(i, r10_bio);
1123 d = r10_bio->devs[i].devnum; 1122 d = r10_bio->devs[i].devnum;
1124 1123
@@ -1518,8 +1517,7 @@ static int init_resync(conf_t *conf)
1518 int buffs; 1517 int buffs;
1519 1518
1520 buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE; 1519 buffs = RESYNC_WINDOW / RESYNC_BLOCK_SIZE;
1521 if (conf->r10buf_pool) 1520 BUG_ON(conf->r10buf_pool);
1522 BUG();
1523 conf->r10buf_pool = mempool_create(buffs, r10buf_pool_alloc, r10buf_pool_free, conf); 1521 conf->r10buf_pool = mempool_create(buffs, r10buf_pool_alloc, r10buf_pool_free, conf);
1524 if (!conf->r10buf_pool) 1522 if (!conf->r10buf_pool)
1525 return -ENOMEM; 1523 return -ENOMEM;
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index dae740adaf65..31843604049c 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -73,10 +73,8 @@ static void print_raid5_conf (raid5_conf_t *conf);
73static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) 73static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
74{ 74{
75 if (atomic_dec_and_test(&sh->count)) { 75 if (atomic_dec_and_test(&sh->count)) {
76 if (!list_empty(&sh->lru)) 76 BUG_ON(!list_empty(&sh->lru));
77 BUG(); 77 BUG_ON(atomic_read(&conf->active_stripes)==0);
78 if (atomic_read(&conf->active_stripes)==0)
79 BUG();
80 if (test_bit(STRIPE_HANDLE, &sh->state)) { 78 if (test_bit(STRIPE_HANDLE, &sh->state)) {
81 if (test_bit(STRIPE_DELAYED, &sh->state)) 79 if (test_bit(STRIPE_DELAYED, &sh->state))
82 list_add_tail(&sh->lru, &conf->delayed_list); 80 list_add_tail(&sh->lru, &conf->delayed_list);
@@ -184,10 +182,8 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int
184 raid5_conf_t *conf = sh->raid_conf; 182 raid5_conf_t *conf = sh->raid_conf;
185 int i; 183 int i;
186 184
187 if (atomic_read(&sh->count) != 0) 185 BUG_ON(atomic_read(&sh->count) != 0);
188 BUG(); 186 BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
189 if (test_bit(STRIPE_HANDLE, &sh->state))
190 BUG();
191 187
192 CHECK_DEVLOCK(); 188 CHECK_DEVLOCK();
193 PRINTK("init_stripe called, stripe %llu\n", 189 PRINTK("init_stripe called, stripe %llu\n",
@@ -269,8 +265,7 @@ static struct stripe_head *get_active_stripe(raid5_conf_t *conf, sector_t sector
269 init_stripe(sh, sector, pd_idx, disks); 265 init_stripe(sh, sector, pd_idx, disks);
270 } else { 266 } else {
271 if (atomic_read(&sh->count)) { 267 if (atomic_read(&sh->count)) {
272 if (!list_empty(&sh->lru)) 268 BUG_ON(!list_empty(&sh->lru));
273 BUG();
274 } else { 269 } else {
275 if (!test_bit(STRIPE_HANDLE, &sh->state)) 270 if (!test_bit(STRIPE_HANDLE, &sh->state))
276 atomic_inc(&conf->active_stripes); 271 atomic_inc(&conf->active_stripes);
@@ -465,8 +460,7 @@ static int drop_one_stripe(raid5_conf_t *conf)
465 spin_unlock_irq(&conf->device_lock); 460 spin_unlock_irq(&conf->device_lock);
466 if (!sh) 461 if (!sh)
467 return 0; 462 return 0;
468 if (atomic_read(&sh->count)) 463 BUG_ON(atomic_read(&sh->count));
469 BUG();
470 shrink_buffers(sh, conf->pool_size); 464 shrink_buffers(sh, conf->pool_size);
471 kmem_cache_free(conf->slab_cache, sh); 465 kmem_cache_free(conf->slab_cache, sh);
472 atomic_dec(&conf->active_stripes); 466 atomic_dec(&conf->active_stripes);
@@ -882,8 +876,7 @@ static void compute_parity(struct stripe_head *sh, int method)
882 ptr[0] = page_address(sh->dev[pd_idx].page); 876 ptr[0] = page_address(sh->dev[pd_idx].page);
883 switch(method) { 877 switch(method) {
884 case READ_MODIFY_WRITE: 878 case READ_MODIFY_WRITE:
885 if (!test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags)) 879 BUG_ON(!test_bit(R5_UPTODATE, &sh->dev[pd_idx].flags));
886 BUG();
887 for (i=disks ; i-- ;) { 880 for (i=disks ; i-- ;) {
888 if (i==pd_idx) 881 if (i==pd_idx)
889 continue; 882 continue;
@@ -896,7 +889,7 @@ static void compute_parity(struct stripe_head *sh, int method)
896 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 889 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
897 wake_up(&conf->wait_for_overlap); 890 wake_up(&conf->wait_for_overlap);
898 891
899 if (sh->dev[i].written) BUG(); 892 BUG_ON(sh->dev[i].written);
900 sh->dev[i].written = chosen; 893 sh->dev[i].written = chosen;
901 check_xor(); 894 check_xor();
902 } 895 }
@@ -912,7 +905,7 @@ static void compute_parity(struct stripe_head *sh, int method)
912 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 905 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
913 wake_up(&conf->wait_for_overlap); 906 wake_up(&conf->wait_for_overlap);
914 907
915 if (sh->dev[i].written) BUG(); 908 BUG_ON(sh->dev[i].written);
916 sh->dev[i].written = chosen; 909 sh->dev[i].written = chosen;
917 } 910 }
918 break; 911 break;
@@ -995,8 +988,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
995 if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) 988 if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9))
996 goto overlap; 989 goto overlap;
997 990
998 if (*bip && bi->bi_next && (*bip) != bi->bi_next) 991 BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next);
999 BUG();
1000 if (*bip) 992 if (*bip)
1001 bi->bi_next = *bip; 993 bi->bi_next = *bip;
1002 *bip = bi; 994 *bip = bi;
@@ -1430,8 +1422,7 @@ static void handle_stripe(struct stripe_head *sh)
1430 set_bit(STRIPE_HANDLE, &sh->state); 1422 set_bit(STRIPE_HANDLE, &sh->state);
1431 if (failed == 0) { 1423 if (failed == 0) {
1432 char *pagea; 1424 char *pagea;
1433 if (uptodate != disks) 1425 BUG_ON(uptodate != disks);
1434 BUG();
1435 compute_parity(sh, CHECK_PARITY); 1426 compute_parity(sh, CHECK_PARITY);
1436 uptodate--; 1427 uptodate--;
1437 pagea = page_address(sh->dev[sh->pd_idx].page); 1428 pagea = page_address(sh->dev[sh->pd_idx].page);
@@ -2096,8 +2087,7 @@ static void raid5d (mddev_t *mddev)
2096 2087
2097 list_del_init(first); 2088 list_del_init(first);
2098 atomic_inc(&sh->count); 2089 atomic_inc(&sh->count);
2099 if (atomic_read(&sh->count)!= 1) 2090 BUG_ON(atomic_read(&sh->count)!= 1);
2100 BUG();
2101 spin_unlock_irq(&conf->device_lock); 2091 spin_unlock_irq(&conf->device_lock);
2102 2092
2103 handled++; 2093 handled++;
diff --git a/drivers/md/raid6main.c b/drivers/md/raid6main.c
index 6df4930fddec..bc69355e0100 100644
--- a/drivers/md/raid6main.c
+++ b/drivers/md/raid6main.c
@@ -91,10 +91,8 @@ static void print_raid6_conf (raid6_conf_t *conf);
91static void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh) 91static void __release_stripe(raid6_conf_t *conf, struct stripe_head *sh)
92{ 92{
93 if (atomic_dec_and_test(&sh->count)) { 93 if (atomic_dec_and_test(&sh->count)) {
94 if (!list_empty(&sh->lru)) 94 BUG_ON(!list_empty(&sh->lru));
95 BUG(); 95 BUG_ON(atomic_read(&conf->active_stripes)==0);
96 if (atomic_read(&conf->active_stripes)==0)
97 BUG();
98 if (test_bit(STRIPE_HANDLE, &sh->state)) { 96 if (test_bit(STRIPE_HANDLE, &sh->state)) {
99 if (test_bit(STRIPE_DELAYED, &sh->state)) 97 if (test_bit(STRIPE_DELAYED, &sh->state))
100 list_add_tail(&sh->lru, &conf->delayed_list); 98 list_add_tail(&sh->lru, &conf->delayed_list);
@@ -202,10 +200,8 @@ static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx)
202 raid6_conf_t *conf = sh->raid_conf; 200 raid6_conf_t *conf = sh->raid_conf;
203 int disks = conf->raid_disks, i; 201 int disks = conf->raid_disks, i;
204 202
205 if (atomic_read(&sh->count) != 0) 203 BUG_ON(atomic_read(&sh->count) != 0);
206 BUG(); 204 BUG_ON(test_bit(STRIPE_HANDLE, &sh->state));
207 if (test_bit(STRIPE_HANDLE, &sh->state))
208 BUG();
209 205
210 CHECK_DEVLOCK(); 206 CHECK_DEVLOCK();
211 PRINTK("init_stripe called, stripe %llu\n", 207 PRINTK("init_stripe called, stripe %llu\n",
@@ -284,13 +280,11 @@ static struct stripe_head *get_active_stripe(raid6_conf_t *conf, sector_t sector
284 init_stripe(sh, sector, pd_idx); 280 init_stripe(sh, sector, pd_idx);
285 } else { 281 } else {
286 if (atomic_read(&sh->count)) { 282 if (atomic_read(&sh->count)) {
287 if (!list_empty(&sh->lru)) 283 BUG_ON(!list_empty(&sh->lru));
288 BUG();
289 } else { 284 } else {
290 if (!test_bit(STRIPE_HANDLE, &sh->state)) 285 if (!test_bit(STRIPE_HANDLE, &sh->state))
291 atomic_inc(&conf->active_stripes); 286 atomic_inc(&conf->active_stripes);
292 if (list_empty(&sh->lru)) 287 BUG_ON(list_empty(&sh->lru));
293 BUG();
294 list_del_init(&sh->lru); 288 list_del_init(&sh->lru);
295 } 289 }
296 } 290 }
@@ -353,8 +347,7 @@ static int drop_one_stripe(raid6_conf_t *conf)
353 spin_unlock_irq(&conf->device_lock); 347 spin_unlock_irq(&conf->device_lock);
354 if (!sh) 348 if (!sh)
355 return 0; 349 return 0;
356 if (atomic_read(&sh->count)) 350 BUG_ON(atomic_read(&sh->count));
357 BUG();
358 shrink_buffers(sh, conf->raid_disks); 351 shrink_buffers(sh, conf->raid_disks);
359 kmem_cache_free(conf->slab_cache, sh); 352 kmem_cache_free(conf->slab_cache, sh);
360 atomic_dec(&conf->active_stripes); 353 atomic_dec(&conf->active_stripes);
@@ -780,7 +773,7 @@ static void compute_parity(struct stripe_head *sh, int method)
780 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags)) 773 if (test_and_clear_bit(R5_Overlap, &sh->dev[i].flags))
781 wake_up(&conf->wait_for_overlap); 774 wake_up(&conf->wait_for_overlap);
782 775
783 if (sh->dev[i].written) BUG(); 776 BUG_ON(sh->dev[i].written);
784 sh->dev[i].written = chosen; 777 sh->dev[i].written = chosen;
785 } 778 }
786 break; 779 break;
@@ -970,8 +963,7 @@ static int add_stripe_bio(struct stripe_head *sh, struct bio *bi, int dd_idx, in
970 if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9)) 963 if (*bip && (*bip)->bi_sector < bi->bi_sector + ((bi->bi_size)>>9))
971 goto overlap; 964 goto overlap;
972 965
973 if (*bip && bi->bi_next && (*bip) != bi->bi_next) 966 BUG_ON(*bip && bi->bi_next && (*bip) != bi->bi_next);
974 BUG();
975 if (*bip) 967 if (*bip)
976 bi->bi_next = *bip; 968 bi->bi_next = *bip;
977 *bip = bi; 969 *bip = bi;
@@ -1906,8 +1898,7 @@ static void raid6d (mddev_t *mddev)
1906 1898
1907 list_del_init(first); 1899 list_del_init(first);
1908 atomic_inc(&sh->count); 1900 atomic_inc(&sh->count);
1909 if (atomic_read(&sh->count)!= 1) 1901 BUG_ON(atomic_read(&sh->count)!= 1);
1910 BUG();
1911 spin_unlock_irq(&conf->device_lock); 1902 spin_unlock_irq(&conf->device_lock);
1912 1903
1913 handled++; 1904 handled++;
@@ -2151,6 +2142,8 @@ static int run(mddev_t *mddev)
2151 } 2142 }
2152 2143
2153 /* Ok, everything is just fine now */ 2144 /* Ok, everything is just fine now */
2145 sysfs_create_group(&mddev->kobj, &raid6_attrs_group);
2146
2154 mddev->array_size = mddev->size * (mddev->raid_disks - 2); 2147 mddev->array_size = mddev->size * (mddev->raid_disks - 2);
2155 2148
2156 mddev->queue->unplug_fn = raid6_unplug_device; 2149 mddev->queue->unplug_fn = raid6_unplug_device;
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index baa9f58beffc..fffc711c260c 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -51,18 +51,18 @@ config VIDEO_TVEEPROM
51 tristate 51 tristate
52 52
53config USB_DABUSB 53config USB_DABUSB
54 tristate "DABUSB driver" 54 tristate "DABUSB driver"
55 depends on USB 55 depends on USB
56 ---help--- 56 ---help---
57 A Digital Audio Broadcasting (DAB) Receiver for USB and Linux 57 A Digital Audio Broadcasting (DAB) Receiver for USB and Linux
58 brought to you by the DAB-Team 58 brought to you by the DAB-Team
59 <http://wwwbode.cs.tum.edu/Par/arch/dab/>. This driver can be taken 59 <http://wwwbode.cs.tum.edu/Par/arch/dab/>. This driver can be taken
60 as an example for URB-based bulk, control, and isochronous 60 as an example for URB-based bulk, control, and isochronous
61 transactions. URB's are explained in 61 transactions. URB's are explained in
62 <Documentation/usb/URB.txt>. 62 <Documentation/usb/URB.txt>.
63 63
64 To compile this driver as a module, choose M here: the 64 To compile this driver as a module, choose M here: the
65 module will be called dabusb. 65 module will be called dabusb.
66 66
67endmenu 67endmenu
68 68
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index 2337b41714e0..376ca48f1d1d 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -7,6 +7,7 @@ config DVB_BT8XX
7 select DVB_CX24110 7 select DVB_CX24110
8 select DVB_OR51211 8 select DVB_OR51211
9 select DVB_LGDT330X 9 select DVB_LGDT330X
10 select FW_LOADER
10 help 11 help
11 Support for PCI cards based on the Bt8xx PCI bridge. Examples are 12 Support for PCI cards based on the Bt8xx PCI bridge. Examples are
12 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards, 13 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards,
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 09e96e9ddbdf..04578df3f249 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -141,12 +141,18 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
141 } 141 }
142 142
143 if ((file->f_flags & O_ACCMODE) == O_RDONLY) { 143 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
144 void *mem = vmalloc(DVR_BUFFER_SIZE); 144 void *mem;
145 if (!dvbdev->readers) {
146 mutex_unlock(&dmxdev->mutex);
147 return -EBUSY;
148 }
149 mem = vmalloc(DVR_BUFFER_SIZE);
145 if (!mem) { 150 if (!mem) {
146 mutex_unlock(&dmxdev->mutex); 151 mutex_unlock(&dmxdev->mutex);
147 return -ENOMEM; 152 return -ENOMEM;
148 } 153 }
149 dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE); 154 dvb_ringbuffer_init(&dmxdev->dvr_buffer, mem, DVR_BUFFER_SIZE);
155 dvbdev->readers--;
150 } 156 }
151 157
152 if ((file->f_flags & O_ACCMODE) == O_WRONLY) { 158 if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
@@ -184,6 +190,7 @@ static int dvb_dvr_release(struct inode *inode, struct file *file)
184 dmxdev->dvr_orig_fe); 190 dmxdev->dvr_orig_fe);
185 } 191 }
186 if ((file->f_flags & O_ACCMODE) == O_RDONLY) { 192 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
193 dvbdev->readers++;
187 if (dmxdev->dvr_buffer.data) { 194 if (dmxdev->dvr_buffer.data) {
188 void *mem = dmxdev->dvr_buffer.data; 195 void *mem = dmxdev->dvr_buffer.data;
189 mb(); 196 mb();
@@ -1029,8 +1036,7 @@ static struct file_operations dvb_dvr_fops = {
1029 1036
1030static struct dvb_device dvbdev_dvr = { 1037static struct dvb_device dvbdev_dvr = {
1031 .priv = NULL, 1038 .priv = NULL,
1032 .users = 1, 1039 .readers = 1,
1033 .writers = 1,
1034 .fops = &dvb_dvr_fops 1040 .fops = &dvb_dvr_fops
1035}; 1041};
1036 1042
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 2c3ea8f95dcd..4f8f257e6795 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -105,6 +105,7 @@ struct dvb_frontend_private {
105 fe_status_t status; 105 fe_status_t status;
106 unsigned long tune_mode_flags; 106 unsigned long tune_mode_flags;
107 unsigned int delay; 107 unsigned int delay;
108 unsigned int reinitialise;
108 109
109 /* swzigzag values */ 110 /* swzigzag values */
110 unsigned int state; 111 unsigned int state;
@@ -121,6 +122,7 @@ struct dvb_frontend_private {
121 unsigned int check_wrapped; 122 unsigned int check_wrapped;
122}; 123};
123 124
125static void dvb_frontend_wakeup(struct dvb_frontend *fe);
124 126
125static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status) 127static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
126{ 128{
@@ -213,6 +215,15 @@ static void dvb_frontend_init(struct dvb_frontend *fe)
213 fe->ops->init(fe); 215 fe->ops->init(fe);
214} 216}
215 217
218void dvb_frontend_reinitialise(struct dvb_frontend *fe)
219{
220 struct dvb_frontend_private *fepriv = fe->frontend_priv;
221
222 fepriv->reinitialise = 1;
223 dvb_frontend_wakeup(fe);
224}
225EXPORT_SYMBOL(dvb_frontend_reinitialise);
226
216static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked) 227static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked)
217{ 228{
218 int q2; 229 int q2;
@@ -505,8 +516,8 @@ static int dvb_frontend_thread(void *data)
505 fepriv->quality = 0; 516 fepriv->quality = 0;
506 fepriv->delay = 3*HZ; 517 fepriv->delay = 3*HZ;
507 fepriv->status = 0; 518 fepriv->status = 0;
508 dvb_frontend_init(fe);
509 fepriv->wakeup = 0; 519 fepriv->wakeup = 0;
520 fepriv->reinitialise = 1;
510 521
511 while (1) { 522 while (1) {
512 up(&fepriv->sem); /* is locked when we enter the thread... */ 523 up(&fepriv->sem); /* is locked when we enter the thread... */
@@ -524,6 +535,11 @@ static int dvb_frontend_thread(void *data)
524 if (down_interruptible(&fepriv->sem)) 535 if (down_interruptible(&fepriv->sem))
525 break; 536 break;
526 537
538 if (fepriv->reinitialise) {
539 dvb_frontend_init(fe);
540 fepriv->reinitialise = 0;
541 }
542
527 /* do an iteration of the tuning loop */ 543 /* do an iteration of the tuning loop */
528 if (fe->ops->tune) { 544 if (fe->ops->tune) {
529 /* have we been asked to retune? */ 545 /* have we been asked to retune? */
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index d5aee5ad67a0..5926a3b745c9 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -112,6 +112,8 @@ extern int dvb_register_frontend(struct dvb_adapter* dvb,
112 112
113extern int dvb_unregister_frontend(struct dvb_frontend* fe); 113extern int dvb_unregister_frontend(struct dvb_frontend* fe);
114 114
115extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
116
115extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec); 117extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec);
116extern s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime); 118extern s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime);
117 119
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index a14e737ec848..7edd6362b9cc 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -233,6 +233,45 @@ static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
233 { 0xfe, 0x4e, KEY_POWER }, 233 { 0xfe, 0x4e, KEY_POWER },
234}; 234};
235 235
236static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
237 { 0xfc, 0x02, KEY_SETUP }, /* Profile */
238 { 0xfc, 0x43, KEY_POWER2 },
239 { 0xfc, 0x06, KEY_EPG },
240 { 0xfc, 0x5a, KEY_BACK },
241 { 0xfc, 0x05, KEY_MENU },
242 { 0xfc, 0x47, KEY_INFO },
243 { 0xfc, 0x01, KEY_TAB },
244 { 0xfc, 0x42, KEY_PREVIOUSSONG },/* Replay */
245 { 0xfc, 0x49, KEY_VOLUMEUP },
246 { 0xfc, 0x09, KEY_VOLUMEDOWN },
247 { 0xfc, 0x54, KEY_CHANNELUP },
248 { 0xfc, 0x0b, KEY_CHANNELDOWN },
249 { 0xfc, 0x16, KEY_CAMERA },
250 { 0xfc, 0x40, KEY_TUNER }, /* ATV/DTV */
251 { 0xfc, 0x45, KEY_OPEN },
252 { 0xfc, 0x19, KEY_1 },
253 { 0xfc, 0x18, KEY_2 },
254 { 0xfc, 0x1b, KEY_3 },
255 { 0xfc, 0x1a, KEY_4 },
256 { 0xfc, 0x58, KEY_5 },
257 { 0xfc, 0x59, KEY_6 },
258 { 0xfc, 0x15, KEY_7 },
259 { 0xfc, 0x14, KEY_8 },
260 { 0xfc, 0x17, KEY_9 },
261 { 0xfc, 0x44, KEY_ANGLE }, /* Aspect */
262 { 0xfc, 0x55, KEY_0 },
263 { 0xfc, 0x07, KEY_ZOOM },
264 { 0xfc, 0x0a, KEY_REWIND },
265 { 0xfc, 0x08, KEY_PLAYPAUSE },
266 { 0xfc, 0x4b, KEY_FASTFORWARD },
267 { 0xfc, 0x5b, KEY_MUTE },
268 { 0xfc, 0x04, KEY_STOP },
269 { 0xfc, 0x56, KEY_RECORD },
270 { 0xfc, 0x57, KEY_POWER },
271 { 0xfc, 0x41, KEY_UNKNOWN }, /* INPUT */
272 { 0xfc, 0x00, KEY_UNKNOWN }, /* HD */
273};
274
236static int cxusb_dee1601_demod_init(struct dvb_frontend* fe) 275static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
237{ 276{
238 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 }; 277 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
@@ -511,6 +550,11 @@ static struct dvb_usb_properties cxusb_bluebird_lgh064f_properties = {
511 550
512 .i2c_algo = &cxusb_i2c_algo, 551 .i2c_algo = &cxusb_i2c_algo,
513 552
553 .rc_interval = 100,
554 .rc_key_map = dvico_portable_rc_keys,
555 .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
556 .rc_query = cxusb_rc_query,
557
514 .generic_bulk_ctrl_endpoint = 0x01, 558 .generic_bulk_ctrl_endpoint = 0x01,
515 /* parameter for the MPEG2-data transfer */ 559 /* parameter for the MPEG2-data transfer */
516 .urb = { 560 .urb = {
@@ -600,6 +644,11 @@ static struct dvb_usb_properties cxusb_bluebird_lgz201_properties = {
600 644
601 .i2c_algo = &cxusb_i2c_algo, 645 .i2c_algo = &cxusb_i2c_algo,
602 646
647 .rc_interval = 100,
648 .rc_key_map = dvico_portable_rc_keys,
649 .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
650 .rc_query = cxusb_rc_query,
651
603 .generic_bulk_ctrl_endpoint = 0x01, 652 .generic_bulk_ctrl_endpoint = 0x01,
604 /* parameter for the MPEG2-data transfer */ 653 /* parameter for the MPEG2-data transfer */
605 .urb = { 654 .urb = {
@@ -640,6 +689,11 @@ static struct dvb_usb_properties cxusb_bluebird_dtt7579_properties = {
640 689
641 .i2c_algo = &cxusb_i2c_algo, 690 .i2c_algo = &cxusb_i2c_algo,
642 691
692 .rc_interval = 100,
693 .rc_key_map = dvico_portable_rc_keys,
694 .rc_key_map_size = ARRAY_SIZE(dvico_portable_rc_keys),
695 .rc_query = cxusb_rc_query,
696
643 .generic_bulk_ctrl_endpoint = 0x01, 697 .generic_bulk_ctrl_endpoint = 0x01,
644 /* parameter for the MPEG2-data transfer */ 698 /* parameter for the MPEG2-data transfer */
645 .urb = { 699 .urb = {
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index 12ebaf8bddca..70afcfd141ca 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -94,12 +94,14 @@ static int dtt200u_frontend_attach(struct dvb_usb_device *d)
94 94
95static struct dvb_usb_properties dtt200u_properties; 95static struct dvb_usb_properties dtt200u_properties;
96static struct dvb_usb_properties wt220u_properties; 96static struct dvb_usb_properties wt220u_properties;
97static struct dvb_usb_properties wt220u_zl0353_properties;
97 98
98static int dtt200u_usb_probe(struct usb_interface *intf, 99static int dtt200u_usb_probe(struct usb_interface *intf,
99 const struct usb_device_id *id) 100 const struct usb_device_id *id)
100{ 101{
101 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 || 102 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 ||
102 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0) 103 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0 ||
104 dvb_usb_device_init(intf,&wt220u_zl0353_properties,THIS_MODULE,NULL) == 0)
103 return 0; 105 return 0;
104 106
105 return -ENODEV; 107 return -ENODEV;
@@ -110,6 +112,8 @@ static struct usb_device_id dtt200u_usb_table [] = {
110 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_WARM) }, 112 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_DTT200U_WARM) },
111 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_COLD) }, 113 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_COLD) },
112 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) }, 114 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_WARM) },
115 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZL0353_COLD) },
116 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZL0353_WARM) },
113 { 0 }, 117 { 0 },
114}; 118};
115MODULE_DEVICE_TABLE(usb, dtt200u_usb_table); 119MODULE_DEVICE_TABLE(usb, dtt200u_usb_table);
@@ -196,6 +200,47 @@ static struct dvb_usb_properties wt220u_properties = {
196 } 200 }
197}; 201};
198 202
203static struct dvb_usb_properties wt220u_zl0353_properties = {
204 .caps = DVB_USB_HAS_PID_FILTER | DVB_USB_NEED_PID_FILTERING,
205 .pid_filter_count = 15,
206
207 .usb_ctrl = CYPRESS_FX2,
208 .firmware = "dvb-usb-wt220u-zl0353-01.fw",
209
210 .power_ctrl = dtt200u_power_ctrl,
211 .streaming_ctrl = dtt200u_streaming_ctrl,
212 .pid_filter = dtt200u_pid_filter,
213 .frontend_attach = dtt200u_frontend_attach,
214
215 .rc_interval = 300,
216 .rc_key_map = dtt200u_rc_keys,
217 .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
218 .rc_query = dtt200u_rc_query,
219
220 .generic_bulk_ctrl_endpoint = 0x01,
221
222 /* parameter for the MPEG2-data transfer */
223 .urb = {
224 .type = DVB_USB_BULK,
225 .count = 7,
226 .endpoint = 0x02,
227 .u = {
228 .bulk = {
229 .buffersize = 4096,
230 }
231 }
232 },
233
234 .num_device_descs = 1,
235 .devices = {
236 { .name = "WideView WT-220U PenType Receiver (based on ZL353)",
237 .cold_ids = { &dtt200u_usb_table[4], NULL },
238 .warm_ids = { &dtt200u_usb_table[5], NULL },
239 },
240 { NULL },
241 }
242};
243
199/* usb specific object needed to register this driver with the usb subsystem */ 244/* usb specific object needed to register this driver with the usb subsystem */
200static struct usb_driver dtt200u_usb_driver = { 245static struct usb_driver dtt200u_usb_driver = {
201 .name = "dvb_usb_dtt200u", 246 .name = "dvb_usb_dtt200u",
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 4a1b9e77e339..cb239049b098 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -83,6 +83,8 @@
83#define USB_PID_DTT200U_WARM 0x0301 83#define USB_PID_DTT200U_WARM 0x0301
84#define USB_PID_WT220U_COLD 0x0222 84#define USB_PID_WT220U_COLD 0x0222
85#define USB_PID_WT220U_WARM 0x0221 85#define USB_PID_WT220U_WARM 0x0221
86#define USB_PID_WT220U_ZL0353_COLD 0x022a
87#define USB_PID_WT220U_ZL0353_WARM 0x022b
86#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300 88#define USB_PID_WINTV_NOVA_T_USB2_COLD 0x9300
87#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301 89#define USB_PID_WINTV_NOVA_T_USB2_WARM 0x9301
88#define USB_PID_NEBULA_DIGITV 0x0201 90#define USB_PID_NEBULA_DIGITV 0x0201
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c
index b6d95e1c9c52..2a89f8c5da99 100644
--- a/drivers/media/dvb/dvb-usb/vp702x-fe.c
+++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c
@@ -147,8 +147,9 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
147 cmd[4] = (sr >> 4) & 0xff; 147 cmd[4] = (sr >> 4) & 0xff;
148 cmd[5] = (sr << 4) & 0xf0; 148 cmd[5] = (sr << 4) & 0xf0;
149 149
150 deb_fe("setting frontend to: %u -> %u (%x) LNB-based GHz, symbolrate: %d -> %Lu (%Lx)\n", 150 deb_fe("setting frontend to: %u -> %u (%x) LNB-based GHz, symbolrate: %d -> %lu (%lx)\n",
151 fep->frequency,freq,freq, fep->u.qpsk.symbol_rate, sr, sr); 151 fep->frequency,freq,freq, fep->u.qpsk.symbol_rate,
152 (unsigned long) sr, (unsigned long) sr);
152 153
153/* if (fep->inversion == INVERSION_ON) 154/* if (fep->inversion == INVERSION_ON)
154 cmd[6] |= 0x80; */ 155 cmd[6] |= 0x80; */
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 94233168d241..37d5e0af1683 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -181,6 +181,11 @@ config DVB_OR51211
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.
183 183
184 This driver needs external firmware. Please use the command
185 "<kerneldir>/Documentation/dvb/get_dvb_firmware or51211" to
186 download it, and then copy it to /usr/lib/hotplug/firmware
187 or /lib/firmware (depending on configuration of firmware hotplug).
188
184config DVB_OR51132 189config DVB_OR51132
185 tristate "Oren OR51132 based" 190 tristate "Oren OR51132 based"
186 depends on DVB_CORE 191 depends on DVB_CORE
@@ -189,6 +194,13 @@ config DVB_OR51132
189 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
190 to support this frontend. 195 to support this frontend.
191 196
197 This driver needs external firmware. Please use the commands
198 "<kerneldir>/Documentation/dvb/get_dvb_firmware or51132_vsb" and/or
199 "<kerneldir>/Documentation/dvb/get_dvb_firmware or51132_qam" to
200 download firmwares for 8VSB and QAM64/256, respectively. Copy them to
201 /usr/lib/hotplug/firmware or /lib/firmware (depending on
202 configuration of firmware hotplug).
203
192config DVB_BCM3510 204config DVB_BCM3510
193 tristate "Broadcom BCM3510" 205 tristate "Broadcom BCM3510"
194 depends on DVB_CORE 206 depends on DVB_CORE
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 8e8df7b4ca0e..b83dafa4e12c 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -52,7 +52,6 @@ struct tda1004x_state {
52 struct dvb_frontend frontend; 52 struct dvb_frontend frontend;
53 53
54 /* private demod data */ 54 /* private demod data */
55 u8 initialised;
56 enum tda1004x_demod demod_type; 55 enum tda1004x_demod demod_type;
57}; 56};
58 57
@@ -594,9 +593,6 @@ static int tda10045_init(struct dvb_frontend* fe)
594 593
595 dprintk("%s\n", __FUNCTION__); 594 dprintk("%s\n", __FUNCTION__);
596 595
597 if (state->initialised)
598 return 0;
599
600 if (tda10045_fwupload(fe)) { 596 if (tda10045_fwupload(fe)) {
601 printk("tda1004x: firmware upload failed\n"); 597 printk("tda1004x: firmware upload failed\n");
602 return -EIO; 598 return -EIO;
@@ -626,7 +622,6 @@ static int tda10045_init(struct dvb_frontend* fe)
626 622
627 tda1004x_write_mask(state, 0x1f, 0x01, state->config->invert_oclk); 623 tda1004x_write_mask(state, 0x1f, 0x01, state->config->invert_oclk);
628 624
629 state->initialised = 1;
630 return 0; 625 return 0;
631} 626}
632 627
@@ -635,9 +630,6 @@ static int tda10046_init(struct dvb_frontend* fe)
635 struct tda1004x_state* state = fe->demodulator_priv; 630 struct tda1004x_state* state = fe->demodulator_priv;
636 dprintk("%s\n", __FUNCTION__); 631 dprintk("%s\n", __FUNCTION__);
637 632
638 if (state->initialised)
639 return 0;
640
641 if (tda10046_fwupload(fe)) { 633 if (tda10046_fwupload(fe)) {
642 printk("tda1004x: firmware upload failed\n"); 634 printk("tda1004x: firmware upload failed\n");
643 return -EIO; 635 return -EIO;
@@ -697,7 +689,6 @@ static int tda10046_init(struct dvb_frontend* fe)
697 // tda1004x_write_mask(state, 0x50, 0x80, 0x80); // handle out of guard echoes 689 // tda1004x_write_mask(state, 0x50, 0x80, 0x80); // handle out of guard echoes
698 tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7); 690 tda1004x_write_mask(state, 0x3a, 0x80, state->config->invert_oclk << 7);
699 691
700 state->initialised = 1;
701 return 0; 692 return 0;
702} 693}
703 694
@@ -1207,7 +1198,6 @@ static int tda1004x_sleep(struct dvb_frontend* fe)
1207 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1); 1198 tda1004x_write_mask(state, TDA1004X_CONFC4, 1, 1);
1208 break; 1199 break;
1209 } 1200 }
1210 state->initialised = 0;
1211 1201
1212 return 0; 1202 return 0;
1213} 1203}
@@ -1271,7 +1261,6 @@ struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
1271 state->config = config; 1261 state->config = config;
1272 state->i2c = i2c; 1262 state->i2c = i2c;
1273 memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops)); 1263 memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops));
1274 state->initialised = 0;
1275 state->demod_type = TDA1004X_DEMOD_TDA10045; 1264 state->demod_type = TDA1004X_DEMOD_TDA10045;
1276 1265
1277 /* check if the demod is there */ 1266 /* check if the demod is there */
@@ -1330,7 +1319,6 @@ struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
1330 state->config = config; 1319 state->config = config;
1331 state->i2c = i2c; 1320 state->i2c = i2c;
1332 memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops)); 1321 memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops));
1333 state->initialised = 0;
1334 state->demod_type = TDA1004X_DEMOD_TDA10046; 1322 state->demod_type = TDA1004X_DEMOD_TDA10046;
1335 1323
1336 /* check if the demod is there */ 1324 /* check if the demod is there */
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 840efec32cb6..d028245c8eed 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -87,6 +87,7 @@ static int volume = 255;
87static int budgetpatch; 87static int budgetpatch;
88static int wss_cfg_4_3 = 0x4008; 88static int wss_cfg_4_3 = 0x4008;
89static int wss_cfg_16_9 = 0x0007; 89static int wss_cfg_16_9 = 0x0007;
90static int tv_standard;
90 91
91module_param_named(debug, av7110_debug, int, 0644); 92module_param_named(debug, av7110_debug, int, 0644);
92MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)"); 93MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)");
@@ -109,6 +110,8 @@ module_param(wss_cfg_4_3, int, 0444);
109MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data"); 110MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data");
110module_param(wss_cfg_16_9, int, 0444); 111module_param(wss_cfg_16_9, int, 0444);
111MODULE_PARM_DESC(wss_cfg_16_9, "WSS 16:9 - default 0x0007 - bit 15: disable, 14: burst mode, 13..0: wss data"); 112MODULE_PARM_DESC(wss_cfg_16_9, "WSS 16:9 - default 0x0007 - bit 15: disable, 14: burst mode, 13..0: wss data");
113module_param(tv_standard, int, 0444);
114MODULE_PARM_DESC(tv_standard, "TV standard: 0 PAL (default), 1 NTSC");
112 115
113static void restart_feeds(struct av7110 *av7110); 116static void restart_feeds(struct av7110 *av7110);
114 117
@@ -2123,7 +2126,7 @@ static int frontend_init(struct av7110 *av7110)
2123 read_pwm(av7110)); 2126 read_pwm(av7110));
2124 break; 2127 break;
2125 case 0x0003: 2128 case 0x0003:
2126 /* Haupauge DVB-C 2.1 VES1820/ALPS TDBE2 */ 2129 /* Hauppauge DVB-C 2.1 VES1820/ALPS TDBE2 */
2127 av7110->fe = ves1820_attach(&alps_tdbe2_config, &av7110->i2c_adap, 2130 av7110->fe = ves1820_attach(&alps_tdbe2_config, &av7110->i2c_adap,
2128 read_pwm(av7110)); 2131 read_pwm(av7110));
2129 break; 2132 break;
@@ -2543,6 +2546,9 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2543 av7110->osdwin = 1; 2546 av7110->osdwin = 1;
2544 mutex_init(&av7110->osd_mutex); 2547 mutex_init(&av7110->osd_mutex);
2545 2548
2549 /* TV standard */
2550 av7110->vidmode = tv_standard == 1 ? VIDEO_MODE_NTSC : VIDEO_MODE_PAL;
2551
2546 /* ARM "watchdog" */ 2552 /* ARM "watchdog" */
2547 init_waitqueue_head(&av7110->arm_wait); 2553 init_waitqueue_head(&av7110->arm_wait);
2548 av7110->arm_thread = NULL; 2554 av7110->arm_thread = NULL;
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index 400facec7407..2eff09f638d3 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -1479,8 +1479,6 @@ int av7110_av_init(struct av7110 *av7110)
1479 void (*play[])(u8 *, int, void *) = { play_audio_cb, play_video_cb }; 1479 void (*play[])(u8 *, int, void *) = { play_audio_cb, play_video_cb };
1480 int i, ret; 1480 int i, ret;
1481 1481
1482 av7110->vidmode = VIDEO_MODE_PAL;
1483
1484 for (i = 0; i < 2; i++) { 1482 for (i = 0; i < 2; i++) {
1485 struct ipack *ipack = av7110->ipack + i; 1483 struct ipack *ipack = av7110->ipack + i;
1486 1484
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 9dd4745f5312..8efe3ce5f66c 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -60,11 +60,11 @@ struct budget_av {
60 struct dvb_ca_en50221 ca; 60 struct dvb_ca_en50221 ca;
61}; 61};
62 62
63/* GPIO CI Connections: 63/* GPIO Connections:
64 * 0 - Vcc/Reset (Reset is controlled by capacitor) 64 * 0 - Vcc/Reset (Reset is controlled by capacitor). Resets the frontend *AS WELL*!
65 * 1 - Attribute Memory 65 * 1 - CI memory select 0=>IO memory, 1=>Attribute Memory
66 * 2 - Card Enable (Active Low) 66 * 2 - CI Card Enable (Active Low)
67 * 3 - Card Detect 67 * 3 - CI Card Detect
68 */ 68 */
69 69
70/**************************************************************************** 70/****************************************************************************
@@ -214,6 +214,9 @@ static int ciintf_slot_reset(struct dvb_ca_en50221 *ca, int slot)
214 while (--timeout > 0 && ciintf_read_attribute_mem(ca, slot, 0) != 0x1d) 214 while (--timeout > 0 && ciintf_read_attribute_mem(ca, slot, 0) != 0x1d)
215 msleep(100); 215 msleep(100);
216 216
217 /* reinitialise the frontend */
218 dvb_frontend_reinitialise(budget_av->budget.dvb_frontend);
219
217 if (timeout <= 0) 220 if (timeout <= 0)
218 { 221 {
219 printk(KERN_ERR "budget-av: cam reset failed (timeout).\n"); 222 printk(KERN_ERR "budget-av: cam reset failed (timeout).\n");
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index 633e68c341c8..ea2066d461fc 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -39,9 +39,21 @@
39#include "budget.h" 39#include "budget.h"
40#include "ttpci-eeprom.h" 40#include "ttpci-eeprom.h"
41 41
42#define TS_WIDTH (2 * TS_SIZE)
43#define TS_WIDTH_ACTIVY TS_SIZE
44#define TS_HEIGHT_MASK 0xf00
45#define TS_HEIGHT_MASK_ACTIVY 0xc00
46#define TS_MIN_BUFSIZE_K 188
47#define TS_MAX_BUFSIZE_K 1410
48#define TS_MAX_BUFSIZE_K_ACTIVY 564
49#define BUFFER_WARNING_WAIT (30*HZ)
50
42int budget_debug; 51int budget_debug;
52static int dma_buffer_size = TS_MIN_BUFSIZE_K;
43module_param_named(debug, budget_debug, int, 0644); 53module_param_named(debug, budget_debug, int, 0644);
54module_param_named(bufsize, dma_buffer_size, int, 0444);
44MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off)."); 55MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
56MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
45 57
46/**************************************************************************** 58/****************************************************************************
47 * TT budget / WinTV Nova 59 * TT budget / WinTV Nova
@@ -70,11 +82,10 @@ static int start_ts_capture(struct budget *budget)
70 82
71 saa7146_write(dev, MC1, MASK_20); // DMA3 off 83 saa7146_write(dev, MC1, MASK_20); // DMA3 off
72 84
73 memset(budget->grabbing, 0x00, TS_HEIGHT * TS_WIDTH); 85 memset(budget->grabbing, 0x00, budget->buffer_size);
74 86
75 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000)); 87 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
76 88
77 budget->tsf = 0xff;
78 budget->ttbp = 0; 89 budget->ttbp = 0;
79 90
80 /* 91 /*
@@ -115,16 +126,12 @@ static int start_ts_capture(struct budget *budget)
115 126
116 saa7146_write(dev, BASE_ODD3, 0); 127 saa7146_write(dev, BASE_ODD3, 0);
117 saa7146_write(dev, BASE_EVEN3, 0); 128 saa7146_write(dev, BASE_EVEN3, 0);
118 saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT); 129 saa7146_write(dev, PROT_ADDR3, budget->buffer_size);
119 saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90); 130 saa7146_write(dev, BASE_PAGE3, budget->pt.dma | ME1 | 0x90);
120 131
121 if (budget->card->type == BUDGET_FS_ACTIVY) { 132 saa7146_write(dev, PITCH3, budget->buffer_width);
122 saa7146_write(dev, PITCH3, TS_WIDTH / 2); 133 saa7146_write(dev, NUM_LINE_BYTE3,
123 saa7146_write(dev, NUM_LINE_BYTE3, ((TS_HEIGHT * 2) << 16) | (TS_WIDTH / 2)); 134 (budget->buffer_height << 16) | budget->buffer_width);
124 } else {
125 saa7146_write(dev, PITCH3, TS_WIDTH);
126 saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
127 }
128 135
129 saa7146_write(dev, MC2, (MASK_04 | MASK_20)); 136 saa7146_write(dev, MC2, (MASK_04 | MASK_20));
130 137
@@ -141,11 +148,12 @@ static void vpeirq(unsigned long data)
141 u8 *mem = (u8 *) (budget->grabbing); 148 u8 *mem = (u8 *) (budget->grabbing);
142 u32 olddma = budget->ttbp; 149 u32 olddma = budget->ttbp;
143 u32 newdma = saa7146_read(budget->dev, PCI_VDP3); 150 u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
151 u32 count;
144 152
145 /* nearest lower position divisible by 188 */ 153 /* nearest lower position divisible by 188 */
146 newdma -= newdma % 188; 154 newdma -= newdma % 188;
147 155
148 if (newdma >= TS_BUFLEN) 156 if (newdma >= budget->buffer_size)
149 return; 157 return;
150 158
151 budget->ttbp = newdma; 159 budget->ttbp = newdma;
@@ -154,11 +162,24 @@ static void vpeirq(unsigned long data)
154 return; 162 return;
155 163
156 if (newdma > olddma) { /* no wraparound, dump olddma..newdma */ 164 if (newdma > olddma) { /* no wraparound, dump olddma..newdma */
157 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, (newdma - olddma) / 188); 165 count = newdma - olddma;
166 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
158 } else { /* wraparound, dump olddma..buflen and 0..newdma */ 167 } else { /* wraparound, dump olddma..buflen and 0..newdma */
159 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, (TS_BUFLEN - olddma) / 188); 168 count = budget->buffer_size - olddma;
169 dvb_dmx_swfilter_packets(&budget->demux, mem + olddma, count / 188);
170 count += newdma;
160 dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188); 171 dvb_dmx_swfilter_packets(&budget->demux, mem, newdma / 188);
161 } 172 }
173
174 if (count > budget->buffer_warning_threshold)
175 budget->buffer_warnings++;
176
177 if (budget->buffer_warnings && time_after(jiffies, budget->buffer_warning_time)) {
178 printk("%s %s: used %d times >80%% of buffer (%u bytes now)\n",
179 budget->dev->name, __FUNCTION__, budget->buffer_warnings, count);
180 budget->buffer_warning_time = jiffies + BUFFER_WARNING_WAIT;
181 budget->buffer_warnings = 0;
182 }
162} 183}
163 184
164 185
@@ -341,9 +362,10 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
341 struct saa7146_pci_extension_data *info, 362 struct saa7146_pci_extension_data *info,
342 struct module *owner) 363 struct module *owner)
343{ 364{
344 int length = TS_WIDTH * TS_HEIGHT;
345 int ret = 0; 365 int ret = 0;
346 struct budget_info *bi = info->ext_priv; 366 struct budget_info *bi = info->ext_priv;
367 int max_bufsize;
368 int height_mask;
347 369
348 memset(budget, 0, sizeof(struct budget)); 370 memset(budget, 0, sizeof(struct budget));
349 371
@@ -352,6 +374,32 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
352 budget->card = bi; 374 budget->card = bi;
353 budget->dev = (struct saa7146_dev *) dev; 375 budget->dev = (struct saa7146_dev *) dev;
354 376
377 if (budget->card->type == BUDGET_FS_ACTIVY) {
378 budget->buffer_width = TS_WIDTH_ACTIVY;
379 max_bufsize = TS_MAX_BUFSIZE_K_ACTIVY;
380 height_mask = TS_HEIGHT_MASK_ACTIVY;
381 } else {
382 budget->buffer_width = TS_WIDTH;
383 max_bufsize = TS_MAX_BUFSIZE_K;
384 height_mask = TS_HEIGHT_MASK;
385 }
386
387 if (dma_buffer_size < TS_MIN_BUFSIZE_K)
388 dma_buffer_size = TS_MIN_BUFSIZE_K;
389 else if (dma_buffer_size > max_bufsize)
390 dma_buffer_size = max_bufsize;
391
392 budget->buffer_height = dma_buffer_size * 1024 / budget->buffer_width;
393 budget->buffer_height &= height_mask;
394 budget->buffer_size = budget->buffer_height * budget->buffer_width;
395 budget->buffer_warning_threshold = budget->buffer_size * 80/100;
396 budget->buffer_warnings = 0;
397 budget->buffer_warning_time = jiffies;
398
399 dprintk(2, "%s: width = %d, height = %d\n",
400 budget->dev->name, budget->buffer_width, budget->buffer_height);
401 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
402
355 dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner); 403 dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner);
356 404
357 /* set dd1 stream a & b */ 405 /* set dd1 stream a & b */
@@ -392,7 +440,7 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
392 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac); 440 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);
393 441
394 if (NULL == 442 if (NULL ==
395 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, length, &budget->pt))) { 443 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt))) {
396 ret = -ENOMEM; 444 ret = -ENOMEM;
397 goto err; 445 goto err;
398 } 446 }
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index 9fc9185a8426..1b3aaac5e763 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -577,6 +577,17 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
577 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); 577 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO);
578 // Set RPS1 Address register to point to RPS code (r108 p42) 578 // Set RPS1 Address register to point to RPS code (r108 p42)
579 saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle); 579 saa7146_write(dev, RPS_ADDR1, dev->d_rps1.dma_handle);
580
581 if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL)))
582 return -ENOMEM;
583
584 dprintk(2, "budget: %p\n", budget);
585
586 if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) {
587 kfree (budget);
588 return err;
589 }
590
580 // Set Source Line Counter Threshold, using BRS (rCC p43) 591 // Set Source Line Counter Threshold, using BRS (rCC p43)
581 // It generates HS event every TS_HEIGHT lines 592 // It generates HS event every TS_HEIGHT lines
582 // this is related to TS_WIDTH set in register 593 // this is related to TS_WIDTH set in register
@@ -585,24 +596,13 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
585 //,then RPS_THRESH1 596 //,then RPS_THRESH1
586 // should be set to trigger every TS_HEIGHT (512) lines. 597 // should be set to trigger every TS_HEIGHT (512) lines.
587 // 598 //
588 saa7146_write(dev, RPS_THRESH1, (TS_HEIGHT*1) | MASK_12 ); 599 saa7146_write(dev, RPS_THRESH1, budget->buffer_height | MASK_12 );
589 600
590 // saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 ); 601 // saa7146_write(dev, RPS_THRESH0, ((TS_HEIGHT/2)<<16) |MASK_28| (TS_HEIGHT/2) |MASK_12 );
591 // Enable RPS1 (rFC p33) 602 // Enable RPS1 (rFC p33)
592 saa7146_write(dev, MC1, (MASK_13 | MASK_29)); 603 saa7146_write(dev, MC1, (MASK_13 | MASK_29));
593 604
594 605
595 if (!(budget = kmalloc (sizeof(struct budget_patch), GFP_KERNEL)))
596 return -ENOMEM;
597
598 dprintk(2, "budget: %p\n", budget);
599
600 if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) {
601 kfree (budget);
602 return err;
603 }
604
605
606 dev->ext_priv = budget; 606 dev->ext_priv = budget;
607 607
608 budget->dvb_adapter.priv = budget; 608 budget->dvb_adapter.priv = budget;
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index 4ac0f4d08025..ecea3a13030e 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -58,7 +58,13 @@ struct budget {
58 int ci_present; 58 int ci_present;
59 int video_port; 59 int video_port;
60 60
61 u8 tsf; 61 u32 buffer_width;
62 u32 buffer_height;
63 u32 buffer_size;
64 u32 buffer_warning_threshold;
65 u32 buffer_warnings;
66 unsigned long buffer_warning_time;
67
62 u32 ttbp; 68 u32 ttbp;
63 int feeding; 69 int feeding;
64 70
@@ -79,11 +85,6 @@ static struct saa7146_pci_extension_data x_var = { \
79 .ext_priv = &x_var ## _info, \ 85 .ext_priv = &x_var ## _info, \
80 .ext = &budget_extension }; 86 .ext = &budget_extension };
81 87
82#define TS_WIDTH (376)
83#define TS_HEIGHT (512)
84#define TS_BUFLEN (TS_WIDTH*TS_HEIGHT)
85#define TS_MAX_PACKETS (TS_BUFLEN/TS_SIZE)
86
87#define BUDGET_TT 0 88#define BUDGET_TT 0
88#define BUDGET_TT_HW_DISEQC 1 89#define BUDGET_TT_HW_DISEQC 1
89#define BUDGET_PATCH 3 90#define BUDGET_PATCH 3
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f31a19890b15..85888a8a93c9 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -300,7 +300,7 @@ config VIDEO_OVCAMCHIP
300 camera drivers. 300 camera drivers.
301 301
302 To compile this driver as a module, choose M here: the 302 To compile this driver as a module, choose M here: the
303 module will be called ovcamchip 303 module will be called ovcamchip.
304 304
305config VIDEO_M32R_AR 305config VIDEO_M32R_AR
306 tristate "AR devices" 306 tristate "AR devices"
@@ -316,6 +316,13 @@ config VIDEO_M32R_AR_M64278
316 Say Y here to use the Renesas M64278E-800 camera module, 316 Say Y here to use the Renesas M64278E-800 camera module,
317 which supports VGA(640x480 pixcels) size of images. 317 which supports VGA(640x480 pixcels) size of images.
318 318
319#
320# Encoder / Decoder module configuration
321#
322
323menu "Encoders and Decoders"
324 depends on VIDEO_DEV
325
319config VIDEO_MSP3400 326config VIDEO_MSP3400
320 tristate "Micronas MSP34xx audio decoders" 327 tristate "Micronas MSP34xx audio decoders"
321 depends on VIDEO_DEV && I2C 328 depends on VIDEO_DEV && I2C
@@ -323,7 +330,7 @@ config VIDEO_MSP3400
323 Support for the Micronas MSP34xx series of audio decoders. 330 Support for the Micronas MSP34xx series of audio decoders.
324 331
325 To compile this driver as a module, choose M here: the 332 To compile this driver as a module, choose M here: the
326 module will be called msp3400 333 module will be called msp3400.
327 334
328config VIDEO_CS53L32A 335config VIDEO_CS53L32A
329 tristate "Cirrus Logic CS53L32A audio ADC" 336 tristate "Cirrus Logic CS53L32A audio ADC"
@@ -333,17 +340,27 @@ config VIDEO_CS53L32A
333 stereo A/D converter. 340 stereo A/D converter.
334 341
335 To compile this driver as a module, choose M here: the 342 To compile this driver as a module, choose M here: the
336 module will be called cs53l32a 343 module will be called cs53l32a.
337 344
338config VIDEO_WM8775 345config VIDEO_WM8775
339 tristate "Wolfson Microelectronics WM8775 audio ADC" 346 tristate "Wolfson Microelectronics WM8775 audio ADC with input mixer"
340 depends on VIDEO_DEV && I2C && EXPERIMENTAL 347 depends on VIDEO_DEV && I2C && EXPERIMENTAL
341 ---help--- 348 ---help---
342 Support for the Wolfson Microelectronics WM8775 349 Support for the Wolfson Microelectronics WM8775 high
343 high performance stereo A/D Converter. 350 performance stereo A/D Converter with a 4 channel input mixer.
344 351
345 To compile this driver as a module, choose M here: the 352 To compile this driver as a module, choose M here: the
346 module will be called wm8775 353 module will be called wm8775.
354
355config VIDEO_WM8739
356 tristate "Wolfson Microelectronics WM8739 stereo audio ADC"
357 depends on VIDEO_DEV && I2C && EXPERIMENTAL
358 ---help---
359 Support for the Wolfson Microelectronics WM8739
360 stereo A/D Converter.
361
362 To compile this driver as a module, choose M here: the
363 module will be called wm8739.
347 364
348source "drivers/media/video/cx25840/Kconfig" 365source "drivers/media/video/cx25840/Kconfig"
349 366
@@ -354,7 +371,7 @@ config VIDEO_SAA711X
354 Support for the Philips SAA7113/4/5 video decoders. 371 Support for the Philips SAA7113/4/5 video decoders.
355 372
356 To compile this driver as a module, choose M here: the 373 To compile this driver as a module, choose M here: the
357 module will be called saa7115 374 module will be called saa7115.
358 375
359config VIDEO_SAA7127 376config VIDEO_SAA7127
360 tristate "Philips SAA7127/9 digital video encoders" 377 tristate "Philips SAA7127/9 digital video encoders"
@@ -363,7 +380,32 @@ config VIDEO_SAA7127
363 Support for the Philips SAA7127/9 digital video encoders. 380 Support for the Philips SAA7127/9 digital video encoders.
364 381
365 To compile this driver as a module, choose M here: the 382 To compile this driver as a module, choose M here: the
366 module will be called saa7127 383 module will be called saa7127.
384
385config VIDEO_UPD64031A
386 tristate "NEC Electronics uPD64031A Ghost Reduction"
387 depends on VIDEO_DEV && I2C && EXPERIMENTAL
388 ---help---
389 Support for the NEC Electronics uPD64031A Ghost Reduction
390 video chip. It is most often found in NTSC TV cards made for
391 Japan and is used to reduce the 'ghosting' effect that can
392 be present in analog TV broadcasts.
393
394 To compile this driver as a module, choose M here: the
395 module will be called upd64031a.
396
397config VIDEO_UPD64083
398 tristate "NEC Electronics uPD64083 3-Dimensional Y/C separation"
399 depends on VIDEO_DEV && I2C && EXPERIMENTAL
400 ---help---
401 Support for the NEC Electronics uPD64083 3-Dimensional Y/C
402 separation video chip. It is used to improve the quality of
403 the colors of a composite signal.
404
405 To compile this driver as a module, choose M here: the
406 module will be called upd64083.
407
408endmenu # encoder / decoder chips
367 409
368# 410#
369# USB Multimedia device configuration 411# USB Multimedia device configuration
@@ -374,20 +416,6 @@ menu "V4L USB devices"
374 416
375source "drivers/media/video/em28xx/Kconfig" 417source "drivers/media/video/em28xx/Kconfig"
376 418
377config USB_VICAM
378 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
379 depends on USB && VIDEO_DEV && EXPERIMENTAL
380 ---help---
381 Say Y here if you have 3com homeconnect camera (vicam).
382
383 This driver uses the Video For Linux API. You must say Y or M to
384 "Video For Linux" (under Multimedia Devices) to use this driver.
385 Information on this API and pointers to "v4l" programs may be found
386 at <file:Documentation/video4linux/API.html>.
387
388 To compile this driver as a module, choose M here: the
389 module will be called vicam.
390
391config USB_DSBR 419config USB_DSBR
392 tristate "D-Link USB FM radio support (EXPERIMENTAL)" 420 tristate "D-Link USB FM radio support (EXPERIMENTAL)"
393 depends on USB && VIDEO_DEV && EXPERIMENTAL 421 depends on USB && VIDEO_DEV && EXPERIMENTAL
@@ -397,79 +425,20 @@ config USB_DSBR
397 you must connect the line out connector to a sound card or a 425 you must connect the line out connector to a sound card or a
398 set of speakers. 426 set of speakers.
399 427
400 This driver uses the Video For Linux API. You must enable
401 (Y or M in config) Video For Linux (under Character Devices)
402 to use this driver. Information on this API and pointers to
403 "v4l" programs may be found at
404 <file:Documentation/video4linux/API.html>.
405
406 To compile this driver as a module, choose M here: the 428 To compile this driver as a module, choose M here: the
407 module will be called dsbr100. 429 module will be called dsbr100.
408 430
409config USB_ET61X251 431source "drivers/media/video/usbvideo/Kconfig"
410 tristate "USB ET61X[12]51 PC Camera Controller support"
411 depends on USB && VIDEO_DEV
412 ---help---
413 Say Y here if you want support for cameras based on Etoms ET61X151
414 or ET61X251 PC Camera Controllers.
415
416 See <file:Documentation/usb/et61x251.txt> for more informations.
417
418 This driver uses the Video For Linux API. You must say Y or M to
419 "Video For Linux" to use this driver.
420
421 To compile this driver as a module, choose M here: the
422 module will be called et61x251.
423 432
424config USB_IBMCAM 433source "drivers/media/video/et61x251/Kconfig"
425 tristate "USB IBM (Xirlink) C-it Camera support"
426 depends on USB && VIDEO_DEV
427 ---help---
428 Say Y here if you want to connect a IBM "C-It" camera, also known as
429 "Xirlink PC Camera" to your computer's USB port. For more
430 information, read <file:Documentation/usb/ibmcam.txt>.
431
432 This driver uses the Video For Linux API. You must enable
433 (Y or M in config) Video For Linux (under Character Devices)
434 to use this driver. Information on this API and pointers to
435 "v4l" programs may be found at
436 <file:Documentation/video4linux/API.html>.
437
438 To compile this driver as a module, choose M here: the
439 module will be called ibmcam.
440
441 This camera has several configuration options which
442 can be specified when you load the module. Read
443 <file:Documentation/usb/ibmcam.txt> to learn more.
444
445config USB_KONICAWC
446 tristate "USB Konica Webcam support"
447 depends on USB && VIDEO_DEV
448 ---help---
449 Say Y here if you want support for webcams based on a Konica
450 chipset. This is known to work with the Intel YC76 webcam.
451
452 This driver uses the Video For Linux API. You must enable
453 (Y or M in config) Video For Linux (under Character Devices)
454 to use this driver. Information on this API and pointers to
455 "v4l" programs may be found at
456 <file:Documentation/video4linux/API.html>.
457
458 To compile this driver as a module, choose M here: the
459 module will be called konicawc.
460 434
461config USB_OV511 435config USB_OV511
462 tristate "USB OV511 Camera support" 436 tristate "USB OV511 Camera support"
463 depends on USB && VIDEO_DEV 437 depends on USB && VIDEO_DEV
464 ---help--- 438 ---help---
465 Say Y here if you want to connect this type of camera to your 439 Say Y here if you want to connect this type of camera to your
466 computer's USB port. See <file:Documentation/usb/ov511.txt> for more 440 computer's USB port. See <file:Documentation/video4linux/ov511.txt>
467 information and for a list of supported cameras. 441 for more information and for a list of supported cameras.
468
469 This driver uses the Video For Linux API. You must say Y or M to
470 "Video For Linux" (under Character Devices) to use this driver.
471 Information on this API and pointers to "v4l" programs may be found
472 at <file:Documentation/video4linux/API.html>.
473 442
474 To compile this driver as a module, choose M here: the 443 To compile this driver as a module, choose M here: the
475 module will be called ov511. 444 module will be called ov511.
@@ -479,31 +448,13 @@ config USB_SE401
479 depends on USB && VIDEO_DEV 448 depends on USB && VIDEO_DEV
480 ---help--- 449 ---help---
481 Say Y here if you want to connect this type of camera to your 450 Say Y here if you want to connect this type of camera to your
482 computer's USB port. See <file:Documentation/usb/se401.txt> for more 451 computer's USB port. See <file:Documentation/video4linux/se401.txt>
483 information and for a list of supported cameras. 452 for more information and for a list of supported cameras.
484
485 This driver uses the Video For Linux API. You must say Y or M to
486 "Video For Linux" (under Multimedia Devices) to use this driver.
487 Information on this API and pointers to "v4l" programs may be found
488 at <file:Documentation/video4linux/API.html>.
489 453
490 To compile this driver as a module, choose M here: the 454 To compile this driver as a module, choose M here: the
491 module will be called se401. 455 module will be called se401.
492 456
493config USB_SN9C102 457source "drivers/media/video/sn9c102/Kconfig"
494 tristate "USB SN9C10x PC Camera Controller support"
495 depends on USB && VIDEO_DEV
496 ---help---
497 Say Y here if you want support for cameras based on SONiX SN9C101,
498 SN9C102 or SN9C103 PC Camera Controllers.
499
500 See <file:Documentation/usb/sn9c102.txt> for more informations.
501
502 This driver uses the Video For Linux API. You must say Y or M to
503 "Video For Linux" to use this driver.
504
505 To compile this driver as a module, choose M here: the
506 module will be called sn9c102.
507 458
508config USB_STV680 459config USB_STV680
509 tristate "USB STV680 (Pencam) Camera support" 460 tristate "USB STV680 (Pencam) Camera support"
@@ -511,20 +462,16 @@ config USB_STV680
511 ---help--- 462 ---help---
512 Say Y here if you want to connect this type of camera to your 463 Say Y here if you want to connect this type of camera to your
513 computer's USB port. This includes the Pencam line of cameras. 464 computer's USB port. This includes the Pencam line of cameras.
514 See <file:Documentation/usb/stv680.txt> for more information and for 465 See <file:Documentation/video4linux/stv680.txt> for more information
515 a list of supported cameras. 466 and for a list of supported cameras.
516
517 This driver uses the Video For Linux API. You must say Y or M to
518 "Video For Linux" (under Multimedia Devices) to use this driver.
519 Information on this API and pointers to "v4l" programs may be found
520 at <file:Documentation/video4linux/API.html>.
521 467
522 To compile this driver as a module, choose M here: the 468 To compile this driver as a module, choose M here: the
523 module will be called stv680. 469 module will be called stv680.
524 470
525config USB_W9968CF 471config USB_W9968CF
526 tristate "USB W996[87]CF JPEG Dual Mode Camera support" 472 tristate "USB W996[87]CF JPEG Dual Mode Camera support"
527 depends on USB && VIDEO_DEV && I2C && VIDEO_OVCAMCHIP 473 depends on USB && VIDEO_DEV && I2C
474 select VIDEO_OVCAMCHIP
528 ---help--- 475 ---help---
529 Say Y here if you want support for cameras based on OV681 or 476 Say Y here if you want support for cameras based on OV681 or
530 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips. 477 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips.
@@ -534,64 +481,14 @@ config USB_W9968CF
534 resolutions and framerates, but cannot be included in the official 481 resolutions and framerates, but cannot be included in the official
535 Linux kernel for performance purposes. 482 Linux kernel for performance purposes.
536 483
537 See <file:Documentation/usb/w9968cf.txt> for more informations. 484 See <file:Documentation/video4linux/w9968cf.txt> for more info.
538
539 This driver uses the Video For Linux and the I2C APIs. It needs the
540 OmniVision Camera Chip support as well. You must say Y or M to
541 "Video For Linux", "I2C Support" and "OmniVision Camera Chip
542 support" to use this driver.
543 485
544 To compile this driver as a module, choose M here: the 486 To compile this driver as a module, choose M here: the
545 module will be called w9968cf. 487 module will be called w9968cf.
546 488
547config USB_ZC0301 489source "drivers/media/video/zc0301/Kconfig"
548 tristate "USB ZC0301 Image Processor and Control Chip support"
549 depends on USB && VIDEO_DEV
550 ---help---
551 Say Y here if you want support for cameras based on the ZC0301
552 Image Processor and Control Chip.
553
554 See <file:Documentation/usb/zc0301.txt> for more informations.
555
556 This driver uses the Video For Linux API. You must say Y or M to
557 "Video For Linux" to use this driver.
558
559 To compile this driver as a module, choose M here: the
560 module will be called zc0301.
561
562config USB_PWC
563 tristate "USB Philips Cameras"
564 depends on USB && VIDEO_DEV
565 ---help---
566 Say Y or M here if you want to use one of these Philips & OEM
567 webcams:
568 * Philips PCA645, PCA646
569 * Philips PCVC675, PCVC680, PCVC690
570 * Philips PCVC720/40, PCVC730, PCVC740, PCVC750
571 * Askey VC010
572 * Logitech QuickCam Pro 3000, 4000, 'Zoom', 'Notebook Pro'
573 and 'Orbit'/'Sphere'
574 * Samsung MPC-C10, MPC-C30
575 * Creative Webcam 5, Pro Ex
576 * SOTEC Afina Eye
577 * Visionite VCS-UC300, VCS-UM100
578
579 The PCA635, PCVC665 and PCVC720/20 are not supported by this driver
580 and never will be, but the 665 and 720/20 are supported by other
581 drivers.
582
583 See <file:Documentation/usb/philips.txt> for more information and
584 installation instructions.
585
586 The built-in microphone is enabled by selecting USB Audio support.
587
588 This driver uses the Video For Linux API. You must say Y or M to
589 "Video For Linux" (under Character Devices) to use this driver.
590 Information on this API and pointers to "v4l" programs may be found
591 at <file:Documentation/video4linux/API.html>.
592 490
593 To compile this driver as a module, choose M here: the 491source "drivers/media/video/pwc/Kconfig"
594 module will be called pwc.
595 492
596endmenu # V4L USB devices 493endmenu # V4L USB devices
597 494
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 1c0e72e5a593..b3ea2d63db9b 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_VIDEO_EM28XX) += tvp5150.o
45obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o 45obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
46obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 46obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
47obj-$(CONFIG_VIDEO_WM8775) += wm8775.o 47obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
48obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
48obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/ 49obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/
49obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ 50obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
50obj-$(CONFIG_VIDEO_MXB) += saa7111.o tda9840.o tea6415c.o tea6420.o mxb.o 51obj-$(CONFIG_VIDEO_MXB) += saa7111.o tda9840.o tea6415c.o tea6420.o mxb.o
@@ -64,9 +65,8 @@ obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
64obj-$(CONFIG_VIDEO_CX25840) += cx25840/ 65obj-$(CONFIG_VIDEO_CX25840) += cx25840/
65obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o 66obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
66obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o 67obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
67 68obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
68et61x251-objs := et61x251_core.o et61x251_tas5130d1b.o 69obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
69zc0301-objs := zc0301_core.o zc0301_pas202bcb.o
70 70
71obj-$(CONFIG_USB_DABUSB) += dabusb.o 71obj-$(CONFIG_USB_DABUSB) += dabusb.o
72obj-$(CONFIG_USB_DSBR) += dsbr100.o 72obj-$(CONFIG_USB_DSBR) += dsbr100.o
@@ -84,4 +84,4 @@ obj-$(CONFIG_USB_IBMCAM) += usbvideo/
84obj-$(CONFIG_USB_KONICAWC) += usbvideo/ 84obj-$(CONFIG_USB_KONICAWC) += usbvideo/
85obj-$(CONFIG_USB_VICAM) += usbvideo/ 85obj-$(CONFIG_USB_VICAM) += usbvideo/
86 86
87EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 87EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
diff --git a/drivers/media/video/bt8xx/Makefile b/drivers/media/video/bt8xx/Makefile
index 94350f21cdc0..db641a36b197 100644
--- a/drivers/media/video/bt8xx/Makefile
+++ b/drivers/media/video/bt8xx/Makefile
@@ -9,4 +9,4 @@ bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
9obj-$(CONFIG_VIDEO_BT848) += bttv.o 9obj-$(CONFIG_VIDEO_BT848) += bttv.o
10 10
11EXTRA_CFLAGS += -I$(src)/.. 11EXTRA_CFLAGS += -I$(src)/..
12EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 12EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 74def9c23952..423e954948be 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -973,12 +973,12 @@ audio_mux(struct bttv *btv, int input, int mute)
973 For now this is sufficient. */ 973 For now this is sufficient. */
974 switch (input) { 974 switch (input) {
975 case TVAUDIO_INPUT_RADIO: 975 case TVAUDIO_INPUT_RADIO:
976 route.input = MSP_INPUT(MSP_IN_SCART_2, MSP_IN_TUNER_1, 976 route.input = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1,
977 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART); 977 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
978 break; 978 break;
979 case TVAUDIO_INPUT_EXTERN: 979 case TVAUDIO_INPUT_EXTERN:
980 route.input = MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1, 980 route.input = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
981 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART); 981 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
982 break; 982 break;
983 case TVAUDIO_INPUT_INTERN: 983 case TVAUDIO_INPUT_INTERN:
984 /* Yes, this is the same input as for RADIO. I doubt 984 /* Yes, this is the same input as for RADIO. I doubt
@@ -986,8 +986,8 @@ audio_mux(struct bttv *btv, int input, int mute)
986 input is the BTTV_BOARD_AVERMEDIA98. I wonder how 986 input is the BTTV_BOARD_AVERMEDIA98. I wonder how
987 that was tested. My guess is that the whole INTERN 987 that was tested. My guess is that the whole INTERN
988 input does not work. */ 988 input does not work. */
989 route.input = MSP_INPUT(MSP_IN_SCART_2, MSP_IN_TUNER_1, 989 route.input = MSP_INPUT(MSP_IN_SCART2, MSP_IN_TUNER1,
990 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART); 990 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART);
991 break; 991 break;
992 case TVAUDIO_INPUT_TUNER: 992 case TVAUDIO_INPUT_TUNER:
993 default: 993 default:
@@ -1023,14 +1023,11 @@ audio_input(struct bttv *btv, int input)
1023static void 1023static void
1024i2c_vidiocschan(struct bttv *btv) 1024i2c_vidiocschan(struct bttv *btv)
1025{ 1025{
1026 struct video_channel c; 1026 v4l2_std_id std = bttv_tvnorms[btv->tvnorm].v4l2_id;
1027 1027
1028 memset(&c,0,sizeof(c)); 1028 bttv_call_i2c_clients(btv, VIDIOC_S_STD, &std);
1029 c.norm = btv->tvnorm;
1030 c.channel = btv->input;
1031 bttv_call_i2c_clients(btv,VIDIOCSCHAN,&c);
1032 if (btv->c.type == BTTV_BOARD_VOODOOTV_FM) 1029 if (btv->c.type == BTTV_BOARD_VOODOOTV_FM)
1033 bttv_tda9880_setnorm(btv,c.norm); 1030 bttv_tda9880_setnorm(btv,btv->tvnorm);
1034} 1031}
1035 1032
1036static int 1033static int
@@ -1184,11 +1181,27 @@ static int get_control(struct bttv *btv, struct v4l2_control *c)
1184 break; 1181 break;
1185 if (i == BTTV_CTLS) 1182 if (i == BTTV_CTLS)
1186 return -EINVAL; 1183 return -EINVAL;
1187 if (i >= 4 && i <= 8) { 1184 if (btv->audio_hook && i >= 4 && i <= 8) {
1188 memset(&va,0,sizeof(va)); 1185 memset(&va,0,sizeof(va));
1189 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va); 1186 btv->audio_hook(btv,&va,0);
1190 if (btv->audio_hook) 1187 switch (c->id) {
1191 btv->audio_hook(btv,&va,0); 1188 case V4L2_CID_AUDIO_MUTE:
1189 c->value = (VIDEO_AUDIO_MUTE & va.flags) ? 1 : 0;
1190 break;
1191 case V4L2_CID_AUDIO_VOLUME:
1192 c->value = va.volume;
1193 break;
1194 case V4L2_CID_AUDIO_BALANCE:
1195 c->value = va.balance;
1196 break;
1197 case V4L2_CID_AUDIO_BASS:
1198 c->value = va.bass;
1199 break;
1200 case V4L2_CID_AUDIO_TREBLE:
1201 c->value = va.treble;
1202 break;
1203 }
1204 return 0;
1192 } 1205 }
1193 switch (c->id) { 1206 switch (c->id) {
1194 case V4L2_CID_BRIGHTNESS: 1207 case V4L2_CID_BRIGHTNESS:
@@ -1205,19 +1218,11 @@ static int get_control(struct bttv *btv, struct v4l2_control *c)
1205 break; 1218 break;
1206 1219
1207 case V4L2_CID_AUDIO_MUTE: 1220 case V4L2_CID_AUDIO_MUTE:
1208 c->value = (VIDEO_AUDIO_MUTE & va.flags) ? 1 : 0;
1209 break;
1210 case V4L2_CID_AUDIO_VOLUME: 1221 case V4L2_CID_AUDIO_VOLUME:
1211 c->value = va.volume;
1212 break;
1213 case V4L2_CID_AUDIO_BALANCE: 1222 case V4L2_CID_AUDIO_BALANCE:
1214 c->value = va.balance;
1215 break;
1216 case V4L2_CID_AUDIO_BASS: 1223 case V4L2_CID_AUDIO_BASS:
1217 c->value = va.bass;
1218 break;
1219 case V4L2_CID_AUDIO_TREBLE: 1224 case V4L2_CID_AUDIO_TREBLE:
1220 c->value = va.treble; 1225 bttv_call_i2c_clients(btv,VIDIOC_G_CTRL,c);
1221 break; 1226 break;
1222 1227
1223 case V4L2_CID_PRIVATE_CHROMA_AGC: 1228 case V4L2_CID_PRIVATE_CHROMA_AGC:
@@ -1269,11 +1274,35 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1269 break; 1274 break;
1270 if (i == BTTV_CTLS) 1275 if (i == BTTV_CTLS)
1271 return -EINVAL; 1276 return -EINVAL;
1272 if (i >= 4 && i <= 8) { 1277 if (btv->audio_hook && i >= 4 && i <= 8) {
1273 memset(&va,0,sizeof(va)); 1278 memset(&va,0,sizeof(va));
1274 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va); 1279 btv->audio_hook(btv,&va,0);
1275 if (btv->audio_hook) 1280 switch (c->id) {
1276 btv->audio_hook(btv,&va,0); 1281 case V4L2_CID_AUDIO_MUTE:
1282 if (c->value) {
1283 va.flags |= VIDEO_AUDIO_MUTE;
1284 audio_mute(btv, 1);
1285 } else {
1286 va.flags &= ~VIDEO_AUDIO_MUTE;
1287 audio_mute(btv, 0);
1288 }
1289 break;
1290
1291 case V4L2_CID_AUDIO_VOLUME:
1292 va.volume = c->value;
1293 break;
1294 case V4L2_CID_AUDIO_BALANCE:
1295 va.balance = c->value;
1296 break;
1297 case V4L2_CID_AUDIO_BASS:
1298 va.bass = c->value;
1299 break;
1300 case V4L2_CID_AUDIO_TREBLE:
1301 va.treble = c->value;
1302 break;
1303 }
1304 btv->audio_hook(btv,&va,1);
1305 return 0;
1277 } 1306 }
1278 switch (c->id) { 1307 switch (c->id) {
1279 case V4L2_CID_BRIGHTNESS: 1308 case V4L2_CID_BRIGHTNESS:
@@ -1289,26 +1318,13 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1289 bt848_sat(btv,c->value); 1318 bt848_sat(btv,c->value);
1290 break; 1319 break;
1291 case V4L2_CID_AUDIO_MUTE: 1320 case V4L2_CID_AUDIO_MUTE:
1292 if (c->value) { 1321 audio_mute(btv, c->value);
1293 va.flags |= VIDEO_AUDIO_MUTE; 1322 /* fall through */
1294 audio_mute(btv, 1);
1295 } else {
1296 va.flags &= ~VIDEO_AUDIO_MUTE;
1297 audio_mute(btv, 0);
1298 }
1299 break;
1300
1301 case V4L2_CID_AUDIO_VOLUME: 1323 case V4L2_CID_AUDIO_VOLUME:
1302 va.volume = c->value;
1303 break;
1304 case V4L2_CID_AUDIO_BALANCE: 1324 case V4L2_CID_AUDIO_BALANCE:
1305 va.balance = c->value;
1306 break;
1307 case V4L2_CID_AUDIO_BASS: 1325 case V4L2_CID_AUDIO_BASS:
1308 va.bass = c->value;
1309 break;
1310 case V4L2_CID_AUDIO_TREBLE: 1326 case V4L2_CID_AUDIO_TREBLE:
1311 va.treble = c->value; 1327 bttv_call_i2c_clients(btv,VIDIOC_S_CTRL,c);
1312 break; 1328 break;
1313 1329
1314 case V4L2_CID_PRIVATE_CHROMA_AGC: 1330 case V4L2_CID_PRIVATE_CHROMA_AGC:
@@ -1364,11 +1380,6 @@ static int set_control(struct bttv *btv, struct v4l2_control *c)
1364 default: 1380 default:
1365 return -EINVAL; 1381 return -EINVAL;
1366 } 1382 }
1367 if (i >= 4 && i <= 8) {
1368 bttv_call_i2c_clients(btv, VIDIOCSAUDIO, &va);
1369 if (btv->audio_hook)
1370 btv->audio_hook(btv,&va,1);
1371 }
1372 return 0; 1383 return 0;
1373} 1384}
1374 1385
@@ -1591,12 +1602,16 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1591 } 1602 }
1592 case VIDIOCSFREQ: 1603 case VIDIOCSFREQ:
1593 { 1604 {
1594 unsigned long *freq = arg; 1605 struct v4l2_frequency freq;
1606
1607 memset(&freq, 0, sizeof(freq));
1608 freq.frequency = *(unsigned long *)arg;
1595 mutex_lock(&btv->lock); 1609 mutex_lock(&btv->lock);
1596 btv->freq=*freq; 1610 freq.type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1597 bttv_call_i2c_clients(btv,VIDIOCSFREQ,freq); 1611 btv->freq = *(unsigned long *)arg;
1612 bttv_call_i2c_clients(btv,VIDIOC_S_FREQUENCY,&freq);
1598 if (btv->has_matchbox && btv->radio_user) 1613 if (btv->has_matchbox && btv->radio_user)
1599 tea5757_set_freq(btv,*freq); 1614 tea5757_set_freq(btv,*(unsigned long *)arg);
1600 mutex_unlock(&btv->lock); 1615 mutex_unlock(&btv->lock);
1601 return 0; 1616 return 0;
1602 } 1617 }
@@ -1827,33 +1842,26 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1827 return -EINVAL; 1842 return -EINVAL;
1828 mutex_lock(&btv->lock); 1843 mutex_lock(&btv->lock);
1829 memset(t,0,sizeof(*t)); 1844 memset(t,0,sizeof(*t));
1845 t->rxsubchans = V4L2_TUNER_SUB_MONO;
1846 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t);
1830 strcpy(t->name, "Television"); 1847 strcpy(t->name, "Television");
1831 t->type = V4L2_TUNER_ANALOG_TV;
1832 t->capability = V4L2_TUNER_CAP_NORM; 1848 t->capability = V4L2_TUNER_CAP_NORM;
1833 t->rxsubchans = V4L2_TUNER_SUB_MONO; 1849 t->type = V4L2_TUNER_ANALOG_TV;
1834 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC) 1850 if (btread(BT848_DSTATUS)&BT848_DSTATUS_HLOC)
1835 t->signal = 0xffff; 1851 t->signal = 0xffff;
1836 { 1852
1837 struct video_tuner tuner; 1853 if (btv->audio_hook) {
1838
1839 memset(&tuner, 0, sizeof (tuner));
1840 tuner.rangehigh = 0xffffffffUL;
1841 bttv_call_i2c_clients(btv, VIDIOCGTUNER, &tuner);
1842 t->rangelow = tuner.rangelow;
1843 t->rangehigh = tuner.rangehigh;
1844 }
1845 {
1846 /* Hmmm ... */ 1854 /* Hmmm ... */
1847 struct video_audio va; 1855 struct video_audio va;
1848 memset(&va, 0, sizeof(struct video_audio)); 1856 memset(&va, 0, sizeof(struct video_audio));
1849 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va); 1857 btv->audio_hook(btv,&va,0);
1850 if (btv->audio_hook) 1858 t->audmode = V4L2_TUNER_MODE_MONO;
1851 btv->audio_hook(btv,&va,0); 1859 t->rxsubchans = V4L2_TUNER_SUB_MONO;
1852 if(va.mode & VIDEO_SOUND_STEREO) { 1860 if(va.mode & VIDEO_SOUND_STEREO) {
1853 t->audmode = V4L2_TUNER_MODE_STEREO; 1861 t->audmode = V4L2_TUNER_MODE_STEREO;
1854 t->rxsubchans |= V4L2_TUNER_SUB_STEREO; 1862 t->rxsubchans = V4L2_TUNER_SUB_STEREO;
1855 } 1863 }
1856 if(va.mode & VIDEO_SOUND_LANG1) { 1864 if(va.mode & VIDEO_SOUND_LANG2) {
1857 t->audmode = V4L2_TUNER_MODE_LANG1; 1865 t->audmode = V4L2_TUNER_MODE_LANG1;
1858 t->rxsubchans = V4L2_TUNER_SUB_LANG1 1866 t->rxsubchans = V4L2_TUNER_SUB_LANG1
1859 | V4L2_TUNER_SUB_LANG2; 1867 | V4L2_TUNER_SUB_LANG2;
@@ -1872,10 +1880,10 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1872 if (0 != t->index) 1880 if (0 != t->index)
1873 return -EINVAL; 1881 return -EINVAL;
1874 mutex_lock(&btv->lock); 1882 mutex_lock(&btv->lock);
1875 { 1883 bttv_call_i2c_clients(btv, VIDIOC_S_TUNER, t);
1884 if (btv->audio_hook) {
1876 struct video_audio va; 1885 struct video_audio va;
1877 memset(&va, 0, sizeof(struct video_audio)); 1886 memset(&va, 0, sizeof(struct video_audio));
1878 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va);
1879 if (t->audmode == V4L2_TUNER_MODE_MONO) 1887 if (t->audmode == V4L2_TUNER_MODE_MONO)
1880 va.mode = VIDEO_SOUND_MONO; 1888 va.mode = VIDEO_SOUND_MONO;
1881 else if (t->audmode == V4L2_TUNER_MODE_STEREO || 1889 else if (t->audmode == V4L2_TUNER_MODE_STEREO ||
@@ -1885,9 +1893,7 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1885 va.mode = VIDEO_SOUND_LANG1; 1893 va.mode = VIDEO_SOUND_LANG1;
1886 else if (t->audmode == V4L2_TUNER_MODE_LANG2) 1894 else if (t->audmode == V4L2_TUNER_MODE_LANG2)
1887 va.mode = VIDEO_SOUND_LANG2; 1895 va.mode = VIDEO_SOUND_LANG2;
1888 bttv_call_i2c_clients(btv, VIDIOCSAUDIO, &va); 1896 btv->audio_hook(btv,&va,1);
1889 if (btv->audio_hook)
1890 btv->audio_hook(btv,&va,1);
1891 } 1897 }
1892 mutex_unlock(&btv->lock); 1898 mutex_unlock(&btv->lock);
1893 return 0; 1899 return 0;
@@ -1912,7 +1918,7 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1912 return -EINVAL; 1918 return -EINVAL;
1913 mutex_lock(&btv->lock); 1919 mutex_lock(&btv->lock);
1914 btv->freq = f->frequency; 1920 btv->freq = f->frequency;
1915 bttv_call_i2c_clients(btv,VIDIOCSFREQ,&btv->freq); 1921 bttv_call_i2c_clients(btv,VIDIOC_S_FREQUENCY,f);
1916 if (btv->has_matchbox && btv->radio_user) 1922 if (btv->has_matchbox && btv->radio_user)
1917 tea5757_set_freq(btv,btv->freq); 1923 tea5757_set_freq(btv,btv->freq);
1918 mutex_unlock(&btv->lock); 1924 mutex_unlock(&btv->lock);
@@ -1920,7 +1926,9 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1920 } 1926 }
1921 case VIDIOC_LOG_STATUS: 1927 case VIDIOC_LOG_STATUS:
1922 { 1928 {
1929 printk(KERN_INFO "bttv%d: ================= START STATUS CARD #%d =================\n", btv->c.nr, btv->c.nr);
1923 bttv_call_i2c_clients(btv, VIDIOC_LOG_STATUS, NULL); 1930 bttv_call_i2c_clients(btv, VIDIOC_LOG_STATUS, NULL);
1931 printk(KERN_INFO "bttv%d: ================== END STATUS CARD #%d ==================\n", btv->c.nr, btv->c.nr);
1924 return 0; 1932 return 0;
1925 } 1933 }
1926 1934
@@ -2870,12 +2878,10 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
2870 return 0; 2878 return 0;
2871 } 2879 }
2872 *c = bttv_ctls[i]; 2880 *c = bttv_ctls[i];
2873 if (i >= 4 && i <= 8) { 2881 if (btv->audio_hook && i >= 4 && i <= 8) {
2874 struct video_audio va; 2882 struct video_audio va;
2875 memset(&va,0,sizeof(va)); 2883 memset(&va,0,sizeof(va));
2876 bttv_call_i2c_clients(btv, VIDIOCGAUDIO, &va); 2884 btv->audio_hook(btv,&va,0);
2877 if (btv->audio_hook)
2878 btv->audio_hook(btv,&va,0);
2879 switch (bttv_ctls[i].id) { 2885 switch (bttv_ctls[i].id) {
2880 case V4L2_CID_AUDIO_VOLUME: 2886 case V4L2_CID_AUDIO_VOLUME:
2881 if (!(va.flags & VIDEO_AUDIO_VOLUME)) 2887 if (!(va.flags & VIDEO_AUDIO_VOLUME))
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index e20ff238e409..8c9f0f7cf467 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -184,7 +184,7 @@ void bttv_vbi_try_fmt(struct bttv_fh *fh, struct v4l2_format *f)
184 - tvnorm->vbistart[0]; 184 - tvnorm->vbistart[0];
185 count1 = (s64) f->fmt.vbi.start[1] + f->fmt.vbi.count[1] 185 count1 = (s64) f->fmt.vbi.start[1] + f->fmt.vbi.count[1]
186 - tvnorm->vbistart[1]; 186 - tvnorm->vbistart[1];
187 count = clamp (max (count0, count1), 1LL, (s64) VBI_MAXLINES); 187 count = clamp (max (count0, count1), (s64) 1, (s64) VBI_MAXLINES);
188 188
189 f->fmt.vbi.start[0] = tvnorm->vbistart[0]; 189 f->fmt.vbi.start[0] = tvnorm->vbistart[0];
190 f->fmt.vbi.start[1] = tvnorm->vbistart[1]; 190 f->fmt.vbi.start[1] = tvnorm->vbistart[1];
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 2227c5640c12..85d84e89d8f4 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -64,14 +64,13 @@ MODULE_LICENSE("GPL");
64MODULE_SUPPORTED_DEVICE("video"); 64MODULE_SUPPORTED_DEVICE("video");
65#endif 65#endif
66 66
67static unsigned short colorspace_conv = 0; 67static unsigned short colorspace_conv;
68module_param(colorspace_conv, ushort, 0444); 68module_param(colorspace_conv, ushort, 0444);
69MODULE_PARM_DESC(colorspace_conv, 69MODULE_PARM_DESC(colorspace_conv,
70 "\n<n> Colorspace conversion:" 70 " Colorspace conversion:"
71 "\n0 = disable" 71 "\n 0 = disable, 1 = enable"
72 "\n1 = enable" 72 "\n Default value is 0"
73 "\nDefault value is 0" 73 );
74 "\n");
75 74
76#define ABOUT "V4L-Driver for Vision CPiA based cameras" 75#define ABOUT "V4L-Driver for Vision CPiA based cameras"
77 76
@@ -4042,7 +4041,7 @@ static int __init cpia_init(void)
4042 "allowed, it is disabled by default now. Users should fix the " 4041 "allowed, it is disabled by default now. Users should fix the "
4043 "applications in case they don't work without conversion " 4042 "applications in case they don't work without conversion "
4044 "reenabled by setting the 'colorspace_conv' module " 4043 "reenabled by setting the 'colorspace_conv' module "
4045 "parameter to 1"); 4044 "parameter to 1\n");
4046 4045
4047#ifdef CONFIG_PROC_FS 4046#ifdef CONFIG_PROC_FS
4048 proc_cpia_create(); 4047 proc_cpia_create();
diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
index 8394283993f6..1764991b0ac9 100644
--- a/drivers/media/video/cpia2/cpia2.h
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -456,7 +456,7 @@ int cpia2_init_camera(struct camera_data *cam);
456int cpia2_allocate_buffers(struct camera_data *cam); 456int cpia2_allocate_buffers(struct camera_data *cam);
457void cpia2_free_buffers(struct camera_data *cam); 457void cpia2_free_buffers(struct camera_data *cam);
458long cpia2_read(struct camera_data *cam, 458long cpia2_read(struct camera_data *cam,
459 char *buf, unsigned long count, int noblock); 459 char __user *buf, unsigned long count, int noblock);
460unsigned int cpia2_poll(struct camera_data *cam, 460unsigned int cpia2_poll(struct camera_data *cam,
461 struct file *filp, poll_table *wait); 461 struct file *filp, poll_table *wait);
462int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma); 462int cpia2_remap_buffer(struct camera_data *cam, struct vm_area_struct *vma);
diff --git a/drivers/media/video/cpia_pp.c b/drivers/media/video/cpia_pp.c
index 3021f21aae36..0b00e6027dfb 100644
--- a/drivers/media/video/cpia_pp.c
+++ b/drivers/media/video/cpia_pp.c
@@ -873,7 +873,7 @@ static int __init cpia_pp_setup(char *str)
873 parport_nr[parport_ptr++] = PPCPIA_PARPORT_NONE; 873 parport_nr[parport_ptr++] = PPCPIA_PARPORT_NONE;
874 } 874 }
875 875
876 return 0; 876 return 1;
877} 877}
878 878
879__setup("cpia_pp=", cpia_pp_setup); 879__setup("cpia_pp=", cpia_pp_setup);
diff --git a/drivers/media/video/cx25840/Makefile b/drivers/media/video/cx25840/Makefile
index 32a896c23d1e..6e8665be8954 100644
--- a/drivers/media/video/cx25840/Makefile
+++ b/drivers/media/video/cx25840/Makefile
@@ -3,4 +3,4 @@ cx25840-objs := cx25840-core.o cx25840-audio.o cx25840-firmware.o \
3 3
4obj-$(CONFIG_VIDEO_CX25840) += cx25840.o 4obj-$(CONFIG_VIDEO_CX25840) += cx25840.o
5 5
6EXTRA_CFLAGS += -I$(src)/.. 6EXTRA_CFLAGS += -Idrivers/media/video
diff --git a/drivers/media/video/cx25840/cx25840-audio.c b/drivers/media/video/cx25840/cx25840-audio.c
index a4540e858f21..9a4b813152e5 100644
--- a/drivers/media/video/cx25840/cx25840-audio.c
+++ b/drivers/media/video/cx25840/cx25840-audio.c
@@ -19,8 +19,9 @@
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
22#include <media/cx25840.h>
22 23
23#include "cx25840.h" 24#include "cx25840-core.h"
24 25
25static int set_audclk_freq(struct i2c_client *client, u32 freq) 26static int set_audclk_freq(struct i2c_client *client, u32 freq)
26{ 27{
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index a65b3cc4bf03..a961bb2ab0fd 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -32,8 +32,9 @@
32#include <linux/videodev2.h> 32#include <linux/videodev2.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include <media/cx25840.h>
35 36
36#include "cx25840.h" 37#include "cx25840-core.h"
37 38
38MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver"); 39MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver");
39MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford"); 40MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford");
@@ -668,6 +669,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
668{ 669{
669 struct cx25840_state *state = i2c_get_clientdata(client); 670 struct cx25840_state *state = i2c_get_clientdata(client);
670 struct v4l2_tuner *vt = arg; 671 struct v4l2_tuner *vt = arg;
672 struct v4l2_routing *route = arg;
671 673
672 switch (cmd) { 674 switch (cmd) {
673#ifdef CONFIG_VIDEO_ADV_DEBUG 675#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -749,19 +751,21 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
749 state->radio = 1; 751 state->radio = 1;
750 break; 752 break;
751 753
752 case VIDIOC_G_INPUT: 754 case VIDIOC_INT_G_VIDEO_ROUTING:
753 *(int *)arg = state->vid_input; 755 route->input = state->vid_input;
756 route->output = 0;
754 break; 757 break;
755 758
756 case VIDIOC_S_INPUT: 759 case VIDIOC_INT_S_VIDEO_ROUTING:
757 return set_input(client, *(enum cx25840_video_input *)arg, state->aud_input); 760 return set_input(client, route->input, state->aud_input);
758 761
759 case VIDIOC_S_AUDIO: 762 case VIDIOC_INT_G_AUDIO_ROUTING:
760 { 763 route->input = state->aud_input;
761 struct v4l2_audio *input = arg; 764 route->output = 0;
765 break;
762 766
763 return set_input(client, state->vid_input, input->index); 767 case VIDIOC_INT_S_AUDIO_ROUTING:
764 } 768 return set_input(client, state->vid_input, route->input);
765 769
766 case VIDIOC_S_FREQUENCY: 770 case VIDIOC_S_FREQUENCY:
767 input_change(client); 771 input_change(client);
diff --git a/drivers/media/video/cx25840/cx25840.h b/drivers/media/video/cx25840/cx25840-core.h
index dd70664d1dd9..1736929fc204 100644
--- a/drivers/media/video/cx25840/cx25840.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -1,4 +1,4 @@
1/* cx25840 API header 1/* cx25840 internal API header
2 * 2 *
3 * Copyright (C) 2003-2004 Chris Kennedy 3 * Copyright (C) 2003-2004 Chris Kennedy
4 * 4 *
@@ -17,8 +17,8 @@
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20#ifndef _CX25840_H_ 20#ifndef _CX25840_CORE_H_
21#define _CX25840_H_ 21#define _CX25840_CORE_H_
22 22
23 23
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
@@ -32,46 +32,6 @@
32 providing this information. */ 32 providing this information. */
33#define CX25840_CID_ENABLE_PVR150_WORKAROUND (V4L2_CID_PRIVATE_BASE+0) 33#define CX25840_CID_ENABLE_PVR150_WORKAROUND (V4L2_CID_PRIVATE_BASE+0)
34 34
35enum cx25840_video_input {
36 /* Composite video inputs In1-In8 */
37 CX25840_COMPOSITE1 = 1,
38 CX25840_COMPOSITE2,
39 CX25840_COMPOSITE3,
40 CX25840_COMPOSITE4,
41 CX25840_COMPOSITE5,
42 CX25840_COMPOSITE6,
43 CX25840_COMPOSITE7,
44 CX25840_COMPOSITE8,
45
46 /* S-Video inputs consist of one luma input (In1-In4) ORed with one
47 chroma input (In5-In8) */
48 CX25840_SVIDEO_LUMA1 = 0x10,
49 CX25840_SVIDEO_LUMA2 = 0x20,
50 CX25840_SVIDEO_LUMA3 = 0x30,
51 CX25840_SVIDEO_LUMA4 = 0x40,
52 CX25840_SVIDEO_CHROMA4 = 0x400,
53 CX25840_SVIDEO_CHROMA5 = 0x500,
54 CX25840_SVIDEO_CHROMA6 = 0x600,
55 CX25840_SVIDEO_CHROMA7 = 0x700,
56 CX25840_SVIDEO_CHROMA8 = 0x800,
57
58 /* S-Video aliases for common luma/chroma combinations */
59 CX25840_SVIDEO1 = 0x510,
60 CX25840_SVIDEO2 = 0x620,
61 CX25840_SVIDEO3 = 0x730,
62 CX25840_SVIDEO4 = 0x840,
63};
64
65enum cx25840_audio_input {
66 /* Audio inputs: serial or In4-In8 */
67 CX25840_AUDIO_SERIAL,
68 CX25840_AUDIO4 = 4,
69 CX25840_AUDIO5,
70 CX25840_AUDIO6,
71 CX25840_AUDIO7,
72 CX25840_AUDIO8,
73};
74
75struct cx25840_state { 35struct cx25840_state {
76 int pvr150_workaround; 36 int pvr150_workaround;
77 int radio; 37 int radio;
diff --git a/drivers/media/video/cx25840/cx25840-firmware.c b/drivers/media/video/cx25840/cx25840-firmware.c
index e1a7823d82cd..f59ced181c55 100644
--- a/drivers/media/video/cx25840/cx25840-firmware.c
+++ b/drivers/media/video/cx25840/cx25840-firmware.c
@@ -20,11 +20,22 @@
20#include <linux/i2c-algo-bit.h> 20#include <linux/i2c-algo-bit.h>
21#include <linux/firmware.h> 21#include <linux/firmware.h>
22#include <media/v4l2-common.h> 22#include <media/v4l2-common.h>
23#include <media/cx25840.h>
23 24
24#include "cx25840.h" 25#include "cx25840-core.h"
25 26
26#define FWFILE "v4l-cx25840.fw" 27#define FWFILE "v4l-cx25840.fw"
27#define FWSEND 1024 28
29/*
30 * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the
31 * size of the firmware chunks sent down the I2C bus to the chip.
32 * Previously this had been set to 1024 but unfortunately some I2C
33 * implementations can't transfer data in such big gulps.
34 * Specifically, the pvrusb2 driver has a hard limit of around 60
35 * bytes, due to the encapsulation there of I2C traffic into USB
36 * messages. So we have to significantly reduce this parameter.
37 */
38#define FWSEND 48
28 39
29#define FWDEV(x) &((x)->adapter->dev) 40#define FWDEV(x) &((x)->adapter->dev)
30 41
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index e96fd1f1d6dc..57feca288d2b 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -19,8 +19,9 @@
19#include <linux/videodev2.h> 19#include <linux/videodev2.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
22#include <media/cx25840.h>
22 23
23#include "cx25840.h" 24#include "cx25840-core.h"
24 25
25static int odd_parity(u8 c) 26static int odd_parity(u8 c)
26{ 27{
@@ -151,7 +152,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
151 case VIDIOC_G_FMT: 152 case VIDIOC_G_FMT:
152 { 153 {
153 static u16 lcr2vbi[] = { 154 static u16 lcr2vbi[] = {
154 0, V4L2_SLICED_TELETEXT_PAL_B, 0, /* 1 */ 155 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */
155 0, V4L2_SLICED_WSS_625, 0, /* 4 */ 156 0, V4L2_SLICED_WSS_625, 0, /* 4 */
156 V4L2_SLICED_CAPTION_525, /* 6 */ 157 V4L2_SLICED_CAPTION_525, /* 6 */
157 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */ 158 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
@@ -231,7 +232,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
231 for (i = 7; i <= 23; i++) { 232 for (i = 7; i <= 23; i++) {
232 for (x = 0; x <= 1; x++) { 233 for (x = 0; x <= 1; x++) {
233 switch (svbi->service_lines[1-x][i]) { 234 switch (svbi->service_lines[1-x][i]) {
234 case V4L2_SLICED_TELETEXT_PAL_B: 235 case V4L2_SLICED_TELETEXT_B:
235 lcr[i] |= 1 << (4 * x); 236 lcr[i] |= 1 << (4 * x);
236 break; 237 break;
237 case V4L2_SLICED_WSS_625: 238 case V4L2_SLICED_WSS_625:
@@ -282,7 +283,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
282 283
283 switch (id2) { 284 switch (id2) {
284 case 1: 285 case 1:
285 id2 = V4L2_SLICED_TELETEXT_PAL_B; 286 id2 = V4L2_SLICED_TELETEXT_B;
286 break; 287 break;
287 case 4: 288 case 4:
288 id2 = V4L2_SLICED_WSS_625; 289 id2 = V4L2_SLICED_WSS_625;
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index ff0f72340d69..630273992a41 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -1,3 +1,7 @@
1config VIDEO_CX88_VP3054
2 tristate
3 depends on VIDEO_CX88_DVB && DVB_MT352
4
1config VIDEO_CX88 5config VIDEO_CX88
2 tristate "Conexant 2388x (bt878 successor) support" 6 tristate "Conexant 2388x (bt878 successor) support"
3 depends on VIDEO_DEV && PCI && I2C 7 depends on VIDEO_DEV && PCI && I2C
@@ -25,7 +29,7 @@ config VIDEO_CX88_ALSA
25 29
26 It only works with boards with function 01 enabled. 30 It only works with boards with function 01 enabled.
27 To check if your board supports, use lspci -n. 31 To check if your board supports, use lspci -n.
28 If supported, you should see 1471:8801 or 1471:8811 32 If supported, you should see 14f1:8801 or 14f1:8811
29 PCI device. 33 PCI device.
30 34
31 To compile this driver as a module, choose M here: the 35 To compile this driver as a module, choose M here: the
@@ -73,10 +77,11 @@ config VIDEO_CX88_DVB_MT352
73 This adds DVB-T support for cards based on the 77 This adds DVB-T support for cards based on the
74 Connexant 2388x chip and the MT352 demodulator. 78 Connexant 2388x chip and the MT352 demodulator.
75 79
76config VIDEO_CX88_VP3054 80config VIDEO_CX88_DVB_VP3054
77 tristate "VP-3054 Secondary I2C Bus Support" 81 bool "VP-3054 Secondary I2C Bus Support"
78 default m 82 default y
79 depends on DVB_MT352 83 depends on VIDEO_CX88_DVB_MT352
84 select VIDEO_CX88_VP3054
80 ---help--- 85 ---help---
81 This adds DVB-T support for cards based on the 86 This adds DVB-T support for cards based on the
82 Connexant 2388x chip and the MT352 demodulator, 87 Connexant 2388x chip and the MT352 demodulator,
diff --git a/drivers/media/video/cx88/Makefile b/drivers/media/video/cx88/Makefile
index 6482b9aa6a1f..0dcd09b9b727 100644
--- a/drivers/media/video/cx88/Makefile
+++ b/drivers/media/video/cx88/Makefile
@@ -8,9 +8,9 @@ obj-$(CONFIG_VIDEO_CX88_DVB) += cx88-dvb.o
8obj-$(CONFIG_VIDEO_CX88_ALSA) += cx88-alsa.o 8obj-$(CONFIG_VIDEO_CX88_ALSA) += cx88-alsa.o
9obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o 9obj-$(CONFIG_VIDEO_CX88_VP3054) += cx88-vp3054-i2c.o
10 10
11EXTRA_CFLAGS += -I$(src)/.. 11EXTRA_CFLAGS += -Idrivers/media/video
12EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 12EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
13EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/frontends 13EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
14 14
15extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1 15extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1
16extra-cflags-$(CONFIG_DVB_CX22702) += -DHAVE_CX22702=1 16extra-cflags-$(CONFIG_DVB_CX22702) += -DHAVE_CX22702=1
diff --git a/drivers/media/video/em28xx/Makefile b/drivers/media/video/em28xx/Makefile
index da457a05b0dd..826d0e340753 100644
--- a/drivers/media/video/em28xx/Makefile
+++ b/drivers/media/video/em28xx/Makefile
@@ -3,4 +3,4 @@ em28xx-objs := em28xx-video.o em28xx-i2c.o em28xx-cards.o em28xx-core.o \
3 3
4obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o 4obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
5 5
6EXTRA_CFLAGS += -I$(src)/.. 6EXTRA_CFLAGS += -Idrivers/media/video
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index f62fd706b45a..3ba3439db580 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -151,8 +151,8 @@ struct em28xx_board em28xx_boards[] = {
151 },{ 151 },{
152 .type = EM28XX_VMUX_SVIDEO, 152 .type = EM28XX_VMUX_SVIDEO,
153 .vmux = 2, 153 .vmux = 2,
154 .amux = MSP_INPUT(MSP_IN_SCART_1, MSP_IN_TUNER_1, 154 .amux = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
155 MSP_DSP_OUT_SCART, MSP_DSP_OUT_SCART), 155 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
156 }}, 156 }},
157 }, 157 },
158 [EM2820_BOARD_MSI_VOX_USB_2] = { 158 [EM2820_BOARD_MSI_VOX_USB_2] = {
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index dfba33d0fa61..ddc92cbb5276 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -222,7 +222,7 @@ static void video_mux(struct em28xx *dev, int index)
222 if (dev->i2s_speed) 222 if (dev->i2s_speed)
223 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); 223 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed);
224 route.input = dev->ctl_ainput; 224 route.input = dev->ctl_ainput;
225 route.output = MSP_OUTPUT(MSP_OUT_SCART1_DA); 225 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
226 /* Note: this is msp3400 specific */ 226 /* Note: this is msp3400 specific */
227 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route); 227 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route);
228 ainput = EM28XX_AUDIO_SRC_TUNER; 228 ainput = EM28XX_AUDIO_SRC_TUNER;
@@ -1141,26 +1141,16 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp,
1141 case VIDIOC_G_TUNER: 1141 case VIDIOC_G_TUNER:
1142 { 1142 {
1143 struct v4l2_tuner *t = arg; 1143 struct v4l2_tuner *t = arg;
1144 int status = 0;
1145 1144
1146 if (0 != t->index) 1145 if (0 != t->index)
1147 return -EINVAL; 1146 return -EINVAL;
1148 1147
1149 memset(t, 0, sizeof(*t)); 1148 memset(t, 0, sizeof(*t));
1150 strcpy(t->name, "Tuner"); 1149 strcpy(t->name, "Tuner");
1151 t->type = V4L2_TUNER_ANALOG_TV;
1152 t->capability = V4L2_TUNER_CAP_NORM;
1153 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
1154/* t->signal = 0xffff;*/
1155/* em28xx_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/
1156 /* No way to get signal strength? */
1157 mutex_lock(&dev->lock); 1150 mutex_lock(&dev->lock);
1158 em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, 1151 /* let clients fill in the remainder of this struct */
1159 &status); 1152 em28xx_i2c_call_clients(dev, cmd, t);
1160 mutex_unlock(&dev->lock); 1153 mutex_unlock(&dev->lock);
1161 t->signal =
1162 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
1163
1164 em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal, 1154 em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal,
1165 t->afc); 1155 t->afc);
1166 return 0; 1156 return 0;
@@ -1168,26 +1158,13 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp,
1168 case VIDIOC_S_TUNER: 1158 case VIDIOC_S_TUNER:
1169 { 1159 {
1170 struct v4l2_tuner *t = arg; 1160 struct v4l2_tuner *t = arg;
1171 int status = 0;
1172 1161
1173 if (0 != t->index) 1162 if (0 != t->index)
1174 return -EINVAL; 1163 return -EINVAL;
1175 memset(t, 0, sizeof(*t));
1176 strcpy(t->name, "Tuner");
1177 t->type = V4L2_TUNER_ANALOG_TV;
1178 t->capability = V4L2_TUNER_CAP_NORM;
1179 t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
1180/* t->signal = 0xffff; */
1181 /* No way to get signal strength? */
1182 mutex_lock(&dev->lock); 1164 mutex_lock(&dev->lock);
1183 em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, 1165 /* let clients handle this */
1184 &status); 1166 em28xx_i2c_call_clients(dev, cmd, t);
1185 mutex_unlock(&dev->lock); 1167 mutex_unlock(&dev->lock);
1186 t->signal =
1187 (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
1188
1189 em28xx_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n",
1190 t->signal, t->afc);
1191 return 0; 1168 return 0;
1192 } 1169 }
1193 case VIDIOC_G_FREQUENCY: 1170 case VIDIOC_G_FREQUENCY:
diff --git a/drivers/media/video/et61x251/Kconfig b/drivers/media/video/et61x251/Kconfig
new file mode 100644
index 000000000000..6c43a90c6569
--- /dev/null
+++ b/drivers/media/video/et61x251/Kconfig
@@ -0,0 +1,14 @@
1config USB_ET61X251
2 tristate "USB ET61X[12]51 PC Camera Controller support"
3 depends on USB && VIDEO_DEV
4 ---help---
5 Say Y here if you want support for cameras based on Etoms ET61X151
6 or ET61X251 PC Camera Controllers.
7
8 See <file:Documentation/video4linux/et61x251.txt> for more info.
9
10 This driver uses the Video For Linux API. You must say Y or M to
11 "Video For Linux" to use this driver.
12
13 To compile this driver as a module, choose M here: the
14 module will be called et61x251.
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 95bacf435414..7e66d83fe0ce 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -411,6 +411,9 @@ static int ir_probe(struct i2c_adapter *adap)
411 case I2C_HW_B_BT848: 411 case I2C_HW_B_BT848:
412 probe = probe_bttv; 412 probe = probe_bttv;
413 break; 413 break;
414 case I2C_HW_B_CX2341X:
415 probe = probe_bttv;
416 break;
414 case I2C_HW_SAA7134: 417 case I2C_HW_SAA7134:
415 probe = probe_saa7134; 418 probe = probe_saa7134;
416 break; 419 break;
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index c40e8ba9a2ea..b806999d6e0f 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -279,20 +279,8 @@ void msp_set_scart(struct i2c_client *client, int in, int out)
279 msp_write_dsp(client, 0x13, state->acb); 279 msp_write_dsp(client, 0x13, state->acb);
280 280
281 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */ 281 /* Sets I2S speed 0 = 1.024 Mbps, 1 = 2.048 Mbps */
282 msp_write_dem(client, 0x40, state->i2s_mode); 282 if (state->has_i2s_conf)
283} 283 msp_write_dem(client, 0x40, state->i2s_mode);
284
285void msp_set_mute(struct i2c_client *client)
286{
287 struct msp_state *state = i2c_get_clientdata(client);
288
289 v4l_dbg(1, msp_debug, client, "mute audio\n");
290 msp_write_dsp(client, 0x0000, 0);
291 msp_write_dsp(client, 0x0007, 1);
292 if (state->has_scart2_out_volume)
293 msp_write_dsp(client, 0x0040, 1);
294 if (state->has_headphones)
295 msp_write_dsp(client, 0x0006, 0);
296} 284}
297 285
298void msp_set_audio(struct i2c_client *client) 286void msp_set_audio(struct i2c_client *client)
@@ -300,17 +288,19 @@ void msp_set_audio(struct i2c_client *client)
300 struct msp_state *state = i2c_get_clientdata(client); 288 struct msp_state *state = i2c_get_clientdata(client);
301 int bal = 0, bass, treble, loudness; 289 int bal = 0, bass, treble, loudness;
302 int val = 0; 290 int val = 0;
291 int reallymuted = state->muted | state->scan_in_progress;
303 292
304 if (!state->muted) 293 if (!reallymuted)
305 val = (state->volume * 0x7f / 65535) << 8; 294 val = (state->volume * 0x7f / 65535) << 8;
306 295
307 v4l_dbg(1, msp_debug, client, "mute=%s volume=%d\n", 296 v4l_dbg(1, msp_debug, client, "mute=%s scanning=%s volume=%d\n",
308 state->muted ? "on" : "off", state->volume); 297 state->muted ? "on" : "off", state->scan_in_progress ? "yes" : "no",
298 state->volume);
309 299
310 msp_write_dsp(client, 0x0000, val); 300 msp_write_dsp(client, 0x0000, val);
311 msp_write_dsp(client, 0x0007, state->muted ? 0x1 : (val | 0x1)); 301 msp_write_dsp(client, 0x0007, reallymuted ? 0x1 : (val | 0x1));
312 if (state->has_scart2_out_volume) 302 if (state->has_scart2_out_volume)
313 msp_write_dsp(client, 0x0040, state->muted ? 0x1 : (val | 0x1)); 303 msp_write_dsp(client, 0x0040, reallymuted ? 0x1 : (val | 0x1));
314 if (state->has_headphones) 304 if (state->has_headphones)
315 msp_write_dsp(client, 0x0006, val); 305 msp_write_dsp(client, 0x0006, val);
316 if (!state->has_sound_processing) 306 if (!state->has_sound_processing)
@@ -346,7 +336,6 @@ static void msp_wake_thread(struct i2c_client *client)
346 336
347 if (NULL == state->kthread) 337 if (NULL == state->kthread)
348 return; 338 return;
349 msp_set_mute(client);
350 state->watch_stereo = 0; 339 state->watch_stereo = 0;
351 state->restart = 1; 340 state->restart = 1;
352 wake_up_interruptible(&state->wq); 341 wake_up_interruptible(&state->wq);
@@ -374,19 +363,15 @@ int msp_sleep(struct msp_state *state, int timeout)
374 363
375/* ------------------------------------------------------------------------ */ 364/* ------------------------------------------------------------------------ */
376 365
377static int msp_mode_v4l2_to_v4l1(int rxsubchans) 366static int msp_mode_v4l2_to_v4l1(int rxsubchans, int audmode)
378{ 367{
379 int mode = 0; 368 if (rxsubchans == V4L2_TUNER_SUB_MONO)
380 369 return VIDEO_SOUND_MONO;
381 if (rxsubchans & V4L2_TUNER_SUB_STEREO) 370 if (rxsubchans == V4L2_TUNER_SUB_STEREO)
382 mode |= VIDEO_SOUND_STEREO; 371 return VIDEO_SOUND_STEREO;
383 if (rxsubchans & V4L2_TUNER_SUB_LANG2) 372 if (audmode == V4L2_TUNER_MODE_LANG2)
384 mode |= VIDEO_SOUND_LANG2 | VIDEO_SOUND_STEREO; 373 return VIDEO_SOUND_LANG2;
385 if (rxsubchans & V4L2_TUNER_SUB_LANG1) 374 return VIDEO_SOUND_LANG1;
386 mode |= VIDEO_SOUND_LANG1 | VIDEO_SOUND_STEREO;
387 if (mode == 0)
388 mode |= VIDEO_SOUND_MONO;
389 return mode;
390} 375}
391 376
392static int msp_mode_v4l1_to_v4l2(int mode) 377static int msp_mode_v4l1_to_v4l2(int mode)
@@ -605,7 +590,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
605 break; 590 break;
606 if (state->opmode == OPMODE_AUTOSELECT) 591 if (state->opmode == OPMODE_AUTOSELECT)
607 msp_detect_stereo(client); 592 msp_detect_stereo(client);
608 va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans); 593 va->mode = msp_mode_v4l2_to_v4l1(state->rxsubchans, state->audmode);
609 break; 594 break;
610 } 595 }
611 596
@@ -620,7 +605,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
620 state->treble = va->treble; 605 state->treble = va->treble;
621 msp_set_audio(client); 606 msp_set_audio(client);
622 607
623 if (va->mode != 0 && state->radio == 0) { 608 if (va->mode != 0 && state->radio == 0 &&
609 state->audmode != msp_mode_v4l1_to_v4l2(va->mode)) {
624 state->audmode = msp_mode_v4l1_to_v4l2(va->mode); 610 state->audmode = msp_mode_v4l1_to_v4l2(va->mode);
625 msp_set_audmode(client); 611 msp_set_audmode(client);
626 } 612 }
@@ -687,21 +673,23 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
687 int sc_in = rt->input & 0x7; 673 int sc_in = rt->input & 0x7;
688 int sc1_out = rt->output & 0xf; 674 int sc1_out = rt->output & 0xf;
689 int sc2_out = (rt->output >> 4) & 0xf; 675 int sc2_out = (rt->output >> 4) & 0xf;
690 u16 val; 676 u16 val, reg;
691 677
678 if (state->routing.input == rt->input &&
679 state->routing.output == rt->output)
680 break;
692 state->routing = *rt; 681 state->routing = *rt;
693 if (state->opmode == OPMODE_AUTOSELECT) {
694 val = msp_read_dem(client, 0x30) & ~0x100;
695 msp_write_dem(client, 0x30, val | (tuner ? 0x100 : 0));
696 } else {
697 val = msp_read_dem(client, 0xbb) & ~0x100;
698 msp_write_dem(client, 0xbb, val | (tuner ? 0x100 : 0));
699 }
700 msp_set_scart(client, sc_in, 0); 682 msp_set_scart(client, sc_in, 0);
701 msp_set_scart(client, sc1_out, 1); 683 msp_set_scart(client, sc1_out, 1);
702 msp_set_scart(client, sc2_out, 2); 684 msp_set_scart(client, sc2_out, 2);
703 msp_set_audmode(client); 685 msp_set_audmode(client);
704 msp_wake_thread(client); 686 reg = (state->opmode == OPMODE_AUTOSELECT) ? 0x30 : 0xbb;
687 val = msp_read_dem(client, reg);
688 if (tuner != ((val >> 8) & 1)) {
689 msp_write_dem(client, reg, (val & ~0x100) | (tuner << 8));
690 /* wake thread when a new tuner input is chosen */
691 msp_wake_thread(client);
692 }
705 break; 693 break;
706 } 694 }
707 695
@@ -715,7 +703,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
715 msp_detect_stereo(client); 703 msp_detect_stereo(client);
716 vt->audmode = state->audmode; 704 vt->audmode = state->audmode;
717 vt->rxsubchans = state->rxsubchans; 705 vt->rxsubchans = state->rxsubchans;
718 vt->capability = V4L2_TUNER_CAP_STEREO | 706 vt->capability |= V4L2_TUNER_CAP_STEREO |
719 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; 707 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
720 break; 708 break;
721 } 709 }
@@ -726,6 +714,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
726 714
727 if (state->radio) /* TODO: add mono/stereo support for radio */ 715 if (state->radio) /* TODO: add mono/stereo support for radio */
728 break; 716 break;
717 if (state->audmode == vt->audmode)
718 break;
729 state->audmode = vt->audmode; 719 state->audmode = vt->audmode;
730 /* only set audmode */ 720 /* only set audmode */
731 msp_set_audmode(client); 721 msp_set_audmode(client);
@@ -887,7 +877,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
887 877
888 memset(state, 0, sizeof(*state)); 878 memset(state, 0, sizeof(*state));
889 state->v4l2_std = V4L2_STD_NTSC; 879 state->v4l2_std = V4L2_STD_NTSC;
890 state->audmode = V4L2_TUNER_MODE_LANG1; 880 state->audmode = V4L2_TUNER_MODE_STEREO;
891 state->volume = 58880; /* 0db gain */ 881 state->volume = 58880; /* 0db gain */
892 state->balance = 32768; /* 0db gain */ 882 state->balance = 32768; /* 0db gain */
893 state->bass = 32768; 883 state->bass = 32768;
@@ -931,13 +921,16 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
931 state->has_radio = msp_revision >= 'G'; 921 state->has_radio = msp_revision >= 'G';
932 /* Has headphones output: not for stripped down products */ 922 /* Has headphones output: not for stripped down products */
933 state->has_headphones = msp_prod_lo < 5; 923 state->has_headphones = msp_prod_lo < 5;
924 /* Has scart2 input: not in stripped down products of the '3' family */
925 state->has_scart2 = msp_family >= 4 || msp_prod_lo < 7;
926 /* Has scart3 input: not in stripped down products of the '3' family */
927 state->has_scart3 = msp_family >= 4 || msp_prod_lo < 5;
934 /* Has scart4 input: not in pre D revisions, not in stripped D revs */ 928 /* Has scart4 input: not in pre D revisions, not in stripped D revs */
935 state->has_scart4 = msp_family >= 4 || (msp_revision >= 'D' && msp_prod_lo < 5); 929 state->has_scart4 = msp_family >= 4 || (msp_revision >= 'D' && msp_prod_lo < 5);
936 /* Has scart2 and scart3 inputs and scart2 output: not in stripped 930 /* Has scart2 output: not in stripped down products of the '3' family */
937 down products of the '3' family */ 931 state->has_scart2_out = msp_family >= 4 || msp_prod_lo < 5;
938 state->has_scart23_in_scart2_out = msp_family >= 4 || msp_prod_lo < 5;
939 /* Has scart2 a volume control? Not in pre-D revisions. */ 932 /* Has scart2 a volume control? Not in pre-D revisions. */
940 state->has_scart2_out_volume = msp_revision > 'C' && state->has_scart23_in_scart2_out; 933 state->has_scart2_out_volume = msp_revision > 'C' && state->has_scart2_out;
941 /* Has a configurable i2s out? */ 934 /* Has a configurable i2s out? */
942 state->has_i2s_conf = msp_revision >= 'G' && msp_prod_lo < 7; 935 state->has_i2s_conf = msp_revision >= 'G' && msp_prod_lo < 7;
943 /* Has subwoofer output: not in pre-D revs and not in stripped down products */ 936 /* Has subwoofer output: not in pre-D revs and not in stripped down products */
diff --git a/drivers/media/video/msp3400-driver.h b/drivers/media/video/msp3400-driver.h
index 1940748bb633..4e451049013d 100644
--- a/drivers/media/video/msp3400-driver.h
+++ b/drivers/media/video/msp3400-driver.h
@@ -54,8 +54,10 @@ struct msp_state {
54 u8 has_radio; 54 u8 has_radio;
55 u8 has_headphones; 55 u8 has_headphones;
56 u8 has_ntsc_jp_d_k3; 56 u8 has_ntsc_jp_d_k3;
57 u8 has_scart2;
58 u8 has_scart3;
57 u8 has_scart4; 59 u8 has_scart4;
58 u8 has_scart23_in_scart2_out; 60 u8 has_scart2_out;
59 u8 has_scart2_out_volume; 61 u8 has_scart2_out_volume;
60 u8 has_i2s_conf; 62 u8 has_i2s_conf;
61 u8 has_subwoofer; 63 u8 has_subwoofer;
@@ -83,6 +85,7 @@ struct msp_state {
83 int volume, muted; 85 int volume, muted;
84 int balance, loudness; 86 int balance, loudness;
85 int bass, treble; 87 int bass, treble;
88 int scan_in_progress;
86 89
87 /* thread */ 90 /* thread */
88 struct task_struct *kthread; 91 struct task_struct *kthread;
@@ -98,7 +101,6 @@ int msp_read_dem(struct i2c_client *client, int addr);
98int msp_read_dsp(struct i2c_client *client, int addr); 101int msp_read_dsp(struct i2c_client *client, int addr);
99int msp_reset(struct i2c_client *client); 102int msp_reset(struct i2c_client *client);
100void msp_set_scart(struct i2c_client *client, int in, int out); 103void msp_set_scart(struct i2c_client *client, int in, int out);
101void msp_set_mute(struct i2c_client *client);
102void msp_set_audio(struct i2c_client *client); 104void msp_set_audio(struct i2c_client *client);
103int msp_sleep(struct msp_state *state, int timeout); 105int msp_sleep(struct msp_state *state, int timeout);
104 106
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index c3984ea9ca07..633a10213789 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -170,7 +170,7 @@ static void msp_set_source(struct i2c_client *client, u16 src)
170 msp_write_dsp(client, 0x000a, src); 170 msp_write_dsp(client, 0x000a, src);
171 msp_write_dsp(client, 0x000b, src); 171 msp_write_dsp(client, 0x000b, src);
172 msp_write_dsp(client, 0x000c, src); 172 msp_write_dsp(client, 0x000c, src);
173 if (state->has_scart23_in_scart2_out) 173 if (state->has_scart2_out)
174 msp_write_dsp(client, 0x0041, src); 174 msp_write_dsp(client, 0x0041, src);
175} 175}
176 176
@@ -228,6 +228,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
228 char *modestr = (state->audmode >= 0 && state->audmode < 5) ? 228 char *modestr = (state->audmode >= 0 && state->audmode < 5) ?
229 strmode[state->audmode] : "unknown"; 229 strmode[state->audmode] : "unknown";
230 int src = 0; /* channel source: FM/AM, nicam or SCART */ 230 int src = 0; /* channel source: FM/AM, nicam or SCART */
231 int audmode = state->audmode;
231 232
232 if (state->opmode == OPMODE_AUTOSELECT) { 233 if (state->opmode == OPMODE_AUTOSELECT) {
233 /* this method would break everything, let's make sure 234 /* this method would break everything, let's make sure
@@ -239,11 +240,29 @@ static void msp3400c_set_audmode(struct i2c_client *client)
239 return; 240 return;
240 } 241 }
241 242
243 /* Note: for the C and D revs no NTSC stereo + SAP is possible as
244 the hardware does not support SAP. So the rxsubchans combination
245 of STEREO | LANG2 does not occur. */
246
247 /* switch to mono if only mono is available */
248 if (state->rxsubchans == V4L2_TUNER_SUB_MONO)
249 audmode = V4L2_TUNER_MODE_MONO;
250 /* if bilingual */
251 else if (state->rxsubchans & V4L2_TUNER_SUB_LANG2) {
252 /* and mono or stereo, then fallback to lang1 */
253 if (audmode == V4L2_TUNER_MODE_MONO ||
254 audmode == V4L2_TUNER_MODE_STEREO)
255 audmode = V4L2_TUNER_MODE_LANG1;
256 }
257 /* if stereo, and audmode is not mono, then switch to stereo */
258 else if (audmode != V4L2_TUNER_MODE_MONO)
259 audmode = V4L2_TUNER_MODE_STEREO;
260
242 /* switch demodulator */ 261 /* switch demodulator */
243 switch (state->mode) { 262 switch (state->mode) {
244 case MSP_MODE_FM_TERRA: 263 case MSP_MODE_FM_TERRA:
245 v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr); 264 v4l_dbg(1, msp_debug, client, "FM set_audmode: %s\n", modestr);
246 switch (state->audmode) { 265 switch (audmode) {
247 case V4L2_TUNER_MODE_STEREO: 266 case V4L2_TUNER_MODE_STEREO:
248 msp_write_dsp(client, 0x000e, 0x3001); 267 msp_write_dsp(client, 0x000e, 0x3001);
249 break; 268 break;
@@ -257,7 +276,7 @@ static void msp3400c_set_audmode(struct i2c_client *client)
257 break; 276 break;
258 case MSP_MODE_FM_SAT: 277 case MSP_MODE_FM_SAT:
259 v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr); 278 v4l_dbg(1, msp_debug, client, "SAT set_audmode: %s\n", modestr);
260 switch (state->audmode) { 279 switch (audmode) {
261 case V4L2_TUNER_MODE_MONO: 280 case V4L2_TUNER_MODE_MONO:
262 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5)); 281 msp3400c_set_carrier(client, MSP_CARRIER(6.5), MSP_CARRIER(6.5));
263 break; 282 break;
@@ -296,7 +315,8 @@ static void msp3400c_set_audmode(struct i2c_client *client)
296 } 315 }
297 316
298 /* switch audio */ 317 /* switch audio */
299 switch (state->audmode) { 318 v4l_dbg(1, msp_debug, client, "set audmode %d\n", audmode);
319 switch (audmode) {
300 case V4L2_TUNER_MODE_STEREO: 320 case V4L2_TUNER_MODE_STEREO:
301 case V4L2_TUNER_MODE_LANG1_LANG2: 321 case V4L2_TUNER_MODE_LANG1_LANG2:
302 src |= 0x0020; 322 src |= 0x0020;
@@ -314,10 +334,6 @@ static void msp3400c_set_audmode(struct i2c_client *client)
314 src = 0x0030; 334 src = 0x0030;
315 break; 335 break;
316 case V4L2_TUNER_MODE_LANG1: 336 case V4L2_TUNER_MODE_LANG1:
317 /* switch to stereo for stereo transmission, otherwise
318 keep first language */
319 if (state->rxsubchans & V4L2_TUNER_SUB_STEREO)
320 src |= 0x0020;
321 break; 337 break;
322 case V4L2_TUNER_MODE_LANG2: 338 case V4L2_TUNER_MODE_LANG2:
323 src |= 0x0010; 339 src |= 0x0010;
@@ -367,7 +383,7 @@ static int msp3400c_detect_stereo(struct i2c_client *client)
367 if (val > 32767) 383 if (val > 32767)
368 val -= 65536; 384 val -= 65536;
369 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val); 385 v4l_dbg(2, msp_debug, client, "stereo detect register: %d\n", val);
370 if (val > 4096) { 386 if (val > 8192) {
371 rxsubchans = V4L2_TUNER_SUB_STEREO; 387 rxsubchans = V4L2_TUNER_SUB_STEREO;
372 } else if (val < -4096) { 388 } else if (val < -4096) {
373 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; 389 rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
@@ -464,19 +480,22 @@ int msp3400c_thread(void *data)
464 if (state->radio || MSP_MODE_EXTERN == state->mode) { 480 if (state->radio || MSP_MODE_EXTERN == state->mode) {
465 /* no carrier scan, just unmute */ 481 /* no carrier scan, just unmute */
466 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 482 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
483 state->scan_in_progress = 0;
467 msp_set_audio(client); 484 msp_set_audio(client);
468 continue; 485 continue;
469 } 486 }
470 487
471 /* mute */ 488 /* mute audio */
472 msp_set_mute(client); 489 state->scan_in_progress = 1;
490 msp_set_audio(client);
491
473 msp3400c_set_mode(client, MSP_MODE_AM_DETECT); 492 msp3400c_set_mode(client, MSP_MODE_AM_DETECT);
474 val1 = val2 = 0; 493 val1 = val2 = 0;
475 max1 = max2 = -1; 494 max1 = max2 = -1;
476 state->watch_stereo = 0; 495 state->watch_stereo = 0;
477 state->nicam_on = 0; 496 state->nicam_on = 0;
478 497
479 /* some time for the tuner to sync */ 498 /* wait for tuner to settle down after a channel change */
480 if (msp_sleep(state, 200)) 499 if (msp_sleep(state, 200))
481 goto restart; 500 goto restart;
482 501
@@ -552,7 +571,6 @@ int msp3400c_thread(void *data)
552 /* B/G NICAM */ 571 /* B/G NICAM */
553 state->second = msp3400c_carrier_detect_55[max2].cdo; 572 state->second = msp3400c_carrier_detect_55[max2].cdo;
554 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1); 573 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
555 msp3400c_set_carrier(client, state->second, state->main);
556 state->nicam_on = 1; 574 state->nicam_on = 1;
557 state->watch_stereo = 1; 575 state->watch_stereo = 1;
558 } else { 576 } else {
@@ -563,7 +581,6 @@ int msp3400c_thread(void *data)
563 /* PAL I NICAM */ 581 /* PAL I NICAM */
564 state->second = MSP_CARRIER(6.552); 582 state->second = MSP_CARRIER(6.552);
565 msp3400c_set_mode(client, MSP_MODE_FM_NICAM2); 583 msp3400c_set_mode(client, MSP_MODE_FM_NICAM2);
566 msp3400c_set_carrier(client, state->second, state->main);
567 state->nicam_on = 1; 584 state->nicam_on = 1;
568 state->watch_stereo = 1; 585 state->watch_stereo = 1;
569 break; 586 break;
@@ -577,13 +594,11 @@ int msp3400c_thread(void *data)
577 /* L NICAM or AM-mono */ 594 /* L NICAM or AM-mono */
578 state->second = msp3400c_carrier_detect_65[max2].cdo; 595 state->second = msp3400c_carrier_detect_65[max2].cdo;
579 msp3400c_set_mode(client, MSP_MODE_AM_NICAM); 596 msp3400c_set_mode(client, MSP_MODE_AM_NICAM);
580 msp3400c_set_carrier(client, state->second, state->main);
581 state->watch_stereo = 1; 597 state->watch_stereo = 1;
582 } else if (max2 == 0 && state->has_nicam) { 598 } else if (max2 == 0 && state->has_nicam) {
583 /* D/K NICAM */ 599 /* D/K NICAM */
584 state->second = msp3400c_carrier_detect_65[max2].cdo; 600 state->second = msp3400c_carrier_detect_65[max2].cdo;
585 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1); 601 msp3400c_set_mode(client, MSP_MODE_FM_NICAM1);
586 msp3400c_set_carrier(client, state->second, state->main);
587 state->nicam_on = 1; 602 state->nicam_on = 1;
588 state->watch_stereo = 1; 603 state->watch_stereo = 1;
589 } else { 604 } else {
@@ -595,25 +610,25 @@ int msp3400c_thread(void *data)
595 no_second: 610 no_second:
596 state->second = msp3400c_carrier_detect_main[max1].cdo; 611 state->second = msp3400c_carrier_detect_main[max1].cdo;
597 msp3400c_set_mode(client, MSP_MODE_FM_TERRA); 612 msp3400c_set_mode(client, MSP_MODE_FM_TERRA);
598 msp3400c_set_carrier(client, state->second, state->main);
599 state->rxsubchans = V4L2_TUNER_SUB_MONO;
600 break; 613 break;
601 } 614 }
615 msp3400c_set_carrier(client, state->second, state->main);
602 616
603 /* unmute */ 617 /* unmute */
604 msp_set_audio(client); 618 state->scan_in_progress = 0;
605 msp3400c_set_audmode(client); 619 msp3400c_set_audmode(client);
620 msp_set_audio(client);
606 621
607 if (msp_debug) 622 if (msp_debug)
608 msp3400c_print_mode(client); 623 msp3400c_print_mode(client);
609 624
610 /* monitor tv audio mode, the first time don't wait 625 /* monitor tv audio mode, the first time don't wait
611 so long to get a quick stereo/bilingual result */ 626 so long to get a quick stereo/bilingual result */
612 if (msp_sleep(state, 1000)) 627 count = 3;
613 goto restart;
614 while (state->watch_stereo) { 628 while (state->watch_stereo) {
615 if (msp_sleep(state, 5000)) 629 if (msp_sleep(state, count ? 1000 : 5000))
616 goto restart; 630 goto restart;
631 if (count) count--;
617 watch_stereo(client); 632 watch_stereo(client);
618 } 633 }
619 } 634 }
@@ -626,7 +641,7 @@ int msp3410d_thread(void *data)
626{ 641{
627 struct i2c_client *client = data; 642 struct i2c_client *client = data;
628 struct msp_state *state = i2c_get_clientdata(client); 643 struct msp_state *state = i2c_get_clientdata(client);
629 int val, i, std; 644 int val, i, std, count;
630 645
631 v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n"); 646 v4l_dbg(1, msp_debug, client, "msp3410 daemon started\n");
632 647
@@ -644,16 +659,14 @@ int msp3410d_thread(void *data)
644 if (state->mode == MSP_MODE_EXTERN) { 659 if (state->mode == MSP_MODE_EXTERN) {
645 /* no carrier scan needed, just unmute */ 660 /* no carrier scan needed, just unmute */
646 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 661 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
662 state->scan_in_progress = 0;
647 msp_set_audio(client); 663 msp_set_audio(client);
648 continue; 664 continue;
649 } 665 }
650 666
651 /* put into sane state (and mute) */ 667 /* mute audio */
652 msp_reset(client); 668 state->scan_in_progress = 1;
653 669 msp_set_audio(client);
654 /* some time for the tuner to sync */
655 if (msp_sleep(state,200))
656 goto restart;
657 670
658 /* start autodetect. Note: autodetect is not supported for 671 /* start autodetect. Note: autodetect is not supported for
659 NTSC-M and radio, hence we force the standard in those cases. */ 672 NTSC-M and radio, hence we force the standard in those cases. */
@@ -664,6 +677,10 @@ int msp3410d_thread(void *data)
664 state->watch_stereo = 0; 677 state->watch_stereo = 0;
665 state->nicam_on = 0; 678 state->nicam_on = 0;
666 679
680 /* wait for tuner to settle down after a channel change */
681 if (msp_sleep(state, 200))
682 goto restart;
683
667 if (msp_debug) 684 if (msp_debug)
668 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n", 685 v4l_dbg(2, msp_debug, client, "setting standard: %s (0x%04x)\n",
669 msp_standard_std_name(std), std); 686 msp_standard_std_name(std), std);
@@ -693,6 +710,7 @@ int msp3410d_thread(void *data)
693 state->main = msp_stdlist[i].main; 710 state->main = msp_stdlist[i].main;
694 state->second = msp_stdlist[i].second; 711 state->second = msp_stdlist[i].second;
695 state->std = val; 712 state->std = val;
713 state->rxsubchans = V4L2_TUNER_SUB_MONO;
696 714
697 if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) && 715 if (msp_amsound && !state->radio && (state->v4l2_std & V4L2_STD_SECAM) &&
698 (val != 0x0009)) { 716 (val != 0x0009)) {
@@ -714,20 +732,17 @@ int msp3410d_thread(void *data)
714 else 732 else
715 state->mode = MSP_MODE_FM_NICAM1; 733 state->mode = MSP_MODE_FM_NICAM1;
716 /* just turn on stereo */ 734 /* just turn on stereo */
717 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
718 state->nicam_on = 1; 735 state->nicam_on = 1;
719 state->watch_stereo = 1; 736 state->watch_stereo = 1;
720 break; 737 break;
721 case 0x0009: 738 case 0x0009:
722 state->mode = MSP_MODE_AM_NICAM; 739 state->mode = MSP_MODE_AM_NICAM;
723 state->rxsubchans = V4L2_TUNER_SUB_MONO;
724 state->nicam_on = 1; 740 state->nicam_on = 1;
725 state->watch_stereo = 1; 741 state->watch_stereo = 1;
726 break; 742 break;
727 case 0x0020: /* BTSC */ 743 case 0x0020: /* BTSC */
728 /* The pre-'G' models only have BTSC-mono */ 744 /* The pre-'G' models only have BTSC-mono */
729 state->mode = MSP_MODE_BTSC; 745 state->mode = MSP_MODE_BTSC;
730 state->rxsubchans = V4L2_TUNER_SUB_MONO;
731 break; 746 break;
732 case 0x0040: /* FM radio */ 747 case 0x0040: /* FM radio */
733 state->mode = MSP_MODE_FM_RADIO; 748 state->mode = MSP_MODE_FM_RADIO;
@@ -737,15 +752,12 @@ int msp3410d_thread(void *data)
737 msp3400c_set_mode(client, MSP_MODE_FM_RADIO); 752 msp3400c_set_mode(client, MSP_MODE_FM_RADIO);
738 msp3400c_set_carrier(client, MSP_CARRIER(10.7), 753 msp3400c_set_carrier(client, MSP_CARRIER(10.7),
739 MSP_CARRIER(10.7)); 754 MSP_CARRIER(10.7));
740 /* scart routing (this doesn't belong here I think) */
741 msp_set_scart(client,SCART_IN2,0);
742 break; 755 break;
743 case 0x0002: 756 case 0x0002:
744 case 0x0003: 757 case 0x0003:
745 case 0x0004: 758 case 0x0004:
746 case 0x0005: 759 case 0x0005:
747 state->mode = MSP_MODE_FM_TERRA; 760 state->mode = MSP_MODE_FM_TERRA;
748 state->rxsubchans = V4L2_TUNER_SUB_MONO;
749 state->watch_stereo = 1; 761 state->watch_stereo = 1;
750 break; 762 break;
751 } 763 }
@@ -759,20 +771,19 @@ int msp3410d_thread(void *data)
759 if (state->has_i2s_conf) 771 if (state->has_i2s_conf)
760 msp_write_dem(client, 0x40, state->i2s_mode); 772 msp_write_dem(client, 0x40, state->i2s_mode);
761 773
762 /* unmute, restore misc registers */ 774 /* unmute */
763 msp_set_audio(client);
764
765 msp_write_dsp(client, 0x13, state->acb);
766 msp3400c_set_audmode(client); 775 msp3400c_set_audmode(client);
776 state->scan_in_progress = 0;
777 msp_set_audio(client);
767 778
768 /* monitor tv audio mode, the first time don't wait 779 /* monitor tv audio mode, the first time don't wait
769 so long to get a quick stereo/bilingual result */ 780 so long to get a quick stereo/bilingual result */
770 if (msp_sleep(state, 1000)) 781 count = 3;
771 goto restart;
772 while (state->watch_stereo) { 782 while (state->watch_stereo) {
773 watch_stereo(client); 783 if (msp_sleep(state, count ? 1000 : 5000))
774 if (msp_sleep(state, 5000))
775 goto restart; 784 goto restart;
785 if (count) count--;
786 watch_stereo(client);
776 } 787 }
777 } 788 }
778 v4l_dbg(1, msp_debug, client, "thread: exit\n"); 789 v4l_dbg(1, msp_debug, client, "thread: exit\n");
@@ -829,27 +840,27 @@ static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
829 source = 0; /* mono only */ 840 source = 0; /* mono only */
830 matrix = 0x30; 841 matrix = 0x30;
831 break; 842 break;
832 case V4L2_TUNER_MODE_LANG1:
833 source = 3; /* stereo or A */
834 matrix = 0x00;
835 break;
836 case V4L2_TUNER_MODE_LANG2: 843 case V4L2_TUNER_MODE_LANG2:
837 source = 4; /* stereo or B */ 844 source = 4; /* stereo or B */
838 matrix = 0x10; 845 matrix = 0x10;
839 break; 846 break;
840 case V4L2_TUNER_MODE_STEREO:
841 case V4L2_TUNER_MODE_LANG1_LANG2: 847 case V4L2_TUNER_MODE_LANG1_LANG2:
842 default:
843 source = 1; /* stereo or A|B */ 848 source = 1; /* stereo or A|B */
844 matrix = 0x20; 849 matrix = 0x20;
845 break; 850 break;
851 case V4L2_TUNER_MODE_STEREO:
852 case V4L2_TUNER_MODE_LANG1:
853 default:
854 source = 3; /* stereo or A */
855 matrix = 0x00;
856 break;
846 } 857 }
847 858
848 if (in == MSP_DSP_OUT_TUNER) 859 if (in == MSP_DSP_IN_TUNER)
849 source = (source << 8) | 0x20; 860 source = (source << 8) | 0x20;
850 /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14 861 /* the msp34x2g puts the MAIN_AVC, MAIN and AUX sources in 12, 13, 14
851 instead of 11, 12, 13. So we add one for that msp version. */ 862 instead of 11, 12, 13. So we add one for that msp version. */
852 else if (in >= MSP_DSP_OUT_MAIN_AVC && state->has_dolby_pro_logic) 863 else if (in >= MSP_DSP_IN_MAIN_AVC && state->has_dolby_pro_logic)
853 source = ((in + 1) << 8) | matrix; 864 source = ((in + 1) << 8) | matrix;
854 else 865 else
855 source = (in << 8) | matrix; 866 source = (in << 8) | matrix;
@@ -869,7 +880,7 @@ static void msp34xxg_set_sources(struct i2c_client *client)
869 msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf); 880 msp34xxg_set_source(client, 0x000c, (in >> 4) & 0xf);
870 msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf); 881 msp34xxg_set_source(client, 0x0009, (in >> 8) & 0xf);
871 msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf); 882 msp34xxg_set_source(client, 0x000a, (in >> 12) & 0xf);
872 if (state->has_scart23_in_scart2_out) 883 if (state->has_scart2_out)
873 msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf); 884 msp34xxg_set_source(client, 0x0041, (in >> 16) & 0xf);
874 msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf); 885 msp34xxg_set_source(client, 0x000b, (in >> 20) & 0xf);
875} 886}
@@ -887,10 +898,6 @@ static void msp34xxg_reset(struct i2c_client *client)
887 898
888 msp_reset(client); 899 msp_reset(client);
889 900
890 /* make sure that input/output is muted (paranoid mode) */
891 /* ACB, mute DSP input, mute SCART 1 */
892 msp_write_dsp(client, 0x13, 0x0f20);
893
894 if (state->has_i2s_conf) 901 if (state->has_i2s_conf)
895 msp_write_dem(client, 0x40, state->i2s_mode); 902 msp_write_dem(client, 0x40, state->i2s_mode);
896 903
@@ -1028,7 +1035,7 @@ static void msp34xxg_set_audmode(struct i2c_client *client)
1028 1035
1029 if (state->std == 0x20) { 1036 if (state->std == 0x20) {
1030 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) && 1037 if ((state->rxsubchans & V4L2_TUNER_SUB_SAP) &&
1031 (state->audmode == V4L2_TUNER_MODE_STEREO || 1038 (state->audmode == V4L2_TUNER_MODE_LANG1_LANG2 ||
1032 state->audmode == V4L2_TUNER_MODE_LANG2)) { 1039 state->audmode == V4L2_TUNER_MODE_LANG2)) {
1033 msp_write_dem(client, 0x20, 0x21); 1040 msp_write_dem(client, 0x20, 0x21);
1034 } else { 1041 } else {
diff --git a/drivers/media/video/planb.c b/drivers/media/video/planb.c
index 522e9ddeb089..d9e3cada52f4 100644
--- a/drivers/media/video/planb.c
+++ b/drivers/media/video/planb.c
@@ -2156,7 +2156,7 @@ static int find_planb(void)
2156 struct pci_dev *pdev; 2156 struct pci_dev *pdev;
2157 int rc; 2157 int rc;
2158 2158
2159 if (_machine != _MACH_Pmac) 2159 if (!machine_is(powermac))
2160 return 0; 2160 return 0;
2161 2161
2162 planb_devices = find_devices("planb"); 2162 planb_devices = find_devices("planb");
diff --git a/drivers/media/video/pwc/Kconfig b/drivers/media/video/pwc/Kconfig
new file mode 100644
index 000000000000..86376556f108
--- /dev/null
+++ b/drivers/media/video/pwc/Kconfig
@@ -0,0 +1,28 @@
1config USB_PWC
2 tristate "USB Philips Cameras"
3 depends on USB && VIDEO_DEV
4 ---help---
5 Say Y or M here if you want to use one of these Philips & OEM
6 webcams:
7 * Philips PCA645, PCA646
8 * Philips PCVC675, PCVC680, PCVC690
9 * Philips PCVC720/40, PCVC730, PCVC740, PCVC750
10 * Askey VC010
11 * Logitech QuickCam Pro 3000, 4000, 'Zoom', 'Notebook Pro'
12 and 'Orbit'/'Sphere'
13 * Samsung MPC-C10, MPC-C30
14 * Creative Webcam 5, Pro Ex
15 * SOTEC Afina Eye
16 * Visionite VCS-UC300, VCS-UM100
17
18 The PCA635, PCVC665 and PCVC720/20 are not supported by this driver
19 and never will be, but the 665 and 720/20 are supported by other
20 drivers.
21
22 See <file:Documentation/usb/philips.txt> for more information and
23 installation instructions.
24
25 The built-in microphone is enabled by selecting USB Audio support.
26
27 To compile this driver as a module, choose M here: the
28 module will be called pwc.
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index b05015282601..dceebc0b1250 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -40,6 +40,7 @@
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/videodev2.h> 41#include <linux/videodev2.h>
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <media/saa7115.h>
43#include <asm/div64.h> 44#include <asm/div64.h>
44 45
45MODULE_DESCRIPTION("Philips SAA7113/SAA7114/SAA7115 video decoder driver"); 46MODULE_DESCRIPTION("Philips SAA7113/SAA7114/SAA7115 video decoder driver");
@@ -53,7 +54,7 @@ module_param(debug, bool, 0644);
53MODULE_PARM_DESC(debug, "Debug level (0-1)"); 54MODULE_PARM_DESC(debug, "Debug level (0-1)");
54 55
55static unsigned short normal_i2c[] = { 56static unsigned short normal_i2c[] = {
56 0x4a >>1, 0x48 >>1, /* SAA7113 */ 57 0x4a >> 1, 0x48 >> 1, /* SAA7113 */
57 0x42 >> 1, 0x40 >> 1, /* SAA7114 and SAA7115 */ 58 0x42 >> 1, 0x40 >> 1, /* SAA7114 and SAA7115 */
58 I2C_CLIENT_END }; 59 I2C_CLIENT_END };
59 60
@@ -722,16 +723,16 @@ static void saa7115_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
722 100 reserved NTSC-Japan (3.58MHz) 723 100 reserved NTSC-Japan (3.58MHz)
723 */ 724 */
724 if (state->ident == V4L2_IDENT_SAA7113) { 725 if (state->ident == V4L2_IDENT_SAA7113) {
725 u8 reg = saa7115_read(client, 0x0e) & 0x8f; 726 u8 reg = saa7115_read(client, 0x0e) & 0x8f;
726 727
727 if (std == V4L2_STD_PAL_M) { 728 if (std == V4L2_STD_PAL_M) {
728 reg|=0x30; 729 reg |= 0x30;
729 } else if (std == V4L2_STD_PAL_N) { 730 } else if (std == V4L2_STD_PAL_N) {
730 reg|=0x20; 731 reg |= 0x20;
731 } else if (std == V4L2_STD_PAL_60) { 732 } else if (std == V4L2_STD_PAL_60) {
732 reg|=0x10; 733 reg |= 0x10;
733 } else if (std == V4L2_STD_NTSC_M_JP) { 734 } else if (std == V4L2_STD_NTSC_M_JP) {
734 reg|=0x40; 735 reg |= 0x40;
735 } 736 }
736 saa7115_write(client, 0x0e, reg); 737 saa7115_write(client, 0x0e, reg);
737 } 738 }
@@ -811,7 +812,7 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
811 u8 lcr[24]; 812 u8 lcr[24];
812 int i, x; 813 int i, x;
813 814
814 /* saa7113/71144 doesn't yet support VBI */ 815 /* saa7113/7114 doesn't yet support VBI */
815 if (state->ident != V4L2_IDENT_SAA7115) 816 if (state->ident != V4L2_IDENT_SAA7115)
816 return; 817 return;
817 818
@@ -851,7 +852,7 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
851 case 0: 852 case 0:
852 lcr[i] |= 0xf << (4 * x); 853 lcr[i] |= 0xf << (4 * x);
853 break; 854 break;
854 case V4L2_SLICED_TELETEXT_PAL_B: 855 case V4L2_SLICED_TELETEXT_B:
855 lcr[i] |= 1 << (4 * x); 856 lcr[i] |= 1 << (4 * x);
856 break; 857 break;
857 case V4L2_SLICED_CAPTION_525: 858 case V4L2_SLICED_CAPTION_525:
@@ -880,7 +881,7 @@ static void saa7115_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
880static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) 881static int saa7115_get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
881{ 882{
882 static u16 lcr2vbi[] = { 883 static u16 lcr2vbi[] = {
883 0, V4L2_SLICED_TELETEXT_PAL_B, 0, /* 1 */ 884 0, V4L2_SLICED_TELETEXT_B, 0, /* 1 */
884 0, V4L2_SLICED_CAPTION_525, /* 4 */ 885 0, V4L2_SLICED_CAPTION_525, /* 4 */
885 V4L2_SLICED_WSS_625, 0, /* 5 */ 886 V4L2_SLICED_WSS_625, 0, /* 5 */
886 V4L2_SLICED_VPS, 0, 0, 0, 0, /* 7 */ 887 V4L2_SLICED_VPS, 0, 0, 0, 0, /* 7 */
@@ -1045,7 +1046,7 @@ static void saa7115_decode_vbi_line(struct i2c_client *client,
1045 /* decode payloads */ 1046 /* decode payloads */
1046 switch (id2) { 1047 switch (id2) {
1047 case 1: 1048 case 1:
1048 vbi->type = V4L2_SLICED_TELETEXT_PAL_B; 1049 vbi->type = V4L2_SLICED_TELETEXT_B;
1049 break; 1050 break;
1050 case 4: 1051 case 4:
1051 if (!saa7115_odd_parity(p[0]) || !saa7115_odd_parity(p[1])) 1052 if (!saa7115_odd_parity(p[0]) || !saa7115_odd_parity(p[1]))
@@ -1180,6 +1181,46 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1180 state->radio = 1; 1181 state->radio = 1;
1181 break; 1182 break;
1182 1183
1184 case VIDIOC_INT_G_VIDEO_ROUTING:
1185 {
1186 struct v4l2_routing *route = arg;
1187
1188 route->input = state->input;
1189 route->output = 0;
1190 break;
1191 }
1192
1193 case VIDIOC_INT_S_VIDEO_ROUTING:
1194 {
1195 struct v4l2_routing *route = arg;
1196
1197 v4l_dbg(1, debug, client, "decoder set input %d\n", route->input);
1198 /* saa7113 does not have these inputs */
1199 if (state->ident == V4L2_IDENT_SAA7113 &&
1200 (route->input == SAA7115_COMPOSITE4 ||
1201 route->input == SAA7115_COMPOSITE5)) {
1202 return -EINVAL;
1203 }
1204 if (route->input > SAA7115_SVIDEO3)
1205 return -EINVAL;
1206 if (state->input == route->input)
1207 break;
1208 v4l_dbg(1, debug, client, "now setting %s input\n",
1209 (route->input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite");
1210 state->input = route->input;
1211
1212 /* select mode */
1213 saa7115_write(client, 0x02,
1214 (saa7115_read(client, 0x02) & 0xf0) |
1215 state->input);
1216
1217 /* bypass chrominance trap for S-Video modes */
1218 saa7115_write(client, 0x09,
1219 (saa7115_read(client, 0x09) & 0x7f) |
1220 (state->input >= SAA7115_SVIDEO0 ? 0x80 : 0x0));
1221 break;
1222 }
1223
1183 case VIDIOC_G_INPUT: 1224 case VIDIOC_G_INPUT:
1184 *(int *)arg = state->input; 1225 *(int *)arg = state->input;
1185 break; 1226 break;
@@ -1321,7 +1362,7 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1321 1362
1322 saa7115_write(client, 0, 5); 1363 saa7115_write(client, 0, 5);
1323 chip_id = saa7115_read(client, 0) & 0x0f; 1364 chip_id = saa7115_read(client, 0) & 0x0f;
1324 if (chip_id <3 && chip_id > 5) { 1365 if (chip_id < 3 && chip_id > 5) {
1325 v4l_dbg(1, debug, client, "saa7115 not found\n"); 1366 v4l_dbg(1, debug, client, "saa7115 not found\n");
1326 kfree(client); 1367 kfree(client);
1327 return 0; 1368 return 0;
@@ -1360,7 +1401,7 @@ static int saa7115_attach(struct i2c_adapter *adapter, int address, int kind)
1360 v4l_dbg(1, debug, client, "writing init values\n"); 1401 v4l_dbg(1, debug, client, "writing init values\n");
1361 1402
1362 /* init to 60hz/48khz */ 1403 /* init to 60hz/48khz */
1363 if (state->ident==V4L2_IDENT_SAA7113) 1404 if (state->ident == V4L2_IDENT_SAA7113)
1364 saa7115_writeregs(client, saa7113_init_auto_input); 1405 saa7115_writeregs(client, saa7113_init_auto_input);
1365 else 1406 else
1366 saa7115_writeregs(client, saa7115_init_auto_input); 1407 saa7115_writeregs(client, saa7115_init_auto_input);
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index 992c71774f30..133f9e5252fe 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -54,6 +54,7 @@
54#include <linux/i2c.h> 54#include <linux/i2c.h>
55#include <linux/videodev2.h> 55#include <linux/videodev2.h>
56#include <media/v4l2-common.h> 56#include <media/v4l2-common.h>
57#include <media/saa7127.h>
57 58
58static int debug = 0; 59static int debug = 0;
59static int test_image = 0; 60static int test_image = 0;
@@ -222,22 +223,6 @@ static struct i2c_reg_value saa7127_init_config_50hz[] = {
222 { 0, 0 } 223 { 0, 0 }
223}; 224};
224 225
225/* Enumeration for the Supported input types */
226enum saa7127_input_type {
227 SAA7127_INPUT_TYPE_NORMAL,
228 SAA7127_INPUT_TYPE_TEST_IMAGE
229};
230
231/* Enumeration for the Supported Output signal types */
232enum saa7127_output_type {
233 SAA7127_OUTPUT_TYPE_BOTH,
234 SAA7127_OUTPUT_TYPE_COMPOSITE,
235 SAA7127_OUTPUT_TYPE_SVIDEO,
236 SAA7127_OUTPUT_TYPE_RGB,
237 SAA7127_OUTPUT_TYPE_YUV_C,
238 SAA7127_OUTPUT_TYPE_YUV_V
239};
240
241/* 226/*
242 ********************************************************************** 227 **********************************************************************
243 * 228 *
@@ -561,7 +546,7 @@ static int saa7127_command(struct i2c_client *client,
561{ 546{
562 struct saa7127_state *state = i2c_get_clientdata(client); 547 struct saa7127_state *state = i2c_get_clientdata(client);
563 struct v4l2_format *fmt = arg; 548 struct v4l2_format *fmt = arg;
564 int *iarg = arg; 549 struct v4l2_routing *route = arg;
565 550
566 switch (cmd) { 551 switch (cmd) {
567 case VIDIOC_S_STD: 552 case VIDIOC_S_STD:
@@ -573,15 +558,23 @@ static int saa7127_command(struct i2c_client *client,
573 *(v4l2_std_id *)arg = state->std; 558 *(v4l2_std_id *)arg = state->std;
574 break; 559 break;
575 560
576 case VIDIOC_S_INPUT: 561 case VIDIOC_INT_G_VIDEO_ROUTING:
577 if (state->input_type == *iarg) 562 route->input = state->input_type;
578 break; 563 route->output = state->output_type;
579 return saa7127_set_input_type(client, *iarg); 564 break;
580 565
581 case VIDIOC_S_OUTPUT: 566 case VIDIOC_INT_S_VIDEO_ROUTING:
582 if (state->output_type == *iarg) 567 {
583 break; 568 int rc = 0;
584 return saa7127_set_output_type(client, *iarg); 569
570 if (state->input_type != route->input) {
571 rc = saa7127_set_input_type(client, route->input);
572 }
573 if (rc == 0 && state->output_type != route->output) {
574 rc = saa7127_set_output_type(client, route->output);
575 }
576 return rc;
577 }
585 578
586 case VIDIOC_STREAMON: 579 case VIDIOC_STREAMON:
587 case VIDIOC_STREAMOFF: 580 case VIDIOC_STREAMOFF:
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 86671a43e769..e1c1805df1fb 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -39,6 +39,7 @@ config VIDEO_SAA7134_DVB
39 tristate "DVB/ATSC Support for saa7134 based TV cards" 39 tristate "DVB/ATSC Support for saa7134 based TV cards"
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 ---help--- 43 ---help---
43 This adds support for DVB cards based on the 44 This adds support for DVB cards based on the
44 Philips saa7134 chip. 45 Philips saa7134 chip.
diff --git a/drivers/media/video/saa7134/Makefile b/drivers/media/video/saa7134/Makefile
index 1ba998424bbd..be7b9ee697d6 100644
--- a/drivers/media/video/saa7134/Makefile
+++ b/drivers/media/video/saa7134/Makefile
@@ -11,9 +11,9 @@ obj-$(CONFIG_VIDEO_SAA7134_OSS) += saa7134-oss.o
11 11
12obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o 12obj-$(CONFIG_VIDEO_SAA7134_DVB) += saa7134-dvb.o
13 13
14EXTRA_CFLAGS += -I$(src)/.. 14EXTRA_CFLAGS += -Idrivers/media/video
15EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/dvb-core 15EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
16EXTRA_CFLAGS += -I$(srctree)/drivers/media/dvb/frontends 16EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
17 17
18extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1 18extra-cflags-$(CONFIG_VIDEO_BUF_DVB) += -DHAVE_VIDEO_BUF_DVB=1
19extra-cflags-$(CONFIG_DVB_MT352) += -DHAVE_MT352=1 19extra-cflags-$(CONFIG_DVB_MT352) += -DHAVE_MT352=1
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index fdd7f48f3b76..e666a4465ca4 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -208,7 +208,7 @@ struct saa7134_board saa7134_boards[] = {
208 [SAA7134_BOARD_FLYTVPLATINUM_FM] = { 208 [SAA7134_BOARD_FLYTVPLATINUM_FM] = {
209 /* LifeView FlyTV Platinum FM (LR214WF) */ 209 /* LifeView FlyTV Platinum FM (LR214WF) */
210 /* "Peter Missel <peter.missel@onlinehome.de> */ 210 /* "Peter Missel <peter.missel@onlinehome.de> */
211 .name = "LifeView FlyTV Platinum FM", 211 .name = "LifeView FlyTV Platinum FM / Gold",
212 .audio_clock = 0x00200000, 212 .audio_clock = 0x00200000,
213 .tuner_type = TUNER_PHILIPS_TDA8290, 213 .tuner_type = TUNER_PHILIPS_TDA8290,
214 .radio_type = UNSET, 214 .radio_type = UNSET,
@@ -2660,7 +2660,7 @@ struct saa7134_board saa7134_boards[] = {
2660 .mpeg = SAA7134_MPEG_DVB, 2660 .mpeg = SAA7134_MPEG_DVB,
2661 .inputs = {{ 2661 .inputs = {{
2662 .name = name_comp1, 2662 .name = name_comp1,
2663 .vmux = 0, 2663 .vmux = 1,
2664 .amux = LINE1, 2664 .amux = LINE1,
2665 },{ 2665 },{
2666 .name = name_svideo, 2666 .name = name_svideo,
@@ -2671,7 +2671,7 @@ struct saa7134_board saa7134_boards[] = {
2671 [SAA7134_BOARD_FLYDVBT_LR301] = { 2671 [SAA7134_BOARD_FLYDVBT_LR301] = {
2672 /* LifeView FlyDVB-T */ 2672 /* LifeView FlyDVB-T */
2673 /* Giampiero Giancipoli <gianci@libero.it> */ 2673 /* Giampiero Giancipoli <gianci@libero.it> */
2674 .name = "LifeView FlyDVB-T", 2674 .name = "LifeView FlyDVB-T / Genius VideoWonder DVB-T",
2675 .audio_clock = 0x00200000, 2675 .audio_clock = 0x00200000,
2676 .tuner_type = TUNER_ABSENT, 2676 .tuner_type = TUNER_ABSENT,
2677 .radio_type = UNSET, 2677 .radio_type = UNSET,
@@ -2808,6 +2808,40 @@ struct saa7134_board saa7134_boards[] = {
2808 .tuner_addr = ADDR_UNSET, 2808 .tuner_addr = ADDR_UNSET,
2809 .radio_addr = ADDR_UNSET, 2809 .radio_addr = ADDR_UNSET,
2810 }, 2810 },
2811 [SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS] = {
2812 .name = "LifeView FlyDVB-T Hybrid Cardbus",
2813 .audio_clock = 0x00200000,
2814 .tuner_type = TUNER_PHILIPS_TDA8290,
2815 .radio_type = UNSET,
2816 .tuner_addr = ADDR_UNSET,
2817 .radio_addr = ADDR_UNSET,
2818 .mpeg = SAA7134_MPEG_DVB,
2819 .gpiomask = 0x00600000, /* Bit 21 0=Radio, Bit 22 0=TV */
2820 .inputs = {{
2821 .name = name_tv,
2822 .vmux = 1,
2823 .amux = TV,
2824 .gpio = 0x200000, /* GPIO21=High for TV input */
2825 .tv = 1,
2826 },{
2827 .name = name_svideo, /* S-Video signal on S-Video input */
2828 .vmux = 8,
2829 .amux = LINE2,
2830 },{
2831 .name = name_comp1, /* Composite signal on S-Video input */
2832 .vmux = 0,
2833 .amux = LINE2,
2834 },{
2835 .name = name_comp2, /* Composite input */
2836 .vmux = 3,
2837 .amux = LINE2,
2838 }},
2839 .radio = {
2840 .name = name_radio,
2841 .amux = TV,
2842 .gpio = 0x000000, /* GPIO21=Low for FM radio antenna */
2843 },
2844 },
2811}; 2845};
2812 2846
2813const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 2847const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -3333,6 +3367,30 @@ struct pci_device_id saa7134_pci_tbl[] = {
3333 .subdevice = 0x0005, 3367 .subdevice = 0x0005,
3334 .driver_data = SAA7134_BOARD_MD7134_BRIDGE_2, 3368 .driver_data = SAA7134_BOARD_MD7134_BRIDGE_2,
3335 },{ 3369 },{
3370 .vendor = PCI_VENDOR_ID_PHILIPS,
3371 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3372 .subvendor = 0x1489,
3373 .subdevice = 0x0301,
3374 .driver_data = SAA7134_BOARD_FLYDVBT_LR301,
3375 },{
3376 .vendor = PCI_VENDOR_ID_PHILIPS,
3377 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3378 .subvendor = 0x5168, /* Animation Technologies (LifeView) */
3379 .subdevice = 0x0304,
3380 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM,
3381 },{
3382 .vendor = PCI_VENDOR_ID_PHILIPS,
3383 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3384 .subvendor = 0x5168,
3385 .subdevice = 0x3306,
3386 .driver_data = SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS,
3387 },{
3388 .vendor = PCI_VENDOR_ID_PHILIPS,
3389 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3390 .subvendor = 0x5168,
3391 .subdevice = 0x3502, /* whats the difference to 0x3306 ?*/
3392 .driver_data = SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS,
3393 },{
3336 /* --- boards without eeprom + subsystem ID --- */ 3394 /* --- boards without eeprom + subsystem ID --- */
3337 .vendor = PCI_VENDOR_ID_PHILIPS, 3395 .vendor = PCI_VENDOR_ID_PHILIPS,
3338 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 3396 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -3462,6 +3520,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3462 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x06); 3520 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x06);
3463 break; 3521 break;
3464 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331: 3522 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
3523 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
3465 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08); 3524 saa_writeb(SAA7134_GPIO_GPMODE3, 0x08);
3466 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x00); 3525 saa_writeb(SAA7134_GPIO_GPSTATUS3, 0x00);
3467 break; 3526 break;
@@ -3633,6 +3692,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
3633 } 3692 }
3634 break; 3693 break;
3635 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331: 3694 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
3695 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
3636 /* make the tda10046 find its eeprom */ 3696 /* make the tda10046 find its eeprom */
3637 { 3697 {
3638 u8 data[] = { 0x3c, 0x33, 0x62}; 3698 u8 data[] = { 0x3c, 0x33, 0x62};
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index c98571c9d5a6..13de05532e0a 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -32,6 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/dma-mapping.h>
35 36
36#include "saa7134-reg.h" 37#include "saa7134-reg.h"
37#include "saa7134.h" 38#include "saa7134.h"
@@ -870,7 +871,7 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
870 pci_name(pci_dev), dev->pci_rev, pci_dev->irq, 871 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
871 dev->pci_lat,pci_resource_start(pci_dev,0)); 872 dev->pci_lat,pci_resource_start(pci_dev,0));
872 pci_set_master(pci_dev); 873 pci_set_master(pci_dev);
873 if (!pci_dma_supported(pci_dev,0xffffffff)) { 874 if (!pci_dma_supported(pci_dev, DMA_32BIT_MASK)) {
874 printk("%s: Oops: no 32bit PCI DMA ???\n",dev->name); 875 printk("%s: Oops: no 32bit PCI DMA ???\n",dev->name);
875 err = -EIO; 876 err = -EIO;
876 goto fail1; 877 goto fail1;
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 86cfdb8514cb..222a36c38917 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -1064,6 +1064,10 @@ static int dvb_init(struct saa7134_dev *dev)
1064 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config, 1064 dev->dvb.frontend = tda10046_attach(&tevion_dvbt220rf_config,
1065 &dev->i2c_adap); 1065 &dev->i2c_adap);
1066 break; 1066 break;
1067 case SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS:
1068 dev->dvb.frontend = tda10046_attach(&ads_tech_duo_config,
1069 &dev->i2c_adap);
1070 break;
1067#endif 1071#endif
1068#ifdef HAVE_NXT200X 1072#ifdef HAVE_NXT200X
1069 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180: 1073 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 31ba293854c1..353af3a8b766 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -220,6 +220,7 @@ struct saa7134_format {
220#define SAA7134_BOARD_AVERMEDIA_A169_B 91 220#define SAA7134_BOARD_AVERMEDIA_A169_B 91
221#define SAA7134_BOARD_AVERMEDIA_A169_B1 92 221#define SAA7134_BOARD_AVERMEDIA_A169_B1 92
222#define SAA7134_BOARD_MD7134_BRIDGE_2 93 222#define SAA7134_BOARD_MD7134_BRIDGE_2 93
223#define SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS 94
223 224
224#define SAA7134_MAXBOARDS 8 225#define SAA7134_MAXBOARDS 8
225#define SAA7134_INPUT_MAX 8 226#define SAA7134_INPUT_MAX 8
diff --git a/drivers/media/video/sn9c102/Kconfig b/drivers/media/video/sn9c102/Kconfig
new file mode 100644
index 000000000000..55f2bc11964b
--- /dev/null
+++ b/drivers/media/video/sn9c102/Kconfig
@@ -0,0 +1,11 @@
1config USB_SN9C102
2 tristate "USB SN9C10x PC Camera Controller support"
3 depends on USB && VIDEO_DEV
4 ---help---
5 Say Y here if you want support for cameras based on SONiX SN9C101,
6 SN9C102 or SN9C103 PC Camera Controllers.
7
8 See <file:Documentation/video4linux/sn9c102.txt> for more info.
9
10 To compile this driver as a module, choose M here: the
11 module will be called sn9c102.
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index df195c905366..1013b4de89a2 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -401,7 +401,7 @@ static void tuner_status(struct i2c_client *client)
401 } 401 }
402 tuner_info("Tuner mode: %s\n", p); 402 tuner_info("Tuner mode: %s\n", p);
403 tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction); 403 tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
404 tuner_info("Standard: 0x%08llx\n", t->std); 404 tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std);
405 if (t->mode != V4L2_TUNER_RADIO) 405 if (t->mode != V4L2_TUNER_RADIO)
406 return; 406 return;
407 if (t->has_signal) { 407 if (t->has_signal) {
@@ -558,10 +558,10 @@ static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode,
558 558
559static inline int check_v4l2(struct tuner *t) 559static inline int check_v4l2(struct tuner *t)
560{ 560{
561 if (t->using_v4l2) { 561 /* bttv still uses both v4l1 and v4l2 calls to the tuner (v4l2 for
562 tuner_dbg ("ignore v4l1 call\n"); 562 TV, v4l1 for radio), until that is fixed this code is disabled.
563 return EINVAL; 563 Otherwise the radio (v4l1) wouldn't tune after using the TV (v4l2)
564 } 564 first. */
565 return 0; 565 return 0;
566} 566}
567 567
@@ -744,6 +744,8 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
744 switch_v4l2(); 744 switch_v4l2();
745 745
746 tuner->type = t->mode; 746 tuner->type = t->mode;
747 if (t->mode == V4L2_TUNER_ANALOG_TV)
748 tuner->capability |= V4L2_TUNER_CAP_NORM;
747 if (t->mode != V4L2_TUNER_RADIO) { 749 if (t->mode != V4L2_TUNER_RADIO) {
748 tuner->rangelow = tv_range[0] * 16; 750 tuner->rangelow = tv_range[0] * 16;
749 tuner->rangehigh = tv_range[1] * 16; 751 tuner->rangehigh = tv_range[1] * 16;
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 356bff455ad1..c2b756107548 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -1706,21 +1706,6 @@ static int chip_command(struct i2c_client *client,
1706 break; 1706 break;
1707 } 1707 }
1708 1708
1709 case VIDIOC_S_AUDIO:
1710 {
1711 struct v4l2_audio *sarg = arg;
1712
1713 if (!(desc->flags & CHIP_HAS_INPUTSEL) || sarg->index >= 4)
1714 return -EINVAL;
1715 /* There are four inputs: tuner, radio, extern and intern. */
1716 chip->input = sarg->index;
1717 if (chip->muted)
1718 break;
1719 chip_write_masked(chip, desc->inputreg,
1720 desc->inputmap[chip->input], desc->inputmask);
1721 break;
1722 }
1723
1724 case VIDIOC_S_TUNER: 1709 case VIDIOC_S_TUNER:
1725 { 1710 {
1726 struct v4l2_tuner *vt = arg; 1711 struct v4l2_tuner *vt = arg;
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index e0d2ff83fc91..431c3e2f6c42 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -757,9 +757,9 @@ tveeprom_detect_client(struct i2c_adapter *adapter,
757static int 757static int
758tveeprom_attach_adapter (struct i2c_adapter *adapter) 758tveeprom_attach_adapter (struct i2c_adapter *adapter)
759{ 759{
760 if (adapter->id != I2C_HW_B_BT848) 760 if (adapter->class & I2C_CLASS_TV_ANALOG)
761 return 0; 761 return i2c_probe(adapter, &addr_data, tveeprom_detect_client);
762 return i2c_probe(adapter, &addr_data, tveeprom_detect_client); 762 return 0;
763} 763}
764 764
765static int 765static int
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 69d0fe159f4d..dab4973bcf82 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -53,7 +53,7 @@ static struct v4l2_queryctrl tvp5150_qctrl[] = {
53 .minimum = 0, 53 .minimum = 0,
54 .maximum = 255, 54 .maximum = 255,
55 .step = 1, 55 .step = 1,
56 .default_value = 0, 56 .default_value = 128,
57 .flags = 0, 57 .flags = 0,
58 }, { 58 }, {
59 .id = V4L2_CID_CONTRAST, 59 .id = V4L2_CID_CONTRAST,
@@ -62,7 +62,7 @@ static struct v4l2_queryctrl tvp5150_qctrl[] = {
62 .minimum = 0, 62 .minimum = 0,
63 .maximum = 255, 63 .maximum = 255,
64 .step = 0x1, 64 .step = 0x1,
65 .default_value = 0x10, 65 .default_value = 128,
66 .flags = 0, 66 .flags = 0,
67 }, { 67 }, {
68 .id = V4L2_CID_SATURATION, 68 .id = V4L2_CID_SATURATION,
@@ -71,7 +71,7 @@ static struct v4l2_queryctrl tvp5150_qctrl[] = {
71 .minimum = 0, 71 .minimum = 0,
72 .maximum = 255, 72 .maximum = 255,
73 .step = 0x1, 73 .step = 0x1,
74 .default_value = 0x10, 74 .default_value = 128,
75 .flags = 0, 75 .flags = 0,
76 }, { 76 }, {
77 .id = V4L2_CID_HUE, 77 .id = V4L2_CID_HUE,
@@ -80,7 +80,7 @@ static struct v4l2_queryctrl tvp5150_qctrl[] = {
80 .minimum = -128, 80 .minimum = -128,
81 .maximum = 127, 81 .maximum = 127,
82 .step = 0x1, 82 .step = 0x1,
83 .default_value = 0x10, 83 .default_value = 0,
84 .flags = 0, 84 .flags = 0,
85 } 85 }
86}; 86};
@@ -500,16 +500,21 @@ struct i2c_vbi_ram_value {
500 500
501static struct i2c_vbi_ram_value vbi_ram_default[] = 501static struct i2c_vbi_ram_value vbi_ram_default[] =
502{ 502{
503 /* FIXME: Current api doesn't handle all VBI types, those not
504 yet supported are placed under #if 0 */
505#if 0
503 {0x010, /* Teletext, SECAM, WST System A */ 506 {0x010, /* Teletext, SECAM, WST System A */
504 {V4L2_SLICED_TELETEXT_SECAM,6,23,1}, 507 {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
505 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26, 508 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
506 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 } 509 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
507 }, 510 },
511#endif
508 {0x030, /* Teletext, PAL, WST System B */ 512 {0x030, /* Teletext, PAL, WST System B */
509 {V4L2_SLICED_TELETEXT_PAL_B,6,22,1}, 513 {V4L2_SLICED_TELETEXT_B,6,22,1},
510 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b, 514 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
511 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 } 515 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
512 }, 516 },
517#if 0
513 {0x050, /* Teletext, PAL, WST System C */ 518 {0x050, /* Teletext, PAL, WST System C */
514 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1}, 519 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
515 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, 520 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
@@ -535,6 +540,7 @@ static struct i2c_vbi_ram_value vbi_ram_default[] =
535 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, 540 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
536 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } 541 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
537 }, 542 },
543#endif
538 {0x0f0, /* Closed Caption, NTSC */ 544 {0x0f0, /* Closed Caption, NTSC */
539 {V4L2_SLICED_CAPTION_525,21,21,1}, 545 {V4L2_SLICED_CAPTION_525,21,21,1},
540 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, 546 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
@@ -545,6 +551,7 @@ static struct i2c_vbi_ram_value vbi_ram_default[] =
545 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42, 551 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
546 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 } 552 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
547 }, 553 },
554#if 0
548 {0x130, /* Wide Screen Signal, NTSC C */ 555 {0x130, /* Wide Screen Signal, NTSC C */
549 {V4L2_SLICED_WSS_525,20,20,1}, 556 {V4L2_SLICED_WSS_525,20,20,1},
550 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43, 557 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
@@ -560,6 +567,7 @@ static struct i2c_vbi_ram_value vbi_ram_default[] =
560 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, 567 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
561 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } 568 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
562 }, 569 },
570#endif
563 {0x190, /* Video Program System (VPS), PAL */ 571 {0x190, /* Video Program System (VPS), PAL */
564 {V4L2_SLICED_VPS,16,16,0}, 572 {V4L2_SLICED_VPS,16,16,0},
565 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d, 573 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
@@ -850,7 +858,6 @@ static int tvp5150_command(struct i2c_client *c,
850 858
851 case 0: 859 case 0:
852 case VIDIOC_INT_RESET: 860 case VIDIOC_INT_RESET:
853 case DECODER_INIT:
854 tvp5150_reset(c); 861 tvp5150_reset(c);
855 break; 862 break;
856 case VIDIOC_S_STD: 863 case VIDIOC_S_STD:
@@ -949,99 +956,15 @@ static int tvp5150_command(struct i2c_client *c,
949#endif 956#endif
950 957
951 case VIDIOC_LOG_STATUS: 958 case VIDIOC_LOG_STATUS:
952 case DECODER_DUMP:
953 dump_reg(c); 959 dump_reg(c);
954 break; 960 break;
955 961
956 case DECODER_GET_CAPABILITIES: 962 case VIDIOC_G_TUNER:
957 { 963 {
958 struct video_decoder_capability *cap = arg; 964 struct v4l2_tuner *vt = arg;
959 965 int status = tvp5150_read(c, 0x88);
960 cap->flags = VIDEO_DECODER_PAL |
961 VIDEO_DECODER_NTSC |
962 VIDEO_DECODER_SECAM |
963 VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR;
964 cap->inputs = 3;
965 cap->outputs = 1;
966 break;
967 }
968 case DECODER_GET_STATUS:
969 {
970 int *iarg = arg;
971 int status;
972 int res=0;
973 status = tvp5150_read(c, 0x88);
974 if(status&0x08){
975 res |= DECODER_STATUS_COLOR;
976 }
977 if(status&0x04 && status&0x02){
978 res |= DECODER_STATUS_GOOD;
979 }
980 *iarg=res;
981 break;
982 }
983
984 case DECODER_SET_GPIO:
985 break;
986
987 case DECODER_SET_VBI_BYPASS:
988 break;
989
990 case DECODER_SET_NORM:
991 {
992 int *iarg = arg;
993
994 switch (*iarg) {
995
996 case VIDEO_MODE_NTSC:
997 break;
998
999 case VIDEO_MODE_PAL:
1000 break;
1001
1002 case VIDEO_MODE_SECAM:
1003 break;
1004
1005 case VIDEO_MODE_AUTO:
1006 break;
1007
1008 default:
1009 return -EINVAL;
1010
1011 }
1012 decoder->norm = *iarg;
1013 break;
1014 }
1015 case DECODER_SET_INPUT:
1016 {
1017 int *iarg = arg;
1018 if (*iarg < 0 || *iarg > 3) {
1019 return -EINVAL;
1020 }
1021
1022 decoder->input = *iarg;
1023 tvp5150_selmux(c, decoder->input);
1024
1025 break;
1026 }
1027 case DECODER_SET_OUTPUT:
1028 {
1029 int *iarg = arg;
1030
1031 /* not much choice of outputs */
1032 if (*iarg != 0) {
1033 return -EINVAL;
1034 }
1035 break;
1036 }
1037 case DECODER_ENABLE_OUTPUT:
1038 {
1039 int *iarg = arg;
1040
1041 decoder->enable = (*iarg != 0);
1042
1043 tvp5150_selmux(c, decoder->input);
1044 966
967 vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
1045 break; 968 break;
1046 } 969 }
1047 case VIDIOC_QUERYCTRL: 970 case VIDIOC_QUERYCTRL:
@@ -1087,35 +1010,6 @@ static int tvp5150_command(struct i2c_client *c,
1087 return -EINVAL; 1010 return -EINVAL;
1088 } 1011 }
1089 1012
1090 case DECODER_SET_PICTURE:
1091 {
1092 struct video_picture *pic = arg;
1093 if (decoder->bright != pic->brightness) {
1094 /* We want 0 to 255 we get 0-65535 */
1095 decoder->bright = pic->brightness;
1096 tvp5150_write(c, TVP5150_BRIGHT_CTL,
1097 decoder->bright >> 8);
1098 }
1099 if (decoder->contrast != pic->contrast) {
1100 /* We want 0 to 255 we get 0-65535 */
1101 decoder->contrast = pic->contrast;
1102 tvp5150_write(c, TVP5150_CONTRAST_CTL,
1103 decoder->contrast >> 8);
1104 }
1105 if (decoder->sat != pic->colour) {
1106 /* We want 0 to 255 we get 0-65535 */
1107 decoder->sat = pic->colour;
1108 tvp5150_write(c, TVP5150_SATURATION_CTL,
1109 decoder->contrast >> 8);
1110 }
1111 if (decoder->hue != pic->hue) {
1112 /* We want -128 to 127 we get 0-65535 */
1113 decoder->hue = pic->hue;
1114 tvp5150_write(c, TVP5150_HUE_CTL,
1115 (decoder->hue - 32768) >> 8);
1116 }
1117 break;
1118 }
1119 default: 1013 default:
1120 return -EINVAL; 1014 return -EINVAL;
1121 } 1015 }
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c
new file mode 100644
index 000000000000..fc52201d607e
--- /dev/null
+++ b/drivers/media/video/upd64031a.c
@@ -0,0 +1,286 @@
1/*
2 * upd64031A - NEC Electronics Ghost Reduction for NTSC in Japan
3 *
4 * 2003 by T.Adachi <tadachi@tadachi-net.com>
5 * 2003 by Takeru KOMORIYA <komoriya@paken.org>
6 * 2006 by Hans Verkuil <hverkuil@xs4all.nl>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24#include <linux/version.h>
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/i2c.h>
28#include <linux/videodev2.h>
29#include <media/v4l2-common.h>
30#include <media/upd64031a.h>
31
32// --------------------- read registers functions define -----------------------
33
34/* bit masks */
35#define GR_MODE_MASK 0xc0
36#define DIRECT_3DYCS_CONNECT_MASK 0xc0
37#define SYNC_CIRCUIT_MASK 0xa0
38
39// -----------------------------------------------------------------------------
40
41MODULE_DESCRIPTION("uPD64031A driver");
42MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil");
43MODULE_LICENSE("GPL");
44
45static int debug = 0;
46module_param(debug, int, 0644);
47
48MODULE_PARM_DESC(debug, "Debug level (0-1)");
49
50static unsigned short normal_i2c[] = { 0x24 >> 1, 0x26 >> 1, I2C_CLIENT_END };
51
52
53I2C_CLIENT_INSMOD;
54
55enum {
56 R00 = 0, R01, R02, R03, R04,
57 R05, R06, R07, R08, R09,
58 R0A, R0B, R0C, R0D, R0E, R0F,
59 /* unused registers
60 R10, R11, R12, R13, R14,
61 R15, R16, R17,
62 */
63 TOT_REGS
64};
65
66struct upd64031a_state {
67 u8 regs[TOT_REGS];
68 u8 gr_mode;
69 u8 direct_3dycs_connect;
70 u8 ext_comp_sync;
71 u8 ext_vert_sync;
72};
73
74static u8 upd64031a_init[] = {
75 0x00, 0xb8, 0x48, 0xd2, 0xe6,
76 0x03, 0x10, 0x0b, 0xaf, 0x7f,
77 0x00, 0x00, 0x1d, 0x5e, 0x00,
78 0xd0
79};
80
81/* ------------------------------------------------------------------------ */
82
83static u8 upd64031a_read(struct i2c_client *client, u8 reg)
84{
85 u8 buf[2];
86
87 if (reg >= sizeof(buf))
88 return 0xff;
89 i2c_master_recv(client, buf, 2);
90 return buf[reg];
91}
92
93/* ------------------------------------------------------------------------ */
94
95static void upd64031a_write(struct i2c_client *client, u8 reg, u8 val)
96{
97 u8 buf[2];
98
99 buf[0] = reg;
100 buf[1] = val;
101 v4l_dbg(1, debug, client, "writing reg addr: %02X val: %02X\n", reg, val);
102 if (i2c_master_send(client, buf, 2) != 2)
103 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val);
104}
105
106/* ------------------------------------------------------------------------ */
107
108/* The input changed due to new input or channel changed */
109static void upd64031a_change(struct i2c_client *client)
110{
111 struct upd64031a_state *state = i2c_get_clientdata(client);
112 u8 reg = state->regs[R00];
113
114 v4l_dbg(1, debug, client, "changed input or channel\n");
115 upd64031a_write(client, R00, reg | 0x10);
116 upd64031a_write(client, R00, reg & ~0x10);
117}
118
119/* ------------------------------------------------------------------------ */
120
121static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *arg)
122{
123 struct upd64031a_state *state = i2c_get_clientdata(client);
124 struct v4l2_routing *route = arg;
125
126 switch (cmd) {
127 case VIDIOC_S_FREQUENCY:
128 upd64031a_change(client);
129 break;
130
131 case VIDIOC_INT_G_VIDEO_ROUTING:
132 route->input = (state->gr_mode >> 6) |
133 (state->direct_3dycs_connect >> 4) |
134 (state->ext_comp_sync >> 1) |
135 (state->ext_vert_sync >> 2);
136 route->output = 0;
137 break;
138
139 case VIDIOC_INT_S_VIDEO_ROUTING:
140 {
141 u8 r00, r05, r08;
142
143 state->gr_mode = (route->input & 3) << 6;
144 state->direct_3dycs_connect = (route->input & 0xc) << 4;
145 state->ext_comp_sync = (route->input & UPD64031A_COMPOSITE_EXTERNAL) << 1;
146 state->ext_vert_sync = (route->input & UPD64031A_VERTICAL_EXTERNAL) << 2;
147 r00 = (state->regs[R00] & ~GR_MODE_MASK) | state->gr_mode;
148 r05 = (state->regs[R00] & ~SYNC_CIRCUIT_MASK) |
149 state->ext_comp_sync | state->ext_vert_sync;
150 r08 = (state->regs[R08] & ~DIRECT_3DYCS_CONNECT_MASK) |
151 state->direct_3dycs_connect;
152 upd64031a_write(client, R00, r00);
153 upd64031a_write(client, R05, r05);
154 upd64031a_write(client, R08, r08);
155 upd64031a_change(client);
156 break;
157 }
158
159 case VIDIOC_LOG_STATUS:
160 v4l_info(client, "Status: SA00=0x%02x SA01=0x%02x\n",
161 upd64031a_read(client, 0), upd64031a_read(client, 1));
162 break;
163
164#ifdef CONFIG_VIDEO_ADV_DEBUG
165 case VIDIOC_INT_G_REGISTER:
166 {
167 struct v4l2_register *reg = arg;
168
169 if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
170 return -EINVAL;
171 reg->val = upd64031a_read(client, reg->reg & 0xff);
172 break;
173 }
174
175 case VIDIOC_INT_S_REGISTER:
176 {
177 struct v4l2_register *reg = arg;
178 u8 addr = reg->reg & 0xff;
179 u8 val = reg->val & 0xff;
180
181 if (reg->i2c_id != I2C_DRIVERID_UPD64031A)
182 return -EINVAL;
183 if (!capable(CAP_SYS_ADMIN))
184 return -EPERM;
185 upd64031a_write(client, addr, val);
186 break;
187 }
188#endif
189
190 default:
191 break;
192 }
193 return 0;
194}
195
196/* ------------------------------------------------------------------------ */
197
198/* i2c implementation */
199
200static struct i2c_driver i2c_driver;
201
202static int upd64031a_attach(struct i2c_adapter *adapter, int address, int kind)
203{
204 struct i2c_client *client;
205 struct upd64031a_state *state;
206 int i;
207
208 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
209 return 0;
210
211 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
212 if (client == NULL) {
213 return -ENOMEM;
214 }
215
216 client->addr = address;
217 client->adapter = adapter;
218 client->driver = &i2c_driver;
219 snprintf(client->name, sizeof(client->name) - 1, "uPD64031A");
220
221 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
222
223 state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL);
224 if (state == NULL) {
225 kfree(client);
226 return -ENOMEM;
227 }
228 i2c_set_clientdata(client, state);
229 memcpy(state->regs, upd64031a_init, sizeof(state->regs));
230 state->gr_mode = UPD64031A_GR_ON << 6;
231 state->direct_3dycs_connect = UPD64031A_3DYCS_COMPOSITE << 4;
232 state->ext_comp_sync = state->ext_vert_sync = 0;
233 for (i = 0; i < TOT_REGS; i++) {
234 upd64031a_write(client, i, state->regs[i]);
235 }
236
237 i2c_attach_client(client);
238
239 return 0;
240}
241
242static int upd64031a_probe(struct i2c_adapter *adapter)
243{
244 if (adapter->class & I2C_CLASS_TV_ANALOG)
245 return i2c_probe(adapter, &addr_data, upd64031a_attach);
246 return 0;
247}
248
249static int upd64031a_detach(struct i2c_client *client)
250{
251 int err;
252
253 err = i2c_detach_client(client);
254 if (err)
255 return err;
256
257 kfree(client);
258 return 0;
259}
260
261/* ----------------------------------------------------------------------- */
262
263/* i2c implementation */
264static struct i2c_driver i2c_driver = {
265 .driver = {
266 .name = "upd64031a",
267 },
268 .id = I2C_DRIVERID_UPD64031A,
269 .attach_adapter = upd64031a_probe,
270 .detach_client = upd64031a_detach,
271 .command = upd64031a_command,
272};
273
274
275static int __init upd64031a_init_module(void)
276{
277 return i2c_add_driver(&i2c_driver);
278}
279
280static void __exit upd64031a_exit_module(void)
281{
282 i2c_del_driver(&i2c_driver);
283}
284
285module_init(upd64031a_init_module);
286module_exit(upd64031a_exit_module);
diff --git a/drivers/media/video/upd64083.c b/drivers/media/video/upd64083.c
new file mode 100644
index 000000000000..c3a7ffe5c267
--- /dev/null
+++ b/drivers/media/video/upd64083.c
@@ -0,0 +1,262 @@
1/*
2 * upd6408x - NEC Electronics 3-Dimensional Y/C separation driver
3 *
4 * 2003 by T.Adachi (tadachi@tadachi-net.com)
5 * 2003 by Takeru KOMORIYA <komoriya@paken.org>
6 * 2006 by Hans Verkuil <hverkuil@xs4all.nl>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22
23#include <linux/version.h>
24#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/i2c.h>
27#include <linux/videodev2.h>
28#include <media/v4l2-common.h>
29#include <media/upd64083.h>
30
31MODULE_DESCRIPTION("uPD64083 driver");
32MODULE_AUTHOR("T. Adachi, Takeru KOMORIYA, Hans Verkuil");
33MODULE_LICENSE("GPL");
34
35static int debug = 0;
36module_param(debug, bool, 0644);
37
38MODULE_PARM_DESC(debug, "Debug level (0-1)");
39
40static unsigned short normal_i2c[] = { 0xb8 >> 1, 0xba >> 1, I2C_CLIENT_END };
41
42
43I2C_CLIENT_INSMOD;
44
45enum {
46 R00 = 0, R01, R02, R03, R04,
47 R05, R06, R07, R08, R09,
48 R0A, R0B, R0C, R0D, R0E, R0F,
49 R10, R11, R12, R13, R14,
50 R15, R16,
51 TOT_REGS
52};
53
54struct upd64083_state {
55 u8 mode;
56 u8 ext_y_adc;
57 u8 regs[TOT_REGS];
58};
59
60/* Initial values when used in combination with the
61 NEC upd64031a ghost reduction chip. */
62static u8 upd64083_init[] = {
63 0x1f, 0x01, 0xa0, 0x2d, 0x29, /* we use EXCSS=0 */
64 0x36, 0xdd, 0x05, 0x56, 0x48,
65 0x00, 0x3a, 0xa0, 0x05, 0x08,
66 0x44, 0x60, 0x08, 0x52, 0xf8,
67 0x53, 0x60, 0x10
68};
69
70/* ------------------------------------------------------------------------ */
71
72static void upd64083_log_status(struct i2c_client *client)
73{
74 u8 buf[7];
75
76 i2c_master_recv(client, buf, 7);
77 v4l_info(client, "Status: SA00=%02x SA01=%02x SA02=%02x SA03=%02x "
78 "SA04=%02x SA05=%02x SA06=%02x\n",
79 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
80}
81
82/* ------------------------------------------------------------------------ */
83
84static void upd64083_write(struct i2c_client *client, u8 reg, u8 val)
85{
86 u8 buf[2];
87
88 buf[0] = reg;
89 buf[1] = val;
90 v4l_dbg(1, debug, client, "writing reg addr: %02x val: %02x\n", reg, val);
91 if (i2c_master_send(client, buf, 2) != 2)
92 v4l_err(client, "I/O error write 0x%02x/0x%02x\n", reg, val);
93}
94
95/* ------------------------------------------------------------------------ */
96
97#ifdef CONFIG_VIDEO_ADV_DEBUG
98static u8 upd64083_read(struct i2c_client *client, u8 reg)
99{
100 u8 buf[7];
101
102 if (reg >= sizeof(buf))
103 return 0xff;
104 i2c_master_recv(client, buf, sizeof(buf));
105 return buf[reg];
106}
107#endif
108
109/* ------------------------------------------------------------------------ */
110
111static int upd64083_command(struct i2c_client *client, unsigned int cmd, void *arg)
112{
113 struct upd64083_state *state = i2c_get_clientdata(client);
114 struct v4l2_routing *route = arg;
115
116 switch (cmd) {
117 case VIDIOC_INT_G_VIDEO_ROUTING:
118 route->input = (state->mode >> 6) | (state->ext_y_adc >> 3);
119 route->output = 0;
120 break;
121
122 case VIDIOC_INT_S_VIDEO_ROUTING:
123 {
124 u8 r00, r02;
125
126 if (route->input > 7 || (route->input & 6) == 6)
127 return -EINVAL;
128 state->mode = (route->input & 3) << 6;
129 state->ext_y_adc = (route->input & UPD64083_EXT_Y_ADC) << 3;
130 r00 = (state->regs[R00] & ~(3 << 6)) | state->mode;
131 r02 = (state->regs[R02] & ~(1 << 5)) | state->ext_y_adc;
132 upd64083_write(client, R00, r00);
133 upd64083_write(client, R02, r02);
134 break;
135 }
136
137 case VIDIOC_LOG_STATUS:
138 upd64083_log_status(client);
139 break;
140
141#ifdef CONFIG_VIDEO_ADV_DEBUG
142 case VIDIOC_INT_G_REGISTER:
143 {
144 struct v4l2_register *reg = arg;
145
146 if (reg->i2c_id != I2C_DRIVERID_UPD64083)
147 return -EINVAL;
148 reg->val = upd64083_read(client, reg->reg & 0xff);
149 break;
150 }
151
152 case VIDIOC_INT_S_REGISTER:
153 {
154 struct v4l2_register *reg = arg;
155 u8 addr = reg->reg & 0xff;
156 u8 val = reg->val & 0xff;
157
158 if (reg->i2c_id != I2C_DRIVERID_UPD64083)
159 return -EINVAL;
160 if (!capable(CAP_SYS_ADMIN))
161 return -EPERM;
162 upd64083_write(client, addr, val);
163 break;
164 }
165#endif
166 default:
167 break;
168 }
169
170 return 0;
171}
172
173/* ------------------------------------------------------------------------ */
174
175/* i2c implementation */
176
177static struct i2c_driver i2c_driver;
178
179static int upd64083_attach(struct i2c_adapter *adapter, int address, int kind)
180{
181 struct i2c_client *client;
182 struct upd64083_state *state;
183 int i;
184
185 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
186 return 0;
187
188 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
189 if (client == NULL) {
190 return -ENOMEM;
191 }
192
193 client->addr = address;
194 client->adapter = adapter;
195 client->driver = &i2c_driver;
196 snprintf(client->name, sizeof(client->name) - 1, "uPD64083");
197
198 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
199
200 state = kmalloc(sizeof(struct upd64083_state), GFP_KERNEL);
201 if (state == NULL) {
202 kfree(client);
203 return -ENOMEM;
204 }
205 i2c_set_clientdata(client, state);
206 /* Initially assume that a ghost reduction chip is present */
207 state->mode = 0; /* YCS mode */
208 state->ext_y_adc = (1 << 5);
209 memcpy(state->regs, upd64083_init, TOT_REGS);
210 for (i = 0; i < TOT_REGS; i++) {
211 upd64083_write(client, i, state->regs[i]);
212 }
213 i2c_attach_client(client);
214
215 return 0;
216}
217
218static int upd64083_probe(struct i2c_adapter *adapter)
219{
220 if (adapter->class & I2C_CLASS_TV_ANALOG)
221 return i2c_probe(adapter, &addr_data, upd64083_attach);
222 return 0;
223}
224
225static int upd64083_detach(struct i2c_client *client)
226{
227 int err;
228
229 err = i2c_detach_client(client);
230 if (err)
231 return err;
232
233 kfree(client);
234 return 0;
235}
236
237/* ----------------------------------------------------------------------- */
238
239/* i2c implementation */
240static struct i2c_driver i2c_driver = {
241 .driver = {
242 .name = "upd64083",
243 },
244 .id = I2C_DRIVERID_UPD64083,
245 .attach_adapter = upd64083_probe,
246 .detach_client = upd64083_detach,
247 .command = upd64083_command,
248};
249
250
251static int __init upd64083_init_module(void)
252{
253 return i2c_add_driver(&i2c_driver);
254}
255
256static void __exit upd64083_exit_module(void)
257{
258 i2c_del_driver(&i2c_driver);
259}
260
261module_init(upd64083_init_module);
262module_exit(upd64083_exit_module);
diff --git a/drivers/media/video/usbvideo/Kconfig b/drivers/media/video/usbvideo/Kconfig
new file mode 100644
index 000000000000..08a5d20bb2c0
--- /dev/null
+++ b/drivers/media/video/usbvideo/Kconfig
@@ -0,0 +1,38 @@
1config VIDEO_USBVIDEO
2 tristate
3
4config USB_VICAM
5 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
6 depends on USB && VIDEO_DEV && EXPERIMENTAL
7 select VIDEO_USBVIDEO
8 ---help---
9 Say Y here if you have 3com homeconnect camera (vicam).
10
11 To compile this driver as a module, choose M here: the
12 module will be called vicam.
13
14config USB_IBMCAM
15 tristate "USB IBM (Xirlink) C-it Camera support"
16 depends on USB && VIDEO_DEV
17 select VIDEO_USBVIDEO
18 ---help---
19 Say Y here if you want to connect a IBM "C-It" camera, also known as
20 "Xirlink PC Camera" to your computer's USB port.
21
22 To compile this driver as a module, choose M here: the
23 module will be called ibmcam.
24
25 This camera has several configuration options which
26 can be specified when you load the module. Read
27 <file:Documentation/video4linux/ibmcam.txt> to learn more.
28
29config USB_KONICAWC
30 tristate "USB Konica Webcam support"
31 depends on USB && VIDEO_DEV
32 select VIDEO_USBVIDEO
33 ---help---
34 Say Y here if you want support for webcams based on a Konica
35 chipset. This is known to work with the Intel YC76 webcam.
36
37 To compile this driver as a module, choose M here: the
38 module will be called konicawc.
diff --git a/drivers/media/video/usbvideo/Makefile b/drivers/media/video/usbvideo/Makefile
index ed410a5ee8c9..bb52eb8dc2f9 100644
--- a/drivers/media/video/usbvideo/Makefile
+++ b/drivers/media/video/usbvideo/Makefile
@@ -1,4 +1,4 @@
1obj-$(CONFIG_USB_IBMCAM) += ibmcam.o usbvideo.o ultracam.o 1obj-$(CONFIG_VIDEO_USBVIDEO) += usbvideo.o
2obj-$(CONFIG_USB_KONICAWC) += konicawc.o usbvideo.o 2obj-$(CONFIG_USB_IBMCAM) += ibmcam.o ultracam.o
3obj-$(CONFIG_USB_VICAM) += vicam.o usbvideo.o 3obj-$(CONFIG_USB_KONICAWC) += konicawc.o
4 4obj-$(CONFIG_USB_VICAM) += vicam.o
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 11a97f30b876..d330fa985bcc 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -317,6 +317,7 @@ static const char *v4l2_int_ioctls[] = {
317 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY", 317 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
318 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG", 318 [_IOC_NR(TDA9887_SET_CONFIG)] = "TDA9887_SET_CONFIG",
319 319
320 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
320 [_IOC_NR(VIDIOC_INT_S_REGISTER)] = "VIDIOC_INT_S_REGISTER", 321 [_IOC_NR(VIDIOC_INT_S_REGISTER)] = "VIDIOC_INT_S_REGISTER",
321 [_IOC_NR(VIDIOC_INT_G_REGISTER)] = "VIDIOC_INT_G_REGISTER", 322 [_IOC_NR(VIDIOC_INT_G_REGISTER)] = "VIDIOC_INT_G_REGISTER",
322 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET", 323 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
@@ -325,7 +326,12 @@ static const char *v4l2_int_ioctls[] = {
325 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA", 326 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
326 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA", 327 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
327 [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)] = "VIDIOC_INT_G_CHIP_IDENT", 328 [_IOC_NR(VIDIOC_INT_G_CHIP_IDENT)] = "VIDIOC_INT_G_CHIP_IDENT",
328 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ" 329 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
330 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
331 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
332 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
333 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
334 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING"
329}; 335};
330#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls) 336#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
331 337
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index d2ca0f08d0df..acc5ea936687 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -399,19 +399,25 @@ void videobuf_queue_pci(struct videobuf_queue* q)
399int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma) 399int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma)
400{ 400{
401 struct videobuf_queue q; 401 struct videobuf_queue q;
402 struct videobuf_queue_ops qops;
402 403
403 q.dev=pci; 404 q.dev=pci;
404 q.ops->vb_map_sg=(vb_map_sg_t *)pci_unmap_sg; 405 qops.vb_map_sg=(vb_map_sg_t *)pci_map_sg;
406 qops.vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg;
407 q.ops = &qops;
405 408
406 return (videobuf_dma_unmap(&q,dma)); 409 return (videobuf_dma_map(&q,dma));
407} 410}
408 411
409int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma) 412int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma)
410{ 413{
411 struct videobuf_queue q; 414 struct videobuf_queue q;
415 struct videobuf_queue_ops qops;
412 416
413 q.dev=pci; 417 q.dev=pci;
414 q.ops->vb_map_sg=(vb_map_sg_t *)pci_unmap_sg; 418 qops.vb_map_sg=(vb_map_sg_t *)pci_map_sg;
419 qops.vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg;
420 q.ops = &qops;
415 421
416 return (videobuf_dma_unmap(&q,dma)); 422 return (videobuf_dma_unmap(&q,dma));
417} 423}
@@ -923,7 +929,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
923 /* need to capture a new frame */ 929 /* need to capture a new frame */
924 retval = -ENOMEM; 930 retval = -ENOMEM;
925 q->read_buf = videobuf_alloc(q->msize); 931 q->read_buf = videobuf_alloc(q->msize);
926 dprintk(1,"video alloc=0x%08x\n",(unsigned int) q->read_buf); 932 dprintk(1,"video alloc=0x%p\n", q->read_buf);
927 if (NULL == q->read_buf) 933 if (NULL == q->read_buf)
928 goto done; 934 goto done;
929 q->read_buf->memory = V4L2_MEMORY_USERPTR; 935 q->read_buf->memory = V4L2_MEMORY_USERPTR;
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
new file mode 100644
index 000000000000..a9b59c35cd67
--- /dev/null
+++ b/drivers/media/video/wm8739.c
@@ -0,0 +1,355 @@
1/*
2 * wm8739
3 *
4 * Copyright (C) 2005 T. Adachi <tadachi@tadachi-net.com>
5 *
6 * Copyright (C) 2005 Hans Verkuil <hverkuil@xs4all.nl>
7 * - Cleanup
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/ioctl.h>
27#include <asm/uaccess.h>
28#include <linux/i2c.h>
29#include <linux/i2c-id.h>
30#include <linux/videodev.h>
31#include <media/v4l2-common.h>
32
33MODULE_DESCRIPTION("wm8739 driver");
34MODULE_AUTHOR("T. Adachi, Hans Verkuil");
35MODULE_LICENSE("GPL");
36
37static int debug = 0;
38static unsigned short normal_i2c[] = { 0x34 >> 1, 0x36 >> 1, I2C_CLIENT_END };
39
40module_param(debug, int, 0644);
41
42MODULE_PARM_DESC(debug, "Debug level (0-1)");
43
44
45I2C_CLIENT_INSMOD;
46
47/* ------------------------------------------------------------------------ */
48
49enum {
50 R0 = 0, R1,
51 R5 = 5, R6, R7, R8, R9, R15 = 15,
52 TOT_REGS
53};
54
55struct wm8739_state {
56 u32 clock_freq;
57 u8 muted;
58 u16 volume;
59 u16 balance;
60 u8 vol_l; /* +12dB to -34.5dB 1.5dB step (5bit) def:0dB */
61 u8 vol_r; /* +12dB to -34.5dB 1.5dB step (5bit) def:0dB */
62};
63
64/* ------------------------------------------------------------------------ */
65
66static int wm8739_write(struct i2c_client *client, int reg, u16 val)
67{
68 int i;
69
70 if (reg < 0 || reg >= TOT_REGS) {
71 v4l_err(client, "Invalid register R%d\n", reg);
72 return -1;
73 }
74
75 v4l_dbg(1, debug, client, "write: %02x %02x\n", reg, val);
76
77 for (i = 0; i < 3; i++) {
78 if (i2c_smbus_write_byte_data(client, (reg << 1) |
79 (val >> 8), val & 0xff) == 0) {
80 return 0;
81 }
82 }
83 v4l_err(client, "I2C: cannot write %03x to register R%d\n", val, reg);
84 return -1;
85}
86
87/* write regs to set audio volume etc */
88static void wm8739_set_audio(struct i2c_client *client)
89{
90 struct wm8739_state *state = i2c_get_clientdata(client);
91 u16 mute = state->muted ? 0x80 : 0;
92
93 /* Volume setting: bits 0-4, 0x1f = 12 dB, 0x00 = -34.5 dB
94 * Default setting: 0x17 = 0 dB
95 */
96 wm8739_write(client, R0, (state->vol_l & 0x1f) | mute);
97 wm8739_write(client, R1, (state->vol_r & 0x1f) | mute);
98}
99
100static int wm8739_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
101{
102 struct wm8739_state *state = i2c_get_clientdata(client);
103
104 switch (ctrl->id) {
105 case V4L2_CID_AUDIO_MUTE:
106 ctrl->value = state->muted;
107 break;
108
109 case V4L2_CID_AUDIO_VOLUME:
110 ctrl->value = state->volume;
111 break;
112
113 case V4L2_CID_AUDIO_BALANCE:
114 ctrl->value = state->balance;
115 break;
116
117 default:
118 return -EINVAL;
119 }
120 return 0;
121}
122
123static int wm8739_set_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
124{
125 struct wm8739_state *state = i2c_get_clientdata(client);
126 unsigned int work_l, work_r;
127
128 switch (ctrl->id) {
129 case V4L2_CID_AUDIO_MUTE:
130 state->muted = ctrl->value;
131 break;
132
133 case V4L2_CID_AUDIO_VOLUME:
134 state->volume = ctrl->value;
135 break;
136
137 case V4L2_CID_AUDIO_BALANCE:
138 state->balance = ctrl->value;
139 break;
140
141 default:
142 return -EINVAL;
143 }
144
145 /* normalize ( 65535 to 0 -> 31 to 0 (12dB to -34.5dB) ) */
146 work_l = (min(65536 - state->balance, 32768) * state->volume) / 32768;
147 work_r = (min(state->balance, (u16)32768) * state->volume) / 32768;
148
149 state->vol_l = (long)work_l * 31 / 65535;
150 state->vol_r = (long)work_r * 31 / 65535;
151
152 /* set audio volume etc. */
153 wm8739_set_audio(client);
154 return 0;
155}
156
157/* ------------------------------------------------------------------------ */
158
159static struct v4l2_queryctrl wm8739_qctrl[] = {
160 {
161 .id = V4L2_CID_AUDIO_VOLUME,
162 .name = "Volume",
163 .minimum = 0,
164 .maximum = 65535,
165 .step = 65535/100,
166 .default_value = 58880,
167 .flags = 0,
168 .type = V4L2_CTRL_TYPE_INTEGER,
169 },{
170 .id = V4L2_CID_AUDIO_MUTE,
171 .name = "Mute",
172 .minimum = 0,
173 .maximum = 1,
174 .step = 1,
175 .default_value = 1,
176 .flags = 0,
177 .type = V4L2_CTRL_TYPE_BOOLEAN,
178 },{
179 .id = V4L2_CID_AUDIO_BALANCE,
180 .name = "Balance",
181 .minimum = 0,
182 .maximum = 65535,
183 .step = 65535/100,
184 .default_value = 32768,
185 .flags = 0,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 }
188};
189
190/* ------------------------------------------------------------------------ */
191
192static int wm8739_command(struct i2c_client *client, unsigned int cmd, void *arg)
193{
194 struct wm8739_state *state = i2c_get_clientdata(client);
195
196 switch (cmd) {
197 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
198 {
199 u32 audiofreq = *(u32 *)arg;
200
201 state->clock_freq = audiofreq;
202 wm8739_write(client, R9, 0x000); /* de-activate */
203 switch (audiofreq) {
204 case 44100:
205 wm8739_write(client, R8, 0x020); /* 256fps, fs=44.1k */
206 break;
207 case 48000:
208 wm8739_write(client, R8, 0x000); /* 256fps, fs=48k */
209 break;
210 case 32000:
211 wm8739_write(client, R8, 0x018); /* 256fps, fs=32k */
212 break;
213 default:
214 break;
215 }
216 wm8739_write(client, R9, 0x001); /* activate */
217 break;
218 }
219
220 case VIDIOC_G_CTRL:
221 return wm8739_get_ctrl(client, arg);
222
223 case VIDIOC_S_CTRL:
224 return wm8739_set_ctrl(client, arg);
225
226 case VIDIOC_QUERYCTRL:
227 {
228 struct v4l2_queryctrl *qc = arg;
229 int i;
230
231 for (i = 0; i < ARRAY_SIZE(wm8739_qctrl); i++)
232 if (qc->id && qc->id == wm8739_qctrl[i].id) {
233 memcpy(qc, &wm8739_qctrl[i], sizeof(*qc));
234 return 0;
235 }
236 return -EINVAL;
237 }
238
239 case VIDIOC_LOG_STATUS:
240 v4l_info(client, "Frequency: %u Hz\n", state->clock_freq);
241 v4l_info(client, "Volume L: %02x%s\n", state->vol_l & 0x1f,
242 state->muted ? " (muted)" : "");
243 v4l_info(client, "Volume R: %02x%s\n", state->vol_r & 0x1f,
244 state->muted ? " (muted)" : "");
245 break;
246
247 default:
248 return -EINVAL;
249 }
250
251 return 0;
252}
253
254/* ------------------------------------------------------------------------ */
255
256/* i2c implementation */
257
258static struct i2c_driver i2c_driver;
259
260static int wm8739_attach(struct i2c_adapter *adapter, int address, int kind)
261{
262 struct i2c_client *client;
263 struct wm8739_state *state;
264
265 /* Check if the adapter supports the needed features */
266 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
267 return 0;
268
269 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
270 if (client == NULL)
271 return -ENOMEM;
272
273 client->addr = address;
274 client->adapter = adapter;
275 client->driver = &i2c_driver;
276 snprintf(client->name, sizeof(client->name) - 1, "wm8739");
277
278 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
279
280 state = kmalloc(sizeof(struct wm8739_state), GFP_KERNEL);
281 if (state == NULL) {
282 kfree(client);
283 return -ENOMEM;
284 }
285 state->vol_l = 0x17; /* 0dB */
286 state->vol_r = 0x17; /* 0dB */
287 state->muted = 0;
288 state->balance = 32768;
289 /* normalize (12dB(31) to -34.5dB(0) [0dB(23)] -> 65535 to 0) */
290 state->volume = ((long)state->vol_l + 1) * 65535 / 31;
291 state->clock_freq = 48000;
292 i2c_set_clientdata(client, state);
293
294 /* initialize wm8739 */
295 wm8739_write(client, R15, 0x00); /* reset */
296 wm8739_write(client, R5, 0x000); /* filter setting, high path, offet clear */
297 wm8739_write(client, R6, 0x000); /* ADC, OSC, Power Off mode Disable */
298 wm8739_write(client, R7, 0x049); /* Digital Audio interface format */
299 /* Enable Master mode */
300 /* 24 bit, MSB first/left justified */
301 wm8739_write(client, R8, 0x000); /* sampling control */
302 /* normal, 256fs, 48KHz sampling rate */
303 wm8739_write(client, R9, 0x001); /* activate */
304 wm8739_set_audio(client); /* set volume/mute */
305
306 i2c_attach_client(client);
307
308 return 0;
309}
310
311static int wm8739_probe(struct i2c_adapter *adapter)
312{
313 if (adapter->class & I2C_CLASS_TV_ANALOG)
314 return i2c_probe(adapter, &addr_data, wm8739_attach);
315 return 0;
316}
317
318static int wm8739_detach(struct i2c_client *client)
319{
320 int err;
321
322 err = i2c_detach_client(client);
323 if (err)
324 return err;
325
326 kfree(client);
327 return 0;
328}
329
330/* ----------------------------------------------------------------------- */
331
332/* i2c implementation */
333static struct i2c_driver i2c_driver = {
334 .driver = {
335 .name = "wm8739",
336 },
337 .id = I2C_DRIVERID_WM8739,
338 .attach_adapter = wm8739_probe,
339 .detach_client = wm8739_detach,
340 .command = wm8739_command,
341};
342
343
344static int __init wm8739_init_module(void)
345{
346 return i2c_add_driver(&i2c_driver);
347}
348
349static void __exit wm8739_cleanup_module(void)
350{
351 i2c_del_driver(&i2c_driver);
352}
353
354module_init(wm8739_init_module);
355module_exit(wm8739_cleanup_module);
diff --git a/drivers/media/video/zc0301/Kconfig b/drivers/media/video/zc0301/Kconfig
new file mode 100644
index 000000000000..c3bf886b80cd
--- /dev/null
+++ b/drivers/media/video/zc0301/Kconfig
@@ -0,0 +1,11 @@
1config USB_ZC0301
2 tristate "USB ZC0301 Image Processor and Control Chip support"
3 depends on USB && VIDEO_DEV
4 ---help---
5 Say Y here if you want support for cameras based on the ZC0301
6 Image Processor and Control Chip.
7
8 See <file:Documentation/video4linux/zc0301.txt> for more info.
9
10 To compile this driver as a module, choose M here: the
11 module will be called zc0301.
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 010d4a39269b..e9716b10acea 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -366,7 +366,15 @@ mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
366static int 366static int
367mptsas_slave_configure(struct scsi_device *sdev) 367mptsas_slave_configure(struct scsi_device *sdev)
368{ 368{
369 sas_read_port_mode_page(sdev); 369 struct Scsi_Host *host = sdev->host;
370 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
371
372 /*
373 * RAID volumes placed beyond the last expected port.
374 * Ignore sending sas mode pages in that case..
375 */
376 if (sdev->channel < hd->ioc->num_ports)
377 sas_read_port_mode_page(sdev);
370 378
371 return mptscsih_slave_configure(sdev); 379 return mptscsih_slave_configure(sdev);
372} 380}
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 3f5d77f633fa..003b077c2324 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -60,6 +60,17 @@ config MMC_SDHCI
60 60
61 If unsure, say N. 61 If unsure, say N.
62 62
63config MMC_OMAP
64 tristate "TI OMAP Multimedia Card Interface support"
65 depends on ARCH_OMAP && MMC
66 select TPS65010 if MACH_OMAP_H2
67 help
68 This selects the TI OMAP Multimedia card Interface.
69 If you have an OMAP board with a Multimedia Card slot,
70 say Y or M here.
71
72 If unsure, say N.
73
63config MMC_WBSD 74config MMC_WBSD
64 tristate "Winbond W83L51xD SD/MMC Card Interface support" 75 tristate "Winbond W83L51xD SD/MMC Card Interface support"
65 depends on MMC && ISA_DMA_API 76 depends on MMC && ISA_DMA_API
@@ -80,4 +91,22 @@ config MMC_AU1X
80 91
81 If unsure, say N. 92 If unsure, say N.
82 93
94config MMC_AT91RM9200
95 tristate "AT91RM9200 SD/MMC Card Interface support"
96 depends on ARCH_AT91RM9200 && MMC
97 help
98 This selects the AT91RM9200 MCI controller.
99
100 If unsure, say N.
101
102config MMC_IMX
103 tristate "Motorola i.MX Multimedia Card Interface support"
104 depends on ARCH_IMX && MMC
105 help
106 This selects the Motorola i.MX Multimedia card Interface.
107 If you have a i.MX platform with a Multimedia Card slot,
108 say Y or M here.
109
110 If unsure, say N.
111
83endmenu 112endmenu
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 769d545284a4..d2957e35cc6f 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -17,8 +17,15 @@ obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
17# 17#
18obj-$(CONFIG_MMC_ARMMMCI) += mmci.o 18obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
19obj-$(CONFIG_MMC_PXA) += pxamci.o 19obj-$(CONFIG_MMC_PXA) += pxamci.o
20obj-$(CONFIG_MMC_IMX) += imxmmc.o
20obj-$(CONFIG_MMC_SDHCI) += sdhci.o 21obj-$(CONFIG_MMC_SDHCI) += sdhci.o
21obj-$(CONFIG_MMC_WBSD) += wbsd.o 22obj-$(CONFIG_MMC_WBSD) += wbsd.o
22obj-$(CONFIG_MMC_AU1X) += au1xmmc.o 23obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
24obj-$(CONFIG_MMC_OMAP) += omap.o
25obj-$(CONFIG_MMC_AT91RM9200) += at91_mci.o
23 26
24mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o 27mmc_core-y := mmc.o mmc_queue.o mmc_sysfs.o
28
29ifeq ($(CONFIG_MMC_DEBUG),y)
30EXTRA_CFLAGS += -DDEBUG
31endif
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
new file mode 100644
index 000000000000..6061c2d101a0
--- /dev/null
+++ b/drivers/mmc/at91_mci.c
@@ -0,0 +1,988 @@
1/*
2 * linux/drivers/mmc/at91_mci.c - ATMEL AT91RM9200 MCI Driver
3 *
4 * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
5 *
6 * Copyright (C) 2006 Malcolm Noyes
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/*
14 This is the AT91RM9200 MCI driver that has been tested with both MMC cards
15 and SD-cards. Boards that support write protect are now supported.
16 The CCAT91SBC001 board does not support SD cards.
17
18 The three entry points are at91_mci_request, at91_mci_set_ios
19 and at91_mci_get_ro.
20
21 SET IOS
22 This configures the device to put it into the correct mode and clock speed
23 required.
24
25 MCI REQUEST
26 MCI request processes the commands sent in the mmc_request structure. This
27 can consist of a processing command and a stop command in the case of
28 multiple block transfers.
29
30 There are three main types of request, commands, reads and writes.
31
32 Commands are straight forward. The command is submitted to the controller and
33 the request function returns. When the controller generates an interrupt to indicate
34 the command is finished, the response to the command are read and the mmc_request_done
35 function called to end the request.
36
37 Reads and writes work in a similar manner to normal commands but involve the PDC (DMA)
38 controller to manage the transfers.
39
40 A read is done from the controller directly to the scatterlist passed in from the request.
41 Due to a bug in the controller, when a read is completed, all the words are byte
42 swapped in the scatterlist buffers.
43
44 The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY
45
46 A write is slightly different in that the bytes to write are read from the scatterlist
47 into a dma memory buffer (this is in case the source buffer should be read only). The
48 entire write buffer is then done from this single dma memory buffer.
49
50 The sequence of write interrupts is: ENDTX, TXBUFE, NOTBUSY, CMDRDY
51
52 GET RO
53 Gets the status of the write protect pin, if available.
54*/
55
56#include <linux/config.h>
57#include <linux/module.h>
58#include <linux/moduleparam.h>
59#include <linux/init.h>
60#include <linux/ioport.h>
61#include <linux/platform_device.h>
62#include <linux/interrupt.h>
63#include <linux/blkdev.h>
64#include <linux/delay.h>
65#include <linux/err.h>
66#include <linux/dma-mapping.h>
67#include <linux/clk.h>
68
69#include <linux/mmc/host.h>
70#include <linux/mmc/protocol.h>
71
72#include <asm/io.h>
73#include <asm/irq.h>
74#include <asm/mach/mmc.h>
75#include <asm/arch/board.h>
76#include <asm/arch/gpio.h>
77#include <asm/arch/at91rm9200_mci.h>
78#include <asm/arch/at91rm9200_pdc.h>
79
80#define DRIVER_NAME "at91_mci"
81
82#undef SUPPORT_4WIRE
83
84#ifdef CONFIG_MMC_DEBUG
85#define DBG(fmt...) \
86 printk(fmt)
87#else
88#define DBG(fmt...) do { } while (0)
89#endif
90
91static struct clk *mci_clk;
92
93#define FL_SENT_COMMAND (1 << 0)
94#define FL_SENT_STOP (1 << 1)
95
96
97
98/*
99 * Read from a MCI register.
100 */
101static inline unsigned long at91_mci_read(unsigned int reg)
102{
103 void __iomem *mci_base = (void __iomem *)AT91_VA_BASE_MCI;
104
105 return __raw_readl(mci_base + reg);
106}
107
108/*
109 * Write to a MCI register.
110 */
111static inline void at91_mci_write(unsigned int reg, unsigned long value)
112{
113 void __iomem *mci_base = (void __iomem *)AT91_VA_BASE_MCI;
114
115 __raw_writel(value, mci_base + reg);
116}
117
118/*
119 * Low level type for this driver
120 */
121struct at91mci_host
122{
123 struct mmc_host *mmc;
124 struct mmc_command *cmd;
125 struct mmc_request *request;
126
127 struct at91_mmc_data *board;
128 int present;
129
130 /*
131 * Flag indicating when the command has been sent. This is used to
132 * work out whether or not to send the stop
133 */
134 unsigned int flags;
135 /* flag for current bus settings */
136 u32 bus_mode;
137
138 /* DMA buffer used for transmitting */
139 unsigned int* buffer;
140 dma_addr_t physical_address;
141 unsigned int total_length;
142
143 /* Latest in the scatterlist that has been enabled for transfer, but not freed */
144 int in_use_index;
145
146 /* Latest in the scatterlist that has been enabled for transfer */
147 int transfer_index;
148};
149
150/*
151 * Copy from sg to a dma block - used for transfers
152 */
153static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data *data)
154{
155 unsigned int len, i, size;
156 unsigned *dmabuf = host->buffer;
157
158 size = host->total_length;
159 len = data->sg_len;
160
161 /*
162 * Just loop through all entries. Size might not
163 * be the entire list though so make sure that
164 * we do not transfer too much.
165 */
166 for (i = 0; i < len; i++) {
167 struct scatterlist *sg;
168 int amount;
169 int index;
170 unsigned int *sgbuffer;
171
172 sg = &data->sg[i];
173
174 sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
175 amount = min(size, sg->length);
176 size -= amount;
177 amount /= 4;
178
179 for (index = 0; index < amount; index++)
180 *dmabuf++ = swab32(sgbuffer[index]);
181
182 kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ);
183
184 if (size == 0)
185 break;
186 }
187
188 /*
189 * Check that we didn't get a request to transfer
190 * more data than can fit into the SG list.
191 */
192 BUG_ON(size != 0);
193}
194
195/*
196 * Prepare a dma read
197 */
198static void at91mci_pre_dma_read(struct at91mci_host *host)
199{
200 int i;
201 struct scatterlist *sg;
202 struct mmc_command *cmd;
203 struct mmc_data *data;
204
205 DBG("pre dma read\n");
206
207 cmd = host->cmd;
208 if (!cmd) {
209 DBG("no command\n");
210 return;
211 }
212
213 data = cmd->data;
214 if (!data) {
215 DBG("no data\n");
216 return;
217 }
218
219 for (i = 0; i < 2; i++) {
220 /* nothing left to transfer */
221 if (host->transfer_index >= data->sg_len) {
222 DBG("Nothing left to transfer (index = %d)\n", host->transfer_index);
223 break;
224 }
225
226 /* Check to see if this needs filling */
227 if (i == 0) {
228 if (at91_mci_read(AT91_PDC_RCR) != 0) {
229 DBG("Transfer active in current\n");
230 continue;
231 }
232 }
233 else {
234 if (at91_mci_read(AT91_PDC_RNCR) != 0) {
235 DBG("Transfer active in next\n");
236 continue;
237 }
238 }
239
240 /* Setup the next transfer */
241 DBG("Using transfer index %d\n", host->transfer_index);
242
243 sg = &data->sg[host->transfer_index++];
244 DBG("sg = %p\n", sg);
245
246 sg->dma_address = dma_map_page(NULL, sg->page, sg->offset, sg->length, DMA_FROM_DEVICE);
247
248 DBG("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
249
250 if (i == 0) {
251 at91_mci_write(AT91_PDC_RPR, sg->dma_address);
252 at91_mci_write(AT91_PDC_RCR, sg->length / 4);
253 }
254 else {
255 at91_mci_write(AT91_PDC_RNPR, sg->dma_address);
256 at91_mci_write(AT91_PDC_RNCR, sg->length / 4);
257 }
258 }
259
260 DBG("pre dma read done\n");
261}
262
263/*
264 * Handle after a dma read
265 */
266static void at91mci_post_dma_read(struct at91mci_host *host)
267{
268 struct mmc_command *cmd;
269 struct mmc_data *data;
270
271 DBG("post dma read\n");
272
273 cmd = host->cmd;
274 if (!cmd) {
275 DBG("no command\n");
276 return;
277 }
278
279 data = cmd->data;
280 if (!data) {
281 DBG("no data\n");
282 return;
283 }
284
285 while (host->in_use_index < host->transfer_index) {
286 unsigned int *buffer;
287 int index;
288 int len;
289
290 struct scatterlist *sg;
291
292 DBG("finishing index %d\n", host->in_use_index);
293
294 sg = &data->sg[host->in_use_index++];
295
296 DBG("Unmapping page %08X\n", sg->dma_address);
297
298 dma_unmap_page(NULL, sg->dma_address, sg->length, DMA_FROM_DEVICE);
299
300 /* Swap the contents of the buffer */
301 buffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
302 DBG("buffer = %p, length = %d\n", buffer, sg->length);
303
304 data->bytes_xfered += sg->length;
305
306 len = sg->length / 4;
307
308 for (index = 0; index < len; index++) {
309 buffer[index] = swab32(buffer[index]);
310 }
311 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
312 flush_dcache_page(sg->page);
313 }
314
315 /* Is there another transfer to trigger? */
316 if (host->transfer_index < data->sg_len)
317 at91mci_pre_dma_read(host);
318 else {
319 at91_mci_write(AT91_MCI_IER, AT91_MCI_RXBUFF);
320 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
321 }
322
323 DBG("post dma read done\n");
324}
325
326/*
327 * Handle transmitted data
328 */
329static void at91_mci_handle_transmitted(struct at91mci_host *host)
330{
331 struct mmc_command *cmd;
332 struct mmc_data *data;
333
334 DBG("Handling the transmit\n");
335
336 /* Disable the transfer */
337 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
338
339 /* Now wait for cmd ready */
340 at91_mci_write(AT91_MCI_IDR, AT91_MCI_TXBUFE);
341 at91_mci_write(AT91_MCI_IER, AT91_MCI_NOTBUSY);
342
343 cmd = host->cmd;
344 if (!cmd) return;
345
346 data = cmd->data;
347 if (!data) return;
348
349 data->bytes_xfered = host->total_length;
350}
351
352/*
353 * Enable the controller
354 */
355static void at91_mci_enable(void)
356{
357 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIEN);
358 at91_mci_write(AT91_MCI_IDR, 0xFFFFFFFF);
359 at91_mci_write(AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC);
360 at91_mci_write(AT91_MCI_MR, 0x834A);
361 at91_mci_write(AT91_MCI_SDCR, 0x0);
362}
363
364/*
365 * Disable the controller
366 */
367static void at91_mci_disable(void)
368{
369 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST);
370}
371
372/*
373 * Send a command
374 * return the interrupts to enable
375 */
376static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_command *cmd)
377{
378 unsigned int cmdr, mr;
379 unsigned int block_length;
380 struct mmc_data *data = cmd->data;
381
382 unsigned int blocks;
383 unsigned int ier = 0;
384
385 host->cmd = cmd;
386
387 /* Not sure if this is needed */
388#if 0
389 if ((at91_mci_read(AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) {
390 DBG("Clearing timeout\n");
391 at91_mci_write(AT91_MCI_ARGR, 0);
392 at91_mci_write(AT91_MCI_CMDR, AT91_MCI_OPDCMD);
393 while (!(at91_mci_read(AT91_MCI_SR) & AT91_MCI_CMDRDY)) {
394 /* spin */
395 DBG("Clearing: SR = %08X\n", at91_mci_read(AT91_MCI_SR));
396 }
397 }
398#endif
399 cmdr = cmd->opcode;
400
401 if (mmc_resp_type(cmd) == MMC_RSP_NONE)
402 cmdr |= AT91_MCI_RSPTYP_NONE;
403 else {
404 /* if a response is expected then allow maximum response latancy */
405 cmdr |= AT91_MCI_MAXLAT;
406 /* set 136 bit response for R2, 48 bit response otherwise */
407 if (mmc_resp_type(cmd) == MMC_RSP_R2)
408 cmdr |= AT91_MCI_RSPTYP_136;
409 else
410 cmdr |= AT91_MCI_RSPTYP_48;
411 }
412
413 if (data) {
414 block_length = 1 << data->blksz_bits;
415 blocks = data->blocks;
416
417 /* always set data start - also set direction flag for read */
418 if (data->flags & MMC_DATA_READ)
419 cmdr |= (AT91_MCI_TRDIR | AT91_MCI_TRCMD_START);
420 else if (data->flags & MMC_DATA_WRITE)
421 cmdr |= AT91_MCI_TRCMD_START;
422
423 if (data->flags & MMC_DATA_STREAM)
424 cmdr |= AT91_MCI_TRTYP_STREAM;
425 if (data->flags & MMC_DATA_MULTI)
426 cmdr |= AT91_MCI_TRTYP_MULTIPLE;
427 }
428 else {
429 block_length = 0;
430 blocks = 0;
431 }
432
433 if (cmd->opcode == MMC_STOP_TRANSMISSION)
434 cmdr |= AT91_MCI_TRCMD_STOP;
435
436 if (host->bus_mode == MMC_BUSMODE_OPENDRAIN)
437 cmdr |= AT91_MCI_OPDCMD;
438
439 /*
440 * Set the arguments and send the command
441 */
442 DBG("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08lX)\n",
443 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(AT91_MCI_MR));
444
445 if (!data) {
446 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS);
447 at91_mci_write(AT91_PDC_RPR, 0);
448 at91_mci_write(AT91_PDC_RCR, 0);
449 at91_mci_write(AT91_PDC_RNPR, 0);
450 at91_mci_write(AT91_PDC_RNCR, 0);
451 at91_mci_write(AT91_PDC_TPR, 0);
452 at91_mci_write(AT91_PDC_TCR, 0);
453 at91_mci_write(AT91_PDC_TNPR, 0);
454 at91_mci_write(AT91_PDC_TNCR, 0);
455
456 at91_mci_write(AT91_MCI_ARGR, cmd->arg);
457 at91_mci_write(AT91_MCI_CMDR, cmdr);
458 return AT91_MCI_CMDRDY;
459 }
460
461 mr = at91_mci_read(AT91_MCI_MR) & 0x7fff; /* zero block length and PDC mode */
462 at91_mci_write(AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE);
463
464 /*
465 * Disable the PDC controller
466 */
467 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
468
469 if (cmdr & AT91_MCI_TRCMD_START) {
470 data->bytes_xfered = 0;
471 host->transfer_index = 0;
472 host->in_use_index = 0;
473 if (cmdr & AT91_MCI_TRDIR) {
474 /*
475 * Handle a read
476 */
477 host->buffer = NULL;
478 host->total_length = 0;
479
480 at91mci_pre_dma_read(host);
481 ier = AT91_MCI_ENDRX /* | AT91_MCI_RXBUFF */;
482 }
483 else {
484 /*
485 * Handle a write
486 */
487 host->total_length = block_length * blocks;
488 host->buffer = dma_alloc_coherent(NULL,
489 host->total_length,
490 &host->physical_address, GFP_KERNEL);
491
492 at91mci_sg_to_dma(host, data);
493
494 DBG("Transmitting %d bytes\n", host->total_length);
495
496 at91_mci_write(AT91_PDC_TPR, host->physical_address);
497 at91_mci_write(AT91_PDC_TCR, host->total_length / 4);
498 ier = AT91_MCI_TXBUFE;
499 }
500 }
501
502 /*
503 * Send the command and then enable the PDC - not the other way round as
504 * the data sheet says
505 */
506
507 at91_mci_write(AT91_MCI_ARGR, cmd->arg);
508 at91_mci_write(AT91_MCI_CMDR, cmdr);
509
510 if (cmdr & AT91_MCI_TRCMD_START) {
511 if (cmdr & AT91_MCI_TRDIR)
512 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTEN);
513 else
514 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_TXTEN);
515 }
516 return ier;
517}
518
519/*
520 * Wait for a command to complete
521 */
522static void at91mci_process_command(struct at91mci_host *host, struct mmc_command *cmd)
523{
524 unsigned int ier;
525
526 ier = at91_mci_send_command(host, cmd);
527
528 DBG("setting ier to %08X\n", ier);
529
530 /* Stop on errors or the required value */
531 at91_mci_write(AT91_MCI_IER, 0xffff0000 | ier);
532}
533
534/*
535 * Process the next step in the request
536 */
537static void at91mci_process_next(struct at91mci_host *host)
538{
539 if (!(host->flags & FL_SENT_COMMAND)) {
540 host->flags |= FL_SENT_COMMAND;
541 at91mci_process_command(host, host->request->cmd);
542 }
543 else if ((!(host->flags & FL_SENT_STOP)) && host->request->stop) {
544 host->flags |= FL_SENT_STOP;
545 at91mci_process_command(host, host->request->stop);
546 }
547 else
548 mmc_request_done(host->mmc, host->request);
549}
550
551/*
552 * Handle a command that has been completed
553 */
554static void at91mci_completed_command(struct at91mci_host *host)
555{
556 struct mmc_command *cmd = host->cmd;
557 unsigned int status;
558
559 at91_mci_write(AT91_MCI_IDR, 0xffffffff);
560
561 cmd->resp[0] = at91_mci_read(AT91_MCI_RSPR(0));
562 cmd->resp[1] = at91_mci_read(AT91_MCI_RSPR(1));
563 cmd->resp[2] = at91_mci_read(AT91_MCI_RSPR(2));
564 cmd->resp[3] = at91_mci_read(AT91_MCI_RSPR(3));
565
566 if (host->buffer) {
567 dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address);
568 host->buffer = NULL;
569 }
570
571 status = at91_mci_read(AT91_MCI_SR);
572
573 DBG("Status = %08X [%08X %08X %08X %08X]\n",
574 status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
575
576 if (status & (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE |
577 AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE |
578 AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)) {
579 if ((status & AT91_MCI_RCRCE) &&
580 ((cmd->opcode == MMC_SEND_OP_COND) || (cmd->opcode == SD_APP_OP_COND))) {
581 cmd->error = MMC_ERR_NONE;
582 }
583 else {
584 if (status & (AT91_MCI_RTOE | AT91_MCI_DTOE))
585 cmd->error = MMC_ERR_TIMEOUT;
586 else if (status & (AT91_MCI_RCRCE | AT91_MCI_DCRCE))
587 cmd->error = MMC_ERR_BADCRC;
588 else if (status & (AT91_MCI_OVRE | AT91_MCI_UNRE))
589 cmd->error = MMC_ERR_FIFO;
590 else
591 cmd->error = MMC_ERR_FAILED;
592
593 DBG("Error detected and set to %d (cmd = %d, retries = %d)\n",
594 cmd->error, cmd->opcode, cmd->retries);
595 }
596 }
597 else
598 cmd->error = MMC_ERR_NONE;
599
600 at91mci_process_next(host);
601}
602
603/*
604 * Handle an MMC request
605 */
606static void at91_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)
607{
608 struct at91mci_host *host = mmc_priv(mmc);
609 host->request = mrq;
610 host->flags = 0;
611
612 at91mci_process_next(host);
613}
614
615/*
616 * Set the IOS
617 */
618static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
619{
620 int clkdiv;
621 struct at91mci_host *host = mmc_priv(mmc);
622 unsigned long at91_master_clock = clk_get_rate(mci_clk);
623
624 DBG("Clock %uHz, busmode %u, powermode %u, Vdd %u\n",
625 ios->clock, ios->bus_mode, ios->power_mode, ios->vdd);
626
627 if (host)
628 host->bus_mode = ios->bus_mode;
629 else
630 printk("MMC: No host for bus_mode\n");
631
632 if (ios->clock == 0) {
633 /* Disable the MCI controller */
634 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIDIS);
635 clkdiv = 0;
636 }
637 else {
638 /* Enable the MCI controller */
639 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIEN);
640
641 if ((at91_master_clock % (ios->clock * 2)) == 0)
642 clkdiv = ((at91_master_clock / ios->clock) / 2) - 1;
643 else
644 clkdiv = (at91_master_clock / ios->clock) / 2;
645
646 DBG("clkdiv = %d. mcck = %ld\n", clkdiv,
647 at91_master_clock / (2 * (clkdiv + 1)));
648 }
649 if (ios->bus_width == MMC_BUS_WIDTH_4 && host->board->wire4) {
650 DBG("MMC: Setting controller bus width to 4\n");
651 at91_mci_write(AT91_MCI_SDCR, at91_mci_read(AT91_MCI_SDCR) | AT91_MCI_SDCBUS);
652 }
653 else {
654 DBG("MMC: Setting controller bus width to 1\n");
655 at91_mci_write(AT91_MCI_SDCR, at91_mci_read(AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS);
656 }
657
658 /* Set the clock divider */
659 at91_mci_write(AT91_MCI_MR, (at91_mci_read(AT91_MCI_MR) & ~AT91_MCI_CLKDIV) | clkdiv);
660
661 /* maybe switch power to the card */
662 if (host && host->board->vcc_pin) {
663 switch (ios->power_mode) {
664 case MMC_POWER_OFF:
665 at91_set_gpio_output(host->board->vcc_pin, 0);
666 break;
667 case MMC_POWER_UP:
668 case MMC_POWER_ON:
669 at91_set_gpio_output(host->board->vcc_pin, 1);
670 break;
671 }
672 }
673}
674
675/*
676 * Handle an interrupt
677 */
678static irqreturn_t at91_mci_irq(int irq, void *devid, struct pt_regs *regs)
679{
680 struct at91mci_host *host = devid;
681 int completed = 0;
682
683 unsigned int int_status;
684
685 if (host == NULL)
686 return IRQ_HANDLED;
687
688 int_status = at91_mci_read(AT91_MCI_SR);
689 DBG("MCI irq: status = %08X, %08lX, %08lX\n", int_status, at91_mci_read(AT91_MCI_IMR),
690 int_status & at91_mci_read(AT91_MCI_IMR));
691
692 if ((int_status & at91_mci_read(AT91_MCI_IMR)) & 0xffff0000)
693 completed = 1;
694
695 int_status &= at91_mci_read(AT91_MCI_IMR);
696
697 if (int_status & AT91_MCI_UNRE)
698 DBG("MMC: Underrun error\n");
699 if (int_status & AT91_MCI_OVRE)
700 DBG("MMC: Overrun error\n");
701 if (int_status & AT91_MCI_DTOE)
702 DBG("MMC: Data timeout\n");
703 if (int_status & AT91_MCI_DCRCE)
704 DBG("MMC: CRC error in data\n");
705 if (int_status & AT91_MCI_RTOE)
706 DBG("MMC: Response timeout\n");
707 if (int_status & AT91_MCI_RENDE)
708 DBG("MMC: Response end bit error\n");
709 if (int_status & AT91_MCI_RCRCE)
710 DBG("MMC: Response CRC error\n");
711 if (int_status & AT91_MCI_RDIRE)
712 DBG("MMC: Response direction error\n");
713 if (int_status & AT91_MCI_RINDE)
714 DBG("MMC: Response index error\n");
715
716 /* Only continue processing if no errors */
717 if (!completed) {
718 if (int_status & AT91_MCI_TXBUFE) {
719 DBG("TX buffer empty\n");
720 at91_mci_handle_transmitted(host);
721 }
722
723 if (int_status & AT91_MCI_RXBUFF) {
724 DBG("RX buffer full\n");
725 at91_mci_write(AT91_MCI_IER, AT91_MCI_CMDRDY);
726 }
727
728 if (int_status & AT91_MCI_ENDTX) {
729 DBG("Transmit has ended\n");
730 }
731
732 if (int_status & AT91_MCI_ENDRX) {
733 DBG("Receive has ended\n");
734 at91mci_post_dma_read(host);
735 }
736
737 if (int_status & AT91_MCI_NOTBUSY) {
738 DBG("Card is ready\n");
739 at91_mci_write(AT91_MCI_IER, AT91_MCI_CMDRDY);
740 }
741
742 if (int_status & AT91_MCI_DTIP) {
743 DBG("Data transfer in progress\n");
744 }
745
746 if (int_status & AT91_MCI_BLKE) {
747 DBG("Block transfer has ended\n");
748 }
749
750 if (int_status & AT91_MCI_TXRDY) {
751 DBG("Ready to transmit\n");
752 }
753
754 if (int_status & AT91_MCI_RXRDY) {
755 DBG("Ready to receive\n");
756 }
757
758 if (int_status & AT91_MCI_CMDRDY) {
759 DBG("Command ready\n");
760 completed = 1;
761 }
762 }
763 at91_mci_write(AT91_MCI_IDR, int_status);
764
765 if (completed) {
766 DBG("Completed command\n");
767 at91_mci_write(AT91_MCI_IDR, 0xffffffff);
768 at91mci_completed_command(host);
769 }
770
771 return IRQ_HANDLED;
772}
773
774static irqreturn_t at91_mmc_det_irq(int irq, void *_host, struct pt_regs *regs)
775{
776 struct at91mci_host *host = _host;
777 int present = !at91_get_gpio_value(irq);
778
779 /*
780 * we expect this irq on both insert and remove,
781 * and use a short delay to debounce.
782 */
783 if (present != host->present) {
784 host->present = present;
785 DBG("%s: card %s\n", mmc_hostname(host->mmc),
786 present ? "insert" : "remove");
787 if (!present) {
788 DBG("****** Resetting SD-card bus width ******\n");
789 at91_mci_write(AT91_MCI_SDCR, 0);
790 }
791 mmc_detect_change(host->mmc, msecs_to_jiffies(100));
792 }
793 return IRQ_HANDLED;
794}
795
796int at91_mci_get_ro(struct mmc_host *mmc)
797{
798 int read_only = 0;
799 struct at91mci_host *host = mmc_priv(mmc);
800
801 if (host->board->wp_pin) {
802 read_only = at91_get_gpio_value(host->board->wp_pin);
803 printk(KERN_WARNING "%s: card is %s\n", mmc_hostname(mmc),
804 (read_only ? "read-only" : "read-write") );
805 }
806 else {
807 printk(KERN_WARNING "%s: host does not support reading read-only "
808 "switch. Assuming write-enable.\n", mmc_hostname(mmc));
809 }
810 return read_only;
811}
812
813static struct mmc_host_ops at91_mci_ops = {
814 .request = at91_mci_request,
815 .set_ios = at91_mci_set_ios,
816 .get_ro = at91_mci_get_ro,
817};
818
819/*
820 * Probe for the device
821 */
822static int at91_mci_probe(struct platform_device *pdev)
823{
824 struct mmc_host *mmc;
825 struct at91mci_host *host;
826 int ret;
827
828 DBG("Probe MCI devices\n");
829 at91_mci_disable();
830 at91_mci_enable();
831
832 mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev);
833 if (!mmc) {
834 DBG("Failed to allocate mmc host\n");
835 return -ENOMEM;
836 }
837
838 mmc->ops = &at91_mci_ops;
839 mmc->f_min = 375000;
840 mmc->f_max = 25000000;
841 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
842
843 host = mmc_priv(mmc);
844 host->mmc = mmc;
845 host->buffer = NULL;
846 host->bus_mode = 0;
847 host->board = pdev->dev.platform_data;
848 if (host->board->wire4) {
849#ifdef SUPPORT_4WIRE
850 mmc->caps |= MMC_CAP_4_BIT_DATA;
851#else
852 printk("MMC: 4 wire bus mode not supported by this driver - using 1 wire\n");
853#endif
854 }
855
856 /*
857 * Get Clock
858 */
859 mci_clk = clk_get(&pdev->dev, "mci_clk");
860 if (!mci_clk) {
861 printk(KERN_ERR "AT91 MMC: no clock defined.\n");
862 return -ENODEV;
863 }
864 clk_enable(mci_clk); /* Enable the peripheral clock */
865
866 /*
867 * Allocate the MCI interrupt
868 */
869 ret = request_irq(AT91_ID_MCI, at91_mci_irq, SA_SHIRQ, DRIVER_NAME, host);
870 if (ret) {
871 DBG("Failed to request MCI interrupt\n");
872 return ret;
873 }
874
875 platform_set_drvdata(pdev, mmc);
876
877 /*
878 * Add host to MMC layer
879 */
880 if (host->board->det_pin)
881 host->present = !at91_get_gpio_value(host->board->det_pin);
882 else
883 host->present = -1;
884
885 mmc_add_host(mmc);
886
887 /*
888 * monitor card insertion/removal if we can
889 */
890 if (host->board->det_pin) {
891 ret = request_irq(host->board->det_pin, at91_mmc_det_irq,
892 SA_SAMPLE_RANDOM, DRIVER_NAME, host);
893 if (ret)
894 DBG("couldn't allocate MMC detect irq\n");
895 }
896
897 DBG(KERN_INFO "Added MCI driver\n");
898
899 return 0;
900}
901
902/*
903 * Remove a device
904 */
905static int at91_mci_remove(struct platform_device *pdev)
906{
907 struct mmc_host *mmc = platform_get_drvdata(pdev);
908 struct at91mci_host *host;
909
910 if (!mmc)
911 return -1;
912
913 host = mmc_priv(mmc);
914
915 if (host->present != -1) {
916 free_irq(host->board->det_pin, host);
917 cancel_delayed_work(&host->mmc->detect);
918 }
919
920 mmc_remove_host(mmc);
921 at91_mci_disable();
922 free_irq(AT91_ID_MCI, host);
923 mmc_free_host(mmc);
924
925 clk_disable(mci_clk); /* Disable the peripheral clock */
926 clk_put(mci_clk);
927
928 platform_set_drvdata(pdev, NULL);
929
930 DBG("Removed\n");
931
932 return 0;
933}
934
935#ifdef CONFIG_PM
936static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state)
937{
938 struct mmc_host *mmc = platform_get_drvdata(pdev);
939 int ret = 0;
940
941 if (mmc)
942 ret = mmc_suspend_host(mmc, state);
943
944 return ret;
945}
946
947static int at91_mci_resume(struct platform_device *pdev)
948{
949 struct mmc_host *mmc = platform_get_drvdata(pdev);
950 int ret = 0;
951
952 if (mmc)
953 ret = mmc_resume_host(mmc);
954
955 return ret;
956}
957#else
958#define at91_mci_suspend NULL
959#define at91_mci_resume NULL
960#endif
961
962static struct platform_driver at91_mci_driver = {
963 .probe = at91_mci_probe,
964 .remove = at91_mci_remove,
965 .suspend = at91_mci_suspend,
966 .resume = at91_mci_resume,
967 .driver = {
968 .name = DRIVER_NAME,
969 .owner = THIS_MODULE,
970 },
971};
972
973static int __init at91_mci_init(void)
974{
975 return platform_driver_register(&at91_mci_driver);
976}
977
978static void __exit at91_mci_exit(void)
979{
980 platform_driver_unregister(&at91_mci_driver);
981}
982
983module_init(at91_mci_init);
984module_exit(at91_mci_exit);
985
986MODULE_DESCRIPTION("AT91 Multimedia Card Interface driver");
987MODULE_AUTHOR("Nick Randell");
988MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/au1xmmc.c b/drivers/mmc/au1xmmc.c
index 85e89c77bdea..c0326bbc5f28 100644
--- a/drivers/mmc/au1xmmc.c
+++ b/drivers/mmc/au1xmmc.c
@@ -56,12 +56,11 @@
56#define DRIVER_NAME "au1xxx-mmc" 56#define DRIVER_NAME "au1xxx-mmc"
57 57
58/* Set this to enable special debugging macros */ 58/* Set this to enable special debugging macros */
59/* #define MMC_DEBUG */
60 59
61#ifdef MMC_DEBUG 60#ifdef DEBUG
62#define DEBUG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args) 61#define DBG(fmt, idx, args...) printk("au1xx(%d): DEBUG: " fmt, idx, ##args)
63#else 62#else
64#define DEBUG(fmt, idx, args...) 63#define DBG(fmt, idx, args...)
65#endif 64#endif
66 65
67const struct { 66const struct {
@@ -424,18 +423,18 @@ static void au1xmmc_receive_pio(struct au1xmmc_host *host)
424 break; 423 break;
425 424
426 if (status & SD_STATUS_RC) { 425 if (status & SD_STATUS_RC) {
427 DEBUG("RX CRC Error [%d + %d].\n", host->id, 426 DBG("RX CRC Error [%d + %d].\n", host->id,
428 host->pio.len, count); 427 host->pio.len, count);
429 break; 428 break;
430 } 429 }
431 430
432 if (status & SD_STATUS_RO) { 431 if (status & SD_STATUS_RO) {
433 DEBUG("RX Overrun [%d + %d]\n", host->id, 432 DBG("RX Overrun [%d + %d]\n", host->id,
434 host->pio.len, count); 433 host->pio.len, count);
435 break; 434 break;
436 } 435 }
437 else if (status & SD_STATUS_RU) { 436 else if (status & SD_STATUS_RU) {
438 DEBUG("RX Underrun [%d + %d]\n", host->id, 437 DBG("RX Underrun [%d + %d]\n", host->id,
439 host->pio.len, count); 438 host->pio.len, count);
440 break; 439 break;
441 } 440 }
@@ -721,7 +720,7 @@ static void au1xmmc_set_ios(struct mmc_host* mmc, struct mmc_ios* ios)
721{ 720{
722 struct au1xmmc_host *host = mmc_priv(mmc); 721 struct au1xmmc_host *host = mmc_priv(mmc);
723 722
724 DEBUG("set_ios (power=%u, clock=%uHz, vdd=%u, mode=%u)\n", 723 DBG("set_ios (power=%u, clock=%uHz, vdd=%u, mode=%u)\n",
725 host->id, ios->power_mode, ios->clock, ios->vdd, 724 host->id, ios->power_mode, ios->clock, ios->vdd,
726 ios->bus_mode); 725 ios->bus_mode);
727 726
@@ -810,7 +809,7 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id, struct pt_regs *regs)
810 au1xmmc_receive_pio(host); 809 au1xmmc_receive_pio(host);
811 } 810 }
812 else if (status & 0x203FBC70) { 811 else if (status & 0x203FBC70) {
813 DEBUG("Unhandled status %8.8x\n", host->id, status); 812 DBG("Unhandled status %8.8x\n", host->id, status);
814 handled = 0; 813 handled = 0;
815 } 814 }
816 815
@@ -839,7 +838,7 @@ static void au1xmmc_poll_event(unsigned long arg)
839 838
840 if (host->mrq != NULL) { 839 if (host->mrq != NULL) {
841 u32 status = au_readl(HOST_STATUS(host)); 840 u32 status = au_readl(HOST_STATUS(host));
842 DEBUG("PENDING - %8.8x\n", host->id, status); 841 DBG("PENDING - %8.8x\n", host->id, status);
843 } 842 }
844 843
845 mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT); 844 mod_timer(&host->timer, jiffies + AU1XMMC_DETECT_TIMEOUT);
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c
new file mode 100644
index 000000000000..ffb7f55d3467
--- /dev/null
+++ b/drivers/mmc/imxmmc.c
@@ -0,0 +1,1096 @@
1/*
2 * linux/drivers/mmc/imxmmc.c - Motorola i.MX MMCI driver
3 *
4 * Copyright (C) 2004 Sascha Hauer, Pengutronix <sascha@saschahauer.de>
5 * Copyright (C) 2006 Pavel Pisa, PiKRON <ppisa@pikron.com>
6 *
7 * derived from pxamci.c by Russell King
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * 2005-04-17 Pavel Pisa <pisa@cmp.felk.cvut.cz>
14 * Changed to conform redesigned i.MX scatter gather DMA interface
15 *
16 * 2005-11-04 Pavel Pisa <pisa@cmp.felk.cvut.cz>
17 * Updated for 2.6.14 kernel
18 *
19 * 2005-12-13 Jay Monkman <jtm@smoothsmoothie.com>
20 * Found and corrected problems in the write path
21 *
22 * 2005-12-30 Pavel Pisa <pisa@cmp.felk.cvut.cz>
23 * The event handling rewritten right way in softirq.
24 * Added many ugly hacks and delays to overcome SDHC
25 * deficiencies
26 *
27 */
28#include <linux/config.h>
29
30#ifdef CONFIG_MMC_DEBUG
31#define DEBUG
32#else
33#undef DEBUG
34#endif
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/ioport.h>
39#include <linux/platform_device.h>
40#include <linux/interrupt.h>
41#include <linux/blkdev.h>
42#include <linux/dma-mapping.h>
43#include <linux/mmc/host.h>
44#include <linux/mmc/card.h>
45#include <linux/mmc/protocol.h>
46#include <linux/delay.h>
47
48#include <asm/dma.h>
49#include <asm/io.h>
50#include <asm/irq.h>
51#include <asm/sizes.h>
52#include <asm/arch/mmc.h>
53#include <asm/arch/imx-dma.h>
54
55#include "imxmmc.h"
56
57#define DRIVER_NAME "imx-mmc"
58
59#define IMXMCI_INT_MASK_DEFAULT (INT_MASK_BUF_READY | INT_MASK_DATA_TRAN | \
60 INT_MASK_WRITE_OP_DONE | INT_MASK_END_CMD_RES | \
61 INT_MASK_AUTO_CARD_DETECT | INT_MASK_DAT0_EN | INT_MASK_SDIO)
62
63struct imxmci_host {
64 struct mmc_host *mmc;
65 spinlock_t lock;
66 struct resource *res;
67 int irq;
68 imx_dmach_t dma;
69 unsigned int clkrt;
70 unsigned int cmdat;
71 volatile unsigned int imask;
72 unsigned int power_mode;
73 unsigned int present;
74 struct imxmmc_platform_data *pdata;
75
76 struct mmc_request *req;
77 struct mmc_command *cmd;
78 struct mmc_data *data;
79
80 struct timer_list timer;
81 struct tasklet_struct tasklet;
82 unsigned int status_reg;
83 unsigned long pending_events;
84 /* Next to fields are there for CPU driven transfers to overcome SDHC deficiencies */
85 u16 *data_ptr;
86 unsigned int data_cnt;
87 atomic_t stuck_timeout;
88
89 unsigned int dma_nents;
90 unsigned int dma_size;
91 unsigned int dma_dir;
92 int dma_allocated;
93
94 unsigned char actual_bus_width;
95};
96
97#define IMXMCI_PEND_IRQ_b 0
98#define IMXMCI_PEND_DMA_END_b 1
99#define IMXMCI_PEND_DMA_ERR_b 2
100#define IMXMCI_PEND_WAIT_RESP_b 3
101#define IMXMCI_PEND_DMA_DATA_b 4
102#define IMXMCI_PEND_CPU_DATA_b 5
103#define IMXMCI_PEND_CARD_XCHG_b 6
104#define IMXMCI_PEND_SET_INIT_b 7
105
106#define IMXMCI_PEND_IRQ_m (1 << IMXMCI_PEND_IRQ_b)
107#define IMXMCI_PEND_DMA_END_m (1 << IMXMCI_PEND_DMA_END_b)
108#define IMXMCI_PEND_DMA_ERR_m (1 << IMXMCI_PEND_DMA_ERR_b)
109#define IMXMCI_PEND_WAIT_RESP_m (1 << IMXMCI_PEND_WAIT_RESP_b)
110#define IMXMCI_PEND_DMA_DATA_m (1 << IMXMCI_PEND_DMA_DATA_b)
111#define IMXMCI_PEND_CPU_DATA_m (1 << IMXMCI_PEND_CPU_DATA_b)
112#define IMXMCI_PEND_CARD_XCHG_m (1 << IMXMCI_PEND_CARD_XCHG_b)
113#define IMXMCI_PEND_SET_INIT_m (1 << IMXMCI_PEND_SET_INIT_b)
114
115static void imxmci_stop_clock(struct imxmci_host *host)
116{
117 int i = 0;
118 MMC_STR_STP_CLK &= ~STR_STP_CLK_START_CLK;
119 while(i < 0x1000) {
120 if(!(i & 0x7f))
121 MMC_STR_STP_CLK |= STR_STP_CLK_STOP_CLK;
122
123 if(!(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN)) {
124 /* Check twice before cut */
125 if(!(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN))
126 return;
127 }
128
129 i++;
130 }
131 dev_dbg(mmc_dev(host->mmc), "imxmci_stop_clock blocked, no luck\n");
132}
133
134static void imxmci_start_clock(struct imxmci_host *host)
135{
136 int i = 0;
137 MMC_STR_STP_CLK &= ~STR_STP_CLK_STOP_CLK;
138 while(i < 0x1000) {
139 if(!(i & 0x7f))
140 MMC_STR_STP_CLK |= STR_STP_CLK_START_CLK;
141
142 if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN) {
143 /* Check twice before cut */
144 if(MMC_STATUS & STATUS_CARD_BUS_CLK_RUN)
145 return;
146 }
147
148 i++;
149 }
150 dev_dbg(mmc_dev(host->mmc), "imxmci_start_clock blocked, no luck\n");
151}
152
153static void imxmci_softreset(void)
154{
155 /* reset sequence */
156 MMC_STR_STP_CLK = 0x8;
157 MMC_STR_STP_CLK = 0xD;
158 MMC_STR_STP_CLK = 0x5;
159 MMC_STR_STP_CLK = 0x5;
160 MMC_STR_STP_CLK = 0x5;
161 MMC_STR_STP_CLK = 0x5;
162 MMC_STR_STP_CLK = 0x5;
163 MMC_STR_STP_CLK = 0x5;
164 MMC_STR_STP_CLK = 0x5;
165 MMC_STR_STP_CLK = 0x5;
166
167 MMC_RES_TO = 0xff;
168 MMC_BLK_LEN = 512;
169 MMC_NOB = 1;
170}
171
172static int imxmci_busy_wait_for_status(struct imxmci_host *host,
173 unsigned int *pstat, unsigned int stat_mask,
174 int timeout, const char *where)
175{
176 int loops=0;
177 while(!(*pstat & stat_mask)) {
178 loops+=2;
179 if(loops >= timeout) {
180 dev_dbg(mmc_dev(host->mmc), "busy wait timeout in %s, STATUS = 0x%x (0x%x)\n",
181 where, *pstat, stat_mask);
182 return -1;
183 }
184 udelay(2);
185 *pstat |= MMC_STATUS;
186 }
187 if(!loops)
188 return 0;
189
190 dev_info(mmc_dev(host->mmc), "busy wait for %d usec in %s, STATUS = 0x%x (0x%x)\n",
191 loops, where, *pstat, stat_mask);
192 return loops;
193}
194
195static void imxmci_setup_data(struct imxmci_host *host, struct mmc_data *data)
196{
197 unsigned int nob = data->blocks;
198 unsigned int blksz = 1 << data->blksz_bits;
199 unsigned int datasz = nob * blksz;
200 int i;
201
202 if (data->flags & MMC_DATA_STREAM)
203 nob = 0xffff;
204
205 host->data = data;
206 data->bytes_xfered = 0;
207
208 MMC_NOB = nob;
209 MMC_BLK_LEN = blksz;
210
211 /*
212 * DMA cannot be used for small block sizes, we have to use CPU driven transfers otherwise.
213 * We are in big troubles for non-512 byte transfers according to note in the paragraph
214 * 20.6.7 of User Manual anyway, but we need to be able to transfer SCR at least.
215 * The situation is even more complex in reality. The SDHC in not able to handle wll
216 * partial FIFO fills and reads. The length has to be rounded up to burst size multiple.
217 * This is required for SCR read at least.
218 */
219 if (datasz < 64) {
220 host->dma_size = datasz;
221 if (data->flags & MMC_DATA_READ) {
222 host->dma_dir = DMA_FROM_DEVICE;
223
224 /* Hack to enable read SCR */
225 if(datasz < 16) {
226 MMC_NOB = 1;
227 MMC_BLK_LEN = 16;
228 }
229 } else {
230 host->dma_dir = DMA_TO_DEVICE;
231 }
232
233 /* Convert back to virtual address */
234 host->data_ptr = (u16*)(page_address(data->sg->page) + data->sg->offset);
235 host->data_cnt = 0;
236
237 clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events);
238 set_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events);
239
240 return;
241 }
242
243 if (data->flags & MMC_DATA_READ) {
244 host->dma_dir = DMA_FROM_DEVICE;
245 host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg,
246 data->sg_len, host->dma_dir);
247
248 imx_dma_setup_sg(host->dma, data->sg, data->sg_len, datasz,
249 host->res->start + MMC_BUFFER_ACCESS_OFS, DMA_MODE_READ);
250
251 /*imx_dma_setup_mem2dev_ccr(host->dma, DMA_MODE_READ, IMX_DMA_WIDTH_16, CCR_REN);*/
252 CCR(host->dma) = CCR_DMOD_LINEAR | CCR_DSIZ_32 | CCR_SMOD_FIFO | CCR_SSIZ_16 | CCR_REN;
253 } else {
254 host->dma_dir = DMA_TO_DEVICE;
255
256 host->dma_nents = dma_map_sg(mmc_dev(host->mmc), data->sg,
257 data->sg_len, host->dma_dir);
258
259 imx_dma_setup_sg(host->dma, data->sg, data->sg_len, datasz,
260 host->res->start + MMC_BUFFER_ACCESS_OFS, DMA_MODE_WRITE);
261
262 /*imx_dma_setup_mem2dev_ccr(host->dma, DMA_MODE_WRITE, IMX_DMA_WIDTH_16, CCR_REN);*/
263 CCR(host->dma) = CCR_SMOD_LINEAR | CCR_SSIZ_32 | CCR_DMOD_FIFO | CCR_DSIZ_16 | CCR_REN;
264 }
265
266#if 1 /* This code is there only for consistency checking and can be disabled in future */
267 host->dma_size = 0;
268 for(i=0; i<host->dma_nents; i++)
269 host->dma_size+=data->sg[i].length;
270
271 if (datasz > host->dma_size) {
272 dev_err(mmc_dev(host->mmc), "imxmci_setup_data datasz 0x%x > 0x%x dm_size\n",
273 datasz, host->dma_size);
274 }
275#endif
276
277 host->dma_size = datasz;
278
279 wmb();
280
281 if(host->actual_bus_width == MMC_BUS_WIDTH_4)
282 BLR(host->dma) = 0; /* burst 64 byte read / 64 bytes write */
283 else
284 BLR(host->dma) = 16; /* burst 16 byte read / 16 bytes write */
285
286 RSSR(host->dma) = DMA_REQ_SDHC;
287
288 set_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events);
289 clear_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events);
290
291 /* start DMA engine for read, write is delayed after initial response */
292 if (host->dma_dir == DMA_FROM_DEVICE) {
293 imx_dma_enable(host->dma);
294 }
295}
296
297static void imxmci_start_cmd(struct imxmci_host *host, struct mmc_command *cmd, unsigned int cmdat)
298{
299 unsigned long flags;
300 u32 imask;
301
302 WARN_ON(host->cmd != NULL);
303 host->cmd = cmd;
304
305 if (cmd->flags & MMC_RSP_BUSY)
306 cmdat |= CMD_DAT_CONT_BUSY;
307
308 switch (mmc_resp_type(cmd)) {
309 case MMC_RSP_R1: /* short CRC, OPCODE */
310 case MMC_RSP_R1B:/* short CRC, OPCODE, BUSY */
311 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R1;
312 break;
313 case MMC_RSP_R2: /* long 136 bit + CRC */
314 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R2;
315 break;
316 case MMC_RSP_R3: /* short */
317 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R3;
318 break;
319 case MMC_RSP_R6: /* short CRC */
320 cmdat |= CMD_DAT_CONT_RESPONSE_FORMAT_R6;
321 break;
322 default:
323 break;
324 }
325
326 if ( test_and_clear_bit(IMXMCI_PEND_SET_INIT_b, &host->pending_events) )
327 cmdat |= CMD_DAT_CONT_INIT; /* This command needs init */
328
329 if ( host->actual_bus_width == MMC_BUS_WIDTH_4 )
330 cmdat |= CMD_DAT_CONT_BUS_WIDTH_4;
331
332 MMC_CMD = cmd->opcode;
333 MMC_ARGH = cmd->arg >> 16;
334 MMC_ARGL = cmd->arg & 0xffff;
335 MMC_CMD_DAT_CONT = cmdat;
336
337 atomic_set(&host->stuck_timeout, 0);
338 set_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events);
339
340
341 imask = IMXMCI_INT_MASK_DEFAULT;
342 imask &= ~INT_MASK_END_CMD_RES;
343 if ( cmdat & CMD_DAT_CONT_DATA_ENABLE ) {
344 /*imask &= ~INT_MASK_BUF_READY;*/
345 imask &= ~INT_MASK_DATA_TRAN;
346 if ( cmdat & CMD_DAT_CONT_WRITE )
347 imask &= ~INT_MASK_WRITE_OP_DONE;
348 if(test_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events))
349 imask &= ~INT_MASK_BUF_READY;
350 }
351
352 spin_lock_irqsave(&host->lock, flags);
353 host->imask = imask;
354 MMC_INT_MASK = host->imask;
355 spin_unlock_irqrestore(&host->lock, flags);
356
357 dev_dbg(mmc_dev(host->mmc), "CMD%02d (0x%02x) mask set to 0x%04x\n",
358 cmd->opcode, cmd->opcode, imask);
359
360 imxmci_start_clock(host);
361}
362
363static void imxmci_finish_request(struct imxmci_host *host, struct mmc_request *req)
364{
365 unsigned long flags;
366
367 spin_lock_irqsave(&host->lock, flags);
368
369 host->pending_events &= ~(IMXMCI_PEND_WAIT_RESP_m | IMXMCI_PEND_DMA_END_m |
370 IMXMCI_PEND_DMA_DATA_m | IMXMCI_PEND_CPU_DATA_m);
371
372 host->imask = IMXMCI_INT_MASK_DEFAULT;
373 MMC_INT_MASK = host->imask;
374
375 spin_unlock_irqrestore(&host->lock, flags);
376
377 host->req = NULL;
378 host->cmd = NULL;
379 host->data = NULL;
380 mmc_request_done(host->mmc, req);
381}
382
383static int imxmci_finish_data(struct imxmci_host *host, unsigned int stat)
384{
385 struct mmc_data *data = host->data;
386 int data_error;
387
388 if(test_and_clear_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)){
389 imx_dma_disable(host->dma);
390 dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->dma_nents,
391 host->dma_dir);
392 }
393
394 if ( stat & STATUS_ERR_MASK ) {
395 dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",stat);
396 if(stat & (STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR))
397 data->error = MMC_ERR_BADCRC;
398 else if(stat & STATUS_TIME_OUT_READ)
399 data->error = MMC_ERR_TIMEOUT;
400 else
401 data->error = MMC_ERR_FAILED;
402 } else {
403 data->bytes_xfered = host->dma_size;
404 }
405
406 data_error = data->error;
407
408 host->data = NULL;
409
410 return data_error;
411}
412
413static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
414{
415 struct mmc_command *cmd = host->cmd;
416 int i;
417 u32 a,b,c;
418 struct mmc_data *data = host->data;
419
420 if (!cmd)
421 return 0;
422
423 host->cmd = NULL;
424
425 if (stat & STATUS_TIME_OUT_RESP) {
426 dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n");
427 cmd->error = MMC_ERR_TIMEOUT;
428 } else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
429 dev_dbg(mmc_dev(host->mmc), "cmd crc error\n");
430 cmd->error = MMC_ERR_BADCRC;
431 }
432
433 if(cmd->flags & MMC_RSP_PRESENT) {
434 if(cmd->flags & MMC_RSP_136) {
435 for (i = 0; i < 4; i++) {
436 u32 a = MMC_RES_FIFO & 0xffff;
437 u32 b = MMC_RES_FIFO & 0xffff;
438 cmd->resp[i] = a<<16 | b;
439 }
440 } else {
441 a = MMC_RES_FIFO & 0xffff;
442 b = MMC_RES_FIFO & 0xffff;
443 c = MMC_RES_FIFO & 0xffff;
444 cmd->resp[0] = a<<24 | b<<8 | c>>8;
445 }
446 }
447
448 dev_dbg(mmc_dev(host->mmc), "RESP 0x%08x, 0x%08x, 0x%08x, 0x%08x, error %d\n",
449 cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3], cmd->error);
450
451 if (data && (cmd->error == MMC_ERR_NONE) && !(stat & STATUS_ERR_MASK)) {
452 if (host->req->data->flags & MMC_DATA_WRITE) {
453
454 /* Wait for FIFO to be empty before starting DMA write */
455
456 stat = MMC_STATUS;
457 if(imxmci_busy_wait_for_status(host, &stat,
458 STATUS_APPL_BUFF_FE,
459 40, "imxmci_cmd_done DMA WR") < 0) {
460 cmd->error = MMC_ERR_FIFO;
461 imxmci_finish_data(host, stat);
462 if(host->req)
463 imxmci_finish_request(host, host->req);
464 dev_warn(mmc_dev(host->mmc), "STATUS = 0x%04x\n",
465 stat);
466 return 0;
467 }
468
469 if(test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) {
470 imx_dma_enable(host->dma);
471 }
472 }
473 } else {
474 struct mmc_request *req;
475 imxmci_stop_clock(host);
476 req = host->req;
477
478 if(data)
479 imxmci_finish_data(host, stat);
480
481 if( req ) {
482 imxmci_finish_request(host, req);
483 } else {
484 dev_warn(mmc_dev(host->mmc), "imxmci_cmd_done: no request to finish\n");
485 }
486 }
487
488 return 1;
489}
490
491static int imxmci_data_done(struct imxmci_host *host, unsigned int stat)
492{
493 struct mmc_data *data = host->data;
494 int data_error;
495
496 if (!data)
497 return 0;
498
499 data_error = imxmci_finish_data(host, stat);
500
501 if (host->req->stop && (data_error == MMC_ERR_NONE)) {
502 imxmci_stop_clock(host);
503 imxmci_start_cmd(host, host->req->stop, 0);
504 } else {
505 struct mmc_request *req;
506 req = host->req;
507 if( req ) {
508 imxmci_finish_request(host, req);
509 } else {
510 dev_warn(mmc_dev(host->mmc), "imxmci_data_done: no request to finish\n");
511 }
512 }
513
514 return 1;
515}
516
517static int imxmci_cpu_driven_data(struct imxmci_host *host, unsigned int *pstat)
518{
519 int i;
520 int burst_len;
521 int flush_len;
522 int trans_done = 0;
523 unsigned int stat = *pstat;
524
525 if(host->actual_bus_width == MMC_BUS_WIDTH_4)
526 burst_len = 16;
527 else
528 burst_len = 64;
529
530 /* This is unfortunately required */
531 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data running STATUS = 0x%x\n",
532 stat);
533
534 if(host->dma_dir == DMA_FROM_DEVICE) {
535 imxmci_busy_wait_for_status(host, &stat,
536 STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE,
537 20, "imxmci_cpu_driven_data read");
538
539 while((stat & (STATUS_APPL_BUFF_FF | STATUS_DATA_TRANS_DONE)) &&
540 (host->data_cnt < host->dma_size)) {
541 if(burst_len >= host->dma_size - host->data_cnt) {
542 flush_len = burst_len;
543 burst_len = host->dma_size - host->data_cnt;
544 flush_len -= burst_len;
545 host->data_cnt = host->dma_size;
546 trans_done = 1;
547 } else {
548 flush_len = 0;
549 host->data_cnt += burst_len;
550 }
551
552 for(i = burst_len; i>=2 ; i-=2) {
553 *(host->data_ptr++) = MMC_BUFFER_ACCESS;
554 udelay(20); /* required for clocks < 8MHz*/
555 }
556
557 if(i == 1)
558 *(u8*)(host->data_ptr) = MMC_BUFFER_ACCESS;
559
560 stat = MMC_STATUS;
561
562 /* Flush extra bytes from FIFO */
563 while(flush_len >= 2){
564 flush_len -= 2;
565 i = MMC_BUFFER_ACCESS;
566 stat = MMC_STATUS;
567 stat &= ~STATUS_CRC_READ_ERR; /* Stupid but required there */
568 }
569
570 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data read burst %d STATUS = 0x%x\n",
571 burst_len, stat);
572 }
573 } else {
574 imxmci_busy_wait_for_status(host, &stat,
575 STATUS_APPL_BUFF_FE,
576 20, "imxmci_cpu_driven_data write");
577
578 while((stat & STATUS_APPL_BUFF_FE) &&
579 (host->data_cnt < host->dma_size)) {
580 if(burst_len >= host->dma_size - host->data_cnt) {
581 burst_len = host->dma_size - host->data_cnt;
582 host->data_cnt = host->dma_size;
583 trans_done = 1;
584 } else {
585 host->data_cnt += burst_len;
586 }
587
588 for(i = burst_len; i>0 ; i-=2)
589 MMC_BUFFER_ACCESS = *(host->data_ptr++);
590
591 stat = MMC_STATUS;
592
593 dev_dbg(mmc_dev(host->mmc), "imxmci_cpu_driven_data write burst %d STATUS = 0x%x\n",
594 burst_len, stat);
595 }
596 }
597
598 *pstat = stat;
599
600 return trans_done;
601}
602
603static void imxmci_dma_irq(int dma, void *devid, struct pt_regs *regs)
604{
605 struct imxmci_host *host = devid;
606 uint32_t stat = MMC_STATUS;
607
608 atomic_set(&host->stuck_timeout, 0);
609 host->status_reg = stat;
610 set_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events);
611 tasklet_schedule(&host->tasklet);
612}
613
614static irqreturn_t imxmci_irq(int irq, void *devid, struct pt_regs *regs)
615{
616 struct imxmci_host *host = devid;
617 uint32_t stat = MMC_STATUS;
618 int handled = 1;
619
620 MMC_INT_MASK = host->imask | INT_MASK_SDIO | INT_MASK_AUTO_CARD_DETECT;
621
622 atomic_set(&host->stuck_timeout, 0);
623 host->status_reg = stat;
624 set_bit(IMXMCI_PEND_IRQ_b, &host->pending_events);
625 tasklet_schedule(&host->tasklet);
626
627 return IRQ_RETVAL(handled);;
628}
629
630static void imxmci_tasklet_fnc(unsigned long data)
631{
632 struct imxmci_host *host = (struct imxmci_host *)data;
633 u32 stat;
634 unsigned int data_dir_mask = 0; /* STATUS_WR_CRC_ERROR_CODE_MASK */
635 int timeout = 0;
636
637 if(atomic_read(&host->stuck_timeout) > 4) {
638 char *what;
639 timeout = 1;
640 stat = MMC_STATUS;
641 host->status_reg = stat;
642 if (test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events))
643 if (test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events))
644 what = "RESP+DMA";
645 else
646 what = "RESP";
647 else
648 if (test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events))
649 if(test_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events))
650 what = "DATA";
651 else
652 what = "DMA";
653 else
654 what = "???";
655
656 dev_err(mmc_dev(host->mmc), "%s TIMEOUT, hardware stucked STATUS = 0x%04x IMASK = 0x%04x\n",
657 what, stat, MMC_INT_MASK);
658 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",
659 MMC_CMD_DAT_CONT, MMC_BLK_LEN, MMC_NOB, CCR(host->dma));
660 dev_err(mmc_dev(host->mmc), "CMD%d, bus %d-bit, dma_size = 0x%x\n",
661 host->cmd?host->cmd->opcode:0, 1<<host->actual_bus_width, host->dma_size);
662 }
663
664 if(!host->present || timeout)
665 host->status_reg = STATUS_TIME_OUT_RESP | STATUS_TIME_OUT_READ |
666 STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR;
667
668 if(test_bit(IMXMCI_PEND_IRQ_b, &host->pending_events) || timeout) {
669 clear_bit(IMXMCI_PEND_IRQ_b, &host->pending_events);
670
671 stat = MMC_STATUS;
672 /*
673 * This is not required in theory, but there is chance to miss some flag
674 * which clears automatically by mask write, FreeScale original code keeps
675 * stat from IRQ time so do I
676 */
677 stat |= host->status_reg;
678
679 if(test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) {
680 imxmci_busy_wait_for_status(host, &stat,
681 STATUS_END_CMD_RESP | STATUS_ERR_MASK,
682 20, "imxmci_tasklet_fnc resp (ERRATUM #4)");
683 }
684
685 if(stat & (STATUS_END_CMD_RESP | STATUS_ERR_MASK)) {
686 if(test_and_clear_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events))
687 imxmci_cmd_done(host, stat);
688 if(host->data && (stat & STATUS_ERR_MASK))
689 imxmci_data_done(host, stat);
690 }
691
692 if(test_bit(IMXMCI_PEND_CPU_DATA_b, &host->pending_events)) {
693 stat |= MMC_STATUS;
694 if(imxmci_cpu_driven_data(host, &stat)){
695 if(test_and_clear_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events))
696 imxmci_cmd_done(host, stat);
697 atomic_clear_mask(IMXMCI_PEND_IRQ_m|IMXMCI_PEND_CPU_DATA_m,
698 &host->pending_events);
699 imxmci_data_done(host, stat);
700 }
701 }
702 }
703
704 if(test_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events) &&
705 !test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events)) {
706
707 stat = MMC_STATUS;
708 /* Same as above */
709 stat |= host->status_reg;
710
711 if(host->dma_dir == DMA_TO_DEVICE) {
712 data_dir_mask = STATUS_WRITE_OP_DONE;
713 } else {
714 data_dir_mask = STATUS_DATA_TRANS_DONE;
715 }
716
717 imxmci_busy_wait_for_status(host, &stat,
718 data_dir_mask,
719 50, "imxmci_tasklet_fnc data");
720
721 if(stat & data_dir_mask) {
722 clear_bit(IMXMCI_PEND_DMA_END_b, &host->pending_events);
723 imxmci_data_done(host, stat);
724 }
725 }
726
727 if(test_and_clear_bit(IMXMCI_PEND_CARD_XCHG_b, &host->pending_events)) {
728
729 if(host->cmd)
730 imxmci_cmd_done(host, STATUS_TIME_OUT_RESP);
731
732 if(host->data)
733 imxmci_data_done(host, STATUS_TIME_OUT_READ |
734 STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR);
735
736 if(host->req)
737 imxmci_finish_request(host, host->req);
738
739 mmc_detect_change(host->mmc, msecs_to_jiffies(100));
740
741 }
742}
743
744static void imxmci_request(struct mmc_host *mmc, struct mmc_request *req)
745{
746 struct imxmci_host *host = mmc_priv(mmc);
747 unsigned int cmdat;
748
749 WARN_ON(host->req != NULL);
750
751 host->req = req;
752
753 cmdat = 0;
754
755 if (req->data) {
756 imxmci_setup_data(host, req->data);
757
758 cmdat |= CMD_DAT_CONT_DATA_ENABLE;
759
760 if (req->data->flags & MMC_DATA_WRITE)
761 cmdat |= CMD_DAT_CONT_WRITE;
762
763 if (req->data->flags & MMC_DATA_STREAM) {
764 cmdat |= CMD_DAT_CONT_STREAM_BLOCK;
765 }
766 }
767
768 imxmci_start_cmd(host, req->cmd, cmdat);
769}
770
771#define CLK_RATE 19200000
772
773static void imxmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
774{
775 struct imxmci_host *host = mmc_priv(mmc);
776 int prescaler;
777
778 dev_dbg(mmc_dev(host->mmc), "clock %u power %u vdd %u width %u\n",
779 ios->clock, ios->power_mode, ios->vdd,
780 (ios->bus_width==MMC_BUS_WIDTH_4)?4:1);
781
782 if( ios->bus_width==MMC_BUS_WIDTH_4 ) {
783 host->actual_bus_width = MMC_BUS_WIDTH_4;
784 imx_gpio_mode(PB11_PF_SD_DAT3);
785 }else{
786 host->actual_bus_width = MMC_BUS_WIDTH_1;
787 imx_gpio_mode(GPIO_PORTB | GPIO_IN | GPIO_PUEN | 11);
788 }
789
790 if ( host->power_mode != ios->power_mode ) {
791 switch (ios->power_mode) {
792 case MMC_POWER_OFF:
793 break;
794 case MMC_POWER_UP:
795 set_bit(IMXMCI_PEND_SET_INIT_b, &host->pending_events);
796 break;
797 case MMC_POWER_ON:
798 break;
799 }
800 host->power_mode = ios->power_mode;
801 }
802
803 if ( ios->clock ) {
804 unsigned int clk;
805
806 /* The prescaler is 5 for PERCLK2 equal to 96MHz
807 * then 96MHz / 5 = 19.2 MHz
808 */
809 clk=imx_get_perclk2();
810 prescaler=(clk+(CLK_RATE*7)/8)/CLK_RATE;
811 switch(prescaler) {
812 case 0:
813 case 1: prescaler = 0;
814 break;
815 case 2: prescaler = 1;
816 break;
817 case 3: prescaler = 2;
818 break;
819 case 4: prescaler = 4;
820 break;
821 default:
822 case 5: prescaler = 5;
823 break;
824 }
825
826 dev_dbg(mmc_dev(host->mmc), "PERCLK2 %d MHz -> prescaler %d\n",
827 clk, prescaler);
828
829 for(clk=0; clk<8; clk++) {
830 int x;
831 x = CLK_RATE / (1<<clk);
832 if( x <= ios->clock)
833 break;
834 }
835
836 MMC_STR_STP_CLK |= STR_STP_CLK_ENABLE; /* enable controller */
837
838 imxmci_stop_clock(host);
839 MMC_CLK_RATE = (prescaler<<3) | clk;
840 imxmci_start_clock(host);
841
842 dev_dbg(mmc_dev(host->mmc), "MMC_CLK_RATE: 0x%08x\n", MMC_CLK_RATE);
843 } else {
844 imxmci_stop_clock(host);
845 }
846}
847
848static struct mmc_host_ops imxmci_ops = {
849 .request = imxmci_request,
850 .set_ios = imxmci_set_ios,
851};
852
853static struct resource *platform_device_resource(struct platform_device *dev, unsigned int mask, int nr)
854{
855 int i;
856
857 for (i = 0; i < dev->num_resources; i++)
858 if (dev->resource[i].flags == mask && nr-- == 0)
859 return &dev->resource[i];
860 return NULL;
861}
862
863static int platform_device_irq(struct platform_device *dev, int nr)
864{
865 int i;
866
867 for (i = 0; i < dev->num_resources; i++)
868 if (dev->resource[i].flags == IORESOURCE_IRQ && nr-- == 0)
869 return dev->resource[i].start;
870 return NO_IRQ;
871}
872
873static void imxmci_check_status(unsigned long data)
874{
875 struct imxmci_host *host = (struct imxmci_host *)data;
876
877 if( host->pdata->card_present() != host->present ) {
878 host->present ^= 1;
879 dev_info(mmc_dev(host->mmc), "card %s\n",
880 host->present ? "inserted" : "removed");
881
882 set_bit(IMXMCI_PEND_CARD_XCHG_b, &host->pending_events);
883 tasklet_schedule(&host->tasklet);
884 }
885
886 if(test_bit(IMXMCI_PEND_WAIT_RESP_b, &host->pending_events) ||
887 test_bit(IMXMCI_PEND_DMA_DATA_b, &host->pending_events)) {
888 atomic_inc(&host->stuck_timeout);
889 if(atomic_read(&host->stuck_timeout) > 4)
890 tasklet_schedule(&host->tasklet);
891 } else {
892 atomic_set(&host->stuck_timeout, 0);
893
894 }
895
896 mod_timer(&host->timer, jiffies + (HZ>>1));
897}
898
899static int imxmci_probe(struct platform_device *pdev)
900{
901 struct mmc_host *mmc;
902 struct imxmci_host *host = NULL;
903 struct resource *r;
904 int ret = 0, irq;
905
906 printk(KERN_INFO "i.MX mmc driver\n");
907
908 r = platform_device_resource(pdev, IORESOURCE_MEM, 0);
909 irq = platform_device_irq(pdev, 0);
910 if (!r || irq == NO_IRQ)
911 return -ENXIO;
912
913 r = request_mem_region(r->start, 0x100, "IMXMCI");
914 if (!r)
915 return -EBUSY;
916
917 mmc = mmc_alloc_host(sizeof(struct imxmci_host), &pdev->dev);
918 if (!mmc) {
919 ret = -ENOMEM;
920 goto out;
921 }
922
923 mmc->ops = &imxmci_ops;
924 mmc->f_min = 150000;
925 mmc->f_max = CLK_RATE/2;
926 mmc->ocr_avail = MMC_VDD_32_33;
927 mmc->caps |= MMC_CAP_4_BIT_DATA;
928
929 /* MMC core transfer sizes tunable parameters */
930 mmc->max_hw_segs = 64;
931 mmc->max_phys_segs = 64;
932 mmc->max_sectors = 64; /* default 1 << (PAGE_CACHE_SHIFT - 9) */
933 mmc->max_seg_size = 64*512; /* default PAGE_CACHE_SIZE */
934
935 host = mmc_priv(mmc);
936 host->mmc = mmc;
937 host->dma_allocated = 0;
938 host->pdata = pdev->dev.platform_data;
939
940 spin_lock_init(&host->lock);
941 host->res = r;
942 host->irq = irq;
943
944 imx_gpio_mode(PB8_PF_SD_DAT0);
945 imx_gpio_mode(PB9_PF_SD_DAT1);
946 imx_gpio_mode(PB10_PF_SD_DAT2);
947 /* Configured as GPIO with pull-up to ensure right MCC card mode */
948 /* Switched to PB11_PF_SD_DAT3 if 4 bit bus is configured */
949 imx_gpio_mode(GPIO_PORTB | GPIO_IN | GPIO_PUEN | 11);
950 /* imx_gpio_mode(PB11_PF_SD_DAT3); */
951 imx_gpio_mode(PB12_PF_SD_CLK);
952 imx_gpio_mode(PB13_PF_SD_CMD);
953
954 imxmci_softreset();
955
956 if ( MMC_REV_NO != 0x390 ) {
957 dev_err(mmc_dev(host->mmc), "wrong rev.no. 0x%08x. aborting.\n",
958 MMC_REV_NO);
959 goto out;
960 }
961
962 MMC_READ_TO = 0x2db4; /* recommended in data sheet */
963
964 host->imask = IMXMCI_INT_MASK_DEFAULT;
965 MMC_INT_MASK = host->imask;
966
967
968 if(imx_dma_request_by_prio(&host->dma, DRIVER_NAME, DMA_PRIO_LOW)<0){
969 dev_err(mmc_dev(host->mmc), "imx_dma_request_by_prio failed\n");
970 ret = -EBUSY;
971 goto out;
972 }
973 host->dma_allocated=1;
974 imx_dma_setup_handlers(host->dma, imxmci_dma_irq, NULL, host);
975
976 tasklet_init(&host->tasklet, imxmci_tasklet_fnc, (unsigned long)host);
977 host->status_reg=0;
978 host->pending_events=0;
979
980 ret = request_irq(host->irq, imxmci_irq, 0, DRIVER_NAME, host);
981 if (ret)
982 goto out;
983
984 host->present = host->pdata->card_present();
985 init_timer(&host->timer);
986 host->timer.data = (unsigned long)host;
987 host->timer.function = imxmci_check_status;
988 add_timer(&host->timer);
989 mod_timer(&host->timer, jiffies + (HZ>>1));
990
991 platform_set_drvdata(pdev, mmc);
992
993 mmc_add_host(mmc);
994
995 return 0;
996
997out:
998 if (host) {
999 if(host->dma_allocated){
1000 imx_dma_free(host->dma);
1001 host->dma_allocated=0;
1002 }
1003 }
1004 if (mmc)
1005 mmc_free_host(mmc);
1006 release_resource(r);
1007 return ret;
1008}
1009
1010static int imxmci_remove(struct platform_device *pdev)
1011{
1012 struct mmc_host *mmc = platform_get_drvdata(pdev);
1013
1014 platform_set_drvdata(pdev, NULL);
1015
1016 if (mmc) {
1017 struct imxmci_host *host = mmc_priv(mmc);
1018
1019 tasklet_disable(&host->tasklet);
1020
1021 del_timer_sync(&host->timer);
1022 mmc_remove_host(mmc);
1023
1024 free_irq(host->irq, host);
1025 if(host->dma_allocated){
1026 imx_dma_free(host->dma);
1027 host->dma_allocated=0;
1028 }
1029
1030 tasklet_kill(&host->tasklet);
1031
1032 release_resource(host->res);
1033
1034 mmc_free_host(mmc);
1035 }
1036 return 0;
1037}
1038
1039#ifdef CONFIG_PM
1040static int imxmci_suspend(struct platform_device *dev, pm_message_t state)
1041{
1042 struct mmc_host *mmc = platform_get_drvdata(dev);
1043 int ret = 0;
1044
1045 if (mmc)
1046 ret = mmc_suspend_host(mmc, state);
1047
1048 return ret;
1049}
1050
1051static int imxmci_resume(struct platform_device *dev)
1052{
1053 struct mmc_host *mmc = platform_get_drvdata(dev);
1054 struct imxmci_host *host;
1055 int ret = 0;
1056
1057 if (mmc) {
1058 host = mmc_priv(mmc);
1059 if(host)
1060 set_bit(IMXMCI_PEND_SET_INIT_b, &host->pending_events);
1061 ret = mmc_resume_host(mmc);
1062 }
1063
1064 return ret;
1065}
1066#else
1067#define imxmci_suspend NULL
1068#define imxmci_resume NULL
1069#endif /* CONFIG_PM */
1070
1071static struct platform_driver imxmci_driver = {
1072 .probe = imxmci_probe,
1073 .remove = imxmci_remove,
1074 .suspend = imxmci_suspend,
1075 .resume = imxmci_resume,
1076 .driver = {
1077 .name = DRIVER_NAME,
1078 }
1079};
1080
1081static int __init imxmci_init(void)
1082{
1083 return platform_driver_register(&imxmci_driver);
1084}
1085
1086static void __exit imxmci_exit(void)
1087{
1088 platform_driver_unregister(&imxmci_driver);
1089}
1090
1091module_init(imxmci_init);
1092module_exit(imxmci_exit);
1093
1094MODULE_DESCRIPTION("i.MX Multimedia Card Interface Driver");
1095MODULE_AUTHOR("Sascha Hauer, Pengutronix");
1096MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/imxmmc.h b/drivers/mmc/imxmmc.h
new file mode 100644
index 000000000000..e5339e334dbb
--- /dev/null
+++ b/drivers/mmc/imxmmc.h
@@ -0,0 +1,67 @@
1
2# define __REG16(x) (*((volatile u16 *)IO_ADDRESS(x)))
3
4#define MMC_STR_STP_CLK __REG16(IMX_MMC_BASE + 0x00)
5#define MMC_STATUS __REG16(IMX_MMC_BASE + 0x04)
6#define MMC_CLK_RATE __REG16(IMX_MMC_BASE + 0x08)
7#define MMC_CMD_DAT_CONT __REG16(IMX_MMC_BASE + 0x0C)
8#define MMC_RES_TO __REG16(IMX_MMC_BASE + 0x10)
9#define MMC_READ_TO __REG16(IMX_MMC_BASE + 0x14)
10#define MMC_BLK_LEN __REG16(IMX_MMC_BASE + 0x18)
11#define MMC_NOB __REG16(IMX_MMC_BASE + 0x1C)
12#define MMC_REV_NO __REG16(IMX_MMC_BASE + 0x20)
13#define MMC_INT_MASK __REG16(IMX_MMC_BASE + 0x24)
14#define MMC_CMD __REG16(IMX_MMC_BASE + 0x28)
15#define MMC_ARGH __REG16(IMX_MMC_BASE + 0x2C)
16#define MMC_ARGL __REG16(IMX_MMC_BASE + 0x30)
17#define MMC_RES_FIFO __REG16(IMX_MMC_BASE + 0x34)
18#define MMC_BUFFER_ACCESS __REG16(IMX_MMC_BASE + 0x38)
19#define MMC_BUFFER_ACCESS_OFS 0x38
20
21
22#define STR_STP_CLK_ENDIAN (1<<5)
23#define STR_STP_CLK_RESET (1<<3)
24#define STR_STP_CLK_ENABLE (1<<2)
25#define STR_STP_CLK_START_CLK (1<<1)
26#define STR_STP_CLK_STOP_CLK (1<<0)
27#define STATUS_CARD_PRESENCE (1<<15)
28#define STATUS_SDIO_INT_ACTIVE (1<<14)
29#define STATUS_END_CMD_RESP (1<<13)
30#define STATUS_WRITE_OP_DONE (1<<12)
31#define STATUS_DATA_TRANS_DONE (1<<11)
32#define STATUS_WR_CRC_ERROR_CODE_MASK (3<<10)
33#define STATUS_CARD_BUS_CLK_RUN (1<<8)
34#define STATUS_APPL_BUFF_FF (1<<7)
35#define STATUS_APPL_BUFF_FE (1<<6)
36#define STATUS_RESP_CRC_ERR (1<<5)
37#define STATUS_CRC_READ_ERR (1<<3)
38#define STATUS_CRC_WRITE_ERR (1<<2)
39#define STATUS_TIME_OUT_RESP (1<<1)
40#define STATUS_TIME_OUT_READ (1<<0)
41#define STATUS_ERR_MASK 0x2f
42#define CLK_RATE_PRESCALER(x) ((x) & 0x7)
43#define CLK_RATE_CLK_RATE(x) (((x) & 0x7) << 3)
44#define CMD_DAT_CONT_CMD_RESP_LONG_OFF (1<<12)
45#define CMD_DAT_CONT_STOP_READWAIT (1<<11)
46#define CMD_DAT_CONT_START_READWAIT (1<<10)
47#define CMD_DAT_CONT_BUS_WIDTH_1 (0<<8)
48#define CMD_DAT_CONT_BUS_WIDTH_4 (2<<8)
49#define CMD_DAT_CONT_INIT (1<<7)
50#define CMD_DAT_CONT_BUSY (1<<6)
51#define CMD_DAT_CONT_STREAM_BLOCK (1<<5)
52#define CMD_DAT_CONT_WRITE (1<<4)
53#define CMD_DAT_CONT_DATA_ENABLE (1<<3)
54#define CMD_DAT_CONT_RESPONSE_FORMAT_R1 (1)
55#define CMD_DAT_CONT_RESPONSE_FORMAT_R2 (2)
56#define CMD_DAT_CONT_RESPONSE_FORMAT_R3 (3)
57#define CMD_DAT_CONT_RESPONSE_FORMAT_R4 (4)
58#define CMD_DAT_CONT_RESPONSE_FORMAT_R5 (5)
59#define CMD_DAT_CONT_RESPONSE_FORMAT_R6 (6)
60#define INT_MASK_AUTO_CARD_DETECT (1<<6)
61#define INT_MASK_DAT0_EN (1<<5)
62#define INT_MASK_SDIO (1<<4)
63#define INT_MASK_BUF_READY (1<<3)
64#define INT_MASK_END_CMD_RES (1<<2)
65#define INT_MASK_WRITE_OP_DONE (1<<1)
66#define INT_MASK_DATA_TRAN (1<<0)
67#define INT_ALL (0x7f)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1888060c5e0c..da6ddd910fc5 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -27,12 +27,6 @@
27 27
28#include "mmc.h" 28#include "mmc.h"
29 29
30#ifdef CONFIG_MMC_DEBUG
31#define DBG(x...) printk(KERN_DEBUG x)
32#else
33#define DBG(x...) do { } while (0)
34#endif
35
36#define CMD_RETRIES 3 30#define CMD_RETRIES 3
37 31
38/* 32/*
@@ -77,8 +71,9 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
77{ 71{
78 struct mmc_command *cmd = mrq->cmd; 72 struct mmc_command *cmd = mrq->cmd;
79 int err = mrq->cmd->error; 73 int err = mrq->cmd->error;
80 DBG("MMC: req done (%02x): %d: %08x %08x %08x %08x\n", cmd->opcode, 74 pr_debug("MMC: req done (%02x): %d: %08x %08x %08x %08x\n",
81 err, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); 75 cmd->opcode, err, cmd->resp[0], cmd->resp[1],
76 cmd->resp[2], cmd->resp[3]);
82 77
83 if (err && cmd->retries) { 78 if (err && cmd->retries) {
84 cmd->retries--; 79 cmd->retries--;
@@ -102,8 +97,8 @@ EXPORT_SYMBOL(mmc_request_done);
102void 97void
103mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) 98mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
104{ 99{
105 DBG("MMC: starting cmd %02x arg %08x flags %08x\n", 100 pr_debug("MMC: starting cmd %02x arg %08x flags %08x\n",
106 mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags); 101 mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags);
107 102
108 WARN_ON(host->card_busy == NULL); 103 WARN_ON(host->card_busy == NULL);
109 104
@@ -976,8 +971,8 @@ static unsigned int mmc_calculate_clock(struct mmc_host *host)
976 if (!mmc_card_dead(card) && max_dtr > card->csd.max_dtr) 971 if (!mmc_card_dead(card) && max_dtr > card->csd.max_dtr)
977 max_dtr = card->csd.max_dtr; 972 max_dtr = card->csd.max_dtr;
978 973
979 DBG("MMC: selected %d.%03dMHz transfer rate\n", 974 pr_debug("MMC: selected %d.%03dMHz transfer rate\n",
980 max_dtr / 1000000, (max_dtr / 1000) % 1000); 975 max_dtr / 1000000, (max_dtr / 1000) % 1000);
981 976
982 return max_dtr; 977 return max_dtr;
983} 978}
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c
index 9fef29d978b5..df7e861e2fc7 100644
--- a/drivers/mmc/mmci.c
+++ b/drivers/mmc/mmci.c
@@ -33,12 +33,8 @@
33 33
34#define DRIVER_NAME "mmci-pl18x" 34#define DRIVER_NAME "mmci-pl18x"
35 35
36#ifdef CONFIG_MMC_DEBUG
37#define DBG(host,fmt,args...) \ 36#define DBG(host,fmt,args...) \
38 pr_debug("%s: %s: " fmt, mmc_hostname(host->mmc), __func__ , args) 37 pr_debug("%s: %s: " fmt, mmc_hostname(host->mmc), __func__ , args)
39#else
40#define DBG(host,fmt,args...) do { } while (0)
41#endif
42 38
43static unsigned int fmax = 515633; 39static unsigned int fmax = 515633;
44 40
diff --git a/drivers/mmc/omap.c b/drivers/mmc/omap.c
new file mode 100644
index 000000000000..becb3c68c34d
--- /dev/null
+++ b/drivers/mmc/omap.c
@@ -0,0 +1,1226 @@
1/*
2 * linux/drivers/media/mmc/omap.c
3 *
4 * Copyright (C) 2004 Nokia Corporation
5 * Written by Tuukka Tikkanen and Juha Yrjölä<juha.yrjola@nokia.com>
6 * Misc hacks here and there by Tony Lindgren <tony@atomide.com>
7 * Other hacks (DMA, SD, etc) by David Brownell
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/config.h>
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/ioport.h>
19#include <linux/platform_device.h>
20#include <linux/interrupt.h>
21#include <linux/dma-mapping.h>
22#include <linux/delay.h>
23#include <linux/spinlock.h>
24#include <linux/timer.h>
25#include <linux/mmc/host.h>
26#include <linux/mmc/protocol.h>
27#include <linux/mmc/card.h>
28#include <linux/clk.h>
29
30#include <asm/io.h>
31#include <asm/irq.h>
32#include <asm/scatterlist.h>
33#include <asm/mach-types.h>
34
35#include <asm/arch/board.h>
36#include <asm/arch/gpio.h>
37#include <asm/arch/dma.h>
38#include <asm/arch/mux.h>
39#include <asm/arch/fpga.h>
40#include <asm/arch/tps65010.h>
41
42#include "omap.h"
43
44#define DRIVER_NAME "mmci-omap"
45#define RSP_TYPE(x) ((x) & ~(MMC_RSP_BUSY|MMC_RSP_OPCODE))
46
47/* Specifies how often in millisecs to poll for card status changes
48 * when the cover switch is open */
49#define OMAP_MMC_SWITCH_POLL_DELAY 500
50
51static int mmc_omap_enable_poll = 1;
52
53struct mmc_omap_host {
54 int initialized;
55 int suspended;
56 struct mmc_request * mrq;
57 struct mmc_command * cmd;
58 struct mmc_data * data;
59 struct mmc_host * mmc;
60 struct device * dev;
61 unsigned char id; /* 16xx chips have 2 MMC blocks */
62 struct clk * iclk;
63 struct clk * fclk;
64 void __iomem *base;
65 int irq;
66 unsigned char bus_mode;
67 unsigned char hw_bus_mode;
68
69 unsigned int sg_len;
70 int sg_idx;
71 u16 * buffer;
72 u32 buffer_bytes_left;
73 u32 total_bytes_left;
74
75 unsigned use_dma:1;
76 unsigned brs_received:1, dma_done:1;
77 unsigned dma_is_read:1;
78 unsigned dma_in_use:1;
79 int dma_ch;
80 spinlock_t dma_lock;
81 struct timer_list dma_timer;
82 unsigned dma_len;
83
84 short power_pin;
85 short wp_pin;
86
87 int switch_pin;
88 struct work_struct switch_work;
89 struct timer_list switch_timer;
90 int switch_last_state;
91};
92
93static inline int
94mmc_omap_cover_is_open(struct mmc_omap_host *host)
95{
96 if (host->switch_pin < 0)
97 return 0;
98 return omap_get_gpio_datain(host->switch_pin);
99}
100
101static ssize_t
102mmc_omap_show_cover_switch(struct device *dev,
103 struct device_attribute *attr, char *buf)
104{
105 struct mmc_omap_host *host = dev_get_drvdata(dev);
106
107 return sprintf(buf, "%s\n", mmc_omap_cover_is_open(host) ? "open" :
108 "closed");
109}
110
111static DEVICE_ATTR(cover_switch, S_IRUGO, mmc_omap_show_cover_switch, NULL);
112
113static ssize_t
114mmc_omap_show_enable_poll(struct device *dev,
115 struct device_attribute *attr, char *buf)
116{
117 return snprintf(buf, PAGE_SIZE, "%d\n", mmc_omap_enable_poll);
118}
119
120static ssize_t
121mmc_omap_store_enable_poll(struct device *dev,
122 struct device_attribute *attr, const char *buf,
123 size_t size)
124{
125 int enable_poll;
126
127 if (sscanf(buf, "%10d", &enable_poll) != 1)
128 return -EINVAL;
129
130 if (enable_poll != mmc_omap_enable_poll) {
131 struct mmc_omap_host *host = dev_get_drvdata(dev);
132
133 mmc_omap_enable_poll = enable_poll;
134 if (enable_poll && host->switch_pin >= 0)
135 schedule_work(&host->switch_work);
136 }
137 return size;
138}
139
140static DEVICE_ATTR(enable_poll, 0664,
141 mmc_omap_show_enable_poll, mmc_omap_store_enable_poll);
142
143static void
144mmc_omap_start_command(struct mmc_omap_host *host, struct mmc_command *cmd)
145{
146 u32 cmdreg;
147 u32 resptype;
148 u32 cmdtype;
149
150 host->cmd = cmd;
151
152 resptype = 0;
153 cmdtype = 0;
154
155 /* Our hardware needs to know exact type */
156 switch (RSP_TYPE(mmc_resp_type(cmd))) {
157 case RSP_TYPE(MMC_RSP_R1):
158 /* resp 1, resp 1b */
159 resptype = 1;
160 break;
161 case RSP_TYPE(MMC_RSP_R2):
162 resptype = 2;
163 break;
164 case RSP_TYPE(MMC_RSP_R3):
165 resptype = 3;
166 break;
167 default:
168 break;
169 }
170
171 if (mmc_cmd_type(cmd) == MMC_CMD_ADTC) {
172 cmdtype = OMAP_MMC_CMDTYPE_ADTC;
173 } else if (mmc_cmd_type(cmd) == MMC_CMD_BC) {
174 cmdtype = OMAP_MMC_CMDTYPE_BC;
175 } else if (mmc_cmd_type(cmd) == MMC_CMD_BCR) {
176 cmdtype = OMAP_MMC_CMDTYPE_BCR;
177 } else {
178 cmdtype = OMAP_MMC_CMDTYPE_AC;
179 }
180
181 cmdreg = cmd->opcode | (resptype << 8) | (cmdtype << 12);
182
183 if (host->bus_mode == MMC_BUSMODE_OPENDRAIN)
184 cmdreg |= 1 << 6;
185
186 if (cmd->flags & MMC_RSP_BUSY)
187 cmdreg |= 1 << 11;
188
189 if (host->data && !(host->data->flags & MMC_DATA_WRITE))
190 cmdreg |= 1 << 15;
191
192 clk_enable(host->fclk);
193
194 OMAP_MMC_WRITE(host->base, CTO, 200);
195 OMAP_MMC_WRITE(host->base, ARGL, cmd->arg & 0xffff);
196 OMAP_MMC_WRITE(host->base, ARGH, cmd->arg >> 16);
197 OMAP_MMC_WRITE(host->base, IE,
198 OMAP_MMC_STAT_A_EMPTY | OMAP_MMC_STAT_A_FULL |
199 OMAP_MMC_STAT_CMD_CRC | OMAP_MMC_STAT_CMD_TOUT |
200 OMAP_MMC_STAT_DATA_CRC | OMAP_MMC_STAT_DATA_TOUT |
201 OMAP_MMC_STAT_END_OF_CMD | OMAP_MMC_STAT_CARD_ERR |
202 OMAP_MMC_STAT_END_OF_DATA);
203 OMAP_MMC_WRITE(host->base, CMD, cmdreg);
204}
205
206static void
207mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data)
208{
209 if (host->dma_in_use) {
210 enum dma_data_direction dma_data_dir;
211
212 BUG_ON(host->dma_ch < 0);
213 if (data->error != MMC_ERR_NONE)
214 omap_stop_dma(host->dma_ch);
215 /* Release DMA channel lazily */
216 mod_timer(&host->dma_timer, jiffies + HZ);
217 if (data->flags & MMC_DATA_WRITE)
218 dma_data_dir = DMA_TO_DEVICE;
219 else
220 dma_data_dir = DMA_FROM_DEVICE;
221 dma_unmap_sg(mmc_dev(host->mmc), data->sg, host->sg_len,
222 dma_data_dir);
223 }
224 host->data = NULL;
225 host->sg_len = 0;
226 clk_disable(host->fclk);
227
228 /* NOTE: MMC layer will sometimes poll-wait CMD13 next, issuing
229 * dozens of requests until the card finishes writing data.
230 * It'd be cheaper to just wait till an EOFB interrupt arrives...
231 */
232
233 if (!data->stop) {
234 host->mrq = NULL;
235 mmc_request_done(host->mmc, data->mrq);
236 return;
237 }
238
239 mmc_omap_start_command(host, data->stop);
240}
241
242static void
243mmc_omap_end_of_data(struct mmc_omap_host *host, struct mmc_data *data)
244{
245 unsigned long flags;
246 int done;
247
248 if (!host->dma_in_use) {
249 mmc_omap_xfer_done(host, data);
250 return;
251 }
252 done = 0;
253 spin_lock_irqsave(&host->dma_lock, flags);
254 if (host->dma_done)
255 done = 1;
256 else
257 host->brs_received = 1;
258 spin_unlock_irqrestore(&host->dma_lock, flags);
259 if (done)
260 mmc_omap_xfer_done(host, data);
261}
262
263static void
264mmc_omap_dma_timer(unsigned long data)
265{
266 struct mmc_omap_host *host = (struct mmc_omap_host *) data;
267
268 BUG_ON(host->dma_ch < 0);
269 omap_free_dma(host->dma_ch);
270 host->dma_ch = -1;
271}
272
273static void
274mmc_omap_dma_done(struct mmc_omap_host *host, struct mmc_data *data)
275{
276 unsigned long flags;
277 int done;
278
279 done = 0;
280 spin_lock_irqsave(&host->dma_lock, flags);
281 if (host->brs_received)
282 done = 1;
283 else
284 host->dma_done = 1;
285 spin_unlock_irqrestore(&host->dma_lock, flags);
286 if (done)
287 mmc_omap_xfer_done(host, data);
288}
289
290static void
291mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
292{
293 host->cmd = NULL;
294
295 if (cmd->flags & MMC_RSP_PRESENT) {
296 if (cmd->flags & MMC_RSP_136) {
297 /* response type 2 */
298 cmd->resp[3] =
299 OMAP_MMC_READ(host->base, RSP0) |
300 (OMAP_MMC_READ(host->base, RSP1) << 16);
301 cmd->resp[2] =
302 OMAP_MMC_READ(host->base, RSP2) |
303 (OMAP_MMC_READ(host->base, RSP3) << 16);
304 cmd->resp[1] =
305 OMAP_MMC_READ(host->base, RSP4) |
306 (OMAP_MMC_READ(host->base, RSP5) << 16);
307 cmd->resp[0] =
308 OMAP_MMC_READ(host->base, RSP6) |
309 (OMAP_MMC_READ(host->base, RSP7) << 16);
310 } else {
311 /* response types 1, 1b, 3, 4, 5, 6 */
312 cmd->resp[0] =
313 OMAP_MMC_READ(host->base, RSP6) |
314 (OMAP_MMC_READ(host->base, RSP7) << 16);
315 }
316 }
317
318 if (host->data == NULL || cmd->error != MMC_ERR_NONE) {
319 host->mrq = NULL;
320 clk_disable(host->fclk);
321 mmc_request_done(host->mmc, cmd->mrq);
322 }
323}
324
325/* PIO only */
326static void
327mmc_omap_sg_to_buf(struct mmc_omap_host *host)
328{
329 struct scatterlist *sg;
330
331 sg = host->data->sg + host->sg_idx;
332 host->buffer_bytes_left = sg->length;
333 host->buffer = page_address(sg->page) + sg->offset;
334 if (host->buffer_bytes_left > host->total_bytes_left)
335 host->buffer_bytes_left = host->total_bytes_left;
336}
337
338/* PIO only */
339static void
340mmc_omap_xfer_data(struct mmc_omap_host *host, int write)
341{
342 int n;
343 void __iomem *reg;
344 u16 *p;
345
346 if (host->buffer_bytes_left == 0) {
347 host->sg_idx++;
348 BUG_ON(host->sg_idx == host->sg_len);
349 mmc_omap_sg_to_buf(host);
350 }
351 n = 64;
352 if (n > host->buffer_bytes_left)
353 n = host->buffer_bytes_left;
354 host->buffer_bytes_left -= n;
355 host->total_bytes_left -= n;
356 host->data->bytes_xfered += n;
357
358 if (write) {
359 __raw_writesw(host->base + OMAP_MMC_REG_DATA, host->buffer, n);
360 } else {
361 __raw_readsw(host->base + OMAP_MMC_REG_DATA, host->buffer, n);
362 }
363}
364
365static inline void mmc_omap_report_irq(u16 status)
366{
367 static const char *mmc_omap_status_bits[] = {
368 "EOC", "CD", "CB", "BRS", "EOFB", "DTO", "DCRC", "CTO",
369 "CCRC", "CRW", "AF", "AE", "OCRB", "CIRQ", "CERR"
370 };
371 int i, c = 0;
372
373 for (i = 0; i < ARRAY_SIZE(mmc_omap_status_bits); i++)
374 if (status & (1 << i)) {
375 if (c)
376 printk(" ");
377 printk("%s", mmc_omap_status_bits[i]);
378 c++;
379 }
380}
381
382static irqreturn_t mmc_omap_irq(int irq, void *dev_id, struct pt_regs *regs)
383{
384 struct mmc_omap_host * host = (struct mmc_omap_host *)dev_id;
385 u16 status;
386 int end_command;
387 int end_transfer;
388 int transfer_error;
389
390 if (host->cmd == NULL && host->data == NULL) {
391 status = OMAP_MMC_READ(host->base, STAT);
392 dev_info(mmc_dev(host->mmc),"spurious irq 0x%04x\n", status);
393 if (status != 0) {
394 OMAP_MMC_WRITE(host->base, STAT, status);
395 OMAP_MMC_WRITE(host->base, IE, 0);
396 }
397 return IRQ_HANDLED;
398 }
399
400 end_command = 0;
401 end_transfer = 0;
402 transfer_error = 0;
403
404 while ((status = OMAP_MMC_READ(host->base, STAT)) != 0) {
405 OMAP_MMC_WRITE(host->base, STAT, status);
406#ifdef CONFIG_MMC_DEBUG
407 dev_dbg(mmc_dev(host->mmc), "MMC IRQ %04x (CMD %d): ",
408 status, host->cmd != NULL ? host->cmd->opcode : -1);
409 mmc_omap_report_irq(status);
410 printk("\n");
411#endif
412 if (host->total_bytes_left) {
413 if ((status & OMAP_MMC_STAT_A_FULL) ||
414 (status & OMAP_MMC_STAT_END_OF_DATA))
415 mmc_omap_xfer_data(host, 0);
416 if (status & OMAP_MMC_STAT_A_EMPTY)
417 mmc_omap_xfer_data(host, 1);
418 }
419
420 if (status & OMAP_MMC_STAT_END_OF_DATA) {
421 end_transfer = 1;
422 }
423
424 if (status & OMAP_MMC_STAT_DATA_TOUT) {
425 dev_dbg(mmc_dev(host->mmc), "data timeout\n");
426 if (host->data) {
427 host->data->error |= MMC_ERR_TIMEOUT;
428 transfer_error = 1;
429 }
430 }
431
432 if (status & OMAP_MMC_STAT_DATA_CRC) {
433 if (host->data) {
434 host->data->error |= MMC_ERR_BADCRC;
435 dev_dbg(mmc_dev(host->mmc),
436 "data CRC error, bytes left %d\n",
437 host->total_bytes_left);
438 transfer_error = 1;
439 } else {
440 dev_dbg(mmc_dev(host->mmc), "data CRC error\n");
441 }
442 }
443
444 if (status & OMAP_MMC_STAT_CMD_TOUT) {
445 /* Timeouts are routine with some commands */
446 if (host->cmd) {
447 if (host->cmd->opcode != MMC_ALL_SEND_CID &&
448 host->cmd->opcode !=
449 MMC_SEND_OP_COND &&
450 host->cmd->opcode !=
451 MMC_APP_CMD &&
452 !mmc_omap_cover_is_open(host))
453 dev_err(mmc_dev(host->mmc),
454 "command timeout, CMD %d\n",
455 host->cmd->opcode);
456 host->cmd->error = MMC_ERR_TIMEOUT;
457 end_command = 1;
458 }
459 }
460
461 if (status & OMAP_MMC_STAT_CMD_CRC) {
462 if (host->cmd) {
463 dev_err(mmc_dev(host->mmc),
464 "command CRC error (CMD%d, arg 0x%08x)\n",
465 host->cmd->opcode, host->cmd->arg);
466 host->cmd->error = MMC_ERR_BADCRC;
467 end_command = 1;
468 } else
469 dev_err(mmc_dev(host->mmc),
470 "command CRC error without cmd?\n");
471 }
472
473 if (status & OMAP_MMC_STAT_CARD_ERR) {
474 if (host->cmd && host->cmd->opcode == MMC_STOP_TRANSMISSION) {
475 u32 response = OMAP_MMC_READ(host->base, RSP6)
476 | (OMAP_MMC_READ(host->base, RSP7) << 16);
477 /* STOP sometimes sets must-ignore bits */
478 if (!(response & (R1_CC_ERROR
479 | R1_ILLEGAL_COMMAND
480 | R1_COM_CRC_ERROR))) {
481 end_command = 1;
482 continue;
483 }
484 }
485
486 dev_dbg(mmc_dev(host->mmc), "card status error (CMD%d)\n",
487 host->cmd->opcode);
488 if (host->cmd) {
489 host->cmd->error = MMC_ERR_FAILED;
490 end_command = 1;
491 }
492 if (host->data) {
493 host->data->error = MMC_ERR_FAILED;
494 transfer_error = 1;
495 }
496 }
497
498 /*
499 * NOTE: On 1610 the END_OF_CMD may come too early when
500 * starting a write
501 */
502 if ((status & OMAP_MMC_STAT_END_OF_CMD) &&
503 (!(status & OMAP_MMC_STAT_A_EMPTY))) {
504 end_command = 1;
505 }
506 }
507
508 if (end_command) {
509 mmc_omap_cmd_done(host, host->cmd);
510 }
511 if (transfer_error)
512 mmc_omap_xfer_done(host, host->data);
513 else if (end_transfer)
514 mmc_omap_end_of_data(host, host->data);
515
516 return IRQ_HANDLED;
517}
518
519static irqreturn_t mmc_omap_switch_irq(int irq, void *dev_id, struct pt_regs *regs)
520{
521 struct mmc_omap_host *host = (struct mmc_omap_host *) dev_id;
522
523 schedule_work(&host->switch_work);
524
525 return IRQ_HANDLED;
526}
527
528static void mmc_omap_switch_timer(unsigned long arg)
529{
530 struct mmc_omap_host *host = (struct mmc_omap_host *) arg;
531
532 schedule_work(&host->switch_work);
533}
534
535/* FIXME: Handle card insertion and removal properly. Maybe use a mask
536 * for MMC state? */
537static void mmc_omap_switch_callback(unsigned long data, u8 mmc_mask)
538{
539}
540
541static void mmc_omap_switch_handler(void *data)
542{
543 struct mmc_omap_host *host = (struct mmc_omap_host *) data;
544 struct mmc_card *card;
545 static int complained = 0;
546 int cards = 0, cover_open;
547
548 if (host->switch_pin == -1)
549 return;
550 cover_open = mmc_omap_cover_is_open(host);
551 if (cover_open != host->switch_last_state) {
552 kobject_uevent(&host->dev->kobj, KOBJ_CHANGE);
553 host->switch_last_state = cover_open;
554 }
555 mmc_detect_change(host->mmc, 0);
556 list_for_each_entry(card, &host->mmc->cards, node) {
557 if (mmc_card_present(card))
558 cards++;
559 }
560 if (mmc_omap_cover_is_open(host)) {
561 if (!complained) {
562 dev_info(mmc_dev(host->mmc), "cover is open");
563 complained = 1;
564 }
565 if (mmc_omap_enable_poll)
566 mod_timer(&host->switch_timer, jiffies +
567 msecs_to_jiffies(OMAP_MMC_SWITCH_POLL_DELAY));
568 } else {
569 complained = 0;
570 }
571}
572
573/* Prepare to transfer the next segment of a scatterlist */
574static void
575mmc_omap_prepare_dma(struct mmc_omap_host *host, struct mmc_data *data)
576{
577 int dma_ch = host->dma_ch;
578 unsigned long data_addr;
579 u16 buf, frame;
580 u32 count;
581 struct scatterlist *sg = &data->sg[host->sg_idx];
582 int src_port = 0;
583 int dst_port = 0;
584 int sync_dev = 0;
585
586 data_addr = io_v2p((u32) host->base) + OMAP_MMC_REG_DATA;
587 frame = 1 << data->blksz_bits;
588 count = sg_dma_len(sg);
589
590 if ((data->blocks == 1) && (count > (1 << data->blksz_bits)))
591 count = frame;
592
593 host->dma_len = count;
594
595 /* FIFO is 16x2 bytes on 15xx, and 32x2 bytes on 16xx and 24xx.
596 * Use 16 or 32 word frames when the blocksize is at least that large.
597 * Blocksize is usually 512 bytes; but not for some SD reads.
598 */
599 if (cpu_is_omap15xx() && frame > 32)
600 frame = 32;
601 else if (frame > 64)
602 frame = 64;
603 count /= frame;
604 frame >>= 1;
605
606 if (!(data->flags & MMC_DATA_WRITE)) {
607 buf = 0x800f | ((frame - 1) << 8);
608
609 if (cpu_class_is_omap1()) {
610 src_port = OMAP_DMA_PORT_TIPB;
611 dst_port = OMAP_DMA_PORT_EMIFF;
612 }
613 if (cpu_is_omap24xx())
614 sync_dev = OMAP24XX_DMA_MMC1_RX;
615
616 omap_set_dma_src_params(dma_ch, src_port,
617 OMAP_DMA_AMODE_CONSTANT,
618 data_addr, 0, 0);
619 omap_set_dma_dest_params(dma_ch, dst_port,
620 OMAP_DMA_AMODE_POST_INC,
621 sg_dma_address(sg), 0, 0);
622 omap_set_dma_dest_data_pack(dma_ch, 1);
623 omap_set_dma_dest_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4);
624 } else {
625 buf = 0x0f80 | ((frame - 1) << 0);
626
627 if (cpu_class_is_omap1()) {
628 src_port = OMAP_DMA_PORT_EMIFF;
629 dst_port = OMAP_DMA_PORT_TIPB;
630 }
631 if (cpu_is_omap24xx())
632 sync_dev = OMAP24XX_DMA_MMC1_TX;
633
634 omap_set_dma_dest_params(dma_ch, dst_port,
635 OMAP_DMA_AMODE_CONSTANT,
636 data_addr, 0, 0);
637 omap_set_dma_src_params(dma_ch, src_port,
638 OMAP_DMA_AMODE_POST_INC,
639 sg_dma_address(sg), 0, 0);
640 omap_set_dma_src_data_pack(dma_ch, 1);
641 omap_set_dma_src_burst_mode(dma_ch, OMAP_DMA_DATA_BURST_4);
642 }
643
644 /* Max limit for DMA frame count is 0xffff */
645 if (unlikely(count > 0xffff))
646 BUG();
647
648 OMAP_MMC_WRITE(host->base, BUF, buf);
649 omap_set_dma_transfer_params(dma_ch, OMAP_DMA_DATA_TYPE_S16,
650 frame, count, OMAP_DMA_SYNC_FRAME,
651 sync_dev, 0);
652}
653
654/* A scatterlist segment completed */
655static void mmc_omap_dma_cb(int lch, u16 ch_status, void *data)
656{
657 struct mmc_omap_host *host = (struct mmc_omap_host *) data;
658 struct mmc_data *mmcdat = host->data;
659
660 if (unlikely(host->dma_ch < 0)) {
661 dev_err(mmc_dev(host->mmc), "DMA callback while DMA not
662 enabled\n");
663 return;
664 }
665 /* FIXME: We really should do something to _handle_ the errors */
666 if (ch_status & OMAP_DMA_TOUT_IRQ) {
667 dev_err(mmc_dev(host->mmc),"DMA timeout\n");
668 return;
669 }
670 if (ch_status & OMAP_DMA_DROP_IRQ) {
671 dev_err(mmc_dev(host->mmc), "DMA sync error\n");
672 return;
673 }
674 if (!(ch_status & OMAP_DMA_BLOCK_IRQ)) {
675 return;
676 }
677 mmcdat->bytes_xfered += host->dma_len;
678 host->sg_idx++;
679 if (host->sg_idx < host->sg_len) {
680 mmc_omap_prepare_dma(host, host->data);
681 omap_start_dma(host->dma_ch);
682 } else
683 mmc_omap_dma_done(host, host->data);
684}
685
686static int mmc_omap_get_dma_channel(struct mmc_omap_host *host, struct mmc_data *data)
687{
688 const char *dev_name;
689 int sync_dev, dma_ch, is_read, r;
690
691 is_read = !(data->flags & MMC_DATA_WRITE);
692 del_timer_sync(&host->dma_timer);
693 if (host->dma_ch >= 0) {
694 if (is_read == host->dma_is_read)
695 return 0;
696 omap_free_dma(host->dma_ch);
697 host->dma_ch = -1;
698 }
699
700 if (is_read) {
701 if (host->id == 1) {
702 sync_dev = OMAP_DMA_MMC_RX;
703 dev_name = "MMC1 read";
704 } else {
705 sync_dev = OMAP_DMA_MMC2_RX;
706 dev_name = "MMC2 read";
707 }
708 } else {
709 if (host->id == 1) {
710 sync_dev = OMAP_DMA_MMC_TX;
711 dev_name = "MMC1 write";
712 } else {
713 sync_dev = OMAP_DMA_MMC2_TX;
714 dev_name = "MMC2 write";
715 }
716 }
717 r = omap_request_dma(sync_dev, dev_name, mmc_omap_dma_cb,
718 host, &dma_ch);
719 if (r != 0) {
720 dev_dbg(mmc_dev(host->mmc), "omap_request_dma() failed with %d\n", r);
721 return r;
722 }
723 host->dma_ch = dma_ch;
724 host->dma_is_read = is_read;
725
726 return 0;
727}
728
729static inline void set_cmd_timeout(struct mmc_omap_host *host, struct mmc_request *req)
730{
731 u16 reg;
732
733 reg = OMAP_MMC_READ(host->base, SDIO);
734 reg &= ~(1 << 5);
735 OMAP_MMC_WRITE(host->base, SDIO, reg);
736 /* Set maximum timeout */
737 OMAP_MMC_WRITE(host->base, CTO, 0xff);
738}
739
740static inline void set_data_timeout(struct mmc_omap_host *host, struct mmc_request *req)
741{
742 int timeout;
743 u16 reg;
744
745 /* Convert ns to clock cycles by assuming 20MHz frequency
746 * 1 cycle at 20MHz = 500 ns
747 */
748 timeout = req->data->timeout_clks + req->data->timeout_ns / 500;
749
750 /* Check if we need to use timeout multiplier register */
751 reg = OMAP_MMC_READ(host->base, SDIO);
752 if (timeout > 0xffff) {
753 reg |= (1 << 5);
754 timeout /= 1024;
755 } else
756 reg &= ~(1 << 5);
757 OMAP_MMC_WRITE(host->base, SDIO, reg);
758 OMAP_MMC_WRITE(host->base, DTO, timeout);
759}
760
761static void
762mmc_omap_prepare_data(struct mmc_omap_host *host, struct mmc_request *req)
763{
764 struct mmc_data *data = req->data;
765 int i, use_dma, block_size;
766 unsigned sg_len;
767
768 host->data = data;
769 if (data == NULL) {
770 OMAP_MMC_WRITE(host->base, BLEN, 0);
771 OMAP_MMC_WRITE(host->base, NBLK, 0);
772 OMAP_MMC_WRITE(host->base, BUF, 0);
773 host->dma_in_use = 0;
774 set_cmd_timeout(host, req);
775 return;
776 }
777
778
779 block_size = 1 << data->blksz_bits;
780
781 OMAP_MMC_WRITE(host->base, NBLK, data->blocks - 1);
782 OMAP_MMC_WRITE(host->base, BLEN, block_size - 1);
783 set_data_timeout(host, req);
784
785 /* cope with calling layer confusion; it issues "single
786 * block" writes using multi-block scatterlists.
787 */
788 sg_len = (data->blocks == 1) ? 1 : data->sg_len;
789
790 /* Only do DMA for entire blocks */
791 use_dma = host->use_dma;
792 if (use_dma) {
793 for (i = 0; i < sg_len; i++) {
794 if ((data->sg[i].length % block_size) != 0) {
795 use_dma = 0;
796 break;
797 }
798 }
799 }
800
801 host->sg_idx = 0;
802 if (use_dma) {
803 if (mmc_omap_get_dma_channel(host, data) == 0) {
804 enum dma_data_direction dma_data_dir;
805
806 if (data->flags & MMC_DATA_WRITE)
807 dma_data_dir = DMA_TO_DEVICE;
808 else
809 dma_data_dir = DMA_FROM_DEVICE;
810
811 host->sg_len = dma_map_sg(mmc_dev(host->mmc), data->sg,
812 sg_len, dma_data_dir);
813 host->total_bytes_left = 0;
814 mmc_omap_prepare_dma(host, req->data);
815 host->brs_received = 0;
816 host->dma_done = 0;
817 host->dma_in_use = 1;
818 } else
819 use_dma = 0;
820 }
821
822 /* Revert to PIO? */
823 if (!use_dma) {
824 OMAP_MMC_WRITE(host->base, BUF, 0x1f1f);
825 host->total_bytes_left = data->blocks * block_size;
826 host->sg_len = sg_len;
827 mmc_omap_sg_to_buf(host);
828 host->dma_in_use = 0;
829 }
830}
831
832static void mmc_omap_request(struct mmc_host *mmc, struct mmc_request *req)
833{
834 struct mmc_omap_host *host = mmc_priv(mmc);
835
836 WARN_ON(host->mrq != NULL);
837
838 host->mrq = req;
839
840 /* only touch fifo AFTER the controller readies it */
841 mmc_omap_prepare_data(host, req);
842 mmc_omap_start_command(host, req->cmd);
843 if (host->dma_in_use)
844 omap_start_dma(host->dma_ch);
845}
846
847static void innovator_fpga_socket_power(int on)
848{
849#if defined(CONFIG_MACH_OMAP_INNOVATOR) && defined(CONFIG_ARCH_OMAP15XX)
850
851 if (on) {
852 fpga_write(fpga_read(OMAP1510_FPGA_POWER) | (1 << 3),
853 OMAP1510_FPGA_POWER);
854 } else {
855 fpga_write(fpga_read(OMAP1510_FPGA_POWER) & ~(1 << 3),
856 OMAP1510_FPGA_POWER);
857 }
858#endif
859}
860
861/*
862 * Turn the socket power on/off. Innovator uses FPGA, most boards
863 * probably use GPIO.
864 */
865static void mmc_omap_power(struct mmc_omap_host *host, int on)
866{
867 if (on) {
868 if (machine_is_omap_innovator())
869 innovator_fpga_socket_power(1);
870 else if (machine_is_omap_h2())
871 tps65010_set_gpio_out_value(GPIO3, HIGH);
872 else if (machine_is_omap_h3())
873 /* GPIO 4 of TPS65010 sends SD_EN signal */
874 tps65010_set_gpio_out_value(GPIO4, HIGH);
875 else if (cpu_is_omap24xx()) {
876 u16 reg = OMAP_MMC_READ(host->base, CON);
877 OMAP_MMC_WRITE(host->base, CON, reg | (1 << 11));
878 } else
879 if (host->power_pin >= 0)
880 omap_set_gpio_dataout(host->power_pin, 1);
881 } else {
882 if (machine_is_omap_innovator())
883 innovator_fpga_socket_power(0);
884 else if (machine_is_omap_h2())
885 tps65010_set_gpio_out_value(GPIO3, LOW);
886 else if (machine_is_omap_h3())
887 tps65010_set_gpio_out_value(GPIO4, LOW);
888 else if (cpu_is_omap24xx()) {
889 u16 reg = OMAP_MMC_READ(host->base, CON);
890 OMAP_MMC_WRITE(host->base, CON, reg & ~(1 << 11));
891 } else
892 if (host->power_pin >= 0)
893 omap_set_gpio_dataout(host->power_pin, 0);
894 }
895}
896
897static void mmc_omap_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
898{
899 struct mmc_omap_host *host = mmc_priv(mmc);
900 int dsor;
901 int realclock, i;
902
903 realclock = ios->clock;
904
905 if (ios->clock == 0)
906 dsor = 0;
907 else {
908 int func_clk_rate = clk_get_rate(host->fclk);
909
910 dsor = func_clk_rate / realclock;
911 if (dsor < 1)
912 dsor = 1;
913
914 if (func_clk_rate / dsor > realclock)
915 dsor++;
916
917 if (dsor > 250)
918 dsor = 250;
919 dsor++;
920
921 if (ios->bus_width == MMC_BUS_WIDTH_4)
922 dsor |= 1 << 15;
923 }
924
925 switch (ios->power_mode) {
926 case MMC_POWER_OFF:
927 mmc_omap_power(host, 0);
928 break;
929 case MMC_POWER_UP:
930 case MMC_POWER_ON:
931 mmc_omap_power(host, 1);
932 dsor |= 1<<11;
933 break;
934 }
935
936 host->bus_mode = ios->bus_mode;
937 host->hw_bus_mode = host->bus_mode;
938
939 clk_enable(host->fclk);
940
941 /* On insanely high arm_per frequencies something sometimes
942 * goes somehow out of sync, and the POW bit is not being set,
943 * which results in the while loop below getting stuck.
944 * Writing to the CON register twice seems to do the trick. */
945 for (i = 0; i < 2; i++)
946 OMAP_MMC_WRITE(host->base, CON, dsor);
947 if (ios->power_mode == MMC_POWER_UP) {
948 /* Send clock cycles, poll completion */
949 OMAP_MMC_WRITE(host->base, IE, 0);
950 OMAP_MMC_WRITE(host->base, STAT, 0xffff);
951 OMAP_MMC_WRITE(host->base, CMD, 1<<7);
952 while (0 == (OMAP_MMC_READ(host->base, STAT) & 1));
953 OMAP_MMC_WRITE(host->base, STAT, 1);
954 }
955 clk_disable(host->fclk);
956}
957
958static int mmc_omap_get_ro(struct mmc_host *mmc)
959{
960 struct mmc_omap_host *host = mmc_priv(mmc);
961
962 return host->wp_pin && omap_get_gpio_datain(host->wp_pin);
963}
964
965static struct mmc_host_ops mmc_omap_ops = {
966 .request = mmc_omap_request,
967 .set_ios = mmc_omap_set_ios,
968 .get_ro = mmc_omap_get_ro,
969};
970
971static int __init mmc_omap_probe(struct platform_device *pdev)
972{
973 struct omap_mmc_conf *minfo = pdev->dev.platform_data;
974 struct mmc_host *mmc;
975 struct mmc_omap_host *host = NULL;
976 int ret = 0;
977
978 if (platform_get_resource(pdev, IORESOURCE_MEM, 0) ||
979 platform_get_irq(pdev, IORESOURCE_IRQ, 0)) {
980 dev_err(&pdev->dev, "mmc_omap_probe: invalid resource type\n");
981 return -ENODEV;
982 }
983
984 if (!request_mem_region(pdev->resource[0].start,
985 pdev->resource[0].end - pdev->resource[0].start + 1,
986 pdev->name)) {
987 dev_dbg(&pdev->dev, "request_mem_region failed\n");
988 return -EBUSY;
989 }
990
991 mmc = mmc_alloc_host(sizeof(struct mmc_omap_host), &pdev->dev);
992 if (!mmc) {
993 ret = -ENOMEM;
994 goto out;
995 }
996
997 host = mmc_priv(mmc);
998 host->mmc = mmc;
999
1000 spin_lock_init(&host->dma_lock);
1001 init_timer(&host->dma_timer);
1002 host->dma_timer.function = mmc_omap_dma_timer;
1003 host->dma_timer.data = (unsigned long) host;
1004
1005 host->id = pdev->id;
1006
1007 if (cpu_is_omap24xx()) {
1008 host->iclk = clk_get(&pdev->dev, "mmc_ick");
1009 if (IS_ERR(host->iclk))
1010 goto out;
1011 clk_enable(host->iclk);
1012 }
1013
1014 if (!cpu_is_omap24xx())
1015 host->fclk = clk_get(&pdev->dev, "mmc_ck");
1016 else
1017 host->fclk = clk_get(&pdev->dev, "mmc_fck");
1018
1019 if (IS_ERR(host->fclk)) {
1020 ret = PTR_ERR(host->fclk);
1021 goto out;
1022 }
1023
1024 /* REVISIT:
1025 * Also, use minfo->cover to decide how to manage
1026 * the card detect sensing.
1027 */
1028 host->power_pin = minfo->power_pin;
1029 host->switch_pin = minfo->switch_pin;
1030 host->wp_pin = minfo->wp_pin;
1031 host->use_dma = 1;
1032 host->dma_ch = -1;
1033
1034 host->irq = pdev->resource[1].start;
1035 host->base = ioremap(pdev->res.start, SZ_4K);
1036 if (!host->base) {
1037 ret = -ENOMEM;
1038 goto out;
1039 }
1040
1041 if (minfo->wire4)
1042 mmc->caps |= MMC_CAP_4_BIT_DATA;
1043
1044 mmc->ops = &mmc_omap_ops;
1045 mmc->f_min = 400000;
1046 mmc->f_max = 24000000;
1047 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1048
1049 /* Use scatterlist DMA to reduce per-transfer costs.
1050 * NOTE max_seg_size assumption that small blocks aren't
1051 * normally used (except e.g. for reading SD registers).
1052 */
1053 mmc->max_phys_segs = 32;
1054 mmc->max_hw_segs = 32;
1055 mmc->max_sectors = 256; /* NBLK max 11-bits, OMAP also limited by DMA */
1056 mmc->max_seg_size = mmc->max_sectors * 512;
1057
1058 if (host->power_pin >= 0) {
1059 if ((ret = omap_request_gpio(host->power_pin)) != 0) {
1060 dev_err(mmc_dev(host->mmc), "Unable to get GPIO
1061 pin for MMC power\n");
1062 goto out;
1063 }
1064 omap_set_gpio_direction(host->power_pin, 0);
1065 }
1066
1067 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
1068 if (ret)
1069 goto out;
1070
1071 host->dev = &pdev->dev;
1072 platform_set_drvdata(pdev, host);
1073
1074 mmc_add_host(mmc);
1075
1076 if (host->switch_pin >= 0) {
1077 INIT_WORK(&host->switch_work, mmc_omap_switch_handler, host);
1078 init_timer(&host->switch_timer);
1079 host->switch_timer.function = mmc_omap_switch_timer;
1080 host->switch_timer.data = (unsigned long) host;
1081 if (omap_request_gpio(host->switch_pin) != 0) {
1082 dev_warn(mmc_dev(host->mmc), "Unable to get GPIO pin for MMC cover switch\n");
1083 host->switch_pin = -1;
1084 goto no_switch;
1085 }
1086
1087 omap_set_gpio_direction(host->switch_pin, 1);
1088 ret = request_irq(OMAP_GPIO_IRQ(host->switch_pin),
1089 mmc_omap_switch_irq, SA_TRIGGER_RISING, DRIVER_NAME, host);
1090 if (ret) {
1091 dev_warn(mmc_dev(host->mmc), "Unable to get IRQ for MMC cover switch\n");
1092 omap_free_gpio(host->switch_pin);
1093 host->switch_pin = -1;
1094 goto no_switch;
1095 }
1096 ret = device_create_file(&pdev->dev, &dev_attr_cover_switch);
1097 if (ret == 0) {
1098 ret = device_create_file(&pdev->dev, &dev_attr_enable_poll);
1099 if (ret != 0)
1100 device_remove_file(&pdev->dev, &dev_attr_cover_switch);
1101 }
1102 if (ret) {
1103 dev_wan(mmc_dev(host->mmc), "Unable to create sysfs attributes\n");
1104 free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
1105 omap_free_gpio(host->switch_pin);
1106 host->switch_pin = -1;
1107 goto no_switch;
1108 }
1109 if (mmc_omap_enable_poll && mmc_omap_cover_is_open(host))
1110 schedule_work(&host->switch_work);
1111 }
1112
1113no_switch:
1114 return 0;
1115
1116out:
1117 /* FIXME: Free other resources too. */
1118 if (host) {
1119 if (host->iclk && !IS_ERR(host->iclk))
1120 clk_put(host->iclk);
1121 if (host->fclk && !IS_ERR(host->fclk))
1122 clk_put(host->fclk);
1123 mmc_free_host(host->mmc);
1124 }
1125 return ret;
1126}
1127
1128static int mmc_omap_remove(struct platform_device *pdev)
1129{
1130 struct mmc_omap_host *host = platform_get_drvdata(pdev);
1131
1132 platform_set_drvdata(pdev, NULL);
1133
1134 if (host) {
1135 mmc_remove_host(host->mmc);
1136 free_irq(host->irq, host);
1137
1138 if (host->power_pin >= 0)
1139 omap_free_gpio(host->power_pin);
1140 if (host->switch_pin >= 0) {
1141 device_remove_file(&pdev->dev, &dev_attr_enable_poll);
1142 device_remove_file(&pdev->dev, &dev_attr_cover_switch);
1143 free_irq(OMAP_GPIO_IRQ(host->switch_pin), host);
1144 omap_free_gpio(host->switch_pin);
1145 host->switch_pin = -1;
1146 del_timer_sync(&host->switch_timer);
1147 flush_scheduled_work();
1148 }
1149 if (host->iclk && !IS_ERR(host->iclk))
1150 clk_put(host->iclk);
1151 if (host->fclk && !IS_ERR(host->fclk))
1152 clk_put(host->fclk);
1153 mmc_free_host(host->mmc);
1154 }
1155
1156 release_mem_region(pdev->resource[0].start,
1157 pdev->resource[0].end - pdev->resource[0].start + 1);
1158
1159 return 0;
1160}
1161
1162#ifdef CONFIG_PM
1163static int mmc_omap_suspend(struct platform_device *pdev, pm_message_t mesg)
1164{
1165 int ret = 0;
1166 struct mmc_omap_host *host = platform_get_drvdata(pdev);
1167
1168 if (host && host->suspended)
1169 return 0;
1170
1171 if (host) {
1172 ret = mmc_suspend_host(host->mmc, mesg);
1173 if (ret == 0)
1174 host->suspended = 1;
1175 }
1176 return ret;
1177}
1178
1179static int mmc_omap_resume(struct platform_device *pdev)
1180{
1181 int ret = 0;
1182 struct mmc_omap_host *host = platform_get_drvdata(pdev);
1183
1184 if (host && !host->suspended)
1185 return 0;
1186
1187 if (host) {
1188 ret = mmc_resume_host(host->mmc);
1189 if (ret == 0)
1190 host->suspended = 0;
1191 }
1192
1193 return ret;
1194}
1195#else
1196#define mmc_omap_suspend NULL
1197#define mmc_omap_resume NULL
1198#endif
1199
1200static struct platform_driver mmc_omap_driver = {
1201 .probe = mmc_omap_probe,
1202 .remove = mmc_omap_remove,
1203 .suspend = mmc_omap_suspend,
1204 .resume = mmc_omap_resume,
1205 .driver = {
1206 .name = DRIVER_NAME,
1207 },
1208};
1209
1210static int __init mmc_omap_init(void)
1211{
1212 return platform_driver_register(&mmc_omap_driver);
1213}
1214
1215static void __exit mmc_omap_exit(void)
1216{
1217 platform_driver_unregister(&mmc_omap_driver);
1218}
1219
1220module_init(mmc_omap_init);
1221module_exit(mmc_omap_exit);
1222
1223MODULE_DESCRIPTION("OMAP Multimedia Card driver");
1224MODULE_LICENSE("GPL");
1225MODULE_ALIAS(DRIVER_NAME);
1226MODULE_AUTHOR("Juha Yrjölä");
diff --git a/drivers/mmc/omap.h b/drivers/mmc/omap.h
new file mode 100644
index 000000000000..c954d355a5e3
--- /dev/null
+++ b/drivers/mmc/omap.h
@@ -0,0 +1,55 @@
1#ifndef DRIVERS_MEDIA_MMC_OMAP_H
2#define DRIVERS_MEDIA_MMC_OMAP_H
3
4#define OMAP_MMC_REG_CMD 0x00
5#define OMAP_MMC_REG_ARGL 0x04
6#define OMAP_MMC_REG_ARGH 0x08
7#define OMAP_MMC_REG_CON 0x0c
8#define OMAP_MMC_REG_STAT 0x10
9#define OMAP_MMC_REG_IE 0x14
10#define OMAP_MMC_REG_CTO 0x18
11#define OMAP_MMC_REG_DTO 0x1c
12#define OMAP_MMC_REG_DATA 0x20
13#define OMAP_MMC_REG_BLEN 0x24
14#define OMAP_MMC_REG_NBLK 0x28
15#define OMAP_MMC_REG_BUF 0x2c
16#define OMAP_MMC_REG_SDIO 0x34
17#define OMAP_MMC_REG_REV 0x3c
18#define OMAP_MMC_REG_RSP0 0x40
19#define OMAP_MMC_REG_RSP1 0x44
20#define OMAP_MMC_REG_RSP2 0x48
21#define OMAP_MMC_REG_RSP3 0x4c
22#define OMAP_MMC_REG_RSP4 0x50
23#define OMAP_MMC_REG_RSP5 0x54
24#define OMAP_MMC_REG_RSP6 0x58
25#define OMAP_MMC_REG_RSP7 0x5c
26#define OMAP_MMC_REG_IOSR 0x60
27#define OMAP_MMC_REG_SYSC 0x64
28#define OMAP_MMC_REG_SYSS 0x68
29
30#define OMAP_MMC_STAT_CARD_ERR (1 << 14)
31#define OMAP_MMC_STAT_CARD_IRQ (1 << 13)
32#define OMAP_MMC_STAT_OCR_BUSY (1 << 12)
33#define OMAP_MMC_STAT_A_EMPTY (1 << 11)
34#define OMAP_MMC_STAT_A_FULL (1 << 10)
35#define OMAP_MMC_STAT_CMD_CRC (1 << 8)
36#define OMAP_MMC_STAT_CMD_TOUT (1 << 7)
37#define OMAP_MMC_STAT_DATA_CRC (1 << 6)
38#define OMAP_MMC_STAT_DATA_TOUT (1 << 5)
39#define OMAP_MMC_STAT_END_BUSY (1 << 4)
40#define OMAP_MMC_STAT_END_OF_DATA (1 << 3)
41#define OMAP_MMC_STAT_CARD_BUSY (1 << 2)
42#define OMAP_MMC_STAT_END_OF_CMD (1 << 0)
43
44#define OMAP_MMC_READ(base, reg) __raw_readw((base) + OMAP_MMC_REG_##reg)
45#define OMAP_MMC_WRITE(base, reg, val) __raw_writew((val), (base) + OMAP_MMC_REG_##reg)
46
47/*
48 * Command types
49 */
50#define OMAP_MMC_CMDTYPE_BC 0
51#define OMAP_MMC_CMDTYPE_BCR 1
52#define OMAP_MMC_CMDTYPE_AC 2
53#define OMAP_MMC_CMDTYPE_ADTC 3
54
55#endif
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index c32fad1ce51c..eb9a8826e9b5 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -37,12 +37,6 @@
37 37
38#include "pxamci.h" 38#include "pxamci.h"
39 39
40#ifdef CONFIG_MMC_DEBUG
41#define DBG(x...) printk(KERN_DEBUG x)
42#else
43#define DBG(x...) do { } while (0)
44#endif
45
46#define DRIVER_NAME "pxa2xx-mci" 40#define DRIVER_NAME "pxa2xx-mci"
47 41
48#define NR_SG 1 42#define NR_SG 1
@@ -206,7 +200,7 @@ static void pxamci_start_cmd(struct pxamci_host *host, struct mmc_command *cmd,
206 200
207static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq) 201static void pxamci_finish_request(struct pxamci_host *host, struct mmc_request *mrq)
208{ 202{
209 DBG("PXAMCI: request done\n"); 203 pr_debug("PXAMCI: request done\n");
210 host->mrq = NULL; 204 host->mrq = NULL;
211 host->cmd = NULL; 205 host->cmd = NULL;
212 host->data = NULL; 206 host->data = NULL;
@@ -252,7 +246,7 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
252 if ((cmd->resp[0] & 0x80000000) == 0) 246 if ((cmd->resp[0] & 0x80000000) == 0)
253 cmd->error = MMC_ERR_BADCRC; 247 cmd->error = MMC_ERR_BADCRC;
254 } else { 248 } else {
255 DBG("ignoring CRC from command %d - *risky*\n",cmd->opcode); 249 pr_debug("ignoring CRC from command %d - *risky*\n",cmd->opcode);
256 } 250 }
257#else 251#else
258 cmd->error = MMC_ERR_BADCRC; 252 cmd->error = MMC_ERR_BADCRC;
@@ -317,12 +311,12 @@ static irqreturn_t pxamci_irq(int irq, void *devid, struct pt_regs *regs)
317 311
318 ireg = readl(host->base + MMC_I_REG); 312 ireg = readl(host->base + MMC_I_REG);
319 313
320 DBG("PXAMCI: irq %08x\n", ireg); 314 pr_debug("PXAMCI: irq %08x\n", ireg);
321 315
322 if (ireg) { 316 if (ireg) {
323 unsigned stat = readl(host->base + MMC_STAT); 317 unsigned stat = readl(host->base + MMC_STAT);
324 318
325 DBG("PXAMCI: stat %08x\n", stat); 319 pr_debug("PXAMCI: stat %08x\n", stat);
326 320
327 if (ireg & END_CMD_RES) 321 if (ireg & END_CMD_RES)
328 handled |= pxamci_cmd_done(host, stat); 322 handled |= pxamci_cmd_done(host, stat);
@@ -376,9 +370,9 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
376{ 370{
377 struct pxamci_host *host = mmc_priv(mmc); 371 struct pxamci_host *host = mmc_priv(mmc);
378 372
379 DBG("pxamci_set_ios: clock %u power %u vdd %u.%02u\n", 373 pr_debug("pxamci_set_ios: clock %u power %u vdd %u.%02u\n",
380 ios->clock, ios->power_mode, ios->vdd / 100, 374 ios->clock, ios->power_mode, ios->vdd / 100,
381 ios->vdd % 100); 375 ios->vdd % 100);
382 376
383 if (ios->clock) { 377 if (ios->clock) {
384 unsigned int clk = CLOCKRATE / ios->clock; 378 unsigned int clk = CLOCKRATE / ios->clock;
@@ -405,8 +399,8 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
405 host->cmdat |= CMDAT_INIT; 399 host->cmdat |= CMDAT_INIT;
406 } 400 }
407 401
408 DBG("pxamci_set_ios: clkrt = %x cmdat = %x\n", 402 pr_debug("pxamci_set_ios: clkrt = %x cmdat = %x\n",
409 host->clkrt, host->cmdat); 403 host->clkrt, host->cmdat);
410} 404}
411 405
412static struct mmc_host_ops pxamci_ops = { 406static struct mmc_host_ops pxamci_ops = {
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 8b811d94371c..bdbfca050029 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -31,12 +31,8 @@
31 31
32#define BUGMAIL "<sdhci-devel@list.drzeus.cx>" 32#define BUGMAIL "<sdhci-devel@list.drzeus.cx>"
33 33
34#ifdef CONFIG_MMC_DEBUG
35#define DBG(f, x...) \ 34#define DBG(f, x...) \
36 printk(KERN_DEBUG DRIVER_NAME " [%s()]: " f, __func__,## x) 35 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
37#else
38#define DBG(f, x...) do { } while (0)
39#endif
40 36
41static const struct pci_device_id pci_ids[] __devinitdata = { 37static const struct pci_device_id pci_ids[] __devinitdata = {
42 /* handle any SD host controller */ 38 /* handle any SD host controller */
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index 3be397d436fa..511f7b0b31d2 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -44,15 +44,10 @@
44#define DRIVER_NAME "wbsd" 44#define DRIVER_NAME "wbsd"
45#define DRIVER_VERSION "1.5" 45#define DRIVER_VERSION "1.5"
46 46
47#ifdef CONFIG_MMC_DEBUG
48#define DBG(x...) \ 47#define DBG(x...) \
49 printk(KERN_DEBUG DRIVER_NAME ": " x) 48 pr_debug(DRIVER_NAME ": " x)
50#define DBGF(f, x...) \ 49#define DBGF(f, x...) \
51 printk(KERN_DEBUG DRIVER_NAME " [%s()]: " f, __func__ , ##x) 50 pr_debug(DRIVER_NAME " [%s()]: " f, __func__ , ##x)
52#else
53#define DBG(x...) do { } while (0)
54#define DBGF(x...) do { } while (0)
55#endif
56 51
57/* 52/*
58 * Device resources 53 * Device resources
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index 0f6bb2e625d8..a7ec5954caf5 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -200,27 +200,6 @@ config MTD_CFI_AMDSTD
200 provides support for one of those command sets, used on chips 200 provides support for one of those command sets, used on chips
201 including the AMD Am29LV320. 201 including the AMD Am29LV320.
202 202
203config MTD_CFI_AMDSTD_RETRY
204 int "Retry failed commands (erase/program)"
205 depends on MTD_CFI_AMDSTD
206 default "0"
207 help
208 Some chips, when attached to a shared bus, don't properly filter
209 bus traffic that is destined to other devices. This broken
210 behavior causes erase and program sequences to be aborted when
211 the sequences are mixed with traffic for other devices.
212
213 SST49LF040 (and related) chips are know to be broken.
214
215config MTD_CFI_AMDSTD_RETRY_MAX
216 int "Max retries of failed commands (erase/program)"
217 depends on MTD_CFI_AMDSTD_RETRY
218 default "0"
219 help
220 If you have an SST49LF040 (or related chip) then this value should
221 be set to at least 1. This can also be adjusted at driver load
222 time with the retry_cmd_max module parameter.
223
224config MTD_CFI_STAA 203config MTD_CFI_STAA
225 tristate "Support for ST (Advanced Architecture) flash chips" 204 tristate "Support for ST (Advanced Architecture) flash chips"
226 depends on MTD_GEN_PROBE 205 depends on MTD_GEN_PROBE
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
index fdb91b6f1d97..57115618c496 100644
--- a/drivers/mtd/chips/amd_flash.c
+++ b/drivers/mtd/chips/amd_flash.c
@@ -664,7 +664,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
664 printk("%s: Probing for AMD compatible flash...\n", map->name); 664 printk("%s: Probing for AMD compatible flash...\n", map->name);
665 665
666 if ((table_pos[0] = probe_new_chip(mtd, 0, NULL, &temp, table, 666 if ((table_pos[0] = probe_new_chip(mtd, 0, NULL, &temp, table,
667 sizeof(table)/sizeof(table[0]))) 667 ARRAY_SIZE(table)))
668 == -1) { 668 == -1) {
669 printk(KERN_WARNING 669 printk(KERN_WARNING
670 "%s: Found no AMD compatible device at location zero\n", 670 "%s: Found no AMD compatible device at location zero\n",
@@ -696,7 +696,7 @@ static struct mtd_info *amd_flash_probe(struct map_info *map)
696 base += (1 << temp.chipshift)) { 696 base += (1 << temp.chipshift)) {
697 int numchips = temp.numchips; 697 int numchips = temp.numchips;
698 table_pos[numchips] = probe_new_chip(mtd, base, chips, 698 table_pos[numchips] = probe_new_chip(mtd, base, chips,
699 &temp, table, sizeof(table)/sizeof(table[0])); 699 &temp, table, ARRAY_SIZE(table));
700 } 700 }
701 701
702 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) * 702 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index edb306c03c0a..517ea33e7260 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -34,6 +34,7 @@
34#define MANUFACTURER_MACRONIX 0x00C2 34#define MANUFACTURER_MACRONIX 0x00C2
35#define MANUFACTURER_NEC 0x0010 35#define MANUFACTURER_NEC 0x0010
36#define MANUFACTURER_PMC 0x009D 36#define MANUFACTURER_PMC 0x009D
37#define MANUFACTURER_SHARP 0x00b0
37#define MANUFACTURER_SST 0x00BF 38#define MANUFACTURER_SST 0x00BF
38#define MANUFACTURER_ST 0x0020 39#define MANUFACTURER_ST 0x0020
39#define MANUFACTURER_TOSHIBA 0x0098 40#define MANUFACTURER_TOSHIBA 0x0098
@@ -124,6 +125,9 @@
124#define PM49FL004 0x006E 125#define PM49FL004 0x006E
125#define PM49FL008 0x006A 126#define PM49FL008 0x006A
126 127
128/* Sharp */
129#define LH28F640BF 0x00b0
130
127/* ST - www.st.com */ 131/* ST - www.st.com */
128#define M29W800DT 0x00D7 132#define M29W800DT 0x00D7
129#define M29W800DB 0x005B 133#define M29W800DB 0x005B
@@ -1267,6 +1271,19 @@ static const struct amd_flash_info jedec_table[] = {
1267 .regions = { 1271 .regions = {
1268 ERASEINFO( 0x01000, 256 ) 1272 ERASEINFO( 0x01000, 256 )
1269 } 1273 }
1274 }, {
1275 .mfr_id = MANUFACTURER_SHARP,
1276 .dev_id = LH28F640BF,
1277 .name = "LH28F640BF",
1278 .uaddr = {
1279 [0] = MTD_UADDR_UNNECESSARY, /* x8 */
1280 },
1281 .DevSize = SIZE_4MiB,
1282 .CmdSet = P_ID_INTEL_STD,
1283 .NumEraseRegions= 1,
1284 .regions = {
1285 ERASEINFO(0x40000,16),
1286 }
1270 }, { 1287 }, {
1271 .mfr_id = MANUFACTURER_SST, 1288 .mfr_id = MANUFACTURER_SST,
1272 .dev_id = SST39LF512, 1289 .dev_id = SST39LF512,
@@ -2035,7 +2052,7 @@ static int jedec_probe_chip(struct map_info *map, __u32 base,
2035 DEBUG(MTD_DEBUG_LEVEL3, 2052 DEBUG(MTD_DEBUG_LEVEL3,
2036 "Search for id:(%02x %02x) interleave(%d) type(%d)\n", 2053 "Search for id:(%02x %02x) interleave(%d) type(%d)\n",
2037 cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type); 2054 cfi->mfr, cfi->id, cfi_interleave(cfi), cfi->device_type);
2038 for (i=0; i<sizeof(jedec_table)/sizeof(jedec_table[0]); i++) { 2055 for (i = 0; i < ARRAY_SIZE(jedec_table); i++) {
2039 if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) { 2056 if ( jedec_match( base, map, cfi, &jedec_table[i] ) ) {
2040 DEBUG( MTD_DEBUG_LEVEL3, 2057 DEBUG( MTD_DEBUG_LEVEL3,
2041 "MTD %s(): matched device 0x%x,0x%x unlock_addrs: 0x%.4x 0x%.4x\n", 2058 "MTD %s(): matched device 0x%x,0x%x unlock_addrs: 0x%.4x 0x%.4x\n",
diff --git a/drivers/mtd/chips/sharp.c b/drivers/mtd/chips/sharp.c
index 36f61a6a766e..3cc0b23c5865 100644
--- a/drivers/mtd/chips/sharp.c
+++ b/drivers/mtd/chips/sharp.c
@@ -64,7 +64,7 @@
64 64
65#undef AUTOUNLOCK /* automatically unlocks blocks before erasing */ 65#undef AUTOUNLOCK /* automatically unlocks blocks before erasing */
66 66
67struct mtd_info *sharp_probe(struct map_info *); 67static struct mtd_info *sharp_probe(struct map_info *);
68 68
69static int sharp_probe_map(struct map_info *map,struct mtd_info *mtd); 69static int sharp_probe_map(struct map_info *map,struct mtd_info *mtd);
70 70
@@ -96,7 +96,6 @@ struct sharp_info{
96 struct flchip chips[1]; 96 struct flchip chips[1];
97}; 97};
98 98
99struct mtd_info *sharp_probe(struct map_info *map);
100static void sharp_destroy(struct mtd_info *mtd); 99static void sharp_destroy(struct mtd_info *mtd);
101 100
102static struct mtd_chip_driver sharp_chipdrv = { 101static struct mtd_chip_driver sharp_chipdrv = {
@@ -107,7 +106,7 @@ static struct mtd_chip_driver sharp_chipdrv = {
107}; 106};
108 107
109 108
110struct mtd_info *sharp_probe(struct map_info *map) 109static struct mtd_info *sharp_probe(struct map_info *map)
111{ 110{
112 struct mtd_info *mtd = NULL; 111 struct mtd_info *mtd = NULL;
113 struct sharp_info *sharp = NULL; 112 struct sharp_info *sharp = NULL;
@@ -581,7 +580,7 @@ static void sharp_destroy(struct mtd_info *mtd)
581 580
582} 581}
583 582
584int __init sharp_probe_init(void) 583static int __init sharp_probe_init(void)
585{ 584{
586 printk("MTD Sharp chip driver <ds@lineo.com>\n"); 585 printk("MTD Sharp chip driver <ds@lineo.com>\n");
587 586
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 6b8bb2e4dcfd..a7a7bfe33879 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -42,7 +42,8 @@
42 42
43 43
44/* special size referring to all the remaining space in a partition */ 44/* special size referring to all the remaining space in a partition */
45#define SIZE_REMAINING 0xffffffff 45#define SIZE_REMAINING UINT_MAX
46#define OFFSET_CONTINUOUS UINT_MAX
46 47
47struct cmdline_mtd_partition { 48struct cmdline_mtd_partition {
48 struct cmdline_mtd_partition *next; 49 struct cmdline_mtd_partition *next;
@@ -75,7 +76,7 @@ static struct mtd_partition * newpart(char *s,
75{ 76{
76 struct mtd_partition *parts; 77 struct mtd_partition *parts;
77 unsigned long size; 78 unsigned long size;
78 unsigned long offset = 0; 79 unsigned long offset = OFFSET_CONTINUOUS;
79 char *name; 80 char *name;
80 int name_len; 81 int name_len;
81 unsigned char *extra_mem; 82 unsigned char *extra_mem;
@@ -314,7 +315,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
314 { 315 {
315 for(i = 0, offset = 0; i < part->num_parts; i++) 316 for(i = 0, offset = 0; i < part->num_parts; i++)
316 { 317 {
317 if (!part->parts[i].offset) 318 if (part->parts[i].offset == OFFSET_CONTINUOUS)
318 part->parts[i].offset = offset; 319 part->parts[i].offset = offset;
319 else 320 else
320 offset = part->parts[i].offset; 321 offset = part->parts[i].offset;
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index dd628cb51e31..7fac438b5c32 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -129,8 +129,8 @@ config MTDRAM_ABS_POS
129 allocating space from Linux's available memory. Otherwise, leave 129 allocating space from Linux's available memory. Otherwise, leave
130 this set to zero. Most people will want to leave this as zero. 130 this set to zero. Most people will want to leave this as zero.
131 131
132config MTD_BLKMTD 132config MTD_BLOCK2MTD
133 tristate "MTD emulation using block device" 133 tristate "MTD using block device"
134 depends on MTD 134 depends on MTD
135 help 135 help
136 This driver allows a block device to appear as an MTD. It would 136 This driver allows a block device to appear as an MTD. It would
@@ -141,15 +141,6 @@ config MTD_BLKMTD
141 Testing MTD users (eg JFFS2) on large media and media that might 141 Testing MTD users (eg JFFS2) on large media and media that might
142 be removed during a write (using the floppy drive). 142 be removed during a write (using the floppy drive).
143 143
144config MTD_BLOCK2MTD
145 tristate "MTD using block device (rewrite)"
146 depends on MTD && EXPERIMENTAL
147 help
148 This driver is basically the same at MTD_BLKMTD above, but
149 experienced some interface changes plus serious speedups. In
150 the long term, it should replace MTD_BLKMTD. Right now, you
151 shouldn't entrust important data to it yet.
152
153comment "Disk-On-Chip Device Drivers" 144comment "Disk-On-Chip Device Drivers"
154 145
155config MTD_DOC2000 146config MTD_DOC2000
diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile
index 7c5ed2178380..b6573670316f 100644
--- a/drivers/mtd/devices/Makefile
+++ b/drivers/mtd/devices/Makefile
@@ -21,7 +21,6 @@ obj-$(CONFIG_MTD_PMC551) += pmc551.o
21obj-$(CONFIG_MTD_MS02NV) += ms02-nv.o 21obj-$(CONFIG_MTD_MS02NV) += ms02-nv.o
22obj-$(CONFIG_MTD_MTDRAM) += mtdram.o 22obj-$(CONFIG_MTD_MTDRAM) += mtdram.o
23obj-$(CONFIG_MTD_LART) += lart.o 23obj-$(CONFIG_MTD_LART) += lart.o
24obj-$(CONFIG_MTD_BLKMTD) += blkmtd.o
25obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o 24obj-$(CONFIG_MTD_BLOCK2MTD) += block2mtd.o
26obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o 25obj-$(CONFIG_MTD_DATAFLASH) += mtd_dataflash.o
27obj-$(CONFIG_MTD_M25P80) += m25p80.o 26obj-$(CONFIG_MTD_M25P80) += m25p80.o
diff --git a/drivers/mtd/devices/blkmtd.c b/drivers/mtd/devices/blkmtd.c
deleted file mode 100644
index 04f864d238db..000000000000
--- a/drivers/mtd/devices/blkmtd.c
+++ /dev/null
@@ -1,820 +0,0 @@
1/*
2 * $Id: blkmtd.c,v 1.27 2005/11/07 11:14:24 gleixner Exp $
3 *
4 * blkmtd.c - use a block device as a fake MTD
5 *
6 * Author: Simon Evans <spse@secret.org.uk>
7 *
8 * Copyright (C) 2001,2002 Simon Evans
9 *
10 * Licence: GPL
11 *
12 * How it works:
13 * The driver uses raw/io to read/write the device and the page
14 * cache to cache access. Writes update the page cache with the
15 * new data and mark it dirty and add the page into a BIO which
16 * is then written out.
17 *
18 * It can be loaded Read-Only to prevent erases and writes to the
19 * medium.
20 *
21 */
22
23#include <linux/config.h>
24#include <linux/module.h>
25#include <linux/fs.h>
26#include <linux/blkdev.h>
27#include <linux/bio.h>
28#include <linux/pagemap.h>
29#include <linux/list.h>
30#include <linux/init.h>
31#include <linux/mtd/mtd.h>
32
33
34#define err(format, arg...) printk(KERN_ERR "blkmtd: " format "\n" , ## arg)
35#define info(format, arg...) printk(KERN_INFO "blkmtd: " format "\n" , ## arg)
36#define warn(format, arg...) printk(KERN_WARNING "blkmtd: " format "\n" , ## arg)
37#define crit(format, arg...) printk(KERN_CRIT "blkmtd: " format "\n" , ## arg)
38
39
40/* Default erase size in K, always make it a multiple of PAGE_SIZE */
41#define CONFIG_MTD_BLKDEV_ERASESIZE (128 << 10) /* 128KiB */
42#define VERSION "$Revision: 1.27 $"
43
44/* Info for the block device */
45struct blkmtd_dev {
46 struct list_head list;
47 struct block_device *blkdev;
48 struct mtd_info mtd_info;
49 struct semaphore wrbuf_mutex;
50};
51
52
53/* Static info about the MTD, used in cleanup_module */
54static LIST_HEAD(blkmtd_device_list);
55
56
57static void blkmtd_sync(struct mtd_info *mtd);
58
59#define MAX_DEVICES 4
60
61/* Module parameters passed by insmod/modprobe */
62static char *device[MAX_DEVICES]; /* the block device to use */
63static int erasesz[MAX_DEVICES]; /* optional default erase size */
64static int ro[MAX_DEVICES]; /* optional read only flag */
65static int sync;
66
67
68MODULE_LICENSE("GPL");
69MODULE_AUTHOR("Simon Evans <spse@secret.org.uk>");
70MODULE_DESCRIPTION("Emulate an MTD using a block device");
71module_param_array(device, charp, NULL, 0);
72MODULE_PARM_DESC(device, "block device to use");
73module_param_array(erasesz, int, NULL, 0);
74MODULE_PARM_DESC(erasesz, "optional erase size to use in KiB. eg 4=4KiB.");
75module_param_array(ro, bool, NULL, 0);
76MODULE_PARM_DESC(ro, "1=Read only, writes and erases cause errors");
77module_param(sync, bool, 0);
78MODULE_PARM_DESC(sync, "1=Synchronous writes");
79
80
81/* completion handler for BIO reads */
82static int bi_read_complete(struct bio *bio, unsigned int bytes_done, int error)
83{
84 if (bio->bi_size)
85 return 1;
86
87 complete((struct completion*)bio->bi_private);
88 return 0;
89}
90
91
92/* completion handler for BIO writes */
93static int bi_write_complete(struct bio *bio, unsigned int bytes_done, int error)
94{
95 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
96 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
97
98 if (bio->bi_size)
99 return 1;
100
101 if(!uptodate)
102 err("bi_write_complete: not uptodate\n");
103
104 do {
105 struct page *page = bvec->bv_page;
106 DEBUG(3, "Cleaning up page %ld\n", page->index);
107 if (--bvec >= bio->bi_io_vec)
108 prefetchw(&bvec->bv_page->flags);
109
110 if (uptodate) {
111 SetPageUptodate(page);
112 } else {
113 ClearPageUptodate(page);
114 SetPageError(page);
115 }
116 clear_page_dirty(page);
117 unlock_page(page);
118 page_cache_release(page);
119 } while (bvec >= bio->bi_io_vec);
120
121 complete((struct completion*)bio->bi_private);
122 return 0;
123}
124
125
126/* read one page from the block device */
127static int blkmtd_readpage(struct blkmtd_dev *dev, struct page *page)
128{
129 struct bio *bio;
130 struct completion event;
131 int err = -ENOMEM;
132
133 if(PageUptodate(page)) {
134 DEBUG(2, "blkmtd: readpage page %ld is already upto date\n", page->index);
135 unlock_page(page);
136 return 0;
137 }
138
139 ClearPageUptodate(page);
140 ClearPageError(page);
141
142 bio = bio_alloc(GFP_KERNEL, 1);
143 if(bio) {
144 init_completion(&event);
145 bio->bi_bdev = dev->blkdev;
146 bio->bi_sector = page->index << (PAGE_SHIFT-9);
147 bio->bi_private = &event;
148 bio->bi_end_io = bi_read_complete;
149 if(bio_add_page(bio, page, PAGE_SIZE, 0) == PAGE_SIZE) {
150 submit_bio(READ_SYNC, bio);
151 wait_for_completion(&event);
152 err = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : -EIO;
153 bio_put(bio);
154 }
155 }
156
157 if(err)
158 SetPageError(page);
159 else
160 SetPageUptodate(page);
161 flush_dcache_page(page);
162 unlock_page(page);
163 return err;
164}
165
166
167/* write out the current BIO and wait for it to finish */
168static int blkmtd_write_out(struct bio *bio)
169{
170 struct completion event;
171 int err;
172
173 if(!bio->bi_vcnt) {
174 bio_put(bio);
175 return 0;
176 }
177
178 init_completion(&event);
179 bio->bi_private = &event;
180 bio->bi_end_io = bi_write_complete;
181 submit_bio(WRITE_SYNC, bio);
182 wait_for_completion(&event);
183 DEBUG(3, "submit_bio completed, bi_vcnt = %d\n", bio->bi_vcnt);
184 err = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : -EIO;
185 bio_put(bio);
186 return err;
187}
188
189
190/**
191 * blkmtd_add_page - add a page to the current BIO
192 * @bio: bio to add to (NULL to alloc initial bio)
193 * @blkdev: block device
194 * @page: page to add
195 * @pagecnt: pages left to add
196 *
197 * Adds a page to the current bio, allocating it if necessary. If it cannot be
198 * added, the current bio is written out and a new one is allocated. Returns
199 * the new bio to add or NULL on error
200 */
201static struct bio *blkmtd_add_page(struct bio *bio, struct block_device *blkdev,
202 struct page *page, int pagecnt)
203{
204
205 retry:
206 if(!bio) {
207 bio = bio_alloc(GFP_KERNEL, pagecnt);
208 if(!bio)
209 return NULL;
210 bio->bi_sector = page->index << (PAGE_SHIFT-9);
211 bio->bi_bdev = blkdev;
212 }
213
214 if(bio_add_page(bio, page, PAGE_SIZE, 0) != PAGE_SIZE) {
215 blkmtd_write_out(bio);
216 bio = NULL;
217 goto retry;
218 }
219 return bio;
220}
221
222
223/**
224 * write_pages - write block of data to device via the page cache
225 * @dev: device to write to
226 * @buf: data source or NULL if erase (output is set to 0xff)
227 * @to: offset into output device
228 * @len: amount to data to write
229 * @retlen: amount of data written
230 *
231 * Grab pages from the page cache and fill them with the source data.
232 * Non page aligned start and end result in a readin of the page and
233 * part of the page being modified. Pages are added to the bio and then written
234 * out.
235 */
236static int write_pages(struct blkmtd_dev *dev, const u_char *buf, loff_t to,
237 size_t len, size_t *retlen)
238{
239 int pagenr, offset;
240 size_t start_len = 0, end_len;
241 int pagecnt = 0;
242 int err = 0;
243 struct bio *bio = NULL;
244 size_t thislen = 0;
245
246 pagenr = to >> PAGE_SHIFT;
247 offset = to & ~PAGE_MASK;
248
249 DEBUG(2, "blkmtd: write_pages: buf = %p to = %ld len = %zd pagenr = %d offset = %d\n",
250 buf, (long)to, len, pagenr, offset);
251
252 /* see if we have to do a partial write at the start */
253 if(offset) {
254 start_len = ((offset + len) > PAGE_SIZE) ? PAGE_SIZE - offset : len;
255 len -= start_len;
256 }
257
258 /* calculate the length of the other two regions */
259 end_len = len & ~PAGE_MASK;
260 len -= end_len;
261
262 if(start_len)
263 pagecnt++;
264
265 if(len)
266 pagecnt += len >> PAGE_SHIFT;
267
268 if(end_len)
269 pagecnt++;
270
271 down(&dev->wrbuf_mutex);
272
273 DEBUG(3, "blkmtd: write: start_len = %zd len = %zd end_len = %zd pagecnt = %d\n",
274 start_len, len, end_len, pagecnt);
275
276 if(start_len) {
277 /* do partial start region */
278 struct page *page;
279
280 DEBUG(3, "blkmtd: write: doing partial start, page = %d len = %zd offset = %d\n",
281 pagenr, start_len, offset);
282
283 BUG_ON(!buf);
284 page = read_cache_page(dev->blkdev->bd_inode->i_mapping, pagenr, (filler_t *)blkmtd_readpage, dev);
285 lock_page(page);
286 if(PageDirty(page)) {
287 err("to = %lld start_len = %zd len = %zd end_len = %zd pagenr = %d\n",
288 to, start_len, len, end_len, pagenr);
289 BUG();
290 }
291 memcpy(page_address(page)+offset, buf, start_len);
292 set_page_dirty(page);
293 SetPageUptodate(page);
294 buf += start_len;
295 thislen = start_len;
296 bio = blkmtd_add_page(bio, dev->blkdev, page, pagecnt);
297 if(!bio) {
298 err = -ENOMEM;
299 err("bio_add_page failed\n");
300 goto write_err;
301 }
302 pagecnt--;
303 pagenr++;
304 }
305
306 /* Now do the main loop to a page aligned, n page sized output */
307 if(len) {
308 int pagesc = len >> PAGE_SHIFT;
309 DEBUG(3, "blkmtd: write: whole pages start = %d, count = %d\n",
310 pagenr, pagesc);
311 while(pagesc) {
312 struct page *page;
313
314 /* see if page is in the page cache */
315 DEBUG(3, "blkmtd: write: grabbing page %d from page cache\n", pagenr);
316 page = grab_cache_page(dev->blkdev->bd_inode->i_mapping, pagenr);
317 if(PageDirty(page)) {
318 BUG();
319 }
320 if(!page) {
321 warn("write: cannot grab cache page %d", pagenr);
322 err = -ENOMEM;
323 goto write_err;
324 }
325 if(!buf) {
326 memset(page_address(page), 0xff, PAGE_SIZE);
327 } else {
328 memcpy(page_address(page), buf, PAGE_SIZE);
329 buf += PAGE_SIZE;
330 }
331 bio = blkmtd_add_page(bio, dev->blkdev, page, pagecnt);
332 if(!bio) {
333 err = -ENOMEM;
334 err("bio_add_page failed\n");
335 goto write_err;
336 }
337 pagenr++;
338 pagecnt--;
339 set_page_dirty(page);
340 SetPageUptodate(page);
341 pagesc--;
342 thislen += PAGE_SIZE;
343 }
344 }
345
346 if(end_len) {
347 /* do the third region */
348 struct page *page;
349 DEBUG(3, "blkmtd: write: doing partial end, page = %d len = %zd\n",
350 pagenr, end_len);
351 BUG_ON(!buf);
352 page = read_cache_page(dev->blkdev->bd_inode->i_mapping, pagenr, (filler_t *)blkmtd_readpage, dev);
353 lock_page(page);
354 if(PageDirty(page)) {
355 err("to = %lld start_len = %zd len = %zd end_len = %zd pagenr = %d\n",
356 to, start_len, len, end_len, pagenr);
357 BUG();
358 }
359 memcpy(page_address(page), buf, end_len);
360 set_page_dirty(page);
361 SetPageUptodate(page);
362 DEBUG(3, "blkmtd: write: writing out partial end\n");
363 thislen += end_len;
364 bio = blkmtd_add_page(bio, dev->blkdev, page, pagecnt);
365 if(!bio) {
366 err = -ENOMEM;
367 err("bio_add_page failed\n");
368 goto write_err;
369 }
370 pagenr++;
371 }
372
373 DEBUG(3, "blkmtd: write: got %d vectors to write\n", bio->bi_vcnt);
374 write_err:
375 if(bio)
376 blkmtd_write_out(bio);
377
378 DEBUG(2, "blkmtd: write: end, retlen = %zd, err = %d\n", *retlen, err);
379 up(&dev->wrbuf_mutex);
380
381 if(retlen)
382 *retlen = thislen;
383 return err;
384}
385
386
387/* erase a specified part of the device */
388static int blkmtd_erase(struct mtd_info *mtd, struct erase_info *instr)
389{
390 struct blkmtd_dev *dev = mtd->priv;
391 struct mtd_erase_region_info *einfo = mtd->eraseregions;
392 int numregions = mtd->numeraseregions;
393 size_t from;
394 u_long len;
395 int err = -EIO;
396 size_t retlen;
397
398 instr->state = MTD_ERASING;
399 from = instr->addr;
400 len = instr->len;
401
402 /* check erase region has valid start and length */
403 DEBUG(2, "blkmtd: erase: dev = `%s' from = 0x%zx len = 0x%lx\n",
404 mtd->name+9, from, len);
405 while(numregions) {
406 DEBUG(3, "blkmtd: checking erase region = 0x%08X size = 0x%X num = 0x%x\n",
407 einfo->offset, einfo->erasesize, einfo->numblocks);
408 if(from >= einfo->offset
409 && from < einfo->offset + (einfo->erasesize * einfo->numblocks)) {
410 if(len == einfo->erasesize
411 && ( (from - einfo->offset) % einfo->erasesize == 0))
412 break;
413 }
414 numregions--;
415 einfo++;
416 }
417
418 if(!numregions) {
419 /* Not a valid erase block */
420 err("erase: invalid erase request 0x%lX @ 0x%08zX", len, from);
421 instr->state = MTD_ERASE_FAILED;
422 err = -EIO;
423 }
424
425 if(instr->state != MTD_ERASE_FAILED) {
426 /* do the erase */
427 DEBUG(3, "Doing erase from = %zd len = %ld\n", from, len);
428 err = write_pages(dev, NULL, from, len, &retlen);
429 if(err || retlen != len) {
430 err("erase failed err = %d", err);
431 instr->state = MTD_ERASE_FAILED;
432 } else {
433 instr->state = MTD_ERASE_DONE;
434 }
435 }
436
437 DEBUG(3, "blkmtd: erase: checking callback\n");
438 mtd_erase_callback(instr);
439 DEBUG(2, "blkmtd: erase: finished (err = %d)\n", err);
440 return err;
441}
442
443
444/* read a range of the data via the page cache */
445static int blkmtd_read(struct mtd_info *mtd, loff_t from, size_t len,
446 size_t *retlen, u_char *buf)
447{
448 struct blkmtd_dev *dev = mtd->priv;
449 int err = 0;
450 int offset;
451 int pagenr, pages;
452 size_t thislen = 0;
453
454 DEBUG(2, "blkmtd: read: dev = `%s' from = %lld len = %zd buf = %p\n",
455 mtd->name+9, from, len, buf);
456
457 if(from > mtd->size)
458 return -EINVAL;
459 if(from + len > mtd->size)
460 len = mtd->size - from;
461
462 pagenr = from >> PAGE_SHIFT;
463 offset = from - (pagenr << PAGE_SHIFT);
464
465 pages = (offset+len+PAGE_SIZE-1) >> PAGE_SHIFT;
466 DEBUG(3, "blkmtd: read: pagenr = %d offset = %d, pages = %d\n",
467 pagenr, offset, pages);
468
469 while(pages) {
470 struct page *page;
471 int cpylen;
472
473 DEBUG(3, "blkmtd: read: looking for page: %d\n", pagenr);
474 page = read_cache_page(dev->blkdev->bd_inode->i_mapping, pagenr, (filler_t *)blkmtd_readpage, dev);
475 if(IS_ERR(page)) {
476 err = -EIO;
477 goto readerr;
478 }
479
480 cpylen = (PAGE_SIZE > len) ? len : PAGE_SIZE;
481 if(offset+cpylen > PAGE_SIZE)
482 cpylen = PAGE_SIZE-offset;
483
484 memcpy(buf + thislen, page_address(page) + offset, cpylen);
485 offset = 0;
486 len -= cpylen;
487 thislen += cpylen;
488 pagenr++;
489 pages--;
490 if(!PageDirty(page))
491 page_cache_release(page);
492 }
493
494 readerr:
495 if(retlen)
496 *retlen = thislen;
497 DEBUG(2, "blkmtd: end read: retlen = %zd, err = %d\n", thislen, err);
498 return err;
499}
500
501
502/* write data to the underlying device */
503static int blkmtd_write(struct mtd_info *mtd, loff_t to, size_t len,
504 size_t *retlen, const u_char *buf)
505{
506 struct blkmtd_dev *dev = mtd->priv;
507 int err;
508
509 if(!len)
510 return 0;
511
512 DEBUG(2, "blkmtd: write: dev = `%s' to = %lld len = %zd buf = %p\n",
513 mtd->name+9, to, len, buf);
514
515 if(to >= mtd->size) {
516 return -ENOSPC;
517 }
518
519 if(to + len > mtd->size) {
520 len = mtd->size - to;
521 }
522
523 err = write_pages(dev, buf, to, len, retlen);
524 if(err > 0)
525 err = 0;
526 DEBUG(2, "blkmtd: write: end, err = %d\n", err);
527 return err;
528}
529
530
531/* sync the device - wait until the write queue is empty */
532static void blkmtd_sync(struct mtd_info *mtd)
533{
534 /* Currently all writes are synchronous */
535}
536
537
538static void free_device(struct blkmtd_dev *dev)
539{
540 DEBUG(2, "blkmtd: free_device() dev = %p\n", dev);
541 if(dev) {
542 kfree(dev->mtd_info.eraseregions);
543 kfree(dev->mtd_info.name);
544 if(dev->blkdev) {
545 invalidate_inode_pages(dev->blkdev->bd_inode->i_mapping);
546 close_bdev_excl(dev->blkdev);
547 }
548 kfree(dev);
549 }
550}
551
552
553/* For a given size and initial erase size, calculate the number
554 * and size of each erase region. Goes round the loop twice,
555 * once to find out how many regions, then allocates space,
556 * then round the loop again to fill it in.
557 */
558static struct mtd_erase_region_info *calc_erase_regions(
559 size_t erase_size, size_t total_size, int *regions)
560{
561 struct mtd_erase_region_info *info = NULL;
562
563 DEBUG(2, "calc_erase_regions, es = %zd size = %zd regions = %d\n",
564 erase_size, total_size, *regions);
565 /* Make any user specified erasesize be a power of 2
566 and at least PAGE_SIZE */
567 if(erase_size) {
568 int es = erase_size;
569 erase_size = 1;
570 while(es != 1) {
571 es >>= 1;
572 erase_size <<= 1;
573 }
574 if(erase_size < PAGE_SIZE)
575 erase_size = PAGE_SIZE;
576 } else {
577 erase_size = CONFIG_MTD_BLKDEV_ERASESIZE;
578 }
579
580 *regions = 0;
581
582 do {
583 int tot_size = total_size;
584 int er_size = erase_size;
585 int count = 0, offset = 0, regcnt = 0;
586
587 while(tot_size) {
588 count = tot_size / er_size;
589 if(count) {
590 tot_size = tot_size % er_size;
591 if(info) {
592 DEBUG(2, "adding to erase info off=%d er=%d cnt=%d\n",
593 offset, er_size, count);
594 (info+regcnt)->offset = offset;
595 (info+regcnt)->erasesize = er_size;
596 (info+regcnt)->numblocks = count;
597 (*regions)++;
598 }
599 regcnt++;
600 offset += (count * er_size);
601 }
602 while(er_size > tot_size)
603 er_size >>= 1;
604 }
605 if(info == NULL) {
606 info = kmalloc(regcnt * sizeof(struct mtd_erase_region_info), GFP_KERNEL);
607 if(!info)
608 break;
609 }
610 } while(!(*regions));
611 DEBUG(2, "calc_erase_regions done, es = %zd size = %zd regions = %d\n",
612 erase_size, total_size, *regions);
613 return info;
614}
615
616
617extern dev_t __init name_to_dev_t(const char *line);
618
619static struct blkmtd_dev *add_device(char *devname, int readonly, int erase_size)
620{
621 struct block_device *bdev;
622 int mode;
623 struct blkmtd_dev *dev;
624
625 if(!devname)
626 return NULL;
627
628 /* Get a handle on the device */
629
630
631#ifdef MODULE
632 mode = (readonly) ? O_RDONLY : O_RDWR;
633 bdev = open_bdev_excl(devname, mode, NULL);
634#else
635 mode = (readonly) ? FMODE_READ : FMODE_WRITE;
636 bdev = open_by_devnum(name_to_dev_t(devname), mode);
637#endif
638 if(IS_ERR(bdev)) {
639 err("error: cannot open device %s", devname);
640 DEBUG(2, "blkmtd: opening bdev returned %ld\n", PTR_ERR(bdev));
641 return NULL;
642 }
643
644 DEBUG(1, "blkmtd: found a block device major = %d, minor = %d\n",
645 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
646
647 if(MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) {
648 err("attempting to use an MTD device as a block device");
649 blkdev_put(bdev);
650 return NULL;
651 }
652
653 dev = kmalloc(sizeof(struct blkmtd_dev), GFP_KERNEL);
654 if(dev == NULL) {
655 blkdev_put(bdev);
656 return NULL;
657 }
658
659 memset(dev, 0, sizeof(struct blkmtd_dev));
660 dev->blkdev = bdev;
661 if(!readonly) {
662 init_MUTEX(&dev->wrbuf_mutex);
663 }
664
665 dev->mtd_info.size = dev->blkdev->bd_inode->i_size & PAGE_MASK;
666
667 /* Setup the MTD structure */
668 /* make the name contain the block device in */
669 dev->mtd_info.name = kmalloc(sizeof("blkmtd: ") + strlen(devname), GFP_KERNEL);
670 if(dev->mtd_info.name == NULL)
671 goto devinit_err;
672
673 sprintf(dev->mtd_info.name, "blkmtd: %s", devname);
674 dev->mtd_info.eraseregions = calc_erase_regions(erase_size, dev->mtd_info.size,
675 &dev->mtd_info.numeraseregions);
676 if(dev->mtd_info.eraseregions == NULL)
677 goto devinit_err;
678
679 dev->mtd_info.erasesize = dev->mtd_info.eraseregions->erasesize;
680 DEBUG(1, "blkmtd: init: found %d erase regions\n",
681 dev->mtd_info.numeraseregions);
682
683 if(readonly) {
684 dev->mtd_info.type = MTD_ROM;
685 dev->mtd_info.flags = MTD_CAP_ROM;
686 } else {
687 dev->mtd_info.type = MTD_RAM;
688 dev->mtd_info.flags = MTD_CAP_RAM;
689 dev->mtd_info.erase = blkmtd_erase;
690 dev->mtd_info.write = blkmtd_write;
691 dev->mtd_info.writev = default_mtd_writev;
692 dev->mtd_info.sync = blkmtd_sync;
693 }
694 dev->mtd_info.read = blkmtd_read;
695 dev->mtd_info.readv = default_mtd_readv;
696 dev->mtd_info.priv = dev;
697 dev->mtd_info.owner = THIS_MODULE;
698
699 list_add(&dev->list, &blkmtd_device_list);
700 if (add_mtd_device(&dev->mtd_info)) {
701 /* Device didnt get added, so free the entry */
702 list_del(&dev->list);
703 goto devinit_err;
704 } else {
705 info("mtd%d: [%s] erase_size = %dKiB %s",
706 dev->mtd_info.index, dev->mtd_info.name + strlen("blkmtd: "),
707 dev->mtd_info.erasesize >> 10,
708 readonly ? "(read-only)" : "");
709 }
710
711 return dev;
712
713 devinit_err:
714 free_device(dev);
715 return NULL;
716}
717
718
719/* Cleanup and exit - sync the device and kill of the kernel thread */
720static void __devexit cleanup_blkmtd(void)
721{
722 struct list_head *temp1, *temp2;
723
724 /* Remove the MTD devices */
725 list_for_each_safe(temp1, temp2, &blkmtd_device_list) {
726 struct blkmtd_dev *dev = list_entry(temp1, struct blkmtd_dev,
727 list);
728 blkmtd_sync(&dev->mtd_info);
729 del_mtd_device(&dev->mtd_info);
730 info("mtd%d: [%s] removed", dev->mtd_info.index,
731 dev->mtd_info.name + strlen("blkmtd: "));
732 list_del(&dev->list);
733 free_device(dev);
734 }
735}
736
737#ifndef MODULE
738
739/* Handle kernel boot params */
740
741
742static int __init param_blkmtd_device(char *str)
743{
744 int i;
745
746 for(i = 0; i < MAX_DEVICES; i++) {
747 device[i] = str;
748 DEBUG(2, "blkmtd: device setup: %d = %s\n", i, device[i]);
749 strsep(&str, ",");
750 }
751 return 1;
752}
753
754
755static int __init param_blkmtd_erasesz(char *str)
756{
757 int i;
758 for(i = 0; i < MAX_DEVICES; i++) {
759 char *val = strsep(&str, ",");
760 if(val)
761 erasesz[i] = simple_strtoul(val, NULL, 0);
762 DEBUG(2, "blkmtd: erasesz setup: %d = %d\n", i, erasesz[i]);
763 }
764
765 return 1;
766}
767
768
769static int __init param_blkmtd_ro(char *str)
770{
771 int i;
772 for(i = 0; i < MAX_DEVICES; i++) {
773 char *val = strsep(&str, ",");
774 if(val)
775 ro[i] = simple_strtoul(val, NULL, 0);
776 DEBUG(2, "blkmtd: ro setup: %d = %d\n", i, ro[i]);
777 }
778
779 return 1;
780}
781
782
783static int __init param_blkmtd_sync(char *str)
784{
785 if(str[0] == '1')
786 sync = 1;
787 return 1;
788}
789
790__setup("blkmtd_device=", param_blkmtd_device);
791__setup("blkmtd_erasesz=", param_blkmtd_erasesz);
792__setup("blkmtd_ro=", param_blkmtd_ro);
793__setup("blkmtd_sync=", param_blkmtd_sync);
794
795#endif
796
797
798/* Startup */
799static int __init init_blkmtd(void)
800{
801 int i;
802
803 info("version " VERSION);
804 /* Check args - device[0] is the bare minimum*/
805 if(!device[0]) {
806 err("error: missing `device' name\n");
807 return -EINVAL;
808 }
809
810 for(i = 0; i < MAX_DEVICES; i++)
811 add_device(device[i], ro[i], erasesz[i] << 10);
812
813 if(list_empty(&blkmtd_device_list))
814 return -EINVAL;
815
816 return 0;
817}
818
819module_init(init_blkmtd);
820module_exit(cleanup_blkmtd);
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 7ff403b2a0a0..4160b8334c53 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -18,6 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/buffer_head.h> 20#include <linux/buffer_head.h>
21#include <linux/mutex.h>
21 22
22#define VERSION "$Revision: 1.30 $" 23#define VERSION "$Revision: 1.30 $"
23 24
@@ -31,7 +32,7 @@ struct block2mtd_dev {
31 struct list_head list; 32 struct list_head list;
32 struct block_device *blkdev; 33 struct block_device *blkdev;
33 struct mtd_info mtd; 34 struct mtd_info mtd;
34 struct semaphore write_mutex; 35 struct mutex write_mutex;
35}; 36};
36 37
37 38
@@ -134,9 +135,9 @@ static int block2mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
134 int err; 135 int err;
135 136
136 instr->state = MTD_ERASING; 137 instr->state = MTD_ERASING;
137 down(&dev->write_mutex); 138 mutex_lock(&dev->write_mutex);
138 err = _block2mtd_erase(dev, from, len); 139 err = _block2mtd_erase(dev, from, len);
139 up(&dev->write_mutex); 140 mutex_unlock(&dev->write_mutex);
140 if (err) { 141 if (err) {
141 ERROR("erase failed err = %d", err); 142 ERROR("erase failed err = %d", err);
142 instr->state = MTD_ERASE_FAILED; 143 instr->state = MTD_ERASE_FAILED;
@@ -249,9 +250,9 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len,
249 if (to + len > mtd->size) 250 if (to + len > mtd->size)
250 len = mtd->size - to; 251 len = mtd->size - to;
251 252
252 down(&dev->write_mutex); 253 mutex_lock(&dev->write_mutex);
253 err = _block2mtd_write(dev, buf, to, len, retlen); 254 err = _block2mtd_write(dev, buf, to, len, retlen);
254 up(&dev->write_mutex); 255 mutex_unlock(&dev->write_mutex);
255 if (err > 0) 256 if (err > 0)
256 err = 0; 257 err = 0;
257 return err; 258 return err;
@@ -310,7 +311,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
310 goto devinit_err; 311 goto devinit_err;
311 } 312 }
312 313
313 init_MUTEX(&dev->write_mutex); 314 mutex_init(&dev->write_mutex);
314 315
315 /* Setup the MTD structure */ 316 /* Setup the MTD structure */
316 /* make the name contain the block device in */ 317 /* make the name contain the block device in */
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index e4345cf744a2..23e7a5c7d2c1 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -20,6 +20,7 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <linux/mutex.h>
23 24
24#include <linux/mtd/mtd.h> 25#include <linux/mtd/mtd.h>
25#include <linux/mtd/nand.h> 26#include <linux/mtd/nand.h>
@@ -605,7 +606,7 @@ static void DoC2k_init(struct mtd_info *mtd)
605 606
606 this->curfloor = -1; 607 this->curfloor = -1;
607 this->curchip = -1; 608 this->curchip = -1;
608 init_MUTEX(&this->lock); 609 mutex_init(&this->lock);
609 610
610 /* Ident all the chips present. */ 611 /* Ident all the chips present. */
611 DoC_ScanChips(this, maxchips); 612 DoC_ScanChips(this, maxchips);
@@ -645,7 +646,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
645 if (from >= this->totlen) 646 if (from >= this->totlen)
646 return -EINVAL; 647 return -EINVAL;
647 648
648 down(&this->lock); 649 mutex_lock(&this->lock);
649 650
650 *retlen = 0; 651 *retlen = 0;
651 while (left) { 652 while (left) {
@@ -774,7 +775,7 @@ static int doc_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
774 buf += len; 775 buf += len;
775 } 776 }
776 777
777 up(&this->lock); 778 mutex_unlock(&this->lock);
778 779
779 return ret; 780 return ret;
780} 781}
@@ -803,7 +804,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
803 if (to >= this->totlen) 804 if (to >= this->totlen)
804 return -EINVAL; 805 return -EINVAL;
805 806
806 down(&this->lock); 807 mutex_lock(&this->lock);
807 808
808 *retlen = 0; 809 *retlen = 0;
809 while (left) { 810 while (left) {
@@ -873,7 +874,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
873 printk(KERN_ERR "Error programming flash\n"); 874 printk(KERN_ERR "Error programming flash\n");
874 /* Error in programming */ 875 /* Error in programming */
875 *retlen = 0; 876 *retlen = 0;
876 up(&this->lock); 877 mutex_unlock(&this->lock);
877 return -EIO; 878 return -EIO;
878 } 879 }
879 880
@@ -935,7 +936,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
935 printk(KERN_ERR "Error programming flash\n"); 936 printk(KERN_ERR "Error programming flash\n");
936 /* Error in programming */ 937 /* Error in programming */
937 *retlen = 0; 938 *retlen = 0;
938 up(&this->lock); 939 mutex_unlock(&this->lock);
939 return -EIO; 940 return -EIO;
940 } 941 }
941 942
@@ -956,7 +957,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
956 957
957 ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x); 958 ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
958 if (ret) { 959 if (ret) {
959 up(&this->lock); 960 mutex_unlock(&this->lock);
960 return ret; 961 return ret;
961 } 962 }
962 } 963 }
@@ -966,7 +967,7 @@ static int doc_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
966 buf += len; 967 buf += len;
967 } 968 }
968 969
969 up(&this->lock); 970 mutex_unlock(&this->lock);
970 return 0; 971 return 0;
971} 972}
972 973
@@ -975,13 +976,13 @@ static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
975 u_char *eccbuf, struct nand_oobinfo *oobsel) 976 u_char *eccbuf, struct nand_oobinfo *oobsel)
976{ 977{
977 static char static_buf[512]; 978 static char static_buf[512];
978 static DECLARE_MUTEX(writev_buf_sem); 979 static DEFINE_MUTEX(writev_buf_mutex);
979 980
980 size_t totretlen = 0; 981 size_t totretlen = 0;
981 size_t thisvecofs = 0; 982 size_t thisvecofs = 0;
982 int ret= 0; 983 int ret= 0;
983 984
984 down(&writev_buf_sem); 985 mutex_lock(&writev_buf_mutex);
985 986
986 while(count) { 987 while(count) {
987 size_t thislen, thisretlen; 988 size_t thislen, thisretlen;
@@ -1024,7 +1025,7 @@ static int doc_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
1024 to += thislen; 1025 to += thislen;
1025 } 1026 }
1026 1027
1027 up(&writev_buf_sem); 1028 mutex_unlock(&writev_buf_mutex);
1028 *retlen = totretlen; 1029 *retlen = totretlen;
1029 return ret; 1030 return ret;
1030} 1031}
@@ -1037,7 +1038,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
1037 int len256 = 0, ret; 1038 int len256 = 0, ret;
1038 struct Nand *mychip; 1039 struct Nand *mychip;
1039 1040
1040 down(&this->lock); 1041 mutex_lock(&this->lock);
1041 1042
1042 mychip = &this->chips[ofs >> this->chipshift]; 1043 mychip = &this->chips[ofs >> this->chipshift];
1043 1044
@@ -1083,7 +1084,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
1083 1084
1084 ret = DoC_WaitReady(this); 1085 ret = DoC_WaitReady(this);
1085 1086
1086 up(&this->lock); 1087 mutex_unlock(&this->lock);
1087 return ret; 1088 return ret;
1088 1089
1089} 1090}
@@ -1197,10 +1198,10 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, size_t len,
1197 struct DiskOnChip *this = mtd->priv; 1198 struct DiskOnChip *this = mtd->priv;
1198 int ret; 1199 int ret;
1199 1200
1200 down(&this->lock); 1201 mutex_lock(&this->lock);
1201 ret = doc_write_oob_nolock(mtd, ofs, len, retlen, buf); 1202 ret = doc_write_oob_nolock(mtd, ofs, len, retlen, buf);
1202 1203
1203 up(&this->lock); 1204 mutex_unlock(&this->lock);
1204 return ret; 1205 return ret;
1205} 1206}
1206 1207
@@ -1214,10 +1215,10 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
1214 struct Nand *mychip; 1215 struct Nand *mychip;
1215 int status; 1216 int status;
1216 1217
1217 down(&this->lock); 1218 mutex_lock(&this->lock);
1218 1219
1219 if (ofs & (mtd->erasesize-1) || len & (mtd->erasesize-1)) { 1220 if (ofs & (mtd->erasesize-1) || len & (mtd->erasesize-1)) {
1220 up(&this->lock); 1221 mutex_unlock(&this->lock);
1221 return -EINVAL; 1222 return -EINVAL;
1222 } 1223 }
1223 1224
@@ -1265,7 +1266,7 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *instr)
1265 callback: 1266 callback:
1266 mtd_erase_callback(instr); 1267 mtd_erase_callback(instr);
1267 1268
1268 up(&this->lock); 1269 mutex_unlock(&this->lock);
1269 return 0; 1270 return 0;
1270} 1271}
1271 1272
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 1e876fcb0408..29b0ddaa324e 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -581,8 +581,6 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
581 581
582/***************************************************************************************************/ 582/***************************************************************************************************/
583 583
584#define NB_OF(x) (sizeof (x) / sizeof (x[0]))
585
586static struct mtd_info mtd; 584static struct mtd_info mtd;
587 585
588static struct mtd_erase_region_info erase_regions[] = { 586static struct mtd_erase_region_info erase_regions[] = {
@@ -640,7 +638,7 @@ int __init lart_flash_init (void)
640 mtd.flags = MTD_CAP_NORFLASH; 638 mtd.flags = MTD_CAP_NORFLASH;
641 mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN; 639 mtd.size = FLASH_BLOCKSIZE_PARAM * FLASH_NUMBLOCKS_16m_PARAM + FLASH_BLOCKSIZE_MAIN * FLASH_NUMBLOCKS_16m_MAIN;
642 mtd.erasesize = FLASH_BLOCKSIZE_MAIN; 640 mtd.erasesize = FLASH_BLOCKSIZE_MAIN;
643 mtd.numeraseregions = NB_OF (erase_regions); 641 mtd.numeraseregions = ARRAY_SIZE(erase_regions);
644 mtd.eraseregions = erase_regions; 642 mtd.eraseregions = erase_regions;
645 mtd.erase = flash_erase; 643 mtd.erase = flash_erase;
646 mtd.read = flash_read; 644 mtd.read = flash_read;
@@ -670,9 +668,9 @@ int __init lart_flash_init (void)
670 result,mtd.eraseregions[result].numblocks); 668 result,mtd.eraseregions[result].numblocks);
671 669
672#ifdef HAVE_PARTITIONS 670#ifdef HAVE_PARTITIONS
673 printk ("\npartitions = %d\n",NB_OF (lart_partitions)); 671 printk ("\npartitions = %d\n", ARRAY_SIZE(lart_partitions));
674 672
675 for (result = 0; result < NB_OF (lart_partitions); result++) 673 for (result = 0; result < ARRAY_SIZE(lart_partitions); result++)
676 printk (KERN_DEBUG 674 printk (KERN_DEBUG
677 "\n\n" 675 "\n\n"
678 "lart_partitions[%d].name = %s\n" 676 "lart_partitions[%d].name = %s\n"
@@ -687,7 +685,7 @@ int __init lart_flash_init (void)
687#ifndef HAVE_PARTITIONS 685#ifndef HAVE_PARTITIONS
688 result = add_mtd_device (&mtd); 686 result = add_mtd_device (&mtd);
689#else 687#else
690 result = add_mtd_partitions (&mtd,lart_partitions,NB_OF (lart_partitions)); 688 result = add_mtd_partitions (&mtd,lart_partitions, ARRAY_SIZE(lart_partitions));
691#endif 689#endif
692 690
693 return (result); 691 return (result);
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index d5f24089be71..04e65d5dae00 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -186,7 +186,7 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
186 struct m25p *flash = mtd_to_m25p(mtd); 186 struct m25p *flash = mtd_to_m25p(mtd);
187 u32 addr,len; 187 u32 addr,len;
188 188
189 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 189 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n",
190 flash->spi->dev.bus_id, __FUNCTION__, "at", 190 flash->spi->dev.bus_id, __FUNCTION__, "at",
191 (u32)instr->addr, instr->len); 191 (u32)instr->addr, instr->len);
192 192
diff --git a/drivers/mtd/devices/ms02-nv.c b/drivers/mtd/devices/ms02-nv.c
index 0ff2e4378244..485f663493d2 100644
--- a/drivers/mtd/devices/ms02-nv.c
+++ b/drivers/mtd/devices/ms02-nv.c
@@ -308,7 +308,7 @@ static int __init ms02nv_init(void)
308 break; 308 break;
309 } 309 }
310 310
311 for (i = 0; i < (sizeof(ms02nv_addrs) / sizeof(*ms02nv_addrs)); i++) 311 for (i = 0; i < ARRAY_SIZE(ms02nv_addrs); i++)
312 if (!ms02nv_init_one(ms02nv_addrs[i] << stride)) 312 if (!ms02nv_init_one(ms02nv_addrs[i] << stride))
313 count++; 313 count++;
314 314
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 8a544890173d..a3b92479719d 100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
@@ -47,9 +47,6 @@
47 */ 47 */
48#define MAX_LOOPS 10000 48#define MAX_LOOPS 10000
49 49
50extern void INFTL_dumptables(struct INFTLrecord *inftl);
51extern void INFTL_dumpVUchains(struct INFTLrecord *inftl);
52
53static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) 50static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
54{ 51{
55 struct INFTLrecord *inftl; 52 struct INFTLrecord *inftl;
@@ -132,7 +129,7 @@ static void inftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
132 return; 129 return;
133 } 130 }
134#ifdef PSYCHO_DEBUG 131#ifdef PSYCHO_DEBUG
135 printk(KERN_INFO "INFTL: Found new nftl%c\n", nftl->mbd.devnum + 'a'); 132 printk(KERN_INFO "INFTL: Found new inftl%c\n", inftl->mbd.devnum + 'a');
136#endif 133#endif
137 return; 134 return;
138} 135}
@@ -885,8 +882,6 @@ static struct mtd_blktrans_ops inftl_tr = {
885 .owner = THIS_MODULE, 882 .owner = THIS_MODULE,
886}; 883};
887 884
888extern char inftlmountrev[];
889
890static int __init init_inftl(void) 885static int __init init_inftl(void)
891{ 886{
892 printk(KERN_INFO "INFTL: inftlcore.c $Revision: 1.19 $, " 887 printk(KERN_INFO "INFTL: inftlcore.c $Revision: 1.19 $, "
diff --git a/drivers/mtd/maps/alchemy-flash.c b/drivers/mtd/maps/alchemy-flash.c
index a57791a6ce40..b933a2a27b18 100644
--- a/drivers/mtd/maps/alchemy-flash.c
+++ b/drivers/mtd/maps/alchemy-flash.c
@@ -126,8 +126,6 @@ static struct mtd_partition alchemy_partitions[] = {
126 } 126 }
127}; 127};
128 128
129#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
130
131static struct mtd_info *mymtd; 129static struct mtd_info *mymtd;
132 130
133int __init alchemy_mtd_init(void) 131int __init alchemy_mtd_init(void)
@@ -154,7 +152,7 @@ int __init alchemy_mtd_init(void)
154 * Static partition definition selection 152 * Static partition definition selection
155 */ 153 */
156 parts = alchemy_partitions; 154 parts = alchemy_partitions;
157 nb_parts = NB_OF(alchemy_partitions); 155 nb_parts = ARRAY_SIZE(alchemy_partitions);
158 alchemy_map.size = window_size; 156 alchemy_map.size = window_size;
159 157
160 /* 158 /*
diff --git a/drivers/mtd/maps/cfi_flagadm.c b/drivers/mtd/maps/cfi_flagadm.c
index 6a8c0415bde8..fd0f0d3187de 100644
--- a/drivers/mtd/maps/cfi_flagadm.c
+++ b/drivers/mtd/maps/cfi_flagadm.c
@@ -86,7 +86,7 @@ struct mtd_partition flagadm_parts[] = {
86 } 86 }
87}; 87};
88 88
89#define PARTITION_COUNT (sizeof(flagadm_parts)/sizeof(struct mtd_partition)) 89#define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
90 90
91static struct mtd_info *mymtd; 91static struct mtd_info *mymtd;
92 92
diff --git a/drivers/mtd/maps/dbox2-flash.c b/drivers/mtd/maps/dbox2-flash.c
index 49d90542fc75..652813cd6c2d 100644
--- a/drivers/mtd/maps/dbox2-flash.c
+++ b/drivers/mtd/maps/dbox2-flash.c
@@ -57,7 +57,7 @@ static struct mtd_partition partition_info[]= {
57 } 57 }
58}; 58};
59 59
60#define NUM_PARTITIONS (sizeof(partition_info) / sizeof(partition_info[0])) 60#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
61 61
62#define WINDOW_ADDR 0x10000000 62#define WINDOW_ADDR 0x10000000
63#define WINDOW_SIZE 0x800000 63#define WINDOW_SIZE 0x800000
diff --git a/drivers/mtd/maps/dilnetpc.c b/drivers/mtd/maps/dilnetpc.c
index efb221692641..c299d10b33e6 100644
--- a/drivers/mtd/maps/dilnetpc.c
+++ b/drivers/mtd/maps/dilnetpc.c
@@ -300,7 +300,7 @@ static struct mtd_partition partition_info[]=
300 }, 300 },
301}; 301};
302 302
303#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0])) 303#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
304 304
305static struct mtd_info *mymtd; 305static struct mtd_info *mymtd;
306static struct mtd_info *lowlvl_parts[NUM_PARTITIONS]; 306static struct mtd_info *lowlvl_parts[NUM_PARTITIONS];
@@ -345,7 +345,7 @@ static struct mtd_partition higlvl_partition_info[]=
345 }, 345 },
346}; 346};
347 347
348#define NUM_HIGHLVL_PARTITIONS (sizeof(higlvl_partition_info)/sizeof(partition_info[0])) 348#define NUM_HIGHLVL_PARTITIONS ARRAY_SIZE(higlvl_partition_info)
349 349
350 350
351static int dnp_adnp_probe(void) 351static int dnp_adnp_probe(void)
diff --git a/drivers/mtd/maps/dmv182.c b/drivers/mtd/maps/dmv182.c
index b993ac01a9a5..2bb3c0f0f970 100644
--- a/drivers/mtd/maps/dmv182.c
+++ b/drivers/mtd/maps/dmv182.c
@@ -99,7 +99,7 @@ static struct mtd_info *this_mtd;
99static int __init init_svme182(void) 99static int __init init_svme182(void)
100{ 100{
101 struct mtd_partition *partitions; 101 struct mtd_partition *partitions;
102 int num_parts = sizeof(svme182_partitions) / sizeof(struct mtd_partition); 102 int num_parts = ARRAY_SIZE(svme182_partitions);
103 103
104 partitions = svme182_partitions; 104 partitions = svme182_partitions;
105 105
diff --git a/drivers/mtd/maps/h720x-flash.c b/drivers/mtd/maps/h720x-flash.c
index 319094821101..0667101ccbe1 100644
--- a/drivers/mtd/maps/h720x-flash.c
+++ b/drivers/mtd/maps/h720x-flash.c
@@ -59,7 +59,7 @@ static struct mtd_partition h720x_partitions[] = {
59 } 59 }
60}; 60};
61 61
62#define NUM_PARTITIONS (sizeof(h720x_partitions)/sizeof(h720x_partitions[0])) 62#define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions)
63 63
64static int nr_mtd_parts; 64static int nr_mtd_parts;
65static struct mtd_partition *mtd_parts; 65static struct mtd_partition *mtd_parts;
diff --git a/drivers/mtd/maps/netsc520.c b/drivers/mtd/maps/netsc520.c
index 33060a315722..ed215470158b 100644
--- a/drivers/mtd/maps/netsc520.c
+++ b/drivers/mtd/maps/netsc520.c
@@ -76,7 +76,7 @@ static struct mtd_partition partition_info[]={
76 .size = 0x80000 76 .size = 0x80000
77 }, 77 },
78}; 78};
79#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0])) 79#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
80 80
81#define WINDOW_SIZE 0x00100000 81#define WINDOW_SIZE 0x00100000
82#define WINDOW_ADDR 0x00200000 82#define WINDOW_ADDR 0x00200000
@@ -88,7 +88,7 @@ static struct map_info netsc520_map = {
88 .phys = WINDOW_ADDR, 88 .phys = WINDOW_ADDR,
89}; 89};
90 90
91#define NUM_FLASH_BANKS (sizeof(netsc520_map)/sizeof(struct map_info)) 91#define NUM_FLASH_BANKS ARRAY_SIZE(netsc520_map)
92 92
93static struct mtd_info *mymtd; 93static struct mtd_info *mymtd;
94 94
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index 632eb2aa968f..54a3102ab19a 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -128,8 +128,7 @@ static struct mtd_partition nettel_amd_partitions[] = {
128 } 128 }
129}; 129};
130 130
131#define NUM_AMD_PARTITIONS \ 131#define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions)
132 (sizeof(nettel_amd_partitions)/sizeof(nettel_amd_partitions[0]))
133 132
134/****************************************************************************/ 133/****************************************************************************/
135 134
diff --git a/drivers/mtd/maps/ocotea.c b/drivers/mtd/maps/ocotea.c
index c223514ca2eb..a21fcd195ab4 100644
--- a/drivers/mtd/maps/ocotea.c
+++ b/drivers/mtd/maps/ocotea.c
@@ -58,8 +58,6 @@ static struct mtd_partition ocotea_large_partitions[] = {
58 } 58 }
59}; 59};
60 60
61#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
62
63int __init init_ocotea(void) 61int __init init_ocotea(void)
64{ 62{
65 u8 fpga0_reg; 63 u8 fpga0_reg;
@@ -97,7 +95,7 @@ int __init init_ocotea(void)
97 if (flash) { 95 if (flash) {
98 flash->owner = THIS_MODULE; 96 flash->owner = THIS_MODULE;
99 add_mtd_partitions(flash, ocotea_small_partitions, 97 add_mtd_partitions(flash, ocotea_small_partitions,
100 NB_OF(ocotea_small_partitions)); 98 ARRAY_SIZE(ocotea_small_partitions));
101 } else { 99 } else {
102 printk("map probe failed for flash\n"); 100 printk("map probe failed for flash\n");
103 return -ENXIO; 101 return -ENXIO;
@@ -118,7 +116,7 @@ int __init init_ocotea(void)
118 if (flash) { 116 if (flash) {
119 flash->owner = THIS_MODULE; 117 flash->owner = THIS_MODULE;
120 add_mtd_partitions(flash, ocotea_large_partitions, 118 add_mtd_partitions(flash, ocotea_large_partitions,
121 NB_OF(ocotea_large_partitions)); 119 ARRAY_SIZE(ocotea_large_partitions));
122 } else { 120 } else {
123 printk("map probe failed for flash\n"); 121 printk("map probe failed for flash\n");
124 return -ENXIO; 122 return -ENXIO;
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index 21822c2edbe4..d2ab1bae9c34 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -334,9 +334,6 @@ mtd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
334 return 0; 334 return 0;
335 335
336release: 336release:
337 if (mtd)
338 map_destroy(mtd);
339
340 if (map) { 337 if (map) {
341 map->exit(dev, map); 338 map->exit(dev, map);
342 kfree(map); 339 kfree(map);
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index f988c817e196..d27f4129afd3 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -54,7 +54,7 @@ static const int debug = 0;
54#define MAX_PCMCIA_ADDR 0x4000000 54#define MAX_PCMCIA_ADDR 0x4000000
55 55
56struct pcmciamtd_dev { 56struct pcmciamtd_dev {
57 dev_link_t link; /* PCMCIA link */ 57 struct pcmcia_device *p_dev;
58 dev_node_t node; /* device node */ 58 dev_node_t node; /* device node */
59 caddr_t win_base; /* ioremapped address of PCMCIA window */ 59 caddr_t win_base; /* ioremapped address of PCMCIA window */
60 unsigned int win_size; /* size of window */ 60 unsigned int win_size; /* size of window */
@@ -111,8 +111,8 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
111 memreq_t mrq; 111 memreq_t mrq;
112 int ret; 112 int ret;
113 113
114 if(!(dev->link.state & DEV_PRESENT)) { 114 if (!pcmcia_dev_present(dev->p_dev)) {
115 DEBUG(1, "device removed state = 0x%4.4X", dev->link.state); 115 DEBUG(1, "device removed");
116 return 0; 116 return 0;
117 } 117 }
118 118
@@ -122,7 +122,7 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
122 dev->offset, mrq.CardOffset); 122 dev->offset, mrq.CardOffset);
123 mrq.Page = 0; 123 mrq.Page = 0;
124 if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) { 124 if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) {
125 cs_error(dev->link.handle, MapMemPage, ret); 125 cs_error(dev->p_dev, MapMemPage, ret);
126 return NULL; 126 return NULL;
127 } 127 }
128 dev->offset = mrq.CardOffset; 128 dev->offset = mrq.CardOffset;
@@ -238,7 +238,7 @@ static void pcmcia_copy_to_remap(struct map_info *map, unsigned long to, const v
238 238
239/* read/write{8,16} copy_{from,to} routines with direct access */ 239/* read/write{8,16} copy_{from,to} routines with direct access */
240 240
241#define DEV_REMOVED(x) (!(*(u_int *)x->map_priv_1 & DEV_PRESENT)) 241#define DEV_REMOVED(x) (!(pcmcia_dev_present(((struct pcmciamtd_dev *)map->map_priv_1)->p_dev)))
242 242
243static map_word pcmcia_read8(struct map_info *map, unsigned long ofs) 243static map_word pcmcia_read8(struct map_info *map, unsigned long ofs)
244{ 244{
@@ -319,7 +319,7 @@ static void pcmcia_copy_to(struct map_info *map, unsigned long to, const void *f
319static void pcmciamtd_set_vpp(struct map_info *map, int on) 319static void pcmciamtd_set_vpp(struct map_info *map, int on)
320{ 320{
321 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 321 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
322 dev_link_t *link = &dev->link; 322 struct pcmcia_device *link = dev->p_dev;
323 modconf_t mod; 323 modconf_t mod;
324 int ret; 324 int ret;
325 325
@@ -328,9 +328,9 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
328 mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0; 328 mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0;
329 329
330 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); 330 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
331 ret = pcmcia_modify_configuration(link->handle, &mod); 331 ret = pcmcia_modify_configuration(link, &mod);
332 if(ret != CS_SUCCESS) { 332 if(ret != CS_SUCCESS) {
333 cs_error(link->handle, ModifyConfiguration, ret); 333 cs_error(link, ModifyConfiguration, ret);
334 } 334 }
335} 335}
336 336
@@ -340,7 +340,7 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
340 * still open, this will be postponed until it is closed. 340 * still open, this will be postponed until it is closed.
341 */ 341 */
342 342
343static void pcmciamtd_release(dev_link_t *link) 343static void pcmciamtd_release(struct pcmcia_device *link)
344{ 344{
345 struct pcmciamtd_dev *dev = link->priv; 345 struct pcmciamtd_dev *dev = link->priv;
346 346
@@ -353,12 +353,11 @@ static void pcmciamtd_release(dev_link_t *link)
353 } 353 }
354 pcmcia_release_window(link->win); 354 pcmcia_release_window(link->win);
355 } 355 }
356 pcmcia_release_configuration(link->handle); 356 pcmcia_disable_device(link);
357 link->state &= ~DEV_CONFIG;
358} 357}
359 358
360 359
361static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_name) 360static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link, int *new_name)
362{ 361{
363 int rc; 362 int rc;
364 tuple_t tuple; 363 tuple_t tuple;
@@ -371,16 +370,16 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
371 tuple.TupleOffset = 0; 370 tuple.TupleOffset = 0;
372 tuple.DesiredTuple = RETURN_FIRST_TUPLE; 371 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
373 372
374 rc = pcmcia_get_first_tuple(link->handle, &tuple); 373 rc = pcmcia_get_first_tuple(link, &tuple);
375 while(rc == CS_SUCCESS) { 374 while(rc == CS_SUCCESS) {
376 rc = pcmcia_get_tuple_data(link->handle, &tuple); 375 rc = pcmcia_get_tuple_data(link, &tuple);
377 if(rc != CS_SUCCESS) { 376 if(rc != CS_SUCCESS) {
378 cs_error(link->handle, GetTupleData, rc); 377 cs_error(link, GetTupleData, rc);
379 break; 378 break;
380 } 379 }
381 rc = pcmcia_parse_tuple(link->handle, &tuple, &parse); 380 rc = pcmcia_parse_tuple(link, &tuple, &parse);
382 if(rc != CS_SUCCESS) { 381 if(rc != CS_SUCCESS) {
383 cs_error(link->handle, ParseTuple, rc); 382 cs_error(link, ParseTuple, rc);
384 break; 383 break;
385 } 384 }
386 385
@@ -451,7 +450,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
451 DEBUG(2, "Unknown tuple code %d", tuple.TupleCode); 450 DEBUG(2, "Unknown tuple code %d", tuple.TupleCode);
452 } 451 }
453 452
454 rc = pcmcia_get_next_tuple(link->handle, &tuple); 453 rc = pcmcia_get_next_tuple(link, &tuple);
455 } 454 }
456 if(!dev->pcmcia_map.size) 455 if(!dev->pcmcia_map.size)
457 dev->pcmcia_map.size = MAX_PCMCIA_ADDR; 456 dev->pcmcia_map.size = MAX_PCMCIA_ADDR;
@@ -488,7 +487,7 @@ static void card_settings(struct pcmciamtd_dev *dev, dev_link_t *link, int *new_
488#define CS_CHECK(fn, ret) \ 487#define CS_CHECK(fn, ret) \
489do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 488do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
490 489
491static void pcmciamtd_config(dev_link_t *link) 490static int pcmciamtd_config(struct pcmcia_device *link)
492{ 491{
493 struct pcmciamtd_dev *dev = link->priv; 492 struct pcmciamtd_dev *dev = link->priv;
494 struct mtd_info *mtd = NULL; 493 struct mtd_info *mtd = NULL;
@@ -504,13 +503,10 @@ static void pcmciamtd_config(dev_link_t *link)
504 503
505 DEBUG(3, "link=0x%p", link); 504 DEBUG(3, "link=0x%p", link);
506 505
507 /* Configure card */
508 link->state |= DEV_CONFIG;
509
510 DEBUG(2, "Validating CIS"); 506 DEBUG(2, "Validating CIS");
511 ret = pcmcia_validate_cis(link->handle, &cisinfo); 507 ret = pcmcia_validate_cis(link, &cisinfo);
512 if(ret != CS_SUCCESS) { 508 if(ret != CS_SUCCESS) {
513 cs_error(link->handle, GetTupleData, ret); 509 cs_error(link, GetTupleData, ret);
514 } else { 510 } else {
515 DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains); 511 DEBUG(2, "ValidateCIS found %d chains", cisinfo.Chains);
516 } 512 }
@@ -538,7 +534,7 @@ static void pcmciamtd_config(dev_link_t *link)
538 req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16; 534 req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16;
539 req.Base = 0; 535 req.Base = 0;
540 req.AccessSpeed = mem_speed; 536 req.AccessSpeed = mem_speed;
541 link->win = (window_handle_t)link->handle; 537 link->win = (window_handle_t)link;
542 req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR; 538 req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR;
543 dev->win_size = 0; 539 dev->win_size = 0;
544 540
@@ -546,7 +542,7 @@ static void pcmciamtd_config(dev_link_t *link)
546 int ret; 542 int ret;
547 DEBUG(2, "requesting window with size = %dKiB memspeed = %d", 543 DEBUG(2, "requesting window with size = %dKiB memspeed = %d",
548 req.Size >> 10, req.AccessSpeed); 544 req.Size >> 10, req.AccessSpeed);
549 ret = pcmcia_request_window(&link->handle, &req, &link->win); 545 ret = pcmcia_request_window(&link, &req, &link->win);
550 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); 546 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size);
551 if(ret) { 547 if(ret) {
552 req.Size >>= 1; 548 req.Size >>= 1;
@@ -562,19 +558,19 @@ static void pcmciamtd_config(dev_link_t *link)
562 if(!dev->win_size) { 558 if(!dev->win_size) {
563 err("Cant allocate memory window"); 559 err("Cant allocate memory window");
564 pcmciamtd_release(link); 560 pcmciamtd_release(link);
565 return; 561 return -ENODEV;
566 } 562 }
567 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); 563 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
568 564
569 /* Get write protect status */ 565 /* Get write protect status */
570 CS_CHECK(GetStatus, pcmcia_get_status(link->handle, &status)); 566 CS_CHECK(GetStatus, pcmcia_get_status(link, &status));
571 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx", 567 DEBUG(2, "status value: 0x%x window handle = 0x%8.8lx",
572 status.CardState, (unsigned long)link->win); 568 status.CardState, (unsigned long)link->win);
573 dev->win_base = ioremap(req.Base, req.Size); 569 dev->win_base = ioremap(req.Base, req.Size);
574 if(!dev->win_base) { 570 if(!dev->win_base) {
575 err("ioremap(%lu, %u) failed", req.Base, req.Size); 571 err("ioremap(%lu, %u) failed", req.Base, req.Size);
576 pcmciamtd_release(link); 572 pcmciamtd_release(link);
577 return; 573 return -ENODEV;
578 } 574 }
579 DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x", 575 DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x",
580 dev, req.Base, dev->win_base, req.Size); 576 dev, req.Base, dev->win_base, req.Size);
@@ -584,17 +580,14 @@ static void pcmciamtd_config(dev_link_t *link)
584 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win; 580 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win;
585 581
586 DEBUG(2, "Getting configuration"); 582 DEBUG(2, "Getting configuration");
587 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link->handle, &t)); 583 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &t));
588 DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2); 584 DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2);
589 dev->vpp = (vpp) ? vpp : t.Vpp1; 585 dev->vpp = (vpp) ? vpp : t.Vpp1;
590 link->conf.Attributes = 0; 586 link->conf.Attributes = 0;
591 link->conf.Vcc = t.Vcc;
592 if(setvpp == 2) { 587 if(setvpp == 2) {
593 link->conf.Vpp1 = dev->vpp; 588 link->conf.Vpp = dev->vpp;
594 link->conf.Vpp2 = dev->vpp;
595 } else { 589 } else {
596 link->conf.Vpp1 = 0; 590 link->conf.Vpp = 0;
597 link->conf.Vpp2 = 0;
598 } 591 }
599 592
600 link->conf.IntType = INT_MEMORY; 593 link->conf.IntType = INT_MEMORY;
@@ -606,9 +599,10 @@ static void pcmciamtd_config(dev_link_t *link)
606 link->conf.ConfigIndex = 0; 599 link->conf.ConfigIndex = 0;
607 link->conf.Present = t.Present; 600 link->conf.Present = t.Present;
608 DEBUG(2, "Setting Configuration"); 601 DEBUG(2, "Setting Configuration");
609 ret = pcmcia_request_configuration(link->handle, &link->conf); 602 ret = pcmcia_request_configuration(link, &link->conf);
610 if(ret != CS_SUCCESS) { 603 if(ret != CS_SUCCESS) {
611 cs_error(link->handle, RequestConfiguration, ret); 604 cs_error(link, RequestConfiguration, ret);
605 return -ENODEV;
612 } 606 }
613 607
614 if(mem_type == 1) { 608 if(mem_type == 1) {
@@ -616,7 +610,7 @@ static void pcmciamtd_config(dev_link_t *link)
616 } else if(mem_type == 2) { 610 } else if(mem_type == 2) {
617 mtd = do_map_probe("map_rom", &dev->pcmcia_map); 611 mtd = do_map_probe("map_rom", &dev->pcmcia_map);
618 } else { 612 } else {
619 for(i = 0; i < sizeof(probes) / sizeof(char *); i++) { 613 for(i = 0; i < ARRAY_SIZE(probes); i++) {
620 DEBUG(1, "Trying %s", probes[i]); 614 DEBUG(1, "Trying %s", probes[i]);
621 mtd = do_map_probe(probes[i], &dev->pcmcia_map); 615 mtd = do_map_probe(probes[i], &dev->pcmcia_map);
622 if(mtd) 616 if(mtd)
@@ -629,7 +623,7 @@ static void pcmciamtd_config(dev_link_t *link)
629 if(!mtd) { 623 if(!mtd) {
630 DEBUG(1, "Cant find an MTD"); 624 DEBUG(1, "Cant find an MTD");
631 pcmciamtd_release(link); 625 pcmciamtd_release(link);
632 return; 626 return -ENODEV;
633 } 627 }
634 628
635 dev->mtd_info = mtd; 629 dev->mtd_info = mtd;
@@ -654,7 +648,6 @@ static void pcmciamtd_config(dev_link_t *link)
654 use the faster non-remapping read/write functions */ 648 use the faster non-remapping read/write functions */
655 if(mtd->size <= dev->win_size) { 649 if(mtd->size <= dev->win_size) {
656 DEBUG(1, "Using non remapping memory functions"); 650 DEBUG(1, "Using non remapping memory functions");
657 dev->pcmcia_map.map_priv_1 = (unsigned long)&(dev->link.state);
658 dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base; 651 dev->pcmcia_map.map_priv_2 = (unsigned long)dev->win_base;
659 if (dev->pcmcia_map.bankwidth == 1) { 652 if (dev->pcmcia_map.bankwidth == 1) {
660 dev->pcmcia_map.read = pcmcia_read8; 653 dev->pcmcia_map.read = pcmcia_read8;
@@ -672,19 +665,18 @@ static void pcmciamtd_config(dev_link_t *link)
672 dev->mtd_info = NULL; 665 dev->mtd_info = NULL;
673 err("Couldnt register MTD device"); 666 err("Couldnt register MTD device");
674 pcmciamtd_release(link); 667 pcmciamtd_release(link);
675 return; 668 return -ENODEV;
676 } 669 }
677 snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index); 670 snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index);
678 info("mtd%d: %s", mtd->index, mtd->name); 671 info("mtd%d: %s", mtd->index, mtd->name);
679 link->state &= ~DEV_CONFIG_PENDING; 672 link->dev_node = &dev->node;
680 link->dev = &dev->node; 673 return 0;
681 return;
682 674
683 cs_failed: 675 cs_failed:
684 cs_error(link->handle, last_fn, last_ret); 676 cs_error(link, last_fn, last_ret);
685 err("CS Error, exiting"); 677 err("CS Error, exiting");
686 pcmciamtd_release(link); 678 pcmciamtd_release(link);
687 return; 679 return -ENODEV;
688} 680}
689 681
690 682
@@ -713,21 +705,18 @@ static int pcmciamtd_resume(struct pcmcia_device *dev)
713 * when the device is released. 705 * when the device is released.
714 */ 706 */
715 707
716static void pcmciamtd_detach(struct pcmcia_device *p_dev) 708static void pcmciamtd_detach(struct pcmcia_device *link)
717{ 709{
718 dev_link_t *link = dev_to_instance(p_dev); 710 struct pcmciamtd_dev *dev = link->priv;
719 711
720 DEBUG(3, "link=0x%p", link); 712 DEBUG(3, "link=0x%p", link);
721 713
722 if(link->state & DEV_CONFIG) { 714 if(dev->mtd_info) {
723 struct pcmciamtd_dev *dev = link->priv; 715 del_mtd_device(dev->mtd_info);
724 if(dev->mtd_info) { 716 info("mtd%d: Removed", dev->mtd_info->index);
725 del_mtd_device(dev->mtd_info);
726 info("mtd%d: Removed", dev->mtd_info->index);
727 }
728
729 pcmciamtd_release(link);
730 } 717 }
718
719 pcmciamtd_release(link);
731} 720}
732 721
733 722
@@ -736,10 +725,9 @@ static void pcmciamtd_detach(struct pcmcia_device *p_dev)
736 * with Card Services. 725 * with Card Services.
737 */ 726 */
738 727
739static int pcmciamtd_attach(struct pcmcia_device *p_dev) 728static int pcmciamtd_probe(struct pcmcia_device *link)
740{ 729{
741 struct pcmciamtd_dev *dev; 730 struct pcmciamtd_dev *dev;
742 dev_link_t *link;
743 731
744 /* Create new memory card device */ 732 /* Create new memory card device */
745 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 733 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
@@ -747,20 +735,13 @@ static int pcmciamtd_attach(struct pcmcia_device *p_dev)
747 DEBUG(1, "dev=0x%p", dev); 735 DEBUG(1, "dev=0x%p", dev);
748 736
749 memset(dev, 0, sizeof(*dev)); 737 memset(dev, 0, sizeof(*dev));
750 link = &dev->link; 738 dev->p_dev = link;
751 link->priv = dev; 739 link->priv = dev;
752 740
753 link->conf.Attributes = 0; 741 link->conf.Attributes = 0;
754 link->conf.IntType = INT_MEMORY; 742 link->conf.IntType = INT_MEMORY;
755 743
756 link->next = NULL; 744 return pcmciamtd_config(link);
757 link->handle = p_dev;
758 p_dev->instance = link;
759
760 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
761 pcmciamtd_config(link);
762
763 return 0;
764} 745}
765 746
766static struct pcmcia_device_id pcmciamtd_ids[] = { 747static struct pcmcia_device_id pcmciamtd_ids[] = {
@@ -794,7 +775,7 @@ static struct pcmcia_driver pcmciamtd_driver = {
794 .drv = { 775 .drv = {
795 .name = "pcmciamtd" 776 .name = "pcmciamtd"
796 }, 777 },
797 .probe = pcmciamtd_attach, 778 .probe = pcmciamtd_probe,
798 .remove = pcmciamtd_detach, 779 .remove = pcmciamtd_detach,
799 .owner = THIS_MODULE, 780 .owner = THIS_MODULE,
800 .id_table = pcmciamtd_ids, 781 .id_table = pcmciamtd_ids,
diff --git a/drivers/mtd/maps/redwood.c b/drivers/mtd/maps/redwood.c
index 5b76ed886185..50b14033613f 100644
--- a/drivers/mtd/maps/redwood.c
+++ b/drivers/mtd/maps/redwood.c
@@ -121,8 +121,7 @@ struct map_info redwood_flash_map = {
121}; 121};
122 122
123 123
124#define NUM_REDWOOD_FLASH_PARTITIONS \ 124#define NUM_REDWOOD_FLASH_PARTITIONS ARRAY_SIZE(redwood_flash_partitions)
125 (sizeof(redwood_flash_partitions)/sizeof(redwood_flash_partitions[0]))
126 125
127static struct mtd_info *redwood_mtd; 126static struct mtd_info *redwood_mtd;
128 127
diff --git a/drivers/mtd/maps/sbc8240.c b/drivers/mtd/maps/sbc8240.c
index 225cdd9ba5b2..350286dc1d2e 100644
--- a/drivers/mtd/maps/sbc8240.c
+++ b/drivers/mtd/maps/sbc8240.c
@@ -66,7 +66,7 @@ static struct map_info sbc8240_map[2] = {
66 } 66 }
67}; 67};
68 68
69#define NUM_FLASH_BANKS (sizeof(sbc8240_map) / sizeof(struct map_info)) 69#define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)
70 70
71/* 71/*
72 * The following defines the partition layout of SBC8240 boards. 72 * The following defines the partition layout of SBC8240 boards.
@@ -125,8 +125,6 @@ static struct mtd_partition sbc8240_fs_partitions [] = {
125 } 125 }
126}; 126};
127 127
128#define NB_OF(x) (sizeof (x) / sizeof (x[0]))
129
130/* trivial struct to describe partition information */ 128/* trivial struct to describe partition information */
131struct mtd_part_def 129struct mtd_part_def
132{ 130{
@@ -190,10 +188,10 @@ int __init init_sbc8240_mtd (void)
190#ifdef CONFIG_MTD_PARTITIONS 188#ifdef CONFIG_MTD_PARTITIONS
191 sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions; 189 sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions;
192 sbc8240_part_banks[0].type = "static image"; 190 sbc8240_part_banks[0].type = "static image";
193 sbc8240_part_banks[0].nums = NB_OF(sbc8240_uboot_partitions); 191 sbc8240_part_banks[0].nums = ARRAY_SIZE(sbc8240_uboot_partitions);
194 sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions; 192 sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions;
195 sbc8240_part_banks[1].type = "static file system"; 193 sbc8240_part_banks[1].type = "static file system";
196 sbc8240_part_banks[1].nums = NB_OF(sbc8240_fs_partitions); 194 sbc8240_part_banks[1].nums = ARRAY_SIZE(sbc8240_fs_partitions);
197 195
198 for (i = 0; i < NUM_FLASH_BANKS; i++) { 196 for (i = 0; i < NUM_FLASH_BANKS; i++) {
199 197
diff --git a/drivers/mtd/maps/sc520cdp.c b/drivers/mtd/maps/sc520cdp.c
index ed92afadd8a9..e8c130e1efd3 100644
--- a/drivers/mtd/maps/sc520cdp.c
+++ b/drivers/mtd/maps/sc520cdp.c
@@ -107,7 +107,7 @@ static struct map_info sc520cdp_map[] = {
107 }, 107 },
108}; 108};
109 109
110#define NUM_FLASH_BANKS (sizeof(sc520cdp_map)/sizeof(struct map_info)) 110#define NUM_FLASH_BANKS ARRAY_SIZE(sc520cdp_map)
111 111
112static struct mtd_info *mymtd[NUM_FLASH_BANKS]; 112static struct mtd_info *mymtd[NUM_FLASH_BANKS];
113static struct mtd_info *merged_mtd; 113static struct mtd_info *merged_mtd;
diff --git a/drivers/mtd/maps/scx200_docflash.c b/drivers/mtd/maps/scx200_docflash.c
index 2c91dff8bb60..28b8a571a91a 100644
--- a/drivers/mtd/maps/scx200_docflash.c
+++ b/drivers/mtd/maps/scx200_docflash.c
@@ -70,7 +70,7 @@ static struct mtd_partition partition_info[] = {
70 .size = 0x80000 70 .size = 0x80000
71 }, 71 },
72}; 72};
73#define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0])) 73#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
74#endif 74#endif
75 75
76 76
diff --git a/drivers/mtd/maps/sharpsl-flash.c b/drivers/mtd/maps/sharpsl-flash.c
index 999f4bb3d845..12fe53c0d2fc 100644
--- a/drivers/mtd/maps/sharpsl-flash.c
+++ b/drivers/mtd/maps/sharpsl-flash.c
@@ -49,8 +49,6 @@ static struct mtd_partition sharpsl_partitions[1] = {
49 } 49 }
50}; 50};
51 51
52#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
53
54int __init init_sharpsl(void) 52int __init init_sharpsl(void)
55{ 53{
56 struct mtd_partition *parts; 54 struct mtd_partition *parts;
@@ -92,7 +90,7 @@ int __init init_sharpsl(void)
92 } 90 }
93 91
94 parts = sharpsl_partitions; 92 parts = sharpsl_partitions;
95 nb_parts = NB_OF(sharpsl_partitions); 93 nb_parts = ARRAY_SIZE(sharpsl_partitions);
96 94
97 printk(KERN_NOTICE "Using %s partision definition\n", part_type); 95 printk(KERN_NOTICE "Using %s partision definition\n", part_type);
98 add_mtd_partitions(mymtd, parts, nb_parts); 96 add_mtd_partitions(mymtd, parts, nb_parts);
diff --git a/drivers/mtd/maps/ts5500_flash.c b/drivers/mtd/maps/ts5500_flash.c
index 4b372bcb17f1..a7422c200567 100644
--- a/drivers/mtd/maps/ts5500_flash.c
+++ b/drivers/mtd/maps/ts5500_flash.c
@@ -64,7 +64,7 @@ static struct mtd_partition ts5500_partitions[] = {
64 } 64 }
65}; 65};
66 66
67#define NUM_PARTITIONS (sizeof(ts5500_partitions)/sizeof(struct mtd_partition)) 67#define NUM_PARTITIONS ARRAY_SIZE(ts5500_partitions)
68 68
69static struct mtd_info *mymtd; 69static struct mtd_info *mymtd;
70 70
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c
index 79d92808b766..f7264dc2ac9b 100644
--- a/drivers/mtd/maps/uclinux.c
+++ b/drivers/mtd/maps/uclinux.c
@@ -37,7 +37,7 @@ struct mtd_partition uclinux_romfs[] = {
37 { .name = "ROMfs" } 37 { .name = "ROMfs" }
38}; 38};
39 39
40#define NUM_PARTITIONS (sizeof(uclinux_romfs) / sizeof(uclinux_romfs[0])) 40#define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
41 41
42/****************************************************************************/ 42/****************************************************************************/
43 43
diff --git a/drivers/mtd/maps/vmax301.c b/drivers/mtd/maps/vmax301.c
index e0063941c0df..b3e487395435 100644
--- a/drivers/mtd/maps/vmax301.c
+++ b/drivers/mtd/maps/vmax301.c
@@ -182,7 +182,7 @@ int __init init_vmax301(void)
182 } 182 }
183 } 183 }
184 184
185 if (!vmax_mtd[1] && !vmax_mtd[2]) { 185 if (!vmax_mtd[0] && !vmax_mtd[1]) {
186 iounmap((void *)iomapadr); 186 iounmap((void *)iomapadr);
187 return -ENXIO; 187 return -ENXIO;
188 } 188 }
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 840dd66ce2dc..458d3c8ae1ee 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -19,12 +19,12 @@
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/hdreg.h> 20#include <linux/hdreg.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <asm/semaphore.h> 22#include <linux/mutex.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24 24
25static LIST_HEAD(blktrans_majors); 25static LIST_HEAD(blktrans_majors);
26 26
27extern struct semaphore mtd_table_mutex; 27extern struct mutex mtd_table_mutex;
28extern struct mtd_info *mtd_table[]; 28extern struct mtd_info *mtd_table[];
29 29
30struct mtd_blkcore_priv { 30struct mtd_blkcore_priv {
@@ -122,9 +122,9 @@ static int mtd_blktrans_thread(void *arg)
122 122
123 spin_unlock_irq(rq->queue_lock); 123 spin_unlock_irq(rq->queue_lock);
124 124
125 down(&dev->sem); 125 mutex_lock(&dev->lock);
126 res = do_blktrans_request(tr, dev, req); 126 res = do_blktrans_request(tr, dev, req);
127 up(&dev->sem); 127 mutex_unlock(&dev->lock);
128 128
129 spin_lock_irq(rq->queue_lock); 129 spin_lock_irq(rq->queue_lock);
130 130
@@ -235,8 +235,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
235 int last_devnum = -1; 235 int last_devnum = -1;
236 struct gendisk *gd; 236 struct gendisk *gd;
237 237
238 if (!down_trylock(&mtd_table_mutex)) { 238 if (!!mutex_trylock(&mtd_table_mutex)) {
239 up(&mtd_table_mutex); 239 mutex_unlock(&mtd_table_mutex);
240 BUG(); 240 BUG();
241 } 241 }
242 242
@@ -267,7 +267,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
267 return -EBUSY; 267 return -EBUSY;
268 } 268 }
269 269
270 init_MUTEX(&new->sem); 270 mutex_init(&new->lock);
271 list_add_tail(&new->list, &tr->devs); 271 list_add_tail(&new->list, &tr->devs);
272 added: 272 added:
273 if (!tr->writesect) 273 if (!tr->writesect)
@@ -313,8 +313,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
313 313
314int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old) 314int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
315{ 315{
316 if (!down_trylock(&mtd_table_mutex)) { 316 if (!!mutex_trylock(&mtd_table_mutex)) {
317 up(&mtd_table_mutex); 317 mutex_unlock(&mtd_table_mutex);
318 BUG(); 318 BUG();
319 } 319 }
320 320
@@ -378,14 +378,14 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
378 378
379 memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv)); 379 memset(tr->blkcore_priv, 0, sizeof(*tr->blkcore_priv));
380 380
381 down(&mtd_table_mutex); 381 mutex_lock(&mtd_table_mutex);
382 382
383 ret = register_blkdev(tr->major, tr->name); 383 ret = register_blkdev(tr->major, tr->name);
384 if (ret) { 384 if (ret) {
385 printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n", 385 printk(KERN_WARNING "Unable to register %s block device on major %d: %d\n",
386 tr->name, tr->major, ret); 386 tr->name, tr->major, ret);
387 kfree(tr->blkcore_priv); 387 kfree(tr->blkcore_priv);
388 up(&mtd_table_mutex); 388 mutex_unlock(&mtd_table_mutex);
389 return ret; 389 return ret;
390 } 390 }
391 spin_lock_init(&tr->blkcore_priv->queue_lock); 391 spin_lock_init(&tr->blkcore_priv->queue_lock);
@@ -396,7 +396,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
396 if (!tr->blkcore_priv->rq) { 396 if (!tr->blkcore_priv->rq) {
397 unregister_blkdev(tr->major, tr->name); 397 unregister_blkdev(tr->major, tr->name);
398 kfree(tr->blkcore_priv); 398 kfree(tr->blkcore_priv);
399 up(&mtd_table_mutex); 399 mutex_unlock(&mtd_table_mutex);
400 return -ENOMEM; 400 return -ENOMEM;
401 } 401 }
402 402
@@ -407,7 +407,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
407 blk_cleanup_queue(tr->blkcore_priv->rq); 407 blk_cleanup_queue(tr->blkcore_priv->rq);
408 unregister_blkdev(tr->major, tr->name); 408 unregister_blkdev(tr->major, tr->name);
409 kfree(tr->blkcore_priv); 409 kfree(tr->blkcore_priv);
410 up(&mtd_table_mutex); 410 mutex_unlock(&mtd_table_mutex);
411 return ret; 411 return ret;
412 } 412 }
413 413
@@ -419,7 +419,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
419 tr->add_mtd(tr, mtd_table[i]); 419 tr->add_mtd(tr, mtd_table[i]);
420 } 420 }
421 421
422 up(&mtd_table_mutex); 422 mutex_unlock(&mtd_table_mutex);
423 423
424 return 0; 424 return 0;
425} 425}
@@ -428,7 +428,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
428{ 428{
429 struct list_head *this, *next; 429 struct list_head *this, *next;
430 430
431 down(&mtd_table_mutex); 431 mutex_lock(&mtd_table_mutex);
432 432
433 /* Clean up the kernel thread */ 433 /* Clean up the kernel thread */
434 tr->blkcore_priv->exiting = 1; 434 tr->blkcore_priv->exiting = 1;
@@ -446,7 +446,7 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
446 blk_cleanup_queue(tr->blkcore_priv->rq); 446 blk_cleanup_queue(tr->blkcore_priv->rq);
447 unregister_blkdev(tr->major, tr->name); 447 unregister_blkdev(tr->major, tr->name);
448 448
449 up(&mtd_table_mutex); 449 mutex_unlock(&mtd_table_mutex);
450 450
451 kfree(tr->blkcore_priv); 451 kfree(tr->blkcore_priv);
452 452
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index e84756644fd1..2cef280e388c 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -19,11 +19,13 @@
19 19
20#include <linux/mtd/mtd.h> 20#include <linux/mtd/mtd.h>
21#include <linux/mtd/blktrans.h> 21#include <linux/mtd/blktrans.h>
22#include <linux/mutex.h>
23
22 24
23static struct mtdblk_dev { 25static struct mtdblk_dev {
24 struct mtd_info *mtd; 26 struct mtd_info *mtd;
25 int count; 27 int count;
26 struct semaphore cache_sem; 28 struct mutex cache_mutex;
27 unsigned char *cache_data; 29 unsigned char *cache_data;
28 unsigned long cache_offset; 30 unsigned long cache_offset;
29 unsigned int cache_size; 31 unsigned int cache_size;
@@ -284,7 +286,7 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
284 mtdblk->count = 1; 286 mtdblk->count = 1;
285 mtdblk->mtd = mtd; 287 mtdblk->mtd = mtd;
286 288
287 init_MUTEX (&mtdblk->cache_sem); 289 mutex_init(&mtdblk->cache_mutex);
288 mtdblk->cache_state = STATE_EMPTY; 290 mtdblk->cache_state = STATE_EMPTY;
289 if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM && 291 if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM &&
290 mtdblk->mtd->erasesize) { 292 mtdblk->mtd->erasesize) {
@@ -306,9 +308,9 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd)
306 308
307 DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n"); 309 DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n");
308 310
309 down(&mtdblk->cache_sem); 311 mutex_lock(&mtdblk->cache_mutex);
310 write_cached_data(mtdblk); 312 write_cached_data(mtdblk);
311 up(&mtdblk->cache_sem); 313 mutex_unlock(&mtdblk->cache_mutex);
312 314
313 if (!--mtdblk->count) { 315 if (!--mtdblk->count) {
314 /* It was the last usage. Free the device */ 316 /* It was the last usage. Free the device */
@@ -327,9 +329,9 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
327{ 329{
328 struct mtdblk_dev *mtdblk = mtdblks[dev->devnum]; 330 struct mtdblk_dev *mtdblk = mtdblks[dev->devnum];
329 331
330 down(&mtdblk->cache_sem); 332 mutex_lock(&mtdblk->cache_mutex);
331 write_cached_data(mtdblk); 333 write_cached_data(mtdblk);
332 up(&mtdblk->cache_sem); 334 mutex_unlock(&mtdblk->cache_mutex);
333 335
334 if (mtdblk->mtd->sync) 336 if (mtdblk->mtd->sync)
335 mtdblk->mtd->sync(mtdblk->mtd); 337 mtdblk->mtd->sync(mtdblk->mtd);
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index dade02ab0687..9905870f56e5 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -19,15 +19,13 @@
19#include <linux/ioctl.h> 19#include <linux/ioctl.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/mtd/compatmac.h> 21#include <linux/mtd/compatmac.h>
22#ifdef CONFIG_PROC_FS
23#include <linux/proc_fs.h> 22#include <linux/proc_fs.h>
24#endif
25 23
26#include <linux/mtd/mtd.h> 24#include <linux/mtd/mtd.h>
27 25
28/* These are exported solely for the purpose of mtd_blkdevs.c. You 26/* These are exported solely for the purpose of mtd_blkdevs.c. You
29 should not use them for _anything_ else */ 27 should not use them for _anything_ else */
30DECLARE_MUTEX(mtd_table_mutex); 28DEFINE_MUTEX(mtd_table_mutex);
31struct mtd_info *mtd_table[MAX_MTD_DEVICES]; 29struct mtd_info *mtd_table[MAX_MTD_DEVICES];
32 30
33EXPORT_SYMBOL_GPL(mtd_table_mutex); 31EXPORT_SYMBOL_GPL(mtd_table_mutex);
@@ -49,7 +47,7 @@ int add_mtd_device(struct mtd_info *mtd)
49{ 47{
50 int i; 48 int i;
51 49
52 down(&mtd_table_mutex); 50 mutex_lock(&mtd_table_mutex);
53 51
54 for (i=0; i < MAX_MTD_DEVICES; i++) 52 for (i=0; i < MAX_MTD_DEVICES; i++)
55 if (!mtd_table[i]) { 53 if (!mtd_table[i]) {
@@ -67,7 +65,7 @@ int add_mtd_device(struct mtd_info *mtd)
67 not->add(mtd); 65 not->add(mtd);
68 } 66 }
69 67
70 up(&mtd_table_mutex); 68 mutex_unlock(&mtd_table_mutex);
71 /* We _know_ we aren't being removed, because 69 /* We _know_ we aren't being removed, because
72 our caller is still holding us here. So none 70 our caller is still holding us here. So none
73 of this try_ nonsense, and no bitching about it 71 of this try_ nonsense, and no bitching about it
@@ -76,7 +74,7 @@ int add_mtd_device(struct mtd_info *mtd)
76 return 0; 74 return 0;
77 } 75 }
78 76
79 up(&mtd_table_mutex); 77 mutex_unlock(&mtd_table_mutex);
80 return 1; 78 return 1;
81} 79}
82 80
@@ -94,7 +92,7 @@ int del_mtd_device (struct mtd_info *mtd)
94{ 92{
95 int ret; 93 int ret;
96 94
97 down(&mtd_table_mutex); 95 mutex_lock(&mtd_table_mutex);
98 96
99 if (mtd_table[mtd->index] != mtd) { 97 if (mtd_table[mtd->index] != mtd) {
100 ret = -ENODEV; 98 ret = -ENODEV;
@@ -118,7 +116,7 @@ int del_mtd_device (struct mtd_info *mtd)
118 ret = 0; 116 ret = 0;
119 } 117 }
120 118
121 up(&mtd_table_mutex); 119 mutex_unlock(&mtd_table_mutex);
122 return ret; 120 return ret;
123} 121}
124 122
@@ -135,7 +133,7 @@ void register_mtd_user (struct mtd_notifier *new)
135{ 133{
136 int i; 134 int i;
137 135
138 down(&mtd_table_mutex); 136 mutex_lock(&mtd_table_mutex);
139 137
140 list_add(&new->list, &mtd_notifiers); 138 list_add(&new->list, &mtd_notifiers);
141 139
@@ -145,7 +143,7 @@ void register_mtd_user (struct mtd_notifier *new)
145 if (mtd_table[i]) 143 if (mtd_table[i])
146 new->add(mtd_table[i]); 144 new->add(mtd_table[i]);
147 145
148 up(&mtd_table_mutex); 146 mutex_unlock(&mtd_table_mutex);
149} 147}
150 148
151/** 149/**
@@ -162,7 +160,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
162{ 160{
163 int i; 161 int i;
164 162
165 down(&mtd_table_mutex); 163 mutex_lock(&mtd_table_mutex);
166 164
167 module_put(THIS_MODULE); 165 module_put(THIS_MODULE);
168 166
@@ -171,7 +169,7 @@ int unregister_mtd_user (struct mtd_notifier *old)
171 old->remove(mtd_table[i]); 169 old->remove(mtd_table[i]);
172 170
173 list_del(&old->list); 171 list_del(&old->list);
174 up(&mtd_table_mutex); 172 mutex_unlock(&mtd_table_mutex);
175 return 0; 173 return 0;
176} 174}
177 175
@@ -193,7 +191,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
193 struct mtd_info *ret = NULL; 191 struct mtd_info *ret = NULL;
194 int i; 192 int i;
195 193
196 down(&mtd_table_mutex); 194 mutex_lock(&mtd_table_mutex);
197 195
198 if (num == -1) { 196 if (num == -1) {
199 for (i=0; i< MAX_MTD_DEVICES; i++) 197 for (i=0; i< MAX_MTD_DEVICES; i++)
@@ -211,7 +209,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num)
211 if (ret) 209 if (ret)
212 ret->usecount++; 210 ret->usecount++;
213 211
214 up(&mtd_table_mutex); 212 mutex_unlock(&mtd_table_mutex);
215 return ret; 213 return ret;
216} 214}
217 215
@@ -219,9 +217,9 @@ void put_mtd_device(struct mtd_info *mtd)
219{ 217{
220 int c; 218 int c;
221 219
222 down(&mtd_table_mutex); 220 mutex_lock(&mtd_table_mutex);
223 c = --mtd->usecount; 221 c = --mtd->usecount;
224 up(&mtd_table_mutex); 222 mutex_unlock(&mtd_table_mutex);
225 BUG_ON(c < 0); 223 BUG_ON(c < 0);
226 224
227 module_put(mtd->owner); 225 module_put(mtd->owner);
@@ -296,10 +294,11 @@ EXPORT_SYMBOL(unregister_mtd_user);
296EXPORT_SYMBOL(default_mtd_writev); 294EXPORT_SYMBOL(default_mtd_writev);
297EXPORT_SYMBOL(default_mtd_readv); 295EXPORT_SYMBOL(default_mtd_readv);
298 296
297#ifdef CONFIG_PROC_FS
298
299/*====================================================================*/ 299/*====================================================================*/
300/* Support for /proc/mtd */ 300/* Support for /proc/mtd */
301 301
302#ifdef CONFIG_PROC_FS
303static struct proc_dir_entry *proc_mtd; 302static struct proc_dir_entry *proc_mtd;
304 303
305static inline int mtd_proc_info (char *buf, int i) 304static inline int mtd_proc_info (char *buf, int i)
@@ -319,7 +318,7 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
319 int len, l, i; 318 int len, l, i;
320 off_t begin = 0; 319 off_t begin = 0;
321 320
322 down(&mtd_table_mutex); 321 mutex_lock(&mtd_table_mutex);
323 322
324 len = sprintf(page, "dev: size erasesize name\n"); 323 len = sprintf(page, "dev: size erasesize name\n");
325 for (i=0; i< MAX_MTD_DEVICES; i++) { 324 for (i=0; i< MAX_MTD_DEVICES; i++) {
@@ -337,38 +336,34 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
337 *eof = 1; 336 *eof = 1;
338 337
339done: 338done:
340 up(&mtd_table_mutex); 339 mutex_unlock(&mtd_table_mutex);
341 if (off >= len+begin) 340 if (off >= len+begin)
342 return 0; 341 return 0;
343 *start = page + (off-begin); 342 *start = page + (off-begin);
344 return ((count < begin+len-off) ? count : begin+len-off); 343 return ((count < begin+len-off) ? count : begin+len-off);
345} 344}
346 345
347#endif /* CONFIG_PROC_FS */
348
349/*====================================================================*/ 346/*====================================================================*/
350/* Init code */ 347/* Init code */
351 348
352static int __init init_mtd(void) 349static int __init init_mtd(void)
353{ 350{
354#ifdef CONFIG_PROC_FS
355 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 351 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
356 proc_mtd->read_proc = mtd_read_proc; 352 proc_mtd->read_proc = mtd_read_proc;
357#endif
358 return 0; 353 return 0;
359} 354}
360 355
361static void __exit cleanup_mtd(void) 356static void __exit cleanup_mtd(void)
362{ 357{
363#ifdef CONFIG_PROC_FS
364 if (proc_mtd) 358 if (proc_mtd)
365 remove_proc_entry( "mtd", NULL); 359 remove_proc_entry( "mtd", NULL);
366#endif
367} 360}
368 361
369module_init(init_mtd); 362module_init(init_mtd);
370module_exit(cleanup_mtd); 363module_exit(cleanup_mtd);
371 364
365#endif /* CONFIG_PROC_FS */
366
372 367
373MODULE_LICENSE("GPL"); 368MODULE_LICENSE("GPL");
374MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 369MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 1fc4c134d939..cfe288a6e853 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -178,17 +178,16 @@ config MTD_NAND_DISKONCHIP_BBTWRITE
178 Even if you leave this disabled, you can enable BBT writes at module 178 Even if you leave this disabled, you can enable BBT writes at module
179 load time (assuming you build diskonchip as a module) with the module 179 load time (assuming you build diskonchip as a module) with the module
180 parameter "inftl_bbt_write=1". 180 parameter "inftl_bbt_write=1".
181
182 config MTD_NAND_SHARPSL
183 bool "Support for NAND Flash on Sharp SL Series (C7xx + others)"
184 depends on MTD_NAND && ARCH_PXA
185
186 config MTD_NAND_NANDSIM
187 bool "Support for NAND Flash Simulator"
188 depends on MTD_NAND && MTD_PARTITIONS
189 181
182config MTD_NAND_SHARPSL
183 tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)"
184 depends on MTD_NAND && ARCH_PXA
185
186config MTD_NAND_NANDSIM
187 tristate "Support for NAND Flash Simulator"
188 depends on MTD_NAND && MTD_PARTITIONS
190 help 189 help
191 The simulator may simulate verious NAND flash chips for the 190 The simulator may simulate verious NAND flash chips for the
192 MTD nand layer. 191 MTD nand layer.
193 192
194endmenu 193endmenu
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 201e1362da14..bde3550910a2 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -55,8 +55,6 @@ static const struct mtd_partition partition_info[] = {
55 .size = MTDPART_SIZ_FULL 55 .size = MTDPART_SIZ_FULL
56 } 56 }
57}; 57};
58#define NB_OF(x) (sizeof(x)/sizeof(x[0]))
59
60 58
61/** 59/**
62 * au_read_byte - read one byte from the chip 60 * au_read_byte - read one byte from the chip
@@ -462,7 +460,7 @@ int __init au1xxx_nand_init (void)
462 } 460 }
463 461
464 /* Register the partitions */ 462 /* Register the partitions */
465 add_mtd_partitions(au1550_mtd, partition_info, NB_OF(partition_info)); 463 add_mtd_partitions(au1550_mtd, partition_info, ARRAY_SIZE(partition_info));
466 464
467 return 0; 465 return 0;
468 466
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5d222460b42a..95e96fa1fceb 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -80,6 +80,7 @@
80#include <linux/mtd/compatmac.h> 80#include <linux/mtd/compatmac.h>
81#include <linux/interrupt.h> 81#include <linux/interrupt.h>
82#include <linux/bitops.h> 82#include <linux/bitops.h>
83#include <linux/leds.h>
83#include <asm/io.h> 84#include <asm/io.h>
84 85
85#ifdef CONFIG_MTD_PARTITIONS 86#ifdef CONFIG_MTD_PARTITIONS
@@ -515,6 +516,8 @@ static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, i
515 return nand_isbad_bbt (mtd, ofs, allowbbt); 516 return nand_isbad_bbt (mtd, ofs, allowbbt);
516} 517}
517 518
519DEFINE_LED_TRIGGER(nand_led_trigger);
520
518/* 521/*
519 * Wait for the ready pin, after a command 522 * Wait for the ready pin, after a command
520 * The timeout is catched later. 523 * The timeout is catched later.
@@ -524,12 +527,14 @@ static void nand_wait_ready(struct mtd_info *mtd)
524 struct nand_chip *this = mtd->priv; 527 struct nand_chip *this = mtd->priv;
525 unsigned long timeo = jiffies + 2; 528 unsigned long timeo = jiffies + 2;
526 529
530 led_trigger_event(nand_led_trigger, LED_FULL);
527 /* wait until command is processed or timeout occures */ 531 /* wait until command is processed or timeout occures */
528 do { 532 do {
529 if (this->dev_ready(mtd)) 533 if (this->dev_ready(mtd))
530 return; 534 break;
531 touch_softlockup_watchdog(); 535 touch_softlockup_watchdog();
532 } while (time_before(jiffies, timeo)); 536 } while (time_before(jiffies, timeo));
537 led_trigger_event(nand_led_trigger, LED_OFF);
533} 538}
534 539
535/** 540/**
@@ -817,6 +822,8 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
817 else 822 else
818 timeo += (HZ * 20) / 1000; 823 timeo += (HZ * 20) / 1000;
819 824
825 led_trigger_event(nand_led_trigger, LED_FULL);
826
820 /* Apply this short delay always to ensure that we do wait tWB in 827 /* Apply this short delay always to ensure that we do wait tWB in
821 * any case on any machine. */ 828 * any case on any machine. */
822 ndelay (100); 829 ndelay (100);
@@ -840,6 +847,8 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
840 } 847 }
841 cond_resched(); 848 cond_resched();
842 } 849 }
850 led_trigger_event(nand_led_trigger, LED_OFF);
851
843 status = (int) this->read_byte(mtd); 852 status = (int) this->read_byte(mtd);
844 return status; 853 return status;
845} 854}
@@ -2724,6 +2733,21 @@ void nand_release (struct mtd_info *mtd)
2724EXPORT_SYMBOL_GPL (nand_scan); 2733EXPORT_SYMBOL_GPL (nand_scan);
2725EXPORT_SYMBOL_GPL (nand_release); 2734EXPORT_SYMBOL_GPL (nand_release);
2726 2735
2736
2737static int __init nand_base_init(void)
2738{
2739 led_trigger_register_simple("nand-disk", &nand_led_trigger);
2740 return 0;
2741}
2742
2743static void __exit nand_base_exit(void)
2744{
2745 led_trigger_unregister_simple(nand_led_trigger);
2746}
2747
2748module_init(nand_base_init);
2749module_exit(nand_base_exit);
2750
2727MODULE_LICENSE ("GPL"); 2751MODULE_LICENSE ("GPL");
2728MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>"); 2752MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>");
2729MODULE_DESCRIPTION ("Generic NAND flash driver code"); 2753MODULE_DESCRIPTION ("Generic NAND flash driver code");
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 8815c8dbef2d..c077d2ec9cdd 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -85,10 +85,6 @@ static int parse_redboot_partitions(struct mtd_info *master,
85 85
86 numslots = (master->erasesize / sizeof(struct fis_image_desc)); 86 numslots = (master->erasesize / sizeof(struct fis_image_desc));
87 for (i = 0; i < numslots; i++) { 87 for (i = 0; i < numslots; i++) {
88 if (buf[i].name[0] == 0xff) {
89 i = numslots;
90 break;
91 }
92 if (!memcmp(buf[i].name, "FIS directory", 14)) { 88 if (!memcmp(buf[i].name, "FIS directory", 14)) {
93 /* This is apparently the FIS directory entry for the 89 /* This is apparently the FIS directory entry for the
94 * FIS directory itself. The FIS directory size is 90 * FIS directory itself. The FIS directory size is
@@ -128,7 +124,7 @@ static int parse_redboot_partitions(struct mtd_info *master,
128 struct fis_list *new_fl, **prev; 124 struct fis_list *new_fl, **prev;
129 125
130 if (buf[i].name[0] == 0xff) 126 if (buf[i].name[0] == 0xff)
131 break; 127 continue;
132 if (!redboot_checksum(&buf[i])) 128 if (!redboot_checksum(&buf[i]))
133 break; 129 break;
134 130
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 70f63891b19c..274b0138d442 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -788,7 +788,7 @@ struct vortex_private {
788 int options; /* User-settable misc. driver options. */ 788 int options; /* User-settable misc. driver options. */
789 unsigned int media_override:4, /* Passed-in media type. */ 789 unsigned int media_override:4, /* Passed-in media type. */
790 default_media:4, /* Read from the EEPROM/Wn3_Config. */ 790 default_media:4, /* Read from the EEPROM/Wn3_Config. */
791 full_duplex:1, force_fd:1, autoselect:1, 791 full_duplex:1, autoselect:1,
792 bus_master:1, /* Vortex can only do a fragment bus-m. */ 792 bus_master:1, /* Vortex can only do a fragment bus-m. */
793 full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang */ 793 full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang */
794 flow_ctrl:1, /* Use 802.3x flow control (PAUSE only) */ 794 flow_ctrl:1, /* Use 802.3x flow control (PAUSE only) */
@@ -1633,12 +1633,6 @@ vortex_set_duplex(struct net_device *dev)
1633 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ? 1633 ((vp->full_duplex && vp->flow_ctrl && vp->partner_flow_ctrl) ?
1634 0x100 : 0), 1634 0x100 : 0),
1635 ioaddr + Wn3_MAC_Ctrl); 1635 ioaddr + Wn3_MAC_Ctrl);
1636
1637 issue_and_wait(dev, TxReset);
1638 /*
1639 * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
1640 */
1641 issue_and_wait(dev, RxReset|0x04);
1642} 1636}
1643 1637
1644static void vortex_check_media(struct net_device *dev, unsigned int init) 1638static void vortex_check_media(struct net_device *dev, unsigned int init)
@@ -1663,7 +1657,7 @@ vortex_up(struct net_device *dev)
1663 struct vortex_private *vp = netdev_priv(dev); 1657 struct vortex_private *vp = netdev_priv(dev);
1664 void __iomem *ioaddr = vp->ioaddr; 1658 void __iomem *ioaddr = vp->ioaddr;
1665 unsigned int config; 1659 unsigned int config;
1666 int i; 1660 int i, mii_reg1, mii_reg5;
1667 1661
1668 if (VORTEX_PCI(vp)) { 1662 if (VORTEX_PCI(vp)) {
1669 pci_set_power_state(VORTEX_PCI(vp), PCI_D0); /* Go active */ 1663 pci_set_power_state(VORTEX_PCI(vp), PCI_D0); /* Go active */
@@ -1723,14 +1717,23 @@ vortex_up(struct net_device *dev)
1723 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config); 1717 printk(KERN_DEBUG "vortex_up(): writing 0x%x to InternalConfig\n", config);
1724 iowrite32(config, ioaddr + Wn3_Config); 1718 iowrite32(config, ioaddr + Wn3_Config);
1725 1719
1726 netif_carrier_off(dev);
1727 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) { 1720 if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
1728 EL3WINDOW(4); 1721 EL3WINDOW(4);
1722 mii_reg1 = mdio_read(dev, vp->phys[0], MII_BMSR);
1723 mii_reg5 = mdio_read(dev, vp->phys[0], MII_LPA);
1724 vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
1725
1729 vortex_check_media(dev, 1); 1726 vortex_check_media(dev, 1);
1730 } 1727 }
1731 else 1728 else
1732 vortex_set_duplex(dev); 1729 vortex_set_duplex(dev);
1733 1730
1731 issue_and_wait(dev, TxReset);
1732 /*
1733 * Don't reset the PHY - that upsets autonegotiation during DHCP operations.
1734 */
1735 issue_and_wait(dev, RxReset|0x04);
1736
1734 1737
1735 iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD); 1738 iowrite16(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
1736 1739
@@ -2083,16 +2086,14 @@ vortex_error(struct net_device *dev, int status)
2083 } 2086 }
2084 if (tx_status & 0x14) vp->stats.tx_fifo_errors++; 2087 if (tx_status & 0x14) vp->stats.tx_fifo_errors++;
2085 if (tx_status & 0x38) vp->stats.tx_aborted_errors++; 2088 if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
2089 if (tx_status & 0x08) vp->xstats.tx_max_collisions++;
2086 iowrite8(0, ioaddr + TxStatus); 2090 iowrite8(0, ioaddr + TxStatus);
2087 if (tx_status & 0x30) { /* txJabber or txUnderrun */ 2091 if (tx_status & 0x30) { /* txJabber or txUnderrun */
2088 do_tx_reset = 1; 2092 do_tx_reset = 1;
2089 } else if (tx_status & 0x08) { /* maxCollisions */ 2093 } else if ((tx_status & 0x08) && (vp->drv_flags & MAX_COLLISION_RESET)) { /* maxCollisions */
2090 vp->xstats.tx_max_collisions++; 2094 do_tx_reset = 1;
2091 if (vp->drv_flags & MAX_COLLISION_RESET) { 2095 reset_mask = 0x0108; /* Reset interface logic, but not download logic */
2092 do_tx_reset = 1; 2096 } else { /* Merely re-enable the transmitter. */
2093 reset_mask = 0x0108; /* Reset interface logic, but not download logic */
2094 }
2095 } else { /* Merely re-enable the transmitter. */
2096 iowrite16(TxEnable, ioaddr + EL3_CMD); 2097 iowrite16(TxEnable, ioaddr + EL3_CMD);
2097 } 2098 }
2098 } 2099 }
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index ce99845d8266..066e22b01a94 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -539,8 +539,7 @@ rx_status_loop:
539 unsigned buflen; 539 unsigned buflen;
540 540
541 skb = cp->rx_skb[rx_tail].skb; 541 skb = cp->rx_skb[rx_tail].skb;
542 if (!skb) 542 BUG_ON(!skb);
543 BUG();
544 543
545 desc = &cp->rx_ring[rx_tail]; 544 desc = &cp->rx_ring[rx_tail];
546 status = le32_to_cpu(desc->opts1); 545 status = le32_to_cpu(desc->opts1);
@@ -723,8 +722,7 @@ static void cp_tx (struct cp_private *cp)
723 break; 722 break;
724 723
725 skb = cp->tx_skb[tx_tail].skb; 724 skb = cp->tx_skb[tx_tail].skb;
726 if (!skb) 725 BUG_ON(!skb);
727 BUG();
728 726
729 pci_unmap_single(cp->pdev, cp->tx_skb[tx_tail].mapping, 727 pci_unmap_single(cp->pdev, cp->tx_skb[tx_tail].mapping,
730 cp->tx_skb[tx_tail].len, PCI_DMA_TODEVICE); 728 cp->tx_skb[tx_tail].len, PCI_DMA_TODEVICE);
@@ -1550,8 +1548,7 @@ static void cp_get_ethtool_stats (struct net_device *dev,
1550 tmp_stats[i++] = le16_to_cpu(nic_stats->tx_abort); 1548 tmp_stats[i++] = le16_to_cpu(nic_stats->tx_abort);
1551 tmp_stats[i++] = le16_to_cpu(nic_stats->tx_underrun); 1549 tmp_stats[i++] = le16_to_cpu(nic_stats->tx_underrun);
1552 tmp_stats[i++] = cp->cp_stats.rx_frags; 1550 tmp_stats[i++] = cp->cp_stats.rx_frags;
1553 if (i != CP_NUM_STATS) 1551 BUG_ON(i != CP_NUM_STATS);
1554 BUG();
1555 1552
1556 pci_free_consistent(cp->pdev, sizeof(*nic_stats), nic_stats, dma); 1553 pci_free_consistent(cp->pdev, sizeof(*nic_stats), nic_stats, dma);
1557} 1554}
@@ -1856,8 +1853,7 @@ static void cp_remove_one (struct pci_dev *pdev)
1856 struct net_device *dev = pci_get_drvdata(pdev); 1853 struct net_device *dev = pci_get_drvdata(pdev);
1857 struct cp_private *cp = netdev_priv(dev); 1854 struct cp_private *cp = netdev_priv(dev);
1858 1855
1859 if (!dev) 1856 BUG_ON(!dev);
1860 BUG();
1861 unregister_netdev(dev); 1857 unregister_netdev(dev);
1862 iounmap(cp->regs); 1858 iounmap(cp->regs);
1863 if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0); 1859 if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0);
diff --git a/drivers/net/8390.h b/drivers/net/8390.h
index 599b68d8c45f..51e39dcd0603 100644
--- a/drivers/net/8390.h
+++ b/drivers/net/8390.h
@@ -134,7 +134,7 @@ struct ei_device {
134#define inb_p(_p) inb(_p) 134#define inb_p(_p) inb(_p)
135#define outb_p(_v,_p) outb(_v,_p) 135#define outb_p(_v,_p) outb(_v,_p)
136 136
137#elif defined(CONFIG_NET_CBUS) || defined(CONFIG_NE_H8300) || defined(CONFIG_NE_H8300_MODULE) 137#elif defined(CONFIG_NE_H8300) || defined(CONFIG_NE_H8300_MODULE)
138#define EI_SHIFT(x) (ei_local->reg_offset[x]) 138#define EI_SHIFT(x) (ei_local->reg_offset[x])
139#else 139#else
140#define EI_SHIFT(x) (x) 140#define EI_SHIFT(x) (x)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index e20b849a22e8..bdaaad8f2123 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2313,13 +2313,11 @@ config S2IO_NAPI
2313 2313
2314endmenu 2314endmenu
2315 2315
2316if !UML
2317source "drivers/net/tokenring/Kconfig" 2316source "drivers/net/tokenring/Kconfig"
2318 2317
2319source "drivers/net/wireless/Kconfig" 2318source "drivers/net/wireless/Kconfig"
2320 2319
2321source "drivers/net/pcmcia/Kconfig" 2320source "drivers/net/pcmcia/Kconfig"
2322endif
2323 2321
2324source "drivers/net/wan/Kconfig" 2322source "drivers/net/wan/Kconfig"
2325 2323
diff --git a/drivers/net/acenic_firmware.h b/drivers/net/acenic_firmware.h
index 6d625d595622..d7882dd783c8 100644
--- a/drivers/net/acenic_firmware.h
+++ b/drivers/net/acenic_firmware.h
@@ -4397,7 +4397,7 @@ static u32 tigonFwText[(MAX_TEXT_LEN/4) + 1] __devinitdata = {
43970x3c010001, 0x220821, 0xac317e30, 0x8fbf0024, 43970x3c010001, 0x220821, 0xac317e30, 0x8fbf0024,
43980x8fb40020, 0x8fb3001c, 0x8fb20018, 0x8fb10014, 43980x8fb40020, 0x8fb3001c, 0x8fb20018, 0x8fb10014,
43990x8fb00010, 0x3e00008, 0x27bd0028, 0x0 }; 43990x8fb00010, 0x3e00008, 0x27bd0028, 0x0 };
4400static u32 tigonFwRodata[(MAX_RODATA_LEN/4) + 1] __initdata = { 4400static u32 tigonFwRodata[(MAX_RODATA_LEN/4) + 1] __devinitdata = {
44010x24486561, 0x6465723a, 0x202f7072, 44010x24486561, 0x6465723a, 0x202f7072,
44020x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765, 44020x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
44030x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e, 44030x2f2e2f6e, 0x69632f66, 0x772f636f, 0x6d6d6f6e,
@@ -4571,7 +4571,7 @@ static u32 tigonFwRodata[(MAX_RODATA_LEN/4) + 1] __initdata = {
45710x0, 0x14c38, 0x14c38, 0x14b80, 45710x0, 0x14c38, 0x14c38, 0x14b80,
45720x14bc4, 0x14c38, 0x14c38, 0x0, 45720x14bc4, 0x14c38, 0x14c38, 0x0,
45730x0, 0x0 }; 45730x0, 0x0 };
4574static u32 tigonFwData[(MAX_DATA_LEN/4) + 1] __initdata = { 4574static u32 tigonFwData[(MAX_DATA_LEN/4) + 1] __devinitdata = {
45750x416c7465, 45750x416c7465,
45760x6f6e2041, 0x63654e49, 0x43205600, 0x416c7465, 45760x6f6e2041, 0x63654e49, 0x43205600, 0x416c7465,
45770x6f6e2041, 0x63654e49, 0x43205600, 0x42424242, 45770x6f6e2041, 0x63654e49, 0x43205600, 0x42424242,
@@ -4612,7 +4612,7 @@ static u32 tigonFwData[(MAX_DATA_LEN/4) + 1] __initdata = {
4612#define tigon2FwSbssLen 0xcc 4612#define tigon2FwSbssLen 0xcc
4613#define tigon2FwBssAddr 0x00016f50 4613#define tigon2FwBssAddr 0x00016f50
4614#define tigon2FwBssLen 0x20c0 4614#define tigon2FwBssLen 0x20c0
4615static u32 tigon2FwText[(MAX_TEXT_LEN/4) + 1] __initdata = { 4615static u32 tigon2FwText[(MAX_TEXT_LEN/4) + 1] __devinitdata = {
46160x0, 46160x0,
46170x10000003, 0x0, 0xd, 0xd, 46170x10000003, 0x0, 0xd, 0xd,
46180x3c1d0001, 0x8fbd6d20, 0x3a0f021, 0x3c100000, 46180x3c1d0001, 0x8fbd6d20, 0x3a0f021, 0x3c100000,
@@ -9154,7 +9154,7 @@ static u32 tigon2FwText[(MAX_TEXT_LEN/4) + 1] __initdata = {
91540x24020001, 0x8f430328, 0x1021, 0x24630001, 91540x24020001, 0x8f430328, 0x1021, 0x24630001,
91550x3e00008, 0xaf430328, 0x3e00008, 0x0, 91550x3e00008, 0xaf430328, 0x3e00008, 0x0,
91560x0, 0x0, 0x0, 0x0 }; 91560x0, 0x0, 0x0, 0x0 };
9157static u32 tigon2FwRodata[(MAX_RODATA_LEN/4) + 1] __initdata = { 9157static u32 tigon2FwRodata[(MAX_RODATA_LEN/4) + 1] __devinitdata = {
91580x24486561, 0x6465723a, 0x202f7072, 91580x24486561, 0x6465723a, 0x202f7072,
91590x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765, 91590x6f6a6563, 0x74732f72, 0x63732f73, 0x772f6765,
91600x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f, 91600x2f2e2f6e, 0x69632f66, 0x77322f63, 0x6f6d6d6f,
@@ -9425,7 +9425,7 @@ static u32 tigon2FwRodata[(MAX_RODATA_LEN/4) + 1] __initdata = {
94250x14ed8, 0x14b8c, 0x14bd8, 0x14c24, 94250x14ed8, 0x14b8c, 0x14bd8, 0x14c24,
94260x14ed8, 0x7365746d, 0x61636163, 0x74000000, 94260x14ed8, 0x7365746d, 0x61636163, 0x74000000,
94270x0, 0x0 }; 94270x0, 0x0 };
9428static u32 tigon2FwData[(MAX_DATA_LEN/4) + 1] __initdata = { 9428static u32 tigon2FwData[(MAX_DATA_LEN/4) + 1] __devinitdata = {
94290x1, 94290x1,
94300x1, 0x1, 0xc001fc, 0x3ffc, 94300x1, 0x1, 0xc001fc, 0x3ffc,
94310xc00000, 0x416c7465, 0x6f6e2041, 0x63654e49, 94310xc00000, 0x416c7465, 0x6f6e2041, 0x63654e49,
diff --git a/drivers/net/arcnet/arcnet.c b/drivers/net/arcnet/arcnet.c
index 64e2caf3083d..fabc0607b0f1 100644
--- a/drivers/net/arcnet/arcnet.c
+++ b/drivers/net/arcnet/arcnet.c
@@ -765,8 +765,7 @@ irqreturn_t arcnet_interrupt(int irq, void *dev_id, struct pt_regs *regs)
765 BUGMSG(D_DURING, "in arcnet_interrupt\n"); 765 BUGMSG(D_DURING, "in arcnet_interrupt\n");
766 766
767 lp = dev->priv; 767 lp = dev->priv;
768 if (!lp) 768 BUG_ON(!lp);
769 BUG();
770 769
771 spin_lock(&lp->lock); 770 spin_lock(&lp->lock);
772 771
diff --git a/drivers/net/arcnet/com90xx.c b/drivers/net/arcnet/com90xx.c
index 43150b2bd13f..0d45553ff75c 100644
--- a/drivers/net/arcnet/com90xx.c
+++ b/drivers/net/arcnet/com90xx.c
@@ -125,11 +125,11 @@ static void __init com90xx_probe(void)
125 if (!io && !irq && !shmem && !*device && com90xx_skip_probe) 125 if (!io && !irq && !shmem && !*device && com90xx_skip_probe)
126 return; 126 return;
127 127
128 shmems = kzalloc(((0x10000-0xa0000) / 0x800) * sizeof(unsigned long), 128 shmems = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(unsigned long),
129 GFP_KERNEL); 129 GFP_KERNEL);
130 if (!shmems) 130 if (!shmems)
131 return; 131 return;
132 iomem = kzalloc(((0x10000-0xa0000) / 0x800) * sizeof(void __iomem *), 132 iomem = kzalloc(((0x100000-0xa0000) / 0x800) * sizeof(void __iomem *),
133 GFP_KERNEL); 133 GFP_KERNEL);
134 if (!iomem) { 134 if (!iomem) {
135 kfree(shmems); 135 kfree(shmems);
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index c3267e4e1bb0..3d306681919e 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -2,6 +2,7 @@
2 * 2 *
3 * Copyright (C) 2002 David S. Miller (davem@redhat.com) 3 * Copyright (C) 2002 David S. Miller (davem@redhat.com)
4 * Fixed by Pekka Pietikainen (pp@ee.oulu.fi) 4 * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
5 * Copyright (C) 2006 Broadcom Corporation.
5 * 6 *
6 * Distribute under GPL. 7 * Distribute under GPL.
7 */ 8 */
@@ -28,8 +29,8 @@
28 29
29#define DRV_MODULE_NAME "b44" 30#define DRV_MODULE_NAME "b44"
30#define PFX DRV_MODULE_NAME ": " 31#define PFX DRV_MODULE_NAME ": "
31#define DRV_MODULE_VERSION "0.97" 32#define DRV_MODULE_VERSION "1.00"
32#define DRV_MODULE_RELDATE "Nov 30, 2005" 33#define DRV_MODULE_RELDATE "Apr 7, 2006"
33 34
34#define B44_DEF_MSG_ENABLE \ 35#define B44_DEF_MSG_ENABLE \
35 (NETIF_MSG_DRV | \ 36 (NETIF_MSG_DRV | \
@@ -136,7 +137,7 @@ static inline unsigned long br32(const struct b44 *bp, unsigned long reg)
136 return readl(bp->regs + reg); 137 return readl(bp->regs + reg);
137} 138}
138 139
139static inline void bw32(const struct b44 *bp, 140static inline void bw32(const struct b44 *bp,
140 unsigned long reg, unsigned long val) 141 unsigned long reg, unsigned long val)
141{ 142{
142 writel(val, bp->regs + reg); 143 writel(val, bp->regs + reg);
@@ -286,13 +287,13 @@ static void __b44_cam_write(struct b44 *bp, unsigned char *data, int index)
286 val |= ((u32) data[4]) << 8; 287 val |= ((u32) data[4]) << 8;
287 val |= ((u32) data[5]) << 0; 288 val |= ((u32) data[5]) << 0;
288 bw32(bp, B44_CAM_DATA_LO, val); 289 bw32(bp, B44_CAM_DATA_LO, val);
289 val = (CAM_DATA_HI_VALID | 290 val = (CAM_DATA_HI_VALID |
290 (((u32) data[0]) << 8) | 291 (((u32) data[0]) << 8) |
291 (((u32) data[1]) << 0)); 292 (((u32) data[1]) << 0));
292 bw32(bp, B44_CAM_DATA_HI, val); 293 bw32(bp, B44_CAM_DATA_HI, val);
293 bw32(bp, B44_CAM_CTRL, (CAM_CTRL_WRITE | 294 bw32(bp, B44_CAM_CTRL, (CAM_CTRL_WRITE |
294 (index << CAM_CTRL_INDEX_SHIFT))); 295 (index << CAM_CTRL_INDEX_SHIFT)));
295 b44_wait_bit(bp, B44_CAM_CTRL, CAM_CTRL_BUSY, 100, 1); 296 b44_wait_bit(bp, B44_CAM_CTRL, CAM_CTRL_BUSY, 100, 1);
296} 297}
297 298
298static inline void __b44_disable_ints(struct b44 *bp) 299static inline void __b44_disable_ints(struct b44 *bp)
@@ -410,25 +411,18 @@ static void __b44_set_flow_ctrl(struct b44 *bp, u32 pause_flags)
410 411
411static void b44_set_flow_ctrl(struct b44 *bp, u32 local, u32 remote) 412static void b44_set_flow_ctrl(struct b44 *bp, u32 local, u32 remote)
412{ 413{
413 u32 pause_enab = bp->flags & (B44_FLAG_TX_PAUSE | 414 u32 pause_enab = 0;
414 B44_FLAG_RX_PAUSE);
415 415
416 if (local & ADVERTISE_PAUSE_CAP) { 416 /* The driver supports only rx pause by default because
417 if (local & ADVERTISE_PAUSE_ASYM) { 417 the b44 mac tx pause mechanism generates excessive
418 if (remote & LPA_PAUSE_CAP) 418 pause frames.
419 pause_enab |= (B44_FLAG_TX_PAUSE | 419 Use ethtool to turn on b44 tx pause if necessary.
420 B44_FLAG_RX_PAUSE); 420 */
421 else if (remote & LPA_PAUSE_ASYM) 421 if ((local & ADVERTISE_PAUSE_CAP) &&
422 pause_enab |= B44_FLAG_RX_PAUSE; 422 (local & ADVERTISE_PAUSE_ASYM)){
423 } else { 423 if ((remote & LPA_PAUSE_ASYM) &&
424 if (remote & LPA_PAUSE_CAP) 424 !(remote & LPA_PAUSE_CAP))
425 pause_enab |= (B44_FLAG_TX_PAUSE | 425 pause_enab |= B44_FLAG_RX_PAUSE;
426 B44_FLAG_RX_PAUSE);
427 }
428 } else if (local & ADVERTISE_PAUSE_ASYM) {
429 if ((remote & LPA_PAUSE_CAP) &&
430 (remote & LPA_PAUSE_ASYM))
431 pause_enab |= B44_FLAG_TX_PAUSE;
432 } 426 }
433 427
434 __b44_set_flow_ctrl(bp, pause_enab); 428 __b44_set_flow_ctrl(bp, pause_enab);
@@ -608,8 +602,7 @@ static void b44_tx(struct b44 *bp)
608 struct ring_info *rp = &bp->tx_buffers[cons]; 602 struct ring_info *rp = &bp->tx_buffers[cons];
609 struct sk_buff *skb = rp->skb; 603 struct sk_buff *skb = rp->skb;
610 604
611 if (unlikely(skb == NULL)) 605 BUG_ON(skb == NULL);
612 BUG();
613 606
614 pci_unmap_single(bp->pdev, 607 pci_unmap_single(bp->pdev,
615 pci_unmap_addr(rp, mapping), 608 pci_unmap_addr(rp, mapping),
@@ -1064,7 +1057,7 @@ static int b44_change_mtu(struct net_device *dev, int new_mtu)
1064 spin_unlock_irq(&bp->lock); 1057 spin_unlock_irq(&bp->lock);
1065 1058
1066 b44_enable_ints(bp); 1059 b44_enable_ints(bp);
1067 1060
1068 return 0; 1061 return 0;
1069} 1062}
1070 1063
@@ -1339,6 +1332,9 @@ static int b44_set_mac_addr(struct net_device *dev, void *p)
1339 if (netif_running(dev)) 1332 if (netif_running(dev))
1340 return -EBUSY; 1333 return -EBUSY;
1341 1334
1335 if (!is_valid_ether_addr(addr->sa_data))
1336 return -EINVAL;
1337
1342 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); 1338 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1343 1339
1344 spin_lock_irq(&bp->lock); 1340 spin_lock_irq(&bp->lock);
@@ -1379,7 +1375,7 @@ static void b44_init_hw(struct b44 *bp)
1379 bw32(bp, B44_DMARX_ADDR, bp->rx_ring_dma + bp->dma_offset); 1375 bw32(bp, B44_DMARX_ADDR, bp->rx_ring_dma + bp->dma_offset);
1380 1376
1381 bw32(bp, B44_DMARX_PTR, bp->rx_pending); 1377 bw32(bp, B44_DMARX_PTR, bp->rx_pending);
1382 bp->rx_prod = bp->rx_pending; 1378 bp->rx_prod = bp->rx_pending;
1383 1379
1384 bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ); 1380 bw32(bp, B44_MIB_CTRL, MIB_CTRL_CLR_ON_READ);
1385 1381
@@ -1551,9 +1547,9 @@ static void __b44_set_rx_mode(struct net_device *dev)
1551 val |= RXCONFIG_ALLMULTI; 1547 val |= RXCONFIG_ALLMULTI;
1552 else 1548 else
1553 i = __b44_load_mcast(bp, dev); 1549 i = __b44_load_mcast(bp, dev);
1554 1550
1555 for (; i < 64; i++) { 1551 for (; i < 64; i++) {
1556 __b44_cam_write(bp, zero, i); 1552 __b44_cam_write(bp, zero, i);
1557 } 1553 }
1558 bw32(bp, B44_RXCONFIG, val); 1554 bw32(bp, B44_RXCONFIG, val);
1559 val = br32(bp, B44_CAM_CTRL); 1555 val = br32(bp, B44_CAM_CTRL);
@@ -1735,7 +1731,7 @@ static int b44_set_ringparam(struct net_device *dev,
1735 spin_unlock_irq(&bp->lock); 1731 spin_unlock_irq(&bp->lock);
1736 1732
1737 b44_enable_ints(bp); 1733 b44_enable_ints(bp);
1738 1734
1739 return 0; 1735 return 0;
1740} 1736}
1741 1737
@@ -1780,7 +1776,7 @@ static int b44_set_pauseparam(struct net_device *dev,
1780 spin_unlock_irq(&bp->lock); 1776 spin_unlock_irq(&bp->lock);
1781 1777
1782 b44_enable_ints(bp); 1778 b44_enable_ints(bp);
1783 1779
1784 return 0; 1780 return 0;
1785} 1781}
1786 1782
@@ -1876,6 +1872,12 @@ static int __devinit b44_get_invariants(struct b44 *bp)
1876 bp->dev->dev_addr[3] = eeprom[80]; 1872 bp->dev->dev_addr[3] = eeprom[80];
1877 bp->dev->dev_addr[4] = eeprom[83]; 1873 bp->dev->dev_addr[4] = eeprom[83];
1878 bp->dev->dev_addr[5] = eeprom[82]; 1874 bp->dev->dev_addr[5] = eeprom[82];
1875
1876 if (!is_valid_ether_addr(&bp->dev->dev_addr[0])){
1877 printk(KERN_ERR PFX "Invalid MAC address found in EEPROM\n");
1878 return -EINVAL;
1879 }
1880
1879 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, bp->dev->addr_len); 1881 memcpy(bp->dev->perm_addr, bp->dev->dev_addr, bp->dev->addr_len);
1880 1882
1881 bp->phy_addr = eeprom[90] & 0x1f; 1883 bp->phy_addr = eeprom[90] & 0x1f;
@@ -1890,7 +1892,7 @@ static int __devinit b44_get_invariants(struct b44 *bp)
1890 bp->core_unit = ssb_core_unit(bp); 1892 bp->core_unit = ssb_core_unit(bp);
1891 bp->dma_offset = SB_PCI_DMA; 1893 bp->dma_offset = SB_PCI_DMA;
1892 1894
1893 /* XXX - really required? 1895 /* XXX - really required?
1894 bp->flags |= B44_FLAG_BUGGY_TXPTR; 1896 bp->flags |= B44_FLAG_BUGGY_TXPTR;
1895 */ 1897 */
1896out: 1898out:
@@ -1938,7 +1940,7 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
1938 "aborting.\n"); 1940 "aborting.\n");
1939 goto err_out_free_res; 1941 goto err_out_free_res;
1940 } 1942 }
1941 1943
1942 err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK); 1944 err = pci_set_consistent_dma_mask(pdev, (u64) B44_DMA_MASK);
1943 if (err) { 1945 if (err) {
1944 printk(KERN_ERR PFX "No usable DMA configuration, " 1946 printk(KERN_ERR PFX "No usable DMA configuration, "
@@ -2033,6 +2035,11 @@ static int __devinit b44_init_one(struct pci_dev *pdev,
2033 2035
2034 pci_save_state(bp->pdev); 2036 pci_save_state(bp->pdev);
2035 2037
2038 /* Chip reset provides power to the b44 MAC & PCI cores, which
2039 * is necessary for MAC register access.
2040 */
2041 b44_chip_reset(bp);
2042
2036 printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name); 2043 printk(KERN_INFO "%s: Broadcom 4400 10/100BaseT Ethernet ", dev->name);
2037 for (i = 0; i < 6; i++) 2044 for (i = 0; i < 6; i++)
2038 printk("%2.2x%c", dev->dev_addr[i], 2045 printk("%2.2x%c", dev->dev_addr[i],
@@ -2078,10 +2085,10 @@ static int b44_suspend(struct pci_dev *pdev, pm_message_t state)
2078 2085
2079 del_timer_sync(&bp->timer); 2086 del_timer_sync(&bp->timer);
2080 2087
2081 spin_lock_irq(&bp->lock); 2088 spin_lock_irq(&bp->lock);
2082 2089
2083 b44_halt(bp); 2090 b44_halt(bp);
2084 netif_carrier_off(bp->dev); 2091 netif_carrier_off(bp->dev);
2085 netif_device_detach(bp->dev); 2092 netif_device_detach(bp->dev);
2086 b44_free_rings(bp); 2093 b44_free_rings(bp);
2087 2094
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 2671da20a496..5ca99e26660a 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -63,7 +63,7 @@
63/* Time in jiffies before concluding the transmitter is hung. */ 63/* Time in jiffies before concluding the transmitter is hung. */
64#define TX_TIMEOUT (5*HZ) 64#define TX_TIMEOUT (5*HZ)
65 65
66static char version[] __devinitdata = 66static const char version[] __devinitdata =
67 "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; 67 "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
68 68
69MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>"); 69MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index f3f5825469d6..6a407070c2e8 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2294,6 +2294,34 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
2294 port->sm_vars |= AD_PORT_BEGIN; 2294 port->sm_vars |= AD_PORT_BEGIN;
2295} 2295}
2296 2296
2297/*
2298 * set link state for bonding master: if we have an active partnered
2299 * aggregator, we're up, if not, we're down. Presumes that we cannot
2300 * have an active aggregator if there are no slaves with link up.
2301 *
2302 * Called by bond_set_carrier(). Return zero if carrier state does not
2303 * change, nonzero if it does.
2304 */
2305int bond_3ad_set_carrier(struct bonding *bond)
2306{
2307 struct aggregator *agg;
2308
2309 agg = __get_active_agg(&(SLAVE_AD_INFO(bond->first_slave).aggregator));
2310 if (agg && MAC_ADDRESS_COMPARE(&agg->partner_system, &null_mac_addr)) {
2311 if (!netif_carrier_ok(bond->dev)) {
2312 netif_carrier_on(bond->dev);
2313 return 1;
2314 }
2315 return 0;
2316 }
2317
2318 if (netif_carrier_ok(bond->dev)) {
2319 netif_carrier_off(bond->dev);
2320 return 1;
2321 }
2322 return 0;
2323}
2324
2297/** 2325/**
2298 * bond_3ad_get_active_agg_info - get information of the active aggregator 2326 * bond_3ad_get_active_agg_info - get information of the active aggregator
2299 * @bond: bonding struct to work on 2327 * @bond: bonding struct to work on
diff --git a/drivers/net/bonding/bond_3ad.h b/drivers/net/bonding/bond_3ad.h
index 5ee2cef5b037..6ad5ad6e65d5 100644
--- a/drivers/net/bonding/bond_3ad.h
+++ b/drivers/net/bonding/bond_3ad.h
@@ -283,5 +283,6 @@ void bond_3ad_handle_link_change(struct slave *slave, char link);
283int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info); 283int bond_3ad_get_active_agg_info(struct bonding *bond, struct ad_info *ad_info);
284int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev); 284int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev);
285int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev); 285int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type* ptype, struct net_device *orig_dev);
286int bond_3ad_set_carrier(struct bonding *bond);
286#endif //__BOND_3AD_H__ 287#endif //__BOND_3AD_H__
287 288
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index f13a539dc169..55d236726d11 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -559,6 +559,42 @@ out:
559/*------------------------------- Link status -------------------------------*/ 559/*------------------------------- Link status -------------------------------*/
560 560
561/* 561/*
562 * Set the carrier state for the master according to the state of its
563 * slaves. If any slaves are up, the master is up. In 802.3ad mode,
564 * do special 802.3ad magic.
565 *
566 * Returns zero if carrier state does not change, nonzero if it does.
567 */
568static int bond_set_carrier(struct bonding *bond)
569{
570 struct slave *slave;
571 int i;
572
573 if (bond->slave_cnt == 0)
574 goto down;
575
576 if (bond->params.mode == BOND_MODE_8023AD)
577 return bond_3ad_set_carrier(bond);
578
579 bond_for_each_slave(bond, slave, i) {
580 if (slave->link == BOND_LINK_UP) {
581 if (!netif_carrier_ok(bond->dev)) {
582 netif_carrier_on(bond->dev);
583 return 1;
584 }
585 return 0;
586 }
587 }
588
589down:
590 if (netif_carrier_ok(bond->dev)) {
591 netif_carrier_off(bond->dev);
592 return 1;
593 }
594 return 0;
595}
596
597/*
562 * Get link speed and duplex from the slave's base driver 598 * Get link speed and duplex from the slave's base driver
563 * using ethtool. If for some reason the call fails or the 599 * using ethtool. If for some reason the call fails or the
564 * values are invalid, fake speed and duplex to 100/Full 600 * values are invalid, fake speed and duplex to 100/Full
@@ -1074,10 +1110,24 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1074void bond_select_active_slave(struct bonding *bond) 1110void bond_select_active_slave(struct bonding *bond)
1075{ 1111{
1076 struct slave *best_slave; 1112 struct slave *best_slave;
1113 int rv;
1077 1114
1078 best_slave = bond_find_best_slave(bond); 1115 best_slave = bond_find_best_slave(bond);
1079 if (best_slave != bond->curr_active_slave) { 1116 if (best_slave != bond->curr_active_slave) {
1080 bond_change_active_slave(bond, best_slave); 1117 bond_change_active_slave(bond, best_slave);
1118 rv = bond_set_carrier(bond);
1119 if (!rv)
1120 return;
1121
1122 if (netif_carrier_ok(bond->dev)) {
1123 printk(KERN_INFO DRV_NAME
1124 ": %s: first active interface up!\n",
1125 bond->dev->name);
1126 } else {
1127 printk(KERN_INFO DRV_NAME ": %s: "
1128 "now running without any active interface !\n",
1129 bond->dev->name);
1130 }
1081 } 1131 }
1082} 1132}
1083 1133
@@ -1458,10 +1508,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1458 if (((!bond->curr_active_slave) || 1508 if (((!bond->curr_active_slave) ||
1459 (bond->curr_active_slave->dev->priv_flags & IFF_SLAVE_INACTIVE)) && 1509 (bond->curr_active_slave->dev->priv_flags & IFF_SLAVE_INACTIVE)) &&
1460 (new_slave->link != BOND_LINK_DOWN)) { 1510 (new_slave->link != BOND_LINK_DOWN)) {
1461 dprintk("This is the first active slave\n");
1462 /* first slave or no active slave yet, and this link 1511 /* first slave or no active slave yet, and this link
1463 is OK, so make this interface the active one */ 1512 is OK, so make this interface the active one */
1464 bond_change_active_slave(bond, new_slave); 1513 bond_change_active_slave(bond, new_slave);
1514 printk(KERN_INFO DRV_NAME
1515 ": %s: first active interface up!\n",
1516 bond->dev->name);
1517 netif_carrier_on(bond->dev);
1518
1465 } else { 1519 } else {
1466 dprintk("This is just a backup slave\n"); 1520 dprintk("This is just a backup slave\n");
1467 bond_set_slave_inactive_flags(new_slave); 1521 bond_set_slave_inactive_flags(new_slave);
@@ -1517,6 +1571,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1517 break; 1571 break;
1518 } /* switch(bond_mode) */ 1572 } /* switch(bond_mode) */
1519 1573
1574 bond_set_carrier(bond);
1575
1520 write_unlock_bh(&bond->lock); 1576 write_unlock_bh(&bond->lock);
1521 1577
1522 res = bond_create_slave_symlinks(bond_dev, slave_dev); 1578 res = bond_create_slave_symlinks(bond_dev, slave_dev);
@@ -1656,18 +1712,12 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1656 bond_alb_deinit_slave(bond, slave); 1712 bond_alb_deinit_slave(bond, slave);
1657 } 1713 }
1658 1714
1659 if (oldcurrent == slave) { 1715 if (oldcurrent == slave)
1660 bond_select_active_slave(bond); 1716 bond_select_active_slave(bond);
1661 1717
1662 if (!bond->curr_active_slave) {
1663 printk(KERN_INFO DRV_NAME
1664 ": %s: now running without any active "
1665 "interface !\n",
1666 bond_dev->name);
1667 }
1668 }
1669
1670 if (bond->slave_cnt == 0) { 1718 if (bond->slave_cnt == 0) {
1719 bond_set_carrier(bond);
1720
1671 /* if the last slave was removed, zero the mac address 1721 /* if the last slave was removed, zero the mac address
1672 * of the master so it will be set by the application 1722 * of the master so it will be set by the application
1673 * to the mac address of the first slave 1723 * to the mac address of the first slave
@@ -1751,6 +1801,8 @@ static int bond_release_all(struct net_device *bond_dev)
1751 1801
1752 write_lock_bh(&bond->lock); 1802 write_lock_bh(&bond->lock);
1753 1803
1804 netif_carrier_off(bond_dev);
1805
1754 if (bond->slave_cnt == 0) { 1806 if (bond->slave_cnt == 0) {
1755 goto out; 1807 goto out;
1756 } 1808 }
@@ -2187,15 +2239,9 @@ void bond_mii_monitor(struct net_device *bond_dev)
2187 2239
2188 bond_select_active_slave(bond); 2240 bond_select_active_slave(bond);
2189 2241
2190 if (oldcurrent && !bond->curr_active_slave) {
2191 printk(KERN_INFO DRV_NAME
2192 ": %s: now running without any active "
2193 "interface !\n",
2194 bond_dev->name);
2195 }
2196
2197 write_unlock(&bond->curr_slave_lock); 2242 write_unlock(&bond->curr_slave_lock);
2198 } 2243 } else
2244 bond_set_carrier(bond);
2199 2245
2200re_arm: 2246re_arm:
2201 if (bond->params.miimon) { 2247 if (bond->params.miimon) {
@@ -2499,13 +2545,6 @@ void bond_loadbalance_arp_mon(struct net_device *bond_dev)
2499 2545
2500 bond_select_active_slave(bond); 2546 bond_select_active_slave(bond);
2501 2547
2502 if (oldcurrent && !bond->curr_active_slave) {
2503 printk(KERN_INFO DRV_NAME
2504 ": %s: now running without any active "
2505 "interface !\n",
2506 bond_dev->name);
2507 }
2508
2509 write_unlock(&bond->curr_slave_lock); 2548 write_unlock(&bond->curr_slave_lock);
2510 } 2549 }
2511 2550
@@ -2579,12 +2618,15 @@ void bond_activebackup_arp_mon(struct net_device *bond_dev)
2579 bond->current_arp_slave = NULL; 2618 bond->current_arp_slave = NULL;
2580 } 2619 }
2581 2620
2621 bond_set_carrier(bond);
2622
2582 if (slave == bond->curr_active_slave) { 2623 if (slave == bond->curr_active_slave) {
2583 printk(KERN_INFO DRV_NAME 2624 printk(KERN_INFO DRV_NAME
2584 ": %s: %s is up and now the " 2625 ": %s: %s is up and now the "
2585 "active interface\n", 2626 "active interface\n",
2586 bond_dev->name, 2627 bond_dev->name,
2587 slave->dev->name); 2628 slave->dev->name);
2629 netif_carrier_on(bond->dev);
2588 } else { 2630 } else {
2589 printk(KERN_INFO DRV_NAME 2631 printk(KERN_INFO DRV_NAME
2590 ": %s: backup interface %s is " 2632 ": %s: backup interface %s is "
@@ -2844,7 +2886,8 @@ static void bond_info_show_master(struct seq_file *seq)
2844 (curr) ? curr->dev->name : "None"); 2886 (curr) ? curr->dev->name : "None");
2845 } 2887 }
2846 2888
2847 seq_printf(seq, "MII Status: %s\n", (curr) ? "up" : "down"); 2889 seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ?
2890 "up" : "down");
2848 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon); 2891 seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon);
2849 seq_printf(seq, "Up Delay (ms): %d\n", 2892 seq_printf(seq, "Up Delay (ms): %d\n",
2850 bond->params.updelay * bond->params.miimon); 2893 bond->params.updelay * bond->params.miimon);
@@ -4531,6 +4574,8 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
4531 if (newbond) 4574 if (newbond)
4532 *newbond = bond_dev->priv; 4575 *newbond = bond_dev->priv;
4533 4576
4577 netif_carrier_off(bond_dev);
4578
4534 rtnl_unlock(); /* allows sysfs registration of net device */ 4579 rtnl_unlock(); /* allows sysfs registration of net device */
4535 res = bond_create_sysfs_entry(bond_dev->priv); 4580 res = bond_create_sysfs_entry(bond_dev->priv);
4536 goto done; 4581 goto done;
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index ce9dc9b4e2dc..0bdfe2c71453 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -22,8 +22,8 @@
22#include "bond_3ad.h" 22#include "bond_3ad.h"
23#include "bond_alb.h" 23#include "bond_alb.h"
24 24
25#define DRV_VERSION "3.0.2" 25#define DRV_VERSION "3.0.3"
26#define DRV_RELDATE "February 21, 2006" 26#define DRV_RELDATE "March 23, 2006"
27#define DRV_NAME "bonding" 27#define DRV_NAME "bonding"
28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 28#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
29 29
diff --git a/drivers/net/chelsio/Makefile b/drivers/net/chelsio/Makefile
index 91e927827c43..54c78d94f48b 100644
--- a/drivers/net/chelsio/Makefile
+++ b/drivers/net/chelsio/Makefile
@@ -4,7 +4,7 @@
4 4
5obj-$(CONFIG_CHELSIO_T1) += cxgb.o 5obj-$(CONFIG_CHELSIO_T1) += cxgb.o
6 6
7EXTRA_CFLAGS += -I$(TOPDIR)/drivers/net/chelsio $(DEBUG_FLAGS) 7EXTRA_CFLAGS += -Idrivers/net/chelsio $(DEBUG_FLAGS)
8 8
9 9
10cxgb-objs := cxgb2.o espi.o pm3393.o sge.o subr.o mv88x201x.o 10cxgb-objs := cxgb2.o espi.o pm3393.o sge.o subr.o mv88x201x.o
diff --git a/drivers/net/chelsio/sge.c b/drivers/net/chelsio/sge.c
index 30ff8ea1a402..4391bf4bf573 100644
--- a/drivers/net/chelsio/sge.c
+++ b/drivers/net/chelsio/sge.c
@@ -1093,8 +1093,7 @@ static int process_responses(struct adapter *adapter, int budget)
1093 if (likely(e->DataValid)) { 1093 if (likely(e->DataValid)) {
1094 struct freelQ *fl = &sge->freelQ[e->FreelistQid]; 1094 struct freelQ *fl = &sge->freelQ[e->FreelistQid];
1095 1095
1096 if (unlikely(!e->Sop || !e->Eop)) 1096 BUG_ON(!e->Sop || !e->Eop);
1097 BUG();
1098 if (unlikely(e->Offload)) 1097 if (unlikely(e->Offload))
1099 unexpected_offload(adapter, fl); 1098 unexpected_offload(adapter, fl);
1100 else 1099 else
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 49cd096a3c3d..add8dc4aa7b0 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -3308,8 +3308,7 @@ e1000_clean(struct net_device *poll_dev, int *budget)
3308 3308
3309 while (poll_dev != &adapter->polling_netdev[i]) { 3309 while (poll_dev != &adapter->polling_netdev[i]) {
3310 i++; 3310 i++;
3311 if (unlikely(i == adapter->num_rx_queues)) 3311 BUG_ON(i == adapter->num_rx_queues);
3312 BUG();
3313 } 3312 }
3314 3313
3315 if (likely(adapter->num_tx_queues == 1)) { 3314 if (likely(adapter->num_tx_queues == 1)) {
diff --git a/drivers/net/eql.c b/drivers/net/eql.c
index aa1569182fd6..815436c6170f 100644
--- a/drivers/net/eql.c
+++ b/drivers/net/eql.c
@@ -203,8 +203,7 @@ static int eql_open(struct net_device *dev)
203 printk(KERN_INFO "%s: remember to turn off Van-Jacobson compression on " 203 printk(KERN_INFO "%s: remember to turn off Van-Jacobson compression on "
204 "your slave devices.\n", dev->name); 204 "your slave devices.\n", dev->name);
205 205
206 if (!list_empty(&eql->queue.all_slaves)) 206 BUG_ON(!list_empty(&eql->queue.all_slaves));
207 BUG();
208 207
209 eql->min_slaves = 1; 208 eql->min_slaves = 1;
210 eql->max_slaves = EQL_DEFAULT_MAX_SLAVES; /* 4 usually... */ 209 eql->max_slaves = EQL_DEFAULT_MAX_SLAVES; /* 4 usually... */
diff --git a/drivers/net/hydra.h b/drivers/net/hydra.h
deleted file mode 100644
index 37414146258d..000000000000
--- a/drivers/net/hydra.h
+++ /dev/null
@@ -1,177 +0,0 @@
1/* $Linux: hydra.h,v 1.0 1994/10/26 02:03:47 cgd Exp $ */
2
3/*
4 * Copyright (c) 1994 Timo Rossi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Timo Rossi
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * The Hydra Systems card uses the National Semiconductor
35 * 8390 NIC (Network Interface Controller) chip, located
36 * at card base address + 0xffe1. NIC registers are accessible
37 * only at odd byte addresses, so the register offsets must
38 * be multiplied by two.
39 *
40 * Card address PROM is located at card base + 0xffc0 (even byte addresses)
41 *
42 * RAM starts at the card base address, and is 16K or 64K.
43 * The current Amiga NetBSD hydra driver is hardwired for 16K.
44 * It seems that the RAM should be accessed as words or longwords only.
45 *
46 */
47
48/* adapted for Linux by Topi Kanerva 03/29/95
49 with original author's permission */
50
51#define HYDRA_NIC_BASE 0xffe1
52
53/* Page0 registers */
54
55#define NIC_CR 0 /* Command register */
56#define NIC_PSTART (1*2) /* Page start (write) */
57#define NIC_PSTOP (2*2) /* Page stop (write) */
58#define NIC_BNDRY (3*2) /* Boundary pointer */
59#define NIC_TSR (4*2) /* Transmit status (read) */
60#define NIC_TPSR (4*2) /* Transmit page start (write) */
61#define NIC_NCR (5*2) /* Number of collisions, read */
62#define NIC_TBCR0 (5*2) /* Transmit byte count low (write) */
63#define NIC_FIFO (6*2) /* FIFO reg. (read) */
64#define NIC_TBCR1 (6*2) /* Transmit byte count high (write) */
65#define NIC_ISR (7*2) /* Interrupt status register */
66#define NIC_RBCR0 (0xa*2) /* Remote byte count low (write) */
67#define NIC_RBCR1 (0xb*2) /* Remote byte count high (write) */
68#define NIC_RSR (0xc*2) /* Receive status (read) */
69#define NIC_RCR (0xc*2) /* Receive config (write) */
70#define NIC_CNTR0 (0xd*2) /* Frame alignment error count (read) */
71#define NIC_TCR (0xd*2) /* Transmit config (write) */
72#define NIC_CNTR1 (0xe*2) /* CRC error counter (read) */
73#define NIC_DCR (0xe*2) /* Data config (write) */
74#define NIC_CNTR2 (0xf*2) /* missed packet counter (read) */
75#define NIC_IMR (0xf*2) /* Interrupt mask reg. (write) */
76
77/* Page1 registers */
78
79#define NIC_PAR0 (1*2) /* Physical address */
80#define NIC_PAR1 (2*2)
81#define NIC_PAR2 (3*2)
82#define NIC_PAR3 (4*2)
83#define NIC_PAR4 (5*2)
84#define NIC_PAR5 (6*2)
85#define NIC_CURR (7*2) /* Current RX ring-buffer page */
86#define NIC_MAR0 (8*2) /* Multicast address */
87#define NIC_MAR1 (9*2)
88#define NIC_MAR2 (0xa*2)
89#define NIC_MAR3 (0xb*2)
90#define NIC_MAR4 (0xc*2)
91#define NIC_MAR5 (0xd*2)
92#define NIC_MAR6 (0xe*2)
93#define NIC_MAR7 (0xf*2)
94
95/* Command register definitions */
96
97#define CR_STOP 0x01 /* Stop -- software reset command */
98#define CR_START 0x02 /* Start */
99#define CR_TXP 0x04 /* Transmit packet */
100
101#define CR_RD0 0x08 /* Remote DMA cmd */
102#define CR_RD1 0x10
103#define CR_RD2 0x20
104
105#define CR_NODMA CR_RD2
106
107#define CR_PS0 0x40 /* Page select */
108#define CR_PS1 0x80
109
110#define CR_PAGE0 0
111#define CR_PAGE1 CR_PS0
112#define CR_PAGE2 CR_PS1
113
114/* Interrupt status reg. definitions */
115
116#define ISR_PRX 0x01 /* Packet received without errors */
117#define ISR_PTX 0x02 /* Packet transmitted without errors */
118#define ISR_RXE 0x04 /* Receive error */
119#define ISR_TXE 0x08 /* Transmit error */
120#define ISR_OVW 0x10 /* Ring buffer overrun */
121#define ISR_CNT 0x20 /* Counter overflow */
122#define ISR_RDC 0x40 /* Remote DMA compile */
123#define ISR_RST 0x80 /* Reset status */
124
125/* Data config reg. definitions */
126
127#define DCR_WTS 0x01 /* Word transfer select */
128#define DCR_BOS 0x02 /* Byte order select */
129#define DCR_LAS 0x04 /* Long address select */
130#define DCR_LS 0x08 /* Loopback select */
131#define DCR_AR 0x10 /* Auto-init remote */
132#define DCR_FT0 0x20 /* FIFO threshold select */
133#define DCR_FT1 0x40
134
135/* Transmit config reg. definitions */
136
137#define TCR_CRC 0x01 /* Inhibit CRC */
138#define TCR_LB0 0x02 /* Loopback control */
139#define TCR_LB1 0x04
140#define TCR_ATD 0x08 /* Auto transmit disable */
141#define TCR_OFST 0x10 /* Collision offset enable */
142
143/* Transmit status reg. definitions */
144
145#define TSR_PTX 0x01 /* Packet transmitted */
146#define TSR_COL 0x04 /* Transmit collided */
147#define TSR_ABT 0x08 /* Transmit aborted */
148#define TSR_CRS 0x10 /* Carrier sense lost */
149#define TSR_FU 0x20 /* FIFO underrun */
150#define TSR_CDH 0x40 /* CD Heartbeat */
151#define TSR_OWC 0x80 /* Out of Window Collision */
152
153/* Receiver config register definitions */
154
155#define RCR_SEP 0x01 /* Save errored packets */
156#define RCR_AR 0x02 /* Accept runt packets */
157#define RCR_AB 0x04 /* Accept broadcast */
158#define RCR_AM 0x08 /* Accept multicast */
159#define RCR_PRO 0x10 /* Promiscuous mode */
160#define RCR_MON 0x20 /* Monitor mode */
161
162/* Receiver status register definitions */
163
164#define RSR_PRX 0x01 /* Packet received without error */
165#define RSR_CRC 0x02 /* CRC error */
166#define RSR_FAE 0x04 /* Frame alignment error */
167#define RSR_FO 0x08 /* FIFO overrun */
168#define RSR_MPA 0x10 /* Missed packet */
169#define RSR_PHY 0x20 /* Physical address */
170#define RSR_DIS 0x40 /* Received disabled */
171#define RSR_DFR 0x80 /* Deferring (jabber) */
172
173/* Hydra System card address PROM offset */
174
175#define HYDRA_ADDRPROM 0xffc0
176
177
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index ceb98fd398af..52d01027d9e7 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -235,7 +235,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, struc
235 235
236 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); 236 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
237 237
238 if(lpar_rc != H_Success) { 238 if(lpar_rc != H_SUCCESS) {
239 pool->free_map[free_index] = index; 239 pool->free_map[free_index] = index;
240 pool->skbuff[index] = NULL; 240 pool->skbuff[index] = NULL;
241 pool->consumer_index--; 241 pool->consumer_index--;
@@ -373,7 +373,7 @@ static void ibmveth_rxq_recycle_buffer(struct ibmveth_adapter *adapter)
373 373
374 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc); 374 lpar_rc = h_add_logical_lan_buffer(adapter->vdev->unit_address, desc.desc);
375 375
376 if(lpar_rc != H_Success) { 376 if(lpar_rc != H_SUCCESS) {
377 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc); 377 ibmveth_debug_printk("h_add_logical_lan_buffer failed during recycle rc=%ld", lpar_rc);
378 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator); 378 ibmveth_remove_buffer_from_pool(adapter, adapter->rx_queue.queue_addr[adapter->rx_queue.index].correlator);
379 } 379 }
@@ -511,7 +511,7 @@ static int ibmveth_open(struct net_device *netdev)
511 adapter->filter_list_dma, 511 adapter->filter_list_dma,
512 mac_address); 512 mac_address);
513 513
514 if(lpar_rc != H_Success) { 514 if(lpar_rc != H_SUCCESS) {
515 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc); 515 ibmveth_error_printk("h_register_logical_lan failed with %ld\n", lpar_rc);
516 ibmveth_error_printk("buffer TCE:0x%lx filter TCE:0x%lx rxq desc:0x%lx MAC:0x%lx\n", 516 ibmveth_error_printk("buffer TCE:0x%lx filter TCE:0x%lx rxq desc:0x%lx MAC:0x%lx\n",
517 adapter->buffer_list_dma, 517 adapter->buffer_list_dma,
@@ -527,7 +527,7 @@ static int ibmveth_open(struct net_device *netdev)
527 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc); 527 ibmveth_error_printk("unable to request irq 0x%x, rc %d\n", netdev->irq, rc);
528 do { 528 do {
529 rc = h_free_logical_lan(adapter->vdev->unit_address); 529 rc = h_free_logical_lan(adapter->vdev->unit_address);
530 } while (H_isLongBusy(rc) || (rc == H_Busy)); 530 } while (H_IS_LONG_BUSY(rc) || (rc == H_BUSY));
531 531
532 ibmveth_cleanup(adapter); 532 ibmveth_cleanup(adapter);
533 return rc; 533 return rc;
@@ -556,9 +556,9 @@ static int ibmveth_close(struct net_device *netdev)
556 556
557 do { 557 do {
558 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address); 558 lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
559 } while (H_isLongBusy(lpar_rc) || (lpar_rc == H_Busy)); 559 } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
560 560
561 if(lpar_rc != H_Success) 561 if(lpar_rc != H_SUCCESS)
562 { 562 {
563 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n", 563 ibmveth_error_printk("h_free_logical_lan failed with %lx, continuing with close\n",
564 lpar_rc); 564 lpar_rc);
@@ -693,9 +693,9 @@ static int ibmveth_start_xmit(struct sk_buff *skb, struct net_device *netdev)
693 desc[4].desc, 693 desc[4].desc,
694 desc[5].desc, 694 desc[5].desc,
695 correlator); 695 correlator);
696 } while ((lpar_rc == H_Busy) && (retry_count--)); 696 } while ((lpar_rc == H_BUSY) && (retry_count--));
697 697
698 if(lpar_rc != H_Success && lpar_rc != H_Dropped) { 698 if(lpar_rc != H_SUCCESS && lpar_rc != H_DROPPED) {
699 int i; 699 int i;
700 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc); 700 ibmveth_error_printk("tx: h_send_logical_lan failed with rc=%ld\n", lpar_rc);
701 for(i = 0; i < 6; i++) { 701 for(i = 0; i < 6; i++) {
@@ -786,14 +786,14 @@ static int ibmveth_poll(struct net_device *netdev, int *budget)
786 /* we think we are done - reenable interrupts, then check once more to make sure we are done */ 786 /* we think we are done - reenable interrupts, then check once more to make sure we are done */
787 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_ENABLE); 787 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_ENABLE);
788 788
789 ibmveth_assert(lpar_rc == H_Success); 789 ibmveth_assert(lpar_rc == H_SUCCESS);
790 790
791 netif_rx_complete(netdev); 791 netif_rx_complete(netdev);
792 792
793 if(ibmveth_rxq_pending_buffer(adapter) && netif_rx_reschedule(netdev, frames_processed)) 793 if(ibmveth_rxq_pending_buffer(adapter) && netif_rx_reschedule(netdev, frames_processed))
794 { 794 {
795 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); 795 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
796 ibmveth_assert(lpar_rc == H_Success); 796 ibmveth_assert(lpar_rc == H_SUCCESS);
797 more_work = 1; 797 more_work = 1;
798 goto restart_poll; 798 goto restart_poll;
799 } 799 }
@@ -813,7 +813,7 @@ static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance, struct pt_regs
813 813
814 if(netif_rx_schedule_prep(netdev)) { 814 if(netif_rx_schedule_prep(netdev)) {
815 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE); 815 lpar_rc = h_vio_signal(adapter->vdev->unit_address, VIO_IRQ_DISABLE);
816 ibmveth_assert(lpar_rc == H_Success); 816 ibmveth_assert(lpar_rc == H_SUCCESS);
817 __netif_rx_schedule(netdev); 817 __netif_rx_schedule(netdev);
818 } 818 }
819 return IRQ_HANDLED; 819 return IRQ_HANDLED;
@@ -835,7 +835,7 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
835 IbmVethMcastEnableRecv | 835 IbmVethMcastEnableRecv |
836 IbmVethMcastDisableFiltering, 836 IbmVethMcastDisableFiltering,
837 0); 837 0);
838 if(lpar_rc != H_Success) { 838 if(lpar_rc != H_SUCCESS) {
839 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc); 839 ibmveth_error_printk("h_multicast_ctrl rc=%ld when entering promisc mode\n", lpar_rc);
840 } 840 }
841 } else { 841 } else {
@@ -847,7 +847,7 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
847 IbmVethMcastDisableFiltering | 847 IbmVethMcastDisableFiltering |
848 IbmVethMcastClearFilterTable, 848 IbmVethMcastClearFilterTable,
849 0); 849 0);
850 if(lpar_rc != H_Success) { 850 if(lpar_rc != H_SUCCESS) {
851 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc); 851 ibmveth_error_printk("h_multicast_ctrl rc=%ld when attempting to clear filter table\n", lpar_rc);
852 } 852 }
853 /* add the addresses to the filter table */ 853 /* add the addresses to the filter table */
@@ -858,7 +858,7 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
858 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 858 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
859 IbmVethMcastAddFilter, 859 IbmVethMcastAddFilter,
860 mcast_addr); 860 mcast_addr);
861 if(lpar_rc != H_Success) { 861 if(lpar_rc != H_SUCCESS) {
862 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc); 862 ibmveth_error_printk("h_multicast_ctrl rc=%ld when adding an entry to the filter table\n", lpar_rc);
863 } 863 }
864 } 864 }
@@ -867,7 +867,7 @@ static void ibmveth_set_multicast_list(struct net_device *netdev)
867 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address, 867 lpar_rc = h_multicast_ctrl(adapter->vdev->unit_address,
868 IbmVethMcastEnableFiltering, 868 IbmVethMcastEnableFiltering,
869 0); 869 0);
870 if(lpar_rc != H_Success) { 870 if(lpar_rc != H_SUCCESS) {
871 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc); 871 ibmveth_error_printk("h_multicast_ctrl rc=%ld when enabling filtering\n", lpar_rc);
872 } 872 }
873 } 873 }
diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
index 6e2ec56cde0b..96bdb73c2283 100644
--- a/drivers/net/irda/irda-usb.c
+++ b/drivers/net/irda/irda-usb.c
@@ -1,7 +1,7 @@
1/***************************************************************************** 1/*****************************************************************************
2 * 2 *
3 * Filename: irda-usb.c 3 * Filename: irda-usb.c
4 * Version: 0.9b 4 * Version: 0.10
5 * Description: IrDA-USB Driver 5 * Description: IrDA-USB Driver
6 * Status: Experimental 6 * Status: Experimental
7 * Author: Dag Brattli <dag@brattli.net> 7 * Author: Dag Brattli <dag@brattli.net>
@@ -9,6 +9,9 @@
9 * Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at> 9 * Copyright (C) 2000, Roman Weissgaerber <weissg@vienna.at>
10 * Copyright (C) 2001, Dag Brattli <dag@brattli.net> 10 * Copyright (C) 2001, Dag Brattli <dag@brattli.net>
11 * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com> 11 * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
12 * Copyright (C) 2004, SigmaTel, Inc. <irquality@sigmatel.com>
13 * Copyright (C) 2005, Milan Beno <beno@pobox.sk>
14 * Copyright (C) 2006, Nick Fedchik <nick@fedchik.org.ua>
12 * 15 *
13 * This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
@@ -61,6 +64,7 @@
61#include <linux/slab.h> 64#include <linux/slab.h>
62#include <linux/rtnetlink.h> 65#include <linux/rtnetlink.h>
63#include <linux/usb.h> 66#include <linux/usb.h>
67#include <linux/firmware.h>
64 68
65#include "irda-usb.h" 69#include "irda-usb.h"
66 70
@@ -78,8 +82,12 @@ static struct usb_device_id dongles[] = {
78 { USB_DEVICE(0x50f, 0x180), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW }, 82 { USB_DEVICE(0x50f, 0x180), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
79 /* Extended Systems, Inc., XTNDAccess IrDA USB (ESI-9685) */ 83 /* Extended Systems, Inc., XTNDAccess IrDA USB (ESI-9685) */
80 { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW }, 84 { USB_DEVICE(0x8e9, 0x100), .driver_info = IUC_SPEED_BUG | IUC_NO_WINDOW },
85 /* SigmaTel STIR4210/4220/4116 USB IrDA (VFIR) Bridge */
86 { USB_DEVICE(0x66f, 0x4210), .driver_info = IUC_STIR_4210 | IUC_SPEED_BUG },
87 { USB_DEVICE(0x66f, 0x4220), .driver_info = IUC_STIR_4210 | IUC_SPEED_BUG },
88 { USB_DEVICE(0x66f, 0x4116), .driver_info = IUC_STIR_4210 | IUC_SPEED_BUG },
81 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | 89 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
82 USB_DEVICE_ID_MATCH_INT_SUBCLASS, 90 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
83 .bInterfaceClass = USB_CLASS_APP_SPEC, 91 .bInterfaceClass = USB_CLASS_APP_SPEC,
84 .bInterfaceSubClass = USB_CLASS_IRDA, 92 .bInterfaceSubClass = USB_CLASS_IRDA,
85 .driver_info = IUC_DEFAULT, }, 93 .driver_info = IUC_DEFAULT, },
@@ -99,6 +107,7 @@ MODULE_DEVICE_TABLE(usb, dongles);
99 107
100/*------------------------------------------------------------------*/ 108/*------------------------------------------------------------------*/
101 109
110static void irda_usb_init_qos(struct irda_usb_cb *self) ;
102static struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf); 111static struct irda_class_desc *irda_usb_find_class_desc(struct usb_interface *intf);
103static void irda_usb_disconnect(struct usb_interface *intf); 112static void irda_usb_disconnect(struct usb_interface *intf);
104static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self); 113static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self);
@@ -141,7 +150,24 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
141 __u8 *header, 150 __u8 *header,
142 int force) 151 int force)
143{ 152{
144 /* Set the negotiated link speed */ 153 /* Here we check if we have an STIR421x chip,
154 * and if either speed or xbofs (or both) needs
155 * to be changed.
156 */
157 if (self->capability & IUC_STIR_4210 &&
158 ((self->new_speed != -1) || (self->new_xbofs != -1))) {
159
160 /* With STIR421x, speed and xBOFs must be set at the same
161 * time, even if only one of them changes.
162 */
163 if (self->new_speed == -1)
164 self->new_speed = self->speed ;
165
166 if (self->new_xbofs == -1)
167 self->new_xbofs = self->xbofs ;
168 }
169
170 /* Set the link speed */
145 if (self->new_speed != -1) { 171 if (self->new_speed != -1) {
146 /* Hum... Ugly hack :-( 172 /* Hum... Ugly hack :-(
147 * Some device are not compliant with the spec and change 173 * Some device are not compliant with the spec and change
@@ -191,7 +217,11 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
191 *header = SPEED_4000000; 217 *header = SPEED_4000000;
192 self->new_xbofs = 0; 218 self->new_xbofs = 0;
193 break; 219 break;
194 } 220 case 16000000:
221 *header = SPEED_16000000;
222 self->new_xbofs = 0;
223 break;
224 }
195 } else 225 } else
196 /* No change */ 226 /* No change */
197 *header = 0; 227 *header = 0;
@@ -235,6 +265,32 @@ static void irda_usb_build_header(struct irda_usb_cb *self,
235 } 265 }
236} 266}
237 267
268/*
269* calculate turnaround time for SigmaTel header
270*/
271static __u8 get_turnaround_time(struct sk_buff *skb)
272{
273 int turnaround_time = irda_get_mtt(skb);
274
275 if ( turnaround_time == 0 )
276 return 0;
277 else if ( turnaround_time <= 10 )
278 return 1;
279 else if ( turnaround_time <= 50 )
280 return 2;
281 else if ( turnaround_time <= 100 )
282 return 3;
283 else if ( turnaround_time <= 500 )
284 return 4;
285 else if ( turnaround_time <= 1000 )
286 return 5;
287 else if ( turnaround_time <= 5000 )
288 return 6;
289 else
290 return 7;
291}
292
293
238/*------------------------------------------------------------------*/ 294/*------------------------------------------------------------------*/
239/* 295/*
240 * Send a command to change the speed of the dongle 296 * Send a command to change the speed of the dongle
@@ -262,12 +318,18 @@ static void irda_usb_change_speed_xbofs(struct irda_usb_cb *self)
262 /* Set the new speed and xbofs in this fake frame */ 318 /* Set the new speed and xbofs in this fake frame */
263 irda_usb_build_header(self, frame, 1); 319 irda_usb_build_header(self, frame, 1);
264 320
321 if ( self->capability & IUC_STIR_4210 ) {
322 if (frame[0] == 0) return ; // do nothing if no change
323 frame[1] = 0; // other parameters don't change here
324 frame[2] = 0;
325 }
326
265 /* Submit the 0 length IrDA frame to trigger new speed settings */ 327 /* Submit the 0 length IrDA frame to trigger new speed settings */
266 usb_fill_bulk_urb(urb, self->usbdev, 328 usb_fill_bulk_urb(urb, self->usbdev,
267 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep), 329 usb_sndbulkpipe(self->usbdev, self->bulk_out_ep),
268 frame, IRDA_USB_SPEED_MTU, 330 frame, IRDA_USB_SPEED_MTU,
269 speed_bulk_callback, self); 331 speed_bulk_callback, self);
270 urb->transfer_buffer_length = USB_IRDA_HEADER; 332 urb->transfer_buffer_length = self->header_length;
271 urb->transfer_flags = 0; 333 urb->transfer_flags = 0;
272 334
273 /* Irq disabled -> GFP_ATOMIC */ 335 /* Irq disabled -> GFP_ATOMIC */
@@ -383,16 +445,35 @@ static int irda_usb_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
383 * allocation will be done lower in skb_push(). 445 * allocation will be done lower in skb_push().
384 * Also, we don't use directly skb_cow(), because it require 446 * Also, we don't use directly skb_cow(), because it require
385 * headroom >= 16, which force unnecessary copies - Jean II */ 447 * headroom >= 16, which force unnecessary copies - Jean II */
386 if (skb_headroom(skb) < USB_IRDA_HEADER) { 448 if (skb_headroom(skb) < self->header_length) {
387 IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__); 449 IRDA_DEBUG(0, "%s(), Insuficient skb headroom.\n", __FUNCTION__);
388 if (skb_cow(skb, USB_IRDA_HEADER)) { 450 if (skb_cow(skb, self->header_length)) {
389 IRDA_WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__); 451 IRDA_WARNING("%s(), failed skb_cow() !!!\n", __FUNCTION__);
390 goto drop; 452 goto drop;
391 } 453 }
392 } 454 }
393 455
394 /* Change setting for next frame */ 456 /* Change setting for next frame */
395 irda_usb_build_header(self, skb_push(skb, USB_IRDA_HEADER), 0); 457
458 if ( self->capability & IUC_STIR_4210 ) {
459 __u8 turnaround_time;
460 __u8* frame;
461 turnaround_time = get_turnaround_time( skb );
462 frame= skb_push(skb, self->header_length);
463 irda_usb_build_header(self, frame, 0);
464 frame[2] = turnaround_time;
465 if ((skb->len != 0) &&
466 ((skb->len % 128) == 0) &&
467 ((skb->len % 512) != 0)) {
468 /* add extra byte for special SigmaTel feature */
469 frame[1] = 1;
470 skb_put(skb, 1);
471 } else {
472 frame[1] = 0;
473 }
474 } else {
475 irda_usb_build_header(self, skb_push(skb, self->header_length), 0);
476 }
396 477
397 /* FIXME: Make macro out of this one */ 478 /* FIXME: Make macro out of this one */
398 ((struct irda_skb_cb *)skb->cb)->context = self; 479 ((struct irda_skb_cb *)skb->cb)->context = self;
@@ -795,7 +876,7 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
795 } 876 }
796 877
797 /* Check for empty frames */ 878 /* Check for empty frames */
798 if (urb->actual_length <= USB_IRDA_HEADER) { 879 if (urb->actual_length <= self->header_length) {
799 IRDA_WARNING("%s(), empty frame!\n", __FUNCTION__); 880 IRDA_WARNING("%s(), empty frame!\n", __FUNCTION__);
800 goto done; 881 goto done;
801 } 882 }
@@ -816,7 +897,11 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
816 docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD); 897 docopy = (urb->actual_length < IRDA_RX_COPY_THRESHOLD);
817 898
818 /* Allocate a new skb */ 899 /* Allocate a new skb */
819 newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU); 900 if ( self->capability & IUC_STIR_4210 )
901 newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU + USB_IRDA_SIGMATEL_HEADER);
902 else
903 newskb = dev_alloc_skb(docopy ? urb->actual_length : IRDA_SKB_MAX_MTU);
904
820 if (!newskb) { 905 if (!newskb) {
821 self->stats.rx_dropped++; 906 self->stats.rx_dropped++;
822 /* We could deliver the current skb, but this would stall 907 /* We could deliver the current skb, but this would stall
@@ -845,7 +930,7 @@ static void irda_usb_receive(struct urb *urb, struct pt_regs *regs)
845 930
846 /* Set proper length on skb & remove USB-IrDA header */ 931 /* Set proper length on skb & remove USB-IrDA header */
847 skb_put(dataskb, urb->actual_length); 932 skb_put(dataskb, urb->actual_length);
848 skb_pull(dataskb, USB_IRDA_HEADER); 933 skb_pull(dataskb, self->header_length);
849 934
850 /* Ask the networking layer to queue the packet for the IrDA stack */ 935 /* Ask the networking layer to queue the packet for the IrDA stack */
851 dataskb->dev = self->netdev; 936 dataskb->dev = self->netdev;
@@ -937,6 +1022,191 @@ static int irda_usb_is_receiving(struct irda_usb_cb *self)
937 return 0; /* For now */ 1022 return 0; /* For now */
938} 1023}
939 1024
1025
1026#define STIR421X_PATCH_PRODUCT_VERSION_STR "Product Version: "
1027#define STIR421X_PATCH_COMPONENT_VERSION_STR "Component Version: "
1028#define STIR421X_PATCH_DATA_TAG_STR "STMP"
1029#define STIR421X_PATCH_FILE_VERSION_MAX_OFFSET 512 /* version info is before here */
1030#define STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET 512 /* patch image starts before here */
1031#define STIR421X_PATCH_FILE_END_OF_HEADER_TAG 0x1A /* marks end of patch file header (PC DOS text file EOF character) */
1032
1033/*
1034 * Known firmware patches for STIR421x dongles
1035 */
1036static char * stir421x_patches[] = {
1037 "42101001.sb",
1038 "42101002.sb",
1039};
1040
1041static int stir421x_get_patch_version(unsigned char * patch, const unsigned long patch_len)
1042{
1043 unsigned int version_offset;
1044 unsigned long version_major, version_minor, version_build;
1045 unsigned char * version_start;
1046 int version_found = 0;
1047
1048 for (version_offset = 0;
1049 version_offset < STIR421X_PATCH_FILE_END_OF_HEADER_TAG;
1050 version_offset++) {
1051 if (!memcmp(patch + version_offset,
1052 STIR421X_PATCH_PRODUCT_VERSION_STR,
1053 sizeof(STIR421X_PATCH_PRODUCT_VERSION_STR) - 1)) {
1054 version_found = 1;
1055 version_start = patch +
1056 version_offset +
1057 sizeof(STIR421X_PATCH_PRODUCT_VERSION_STR) - 1;
1058 break;
1059 }
1060 }
1061
1062 /* We couldn't find a product version on this patch */
1063 if (!version_found)
1064 return -EINVAL;
1065
1066 /* Let's check if the product version is dotted */
1067 if (version_start[3] != '.' ||
1068 version_start[7] != '.')
1069 return -EINVAL;
1070
1071 version_major = simple_strtoul(version_start, NULL, 10);
1072 version_minor = simple_strtoul(version_start + 4, NULL, 10);
1073 version_build = simple_strtoul(version_start + 8, NULL, 10);
1074
1075 IRDA_DEBUG(2, "%s(), Major: %ld Minor: %ld Build: %ld\n",
1076 __FUNCTION__,
1077 version_major, version_minor, version_build);
1078
1079 return (((version_major) << 12) +
1080 ((version_minor) << 8) +
1081 ((version_build / 10) << 4) +
1082 (version_build % 10));
1083
1084}
1085
1086
1087static int stir421x_upload_patch (struct irda_usb_cb *self,
1088 unsigned char * patch,
1089 const unsigned int patch_len)
1090{
1091 int retval = 0;
1092 int actual_len;
1093 unsigned int i = 0, download_amount = 0;
1094 unsigned char * patch_chunk;
1095
1096 IRDA_DEBUG (2, "%s(), Uploading STIR421x Patch\n", __FUNCTION__);
1097
1098 patch_chunk = kzalloc(STIR421X_MAX_PATCH_DOWNLOAD_SIZE, GFP_KERNEL);
1099 if (patch_chunk == NULL)
1100 return -ENOMEM;
1101
1102 /* break up patch into 1023-byte sections */
1103 for (i = 0; retval >= 0 && i < patch_len; i += download_amount) {
1104 download_amount = patch_len - i;
1105 if (download_amount > STIR421X_MAX_PATCH_DOWNLOAD_SIZE)
1106 download_amount = STIR421X_MAX_PATCH_DOWNLOAD_SIZE;
1107
1108 /* download the patch section */
1109 memcpy(patch_chunk, patch + i, download_amount);
1110
1111 retval = usb_bulk_msg (self->usbdev,
1112 usb_sndbulkpipe (self->usbdev,
1113 self->bulk_out_ep),
1114 patch_chunk, download_amount,
1115 &actual_len, msecs_to_jiffies (500));
1116 IRDA_DEBUG (2, "%s(), Sent %u bytes\n", __FUNCTION__,
1117 actual_len);
1118 if (retval == 0)
1119 mdelay(10);
1120 }
1121
1122 kfree(patch_chunk);
1123
1124 if (i != patch_len) {
1125 IRDA_ERROR ("%s(), Pushed %d bytes (!= patch_len (%d))\n",
1126 __FUNCTION__, i, patch_len);
1127 retval = -EIO;
1128 }
1129
1130 if (retval < 0)
1131 /* todo - mark device as not ready */
1132 IRDA_ERROR ("%s(), STIR421x patch upload failed (%d)\n",
1133 __FUNCTION__, retval);
1134
1135 return retval;
1136}
1137
1138
1139static int stir421x_patch_device(struct irda_usb_cb *self)
1140{
1141 unsigned int i, patch_found = 0, data_found = 0, data_offset;
1142 int patch_version, ret = 0;
1143 const struct firmware *fw_entry;
1144
1145 for (i = 0; i < ARRAY_SIZE(stir421x_patches); i++) {
1146 if(request_firmware(&fw_entry, stir421x_patches[i], &self->usbdev->dev) != 0) {
1147 IRDA_ERROR( "%s(), Patch %s is not available\n", __FUNCTION__, stir421x_patches[i]);
1148 continue;
1149 }
1150
1151 /* We found a patch from userspace */
1152 patch_version = stir421x_get_patch_version (fw_entry->data, fw_entry->size);
1153
1154 if (patch_version < 0) {
1155 /* Couldn't fetch a version, let's move on to the next file */
1156 IRDA_ERROR("%s(), version parsing failed\n", __FUNCTION__);
1157 ret = patch_version;
1158 release_firmware(fw_entry);
1159 continue;
1160 }
1161
1162 if (patch_version != self->usbdev->descriptor.bcdDevice) {
1163 /* Patch version and device don't match */
1164 IRDA_ERROR ("%s(), wrong patch version (%d <-> %d)\n",
1165 __FUNCTION__,
1166 patch_version, self->usbdev->descriptor.bcdDevice);
1167 ret = -EINVAL;
1168 release_firmware(fw_entry);
1169 continue;
1170 }
1171
1172 /* If we're here, we've found a correct patch */
1173 patch_found = 1;
1174 break;
1175
1176 }
1177
1178 /* We couldn't find a valid firmware, let's leave */
1179 if (!patch_found)
1180 return ret;
1181
1182 /* The actual image starts after the "STMP" keyword */
1183 for (data_offset = 0; data_offset < STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET; data_offset++) {
1184 if (!memcmp(fw_entry->data + data_offset,
1185 STIR421X_PATCH_DATA_TAG_STR,
1186 sizeof(STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET))) {
1187 IRDA_DEBUG(2, "%s(), found patch data for STIR421x at offset %d\n",
1188 __FUNCTION__, data_offset);
1189 data_found = 1;
1190 break;
1191 }
1192 }
1193
1194 /* We couldn't find "STMP" from the header */
1195 if (!data_found)
1196 return -EINVAL;
1197
1198 /* Let's upload the patch to the target */
1199 ret = stir421x_upload_patch(self,
1200 &fw_entry->data[data_offset + sizeof(STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET)],
1201 fw_entry->size - (data_offset + sizeof(STIR421X_PATCH_FILE_IMAGE_MAX_OFFSET)));
1202
1203 release_firmware(fw_entry);
1204
1205 return ret;
1206
1207}
1208
1209
940/********************** IRDA DEVICE CALLBACKS **********************/ 1210/********************** IRDA DEVICE CALLBACKS **********************/
941/* 1211/*
942 * Main calls from the IrDA/Network subsystem. 1212 * Main calls from the IrDA/Network subsystem.
@@ -972,6 +1242,11 @@ static int irda_usb_net_open(struct net_device *netdev)
972 return -1; 1242 return -1;
973 } 1243 }
974 1244
1245 if(self->needspatch) {
1246 IRDA_WARNING("%s(), device needs patch\n", __FUNCTION__) ;
1247 return -EIO ;
1248 }
1249
975 /* Initialise default speed and xbofs value 1250 /* Initialise default speed and xbofs value
976 * (IrLAP will change that soon) */ 1251 * (IrLAP will change that soon) */
977 self->speed = -1; 1252 self->speed = -1;
@@ -1050,7 +1325,7 @@ static int irda_usb_net_close(struct net_device *netdev)
1050 del_timer(&self->rx_defer_timer); 1325 del_timer(&self->rx_defer_timer);
1051 1326
1052 /* Deallocate all the Rx path buffers (URBs and skb) */ 1327 /* Deallocate all the Rx path buffers (URBs and skb) */
1053 for (i = 0; i < IU_MAX_RX_URBS; i++) { 1328 for (i = 0; i < self->max_rx_urb; i++) {
1054 struct urb *urb = self->rx_urb[i]; 1329 struct urb *urb = self->rx_urb[i];
1055 struct sk_buff *skb = (struct sk_buff *) urb->context; 1330 struct sk_buff *skb = (struct sk_buff *) urb->context;
1056 /* Cancel the receive command */ 1331 /* Cancel the receive command */
@@ -1426,8 +1701,22 @@ static int irda_usb_probe(struct usb_interface *intf,
1426 spin_lock_init(&self->lock); 1701 spin_lock_init(&self->lock);
1427 init_timer(&self->rx_defer_timer); 1702 init_timer(&self->rx_defer_timer);
1428 1703
1704 self->capability = id->driver_info;
1705 self->needspatch = ((self->capability & IUC_STIR_4210) != 0) ;
1706
1429 /* Create all of the needed urbs */ 1707 /* Create all of the needed urbs */
1430 for (i = 0; i < IU_MAX_RX_URBS; i++) { 1708 if (self->capability & IUC_STIR_4210) {
1709 self->max_rx_urb = IU_SIGMATEL_MAX_RX_URBS;
1710 self->header_length = USB_IRDA_SIGMATEL_HEADER;
1711 } else {
1712 self->max_rx_urb = IU_MAX_RX_URBS;
1713 self->header_length = USB_IRDA_HEADER;
1714 }
1715
1716 self->rx_urb = kzalloc(self->max_rx_urb * sizeof(struct urb *),
1717 GFP_KERNEL);
1718
1719 for (i = 0; i < self->max_rx_urb; i++) {
1431 self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); 1720 self->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
1432 if (!self->rx_urb[i]) { 1721 if (!self->rx_urb[i]) {
1433 goto err_out_1; 1722 goto err_out_1;
@@ -1479,17 +1768,28 @@ static int irda_usb_probe(struct usb_interface *intf,
1479 goto err_out_3; 1768 goto err_out_3;
1480 } 1769 }
1481 1770
1771 self->usbdev = dev;
1772
1482 /* Find IrDA class descriptor */ 1773 /* Find IrDA class descriptor */
1483 irda_desc = irda_usb_find_class_desc(intf); 1774 irda_desc = irda_usb_find_class_desc(intf);
1484 ret = -ENODEV; 1775 ret = -ENODEV;
1485 if (irda_desc == NULL) 1776 if (irda_desc == NULL)
1486 goto err_out_3; 1777 goto err_out_3;
1487 1778
1779 if (self->needspatch) {
1780 ret = usb_control_msg (self->usbdev, usb_sndctrlpipe (self->usbdev, 0),
1781 0x02, 0x40, 0, 0, 0, 0, msecs_to_jiffies(500));
1782 if (ret < 0) {
1783 IRDA_DEBUG (0, "usb_control_msg failed %d\n", ret);
1784 goto err_out_3;
1785 } else {
1786 mdelay(10);
1787 }
1788 }
1789
1488 self->irda_desc = irda_desc; 1790 self->irda_desc = irda_desc;
1489 self->present = 1; 1791 self->present = 1;
1490 self->netopen = 0; 1792 self->netopen = 0;
1491 self->capability = id->driver_info;
1492 self->usbdev = dev;
1493 self->usbintf = intf; 1793 self->usbintf = intf;
1494 1794
1495 /* Allocate the buffer for speed changes */ 1795 /* Allocate the buffer for speed changes */
@@ -1508,8 +1808,32 @@ static int irda_usb_probe(struct usb_interface *intf,
1508 1808
1509 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name); 1809 IRDA_MESSAGE("IrDA: Registered device %s\n", net->name);
1510 usb_set_intfdata(intf, self); 1810 usb_set_intfdata(intf, self);
1811
1812 if (self->needspatch) {
1813 /* Now we fetch and upload the firmware patch */
1814 ret = stir421x_patch_device(self);
1815 self->needspatch = (ret < 0);
1816 if (ret < 0) {
1817 printk("patch_device failed\n");
1818 goto err_out_5;
1819 }
1820
1821 /* replace IrDA class descriptor with what patched device is now reporting */
1822 irda_desc = irda_usb_find_class_desc (self->usbintf);
1823 if (irda_desc == NULL) {
1824 ret = -ENODEV;
1825 goto err_out_5;
1826 }
1827 if (self->irda_desc)
1828 kfree (self->irda_desc);
1829 self->irda_desc = irda_desc;
1830 irda_usb_init_qos(self);
1831 }
1832
1511 return 0; 1833 return 0;
1512 1834
1835err_out_5:
1836 unregister_netdev(self->netdev);
1513err_out_4: 1837err_out_4:
1514 kfree(self->speed_buff); 1838 kfree(self->speed_buff);
1515err_out_3: 1839err_out_3:
@@ -1518,7 +1842,7 @@ err_out_3:
1518err_out_2: 1842err_out_2:
1519 usb_free_urb(self->tx_urb); 1843 usb_free_urb(self->tx_urb);
1520err_out_1: 1844err_out_1:
1521 for (i = 0; i < IU_MAX_RX_URBS; i++) { 1845 for (i = 0; i < self->max_rx_urb; i++) {
1522 if (self->rx_urb[i]) 1846 if (self->rx_urb[i])
1523 usb_free_urb(self->rx_urb[i]); 1847 usb_free_urb(self->rx_urb[i]);
1524 } 1848 }
@@ -1571,7 +1895,7 @@ static void irda_usb_disconnect(struct usb_interface *intf)
1571 /*netif_device_detach(self->netdev);*/ 1895 /*netif_device_detach(self->netdev);*/
1572 netif_stop_queue(self->netdev); 1896 netif_stop_queue(self->netdev);
1573 /* Stop all the receive URBs. Must be synchronous. */ 1897 /* Stop all the receive URBs. Must be synchronous. */
1574 for (i = 0; i < IU_MAX_RX_URBS; i++) 1898 for (i = 0; i < self->max_rx_urb; i++)
1575 usb_kill_urb(self->rx_urb[i]); 1899 usb_kill_urb(self->rx_urb[i]);
1576 /* Cancel Tx and speed URB. 1900 /* Cancel Tx and speed URB.
1577 * Make sure it's synchronous to avoid races. */ 1901 * Make sure it's synchronous to avoid races. */
@@ -1586,8 +1910,9 @@ static void irda_usb_disconnect(struct usb_interface *intf)
1586 self->usbintf = NULL; 1910 self->usbintf = NULL;
1587 1911
1588 /* Clean up our urbs */ 1912 /* Clean up our urbs */
1589 for (i = 0; i < IU_MAX_RX_URBS; i++) 1913 for (i = 0; i < self->max_rx_urb; i++)
1590 usb_free_urb(self->rx_urb[i]); 1914 usb_free_urb(self->rx_urb[i]);
1915 kfree(self->rx_urb);
1591 /* Clean up Tx and speed URB */ 1916 /* Clean up Tx and speed URB */
1592 usb_free_urb(self->tx_urb); 1917 usb_free_urb(self->tx_urb);
1593 usb_free_urb(self->speed_urb); 1918 usb_free_urb(self->speed_urb);
@@ -1648,6 +1973,6 @@ module_exit(usb_irda_cleanup);
1648 */ 1973 */
1649module_param(qos_mtt_bits, int, 0); 1974module_param(qos_mtt_bits, int, 0);
1650MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time"); 1975MODULE_PARM_DESC(qos_mtt_bits, "Minimum Turn Time");
1651MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net> and Jean Tourrilhes <jt@hpl.hp.com>"); 1976MODULE_AUTHOR("Roman Weissgaerber <weissg@vienna.at>, Dag Brattli <dag@brattli.net>, Jean Tourrilhes <jt@hpl.hp.com> and Nick Fedchik <nick@fedchik.org.ua>");
1652MODULE_DESCRIPTION("IrDA-USB Dongle Driver"); 1977MODULE_DESCRIPTION("IrDA-USB Dongle Driver");
1653MODULE_LICENSE("GPL"); 1978MODULE_LICENSE("GPL");
diff --git a/drivers/net/irda/irda-usb.h b/drivers/net/irda/irda-usb.h
index 4026af42dd47..d833db52cebf 100644
--- a/drivers/net/irda/irda-usb.h
+++ b/drivers/net/irda/irda-usb.h
@@ -1,7 +1,7 @@
1/***************************************************************************** 1/*****************************************************************************
2 * 2 *
3 * Filename: irda-usb.h 3 * Filename: irda-usb.h
4 * Version: 0.9b 4 * Version: 0.10
5 * Description: IrDA-USB Driver 5 * Description: IrDA-USB Driver
6 * Status: Experimental 6 * Status: Experimental
7 * Author: Dag Brattli <dag@brattli.net> 7 * Author: Dag Brattli <dag@brattli.net>
@@ -9,6 +9,9 @@
9 * Copyright (C) 2001, Roman Weissgaerber <weissg@vienna.at> 9 * Copyright (C) 2001, Roman Weissgaerber <weissg@vienna.at>
10 * Copyright (C) 2000, Dag Brattli <dag@brattli.net> 10 * Copyright (C) 2000, Dag Brattli <dag@brattli.net>
11 * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com> 11 * Copyright (C) 2001, Jean Tourrilhes <jt@hpl.hp.com>
12 * Copyright (C) 2004, SigmaTel, Inc. <irquality@sigmatel.com>
13 * Copyright (C) 2005, Milan Beno <beno@pobox.sk>
14 * Copyright (C) 2006, Nick FEdchik <nick@fedchik.org.ua>
12 * 15 *
13 * This program is free software; you can redistribute it and/or modify 16 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by 17 * it under the terms of the GNU General Public License as published by
@@ -31,6 +34,9 @@
31#include <net/irda/irda.h> 34#include <net/irda/irda.h>
32#include <net/irda/irda_device.h> /* struct irlap_cb */ 35#include <net/irda/irda_device.h> /* struct irlap_cb */
33 36
37#define PATCH_FILE_SIZE_MAX 65536
38#define PATCH_FILE_SIZE_MIN 80
39
34#define RX_COPY_THRESHOLD 200 40#define RX_COPY_THRESHOLD 200
35#define IRDA_USB_MAX_MTU 2051 41#define IRDA_USB_MAX_MTU 2051
36#define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */ 42#define IRDA_USB_SPEED_MTU 64 /* Weird, but work like this */
@@ -79,15 +85,16 @@
79/* Inbound header */ 85/* Inbound header */
80#define MEDIA_BUSY 0x80 86#define MEDIA_BUSY 0x80
81 87
82#define SPEED_2400 0x01 88#define SPEED_2400 0x01
83#define SPEED_9600 0x02 89#define SPEED_9600 0x02
84#define SPEED_19200 0x03 90#define SPEED_19200 0x03
85#define SPEED_38400 0x04 91#define SPEED_38400 0x04
86#define SPEED_57600 0x05 92#define SPEED_57600 0x05
87#define SPEED_115200 0x06 93#define SPEED_115200 0x06
88#define SPEED_576000 0x07 94#define SPEED_576000 0x07
89#define SPEED_1152000 0x08 95#define SPEED_1152000 0x08
90#define SPEED_4000000 0x09 96#define SPEED_4000000 0x09
97#define SPEED_16000000 0x0a
91 98
92/* Basic capabilities */ 99/* Basic capabilities */
93#define IUC_DEFAULT 0x00 /* Basic device compliant with 1.0 spec */ 100#define IUC_DEFAULT 0x00 /* Basic device compliant with 1.0 spec */
@@ -100,11 +107,14 @@
100#define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */ 107#define IUC_SMALL_PKT 0x10 /* Device doesn't behave with big Rx packets */
101#define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */ 108#define IUC_MAX_WINDOW 0x20 /* Device underestimate the Rx window */
102#define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */ 109#define IUC_MAX_XBOFS 0x40 /* Device need more xbofs than advertised */
110#define IUC_STIR_4210 0x80 /* SigmaTel 4210/4220/4116 VFIR */
103 111
104/* USB class definitions */ 112/* USB class definitions */
105#define USB_IRDA_HEADER 0x01 113#define USB_IRDA_HEADER 0x01
106#define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */ 114#define USB_CLASS_IRDA 0x02 /* USB_CLASS_APP_SPEC subclass */
107#define USB_DT_IRDA 0x21 115#define USB_DT_IRDA 0x21
116#define USB_IRDA_SIGMATEL_HEADER 0x03
117#define IU_SIGMATEL_MAX_RX_URBS (IU_MAX_ACTIVE_RX_URBS + USB_IRDA_SIGMATEL_HEADER)
108 118
109struct irda_class_desc { 119struct irda_class_desc {
110 __u8 bLength; 120 __u8 bLength;
@@ -123,6 +133,7 @@ struct irda_class_desc {
123 * (6.2.5, USB-IrDA class spec 1.0) */ 133 * (6.2.5, USB-IrDA class spec 1.0) */
124 134
125#define IU_REQ_GET_CLASS_DESC 0x06 135#define IU_REQ_GET_CLASS_DESC 0x06
136#define STIR421X_MAX_PATCH_DOWNLOAD_SIZE 1023
126 137
127struct irda_usb_cb { 138struct irda_usb_cb {
128 struct irda_class_desc *irda_desc; 139 struct irda_class_desc *irda_desc;
@@ -136,7 +147,8 @@ struct irda_usb_cb {
136 __u16 bulk_out_mtu; /* Max Tx packet size in bytes */ 147 __u16 bulk_out_mtu; /* Max Tx packet size in bytes */
137 __u8 bulk_int_ep; /* Interrupt Endpoint assignments */ 148 __u8 bulk_int_ep; /* Interrupt Endpoint assignments */
138 149
139 struct urb *rx_urb[IU_MAX_RX_URBS]; /* URBs used to receive data frames */ 150 __u8 max_rx_urb;
151 struct urb **rx_urb; /* URBs used to receive data frames */
140 struct urb *idle_rx_urb; /* Pointer to idle URB in Rx path */ 152 struct urb *idle_rx_urb; /* Pointer to idle URB in Rx path */
141 struct urb *tx_urb; /* URB used to send data frames */ 153 struct urb *tx_urb; /* URB used to send data frames */
142 struct urb *speed_urb; /* URB used to send speed commands */ 154 struct urb *speed_urb; /* URB used to send speed commands */
@@ -157,6 +169,9 @@ struct irda_usb_cb {
157 __u32 speed; /* Current speed */ 169 __u32 speed; /* Current speed */
158 __s32 new_speed; /* speed we need to set */ 170 __s32 new_speed; /* speed we need to set */
159 171
172 __u8 header_length; /* USB-IrDA frame header size */
173 int needspatch; /* device needs firmware patch */
174
160 struct timer_list rx_defer_timer; /* Wait for Rx error to clear */ 175 struct timer_list rx_defer_timer; /* Wait for Rx error to clear */
161}; 176};
162 177
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c
index 63d38fbbd04e..f530686bd09f 100644
--- a/drivers/net/irda/sa1100_ir.c
+++ b/drivers/net/irda/sa1100_ir.c
@@ -695,8 +695,7 @@ static int sa1100_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev)
695 /* 695 /*
696 * We must not be transmitting... 696 * We must not be transmitting...
697 */ 697 */
698 if (si->txskb) 698 BUG_ON(si->txskb);
699 BUG();
700 699
701 netif_stop_queue(dev); 700 netif_stop_queue(dev);
702 701
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index ec94ecdb103d..58f76cefbc83 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -11,6 +11,7 @@
11 * Copyright (c) 2002 Daniele Peri 11 * Copyright (c) 2002 Daniele Peri
12 * All Rights Reserved. 12 * All Rights Reserved.
13 * Copyright (c) 2002 Jean Tourrilhes 13 * Copyright (c) 2002 Jean Tourrilhes
14 * Copyright (c) 2006 Linus Walleij
14 * 15 *
15 * 16 *
16 * Based on smc-ircc.c: 17 * Based on smc-ircc.c:
@@ -61,6 +62,9 @@
61 62
62#include <linux/spinlock.h> 63#include <linux/spinlock.h>
63#include <linux/pm.h> 64#include <linux/pm.h>
65#ifdef CONFIG_PCI
66#include <linux/pci.h>
67#endif
64 68
65#include <net/irda/wrapper.h> 69#include <net/irda/wrapper.h>
66#include <net/irda/irda.h> 70#include <net/irda/irda.h>
@@ -100,6 +104,22 @@ MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
100 104
101/* Types */ 105/* Types */
102 106
107#ifdef CONFIG_PCI
108struct smsc_ircc_subsystem_configuration {
109 unsigned short vendor; /* PCI vendor ID */
110 unsigned short device; /* PCI vendor ID */
111 unsigned short subvendor; /* PCI subsystem vendor ID */
112 unsigned short subdevice; /* PCI sybsystem device ID */
113 unsigned short sir_io; /* I/O port for SIR */
114 unsigned short fir_io; /* I/O port for FIR */
115 unsigned char fir_irq; /* FIR IRQ */
116 unsigned char fir_dma; /* FIR DMA */
117 unsigned short cfg_base; /* I/O port for chip configuration */
118 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
119 const char *name; /* name shown as info */
120};
121#endif
122
103struct smsc_transceiver { 123struct smsc_transceiver {
104 char *name; 124 char *name;
105 void (*set_for_speed)(int fir_base, u32 speed); 125 void (*set_for_speed)(int fir_base, u32 speed);
@@ -202,6 +222,18 @@ static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned shor
202static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type); 222static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
203static int __init smsc_superio_fdc(unsigned short cfg_base); 223static int __init smsc_superio_fdc(unsigned short cfg_base);
204static int __init smsc_superio_lpc(unsigned short cfg_base); 224static int __init smsc_superio_lpc(unsigned short cfg_base);
225#ifdef CONFIG_PCI
226static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
227static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
228static void __init preconfigure_ali_port(struct pci_dev *dev,
229 unsigned short port);
230static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
231static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
232 unsigned short ircc_fir,
233 unsigned short ircc_sir,
234 unsigned char ircc_dma,
235 unsigned char ircc_irq);
236#endif
205 237
206/* Transceivers specific functions */ 238/* Transceivers specific functions */
207 239
@@ -353,6 +385,13 @@ static int __init smsc_ircc_init(void)
353 return ret; 385 return ret;
354 } 386 }
355 387
388#ifdef CONFIG_PCI
389 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
390 /* Ignore errors from preconfiguration */
391 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
392 }
393#endif
394
356 dev_count = 0; 395 dev_count = 0;
357 396
358 if (ircc_fir > 0 && ircc_sir > 0) { 397 if (ircc_fir > 0 && ircc_sir > 0) {
@@ -2285,6 +2324,490 @@ static int __init smsc_superio_lpc(unsigned short cfg_base)
2285 return ret; 2324 return ret;
2286} 2325}
2287 2326
2327/*
2328 * Look for some specific subsystem setups that need
2329 * pre-configuration not properly done by the BIOS (especially laptops)
2330 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2331 * and tosh2450-smcinit.c. The table lists the device entries
2332 * for ISA bridges with an LPC (Low Pin Count) controller which
2333 * handles the communication with the SMSC device. After the LPC
2334 * controller is initialized through PCI, the SMSC device is initialized
2335 * through a dedicated port in the ISA port-mapped I/O area, this latter
2336 * area is used to configure the SMSC device with default
2337 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2338 * used different sets of parameters and different control port
2339 * addresses making a subsystem device table necessary.
2340 */
2341#ifdef CONFIG_PCI
2342#define PCIID_VENDOR_INTEL 0x8086
2343#define PCIID_VENDOR_ALI 0x10b9
2344static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __devinitdata = {
2345 {
2346 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2347 .device = 0x24cc,
2348 .subvendor = 0x103c,
2349 .subdevice = 0x088c,
2350 /* Quite certain these are the same for nc8000 as for nc6000 */
2351 .sir_io = 0x02f8,
2352 .fir_io = 0x0130,
2353 .fir_irq = 0x05,
2354 .fir_dma = 0x03,
2355 .cfg_base = 0x004e,
2356 .preconfigure = preconfigure_through_82801,
2357 .name = "HP nc8000",
2358 },
2359 {
2360 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2361 .device = 0x24cc,
2362 .subvendor = 0x103c,
2363 .subdevice = 0x0890,
2364 .sir_io = 0x02f8,
2365 .fir_io = 0x0130,
2366 .fir_irq = 0x05,
2367 .fir_dma = 0x03,
2368 .cfg_base = 0x004e,
2369 .preconfigure = preconfigure_through_82801,
2370 .name = "HP nc6000",
2371 },
2372 {
2373 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
2374 .vendor = PCIID_VENDOR_INTEL,
2375 .device = 0x24c0,
2376 .subvendor = 0x1179,
2377 .subdevice = 0xffff, /* 0xffff is "any" */
2378 .sir_io = 0x03f8,
2379 .fir_io = 0x0130,
2380 .fir_irq = 0x07,
2381 .fir_dma = 0x01,
2382 .cfg_base = 0x002e,
2383 .preconfigure = preconfigure_through_82801,
2384 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
2385 },
2386 {
2387 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801CAM ISA bridge */
2388 .device = 0x248c,
2389 .subvendor = 0x1179,
2390 .subdevice = 0xffff, /* 0xffff is "any" */
2391 .sir_io = 0x03f8,
2392 .fir_io = 0x0130,
2393 .fir_irq = 0x03,
2394 .fir_dma = 0x03,
2395 .cfg_base = 0x002e,
2396 .preconfigure = preconfigure_through_82801,
2397 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
2398 },
2399 {
2400 /* 82801DBM (ICH4-M) LPC Interface Bridge */
2401 .vendor = PCIID_VENDOR_INTEL,
2402 .device = 0x24cc,
2403 .subvendor = 0x1179,
2404 .subdevice = 0xffff, /* 0xffff is "any" */
2405 .sir_io = 0x03f8,
2406 .fir_io = 0x0130,
2407 .fir_irq = 0x03,
2408 .fir_dma = 0x03,
2409 .cfg_base = 0x002e,
2410 .preconfigure = preconfigure_through_82801,
2411 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2412 },
2413 {
2414 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
2415 .vendor = PCIID_VENDOR_ALI,
2416 .device = 0x1533,
2417 .subvendor = 0x1179,
2418 .subdevice = 0xffff, /* 0xffff is "any" */
2419 .sir_io = 0x02e8,
2420 .fir_io = 0x02f8,
2421 .fir_irq = 0x07,
2422 .fir_dma = 0x03,
2423 .cfg_base = 0x002e,
2424 .preconfigure = preconfigure_through_ali,
2425 .name = "Toshiba laptop with ALi ISA bridge",
2426 },
2427 { } // Terminator
2428};
2429
2430
2431/*
2432 * This sets up the basic SMSC parameters
2433 * (FIR port, SIR port, FIR DMA, FIR IRQ)
2434 * through the chip configuration port.
2435 */
2436static int __init preconfigure_smsc_chip(struct
2437 smsc_ircc_subsystem_configuration
2438 *conf)
2439{
2440 unsigned short iobase = conf->cfg_base;
2441 unsigned char tmpbyte;
2442
2443 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2444 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2445 tmpbyte = inb(iobase +1); // Read device ID
2446 IRDA_DEBUG(0,
2447 "Detected Chip id: 0x%02x, setting up registers...\n",
2448 tmpbyte);
2449
2450 /* Disable UART1 and set up SIR I/O port */
2451 outb(0x24, iobase); // select CR24 - UART1 base addr
2452 outb(0x00, iobase + 1); // disable UART1
2453 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2454 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2455 tmpbyte = inb(iobase + 1);
2456 if (tmpbyte != (conf->sir_io >> 2) ) {
2457 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
2458 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
2459 return -ENXIO;
2460 }
2461
2462 /* Set up FIR IRQ channel for UART2 */
2463 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2464 tmpbyte = inb(iobase + 1);
2465 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2466 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2467 outb(tmpbyte, iobase + 1);
2468 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2469 if (tmpbyte != conf->fir_irq) {
2470 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2471 return -ENXIO;
2472 }
2473
2474 /* Set up FIR I/O port */
2475 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2476 outb((conf->fir_io >> 3), iobase + 1);
2477 tmpbyte = inb(iobase + 1);
2478 if (tmpbyte != (conf->fir_io >> 3) ) {
2479 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2480 return -ENXIO;
2481 }
2482
2483 /* Set up FIR DMA channel */
2484 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2485 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2486 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2487 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2488 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2489 return -ENXIO;
2490 }
2491
2492 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2493 tmpbyte = inb(iobase + 1);
2494 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2495 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
2496 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2497
2498 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2499 tmpbyte = inb(iobase + 1);
2500 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2501
2502 /* This one was not part of tosh1800 */
2503 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2504 tmpbyte = inb(iobase + 1);
2505 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2506
2507 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2508 tmpbyte = inb(iobase + 1);
2509 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2510
2511 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2512 tmpbyte = inb(iobase + 1);
2513 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2514
2515 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2516
2517 return 0;
2518}
2519
2520/* 82801CAM generic registers */
2521#define VID 0x00
2522#define DID 0x02
2523#define PIRQ_A_D_ROUT 0x60
2524#define SIRQ_CNTL 0x64
2525#define PIRQ_E_H_ROUT 0x68
2526#define PCI_DMA_C 0x90
2527/* LPC-specific registers */
2528#define COM_DEC 0xe0
2529#define GEN1_DEC 0xe4
2530#define LPC_EN 0xe6
2531#define GEN2_DEC 0xec
2532/*
2533 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2534 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2535 * They all work the same way!
2536 */
2537static int __init preconfigure_through_82801(struct pci_dev *dev,
2538 struct
2539 smsc_ircc_subsystem_configuration
2540 *conf)
2541{
2542 unsigned short tmpword;
2543 unsigned char tmpbyte;
2544
2545 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2546 /*
2547 * Select the range for the COMA COM port (SIR)
2548 * Register COM_DEC:
2549 * Bit 7: reserved
2550 * Bit 6-4, COMB decode range
2551 * Bit 3: reserved
2552 * Bit 2-0, COMA decode range
2553 *
2554 * Decode ranges:
2555 * 000 = 0x3f8-0x3ff (COM1)
2556 * 001 = 0x2f8-0x2ff (COM2)
2557 * 010 = 0x220-0x227
2558 * 011 = 0x228-0x22f
2559 * 100 = 0x238-0x23f
2560 * 101 = 0x2e8-0x2ef (COM4)
2561 * 110 = 0x338-0x33f
2562 * 111 = 0x3e8-0x3ef (COM3)
2563 */
2564 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2565 tmpbyte &= 0xf8; /* mask COMA bits */
2566 switch(conf->sir_io) {
2567 case 0x3f8:
2568 tmpbyte |= 0x00;
2569 break;
2570 case 0x2f8:
2571 tmpbyte |= 0x01;
2572 break;
2573 case 0x220:
2574 tmpbyte |= 0x02;
2575 break;
2576 case 0x228:
2577 tmpbyte |= 0x03;
2578 break;
2579 case 0x238:
2580 tmpbyte |= 0x04;
2581 break;
2582 case 0x2e8:
2583 tmpbyte |= 0x05;
2584 break;
2585 case 0x338:
2586 tmpbyte |= 0x06;
2587 break;
2588 case 0x3e8:
2589 tmpbyte |= 0x07;
2590 break;
2591 default:
2592 tmpbyte |= 0x01; /* COM2 default */
2593 }
2594 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2595 pci_write_config_byte(dev, COM_DEC, tmpbyte);
2596
2597 /* Enable Low Pin Count interface */
2598 pci_read_config_word(dev, LPC_EN, &tmpword);
2599 /* These seem to be set up at all times,
2600 * just make sure it is properly set.
2601 */
2602 switch(conf->cfg_base) {
2603 case 0x04e:
2604 tmpword |= 0x2000;
2605 break;
2606 case 0x02e:
2607 tmpword |= 0x1000;
2608 break;
2609 case 0x062:
2610 tmpword |= 0x0800;
2611 break;
2612 case 0x060:
2613 tmpword |= 0x0400;
2614 break;
2615 default:
2616 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2617 conf->cfg_base);
2618 break;
2619 }
2620 tmpword &= 0xfffd; /* disable LPC COMB */
2621 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2622 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
2623 pci_write_config_word(dev, LPC_EN, tmpword);
2624
2625 /*
2626 * Configure LPC DMA channel
2627 * PCI_DMA_C bits:
2628 * Bit 15-14: DMA channel 7 select
2629 * Bit 13-12: DMA channel 6 select
2630 * Bit 11-10: DMA channel 5 select
2631 * Bit 9-8: Reserved
2632 * Bit 7-6: DMA channel 3 select
2633 * Bit 5-4: DMA channel 2 select
2634 * Bit 3-2: DMA channel 1 select
2635 * Bit 1-0: DMA channel 0 select
2636 * 00 = Reserved value
2637 * 01 = PC/PCI DMA
2638 * 10 = Reserved value
2639 * 11 = LPC I/F DMA
2640 */
2641 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2642 switch(conf->fir_dma) {
2643 case 0x07:
2644 tmpword |= 0xc000;
2645 break;
2646 case 0x06:
2647 tmpword |= 0x3000;
2648 break;
2649 case 0x05:
2650 tmpword |= 0x0c00;
2651 break;
2652 case 0x03:
2653 tmpword |= 0x00c0;
2654 break;
2655 case 0x02:
2656 tmpword |= 0x0030;
2657 break;
2658 case 0x01:
2659 tmpword |= 0x000c;
2660 break;
2661 case 0x00:
2662 tmpword |= 0x0003;
2663 break;
2664 default:
2665 break; /* do not change settings */
2666 }
2667 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2668 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2669
2670 /*
2671 * GEN2_DEC bits:
2672 * Bit 15-4: Generic I/O range
2673 * Bit 3-1: reserved (read as 0)
2674 * Bit 0: enable GEN2 range on LPC I/F
2675 */
2676 tmpword = conf->fir_io & 0xfff8;
2677 tmpword |= 0x0001;
2678 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2679 pci_write_config_word(dev, GEN2_DEC, tmpword);
2680
2681 /* Pre-configure chip */
2682 return preconfigure_smsc_chip(conf);
2683}
2684
2685/*
2686 * Pre-configure a certain port on the ALi 1533 bridge.
2687 * This is based on reverse-engineering since ALi does not
2688 * provide any data sheet for the 1533 chip.
2689 */
2690static void __init preconfigure_ali_port(struct pci_dev *dev,
2691 unsigned short port)
2692{
2693 unsigned char reg;
2694 /* These bits obviously control the different ports */
2695 unsigned char mask;
2696 unsigned char tmpbyte;
2697
2698 switch(port) {
2699 case 0x0130:
2700 case 0x0178:
2701 reg = 0xb0;
2702 mask = 0x80;
2703 break;
2704 case 0x03f8:
2705 reg = 0xb4;
2706 mask = 0x80;
2707 break;
2708 case 0x02f8:
2709 reg = 0xb4;
2710 mask = 0x30;
2711 break;
2712 case 0x02e8:
2713 reg = 0xb4;
2714 mask = 0x08;
2715 break;
2716 default:
2717 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2718 return;
2719 }
2720
2721 pci_read_config_byte(dev, reg, &tmpbyte);
2722 /* Turn on the right bits */
2723 tmpbyte |= mask;
2724 pci_write_config_byte(dev, reg, tmpbyte);
2725 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
2726 return;
2727}
2728
2729static int __init preconfigure_through_ali(struct pci_dev *dev,
2730 struct
2731 smsc_ircc_subsystem_configuration
2732 *conf)
2733{
2734 /* Configure the two ports on the ALi 1533 */
2735 preconfigure_ali_port(dev, conf->sir_io);
2736 preconfigure_ali_port(dev, conf->fir_io);
2737
2738 /* Pre-configure chip */
2739 return preconfigure_smsc_chip(conf);
2740}
2741
2742static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
2743 unsigned short ircc_fir,
2744 unsigned short ircc_sir,
2745 unsigned char ircc_dma,
2746 unsigned char ircc_irq)
2747{
2748 struct pci_dev *dev = NULL;
2749 unsigned short ss_vendor = 0x0000;
2750 unsigned short ss_device = 0x0000;
2751 int ret = 0;
2752
2753 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2754
2755 while (dev != NULL) {
2756 struct smsc_ircc_subsystem_configuration *conf;
2757
2758 /*
2759 * Cache the subsystem vendor/device:
2760 * some manufacturers fail to set this for all components,
2761 * so we save it in case there is just 0x0000 0x0000 on the
2762 * device we want to check.
2763 */
2764 if (dev->subsystem_vendor != 0x0000U) {
2765 ss_vendor = dev->subsystem_vendor;
2766 ss_device = dev->subsystem_device;
2767 }
2768 conf = subsystem_configurations;
2769 for( ; conf->subvendor; conf++) {
2770 if(conf->vendor == dev->vendor &&
2771 conf->device == dev->device &&
2772 conf->subvendor == ss_vendor &&
2773 /* Sometimes these are cached values */
2774 (conf->subdevice == ss_device ||
2775 conf->subdevice == 0xffff)) {
2776 struct smsc_ircc_subsystem_configuration
2777 tmpconf;
2778
2779 memcpy(&tmpconf, conf,
2780 sizeof(struct smsc_ircc_subsystem_configuration));
2781
2782 /*
2783 * Override the default values with anything
2784 * passed in as parameter
2785 */
2786 if (ircc_cfg != 0)
2787 tmpconf.cfg_base = ircc_cfg;
2788 if (ircc_fir != 0)
2789 tmpconf.fir_io = ircc_fir;
2790 if (ircc_sir != 0)
2791 tmpconf.sir_io = ircc_sir;
2792 if (ircc_dma != 0xff)
2793 tmpconf.fir_dma = ircc_dma;
2794 if (ircc_irq != 0xff)
2795 tmpconf.fir_irq = ircc_irq;
2796
2797 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2798 if (conf->preconfigure)
2799 ret = conf->preconfigure(dev, &tmpconf);
2800 else
2801 ret = -ENODEV;
2802 }
2803 }
2804 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2805 }
2806
2807 return ret;
2808}
2809#endif // CONFIG_PCI
2810
2288/************************************************ 2811/************************************************
2289 * 2812 *
2290 * Transceivers specific functions 2813 * Transceivers specific functions
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index f9f77e4f5965..cfd67d812f0d 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -357,18 +357,20 @@ ixgb_probe(struct pci_dev *pdev,
357 if((err = pci_enable_device(pdev))) 357 if((err = pci_enable_device(pdev)))
358 return err; 358 return err;
359 359
360 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK))) { 360 if(!(err = pci_set_dma_mask(pdev, DMA_64BIT_MASK)) &&
361 !(err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))) {
361 pci_using_dac = 1; 362 pci_using_dac = 1;
362 } else { 363 } else {
363 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) { 364 if((err = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) ||
365 (err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))) {
364 IXGB_ERR("No usable DMA configuration, aborting\n"); 366 IXGB_ERR("No usable DMA configuration, aborting\n");
365 return err; 367 goto err_dma_mask;
366 } 368 }
367 pci_using_dac = 0; 369 pci_using_dac = 0;
368 } 370 }
369 371
370 if((err = pci_request_regions(pdev, ixgb_driver_name))) 372 if((err = pci_request_regions(pdev, ixgb_driver_name)))
371 return err; 373 goto err_request_regions;
372 374
373 pci_set_master(pdev); 375 pci_set_master(pdev);
374 376
@@ -502,6 +504,9 @@ err_ioremap:
502 free_netdev(netdev); 504 free_netdev(netdev);
503err_alloc_etherdev: 505err_alloc_etherdev:
504 pci_release_regions(pdev); 506 pci_release_regions(pdev);
507err_request_regions:
508err_dma_mask:
509 pci_disable_device(pdev);
505 return err; 510 return err;
506} 511}
507 512
diff --git a/drivers/net/ixp2000/ixpdev.c b/drivers/net/ixp2000/ixpdev.c
index 77f104a005f3..fbc2d21020f4 100644
--- a/drivers/net/ixp2000/ixpdev.c
+++ b/drivers/net/ixp2000/ixpdev.c
@@ -299,10 +299,7 @@ int ixpdev_init(int __nds_count, struct net_device **__nds,
299 int i; 299 int i;
300 int err; 300 int err;
301 301
302 if (RX_BUF_COUNT > 192 || TX_BUF_COUNT > 192) { 302 BUILD_BUG_ON(RX_BUF_COUNT > 192 || TX_BUF_COUNT > 192);
303 static void __too_many_rx_or_tx_buffers(void);
304 __too_many_rx_or_tx_buffers();
305 }
306 303
307 printk(KERN_INFO "IXP2000 MSF ethernet driver %s\n", DRV_MODULE_VERSION); 304 printk(KERN_INFO "IXP2000 MSF ethernet driver %s\n", DRV_MODULE_VERSION);
308 305
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index 9f2661355a4a..ea62a3e7d586 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -281,10 +281,16 @@ static void mv643xx_eth_tx_timeout_task(struct net_device *dev)
281{ 281{
282 struct mv643xx_private *mp = netdev_priv(dev); 282 struct mv643xx_private *mp = netdev_priv(dev);
283 283
284 netif_device_detach(dev); 284 if (!netif_running(dev))
285 return;
286
287 netif_stop_queue(dev);
288
285 eth_port_reset(mp->port_num); 289 eth_port_reset(mp->port_num);
286 eth_port_start(dev); 290 eth_port_start(dev);
287 netif_device_attach(dev); 291
292 if (mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB)
293 netif_wake_queue(dev);
288} 294}
289 295
290/** 296/**
@@ -552,9 +558,9 @@ static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id,
552#else 558#else
553 if (eth_int_cause & ETH_INT_CAUSE_RX) 559 if (eth_int_cause & ETH_INT_CAUSE_RX)
554 mv643xx_eth_receive_queue(dev, INT_MAX); 560 mv643xx_eth_receive_queue(dev, INT_MAX);
561#endif
555 if (eth_int_cause_ext & ETH_INT_CAUSE_TX) 562 if (eth_int_cause_ext & ETH_INT_CAUSE_TX)
556 mv643xx_eth_free_completed_tx_descs(dev); 563 mv643xx_eth_free_completed_tx_descs(dev);
557#endif
558 564
559 /* 565 /*
560 * If no real interrupt occured, exit. 566 * If no real interrupt occured, exit.
@@ -1186,7 +1192,12 @@ static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)
1186 1192
1187 BUG_ON(netif_queue_stopped(dev)); 1193 BUG_ON(netif_queue_stopped(dev));
1188 BUG_ON(skb == NULL); 1194 BUG_ON(skb == NULL);
1189 BUG_ON(mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB); 1195
1196 if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) {
1197 printk(KERN_ERR "%s: transmit with queue full\n", dev->name);
1198 netif_stop_queue(dev);
1199 return 1;
1200 }
1190 1201
1191 if (has_tiny_unaligned_frags(skb)) { 1202 if (has_tiny_unaligned_frags(skb)) {
1192 if ((skb_linearize(skb, GFP_ATOMIC) != 0)) { 1203 if ((skb_linearize(skb, GFP_ATOMIC) != 0)) {
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index 8d4999837b65..90627756d6fa 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -226,7 +226,7 @@ static int full_duplex[MAX_UNITS];
226 NATSEMI_PG1_NREGS) 226 NATSEMI_PG1_NREGS)
227#define NATSEMI_REGS_VER 1 /* v1 added RFDR registers */ 227#define NATSEMI_REGS_VER 1 /* v1 added RFDR registers */
228#define NATSEMI_REGS_SIZE (NATSEMI_NREGS * sizeof(u32)) 228#define NATSEMI_REGS_SIZE (NATSEMI_NREGS * sizeof(u32))
229#define NATSEMI_EEPROM_SIZE 24 /* 12 16-bit values */ 229#define NATSEMI_DEF_EEPROM_SIZE 24 /* 12 16-bit values */
230 230
231/* Buffer sizes: 231/* Buffer sizes:
232 * The nic writes 32-bit values, even if the upper bytes of 232 * The nic writes 32-bit values, even if the upper bytes of
@@ -238,7 +238,7 @@ static int full_duplex[MAX_UNITS];
238#define NATSEMI_RX_LIMIT 2046 /* maximum supported by hardware */ 238#define NATSEMI_RX_LIMIT 2046 /* maximum supported by hardware */
239 239
240/* These identify the driver base version and may not be removed. */ 240/* These identify the driver base version and may not be removed. */
241static char version[] __devinitdata = 241static const char version[] __devinitdata =
242 KERN_INFO DRV_NAME " dp8381x driver, version " 242 KERN_INFO DRV_NAME " dp8381x driver, version "
243 DRV_VERSION ", " DRV_RELDATE "\n" 243 DRV_VERSION ", " DRV_RELDATE "\n"
244 KERN_INFO " originally by Donald Becker <becker@scyld.com>\n" 244 KERN_INFO " originally by Donald Becker <becker@scyld.com>\n"
@@ -714,6 +714,8 @@ struct netdev_private {
714 unsigned int iosize; 714 unsigned int iosize;
715 spinlock_t lock; 715 spinlock_t lock;
716 u32 msg_enable; 716 u32 msg_enable;
717 /* EEPROM data */
718 int eeprom_size;
717}; 719};
718 720
719static void move_int_phy(struct net_device *dev, int addr); 721static void move_int_phy(struct net_device *dev, int addr);
@@ -890,6 +892,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
890 np->msg_enable = (debug >= 0) ? (1<<debug)-1 : NATSEMI_DEF_MSG; 892 np->msg_enable = (debug >= 0) ? (1<<debug)-1 : NATSEMI_DEF_MSG;
891 np->hands_off = 0; 893 np->hands_off = 0;
892 np->intr_status = 0; 894 np->intr_status = 0;
895 np->eeprom_size = NATSEMI_DEF_EEPROM_SIZE;
893 896
894 /* Initial port: 897 /* Initial port:
895 * - If the nic was configured to use an external phy and if find_mii 898 * - If the nic was configured to use an external phy and if find_mii
@@ -2582,7 +2585,8 @@ static int get_regs_len(struct net_device *dev)
2582 2585
2583static int get_eeprom_len(struct net_device *dev) 2586static int get_eeprom_len(struct net_device *dev)
2584{ 2587{
2585 return NATSEMI_EEPROM_SIZE; 2588 struct netdev_private *np = netdev_priv(dev);
2589 return np->eeprom_size;
2586} 2590}
2587 2591
2588static int get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) 2592static int get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
@@ -2669,15 +2673,20 @@ static u32 get_link(struct net_device *dev)
2669static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) 2673static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
2670{ 2674{
2671 struct netdev_private *np = netdev_priv(dev); 2675 struct netdev_private *np = netdev_priv(dev);
2672 u8 eebuf[NATSEMI_EEPROM_SIZE]; 2676 u8 *eebuf;
2673 int res; 2677 int res;
2674 2678
2679 eebuf = kmalloc(np->eeprom_size, GFP_KERNEL);
2680 if (!eebuf)
2681 return -ENOMEM;
2682
2675 eeprom->magic = PCI_VENDOR_ID_NS | (PCI_DEVICE_ID_NS_83815<<16); 2683 eeprom->magic = PCI_VENDOR_ID_NS | (PCI_DEVICE_ID_NS_83815<<16);
2676 spin_lock_irq(&np->lock); 2684 spin_lock_irq(&np->lock);
2677 res = netdev_get_eeprom(dev, eebuf); 2685 res = netdev_get_eeprom(dev, eebuf);
2678 spin_unlock_irq(&np->lock); 2686 spin_unlock_irq(&np->lock);
2679 if (!res) 2687 if (!res)
2680 memcpy(data, eebuf+eeprom->offset, eeprom->len); 2688 memcpy(data, eebuf+eeprom->offset, eeprom->len);
2689 kfree(eebuf);
2681 return res; 2690 return res;
2682} 2691}
2683 2692
@@ -3033,9 +3042,10 @@ static int netdev_get_eeprom(struct net_device *dev, u8 *buf)
3033 int i; 3042 int i;
3034 u16 *ebuf = (u16 *)buf; 3043 u16 *ebuf = (u16 *)buf;
3035 void __iomem * ioaddr = ns_ioaddr(dev); 3044 void __iomem * ioaddr = ns_ioaddr(dev);
3045 struct netdev_private *np = netdev_priv(dev);
3036 3046
3037 /* eeprom_read reads 16 bits, and indexes by 16 bits */ 3047 /* eeprom_read reads 16 bits, and indexes by 16 bits */
3038 for (i = 0; i < NATSEMI_EEPROM_SIZE/2; i++) { 3048 for (i = 0; i < np->eeprom_size/2; i++) {
3039 ebuf[i] = eeprom_read(ioaddr, i); 3049 ebuf[i] = eeprom_read(ioaddr, i);
3040 /* The EEPROM itself stores data bit-swapped, but eeprom_read 3050 /* The EEPROM itself stores data bit-swapped, but eeprom_read
3041 * reads it back "sanely". So we swap it back here in order to 3051 * reads it back "sanely". So we swap it back here in order to
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index d11821dd86ed..ced9fdb8335c 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -645,9 +645,7 @@ static void __devexit ne2k_pci_remove_one (struct pci_dev *pdev)
645{ 645{
646 struct net_device *dev = pci_get_drvdata(pdev); 646 struct net_device *dev = pci_get_drvdata(pdev);
647 647
648 if (!dev) 648 BUG_ON(!dev);
649 BUG();
650
651 unregister_netdev(dev); 649 unregister_netdev(dev);
652 release_region(dev->base_addr, NE_IO_EXTENT); 650 release_region(dev->base_addr, NE_IO_EXTENT);
653 free_netdev(dev); 651 free_netdev(dev);
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index edd1b5306b16..66e74f740261 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -87,6 +87,7 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
87} 87}
88 88
89static struct console netconsole = { 89static struct console netconsole = {
90 .name = "netcon",
90 .flags = CON_ENABLED | CON_PRINTBUFFER, 91 .flags = CON_ENABLED | CON_PRINTBUFFER,
91 .write = write_msg 92 .write = write_msg
92}; 93};
@@ -94,7 +95,7 @@ static struct console netconsole = {
94static int option_setup(char *opt) 95static int option_setup(char *opt)
95{ 96{
96 configured = !netpoll_parse_options(&np, opt); 97 configured = !netpoll_parse_options(&np, opt);
97 return 0; 98 return 1;
98} 99}
99 100
100__setup("netconsole=", option_setup); 101__setup("netconsole=", option_setup);
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index 8e9b1a537dee..706aed7d717f 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -568,8 +568,7 @@ static inline int ns83820_add_rx_skb(struct ns83820 *dev, struct sk_buff *skb)
568#endif 568#endif
569 569
570 sg = dev->rx_info.descs + (next_empty * DESC_SIZE); 570 sg = dev->rx_info.descs + (next_empty * DESC_SIZE);
571 if (unlikely(NULL != dev->rx_info.skbs[next_empty])) 571 BUG_ON(NULL != dev->rx_info.skbs[next_empty]);
572 BUG();
573 dev->rx_info.skbs[next_empty] = skb; 572 dev->rx_info.skbs[next_empty] = skb;
574 573
575 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC; 574 dev->rx_info.next_empty = (next_empty + 1) % NR_RX_DESC;
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index ce90becb8bdf..fab93360f017 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -204,7 +204,7 @@ enum Window4 { /* Window 4: Xcvr/media bits. */
204#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */ 204#define MEDIA_TP 0x00C0 /* Enable link beat and jabber for 10baseT. */
205 205
206struct el3_private { 206struct el3_private {
207 dev_link_t link; 207 struct pcmcia_device *p_dev;
208 dev_node_t node; 208 dev_node_t node;
209 struct net_device_stats stats; 209 struct net_device_stats stats;
210 u16 advertising, partner; /* NWay media advertisement */ 210 u16 advertising, partner; /* NWay media advertisement */
@@ -225,8 +225,8 @@ static char mii_preamble_required = 0;
225 225
226/* Index of functions. */ 226/* Index of functions. */
227 227
228static void tc574_config(dev_link_t *link); 228static int tc574_config(struct pcmcia_device *link);
229static void tc574_release(dev_link_t *link); 229static void tc574_release(struct pcmcia_device *link);
230 230
231static void mdio_sync(kio_addr_t ioaddr, int bits); 231static void mdio_sync(kio_addr_t ioaddr, int bits);
232static int mdio_read(kio_addr_t ioaddr, int phy_id, int location); 232static int mdio_read(kio_addr_t ioaddr, int phy_id, int location);
@@ -256,10 +256,9 @@ static void tc574_detach(struct pcmcia_device *p_dev);
256 with Card Services. 256 with Card Services.
257*/ 257*/
258 258
259static int tc574_attach(struct pcmcia_device *p_dev) 259static int tc574_probe(struct pcmcia_device *link)
260{ 260{
261 struct el3_private *lp; 261 struct el3_private *lp;
262 dev_link_t *link;
263 struct net_device *dev; 262 struct net_device *dev;
264 263
265 DEBUG(0, "3c574_attach()\n"); 264 DEBUG(0, "3c574_attach()\n");
@@ -269,8 +268,8 @@ static int tc574_attach(struct pcmcia_device *p_dev)
269 if (!dev) 268 if (!dev)
270 return -ENOMEM; 269 return -ENOMEM;
271 lp = netdev_priv(dev); 270 lp = netdev_priv(dev);
272 link = &lp->link;
273 link->priv = dev; 271 link->priv = dev;
272 lp->p_dev = link;
274 273
275 spin_lock_init(&lp->window_lock); 274 spin_lock_init(&lp->window_lock);
276 link->io.NumPorts1 = 32; 275 link->io.NumPorts1 = 32;
@@ -280,7 +279,6 @@ static int tc574_attach(struct pcmcia_device *p_dev)
280 link->irq.Handler = &el3_interrupt; 279 link->irq.Handler = &el3_interrupt;
281 link->irq.Instance = dev; 280 link->irq.Instance = dev;
282 link->conf.Attributes = CONF_ENABLE_IRQ; 281 link->conf.Attributes = CONF_ENABLE_IRQ;
283 link->conf.Vcc = 50;
284 link->conf.IntType = INT_MEMORY_AND_IO; 282 link->conf.IntType = INT_MEMORY_AND_IO;
285 link->conf.ConfigIndex = 1; 283 link->conf.ConfigIndex = 1;
286 link->conf.Present = PRESENT_OPTION; 284 link->conf.Present = PRESENT_OPTION;
@@ -298,13 +296,7 @@ static int tc574_attach(struct pcmcia_device *p_dev)
298 dev->watchdog_timeo = TX_TIMEOUT; 296 dev->watchdog_timeo = TX_TIMEOUT;
299#endif 297#endif
300 298
301 link->handle = p_dev; 299 return tc574_config(link);
302 p_dev->instance = link;
303
304 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
305 tc574_config(link);
306
307 return 0;
308} /* tc574_attach */ 300} /* tc574_attach */
309 301
310/* 302/*
@@ -316,18 +308,16 @@ static int tc574_attach(struct pcmcia_device *p_dev)
316 308
317*/ 309*/
318 310
319static void tc574_detach(struct pcmcia_device *p_dev) 311static void tc574_detach(struct pcmcia_device *link)
320{ 312{
321 dev_link_t *link = dev_to_instance(p_dev);
322 struct net_device *dev = link->priv; 313 struct net_device *dev = link->priv;
323 314
324 DEBUG(0, "3c574_detach(0x%p)\n", link); 315 DEBUG(0, "3c574_detach(0x%p)\n", link);
325 316
326 if (link->dev) 317 if (link->dev_node)
327 unregister_netdev(dev); 318 unregister_netdev(dev);
328 319
329 if (link->state & DEV_CONFIG) 320 tc574_release(link);
330 tc574_release(link);
331 321
332 free_netdev(dev); 322 free_netdev(dev);
333} /* tc574_detach */ 323} /* tc574_detach */
@@ -343,9 +333,8 @@ static void tc574_detach(struct pcmcia_device *p_dev)
343 333
344static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 334static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
345 335
346static void tc574_config(dev_link_t *link) 336static int tc574_config(struct pcmcia_device *link)
347{ 337{
348 client_handle_t handle = link->handle;
349 struct net_device *dev = link->priv; 338 struct net_device *dev = link->priv;
350 struct el3_private *lp = netdev_priv(dev); 339 struct el3_private *lp = netdev_priv(dev);
351 tuple_t tuple; 340 tuple_t tuple;
@@ -363,30 +352,27 @@ static void tc574_config(dev_link_t *link)
363 352
364 tuple.Attributes = 0; 353 tuple.Attributes = 0;
365 tuple.DesiredTuple = CISTPL_CONFIG; 354 tuple.DesiredTuple = CISTPL_CONFIG;
366 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 355 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
367 tuple.TupleData = (cisdata_t *)buf; 356 tuple.TupleData = (cisdata_t *)buf;
368 tuple.TupleDataMax = 64; 357 tuple.TupleDataMax = 64;
369 tuple.TupleOffset = 0; 358 tuple.TupleOffset = 0;
370 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 359 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
371 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 360 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
372 link->conf.ConfigBase = parse.config.base; 361 link->conf.ConfigBase = parse.config.base;
373 link->conf.Present = parse.config.rmask[0]; 362 link->conf.Present = parse.config.rmask[0];
374 363
375 /* Configure card */
376 link->state |= DEV_CONFIG;
377
378 link->io.IOAddrLines = 16; 364 link->io.IOAddrLines = 16;
379 for (i = j = 0; j < 0x400; j += 0x20) { 365 for (i = j = 0; j < 0x400; j += 0x20) {
380 link->io.BasePort1 = j ^ 0x300; 366 link->io.BasePort1 = j ^ 0x300;
381 i = pcmcia_request_io(link->handle, &link->io); 367 i = pcmcia_request_io(link, &link->io);
382 if (i == CS_SUCCESS) break; 368 if (i == CS_SUCCESS) break;
383 } 369 }
384 if (i != CS_SUCCESS) { 370 if (i != CS_SUCCESS) {
385 cs_error(link->handle, RequestIO, i); 371 cs_error(link, RequestIO, i);
386 goto failed; 372 goto failed;
387 } 373 }
388 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 374 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
389 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 375 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
390 376
391 dev->irq = link->irq.AssignedIRQ; 377 dev->irq = link->irq.AssignedIRQ;
392 dev->base_addr = link->io.BasePort1; 378 dev->base_addr = link->io.BasePort1;
@@ -397,8 +383,8 @@ static void tc574_config(dev_link_t *link)
397 the hardware address. The future products may include a modem chip 383 the hardware address. The future products may include a modem chip
398 and put the address in the CIS. */ 384 and put the address in the CIS. */
399 tuple.DesiredTuple = 0x88; 385 tuple.DesiredTuple = 0x88;
400 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { 386 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
401 pcmcia_get_tuple_data(handle, &tuple); 387 pcmcia_get_tuple_data(link, &tuple);
402 for (i = 0; i < 3; i++) 388 for (i = 0; i < 3; i++)
403 phys_addr[i] = htons(buf[i]); 389 phys_addr[i] = htons(buf[i]);
404 } else { 390 } else {
@@ -412,9 +398,9 @@ static void tc574_config(dev_link_t *link)
412 } 398 }
413 } 399 }
414 tuple.DesiredTuple = CISTPL_VERS_1; 400 tuple.DesiredTuple = CISTPL_VERS_1;
415 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS && 401 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS &&
416 pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS && 402 pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS &&
417 pcmcia_parse_tuple(handle, &tuple, &parse) == CS_SUCCESS) { 403 pcmcia_parse_tuple(link, &tuple, &parse) == CS_SUCCESS) {
418 cardname = parse.version_1.str + parse.version_1.ofs[1]; 404 cardname = parse.version_1.str + parse.version_1.ofs[1];
419 } else 405 } else
420 cardname = "3Com 3c574"; 406 cardname = "3Com 3c574";
@@ -473,13 +459,12 @@ static void tc574_config(dev_link_t *link)
473 } 459 }
474 } 460 }
475 461
476 link->state &= ~DEV_CONFIG_PENDING; 462 link->dev_node = &lp->node;
477 link->dev = &lp->node; 463 SET_NETDEV_DEV(dev, &handle_to_dev(link));
478 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
479 464
480 if (register_netdev(dev) != 0) { 465 if (register_netdev(dev) != 0) {
481 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n"); 466 printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
482 link->dev = NULL; 467 link->dev_node = NULL;
483 goto failed; 468 goto failed;
484 } 469 }
485 470
@@ -493,13 +478,13 @@ static void tc574_config(dev_link_t *link)
493 8 << config.u.ram_size, ram_split[config.u.ram_split], 478 8 << config.u.ram_size, ram_split[config.u.ram_split],
494 config.u.autoselect ? "autoselect " : ""); 479 config.u.autoselect ? "autoselect " : "");
495 480
496 return; 481 return 0;
497 482
498cs_failed: 483cs_failed:
499 cs_error(link->handle, last_fn, last_ret); 484 cs_error(link, last_fn, last_ret);
500failed: 485failed:
501 tc574_release(link); 486 tc574_release(link);
502 return; 487 return -ENODEV;
503 488
504} /* tc574_config */ 489} /* tc574_config */
505 490
@@ -509,44 +494,28 @@ failed:
509 still open, this will be postponed until it is closed. 494 still open, this will be postponed until it is closed.
510*/ 495*/
511 496
512static void tc574_release(dev_link_t *link) 497static void tc574_release(struct pcmcia_device *link)
513{ 498{
514 DEBUG(0, "3c574_release(0x%p)\n", link); 499 pcmcia_disable_device(link);
515
516 pcmcia_release_configuration(link->handle);
517 pcmcia_release_io(link->handle, &link->io);
518 pcmcia_release_irq(link->handle, &link->irq);
519
520 link->state &= ~DEV_CONFIG;
521} 500}
522 501
523static int tc574_suspend(struct pcmcia_device *p_dev) 502static int tc574_suspend(struct pcmcia_device *link)
524{ 503{
525 dev_link_t *link = dev_to_instance(p_dev);
526 struct net_device *dev = link->priv; 504 struct net_device *dev = link->priv;
527 505
528 link->state |= DEV_SUSPEND; 506 if (link->open)
529 if (link->state & DEV_CONFIG) { 507 netif_device_detach(dev);
530 if (link->open)
531 netif_device_detach(dev);
532 pcmcia_release_configuration(link->handle);
533 }
534 508
535 return 0; 509 return 0;
536} 510}
537 511
538static int tc574_resume(struct pcmcia_device *p_dev) 512static int tc574_resume(struct pcmcia_device *link)
539{ 513{
540 dev_link_t *link = dev_to_instance(p_dev);
541 struct net_device *dev = link->priv; 514 struct net_device *dev = link->priv;
542 515
543 link->state &= ~DEV_SUSPEND; 516 if (link->open) {
544 if (link->state & DEV_CONFIG) { 517 tc574_reset(dev);
545 pcmcia_request_configuration(link->handle, &link->conf); 518 netif_device_attach(dev);
546 if (link->open) {
547 tc574_reset(dev);
548 netif_device_attach(dev);
549 }
550 } 519 }
551 520
552 return 0; 521 return 0;
@@ -757,9 +726,9 @@ static void tc574_reset(struct net_device *dev)
757static int el3_open(struct net_device *dev) 726static int el3_open(struct net_device *dev)
758{ 727{
759 struct el3_private *lp = netdev_priv(dev); 728 struct el3_private *lp = netdev_priv(dev);
760 dev_link_t *link = &lp->link; 729 struct pcmcia_device *link = lp->p_dev;
761 730
762 if (!DEV_OK(link)) 731 if (!pcmcia_dev_present(link))
763 return -ENODEV; 732 return -ENODEV;
764 733
765 link->open++; 734 link->open++;
@@ -1203,11 +1172,11 @@ static int el3_close(struct net_device *dev)
1203{ 1172{
1204 kio_addr_t ioaddr = dev->base_addr; 1173 kio_addr_t ioaddr = dev->base_addr;
1205 struct el3_private *lp = netdev_priv(dev); 1174 struct el3_private *lp = netdev_priv(dev);
1206 dev_link_t *link = &lp->link; 1175 struct pcmcia_device *link = lp->p_dev;
1207 1176
1208 DEBUG(2, "%s: shutting down ethercard.\n", dev->name); 1177 DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
1209 1178
1210 if (DEV_OK(link)) { 1179 if (pcmcia_dev_present(link)) {
1211 unsigned long flags; 1180 unsigned long flags;
1212 1181
1213 /* Turn off statistics ASAP. We update lp->stats below. */ 1182 /* Turn off statistics ASAP. We update lp->stats below. */
@@ -1246,7 +1215,7 @@ static struct pcmcia_driver tc574_driver = {
1246 .drv = { 1215 .drv = {
1247 .name = "3c574_cs", 1216 .name = "3c574_cs",
1248 }, 1217 },
1249 .probe = tc574_attach, 1218 .probe = tc574_probe,
1250 .remove = tc574_detach, 1219 .remove = tc574_detach,
1251 .id_table = tc574_ids, 1220 .id_table = tc574_ids,
1252 .suspend = tc574_suspend, 1221 .suspend = tc574_suspend,
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 3dba50849da7..875a0fe251e7 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -105,7 +105,7 @@ enum RxFilter {
105#define TX_TIMEOUT ((400*HZ)/1000) 105#define TX_TIMEOUT ((400*HZ)/1000)
106 106
107struct el3_private { 107struct el3_private {
108 dev_link_t link; 108 struct pcmcia_device *p_dev;
109 dev_node_t node; 109 dev_node_t node;
110 struct net_device_stats stats; 110 struct net_device_stats stats;
111 /* For transceiver monitoring */ 111 /* For transceiver monitoring */
@@ -142,8 +142,8 @@ DRV_NAME ".c " DRV_VERSION " 2001/10/13 00:08:50 (David Hinds)";
142 142
143/*====================================================================*/ 143/*====================================================================*/
144 144
145static void tc589_config(dev_link_t *link); 145static int tc589_config(struct pcmcia_device *link);
146static void tc589_release(dev_link_t *link); 146static void tc589_release(struct pcmcia_device *link);
147 147
148static u16 read_eeprom(kio_addr_t ioaddr, int index); 148static u16 read_eeprom(kio_addr_t ioaddr, int index);
149static void tc589_reset(struct net_device *dev); 149static void tc589_reset(struct net_device *dev);
@@ -170,10 +170,9 @@ static void tc589_detach(struct pcmcia_device *p_dev);
170 170
171======================================================================*/ 171======================================================================*/
172 172
173static int tc589_attach(struct pcmcia_device *p_dev) 173static int tc589_probe(struct pcmcia_device *link)
174{ 174{
175 struct el3_private *lp; 175 struct el3_private *lp;
176 dev_link_t *link;
177 struct net_device *dev; 176 struct net_device *dev;
178 177
179 DEBUG(0, "3c589_attach()\n"); 178 DEBUG(0, "3c589_attach()\n");
@@ -183,8 +182,8 @@ static int tc589_attach(struct pcmcia_device *p_dev)
183 if (!dev) 182 if (!dev)
184 return -ENOMEM; 183 return -ENOMEM;
185 lp = netdev_priv(dev); 184 lp = netdev_priv(dev);
186 link = &lp->link;
187 link->priv = dev; 185 link->priv = dev;
186 lp->p_dev = link;
188 187
189 spin_lock_init(&lp->lock); 188 spin_lock_init(&lp->lock);
190 link->io.NumPorts1 = 16; 189 link->io.NumPorts1 = 16;
@@ -194,7 +193,6 @@ static int tc589_attach(struct pcmcia_device *p_dev)
194 link->irq.Handler = &el3_interrupt; 193 link->irq.Handler = &el3_interrupt;
195 link->irq.Instance = dev; 194 link->irq.Instance = dev;
196 link->conf.Attributes = CONF_ENABLE_IRQ; 195 link->conf.Attributes = CONF_ENABLE_IRQ;
197 link->conf.Vcc = 50;
198 link->conf.IntType = INT_MEMORY_AND_IO; 196 link->conf.IntType = INT_MEMORY_AND_IO;
199 link->conf.ConfigIndex = 1; 197 link->conf.ConfigIndex = 1;
200 link->conf.Present = PRESENT_OPTION; 198 link->conf.Present = PRESENT_OPTION;
@@ -213,13 +211,7 @@ static int tc589_attach(struct pcmcia_device *p_dev)
213#endif 211#endif
214 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 212 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
215 213
216 link->handle = p_dev; 214 return tc589_config(link);
217 p_dev->instance = link;
218
219 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
220 tc589_config(link);
221
222 return 0;
223} /* tc589_attach */ 215} /* tc589_attach */
224 216
225/*====================================================================== 217/*======================================================================
@@ -231,18 +223,16 @@ static int tc589_attach(struct pcmcia_device *p_dev)
231 223
232======================================================================*/ 224======================================================================*/
233 225
234static void tc589_detach(struct pcmcia_device *p_dev) 226static void tc589_detach(struct pcmcia_device *link)
235{ 227{
236 dev_link_t *link = dev_to_instance(p_dev);
237 struct net_device *dev = link->priv; 228 struct net_device *dev = link->priv;
238 229
239 DEBUG(0, "3c589_detach(0x%p)\n", link); 230 DEBUG(0, "3c589_detach(0x%p)\n", link);
240 231
241 if (link->dev) 232 if (link->dev_node)
242 unregister_netdev(dev); 233 unregister_netdev(dev);
243 234
244 if (link->state & DEV_CONFIG) 235 tc589_release(link);
245 tc589_release(link);
246 236
247 free_netdev(dev); 237 free_netdev(dev);
248} /* tc589_detach */ 238} /* tc589_detach */
@@ -258,9 +248,8 @@ static void tc589_detach(struct pcmcia_device *p_dev)
258#define CS_CHECK(fn, ret) \ 248#define CS_CHECK(fn, ret) \
259do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 249do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
260 250
261static void tc589_config(dev_link_t *link) 251static int tc589_config(struct pcmcia_device *link)
262{ 252{
263 client_handle_t handle = link->handle;
264 struct net_device *dev = link->priv; 253 struct net_device *dev = link->priv;
265 struct el3_private *lp = netdev_priv(dev); 254 struct el3_private *lp = netdev_priv(dev);
266 tuple_t tuple; 255 tuple_t tuple;
@@ -275,43 +264,40 @@ static void tc589_config(dev_link_t *link)
275 phys_addr = (u16 *)dev->dev_addr; 264 phys_addr = (u16 *)dev->dev_addr;
276 tuple.Attributes = 0; 265 tuple.Attributes = 0;
277 tuple.DesiredTuple = CISTPL_CONFIG; 266 tuple.DesiredTuple = CISTPL_CONFIG;
278 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 267 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
279 tuple.TupleData = (cisdata_t *)buf; 268 tuple.TupleData = (cisdata_t *)buf;
280 tuple.TupleDataMax = sizeof(buf); 269 tuple.TupleDataMax = sizeof(buf);
281 tuple.TupleOffset = 0; 270 tuple.TupleOffset = 0;
282 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 271 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
283 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 272 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
284 link->conf.ConfigBase = parse.config.base; 273 link->conf.ConfigBase = parse.config.base;
285 link->conf.Present = parse.config.rmask[0]; 274 link->conf.Present = parse.config.rmask[0];
286 275
287 /* Is this a 3c562? */ 276 /* Is this a 3c562? */
288 tuple.DesiredTuple = CISTPL_MANFID; 277 tuple.DesiredTuple = CISTPL_MANFID;
289 tuple.Attributes = TUPLE_RETURN_COMMON; 278 tuple.Attributes = TUPLE_RETURN_COMMON;
290 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 279 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
291 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) { 280 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) {
292 if (le16_to_cpu(buf[0]) != MANFID_3COM) 281 if (le16_to_cpu(buf[0]) != MANFID_3COM)
293 printk(KERN_INFO "3c589_cs: hmmm, is this really a " 282 printk(KERN_INFO "3c589_cs: hmmm, is this really a "
294 "3Com card??\n"); 283 "3Com card??\n");
295 multi = (le16_to_cpu(buf[1]) == PRODID_3COM_3C562); 284 multi = (le16_to_cpu(buf[1]) == PRODID_3COM_3C562);
296 } 285 }
297
298 /* Configure card */
299 link->state |= DEV_CONFIG;
300 286
301 /* For the 3c562, the base address must be xx00-xx7f */ 287 /* For the 3c562, the base address must be xx00-xx7f */
302 link->io.IOAddrLines = 16; 288 link->io.IOAddrLines = 16;
303 for (i = j = 0; j < 0x400; j += 0x10) { 289 for (i = j = 0; j < 0x400; j += 0x10) {
304 if (multi && (j & 0x80)) continue; 290 if (multi && (j & 0x80)) continue;
305 link->io.BasePort1 = j ^ 0x300; 291 link->io.BasePort1 = j ^ 0x300;
306 i = pcmcia_request_io(link->handle, &link->io); 292 i = pcmcia_request_io(link, &link->io);
307 if (i == CS_SUCCESS) break; 293 if (i == CS_SUCCESS) break;
308 } 294 }
309 if (i != CS_SUCCESS) { 295 if (i != CS_SUCCESS) {
310 cs_error(link->handle, RequestIO, i); 296 cs_error(link, RequestIO, i);
311 goto failed; 297 goto failed;
312 } 298 }
313 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 299 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
314 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 300 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
315 301
316 dev->irq = link->irq.AssignedIRQ; 302 dev->irq = link->irq.AssignedIRQ;
317 dev->base_addr = link->io.BasePort1; 303 dev->base_addr = link->io.BasePort1;
@@ -321,8 +307,8 @@ static void tc589_config(dev_link_t *link)
321 /* The 3c589 has an extra EEPROM for configuration info, including 307 /* The 3c589 has an extra EEPROM for configuration info, including
322 the hardware address. The 3c562 puts the address in the CIS. */ 308 the hardware address. The 3c562 puts the address in the CIS. */
323 tuple.DesiredTuple = 0x88; 309 tuple.DesiredTuple = 0x88;
324 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { 310 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
325 pcmcia_get_tuple_data(handle, &tuple); 311 pcmcia_get_tuple_data(link, &tuple);
326 for (i = 0; i < 3; i++) 312 for (i = 0; i < 3; i++)
327 phys_addr[i] = htons(buf[i]); 313 phys_addr[i] = htons(buf[i]);
328 } else { 314 } else {
@@ -346,13 +332,12 @@ static void tc589_config(dev_link_t *link)
346 else 332 else
347 printk(KERN_ERR "3c589_cs: invalid if_port requested\n"); 333 printk(KERN_ERR "3c589_cs: invalid if_port requested\n");
348 334
349 link->dev = &lp->node; 335 link->dev_node = &lp->node;
350 link->state &= ~DEV_CONFIG_PENDING; 336 SET_NETDEV_DEV(dev, &handle_to_dev(link));
351 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
352 337
353 if (register_netdev(dev) != 0) { 338 if (register_netdev(dev) != 0) {
354 printk(KERN_ERR "3c589_cs: register_netdev() failed\n"); 339 printk(KERN_ERR "3c589_cs: register_netdev() failed\n");
355 link->dev = NULL; 340 link->dev_node = NULL;
356 goto failed; 341 goto failed;
357 } 342 }
358 343
@@ -366,14 +351,13 @@ static void tc589_config(dev_link_t *link)
366 printk(KERN_INFO " %dK FIFO split %s Rx:Tx, %s xcvr\n", 351 printk(KERN_INFO " %dK FIFO split %s Rx:Tx, %s xcvr\n",
367 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3], 352 (fifo & 7) ? 32 : 8, ram_split[(fifo >> 16) & 3],
368 if_names[dev->if_port]); 353 if_names[dev->if_port]);
369 return; 354 return 0;
370 355
371cs_failed: 356cs_failed:
372 cs_error(link->handle, last_fn, last_ret); 357 cs_error(link, last_fn, last_ret);
373failed: 358failed:
374 tc589_release(link); 359 tc589_release(link);
375 return; 360 return -ENODEV;
376
377} /* tc589_config */ 361} /* tc589_config */
378 362
379/*====================================================================== 363/*======================================================================
@@ -384,44 +368,28 @@ failed:
384 368
385======================================================================*/ 369======================================================================*/
386 370
387static void tc589_release(dev_link_t *link) 371static void tc589_release(struct pcmcia_device *link)
388{ 372{
389 DEBUG(0, "3c589_release(0x%p)\n", link); 373 pcmcia_disable_device(link);
390
391 pcmcia_release_configuration(link->handle);
392 pcmcia_release_io(link->handle, &link->io);
393 pcmcia_release_irq(link->handle, &link->irq);
394
395 link->state &= ~DEV_CONFIG;
396} 374}
397 375
398static int tc589_suspend(struct pcmcia_device *p_dev) 376static int tc589_suspend(struct pcmcia_device *link)
399{ 377{
400 dev_link_t *link = dev_to_instance(p_dev);
401 struct net_device *dev = link->priv; 378 struct net_device *dev = link->priv;
402 379
403 link->state |= DEV_SUSPEND; 380 if (link->open)
404 if (link->state & DEV_CONFIG) { 381 netif_device_detach(dev);
405 if (link->open)
406 netif_device_detach(dev);
407 pcmcia_release_configuration(link->handle);
408 }
409 382
410 return 0; 383 return 0;
411} 384}
412 385
413static int tc589_resume(struct pcmcia_device *p_dev) 386static int tc589_resume(struct pcmcia_device *link)
414{ 387{
415 dev_link_t *link = dev_to_instance(p_dev);
416 struct net_device *dev = link->priv; 388 struct net_device *dev = link->priv;
417 389
418 link->state &= ~DEV_SUSPEND; 390 if (link->open) {
419 if (link->state & DEV_CONFIG) { 391 tc589_reset(dev);
420 pcmcia_request_configuration(link->handle, &link->conf); 392 netif_device_attach(dev);
421 if (link->open) {
422 tc589_reset(dev);
423 netif_device_attach(dev);
424 }
425 } 393 }
426 394
427 return 0; 395 return 0;
@@ -587,9 +555,9 @@ static int el3_config(struct net_device *dev, struct ifmap *map)
587static int el3_open(struct net_device *dev) 555static int el3_open(struct net_device *dev)
588{ 556{
589 struct el3_private *lp = netdev_priv(dev); 557 struct el3_private *lp = netdev_priv(dev);
590 dev_link_t *link = &lp->link; 558 struct pcmcia_device *link = lp->p_dev;
591 559
592 if (!DEV_OK(link)) 560 if (!pcmcia_dev_present(link))
593 return -ENODEV; 561 return -ENODEV;
594 562
595 link->open++; 563 link->open++;
@@ -848,9 +816,9 @@ static struct net_device_stats *el3_get_stats(struct net_device *dev)
848{ 816{
849 struct el3_private *lp = netdev_priv(dev); 817 struct el3_private *lp = netdev_priv(dev);
850 unsigned long flags; 818 unsigned long flags;
851 dev_link_t *link = &lp->link; 819 struct pcmcia_device *link = lp->p_dev;
852 820
853 if (DEV_OK(link)) { 821 if (pcmcia_dev_present(link)) {
854 spin_lock_irqsave(&lp->lock, flags); 822 spin_lock_irqsave(&lp->lock, flags);
855 update_stats(dev); 823 update_stats(dev);
856 spin_unlock_irqrestore(&lp->lock, flags); 824 spin_unlock_irqrestore(&lp->lock, flags);
@@ -950,11 +918,11 @@ static int el3_rx(struct net_device *dev)
950static void set_multicast_list(struct net_device *dev) 918static void set_multicast_list(struct net_device *dev)
951{ 919{
952 struct el3_private *lp = netdev_priv(dev); 920 struct el3_private *lp = netdev_priv(dev);
953 dev_link_t *link = &lp->link; 921 struct pcmcia_device *link = lp->p_dev;
954 kio_addr_t ioaddr = dev->base_addr; 922 kio_addr_t ioaddr = dev->base_addr;
955 u16 opts = SetRxFilter | RxStation | RxBroadcast; 923 u16 opts = SetRxFilter | RxStation | RxBroadcast;
956 924
957 if (!(DEV_OK(link))) return; 925 if (!pcmcia_dev_present(link)) return;
958 if (dev->flags & IFF_PROMISC) 926 if (dev->flags & IFF_PROMISC)
959 opts |= RxMulticast | RxProm; 927 opts |= RxMulticast | RxProm;
960 else if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) 928 else if (dev->mc_count || (dev->flags & IFF_ALLMULTI))
@@ -965,12 +933,12 @@ static void set_multicast_list(struct net_device *dev)
965static int el3_close(struct net_device *dev) 933static int el3_close(struct net_device *dev)
966{ 934{
967 struct el3_private *lp = netdev_priv(dev); 935 struct el3_private *lp = netdev_priv(dev);
968 dev_link_t *link = &lp->link; 936 struct pcmcia_device *link = lp->p_dev;
969 kio_addr_t ioaddr = dev->base_addr; 937 kio_addr_t ioaddr = dev->base_addr;
970 938
971 DEBUG(1, "%s: shutting down ethercard.\n", dev->name); 939 DEBUG(1, "%s: shutting down ethercard.\n", dev->name);
972 940
973 if (DEV_OK(link)) { 941 if (pcmcia_dev_present(link)) {
974 /* Turn off statistics ASAP. We update lp->stats below. */ 942 /* Turn off statistics ASAP. We update lp->stats below. */
975 outw(StatsDisable, ioaddr + EL3_CMD); 943 outw(StatsDisable, ioaddr + EL3_CMD);
976 944
@@ -1020,7 +988,7 @@ static struct pcmcia_driver tc589_driver = {
1020 .drv = { 988 .drv = {
1021 .name = "3c589_cs", 989 .name = "3c589_cs",
1022 }, 990 },
1023 .probe = tc589_attach, 991 .probe = tc589_probe,
1024 .remove = tc589_detach, 992 .remove = tc589_detach,
1025 .id_table = tc589_ids, 993 .id_table = tc589_ids,
1026 .suspend = tc589_suspend, 994 .suspend = tc589_suspend,
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index aa5581369399..448a09488529 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -35,6 +35,7 @@
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <linux/ethtool.h> 36#include <linux/ethtool.h>
37#include <linux/netdevice.h> 37#include <linux/netdevice.h>
38#include <linux/crc32.h>
38#include "../8390.h" 39#include "../8390.h"
39 40
40#include <pcmcia/cs_types.h> 41#include <pcmcia/cs_types.h>
@@ -85,8 +86,8 @@ static char *version =
85 86
86/*====================================================================*/ 87/*====================================================================*/
87 88
88static void axnet_config(dev_link_t *link); 89static int axnet_config(struct pcmcia_device *link);
89static void axnet_release(dev_link_t *link); 90static void axnet_release(struct pcmcia_device *link);
90static int axnet_open(struct net_device *dev); 91static int axnet_open(struct net_device *dev);
91static int axnet_close(struct net_device *dev); 92static int axnet_close(struct net_device *dev);
92static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 93static int axnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -116,7 +117,7 @@ static irqreturn_t ax_interrupt(int irq, void *dev_id, struct pt_regs *regs);
116/*====================================================================*/ 117/*====================================================================*/
117 118
118typedef struct axnet_dev_t { 119typedef struct axnet_dev_t {
119 dev_link_t link; 120 struct pcmcia_device *p_dev;
120 dev_node_t node; 121 dev_node_t node;
121 caddr_t base; 122 caddr_t base;
122 struct timer_list watchdog; 123 struct timer_list watchdog;
@@ -141,10 +142,9 @@ static inline axnet_dev_t *PRIV(struct net_device *dev)
141 142
142======================================================================*/ 143======================================================================*/
143 144
144static int axnet_attach(struct pcmcia_device *p_dev) 145static int axnet_probe(struct pcmcia_device *link)
145{ 146{
146 axnet_dev_t *info; 147 axnet_dev_t *info;
147 dev_link_t *link;
148 struct net_device *dev; 148 struct net_device *dev;
149 149
150 DEBUG(0, "axnet_attach()\n"); 150 DEBUG(0, "axnet_attach()\n");
@@ -156,7 +156,7 @@ static int axnet_attach(struct pcmcia_device *p_dev)
156 return -ENOMEM; 156 return -ENOMEM;
157 157
158 info = PRIV(dev); 158 info = PRIV(dev);
159 link = &info->link; 159 info->p_dev = link;
160 link->priv = dev; 160 link->priv = dev;
161 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 161 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
162 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 162 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
@@ -168,13 +168,7 @@ static int axnet_attach(struct pcmcia_device *p_dev)
168 dev->do_ioctl = &axnet_ioctl; 168 dev->do_ioctl = &axnet_ioctl;
169 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 169 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
170 170
171 link->handle = p_dev; 171 return axnet_config(link);
172 p_dev->instance = link;
173
174 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
175 axnet_config(link);
176
177 return 0;
178} /* axnet_attach */ 172} /* axnet_attach */
179 173
180/*====================================================================== 174/*======================================================================
@@ -186,18 +180,16 @@ static int axnet_attach(struct pcmcia_device *p_dev)
186 180
187======================================================================*/ 181======================================================================*/
188 182
189static void axnet_detach(struct pcmcia_device *p_dev) 183static void axnet_detach(struct pcmcia_device *link)
190{ 184{
191 dev_link_t *link = dev_to_instance(p_dev);
192 struct net_device *dev = link->priv; 185 struct net_device *dev = link->priv;
193 186
194 DEBUG(0, "axnet_detach(0x%p)\n", link); 187 DEBUG(0, "axnet_detach(0x%p)\n", link);
195 188
196 if (link->dev) 189 if (link->dev_node)
197 unregister_netdev(dev); 190 unregister_netdev(dev);
198 191
199 if (link->state & DEV_CONFIG) 192 axnet_release(link);
200 axnet_release(link);
201 193
202 free_netdev(dev); 194 free_netdev(dev);
203} /* axnet_detach */ 195} /* axnet_detach */
@@ -208,7 +200,7 @@ static void axnet_detach(struct pcmcia_device *p_dev)
208 200
209======================================================================*/ 201======================================================================*/
210 202
211static int get_prom(dev_link_t *link) 203static int get_prom(struct pcmcia_device *link)
212{ 204{
213 struct net_device *dev = link->priv; 205 struct net_device *dev = link->priv;
214 kio_addr_t ioaddr = dev->base_addr; 206 kio_addr_t ioaddr = dev->base_addr;
@@ -262,7 +254,7 @@ static int get_prom(dev_link_t *link)
262#define CS_CHECK(fn, ret) \ 254#define CS_CHECK(fn, ret) \
263do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 255do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
264 256
265static int try_io_port(dev_link_t *link) 257static int try_io_port(struct pcmcia_device *link)
266{ 258{
267 int j, ret; 259 int j, ret;
268 if (link->io.NumPorts1 == 32) { 260 if (link->io.NumPorts1 == 32) {
@@ -283,25 +275,23 @@ static int try_io_port(dev_link_t *link)
283 for (j = 0; j < 0x400; j += 0x20) { 275 for (j = 0; j < 0x400; j += 0x20) {
284 link->io.BasePort1 = j ^ 0x300; 276 link->io.BasePort1 = j ^ 0x300;
285 link->io.BasePort2 = (j ^ 0x300) + 0x10; 277 link->io.BasePort2 = (j ^ 0x300) + 0x10;
286 ret = pcmcia_request_io(link->handle, &link->io); 278 ret = pcmcia_request_io(link, &link->io);
287 if (ret == CS_SUCCESS) return ret; 279 if (ret == CS_SUCCESS) return ret;
288 } 280 }
289 return ret; 281 return ret;
290 } else { 282 } else {
291 return pcmcia_request_io(link->handle, &link->io); 283 return pcmcia_request_io(link, &link->io);
292 } 284 }
293} 285}
294 286
295static void axnet_config(dev_link_t *link) 287static int axnet_config(struct pcmcia_device *link)
296{ 288{
297 client_handle_t handle = link->handle;
298 struct net_device *dev = link->priv; 289 struct net_device *dev = link->priv;
299 axnet_dev_t *info = PRIV(dev); 290 axnet_dev_t *info = PRIV(dev);
300 tuple_t tuple; 291 tuple_t tuple;
301 cisparse_t parse; 292 cisparse_t parse;
302 int i, j, last_ret, last_fn; 293 int i, j, last_ret, last_fn;
303 u_short buf[64]; 294 u_short buf[64];
304 config_info_t conf;
305 295
306 DEBUG(0, "axnet_config(0x%p)\n", link); 296 DEBUG(0, "axnet_config(0x%p)\n", link);
307 297
@@ -310,29 +300,22 @@ static void axnet_config(dev_link_t *link)
310 tuple.TupleDataMax = sizeof(buf); 300 tuple.TupleDataMax = sizeof(buf);
311 tuple.TupleOffset = 0; 301 tuple.TupleOffset = 0;
312 tuple.DesiredTuple = CISTPL_CONFIG; 302 tuple.DesiredTuple = CISTPL_CONFIG;
313 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 303 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
314 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 304 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
315 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 305 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
316 link->conf.ConfigBase = parse.config.base; 306 link->conf.ConfigBase = parse.config.base;
317 /* don't trust the CIS on this; Linksys got it wrong */ 307 /* don't trust the CIS on this; Linksys got it wrong */
318 link->conf.Present = 0x63; 308 link->conf.Present = 0x63;
319 309
320 /* Configure card */
321 link->state |= DEV_CONFIG;
322
323 /* Look up current Vcc */
324 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
325 link->conf.Vcc = conf.Vcc;
326
327 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 310 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
328 tuple.Attributes = 0; 311 tuple.Attributes = 0;
329 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 312 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
330 while (last_ret == CS_SUCCESS) { 313 while (last_ret == CS_SUCCESS) {
331 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 314 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
332 cistpl_io_t *io = &(parse.cftable_entry.io); 315 cistpl_io_t *io = &(parse.cftable_entry.io);
333 316
334 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 317 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
335 pcmcia_parse_tuple(handle, &tuple, &parse) != 0 || 318 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
336 cfg->index == 0 || cfg->io.nwin == 0) 319 cfg->index == 0 || cfg->io.nwin == 0)
337 goto next_entry; 320 goto next_entry;
338 321
@@ -354,21 +337,21 @@ static void axnet_config(dev_link_t *link)
354 if (last_ret == CS_SUCCESS) break; 337 if (last_ret == CS_SUCCESS) break;
355 } 338 }
356 next_entry: 339 next_entry:
357 last_ret = pcmcia_get_next_tuple(handle, &tuple); 340 last_ret = pcmcia_get_next_tuple(link, &tuple);
358 } 341 }
359 if (last_ret != CS_SUCCESS) { 342 if (last_ret != CS_SUCCESS) {
360 cs_error(handle, RequestIO, last_ret); 343 cs_error(link, RequestIO, last_ret);
361 goto failed; 344 goto failed;
362 } 345 }
363 346
364 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 347 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
365 348
366 if (link->io.NumPorts2 == 8) { 349 if (link->io.NumPorts2 == 8) {
367 link->conf.Attributes |= CONF_ENABLE_SPKR; 350 link->conf.Attributes |= CONF_ENABLE_SPKR;
368 link->conf.Status = CCSR_AUDIO_ENA; 351 link->conf.Status = CCSR_AUDIO_ENA;
369 } 352 }
370 353
371 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 354 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
372 dev->irq = link->irq.AssignedIRQ; 355 dev->irq = link->irq.AssignedIRQ;
373 dev->base_addr = link->io.BasePort1; 356 dev->base_addr = link->io.BasePort1;
374 357
@@ -405,7 +388,7 @@ static void axnet_config(dev_link_t *link)
405 Bit 2 of CCSR is active low. */ 388 Bit 2 of CCSR is active low. */
406 if (i == 32) { 389 if (i == 32) {
407 conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 }; 390 conf_reg_t reg = { 0, CS_WRITE, CISREG_CCSR, 0x04 };
408 pcmcia_access_configuration_register(link->handle, &reg); 391 pcmcia_access_configuration_register(link, &reg);
409 for (i = 0; i < 32; i++) { 392 for (i = 0; i < 32; i++) {
410 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1); 393 j = mdio_read(dev->base_addr + AXNET_MII_EEP, i, 1);
411 if ((j != 0) && (j != 0xffff)) break; 394 if ((j != 0) && (j != 0xffff)) break;
@@ -413,13 +396,12 @@ static void axnet_config(dev_link_t *link)
413 } 396 }
414 397
415 info->phy_id = (i < 32) ? i : -1; 398 info->phy_id = (i < 32) ? i : -1;
416 link->dev = &info->node; 399 link->dev_node = &info->node;
417 link->state &= ~DEV_CONFIG_PENDING; 400 SET_NETDEV_DEV(dev, &handle_to_dev(link));
418 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
419 401
420 if (register_netdev(dev) != 0) { 402 if (register_netdev(dev) != 0) {
421 printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n"); 403 printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n");
422 link->dev = NULL; 404 link->dev_node = NULL;
423 goto failed; 405 goto failed;
424 } 406 }
425 407
@@ -435,14 +417,13 @@ static void axnet_config(dev_link_t *link)
435 } else { 417 } else {
436 printk(KERN_NOTICE " No MII transceivers found!\n"); 418 printk(KERN_NOTICE " No MII transceivers found!\n");
437 } 419 }
438 return; 420 return 0;
439 421
440cs_failed: 422cs_failed:
441 cs_error(link->handle, last_fn, last_ret); 423 cs_error(link, last_fn, last_ret);
442failed: 424failed:
443 axnet_release(link); 425 axnet_release(link);
444 link->state &= ~DEV_CONFIG_PENDING; 426 return -ENODEV;
445 return;
446} /* axnet_config */ 427} /* axnet_config */
447 428
448/*====================================================================== 429/*======================================================================
@@ -453,45 +434,29 @@ failed:
453 434
454======================================================================*/ 435======================================================================*/
455 436
456static void axnet_release(dev_link_t *link) 437static void axnet_release(struct pcmcia_device *link)
457{ 438{
458 DEBUG(0, "axnet_release(0x%p)\n", link); 439 pcmcia_disable_device(link);
459
460 pcmcia_release_configuration(link->handle);
461 pcmcia_release_io(link->handle, &link->io);
462 pcmcia_release_irq(link->handle, &link->irq);
463
464 link->state &= ~DEV_CONFIG;
465} 440}
466 441
467static int axnet_suspend(struct pcmcia_device *p_dev) 442static int axnet_suspend(struct pcmcia_device *link)
468{ 443{
469 dev_link_t *link = dev_to_instance(p_dev);
470 struct net_device *dev = link->priv; 444 struct net_device *dev = link->priv;
471 445
472 link->state |= DEV_SUSPEND; 446 if (link->open)
473 if (link->state & DEV_CONFIG) { 447 netif_device_detach(dev);
474 if (link->open)
475 netif_device_detach(dev);
476 pcmcia_release_configuration(link->handle);
477 }
478 448
479 return 0; 449 return 0;
480} 450}
481 451
482static int axnet_resume(struct pcmcia_device *p_dev) 452static int axnet_resume(struct pcmcia_device *link)
483{ 453{
484 dev_link_t *link = dev_to_instance(p_dev);
485 struct net_device *dev = link->priv; 454 struct net_device *dev = link->priv;
486 455
487 link->state &= ~DEV_SUSPEND; 456 if (link->open) {
488 if (link->state & DEV_CONFIG) { 457 axnet_reset_8390(dev);
489 pcmcia_request_configuration(link->handle, &link->conf); 458 AX88190_init(dev, 1);
490 if (link->open) { 459 netif_device_attach(dev);
491 axnet_reset_8390(dev);
492 AX88190_init(dev, 1);
493 netif_device_attach(dev);
494 }
495 } 460 }
496 461
497 return 0; 462 return 0;
@@ -561,11 +526,11 @@ static void mdio_write(kio_addr_t addr, int phy_id, int loc, int value)
561static int axnet_open(struct net_device *dev) 526static int axnet_open(struct net_device *dev)
562{ 527{
563 axnet_dev_t *info = PRIV(dev); 528 axnet_dev_t *info = PRIV(dev);
564 dev_link_t *link = &info->link; 529 struct pcmcia_device *link = info->p_dev;
565 530
566 DEBUG(2, "axnet_open('%s')\n", dev->name); 531 DEBUG(2, "axnet_open('%s')\n", dev->name);
567 532
568 if (!DEV_OK(link)) 533 if (!pcmcia_dev_present(link))
569 return -ENODEV; 534 return -ENODEV;
570 535
571 link->open++; 536 link->open++;
@@ -587,7 +552,7 @@ static int axnet_open(struct net_device *dev)
587static int axnet_close(struct net_device *dev) 552static int axnet_close(struct net_device *dev)
588{ 553{
589 axnet_dev_t *info = PRIV(dev); 554 axnet_dev_t *info = PRIV(dev);
590 dev_link_t *link = &info->link; 555 struct pcmcia_device *link = info->p_dev;
591 556
592 DEBUG(2, "axnet_close('%s')\n", dev->name); 557 DEBUG(2, "axnet_close('%s')\n", dev->name);
593 558
@@ -832,7 +797,7 @@ static struct pcmcia_driver axnet_cs_driver = {
832 .drv = { 797 .drv = {
833 .name = "axnet_cs", 798 .name = "axnet_cs",
834 }, 799 },
835 .probe = axnet_attach, 800 .probe = axnet_probe,
836 .remove = axnet_detach, 801 .remove = axnet_detach,
837 .id_table = axnet_ids, 802 .id_table = axnet_ids,
838 .suspend = axnet_suspend, 803 .suspend = axnet_suspend,
@@ -1595,7 +1560,7 @@ static void ei_receive(struct net_device *dev)
1595 1560
1596static void ei_rx_overrun(struct net_device *dev) 1561static void ei_rx_overrun(struct net_device *dev)
1597{ 1562{
1598 axnet_dev_t *info = (axnet_dev_t *)dev; 1563 axnet_dev_t *info = PRIV(dev);
1599 long e8390_base = dev->base_addr; 1564 long e8390_base = dev->base_addr;
1600 unsigned char was_txing, must_resend = 0; 1565 unsigned char was_txing, must_resend = 0;
1601 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev); 1566 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
@@ -1682,17 +1647,67 @@ static struct net_device_stats *get_stats(struct net_device *dev)
1682 return &ei_local->stat; 1647 return &ei_local->stat;
1683} 1648}
1684 1649
1650/*
1651 * Form the 64 bit 8390 multicast table from the linked list of addresses
1652 * associated with this dev structure.
1653 */
1654
1655static inline void make_mc_bits(u8 *bits, struct net_device *dev)
1656{
1657 struct dev_mc_list *dmi;
1658 u32 crc;
1659
1660 for (dmi=dev->mc_list; dmi; dmi=dmi->next) {
1661
1662 crc = ether_crc(ETH_ALEN, dmi->dmi_addr);
1663 /*
1664 * The 8390 uses the 6 most significant bits of the
1665 * CRC to index the multicast table.
1666 */
1667 bits[crc>>29] |= (1<<((crc>>26)&7));
1668 }
1669}
1670
1685/** 1671/**
1686 * do_set_multicast_list - set/clear multicast filter 1672 * do_set_multicast_list - set/clear multicast filter
1687 * @dev: net device for which multicast filter is adjusted 1673 * @dev: net device for which multicast filter is adjusted
1688 * 1674 *
1689 * Set or clear the multicast filter for this adaptor. May be called 1675 * Set or clear the multicast filter for this adaptor.
1690 * from a BH in 2.1.x. Must be called with lock held. 1676 * Must be called with lock held.
1691 */ 1677 */
1692 1678
1693static void do_set_multicast_list(struct net_device *dev) 1679static void do_set_multicast_list(struct net_device *dev)
1694{ 1680{
1695 long e8390_base = dev->base_addr; 1681 long e8390_base = dev->base_addr;
1682 int i;
1683 struct ei_device *ei_local = (struct ei_device*)netdev_priv(dev);
1684
1685 if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) {
1686 memset(ei_local->mcfilter, 0, 8);
1687 if (dev->mc_list)
1688 make_mc_bits(ei_local->mcfilter, dev);
1689 } else {
1690 /* set to accept-all */
1691 memset(ei_local->mcfilter, 0xFF, 8);
1692 }
1693
1694 /*
1695 * DP8390 manuals don't specify any magic sequence for altering
1696 * the multicast regs on an already running card. To be safe, we
1697 * ensure multicast mode is off prior to loading up the new hash
1698 * table. If this proves to be not enough, we can always resort
1699 * to stopping the NIC, loading the table and then restarting.
1700 */
1701
1702 if (netif_running(dev))
1703 outb_p(E8390_RXCONFIG, e8390_base + EN0_RXCR);
1704
1705 outb_p(E8390_NODMA + E8390_PAGE1, e8390_base + E8390_CMD);
1706 for(i = 0; i < 8; i++)
1707 {
1708 outb_p(ei_local->mcfilter[i], e8390_base + EN1_MULT_SHIFT(i));
1709 }
1710 outb_p(E8390_NODMA + E8390_PAGE0, e8390_base + E8390_CMD);
1696 1711
1697 if(dev->flags&IFF_PROMISC) 1712 if(dev->flags&IFF_PROMISC)
1698 outb_p(E8390_RXCONFIG | 0x58, e8390_base + EN0_RXCR); 1713 outb_p(E8390_RXCONFIG | 0x58, e8390_base + EN0_RXCR);
@@ -1794,12 +1809,6 @@ static void AX88190_init(struct net_device *dev, int startp)
1794 if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i]) 1809 if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i])
1795 printk(KERN_ERR "Hw. address read/write mismap %d\n",i); 1810 printk(KERN_ERR "Hw. address read/write mismap %d\n",i);
1796 } 1811 }
1797 /*
1798 * Initialize the multicast list to accept-all. If we enable multicast
1799 * the higher levels can do the filtering.
1800 */
1801 for (i = 0; i < 8; i++)
1802 outb_p(0xff, e8390_base + EN1_MULT + i);
1803 1812
1804 outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG); 1813 outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG);
1805 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD); 1814 outb_p(E8390_NODMA+E8390_PAGE0+E8390_STOP, e8390_base+E8390_CMD);
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 2827a48ea37c..441de824ab6b 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -118,8 +118,8 @@ MODULE_LICENSE("GPL");
118 118
119/*====================================================================*/ 119/*====================================================================*/
120 120
121static void com20020_config(dev_link_t *link); 121static int com20020_config(struct pcmcia_device *link);
122static void com20020_release(dev_link_t *link); 122static void com20020_release(struct pcmcia_device *link);
123 123
124static void com20020_detach(struct pcmcia_device *p_dev); 124static void com20020_detach(struct pcmcia_device *p_dev);
125 125
@@ -138,9 +138,8 @@ typedef struct com20020_dev_t {
138 138
139======================================================================*/ 139======================================================================*/
140 140
141static int com20020_attach(struct pcmcia_device *p_dev) 141static int com20020_probe(struct pcmcia_device *p_dev)
142{ 142{
143 dev_link_t *link;
144 com20020_dev_t *info; 143 com20020_dev_t *info;
145 struct net_device *dev; 144 struct net_device *dev;
146 struct arcnet_local *lp; 145 struct arcnet_local *lp;
@@ -148,10 +147,6 @@ static int com20020_attach(struct pcmcia_device *p_dev)
148 DEBUG(0, "com20020_attach()\n"); 147 DEBUG(0, "com20020_attach()\n");
149 148
150 /* Create new network device */ 149 /* Create new network device */
151 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
152 if (!link)
153 return -ENOMEM;
154
155 info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL); 150 info = kmalloc(sizeof(struct com20020_dev_t), GFP_KERNEL);
156 if (!info) 151 if (!info)
157 goto fail_alloc_info; 152 goto fail_alloc_info;
@@ -161,7 +156,6 @@ static int com20020_attach(struct pcmcia_device *p_dev)
161 goto fail_alloc_dev; 156 goto fail_alloc_dev;
162 157
163 memset(info, 0, sizeof(struct com20020_dev_t)); 158 memset(info, 0, sizeof(struct com20020_dev_t));
164 memset(link, 0, sizeof(struct dev_link_t));
165 lp = dev->priv; 159 lp = dev->priv;
166 lp->timeout = timeout; 160 lp->timeout = timeout;
167 lp->backplane = backplane; 161 lp->backplane = backplane;
@@ -172,28 +166,23 @@ static int com20020_attach(struct pcmcia_device *p_dev)
172 /* fill in our module parameters as defaults */ 166 /* fill in our module parameters as defaults */
173 dev->dev_addr[0] = node; 167 dev->dev_addr[0] = node;
174 168
175 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 169 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
176 link->io.NumPorts1 = 16; 170 p_dev->io.NumPorts1 = 16;
177 link->io.IOAddrLines = 16; 171 p_dev->io.IOAddrLines = 16;
178 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 172 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
179 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 173 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
180 link->conf.Attributes = CONF_ENABLE_IRQ; 174 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
181 link->conf.Vcc = 50; 175 p_dev->conf.IntType = INT_MEMORY_AND_IO;
182 link->conf.IntType = INT_MEMORY_AND_IO; 176 p_dev->conf.Present = PRESENT_OPTION;
183 link->conf.Present = PRESENT_OPTION;
184
185 link->irq.Instance = info->dev = dev;
186 link->priv = info;
187 177
188 link->state |= DEV_PRESENT; 178 p_dev->irq.Instance = info->dev = dev;
189 com20020_config(link); 179 p_dev->priv = info;
190 180
191 return 0; 181 return com20020_config(p_dev);
192 182
193fail_alloc_dev: 183fail_alloc_dev:
194 kfree(info); 184 kfree(info);
195fail_alloc_info: 185fail_alloc_info:
196 kfree(link);
197 return -ENOMEM; 186 return -ENOMEM;
198} /* com20020_attach */ 187} /* com20020_attach */
199 188
@@ -206,9 +195,8 @@ fail_alloc_info:
206 195
207======================================================================*/ 196======================================================================*/
208 197
209static void com20020_detach(struct pcmcia_device *p_dev) 198static void com20020_detach(struct pcmcia_device *link)
210{ 199{
211 dev_link_t *link = dev_to_instance(p_dev);
212 struct com20020_dev_t *info = link->priv; 200 struct com20020_dev_t *info = link->priv;
213 struct net_device *dev = info->dev; 201 struct net_device *dev = info->dev;
214 202
@@ -216,7 +204,7 @@ static void com20020_detach(struct pcmcia_device *p_dev)
216 204
217 DEBUG(0, "com20020_detach(0x%p)\n", link); 205 DEBUG(0, "com20020_detach(0x%p)\n", link);
218 206
219 if (link->dev) { 207 if (link->dev_node) {
220 DEBUG(1,"unregister...\n"); 208 DEBUG(1,"unregister...\n");
221 209
222 unregister_netdev(dev); 210 unregister_netdev(dev);
@@ -229,8 +217,7 @@ static void com20020_detach(struct pcmcia_device *p_dev)
229 free_irq(dev->irq, dev); 217 free_irq(dev->irq, dev);
230 } 218 }
231 219
232 if (link->state & DEV_CONFIG) 220 com20020_release(link);
233 com20020_release(link);
234 221
235 /* Unlink device structure, free bits */ 222 /* Unlink device structure, free bits */
236 DEBUG(1,"unlinking...\n"); 223 DEBUG(1,"unlinking...\n");
@@ -245,8 +232,6 @@ static void com20020_detach(struct pcmcia_device *p_dev)
245 DEBUG(1,"kfree2...\n"); 232 DEBUG(1,"kfree2...\n");
246 kfree(info); 233 kfree(info);
247 } 234 }
248 DEBUG(1,"kfree3...\n");
249 kfree(link);
250 235
251} /* com20020_detach */ 236} /* com20020_detach */
252 237
@@ -261,10 +246,9 @@ static void com20020_detach(struct pcmcia_device *p_dev)
261#define CS_CHECK(fn, ret) \ 246#define CS_CHECK(fn, ret) \
262do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 247do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
263 248
264static void com20020_config(dev_link_t *link) 249static int com20020_config(struct pcmcia_device *link)
265{ 250{
266 struct arcnet_local *lp; 251 struct arcnet_local *lp;
267 client_handle_t handle;
268 tuple_t tuple; 252 tuple_t tuple;
269 cisparse_t parse; 253 cisparse_t parse;
270 com20020_dev_t *info; 254 com20020_dev_t *info;
@@ -273,7 +257,6 @@ static void com20020_config(dev_link_t *link)
273 u_char buf[64]; 257 u_char buf[64];
274 int ioaddr; 258 int ioaddr;
275 259
276 handle = link->handle;
277 info = link->priv; 260 info = link->priv;
278 dev = info->dev; 261 dev = info->dev;
279 262
@@ -286,14 +269,11 @@ static void com20020_config(dev_link_t *link)
286 tuple.TupleDataMax = 64; 269 tuple.TupleDataMax = 64;
287 tuple.TupleOffset = 0; 270 tuple.TupleOffset = 0;
288 tuple.DesiredTuple = CISTPL_CONFIG; 271 tuple.DesiredTuple = CISTPL_CONFIG;
289 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 272 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
290 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 273 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
291 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 274 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
292 link->conf.ConfigBase = parse.config.base; 275 link->conf.ConfigBase = parse.config.base;
293 276
294 /* Configure card */
295 link->state |= DEV_CONFIG;
296
297 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1); 277 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1);
298 i = !CS_SUCCESS; 278 i = !CS_SUCCESS;
299 if (!link->io.BasePort1) 279 if (!link->io.BasePort1)
@@ -301,13 +281,13 @@ static void com20020_config(dev_link_t *link)
301 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10) 281 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10)
302 { 282 {
303 link->io.BasePort1 = ioaddr; 283 link->io.BasePort1 = ioaddr;
304 i = pcmcia_request_io(link->handle, &link->io); 284 i = pcmcia_request_io(link, &link->io);
305 if (i == CS_SUCCESS) 285 if (i == CS_SUCCESS)
306 break; 286 break;
307 } 287 }
308 } 288 }
309 else 289 else
310 i = pcmcia_request_io(link->handle, &link->io); 290 i = pcmcia_request_io(link, &link->io);
311 291
312 if (i != CS_SUCCESS) 292 if (i != CS_SUCCESS)
313 { 293 {
@@ -321,7 +301,7 @@ static void com20020_config(dev_link_t *link)
321 DEBUG(1,"arcnet: request IRQ %d (%Xh/%Xh)\n", 301 DEBUG(1,"arcnet: request IRQ %d (%Xh/%Xh)\n",
322 link->irq.AssignedIRQ, 302 link->irq.AssignedIRQ,
323 link->irq.IRQInfo1, link->irq.IRQInfo2); 303 link->irq.IRQInfo1, link->irq.IRQInfo2);
324 i = pcmcia_request_irq(link->handle, &link->irq); 304 i = pcmcia_request_irq(link, &link->irq);
325 if (i != CS_SUCCESS) 305 if (i != CS_SUCCESS)
326 { 306 {
327 DEBUG(1,"arcnet: requestIRQ failed totally!\n"); 307 DEBUG(1,"arcnet: requestIRQ failed totally!\n");
@@ -330,7 +310,7 @@ static void com20020_config(dev_link_t *link)
330 310
331 dev->irq = link->irq.AssignedIRQ; 311 dev->irq = link->irq.AssignedIRQ;
332 312
333 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 313 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
334 314
335 if (com20020_check(dev)) 315 if (com20020_check(dev))
336 { 316 {
@@ -342,15 +322,14 @@ static void com20020_config(dev_link_t *link)
342 lp->card_name = "PCMCIA COM20020"; 322 lp->card_name = "PCMCIA COM20020";
343 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */ 323 lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
344 324
345 link->dev = &info->node; 325 link->dev_node = &info->node;
346 link->state &= ~DEV_CONFIG_PENDING; 326 SET_NETDEV_DEV(dev, &handle_to_dev(link));
347 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
348 327
349 i = com20020_found(dev, 0); /* calls register_netdev */ 328 i = com20020_found(dev, 0); /* calls register_netdev */
350 329
351 if (i != 0) { 330 if (i != 0) {
352 DEBUG(1,KERN_NOTICE "com20020_cs: com20020_found() failed\n"); 331 DEBUG(1,KERN_NOTICE "com20020_cs: com20020_found() failed\n");
353 link->dev = NULL; 332 link->dev_node = NULL;
354 goto failed; 333 goto failed;
355 } 334 }
356 335
@@ -358,13 +337,14 @@ static void com20020_config(dev_link_t *link)
358 337
359 DEBUG(1,KERN_INFO "%s: port %#3lx, irq %d\n", 338 DEBUG(1,KERN_INFO "%s: port %#3lx, irq %d\n",
360 dev->name, dev->base_addr, dev->irq); 339 dev->name, dev->base_addr, dev->irq);
361 return; 340 return 0;
362 341
363cs_failed: 342cs_failed:
364 cs_error(link->handle, last_fn, last_ret); 343 cs_error(link, last_fn, last_ret);
365failed: 344failed:
366 DEBUG(1,"com20020_config failed...\n"); 345 DEBUG(1,"com20020_config failed...\n");
367 com20020_release(link); 346 com20020_release(link);
347 return -ENODEV;
368} /* com20020_config */ 348} /* com20020_config */
369 349
370/*====================================================================== 350/*======================================================================
@@ -375,52 +355,33 @@ failed:
375 355
376======================================================================*/ 356======================================================================*/
377 357
378static void com20020_release(dev_link_t *link) 358static void com20020_release(struct pcmcia_device *link)
379{ 359{
380 360 DEBUG(0, "com20020_release(0x%p)\n", link);
381 DEBUG(1,"release...\n"); 361 pcmcia_disable_device(link);
382
383 DEBUG(0, "com20020_release(0x%p)\n", link);
384
385 pcmcia_release_configuration(link->handle);
386 pcmcia_release_io(link->handle, &link->io);
387 pcmcia_release_irq(link->handle, &link->irq);
388
389 link->state &= ~(DEV_CONFIG | DEV_RELEASE_PENDING);
390} 362}
391 363
392static int com20020_suspend(struct pcmcia_device *p_dev) 364static int com20020_suspend(struct pcmcia_device *link)
393{ 365{
394 dev_link_t *link = dev_to_instance(p_dev);
395 com20020_dev_t *info = link->priv; 366 com20020_dev_t *info = link->priv;
396 struct net_device *dev = info->dev; 367 struct net_device *dev = info->dev;
397 368
398 link->state |= DEV_SUSPEND; 369 if (link->open)
399 if (link->state & DEV_CONFIG) { 370 netif_device_detach(dev);
400 if (link->open) {
401 netif_device_detach(dev);
402 }
403 pcmcia_release_configuration(link->handle);
404 }
405 371
406 return 0; 372 return 0;
407} 373}
408 374
409static int com20020_resume(struct pcmcia_device *p_dev) 375static int com20020_resume(struct pcmcia_device *link)
410{ 376{
411 dev_link_t *link = dev_to_instance(p_dev);
412 com20020_dev_t *info = link->priv; 377 com20020_dev_t *info = link->priv;
413 struct net_device *dev = info->dev; 378 struct net_device *dev = info->dev;
414 379
415 link->state &= ~DEV_SUSPEND; 380 if (link->open) {
416 if (link->state & DEV_CONFIG) { 381 int ioaddr = dev->base_addr;
417 pcmcia_request_configuration(link->handle, &link->conf); 382 struct arcnet_local *lp = dev->priv;
418 if (link->open) { 383 ARCRESET;
419 int ioaddr = dev->base_addr; 384 }
420 struct arcnet_local *lp = dev->priv;
421 ARCRESET;
422 }
423 }
424 385
425 return 0; 386 return 0;
426} 387}
@@ -436,7 +397,7 @@ static struct pcmcia_driver com20020_cs_driver = {
436 .drv = { 397 .drv = {
437 .name = "com20020_cs", 398 .name = "com20020_cs",
438 }, 399 },
439 .probe = com20020_attach, 400 .probe = com20020_probe,
440 .remove = com20020_detach, 401 .remove = com20020_detach,
441 .id_table = com20020_ids, 402 .id_table = com20020_ids,
442 .suspend = com20020_suspend, 403 .suspend = com20020_suspend,
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index b7ac14ba8877..09b11761cdfa 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -84,10 +84,10 @@ static char *version = DRV_NAME ".c " DRV_VERSION " 2002/03/23";
84/* 84/*
85 PCMCIA event handlers 85 PCMCIA event handlers
86 */ 86 */
87static void fmvj18x_config(dev_link_t *link); 87static int fmvj18x_config(struct pcmcia_device *link);
88static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id); 88static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id);
89static int fmvj18x_setup_mfc(dev_link_t *link); 89static int fmvj18x_setup_mfc(struct pcmcia_device *link);
90static void fmvj18x_release(dev_link_t *link); 90static void fmvj18x_release(struct pcmcia_device *link);
91static void fmvj18x_detach(struct pcmcia_device *p_dev); 91static void fmvj18x_detach(struct pcmcia_device *p_dev);
92 92
93/* 93/*
@@ -116,7 +116,7 @@ typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
116 driver specific data structure 116 driver specific data structure
117*/ 117*/
118typedef struct local_info_t { 118typedef struct local_info_t {
119 dev_link_t link; 119 struct pcmcia_device *p_dev;
120 dev_node_t node; 120 dev_node_t node;
121 struct net_device_stats stats; 121 struct net_device_stats stats;
122 long open_time; 122 long open_time;
@@ -228,10 +228,9 @@ typedef struct local_info_t {
228#define BANK_1U 0x24 /* bank 1 (CONFIG_1) */ 228#define BANK_1U 0x24 /* bank 1 (CONFIG_1) */
229#define BANK_2U 0x28 /* bank 2 (CONFIG_1) */ 229#define BANK_2U 0x28 /* bank 2 (CONFIG_1) */
230 230
231static int fmvj18x_attach(struct pcmcia_device *p_dev) 231static int fmvj18x_probe(struct pcmcia_device *link)
232{ 232{
233 local_info_t *lp; 233 local_info_t *lp;
234 dev_link_t *link;
235 struct net_device *dev; 234 struct net_device *dev;
236 235
237 DEBUG(0, "fmvj18x_attach()\n"); 236 DEBUG(0, "fmvj18x_attach()\n");
@@ -241,8 +240,8 @@ static int fmvj18x_attach(struct pcmcia_device *p_dev)
241 if (!dev) 240 if (!dev)
242 return -ENOMEM; 241 return -ENOMEM;
243 lp = netdev_priv(dev); 242 lp = netdev_priv(dev);
244 link = &lp->link;
245 link->priv = dev; 243 link->priv = dev;
244 lp->p_dev = link;
246 245
247 /* The io structure describes IO port mapping */ 246 /* The io structure describes IO port mapping */
248 link->io.NumPorts1 = 32; 247 link->io.NumPorts1 = 32;
@@ -257,7 +256,6 @@ static int fmvj18x_attach(struct pcmcia_device *p_dev)
257 256
258 /* General socket configuration */ 257 /* General socket configuration */
259 link->conf.Attributes = CONF_ENABLE_IRQ; 258 link->conf.Attributes = CONF_ENABLE_IRQ;
260 link->conf.Vcc = 50;
261 link->conf.IntType = INT_MEMORY_AND_IO; 259 link->conf.IntType = INT_MEMORY_AND_IO;
262 260
263 /* The FMVJ18x specific entries in the device structure. */ 261 /* The FMVJ18x specific entries in the device structure. */
@@ -274,29 +272,21 @@ static int fmvj18x_attach(struct pcmcia_device *p_dev)
274#endif 272#endif
275 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 273 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
276 274
277 link->handle = p_dev; 275 return fmvj18x_config(link);
278 p_dev->instance = link;
279
280 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
281 fmvj18x_config(link);
282
283 return 0;
284} /* fmvj18x_attach */ 276} /* fmvj18x_attach */
285 277
286/*====================================================================*/ 278/*====================================================================*/
287 279
288static void fmvj18x_detach(struct pcmcia_device *p_dev) 280static void fmvj18x_detach(struct pcmcia_device *link)
289{ 281{
290 dev_link_t *link = dev_to_instance(p_dev);
291 struct net_device *dev = link->priv; 282 struct net_device *dev = link->priv;
292 283
293 DEBUG(0, "fmvj18x_detach(0x%p)\n", link); 284 DEBUG(0, "fmvj18x_detach(0x%p)\n", link);
294 285
295 if (link->dev) 286 if (link->dev_node)
296 unregister_netdev(dev); 287 unregister_netdev(dev);
297 288
298 if (link->state & DEV_CONFIG) 289 fmvj18x_release(link);
299 fmvj18x_release(link);
300 290
301 free_netdev(dev); 291 free_netdev(dev);
302} /* fmvj18x_detach */ 292} /* fmvj18x_detach */
@@ -306,7 +296,7 @@ static void fmvj18x_detach(struct pcmcia_device *p_dev)
306#define CS_CHECK(fn, ret) \ 296#define CS_CHECK(fn, ret) \
307do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 297do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
308 298
309static int mfc_try_io_port(dev_link_t *link) 299static int mfc_try_io_port(struct pcmcia_device *link)
310{ 300{
311 int i, ret; 301 int i, ret;
312 static const kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 302 static const kio_addr_t serial_base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
@@ -318,13 +308,13 @@ static int mfc_try_io_port(dev_link_t *link)
318 link->io.NumPorts2 = 0; 308 link->io.NumPorts2 = 0;
319 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n"); 309 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n");
320 } 310 }
321 ret = pcmcia_request_io(link->handle, &link->io); 311 ret = pcmcia_request_io(link, &link->io);
322 if (ret == CS_SUCCESS) return ret; 312 if (ret == CS_SUCCESS) return ret;
323 } 313 }
324 return ret; 314 return ret;
325} 315}
326 316
327static int ungermann_try_io_port(dev_link_t *link) 317static int ungermann_try_io_port(struct pcmcia_device *link)
328{ 318{
329 int ret; 319 int ret;
330 kio_addr_t ioaddr; 320 kio_addr_t ioaddr;
@@ -334,7 +324,7 @@ static int ungermann_try_io_port(dev_link_t *link)
334 */ 324 */
335 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) { 325 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
336 link->io.BasePort1 = ioaddr; 326 link->io.BasePort1 = ioaddr;
337 ret = pcmcia_request_io(link->handle, &link->io); 327 ret = pcmcia_request_io(link, &link->io);
338 if (ret == CS_SUCCESS) { 328 if (ret == CS_SUCCESS) {
339 /* calculate ConfigIndex value */ 329 /* calculate ConfigIndex value */
340 link->conf.ConfigIndex = 330 link->conf.ConfigIndex =
@@ -345,9 +335,8 @@ static int ungermann_try_io_port(dev_link_t *link)
345 return ret; /* RequestIO failed */ 335 return ret; /* RequestIO failed */
346} 336}
347 337
348static void fmvj18x_config(dev_link_t *link) 338static int fmvj18x_config(struct pcmcia_device *link)
349{ 339{
350 client_handle_t handle = link->handle;
351 struct net_device *dev = link->priv; 340 struct net_device *dev = link->priv;
352 local_info_t *lp = netdev_priv(dev); 341 local_info_t *lp = netdev_priv(dev);
353 tuple_t tuple; 342 tuple_t tuple;
@@ -366,42 +355,34 @@ static void fmvj18x_config(dev_link_t *link)
366 registers. 355 registers.
367 */ 356 */
368 tuple.DesiredTuple = CISTPL_CONFIG; 357 tuple.DesiredTuple = CISTPL_CONFIG;
369 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 358 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
370 tuple.TupleData = (u_char *)buf; 359 tuple.TupleData = (u_char *)buf;
371 tuple.TupleDataMax = 64; 360 tuple.TupleDataMax = 64;
372 tuple.TupleOffset = 0; 361 tuple.TupleOffset = 0;
373 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 362 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
374 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 363 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
375
376 /* Configure card */
377 link->state |= DEV_CONFIG;
378 364
379 link->conf.ConfigBase = parse.config.base; 365 link->conf.ConfigBase = parse.config.base;
380 link->conf.Present = parse.config.rmask[0]; 366 link->conf.Present = parse.config.rmask[0];
381 367
382 tuple.DesiredTuple = CISTPL_FUNCE; 368 tuple.DesiredTuple = CISTPL_FUNCE;
383 tuple.TupleOffset = 0; 369 tuple.TupleOffset = 0;
384 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) { 370 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
385 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ 371 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
386 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 372 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
387 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 373 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
388 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 374 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
389 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 375 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
390 link->conf.ConfigIndex = parse.cftable_entry.index; 376 link->conf.ConfigIndex = parse.cftable_entry.index;
391 tuple.DesiredTuple = CISTPL_MANFID; 377 tuple.DesiredTuple = CISTPL_MANFID;
392 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) 378 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS)
393 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 379 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
394 else 380 else
395 buf[0] = 0xffff; 381 buf[0] = 0xffff;
396 switch (le16_to_cpu(buf[0])) { 382 switch (le16_to_cpu(buf[0])) {
397 case MANFID_TDK: 383 case MANFID_TDK:
398 cardtype = TDK; 384 cardtype = TDK;
399 if (le16_to_cpu(buf[1]) == PRODID_TDK_CF010) { 385 if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
400 cs_status_t status;
401 pcmcia_get_status(handle, &status);
402 if (status.CardState & CS_EVENT_3VCARD)
403 link->conf.Vcc = 33; /* inserted in 3.3V slot */
404 } else if (le16_to_cpu(buf[1]) == PRODID_TDK_GN3410
405 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610 386 || le16_to_cpu(buf[1]) == PRODID_TDK_NP9610
406 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) { 387 || le16_to_cpu(buf[1]) == PRODID_TDK_MN3200) {
407 /* MultiFunction Card */ 388 /* MultiFunction Card */
@@ -429,8 +410,8 @@ static void fmvj18x_config(dev_link_t *link)
429 } else { 410 } else {
430 /* old type card */ 411 /* old type card */
431 tuple.DesiredTuple = CISTPL_MANFID; 412 tuple.DesiredTuple = CISTPL_MANFID;
432 if (pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) 413 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS)
433 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 414 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
434 else 415 else
435 buf[0] = 0xffff; 416 buf[0] = 0xffff;
436 switch (le16_to_cpu(buf[0])) { 417 switch (le16_to_cpu(buf[0])) {
@@ -461,10 +442,10 @@ static void fmvj18x_config(dev_link_t *link)
461 ret = ungermann_try_io_port(link); 442 ret = ungermann_try_io_port(link);
462 if (ret != CS_SUCCESS) goto cs_failed; 443 if (ret != CS_SUCCESS) goto cs_failed;
463 } else { 444 } else {
464 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io)); 445 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
465 } 446 }
466 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 447 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
467 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 448 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
468 dev->irq = link->irq.AssignedIRQ; 449 dev->irq = link->irq.AssignedIRQ;
469 dev->base_addr = link->io.BasePort1; 450 dev->base_addr = link->io.BasePort1;
470 451
@@ -493,17 +474,17 @@ static void fmvj18x_config(dev_link_t *link)
493 case CONTEC: 474 case CONTEC:
494 tuple.DesiredTuple = CISTPL_FUNCE; 475 tuple.DesiredTuple = CISTPL_FUNCE;
495 tuple.TupleOffset = 0; 476 tuple.TupleOffset = 0;
496 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 477 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
497 tuple.TupleOffset = 0; 478 tuple.TupleOffset = 0;
498 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 479 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
499 if (cardtype == MBH10304) { 480 if (cardtype == MBH10304) {
500 /* MBH10304's CIS_FUNCE is corrupted */ 481 /* MBH10304's CIS_FUNCE is corrupted */
501 node_id = &(tuple.TupleData[5]); 482 node_id = &(tuple.TupleData[5]);
502 card_name = "FMV-J182"; 483 card_name = "FMV-J182";
503 } else { 484 } else {
504 while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) { 485 while (tuple.TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID ) {
505 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 486 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
506 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 487 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
507 } 488 }
508 node_id = &(tuple.TupleData[2]); 489 node_id = &(tuple.TupleData[2]);
509 if( cardtype == TDK ) { 490 if( cardtype == TDK ) {
@@ -545,13 +526,12 @@ static void fmvj18x_config(dev_link_t *link)
545 } 526 }
546 527
547 lp->cardtype = cardtype; 528 lp->cardtype = cardtype;
548 link->dev = &lp->node; 529 link->dev_node = &lp->node;
549 link->state &= ~DEV_CONFIG_PENDING; 530 SET_NETDEV_DEV(dev, &handle_to_dev(link));
550 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
551 531
552 if (register_netdev(dev) != 0) { 532 if (register_netdev(dev) != 0) {
553 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n"); 533 printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
554 link->dev = NULL; 534 link->dev_node = NULL;
555 goto failed; 535 goto failed;
556 } 536 }
557 537
@@ -564,19 +544,18 @@ static void fmvj18x_config(dev_link_t *link)
564 for (i = 0; i < 6; i++) 544 for (i = 0; i < 6; i++)
565 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 545 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
566 546
567 return; 547 return 0;
568 548
569cs_failed: 549cs_failed:
570 /* All Card Services errors end up here */ 550 /* All Card Services errors end up here */
571 cs_error(link->handle, last_fn, last_ret); 551 cs_error(link, last_fn, last_ret);
572failed: 552failed:
573 fmvj18x_release(link); 553 fmvj18x_release(link);
574 link->state &= ~DEV_CONFIG_PENDING; 554 return -ENODEV;
575
576} /* fmvj18x_config */ 555} /* fmvj18x_config */
577/*====================================================================*/ 556/*====================================================================*/
578 557
579static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id) 558static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
580{ 559{
581 win_req_t req; 560 win_req_t req;
582 memreq_t mem; 561 memreq_t mem;
@@ -587,9 +566,9 @@ static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
587 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 566 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
588 req.Base = 0; req.Size = 0; 567 req.Base = 0; req.Size = 0;
589 req.AccessSpeed = 0; 568 req.AccessSpeed = 0;
590 i = pcmcia_request_window(&link->handle, &req, &link->win); 569 i = pcmcia_request_window(&link, &req, &link->win);
591 if (i != CS_SUCCESS) { 570 if (i != CS_SUCCESS) {
592 cs_error(link->handle, RequestWindow, i); 571 cs_error(link, RequestWindow, i);
593 return -1; 572 return -1;
594 } 573 }
595 574
@@ -623,13 +602,13 @@ static int fmvj18x_get_hwinfo(dev_link_t *link, u_char *node_id)
623 iounmap(base); 602 iounmap(base);
624 j = pcmcia_release_window(link->win); 603 j = pcmcia_release_window(link->win);
625 if (j != CS_SUCCESS) 604 if (j != CS_SUCCESS)
626 cs_error(link->handle, ReleaseWindow, j); 605 cs_error(link, ReleaseWindow, j);
627 return (i != 0x200) ? 0 : -1; 606 return (i != 0x200) ? 0 : -1;
628 607
629} /* fmvj18x_get_hwinfo */ 608} /* fmvj18x_get_hwinfo */
630/*====================================================================*/ 609/*====================================================================*/
631 610
632static int fmvj18x_setup_mfc(dev_link_t *link) 611static int fmvj18x_setup_mfc(struct pcmcia_device *link)
633{ 612{
634 win_req_t req; 613 win_req_t req;
635 memreq_t mem; 614 memreq_t mem;
@@ -642,9 +621,9 @@ static int fmvj18x_setup_mfc(dev_link_t *link)
642 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 621 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
643 req.Base = 0; req.Size = 0; 622 req.Base = 0; req.Size = 0;
644 req.AccessSpeed = 0; 623 req.AccessSpeed = 0;
645 i = pcmcia_request_window(&link->handle, &req, &link->win); 624 i = pcmcia_request_window(&link, &req, &link->win);
646 if (i != CS_SUCCESS) { 625 if (i != CS_SUCCESS) {
647 cs_error(link->handle, RequestWindow, i); 626 cs_error(link, RequestWindow, i);
648 return -1; 627 return -1;
649 } 628 }
650 629
@@ -666,54 +645,35 @@ static int fmvj18x_setup_mfc(dev_link_t *link)
666 iounmap(base); 645 iounmap(base);
667 j = pcmcia_release_window(link->win); 646 j = pcmcia_release_window(link->win);
668 if (j != CS_SUCCESS) 647 if (j != CS_SUCCESS)
669 cs_error(link->handle, ReleaseWindow, j); 648 cs_error(link, ReleaseWindow, j);
670 return 0; 649 return 0;
671 650
672} 651}
673/*====================================================================*/ 652/*====================================================================*/
674 653
675static void fmvj18x_release(dev_link_t *link) 654static void fmvj18x_release(struct pcmcia_device *link)
676{ 655{
677 656 DEBUG(0, "fmvj18x_release(0x%p)\n", link);
678 DEBUG(0, "fmvj18x_release(0x%p)\n", link); 657 pcmcia_disable_device(link);
679
680 /* Don't bother checking to see if these succeed or not */
681 pcmcia_release_window(link->win);
682 pcmcia_release_configuration(link->handle);
683 pcmcia_release_io(link->handle, &link->io);
684 pcmcia_release_irq(link->handle, &link->irq);
685
686 link->state &= ~DEV_CONFIG;
687} 658}
688 659
689static int fmvj18x_suspend(struct pcmcia_device *p_dev) 660static int fmvj18x_suspend(struct pcmcia_device *link)
690{ 661{
691 dev_link_t *link = dev_to_instance(p_dev);
692 struct net_device *dev = link->priv; 662 struct net_device *dev = link->priv;
693 663
694 link->state |= DEV_SUSPEND; 664 if (link->open)
695 if (link->state & DEV_CONFIG) { 665 netif_device_detach(dev);
696 if (link->open)
697 netif_device_detach(dev);
698 pcmcia_release_configuration(link->handle);
699 }
700
701 666
702 return 0; 667 return 0;
703} 668}
704 669
705static int fmvj18x_resume(struct pcmcia_device *p_dev) 670static int fmvj18x_resume(struct pcmcia_device *link)
706{ 671{
707 dev_link_t *link = dev_to_instance(p_dev);
708 struct net_device *dev = link->priv; 672 struct net_device *dev = link->priv;
709 673
710 link->state &= ~DEV_SUSPEND; 674 if (link->open) {
711 if (link->state & DEV_CONFIG) { 675 fjn_reset(dev);
712 pcmcia_request_configuration(link->handle, &link->conf); 676 netif_device_attach(dev);
713 if (link->open) {
714 fjn_reset(dev);
715 netif_device_attach(dev);
716 }
717 } 677 }
718 678
719 return 0; 679 return 0;
@@ -751,7 +711,7 @@ static struct pcmcia_driver fmvj18x_cs_driver = {
751 .drv = { 711 .drv = {
752 .name = "fmvj18x_cs", 712 .name = "fmvj18x_cs",
753 }, 713 },
754 .probe = fmvj18x_attach, 714 .probe = fmvj18x_probe,
755 .remove = fmvj18x_detach, 715 .remove = fmvj18x_detach,
756 .id_table = fmvj18x_ids, 716 .id_table = fmvj18x_ids,
757 .suspend = fmvj18x_suspend, 717 .suspend = fmvj18x_suspend,
@@ -1148,11 +1108,11 @@ static int fjn_config(struct net_device *dev, struct ifmap *map){
1148static int fjn_open(struct net_device *dev) 1108static int fjn_open(struct net_device *dev)
1149{ 1109{
1150 struct local_info_t *lp = netdev_priv(dev); 1110 struct local_info_t *lp = netdev_priv(dev);
1151 dev_link_t *link = &lp->link; 1111 struct pcmcia_device *link = lp->p_dev;
1152 1112
1153 DEBUG(4, "fjn_open('%s').\n", dev->name); 1113 DEBUG(4, "fjn_open('%s').\n", dev->name);
1154 1114
1155 if (!DEV_OK(link)) 1115 if (!pcmcia_dev_present(link))
1156 return -ENODEV; 1116 return -ENODEV;
1157 1117
1158 link->open++; 1118 link->open++;
@@ -1173,7 +1133,7 @@ static int fjn_open(struct net_device *dev)
1173static int fjn_close(struct net_device *dev) 1133static int fjn_close(struct net_device *dev)
1174{ 1134{
1175 struct local_info_t *lp = netdev_priv(dev); 1135 struct local_info_t *lp = netdev_priv(dev);
1176 dev_link_t *link = &lp->link; 1136 struct pcmcia_device *link = lp->p_dev;
1177 kio_addr_t ioaddr = dev->base_addr; 1137 kio_addr_t ioaddr = dev->base_addr;
1178 1138
1179 DEBUG(4, "fjn_close('%s').\n", dev->name); 1139 DEBUG(4, "fjn_close('%s').\n", dev->name);
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index b9c7e39576f5..b8fe70b85641 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -105,15 +105,15 @@ MODULE_LICENSE("GPL");
105 105
106/*====================================================================*/ 106/*====================================================================*/
107 107
108static void ibmtr_config(dev_link_t *link); 108static int ibmtr_config(struct pcmcia_device *link);
109static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase); 109static void ibmtr_hw_setup(struct net_device *dev, u_int mmiobase);
110static void ibmtr_release(dev_link_t *link); 110static void ibmtr_release(struct pcmcia_device *link);
111static void ibmtr_detach(struct pcmcia_device *p_dev); 111static void ibmtr_detach(struct pcmcia_device *p_dev);
112 112
113/*====================================================================*/ 113/*====================================================================*/
114 114
115typedef struct ibmtr_dev_t { 115typedef struct ibmtr_dev_t {
116 dev_link_t link; 116 struct pcmcia_device *p_dev;
117 struct net_device *dev; 117 struct net_device *dev;
118 dev_node_t node; 118 dev_node_t node;
119 window_handle_t sram_win_handle; 119 window_handle_t sram_win_handle;
@@ -138,12 +138,11 @@ static struct ethtool_ops netdev_ethtool_ops = {
138 138
139======================================================================*/ 139======================================================================*/
140 140
141static int ibmtr_attach(struct pcmcia_device *p_dev) 141static int ibmtr_attach(struct pcmcia_device *link)
142{ 142{
143 ibmtr_dev_t *info; 143 ibmtr_dev_t *info;
144 dev_link_t *link;
145 struct net_device *dev; 144 struct net_device *dev;
146 145
147 DEBUG(0, "ibmtr_attach()\n"); 146 DEBUG(0, "ibmtr_attach()\n");
148 147
149 /* Create new token-ring device */ 148 /* Create new token-ring device */
@@ -156,7 +155,7 @@ static int ibmtr_attach(struct pcmcia_device *p_dev)
156 return -ENOMEM; 155 return -ENOMEM;
157 } 156 }
158 157
159 link = &info->link; 158 info->p_dev = link;
160 link->priv = info; 159 link->priv = info;
161 info->ti = netdev_priv(dev); 160 info->ti = netdev_priv(dev);
162 161
@@ -167,21 +166,14 @@ static int ibmtr_attach(struct pcmcia_device *p_dev)
167 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 166 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
168 link->irq.Handler = &tok_interrupt; 167 link->irq.Handler = &tok_interrupt;
169 link->conf.Attributes = CONF_ENABLE_IRQ; 168 link->conf.Attributes = CONF_ENABLE_IRQ;
170 link->conf.Vcc = 50;
171 link->conf.IntType = INT_MEMORY_AND_IO; 169 link->conf.IntType = INT_MEMORY_AND_IO;
172 link->conf.Present = PRESENT_OPTION; 170 link->conf.Present = PRESENT_OPTION;
173 171
174 link->irq.Instance = info->dev = dev; 172 link->irq.Instance = info->dev = dev;
175
176 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
177
178 link->handle = p_dev;
179 p_dev->instance = link;
180 173
181 link->state |= DEV_PRESENT; 174 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
182 ibmtr_config(link);
183 175
184 return 0; 176 return ibmtr_config(link);
185} /* ibmtr_attach */ 177} /* ibmtr_attach */
186 178
187/*====================================================================== 179/*======================================================================
@@ -193,23 +185,22 @@ static int ibmtr_attach(struct pcmcia_device *p_dev)
193 185
194======================================================================*/ 186======================================================================*/
195 187
196static void ibmtr_detach(struct pcmcia_device *p_dev) 188static void ibmtr_detach(struct pcmcia_device *link)
197{ 189{
198 dev_link_t *link = dev_to_instance(p_dev);
199 struct ibmtr_dev_t *info = link->priv; 190 struct ibmtr_dev_t *info = link->priv;
200 struct net_device *dev = info->dev; 191 struct net_device *dev = info->dev;
201 192
202 DEBUG(0, "ibmtr_detach(0x%p)\n", link); 193 DEBUG(0, "ibmtr_detach(0x%p)\n", link);
203 194
204 if (link->dev) 195 if (link->dev_node)
205 unregister_netdev(dev); 196 unregister_netdev(dev);
206 197
207 { 198 {
208 struct tok_info *ti = netdev_priv(dev); 199 struct tok_info *ti = netdev_priv(dev);
209 del_timer_sync(&(ti->tr_timer)); 200 del_timer_sync(&(ti->tr_timer));
210 } 201 }
211 if (link->state & DEV_CONFIG) 202
212 ibmtr_release(link); 203 ibmtr_release(link);
213 204
214 free_netdev(dev); 205 free_netdev(dev);
215 kfree(info); 206 kfree(info);
@@ -226,9 +217,8 @@ static void ibmtr_detach(struct pcmcia_device *p_dev)
226#define CS_CHECK(fn, ret) \ 217#define CS_CHECK(fn, ret) \
227do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 218do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
228 219
229static void ibmtr_config(dev_link_t *link) 220static int ibmtr_config(struct pcmcia_device *link)
230{ 221{
231 client_handle_t handle = link->handle;
232 ibmtr_dev_t *info = link->priv; 222 ibmtr_dev_t *info = link->priv;
233 struct net_device *dev = info->dev; 223 struct net_device *dev = info->dev;
234 struct tok_info *ti = netdev_priv(dev); 224 struct tok_info *ti = netdev_priv(dev);
@@ -246,29 +236,25 @@ static void ibmtr_config(dev_link_t *link)
246 tuple.TupleDataMax = 64; 236 tuple.TupleDataMax = 64;
247 tuple.TupleOffset = 0; 237 tuple.TupleOffset = 0;
248 tuple.DesiredTuple = CISTPL_CONFIG; 238 tuple.DesiredTuple = CISTPL_CONFIG;
249 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 239 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
250 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 240 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
251 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 241 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
252 link->conf.ConfigBase = parse.config.base; 242 link->conf.ConfigBase = parse.config.base;
253
254 /* Configure card */
255 link->state |= DEV_CONFIG;
256
257 link->conf.ConfigIndex = 0x61; 243 link->conf.ConfigIndex = 0x61;
258 244
259 /* Determine if this is PRIMARY or ALTERNATE. */ 245 /* Determine if this is PRIMARY or ALTERNATE. */
260 246
261 /* Try PRIMARY card at 0xA20-0xA23 */ 247 /* Try PRIMARY card at 0xA20-0xA23 */
262 link->io.BasePort1 = 0xA20; 248 link->io.BasePort1 = 0xA20;
263 i = pcmcia_request_io(link->handle, &link->io); 249 i = pcmcia_request_io(link, &link->io);
264 if (i != CS_SUCCESS) { 250 if (i != CS_SUCCESS) {
265 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */ 251 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */
266 link->io.BasePort1 = 0xA24; 252 link->io.BasePort1 = 0xA24;
267 CS_CHECK(RequestIO, pcmcia_request_io(link->handle, &link->io)); 253 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
268 } 254 }
269 dev->base_addr = link->io.BasePort1; 255 dev->base_addr = link->io.BasePort1;
270 256
271 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 257 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
272 dev->irq = link->irq.AssignedIRQ; 258 dev->irq = link->irq.AssignedIRQ;
273 ti->irq = link->irq.AssignedIRQ; 259 ti->irq = link->irq.AssignedIRQ;
274 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq); 260 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq);
@@ -279,7 +265,7 @@ static void ibmtr_config(dev_link_t *link)
279 req.Base = 0; 265 req.Base = 0;
280 req.Size = 0x2000; 266 req.Size = 0x2000;
281 req.AccessSpeed = 250; 267 req.AccessSpeed = 250;
282 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 268 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
283 269
284 mem.CardOffset = mmiobase; 270 mem.CardOffset = mmiobase;
285 mem.Page = 0; 271 mem.Page = 0;
@@ -292,7 +278,7 @@ static void ibmtr_config(dev_link_t *link)
292 req.Base = 0; 278 req.Base = 0;
293 req.Size = sramsize * 1024; 279 req.Size = sramsize * 1024;
294 req.AccessSpeed = 250; 280 req.AccessSpeed = 250;
295 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &info->sram_win_handle)); 281 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &info->sram_win_handle));
296 282
297 mem.CardOffset = srambase; 283 mem.CardOffset = srambase;
298 mem.Page = 0; 284 mem.Page = 0;
@@ -302,21 +288,20 @@ static void ibmtr_config(dev_link_t *link)
302 ti->sram_virt = ioremap(req.Base, req.Size); 288 ti->sram_virt = ioremap(req.Base, req.Size);
303 ti->sram_phys = req.Base; 289 ti->sram_phys = req.Base;
304 290
305 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 291 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
306 292
307 /* Set up the Token-Ring Controller Configuration Register and 293 /* Set up the Token-Ring Controller Configuration Register and
308 turn on the card. Check the "Local Area Network Credit Card 294 turn on the card. Check the "Local Area Network Credit Card
309 Adapters Technical Reference" SC30-3585 for this info. */ 295 Adapters Technical Reference" SC30-3585 for this info. */
310 ibmtr_hw_setup(dev, mmiobase); 296 ibmtr_hw_setup(dev, mmiobase);
311 297
312 link->dev = &info->node; 298 link->dev_node = &info->node;
313 link->state &= ~DEV_CONFIG_PENDING; 299 SET_NETDEV_DEV(dev, &handle_to_dev(link));
314 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
315 300
316 i = ibmtr_probe_card(dev); 301 i = ibmtr_probe_card(dev);
317 if (i != 0) { 302 if (i != 0) {
318 printk(KERN_NOTICE "ibmtr_cs: register_netdev() failed\n"); 303 printk(KERN_NOTICE "ibmtr_cs: register_netdev() failed\n");
319 link->dev = NULL; 304 link->dev_node = NULL;
320 goto failed; 305 goto failed;
321 } 306 }
322 307
@@ -330,12 +315,13 @@ static void ibmtr_config(dev_link_t *link)
330 for (i = 0; i < TR_ALEN; i++) 315 for (i = 0; i < TR_ALEN; i++)
331 printk("%02X", dev->dev_addr[i]); 316 printk("%02X", dev->dev_addr[i]);
332 printk("\n"); 317 printk("\n");
333 return; 318 return 0;
334 319
335cs_failed: 320cs_failed:
336 cs_error(link->handle, last_fn, last_ret); 321 cs_error(link, last_fn, last_ret);
337failed: 322failed:
338 ibmtr_release(link); 323 ibmtr_release(link);
324 return -ENODEV;
339} /* ibmtr_config */ 325} /* ibmtr_config */
340 326
341/*====================================================================== 327/*======================================================================
@@ -346,56 +332,41 @@ failed:
346 332
347======================================================================*/ 333======================================================================*/
348 334
349static void ibmtr_release(dev_link_t *link) 335static void ibmtr_release(struct pcmcia_device *link)
350{ 336{
351 ibmtr_dev_t *info = link->priv; 337 ibmtr_dev_t *info = link->priv;
352 struct net_device *dev = info->dev; 338 struct net_device *dev = info->dev;
353
354 DEBUG(0, "ibmtr_release(0x%p)\n", link);
355 339
356 pcmcia_release_configuration(link->handle); 340 DEBUG(0, "ibmtr_release(0x%p)\n", link);
357 pcmcia_release_io(link->handle, &link->io);
358 pcmcia_release_irq(link->handle, &link->irq);
359 if (link->win) {
360 struct tok_info *ti = netdev_priv(dev);
361 iounmap(ti->mmio);
362 pcmcia_release_window(link->win);
363 pcmcia_release_window(info->sram_win_handle);
364 }
365 341
366 link->state &= ~DEV_CONFIG; 342 if (link->win) {
343 struct tok_info *ti = netdev_priv(dev);
344 iounmap(ti->mmio);
345 pcmcia_release_window(info->sram_win_handle);
346 }
347 pcmcia_disable_device(link);
367} 348}
368 349
369static int ibmtr_suspend(struct pcmcia_device *p_dev) 350static int ibmtr_suspend(struct pcmcia_device *link)
370{ 351{
371 dev_link_t *link = dev_to_instance(p_dev);
372 ibmtr_dev_t *info = link->priv; 352 ibmtr_dev_t *info = link->priv;
373 struct net_device *dev = info->dev; 353 struct net_device *dev = info->dev;
374 354
375 link->state |= DEV_SUSPEND; 355 if (link->open)
376 if (link->state & DEV_CONFIG) { 356 netif_device_detach(dev);
377 if (link->open)
378 netif_device_detach(dev);
379 pcmcia_release_configuration(link->handle);
380 }
381 357
382 return 0; 358 return 0;
383} 359}
384 360
385static int ibmtr_resume(struct pcmcia_device *p_dev) 361static int ibmtr_resume(struct pcmcia_device *link)
386{ 362{
387 dev_link_t *link = dev_to_instance(p_dev);
388 ibmtr_dev_t *info = link->priv; 363 ibmtr_dev_t *info = link->priv;
389 struct net_device *dev = info->dev; 364 struct net_device *dev = info->dev;
390 365
391 link->state &= ~DEV_SUSPEND; 366 if (link->open) {
392 if (link->state & DEV_CONFIG) { 367 ibmtr_probe(dev); /* really? */
393 pcmcia_request_configuration(link->handle, &link->conf); 368 netif_device_attach(dev);
394 if (link->open) { 369 }
395 ibmtr_probe(dev); /* really? */
396 netif_device_attach(dev);
397 }
398 }
399 370
400 return 0; 371 return 0;
401} 372}
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 787176c57fd9..4260c2128f47 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -362,7 +362,7 @@ typedef struct _mace_statistics {
362} mace_statistics; 362} mace_statistics;
363 363
364typedef struct _mace_private { 364typedef struct _mace_private {
365 dev_link_t link; 365 struct pcmcia_device *p_dev;
366 dev_node_t node; 366 dev_node_t node;
367 struct net_device_stats linux_stats; /* Linux statistics counters */ 367 struct net_device_stats linux_stats; /* Linux statistics counters */
368 mace_statistics mace_stats; /* MACE chip statistics counters */ 368 mace_statistics mace_stats; /* MACE chip statistics counters */
@@ -417,8 +417,8 @@ INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG);
417Function Prototypes 417Function Prototypes
418---------------------------------------------------------------------------- */ 418---------------------------------------------------------------------------- */
419 419
420static void nmclan_config(dev_link_t *link); 420static int nmclan_config(struct pcmcia_device *link);
421static void nmclan_release(dev_link_t *link); 421static void nmclan_release(struct pcmcia_device *link);
422 422
423static void nmclan_reset(struct net_device *dev); 423static void nmclan_reset(struct net_device *dev);
424static int mace_config(struct net_device *dev, struct ifmap *map); 424static int mace_config(struct net_device *dev, struct ifmap *map);
@@ -443,10 +443,9 @@ nmclan_attach
443 Services. 443 Services.
444---------------------------------------------------------------------------- */ 444---------------------------------------------------------------------------- */
445 445
446static int nmclan_attach(struct pcmcia_device *p_dev) 446static int nmclan_probe(struct pcmcia_device *link)
447{ 447{
448 mace_private *lp; 448 mace_private *lp;
449 dev_link_t *link;
450 struct net_device *dev; 449 struct net_device *dev;
451 450
452 DEBUG(0, "nmclan_attach()\n"); 451 DEBUG(0, "nmclan_attach()\n");
@@ -457,7 +456,7 @@ static int nmclan_attach(struct pcmcia_device *p_dev)
457 if (!dev) 456 if (!dev)
458 return -ENOMEM; 457 return -ENOMEM;
459 lp = netdev_priv(dev); 458 lp = netdev_priv(dev);
460 link = &lp->link; 459 lp->p_dev = link;
461 link->priv = dev; 460 link->priv = dev;
462 461
463 spin_lock_init(&lp->bank_lock); 462 spin_lock_init(&lp->bank_lock);
@@ -469,7 +468,6 @@ static int nmclan_attach(struct pcmcia_device *p_dev)
469 link->irq.Handler = &mace_interrupt; 468 link->irq.Handler = &mace_interrupt;
470 link->irq.Instance = dev; 469 link->irq.Instance = dev;
471 link->conf.Attributes = CONF_ENABLE_IRQ; 470 link->conf.Attributes = CONF_ENABLE_IRQ;
472 link->conf.Vcc = 50;
473 link->conf.IntType = INT_MEMORY_AND_IO; 471 link->conf.IntType = INT_MEMORY_AND_IO;
474 link->conf.ConfigIndex = 1; 472 link->conf.ConfigIndex = 1;
475 link->conf.Present = PRESENT_OPTION; 473 link->conf.Present = PRESENT_OPTION;
@@ -489,13 +487,7 @@ static int nmclan_attach(struct pcmcia_device *p_dev)
489 dev->watchdog_timeo = TX_TIMEOUT; 487 dev->watchdog_timeo = TX_TIMEOUT;
490#endif 488#endif
491 489
492 link->handle = p_dev; 490 return nmclan_config(link);
493 p_dev->instance = link;
494
495 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
496 nmclan_config(link);
497
498 return 0;
499} /* nmclan_attach */ 491} /* nmclan_attach */
500 492
501/* ---------------------------------------------------------------------------- 493/* ----------------------------------------------------------------------------
@@ -506,18 +498,16 @@ nmclan_detach
506 when the device is released. 498 when the device is released.
507---------------------------------------------------------------------------- */ 499---------------------------------------------------------------------------- */
508 500
509static void nmclan_detach(struct pcmcia_device *p_dev) 501static void nmclan_detach(struct pcmcia_device *link)
510{ 502{
511 dev_link_t *link = dev_to_instance(p_dev);
512 struct net_device *dev = link->priv; 503 struct net_device *dev = link->priv;
513 504
514 DEBUG(0, "nmclan_detach(0x%p)\n", link); 505 DEBUG(0, "nmclan_detach(0x%p)\n", link);
515 506
516 if (link->dev) 507 if (link->dev_node)
517 unregister_netdev(dev); 508 unregister_netdev(dev);
518 509
519 if (link->state & DEV_CONFIG) 510 nmclan_release(link);
520 nmclan_release(link);
521 511
522 free_netdev(dev); 512 free_netdev(dev);
523} /* nmclan_detach */ 513} /* nmclan_detach */
@@ -661,9 +651,8 @@ nmclan_config
661#define CS_CHECK(fn, ret) \ 651#define CS_CHECK(fn, ret) \
662 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 652 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
663 653
664static void nmclan_config(dev_link_t *link) 654static int nmclan_config(struct pcmcia_device *link)
665{ 655{
666 client_handle_t handle = link->handle;
667 struct net_device *dev = link->priv; 656 struct net_device *dev = link->priv;
668 mace_private *lp = netdev_priv(dev); 657 mace_private *lp = netdev_priv(dev);
669 tuple_t tuple; 658 tuple_t tuple;
@@ -679,17 +668,14 @@ static void nmclan_config(dev_link_t *link)
679 tuple.TupleDataMax = 64; 668 tuple.TupleDataMax = 64;
680 tuple.TupleOffset = 0; 669 tuple.TupleOffset = 0;
681 tuple.DesiredTuple = CISTPL_CONFIG; 670 tuple.DesiredTuple = CISTPL_CONFIG;
682 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 671 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
683 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 672 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
684 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 673 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
685 link->conf.ConfigBase = parse.config.base; 674 link->conf.ConfigBase = parse.config.base;
686 675
687 /* Configure card */ 676 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
688 link->state |= DEV_CONFIG; 677 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
689 678 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
690 CS_CHECK(RequestIO, pcmcia_request_io(handle, &link->io));
691 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
692 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
693 dev->irq = link->irq.AssignedIRQ; 679 dev->irq = link->irq.AssignedIRQ;
694 dev->base_addr = link->io.BasePort1; 680 dev->base_addr = link->io.BasePort1;
695 681
@@ -700,8 +686,8 @@ static void nmclan_config(dev_link_t *link)
700 tuple.TupleData = buf; 686 tuple.TupleData = buf;
701 tuple.TupleDataMax = 64; 687 tuple.TupleDataMax = 64;
702 tuple.TupleOffset = 0; 688 tuple.TupleOffset = 0;
703 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 689 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
704 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 690 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
705 memcpy(dev->dev_addr, tuple.TupleData, ETHER_ADDR_LEN); 691 memcpy(dev->dev_addr, tuple.TupleData, ETHER_ADDR_LEN);
706 692
707 /* Verify configuration by reading the MACE ID. */ 693 /* Verify configuration by reading the MACE ID. */
@@ -716,8 +702,7 @@ static void nmclan_config(dev_link_t *link)
716 } else { 702 } else {
717 printk(KERN_NOTICE "nmclan_cs: mace id not found: %x %x should" 703 printk(KERN_NOTICE "nmclan_cs: mace id not found: %x %x should"
718 " be 0x40 0x?9\n", sig[0], sig[1]); 704 " be 0x40 0x?9\n", sig[0], sig[1]);
719 link->state &= ~DEV_CONFIG_PENDING; 705 return -ENODEV;
720 return;
721 } 706 }
722 } 707 }
723 708
@@ -730,14 +715,13 @@ static void nmclan_config(dev_link_t *link)
730 else 715 else
731 printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n"); 716 printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n");
732 717
733 link->dev = &lp->node; 718 link->dev_node = &lp->node;
734 link->state &= ~DEV_CONFIG_PENDING; 719 SET_NETDEV_DEV(dev, &handle_to_dev(link));
735 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
736 720
737 i = register_netdev(dev); 721 i = register_netdev(dev);
738 if (i != 0) { 722 if (i != 0) {
739 printk(KERN_NOTICE "nmclan_cs: register_netdev() failed\n"); 723 printk(KERN_NOTICE "nmclan_cs: register_netdev() failed\n");
740 link->dev = NULL; 724 link->dev_node = NULL;
741 goto failed; 725 goto failed;
742 } 726 }
743 727
@@ -747,14 +731,13 @@ static void nmclan_config(dev_link_t *link)
747 dev->name, dev->base_addr, dev->irq, if_names[dev->if_port]); 731 dev->name, dev->base_addr, dev->irq, if_names[dev->if_port]);
748 for (i = 0; i < 6; i++) 732 for (i = 0; i < 6; i++)
749 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 733 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
750 return; 734 return 0;
751 735
752cs_failed: 736cs_failed:
753 cs_error(link->handle, last_fn, last_ret); 737 cs_error(link, last_fn, last_ret);
754failed: 738failed:
755 nmclan_release(link); 739 nmclan_release(link);
756 return; 740 return -ENODEV;
757
758} /* nmclan_config */ 741} /* nmclan_config */
759 742
760/* ---------------------------------------------------------------------------- 743/* ----------------------------------------------------------------------------
@@ -763,46 +746,29 @@ nmclan_release
763 net device, and release the PCMCIA configuration. If the device 746 net device, and release the PCMCIA configuration. If the device
764 is still open, this will be postponed until it is closed. 747 is still open, this will be postponed until it is closed.
765---------------------------------------------------------------------------- */ 748---------------------------------------------------------------------------- */
766static void nmclan_release(dev_link_t *link) 749static void nmclan_release(struct pcmcia_device *link)
767{ 750{
768 751 DEBUG(0, "nmclan_release(0x%p)\n", link);
769 DEBUG(0, "nmclan_release(0x%p)\n", link); 752 pcmcia_disable_device(link);
770
771 pcmcia_release_configuration(link->handle);
772 pcmcia_release_io(link->handle, &link->io);
773 pcmcia_release_irq(link->handle, &link->irq);
774
775 link->state &= ~DEV_CONFIG;
776} 753}
777 754
778static int nmclan_suspend(struct pcmcia_device *p_dev) 755static int nmclan_suspend(struct pcmcia_device *link)
779{ 756{
780 dev_link_t *link = dev_to_instance(p_dev);
781 struct net_device *dev = link->priv; 757 struct net_device *dev = link->priv;
782 758
783 link->state |= DEV_SUSPEND; 759 if (link->open)
784 if (link->state & DEV_CONFIG) { 760 netif_device_detach(dev);
785 if (link->open)
786 netif_device_detach(dev);
787 pcmcia_release_configuration(link->handle);
788 }
789
790 761
791 return 0; 762 return 0;
792} 763}
793 764
794static int nmclan_resume(struct pcmcia_device *p_dev) 765static int nmclan_resume(struct pcmcia_device *link)
795{ 766{
796 dev_link_t *link = dev_to_instance(p_dev);
797 struct net_device *dev = link->priv; 767 struct net_device *dev = link->priv;
798 768
799 link->state &= ~DEV_SUSPEND; 769 if (link->open) {
800 if (link->state & DEV_CONFIG) { 770 nmclan_reset(dev);
801 pcmcia_request_configuration(link->handle, &link->conf); 771 netif_device_attach(dev);
802 if (link->open) {
803 nmclan_reset(dev);
804 netif_device_attach(dev);
805 }
806 } 772 }
807 773
808 return 0; 774 return 0;
@@ -818,7 +784,7 @@ static void nmclan_reset(struct net_device *dev)
818 mace_private *lp = netdev_priv(dev); 784 mace_private *lp = netdev_priv(dev);
819 785
820#if RESET_XILINX 786#if RESET_XILINX
821 dev_link_t *link = &lp->link; 787 struct pcmcia_device *link = &lp->link;
822 conf_reg_t reg; 788 conf_reg_t reg;
823 u_long OrigCorValue; 789 u_long OrigCorValue;
824 790
@@ -827,7 +793,7 @@ static void nmclan_reset(struct net_device *dev)
827 reg.Action = CS_READ; 793 reg.Action = CS_READ;
828 reg.Offset = CISREG_COR; 794 reg.Offset = CISREG_COR;
829 reg.Value = 0; 795 reg.Value = 0;
830 pcmcia_access_configuration_register(link->handle, &reg); 796 pcmcia_access_configuration_register(link, &reg);
831 OrigCorValue = reg.Value; 797 OrigCorValue = reg.Value;
832 798
833 /* Reset Xilinx */ 799 /* Reset Xilinx */
@@ -836,12 +802,12 @@ static void nmclan_reset(struct net_device *dev)
836 DEBUG(1, "nmclan_reset: OrigCorValue=0x%lX, resetting...\n", 802 DEBUG(1, "nmclan_reset: OrigCorValue=0x%lX, resetting...\n",
837 OrigCorValue); 803 OrigCorValue);
838 reg.Value = COR_SOFT_RESET; 804 reg.Value = COR_SOFT_RESET;
839 pcmcia_access_configuration_register(link->handle, &reg); 805 pcmcia_access_configuration_register(link, &reg);
840 /* Need to wait for 20 ms for PCMCIA to finish reset. */ 806 /* Need to wait for 20 ms for PCMCIA to finish reset. */
841 807
842 /* Restore original COR configuration index */ 808 /* Restore original COR configuration index */
843 reg.Value = COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK); 809 reg.Value = COR_LEVEL_REQ | (OrigCorValue & COR_CONFIG_MASK);
844 pcmcia_access_configuration_register(link->handle, &reg); 810 pcmcia_access_configuration_register(link, &reg);
845 /* Xilinx is now completely reset along with the MACE chip. */ 811 /* Xilinx is now completely reset along with the MACE chip. */
846 lp->tx_free_frames=AM2150_MAX_TX_FRAMES; 812 lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
847 813
@@ -885,9 +851,9 @@ static int mace_open(struct net_device *dev)
885{ 851{
886 kio_addr_t ioaddr = dev->base_addr; 852 kio_addr_t ioaddr = dev->base_addr;
887 mace_private *lp = netdev_priv(dev); 853 mace_private *lp = netdev_priv(dev);
888 dev_link_t *link = &lp->link; 854 struct pcmcia_device *link = lp->p_dev;
889 855
890 if (!DEV_OK(link)) 856 if (!pcmcia_dev_present(link))
891 return -ENODEV; 857 return -ENODEV;
892 858
893 link->open++; 859 link->open++;
@@ -908,7 +874,7 @@ static int mace_close(struct net_device *dev)
908{ 874{
909 kio_addr_t ioaddr = dev->base_addr; 875 kio_addr_t ioaddr = dev->base_addr;
910 mace_private *lp = netdev_priv(dev); 876 mace_private *lp = netdev_priv(dev);
911 dev_link_t *link = &lp->link; 877 struct pcmcia_device *link = lp->p_dev;
912 878
913 DEBUG(2, "%s: shutting down ethercard.\n", dev->name); 879 DEBUG(2, "%s: shutting down ethercard.\n", dev->name);
914 880
@@ -963,12 +929,12 @@ mace_start_xmit
963static void mace_tx_timeout(struct net_device *dev) 929static void mace_tx_timeout(struct net_device *dev)
964{ 930{
965 mace_private *lp = netdev_priv(dev); 931 mace_private *lp = netdev_priv(dev);
966 dev_link_t *link = &lp->link; 932 struct pcmcia_device *link = lp->p_dev;
967 933
968 printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name); 934 printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name);
969#if RESET_ON_TIMEOUT 935#if RESET_ON_TIMEOUT
970 printk("resetting card\n"); 936 printk("resetting card\n");
971 pcmcia_reset_card(link->handle, NULL); 937 pcmcia_reset_card(link, NULL);
972#else /* #if RESET_ON_TIMEOUT */ 938#else /* #if RESET_ON_TIMEOUT */
973 printk("NOT resetting card\n"); 939 printk("NOT resetting card\n");
974#endif /* #if RESET_ON_TIMEOUT */ 940#endif /* #if RESET_ON_TIMEOUT */
@@ -1635,7 +1601,7 @@ static struct pcmcia_driver nmclan_cs_driver = {
1635 .drv = { 1601 .drv = {
1636 .name = "nmclan_cs", 1602 .name = "nmclan_cs",
1637 }, 1603 },
1638 .probe = nmclan_attach, 1604 .probe = nmclan_probe,
1639 .remove = nmclan_detach, 1605 .remove = nmclan_detach,
1640 .id_table = nmclan_ids, 1606 .id_table = nmclan_ids,
1641 .suspend = nmclan_suspend, 1607 .suspend = nmclan_suspend,
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index b46e5f703efa..506e777c5f06 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -103,8 +103,8 @@ module_param_array(hw_addr, int, NULL, 0);
103/*====================================================================*/ 103/*====================================================================*/
104 104
105static void mii_phy_probe(struct net_device *dev); 105static void mii_phy_probe(struct net_device *dev);
106static void pcnet_config(dev_link_t *link); 106static int pcnet_config(struct pcmcia_device *link);
107static void pcnet_release(dev_link_t *link); 107static void pcnet_release(struct pcmcia_device *link);
108static int pcnet_open(struct net_device *dev); 108static int pcnet_open(struct net_device *dev);
109static int pcnet_close(struct net_device *dev); 109static int pcnet_close(struct net_device *dev);
110static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 110static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -113,9 +113,9 @@ static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs);
113static void ei_watchdog(u_long arg); 113static void ei_watchdog(u_long arg);
114static void pcnet_reset_8390(struct net_device *dev); 114static void pcnet_reset_8390(struct net_device *dev);
115static int set_config(struct net_device *dev, struct ifmap *map); 115static int set_config(struct net_device *dev, struct ifmap *map);
116static int setup_shmem_window(dev_link_t *link, int start_pg, 116static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
117 int stop_pg, int cm_offset); 117 int stop_pg, int cm_offset);
118static int setup_dma_config(dev_link_t *link, int start_pg, 118static int setup_dma_config(struct pcmcia_device *link, int start_pg,
119 int stop_pg); 119 int stop_pg);
120 120
121static void pcnet_detach(struct pcmcia_device *p_dev); 121static void pcnet_detach(struct pcmcia_device *p_dev);
@@ -214,7 +214,7 @@ static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };
214static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII }; 214static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
215 215
216typedef struct pcnet_dev_t { 216typedef struct pcnet_dev_t {
217 dev_link_t link; 217 struct pcmcia_device *p_dev;
218 dev_node_t node; 218 dev_node_t node;
219 u_int flags; 219 u_int flags;
220 void __iomem *base; 220 void __iomem *base;
@@ -240,10 +240,9 @@ static inline pcnet_dev_t *PRIV(struct net_device *dev)
240 240
241======================================================================*/ 241======================================================================*/
242 242
243static int pcnet_probe(struct pcmcia_device *p_dev) 243static int pcnet_probe(struct pcmcia_device *link)
244{ 244{
245 pcnet_dev_t *info; 245 pcnet_dev_t *info;
246 dev_link_t *link;
247 struct net_device *dev; 246 struct net_device *dev;
248 247
249 DEBUG(0, "pcnet_attach()\n"); 248 DEBUG(0, "pcnet_attach()\n");
@@ -252,7 +251,7 @@ static int pcnet_probe(struct pcmcia_device *p_dev)
252 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t)); 251 dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
253 if (!dev) return -ENOMEM; 252 if (!dev) return -ENOMEM;
254 info = PRIV(dev); 253 info = PRIV(dev);
255 link = &info->link; 254 info->p_dev = link;
256 link->priv = dev; 255 link->priv = dev;
257 256
258 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 257 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
@@ -265,13 +264,7 @@ static int pcnet_probe(struct pcmcia_device *p_dev)
265 dev->stop = &pcnet_close; 264 dev->stop = &pcnet_close;
266 dev->set_config = &set_config; 265 dev->set_config = &set_config;
267 266
268 link->handle = p_dev; 267 return pcnet_config(link);
269 p_dev->instance = link;
270
271 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
272 pcnet_config(link);
273
274 return 0;
275} /* pcnet_attach */ 268} /* pcnet_attach */
276 269
277/*====================================================================== 270/*======================================================================
@@ -283,18 +276,16 @@ static int pcnet_probe(struct pcmcia_device *p_dev)
283 276
284======================================================================*/ 277======================================================================*/
285 278
286static void pcnet_detach(struct pcmcia_device *p_dev) 279static void pcnet_detach(struct pcmcia_device *link)
287{ 280{
288 dev_link_t *link = dev_to_instance(p_dev);
289 struct net_device *dev = link->priv; 281 struct net_device *dev = link->priv;
290 282
291 DEBUG(0, "pcnet_detach(0x%p)\n", link); 283 DEBUG(0, "pcnet_detach(0x%p)\n", link);
292 284
293 if (link->dev) 285 if (link->dev_node)
294 unregister_netdev(dev); 286 unregister_netdev(dev);
295 287
296 if (link->state & DEV_CONFIG) 288 pcnet_release(link);
297 pcnet_release(link);
298 289
299 free_netdev(dev); 290 free_netdev(dev);
300} /* pcnet_detach */ 291} /* pcnet_detach */
@@ -306,7 +297,7 @@ static void pcnet_detach(struct pcmcia_device *p_dev)
306 297
307======================================================================*/ 298======================================================================*/
308 299
309static hw_info_t *get_hwinfo(dev_link_t *link) 300static hw_info_t *get_hwinfo(struct pcmcia_device *link)
310{ 301{
311 struct net_device *dev = link->priv; 302 struct net_device *dev = link->priv;
312 win_req_t req; 303 win_req_t req;
@@ -318,9 +309,9 @@ static hw_info_t *get_hwinfo(dev_link_t *link)
318 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 309 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
319 req.Base = 0; req.Size = 0; 310 req.Base = 0; req.Size = 0;
320 req.AccessSpeed = 0; 311 req.AccessSpeed = 0;
321 i = pcmcia_request_window(&link->handle, &req, &link->win); 312 i = pcmcia_request_window(&link, &req, &link->win);
322 if (i != CS_SUCCESS) { 313 if (i != CS_SUCCESS) {
323 cs_error(link->handle, RequestWindow, i); 314 cs_error(link, RequestWindow, i);
324 return NULL; 315 return NULL;
325 } 316 }
326 317
@@ -343,7 +334,7 @@ static hw_info_t *get_hwinfo(dev_link_t *link)
343 iounmap(virt); 334 iounmap(virt);
344 j = pcmcia_release_window(link->win); 335 j = pcmcia_release_window(link->win);
345 if (j != CS_SUCCESS) 336 if (j != CS_SUCCESS)
346 cs_error(link->handle, ReleaseWindow, j); 337 cs_error(link, ReleaseWindow, j);
347 return (i < NR_INFO) ? hw_info+i : NULL; 338 return (i < NR_INFO) ? hw_info+i : NULL;
348} /* get_hwinfo */ 339} /* get_hwinfo */
349 340
@@ -355,7 +346,7 @@ static hw_info_t *get_hwinfo(dev_link_t *link)
355 346
356======================================================================*/ 347======================================================================*/
357 348
358static hw_info_t *get_prom(dev_link_t *link) 349static hw_info_t *get_prom(struct pcmcia_device *link)
359{ 350{
360 struct net_device *dev = link->priv; 351 struct net_device *dev = link->priv;
361 kio_addr_t ioaddr = dev->base_addr; 352 kio_addr_t ioaddr = dev->base_addr;
@@ -409,7 +400,7 @@ static hw_info_t *get_prom(dev_link_t *link)
409 400
410======================================================================*/ 401======================================================================*/
411 402
412static hw_info_t *get_dl10019(dev_link_t *link) 403static hw_info_t *get_dl10019(struct pcmcia_device *link)
413{ 404{
414 struct net_device *dev = link->priv; 405 struct net_device *dev = link->priv;
415 int i; 406 int i;
@@ -431,7 +422,7 @@ static hw_info_t *get_dl10019(dev_link_t *link)
431 422
432======================================================================*/ 423======================================================================*/
433 424
434static hw_info_t *get_ax88190(dev_link_t *link) 425static hw_info_t *get_ax88190(struct pcmcia_device *link)
435{ 426{
436 struct net_device *dev = link->priv; 427 struct net_device *dev = link->priv;
437 kio_addr_t ioaddr = dev->base_addr; 428 kio_addr_t ioaddr = dev->base_addr;
@@ -464,7 +455,7 @@ static hw_info_t *get_ax88190(dev_link_t *link)
464 455
465======================================================================*/ 456======================================================================*/
466 457
467static hw_info_t *get_hwired(dev_link_t *link) 458static hw_info_t *get_hwired(struct pcmcia_device *link)
468{ 459{
469 struct net_device *dev = link->priv; 460 struct net_device *dev = link->priv;
470 int i; 461 int i;
@@ -491,7 +482,7 @@ static hw_info_t *get_hwired(dev_link_t *link)
491#define CS_CHECK(fn, ret) \ 482#define CS_CHECK(fn, ret) \
492do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 483do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
493 484
494static int try_io_port(dev_link_t *link) 485static int try_io_port(struct pcmcia_device *link)
495{ 486{
496 int j, ret; 487 int j, ret;
497 if (link->io.NumPorts1 == 32) { 488 if (link->io.NumPorts1 == 32) {
@@ -512,18 +503,17 @@ static int try_io_port(dev_link_t *link)
512 for (j = 0; j < 0x400; j += 0x20) { 503 for (j = 0; j < 0x400; j += 0x20) {
513 link->io.BasePort1 = j ^ 0x300; 504 link->io.BasePort1 = j ^ 0x300;
514 link->io.BasePort2 = (j ^ 0x300) + 0x10; 505 link->io.BasePort2 = (j ^ 0x300) + 0x10;
515 ret = pcmcia_request_io(link->handle, &link->io); 506 ret = pcmcia_request_io(link, &link->io);
516 if (ret == CS_SUCCESS) return ret; 507 if (ret == CS_SUCCESS) return ret;
517 } 508 }
518 return ret; 509 return ret;
519 } else { 510 } else {
520 return pcmcia_request_io(link->handle, &link->io); 511 return pcmcia_request_io(link, &link->io);
521 } 512 }
522} 513}
523 514
524static void pcnet_config(dev_link_t *link) 515static int pcnet_config(struct pcmcia_device *link)
525{ 516{
526 client_handle_t handle = link->handle;
527 struct net_device *dev = link->priv; 517 struct net_device *dev = link->priv;
528 pcnet_dev_t *info = PRIV(dev); 518 pcnet_dev_t *info = PRIV(dev);
529 tuple_t tuple; 519 tuple_t tuple;
@@ -531,7 +521,6 @@ static void pcnet_config(dev_link_t *link)
531 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset; 521 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
532 int manfid = 0, prodid = 0, has_shmem = 0; 522 int manfid = 0, prodid = 0, has_shmem = 0;
533 u_short buf[64]; 523 u_short buf[64];
534 config_info_t conf;
535 hw_info_t *hw_info; 524 hw_info_t *hw_info;
536 525
537 DEBUG(0, "pcnet_config(0x%p)\n", link); 526 DEBUG(0, "pcnet_config(0x%p)\n", link);
@@ -541,36 +530,29 @@ static void pcnet_config(dev_link_t *link)
541 tuple.TupleDataMax = sizeof(buf); 530 tuple.TupleDataMax = sizeof(buf);
542 tuple.TupleOffset = 0; 531 tuple.TupleOffset = 0;
543 tuple.DesiredTuple = CISTPL_CONFIG; 532 tuple.DesiredTuple = CISTPL_CONFIG;
544 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 533 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
545 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 534 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
546 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 535 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
547 link->conf.ConfigBase = parse.config.base; 536 link->conf.ConfigBase = parse.config.base;
548 link->conf.Present = parse.config.rmask[0]; 537 link->conf.Present = parse.config.rmask[0];
549 538
550 /* Configure card */
551 link->state |= DEV_CONFIG;
552
553 /* Look up current Vcc */
554 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
555 link->conf.Vcc = conf.Vcc;
556
557 tuple.DesiredTuple = CISTPL_MANFID; 539 tuple.DesiredTuple = CISTPL_MANFID;
558 tuple.Attributes = TUPLE_RETURN_COMMON; 540 tuple.Attributes = TUPLE_RETURN_COMMON;
559 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 541 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
560 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) { 542 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS)) {
561 manfid = le16_to_cpu(buf[0]); 543 manfid = le16_to_cpu(buf[0]);
562 prodid = le16_to_cpu(buf[1]); 544 prodid = le16_to_cpu(buf[1]);
563 } 545 }
564 546
565 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 547 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
566 tuple.Attributes = 0; 548 tuple.Attributes = 0;
567 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 549 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
568 while (last_ret == CS_SUCCESS) { 550 while (last_ret == CS_SUCCESS) {
569 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 551 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
570 cistpl_io_t *io = &(parse.cftable_entry.io); 552 cistpl_io_t *io = &(parse.cftable_entry.io);
571 553
572 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 554 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
573 pcmcia_parse_tuple(handle, &tuple, &parse) != 0 || 555 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
574 cfg->index == 0 || cfg->io.nwin == 0) 556 cfg->index == 0 || cfg->io.nwin == 0)
575 goto next_entry; 557 goto next_entry;
576 558
@@ -594,14 +576,14 @@ static void pcnet_config(dev_link_t *link)
594 if (last_ret == CS_SUCCESS) break; 576 if (last_ret == CS_SUCCESS) break;
595 } 577 }
596 next_entry: 578 next_entry:
597 last_ret = pcmcia_get_next_tuple(handle, &tuple); 579 last_ret = pcmcia_get_next_tuple(link, &tuple);
598 } 580 }
599 if (last_ret != CS_SUCCESS) { 581 if (last_ret != CS_SUCCESS) {
600 cs_error(handle, RequestIO, last_ret); 582 cs_error(link, RequestIO, last_ret);
601 goto failed; 583 goto failed;
602 } 584 }
603 585
604 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 586 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
605 587
606 if (link->io.NumPorts2 == 8) { 588 if (link->io.NumPorts2 == 8) {
607 link->conf.Attributes |= CONF_ENABLE_SPKR; 589 link->conf.Attributes |= CONF_ENABLE_SPKR;
@@ -611,7 +593,7 @@ static void pcnet_config(dev_link_t *link)
611 (prodid == PRODID_IBM_HOME_AND_AWAY)) 593 (prodid == PRODID_IBM_HOME_AND_AWAY))
612 link->conf.ConfigIndex |= 0x10; 594 link->conf.ConfigIndex |= 0x10;
613 595
614 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 596 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
615 dev->irq = link->irq.AssignedIRQ; 597 dev->irq = link->irq.AssignedIRQ;
616 dev->base_addr = link->io.BasePort1; 598 dev->base_addr = link->io.BasePort1;
617 if (info->flags & HAS_MISC_REG) { 599 if (info->flags & HAS_MISC_REG) {
@@ -679,9 +661,8 @@ static void pcnet_config(dev_link_t *link)
679 info->eth_phy = 0; 661 info->eth_phy = 0;
680 } 662 }
681 663
682 link->dev = &info->node; 664 link->dev_node = &info->node;
683 link->state &= ~DEV_CONFIG_PENDING; 665 SET_NETDEV_DEV(dev, &handle_to_dev(link));
684 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
685 666
686#ifdef CONFIG_NET_POLL_CONTROLLER 667#ifdef CONFIG_NET_POLL_CONTROLLER
687 dev->poll_controller = ei_poll; 668 dev->poll_controller = ei_poll;
@@ -689,7 +670,7 @@ static void pcnet_config(dev_link_t *link)
689 670
690 if (register_netdev(dev) != 0) { 671 if (register_netdev(dev) != 0) {
691 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n"); 672 printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");
692 link->dev = NULL; 673 link->dev_node = NULL;
693 goto failed; 674 goto failed;
694 } 675 }
695 676
@@ -712,14 +693,13 @@ static void pcnet_config(dev_link_t *link)
712 printk(" hw_addr "); 693 printk(" hw_addr ");
713 for (i = 0; i < 6; i++) 694 for (i = 0; i < 6; i++)
714 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 695 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
715 return; 696 return 0;
716 697
717cs_failed: 698cs_failed:
718 cs_error(link->handle, last_fn, last_ret); 699 cs_error(link, last_fn, last_ret);
719failed: 700failed:
720 pcnet_release(link); 701 pcnet_release(link);
721 link->state &= ~DEV_CONFIG_PENDING; 702 return -ENODEV;
722 return;
723} /* pcnet_config */ 703} /* pcnet_config */
724 704
725/*====================================================================== 705/*======================================================================
@@ -730,21 +710,16 @@ failed:
730 710
731======================================================================*/ 711======================================================================*/
732 712
733static void pcnet_release(dev_link_t *link) 713static void pcnet_release(struct pcmcia_device *link)
734{ 714{
735 pcnet_dev_t *info = PRIV(link->priv); 715 pcnet_dev_t *info = PRIV(link->priv);
736 716
737 DEBUG(0, "pcnet_release(0x%p)\n", link); 717 DEBUG(0, "pcnet_release(0x%p)\n", link);
738 718
739 if (info->flags & USE_SHMEM) { 719 if (info->flags & USE_SHMEM)
740 iounmap(info->base); 720 iounmap(info->base);
741 pcmcia_release_window(link->win);
742 }
743 pcmcia_release_configuration(link->handle);
744 pcmcia_release_io(link->handle, &link->io);
745 pcmcia_release_irq(link->handle, &link->irq);
746 721
747 link->state &= ~DEV_CONFIG; 722 pcmcia_disable_device(link);
748} 723}
749 724
750/*====================================================================== 725/*======================================================================
@@ -756,34 +731,24 @@ static void pcnet_release(dev_link_t *link)
756 731
757======================================================================*/ 732======================================================================*/
758 733
759static int pcnet_suspend(struct pcmcia_device *p_dev) 734static int pcnet_suspend(struct pcmcia_device *link)
760{ 735{
761 dev_link_t *link = dev_to_instance(p_dev);
762 struct net_device *dev = link->priv; 736 struct net_device *dev = link->priv;
763 737
764 link->state |= DEV_SUSPEND; 738 if (link->open)
765 if (link->state & DEV_CONFIG) { 739 netif_device_detach(dev);
766 if (link->open)
767 netif_device_detach(dev);
768 pcmcia_release_configuration(link->handle);
769 }
770 740
771 return 0; 741 return 0;
772} 742}
773 743
774static int pcnet_resume(struct pcmcia_device *p_dev) 744static int pcnet_resume(struct pcmcia_device *link)
775{ 745{
776 dev_link_t *link = dev_to_instance(p_dev);
777 struct net_device *dev = link->priv; 746 struct net_device *dev = link->priv;
778 747
779 link->state &= ~DEV_SUSPEND; 748 if (link->open) {
780 if (link->state & DEV_CONFIG) { 749 pcnet_reset_8390(dev);
781 pcmcia_request_configuration(link->handle, &link->conf); 750 NS8390_init(dev, 1);
782 if (link->open) { 751 netif_device_attach(dev);
783 pcnet_reset_8390(dev);
784 NS8390_init(dev, 1);
785 netif_device_attach(dev);
786 }
787 } 752 }
788 753
789 return 0; 754 return 0;
@@ -1023,11 +988,11 @@ static void mii_phy_probe(struct net_device *dev)
1023static int pcnet_open(struct net_device *dev) 988static int pcnet_open(struct net_device *dev)
1024{ 989{
1025 pcnet_dev_t *info = PRIV(dev); 990 pcnet_dev_t *info = PRIV(dev);
1026 dev_link_t *link = &info->link; 991 struct pcmcia_device *link = info->p_dev;
1027 992
1028 DEBUG(2, "pcnet_open('%s')\n", dev->name); 993 DEBUG(2, "pcnet_open('%s')\n", dev->name);
1029 994
1030 if (!DEV_OK(link)) 995 if (!pcmcia_dev_present(link))
1031 return -ENODEV; 996 return -ENODEV;
1032 997
1033 link->open++; 998 link->open++;
@@ -1051,7 +1016,7 @@ static int pcnet_open(struct net_device *dev)
1051static int pcnet_close(struct net_device *dev) 1016static int pcnet_close(struct net_device *dev)
1052{ 1017{
1053 pcnet_dev_t *info = PRIV(dev); 1018 pcnet_dev_t *info = PRIV(dev);
1054 dev_link_t *link = &info->link; 1019 struct pcmcia_device *link = info->p_dev;
1055 1020
1056 DEBUG(2, "pcnet_close('%s')\n", dev->name); 1021 DEBUG(2, "pcnet_close('%s')\n", dev->name);
1057 1022
@@ -1429,7 +1394,7 @@ static void dma_block_output(struct net_device *dev, int count,
1429 1394
1430/*====================================================================*/ 1395/*====================================================================*/
1431 1396
1432static int setup_dma_config(dev_link_t *link, int start_pg, 1397static int setup_dma_config(struct pcmcia_device *link, int start_pg,
1433 int stop_pg) 1398 int stop_pg)
1434{ 1399{
1435 struct net_device *dev = link->priv; 1400 struct net_device *dev = link->priv;
@@ -1532,7 +1497,7 @@ static void shmem_block_output(struct net_device *dev, int count,
1532 1497
1533/*====================================================================*/ 1498/*====================================================================*/
1534 1499
1535static int setup_shmem_window(dev_link_t *link, int start_pg, 1500static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1536 int stop_pg, int cm_offset) 1501 int stop_pg, int cm_offset)
1537{ 1502{
1538 struct net_device *dev = link->priv; 1503 struct net_device *dev = link->priv;
@@ -1554,7 +1519,7 @@ static int setup_shmem_window(dev_link_t *link, int start_pg,
1554 req.Attributes |= WIN_USE_WAIT; 1519 req.Attributes |= WIN_USE_WAIT;
1555 req.Base = 0; req.Size = window_size; 1520 req.Base = 0; req.Size = window_size;
1556 req.AccessSpeed = mem_speed; 1521 req.AccessSpeed = mem_speed;
1557 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 1522 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
1558 1523
1559 mem.CardOffset = (start_pg << 8) + cm_offset; 1524 mem.CardOffset = (start_pg << 8) + cm_offset;
1560 offset = mem.CardOffset % window_size; 1525 offset = mem.CardOffset % window_size;
@@ -1595,7 +1560,7 @@ static int setup_shmem_window(dev_link_t *link, int start_pg,
1595 return 0; 1560 return 0;
1596 1561
1597cs_failed: 1562cs_failed:
1598 cs_error(link->handle, last_fn, last_ret); 1563 cs_error(link, last_fn, last_ret);
1599failed: 1564failed:
1600 return 1; 1565 return 1;
1601} 1566}
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 8839c4faafd6..e74bf5014ef6 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -49,6 +49,7 @@
49#include <pcmcia/cisreg.h> 49#include <pcmcia/cisreg.h>
50#include <pcmcia/ciscode.h> 50#include <pcmcia/ciscode.h>
51#include <pcmcia/ds.h> 51#include <pcmcia/ds.h>
52#include <pcmcia/ss.h>
52 53
53#include <asm/io.h> 54#include <asm/io.h>
54#include <asm/system.h> 55#include <asm/system.h>
@@ -103,7 +104,7 @@ static const char *version =
103#define MEMORY_WAIT_TIME 8 104#define MEMORY_WAIT_TIME 8
104 105
105struct smc_private { 106struct smc_private {
106 dev_link_t link; 107 struct pcmcia_device *p_dev;
107 spinlock_t lock; 108 spinlock_t lock;
108 u_short manfid; 109 u_short manfid;
109 u_short cardid; 110 u_short cardid;
@@ -278,8 +279,8 @@ enum RxCfg { RxAllMulti = 0x0004, RxPromisc = 0x0002,
278/*====================================================================*/ 279/*====================================================================*/
279 280
280static void smc91c92_detach(struct pcmcia_device *p_dev); 281static void smc91c92_detach(struct pcmcia_device *p_dev);
281static void smc91c92_config(dev_link_t *link); 282static int smc91c92_config(struct pcmcia_device *link);
282static void smc91c92_release(dev_link_t *link); 283static void smc91c92_release(struct pcmcia_device *link);
283 284
284static int smc_open(struct net_device *dev); 285static int smc_open(struct net_device *dev);
285static int smc_close(struct net_device *dev); 286static int smc_close(struct net_device *dev);
@@ -308,10 +309,9 @@ static struct ethtool_ops ethtool_ops;
308 309
309======================================================================*/ 310======================================================================*/
310 311
311static int smc91c92_attach(struct pcmcia_device *p_dev) 312static int smc91c92_probe(struct pcmcia_device *link)
312{ 313{
313 struct smc_private *smc; 314 struct smc_private *smc;
314 dev_link_t *link;
315 struct net_device *dev; 315 struct net_device *dev;
316 316
317 DEBUG(0, "smc91c92_attach()\n"); 317 DEBUG(0, "smc91c92_attach()\n");
@@ -321,7 +321,7 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
321 if (!dev) 321 if (!dev)
322 return -ENOMEM; 322 return -ENOMEM;
323 smc = netdev_priv(dev); 323 smc = netdev_priv(dev);
324 link = &smc->link; 324 smc->p_dev = link;
325 link->priv = dev; 325 link->priv = dev;
326 326
327 spin_lock_init(&smc->lock); 327 spin_lock_init(&smc->lock);
@@ -333,7 +333,6 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
333 link->irq.Handler = &smc_interrupt; 333 link->irq.Handler = &smc_interrupt;
334 link->irq.Instance = dev; 334 link->irq.Instance = dev;
335 link->conf.Attributes = CONF_ENABLE_IRQ; 335 link->conf.Attributes = CONF_ENABLE_IRQ;
336 link->conf.Vcc = 50;
337 link->conf.IntType = INT_MEMORY_AND_IO; 336 link->conf.IntType = INT_MEMORY_AND_IO;
338 337
339 /* The SMC91c92-specific entries in the device structure. */ 338 /* The SMC91c92-specific entries in the device structure. */
@@ -357,13 +356,7 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
357 smc->mii_if.phy_id_mask = 0x1f; 356 smc->mii_if.phy_id_mask = 0x1f;
358 smc->mii_if.reg_num_mask = 0x1f; 357 smc->mii_if.reg_num_mask = 0x1f;
359 358
360 link->handle = p_dev; 359 return smc91c92_config(link);
361 p_dev->instance = link;
362
363 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
364 smc91c92_config(link);
365
366 return 0;
367} /* smc91c92_attach */ 360} /* smc91c92_attach */
368 361
369/*====================================================================== 362/*======================================================================
@@ -375,18 +368,16 @@ static int smc91c92_attach(struct pcmcia_device *p_dev)
375 368
376======================================================================*/ 369======================================================================*/
377 370
378static void smc91c92_detach(struct pcmcia_device *p_dev) 371static void smc91c92_detach(struct pcmcia_device *link)
379{ 372{
380 dev_link_t *link = dev_to_instance(p_dev);
381 struct net_device *dev = link->priv; 373 struct net_device *dev = link->priv;
382 374
383 DEBUG(0, "smc91c92_detach(0x%p)\n", link); 375 DEBUG(0, "smc91c92_detach(0x%p)\n", link);
384 376
385 if (link->dev) 377 if (link->dev_node)
386 unregister_netdev(dev); 378 unregister_netdev(dev);
387 379
388 if (link->state & DEV_CONFIG) 380 smc91c92_release(link);
389 smc91c92_release(link);
390 381
391 free_netdev(dev); 382 free_netdev(dev);
392} /* smc91c92_detach */ 383} /* smc91c92_detach */
@@ -414,7 +405,7 @@ static int cvt_ascii_address(struct net_device *dev, char *s)
414 405
415/*====================================================================*/ 406/*====================================================================*/
416 407
417static int first_tuple(client_handle_t handle, tuple_t *tuple, 408static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
418 cisparse_t *parse) 409 cisparse_t *parse)
419{ 410{
420 int i; 411 int i;
@@ -425,7 +416,7 @@ static int first_tuple(client_handle_t handle, tuple_t *tuple,
425 return pcmcia_parse_tuple(handle, tuple, parse); 416 return pcmcia_parse_tuple(handle, tuple, parse);
426} 417}
427 418
428static int next_tuple(client_handle_t handle, tuple_t *tuple, 419static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
429 cisparse_t *parse) 420 cisparse_t *parse)
430{ 421{
431 int i; 422 int i;
@@ -447,7 +438,7 @@ static int next_tuple(client_handle_t handle, tuple_t *tuple,
447 438
448======================================================================*/ 439======================================================================*/
449 440
450static int mhz_3288_power(dev_link_t *link) 441static int mhz_3288_power(struct pcmcia_device *link)
451{ 442{
452 struct net_device *dev = link->priv; 443 struct net_device *dev = link->priv;
453 struct smc_private *smc = netdev_priv(dev); 444 struct smc_private *smc = netdev_priv(dev);
@@ -469,7 +460,7 @@ static int mhz_3288_power(dev_link_t *link)
469 return 0; 460 return 0;
470} 461}
471 462
472static int mhz_mfc_config(dev_link_t *link) 463static int mhz_mfc_config(struct pcmcia_device *link)
473{ 464{
474 struct net_device *dev = link->priv; 465 struct net_device *dev = link->priv;
475 struct smc_private *smc = netdev_priv(dev); 466 struct smc_private *smc = netdev_priv(dev);
@@ -504,7 +495,7 @@ static int mhz_mfc_config(dev_link_t *link)
504 tuple->TupleDataMax = 255; 495 tuple->TupleDataMax = 255;
505 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 496 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
506 497
507 i = first_tuple(link->handle, tuple, parse); 498 i = first_tuple(link, tuple, parse);
508 /* The Megahertz combo cards have modem-like CIS entries, so 499 /* The Megahertz combo cards have modem-like CIS entries, so
509 we have to explicitly try a bunch of port combinations. */ 500 we have to explicitly try a bunch of port combinations. */
510 while (i == CS_SUCCESS) { 501 while (i == CS_SUCCESS) {
@@ -513,11 +504,11 @@ static int mhz_mfc_config(dev_link_t *link)
513 for (k = 0; k < 0x400; k += 0x10) { 504 for (k = 0; k < 0x400; k += 0x10) {
514 if (k & 0x80) continue; 505 if (k & 0x80) continue;
515 link->io.BasePort1 = k ^ 0x300; 506 link->io.BasePort1 = k ^ 0x300;
516 i = pcmcia_request_io(link->handle, &link->io); 507 i = pcmcia_request_io(link, &link->io);
517 if (i == CS_SUCCESS) break; 508 if (i == CS_SUCCESS) break;
518 } 509 }
519 if (i == CS_SUCCESS) break; 510 if (i == CS_SUCCESS) break;
520 i = next_tuple(link->handle, tuple, parse); 511 i = next_tuple(link, tuple, parse);
521 } 512 }
522 if (i != CS_SUCCESS) 513 if (i != CS_SUCCESS)
523 goto free_cfg_mem; 514 goto free_cfg_mem;
@@ -527,7 +518,7 @@ static int mhz_mfc_config(dev_link_t *link)
527 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 518 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
528 req.Base = req.Size = 0; 519 req.Base = req.Size = 0;
529 req.AccessSpeed = 0; 520 req.AccessSpeed = 0;
530 i = pcmcia_request_window(&link->handle, &req, &link->win); 521 i = pcmcia_request_window(&link, &req, &link->win);
531 if (i != CS_SUCCESS) 522 if (i != CS_SUCCESS)
532 goto free_cfg_mem; 523 goto free_cfg_mem;
533 smc->base = ioremap(req.Base, req.Size); 524 smc->base = ioremap(req.Base, req.Size);
@@ -546,9 +537,8 @@ free_cfg_mem:
546 return i; 537 return i;
547} 538}
548 539
549static int mhz_setup(dev_link_t *link) 540static int mhz_setup(struct pcmcia_device *link)
550{ 541{
551 client_handle_t handle = link->handle;
552 struct net_device *dev = link->priv; 542 struct net_device *dev = link->priv;
553 struct smc_cfg_mem *cfg_mem; 543 struct smc_cfg_mem *cfg_mem;
554 tuple_t *tuple; 544 tuple_t *tuple;
@@ -571,13 +561,13 @@ static int mhz_setup(dev_link_t *link)
571 /* Read the station address from the CIS. It is stored as the last 561 /* Read the station address from the CIS. It is stored as the last
572 (fourth) string in the Version 1 Version/ID tuple. */ 562 (fourth) string in the Version 1 Version/ID tuple. */
573 tuple->DesiredTuple = CISTPL_VERS_1; 563 tuple->DesiredTuple = CISTPL_VERS_1;
574 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) { 564 if (first_tuple(link, tuple, parse) != CS_SUCCESS) {
575 rc = -1; 565 rc = -1;
576 goto free_cfg_mem; 566 goto free_cfg_mem;
577 } 567 }
578 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ 568 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
579 if (next_tuple(handle, tuple, parse) != CS_SUCCESS) 569 if (next_tuple(link, tuple, parse) != CS_SUCCESS)
580 first_tuple(handle, tuple, parse); 570 first_tuple(link, tuple, parse);
581 if (parse->version_1.ns > 3) { 571 if (parse->version_1.ns > 3) {
582 station_addr = parse->version_1.str + parse->version_1.ofs[3]; 572 station_addr = parse->version_1.str + parse->version_1.ofs[3];
583 if (cvt_ascii_address(dev, station_addr) == 0) { 573 if (cvt_ascii_address(dev, station_addr) == 0) {
@@ -588,11 +578,11 @@ static int mhz_setup(dev_link_t *link)
588 578
589 /* Another possibility: for the EM3288, in a special tuple */ 579 /* Another possibility: for the EM3288, in a special tuple */
590 tuple->DesiredTuple = 0x81; 580 tuple->DesiredTuple = 0x81;
591 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) { 581 if (pcmcia_get_first_tuple(link, tuple) != CS_SUCCESS) {
592 rc = -1; 582 rc = -1;
593 goto free_cfg_mem; 583 goto free_cfg_mem;
594 } 584 }
595 if (pcmcia_get_tuple_data(handle, tuple) != CS_SUCCESS) { 585 if (pcmcia_get_tuple_data(link, tuple) != CS_SUCCESS) {
596 rc = -1; 586 rc = -1;
597 goto free_cfg_mem; 587 goto free_cfg_mem;
598 } 588 }
@@ -616,7 +606,7 @@ free_cfg_mem:
616 606
617======================================================================*/ 607======================================================================*/
618 608
619static void mot_config(dev_link_t *link) 609static void mot_config(struct pcmcia_device *link)
620{ 610{
621 struct net_device *dev = link->priv; 611 struct net_device *dev = link->priv;
622 struct smc_private *smc = netdev_priv(dev); 612 struct smc_private *smc = netdev_priv(dev);
@@ -637,7 +627,7 @@ static void mot_config(dev_link_t *link)
637 mdelay(100); 627 mdelay(100);
638} 628}
639 629
640static int mot_setup(dev_link_t *link) 630static int mot_setup(struct pcmcia_device *link)
641{ 631{
642 struct net_device *dev = link->priv; 632 struct net_device *dev = link->priv;
643 kio_addr_t ioaddr = dev->base_addr; 633 kio_addr_t ioaddr = dev->base_addr;
@@ -671,7 +661,7 @@ static int mot_setup(dev_link_t *link)
671 661
672/*====================================================================*/ 662/*====================================================================*/
673 663
674static int smc_config(dev_link_t *link) 664static int smc_config(struct pcmcia_device *link)
675{ 665{
676 struct net_device *dev = link->priv; 666 struct net_device *dev = link->priv;
677 struct smc_cfg_mem *cfg_mem; 667 struct smc_cfg_mem *cfg_mem;
@@ -696,16 +686,16 @@ static int smc_config(dev_link_t *link)
696 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 686 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
697 687
698 link->io.NumPorts1 = 16; 688 link->io.NumPorts1 = 16;
699 i = first_tuple(link->handle, tuple, parse); 689 i = first_tuple(link, tuple, parse);
700 while (i != CS_NO_MORE_ITEMS) { 690 while (i != CS_NO_MORE_ITEMS) {
701 if (i == CS_SUCCESS) { 691 if (i == CS_SUCCESS) {
702 link->conf.ConfigIndex = cf->index; 692 link->conf.ConfigIndex = cf->index;
703 link->io.BasePort1 = cf->io.win[0].base; 693 link->io.BasePort1 = cf->io.win[0].base;
704 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK; 694 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
705 i = pcmcia_request_io(link->handle, &link->io); 695 i = pcmcia_request_io(link, &link->io);
706 if (i == CS_SUCCESS) break; 696 if (i == CS_SUCCESS) break;
707 } 697 }
708 i = next_tuple(link->handle, tuple, parse); 698 i = next_tuple(link, tuple, parse);
709 } 699 }
710 if (i == CS_SUCCESS) 700 if (i == CS_SUCCESS)
711 dev->base_addr = link->io.BasePort1; 701 dev->base_addr = link->io.BasePort1;
@@ -714,9 +704,8 @@ static int smc_config(dev_link_t *link)
714 return i; 704 return i;
715} 705}
716 706
717static int smc_setup(dev_link_t *link) 707static int smc_setup(struct pcmcia_device *link)
718{ 708{
719 client_handle_t handle = link->handle;
720 struct net_device *dev = link->priv; 709 struct net_device *dev = link->priv;
721 struct smc_cfg_mem *cfg_mem; 710 struct smc_cfg_mem *cfg_mem;
722 tuple_t *tuple; 711 tuple_t *tuple;
@@ -739,11 +728,11 @@ static int smc_setup(dev_link_t *link)
739 728
740 /* Check for a LAN function extension tuple */ 729 /* Check for a LAN function extension tuple */
741 tuple->DesiredTuple = CISTPL_FUNCE; 730 tuple->DesiredTuple = CISTPL_FUNCE;
742 i = first_tuple(handle, tuple, parse); 731 i = first_tuple(link, tuple, parse);
743 while (i == CS_SUCCESS) { 732 while (i == CS_SUCCESS) {
744 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID) 733 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
745 break; 734 break;
746 i = next_tuple(handle, tuple, parse); 735 i = next_tuple(link, tuple, parse);
747 } 736 }
748 if (i == CS_SUCCESS) { 737 if (i == CS_SUCCESS) {
749 node_id = (cistpl_lan_node_id_t *)parse->funce.data; 738 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
@@ -756,7 +745,7 @@ static int smc_setup(dev_link_t *link)
756 } 745 }
757 /* Try the third string in the Version 1 Version/ID tuple. */ 746 /* Try the third string in the Version 1 Version/ID tuple. */
758 tuple->DesiredTuple = CISTPL_VERS_1; 747 tuple->DesiredTuple = CISTPL_VERS_1;
759 if (first_tuple(handle, tuple, parse) != CS_SUCCESS) { 748 if (first_tuple(link, tuple, parse) != CS_SUCCESS) {
760 rc = -1; 749 rc = -1;
761 goto free_cfg_mem; 750 goto free_cfg_mem;
762 } 751 }
@@ -774,7 +763,7 @@ free_cfg_mem:
774 763
775/*====================================================================*/ 764/*====================================================================*/
776 765
777static int osi_config(dev_link_t *link) 766static int osi_config(struct pcmcia_device *link)
778{ 767{
779 struct net_device *dev = link->priv; 768 struct net_device *dev = link->priv;
780 static const kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; 769 static const kio_addr_t com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
@@ -794,22 +783,21 @@ static int osi_config(dev_link_t *link)
794 783
795 for (i = j = 0; j < 4; j++) { 784 for (i = j = 0; j < 4; j++) {
796 link->io.BasePort2 = com[j]; 785 link->io.BasePort2 = com[j];
797 i = pcmcia_request_io(link->handle, &link->io); 786 i = pcmcia_request_io(link, &link->io);
798 if (i == CS_SUCCESS) break; 787 if (i == CS_SUCCESS) break;
799 } 788 }
800 if (i != CS_SUCCESS) { 789 if (i != CS_SUCCESS) {
801 /* Fallback: turn off hard decode */ 790 /* Fallback: turn off hard decode */
802 link->conf.ConfigIndex = 0x03; 791 link->conf.ConfigIndex = 0x03;
803 link->io.NumPorts2 = 0; 792 link->io.NumPorts2 = 0;
804 i = pcmcia_request_io(link->handle, &link->io); 793 i = pcmcia_request_io(link, &link->io);
805 } 794 }
806 dev->base_addr = link->io.BasePort1 + 0x10; 795 dev->base_addr = link->io.BasePort1 + 0x10;
807 return i; 796 return i;
808} 797}
809 798
810static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid) 799static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
811{ 800{
812 client_handle_t handle = link->handle;
813 struct net_device *dev = link->priv; 801 struct net_device *dev = link->priv;
814 struct smc_cfg_mem *cfg_mem; 802 struct smc_cfg_mem *cfg_mem;
815 tuple_t *tuple; 803 tuple_t *tuple;
@@ -830,12 +818,12 @@ static int osi_setup(dev_link_t *link, u_short manfid, u_short cardid)
830 818
831 /* Read the station address from tuple 0x90, subtuple 0x04 */ 819 /* Read the station address from tuple 0x90, subtuple 0x04 */
832 tuple->DesiredTuple = 0x90; 820 tuple->DesiredTuple = 0x90;
833 i = pcmcia_get_first_tuple(handle, tuple); 821 i = pcmcia_get_first_tuple(link, tuple);
834 while (i == CS_SUCCESS) { 822 while (i == CS_SUCCESS) {
835 i = pcmcia_get_tuple_data(handle, tuple); 823 i = pcmcia_get_tuple_data(link, tuple);
836 if ((i != CS_SUCCESS) || (buf[0] == 0x04)) 824 if ((i != CS_SUCCESS) || (buf[0] == 0x04))
837 break; 825 break;
838 i = pcmcia_get_next_tuple(handle, tuple); 826 i = pcmcia_get_next_tuple(link, tuple);
839 } 827 }
840 if (i != CS_SUCCESS) { 828 if (i != CS_SUCCESS) {
841 rc = -1; 829 rc = -1;
@@ -868,57 +856,47 @@ free_cfg_mem:
868 return rc; 856 return rc;
869} 857}
870 858
871static int smc91c92_suspend(struct pcmcia_device *p_dev) 859static int smc91c92_suspend(struct pcmcia_device *link)
872{ 860{
873 dev_link_t *link = dev_to_instance(p_dev);
874 struct net_device *dev = link->priv; 861 struct net_device *dev = link->priv;
875 862
876 link->state |= DEV_SUSPEND; 863 if (link->open)
877 if (link->state & DEV_CONFIG) { 864 netif_device_detach(dev);
878 if (link->open)
879 netif_device_detach(dev);
880 pcmcia_release_configuration(link->handle);
881 }
882 865
883 return 0; 866 return 0;
884} 867}
885 868
886static int smc91c92_resume(struct pcmcia_device *p_dev) 869static int smc91c92_resume(struct pcmcia_device *link)
887{ 870{
888 dev_link_t *link = dev_to_instance(p_dev);
889 struct net_device *dev = link->priv; 871 struct net_device *dev = link->priv;
890 struct smc_private *smc = netdev_priv(dev); 872 struct smc_private *smc = netdev_priv(dev);
891 int i; 873 int i;
892 874
893 link->state &= ~DEV_SUSPEND; 875 if ((smc->manfid == MANFID_MEGAHERTZ) &&
894 if (link->state & DEV_CONFIG) { 876 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
895 if ((smc->manfid == MANFID_MEGAHERTZ) && 877 mhz_3288_power(link);
896 (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 878 if (smc->manfid == MANFID_MOTOROLA)
897 mhz_3288_power(link); 879 mot_config(link);
898 pcmcia_request_configuration(link->handle, &link->conf); 880 if ((smc->manfid == MANFID_OSITECH) &&
899 if (smc->manfid == MANFID_MOTOROLA) 881 (smc->cardid != PRODID_OSITECH_SEVEN)) {
900 mot_config(link); 882 /* Power up the card and enable interrupts */
901 if ((smc->manfid == MANFID_OSITECH) && 883 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR);
902 (smc->cardid != PRODID_OSITECH_SEVEN)) { 884 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR);
903 /* Power up the card and enable interrupts */ 885 }
904 set_bits(0x0300, dev->base_addr-0x10+OSITECH_AUI_PWR); 886 if (((smc->manfid == MANFID_OSITECH) &&
905 set_bits(0x0300, dev->base_addr-0x10+OSITECH_RESET_ISR); 887 (smc->cardid == PRODID_OSITECH_SEVEN)) ||
906 } 888 ((smc->manfid == MANFID_PSION) &&
907 if (((smc->manfid == MANFID_OSITECH) && 889 (smc->cardid == PRODID_PSION_NET100))) {
908 (smc->cardid == PRODID_OSITECH_SEVEN)) || 890 /* Download the Seven of Diamonds firmware */
909 ((smc->manfid == MANFID_PSION) && 891 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
910 (smc->cardid == PRODID_PSION_NET100))) { 892 outb(__Xilinx7OD[i], link->io.BasePort1+2);
911 /* Download the Seven of Diamonds firmware */ 893 udelay(50);
912 for (i = 0; i < sizeof(__Xilinx7OD); i++) {
913 outb(__Xilinx7OD[i], link->io.BasePort1+2);
914 udelay(50);
915 }
916 }
917 if (link->open) {
918 smc_reset(dev);
919 netif_device_attach(dev);
920 } 894 }
921 } 895 }
896 if (link->open) {
897 smc_reset(dev);
898 netif_device_attach(dev);
899 }
922 900
923 return 0; 901 return 0;
924} 902}
@@ -931,7 +909,7 @@ static int smc91c92_resume(struct pcmcia_device *p_dev)
931 909
932======================================================================*/ 910======================================================================*/
933 911
934static int check_sig(dev_link_t *link) 912static int check_sig(struct pcmcia_device *link)
935{ 913{
936 struct net_device *dev = link->priv; 914 struct net_device *dev = link->priv;
937 kio_addr_t ioaddr = dev->base_addr; 915 kio_addr_t ioaddr = dev->base_addr;
@@ -964,13 +942,15 @@ static int check_sig(dev_link_t *link)
964 } 942 }
965 943
966 if (width) { 944 if (width) {
967 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n"); 945 modconf_t mod = {
968 smc91c92_suspend(link->handle); 946 .Attributes = CONF_IO_CHANGE_WIDTH,
969 pcmcia_release_io(link->handle, &link->io); 947 };
970 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 948 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
971 pcmcia_request_io(link->handle, &link->io); 949
972 smc91c92_resume(link->handle); 950 smc91c92_suspend(link);
973 return check_sig(link); 951 pcmcia_modify_configuration(link, &mod);
952 smc91c92_resume(link);
953 return check_sig(link);
974 } 954 }
975 return -ENODEV; 955 return -ENODEV;
976} 956}
@@ -984,11 +964,10 @@ static int check_sig(dev_link_t *link)
984======================================================================*/ 964======================================================================*/
985 965
986#define CS_EXIT_TEST(ret, svc, label) \ 966#define CS_EXIT_TEST(ret, svc, label) \
987if (ret != CS_SUCCESS) { cs_error(link->handle, svc, ret); goto label; } 967if (ret != CS_SUCCESS) { cs_error(link, svc, ret); goto label; }
988 968
989static void smc91c92_config(dev_link_t *link) 969static int smc91c92_config(struct pcmcia_device *link)
990{ 970{
991 client_handle_t handle = link->handle;
992 struct net_device *dev = link->priv; 971 struct net_device *dev = link->priv;
993 struct smc_private *smc = netdev_priv(dev); 972 struct smc_private *smc = netdev_priv(dev);
994 struct smc_cfg_mem *cfg_mem; 973 struct smc_cfg_mem *cfg_mem;
@@ -1015,21 +994,18 @@ static void smc91c92_config(dev_link_t *link)
1015 tuple->TupleDataMax = 64; 994 tuple->TupleDataMax = 64;
1016 995
1017 tuple->DesiredTuple = CISTPL_CONFIG; 996 tuple->DesiredTuple = CISTPL_CONFIG;
1018 i = first_tuple(handle, tuple, parse); 997 i = first_tuple(link, tuple, parse);
1019 CS_EXIT_TEST(i, ParseTuple, config_failed); 998 CS_EXIT_TEST(i, ParseTuple, config_failed);
1020 link->conf.ConfigBase = parse->config.base; 999 link->conf.ConfigBase = parse->config.base;
1021 link->conf.Present = parse->config.rmask[0]; 1000 link->conf.Present = parse->config.rmask[0];
1022 1001
1023 tuple->DesiredTuple = CISTPL_MANFID; 1002 tuple->DesiredTuple = CISTPL_MANFID;
1024 tuple->Attributes = TUPLE_RETURN_COMMON; 1003 tuple->Attributes = TUPLE_RETURN_COMMON;
1025 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { 1004 if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
1026 smc->manfid = parse->manfid.manf; 1005 smc->manfid = parse->manfid.manf;
1027 smc->cardid = parse->manfid.card; 1006 smc->cardid = parse->manfid.card;
1028 } 1007 }
1029 1008
1030 /* Configure card */
1031 link->state |= DEV_CONFIG;
1032
1033 if ((smc->manfid == MANFID_OSITECH) && 1009 if ((smc->manfid == MANFID_OSITECH) &&
1034 (smc->cardid != PRODID_OSITECH_SEVEN)) { 1010 (smc->cardid != PRODID_OSITECH_SEVEN)) {
1035 i = osi_config(link); 1011 i = osi_config(link);
@@ -1043,9 +1019,9 @@ static void smc91c92_config(dev_link_t *link)
1043 } 1019 }
1044 CS_EXIT_TEST(i, RequestIO, config_failed); 1020 CS_EXIT_TEST(i, RequestIO, config_failed);
1045 1021
1046 i = pcmcia_request_irq(link->handle, &link->irq); 1022 i = pcmcia_request_irq(link, &link->irq);
1047 CS_EXIT_TEST(i, RequestIRQ, config_failed); 1023 CS_EXIT_TEST(i, RequestIRQ, config_failed);
1048 i = pcmcia_request_configuration(link->handle, &link->conf); 1024 i = pcmcia_request_configuration(link, &link->conf);
1049 CS_EXIT_TEST(i, RequestConfiguration, config_failed); 1025 CS_EXIT_TEST(i, RequestConfiguration, config_failed);
1050 1026
1051 if (smc->manfid == MANFID_MOTOROLA) 1027 if (smc->manfid == MANFID_MOTOROLA)
@@ -1124,13 +1100,12 @@ static void smc91c92_config(dev_link_t *link)
1124 SMC_SELECT_BANK(0); 1100 SMC_SELECT_BANK(0);
1125 } 1101 }
1126 1102
1127 link->dev = &smc->node; 1103 link->dev_node = &smc->node;
1128 link->state &= ~DEV_CONFIG_PENDING; 1104 SET_NETDEV_DEV(dev, &handle_to_dev(link));
1129 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1130 1105
1131 if (register_netdev(dev) != 0) { 1106 if (register_netdev(dev) != 0) {
1132 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n"); 1107 printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
1133 link->dev = NULL; 1108 link->dev_node = NULL;
1134 goto config_undo; 1109 goto config_undo;
1135 } 1110 }
1136 1111
@@ -1160,15 +1135,14 @@ static void smc91c92_config(dev_link_t *link)
1160 } 1135 }
1161 } 1136 }
1162 kfree(cfg_mem); 1137 kfree(cfg_mem);
1163 return; 1138 return 0;
1164 1139
1165config_undo: 1140config_undo:
1166 unregister_netdev(dev); 1141 unregister_netdev(dev);
1167config_failed: /* CS_EXIT_TEST() calls jump to here... */ 1142config_failed: /* CS_EXIT_TEST() calls jump to here... */
1168 smc91c92_release(link); 1143 smc91c92_release(link);
1169 link->state &= ~DEV_CONFIG_PENDING;
1170 kfree(cfg_mem); 1144 kfree(cfg_mem);
1171 1145 return -ENODEV;
1172} /* smc91c92_config */ 1146} /* smc91c92_config */
1173 1147
1174/*====================================================================== 1148/*======================================================================
@@ -1179,22 +1153,15 @@ config_failed: /* CS_EXIT_TEST() calls jump to here... */
1179 1153
1180======================================================================*/ 1154======================================================================*/
1181 1155
1182static void smc91c92_release(dev_link_t *link) 1156static void smc91c92_release(struct pcmcia_device *link)
1183{ 1157{
1184 1158 DEBUG(0, "smc91c92_release(0x%p)\n", link);
1185 DEBUG(0, "smc91c92_release(0x%p)\n", link); 1159 if (link->win) {
1186 1160 struct net_device *dev = link->priv;
1187 pcmcia_release_configuration(link->handle); 1161 struct smc_private *smc = netdev_priv(dev);
1188 pcmcia_release_io(link->handle, &link->io); 1162 iounmap(smc->base);
1189 pcmcia_release_irq(link->handle, &link->irq); 1163 }
1190 if (link->win) { 1164 pcmcia_disable_device(link);
1191 struct net_device *dev = link->priv;
1192 struct smc_private *smc = netdev_priv(dev);
1193 iounmap(smc->base);
1194 pcmcia_release_window(link->win);
1195 }
1196
1197 link->state &= ~DEV_CONFIG;
1198} 1165}
1199 1166
1200/*====================================================================== 1167/*======================================================================
@@ -1283,7 +1250,7 @@ static void smc_dump(struct net_device *dev)
1283static int smc_open(struct net_device *dev) 1250static int smc_open(struct net_device *dev)
1284{ 1251{
1285 struct smc_private *smc = netdev_priv(dev); 1252 struct smc_private *smc = netdev_priv(dev);
1286 dev_link_t *link = &smc->link; 1253 struct pcmcia_device *link = smc->p_dev;
1287 1254
1288#ifdef PCMCIA_DEBUG 1255#ifdef PCMCIA_DEBUG
1289 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n", 1256 DEBUG(0, "%s: smc_open(%p), ID/Window %4.4x.\n",
@@ -1292,7 +1259,7 @@ static int smc_open(struct net_device *dev)
1292#endif 1259#endif
1293 1260
1294 /* Check that the PCMCIA card is still here. */ 1261 /* Check that the PCMCIA card is still here. */
1295 if (!DEV_OK(link)) 1262 if (!pcmcia_dev_present(link))
1296 return -ENODEV; 1263 return -ENODEV;
1297 /* Physical device present signature. */ 1264 /* Physical device present signature. */
1298 if (check_sig(link) < 0) { 1265 if (check_sig(link) < 0) {
@@ -1320,7 +1287,7 @@ static int smc_open(struct net_device *dev)
1320static int smc_close(struct net_device *dev) 1287static int smc_close(struct net_device *dev)
1321{ 1288{
1322 struct smc_private *smc = netdev_priv(dev); 1289 struct smc_private *smc = netdev_priv(dev);
1323 dev_link_t *link = &smc->link; 1290 struct pcmcia_device *link = smc->p_dev;
1324 kio_addr_t ioaddr = dev->base_addr; 1291 kio_addr_t ioaddr = dev->base_addr;
1325 1292
1326 DEBUG(0, "%s: smc_close(), status %4.4x.\n", 1293 DEBUG(0, "%s: smc_close(), status %4.4x.\n",
@@ -2311,7 +2278,7 @@ static struct pcmcia_driver smc91c92_cs_driver = {
2311 .drv = { 2278 .drv = {
2312 .name = "smc91c92_cs", 2279 .name = "smc91c92_cs",
2313 }, 2280 },
2314 .probe = smc91c92_attach, 2281 .probe = smc91c92_probe,
2315 .remove = smc91c92_detach, 2282 .remove = smc91c92_detach,
2316 .id_table = smc91c92_ids, 2283 .id_table = smc91c92_ids,
2317 .suspend = smc91c92_suspend, 2284 .suspend = smc91c92_suspend,
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index eed496803fe4..71f45056a70c 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -289,9 +289,9 @@ static void mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg,
289 * and ejection events. They are invoked from the event handler. 289 * and ejection events. They are invoked from the event handler.
290 */ 290 */
291 291
292static int has_ce2_string(dev_link_t * link); 292static int has_ce2_string(struct pcmcia_device * link);
293static void xirc2ps_config(dev_link_t * link); 293static int xirc2ps_config(struct pcmcia_device * link);
294static void xirc2ps_release(dev_link_t * link); 294static void xirc2ps_release(struct pcmcia_device * link);
295 295
296/**************** 296/****************
297 * The attach() and detach() entry points are used to create and destroy 297 * The attach() and detach() entry points are used to create and destroy
@@ -313,10 +313,10 @@ static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs
313/**************** 313/****************
314 * A linked list of "instances" of the device. Each actual 314 * A linked list of "instances" of the device. Each actual
315 * PCMCIA card corresponds to one device instance, and is described 315 * PCMCIA card corresponds to one device instance, and is described
316 * by one dev_link_t structure (defined in ds.h). 316 * by one struct pcmcia_device structure (defined in ds.h).
317 * 317 *
318 * You may not want to use a linked list for this -- for example, the 318 * You may not want to use a linked list for this -- for example, the
319 * memory card driver uses an array of dev_link_t pointers, where minor 319 * memory card driver uses an array of struct pcmcia_device pointers, where minor
320 * device numbers are used to derive the corresponding array index. 320 * device numbers are used to derive the corresponding array index.
321 */ 321 */
322 322
@@ -326,13 +326,13 @@ static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id, struct pt_regs *regs
326 * example, ethernet cards, modems). In other cases, there may be 326 * example, ethernet cards, modems). In other cases, there may be
327 * many actual or logical devices (SCSI adapters, memory cards with 327 * many actual or logical devices (SCSI adapters, memory cards with
328 * multiple partitions). The dev_node_t structures need to be kept 328 * multiple partitions). The dev_node_t structures need to be kept
329 * in a linked list starting at the 'dev' field of a dev_link_t 329 * in a linked list starting at the 'dev' field of a struct pcmcia_device
330 * structure. We allocate them in the card's private data structure, 330 * structure. We allocate them in the card's private data structure,
331 * because they generally can't be allocated dynamically. 331 * because they generally can't be allocated dynamically.
332 */ 332 */
333 333
334typedef struct local_info_t { 334typedef struct local_info_t {
335 dev_link_t link; 335 struct pcmcia_device *p_dev;
336 dev_node_t node; 336 dev_node_t node;
337 struct net_device_stats stats; 337 struct net_device_stats stats;
338 int card_type; 338 int card_type;
@@ -355,7 +355,7 @@ static void do_tx_timeout(struct net_device *dev);
355static struct net_device_stats *do_get_stats(struct net_device *dev); 355static struct net_device_stats *do_get_stats(struct net_device *dev);
356static void set_addresses(struct net_device *dev); 356static void set_addresses(struct net_device *dev);
357static void set_multicast_list(struct net_device *dev); 357static void set_multicast_list(struct net_device *dev);
358static int set_card_type(dev_link_t *link, const void *s); 358static int set_card_type(struct pcmcia_device *link, const void *s);
359static int do_config(struct net_device *dev, struct ifmap *map); 359static int do_config(struct net_device *dev, struct ifmap *map);
360static int do_open(struct net_device *dev); 360static int do_open(struct net_device *dev);
361static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 361static int do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -368,7 +368,7 @@ static int do_stop(struct net_device *dev);
368 368
369/*=============== Helper functions =========================*/ 369/*=============== Helper functions =========================*/
370static int 370static int
371first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 371first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
372{ 372{
373 int err; 373 int err;
374 374
@@ -379,7 +379,7 @@ first_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse)
379} 379}
380 380
381static int 381static int
382next_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse) 382next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
383{ 383{
384 int err; 384 int err;
385 385
@@ -553,9 +553,8 @@ mii_wr(kio_addr_t ioaddr, u_char phyaddr, u_char phyreg, unsigned data, int len)
553 */ 553 */
554 554
555static int 555static int
556xirc2ps_attach(struct pcmcia_device *p_dev) 556xirc2ps_probe(struct pcmcia_device *link)
557{ 557{
558 dev_link_t *link;
559 struct net_device *dev; 558 struct net_device *dev;
560 local_info_t *local; 559 local_info_t *local;
561 560
@@ -566,12 +565,11 @@ xirc2ps_attach(struct pcmcia_device *p_dev)
566 if (!dev) 565 if (!dev)
567 return -ENOMEM; 566 return -ENOMEM;
568 local = netdev_priv(dev); 567 local = netdev_priv(dev);
569 link = &local->link; 568 local->p_dev = link;
570 link->priv = dev; 569 link->priv = dev;
571 570
572 /* General socket configuration */ 571 /* General socket configuration */
573 link->conf.Attributes = CONF_ENABLE_IRQ; 572 link->conf.Attributes = CONF_ENABLE_IRQ;
574 link->conf.Vcc = 50;
575 link->conf.IntType = INT_MEMORY_AND_IO; 573 link->conf.IntType = INT_MEMORY_AND_IO;
576 link->conf.ConfigIndex = 1; 574 link->conf.ConfigIndex = 1;
577 link->conf.Present = PRESENT_OPTION; 575 link->conf.Present = PRESENT_OPTION;
@@ -593,13 +591,7 @@ xirc2ps_attach(struct pcmcia_device *p_dev)
593 dev->watchdog_timeo = TX_TIMEOUT; 591 dev->watchdog_timeo = TX_TIMEOUT;
594#endif 592#endif
595 593
596 link->handle = p_dev; 594 return xirc2ps_config(link);
597 p_dev->instance = link;
598
599 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
600 xirc2ps_config(link);
601
602 return 0;
603} /* xirc2ps_attach */ 595} /* xirc2ps_attach */
604 596
605/**************** 597/****************
@@ -610,18 +602,16 @@ xirc2ps_attach(struct pcmcia_device *p_dev)
610 */ 602 */
611 603
612static void 604static void
613xirc2ps_detach(struct pcmcia_device *p_dev) 605xirc2ps_detach(struct pcmcia_device *link)
614{ 606{
615 dev_link_t *link = dev_to_instance(p_dev);
616 struct net_device *dev = link->priv; 607 struct net_device *dev = link->priv;
617 608
618 DEBUG(0, "detach(0x%p)\n", link); 609 DEBUG(0, "detach(0x%p)\n", link);
619 610
620 if (link->dev) 611 if (link->dev_node)
621 unregister_netdev(dev); 612 unregister_netdev(dev);
622 613
623 if (link->state & DEV_CONFIG) 614 xirc2ps_release(link);
624 xirc2ps_release(link);
625 615
626 free_netdev(dev); 616 free_netdev(dev);
627} /* xirc2ps_detach */ 617} /* xirc2ps_detach */
@@ -645,7 +635,7 @@ xirc2ps_detach(struct pcmcia_device *p_dev)
645 * 635 *
646 */ 636 */
647static int 637static int
648set_card_type(dev_link_t *link, const void *s) 638set_card_type(struct pcmcia_device *link, const void *s)
649{ 639{
650 struct net_device *dev = link->priv; 640 struct net_device *dev = link->priv;
651 local_info_t *local = netdev_priv(dev); 641 local_info_t *local = netdev_priv(dev);
@@ -714,9 +704,8 @@ set_card_type(dev_link_t *link, const void *s)
714 * Returns: true if this is a CE2 704 * Returns: true if this is a CE2
715 */ 705 */
716static int 706static int
717has_ce2_string(dev_link_t * link) 707has_ce2_string(struct pcmcia_device * link)
718{ 708{
719 client_handle_t handle = link->handle;
720 tuple_t tuple; 709 tuple_t tuple;
721 cisparse_t parse; 710 cisparse_t parse;
722 u_char buf[256]; 711 u_char buf[256];
@@ -726,7 +715,7 @@ has_ce2_string(dev_link_t * link)
726 tuple.TupleDataMax = 254; 715 tuple.TupleDataMax = 254;
727 tuple.TupleOffset = 0; 716 tuple.TupleOffset = 0;
728 tuple.DesiredTuple = CISTPL_VERS_1; 717 tuple.DesiredTuple = CISTPL_VERS_1;
729 if (!first_tuple(handle, &tuple, &parse) && parse.version_1.ns > 2) { 718 if (!first_tuple(link, &tuple, &parse) && parse.version_1.ns > 2) {
730 if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2")) 719 if (strstr(parse.version_1.str + parse.version_1.ofs[2], "CE2"))
731 return 1; 720 return 1;
732 } 721 }
@@ -738,10 +727,9 @@ has_ce2_string(dev_link_t * link)
738 * is received, to configure the PCMCIA socket, and to make the 727 * is received, to configure the PCMCIA socket, and to make the
739 * ethernet device available to the system. 728 * ethernet device available to the system.
740 */ 729 */
741static void 730static int
742xirc2ps_config(dev_link_t * link) 731xirc2ps_config(struct pcmcia_device * link)
743{ 732{
744 client_handle_t handle = link->handle;
745 struct net_device *dev = link->priv; 733 struct net_device *dev = link->priv;
746 local_info_t *local = netdev_priv(dev); 734 local_info_t *local = netdev_priv(dev);
747 tuple_t tuple; 735 tuple_t tuple;
@@ -767,7 +755,7 @@ xirc2ps_config(dev_link_t * link)
767 755
768 /* Is this a valid card */ 756 /* Is this a valid card */
769 tuple.DesiredTuple = CISTPL_MANFID; 757 tuple.DesiredTuple = CISTPL_MANFID;
770 if ((err=first_tuple(handle, &tuple, &parse))) { 758 if ((err=first_tuple(link, &tuple, &parse))) {
771 printk(KNOT_XIRC "manfid not found in CIS\n"); 759 printk(KNOT_XIRC "manfid not found in CIS\n");
772 goto failure; 760 goto failure;
773 } 761 }
@@ -803,15 +791,15 @@ xirc2ps_config(dev_link_t * link)
803 791
804 /* get configuration stuff */ 792 /* get configuration stuff */
805 tuple.DesiredTuple = CISTPL_CONFIG; 793 tuple.DesiredTuple = CISTPL_CONFIG;
806 if ((err=first_tuple(handle, &tuple, &parse))) 794 if ((err=first_tuple(link, &tuple, &parse)))
807 goto cis_error; 795 goto cis_error;
808 link->conf.ConfigBase = parse.config.base; 796 link->conf.ConfigBase = parse.config.base;
809 link->conf.Present = parse.config.rmask[0]; 797 link->conf.Present = parse.config.rmask[0];
810 798
811 /* get the ethernet address from the CIS */ 799 /* get the ethernet address from the CIS */
812 tuple.DesiredTuple = CISTPL_FUNCE; 800 tuple.DesiredTuple = CISTPL_FUNCE;
813 for (err = first_tuple(handle, &tuple, &parse); !err; 801 for (err = first_tuple(link, &tuple, &parse); !err;
814 err = next_tuple(handle, &tuple, &parse)) { 802 err = next_tuple(link, &tuple, &parse)) {
815 /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries: 803 /* Once I saw two CISTPL_FUNCE_LAN_NODE_ID entries:
816 * the first one with a length of zero the second correct - 804 * the first one with a length of zero the second correct -
817 * so I skip all entries with length 0 */ 805 * so I skip all entries with length 0 */
@@ -821,8 +809,8 @@ xirc2ps_config(dev_link_t * link)
821 } 809 }
822 if (err) { /* not found: try to get the node-id from tuple 0x89 */ 810 if (err) { /* not found: try to get the node-id from tuple 0x89 */
823 tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */ 811 tuple.DesiredTuple = 0x89; /* data layout looks like tuple 0x22 */
824 if ((err = pcmcia_get_first_tuple(handle, &tuple)) == 0 && 812 if ((err = pcmcia_get_first_tuple(link, &tuple)) == 0 &&
825 (err = pcmcia_get_tuple_data(handle, &tuple)) == 0) { 813 (err = pcmcia_get_tuple_data(link, &tuple)) == 0) {
826 if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID) 814 if (tuple.TupleDataLen == 8 && *buf == CISTPL_FUNCE_LAN_NODE_ID)
827 memcpy(&parse, buf, 8); 815 memcpy(&parse, buf, 8);
828 else 816 else
@@ -831,8 +819,8 @@ xirc2ps_config(dev_link_t * link)
831 } 819 }
832 if (err) { /* another try (James Lehmer's CE2 version 4.1)*/ 820 if (err) { /* another try (James Lehmer's CE2 version 4.1)*/
833 tuple.DesiredTuple = CISTPL_FUNCE; 821 tuple.DesiredTuple = CISTPL_FUNCE;
834 for (err = first_tuple(handle, &tuple, &parse); !err; 822 for (err = first_tuple(link, &tuple, &parse); !err;
835 err = next_tuple(handle, &tuple, &parse)) { 823 err = next_tuple(link, &tuple, &parse)) {
836 if (parse.funce.type == 0x02 && parse.funce.data[0] == 1 824 if (parse.funce.type == 0x02 && parse.funce.data[0] == 1
837 && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) { 825 && parse.funce.data[1] == 6 && tuple.TupleDataLen == 13) {
838 buf[1] = 4; 826 buf[1] = 4;
@@ -853,9 +841,6 @@ xirc2ps_config(dev_link_t * link)
853 for (i=0; i < 6; i++) 841 for (i=0; i < 6; i++)
854 dev->dev_addr[i] = node_id->id[i]; 842 dev->dev_addr[i] = node_id->id[i];
855 843
856 /* Configure card */
857 link->state |= DEV_CONFIG;
858
859 link->io.IOAddrLines =10; 844 link->io.IOAddrLines =10;
860 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 845 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
861 link->irq.Attributes = IRQ_HANDLE_PRESENT; 846 link->irq.Attributes = IRQ_HANDLE_PRESENT;
@@ -875,14 +860,14 @@ xirc2ps_config(dev_link_t * link)
875 * Ethernet port */ 860 * Ethernet port */
876 link->io.NumPorts1 = 16; /* no Mako stuff anymore */ 861 link->io.NumPorts1 = 16; /* no Mako stuff anymore */
877 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 862 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
878 for (err = first_tuple(handle, &tuple, &parse); !err; 863 for (err = first_tuple(link, &tuple, &parse); !err;
879 err = next_tuple(handle, &tuple, &parse)) { 864 err = next_tuple(link, &tuple, &parse)) {
880 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) { 865 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
881 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 866 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
882 link->conf.ConfigIndex = cf->index ; 867 link->conf.ConfigIndex = cf->index ;
883 link->io.BasePort2 = cf->io.win[0].base; 868 link->io.BasePort2 = cf->io.win[0].base;
884 link->io.BasePort1 = ioaddr; 869 link->io.BasePort1 = ioaddr;
885 if (!(err=pcmcia_request_io(link->handle, &link->io))) 870 if (!(err=pcmcia_request_io(link, &link->io)))
886 goto port_found; 871 goto port_found;
887 } 872 }
888 } 873 }
@@ -896,15 +881,15 @@ xirc2ps_config(dev_link_t * link)
896 */ 881 */
897 for (pass=0; pass < 2; pass++) { 882 for (pass=0; pass < 2; pass++) {
898 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 883 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
899 for (err = first_tuple(handle, &tuple, &parse); !err; 884 for (err = first_tuple(link, &tuple, &parse); !err;
900 err = next_tuple(handle, &tuple, &parse)){ 885 err = next_tuple(link, &tuple, &parse)){
901 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){ 886 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){
902 link->conf.ConfigIndex = cf->index ; 887 link->conf.ConfigIndex = cf->index ;
903 link->io.BasePort2 = cf->io.win[0].base; 888 link->io.BasePort2 = cf->io.win[0].base;
904 link->io.BasePort1 = link->io.BasePort2 889 link->io.BasePort1 = link->io.BasePort2
905 + (pass ? (cf->index & 0x20 ? -24:8) 890 + (pass ? (cf->index & 0x20 ? -24:8)
906 : (cf->index & 0x20 ? 8:-24)); 891 : (cf->index & 0x20 ? 8:-24));
907 if (!(err=pcmcia_request_io(link->handle, &link->io))) 892 if (!(err=pcmcia_request_io(link, &link->io)))
908 goto port_found; 893 goto port_found;
909 } 894 }
910 } 895 }
@@ -919,12 +904,12 @@ xirc2ps_config(dev_link_t * link)
919 link->io.NumPorts1 = 16; 904 link->io.NumPorts1 = 16;
920 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 905 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
921 link->io.BasePort1 = ioaddr; 906 link->io.BasePort1 = ioaddr;
922 if (!(err=pcmcia_request_io(link->handle, &link->io))) 907 if (!(err=pcmcia_request_io(link, &link->io)))
923 goto port_found; 908 goto port_found;
924 } 909 }
925 link->io.BasePort1 = 0; /* let CS decide */ 910 link->io.BasePort1 = 0; /* let CS decide */
926 if ((err=pcmcia_request_io(link->handle, &link->io))) { 911 if ((err=pcmcia_request_io(link, &link->io))) {
927 cs_error(link->handle, RequestIO, err); 912 cs_error(link, RequestIO, err);
928 goto config_error; 913 goto config_error;
929 } 914 }
930 } 915 }
@@ -936,8 +921,8 @@ xirc2ps_config(dev_link_t * link)
936 * Now allocate an interrupt line. Note that this does not 921 * Now allocate an interrupt line. Note that this does not
937 * actually assign a handler to the interrupt. 922 * actually assign a handler to the interrupt.
938 */ 923 */
939 if ((err=pcmcia_request_irq(link->handle, &link->irq))) { 924 if ((err=pcmcia_request_irq(link, &link->irq))) {
940 cs_error(link->handle, RequestIRQ, err); 925 cs_error(link, RequestIRQ, err);
941 goto config_error; 926 goto config_error;
942 } 927 }
943 928
@@ -945,8 +930,8 @@ xirc2ps_config(dev_link_t * link)
945 * This actually configures the PCMCIA socket -- setting up 930 * This actually configures the PCMCIA socket -- setting up
946 * the I/O windows and the interrupt mapping. 931 * the I/O windows and the interrupt mapping.
947 */ 932 */
948 if ((err=pcmcia_request_configuration(link->handle, &link->conf))) { 933 if ((err=pcmcia_request_configuration(link, &link->conf))) {
949 cs_error(link->handle, RequestConfiguration, err); 934 cs_error(link, RequestConfiguration, err);
950 goto config_error; 935 goto config_error;
951 } 936 }
952 937
@@ -963,15 +948,15 @@ xirc2ps_config(dev_link_t * link)
963 reg.Action = CS_WRITE; 948 reg.Action = CS_WRITE;
964 reg.Offset = CISREG_IOBASE_0; 949 reg.Offset = CISREG_IOBASE_0;
965 reg.Value = link->io.BasePort2 & 0xff; 950 reg.Value = link->io.BasePort2 & 0xff;
966 if ((err = pcmcia_access_configuration_register(link->handle, &reg))) { 951 if ((err = pcmcia_access_configuration_register(link, &reg))) {
967 cs_error(link->handle, AccessConfigurationRegister, err); 952 cs_error(link, AccessConfigurationRegister, err);
968 goto config_error; 953 goto config_error;
969 } 954 }
970 reg.Action = CS_WRITE; 955 reg.Action = CS_WRITE;
971 reg.Offset = CISREG_IOBASE_1; 956 reg.Offset = CISREG_IOBASE_1;
972 reg.Value = (link->io.BasePort2 >> 8) & 0xff; 957 reg.Value = (link->io.BasePort2 >> 8) & 0xff;
973 if ((err = pcmcia_access_configuration_register(link->handle, &reg))) { 958 if ((err = pcmcia_access_configuration_register(link, &reg))) {
974 cs_error(link->handle, AccessConfigurationRegister, err); 959 cs_error(link, AccessConfigurationRegister, err);
975 goto config_error; 960 goto config_error;
976 } 961 }
977 962
@@ -982,15 +967,15 @@ xirc2ps_config(dev_link_t * link)
982 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 967 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
983 req.Base = req.Size = 0; 968 req.Base = req.Size = 0;
984 req.AccessSpeed = 0; 969 req.AccessSpeed = 0;
985 if ((err = pcmcia_request_window(&link->handle, &req, &link->win))) { 970 if ((err = pcmcia_request_window(&link, &req, &link->win))) {
986 cs_error(link->handle, RequestWindow, err); 971 cs_error(link, RequestWindow, err);
987 goto config_error; 972 goto config_error;
988 } 973 }
989 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800; 974 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800;
990 mem.CardOffset = 0x0; 975 mem.CardOffset = 0x0;
991 mem.Page = 0; 976 mem.Page = 0;
992 if ((err = pcmcia_map_mem_page(link->win, &mem))) { 977 if ((err = pcmcia_map_mem_page(link->win, &mem))) {
993 cs_error(link->handle, MapMemPage, err); 978 cs_error(link, MapMemPage, err);
994 goto config_error; 979 goto config_error;
995 } 980 }
996 981
@@ -1050,13 +1035,12 @@ xirc2ps_config(dev_link_t * link)
1050 if (local->dingo) 1035 if (local->dingo)
1051 do_reset(dev, 1); /* a kludge to make the cem56 work */ 1036 do_reset(dev, 1); /* a kludge to make the cem56 work */
1052 1037
1053 link->dev = &local->node; 1038 link->dev_node = &local->node;
1054 link->state &= ~DEV_CONFIG_PENDING; 1039 SET_NETDEV_DEV(dev, &handle_to_dev(link));
1055 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
1056 1040
1057 if ((err=register_netdev(dev))) { 1041 if ((err=register_netdev(dev))) {
1058 printk(KNOT_XIRC "register_netdev() failed\n"); 1042 printk(KNOT_XIRC "register_netdev() failed\n");
1059 link->dev = NULL; 1043 link->dev_node = NULL;
1060 goto config_error; 1044 goto config_error;
1061 } 1045 }
1062 1046
@@ -1069,17 +1053,16 @@ xirc2ps_config(dev_link_t * link)
1069 printk("%c%02X", i?':':' ', dev->dev_addr[i]); 1053 printk("%c%02X", i?':':' ', dev->dev_addr[i]);
1070 printk("\n"); 1054 printk("\n");
1071 1055
1072 return; 1056 return 0;
1073 1057
1074 config_error: 1058 config_error:
1075 link->state &= ~DEV_CONFIG_PENDING;
1076 xirc2ps_release(link); 1059 xirc2ps_release(link);
1077 return; 1060 return -ENODEV;
1078 1061
1079 cis_error: 1062 cis_error:
1080 printk(KNOT_XIRC "unable to parse CIS\n"); 1063 printk(KNOT_XIRC "unable to parse CIS\n");
1081 failure: 1064 failure:
1082 link->state &= ~DEV_CONFIG_PENDING; 1065 return -ENODEV;
1083} /* xirc2ps_config */ 1066} /* xirc2ps_config */
1084 1067
1085/**************** 1068/****************
@@ -1088,57 +1071,41 @@ xirc2ps_config(dev_link_t * link)
1088 * still open, this will be postponed until it is closed. 1071 * still open, this will be postponed until it is closed.
1089 */ 1072 */
1090static void 1073static void
1091xirc2ps_release(dev_link_t *link) 1074xirc2ps_release(struct pcmcia_device *link)
1092{ 1075{
1076 DEBUG(0, "release(0x%p)\n", link);
1093 1077
1094 DEBUG(0, "release(0x%p)\n", link); 1078 if (link->win) {
1095 1079 struct net_device *dev = link->priv;
1096 if (link->win) { 1080 local_info_t *local = netdev_priv(dev);
1097 struct net_device *dev = link->priv; 1081 if (local->dingo)
1098 local_info_t *local = netdev_priv(dev); 1082 iounmap(local->dingo_ccr - 0x0800);
1099 if (local->dingo) 1083 }
1100 iounmap(local->dingo_ccr - 0x0800); 1084 pcmcia_disable_device(link);
1101 pcmcia_release_window(link->win);
1102 }
1103 pcmcia_release_configuration(link->handle);
1104 pcmcia_release_io(link->handle, &link->io);
1105 pcmcia_release_irq(link->handle, &link->irq);
1106 link->state &= ~DEV_CONFIG;
1107
1108} /* xirc2ps_release */ 1085} /* xirc2ps_release */
1109 1086
1110/*====================================================================*/ 1087/*====================================================================*/
1111 1088
1112 1089
1113static int xirc2ps_suspend(struct pcmcia_device *p_dev) 1090static int xirc2ps_suspend(struct pcmcia_device *link)
1114{ 1091{
1115 dev_link_t *link = dev_to_instance(p_dev);
1116 struct net_device *dev = link->priv; 1092 struct net_device *dev = link->priv;
1117 1093
1118 link->state |= DEV_SUSPEND; 1094 if (link->open) {
1119 if (link->state & DEV_CONFIG) { 1095 netif_device_detach(dev);
1120 if (link->open) { 1096 do_powerdown(dev);
1121 netif_device_detach(dev);
1122 do_powerdown(dev);
1123 }
1124 pcmcia_release_configuration(link->handle);
1125 } 1097 }
1126 1098
1127 return 0; 1099 return 0;
1128} 1100}
1129 1101
1130static int xirc2ps_resume(struct pcmcia_device *p_dev) 1102static int xirc2ps_resume(struct pcmcia_device *link)
1131{ 1103{
1132 dev_link_t *link = dev_to_instance(p_dev);
1133 struct net_device *dev = link->priv; 1104 struct net_device *dev = link->priv;
1134 1105
1135 link->state &= ~DEV_SUSPEND; 1106 if (link->open) {
1136 if (link->state & DEV_CONFIG) { 1107 do_reset(dev,1);
1137 pcmcia_request_configuration(link->handle, &link->conf); 1108 netif_device_attach(dev);
1138 if (link->open) {
1139 do_reset(dev,1);
1140 netif_device_attach(dev);
1141 }
1142 } 1109 }
1143 1110
1144 return 0; 1111 return 0;
@@ -1552,13 +1519,13 @@ static int
1552do_open(struct net_device *dev) 1519do_open(struct net_device *dev)
1553{ 1520{
1554 local_info_t *lp = netdev_priv(dev); 1521 local_info_t *lp = netdev_priv(dev);
1555 dev_link_t *link = &lp->link; 1522 struct pcmcia_device *link = lp->p_dev;
1556 1523
1557 DEBUG(0, "do_open(%p)\n", dev); 1524 DEBUG(0, "do_open(%p)\n", dev);
1558 1525
1559 /* Check that the PCMCIA card is still here. */ 1526 /* Check that the PCMCIA card is still here. */
1560 /* Physical device present signature. */ 1527 /* Physical device present signature. */
1561 if (!DEV_OK(link)) 1528 if (!pcmcia_dev_present(link))
1562 return -ENODEV; 1529 return -ENODEV;
1563 1530
1564 /* okay */ 1531 /* okay */
@@ -1882,7 +1849,7 @@ do_stop(struct net_device *dev)
1882{ 1849{
1883 kio_addr_t ioaddr = dev->base_addr; 1850 kio_addr_t ioaddr = dev->base_addr;
1884 local_info_t *lp = netdev_priv(dev); 1851 local_info_t *lp = netdev_priv(dev);
1885 dev_link_t *link = &lp->link; 1852 struct pcmcia_device *link = lp->p_dev;
1886 1853
1887 DEBUG(0, "do_stop(%p)\n", dev); 1854 DEBUG(0, "do_stop(%p)\n", dev);
1888 1855
@@ -1935,7 +1902,7 @@ static struct pcmcia_driver xirc2ps_cs_driver = {
1935 .drv = { 1902 .drv = {
1936 .name = "xirc2ps_cs", 1903 .name = "xirc2ps_cs",
1937 }, 1904 },
1938 .probe = xirc2ps_attach, 1905 .probe = xirc2ps_probe,
1939 .remove = xirc2ps_detach, 1906 .remove = xirc2ps_detach,
1940 .id_table = xirc2ps_ids, 1907 .id_table = xirc2ps_ids,
1941 .suspend = xirc2ps_suspend, 1908 .suspend = xirc2ps_suspend,
@@ -1973,7 +1940,7 @@ static int __init setup_xirc2ps_cs(char *str)
1973 MAYBE_SET(lockup_hack, 6); 1940 MAYBE_SET(lockup_hack, 6);
1974#undef MAYBE_SET 1941#undef MAYBE_SET
1975 1942
1976 return 0; 1943 return 1;
1977} 1944}
1978 1945
1979__setup("xirc2ps_cs=", setup_xirc2ps_cs); 1946__setup("xirc2ps_cs=", setup_xirc2ps_cs);
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 9595f74da93f..07c31f19c6ba 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -1167,8 +1167,8 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
1167 * station address PROM at the base address and programmed into the 1167 * station address PROM at the base address and programmed into the
1168 * "Physical Address Registers" CSR12-14. 1168 * "Physical Address Registers" CSR12-14.
1169 * As a precautionary measure, we read the PROM values and complain if 1169 * As a precautionary measure, we read the PROM values and complain if
1170 * they disagree with the CSRs. Either way, we use the CSR values, and 1170 * they disagree with the CSRs. If they miscompare, and the PROM addr
1171 * double check that they are valid. 1171 * is valid, then the PROM addr is used.
1172 */ 1172 */
1173 for (i = 0; i < 3; i++) { 1173 for (i = 0; i < 3; i++) {
1174 unsigned int val; 1174 unsigned int val;
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 35dbf05c7f06..a70c2b0cc104 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -78,6 +78,8 @@ static const struct pci_device_id skge_id_table[] = {
78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) }, 78 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
79 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) }, 79 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU) },
80 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), }, 80 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, PCI_DEVICE_ID_DLINK_DGE510T), },
81 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) },
82 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) },
81 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) }, 83 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4320) },
82 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */ 84 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5005) }, /* Belkin */
83 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) }, 85 { PCI_DEVICE(PCI_VENDOR_ID_CNET, PCI_DEVICE_ID_CNET_GIGACARD) },
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 68f9c206a620..67b0eab16589 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -99,8 +99,6 @@ MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
99static const struct pci_device_id sky2_id_table[] = { 99static const struct pci_device_id sky2_id_table[] = {
100 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) }, 100 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9000) },
101 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) }, 101 { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, 0x9E00) },
102 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b00) },
103 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4b01) },
104 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) }, 102 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4340) },
105 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) }, 103 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4341) },
106 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) }, 104 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4342) },
@@ -579,8 +577,8 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
579 reg = gma_read16(hw, port, GM_PHY_ADDR); 577 reg = gma_read16(hw, port, GM_PHY_ADDR);
580 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR); 578 gma_write16(hw, port, GM_PHY_ADDR, reg | GM_PAR_MIB_CLR);
581 579
582 for (i = 0; i < GM_MIB_CNT_SIZE; i++) 580 for (i = GM_MIB_CNT_BASE; i <= GM_MIB_CNT_END; i += 4)
583 gma_read16(hw, port, GM_MIB_CNT_BASE + 8 * i); 581 gma_read16(hw, port, i);
584 gma_write16(hw, port, GM_PHY_ADDR, reg); 582 gma_write16(hw, port, GM_PHY_ADDR, reg);
585 583
586 /* transmit control */ 584 /* transmit control */
diff --git a/drivers/net/sky2.h b/drivers/net/sky2.h
index 62532b4e45c5..89dd18cd12f0 100644
--- a/drivers/net/sky2.h
+++ b/drivers/net/sky2.h
@@ -1375,7 +1375,7 @@ enum {
1375 GM_PHY_ADDR = 0x0088, /* 16 bit r/w GPHY Address Register */ 1375 GM_PHY_ADDR = 0x0088, /* 16 bit r/w GPHY Address Register */
1376/* MIB Counters */ 1376/* MIB Counters */
1377 GM_MIB_CNT_BASE = 0x0100, /* Base Address of MIB Counters */ 1377 GM_MIB_CNT_BASE = 0x0100, /* Base Address of MIB Counters */
1378 GM_MIB_CNT_SIZE = 256, 1378 GM_MIB_CNT_END = 0x025C, /* Last MIB counter */
1379}; 1379};
1380 1380
1381 1381
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index 1f5975a61e1f..43f5e86fc559 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -1442,7 +1442,7 @@ spider_net_handle_error_irq(struct spider_net_card *card, u32 status_reg)
1442 case SPIDER_NET_GRFAFLLINT: /* fallthrough */ 1442 case SPIDER_NET_GRFAFLLINT: /* fallthrough */
1443 case SPIDER_NET_GRMFLLINT: 1443 case SPIDER_NET_GRMFLLINT:
1444 if (netif_msg_intr(card) && net_ratelimit()) 1444 if (netif_msg_intr(card) && net_ratelimit())
1445 pr_err("Spider RX RAM full, incoming packets " 1445 pr_debug("Spider RX RAM full, incoming packets "
1446 "might be discarded!\n"); 1446 "might be discarded!\n");
1447 spider_net_rx_irq_off(card); 1447 spider_net_rx_irq_off(card);
1448 tasklet_schedule(&card->rxram_full_tl); 1448 tasklet_schedule(&card->rxram_full_tl);
@@ -2086,7 +2086,7 @@ spider_net_setup_netdev(struct spider_net_card *card)
2086 2086
2087 spider_net_setup_netdev_ops(netdev); 2087 spider_net_setup_netdev_ops(netdev);
2088 2088
2089 netdev->features = 0; 2089 netdev->features = NETIF_F_HW_CSUM;
2090 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX | 2090 /* some time: NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
2091 * NETIF_F_HW_VLAN_FILTER */ 2091 * NETIF_F_HW_VLAN_FILTER */
2092 2092
diff --git a/drivers/net/starfire.c b/drivers/net/starfire.c
index 35b18057fbdd..9b7805be21da 100644
--- a/drivers/net/starfire.c
+++ b/drivers/net/starfire.c
@@ -335,7 +335,7 @@ do { \
335 335
336 336
337/* These identify the driver base version and may not be removed. */ 337/* These identify the driver base version and may not be removed. */
338static char version[] __devinitdata = 338static const char version[] __devinitdata =
339KERN_INFO "starfire.c:v1.03 7/26/2000 Written by Donald Becker <becker@scyld.com>\n" 339KERN_INFO "starfire.c:v1.03 7/26/2000 Written by Donald Becker <becker@scyld.com>\n"
340KERN_INFO " (unofficial 2.2/2.4 kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n"; 340KERN_INFO " (unofficial 2.2/2.4 kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n";
341 341
@@ -2122,8 +2122,7 @@ static void __devexit starfire_remove_one (struct pci_dev *pdev)
2122 struct net_device *dev = pci_get_drvdata(pdev); 2122 struct net_device *dev = pci_get_drvdata(pdev);
2123 struct netdev_private *np = netdev_priv(dev); 2123 struct netdev_private *np = netdev_priv(dev);
2124 2124
2125 if (!dev) 2125 BUG_ON(!dev);
2126 BUG();
2127 2126
2128 unregister_netdev(dev); 2127 unregister_netdev(dev);
2129 2128
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index b5473325bff4..73e271e59c6a 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -69,8 +69,8 @@
69 69
70#define DRV_MODULE_NAME "tg3" 70#define DRV_MODULE_NAME "tg3"
71#define PFX DRV_MODULE_NAME ": " 71#define PFX DRV_MODULE_NAME ": "
72#define DRV_MODULE_VERSION "3.54" 72#define DRV_MODULE_VERSION "3.56"
73#define DRV_MODULE_RELDATE "Mar 23, 2006" 73#define DRV_MODULE_RELDATE "Apr 1, 2006"
74 74
75#define TG3_DEF_MAC_MODE 0 75#define TG3_DEF_MAC_MODE 0
76#define TG3_DEF_RX_MODE 0 76#define TG3_DEF_RX_MODE 0
@@ -497,21 +497,20 @@ static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val)
497 unsigned long flags; 497 unsigned long flags;
498 498
499 spin_lock_irqsave(&tp->indirect_lock, flags); 499 spin_lock_irqsave(&tp->indirect_lock, flags);
500 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); 500 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
501 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); 501 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
502 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
502 503
503 /* Always leave this as zero. */ 504 /* Always leave this as zero. */
504 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); 505 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
505 spin_unlock_irqrestore(&tp->indirect_lock, flags); 506 } else {
506} 507 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
508 tw32_f(TG3PCI_MEM_WIN_DATA, val);
507 509
508static void tg3_write_mem_fast(struct tg3 *tp, u32 off, u32 val) 510 /* Always leave this as zero. */
509{ 511 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
510 /* If no workaround is needed, write to mem space directly */ 512 }
511 if (tp->write32 != tg3_write_indirect_reg32) 513 spin_unlock_irqrestore(&tp->indirect_lock, flags);
512 tw32(NIC_SRAM_WIN_BASE + off, val);
513 else
514 tg3_write_mem(tp, off, val);
515} 514}
516 515
517static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) 516static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
@@ -519,11 +518,19 @@ static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val)
519 unsigned long flags; 518 unsigned long flags;
520 519
521 spin_lock_irqsave(&tp->indirect_lock, flags); 520 spin_lock_irqsave(&tp->indirect_lock, flags);
522 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); 521 if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) {
523 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); 522 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off);
523 pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val);
524 524
525 /* Always leave this as zero. */ 525 /* Always leave this as zero. */
526 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); 526 pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0);
527 } else {
528 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off);
529 *val = tr32(TG3PCI_MEM_WIN_DATA);
530
531 /* Always leave this as zero. */
532 tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0);
533 }
527 spin_unlock_irqrestore(&tp->indirect_lock, flags); 534 spin_unlock_irqrestore(&tp->indirect_lock, flags);
528} 535}
529 536
@@ -1367,12 +1374,12 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
1367 } 1374 }
1368 } 1375 }
1369 1376
1377 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
1378
1370 /* Finally, set the new power state. */ 1379 /* Finally, set the new power state. */
1371 pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control); 1380 pci_write_config_word(tp->pdev, pm + PCI_PM_CTRL, power_control);
1372 udelay(100); /* Delay after power state change */ 1381 udelay(100); /* Delay after power state change */
1373 1382
1374 tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN);
1375
1376 return 0; 1383 return 0;
1377} 1384}
1378 1385
@@ -2959,9 +2966,7 @@ static void tg3_tx(struct tg3 *tp)
2959 struct sk_buff *skb = ri->skb; 2966 struct sk_buff *skb = ri->skb;
2960 int i; 2967 int i;
2961 2968
2962 if (unlikely(skb == NULL)) 2969 BUG_ON(skb == NULL);
2963 BUG();
2964
2965 pci_unmap_single(tp->pdev, 2970 pci_unmap_single(tp->pdev,
2966 pci_unmap_addr(ri, mapping), 2971 pci_unmap_addr(ri, mapping),
2967 skb_headlen(skb), 2972 skb_headlen(skb),
@@ -2972,12 +2977,10 @@ static void tg3_tx(struct tg3 *tp)
2972 sw_idx = NEXT_TX(sw_idx); 2977 sw_idx = NEXT_TX(sw_idx);
2973 2978
2974 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 2979 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
2975 if (unlikely(sw_idx == hw_idx)) 2980 BUG_ON(sw_idx == hw_idx);
2976 BUG();
2977 2981
2978 ri = &tp->tx_buffers[sw_idx]; 2982 ri = &tp->tx_buffers[sw_idx];
2979 if (unlikely(ri->skb != NULL)) 2983 BUG_ON(ri->skb != NULL);
2980 BUG();
2981 2984
2982 pci_unmap_page(tp->pdev, 2985 pci_unmap_page(tp->pdev,
2983 pci_unmap_addr(ri, mapping), 2986 pci_unmap_addr(ri, mapping),
@@ -3600,7 +3603,7 @@ static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping,
3600 int len) 3603 int len)
3601{ 3604{
3602#if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) 3605#if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64)
3603 if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) 3606 if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG)
3604 return (((u64) mapping + len) > DMA_40BIT_MASK); 3607 return (((u64) mapping + len) > DMA_40BIT_MASK);
3605 return 0; 3608 return 0;
3606#else 3609#else
@@ -4928,9 +4931,8 @@ static int tg3_halt_cpu(struct tg3 *tp, u32 offset)
4928{ 4931{
4929 int i; 4932 int i;
4930 4933
4931 if (offset == TX_CPU_BASE && 4934 BUG_ON(offset == TX_CPU_BASE &&
4932 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) 4935 (tp->tg3_flags2 & TG3_FLG2_5705_PLUS));
4933 BUG();
4934 4936
4935 if (offset == RX_CPU_BASE) { 4937 if (offset == RX_CPU_BASE) {
4936 for (i = 0; i < 10000; i++) { 4938 for (i = 0; i < 10000; i++) {
@@ -5833,10 +5835,14 @@ static int tg3_reset_hw(struct tg3 *tp)
5833 GRC_MODE_NO_TX_PHDR_CSUM | 5835 GRC_MODE_NO_TX_PHDR_CSUM |
5834 GRC_MODE_NO_RX_PHDR_CSUM); 5836 GRC_MODE_NO_RX_PHDR_CSUM);
5835 tp->grc_mode |= GRC_MODE_HOST_SENDBDS; 5837 tp->grc_mode |= GRC_MODE_HOST_SENDBDS;
5836 if (tp->tg3_flags & TG3_FLAG_NO_TX_PSEUDO_CSUM) 5838
5837 tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; 5839 /* Pseudo-header checksum is done by hardware logic and not
5838 if (tp->tg3_flags & TG3_FLAG_NO_RX_PSEUDO_CSUM) 5840 * the offload processers, so make the chip do the pseudo-
5839 tp->grc_mode |= GRC_MODE_NO_RX_PHDR_CSUM; 5841 * header checksums on receive. For transmit it is more
5842 * convenient to do the pseudo-header checksum in software
5843 * as Linux does that on transmit for us in all cases.
5844 */
5845 tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM;
5840 5846
5841 tw32(GRC_MODE, 5847 tw32(GRC_MODE,
5842 tp->grc_mode | 5848 tp->grc_mode |
@@ -6461,6 +6467,9 @@ static void tg3_timer(unsigned long __opaque)
6461{ 6467{
6462 struct tg3 *tp = (struct tg3 *) __opaque; 6468 struct tg3 *tp = (struct tg3 *) __opaque;
6463 6469
6470 if (tp->irq_sync)
6471 goto restart_timer;
6472
6464 spin_lock(&tp->lock); 6473 spin_lock(&tp->lock);
6465 6474
6466 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { 6475 if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) {
@@ -6537,11 +6546,11 @@ static void tg3_timer(unsigned long __opaque)
6537 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { 6546 if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) {
6538 u32 val; 6547 u32 val;
6539 6548
6540 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_MBOX, 6549 tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
6541 FWCMD_NICDRV_ALIVE2); 6550 FWCMD_NICDRV_ALIVE2);
6542 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); 6551 tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
6543 /* 5 seconds timeout */ 6552 /* 5 seconds timeout */
6544 tg3_write_mem_fast(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5); 6553 tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
6545 val = tr32(GRC_RX_CPU_EVENT); 6554 val = tr32(GRC_RX_CPU_EVENT);
6546 val |= (1 << 14); 6555 val |= (1 << 14);
6547 tw32(GRC_RX_CPU_EVENT, val); 6556 tw32(GRC_RX_CPU_EVENT, val);
@@ -6551,6 +6560,7 @@ static void tg3_timer(unsigned long __opaque)
6551 6560
6552 spin_unlock(&tp->lock); 6561 spin_unlock(&tp->lock);
6553 6562
6563restart_timer:
6554 tp->timer.expires = jiffies + tp->timer_offset; 6564 tp->timer.expires = jiffies + tp->timer_offset;
6555 add_timer(&tp->timer); 6565 add_timer(&tp->timer);
6556} 6566}
@@ -8035,9 +8045,13 @@ static int tg3_test_nvram(struct tg3 *tp)
8035 for (i = 0; i < size; i++) 8045 for (i = 0; i < size; i++)
8036 csum8 += buf8[i]; 8046 csum8 += buf8[i];
8037 8047
8038 if (csum8 == 0) 8048 if (csum8 == 0) {
8039 return 0; 8049 err = 0;
8040 return -EIO; 8050 goto out;
8051 }
8052
8053 err = -EIO;
8054 goto out;
8041 } 8055 }
8042 8056
8043 /* Bootstrap checksum at offset 0x10 */ 8057 /* Bootstrap checksum at offset 0x10 */
@@ -8399,8 +8413,11 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
8399 } 8413 }
8400 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | 8414 mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
8401 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII; 8415 MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII;
8402 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) 8416 if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
8403 mac_mode &= ~MAC_MODE_LINK_POLARITY; 8417 mac_mode &= ~MAC_MODE_LINK_POLARITY;
8418 tg3_writephy(tp, MII_TG3_EXT_CTRL,
8419 MII_TG3_EXT_CTRL_LNK3_LED_MODE);
8420 }
8404 tw32(MAC_MODE, mac_mode); 8421 tw32(MAC_MODE, mac_mode);
8405 } 8422 }
8406 else 8423 else
@@ -9529,8 +9546,11 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
9529 tp->led_ctrl = LED_CTRL_MODE_PHY_1; 9546 tp->led_ctrl = LED_CTRL_MODE_PHY_1;
9530 9547
9531 /* Do not even try poking around in here on Sun parts. */ 9548 /* Do not even try poking around in here on Sun parts. */
9532 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) 9549 if (tp->tg3_flags2 & TG3_FLG2_SUN_570X) {
9550 /* All SUN chips are built-in LOMs. */
9551 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
9533 return; 9552 return;
9553 }
9534 9554
9535 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); 9555 tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val);
9536 if (val == NIC_SRAM_DATA_SIG_MAGIC) { 9556 if (val == NIC_SRAM_DATA_SIG_MAGIC) {
@@ -9628,9 +9648,7 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
9628 tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) 9648 tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL)
9629 tp->led_ctrl = LED_CTRL_MODE_PHY_2; 9649 tp->led_ctrl = LED_CTRL_MODE_PHY_2;
9630 9650
9631 if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && 9651 if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP)
9632 (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) &&
9633 (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP))
9634 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT; 9652 tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT;
9635 9653
9636 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { 9654 if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) {
@@ -10255,6 +10273,13 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10255 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); 10273 pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd);
10256 } 10274 }
10257 10275
10276 if (tp->write32 == tg3_write_indirect_reg32 ||
10277 ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) &&
10278 (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 ||
10279 GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) ||
10280 (tp->tg3_flags2 & TG3_FLG2_SUN_570X))
10281 tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG;
10282
10258 /* Get eeprom hw config before calling tg3_set_power_state(). 10283 /* Get eeprom hw config before calling tg3_set_power_state().
10259 * In particular, the TG3_FLAG_EEPROM_WRITE_PROT flag must be 10284 * In particular, the TG3_FLAG_EEPROM_WRITE_PROT flag must be
10260 * determined before calling tg3_set_power_state() so that 10285 * determined before calling tg3_set_power_state() so that
@@ -10297,15 +10322,6 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
10297 if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0) 10322 if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0)
10298 tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS; 10323 tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS;
10299 10324
10300 /* Pseudo-header checksum is done by hardware logic and not
10301 * the offload processers, so make the chip do the pseudo-
10302 * header checksums on receive. For transmit it is more
10303 * convenient to do the pseudo-header checksum in software
10304 * as Linux does that on transmit for us in all cases.
10305 */
10306 tp->tg3_flags |= TG3_FLAG_NO_TX_PSEUDO_CSUM;
10307 tp->tg3_flags &= ~TG3_FLAG_NO_RX_PSEUDO_CSUM;
10308
10309 /* Derive initial jumbo mode from MTU assigned in 10325 /* Derive initial jumbo mode from MTU assigned in
10310 * ether_setup() via the alloc_etherdev() call 10326 * ether_setup() via the alloc_etherdev() call
10311 */ 10327 */
@@ -10531,6 +10547,7 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
10531{ 10547{
10532 struct net_device *dev = tp->dev; 10548 struct net_device *dev = tp->dev;
10533 u32 hi, lo, mac_offset; 10549 u32 hi, lo, mac_offset;
10550 int addr_ok = 0;
10534 10551
10535#ifdef CONFIG_SPARC64 10552#ifdef CONFIG_SPARC64
10536 if (!tg3_get_macaddr_sparc(tp)) 10553 if (!tg3_get_macaddr_sparc(tp))
@@ -10560,29 +10577,34 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
10560 dev->dev_addr[3] = (lo >> 16) & 0xff; 10577 dev->dev_addr[3] = (lo >> 16) & 0xff;
10561 dev->dev_addr[4] = (lo >> 8) & 0xff; 10578 dev->dev_addr[4] = (lo >> 8) & 0xff;
10562 dev->dev_addr[5] = (lo >> 0) & 0xff; 10579 dev->dev_addr[5] = (lo >> 0) & 0xff;
10563 }
10564 /* Next, try NVRAM. */
10565 else if (!(tp->tg3_flags & TG3_FLG2_SUN_570X) &&
10566 !tg3_nvram_read(tp, mac_offset + 0, &hi) &&
10567 !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
10568 dev->dev_addr[0] = ((hi >> 16) & 0xff);
10569 dev->dev_addr[1] = ((hi >> 24) & 0xff);
10570 dev->dev_addr[2] = ((lo >> 0) & 0xff);
10571 dev->dev_addr[3] = ((lo >> 8) & 0xff);
10572 dev->dev_addr[4] = ((lo >> 16) & 0xff);
10573 dev->dev_addr[5] = ((lo >> 24) & 0xff);
10574 }
10575 /* Finally just fetch it out of the MAC control regs. */
10576 else {
10577 hi = tr32(MAC_ADDR_0_HIGH);
10578 lo = tr32(MAC_ADDR_0_LOW);
10579 10580
10580 dev->dev_addr[5] = lo & 0xff; 10581 /* Some old bootcode may report a 0 MAC address in SRAM */
10581 dev->dev_addr[4] = (lo >> 8) & 0xff; 10582 addr_ok = is_valid_ether_addr(&dev->dev_addr[0]);
10582 dev->dev_addr[3] = (lo >> 16) & 0xff; 10583 }
10583 dev->dev_addr[2] = (lo >> 24) & 0xff; 10584 if (!addr_ok) {
10584 dev->dev_addr[1] = hi & 0xff; 10585 /* Next, try NVRAM. */
10585 dev->dev_addr[0] = (hi >> 8) & 0xff; 10586 if (!(tp->tg3_flags & TG3_FLG2_SUN_570X) &&
10587 !tg3_nvram_read(tp, mac_offset + 0, &hi) &&
10588 !tg3_nvram_read(tp, mac_offset + 4, &lo)) {
10589 dev->dev_addr[0] = ((hi >> 16) & 0xff);
10590 dev->dev_addr[1] = ((hi >> 24) & 0xff);
10591 dev->dev_addr[2] = ((lo >> 0) & 0xff);
10592 dev->dev_addr[3] = ((lo >> 8) & 0xff);
10593 dev->dev_addr[4] = ((lo >> 16) & 0xff);
10594 dev->dev_addr[5] = ((lo >> 24) & 0xff);
10595 }
10596 /* Finally just fetch it out of the MAC control regs. */
10597 else {
10598 hi = tr32(MAC_ADDR_0_HIGH);
10599 lo = tr32(MAC_ADDR_0_LOW);
10600
10601 dev->dev_addr[5] = lo & 0xff;
10602 dev->dev_addr[4] = (lo >> 8) & 0xff;
10603 dev->dev_addr[3] = (lo >> 16) & 0xff;
10604 dev->dev_addr[2] = (lo >> 24) & 0xff;
10605 dev->dev_addr[1] = hi & 0xff;
10606 dev->dev_addr[0] = (hi >> 8) & 0xff;
10607 }
10586 } 10608 }
10587 10609
10588 if (!is_valid_ether_addr(&dev->dev_addr[0])) { 10610 if (!is_valid_ether_addr(&dev->dev_addr[0])) {
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index c43cc3264202..8c8b987d1250 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2171,8 +2171,7 @@ struct tg3 {
2171#define TG3_FLAG_PCIX_MODE 0x00020000 2171#define TG3_FLAG_PCIX_MODE 0x00020000
2172#define TG3_FLAG_PCI_HIGH_SPEED 0x00040000 2172#define TG3_FLAG_PCI_HIGH_SPEED 0x00040000
2173#define TG3_FLAG_PCI_32BIT 0x00080000 2173#define TG3_FLAG_PCI_32BIT 0x00080000
2174#define TG3_FLAG_NO_TX_PSEUDO_CSUM 0x00100000 2174#define TG3_FLAG_SRAM_USE_CONFIG 0x00100000
2175#define TG3_FLAG_NO_RX_PSEUDO_CSUM 0x00200000
2176#define TG3_FLAG_SERDES_WOL_CAP 0x00400000 2175#define TG3_FLAG_SERDES_WOL_CAP 0x00400000
2177#define TG3_FLAG_JUMBO_RING_ENABLE 0x00800000 2176#define TG3_FLAG_JUMBO_RING_ENABLE 0x00800000
2178#define TG3_FLAG_10_100_ONLY 0x01000000 2177#define TG3_FLAG_10_100_ONLY 0x01000000
diff --git a/drivers/net/tokenring/Kconfig b/drivers/net/tokenring/Kconfig
index e4cfc80b283b..99c4c1922f19 100644
--- a/drivers/net/tokenring/Kconfig
+++ b/drivers/net/tokenring/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menu "Token Ring devices" 5menu "Token Ring devices"
6 depends on NETDEVICES 6 depends on NETDEVICES && !UML
7 7
8# So far, we only have PCI, ISA, and MCA token ring devices 8# So far, we only have PCI, ISA, and MCA token ring devices
9config TR 9config TR
diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
index 9345e68c451e..649d8ea354f5 100644
--- a/drivers/net/tokenring/abyss.c
+++ b/drivers/net/tokenring/abyss.c
@@ -438,8 +438,7 @@ static void __devexit abyss_detach (struct pci_dev *pdev)
438{ 438{
439 struct net_device *dev = pci_get_drvdata(pdev); 439 struct net_device *dev = pci_get_drvdata(pdev);
440 440
441 if (!dev) 441 BUG_ON(!dev);
442 BUG();
443 unregister_netdev(dev); 442 unregister_netdev(dev);
444 release_region(dev->base_addr-0x10, ABYSS_IO_EXTENT); 443 release_region(dev->base_addr-0x10, ABYSS_IO_EXTENT);
445 free_irq(dev->irq, dev); 444 free_irq(dev->irq, dev);
diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
index 3a25d191ea4a..19e6f4dfd69c 100644
--- a/drivers/net/tokenring/madgemc.c
+++ b/drivers/net/tokenring/madgemc.c
@@ -735,8 +735,7 @@ static int __devexit madgemc_remove(struct device *device)
735 struct net_local *tp; 735 struct net_local *tp;
736 struct card_info *card; 736 struct card_info *card;
737 737
738 if (!dev) 738 BUG_ON(!dev);
739 BUG();
740 739
741 tp = dev->priv; 740 tp = dev->priv;
742 card = tp->tmspriv; 741 card = tp->tmspriv;
diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
index d1a86a080a65..f56094102042 100644
--- a/drivers/net/tulip/de4x5.c
+++ b/drivers/net/tulip/de4x5.c
@@ -4160,7 +4160,7 @@ get_hw_addr(struct net_device *dev)
4160 ** If the address starts with 00 a0, we have to bit-reverse 4160 ** If the address starts with 00 a0, we have to bit-reverse
4161 ** each byte of the address. 4161 ** each byte of the address.
4162 */ 4162 */
4163 if ( (_machine & _MACH_Pmac) && 4163 if ( machine_is(powermac) &&
4164 (dev->dev_addr[0] == 0) && 4164 (dev->dev_addr[0] == 0) &&
4165 (dev->dev_addr[1] == 0xa0) ) 4165 (dev->dev_addr[1] == 0xa0) )
4166 { 4166 {
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index c1ce87a5f8d3..d9258d42090c 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -134,7 +134,7 @@ static const int multicast_filter_limit = 32;
134#include "typhoon.h" 134#include "typhoon.h"
135#include "typhoon-firmware.h" 135#include "typhoon-firmware.h"
136 136
137static char version[] __devinitdata = 137static const char version[] __devinitdata =
138 "typhoon.c: version " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; 138 "typhoon.c: version " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
139 139
140MODULE_AUTHOR("David Dillow <dave@thedillows.org>"); 140MODULE_AUTHOR("David Dillow <dave@thedillows.org>");
diff --git a/drivers/net/via-rhine.c b/drivers/net/via-rhine.c
index 241871589283..6a23964c1317 100644
--- a/drivers/net/via-rhine.c
+++ b/drivers/net/via-rhine.c
@@ -469,7 +469,7 @@ struct rhine_private {
469 struct sk_buff *tx_skbuff[TX_RING_SIZE]; 469 struct sk_buff *tx_skbuff[TX_RING_SIZE];
470 dma_addr_t tx_skbuff_dma[TX_RING_SIZE]; 470 dma_addr_t tx_skbuff_dma[TX_RING_SIZE];
471 471
472 /* Tx bounce buffers */ 472 /* Tx bounce buffers (Rhine-I only) */
473 unsigned char *tx_buf[TX_RING_SIZE]; 473 unsigned char *tx_buf[TX_RING_SIZE];
474 unsigned char *tx_bufs; 474 unsigned char *tx_bufs;
475 dma_addr_t tx_bufs_dma; 475 dma_addr_t tx_bufs_dma;
@@ -1043,7 +1043,8 @@ static void alloc_tbufs(struct net_device* dev)
1043 rp->tx_ring[i].desc_length = cpu_to_le32(TXDESC); 1043 rp->tx_ring[i].desc_length = cpu_to_le32(TXDESC);
1044 next += sizeof(struct tx_desc); 1044 next += sizeof(struct tx_desc);
1045 rp->tx_ring[i].next_desc = cpu_to_le32(next); 1045 rp->tx_ring[i].next_desc = cpu_to_le32(next);
1046 rp->tx_buf[i] = &rp->tx_bufs[i * PKT_BUF_SZ]; 1046 if (rp->quirks & rqRhineI)
1047 rp->tx_buf[i] = &rp->tx_bufs[i * PKT_BUF_SZ];
1047 } 1048 }
1048 rp->tx_ring[i-1].next_desc = cpu_to_le32(rp->tx_ring_dma); 1049 rp->tx_ring[i-1].next_desc = cpu_to_le32(rp->tx_ring_dma);
1049 1050
@@ -1085,6 +1086,25 @@ static void rhine_check_media(struct net_device *dev, unsigned int init_media)
1085 else 1086 else
1086 iowrite8(ioread8(ioaddr + ChipCmd1) & ~Cmd1FDuplex, 1087 iowrite8(ioread8(ioaddr + ChipCmd1) & ~Cmd1FDuplex,
1087 ioaddr + ChipCmd1); 1088 ioaddr + ChipCmd1);
1089 if (debug > 1)
1090 printk(KERN_INFO "%s: force_media %d, carrier %d\n", dev->name,
1091 rp->mii_if.force_media, netif_carrier_ok(dev));
1092}
1093
1094/* Called after status of force_media possibly changed */
1095static void rhine_set_carrier(struct mii_if_info *mii)
1096{
1097 if (mii->force_media) {
1098 /* autoneg is off: Link is always assumed to be up */
1099 if (!netif_carrier_ok(mii->dev))
1100 netif_carrier_on(mii->dev);
1101 }
1102 else /* Let MMI library update carrier status */
1103 rhine_check_media(mii->dev, 0);
1104 if (debug > 1)
1105 printk(KERN_INFO "%s: force_media %d, carrier %d\n",
1106 mii->dev->name, mii->force_media,
1107 netif_carrier_ok(mii->dev));
1088} 1108}
1089 1109
1090static void rhine_check_media_task(struct net_device *dev) 1110static void rhine_check_media_task(struct net_device *dev)
@@ -1782,6 +1802,7 @@ static int netdev_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
1782 spin_lock_irq(&rp->lock); 1802 spin_lock_irq(&rp->lock);
1783 rc = mii_ethtool_sset(&rp->mii_if, cmd); 1803 rc = mii_ethtool_sset(&rp->mii_if, cmd);
1784 spin_unlock_irq(&rp->lock); 1804 spin_unlock_irq(&rp->lock);
1805 rhine_set_carrier(&rp->mii_if);
1785 1806
1786 return rc; 1807 return rc;
1787} 1808}
@@ -1869,6 +1890,7 @@ static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1869 spin_lock_irq(&rp->lock); 1890 spin_lock_irq(&rp->lock);
1870 rc = generic_mii_ioctl(&rp->mii_if, if_mii(rq), cmd, NULL); 1891 rc = generic_mii_ioctl(&rp->mii_if, if_mii(rq), cmd, NULL);
1871 spin_unlock_irq(&rp->lock); 1892 spin_unlock_irq(&rp->lock);
1893 rhine_set_carrier(&rp->mii_if);
1872 1894
1873 return rc; 1895 return rc;
1874} 1896}
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 883cf7da10fc..b5328b0ff927 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -410,103 +410,6 @@ config WAN_ROUTER_DRIVERS
410 410
411 If unsure, say N. 411 If unsure, say N.
412 412
413config VENDOR_SANGOMA
414 tristate "Sangoma WANPIPE(tm) multiprotocol cards"
415 depends on WAN_ROUTER_DRIVERS && WAN_ROUTER && (PCI || ISA) && BROKEN
416 ---help---
417 Driver for S514-PCI/ISA Synchronous Data Link Adapters (SDLA).
418
419 WANPIPE from Sangoma Technologies Inc. <http://www.sangoma.com/>
420 is a family of intelligent multiprotocol WAN adapters with data
421 transfer rates up to 4Mbps. Cards support:
422
423 - X.25, Frame Relay, PPP, Cisco HDLC protocols.
424
425 - API for protocols like HDLC (LAPB), HDLC Streaming, X.25,
426 Frame Relay and BiSync.
427
428 - Ethernet Bridging over Frame Relay protocol.
429
430 - MULTILINK PPP
431
432 - Async PPP (Modem Dialup)
433
434 The next questions will ask you about the protocols you want
435 the driver to support.
436
437 If you have one or more of these cards, say M to this option;
438 and read <file:Documentation/networking/wan-router.txt>.
439
440 To compile this driver as a module, choose M here: the
441 module will be called wanpipe.
442
443config WANPIPE_CHDLC
444 bool "WANPIPE Cisco HDLC support"
445 depends on VENDOR_SANGOMA
446 ---help---
447 Connect a WANPIPE card to a leased line using the Cisco HDLC.
448
449 - Supports Dual Port Cisco HDLC on the S514-PCI/S508-ISA cards
450 which allows user to build applications using the HDLC streaming API.
451
452 - CHDLC Streaming MULTILINK PPP that can bind multiple WANPIPE T1
453 cards into a single logical channel.
454
455 Say Y and the Cisco HDLC support, HDLC streaming API and
456 MULTILINK PPP will be included in the driver.
457
458config WANPIPE_FR
459 bool "WANPIPE Frame Relay support"
460 depends on VENDOR_SANGOMA
461 help
462 Connect a WANPIPE card to a Frame Relay network, or use Frame Relay
463 API to develop custom applications.
464
465 Contains the Ethernet Bridging over Frame Relay feature, where
466 a WANPIPE frame relay link can be directly connected to the Linux
467 kernel bridge. The Frame Relay option is supported on S514-PCI
468 and S508-ISA cards.
469
470 Say Y and the Frame Relay support will be included in the driver.
471
472config WANPIPE_X25
473 bool "WANPIPE X.25 support"
474 depends on VENDOR_SANGOMA
475 help
476 Connect a WANPIPE card to an X.25 network.
477
478 Includes the X.25 API support for custom applications over the
479 X.25 protocol. The X.25 option is supported on S514-PCI and
480 S508-ISA cards.
481
482 Say Y and the X.25 support will be included in the driver.
483
484config WANPIPE_PPP
485 bool "WANPIPE PPP support"
486 depends on VENDOR_SANGOMA
487 help
488 Connect a WANPIPE card to a leased line using Point-to-Point
489 Protocol (PPP).
490
491 The PPP option is supported on S514-PCI/S508-ISA cards.
492
493 Say Y and the PPP support will be included in the driver.
494
495config WANPIPE_MULTPPP
496 bool "WANPIPE Multi-Port PPP support"
497 depends on VENDOR_SANGOMA
498 help
499 Connect a WANPIPE card to a leased line using Point-to-Point
500 Protocol (PPP).
501
502 Uses in-kernel SyncPPP protocol over the Sangoma HDLC Streaming
503 adapter. In this case each Sangoma adapter port can support an
504 independent PPP connection. For example, a single Quad-Port PCI
505 adapter can support up to four independent PPP links. The PPP
506 option is supported on S514-PCI/S508-ISA cards.
507
508 Say Y and the Multi-Port PPP support will be included in the driver.
509
510config CYCLADES_SYNC 413config CYCLADES_SYNC
511 tristate "Cyclom 2X(tm) cards (EXPERIMENTAL)" 414 tristate "Cyclom 2X(tm) cards (EXPERIMENTAL)"
512 depends on WAN_ROUTER_DRIVERS && (PCI || ISA) 415 depends on WAN_ROUTER_DRIVERS && (PCI || ISA)
diff --git a/drivers/net/wan/Makefile b/drivers/net/wan/Makefile
index ce6c56b903e7..823c6d5ab90d 100644
--- a/drivers/net/wan/Makefile
+++ b/drivers/net/wan/Makefile
@@ -5,14 +5,6 @@
5# Rewritten to use lists instead of if-statements. 5# Rewritten to use lists instead of if-statements.
6# 6#
7 7
8wanpipe-y := sdlamain.o sdla_ft1.o
9wanpipe-$(CONFIG_WANPIPE_X25) += sdla_x25.o
10wanpipe-$(CONFIG_WANPIPE_FR) += sdla_fr.o
11wanpipe-$(CONFIG_WANPIPE_CHDLC) += sdla_chdlc.o
12wanpipe-$(CONFIG_WANPIPE_PPP) += sdla_ppp.o
13wanpipe-$(CONFIG_WANPIPE_MULTPPP) += wanpipe_multppp.o
14wanpipe-objs := $(wanpipe-y)
15
16cyclomx-y := cycx_main.o 8cyclomx-y := cycx_main.o
17cyclomx-$(CONFIG_CYCLOMX_X25) += cycx_x25.o 9cyclomx-$(CONFIG_CYCLOMX_X25) += cycx_x25.o
18cyclomx-objs := $(cyclomx-y) 10cyclomx-objs := $(cyclomx-y)
@@ -43,11 +35,6 @@ obj-$(CONFIG_LANMEDIA) += lmc/
43 35
44obj-$(CONFIG_DLCI) += dlci.o 36obj-$(CONFIG_DLCI) += dlci.o
45obj-$(CONFIG_SDLA) += sdla.o 37obj-$(CONFIG_SDLA) += sdla.o
46ifeq ($(CONFIG_WANPIPE_MULTPPP),y)
47 obj-$(CONFIG_VENDOR_SANGOMA) += sdladrv.o wanpipe.o syncppp.o
48else
49 obj-$(CONFIG_VENDOR_SANGOMA) += sdladrv.o wanpipe.o
50endif
51obj-$(CONFIG_CYCLADES_SYNC) += cycx_drv.o cyclomx.o 38obj-$(CONFIG_CYCLADES_SYNC) += cycx_drv.o cyclomx.o
52obj-$(CONFIG_LAPBETHER) += lapbether.o 39obj-$(CONFIG_LAPBETHER) += lapbether.o
53obj-$(CONFIG_SBNI) += sbni.o 40obj-$(CONFIG_SBNI) += sbni.o
diff --git a/drivers/net/wan/sdla_chdlc.c b/drivers/net/wan/sdla_chdlc.c
deleted file mode 100644
index 496d29237e92..000000000000
--- a/drivers/net/wan/sdla_chdlc.c
+++ /dev/null
@@ -1,4428 +0,0 @@
1/*****************************************************************************
2* sdla_chdlc.c WANPIPE(tm) Multiprotocol WAN Link Driver. Cisco HDLC module.
3*
4* Authors: Nenad Corbic <ncorbic@sangoma.com>
5* Gideon Hack
6*
7* Copyright: (c) 1995-2001 Sangoma Technologies Inc.
8*
9* This program is free software; you can redistribute it and/or
10* modify it under the terms of the GNU General Public License
11* as published by the Free Software Foundation; either version
12* 2 of the License, or (at your option) any later version.
13* ============================================================================
14* Feb 28, 2001 Nenad Corbic Updated if_tx_timeout() routine for
15* 2.4.X kernels.
16* Jan 25, 2001 Nenad Corbic Added a TTY Sync serial driver over the
17* HDLC streaming protocol
18* Added a TTY Async serial driver over the
19* Async protocol.
20* Dec 15, 2000 Nenad Corbic Updated for 2.4.X Kernel support
21* Nov 13, 2000 Nenad Corbic Added true interface type encoding option.
22* Tcpdump doesn't support CHDLC inteface
23* types, to fix this "true type" option will set
24* the interface type to RAW IP mode.
25* Nov 07, 2000 Nenad Corbic Added security features for UDP debugging:
26* Deny all and specify allowed requests.
27* Jun 20, 2000 Nenad Corbic Fixed the API IP ERROR bug. Caused by the
28* latest update.
29* May 09, 2000 Nenad Corbic Option to bring down an interface
30* upon disconnect.
31* Mar 23, 2000 Nenad Corbic Improved task queue, bh handling.
32* Mar 16, 2000 Nenad Corbic Fixed the SLARP Dynamic IP addressing.
33* Mar 06, 2000 Nenad Corbic Bug Fix: corrupted mbox recovery.
34* Feb 10, 2000 Gideon Hack Added ASYNC support.
35* Feb 09, 2000 Nenad Corbic Fixed two shutdown bugs in update() and
36* if_stats() functions.
37* Jan 24, 2000 Nenad Corbic Fixed a startup wanpipe state racing,
38* condition between if_open and isr.
39* Jan 10, 2000 Nenad Corbic Added new socket API support.
40* Dev 15, 1999 Nenad Corbic Fixed up header files for 2.0.X kernels
41* Nov 20, 1999 Nenad Corbic Fixed zero length API bug.
42* Sep 30, 1999 Nenad Corbic Fixed dynamic IP and route setup.
43* Sep 23, 1999 Nenad Corbic Added SMP support, fixed tracing
44* Sep 13, 1999 Nenad Corbic Split up Port 0 and 1 into separate devices.
45* Jun 02, 1999 Gideon Hack Added support for the S514 adapter.
46* Oct 30, 1998 Jaspreet Singh Added Support for CHDLC API (HDLC STREAMING).
47* Oct 28, 1998 Jaspreet Singh Added Support for Dual Port CHDLC.
48* Aug 07, 1998 David Fong Initial version.
49*****************************************************************************/
50
51#include <linux/module.h>
52#include <linux/kernel.h> /* printk(), and other useful stuff */
53#include <linux/stddef.h> /* offsetof(), etc. */
54#include <linux/errno.h> /* return codes */
55#include <linux/string.h> /* inline memset(), etc. */
56#include <linux/slab.h> /* kmalloc(), kfree() */
57#include <linux/wanrouter.h> /* WAN router definitions */
58#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
59#include <linux/if_arp.h> /* ARPHRD_* defines */
60
61
62#include <asm/uaccess.h>
63#include <linux/inetdevice.h>
64#include <linux/netdevice.h>
65
66#include <linux/in.h> /* sockaddr_in */
67#include <linux/inet.h>
68#include <linux/if.h>
69#include <asm/byteorder.h> /* htons(), etc. */
70#include <linux/sdlapci.h>
71#include <asm/io.h>
72
73#include <linux/sdla_chdlc.h> /* CHDLC firmware API definitions */
74#include <linux/sdla_asy.h> /* CHDLC (async) API definitions */
75
76#include <linux/if_wanpipe_common.h> /* Socket Driver common area */
77#include <linux/if_wanpipe.h>
78
79/* TTY Includes */
80#include <linux/tty.h>
81#include <linux/tty_flip.h>
82#include <linux/serial.h>
83
84
85/****** Defines & Macros ****************************************************/
86
87/* reasons for enabling the timer interrupt on the adapter */
88#define TMR_INT_ENABLED_UDP 0x01
89#define TMR_INT_ENABLED_UPDATE 0x02
90#define TMR_INT_ENABLED_CONFIG 0x10
91
92#define MAX_IP_ERRORS 10
93
94#define TTY_CHDLC_MAX_MTU 2000
95#define CHDLC_DFLT_DATA_LEN 1500 /* default MTU */
96#define CHDLC_HDR_LEN 1
97
98#define CHDLC_API 0x01
99
100#define PORT(x) (x == 0 ? "PRIMARY" : "SECONDARY" )
101#define MAX_BH_BUFF 10
102
103//#define PRINT_DEBUG
104#ifdef PRINT_DEBUG
105#define dbg_printk(format, a...) printk(format, ## a)
106#else
107#define dbg_printk(format, a...)
108#endif
109
110/******Data Structures*****************************************************/
111
112/* This structure is placed in the private data area of the device structure.
113 * The card structure used to occupy the private area but now the following
114 * structure will incorporate the card structure along with CHDLC specific data
115 */
116
117typedef struct chdlc_private_area
118{
119 wanpipe_common_t common;
120 sdla_t *card;
121 int TracingEnabled; /* For enabling Tracing */
122 unsigned long curr_trace_addr; /* Used for Tracing */
123 unsigned long start_trace_addr;
124 unsigned long end_trace_addr;
125 unsigned long base_addr_trace_buffer;
126 unsigned long end_addr_trace_buffer;
127 unsigned short number_trace_elements;
128 unsigned available_buffer_space;
129 unsigned long router_start_time;
130 unsigned char route_status;
131 unsigned char route_removed;
132 unsigned long tick_counter; /* For 5s timeout counter */
133 unsigned long router_up_time;
134 u32 IP_address; /* IP addressing */
135 u32 IP_netmask;
136 u32 ip_local;
137 u32 ip_remote;
138 u32 ip_local_tmp;
139 u32 ip_remote_tmp;
140 u8 ip_error;
141 u8 config_chdlc;
142 u8 config_chdlc_timeout;
143 unsigned char mc; /* Mulitcast support on/off */
144 unsigned short udp_pkt_lgth; /* udp packet processing */
145 char udp_pkt_src;
146 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
147 unsigned short timer_int_enabled;
148 char update_comms_stats; /* updating comms stats */
149
150 bh_data_t *bh_head; /* Circular buffer for chdlc_bh */
151 unsigned long tq_working;
152 volatile int bh_write;
153 volatile int bh_read;
154 atomic_t bh_buff_used;
155
156 unsigned char interface_down;
157
158 /* Polling work queue entry. Each interface
159 * has its own work queue entry, which is used
160 * to defer events from the interrupt */
161 struct work_struct poll_work;
162 struct timer_list poll_delay_timer;
163
164 u8 gateway;
165 u8 true_if_encoding;
166 //FIXME: add driver stats as per frame relay!
167
168} chdlc_private_area_t;
169
170/* Route Status options */
171#define NO_ROUTE 0x00
172#define ADD_ROUTE 0x01
173#define ROUTE_ADDED 0x02
174#define REMOVE_ROUTE 0x03
175
176
177/* variable for keeping track of enabling/disabling FT1 monitor status */
178static int rCount = 0;
179
180/* variable for tracking how many interfaces to open for WANPIPE on the
181 two ports */
182
183extern void disable_irq(unsigned int);
184extern void enable_irq(unsigned int);
185
186/****** Function Prototypes *************************************************/
187/* WAN link driver entry points. These are called by the WAN router module. */
188static int update(struct wan_device* wandev);
189static int new_if(struct wan_device* wandev, struct net_device* dev,
190 wanif_conf_t* conf);
191
192/* Network device interface */
193static int if_init(struct net_device* dev);
194static int if_open(struct net_device* dev);
195static int if_close(struct net_device* dev);
196static int if_header(struct sk_buff* skb, struct net_device* dev,
197 unsigned short type, void* daddr, void* saddr,
198 unsigned len);
199
200static int if_rebuild_hdr (struct sk_buff *skb);
201static struct net_device_stats* if_stats(struct net_device* dev);
202
203static int if_send(struct sk_buff* skb, struct net_device* dev);
204
205/* CHDLC Firmware interface functions */
206static int chdlc_configure (sdla_t* card, void* data);
207static int chdlc_comm_enable (sdla_t* card);
208static int chdlc_read_version (sdla_t* card, char* str);
209static int chdlc_set_intr_mode (sdla_t* card, unsigned mode);
210static int chdlc_send (sdla_t* card, void* data, unsigned len);
211static int chdlc_read_comm_err_stats (sdla_t* card);
212static int chdlc_read_op_stats (sdla_t* card);
213static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb);
214
215
216static int chdlc_disable_comm_shutdown (sdla_t *card);
217static void if_tx_timeout(struct net_device *dev);
218
219/* Miscellaneous CHDLC Functions */
220static int set_chdlc_config (sdla_t* card);
221static void init_chdlc_tx_rx_buff( sdla_t* card);
222static int process_chdlc_exception(sdla_t *card);
223static int process_global_exception(sdla_t *card);
224static int update_comms_stats(sdla_t* card,
225 chdlc_private_area_t* chdlc_priv_area);
226static int configure_ip (sdla_t* card);
227static int unconfigure_ip (sdla_t* card);
228static void process_route(sdla_t *card);
229static void port_set_state (sdla_t *card, int);
230static int config_chdlc (sdla_t *card);
231static void disable_comm (sdla_t *card);
232
233static void trigger_chdlc_poll(struct net_device *dev);
234static void chdlc_poll(struct net_device *dev);
235static void chdlc_poll_delay (unsigned long dev_ptr);
236
237
238/* Miscellaneous asynchronous interface Functions */
239static int set_asy_config (sdla_t* card);
240static int asy_comm_enable (sdla_t* card);
241
242/* Interrupt handlers */
243static void wpc_isr (sdla_t* card);
244static void rx_intr (sdla_t* card);
245static void timer_intr(sdla_t *);
246
247/* Bottom half handlers */
248static void chdlc_work(struct net_device *dev);
249static int chdlc_work_cleanup(struct net_device *dev);
250static int bh_enqueue(struct net_device *dev, struct sk_buff *skb);
251
252/* Miscellaneous functions */
253static int chk_bcast_mcast_addr(sdla_t* card, struct net_device* dev,
254 struct sk_buff *skb);
255static int reply_udp( unsigned char *data, unsigned int mbox_len );
256static int intr_test( sdla_t* card);
257static int udp_pkt_type( struct sk_buff *skb , sdla_t* card);
258static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
259 struct sk_buff *skb, struct net_device* dev,
260 chdlc_private_area_t* chdlc_priv_area);
261static int process_udp_mgmt_pkt(sdla_t* card, struct net_device* dev,
262 chdlc_private_area_t* chdlc_priv_area);
263static unsigned short calc_checksum (char *, int);
264static void s508_lock (sdla_t *card, unsigned long *smp_flags);
265static void s508_unlock (sdla_t *card, unsigned long *smp_flags);
266
267
268static int Intr_test_counter;
269
270/* TTY Global Definitions */
271
272#define NR_PORTS 4
273#define WAN_TTY_MAJOR 226
274#define WAN_TTY_MINOR 0
275
276#define WAN_CARD(port) (tty_card_map[port])
277#define MIN_PORT 0
278#define MAX_PORT NR_PORTS-1
279
280#define CRC_LENGTH 2
281
282static int wanpipe_tty_init(sdla_t *card);
283static void wanpipe_tty_receive(sdla_t *, unsigned, unsigned int);
284static void wanpipe_tty_trigger_poll(sdla_t *card);
285
286static struct tty_driver serial_driver;
287static int tty_init_cnt=0;
288
289static struct serial_state rs_table[NR_PORTS];
290
291static char tty_driver_mode=WANOPT_TTY_SYNC;
292
293static char *opt_decode[] = {"NONE","CRTSCTS","XONXOFF-RX",
294 "CRTSCTS XONXOFF-RX","XONXOFF-TX",
295 "CRTSCTS XONXOFF-TX","CRTSCTS XONXOFF"};
296static char *p_decode[] = {"NONE","ODD","EVEN"};
297
298static void* tty_card_map[NR_PORTS] = {NULL,NULL,NULL,NULL};
299
300
301/****** Public Functions ****************************************************/
302
303/*============================================================================
304 * Cisco HDLC protocol initialization routine.
305 *
306 * This routine is called by the main WANPIPE module during setup. At this
307 * point adapter is completely initialized and firmware is running.
308 * o read firmware version (to make sure it's alive)
309 * o configure adapter
310 * o initialize protocol-specific fields of the adapter data space.
311 *
312 * Return: 0 o.k.
313 * < 0 failure.
314 */
315int wpc_init (sdla_t* card, wandev_conf_t* conf)
316{
317 unsigned char port_num;
318 int err;
319 unsigned long max_permitted_baud = 0;
320 SHARED_MEMORY_INFO_STRUCT *flags;
321
322 union
323 {
324 char str[80];
325 } u;
326 volatile CHDLC_MAILBOX_STRUCT* mb;
327 CHDLC_MAILBOX_STRUCT* mb1;
328 unsigned long timeout;
329
330 /* Verify configuration ID */
331 if (conf->config_id != WANCONFIG_CHDLC) {
332 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
333 card->devname, conf->config_id);
334 return -EINVAL;
335 }
336
337 /* Find out which Port to use */
338 if ((conf->comm_port == WANOPT_PRI) || (conf->comm_port == WANOPT_SEC)){
339 if (card->next){
340
341 if (conf->comm_port != card->next->u.c.comm_port){
342 card->u.c.comm_port = conf->comm_port;
343 }else{
344 printk(KERN_INFO "%s: ERROR - %s port used!\n",
345 card->wandev.name, PORT(conf->comm_port));
346 return -EINVAL;
347 }
348 }else{
349 card->u.c.comm_port = conf->comm_port;
350 }
351 }else{
352 printk(KERN_INFO "%s: ERROR - Invalid Port Selected!\n",
353 card->wandev.name);
354 return -EINVAL;
355 }
356
357
358 /* Initialize protocol-specific fields */
359 if(card->hw.type != SDLA_S514){
360
361 if (card->u.c.comm_port == WANOPT_PRI){
362 card->mbox = (void *) card->hw.dpmbase;
363 }else{
364 card->mbox = (void *) card->hw.dpmbase +
365 SEC_BASE_ADDR_MB_STRUCT - PRI_BASE_ADDR_MB_STRUCT;
366 }
367 }else{
368 /* for a S514 adapter, set a pointer to the actual mailbox in the */
369 /* allocated virtual memory area */
370 if (card->u.c.comm_port == WANOPT_PRI){
371 card->mbox = (void *) card->hw.dpmbase + PRI_BASE_ADDR_MB_STRUCT;
372 }else{
373 card->mbox = (void *) card->hw.dpmbase + SEC_BASE_ADDR_MB_STRUCT;
374 }
375 }
376
377 mb = mb1 = card->mbox;
378
379 if (!card->configured){
380
381 /* The board will place an 'I' in the return code to indicate that it is
382 ready to accept commands. We expect this to be completed in less
383 than 1 second. */
384
385 timeout = jiffies;
386 while (mb->return_code != 'I') /* Wait 1s for board to initialize */
387 if ((jiffies - timeout) > 1*HZ) break;
388
389 if (mb->return_code != 'I') {
390 printk(KERN_INFO
391 "%s: Initialization not completed by adapter\n",
392 card->devname);
393 printk(KERN_INFO "Please contact Sangoma representative.\n");
394 return -EIO;
395 }
396 }
397
398 /* Read firmware version. Note that when adapter initializes, it
399 * clears the mailbox, so it may appear that the first command was
400 * executed successfully when in fact it was merely erased. To work
401 * around this, we execute the first command twice.
402 */
403
404 if (chdlc_read_version(card, u.str))
405 return -EIO;
406
407 printk(KERN_INFO "%s: Running Cisco HDLC firmware v%s\n",
408 card->devname, u.str);
409
410 card->isr = &wpc_isr;
411 card->poll = NULL;
412 card->exec = NULL;
413 card->wandev.update = &update;
414 card->wandev.new_if = &new_if;
415 card->wandev.del_if = NULL;
416 card->wandev.udp_port = conf->udp_port;
417 card->disable_comm = &disable_comm;
418 card->wandev.new_if_cnt = 0;
419
420 /* reset the number of times the 'update()' proc has been called */
421 card->u.c.update_call_count = 0;
422
423 card->wandev.ttl = conf->ttl;
424 card->wandev.interface = conf->interface;
425
426 if ((card->u.c.comm_port == WANOPT_SEC && conf->interface == WANOPT_V35)&&
427 card->hw.type != SDLA_S514){
428 printk(KERN_INFO "%s: ERROR - V35 Interface not supported on S508 %s port \n",
429 card->devname, PORT(card->u.c.comm_port));
430 return -EIO;
431 }
432
433 card->wandev.clocking = conf->clocking;
434
435 port_num = card->u.c.comm_port;
436
437 /* in API mode, we can configure for "receive only" buffering */
438 if(card->hw.type == SDLA_S514) {
439 card->u.c.receive_only = conf->receive_only;
440 if(conf->receive_only) {
441 printk(KERN_INFO
442 "%s: Configured for 'receive only' mode\n",
443 card->devname);
444 }
445 }
446
447 /* Setup Port Bps */
448
449 if(card->wandev.clocking) {
450 if((port_num == WANOPT_PRI) || card->u.c.receive_only) {
451 /* For Primary Port 0 */
452 max_permitted_baud =
453 (card->hw.type == SDLA_S514) ?
454 PRI_MAX_BAUD_RATE_S514 :
455 PRI_MAX_BAUD_RATE_S508;
456
457 }else if(port_num == WANOPT_SEC) {
458 /* For Secondary Port 1 */
459 max_permitted_baud =
460 (card->hw.type == SDLA_S514) ?
461 SEC_MAX_BAUD_RATE_S514 :
462 SEC_MAX_BAUD_RATE_S508;
463 }
464
465 if(conf->bps > max_permitted_baud) {
466 conf->bps = max_permitted_baud;
467 printk(KERN_INFO "%s: Baud too high!\n",
468 card->wandev.name);
469 printk(KERN_INFO "%s: Baud rate set to %lu bps\n",
470 card->wandev.name, max_permitted_baud);
471 }
472 card->wandev.bps = conf->bps;
473 }else{
474 card->wandev.bps = 0;
475 }
476
477 /* Setup the Port MTU */
478 if((port_num == WANOPT_PRI) || card->u.c.receive_only) {
479
480 /* For Primary Port 0 */
481 card->wandev.mtu =
482 (conf->mtu >= MIN_LGTH_CHDLC_DATA_CFG) ?
483 min_t(unsigned int, conf->mtu, PRI_MAX_NO_DATA_BYTES_IN_FRAME) :
484 CHDLC_DFLT_DATA_LEN;
485 } else if(port_num == WANOPT_SEC) {
486 /* For Secondary Port 1 */
487 card->wandev.mtu =
488 (conf->mtu >= MIN_LGTH_CHDLC_DATA_CFG) ?
489 min_t(unsigned int, conf->mtu, SEC_MAX_NO_DATA_BYTES_IN_FRAME) :
490 CHDLC_DFLT_DATA_LEN;
491 }
492
493 /* Set up the interrupt status area */
494 /* Read the CHDLC Configuration and obtain:
495 * Ptr to shared memory infor struct
496 * Use this pointer to calculate the value of card->u.c.flags !
497 */
498 mb1->buffer_length = 0;
499 mb1->command = READ_CHDLC_CONFIGURATION;
500 err = sdla_exec(mb1) ? mb1->return_code : CMD_TIMEOUT;
501 if(err != COMMAND_OK) {
502 if(card->hw.type != SDLA_S514)
503 enable_irq(card->hw.irq);
504
505 chdlc_error(card, err, mb1);
506 return -EIO;
507 }
508
509 if(card->hw.type == SDLA_S514){
510 card->u.c.flags = (void *)(card->hw.dpmbase +
511 (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
512 ptr_shared_mem_info_struct));
513 }else{
514 card->u.c.flags = (void *)(card->hw.dpmbase +
515 (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
516 ptr_shared_mem_info_struct % SDLA_WINDOWSIZE));
517 }
518
519 flags = card->u.c.flags;
520
521 /* This is for the ports link state */
522 card->wandev.state = WAN_DUALPORT;
523 card->u.c.state = WAN_DISCONNECTED;
524
525
526 if (!card->wandev.piggyback){
527 int err;
528
529 /* Perform interrupt testing */
530 err = intr_test(card);
531
532 if(err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
533 printk(KERN_INFO "%s: Interrupt test failed (%i)\n",
534 card->devname, Intr_test_counter);
535 printk(KERN_INFO "%s: Please choose another interrupt\n",
536 card->devname);
537 return -EIO;
538 }
539
540 printk(KERN_INFO "%s: Interrupt test passed (%i)\n",
541 card->devname, Intr_test_counter);
542 card->configured = 1;
543 }
544
545 if ((card->tty_opt=conf->tty) == WANOPT_YES){
546 int err;
547 card->tty_minor = conf->tty_minor;
548
549 /* On ASYNC connections internal clocking
550 * is mandatory */
551 if ((card->u.c.async_mode = conf->tty_mode)){
552 card->wandev.clocking = 1;
553 }
554 err=wanpipe_tty_init(card);
555 if (err){
556 return err;
557 }
558 }else{
559
560
561 if (chdlc_set_intr_mode(card, APP_INT_ON_TIMER)){
562 printk (KERN_INFO "%s: "
563 "Failed to set interrupt triggers!\n",
564 card->devname);
565 return -EIO;
566 }
567
568 /* Mask the Timer interrupt */
569 flags->interrupt_info_struct.interrupt_permission &=
570 ~APP_INT_ON_TIMER;
571 }
572
573 /* If we are using CHDLC in backup mode, this flag will
574 * indicate not to look for IP addresses in config_chdlc()*/
575 card->u.c.backup = conf->backup;
576
577 printk(KERN_INFO "\n");
578
579 return 0;
580}
581
582/******* WAN Device Driver Entry Points *************************************/
583
584/*============================================================================
585 * Update device status & statistics
586 * This procedure is called when updating the PROC file system and returns
587 * various communications statistics. These statistics are accumulated from 3
588 * different locations:
589 * 1) The 'if_stats' recorded for the device.
590 * 2) Communication error statistics on the adapter.
591 * 3) CHDLC operational statistics on the adapter.
592 * The board level statistics are read during a timer interrupt. Note that we
593 * read the error and operational statistics during consecitive timer ticks so
594 * as to minimize the time that we are inside the interrupt handler.
595 *
596 */
597static int update(struct wan_device* wandev)
598{
599 sdla_t* card = wandev->private;
600 struct net_device* dev;
601 volatile chdlc_private_area_t* chdlc_priv_area;
602 SHARED_MEMORY_INFO_STRUCT *flags;
603 unsigned long timeout;
604
605 /* sanity checks */
606 if((wandev == NULL) || (wandev->private == NULL))
607 return -EFAULT;
608
609 if(wandev->state == WAN_UNCONFIGURED)
610 return -ENODEV;
611
612 /* more sanity checks */
613 if(!card->u.c.flags)
614 return -ENODEV;
615
616 if(test_bit(PERI_CRIT, (void*)&card->wandev.critical))
617 return -EAGAIN;
618
619 if((dev=card->wandev.dev) == NULL)
620 return -ENODEV;
621
622 if((chdlc_priv_area=dev->priv) == NULL)
623 return -ENODEV;
624
625 flags = card->u.c.flags;
626 if(chdlc_priv_area->update_comms_stats){
627 return -EAGAIN;
628 }
629
630 /* we will need 2 timer interrupts to complete the */
631 /* reading of the statistics */
632 chdlc_priv_area->update_comms_stats = 2;
633 flags->interrupt_info_struct.interrupt_permission |= APP_INT_ON_TIMER;
634 chdlc_priv_area->timer_int_enabled = TMR_INT_ENABLED_UPDATE;
635
636 /* wait a maximum of 1 second for the statistics to be updated */
637 timeout = jiffies;
638 for(;;) {
639 if(chdlc_priv_area->update_comms_stats == 0)
640 break;
641 if ((jiffies - timeout) > (1 * HZ)){
642 chdlc_priv_area->update_comms_stats = 0;
643 chdlc_priv_area->timer_int_enabled &=
644 ~TMR_INT_ENABLED_UPDATE;
645 return -EAGAIN;
646 }
647 }
648
649 return 0;
650}
651
652
653/*============================================================================
654 * Create new logical channel.
655 * This routine is called by the router when ROUTER_IFNEW IOCTL is being
656 * handled.
657 * o parse media- and hardware-specific configuration
658 * o make sure that a new channel can be created
659 * o allocate resources, if necessary
660 * o prepare network device structure for registaration.
661 *
662 * Return: 0 o.k.
663 * < 0 failure (channel will not be created)
664 */
665static int new_if(struct wan_device* wandev, struct net_device* dev,
666 wanif_conf_t* conf)
667{
668 sdla_t* card = wandev->private;
669 chdlc_private_area_t* chdlc_priv_area;
670
671
672 printk(KERN_INFO "%s: Configuring Interface: %s\n",
673 card->devname, conf->name);
674
675 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
676 printk(KERN_INFO "%s: Invalid interface name!\n",
677 card->devname);
678 return -EINVAL;
679 }
680
681 /* allocate and initialize private data */
682 chdlc_priv_area = kmalloc(sizeof(chdlc_private_area_t), GFP_KERNEL);
683
684 if(chdlc_priv_area == NULL)
685 return -ENOMEM;
686
687 memset(chdlc_priv_area, 0, sizeof(chdlc_private_area_t));
688
689 chdlc_priv_area->card = card;
690 chdlc_priv_area->common.sk = NULL;
691 chdlc_priv_area->common.func = NULL;
692
693 /* initialize data */
694 strcpy(card->u.c.if_name, conf->name);
695
696 if(card->wandev.new_if_cnt > 0) {
697 kfree(chdlc_priv_area);
698 return -EEXIST;
699 }
700
701 card->wandev.new_if_cnt++;
702
703 chdlc_priv_area->TracingEnabled = 0;
704 chdlc_priv_area->route_status = NO_ROUTE;
705 chdlc_priv_area->route_removed = 0;
706
707 card->u.c.async_mode = conf->async_mode;
708
709 /* setup for asynchronous mode */
710 if(conf->async_mode) {
711 printk(KERN_INFO "%s: Configuring for asynchronous mode\n",
712 wandev->name);
713
714 if(card->u.c.comm_port == WANOPT_PRI) {
715 printk(KERN_INFO
716 "%s:Asynchronous mode on secondary port only\n",
717 wandev->name);
718 kfree(chdlc_priv_area);
719 return -EINVAL;
720 }
721
722 if(strcmp(conf->usedby, "WANPIPE") == 0) {
723 printk(KERN_INFO
724 "%s: Running in WANIPE Async Mode\n", wandev->name);
725 card->u.c.usedby = WANPIPE;
726 }else{
727 card->u.c.usedby = API;
728 }
729
730 if(!card->wandev.clocking) {
731 printk(KERN_INFO
732 "%s: Asynch. clocking must be 'Internal'\n",
733 wandev->name);
734 kfree(chdlc_priv_area);
735 return -EINVAL;
736 }
737
738 if((card->wandev.bps < MIN_ASY_BAUD_RATE) ||
739 (card->wandev.bps > MAX_ASY_BAUD_RATE)) {
740 printk(KERN_INFO "%s: Selected baud rate is invalid.\n",
741 wandev->name);
742 printk(KERN_INFO "Must be between %u and %u bps.\n",
743 MIN_ASY_BAUD_RATE, MAX_ASY_BAUD_RATE);
744 kfree(chdlc_priv_area);
745 return -EINVAL;
746 }
747
748 card->u.c.api_options = 0;
749 if (conf->asy_data_trans == WANOPT_YES) {
750 card->u.c.api_options |= ASY_RX_DATA_TRANSPARENT;
751 }
752
753 card->u.c.protocol_options = 0;
754 if (conf->rts_hs_for_receive == WANOPT_YES) {
755 card->u.c.protocol_options |= ASY_RTS_HS_FOR_RX;
756 }
757 if (conf->xon_xoff_hs_for_receive == WANOPT_YES) {
758 card->u.c.protocol_options |= ASY_XON_XOFF_HS_FOR_RX;
759 }
760 if (conf->xon_xoff_hs_for_transmit == WANOPT_YES) {
761 card->u.c.protocol_options |= ASY_XON_XOFF_HS_FOR_TX;
762 }
763 if (conf->dcd_hs_for_transmit == WANOPT_YES) {
764 card->u.c.protocol_options |= ASY_DCD_HS_FOR_TX;
765 }
766 if (conf->cts_hs_for_transmit == WANOPT_YES) {
767 card->u.c.protocol_options |= ASY_CTS_HS_FOR_TX;
768 }
769
770 card->u.c.tx_bits_per_char = conf->tx_bits_per_char;
771 card->u.c.rx_bits_per_char = conf->rx_bits_per_char;
772 card->u.c.stop_bits = conf->stop_bits;
773 card->u.c.parity = conf->parity;
774 card->u.c.break_timer = conf->break_timer;
775 card->u.c.inter_char_timer = conf->inter_char_timer;
776 card->u.c.rx_complete_length = conf->rx_complete_length;
777 card->u.c.xon_char = conf->xon_char;
778
779 } else { /* setup for synchronous mode */
780
781 card->u.c.protocol_options = 0;
782 if (conf->ignore_dcd == WANOPT_YES){
783 card->u.c.protocol_options |= IGNORE_DCD_FOR_LINK_STAT;
784 }
785 if (conf->ignore_cts == WANOPT_YES){
786 card->u.c.protocol_options |= IGNORE_CTS_FOR_LINK_STAT;
787 }
788
789 if (conf->ignore_keepalive == WANOPT_YES) {
790 card->u.c.protocol_options |=
791 IGNORE_KPALV_FOR_LINK_STAT;
792 card->u.c.kpalv_tx = MIN_Tx_KPALV_TIMER;
793 card->u.c.kpalv_rx = MIN_Rx_KPALV_TIMER;
794 card->u.c.kpalv_err = MIN_KPALV_ERR_TOL;
795
796 } else { /* Do not ignore keepalives */
797 card->u.c.kpalv_tx =
798 ((conf->keepalive_tx_tmr - MIN_Tx_KPALV_TIMER)
799 >= 0) ?
800 min_t(unsigned int, conf->keepalive_tx_tmr,MAX_Tx_KPALV_TIMER) :
801 DEFAULT_Tx_KPALV_TIMER;
802
803 card->u.c.kpalv_rx =
804 ((conf->keepalive_rx_tmr - MIN_Rx_KPALV_TIMER)
805 >= 0) ?
806 min_t(unsigned int, conf->keepalive_rx_tmr,MAX_Rx_KPALV_TIMER) :
807 DEFAULT_Rx_KPALV_TIMER;
808
809 card->u.c.kpalv_err =
810 ((conf->keepalive_err_margin-MIN_KPALV_ERR_TOL)
811 >= 0) ?
812 min_t(unsigned int, conf->keepalive_err_margin,
813 MAX_KPALV_ERR_TOL) :
814 DEFAULT_KPALV_ERR_TOL;
815 }
816
817 /* Setup slarp timer to control delay between slarps */
818 card->u.c.slarp_timer =
819 ((conf->slarp_timer - MIN_SLARP_REQ_TIMER) >= 0) ?
820 min_t(unsigned int, conf->slarp_timer, MAX_SLARP_REQ_TIMER) :
821 DEFAULT_SLARP_REQ_TIMER;
822
823 if (conf->hdlc_streaming == WANOPT_YES) {
824 printk(KERN_INFO "%s: Enabling HDLC STREAMING Mode\n",
825 wandev->name);
826 card->u.c.protocol_options = HDLC_STREAMING_MODE;
827 }
828
829 if ((chdlc_priv_area->true_if_encoding = conf->true_if_encoding) == WANOPT_YES){
830 printk(KERN_INFO
831 "%s: Enabling, true interface type encoding.\n",
832 card->devname);
833 }
834
835 /* Setup wanpipe as a router (WANPIPE) or as an API */
836 if( strcmp(conf->usedby, "WANPIPE") == 0) {
837
838 printk(KERN_INFO "%s: Running in WANPIPE mode!\n",
839 wandev->name);
840 card->u.c.usedby = WANPIPE;
841
842 /* Option to bring down the interface when
843 * the link goes down */
844 if (conf->if_down){
845 set_bit(DYN_OPT_ON,&chdlc_priv_area->interface_down);
846 printk(KERN_INFO
847 "%s: Dynamic interface configuration enabled\n",
848 card->devname);
849 }
850
851 } else if( strcmp(conf->usedby, "API") == 0) {
852 card->u.c.usedby = API;
853 printk(KERN_INFO "%s: Running in API mode !\n",
854 wandev->name);
855 }
856 }
857
858 /* Tells us that if this interface is a
859 * gateway or not */
860 if ((chdlc_priv_area->gateway = conf->gateway) == WANOPT_YES){
861 printk(KERN_INFO "%s: Interface %s is set as a gateway.\n",
862 card->devname,card->u.c.if_name);
863 }
864
865 /* Get Multicast Information */
866 chdlc_priv_area->mc = conf->mc;
867
868 /* prepare network device data space for registration */
869 strcpy(dev->name,card->u.c.if_name);
870
871 dev->init = &if_init;
872 dev->priv = chdlc_priv_area;
873
874 /* Initialize the polling work routine */
875 INIT_WORK(&chdlc_priv_area->poll_work, (void*)(void*)chdlc_poll, dev);
876
877 /* Initialize the polling delay timer */
878 init_timer(&chdlc_priv_area->poll_delay_timer);
879 chdlc_priv_area->poll_delay_timer.data = (unsigned long)dev;
880 chdlc_priv_area->poll_delay_timer.function = chdlc_poll_delay;
881
882 printk(KERN_INFO "\n");
883
884 return 0;
885}
886
887
888/****** Network Device Interface ********************************************/
889
890/*============================================================================
891 * Initialize Linux network interface.
892 *
893 * This routine is called only once for each interface, during Linux network
894 * interface registration. Returning anything but zero will fail interface
895 * registration.
896 */
897static int if_init(struct net_device* dev)
898{
899 chdlc_private_area_t* chdlc_priv_area = dev->priv;
900 sdla_t* card = chdlc_priv_area->card;
901 struct wan_device* wandev = &card->wandev;
902
903 /* Initialize device driver entry points */
904 dev->open = &if_open;
905 dev->stop = &if_close;
906 dev->hard_header = &if_header;
907 dev->rebuild_header = &if_rebuild_hdr;
908 dev->hard_start_xmit = &if_send;
909 dev->get_stats = &if_stats;
910 dev->tx_timeout = &if_tx_timeout;
911 dev->watchdog_timeo = TX_TIMEOUT;
912
913 /* Initialize media-specific parameters */
914 dev->flags |= IFF_POINTOPOINT;
915 dev->flags |= IFF_NOARP;
916
917 /* Enable Mulitcasting if user selected */
918 if (chdlc_priv_area->mc == WANOPT_YES){
919 dev->flags |= IFF_MULTICAST;
920 }
921
922 if (chdlc_priv_area->true_if_encoding){
923 dev->type = ARPHRD_HDLC; /* This breaks the tcpdump */
924 }else{
925 dev->type = ARPHRD_PPP;
926 }
927
928 dev->mtu = card->wandev.mtu;
929 /* for API usage, add the API header size to the requested MTU size */
930 if(card->u.c.usedby == API) {
931 dev->mtu += sizeof(api_tx_hdr_t);
932 }
933
934 dev->hard_header_len = CHDLC_HDR_LEN;
935
936 /* Initialize hardware parameters */
937 dev->irq = wandev->irq;
938 dev->dma = wandev->dma;
939 dev->base_addr = wandev->ioport;
940 dev->mem_start = wandev->maddr;
941 dev->mem_end = wandev->maddr + wandev->msize - 1;
942
943 /* Set transmit buffer queue length
944 * If too low packets will not be retransmitted
945 * by stack.
946 */
947 dev->tx_queue_len = 100;
948 SET_MODULE_OWNER(dev);
949
950 return 0;
951}
952
953/*============================================================================
954 * Open network interface.
955 * o enable communications and interrupts.
956 * o prevent module from unloading by incrementing use count
957 *
958 * Return 0 if O.k. or errno.
959 */
960static int if_open(struct net_device* dev)
961{
962 chdlc_private_area_t* chdlc_priv_area = dev->priv;
963 sdla_t* card = chdlc_priv_area->card;
964 struct timeval tv;
965 int err = 0;
966
967 /* Only one open per interface is allowed */
968
969 if (netif_running(dev))
970 return -EBUSY;
971
972 /* Initialize the work queue entry */
973 chdlc_priv_area->tq_working=0;
974
975 INIT_WORK(&chdlc_priv_area->common.wanpipe_work,
976 (void *)(void *)chdlc_work, dev);
977
978 /* Allocate and initialize BH circular buffer */
979 /* Add 1 to MAX_BH_BUFF so we don't have test with (MAX_BH_BUFF-1) */
980 chdlc_priv_area->bh_head = kmalloc((sizeof(bh_data_t)*(MAX_BH_BUFF+1)),GFP_ATOMIC);
981 memset(chdlc_priv_area->bh_head,0,(sizeof(bh_data_t)*(MAX_BH_BUFF+1)));
982 atomic_set(&chdlc_priv_area->bh_buff_used, 0);
983
984 do_gettimeofday(&tv);
985 chdlc_priv_area->router_start_time = tv.tv_sec;
986
987 netif_start_queue(dev);
988
989 wanpipe_open(card);
990
991 /* TTY is configured during wanpipe_set_termios
992 * call, not here */
993 if (card->tty_opt)
994 return err;
995
996 set_bit(0,&chdlc_priv_area->config_chdlc);
997 chdlc_priv_area->config_chdlc_timeout=jiffies;
998
999 /* Start the CHDLC configuration after 1sec delay.
1000 * This will give the interface initilization time
1001 * to finish its configuration */
1002 mod_timer(&chdlc_priv_area->poll_delay_timer, jiffies + HZ);
1003 return err;
1004}
1005
1006/*============================================================================
1007 * Close network interface.
1008 * o if this is the last close, then disable communications and interrupts.
1009 * o reset flags.
1010 */
1011static int if_close(struct net_device* dev)
1012{
1013 chdlc_private_area_t* chdlc_priv_area = dev->priv;
1014 sdla_t* card = chdlc_priv_area->card;
1015
1016 if (chdlc_priv_area->bh_head){
1017 int i;
1018 struct sk_buff *skb;
1019
1020 for (i=0; i<(MAX_BH_BUFF+1); i++){
1021 skb = ((bh_data_t *)&chdlc_priv_area->bh_head[i])->skb;
1022 if (skb != NULL){
1023 dev_kfree_skb_any(skb);
1024 }
1025 }
1026 kfree(chdlc_priv_area->bh_head);
1027 chdlc_priv_area->bh_head=NULL;
1028 }
1029
1030 netif_stop_queue(dev);
1031 wanpipe_close(card);
1032 del_timer(&chdlc_priv_area->poll_delay_timer);
1033 return 0;
1034}
1035
1036static void disable_comm (sdla_t *card)
1037{
1038 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
1039
1040 if (card->u.c.comm_enabled){
1041 chdlc_disable_comm_shutdown (card);
1042 }else{
1043 flags->interrupt_info_struct.interrupt_permission = 0;
1044 }
1045
1046 if (!tty_init_cnt)
1047 return;
1048
1049 if (card->tty_opt){
1050 struct serial_state * state;
1051 if (!(--tty_init_cnt)){
1052 int e1;
1053 serial_driver.refcount=0;
1054
1055 if ((e1 = tty_unregister_driver(&serial_driver)))
1056 printk("SERIAL: failed to unregister serial driver (%d)\n",
1057 e1);
1058 printk(KERN_INFO "%s: Unregistering TTY Driver, Major %i\n",
1059 card->devname,WAN_TTY_MAJOR);
1060 }
1061 card->tty=NULL;
1062 tty_card_map[card->tty_minor]=NULL;
1063 state = &rs_table[card->tty_minor];
1064 memset(state, 0, sizeof(*state));
1065 }
1066 return;
1067}
1068
1069
1070/*============================================================================
1071 * Build media header.
1072 *
1073 * The trick here is to put packet type (Ethertype) into 'protocol' field of
1074 * the socket buffer, so that we don't forget it. If packet type is not
1075 * supported, set skb->protocol to 0 and discard packet later.
1076 *
1077 * Return: media header length.
1078 */
1079static int if_header(struct sk_buff* skb, struct net_device* dev,
1080 unsigned short type, void* daddr, void* saddr,
1081 unsigned len)
1082{
1083 skb->protocol = htons(type);
1084
1085 return CHDLC_HDR_LEN;
1086}
1087
1088
1089/*============================================================================
1090 * Handle transmit timeout event from netif watchdog
1091 */
1092static void if_tx_timeout(struct net_device *dev)
1093{
1094 chdlc_private_area_t* chan = dev->priv;
1095 sdla_t *card = chan->card;
1096
1097 /* If our device stays busy for at least 5 seconds then we will
1098 * kick start the device by making dev->tbusy = 0. We expect
1099 * that our device never stays busy more than 5 seconds. So this
1100 * is only used as a last resort.
1101 */
1102
1103 ++card->wandev.stats.collisions;
1104
1105 printk (KERN_INFO "%s: Transmit timed out on %s\n", card->devname,dev->name);
1106 netif_wake_queue (dev);
1107}
1108
1109
1110
1111/*============================================================================
1112 * Re-build media header.
1113 *
1114 * Return: 1 physical address resolved.
1115 * 0 physical address not resolved
1116 */
1117static int if_rebuild_hdr (struct sk_buff *skb)
1118{
1119 return 1;
1120}
1121
1122
1123/*============================================================================
1124 * Send a packet on a network interface.
1125 * o set tbusy flag (marks start of the transmission) to block a timer-based
1126 * transmit from overlapping.
1127 * o check link state. If link is not up, then drop the packet.
1128 * o execute adapter send command.
1129 * o free socket buffer
1130 *
1131 * Return: 0 complete (socket buffer must be freed)
1132 * non-0 packet may be re-transmitted (tbusy must be set)
1133 *
1134 * Notes:
1135 * 1. This routine is called either by the protocol stack or by the "net
1136 * bottom half" (with interrupts enabled).
1137 * 2. Setting tbusy flag will inhibit further transmit requests from the
1138 * protocol stack and can be used for flow control with protocol layer.
1139 */
1140static int if_send(struct sk_buff* skb, struct net_device* dev)
1141{
1142 chdlc_private_area_t *chdlc_priv_area = dev->priv;
1143 sdla_t *card = chdlc_priv_area->card;
1144 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
1145 INTERRUPT_INFORMATION_STRUCT *chdlc_int = &flags->interrupt_info_struct;
1146 int udp_type = 0;
1147 unsigned long smp_flags;
1148 int err=0;
1149
1150 netif_stop_queue(dev);
1151
1152 if (skb == NULL){
1153 /* If we get here, some higher layer thinks we've missed an
1154 * tx-done interrupt.
1155 */
1156 printk(KERN_INFO "%s: interface %s got kicked!\n",
1157 card->devname, dev->name);
1158
1159 netif_wake_queue(dev);
1160 return 0;
1161 }
1162
1163 if (ntohs(skb->protocol) != htons(PVC_PROT)){
1164
1165 /* check the udp packet type */
1166
1167 udp_type = udp_pkt_type(skb, card);
1168
1169 if (udp_type == UDP_CPIPE_TYPE){
1170 if(store_udp_mgmt_pkt(UDP_PKT_FRM_STACK, card, skb, dev,
1171 chdlc_priv_area)){
1172 chdlc_int->interrupt_permission |=
1173 APP_INT_ON_TIMER;
1174 }
1175 netif_start_queue(dev);
1176 return 0;
1177 }
1178
1179 /* check to see if the source IP address is a broadcast or */
1180 /* multicast IP address */
1181 if(chk_bcast_mcast_addr(card, dev, skb)){
1182 ++card->wandev.stats.tx_dropped;
1183 dev_kfree_skb_any(skb);
1184 netif_start_queue(dev);
1185 return 0;
1186 }
1187 }
1188
1189 /* Lock the 508 Card: SMP is supported */
1190 if(card->hw.type != SDLA_S514){
1191 s508_lock(card,&smp_flags);
1192 }
1193
1194 if(test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
1195
1196 printk(KERN_INFO "%s: Critical in if_send: %lx\n",
1197 card->wandev.name,card->wandev.critical);
1198 ++card->wandev.stats.tx_dropped;
1199 netif_start_queue(dev);
1200 goto if_send_exit_crit;
1201 }
1202
1203 if(card->u.c.state != WAN_CONNECTED){
1204 ++card->wandev.stats.tx_dropped;
1205 netif_start_queue(dev);
1206
1207 }else if(!skb->protocol){
1208 ++card->wandev.stats.tx_errors;
1209 netif_start_queue(dev);
1210
1211 }else {
1212 void* data = skb->data;
1213 unsigned len = skb->len;
1214 unsigned char attr;
1215
1216 /* If it's an API packet pull off the API
1217 * header. Also check that the packet size
1218 * is larger than the API header
1219 */
1220 if (card->u.c.usedby == API){
1221 api_tx_hdr_t* api_tx_hdr;
1222
1223 /* discard the frame if we are configured for */
1224 /* 'receive only' mode or if there is no data */
1225 if (card->u.c.receive_only ||
1226 (len <= sizeof(api_tx_hdr_t))) {
1227
1228 ++card->wandev.stats.tx_dropped;
1229 netif_start_queue(dev);
1230 goto if_send_exit_crit;
1231 }
1232
1233 api_tx_hdr = (api_tx_hdr_t *)data;
1234 attr = api_tx_hdr->attr;
1235 data += sizeof(api_tx_hdr_t);
1236 len -= sizeof(api_tx_hdr_t);
1237 }
1238
1239 if(chdlc_send(card, data, len)) {
1240 netif_stop_queue(dev);
1241 }else{
1242 ++card->wandev.stats.tx_packets;
1243 card->wandev.stats.tx_bytes += len;
1244
1245 netif_start_queue(dev);
1246
1247 dev->trans_start = jiffies;
1248 }
1249 }
1250
1251if_send_exit_crit:
1252
1253 if (!(err=netif_queue_stopped(dev))) {
1254 dev_kfree_skb_any(skb);
1255 }else{
1256 chdlc_priv_area->tick_counter = jiffies;
1257 chdlc_int->interrupt_permission |= APP_INT_ON_TX_FRAME;
1258 }
1259
1260 clear_bit(SEND_CRIT, (void*)&card->wandev.critical);
1261 if(card->hw.type != SDLA_S514){
1262 s508_unlock(card,&smp_flags);
1263 }
1264
1265 return err;
1266}
1267
1268
1269/*============================================================================
1270 * Check to see if the packet to be transmitted contains a broadcast or
1271 * multicast source IP address.
1272 */
1273
1274static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
1275 struct sk_buff *skb)
1276{
1277 u32 src_ip_addr;
1278 u32 broadcast_ip_addr = 0;
1279 struct in_device *in_dev;
1280
1281 /* read the IP source address from the outgoing packet */
1282 src_ip_addr = *(u32 *)(skb->data + 12);
1283
1284 /* read the IP broadcast address for the device */
1285 in_dev = dev->ip_ptr;
1286 if(in_dev != NULL) {
1287 struct in_ifaddr *ifa= in_dev->ifa_list;
1288 if(ifa != NULL)
1289 broadcast_ip_addr = ifa->ifa_broadcast;
1290 else
1291 return 0;
1292 }
1293
1294 /* check if the IP Source Address is a Broadcast address */
1295 if((dev->flags & IFF_BROADCAST) && (src_ip_addr == broadcast_ip_addr)) {
1296 printk(KERN_INFO "%s: Broadcast Source Address silently discarded\n",
1297 card->devname);
1298 return 1;
1299 }
1300
1301 /* check if the IP Source Address is a Multicast address */
1302 if((ntohl(src_ip_addr) >= 0xE0000001) &&
1303 (ntohl(src_ip_addr) <= 0xFFFFFFFE)) {
1304 printk(KERN_INFO "%s: Multicast Source Address silently discarded\n",
1305 card->devname);
1306 return 1;
1307 }
1308
1309 return 0;
1310}
1311
1312
1313/*============================================================================
1314 * Reply to UDP Management system.
1315 * Return length of reply.
1316 */
1317static int reply_udp( unsigned char *data, unsigned int mbox_len )
1318{
1319
1320 unsigned short len, udp_length, temp, ip_length;
1321 unsigned long ip_temp;
1322 int even_bound = 0;
1323 chdlc_udp_pkt_t *c_udp_pkt = (chdlc_udp_pkt_t *)data;
1324
1325 /* Set length of packet */
1326 len = sizeof(ip_pkt_t)+
1327 sizeof(udp_pkt_t)+
1328 sizeof(wp_mgmt_t)+
1329 sizeof(cblock_t)+
1330 sizeof(trace_info_t)+
1331 mbox_len;
1332
1333 /* fill in UDP reply */
1334 c_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
1335
1336 /* fill in UDP length */
1337 udp_length = sizeof(udp_pkt_t)+
1338 sizeof(wp_mgmt_t)+
1339 sizeof(cblock_t)+
1340 sizeof(trace_info_t)+
1341 mbox_len;
1342
1343 /* put it on an even boundary */
1344 if ( udp_length & 0x0001 ) {
1345 udp_length += 1;
1346 len += 1;
1347 even_bound = 1;
1348 }
1349
1350 temp = (udp_length<<8)|(udp_length>>8);
1351 c_udp_pkt->udp_pkt.udp_length = temp;
1352
1353 /* swap UDP ports */
1354 temp = c_udp_pkt->udp_pkt.udp_src_port;
1355 c_udp_pkt->udp_pkt.udp_src_port =
1356 c_udp_pkt->udp_pkt.udp_dst_port;
1357 c_udp_pkt->udp_pkt.udp_dst_port = temp;
1358
1359 /* add UDP pseudo header */
1360 temp = 0x1100;
1361 *((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound)) = temp;
1362 temp = (udp_length<<8)|(udp_length>>8);
1363 *((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound+2)) = temp;
1364
1365
1366 /* calculate UDP checksum */
1367 c_udp_pkt->udp_pkt.udp_checksum = 0;
1368 c_udp_pkt->udp_pkt.udp_checksum = calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
1369
1370 /* fill in IP length */
1371 ip_length = len;
1372 temp = (ip_length<<8)|(ip_length>>8);
1373 c_udp_pkt->ip_pkt.total_length = temp;
1374
1375 /* swap IP addresses */
1376 ip_temp = c_udp_pkt->ip_pkt.ip_src_address;
1377 c_udp_pkt->ip_pkt.ip_src_address = c_udp_pkt->ip_pkt.ip_dst_address;
1378 c_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
1379
1380 /* fill in IP checksum */
1381 c_udp_pkt->ip_pkt.hdr_checksum = 0;
1382 c_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
1383
1384 return len;
1385
1386} /* reply_udp */
1387
1388unsigned short calc_checksum (char *data, int len)
1389{
1390 unsigned short temp;
1391 unsigned long sum=0;
1392 int i;
1393
1394 for( i = 0; i <len; i+=2 ) {
1395 memcpy(&temp,&data[i],2);
1396 sum += (unsigned long)temp;
1397 }
1398
1399 while (sum >> 16 ) {
1400 sum = (sum & 0xffffUL) + (sum >> 16);
1401 }
1402
1403 temp = (unsigned short)sum;
1404 temp = ~temp;
1405
1406 if( temp == 0 )
1407 temp = 0xffff;
1408
1409 return temp;
1410}
1411
1412
1413/*============================================================================
1414 * Get ethernet-style interface statistics.
1415 * Return a pointer to struct enet_statistics.
1416 */
1417static struct net_device_stats* if_stats(struct net_device* dev)
1418{
1419 sdla_t *my_card;
1420 chdlc_private_area_t* chdlc_priv_area;
1421
1422 if ((chdlc_priv_area=dev->priv) == NULL)
1423 return NULL;
1424
1425 my_card = chdlc_priv_area->card;
1426 return &my_card->wandev.stats;
1427}
1428
1429
1430/****** Cisco HDLC Firmware Interface Functions *******************************/
1431
1432/*============================================================================
1433 * Read firmware code version.
1434 * Put code version as ASCII string in str.
1435 */
1436static int chdlc_read_version (sdla_t* card, char* str)
1437{
1438 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1439 int len;
1440 char err;
1441 mb->buffer_length = 0;
1442 mb->command = READ_CHDLC_CODE_VERSION;
1443 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1444
1445 if(err != COMMAND_OK) {
1446 chdlc_error(card,err,mb);
1447 }
1448 else if (str) { /* is not null */
1449 len = mb->buffer_length;
1450 memcpy(str, mb->data, len);
1451 str[len] = '\0';
1452 }
1453 return (err);
1454}
1455
1456/*-----------------------------------------------------------------------------
1457 * Configure CHDLC firmware.
1458 */
1459static int chdlc_configure (sdla_t* card, void* data)
1460{
1461 int err;
1462 CHDLC_MAILBOX_STRUCT *mailbox = card->mbox;
1463 int data_length = sizeof(CHDLC_CONFIGURATION_STRUCT);
1464
1465 mailbox->buffer_length = data_length;
1466 memcpy(mailbox->data, data, data_length);
1467 mailbox->command = SET_CHDLC_CONFIGURATION;
1468 err = sdla_exec(mailbox) ? mailbox->return_code : CMD_TIMEOUT;
1469
1470 if (err != COMMAND_OK) chdlc_error (card, err, mailbox);
1471
1472 return err;
1473}
1474
1475
1476/*============================================================================
1477 * Set interrupt mode -- HDLC Version.
1478 */
1479
1480static int chdlc_set_intr_mode (sdla_t* card, unsigned mode)
1481{
1482 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1483 CHDLC_INT_TRIGGERS_STRUCT* int_data =
1484 (CHDLC_INT_TRIGGERS_STRUCT *)mb->data;
1485 int err;
1486
1487 int_data->CHDLC_interrupt_triggers = mode;
1488 int_data->IRQ = card->hw.irq;
1489 int_data->interrupt_timer = 1;
1490
1491 mb->buffer_length = sizeof(CHDLC_INT_TRIGGERS_STRUCT);
1492 mb->command = SET_CHDLC_INTERRUPT_TRIGGERS;
1493 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1494 if (err != COMMAND_OK)
1495 chdlc_error (card, err, mb);
1496 return err;
1497}
1498
1499
1500/*===========================================================
1501 * chdlc_disable_comm_shutdown
1502 *
1503 * Shutdown() disables the communications. We must
1504 * have a sparate functions, because we must not
1505 * call chdlc_error() hander since the private
1506 * area has already been replaced */
1507
1508static int chdlc_disable_comm_shutdown (sdla_t *card)
1509{
1510 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1511 CHDLC_INT_TRIGGERS_STRUCT* int_data =
1512 (CHDLC_INT_TRIGGERS_STRUCT *)mb->data;
1513 int err;
1514
1515 /* Disable Interrutps */
1516 int_data->CHDLC_interrupt_triggers = 0;
1517 int_data->IRQ = card->hw.irq;
1518 int_data->interrupt_timer = 1;
1519
1520 mb->buffer_length = sizeof(CHDLC_INT_TRIGGERS_STRUCT);
1521 mb->command = SET_CHDLC_INTERRUPT_TRIGGERS;
1522 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1523
1524 /* Disable Communications */
1525
1526 if (card->u.c.async_mode) {
1527 mb->command = DISABLE_ASY_COMMUNICATIONS;
1528 }else{
1529 mb->command = DISABLE_CHDLC_COMMUNICATIONS;
1530 }
1531
1532 mb->buffer_length = 0;
1533 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1534
1535 card->u.c.comm_enabled = 0;
1536
1537 return 0;
1538}
1539
1540/*============================================================================
1541 * Enable communications.
1542 */
1543
1544static int chdlc_comm_enable (sdla_t* card)
1545{
1546 int err;
1547 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1548
1549 mb->buffer_length = 0;
1550 mb->command = ENABLE_CHDLC_COMMUNICATIONS;
1551 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1552 if (err != COMMAND_OK)
1553 chdlc_error(card, err, mb);
1554 else
1555 card->u.c.comm_enabled = 1;
1556
1557 return err;
1558}
1559
1560/*============================================================================
1561 * Read communication error statistics.
1562 */
1563static int chdlc_read_comm_err_stats (sdla_t* card)
1564{
1565 int err;
1566 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1567
1568 mb->buffer_length = 0;
1569 mb->command = READ_COMMS_ERROR_STATS;
1570 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1571 if (err != COMMAND_OK)
1572 chdlc_error(card,err,mb);
1573 return err;
1574}
1575
1576
1577/*============================================================================
1578 * Read CHDLC operational statistics.
1579 */
1580static int chdlc_read_op_stats (sdla_t* card)
1581{
1582 int err;
1583 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1584
1585 mb->buffer_length = 0;
1586 mb->command = READ_CHDLC_OPERATIONAL_STATS;
1587 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1588 if (err != COMMAND_OK)
1589 chdlc_error(card,err,mb);
1590 return err;
1591}
1592
1593
1594/*============================================================================
1595 * Update communications error and general packet statistics.
1596 */
1597static int update_comms_stats(sdla_t* card,
1598 chdlc_private_area_t* chdlc_priv_area)
1599{
1600 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1601 COMMS_ERROR_STATS_STRUCT* err_stats;
1602 CHDLC_OPERATIONAL_STATS_STRUCT *op_stats;
1603
1604 /* on the first timer interrupt, read the comms error statistics */
1605 if(chdlc_priv_area->update_comms_stats == 2) {
1606 if(chdlc_read_comm_err_stats(card))
1607 return 1;
1608 err_stats = (COMMS_ERROR_STATS_STRUCT *)mb->data;
1609 card->wandev.stats.rx_over_errors =
1610 err_stats->Rx_overrun_err_count;
1611 card->wandev.stats.rx_crc_errors =
1612 err_stats->CRC_err_count;
1613 card->wandev.stats.rx_frame_errors =
1614 err_stats->Rx_abort_count;
1615 card->wandev.stats.rx_fifo_errors =
1616 err_stats->Rx_dis_pri_bfrs_full_count;
1617 card->wandev.stats.rx_missed_errors =
1618 card->wandev.stats.rx_fifo_errors;
1619 card->wandev.stats.tx_aborted_errors =
1620 err_stats->sec_Tx_abort_count;
1621 }
1622
1623 /* on the second timer interrupt, read the operational statistics */
1624 else {
1625 if(chdlc_read_op_stats(card))
1626 return 1;
1627 op_stats = (CHDLC_OPERATIONAL_STATS_STRUCT *)mb->data;
1628 card->wandev.stats.rx_length_errors =
1629 (op_stats->Rx_Data_discard_short_count +
1630 op_stats->Rx_Data_discard_long_count);
1631 }
1632
1633 return 0;
1634}
1635
1636/*============================================================================
1637 * Send packet.
1638 * Return: 0 - o.k.
1639 * 1 - no transmit buffers available
1640 */
1641static int chdlc_send (sdla_t* card, void* data, unsigned len)
1642{
1643 CHDLC_DATA_TX_STATUS_EL_STRUCT *txbuf = card->u.c.txbuf;
1644
1645 if (txbuf->opp_flag)
1646 return 1;
1647
1648 sdla_poke(&card->hw, txbuf->ptr_data_bfr, data, len);
1649
1650 txbuf->frame_length = len;
1651 txbuf->opp_flag = 1; /* start transmission */
1652
1653 /* Update transmit buffer control fields */
1654 card->u.c.txbuf = ++txbuf;
1655
1656 if ((void*)txbuf > card->u.c.txbuf_last)
1657 card->u.c.txbuf = card->u.c.txbuf_base;
1658
1659 return 0;
1660}
1661
1662/****** Firmware Error Handler **********************************************/
1663
1664/*============================================================================
1665 * Firmware error handler.
1666 * This routine is called whenever firmware command returns non-zero
1667 * return code.
1668 *
1669 * Return zero if previous command has to be cancelled.
1670 */
1671static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb)
1672{
1673 unsigned cmd = mb->command;
1674
1675 switch (err) {
1676
1677 case CMD_TIMEOUT:
1678 printk(KERN_INFO "%s: command 0x%02X timed out!\n",
1679 card->devname, cmd);
1680 break;
1681
1682 case S514_BOTH_PORTS_SAME_CLK_MODE:
1683 if(cmd == SET_CHDLC_CONFIGURATION) {
1684 printk(KERN_INFO
1685 "%s: Configure both ports for the same clock source\n",
1686 card->devname);
1687 break;
1688 }
1689
1690 default:
1691 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n",
1692 card->devname, cmd, err);
1693 }
1694
1695 return 0;
1696}
1697
1698
1699/********** Bottom Half Handlers ********************************************/
1700
1701/* NOTE: There is no API, BH support for Kernels lower than 2.2.X.
1702 * DO NOT INSERT ANY CODE HERE, NOTICE THE
1703 * PREPROCESSOR STATEMENT ABOVE, UNLESS YOU KNOW WHAT YOU ARE
1704 * DOING */
1705
1706static void chdlc_work(struct net_device * dev)
1707{
1708 chdlc_private_area_t* chan = dev->priv;
1709 sdla_t *card = chan->card;
1710 struct sk_buff *skb;
1711
1712 if (atomic_read(&chan->bh_buff_used) == 0){
1713 clear_bit(0, &chan->tq_working);
1714 return;
1715 }
1716
1717 while (atomic_read(&chan->bh_buff_used)){
1718
1719 skb = ((bh_data_t *)&chan->bh_head[chan->bh_read])->skb;
1720
1721 if (skb != NULL){
1722
1723 if (chan->common.sk == NULL || chan->common.func == NULL){
1724 ++card->wandev.stats.rx_dropped;
1725 dev_kfree_skb_any(skb);
1726 chdlc_work_cleanup(dev);
1727 continue;
1728 }
1729
1730 if (chan->common.func(skb,dev,chan->common.sk) != 0){
1731 /* Sock full cannot send, queue us for another
1732 * try */
1733 atomic_set(&chan->common.receive_block,1);
1734 return;
1735 }else{
1736 chdlc_work_cleanup(dev);
1737 }
1738 }else{
1739 chdlc_work_cleanup(dev);
1740 }
1741 }
1742 clear_bit(0, &chan->tq_working);
1743
1744 return;
1745}
1746
1747static int chdlc_work_cleanup(struct net_device *dev)
1748{
1749 chdlc_private_area_t* chan = dev->priv;
1750
1751 ((bh_data_t *)&chan->bh_head[chan->bh_read])->skb = NULL;
1752
1753 if (chan->bh_read == MAX_BH_BUFF){
1754 chan->bh_read=0;
1755 }else{
1756 ++chan->bh_read;
1757 }
1758
1759 atomic_dec(&chan->bh_buff_used);
1760 return 0;
1761}
1762
1763
1764
1765static int bh_enqueue(struct net_device *dev, struct sk_buff *skb)
1766{
1767 /* Check for full */
1768 chdlc_private_area_t* chan = dev->priv;
1769 sdla_t *card = chan->card;
1770
1771 if (atomic_read(&chan->bh_buff_used) == (MAX_BH_BUFF+1)){
1772 ++card->wandev.stats.rx_dropped;
1773 dev_kfree_skb_any(skb);
1774 return 1;
1775 }
1776
1777 ((bh_data_t *)&chan->bh_head[chan->bh_write])->skb = skb;
1778
1779 if (chan->bh_write == MAX_BH_BUFF){
1780 chan->bh_write=0;
1781 }else{
1782 ++chan->bh_write;
1783 }
1784
1785 atomic_inc(&chan->bh_buff_used);
1786
1787 return 0;
1788}
1789
1790/* END OF API BH Support */
1791
1792
1793/****** Interrupt Handlers **************************************************/
1794
1795/*============================================================================
1796 * Cisco HDLC interrupt service routine.
1797 */
1798static void wpc_isr (sdla_t* card)
1799{
1800 struct net_device* dev;
1801 SHARED_MEMORY_INFO_STRUCT* flags = NULL;
1802 int i;
1803 sdla_t *my_card;
1804
1805
1806 /* Check for which port the interrupt has been generated
1807 * Since Secondary Port is piggybacking on the Primary
1808 * the check must be done here.
1809 */
1810
1811 flags = card->u.c.flags;
1812 if (!flags->interrupt_info_struct.interrupt_type){
1813 /* Check for a second port (piggybacking) */
1814 if ((my_card = card->next)){
1815 flags = my_card->u.c.flags;
1816 if (flags->interrupt_info_struct.interrupt_type){
1817 card = my_card;
1818 card->isr(card);
1819 return;
1820 }
1821 }
1822 }
1823
1824 flags = card->u.c.flags;
1825 card->in_isr = 1;
1826 dev = card->wandev.dev;
1827
1828 /* If we get an interrupt with no network device, stop the interrupts
1829 * and issue an error */
1830 if (!card->tty_opt && !dev &&
1831 flags->interrupt_info_struct.interrupt_type !=
1832 COMMAND_COMPLETE_APP_INT_PEND){
1833
1834 goto isr_done;
1835 }
1836
1837 /* if critical due to peripheral operations
1838 * ie. update() or getstats() then reset the interrupt and
1839 * wait for the board to retrigger.
1840 */
1841 if(test_bit(PERI_CRIT, (void*)&card->wandev.critical)) {
1842 printk(KERN_INFO "ISR CRIT TO PERI\n");
1843 goto isr_done;
1844 }
1845
1846 /* On a 508 Card, if critical due to if_send
1847 * Major Error !!! */
1848 if(card->hw.type != SDLA_S514) {
1849 if(test_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
1850 printk(KERN_INFO "%s: Critical while in ISR: %lx\n",
1851 card->devname, card->wandev.critical);
1852 card->in_isr = 0;
1853 flags->interrupt_info_struct.interrupt_type = 0;
1854 return;
1855 }
1856 }
1857
1858 switch(flags->interrupt_info_struct.interrupt_type) {
1859
1860 case RX_APP_INT_PEND: /* 0x01: receive interrupt */
1861 rx_intr(card);
1862 break;
1863
1864 case TX_APP_INT_PEND: /* 0x02: transmit interrupt */
1865 flags->interrupt_info_struct.interrupt_permission &=
1866 ~APP_INT_ON_TX_FRAME;
1867
1868 if (card->tty_opt){
1869 wanpipe_tty_trigger_poll(card);
1870 break;
1871 }
1872
1873 if (dev && netif_queue_stopped(dev)){
1874 if (card->u.c.usedby == API){
1875 netif_start_queue(dev);
1876 wakeup_sk_bh(dev);
1877 }else{
1878 netif_wake_queue(dev);
1879 }
1880 }
1881 break;
1882
1883 case COMMAND_COMPLETE_APP_INT_PEND:/* 0x04: cmd cplt */
1884 ++ Intr_test_counter;
1885 break;
1886
1887 case CHDLC_EXCEP_COND_APP_INT_PEND: /* 0x20 */
1888 process_chdlc_exception(card);
1889 break;
1890
1891 case GLOBAL_EXCEP_COND_APP_INT_PEND:
1892 process_global_exception(card);
1893 break;
1894
1895 case TIMER_APP_INT_PEND:
1896 timer_intr(card);
1897 break;
1898
1899 default:
1900 printk(KERN_INFO "%s: spurious interrupt 0x%02X!\n",
1901 card->devname,
1902 flags->interrupt_info_struct.interrupt_type);
1903 printk(KERN_INFO "Code name: ");
1904 for(i = 0; i < 4; i ++)
1905 printk(KERN_INFO "%c",
1906 flags->global_info_struct.codename[i]);
1907 printk(KERN_INFO "\nCode version: ");
1908 for(i = 0; i < 4; i ++)
1909 printk(KERN_INFO "%c",
1910 flags->global_info_struct.codeversion[i]);
1911 printk(KERN_INFO "\n");
1912 break;
1913 }
1914
1915isr_done:
1916
1917 card->in_isr = 0;
1918 flags->interrupt_info_struct.interrupt_type = 0;
1919 return;
1920}
1921
1922/*============================================================================
1923 * Receive interrupt handler.
1924 */
1925static void rx_intr (sdla_t* card)
1926{
1927 struct net_device *dev;
1928 chdlc_private_area_t *chdlc_priv_area;
1929 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
1930 CHDLC_DATA_RX_STATUS_EL_STRUCT *rxbuf = card->u.c.rxmb;
1931 struct sk_buff *skb;
1932 unsigned len;
1933 unsigned addr = rxbuf->ptr_data_bfr;
1934 void *buf;
1935 int i,udp_type;
1936
1937 if (rxbuf->opp_flag != 0x01) {
1938 printk(KERN_INFO
1939 "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
1940 card->devname, (unsigned)rxbuf, rxbuf->opp_flag);
1941 printk(KERN_INFO "Code name: ");
1942 for(i = 0; i < 4; i ++)
1943 printk(KERN_INFO "%c",
1944 flags->global_info_struct.codename[i]);
1945 printk(KERN_INFO "\nCode version: ");
1946 for(i = 0; i < 4; i ++)
1947 printk(KERN_INFO "%c",
1948 flags->global_info_struct.codeversion[i]);
1949 printk(KERN_INFO "\n");
1950
1951
1952 /* Bug Fix: Mar 6 2000
1953 * If we get a corrupted mailbox, it measn that driver
1954 * is out of sync with the firmware. There is no recovery.
1955 * If we don't turn off all interrupts for this card
1956 * the machine will crash.
1957 */
1958 printk(KERN_INFO "%s: Critical router failure ...!!!\n", card->devname);
1959 printk(KERN_INFO "Please contact Sangoma Technologies !\n");
1960 chdlc_set_intr_mode(card,0);
1961 return;
1962 }
1963
1964 len = rxbuf->frame_length;
1965
1966 if (card->tty_opt){
1967
1968 if (rxbuf->error_flag){
1969 goto rx_exit;
1970 }
1971
1972 if (len <= CRC_LENGTH){
1973 goto rx_exit;
1974 }
1975
1976 if (!card->u.c.async_mode){
1977 len -= CRC_LENGTH;
1978 }
1979
1980 wanpipe_tty_receive(card,addr,len);
1981 goto rx_exit;
1982 }
1983
1984 dev = card->wandev.dev;
1985
1986 if (!dev){
1987 goto rx_exit;
1988 }
1989
1990 if (!netif_running(dev))
1991 goto rx_exit;
1992
1993 chdlc_priv_area = dev->priv;
1994
1995
1996 /* Allocate socket buffer */
1997 skb = dev_alloc_skb(len);
1998
1999 if (skb == NULL) {
2000 printk(KERN_INFO "%s: no socket buffers available!\n",
2001 card->devname);
2002 ++card->wandev.stats.rx_dropped;
2003 goto rx_exit;
2004 }
2005
2006 /* Copy data to the socket buffer */
2007 if((addr + len) > card->u.c.rx_top + 1) {
2008 unsigned tmp = card->u.c.rx_top - addr + 1;
2009 buf = skb_put(skb, tmp);
2010 sdla_peek(&card->hw, addr, buf, tmp);
2011 addr = card->u.c.rx_base;
2012 len -= tmp;
2013 }
2014
2015 buf = skb_put(skb, len);
2016 sdla_peek(&card->hw, addr, buf, len);
2017
2018 skb->protocol = htons(ETH_P_IP);
2019
2020 card->wandev.stats.rx_packets ++;
2021 card->wandev.stats.rx_bytes += skb->len;
2022 udp_type = udp_pkt_type( skb, card );
2023
2024 if(udp_type == UDP_CPIPE_TYPE) {
2025 if(store_udp_mgmt_pkt(UDP_PKT_FRM_NETWORK,
2026 card, skb, dev, chdlc_priv_area)) {
2027 flags->interrupt_info_struct.
2028 interrupt_permission |=
2029 APP_INT_ON_TIMER;
2030 }
2031 } else if(card->u.c.usedby == API) {
2032
2033 api_rx_hdr_t* api_rx_hdr;
2034 skb_push(skb, sizeof(api_rx_hdr_t));
2035 api_rx_hdr = (api_rx_hdr_t*)&skb->data[0x00];
2036 api_rx_hdr->error_flag = rxbuf->error_flag;
2037 api_rx_hdr->time_stamp = rxbuf->time_stamp;
2038
2039 skb->protocol = htons(PVC_PROT);
2040 skb->mac.raw = skb->data;
2041 skb->dev = dev;
2042 skb->pkt_type = WAN_PACKET_DATA;
2043
2044 bh_enqueue(dev, skb);
2045
2046 if (!test_and_set_bit(0,&chdlc_priv_area->tq_working))
2047 wanpipe_queue_work(&chdlc_priv_area->common.wanpipe_work);
2048 }else{
2049 /* FIXME: we should check to see if the received packet is a
2050 multicast packet so that we can increment the multicast
2051 statistic
2052 ++ chdlc_priv_area->if_stats.multicast;
2053 */
2054 /* Pass it up the protocol stack */
2055
2056 skb->dev = dev;
2057 skb->mac.raw = skb->data;
2058 netif_rx(skb);
2059 dev->last_rx = jiffies;
2060 }
2061
2062rx_exit:
2063 /* Release buffer element and calculate a pointer to the next one */
2064 rxbuf->opp_flag = 0x00;
2065 card->u.c.rxmb = ++ rxbuf;
2066 if((void*)rxbuf > card->u.c.rxbuf_last){
2067 card->u.c.rxmb = card->u.c.rxbuf_base;
2068 }
2069}
2070
2071/*============================================================================
2072 * Timer interrupt handler.
2073 * The timer interrupt is used for two purposes:
2074 * 1) Processing udp calls from 'cpipemon'.
2075 * 2) Reading board-level statistics for updating the proc file system.
2076 */
2077void timer_intr(sdla_t *card)
2078{
2079 struct net_device* dev;
2080 chdlc_private_area_t* chdlc_priv_area = NULL;
2081 SHARED_MEMORY_INFO_STRUCT* flags = NULL;
2082
2083 if ((dev = card->wandev.dev)==NULL){
2084 flags = card->u.c.flags;
2085 flags->interrupt_info_struct.interrupt_permission &=
2086 ~APP_INT_ON_TIMER;
2087 return;
2088 }
2089
2090 chdlc_priv_area = dev->priv;
2091
2092 if (chdlc_priv_area->timer_int_enabled & TMR_INT_ENABLED_CONFIG) {
2093 if (!config_chdlc(card)){
2094 chdlc_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_CONFIG;
2095 }
2096 }
2097
2098 /* process a udp call if pending */
2099 if(chdlc_priv_area->timer_int_enabled & TMR_INT_ENABLED_UDP) {
2100 process_udp_mgmt_pkt(card, dev,
2101 chdlc_priv_area);
2102 chdlc_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UDP;
2103 }
2104
2105 /* read the communications statistics if required */
2106 if(chdlc_priv_area->timer_int_enabled & TMR_INT_ENABLED_UPDATE) {
2107 update_comms_stats(card, chdlc_priv_area);
2108 if(!(-- chdlc_priv_area->update_comms_stats)) {
2109 chdlc_priv_area->timer_int_enabled &=
2110 ~TMR_INT_ENABLED_UPDATE;
2111 }
2112 }
2113
2114 /* only disable the timer interrupt if there are no udp or statistic */
2115 /* updates pending */
2116 if(!chdlc_priv_area->timer_int_enabled) {
2117 flags = card->u.c.flags;
2118 flags->interrupt_info_struct.interrupt_permission &=
2119 ~APP_INT_ON_TIMER;
2120 }
2121}
2122
2123/*------------------------------------------------------------------------------
2124 Miscellaneous Functions
2125 - set_chdlc_config() used to set configuration options on the board
2126------------------------------------------------------------------------------*/
2127
2128static int set_chdlc_config(sdla_t* card)
2129{
2130 CHDLC_CONFIGURATION_STRUCT cfg;
2131
2132 memset(&cfg, 0, sizeof(CHDLC_CONFIGURATION_STRUCT));
2133
2134 if(card->wandev.clocking){
2135 cfg.baud_rate = card->wandev.bps;
2136 }
2137
2138 cfg.line_config_options = (card->wandev.interface == WANOPT_RS232) ?
2139 INTERFACE_LEVEL_RS232 : INTERFACE_LEVEL_V35;
2140
2141 cfg.modem_config_options = 0;
2142 cfg.modem_status_timer = 100;
2143
2144 cfg.CHDLC_protocol_options = card->u.c.protocol_options;
2145
2146 if (card->tty_opt){
2147 cfg.CHDLC_API_options = DISCARD_RX_ERROR_FRAMES;
2148 }
2149
2150 cfg.percent_data_buffer_for_Tx = (card->u.c.receive_only) ? 0 : 50;
2151 cfg.CHDLC_statistics_options = (CHDLC_TX_DATA_BYTE_COUNT_STAT |
2152 CHDLC_RX_DATA_BYTE_COUNT_STAT);
2153
2154 if (card->tty_opt){
2155 card->wandev.mtu = TTY_CHDLC_MAX_MTU;
2156 }
2157 cfg.max_CHDLC_data_field_length = card->wandev.mtu;
2158 cfg.transmit_keepalive_timer = card->u.c.kpalv_tx;
2159 cfg.receive_keepalive_timer = card->u.c.kpalv_rx;
2160 cfg.keepalive_error_tolerance = card->u.c.kpalv_err;
2161 cfg.SLARP_request_timer = card->u.c.slarp_timer;
2162
2163 if (cfg.SLARP_request_timer) {
2164 cfg.IP_address = 0;
2165 cfg.IP_netmask = 0;
2166
2167 }else if (card->wandev.dev){
2168 struct net_device *dev = card->wandev.dev;
2169 chdlc_private_area_t *chdlc_priv_area = dev->priv;
2170
2171 struct in_device *in_dev = dev->ip_ptr;
2172
2173 if(in_dev != NULL) {
2174 struct in_ifaddr *ifa = in_dev->ifa_list;
2175
2176 if (ifa != NULL ) {
2177 cfg.IP_address = ntohl(ifa->ifa_local);
2178 cfg.IP_netmask = ntohl(ifa->ifa_mask);
2179 chdlc_priv_area->IP_address = ntohl(ifa->ifa_local);
2180 chdlc_priv_area->IP_netmask = ntohl(ifa->ifa_mask);
2181 }
2182 }
2183
2184 /* FIXME: We must re-think this message in next release
2185 if((cfg.IP_address & 0x000000FF) > 2) {
2186 printk(KERN_WARNING "\n");
2187 printk(KERN_WARNING " WARNING:%s configured with an\n",
2188 card->devname);
2189 printk(KERN_WARNING " invalid local IP address.\n");
2190 printk(KERN_WARNING " Slarp pragmatics will fail.\n");
2191 printk(KERN_WARNING " IP address should be of the\n");
2192 printk(KERN_WARNING " format A.B.C.1 or A.B.C.2.\n");
2193 }
2194 */
2195 }
2196
2197 return chdlc_configure(card, &cfg);
2198}
2199
2200
2201/*-----------------------------------------------------------------------------
2202 set_asy_config() used to set asynchronous configuration options on the board
2203------------------------------------------------------------------------------*/
2204
2205static int set_asy_config(sdla_t* card)
2206{
2207
2208 ASY_CONFIGURATION_STRUCT cfg;
2209 CHDLC_MAILBOX_STRUCT *mailbox = card->mbox;
2210 int err;
2211
2212 memset(&cfg, 0, sizeof(ASY_CONFIGURATION_STRUCT));
2213
2214 if(card->wandev.clocking)
2215 cfg.baud_rate = card->wandev.bps;
2216
2217 cfg.line_config_options = (card->wandev.interface == WANOPT_RS232) ?
2218 INTERFACE_LEVEL_RS232 : INTERFACE_LEVEL_V35;
2219
2220 cfg.modem_config_options = 0;
2221 cfg.asy_API_options = card->u.c.api_options;
2222 cfg.asy_protocol_options = card->u.c.protocol_options;
2223 cfg.Tx_bits_per_char = card->u.c.tx_bits_per_char;
2224 cfg.Rx_bits_per_char = card->u.c.rx_bits_per_char;
2225 cfg.stop_bits = card->u.c.stop_bits;
2226 cfg.parity = card->u.c.parity;
2227 cfg.break_timer = card->u.c.break_timer;
2228 cfg.asy_Rx_inter_char_timer = card->u.c.inter_char_timer;
2229 cfg.asy_Rx_complete_length = card->u.c.rx_complete_length;
2230 cfg.XON_char = card->u.c.xon_char;
2231 cfg.XOFF_char = card->u.c.xoff_char;
2232 cfg.asy_statistics_options = (CHDLC_TX_DATA_BYTE_COUNT_STAT |
2233 CHDLC_RX_DATA_BYTE_COUNT_STAT);
2234
2235 mailbox->buffer_length = sizeof(ASY_CONFIGURATION_STRUCT);
2236 memcpy(mailbox->data, &cfg, mailbox->buffer_length);
2237 mailbox->command = SET_ASY_CONFIGURATION;
2238 err = sdla_exec(mailbox) ? mailbox->return_code : CMD_TIMEOUT;
2239 if (err != COMMAND_OK)
2240 chdlc_error (card, err, mailbox);
2241 return err;
2242}
2243
2244/*============================================================================
2245 * Enable asynchronous communications.
2246 */
2247
2248static int asy_comm_enable (sdla_t* card)
2249{
2250
2251 int err;
2252 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
2253
2254 mb->buffer_length = 0;
2255 mb->command = ENABLE_ASY_COMMUNICATIONS;
2256 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2257 if (err != COMMAND_OK && card->wandev.dev)
2258 chdlc_error(card, err, mb);
2259
2260 if (!err)
2261 card->u.c.comm_enabled = 1;
2262
2263 return err;
2264}
2265
2266/*============================================================================
2267 * Process global exception condition
2268 */
2269static int process_global_exception(sdla_t *card)
2270{
2271 CHDLC_MAILBOX_STRUCT* mbox = card->mbox;
2272 int err;
2273
2274 mbox->buffer_length = 0;
2275 mbox->command = READ_GLOBAL_EXCEPTION_CONDITION;
2276 err = sdla_exec(mbox) ? mbox->return_code : CMD_TIMEOUT;
2277
2278 if(err != CMD_TIMEOUT ){
2279
2280 switch(mbox->return_code) {
2281
2282 case EXCEP_MODEM_STATUS_CHANGE:
2283
2284 printk(KERN_INFO "%s: Modem status change\n",
2285 card->devname);
2286
2287 switch(mbox->data[0] & (DCD_HIGH | CTS_HIGH)) {
2288 case (DCD_HIGH):
2289 printk(KERN_INFO "%s: DCD high, CTS low\n",card->devname);
2290 break;
2291 case (CTS_HIGH):
2292 printk(KERN_INFO "%s: DCD low, CTS high\n",card->devname);
2293 break;
2294 case ((DCD_HIGH | CTS_HIGH)):
2295 printk(KERN_INFO "%s: DCD high, CTS high\n",card->devname);
2296 break;
2297 default:
2298 printk(KERN_INFO "%s: DCD low, CTS low\n",card->devname);
2299 break;
2300 }
2301 break;
2302
2303 case EXCEP_TRC_DISABLED:
2304 printk(KERN_INFO "%s: Line trace disabled\n",
2305 card->devname);
2306 break;
2307
2308 case EXCEP_IRQ_TIMEOUT:
2309 printk(KERN_INFO "%s: IRQ timeout occurred\n",
2310 card->devname);
2311 break;
2312
2313 case 0x17:
2314 if (card->tty_opt){
2315 if (card->tty && card->tty_open){
2316 printk(KERN_INFO
2317 "%s: Modem Hangup Exception: Hanging Up!\n",
2318 card->devname);
2319 tty_hangup(card->tty);
2320 }
2321 break;
2322 }
2323
2324 /* If TTY is not used just drop throught */
2325
2326 default:
2327 printk(KERN_INFO "%s: Global exception %x\n",
2328 card->devname, mbox->return_code);
2329 break;
2330 }
2331 }
2332 return 0;
2333}
2334
2335
2336/*============================================================================
2337 * Process chdlc exception condition
2338 */
2339static int process_chdlc_exception(sdla_t *card)
2340{
2341 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
2342 int err;
2343
2344 mb->buffer_length = 0;
2345 mb->command = READ_CHDLC_EXCEPTION_CONDITION;
2346 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2347 if(err != CMD_TIMEOUT) {
2348
2349 switch (err) {
2350
2351 case EXCEP_LINK_ACTIVE:
2352 port_set_state(card, WAN_CONNECTED);
2353 trigger_chdlc_poll(card->wandev.dev);
2354 break;
2355
2356 case EXCEP_LINK_INACTIVE_MODEM:
2357 port_set_state(card, WAN_DISCONNECTED);
2358 unconfigure_ip(card);
2359 trigger_chdlc_poll(card->wandev.dev);
2360 break;
2361
2362 case EXCEP_LINK_INACTIVE_KPALV:
2363 port_set_state(card, WAN_DISCONNECTED);
2364 printk(KERN_INFO "%s: Keepalive timer expired.\n",
2365 card->devname);
2366 unconfigure_ip(card);
2367 trigger_chdlc_poll(card->wandev.dev);
2368 break;
2369
2370 case EXCEP_IP_ADDRESS_DISCOVERED:
2371 if (configure_ip(card))
2372 return -1;
2373 break;
2374
2375 case EXCEP_LOOPBACK_CONDITION:
2376 printk(KERN_INFO "%s: Loopback Condition Detected.\n",
2377 card->devname);
2378 break;
2379
2380 case NO_CHDLC_EXCEP_COND_TO_REPORT:
2381 printk(KERN_INFO "%s: No exceptions reported.\n",
2382 card->devname);
2383 break;
2384 }
2385
2386 }
2387 return 0;
2388}
2389
2390
2391/*============================================================================
2392 * Configure IP from SLARP negotiation
2393 * This adds dynamic routes when SLARP has provided valid addresses
2394 */
2395
2396static int configure_ip (sdla_t* card)
2397{
2398 struct net_device *dev = card->wandev.dev;
2399 chdlc_private_area_t *chdlc_priv_area;
2400 char err;
2401
2402 if (!dev)
2403 return 0;
2404
2405 chdlc_priv_area = dev->priv;
2406
2407
2408 /* set to discover */
2409 if(card->u.c.slarp_timer != 0x00) {
2410 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
2411 CHDLC_CONFIGURATION_STRUCT *cfg;
2412
2413 mb->buffer_length = 0;
2414 mb->command = READ_CHDLC_CONFIGURATION;
2415 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2416
2417 if(err != COMMAND_OK) {
2418 chdlc_error(card,err,mb);
2419 return -1;
2420 }
2421
2422 cfg = (CHDLC_CONFIGURATION_STRUCT *)mb->data;
2423 chdlc_priv_area->IP_address = cfg->IP_address;
2424 chdlc_priv_area->IP_netmask = cfg->IP_netmask;
2425
2426 /* Set flag to add route */
2427 chdlc_priv_area->route_status = ADD_ROUTE;
2428
2429 /* The idea here is to add the route in the poll routine.
2430 This way, we aren't in interrupt context when adding routes */
2431 trigger_chdlc_poll(dev);
2432 }
2433
2434 return 0;
2435}
2436
2437
2438/*============================================================================
2439 * Un-Configure IP negotiated by SLARP
2440 * This removes dynamic routes when the link becomes inactive.
2441 */
2442
2443static int unconfigure_ip (sdla_t* card)
2444{
2445 struct net_device *dev = card->wandev.dev;
2446 chdlc_private_area_t *chdlc_priv_area;
2447
2448 if (!dev)
2449 return 0;
2450
2451 chdlc_priv_area= dev->priv;
2452
2453 if (chdlc_priv_area->route_status == ROUTE_ADDED) {
2454
2455 /* Note: If this function is called, the
2456 * port state has been DISCONNECTED. This state
2457 * change will trigger a poll_disconnected
2458 * function, that will check for this condition.
2459 */
2460 chdlc_priv_area->route_status = REMOVE_ROUTE;
2461
2462 }
2463 return 0;
2464}
2465
2466/*============================================================================
2467 * Routine to add/remove routes
2468 * Called like a polling routine when Routes are flagged to be added/removed.
2469 */
2470
2471static void process_route (sdla_t *card)
2472{
2473 struct net_device *dev = card->wandev.dev;
2474 unsigned char port_num;
2475 chdlc_private_area_t *chdlc_priv_area = NULL;
2476 u32 local_IP_addr = 0;
2477 u32 remote_IP_addr = 0;
2478 u32 IP_netmask, IP_addr;
2479 int err = 0;
2480 struct in_device *in_dev;
2481 mm_segment_t fs;
2482 struct ifreq if_info;
2483 struct sockaddr_in *if_data1, *if_data2;
2484
2485 chdlc_priv_area = dev->priv;
2486 port_num = card->u.c.comm_port;
2487
2488 /* Bug Fix Mar 16 2000
2489 * AND the IP address to the Mask before checking
2490 * the last two bits. */
2491
2492 if((chdlc_priv_area->route_status == ADD_ROUTE) &&
2493 ((chdlc_priv_area->IP_address & ~chdlc_priv_area->IP_netmask) > 2)) {
2494
2495 printk(KERN_INFO "%s: Dynamic route failure.\n",card->devname);
2496
2497 if(card->u.c.slarp_timer) {
2498 u32 addr_net = htonl(chdlc_priv_area->IP_address);
2499
2500 printk(KERN_INFO "%s: Bad IP address %u.%u.%u.%u received\n",
2501 card->devname,
2502 NIPQUAD(addr_net));
2503 printk(KERN_INFO "%s: from remote station.\n",
2504 card->devname);
2505
2506 }else{
2507 u32 addr_net = htonl(chdlc_priv_area->IP_address);
2508
2509 printk(KERN_INFO "%s: Bad IP address %u.%u.%u.%u issued\n",
2510 card->devname,
2511 NIPQUAD(addr_net));
2512 printk(KERN_INFO "%s: to remote station. Local\n",
2513 card->devname);
2514 printk(KERN_INFO "%s: IP address must be A.B.C.1\n",
2515 card->devname);
2516 printk(KERN_INFO "%s: or A.B.C.2.\n",card->devname);
2517 }
2518
2519 /* remove the route due to the IP address error condition */
2520 chdlc_priv_area->route_status = REMOVE_ROUTE;
2521 err = 1;
2522 }
2523
2524 /* If we are removing a route with bad IP addressing, then use the */
2525 /* locally configured IP addresses */
2526 if((chdlc_priv_area->route_status == REMOVE_ROUTE) && err) {
2527
2528 /* do not remove a bad route that has already been removed */
2529 if(chdlc_priv_area->route_removed) {
2530 return;
2531 }
2532
2533 in_dev = dev->ip_ptr;
2534
2535 if(in_dev != NULL) {
2536 struct in_ifaddr *ifa = in_dev->ifa_list;
2537 if (ifa != NULL ) {
2538 local_IP_addr = ifa->ifa_local;
2539 IP_netmask = ifa->ifa_mask;
2540 }
2541 }
2542 }else{
2543 /* According to Cisco HDLC, if the point-to-point address is
2544 A.B.C.1, then we are the opposite (A.B.C.2), and vice-versa.
2545 */
2546 IP_netmask = ntohl(chdlc_priv_area->IP_netmask);
2547 remote_IP_addr = ntohl(chdlc_priv_area->IP_address);
2548
2549
2550 /* If Netmask is 255.255.255.255 the local address
2551 * calculation will fail. Default it back to 255.255.255.0 */
2552 if (IP_netmask == 0xffffffff)
2553 IP_netmask &= 0x00ffffff;
2554
2555 /* Bug Fix Mar 16 2000
2556 * AND the Remote IP address with IP netmask, instead
2557 * of static netmask of 255.255.255.0 */
2558 local_IP_addr = (remote_IP_addr & IP_netmask) +
2559 (~remote_IP_addr & ntohl(0x0003));
2560
2561 if(!card->u.c.slarp_timer) {
2562 IP_addr = local_IP_addr;
2563 local_IP_addr = remote_IP_addr;
2564 remote_IP_addr = IP_addr;
2565 }
2566 }
2567
2568 fs = get_fs(); /* Save file system */
2569 set_fs(get_ds()); /* Get user space block */
2570
2571 /* Setup a structure for adding/removing routes */
2572 memset(&if_info, 0, sizeof(if_info));
2573 strcpy(if_info.ifr_name, dev->name);
2574
2575 switch (chdlc_priv_area->route_status) {
2576
2577 case ADD_ROUTE:
2578
2579 if(!card->u.c.slarp_timer) {
2580 if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2581 if_data2->sin_addr.s_addr = remote_IP_addr;
2582 if_data2->sin_family = AF_INET;
2583 err = devinet_ioctl(SIOCSIFDSTADDR, &if_info);
2584 } else {
2585 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2586 if_data1->sin_addr.s_addr = local_IP_addr;
2587 if_data1->sin_family = AF_INET;
2588 if(!(err = devinet_ioctl(SIOCSIFADDR, &if_info))){
2589 if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2590 if_data2->sin_addr.s_addr = remote_IP_addr;
2591 if_data2->sin_family = AF_INET;
2592 err = devinet_ioctl(SIOCSIFDSTADDR, &if_info);
2593 }
2594 }
2595
2596 if(err) {
2597 printk(KERN_INFO "%s: Add route %u.%u.%u.%u failed (%d)\n",
2598 card->devname, NIPQUAD(remote_IP_addr), err);
2599 } else {
2600 ((chdlc_private_area_t *)dev->priv)->route_status = ROUTE_ADDED;
2601 printk(KERN_INFO "%s: Dynamic route added.\n",
2602 card->devname);
2603 printk(KERN_INFO "%s: Local IP addr : %u.%u.%u.%u\n",
2604 card->devname, NIPQUAD(local_IP_addr));
2605 printk(KERN_INFO "%s: Remote IP addr: %u.%u.%u.%u\n",
2606 card->devname, NIPQUAD(remote_IP_addr));
2607 chdlc_priv_area->route_removed = 0;
2608 }
2609 break;
2610
2611
2612 case REMOVE_ROUTE:
2613
2614 /* Change the local ip address of the interface to 0.
2615 * This will also delete the destination route.
2616 */
2617 if(!card->u.c.slarp_timer) {
2618 if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2619 if_data2->sin_addr.s_addr = 0;
2620 if_data2->sin_family = AF_INET;
2621 err = devinet_ioctl(SIOCSIFDSTADDR, &if_info);
2622 } else {
2623 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2624 if_data1->sin_addr.s_addr = 0;
2625 if_data1->sin_family = AF_INET;
2626 err = devinet_ioctl(SIOCSIFADDR,&if_info);
2627
2628 }
2629 if(err) {
2630 printk(KERN_INFO
2631 "%s: Remove route %u.%u.%u.%u failed, (err %d)\n",
2632 card->devname, NIPQUAD(remote_IP_addr),
2633 err);
2634 } else {
2635 ((chdlc_private_area_t *)dev->priv)->route_status =
2636 NO_ROUTE;
2637 printk(KERN_INFO "%s: Dynamic route removed: %u.%u.%u.%u\n",
2638 card->devname, NIPQUAD(local_IP_addr));
2639 chdlc_priv_area->route_removed = 1;
2640 }
2641 break;
2642 }
2643
2644 set_fs(fs); /* Restore file system */
2645
2646}
2647
2648
2649/*=============================================================================
2650 * Store a UDP management packet for later processing.
2651 */
2652
2653static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
2654 struct sk_buff *skb, struct net_device* dev,
2655 chdlc_private_area_t* chdlc_priv_area)
2656{
2657 int udp_pkt_stored = 0;
2658
2659 if(!chdlc_priv_area->udp_pkt_lgth &&
2660 (skb->len <= MAX_LGTH_UDP_MGNT_PKT)) {
2661 chdlc_priv_area->udp_pkt_lgth = skb->len;
2662 chdlc_priv_area->udp_pkt_src = udp_pkt_src;
2663 memcpy(chdlc_priv_area->udp_pkt_data, skb->data, skb->len);
2664 chdlc_priv_area->timer_int_enabled = TMR_INT_ENABLED_UDP;
2665 udp_pkt_stored = 1;
2666 }
2667
2668 if(udp_pkt_src == UDP_PKT_FRM_STACK){
2669 dev_kfree_skb_any(skb);
2670 }else{
2671 dev_kfree_skb_any(skb);
2672 }
2673
2674 return(udp_pkt_stored);
2675}
2676
2677
2678/*=============================================================================
2679 * Process UDP management packet.
2680 */
2681
2682static int process_udp_mgmt_pkt(sdla_t* card, struct net_device* dev,
2683 chdlc_private_area_t* chdlc_priv_area )
2684{
2685 unsigned char *buf;
2686 unsigned int frames, len;
2687 struct sk_buff *new_skb;
2688 unsigned short buffer_length, real_len;
2689 unsigned long data_ptr;
2690 unsigned data_length;
2691 int udp_mgmt_req_valid = 1;
2692 CHDLC_MAILBOX_STRUCT *mb = card->mbox;
2693 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
2694 chdlc_udp_pkt_t *chdlc_udp_pkt;
2695 struct timeval tv;
2696 int err;
2697 char ut_char;
2698
2699 chdlc_udp_pkt = (chdlc_udp_pkt_t *) chdlc_priv_area->udp_pkt_data;
2700
2701 if(chdlc_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK){
2702
2703 /* Only these commands are support for remote debugging.
2704 * All others are not */
2705 switch(chdlc_udp_pkt->cblock.command) {
2706
2707 case READ_GLOBAL_STATISTICS:
2708 case READ_MODEM_STATUS:
2709 case READ_CHDLC_LINK_STATUS:
2710 case CPIPE_ROUTER_UP_TIME:
2711 case READ_COMMS_ERROR_STATS:
2712 case READ_CHDLC_OPERATIONAL_STATS:
2713
2714 /* These two commands are executed for
2715 * each request */
2716 case READ_CHDLC_CONFIGURATION:
2717 case READ_CHDLC_CODE_VERSION:
2718 udp_mgmt_req_valid = 1;
2719 break;
2720 default:
2721 udp_mgmt_req_valid = 0;
2722 break;
2723 }
2724 }
2725
2726 if(!udp_mgmt_req_valid) {
2727
2728 /* set length to 0 */
2729 chdlc_udp_pkt->cblock.buffer_length = 0;
2730
2731 /* set return code */
2732 chdlc_udp_pkt->cblock.return_code = 0xCD;
2733
2734 if (net_ratelimit()){
2735 printk(KERN_INFO
2736 "%s: Warning, Illegal UDP command attempted from network: %x\n",
2737 card->devname,chdlc_udp_pkt->cblock.command);
2738 }
2739
2740 } else {
2741 unsigned long trace_status_cfg_addr = 0;
2742 TRACE_STATUS_EL_CFG_STRUCT trace_cfg_struct;
2743 TRACE_STATUS_ELEMENT_STRUCT trace_element_struct;
2744
2745 switch(chdlc_udp_pkt->cblock.command) {
2746
2747 case CPIPE_ENABLE_TRACING:
2748 if (!chdlc_priv_area->TracingEnabled) {
2749
2750 /* OPERATE_DATALINE_MONITOR */
2751
2752 mb->buffer_length = sizeof(LINE_TRACE_CONFIG_STRUCT);
2753 mb->command = SET_TRACE_CONFIGURATION;
2754
2755 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->
2756 trace_config = TRACE_ACTIVE;
2757 /* Trace delay mode is not used because it slows
2758 down transfer and results in a standoff situation
2759 when there is a lot of data */
2760
2761 /* Configure the Trace based on user inputs */
2762 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->trace_config |=
2763 chdlc_udp_pkt->data[0];
2764
2765 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->
2766 trace_deactivation_timer = 4000;
2767
2768
2769 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2770 if (err != COMMAND_OK) {
2771 chdlc_error(card,err,mb);
2772 card->TracingEnabled = 0;
2773 chdlc_udp_pkt->cblock.return_code = err;
2774 mb->buffer_length = 0;
2775 break;
2776 }
2777
2778 /* Get the base address of the trace element list */
2779 mb->buffer_length = 0;
2780 mb->command = READ_TRACE_CONFIGURATION;
2781 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2782
2783 if (err != COMMAND_OK) {
2784 chdlc_error(card,err,mb);
2785 chdlc_priv_area->TracingEnabled = 0;
2786 chdlc_udp_pkt->cblock.return_code = err;
2787 mb->buffer_length = 0;
2788 break;
2789 }
2790
2791 trace_status_cfg_addr =((LINE_TRACE_CONFIG_STRUCT *)
2792 mb->data) -> ptr_trace_stat_el_cfg_struct;
2793
2794 sdla_peek(&card->hw, trace_status_cfg_addr,
2795 &trace_cfg_struct, sizeof(trace_cfg_struct));
2796
2797 chdlc_priv_area->start_trace_addr = trace_cfg_struct.
2798 base_addr_trace_status_elements;
2799
2800 chdlc_priv_area->number_trace_elements =
2801 trace_cfg_struct.number_trace_status_elements;
2802
2803 chdlc_priv_area->end_trace_addr = (unsigned long)
2804 ((TRACE_STATUS_ELEMENT_STRUCT *)
2805 chdlc_priv_area->start_trace_addr +
2806 (chdlc_priv_area->number_trace_elements - 1));
2807
2808 chdlc_priv_area->base_addr_trace_buffer =
2809 trace_cfg_struct.base_addr_trace_buffer;
2810
2811 chdlc_priv_area->end_addr_trace_buffer =
2812 trace_cfg_struct.end_addr_trace_buffer;
2813
2814 chdlc_priv_area->curr_trace_addr =
2815 trace_cfg_struct.next_trace_element_to_use;
2816
2817 chdlc_priv_area->available_buffer_space = 2000 -
2818 sizeof(ip_pkt_t) -
2819 sizeof(udp_pkt_t) -
2820 sizeof(wp_mgmt_t) -
2821 sizeof(cblock_t) -
2822 sizeof(trace_info_t);
2823 }
2824 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
2825 mb->buffer_length = 0;
2826 chdlc_priv_area->TracingEnabled = 1;
2827 break;
2828
2829
2830 case CPIPE_DISABLE_TRACING:
2831 if (chdlc_priv_area->TracingEnabled) {
2832
2833 /* OPERATE_DATALINE_MONITOR */
2834 mb->buffer_length = sizeof(LINE_TRACE_CONFIG_STRUCT);
2835 mb->command = SET_TRACE_CONFIGURATION;
2836 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->
2837 trace_config = TRACE_INACTIVE;
2838 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2839 }
2840
2841 chdlc_priv_area->TracingEnabled = 0;
2842 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
2843 mb->buffer_length = 0;
2844 break;
2845
2846
2847 case CPIPE_GET_TRACE_INFO:
2848
2849 if (!chdlc_priv_area->TracingEnabled) {
2850 chdlc_udp_pkt->cblock.return_code = 1;
2851 mb->buffer_length = 0;
2852 break;
2853 }
2854
2855 chdlc_udp_pkt->trace_info.ismoredata = 0x00;
2856 buffer_length = 0; /* offset of packet already occupied */
2857
2858 for (frames=0; frames < chdlc_priv_area->number_trace_elements; frames++){
2859
2860 trace_pkt_t *trace_pkt = (trace_pkt_t *)
2861 &chdlc_udp_pkt->data[buffer_length];
2862
2863 sdla_peek(&card->hw, chdlc_priv_area->curr_trace_addr,
2864 (unsigned char *)&trace_element_struct,
2865 sizeof(TRACE_STATUS_ELEMENT_STRUCT));
2866
2867 if (trace_element_struct.opp_flag == 0x00) {
2868 break;
2869 }
2870
2871 /* get pointer to real data */
2872 data_ptr = trace_element_struct.ptr_data_bfr;
2873
2874 /* See if there is actual data on the trace buffer */
2875 if (data_ptr){
2876 data_length = trace_element_struct.trace_length;
2877 }else{
2878 data_length = 0;
2879 chdlc_udp_pkt->trace_info.ismoredata = 0x01;
2880 }
2881
2882 if( (chdlc_priv_area->available_buffer_space - buffer_length)
2883 < ( sizeof(trace_pkt_t) + data_length) ) {
2884
2885 /* indicate there are more frames on board & exit */
2886 chdlc_udp_pkt->trace_info.ismoredata = 0x01;
2887 break;
2888 }
2889
2890 trace_pkt->status = trace_element_struct.trace_type;
2891
2892 trace_pkt->time_stamp =
2893 trace_element_struct.trace_time_stamp;
2894
2895 trace_pkt->real_length =
2896 trace_element_struct.trace_length;
2897
2898 /* see if we can fit the frame into the user buffer */
2899 real_len = trace_pkt->real_length;
2900
2901 if (data_ptr == 0) {
2902 trace_pkt->data_avail = 0x00;
2903 } else {
2904 unsigned tmp = 0;
2905
2906 /* get the data from circular buffer
2907 must check for end of buffer */
2908 trace_pkt->data_avail = 0x01;
2909
2910 if ((data_ptr + real_len) >
2911 chdlc_priv_area->end_addr_trace_buffer + 1){
2912
2913 tmp = chdlc_priv_area->end_addr_trace_buffer - data_ptr + 1;
2914 sdla_peek(&card->hw, data_ptr,
2915 trace_pkt->data,tmp);
2916 data_ptr = chdlc_priv_area->base_addr_trace_buffer;
2917 }
2918
2919 sdla_peek(&card->hw, data_ptr,
2920 &trace_pkt->data[tmp], real_len - tmp);
2921 }
2922
2923 /* zero the opp flag to show we got the frame */
2924 ut_char = 0x00;
2925 sdla_poke(&card->hw, chdlc_priv_area->curr_trace_addr, &ut_char, 1);
2926
2927 /* now move onto the next frame */
2928 chdlc_priv_area->curr_trace_addr += sizeof(TRACE_STATUS_ELEMENT_STRUCT);
2929
2930 /* check if we went over the last address */
2931 if ( chdlc_priv_area->curr_trace_addr > chdlc_priv_area->end_trace_addr ) {
2932 chdlc_priv_area->curr_trace_addr = chdlc_priv_area->start_trace_addr;
2933 }
2934
2935 if(trace_pkt->data_avail == 0x01) {
2936 buffer_length += real_len - 1;
2937 }
2938
2939 /* for the header */
2940 buffer_length += sizeof(trace_pkt_t);
2941
2942 } /* For Loop */
2943
2944 if (frames == chdlc_priv_area->number_trace_elements){
2945 chdlc_udp_pkt->trace_info.ismoredata = 0x01;
2946 }
2947 chdlc_udp_pkt->trace_info.num_frames = frames;
2948
2949 mb->buffer_length = buffer_length;
2950 chdlc_udp_pkt->cblock.buffer_length = buffer_length;
2951
2952 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
2953
2954 break;
2955
2956
2957 case CPIPE_FT1_READ_STATUS:
2958 ((unsigned char *)chdlc_udp_pkt->data )[0] =
2959 flags->FT1_info_struct.parallel_port_A_input;
2960
2961 ((unsigned char *)chdlc_udp_pkt->data )[1] =
2962 flags->FT1_info_struct.parallel_port_B_input;
2963
2964 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
2965 chdlc_udp_pkt->cblock.buffer_length = 2;
2966 mb->buffer_length = 2;
2967 break;
2968
2969 case CPIPE_ROUTER_UP_TIME:
2970 do_gettimeofday( &tv );
2971 chdlc_priv_area->router_up_time = tv.tv_sec -
2972 chdlc_priv_area->router_start_time;
2973 *(unsigned long *)&chdlc_udp_pkt->data =
2974 chdlc_priv_area->router_up_time;
2975 mb->buffer_length = sizeof(unsigned long);
2976 chdlc_udp_pkt->cblock.buffer_length = sizeof(unsigned long);
2977 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
2978 break;
2979
2980 case FT1_MONITOR_STATUS_CTRL:
2981 /* Enable FT1 MONITOR STATUS */
2982 if ((chdlc_udp_pkt->data[0] & ENABLE_READ_FT1_STATUS) ||
2983 (chdlc_udp_pkt->data[0] & ENABLE_READ_FT1_OP_STATS)) {
2984
2985 if( rCount++ != 0 ) {
2986 chdlc_udp_pkt->cblock.
2987 return_code = COMMAND_OK;
2988 mb->buffer_length = 1;
2989 break;
2990 }
2991 }
2992
2993 /* Disable FT1 MONITOR STATUS */
2994 if( chdlc_udp_pkt->data[0] == 0) {
2995
2996 if( --rCount != 0) {
2997 chdlc_udp_pkt->cblock.
2998 return_code = COMMAND_OK;
2999 mb->buffer_length = 1;
3000 break;
3001 }
3002 }
3003 goto dflt_1;
3004
3005 default:
3006dflt_1:
3007 /* it's a board command */
3008 mb->command = chdlc_udp_pkt->cblock.command;
3009 mb->buffer_length = chdlc_udp_pkt->cblock.buffer_length;
3010 if (mb->buffer_length) {
3011 memcpy(&mb->data, (unsigned char *) chdlc_udp_pkt->
3012 data, mb->buffer_length);
3013 }
3014 /* run the command on the board */
3015 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
3016 if (err != COMMAND_OK) {
3017 break;
3018 }
3019
3020 /* copy the result back to our buffer */
3021 memcpy(&chdlc_udp_pkt->cblock, mb, sizeof(cblock_t));
3022
3023 if (mb->buffer_length) {
3024 memcpy(&chdlc_udp_pkt->data, &mb->data,
3025 mb->buffer_length);
3026 }
3027
3028 } /* end of switch */
3029 } /* end of else */
3030
3031 /* Fill UDP TTL */
3032 chdlc_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
3033
3034 len = reply_udp(chdlc_priv_area->udp_pkt_data, mb->buffer_length);
3035
3036
3037 if(chdlc_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK){
3038
3039 /* Must check if we interrupted if_send() routine. The
3040 * tx buffers might be used. If so drop the packet */
3041 if (!test_bit(SEND_CRIT,&card->wandev.critical)) {
3042
3043 if(!chdlc_send(card, chdlc_priv_area->udp_pkt_data, len)) {
3044 ++ card->wandev.stats.tx_packets;
3045 card->wandev.stats.tx_bytes += len;
3046 }
3047 }
3048 } else {
3049
3050 /* Pass it up the stack
3051 Allocate socket buffer */
3052 if ((new_skb = dev_alloc_skb(len)) != NULL) {
3053 /* copy data into new_skb */
3054
3055 buf = skb_put(new_skb, len);
3056 memcpy(buf, chdlc_priv_area->udp_pkt_data, len);
3057
3058 /* Decapsulate pkt and pass it up the protocol stack */
3059 new_skb->protocol = htons(ETH_P_IP);
3060 new_skb->dev = dev;
3061 new_skb->mac.raw = new_skb->data;
3062
3063 netif_rx(new_skb);
3064 dev->last_rx = jiffies;
3065 } else {
3066
3067 printk(KERN_INFO "%s: no socket buffers available!\n",
3068 card->devname);
3069 }
3070 }
3071
3072 chdlc_priv_area->udp_pkt_lgth = 0;
3073
3074 return 0;
3075}
3076
3077/*============================================================================
3078 * Initialize Receive and Transmit Buffers.
3079 */
3080
3081static void init_chdlc_tx_rx_buff( sdla_t* card)
3082{
3083 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
3084 CHDLC_TX_STATUS_EL_CFG_STRUCT *tx_config;
3085 CHDLC_RX_STATUS_EL_CFG_STRUCT *rx_config;
3086 char err;
3087
3088 mb->buffer_length = 0;
3089 mb->command = READ_CHDLC_CONFIGURATION;
3090 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
3091
3092 if(err != COMMAND_OK) {
3093 if (card->wandev.dev){
3094 chdlc_error(card,err,mb);
3095 }
3096 return;
3097 }
3098
3099 if(card->hw.type == SDLA_S514) {
3100 tx_config = (CHDLC_TX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
3101 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
3102 ptr_CHDLC_Tx_stat_el_cfg_struct));
3103 rx_config = (CHDLC_RX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
3104 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
3105 ptr_CHDLC_Rx_stat_el_cfg_struct));
3106
3107 /* Setup Head and Tails for buffers */
3108 card->u.c.txbuf_base = (void *)(card->hw.dpmbase +
3109 tx_config->base_addr_Tx_status_elements);
3110 card->u.c.txbuf_last =
3111 (CHDLC_DATA_TX_STATUS_EL_STRUCT *)
3112 card->u.c.txbuf_base +
3113 (tx_config->number_Tx_status_elements - 1);
3114
3115 card->u.c.rxbuf_base = (void *)(card->hw.dpmbase +
3116 rx_config->base_addr_Rx_status_elements);
3117 card->u.c.rxbuf_last =
3118 (CHDLC_DATA_RX_STATUS_EL_STRUCT *)
3119 card->u.c.rxbuf_base +
3120 (rx_config->number_Rx_status_elements - 1);
3121
3122 /* Set up next pointer to be used */
3123 card->u.c.txbuf = (void *)(card->hw.dpmbase +
3124 tx_config->next_Tx_status_element_to_use);
3125 card->u.c.rxmb = (void *)(card->hw.dpmbase +
3126 rx_config->next_Rx_status_element_to_use);
3127 }
3128 else {
3129 tx_config = (CHDLC_TX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
3130 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
3131 ptr_CHDLC_Tx_stat_el_cfg_struct % SDLA_WINDOWSIZE));
3132
3133 rx_config = (CHDLC_RX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
3134 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
3135 ptr_CHDLC_Rx_stat_el_cfg_struct % SDLA_WINDOWSIZE));
3136
3137 /* Setup Head and Tails for buffers */
3138 card->u.c.txbuf_base = (void *)(card->hw.dpmbase +
3139 (tx_config->base_addr_Tx_status_elements % SDLA_WINDOWSIZE));
3140 card->u.c.txbuf_last =
3141 (CHDLC_DATA_TX_STATUS_EL_STRUCT *)card->u.c.txbuf_base
3142 + (tx_config->number_Tx_status_elements - 1);
3143 card->u.c.rxbuf_base = (void *)(card->hw.dpmbase +
3144 (rx_config->base_addr_Rx_status_elements % SDLA_WINDOWSIZE));
3145 card->u.c.rxbuf_last =
3146 (CHDLC_DATA_RX_STATUS_EL_STRUCT *)card->u.c.rxbuf_base
3147 + (rx_config->number_Rx_status_elements - 1);
3148
3149 /* Set up next pointer to be used */
3150 card->u.c.txbuf = (void *)(card->hw.dpmbase +
3151 (tx_config->next_Tx_status_element_to_use % SDLA_WINDOWSIZE));
3152 card->u.c.rxmb = (void *)(card->hw.dpmbase +
3153 (rx_config->next_Rx_status_element_to_use % SDLA_WINDOWSIZE));
3154 }
3155
3156 /* Setup Actual Buffer Start and end addresses */
3157 card->u.c.rx_base = rx_config->base_addr_Rx_buffer;
3158 card->u.c.rx_top = rx_config->end_addr_Rx_buffer;
3159
3160}
3161
3162/*=============================================================================
3163 * Perform Interrupt Test by running READ_CHDLC_CODE_VERSION command MAX_INTR
3164 * _TEST_COUNTER times.
3165 */
3166static int intr_test( sdla_t* card)
3167{
3168 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
3169 int err,i;
3170
3171 Intr_test_counter = 0;
3172
3173 err = chdlc_set_intr_mode(card, APP_INT_ON_COMMAND_COMPLETE);
3174
3175 if (err == CMD_OK) {
3176 for (i = 0; i < MAX_INTR_TEST_COUNTER; i ++) {
3177 mb->buffer_length = 0;
3178 mb->command = READ_CHDLC_CODE_VERSION;
3179 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
3180 if (err != CMD_OK)
3181 chdlc_error(card, err, mb);
3182 }
3183 }
3184 else {
3185 return err;
3186 }
3187
3188 err = chdlc_set_intr_mode(card, 0);
3189
3190 if (err != CMD_OK)
3191 return err;
3192
3193 return 0;
3194}
3195
3196/*==============================================================================
3197 * Determine what type of UDP call it is. CPIPEAB ?
3198 */
3199static int udp_pkt_type(struct sk_buff *skb, sdla_t* card)
3200{
3201 chdlc_udp_pkt_t *chdlc_udp_pkt = (chdlc_udp_pkt_t *)skb->data;
3202
3203#ifdef _WAN_UDP_DEBUG
3204 printk(KERN_INFO "SIG %s = %s\n\
3205 UPP %x = %x\n\
3206 PRT %x = %x\n\
3207 REQ %i = %i\n\
3208 36 th = %x 37th = %x\n",
3209 chdlc_udp_pkt->wp_mgmt.signature,
3210 UDPMGMT_SIGNATURE,
3211 chdlc_udp_pkt->udp_pkt.udp_dst_port,
3212 ntohs(card->wandev.udp_port),
3213 chdlc_udp_pkt->ip_pkt.protocol,
3214 UDPMGMT_UDP_PROTOCOL,
3215 chdlc_udp_pkt->wp_mgmt.request_reply,
3216 UDPMGMT_REQUEST,
3217 skb->data[36], skb->data[37]);
3218#endif
3219
3220 if (!strncmp(chdlc_udp_pkt->wp_mgmt.signature,UDPMGMT_SIGNATURE,8) &&
3221 (chdlc_udp_pkt->udp_pkt.udp_dst_port == ntohs(card->wandev.udp_port)) &&
3222 (chdlc_udp_pkt->ip_pkt.protocol == UDPMGMT_UDP_PROTOCOL) &&
3223 (chdlc_udp_pkt->wp_mgmt.request_reply == UDPMGMT_REQUEST)) {
3224
3225 return UDP_CPIPE_TYPE;
3226
3227 }else{
3228 return UDP_INVALID_TYPE;
3229 }
3230}
3231
3232/*============================================================================
3233 * Set PORT state.
3234 */
3235static void port_set_state (sdla_t *card, int state)
3236{
3237 if (card->u.c.state != state)
3238 {
3239 switch (state)
3240 {
3241 case WAN_CONNECTED:
3242 printk (KERN_INFO "%s: Link connected!\n",
3243 card->devname);
3244 break;
3245
3246 case WAN_CONNECTING:
3247 printk (KERN_INFO "%s: Link connecting...\n",
3248 card->devname);
3249 break;
3250
3251 case WAN_DISCONNECTED:
3252 printk (KERN_INFO "%s: Link disconnected!\n",
3253 card->devname);
3254 break;
3255 }
3256
3257 card->wandev.state = card->u.c.state = state;
3258 if (card->wandev.dev){
3259 struct net_device *dev = card->wandev.dev;
3260 chdlc_private_area_t *chdlc_priv_area = dev->priv;
3261 chdlc_priv_area->common.state = state;
3262 }
3263 }
3264}
3265
3266/*===========================================================================
3267 * config_chdlc
3268 *
3269 * Configure the chdlc protocol and enable communications.
3270 *
3271 * The if_open() function binds this function to the poll routine.
3272 * Therefore, this function will run every time the chdlc interface
3273 * is brought up. We cannot run this function from the if_open
3274 * because if_open does not have access to the remote IP address.
3275 *
3276 * If the communications are not enabled, proceed to configure
3277 * the card and enable communications.
3278 *
3279 * If the communications are enabled, it means that the interface
3280 * was shutdown by ether the user or driver. In this case, we
3281 * have to check that the IP addresses have not changed. If
3282 * the IP addresses have changed, we have to reconfigure the firmware
3283 * and update the changed IP addresses. Otherwise, just exit.
3284 *
3285 */
3286
3287static int config_chdlc (sdla_t *card)
3288{
3289 struct net_device *dev = card->wandev.dev;
3290 chdlc_private_area_t *chdlc_priv_area = dev->priv;
3291 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
3292
3293 if (card->u.c.comm_enabled){
3294
3295 /* Jun 20. 2000: NC
3296 * IP addresses are not used in the API mode */
3297
3298 if ((chdlc_priv_area->ip_local_tmp != chdlc_priv_area->ip_local ||
3299 chdlc_priv_area->ip_remote_tmp != chdlc_priv_area->ip_remote) &&
3300 card->u.c.usedby == WANPIPE) {
3301
3302 /* The IP addersses have changed, we must
3303 * stop the communications and reconfigure
3304 * the card. Reason: the firmware must know
3305 * the local and remote IP addresses. */
3306 disable_comm(card);
3307 port_set_state(card, WAN_DISCONNECTED);
3308 printk(KERN_INFO
3309 "%s: IP addresses changed!\n",
3310 card->devname);
3311 printk(KERN_INFO
3312 "%s: Restarting communications ...\n",
3313 card->devname);
3314 }else{
3315 /* IP addresses are the same and the link is up,
3316 * we don't have to do anything here. Therefore, exit */
3317 return 0;
3318 }
3319 }
3320
3321 chdlc_priv_area->ip_local = chdlc_priv_area->ip_local_tmp;
3322 chdlc_priv_area->ip_remote = chdlc_priv_area->ip_remote_tmp;
3323
3324
3325 /* Setup the Board for asynchronous mode */
3326 if (card->u.c.async_mode){
3327
3328 if (set_asy_config(card)) {
3329 printk (KERN_INFO "%s: Failed CHDLC Async configuration!\n",
3330 card->devname);
3331 return 0;
3332 }
3333 }else{
3334 /* Setup the Board for CHDLC */
3335 if (set_chdlc_config(card)) {
3336 printk (KERN_INFO "%s: Failed CHDLC configuration!\n",
3337 card->devname);
3338 return 0;
3339 }
3340 }
3341
3342 /* Set interrupt mode and mask */
3343 if (chdlc_set_intr_mode(card, APP_INT_ON_RX_FRAME |
3344 APP_INT_ON_GLOBAL_EXCEP_COND |
3345 APP_INT_ON_TX_FRAME |
3346 APP_INT_ON_CHDLC_EXCEP_COND | APP_INT_ON_TIMER)){
3347 printk (KERN_INFO "%s: Failed to set interrupt triggers!\n",
3348 card->devname);
3349 return 0;
3350 }
3351
3352
3353 /* Mask the Transmit and Timer interrupt */
3354 flags->interrupt_info_struct.interrupt_permission &=
3355 ~(APP_INT_ON_TX_FRAME | APP_INT_ON_TIMER);
3356
3357 /* In TTY mode, receive interrupt will be enabled during
3358 * wanpipe_tty_open() operation */
3359 if (card->tty_opt){
3360 flags->interrupt_info_struct.interrupt_permission &= ~APP_INT_ON_RX_FRAME;
3361 }
3362
3363 /* Enable communications */
3364 if (card->u.c.async_mode){
3365 if (asy_comm_enable(card) != 0) {
3366 printk(KERN_INFO "%s: Failed to enable async commnunication!\n",
3367 card->devname);
3368 flags->interrupt_info_struct.interrupt_permission = 0;
3369 card->u.c.comm_enabled=0;
3370 chdlc_set_intr_mode(card,0);
3371 return 0;
3372 }
3373 }else{
3374 if (chdlc_comm_enable(card) != 0) {
3375 printk(KERN_INFO "%s: Failed to enable chdlc communications!\n",
3376 card->devname);
3377 flags->interrupt_info_struct.interrupt_permission = 0;
3378 card->u.c.comm_enabled=0;
3379 chdlc_set_intr_mode(card,0);
3380 return 0;
3381 }
3382 }
3383
3384 /* Initialize Rx/Tx buffer control fields */
3385 init_chdlc_tx_rx_buff(card);
3386 port_set_state(card, WAN_CONNECTING);
3387 return 0;
3388}
3389
3390
3391/*============================================================
3392 * chdlc_poll
3393 *
3394 * Rationale:
3395 * We cannot manipulate the routing tables, or
3396 * ip addresses withing the interrupt. Therefore
3397 * we must perform such actons outside an interrupt
3398 * at a later time.
3399 *
3400 * Description:
3401 * CHDLC polling routine, responsible for
3402 * shutting down interfaces upon disconnect
3403 * and adding/removing routes.
3404 *
3405 * Usage:
3406 * This function is executed for each CHDLC
3407 * interface through a tq_schedule bottom half.
3408 *
3409 * trigger_chdlc_poll() function is used to kick
3410 * the chldc_poll routine.
3411 */
3412
3413static void chdlc_poll(struct net_device *dev)
3414{
3415 chdlc_private_area_t *chdlc_priv_area;
3416 sdla_t *card;
3417 u8 check_gateway=0;
3418 SHARED_MEMORY_INFO_STRUCT* flags;
3419
3420
3421 if (!dev || (chdlc_priv_area=dev->priv) == NULL)
3422 return;
3423
3424 card = chdlc_priv_area->card;
3425 flags = card->u.c.flags;
3426
3427 /* (Re)Configuraiton is in progress, stop what you are
3428 * doing and get out */
3429 if (test_bit(PERI_CRIT,&card->wandev.critical)){
3430 clear_bit(POLL_CRIT,&card->wandev.critical);
3431 return;
3432 }
3433
3434 /* if_open() function has triggered the polling routine
3435 * to determine the configured IP addresses. Once the
3436 * addresses are found, trigger the chdlc configuration */
3437 if (test_bit(0,&chdlc_priv_area->config_chdlc)){
3438
3439 chdlc_priv_area->ip_local_tmp = get_ip_address(dev,WAN_LOCAL_IP);
3440 chdlc_priv_area->ip_remote_tmp = get_ip_address(dev,WAN_POINTOPOINT_IP);
3441
3442 /* Jun 20. 2000 Bug Fix
3443 * Only perform this check in WANPIPE mode, since
3444 * IP addresses are not used in the API mode. */
3445
3446 if (chdlc_priv_area->ip_local_tmp == chdlc_priv_area->ip_remote_tmp &&
3447 card->u.c.slarp_timer == 0x00 &&
3448 !card->u.c.backup &&
3449 card->u.c.usedby == WANPIPE){
3450
3451 if (++chdlc_priv_area->ip_error > MAX_IP_ERRORS){
3452 printk(KERN_INFO "\n%s: --- WARNING ---\n",
3453 card->devname);
3454 printk(KERN_INFO
3455 "%s: The local IP address is the same as the\n",
3456 card->devname);
3457 printk(KERN_INFO
3458 "%s: Point-to-Point IP address.\n",
3459 card->devname);
3460 printk(KERN_INFO "%s: --- WARNING ---\n\n",
3461 card->devname);
3462 }else{
3463 clear_bit(POLL_CRIT,&card->wandev.critical);
3464 chdlc_priv_area->poll_delay_timer.expires = jiffies+HZ;
3465 add_timer(&chdlc_priv_area->poll_delay_timer);
3466 return;
3467 }
3468 }
3469
3470 clear_bit(0,&chdlc_priv_area->config_chdlc);
3471 clear_bit(POLL_CRIT,&card->wandev.critical);
3472
3473 chdlc_priv_area->timer_int_enabled |= TMR_INT_ENABLED_CONFIG;
3474 flags->interrupt_info_struct.interrupt_permission |= APP_INT_ON_TIMER;
3475 return;
3476 }
3477 /* Dynamic interface implementation, as well as dynamic
3478 * routing. */
3479
3480 switch (card->u.c.state){
3481
3482 case WAN_DISCONNECTED:
3483
3484 /* If the dynamic interface configuration is on, and interface
3485 * is up, then bring down the netowrk interface */
3486
3487 if (test_bit(DYN_OPT_ON,&chdlc_priv_area->interface_down) &&
3488 !test_bit(DEV_DOWN, &chdlc_priv_area->interface_down) &&
3489 card->wandev.dev->flags & IFF_UP){
3490
3491 printk(KERN_INFO "%s: Interface %s down.\n",
3492 card->devname,card->wandev.dev->name);
3493 change_dev_flags(card->wandev.dev,(card->wandev.dev->flags&~IFF_UP));
3494 set_bit(DEV_DOWN,&chdlc_priv_area->interface_down);
3495 chdlc_priv_area->route_status = NO_ROUTE;
3496
3497 }else{
3498 /* We need to check if the local IP address is
3499 * zero. If it is, we shouldn't try to remove it.
3500 */
3501
3502 if (card->wandev.dev->flags & IFF_UP &&
3503 get_ip_address(card->wandev.dev,WAN_LOCAL_IP) &&
3504 chdlc_priv_area->route_status != NO_ROUTE &&
3505 card->u.c.slarp_timer){
3506
3507 process_route(card);
3508 }
3509 }
3510 break;
3511
3512 case WAN_CONNECTED:
3513
3514 /* In SMP machine this code can execute before the interface
3515 * comes up. In this case, we must make sure that we do not
3516 * try to bring up the interface before dev_open() is finished */
3517
3518
3519 /* DEV_DOWN will be set only when we bring down the interface
3520 * for the very first time. This way we know that it was us
3521 * that brought the interface down */
3522
3523 if (test_bit(DYN_OPT_ON,&chdlc_priv_area->interface_down) &&
3524 test_bit(DEV_DOWN, &chdlc_priv_area->interface_down) &&
3525 !(card->wandev.dev->flags & IFF_UP)){
3526
3527 printk(KERN_INFO "%s: Interface %s up.\n",
3528 card->devname,card->wandev.dev->name);
3529 change_dev_flags(card->wandev.dev,(card->wandev.dev->flags|IFF_UP));
3530 clear_bit(DEV_DOWN,&chdlc_priv_area->interface_down);
3531 check_gateway=1;
3532 }
3533
3534 if (chdlc_priv_area->route_status == ADD_ROUTE &&
3535 card->u.c.slarp_timer){
3536
3537 process_route(card);
3538 check_gateway=1;
3539 }
3540
3541 if (chdlc_priv_area->gateway && check_gateway)
3542 add_gateway(card,dev);
3543
3544 break;
3545 }
3546
3547 clear_bit(POLL_CRIT,&card->wandev.critical);
3548}
3549
3550/*============================================================
3551 * trigger_chdlc_poll
3552 *
3553 * Description:
3554 * Add a chdlc_poll() work entry into the keventd work queue
3555 * for a specific dlci/interface. This will kick
3556 * the fr_poll() routine at a later time.
3557 *
3558 * Usage:
3559 * Interrupts use this to defer a taks to
3560 * a polling routine.
3561 *
3562 */
3563static void trigger_chdlc_poll(struct net_device *dev)
3564{
3565 chdlc_private_area_t *chdlc_priv_area;
3566 sdla_t *card;
3567
3568 if (!dev)
3569 return;
3570
3571 if ((chdlc_priv_area = dev->priv)==NULL)
3572 return;
3573
3574 card = chdlc_priv_area->card;
3575
3576 if (test_and_set_bit(POLL_CRIT,&card->wandev.critical)){
3577 return;
3578 }
3579 if (test_bit(PERI_CRIT,&card->wandev.critical)){
3580 return;
3581 }
3582 schedule_work(&chdlc_priv_area->poll_work);
3583}
3584
3585
3586static void chdlc_poll_delay (unsigned long dev_ptr)
3587{
3588 struct net_device *dev = (struct net_device *)dev_ptr;
3589 trigger_chdlc_poll(dev);
3590}
3591
3592
3593void s508_lock (sdla_t *card, unsigned long *smp_flags)
3594{
3595 spin_lock_irqsave(&card->wandev.lock, *smp_flags);
3596 if (card->next){
3597 spin_lock(&card->next->wandev.lock);
3598 }
3599}
3600
3601void s508_unlock (sdla_t *card, unsigned long *smp_flags)
3602{
3603 if (card->next){
3604 spin_unlock(&card->next->wandev.lock);
3605 }
3606 spin_unlock_irqrestore(&card->wandev.lock, *smp_flags);
3607}
3608
3609//*********** TTY SECTION ****************
3610
3611static void wanpipe_tty_trigger_tx_irq(sdla_t *card)
3612{
3613 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
3614 INTERRUPT_INFORMATION_STRUCT *chdlc_int = &flags->interrupt_info_struct;
3615 chdlc_int->interrupt_permission |= APP_INT_ON_TX_FRAME;
3616}
3617
3618static void wanpipe_tty_trigger_poll(sdla_t *card)
3619{
3620 schedule_work(&card->tty_work);
3621}
3622
3623static void tty_poll_work (void* data)
3624{
3625 sdla_t *card = (sdla_t*)data;
3626 struct tty_struct *tty;
3627
3628 if ((tty=card->tty)==NULL)
3629 return;
3630
3631 tty_wakeup(tty);
3632#if defined(SERIAL_HAVE_POLL_WAIT)
3633 wake_up_interruptible(&tty->poll_wait);
3634#endif
3635 return;
3636}
3637
3638static void wanpipe_tty_close(struct tty_struct *tty, struct file * filp)
3639{
3640 sdla_t *card;
3641 unsigned long smp_flags;
3642
3643 if (!tty || !tty->driver_data){
3644 return;
3645 }
3646
3647 card = (sdla_t*)tty->driver_data;
3648
3649 if (!card)
3650 return;
3651
3652 printk(KERN_INFO "%s: Closing TTY Driver!\n",
3653 card->devname);
3654
3655 /* Sanity Check */
3656 if (!card->tty_open)
3657 return;
3658
3659 wanpipe_close(card);
3660 if (--card->tty_open == 0){
3661
3662 lock_adapter_irq(&card->wandev.lock,&smp_flags);
3663 card->tty=NULL;
3664 chdlc_disable_comm_shutdown(card);
3665 unlock_adapter_irq(&card->wandev.lock,&smp_flags);
3666
3667 kfree(card->tty_buf);
3668 card->tty_buf = NULL;
3669 kfree(card->tty_rx);
3670 card->tty_rx = NULL;
3671 }
3672 return;
3673}
3674static int wanpipe_tty_open(struct tty_struct *tty, struct file * filp)
3675{
3676 unsigned long smp_flags;
3677 sdla_t *card;
3678
3679 if (!tty){
3680 return -ENODEV;
3681 }
3682
3683 if (!tty->driver_data){
3684 int port;
3685 port = tty->index;
3686 if ((port < 0) || (port >= NR_PORTS))
3687 return -ENODEV;
3688
3689 tty->driver_data = WAN_CARD(port);
3690 if (!tty->driver_data)
3691 return -ENODEV;
3692 }
3693
3694 card = (sdla_t*)tty->driver_data;
3695
3696 if (!card){
3697 lock_adapter_irq(&card->wandev.lock,&smp_flags);
3698 card->tty=NULL;
3699 unlock_adapter_irq(&card->wandev.lock,&smp_flags);
3700 return -ENODEV;
3701 }
3702
3703 printk(KERN_INFO "%s: Opening TTY Driver!\n",
3704 card->devname);
3705
3706 if (card->tty_open == 0){
3707 lock_adapter_irq(&card->wandev.lock,&smp_flags);
3708 card->tty=tty;
3709 unlock_adapter_irq(&card->wandev.lock,&smp_flags);
3710
3711 if (!card->tty_buf){
3712 card->tty_buf = kmalloc(TTY_CHDLC_MAX_MTU, GFP_KERNEL);
3713 if (!card->tty_buf){
3714 card->tty_buf=NULL;
3715 card->tty=NULL;
3716 return -ENOMEM;
3717 }
3718 }
3719
3720 if (!card->tty_rx){
3721 card->tty_rx = kmalloc(TTY_CHDLC_MAX_MTU, GFP_KERNEL);
3722 if (!card->tty_rx){
3723 /* Free the buffer above */
3724 kfree(card->tty_buf);
3725 card->tty_buf=NULL;
3726 card->tty=NULL;
3727 return -ENOMEM;
3728 }
3729 }
3730 }
3731
3732 ++card->tty_open;
3733 wanpipe_open(card);
3734 return 0;
3735}
3736
3737static int wanpipe_tty_write(struct tty_struct * tty, const unsigned char *buf, int count)
3738{
3739 unsigned long smp_flags=0;
3740 sdla_t *card=NULL;
3741
3742 if (!tty){
3743 dbg_printk(KERN_INFO "NO TTY in Write\n");
3744 return -ENODEV;
3745 }
3746
3747 card = (sdla_t *)tty->driver_data;
3748
3749 if (!card){
3750 dbg_printk(KERN_INFO "No Card in TTY Write\n");
3751 return -ENODEV;
3752 }
3753
3754 if (count > card->wandev.mtu){
3755 dbg_printk(KERN_INFO "Frame too big in Write %i Max: %i\n",
3756 count,card->wandev.mtu);
3757 return -EINVAL;
3758 }
3759
3760 if (card->wandev.state != WAN_CONNECTED){
3761 dbg_printk(KERN_INFO "Card not connected in TTY Write\n");
3762 return -EINVAL;
3763 }
3764
3765 /* Lock the 508 Card: SMP is supported */
3766 if(card->hw.type != SDLA_S514){
3767 s508_lock(card,&smp_flags);
3768 }
3769
3770 if (test_and_set_bit(SEND_CRIT,(void*)&card->wandev.critical)){
3771 printk(KERN_INFO "%s: Critical in TTY Write\n",
3772 card->devname);
3773
3774 /* Lock the 508 Card: SMP is supported */
3775 if(card->hw.type != SDLA_S514)
3776 s508_unlock(card,&smp_flags);
3777
3778 return -EINVAL;
3779 }
3780
3781 if (chdlc_send(card,(void*)buf,count)){
3782 dbg_printk(KERN_INFO "%s: Failed to send, retry later: kernel!\n",
3783 card->devname);
3784 clear_bit(SEND_CRIT,(void*)&card->wandev.critical);
3785
3786 wanpipe_tty_trigger_tx_irq(card);
3787
3788 if(card->hw.type != SDLA_S514)
3789 s508_unlock(card,&smp_flags);
3790 return 0;
3791 }
3792 dbg_printk(KERN_INFO "%s: Packet sent OK: %i\n",card->devname,count);
3793 clear_bit(SEND_CRIT,(void*)&card->wandev.critical);
3794
3795 if(card->hw.type != SDLA_S514)
3796 s508_unlock(card,&smp_flags);
3797
3798 return count;
3799}
3800
3801static void wanpipe_tty_receive(sdla_t *card, unsigned addr, unsigned int len)
3802{
3803 unsigned offset=0;
3804 unsigned olen=len;
3805 char fp=0;
3806 struct tty_struct *tty;
3807 int i;
3808 struct tty_ldisc *ld;
3809
3810 if (!card->tty_open){
3811 dbg_printk(KERN_INFO "%s: TTY not open during receive\n",
3812 card->devname);
3813 return;
3814 }
3815
3816 if ((tty=card->tty) == NULL){
3817 dbg_printk(KERN_INFO "%s: No TTY on receive\n",
3818 card->devname);
3819 return;
3820 }
3821
3822 if (!tty->driver_data){
3823 dbg_printk(KERN_INFO "%s: No Driver Data, or Flip on receive\n",
3824 card->devname);
3825 return;
3826 }
3827
3828
3829 if (card->u.c.async_mode){
3830 if ((tty->flip.count+len) >= TTY_FLIPBUF_SIZE){
3831 if (net_ratelimit()){
3832 printk(KERN_INFO
3833 "%s: Received packet size too big: %i bytes, Max: %i!\n",
3834 card->devname,len,TTY_FLIPBUF_SIZE);
3835 }
3836 return;
3837 }
3838
3839
3840 if((addr + len) > card->u.c.rx_top + 1) {
3841 offset = card->u.c.rx_top - addr + 1;
3842
3843 sdla_peek(&card->hw, addr, tty->flip.char_buf_ptr, offset);
3844
3845 addr = card->u.c.rx_base;
3846 len -= offset;
3847
3848 tty->flip.char_buf_ptr+=offset;
3849 tty->flip.count+=offset;
3850 for (i=0;i<offset;i++){
3851 *tty->flip.flag_buf_ptr = 0;
3852 tty->flip.flag_buf_ptr++;
3853 }
3854 }
3855
3856 sdla_peek(&card->hw, addr, tty->flip.char_buf_ptr, len);
3857
3858 tty->flip.char_buf_ptr+=len;
3859 card->tty->flip.count+=len;
3860 for (i=0;i<len;i++){
3861 *tty->flip.flag_buf_ptr = 0;
3862 tty->flip.flag_buf_ptr++;
3863 }
3864
3865 tty->low_latency=1;
3866 tty_flip_buffer_push(tty);
3867 }else{
3868 if (!card->tty_rx){
3869 if (net_ratelimit()){
3870 printk(KERN_INFO
3871 "%s: Receive sync buffer not available!\n",
3872 card->devname);
3873 }
3874 return;
3875 }
3876
3877 if (len > TTY_CHDLC_MAX_MTU){
3878 if (net_ratelimit()){
3879 printk(KERN_INFO
3880 "%s: Received packet size too big: %i bytes, Max: %i!\n",
3881 card->devname,len,TTY_FLIPBUF_SIZE);
3882 }
3883 return;
3884 }
3885
3886
3887 if((addr + len) > card->u.c.rx_top + 1) {
3888 offset = card->u.c.rx_top - addr + 1;
3889
3890 sdla_peek(&card->hw, addr, card->tty_rx, offset);
3891
3892 addr = card->u.c.rx_base;
3893 len -= offset;
3894 }
3895 sdla_peek(&card->hw, addr, card->tty_rx+offset, len);
3896 ld = tty_ldisc_ref(tty);
3897 if (ld) {
3898 if (ld->receive_buf)
3899 ld->receive_buf(tty,card->tty_rx,&fp,olen);
3900 tty_ldisc_deref(ld);
3901 }else{
3902 if (net_ratelimit()){
3903 printk(KERN_INFO
3904 "%s: NO TTY Sync line discipline!\n",
3905 card->devname);
3906 }
3907 }
3908 }
3909
3910 dbg_printk(KERN_INFO "%s: Received Data %i\n",card->devname,olen);
3911 return;
3912}
3913
3914#if 0
3915static int wanpipe_tty_ioctl(struct tty_struct *tty, struct file * file,
3916 unsigned int cmd, unsigned long arg)
3917{
3918 return -ENOIOCTLCMD;
3919}
3920#endif
3921
3922static void wanpipe_tty_stop(struct tty_struct *tty)
3923{
3924 return;
3925}
3926
3927static void wanpipe_tty_start(struct tty_struct *tty)
3928{
3929 return;
3930}
3931
3932static int config_tty (sdla_t *card)
3933{
3934 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
3935
3936 /* Setup the Board for asynchronous mode */
3937 if (card->u.c.async_mode){
3938
3939 if (set_asy_config(card)) {
3940 printk (KERN_INFO "%s: Failed CHDLC Async configuration!\n",
3941 card->devname);
3942 return -EINVAL;
3943 }
3944 }else{
3945 /* Setup the Board for CHDLC */
3946 if (set_chdlc_config(card)) {
3947 printk (KERN_INFO "%s: Failed CHDLC configuration!\n",
3948 card->devname);
3949 return -EINVAL;
3950 }
3951 }
3952
3953 /* Set interrupt mode and mask */
3954 if (chdlc_set_intr_mode(card, APP_INT_ON_RX_FRAME |
3955 APP_INT_ON_GLOBAL_EXCEP_COND |
3956 APP_INT_ON_TX_FRAME |
3957 APP_INT_ON_CHDLC_EXCEP_COND | APP_INT_ON_TIMER)){
3958 printk (KERN_INFO "%s: Failed to set interrupt triggers!\n",
3959 card->devname);
3960 return -EINVAL;
3961 }
3962
3963
3964 /* Mask the Transmit and Timer interrupt */
3965 flags->interrupt_info_struct.interrupt_permission &=
3966 ~(APP_INT_ON_TX_FRAME | APP_INT_ON_TIMER);
3967
3968
3969 /* Enable communications */
3970 if (card->u.c.async_mode){
3971 if (asy_comm_enable(card) != 0) {
3972 printk(KERN_INFO "%s: Failed to enable async commnunication!\n",
3973 card->devname);
3974 flags->interrupt_info_struct.interrupt_permission = 0;
3975 card->u.c.comm_enabled=0;
3976 chdlc_set_intr_mode(card,0);
3977 return -EINVAL;
3978 }
3979 }else{
3980 if (chdlc_comm_enable(card) != 0) {
3981 printk(KERN_INFO "%s: Failed to enable chdlc communications!\n",
3982 card->devname);
3983 flags->interrupt_info_struct.interrupt_permission = 0;
3984 card->u.c.comm_enabled=0;
3985 chdlc_set_intr_mode(card,0);
3986 return -EINVAL;
3987 }
3988 }
3989
3990 /* Initialize Rx/Tx buffer control fields */
3991 init_chdlc_tx_rx_buff(card);
3992 port_set_state(card, WAN_CONNECTING);
3993 return 0;
3994}
3995
3996
3997static int change_speed(sdla_t *card, struct tty_struct *tty,
3998 struct termios *old_termios)
3999{
4000 int baud, ret=0;
4001 unsigned cflag;
4002 int dbits,sbits,parity,handshaking;
4003
4004 cflag = tty->termios->c_cflag;
4005
4006 /* There is always one stop bit */
4007 sbits=WANOPT_ONE;
4008
4009 /* Parity is defaulted to NONE */
4010 parity = WANOPT_NONE;
4011
4012 handshaking=0;
4013
4014 /* byte size and parity */
4015 switch (cflag & CSIZE) {
4016 case CS5: dbits = 5; break;
4017 case CS6: dbits = 6; break;
4018 case CS7: dbits = 7; break;
4019 case CS8: dbits = 8; break;
4020 /* Never happens, but GCC is too dumb to figure it out */
4021 default: dbits = 8; break;
4022 }
4023
4024 /* One more stop bit should be supported, thus increment
4025 * the number of stop bits Max=2 */
4026 if (cflag & CSTOPB) {
4027 sbits = WANOPT_TWO;
4028 }
4029 if (cflag & PARENB) {
4030 parity = WANOPT_EVEN;
4031 }
4032 if (cflag & PARODD){
4033 parity = WANOPT_ODD;
4034 }
4035
4036 /* Determine divisor based on baud rate */
4037 baud = tty_get_baud_rate(tty);
4038
4039 if (!baud)
4040 baud = 9600; /* B0 transition handled in rs_set_termios */
4041
4042 if (cflag & CRTSCTS) {
4043 handshaking|=ASY_RTS_HS_FOR_RX;
4044 }
4045
4046 if (I_IGNPAR(tty))
4047 parity = WANOPT_NONE;
4048
4049 if (I_IXOFF(tty)){
4050 handshaking|=ASY_XON_XOFF_HS_FOR_RX;
4051 handshaking|=ASY_XON_XOFF_HS_FOR_TX;
4052 }
4053
4054 if (I_IXON(tty)){
4055 handshaking|=ASY_XON_XOFF_HS_FOR_RX;
4056 handshaking|=ASY_XON_XOFF_HS_FOR_TX;
4057 }
4058
4059 if (card->u.c.async_mode){
4060 if (card->wandev.bps != baud)
4061 ret=1;
4062 card->wandev.bps = baud;
4063 }
4064
4065 if (card->u.c.async_mode){
4066 if (card->u.c.protocol_options != handshaking)
4067 ret=1;
4068 card->u.c.protocol_options = handshaking;
4069
4070 if (card->u.c.tx_bits_per_char != dbits)
4071 ret=1;
4072 card->u.c.tx_bits_per_char = dbits;
4073
4074 if (card->u.c.rx_bits_per_char != dbits)
4075 ret=1;
4076 card->u.c.rx_bits_per_char = dbits;
4077
4078 if (card->u.c.stop_bits != sbits)
4079 ret=1;
4080 card->u.c.stop_bits = sbits;
4081
4082 if (card->u.c.parity != parity)
4083 ret=1;
4084 card->u.c.parity = parity;
4085
4086 card->u.c.break_timer = 50;
4087 card->u.c.inter_char_timer = 10;
4088 card->u.c.rx_complete_length = 100;
4089 card->u.c.xon_char = 0xFE;
4090 }else{
4091 card->u.c.protocol_options = HDLC_STREAMING_MODE;
4092 }
4093
4094 return ret;
4095}
4096
4097
4098static void wanpipe_tty_set_termios(struct tty_struct *tty, struct termios *old_termios)
4099{
4100 sdla_t *card;
4101 int err=1;
4102
4103 if (!tty){
4104 return;
4105 }
4106
4107 card = (sdla_t *)tty->driver_data;
4108
4109 if (!card)
4110 return;
4111
4112 if (change_speed(card, tty, old_termios) || !card->u.c.comm_enabled){
4113 unsigned long smp_flags;
4114
4115 if (card->u.c.comm_enabled){
4116 lock_adapter_irq(&card->wandev.lock,&smp_flags);
4117 chdlc_disable_comm_shutdown(card);
4118 unlock_adapter_irq(&card->wandev.lock,&smp_flags);
4119 }
4120 lock_adapter_irq(&card->wandev.lock,&smp_flags);
4121 err = config_tty(card);
4122 unlock_adapter_irq(&card->wandev.lock,&smp_flags);
4123 if (card->u.c.async_mode){
4124 printk(KERN_INFO "%s: TTY Async Configuration:\n"
4125 " Baud =%i\n"
4126 " Handshaking =%s\n"
4127 " Tx Dbits =%i\n"
4128 " Rx Dbits =%i\n"
4129 " Parity =%s\n"
4130 " Stop Bits =%i\n",
4131 card->devname,
4132 card->wandev.bps,
4133 opt_decode[card->u.c.protocol_options],
4134 card->u.c.tx_bits_per_char,
4135 card->u.c.rx_bits_per_char,
4136 p_decode[card->u.c.parity] ,
4137 card->u.c.stop_bits);
4138 }else{
4139 printk(KERN_INFO "%s: TTY Sync Configuration:\n"
4140 " Baud =%i\n"
4141 " Protocol =HDLC_STREAMING\n",
4142 card->devname,card->wandev.bps);
4143 }
4144 if (!err){
4145 port_set_state(card,WAN_CONNECTED);
4146 }else{
4147 port_set_state(card,WAN_DISCONNECTED);
4148 }
4149 }
4150 return;
4151}
4152
4153static void wanpipe_tty_put_char(struct tty_struct *tty, unsigned char ch)
4154{
4155 sdla_t *card;
4156 unsigned long smp_flags=0;
4157
4158 if (!tty){
4159 return;
4160 }
4161
4162 card = (sdla_t *)tty->driver_data;
4163
4164 if (!card)
4165 return;
4166
4167 if (card->wandev.state != WAN_CONNECTED)
4168 return;
4169
4170 if(card->hw.type != SDLA_S514)
4171 s508_lock(card,&smp_flags);
4172
4173 if (test_and_set_bit(SEND_CRIT,(void*)&card->wandev.critical)){
4174
4175 wanpipe_tty_trigger_tx_irq(card);
4176
4177 if(card->hw.type != SDLA_S514)
4178 s508_unlock(card,&smp_flags);
4179 return;
4180 }
4181
4182 if (chdlc_send(card,(void*)&ch,1)){
4183 wanpipe_tty_trigger_tx_irq(card);
4184 dbg_printk("%s: Failed to TX char!\n",card->devname);
4185 }
4186
4187 dbg_printk("%s: Char TX OK\n",card->devname);
4188
4189 clear_bit(SEND_CRIT,(void*)&card->wandev.critical);
4190
4191 if(card->hw.type != SDLA_S514)
4192 s508_unlock(card,&smp_flags);
4193
4194 return;
4195}
4196
4197static void wanpipe_tty_flush_chars(struct tty_struct *tty)
4198{
4199 return;
4200}
4201
4202static void wanpipe_tty_flush_buffer(struct tty_struct *tty)
4203{
4204 if (!tty)
4205 return;
4206
4207#if defined(SERIAL_HAVE_POLL_WAIT)
4208 wake_up_interruptible(&tty->poll_wait);
4209#endif
4210 tty_wakeup(tty);
4211 return;
4212}
4213
4214/*
4215 * This function is used to send a high-priority XON/XOFF character to
4216 * the device
4217 */
4218static void wanpipe_tty_send_xchar(struct tty_struct *tty, char ch)
4219{
4220 return;
4221}
4222
4223
4224static int wanpipe_tty_chars_in_buffer(struct tty_struct *tty)
4225{
4226 return 0;
4227}
4228
4229
4230static int wanpipe_tty_write_room(struct tty_struct *tty)
4231{
4232 sdla_t *card;
4233
4234 printk(KERN_INFO "TTY Write Room\n");
4235
4236 if (!tty){
4237 return 0;
4238 }
4239
4240 card = (sdla_t *)tty->driver_data;
4241 if (!card)
4242 return 0;
4243
4244 if (card->wandev.state != WAN_CONNECTED)
4245 return 0;
4246
4247 return SEC_MAX_NO_DATA_BYTES_IN_FRAME;
4248}
4249
4250
4251static int set_modem_status(sdla_t *card, unsigned char data)
4252{
4253 CHDLC_MAILBOX_STRUCT *mb = card->mbox;
4254 int err;
4255
4256 mb->buffer_length=1;
4257 mb->command=SET_MODEM_STATUS;
4258 mb->data[0]=data;
4259 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
4260 if (err != COMMAND_OK)
4261 chdlc_error (card, err, mb);
4262
4263 return err;
4264}
4265
4266static void wanpipe_tty_hangup(struct tty_struct *tty)
4267{
4268 sdla_t *card;
4269 unsigned long smp_flags;
4270
4271 printk(KERN_INFO "TTY Hangup!\n");
4272
4273 if (!tty){
4274 return;
4275 }
4276
4277 card = (sdla_t *)tty->driver_data;
4278 if (!card)
4279 return;
4280
4281 lock_adapter_irq(&card->wandev.lock,&smp_flags);
4282 set_modem_status(card,0);
4283 unlock_adapter_irq(&card->wandev.lock,&smp_flags);
4284 return;
4285}
4286
4287static void wanpipe_tty_break(struct tty_struct *tty, int break_state)
4288{
4289 return;
4290}
4291
4292static void wanpipe_tty_wait_until_sent(struct tty_struct *tty, int timeout)
4293{
4294 return;
4295}
4296
4297static void wanpipe_tty_throttle(struct tty_struct * tty)
4298{
4299 return;
4300}
4301
4302static void wanpipe_tty_unthrottle(struct tty_struct * tty)
4303{
4304 return;
4305}
4306
4307int wanpipe_tty_read_proc(char *page, char **start, off_t off, int count,
4308 int *eof, void *data)
4309{
4310 return 0;
4311}
4312
4313/*
4314 * The serial driver boot-time initialization code!
4315 */
4316int wanpipe_tty_init(sdla_t *card)
4317{
4318 struct serial_state * state;
4319
4320 /* Initialize the tty_driver structure */
4321
4322 if (card->tty_minor < 0 || card->tty_minor > NR_PORTS){
4323 printk(KERN_INFO "%s: Illegal Minor TTY number (0-4): %i\n",
4324 card->devname,card->tty_minor);
4325 return -EINVAL;
4326 }
4327
4328 if (WAN_CARD(card->tty_minor)){
4329 printk(KERN_INFO "%s: TTY Minor %i, already in use\n",
4330 card->devname,card->tty_minor);
4331 return -EBUSY;
4332 }
4333
4334 if (tty_init_cnt==0){
4335
4336 printk(KERN_INFO "%s: TTY %s Driver Init: Major %i, Minor Range %i-%i\n",
4337 card->devname,
4338 card->u.c.async_mode ? "ASYNC" : "SYNC",
4339 WAN_TTY_MAJOR,MIN_PORT,MAX_PORT);
4340
4341 tty_driver_mode = card->u.c.async_mode;
4342
4343 memset(&serial_driver, 0, sizeof(struct tty_driver));
4344 serial_driver.magic = TTY_DRIVER_MAGIC;
4345 serial_driver.owner = THIS_MODULE;
4346 serial_driver.driver_name = "wanpipe_tty";
4347 serial_driver.name = "ttyW";
4348 serial_driver.major = WAN_TTY_MAJOR;
4349 serial_driver.minor_start = WAN_TTY_MINOR;
4350 serial_driver.num = NR_PORTS;
4351 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
4352 serial_driver.subtype = SERIAL_TYPE_NORMAL;
4353
4354 serial_driver.init_termios = tty_std_termios;
4355 serial_driver.init_termios.c_cflag =
4356 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
4357 serial_driver.flags = TTY_DRIVER_REAL_RAW;
4358
4359 serial_driver.refcount = 1; /* !@!@^#^&!! */
4360
4361 serial_driver.open = wanpipe_tty_open;
4362 serial_driver.close = wanpipe_tty_close;
4363 serial_driver.write = wanpipe_tty_write;
4364
4365 serial_driver.put_char = wanpipe_tty_put_char;
4366 serial_driver.flush_chars = wanpipe_tty_flush_chars;
4367 serial_driver.write_room = wanpipe_tty_write_room;
4368 serial_driver.chars_in_buffer = wanpipe_tty_chars_in_buffer;
4369 serial_driver.flush_buffer = wanpipe_tty_flush_buffer;
4370 //serial_driver.ioctl = wanpipe_tty_ioctl;
4371 serial_driver.throttle = wanpipe_tty_throttle;
4372 serial_driver.unthrottle = wanpipe_tty_unthrottle;
4373 serial_driver.send_xchar = wanpipe_tty_send_xchar;
4374 serial_driver.set_termios = wanpipe_tty_set_termios;
4375 serial_driver.stop = wanpipe_tty_stop;
4376 serial_driver.start = wanpipe_tty_start;
4377 serial_driver.hangup = wanpipe_tty_hangup;
4378 serial_driver.break_ctl = wanpipe_tty_break;
4379 serial_driver.wait_until_sent = wanpipe_tty_wait_until_sent;
4380 serial_driver.read_proc = wanpipe_tty_read_proc;
4381
4382 if (tty_register_driver(&serial_driver)){
4383 printk(KERN_INFO "%s: Failed to register serial driver!\n",
4384 card->devname);
4385 }
4386 }
4387
4388
4389 /* The subsequent ports must comply to the initial configuration */
4390 if (tty_driver_mode != card->u.c.async_mode){
4391 printk(KERN_INFO "%s: Error: TTY Driver operation mode mismatch!\n",
4392 card->devname);
4393 printk(KERN_INFO "%s: The TTY driver is configured for %s!\n",
4394 card->devname, tty_driver_mode ? "ASYNC" : "SYNC");
4395 return -EINVAL;
4396 }
4397
4398 tty_init_cnt++;
4399
4400 printk(KERN_INFO "%s: Initializing TTY %s Driver Minor %i\n",
4401 card->devname,
4402 tty_driver_mode ? "ASYNC" : "SYNC",
4403 card->tty_minor);
4404
4405 tty_card_map[card->tty_minor] = card;
4406 state = &rs_table[card->tty_minor];
4407
4408 state->magic = SSTATE_MAGIC;
4409 state->line = 0;
4410 state->type = PORT_UNKNOWN;
4411 state->custom_divisor = 0;
4412 state->close_delay = 5*HZ/10;
4413 state->closing_wait = 30*HZ;
4414 state->icount.cts = state->icount.dsr =
4415 state->icount.rng = state->icount.dcd = 0;
4416 state->icount.rx = state->icount.tx = 0;
4417 state->icount.frame = state->icount.parity = 0;
4418 state->icount.overrun = state->icount.brk = 0;
4419 state->irq = card->wandev.irq;
4420
4421 INIT_WORK(&card->tty_work, tty_poll_work, (void*)card);
4422 return 0;
4423}
4424
4425
4426MODULE_LICENSE("GPL");
4427
4428/****** End ****************************************************************/
diff --git a/drivers/net/wan/sdla_fr.c b/drivers/net/wan/sdla_fr.c
deleted file mode 100644
index 7f1ce9d4333e..000000000000
--- a/drivers/net/wan/sdla_fr.c
+++ /dev/null
@@ -1,5061 +0,0 @@
1/*****************************************************************************
2* sdla_fr.c WANPIPE(tm) Multiprotocol WAN Link Driver. Frame relay module.
3*
4* Author(s): Nenad Corbic <ncorbic@sangoma.com>
5* Gideon Hack
6*
7* Copyright: (c) 1995-2001 Sangoma Technologies Inc.
8*
9* This program is free software; you can redistribute it and/or
10* modify it under the terms of the GNU General Public License
11* as published by the Free Software Foundation; either version
12* 2 of the License, or (at your option) any later version.
13* ============================================================================
14* Nov 23, 2000 Nenad Corbic o Added support for 2.4.X kernels
15* Nov 15, 2000 David Rokavarg
16* Nenad Corbic o Added frame relay bridging support.
17* Original code from Mark Wells and Kristian Hoffmann has
18* been integrated into the frame relay driver.
19* Nov 13, 2000 Nenad Corbic o Added true interface type encoding option.
20* Tcpdump doesn't support Frame Relay inteface
21* types, to fix this true type option will set
22* the interface type to RAW IP mode.
23* Nov 07, 2000 Nenad Corbic o Added security features for UDP debugging:
24* Deny all and specify allowed requests.
25* Nov 06, 2000 Nenad Corbic o Wanpipe interfaces conform to raw packet interfaces.
26* Moved the if_header into the if_send() routine.
27* The if_header() was breaking the libpcap
28* support. i.e. support for tcpdump, ethereal ...
29* Oct 12. 2000 Nenad Corbic o Added error message in fr_configure
30* Jul 31, 2000 Nenad Corbic o Fixed the Router UP Time.
31* Apr 28, 2000 Nenad Corbic o Added the option to shutdown an interface
32* when the channel gets disconnected.
33* Apr 28, 2000 Nenad Corbic o Added M.Grants patch: disallow duplicate
34* interface setups.
35* Apr 25, 2000 Nenad Corbic o Added M.Grants patch: dynamically add/remove
36* new dlcis/interfaces.
37* Mar 23, 2000 Nenad Corbic o Improved task queue, bh handling.
38* Mar 16, 2000 Nenad Corbic o Added Inverse ARP support
39* Mar 13, 2000 Nenad Corbic o Added new socket API support.
40* Mar 06, 2000 Nenad Corbic o Bug Fix: corrupted mbox recovery.
41* Feb 24, 2000 Nenad Corbic o Fixed up FT1 UDP debugging problem.
42* Dev 15, 1999 Nenad Corbic o Fixed up header files for 2.0.X kernels
43*
44* Nov 08, 1999 Nenad Corbic o Combined all debug UDP calls into one function
45* o Removed the ARP support. This has to be done
46* in the next version.
47* o Only a Node can implement NO signalling.
48* Initialize DLCI during if_open() if NO
49* signalling.
50* o Took out IPX support, implement in next
51* version
52* Sep 29, 1999 Nenad Corbic o Added SMP support and changed the update
53* function to use timer interrupt.
54* o Fixed the CIR bug: Set the value of BC
55* to CIR when the CIR is enabled.
56* o Updated comments, statistics and tracing.
57* Jun 02, 1999 Gideon Hack o Updated for S514 support.
58* Sep 18, 1998 Jaspreet Singh o Updated for 2.2.X kernels.
59* Jul 31, 1998 Jaspreet Singh o Removed wpf_poll routine. The channel/DLCI
60* status is received through an event interrupt.
61* Jul 08, 1998 David Fong o Added inverse ARP support.
62* Mar 26, 1997 Jaspreet Singh o Returning return codes for failed UDP cmds.
63* Jan 28, 1997 Jaspreet Singh o Improved handling of inactive DLCIs.
64* Dec 30, 1997 Jaspreet Singh o Replaced dev_tint() with mark_bh(NET_BH)
65* Dec 16, 1997 Jaspreet Singh o Implemented Multiple IPX support.
66* Nov 26, 1997 Jaspreet Singh o Improved load sharing with multiple boards
67* o Added Cli() to protect enabling of interrupts
68* while polling is called.
69* Nov 24, 1997 Jaspreet Singh o Added counters to avoid enabling of interrupts
70* when they have been disabled by another
71* interface or routine (eg. wpf_poll).
72* Nov 06, 1997 Jaspreet Singh o Added INTR_TEST_MODE to avoid polling
73* routine disable interrupts during interrupt
74* testing.
75* Oct 20, 1997 Jaspreet Singh o Added hooks in for Router UP time.
76* Oct 16, 1997 Jaspreet Singh o The critical flag is used to maintain flow
77* control by avoiding RACE conditions. The
78* cli() and restore_flags() are taken out.
79* The fr_channel structure is appended for
80* Driver Statistics.
81* Oct 15, 1997 Farhan Thawar o updated if_send() and receive for IPX
82* Aug 29, 1997 Farhan Thawar o Removed most of the cli() and sti()
83* o Abstracted the UDP management stuff
84* o Now use tbusy and critical more intelligently
85* Jul 21, 1997 Jaspreet Singh o Can configure T391, T392, N391, N392 & N393
86* through router.conf.
87* o Protected calls to sdla_peek() by adDing
88* save_flags(), cli() and restore_flags().
89* o Added error message for Inactive DLCIs in
90* fr_event() and update_chan_state().
91* o Fixed freeing up of buffers using kfree()
92* when packets are received.
93* Jul 07, 1997 Jaspreet Singh o Added configurable TTL for UDP packets
94* o Added ability to discard multicast and
95* broadcast source addressed packets
96* Jun 27, 1997 Jaspreet Singh o Added FT1 monitor capabilities
97* New case (0x44) statement in if_send routine
98* Added a global variable rCount to keep track
99* of FT1 status enabled on the board.
100* May 29, 1997 Jaspreet Singh o Fixed major Flow Control Problem
101* With multiple boards a problem was seen where
102* the second board always stopped transmitting
103* packet after running for a while. The code
104* got into a stage where the interrupts were
105* disabled and dev->tbusy was set to 1.
106* This caused the If_send() routine to get into
107* the if clause for it(0,dev->tbusy)
108* forever.
109* The code got into this stage due to an
110* interrupt occurring within the if clause for
111* set_bit(0,dev->tbusy). Since an interrupt
112* disables furhter transmit interrupt and
113* makes dev->tbusy = 0, this effect was undone
114* by making dev->tbusy = 1 in the if clause.
115* The Fix checks to see if Transmit interrupts
116* are disabled then do not make dev->tbusy = 1
117* Introduced a global variable: int_occur and
118* added tx_int_enabled in the wan_device
119* structure.
120* May 21, 1997 Jaspreet Singh o Fixed UDP Management for multiple
121* boards.
122*
123* Apr 25, 1997 Farhan Thawar o added UDP Management stuff
124* o fixed bug in if_send() and tx_intr() to
125* sleep and wakeup all devices
126* Mar 11, 1997 Farhan Thawar Version 3.1.1
127* o fixed (+1) bug in fr508_rx_intr()
128* o changed if_send() to return 0 if
129* wandev.critical() is true
130* o free socket buffer in if_send() if
131* returning 0
132* o added tx_intr() routine
133* Jan 30, 1997 Gene Kozin Version 3.1.0
134* o implemented exec() entry point
135* o fixed a bug causing driver configured as
136* a FR switch to be stuck in WAN_
137* mode
138* Jan 02, 1997 Gene Kozin Initial version.
139*****************************************************************************/
140
141#include <linux/module.h>
142#include <linux/kernel.h> /* printk(), and other useful stuff */
143#include <linux/stddef.h> /* offsetof(), etc. */
144#include <linux/errno.h> /* return codes */
145#include <linux/string.h> /* inline memset(), etc. */
146#include <linux/slab.h> /* kmalloc(), kfree() */
147#include <linux/wanrouter.h> /* WAN router definitions */
148#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
149#include <linux/workqueue.h>
150#include <linux/if_arp.h> /* ARPHRD_* defines */
151#include <asm/byteorder.h> /* htons(), etc. */
152#include <asm/io.h> /* for inb(), outb(), etc. */
153#include <linux/time.h> /* for do_gettimeofday */
154#include <linux/in.h> /* sockaddr_in */
155#include <linux/jiffies.h> /* time_after() macro */
156#include <asm/errno.h>
157
158#include <linux/ip.h>
159#include <linux/if.h>
160
161#include <linux/if_wanpipe_common.h> /* Wanpipe Socket */
162#include <linux/if_wanpipe.h>
163
164#include <linux/sdla_fr.h> /* frame relay firmware API definitions */
165
166#include <asm/uaccess.h>
167#include <linux/inetdevice.h>
168#include <linux/netdevice.h>
169
170#include <net/route.h> /* Dynamic Route Creation */
171#include <linux/etherdevice.h> /* eth_type_trans() used for bridging */
172#include <linux/random.h>
173
174/****** Defines & Macros ****************************************************/
175
176#define MAX_CMD_RETRY 10 /* max number of firmware retries */
177
178#define FR_HEADER_LEN 8 /* max encapsulation header size */
179#define FR_CHANNEL_MTU 1500 /* unfragmented logical channel MTU */
180
181/* Q.922 frame types */
182#define Q922_UI 0x03 /* Unnumbered Info frame */
183#define Q922_XID 0xAF
184
185/* DLCI configured or not */
186#define DLCI_NOT_CONFIGURED 0x00
187#define DLCI_CONFIG_PENDING 0x01
188#define DLCI_CONFIGURED 0x02
189
190/* CIR enabled or not */
191#define CIR_ENABLED 0x00
192#define CIR_DISABLED 0x01
193
194#define FRAME_RELAY_API 1
195#define MAX_BH_BUFF 10
196
197/* For handle_IPXWAN() */
198#define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))
199
200/****** Data Structures *****************************************************/
201
202/* This is an extention of the 'struct device' we create for each network
203 * interface to keep the rest of channel-specific data.
204 */
205typedef struct fr_channel
206{
207 wanpipe_common_t common;
208 char name[WAN_IFNAME_SZ+1]; /* interface name, ASCIIZ */
209 unsigned dlci_configured ; /* check whether configured or not */
210 unsigned cir_status; /* check whether CIR enabled or not */
211 unsigned dlci; /* logical channel number */
212 unsigned cir; /* committed information rate */
213 unsigned bc; /* committed burst size */
214 unsigned be; /* excess burst size */
215 unsigned mc; /* multicast support on or off */
216 unsigned tx_int_status; /* Transmit Interrupt Status */
217 unsigned short pkt_length; /* Packet Length */
218 unsigned long router_start_time;/* Router start time in seconds */
219 unsigned long tick_counter; /* counter for transmit time out */
220 char dev_pending_devtint; /* interface pending dev_tint() */
221 void *dlci_int_interface; /* pointer to the DLCI Interface */
222 unsigned long IB_addr; /* physical address of Interface Byte */
223 unsigned long state_tick; /* time of the last state change */
224 unsigned char enable_IPX; /* Enable/Disable the use of IPX */
225 unsigned long network_number; /* Internal Network Number for IPX*/
226 sdla_t *card; /* -> owner */
227 unsigned route_flag; /* Add/Rem dest addr in route tables */
228 unsigned inarp; /* Inverse Arp Request status */
229 long inarp_ready; /* Ready to send requests */
230 int inarp_interval; /* Time between InArp Requests */
231 unsigned long inarp_tick; /* InArp jiffies tick counter */
232 long interface_down; /* Bring interface down on disconnect */
233 struct net_device_stats ifstats; /* interface statistics */
234 if_send_stat_t drvstats_if_send;
235 rx_intr_stat_t drvstats_rx_intr;
236 pipe_mgmt_stat_t drvstats_gen;
237 unsigned long router_up_time;
238
239 unsigned short transmit_length;
240 struct sk_buff *delay_skb;
241
242 bh_data_t *bh_head; /* Circular buffer for chdlc_bh */
243 unsigned long tq_working;
244 volatile int bh_write;
245 volatile int bh_read;
246 atomic_t bh_buff_used;
247
248 /* Polling task queue. Each interface
249 * has its own task queue, which is used
250 * to defer events from the interrupt */
251 struct work_struct fr_poll_work;
252 struct timer_list fr_arp_timer;
253
254 u32 ip_local;
255 u32 ip_remote;
256 long config_dlci;
257 long unconfig_dlci;
258
259 /* Whether this interface should be setup as a gateway.
260 * Used by dynamic route setup code */
261 u8 gateway;
262
263 /* True interface type */
264 u8 true_if_encoding;
265 u8 fr_header[FR_HEADER_LEN];
266 char fr_header_len;
267
268} fr_channel_t;
269
270/* Route Flag options */
271#define NO_ROUTE 0x00
272#define ADD_ROUTE 0x01
273#define ROUTE_ADDED 0x02
274#define REMOVE_ROUTE 0x03
275#define ARP_REQ 0x04
276
277/* inarp options */
278#define INARP_NONE 0x00
279#define INARP_REQUEST 0x01
280#define INARP_CONFIGURED 0x02
281
282/* reasons for enabling the timer interrupt on the adapter */
283#define TMR_INT_ENABLED_UDP 0x01
284#define TMR_INT_ENABLED_UPDATE 0x02
285#define TMR_INT_ENABLED_ARP 0x04
286#define TMR_INT_ENABLED_UPDATE_STATE 0x08
287#define TMR_INT_ENABLED_CONFIG 0x10
288#define TMR_INT_ENABLED_UNCONFIG 0x20
289
290
291typedef struct dlci_status
292{
293 unsigned short dlci PACKED;
294 unsigned char state PACKED;
295} dlci_status_t;
296
297typedef struct dlci_IB_mapping
298{
299 unsigned short dlci PACKED;
300 unsigned long addr_value PACKED;
301} dlci_IB_mapping_t;
302
303/* This structure is used for DLCI list Tx interrupt mode. It is used to
304 enable interrupt bit and set the packet length for transmission
305 */
306typedef struct fr_dlci_interface
307{
308 unsigned char gen_interrupt PACKED;
309 unsigned short packet_length PACKED;
310 unsigned char reserved PACKED;
311} fr_dlci_interface_t;
312
313/* variable for keeping track of enabling/disabling FT1 monitor status */
314static int rCount = 0;
315
316extern void disable_irq(unsigned int);
317extern void enable_irq(unsigned int);
318
319/* variable for keeping track of number of interrupts generated during
320 * interrupt test routine
321 */
322static int Intr_test_counter;
323
324/****** Function Prototypes *************************************************/
325
326/* WAN link driver entry points. These are called by the WAN router module. */
327static int update(struct wan_device *wandev);
328static int new_if(struct wan_device *wandev, struct net_device *dev,
329 wanif_conf_t *conf);
330static int del_if(struct wan_device *wandev, struct net_device *dev);
331static void disable_comm (sdla_t *card);
332
333/* WANPIPE-specific entry points */
334static int wpf_exec(struct sdla *card, void *u_cmd, void *u_data);
335
336/* Network device interface */
337static int if_init(struct net_device *dev);
338static int if_open(struct net_device *dev);
339static int if_close(struct net_device *dev);
340
341static void if_tx_timeout(struct net_device *dev);
342
343static int if_rebuild_hdr (struct sk_buff *skb);
344
345static int if_send(struct sk_buff *skb, struct net_device *dev);
346static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
347 struct sk_buff *skb);
348static struct net_device_stats *if_stats(struct net_device *dev);
349
350/* Interrupt handlers */
351static void fr_isr(sdla_t *card);
352static void rx_intr(sdla_t *card);
353static void tx_intr(sdla_t *card);
354static void timer_intr(sdla_t *card);
355static void spur_intr(sdla_t *card);
356
357/* Frame relay firmware interface functions */
358static int fr_read_version(sdla_t *card, char *str);
359static int fr_configure(sdla_t *card, fr_conf_t *conf);
360static int fr_dlci_configure(sdla_t *card, fr_dlc_conf_t *conf, unsigned dlci);
361static int fr_init_dlci (sdla_t *card, fr_channel_t *chan);
362static int fr_set_intr_mode (sdla_t *card, unsigned mode, unsigned mtu, unsigned short timeout);
363static int fr_comm_enable(sdla_t *card);
364static void fr_comm_disable(sdla_t *card);
365static int fr_get_err_stats(sdla_t *card);
366static int fr_get_stats(sdla_t *card);
367static int fr_add_dlci(sdla_t *card, int dlci);
368static int fr_activate_dlci(sdla_t *card, int dlci);
369static int fr_delete_dlci (sdla_t* card, int dlci);
370static int fr_issue_isf(sdla_t *card, int isf);
371static int fr_send(sdla_t *card, int dlci, unsigned char attr, int len,
372 void *buf);
373static int fr_send_data_header(sdla_t *card, int dlci, unsigned char attr, int len,
374 void *buf,unsigned char hdr_len);
375static unsigned int fr_send_hdr(sdla_t *card, int dlci, unsigned int offset);
376
377static int check_dlci_config (sdla_t *card, fr_channel_t *chan);
378static void initialize_rx_tx_buffers (sdla_t *card);
379
380
381/* Firmware asynchronous event handlers */
382static int fr_event(sdla_t *card, int event, fr_mbox_t *mbox);
383static int fr_modem_failure(sdla_t *card, fr_mbox_t *mbox);
384static int fr_dlci_change(sdla_t *card, fr_mbox_t *mbox);
385
386/* Miscellaneous functions */
387static int update_chan_state(struct net_device *dev);
388static void set_chan_state(struct net_device *dev, int state);
389static struct net_device *find_channel(sdla_t *card, unsigned dlci);
390static int is_tx_ready(sdla_t *card, fr_channel_t *chan);
391static unsigned int dec_to_uint(unsigned char *str, int len);
392static int reply_udp( unsigned char *data, unsigned int mbox_len );
393
394static int intr_test( sdla_t* card );
395static void init_chan_statistics( fr_channel_t* chan );
396static void init_global_statistics( sdla_t* card );
397static void read_DLCI_IB_mapping( sdla_t* card, fr_channel_t* chan );
398static int setup_for_delayed_transmit(struct net_device* dev,
399 struct sk_buff *skb);
400
401struct net_device *move_dev_to_next(sdla_t *card, struct net_device *dev);
402static int check_tx_status(sdla_t *card, struct net_device *dev);
403
404/* Frame Relay Socket API */
405static void trigger_fr_bh (fr_channel_t *);
406static void fr_bh(struct net_device *dev);
407static int fr_bh_cleanup(struct net_device *dev);
408static int bh_enqueue(struct net_device *dev, struct sk_buff *skb);
409
410static void trigger_fr_poll(struct net_device *dev);
411static void fr_poll(struct net_device *dev);
412//static void add_gateway(struct net_device *dev);
413
414static void trigger_unconfig_fr(struct net_device *dev);
415static void unconfig_fr (sdla_t *);
416
417static void trigger_config_fr (sdla_t *);
418static void config_fr (sdla_t *);
419
420
421/* Inverse ARP and Dynamic routing functions */
422int process_ARP(arphdr_1490_t *ArpPacket, sdla_t *card, struct net_device *dev);
423int is_arp(void *buf);
424int send_inarp_request(sdla_t *card, struct net_device *dev);
425
426static void trigger_fr_arp(struct net_device *dev);
427static void fr_arp (unsigned long data);
428
429
430/* Udp management functions */
431static int process_udp_mgmt_pkt(sdla_t *card);
432static int udp_pkt_type( struct sk_buff *skb, sdla_t *card );
433static int store_udp_mgmt_pkt(int udp_type, char udp_pkt_src, sdla_t* card,
434 struct sk_buff *skb, int dlci);
435
436/* IPX functions */
437static void switch_net_numbers(unsigned char *sendpacket,
438 unsigned long network_number, unsigned char incoming);
439
440static int handle_IPXWAN(unsigned char *sendpacket, char *devname,
441 unsigned char enable_IPX, unsigned long network_number);
442
443/* Lock Functions: SMP supported */
444void s508_s514_unlock(sdla_t *card, unsigned long *smp_flags);
445void s508_s514_lock(sdla_t *card, unsigned long *smp_flags);
446
447unsigned short calc_checksum (char *, int);
448static int setup_fr_header(struct sk_buff *skb,
449 struct net_device* dev, char op_mode);
450
451
452/****** Public Functions ****************************************************/
453
454/*============================================================================
455 * Frame relay protocol initialization routine.
456 *
457 * This routine is called by the main WANPIPE module during setup. At this
458 * point adapter is completely initialized and firmware is running.
459 * o read firmware version (to make sure it's alive)
460 * o configure adapter
461 * o initialize protocol-specific fields of the adapter data space.
462 *
463 * Return: 0 o.k.
464 * < 0 failure.
465 */
466int wpf_init(sdla_t *card, wandev_conf_t *conf)
467{
468
469 int err;
470 fr508_flags_t* flags;
471
472 union
473 {
474 char str[80];
475 fr_conf_t cfg;
476 } u;
477
478 fr_buf_info_t* buf_info;
479 int i;
480
481
482 printk(KERN_INFO "\n");
483
484 /* Verify configuration ID */
485 if (conf->config_id != WANCONFIG_FR) {
486
487 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
488 card->devname, conf->config_id);
489 return -EINVAL;
490
491 }
492
493 /* Initialize protocol-specific fields of adapter data space */
494 switch (card->hw.fwid) {
495
496 case SFID_FR508:
497 card->mbox = (void*)(card->hw.dpmbase +
498 FR508_MBOX_OFFS);
499 card->flags = (void*)(card->hw.dpmbase +
500 FR508_FLAG_OFFS);
501 if(card->hw.type == SDLA_S514) {
502 card->mbox += FR_MB_VECTOR;
503 card->flags += FR_MB_VECTOR;
504 }
505 card->isr = &fr_isr;
506 break;
507
508 default:
509 return -EINVAL;
510 }
511
512 flags = card->flags;
513
514 /* Read firmware version. Note that when adapter initializes, it
515 * clears the mailbox, so it may appear that the first command was
516 * executed successfully when in fact it was merely erased. To work
517 * around this, we execute the first command twice.
518 */
519
520 if (fr_read_version(card, NULL) || fr_read_version(card, u.str))
521 return -EIO;
522
523 printk(KERN_INFO "%s: running frame relay firmware v%s\n",
524 card->devname, u.str);
525
526 /* Adjust configuration */
527 conf->mtu += FR_HEADER_LEN;
528 conf->mtu = (conf->mtu >= MIN_LGTH_FR_DATA_CFG) ?
529 min_t(unsigned int, conf->mtu, FR_MAX_NO_DATA_BYTES_IN_FRAME) :
530 FR_CHANNEL_MTU + FR_HEADER_LEN;
531
532 conf->bps = min_t(unsigned int, conf->bps, 2048000);
533
534 /* Initialze the configuration structure sent to the board to zero */
535 memset(&u.cfg, 0, sizeof(u.cfg));
536
537 memset(card->u.f.dlci_to_dev_map, 0, sizeof(card->u.f.dlci_to_dev_map));
538
539 /* Configure adapter firmware */
540
541 u.cfg.mtu = conf->mtu;
542 u.cfg.kbps = conf->bps / 1000;
543
544 u.cfg.cir_fwd = u.cfg.cir_bwd = 16;
545 u.cfg.bc_fwd = u.cfg.bc_bwd = 16;
546
547 u.cfg.options = 0x0000;
548 printk(KERN_INFO "%s: Global CIR enabled by Default\n", card->devname);
549
550 switch (conf->u.fr.signalling) {
551
552 case WANOPT_FR_ANSI:
553 u.cfg.options = 0x0000;
554 break;
555
556 case WANOPT_FR_Q933:
557 u.cfg.options |= 0x0200;
558 break;
559
560 case WANOPT_FR_LMI:
561 u.cfg.options |= 0x0400;
562 break;
563
564 case WANOPT_NO:
565 u.cfg.options |= 0x0800;
566 break;
567 default:
568 printk(KERN_INFO "%s: Illegal Signalling option\n",
569 card->wandev.name);
570 return -EINVAL;
571 }
572
573
574 card->wandev.signalling = conf->u.fr.signalling;
575
576 if (conf->station == WANOPT_CPE) {
577
578
579 if (conf->u.fr.signalling == WANOPT_NO){
580 printk(KERN_INFO
581 "%s: ERROR - For NO signalling, station must be set to Node!",
582 card->devname);
583 return -EINVAL;
584 }
585
586 u.cfg.station = 0;
587 u.cfg.options |= 0x8000; /* auto config DLCI */
588 card->u.f.dlci_num = 0;
589
590 } else {
591
592 u.cfg.station = 1; /* switch emulation mode */
593
594 /* For switch emulation we have to create a list of dlci(s)
595 * that will be sent to be global SET_DLCI_CONFIGURATION
596 * command in fr_configure() routine.
597 */
598
599 card->u.f.dlci_num = min_t(unsigned int, max_t(unsigned int, conf->u.fr.dlci_num, 1), 100);
600
601 for ( i = 0; i < card->u.f.dlci_num; i++) {
602
603 card->u.f.node_dlci[i] = (unsigned short)
604 conf->u.fr.dlci[i] ? conf->u.fr.dlci[i] : 16;
605
606 }
607 }
608
609 if (conf->clocking == WANOPT_INTERNAL)
610 u.cfg.port |= 0x0001;
611
612 if (conf->interface == WANOPT_RS232)
613 u.cfg.port |= 0x0002;
614
615 if (conf->u.fr.t391)
616 u.cfg.t391 = min_t(unsigned int, conf->u.fr.t391, 30);
617 else
618 u.cfg.t391 = 5;
619
620 if (conf->u.fr.t392)
621 u.cfg.t392 = min_t(unsigned int, conf->u.fr.t392, 30);
622 else
623 u.cfg.t392 = 15;
624
625 if (conf->u.fr.n391)
626 u.cfg.n391 = min_t(unsigned int, conf->u.fr.n391, 255);
627 else
628 u.cfg.n391 = 2;
629
630 if (conf->u.fr.n392)
631 u.cfg.n392 = min_t(unsigned int, conf->u.fr.n392, 10);
632 else
633 u.cfg.n392 = 3;
634
635 if (conf->u.fr.n393)
636 u.cfg.n393 = min_t(unsigned int, conf->u.fr.n393, 10);
637 else
638 u.cfg.n393 = 4;
639
640 if (fr_configure(card, &u.cfg))
641 return -EIO;
642
643 if (card->hw.type == SDLA_S514) {
644
645 buf_info = (void*)(card->hw.dpmbase + FR_MB_VECTOR +
646 FR508_RXBC_OFFS);
647
648 card->rxmb = (void*)(buf_info->rse_next + card->hw.dpmbase);
649
650 card->u.f.rxmb_base =
651 (void*)(buf_info->rse_base + card->hw.dpmbase);
652
653 card->u.f.rxmb_last =
654 (void*)(buf_info->rse_base +
655 (buf_info->rse_num - 1) * sizeof(fr_rx_buf_ctl_t) +
656 card->hw.dpmbase);
657 }else{
658 buf_info = (void*)(card->hw.dpmbase + FR508_RXBC_OFFS);
659
660 card->rxmb = (void*)(buf_info->rse_next -
661 FR_MB_VECTOR + card->hw.dpmbase);
662
663 card->u.f.rxmb_base =
664 (void*)(buf_info->rse_base -
665 FR_MB_VECTOR + card->hw.dpmbase);
666
667 card->u.f.rxmb_last =
668 (void*)(buf_info->rse_base +
669 (buf_info->rse_num - 1) * sizeof(fr_rx_buf_ctl_t) -
670 FR_MB_VECTOR + card->hw.dpmbase);
671 }
672
673 card->u.f.rx_base = buf_info->buf_base;
674 card->u.f.rx_top = buf_info->buf_top;
675
676 card->u.f.tx_interrupts_pending = 0;
677
678 card->wandev.mtu = conf->mtu;
679 card->wandev.bps = conf->bps;
680 card->wandev.interface = conf->interface;
681 card->wandev.clocking = conf->clocking;
682 card->wandev.station = conf->station;
683 card->poll = NULL;
684 card->exec = &wpf_exec;
685 card->wandev.update = &update;
686 card->wandev.new_if = &new_if;
687 card->wandev.del_if = &del_if;
688 card->wandev.state = WAN_DISCONNECTED;
689 card->wandev.ttl = conf->ttl;
690 card->wandev.udp_port = conf->udp_port;
691 card->disable_comm = &disable_comm;
692 card->u.f.arp_dev = NULL;
693
694 /* Intialize global statistics for a card */
695 init_global_statistics( card );
696
697 card->TracingEnabled = 0;
698
699 /* Interrupt Test */
700 Intr_test_counter = 0;
701 card->intr_mode = INTR_TEST_MODE;
702 err = intr_test( card );
703
704 printk(KERN_INFO "%s: End of Interrupt Test rc=0x%x count=%i\n",
705 card->devname,err,Intr_test_counter);
706
707 if (err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
708 printk(KERN_ERR "%s: Interrupt Test Failed, Counter: %i\n",
709 card->devname, Intr_test_counter);
710 printk(KERN_ERR "Please choose another interrupt\n");
711 err = -EIO;
712 return err;
713 }
714
715 printk(KERN_INFO "%s: Interrupt Test Passed, Counter: %i\n",
716 card->devname, Intr_test_counter);
717
718
719 /* Apr 28 2000. Nenad Corbic
720 * Enable commnunications here, not in if_open or new_if, since
721 * interfaces come down when the link is disconnected.
722 */
723
724 /* If you enable comms and then set ints, you get a Tx int as you
725 * perform the SET_INT_TRIGGERS command. So, we only set int
726 * triggers and then adjust the interrupt mask (to disable Tx ints)
727 * before enabling comms.
728 */
729 if (fr_set_intr_mode(card, (FR_INTR_RXRDY | FR_INTR_TXRDY |
730 FR_INTR_DLC | FR_INTR_TIMER | FR_INTR_TX_MULT_DLCIs) ,
731 card->wandev.mtu, 0)) {
732 return -EIO;
733 }
734
735 flags->imask &= ~(FR_INTR_TXRDY | FR_INTR_TIMER);
736
737 if (fr_comm_enable(card)) {
738 return -EIO;
739 }
740 wanpipe_set_state(card, WAN_CONNECTED);
741 spin_lock_init(&card->u.f.if_send_lock);
742
743 printk(KERN_INFO "\n");
744
745 return 0;
746}
747
748/******* WAN Device Driver Entry Points *************************************/
749
750/*============================================================================
751 * Update device status & statistics.
752 */
753static int update(struct wan_device* wandev)
754{
755 volatile sdla_t* card;
756 unsigned long timeout;
757 fr508_flags_t* flags;
758
759 /* sanity checks */
760 if ((wandev == NULL) || (wandev->private == NULL))
761 return -EFAULT;
762
763 if (wandev->state == WAN_UNCONFIGURED)
764 return -ENODEV;
765
766 card = wandev->private;
767 flags = card->flags;
768
769
770 card->u.f.update_comms_stats = 1;
771 card->u.f.timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
772 flags->imask |= FR_INTR_TIMER;
773 timeout = jiffies;
774 for(;;) {
775 if(card->u.f.update_comms_stats == 0)
776 break;
777 if (time_after(jiffies, timeout + 1 * HZ)){
778 card->u.f.update_comms_stats = 0;
779 return -EAGAIN;
780 }
781 }
782
783 return 0;
784}
785
786/*============================================================================
787 * Create new logical channel.
788 * This routine is called by the router when ROUTER_IFNEW IOCTL is being
789 * handled.
790 * o parse media- and hardware-specific configuration
791 * o make sure that a new channel can be created
792 * o allocate resources, if necessary
793 * o prepare network device structure for registaration.
794 *
795 * Return: 0 o.k.
796 * < 0 failure (channel will not be created)
797 */
798static int new_if(struct wan_device* wandev, struct net_device* dev,
799 wanif_conf_t* conf)
800{
801 sdla_t* card = wandev->private;
802 fr_channel_t* chan;
803 int dlci = 0;
804 int err = 0;
805
806
807 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
808
809 printk(KERN_INFO "%s: Invalid interface name!\n",
810 card->devname);
811 return -EINVAL;
812 }
813
814 /* allocate and initialize private data */
815 chan = kmalloc(sizeof(fr_channel_t), GFP_KERNEL);
816
817 if (chan == NULL)
818 return -ENOMEM;
819
820 memset(chan, 0, sizeof(fr_channel_t));
821 strcpy(chan->name, conf->name);
822 chan->card = card;
823
824 /* verify media address */
825 if (isdigit(conf->addr[0])) {
826
827 dlci = dec_to_uint(conf->addr, 0);
828
829 if (dlci && (dlci <= HIGHEST_VALID_DLCI)) {
830
831 chan->dlci = dlci;
832
833 } else {
834
835 printk(KERN_ERR
836 "%s: Invalid DLCI %u on interface %s!\n",
837 wandev->name, dlci, chan->name);
838 err = -EINVAL;
839 }
840
841 } else {
842 printk(KERN_ERR
843 "%s: Invalid media address on interface %s!\n",
844 wandev->name, chan->name);
845 err = -EINVAL;
846 }
847
848 if ((chan->true_if_encoding = conf->true_if_encoding) == WANOPT_YES){
849 printk(KERN_INFO
850 "%s: Enabling, true interface type encoding.\n",
851 card->devname);
852 }
853
854
855
856 /* Setup wanpipe as a router (WANPIPE) even if it is
857 * a bridged DLCI, or as an API
858 */
859 if (strcmp(conf->usedby, "WANPIPE") == 0 ||
860 strcmp(conf->usedby, "BRIDGE") == 0 ||
861 strcmp(conf->usedby, "BRIDGE_N") == 0){
862
863 if(strcmp(conf->usedby, "WANPIPE") == 0){
864 chan->common.usedby = WANPIPE;
865
866 printk(KERN_INFO "%s: Running in WANPIPE mode.\n",
867 card->devname);
868
869 }else if(strcmp(conf->usedby, "BRIDGE") == 0){
870
871 chan->common.usedby = BRIDGE;
872
873 printk(KERN_INFO "%s: Running in WANPIPE (BRIDGE) mode.\n",
874 card->devname);
875 }else if( strcmp(conf->usedby, "BRIDGE_N") == 0 ){
876
877 chan->common.usedby = BRIDGE_NODE;
878
879 printk(KERN_INFO "%s: Running in WANPIPE (BRIDGE_NODE) mode.\n",
880 card->devname);
881 }
882
883 if (!err){
884 /* Dynamic interface configuration option.
885 * On disconnect, if the options is selected,
886 * the interface will be brought down */
887 if (conf->if_down == WANOPT_YES){
888 set_bit(DYN_OPT_ON,&chan->interface_down);
889 printk(KERN_INFO
890 "%s: Dynamic interface configuration enabled.\n",
891 card->devname);
892 }
893 }
894
895 } else if(strcmp(conf->usedby, "API") == 0){
896
897 chan->common.usedby = API;
898 printk(KERN_INFO "%s: Running in API mode.\n",
899 wandev->name);
900 }
901
902 if (err) {
903
904 kfree(chan);
905 return err;
906 }
907
908 /* place cir,be,bc and other channel specific information into the
909 * chan structure
910 */
911 if (conf->cir) {
912
913 chan->cir = max_t(unsigned int, 1,
914 min_t(unsigned int, conf->cir, 512));
915 chan->cir_status = CIR_ENABLED;
916
917
918 /* If CIR is enabled, force BC to equal CIR
919 * this solves number of potential problems if CIR is
920 * set and BC is not
921 */
922 chan->bc = chan->cir;
923
924 if (conf->be){
925 chan->be = max_t(unsigned int,
926 0, min_t(unsigned int, conf->be, 511));
927 }else{
928 conf->be = 0;
929 }
930
931 printk (KERN_INFO "%s: CIR enabled for DLCI %i \n",
932 wandev->name,chan->dlci);
933 printk (KERN_INFO "%s: CIR = %i ; BC = %i ; BE = %i\n",
934 wandev->name,chan->cir,chan->bc,chan->be);
935
936
937 }else{
938 chan->cir_status = CIR_DISABLED;
939 printk (KERN_INFO "%s: CIR disabled for DLCI %i\n",
940 wandev->name,chan->dlci);
941 }
942
943 chan->mc = conf->mc;
944
945 if (conf->inarp == WANOPT_YES){
946 printk(KERN_INFO "%s: Inverse ARP Support Enabled\n",card->devname);
947 chan->inarp = conf->inarp ? INARP_REQUEST : INARP_NONE;
948 chan->inarp_interval = conf->inarp_interval ? conf->inarp_interval : 10;
949 }else{
950 printk(KERN_INFO "%s: Inverse ARP Support Disabled\n",card->devname);
951 chan->inarp = INARP_NONE;
952 chan->inarp_interval = 10;
953 }
954
955
956 chan->dlci_configured = DLCI_NOT_CONFIGURED;
957
958
959 /*FIXME: IPX disabled in this WANPIPE version */
960 if (conf->enable_IPX == WANOPT_YES){
961 printk(KERN_INFO "%s: ERROR - This version of WANPIPE doesn't support IPX\n",
962 card->devname);
963 kfree(chan);
964 return -EINVAL;
965 }else{
966 chan->enable_IPX = WANOPT_NO;
967 }
968
969 if (conf->network_number){
970 chan->network_number = conf->network_number;
971 }else{
972 chan->network_number = 0xDEADBEEF;
973 }
974
975 chan->route_flag = NO_ROUTE;
976
977 init_chan_statistics(chan);
978
979 chan->transmit_length = 0;
980
981 /* prepare network device data space for registration */
982 strcpy(dev->name,chan->name);
983
984 dev->init = &if_init;
985 dev->priv = chan;
986
987 /* Initialize FR Polling Task Queue
988 * We need a poll routine for each network
989 * interface.
990 */
991 INIT_WORK(&chan->fr_poll_work, (void *)fr_poll, dev);
992
993 init_timer(&chan->fr_arp_timer);
994 chan->fr_arp_timer.data=(unsigned long)dev;
995 chan->fr_arp_timer.function = fr_arp;
996
997 wandev->new_if_cnt++;
998
999 /* Tells us that if this interface is a
1000 * gateway or not */
1001 if ((chan->gateway = conf->gateway) == WANOPT_YES){
1002 printk(KERN_INFO "%s: Interface %s is set as a gateway.\n",
1003 card->devname,dev->name);
1004 }
1005
1006 /* M. Grant Patch Apr 28 2000
1007 * Disallow duplicate dlci configurations. */
1008 if (card->u.f.dlci_to_dev_map[chan->dlci] != NULL) {
1009 kfree(chan);
1010 return -EBUSY;
1011 }
1012
1013 /* Configure this dlci at a later date, when
1014 * the interface comes up. i.e. when if_open()
1015 * executes */
1016 set_bit(0,&chan->config_dlci);
1017
1018 printk(KERN_INFO "\n");
1019
1020 return 0;
1021}
1022
1023/*============================================================================
1024 * Delete logical channel.
1025 */
1026static int del_if(struct wan_device* wandev, struct net_device* dev)
1027{
1028 fr_channel_t* chan = dev->priv;
1029 unsigned long smp_flags=0;
1030
1031 /* This interface is dead, make sure the
1032 * ARP timer is stopped */
1033 del_timer(&chan->fr_arp_timer);
1034
1035 /* If we are a NODE, we must unconfigure this DLCI
1036 * Trigger an unconfigure command that will
1037 * be executed in timer interrupt. We must wait
1038 * for the command to complete. */
1039 trigger_unconfig_fr(dev);
1040
1041 lock_adapter_irq(&wandev->lock, &smp_flags);
1042 wandev->new_if_cnt--;
1043 unlock_adapter_irq(&wandev->lock, &smp_flags);
1044
1045 return 0;
1046}
1047
1048
1049/*=====================================================================
1050 * disable_comm
1051 *
1052 * Description:
1053 * Disable communications.
1054 * This code runs in shutdown (sdlamain.c)
1055 * under critical flag. Therefore it is not
1056 * necessary to set a critical flag here
1057 *
1058 * Usage:
1059 * Commnunications are disabled only on a card
1060 * shutdown.
1061 */
1062
1063static void disable_comm (sdla_t *card)
1064{
1065 printk(KERN_INFO "%s: Disabling Communications!\n",
1066 card->devname);
1067 fr_comm_disable(card);
1068}
1069
1070/****** WANPIPE-specific entry points ***************************************/
1071
1072/*============================================================================
1073 * Execute adapter interface command.
1074 */
1075static int wpf_exec (struct sdla* card, void* u_cmd, void* u_data)
1076{
1077 fr_mbox_t* mbox = card->mbox;
1078 int retry = MAX_CMD_RETRY;
1079 int err, len;
1080 fr_cmd_t cmd;
1081
1082 if(copy_from_user((void*)&cmd, u_cmd, sizeof(cmd)))
1083 return -EFAULT;
1084
1085 /* execute command */
1086 do
1087 {
1088 memcpy(&mbox->cmd, &cmd, sizeof(cmd));
1089
1090 if (cmd.length){
1091 if( copy_from_user((void*)&mbox->data, u_data, cmd.length))
1092 return -EFAULT;
1093 }
1094
1095 if (sdla_exec(mbox))
1096 err = mbox->cmd.result;
1097
1098 else return -EIO;
1099
1100 } while (err && retry-- && fr_event(card, err, mbox));
1101
1102 /* return result */
1103 if (copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(fr_cmd_t)))
1104 return -EFAULT;
1105
1106 len = mbox->cmd.length;
1107
1108 if (len && u_data && !copy_to_user(u_data, (void*)&mbox->data, len))
1109 return -EFAULT;
1110 return 0;
1111}
1112
1113/****** Network Device Interface ********************************************/
1114
1115/*============================================================================
1116 * Initialize Linux network interface.
1117 *
1118 * This routine is called only once for each interface, during Linux network
1119 * interface registration. Returning anything but zero will fail interface
1120 * registration.
1121 */
1122static int if_init(struct net_device* dev)
1123{
1124 fr_channel_t* chan = dev->priv;
1125 sdla_t* card = chan->card;
1126 struct wan_device* wandev = &card->wandev;
1127
1128 /* Initialize device driver entry points */
1129 dev->open = &if_open;
1130 dev->stop = &if_close;
1131 dev->hard_header = NULL;
1132 dev->rebuild_header = &if_rebuild_hdr;
1133 dev->hard_start_xmit = &if_send;
1134 dev->get_stats = &if_stats;
1135 dev->tx_timeout = &if_tx_timeout;
1136 dev->watchdog_timeo = TX_TIMEOUT;
1137
1138 if (chan->common.usedby == WANPIPE || chan->common.usedby == API){
1139
1140 /* Initialize media-specific parameters */
1141 if (chan->true_if_encoding){
1142 dev->type = ARPHRD_DLCI; /* This breaks tcpdump */
1143 }else{
1144 dev->type = ARPHRD_PPP; /* ARP h/w type */
1145 }
1146
1147 dev->flags |= IFF_POINTOPOINT;
1148 dev->flags |= IFF_NOARP;
1149
1150 /* Enable Multicast addressing */
1151 if (chan->mc == WANOPT_YES){
1152 dev->flags |= IFF_MULTICAST;
1153 }
1154
1155 dev->mtu = wandev->mtu - FR_HEADER_LEN;
1156 /* For an API, the maximum number of bytes that the stack will pass
1157 to the driver is (dev->mtu + dev->hard_header_len). So, adjust the
1158 mtu so that a frame of maximum size can be transmitted by the API.
1159 */
1160 if(chan->common.usedby == API) {
1161 dev->mtu += (sizeof(api_tx_hdr_t) - FR_HEADER_LEN);
1162 }
1163
1164 dev->hard_header_len = FR_HEADER_LEN;/* media header length */
1165 dev->addr_len = 2; /* hardware address length */
1166 *(unsigned short*)dev->dev_addr = htons(chan->dlci);
1167
1168 /* Set transmit buffer queue length */
1169 dev->tx_queue_len = 100;
1170
1171 }else{
1172
1173 /* Setup the interface for Bridging */
1174 int hw_addr=0;
1175 ether_setup(dev);
1176
1177 /* Use a random number to generate the MAC address */
1178 memcpy(dev->dev_addr, "\xFE\xFC\x00\x00\x00\x00", 6);
1179 get_random_bytes(&hw_addr, sizeof(hw_addr));
1180 *(int *)(dev->dev_addr + 2) += hw_addr;
1181 }
1182
1183 /* Initialize hardware parameters (just for reference) */
1184 dev->irq = wandev->irq;
1185 dev->dma = wandev->dma;
1186 dev->base_addr = wandev->ioport;
1187 dev->mem_start = wandev->maddr;
1188 dev->mem_end = wandev->maddr + wandev->msize - 1;
1189 SET_MODULE_OWNER(dev);
1190
1191 return 0;
1192}
1193
1194/*============================================================================
1195 * Open network interface.
1196 * o if this is the first open, then enable communications and interrupts.
1197 * o prevent module from unloading by incrementing use count
1198 *
1199 * Return 0 if O.k. or errno.
1200 */
1201static int if_open(struct net_device* dev)
1202{
1203 fr_channel_t* chan = dev->priv;
1204 sdla_t* card = chan->card;
1205 int err = 0;
1206 struct timeval tv;
1207
1208 if (netif_running(dev))
1209 return -EBUSY;
1210
1211 /* Initialize the task queue */
1212 chan->tq_working=0;
1213
1214 INIT_WORK(&chan->common.wanpipe_work, (void *)fr_bh, dev);
1215
1216 /* Allocate and initialize BH circular buffer */
1217 chan->bh_head = kmalloc((sizeof(bh_data_t)*MAX_BH_BUFF),GFP_ATOMIC);
1218 memset(chan->bh_head,0,(sizeof(bh_data_t)*MAX_BH_BUFF));
1219 atomic_set(&chan->bh_buff_used, 0);
1220
1221 netif_start_queue(dev);
1222
1223 wanpipe_open(card);
1224 do_gettimeofday( &tv );
1225 chan->router_start_time = tv.tv_sec;
1226
1227 if (test_bit(0,&chan->config_dlci)){
1228 trigger_config_fr (card);
1229 }else if (chan->inarp == INARP_REQUEST){
1230 trigger_fr_arp(dev);
1231 }
1232
1233 return err;
1234}
1235
1236/*============================================================================
1237 * Close network interface.
1238 * o if this is the last open, then disable communications and interrupts.
1239 * o reset flags.
1240 */
1241static int if_close(struct net_device* dev)
1242{
1243 fr_channel_t* chan = dev->priv;
1244 sdla_t* card = chan->card;
1245
1246 if (chan->inarp == INARP_CONFIGURED) {
1247 chan->inarp = INARP_REQUEST;
1248 }
1249
1250 netif_stop_queue(dev);
1251 wanpipe_close(card);
1252
1253 return 0;
1254}
1255
1256/*============================================================================
1257 * Re-build media header.
1258 *
1259 * Return: 1 physical address resolved.
1260 * 0 physical address not resolved
1261 */
1262static int if_rebuild_hdr (struct sk_buff* skb)
1263{
1264 struct net_device *dev = skb->dev;
1265 fr_channel_t* chan = dev->priv;
1266 sdla_t* card = chan->card;
1267
1268 printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
1269 card->devname, dev->name);
1270 return 1;
1271}
1272
1273/*============================================================================
1274 * Handle transmit timeout event from netif watchdog
1275 */
1276static void if_tx_timeout(struct net_device *dev)
1277{
1278 fr_channel_t* chan = dev->priv;
1279 sdla_t *card = chan->card;
1280
1281 /* If our device stays busy for at least 5 seconds then we will
1282 * kick start the device by making dev->tbusy = 0. We expect
1283 * that our device never stays busy more than 5 seconds. So this
1284 * is only used as a last resort.
1285 */
1286
1287 chan->drvstats_if_send.if_send_tbusy++;
1288 ++chan->ifstats.collisions;
1289
1290 printk (KERN_INFO "%s: Transmit timed out on %s\n",
1291 card->devname, dev->name);
1292 chan->drvstats_if_send.if_send_tbusy_timeout++;
1293 netif_wake_queue (dev);
1294
1295}
1296
1297
1298/*============================================================================
1299 * Send a packet on a network interface.
1300 * o set tbusy flag (marks start of the transmission) to block a timer-based
1301 * transmit from overlapping.
1302 * o set critical flag when accessing board.
1303 * o check link state. If link is not up, then drop the packet.
1304 * o check channel status. If it's down then initiate a call.
1305 * o pass a packet to corresponding WAN device.
1306 * o free socket buffer
1307 *
1308 * Return: 0 complete (socket buffer must be freed)
1309 * non-0 packet may be re-transmitted (tbusy must be set)
1310 *
1311 * Notes:
1312 * 1. This routine is called either by the protocol stack or by the "net
1313 * bottom half" (with interrupts enabled).
1314 *
1315 * 2. Using netif_start_queue() and netif_stop_queue()
1316 * will inhibit further transmit requests from the protocol stack
1317 * and can be used for flow control with protocol layer.
1318 */
1319static int if_send(struct sk_buff* skb, struct net_device* dev)
1320{
1321 fr_channel_t* chan = dev->priv;
1322 sdla_t* card = chan->card;
1323 int err;
1324 unsigned char *sendpacket;
1325 fr508_flags_t* adptr_flags = card->flags;
1326 int udp_type;
1327 long delay_tx_queued = 0;
1328 unsigned long smp_flags=0;
1329 unsigned char attr = 0;
1330
1331 chan->drvstats_if_send.if_send_entry++;
1332
1333 netif_stop_queue(dev);
1334
1335 if (skb == NULL) {
1336 /* if we get here, some higher layer thinks we've missed an
1337 * tx-done interrupt.
1338 */
1339 printk(KERN_INFO "%s: interface %s got kicked!\n",
1340 card->devname, dev->name);
1341 chan->drvstats_if_send.if_send_skb_null ++;
1342
1343 netif_wake_queue(dev);
1344 return 0;
1345 }
1346
1347 /* If a peripheral task is running just drop packets */
1348 if (test_bit(PERI_CRIT, &card->wandev.critical)){
1349
1350 printk(KERN_INFO "%s: Critical in if_send(): Peripheral running!\n",
1351 card->devname);
1352
1353 dev_kfree_skb_any(skb);
1354 netif_start_queue(dev);
1355 return 0;
1356 }
1357
1358 /* We must set the 'tbusy' flag if we already have a packet queued for
1359 transmission in the transmit interrupt handler. However, we must
1360 ensure that the transmit interrupt does not reset the 'tbusy' flag
1361 just before we set it, as this will result in a "transmit timeout".
1362 */
1363 set_bit(SEND_TXIRQ_CRIT, (void*)&card->wandev.critical);
1364 if(chan->transmit_length) {
1365 netif_stop_queue(dev);
1366 chan->tick_counter = jiffies;
1367 clear_bit(SEND_TXIRQ_CRIT, (void*)&card->wandev.critical);
1368 return 1;
1369 }
1370 clear_bit(SEND_TXIRQ_CRIT, (void*)&card->wandev.critical);
1371
1372 /* Move the if_header() code to here. By inserting frame
1373 * relay header in if_header() we would break the
1374 * tcpdump and other packet sniffers */
1375 chan->fr_header_len = setup_fr_header(skb,dev,chan->common.usedby);
1376 if (chan->fr_header_len < 0 ){
1377 ++chan->ifstats.tx_dropped;
1378 ++card->wandev.stats.tx_dropped;
1379
1380 dev_kfree_skb_any(skb);
1381 netif_start_queue(dev);
1382 return 0;
1383 }
1384
1385 sendpacket = skb->data;
1386
1387 udp_type = udp_pkt_type(skb, card);
1388
1389 if(udp_type != UDP_INVALID_TYPE) {
1390 if(store_udp_mgmt_pkt(udp_type, UDP_PKT_FRM_STACK, card, skb,
1391 chan->dlci)) {
1392 adptr_flags->imask |= FR_INTR_TIMER;
1393 if (udp_type == UDP_FPIPE_TYPE){
1394 chan->drvstats_if_send.
1395 if_send_PIPE_request ++;
1396 }
1397 }
1398 netif_start_queue(dev);
1399 return 0;
1400 }
1401
1402 //FIXME: can we do better than sendpacket[2]?
1403 if ((chan->common.usedby == WANPIPE) && (sendpacket[2] == 0x45)) {
1404
1405 /* check to see if the source IP address is a broadcast or */
1406 /* multicast IP address */
1407 if(chk_bcast_mcast_addr(card, dev, skb)){
1408 ++chan->ifstats.tx_dropped;
1409 ++card->wandev.stats.tx_dropped;
1410 dev_kfree_skb_any(skb);
1411 netif_start_queue(dev);
1412 return 0;
1413 }
1414 }
1415
1416
1417 /* Lock the S514/S508 card: SMP Supported */
1418 s508_s514_lock(card,&smp_flags);
1419
1420 if (test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
1421
1422 chan->drvstats_if_send.if_send_critical_non_ISR ++;
1423 chan->ifstats.tx_dropped ++;
1424 printk(KERN_INFO "%s Critical in IF_SEND: if_send() already running!\n",
1425 card->devname);
1426 goto if_send_start_and_exit;
1427 }
1428
1429 /* API packet check: minimum packet size must be greater than
1430 * 16 byte API header */
1431 if((chan->common.usedby == API) && (skb->len <= sizeof(api_tx_hdr_t))) {
1432 ++chan->ifstats.tx_dropped;
1433 ++card->wandev.stats.tx_dropped;
1434
1435
1436 goto if_send_start_and_exit;
1437
1438 }else{
1439 /* During API transmission, get rid of the API header */
1440 if (chan->common.usedby == API) {
1441 api_tx_hdr_t* api_tx_hdr;
1442 api_tx_hdr = (api_tx_hdr_t*)&skb->data[0x00];
1443 attr = api_tx_hdr->attr;
1444 skb_pull(skb,sizeof(api_tx_hdr_t));
1445 }
1446 }
1447
1448 if (card->wandev.state != WAN_CONNECTED) {
1449 chan->drvstats_if_send.if_send_wan_disconnected ++;
1450 ++chan->ifstats.tx_dropped;
1451 ++card->wandev.stats.tx_dropped;
1452
1453 } else if (chan->common.state != WAN_CONNECTED) {
1454 chan->drvstats_if_send.if_send_dlci_disconnected ++;
1455
1456 /* Update the DLCI state in timer interrupt */
1457 card->u.f.timer_int_enabled |= TMR_INT_ENABLED_UPDATE_STATE;
1458 adptr_flags->imask |= FR_INTR_TIMER;
1459
1460 ++chan->ifstats.tx_dropped;
1461 ++card->wandev.stats.tx_dropped;
1462
1463 } else if (!is_tx_ready(card, chan)) {
1464 /* No tx buffers available, store for delayed transmit */
1465 if (!setup_for_delayed_transmit(dev, skb)){
1466 set_bit(1,&delay_tx_queued);
1467 }
1468 chan->drvstats_if_send.if_send_no_bfrs++;
1469
1470 } else if (!skb->protocol) {
1471 /* No protocols drop packet */
1472 chan->drvstats_if_send.if_send_protocol_error ++;
1473 ++card->wandev.stats.tx_errors;
1474
1475 } else if (test_bit(ARP_CRIT,&card->wandev.critical)){
1476 /* We are trying to send an ARP Packet, block IP data until
1477 * ARP is sent */
1478 ++chan->ifstats.tx_dropped;
1479 ++card->wandev.stats.tx_dropped;
1480
1481 } else {
1482 //FIXME: IPX is not implemented in this version of Frame Relay ?
1483 if((chan->common.usedby == WANPIPE) &&
1484 sendpacket[1] == 0x00 &&
1485 sendpacket[2] == 0x80 &&
1486 sendpacket[6] == 0x81 &&
1487 sendpacket[7] == 0x37) {
1488
1489 if( chan->enable_IPX ) {
1490 switch_net_numbers(sendpacket,
1491 chan->network_number, 0);
1492 } else {
1493 //FIXME: Take this out when IPX is fixed
1494 printk(KERN_INFO
1495 "%s: WARNING: Unsupported IPX data in send, packet dropped\n",
1496 card->devname);
1497 }
1498
1499 }else{
1500 err = fr_send_data_header(card, chan->dlci, attr, skb->len, skb->data, chan->fr_header_len);
1501 if (err) {
1502 switch(err) {
1503 case FRRES_CIR_OVERFLOW:
1504 case FRRES_BUFFER_OVERFLOW:
1505 if (!setup_for_delayed_transmit(dev, skb)){
1506 set_bit(1,&delay_tx_queued);
1507 }
1508 chan->drvstats_if_send.
1509 if_send_adptr_bfrs_full ++;
1510 break;
1511
1512 case FRRES_TOO_LONG:
1513 if (net_ratelimit()){
1514 printk(KERN_INFO
1515 "%s: Error: Frame too long, transmission failed %i\n",
1516 card->devname, (unsigned int)skb->len);
1517 }
1518 /* Drop down to default */
1519 default:
1520 chan->drvstats_if_send.
1521 if_send_dlci_disconnected ++;
1522 ++chan->ifstats.tx_dropped;
1523 ++card->wandev.stats.tx_dropped;
1524 break;
1525 }
1526 } else {
1527 chan->drvstats_if_send.
1528 if_send_bfr_passed_to_adptr++;
1529 ++chan->ifstats.tx_packets;
1530 ++card->wandev.stats.tx_packets;
1531
1532 chan->ifstats.tx_bytes += skb->len;
1533 card->wandev.stats.tx_bytes += skb->len;
1534 dev->trans_start = jiffies;
1535 }
1536 }
1537 }
1538
1539if_send_start_and_exit:
1540
1541 netif_start_queue(dev);
1542
1543 /* If we queued the packet for transmission, we must not
1544 * deallocate it. The packet is unlinked from the IP stack
1545 * not copied. Therefore, we must keep the original packet */
1546 if (!test_bit(1,&delay_tx_queued)) {
1547 dev_kfree_skb_any(skb);
1548 }else{
1549 adptr_flags->imask |= FR_INTR_TXRDY;
1550 card->u.f.tx_interrupts_pending ++;
1551 }
1552
1553 clear_bit(SEND_CRIT, (void*)&card->wandev.critical);
1554
1555 s508_s514_unlock(card,&smp_flags);
1556
1557 return 0;
1558}
1559
1560
1561
1562/*============================================================================
1563 * Setup so that a frame can be transmitted on the occurrence of a transmit
1564 * interrupt.
1565 */
1566static int setup_for_delayed_transmit(struct net_device* dev,
1567 struct sk_buff *skb)
1568{
1569 fr_channel_t* chan = dev->priv;
1570 sdla_t* card = chan->card;
1571 fr_dlci_interface_t* dlci_interface;
1572 int len = skb->len;
1573
1574 /* Check that the dlci is properly configured,
1575 * before using tx interrupt */
1576 if (!chan->dlci_int_interface){
1577 if (net_ratelimit()){
1578 printk(KERN_INFO
1579 "%s: ERROR on DLCI %i: Not configured properly !\n",
1580 card->devname, chan->dlci);
1581 printk(KERN_INFO "%s: Please contact Sangoma Technologies\n",
1582 card->devname);
1583 }
1584 return 1;
1585 }
1586
1587 dlci_interface = chan->dlci_int_interface;
1588
1589 if(chan->transmit_length) {
1590 printk(KERN_INFO "%s: Big mess in setup_for_del...\n",
1591 card->devname);
1592 return 1;
1593 }
1594
1595 if(len > FR_MAX_NO_DATA_BYTES_IN_FRAME) {
1596 //FIXME: increment some statistic */
1597 return 1;
1598 }
1599
1600 chan->transmit_length = len;
1601 chan->delay_skb = skb;
1602
1603 dlci_interface->gen_interrupt |= FR_INTR_TXRDY;
1604 dlci_interface->packet_length = len;
1605
1606 /* Turn on TX interrupt at the end of if_send */
1607 return 0;
1608}
1609
1610
1611/*============================================================================
1612 * Check to see if the packet to be transmitted contains a broadcast or
1613 * multicast source IP address.
1614 * Return 0 if not broadcast/multicast address, otherwise return 1.
1615 */
1616
1617static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
1618 struct sk_buff *skb)
1619{
1620 u32 src_ip_addr;
1621 u32 broadcast_ip_addr = 0;
1622 struct in_device *in_dev;
1623 fr_channel_t* chan = dev->priv;
1624
1625 /* read the IP source address from the outgoing packet */
1626 src_ip_addr = *(u32 *)(skb->data + 14);
1627
1628 /* read the IP broadcast address for the device */
1629 in_dev = dev->ip_ptr;
1630 if(in_dev != NULL) {
1631 struct in_ifaddr *ifa= in_dev->ifa_list;
1632 if(ifa != NULL)
1633 broadcast_ip_addr = ifa->ifa_broadcast;
1634 else
1635 return 0;
1636 }
1637
1638 /* check if the IP Source Address is a Broadcast address */
1639 if((dev->flags & IFF_BROADCAST) && (src_ip_addr == broadcast_ip_addr)) {
1640 printk(KERN_INFO
1641 "%s: Broadcast Source Address silently discarded\n",
1642 card->devname);
1643 return 1;
1644 }
1645
1646 /* check if the IP Source Address is a Multicast address */
1647 if((chan->mc == WANOPT_NO) && (ntohl(src_ip_addr) >= 0xE0000001) &&
1648 (ntohl(src_ip_addr) <= 0xFFFFFFFE)) {
1649 printk(KERN_INFO
1650 "%s: Multicast Source Address silently discarded\n",
1651 card->devname);
1652 return 1;
1653 }
1654
1655 return 0;
1656}
1657
1658/*============================================================================
1659 * Reply to UDP Management system.
1660 * Return nothing.
1661 */
1662static int reply_udp( unsigned char *data, unsigned int mbox_len )
1663{
1664 unsigned short len, udp_length, temp, ip_length;
1665 unsigned long ip_temp;
1666 int even_bound = 0;
1667
1668
1669 fr_udp_pkt_t *fr_udp_pkt = (fr_udp_pkt_t *)data;
1670
1671 /* Set length of packet */
1672 len = //sizeof(fr_encap_hdr_t)+
1673 sizeof(ip_pkt_t)+
1674 sizeof(udp_pkt_t)+
1675 sizeof(wp_mgmt_t)+
1676 sizeof(cblock_t)+
1677 mbox_len;
1678
1679
1680 /* fill in UDP reply */
1681 fr_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
1682
1683 /* fill in UDP length */
1684 udp_length = sizeof(udp_pkt_t)+
1685 sizeof(wp_mgmt_t)+
1686 sizeof(cblock_t)+
1687 mbox_len;
1688
1689
1690 /* put it on an even boundary */
1691 if ( udp_length & 0x0001 ) {
1692 udp_length += 1;
1693 len += 1;
1694 even_bound = 1;
1695 }
1696
1697 temp = (udp_length<<8)|(udp_length>>8);
1698 fr_udp_pkt->udp_pkt.udp_length = temp;
1699
1700 /* swap UDP ports */
1701 temp = fr_udp_pkt->udp_pkt.udp_src_port;
1702 fr_udp_pkt->udp_pkt.udp_src_port =
1703 fr_udp_pkt->udp_pkt.udp_dst_port;
1704 fr_udp_pkt->udp_pkt.udp_dst_port = temp;
1705
1706
1707
1708 /* add UDP pseudo header */
1709 temp = 0x1100;
1710 *((unsigned short *)
1711 (fr_udp_pkt->data+mbox_len+even_bound)) = temp;
1712 temp = (udp_length<<8)|(udp_length>>8);
1713 *((unsigned short *)
1714 (fr_udp_pkt->data+mbox_len+even_bound+2)) = temp;
1715
1716 /* calculate UDP checksum */
1717 fr_udp_pkt->udp_pkt.udp_checksum = 0;
1718
1719 fr_udp_pkt->udp_pkt.udp_checksum =
1720 calc_checksum(&data[UDP_OFFSET/*+sizeof(fr_encap_hdr_t)*/],
1721 udp_length+UDP_OFFSET);
1722
1723 /* fill in IP length */
1724 ip_length = udp_length + sizeof(ip_pkt_t);
1725 temp = (ip_length<<8)|(ip_length>>8);
1726 fr_udp_pkt->ip_pkt.total_length = temp;
1727
1728 /* swap IP addresses */
1729 ip_temp = fr_udp_pkt->ip_pkt.ip_src_address;
1730 fr_udp_pkt->ip_pkt.ip_src_address =
1731 fr_udp_pkt->ip_pkt.ip_dst_address;
1732 fr_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
1733
1734
1735 /* fill in IP checksum */
1736 fr_udp_pkt->ip_pkt.hdr_checksum = 0;
1737 fr_udp_pkt->ip_pkt.hdr_checksum =
1738 calc_checksum(&data[/*sizeof(fr_encap_hdr_t)*/0],
1739 sizeof(ip_pkt_t));
1740
1741 return len;
1742} /* reply_udp */
1743
1744unsigned short calc_checksum (char *data, int len)
1745{
1746 unsigned short temp;
1747 unsigned long sum=0;
1748 int i;
1749
1750 for( i = 0; i <len; i+=2 ) {
1751 memcpy(&temp,&data[i],2);
1752 sum += (unsigned long)temp;
1753 }
1754
1755 while (sum >> 16 ) {
1756 sum = (sum & 0xffffUL) + (sum >> 16);
1757 }
1758
1759 temp = (unsigned short)sum;
1760 temp = ~temp;
1761
1762 if( temp == 0 )
1763 temp = 0xffff;
1764
1765 return temp;
1766}
1767
1768/*
1769 If incoming is 0 (outgoing)- if the net numbers is ours make it 0
1770 if incoming is 1 - if the net number is 0 make it ours
1771
1772*/
1773static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming)
1774{
1775 unsigned long pnetwork_number;
1776
1777 pnetwork_number = (unsigned long)((sendpacket[14] << 24) +
1778 (sendpacket[15] << 16) + (sendpacket[16] << 8) +
1779 sendpacket[17]);
1780
1781 if (!incoming) {
1782 /* If the destination network number is ours, make it 0 */
1783 if( pnetwork_number == network_number) {
1784 sendpacket[14] = sendpacket[15] = sendpacket[16] =
1785 sendpacket[17] = 0x00;
1786 }
1787 } else {
1788 /* If the incoming network is 0, make it ours */
1789 if( pnetwork_number == 0) {
1790 sendpacket[14] = (unsigned char)(network_number >> 24);
1791 sendpacket[15] = (unsigned char)((network_number &
1792 0x00FF0000) >> 16);
1793 sendpacket[16] = (unsigned char)((network_number &
1794 0x0000FF00) >> 8);
1795 sendpacket[17] = (unsigned char)(network_number &
1796 0x000000FF);
1797 }
1798 }
1799
1800
1801 pnetwork_number = (unsigned long)((sendpacket[26] << 24) +
1802 (sendpacket[27] << 16) + (sendpacket[28] << 8) +
1803 sendpacket[29]);
1804
1805 if( !incoming ) {
1806 /* If the source network is ours, make it 0 */
1807 if( pnetwork_number == network_number) {
1808 sendpacket[26] = sendpacket[27] = sendpacket[28] =
1809 sendpacket[29] = 0x00;
1810 }
1811 } else {
1812 /* If the source network is 0, make it ours */
1813 if( pnetwork_number == 0 ) {
1814 sendpacket[26] = (unsigned char)(network_number >> 24);
1815 sendpacket[27] = (unsigned char)((network_number &
1816 0x00FF0000) >> 16);
1817 sendpacket[28] = (unsigned char)((network_number &
1818 0x0000FF00) >> 8);
1819 sendpacket[29] = (unsigned char)(network_number &
1820 0x000000FF);
1821 }
1822 }
1823} /* switch_net_numbers */
1824
1825/*============================================================================
1826 * Get ethernet-style interface statistics.
1827 * Return a pointer to struct enet_statistics.
1828 */
1829static struct net_device_stats *if_stats(struct net_device *dev)
1830{
1831 fr_channel_t* chan = dev->priv;
1832
1833 if(chan == NULL)
1834 return NULL;
1835
1836 return &chan->ifstats;
1837}
1838
1839/****** Interrupt Handlers **************************************************/
1840
1841/*============================================================================
1842 * fr_isr: S508 frame relay interrupt service routine.
1843 *
1844 * Description:
1845 * Frame relay main interrupt service route. This
1846 * function check the interrupt type and takes
1847 * the appropriate action.
1848 */
1849static void fr_isr (sdla_t* card)
1850{
1851 fr508_flags_t* flags = card->flags;
1852 char *ptr = &flags->iflag;
1853 int i,err;
1854 fr_mbox_t* mbox = card->mbox;
1855
1856 /* This flag prevents nesting of interrupts. See sdla_isr() routine
1857 * in sdlamain.c. */
1858 card->in_isr = 1;
1859
1860 ++card->statistics.isr_entry;
1861
1862
1863 /* All peripheral (configuraiton, re-configuration) events
1864 * take presidence over the ISR. Thus, retrigger */
1865 if (test_bit(PERI_CRIT, (void*)&card->wandev.critical)) {
1866 ++card->statistics.isr_already_critical;
1867 goto fr_isr_exit;
1868 }
1869
1870 if(card->hw.type != SDLA_S514) {
1871 if (test_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
1872 printk(KERN_INFO "%s: Critical while in ISR: If Send Running!\n",
1873 card->devname);
1874 ++card->statistics.isr_already_critical;
1875 goto fr_isr_exit;
1876 }
1877 }
1878
1879 switch (flags->iflag) {
1880
1881 case FR_INTR_RXRDY: /* receive interrupt */
1882 ++card->statistics.isr_rx;
1883 rx_intr(card);
1884 break;
1885
1886
1887 case FR_INTR_TXRDY: /* transmit interrupt */
1888 ++ card->statistics.isr_tx;
1889 tx_intr(card);
1890 break;
1891
1892 case FR_INTR_READY:
1893 Intr_test_counter++;
1894 ++card->statistics.isr_intr_test;
1895 break;
1896
1897 case FR_INTR_DLC: /* Event interrupt occurred */
1898 mbox->cmd.command = FR_READ_STATUS;
1899 mbox->cmd.length = 0;
1900 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
1901 if (err)
1902 fr_event(card, err, mbox);
1903 break;
1904
1905 case FR_INTR_TIMER: /* Timer interrupt */
1906 timer_intr(card);
1907 break;
1908
1909 default:
1910 ++card->statistics.isr_spurious;
1911 spur_intr(card);
1912 printk(KERN_INFO "%s: Interrupt Type 0x%02X!\n",
1913 card->devname, flags->iflag);
1914
1915 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1916 for(i = 0; i < 8; i ++)
1917 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1918 printk(KERN_INFO "\n");
1919
1920 break;
1921 }
1922
1923fr_isr_exit:
1924
1925 card->in_isr = 0;
1926 flags->iflag = 0;
1927 return;
1928}
1929
1930
1931
1932/*===========================================================
1933 * rx_intr Receive interrupt handler.
1934 *
1935 * Description
1936 * Upon receiveing an interrupt:
1937 * 1. Check that the firmware is in sync with
1938 * the driver.
1939 * 2. Find an appropriate network interface
1940 * based on the received dlci number.
1941 * 3. Check that the netowrk interface exists
1942 * and that it's setup properly.
1943 * 4. Copy the data into an skb buffer.
1944 * 5. Check the packet type and take
1945 * appropriate acton: UPD, API, ARP or Data.
1946 */
1947
1948static void rx_intr (sdla_t* card)
1949{
1950 fr_rx_buf_ctl_t* frbuf = card->rxmb;
1951 fr508_flags_t* flags = card->flags;
1952 fr_channel_t* chan;
1953 char *ptr = &flags->iflag;
1954 struct sk_buff* skb;
1955 struct net_device* dev;
1956 void* buf;
1957 unsigned dlci, len, offs, len_incl_hdr;
1958 int i, udp_type;
1959
1960
1961 /* Check that firmware buffers are in sync */
1962 if (frbuf->flag != 0x01) {
1963
1964 printk(KERN_INFO
1965 "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
1966 card->devname, (unsigned)frbuf, frbuf->flag);
1967
1968 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1969 for(i = 0; i < 8; i ++)
1970 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1971 printk(KERN_INFO "\n");
1972
1973 ++card->statistics.rx_intr_corrupt_rx_bfr;
1974
1975 /* Bug Fix: Mar 6 2000
1976 * If we get a corrupted mailbox, it means that driver
1977 * is out of sync with the firmware. There is no recovery.
1978 * If we don't turn off all interrupts for this card
1979 * the machine will crash.
1980 */
1981 printk(KERN_INFO "%s: Critical router failure ...!!!\n", card->devname);
1982 printk(KERN_INFO "Please contact Sangoma Technologies !\n");
1983 fr_set_intr_mode(card, 0, 0, 0);
1984 return;
1985 }
1986
1987 len = frbuf->length;
1988 dlci = frbuf->dlci;
1989 offs = frbuf->offset;
1990
1991 /* Find the network interface for this packet */
1992 dev = find_channel(card, dlci);
1993
1994
1995 /* Check that the network interface is active and
1996 * properly setup */
1997 if (dev == NULL) {
1998 if( net_ratelimit()) {
1999 printk(KERN_INFO "%s: received data on unconfigured DLCI %d!\n",
2000 card->devname, dlci);
2001 }
2002 ++card->statistics.rx_intr_on_orphaned_DLCI;
2003 ++card->wandev.stats.rx_dropped;
2004 goto rx_done;
2005 }
2006
2007 if ((chan = dev->priv) == NULL){
2008 if( net_ratelimit()) {
2009 printk(KERN_INFO "%s: received data on unconfigured DLCI %d!\n",
2010 card->devname, dlci);
2011 }
2012 ++card->statistics.rx_intr_on_orphaned_DLCI;
2013 ++card->wandev.stats.rx_dropped;
2014 goto rx_done;
2015 }
2016
2017 skb = dev_alloc_skb(len);
2018
2019 if (!netif_running(dev) || (skb == NULL)){
2020
2021 ++chan->ifstats.rx_dropped;
2022
2023 if(skb == NULL) {
2024 if (net_ratelimit()) {
2025 printk(KERN_INFO
2026 "%s: no socket buffers available!\n",
2027 card->devname);
2028 }
2029 chan->drvstats_rx_intr.rx_intr_no_socket ++;
2030 }
2031
2032 if (!netif_running(dev)){
2033 chan->drvstats_rx_intr.
2034 rx_intr_dev_not_started ++;
2035 if (skb){
2036 dev_kfree_skb_any(skb);
2037 }
2038 }
2039 goto rx_done;
2040 }
2041
2042 /* Copy data from the board into the socket buffer */
2043 if ((offs + len) > card->u.f.rx_top + 1) {
2044 unsigned tmp = card->u.f.rx_top - offs + 1;
2045
2046 buf = skb_put(skb, tmp);
2047 sdla_peek(&card->hw, offs, buf, tmp);
2048 offs = card->u.f.rx_base;
2049 len -= tmp;
2050 }
2051
2052 buf = skb_put(skb, len);
2053 sdla_peek(&card->hw, offs, buf, len);
2054
2055
2056 /* We got the packet from the bard.
2057 * Check the packet type and take appropriate action */
2058
2059 udp_type = udp_pkt_type( skb, card );
2060
2061 if(udp_type != UDP_INVALID_TYPE) {
2062
2063 /* UDP Debug packet received, store the
2064 * packet and handle it in timer interrupt */
2065
2066 skb_pull(skb, 1);
2067 if (wanrouter_type_trans(skb, dev)){
2068 if(store_udp_mgmt_pkt(udp_type,UDP_PKT_FRM_NETWORK,card,skb,dlci)){
2069
2070 flags->imask |= FR_INTR_TIMER;
2071
2072 if (udp_type == UDP_FPIPE_TYPE){
2073 ++chan->drvstats_rx_intr.rx_intr_PIPE_request;
2074 }
2075 }
2076 }
2077
2078 }else if (chan->common.usedby == API) {
2079
2080 /* We are in API mode.
2081 * Add an API header to the RAW packet
2082 * and queue it into a circular buffer.
2083 * Then kick the fr_bh() bottom half handler */
2084
2085 api_rx_hdr_t* api_rx_hdr;
2086 chan->drvstats_rx_intr.rx_intr_bfr_passed_to_stack ++;
2087 chan->ifstats.rx_packets ++;
2088 card->wandev.stats.rx_packets ++;
2089
2090 chan->ifstats.rx_bytes += skb->len;
2091 card->wandev.stats.rx_bytes += skb->len;
2092
2093 skb_push(skb, sizeof(api_rx_hdr_t));
2094 api_rx_hdr = (api_rx_hdr_t*)&skb->data[0x00];
2095 api_rx_hdr->attr = frbuf->attr;
2096 api_rx_hdr->time_stamp = frbuf->tmstamp;
2097
2098 skb->protocol = htons(ETH_P_IP);
2099 skb->mac.raw = skb->data;
2100 skb->dev = dev;
2101 skb->pkt_type = WAN_PACKET_DATA;
2102
2103 bh_enqueue(dev, skb);
2104
2105 trigger_fr_bh(chan);
2106
2107 }else if (handle_IPXWAN(skb->data,chan->name,chan->enable_IPX, chan->network_number)){
2108
2109 //FIXME: Frame Relay IPX is not supported, Yet !
2110 //if (chan->enable_IPX) {
2111 // fr_send(card, dlci, 0, skb->len,skb->data);
2112 //}
2113 dev_kfree_skb_any(skb);
2114
2115 } else if (is_arp(skb->data)) {
2116
2117 /* ARP support enabled Mar 16 2000
2118 * Process incoming ARP reply/request, setup
2119 * dynamic routes. */
2120
2121 if (process_ARP((arphdr_1490_t *)skb->data, card, dev)) {
2122 if (net_ratelimit()){
2123 printk (KERN_INFO
2124 "%s: Error processing ARP Packet.\n",
2125 card->devname);
2126 }
2127 }
2128 dev_kfree_skb_any(skb);
2129
2130 } else if (skb->data[0] != 0x03) {
2131
2132 if (net_ratelimit()) {
2133 printk(KERN_INFO "%s: Non IETF packet discarded.\n",
2134 card->devname);
2135 }
2136 dev_kfree_skb_any(skb);
2137
2138 } else {
2139
2140 len_incl_hdr = skb->len;
2141 /* Decapsulate packet and pass it up the
2142 protocol stack */
2143 skb->dev = dev;
2144
2145 if (chan->common.usedby == BRIDGE || chan->common.usedby == BRIDGE_NODE){
2146
2147 /* Make sure it's an Ethernet frame, otherwise drop it */
2148 if (!memcmp(skb->data, "\x03\x00\x80\x00\x80\xC2\x00\x07", 8)) {
2149 skb_pull(skb, 8);
2150 skb->protocol=eth_type_trans(skb,dev);
2151 }else{
2152 ++chan->drvstats_rx_intr.rx_intr_bfr_not_passed_to_stack;
2153 ++chan->ifstats.rx_errors;
2154 ++card->wandev.stats.rx_errors;
2155 goto rx_done;
2156 }
2157 }else{
2158
2159 /* remove hardware header */
2160 buf = skb_pull(skb, 1);
2161
2162 if (!wanrouter_type_trans(skb, dev)) {
2163
2164 /* can't decapsulate packet */
2165 dev_kfree_skb_any(skb);
2166
2167 ++chan->drvstats_rx_intr.rx_intr_bfr_not_passed_to_stack;
2168 ++chan->ifstats.rx_errors;
2169 ++card->wandev.stats.rx_errors;
2170 goto rx_done;
2171 }
2172 skb->mac.raw = skb->data;
2173 }
2174
2175
2176 /* Send a packet up the IP stack */
2177 skb->dev->last_rx = jiffies;
2178 netif_rx(skb);
2179 ++chan->drvstats_rx_intr.rx_intr_bfr_passed_to_stack;
2180 ++chan->ifstats.rx_packets;
2181 ++card->wandev.stats.rx_packets;
2182
2183 chan->ifstats.rx_bytes += len_incl_hdr;
2184 card->wandev.stats.rx_bytes += len_incl_hdr;
2185 }
2186
2187rx_done:
2188
2189 /* Release buffer element and calculate a pointer to the next one */
2190 frbuf->flag = 0;
2191 card->rxmb = ++frbuf;
2192 if ((void*)frbuf > card->u.f.rxmb_last)
2193 card->rxmb = card->u.f.rxmb_base;
2194
2195}
2196
2197/*==================================================================
2198 * tx_intr: Transmit interrupt handler.
2199 *
2200 * Rationale:
2201 * If the board is busy transmitting, if_send() will
2202 * buffers a single packet and turn on
2203 * the tx interrupt. Tx interrupt will be called
2204 * by the board, once the firmware can send more
2205 * data. Thus, no polling is required.
2206 *
2207 * Description:
2208 * Tx interrupt is called for each
2209 * configured dlci channel. Thus:
2210 * 1. Obtain the netowrk interface based on the
2211 * dlci number.
2212 * 2. Check that network interface is up and
2213 * properly setup.
2214 * 3. Check for a buffered packet.
2215 * 4. Transmit the packet.
2216 * 5. If we are in WANPIPE mode, mark the
2217 * NET_BH handler.
2218 * 6. If we are in API mode, kick
2219 * the AF_WANPIPE socket for more data.
2220 *
2221 */
2222static void tx_intr(sdla_t *card)
2223{
2224 fr508_flags_t* flags = card->flags;
2225 fr_tx_buf_ctl_t* bctl;
2226 struct net_device* dev;
2227 fr_channel_t* chan;
2228
2229 if(card->hw.type == SDLA_S514){
2230 bctl = (void*)(flags->tse_offs + card->hw.dpmbase);
2231 }else{
2232 bctl = (void*)(flags->tse_offs - FR_MB_VECTOR +
2233 card->hw.dpmbase);
2234 }
2235
2236 /* Find the structure and make it unbusy */
2237 dev = find_channel(card, flags->dlci);
2238 if (dev == NULL){
2239 printk(KERN_INFO "NO DEV IN TX Interrupt\n");
2240 goto end_of_tx_intr;
2241 }
2242
2243 if ((chan = dev->priv) == NULL){
2244 printk(KERN_INFO "NO CHAN IN TX Interrupt\n");
2245 goto end_of_tx_intr;
2246 }
2247
2248 if(!chan->transmit_length || !chan->delay_skb) {
2249 printk(KERN_INFO "%s: tx int error - transmit length zero\n",
2250 card->wandev.name);
2251 goto end_of_tx_intr;
2252 }
2253
2254 /* If the 'if_send()' procedure is currently checking the 'tbusy'
2255 status, then we cannot transmit. Instead, we configure the microcode
2256 so as to re-issue this transmit interrupt at a later stage.
2257 */
2258 if (test_bit(SEND_TXIRQ_CRIT, (void*)&card->wandev.critical)) {
2259
2260 fr_dlci_interface_t* dlci_interface = chan->dlci_int_interface;
2261 bctl->flag = 0xA0;
2262 dlci_interface->gen_interrupt |= FR_INTR_TXRDY;
2263 return;
2264
2265 }else{
2266 bctl->dlci = flags->dlci;
2267 bctl->length = chan->transmit_length+chan->fr_header_len;
2268 sdla_poke(&card->hw,
2269 fr_send_hdr(card,bctl->dlci,bctl->offset),
2270 chan->delay_skb->data,
2271 chan->delay_skb->len);
2272 bctl->flag = 0xC0;
2273
2274 ++chan->ifstats.tx_packets;
2275 ++card->wandev.stats.tx_packets;
2276 chan->ifstats.tx_bytes += chan->transmit_length;
2277 card->wandev.stats.tx_bytes += chan->transmit_length;
2278
2279 /* We must free an sk buffer, which we used
2280 * for delayed transmission; Otherwise, the sock
2281 * will run out of memory */
2282 dev_kfree_skb_any(chan->delay_skb);
2283
2284 chan->delay_skb = NULL;
2285 chan->transmit_length = 0;
2286
2287 dev->trans_start = jiffies;
2288
2289 if (netif_queue_stopped(dev)){
2290 /* If using API, than wakeup socket BH handler */
2291 if (chan->common.usedby == API){
2292 netif_start_queue(dev);
2293 wakeup_sk_bh(dev);
2294 }else{
2295 netif_wake_queue(dev);
2296 }
2297 }
2298 }
2299
2300end_of_tx_intr:
2301
2302 /* if any other interfaces have transmit interrupts pending,
2303 * do not disable the global transmit interrupt */
2304 if(!(-- card->u.f.tx_interrupts_pending))
2305 flags->imask &= ~FR_INTR_TXRDY;
2306
2307
2308}
2309
2310
2311/*============================================================================
2312 * timer_intr: Timer interrupt handler.
2313 *
2314 * Rationale:
2315 * All commans must be executed within the timer
2316 * interrupt since no two commands should execute
2317 * at the same time.
2318 *
2319 * Description:
2320 * The timer interrupt is used to:
2321 * 1. Processing udp calls from 'fpipemon'.
2322 * 2. Processing update calls from /proc file system
2323 * 3. Reading board-level statistics for
2324 * updating the proc file system.
2325 * 4. Sending inverse ARP request packets.
2326 * 5. Configure a dlci/channel.
2327 * 6. Unconfigure a dlci/channel. (Node only)
2328 */
2329
2330static void timer_intr(sdla_t *card)
2331{
2332 fr508_flags_t* flags = card->flags;
2333
2334 /* UDP Debuging: fpipemon call */
2335 if (card->u.f.timer_int_enabled & TMR_INT_ENABLED_UDP) {
2336 if(card->u.f.udp_type == UDP_FPIPE_TYPE) {
2337 if(process_udp_mgmt_pkt(card)) {
2338 card->u.f.timer_int_enabled &=
2339 ~TMR_INT_ENABLED_UDP;
2340 }
2341 }
2342 }
2343
2344 /* /proc update call : triggered from update() */
2345 if (card->u.f.timer_int_enabled & TMR_INT_ENABLED_UPDATE) {
2346 fr_get_err_stats(card);
2347 fr_get_stats(card);
2348 card->u.f.update_comms_stats = 0;
2349 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE;
2350 }
2351
2352 /* Update the channel state call. This is call is
2353 * triggered by if_send() function */
2354 if (card->u.f.timer_int_enabled & TMR_INT_ENABLED_UPDATE_STATE){
2355 struct net_device *dev;
2356 if (card->wandev.state == WAN_CONNECTED){
2357 for (dev = card->wandev.dev; dev;
2358 dev = *((struct net_device **)dev->priv)){
2359 fr_channel_t *chan = dev->priv;
2360 if (chan->common.state != WAN_CONNECTED){
2361 update_chan_state(dev);
2362 }
2363 }
2364 }
2365 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE_STATE;
2366 }
2367
2368 /* configure a dlci/channel */
2369 if (card->u.f.timer_int_enabled & TMR_INT_ENABLED_CONFIG){
2370 config_fr(card);
2371 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_CONFIG;
2372 }
2373
2374 /* unconfigure a dlci/channel */
2375 if (card->u.f.timer_int_enabled & TMR_INT_ENABLED_UNCONFIG){
2376 unconfig_fr(card);
2377 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_UNCONFIG;
2378 }
2379
2380
2381 /* Transmit ARP packets */
2382 if (card->u.f.timer_int_enabled & TMR_INT_ENABLED_ARP){
2383 int i=0;
2384 struct net_device *dev;
2385
2386 if (card->u.f.arp_dev == NULL)
2387 card->u.f.arp_dev = card->wandev.dev;
2388
2389 dev = card->u.f.arp_dev;
2390
2391 for (;;){
2392
2393 fr_channel_t *chan = dev->priv;
2394
2395 /* If the interface is brought down cancel sending In-ARPs */
2396 if (!(dev->flags&IFF_UP)){
2397 clear_bit(0,&chan->inarp_ready);
2398 }
2399
2400 if (test_bit(0,&chan->inarp_ready)){
2401
2402 if (check_tx_status(card,dev)){
2403 set_bit(ARP_CRIT,&card->wandev.critical);
2404 break;
2405 }
2406
2407 if (!send_inarp_request(card,dev)){
2408 trigger_fr_arp(dev);
2409 chan->inarp_tick = jiffies;
2410 }
2411
2412 clear_bit(0,&chan->inarp_ready);
2413 dev = move_dev_to_next(card,dev);
2414 break;
2415 }
2416 dev = move_dev_to_next(card,dev);
2417
2418 if (++i == card->wandev.new_if_cnt){
2419 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_ARP;
2420 break;
2421 }
2422 }
2423 card->u.f.arp_dev = dev;
2424 }
2425
2426 if(!card->u.f.timer_int_enabled)
2427 flags->imask &= ~FR_INTR_TIMER;
2428}
2429
2430
2431/*============================================================================
2432 * spur_intr: Spurious interrupt handler.
2433 *
2434 * Description:
2435 * We don't know this interrupt.
2436 * Print a warning.
2437 */
2438
2439static void spur_intr (sdla_t* card)
2440{
2441 if (net_ratelimit()){
2442 printk(KERN_INFO "%s: spurious interrupt!\n", card->devname);
2443 }
2444}
2445
2446
2447//FIXME: Fix the IPX in next version
2448/*===========================================================================
2449 * Return 0 for non-IPXWAN packet
2450 * 1 for IPXWAN packet or IPX is not enabled!
2451 * FIXME: Use a IPX structure here not offsets
2452 */
2453static int handle_IPXWAN(unsigned char *sendpacket,
2454 char *devname, unsigned char enable_IPX,
2455 unsigned long network_number)
2456{
2457 int i;
2458
2459 if( sendpacket[1] == 0x00 && sendpacket[2] == 0x80 &&
2460 sendpacket[6] == 0x81 && sendpacket[7] == 0x37) {
2461
2462 /* It's an IPX packet */
2463 if (!enable_IPX){
2464 /* Return 1 so we don't pass it up the stack. */
2465 //FIXME: Take this out when IPX is fixed
2466 if (net_ratelimit()){
2467 printk (KERN_INFO
2468 "%s: WARNING: Unsupported IPX packet received and dropped\n",
2469 devname);
2470 }
2471 return 1;
2472 }
2473 } else {
2474 /* It's not IPX so return and pass it up the stack. */
2475 return 0;
2476 }
2477
2478 if( sendpacket[24] == 0x90 && sendpacket[25] == 0x04){
2479 /* It's IPXWAN */
2480
2481 if( sendpacket[10] == 0x02 && sendpacket[42] == 0x00){
2482
2483 /* It's a timer request packet */
2484 printk(KERN_INFO "%s: Received IPXWAN Timer Request packet\n",
2485 devname);
2486
2487 /* Go through the routing options and answer no to every
2488 * option except Unnumbered RIP/SAP
2489 */
2490 for(i = 49; sendpacket[i] == 0x00; i += 5){
2491 /* 0x02 is the option for Unnumbered RIP/SAP */
2492 if( sendpacket[i + 4] != 0x02){
2493 sendpacket[i + 1] = 0;
2494 }
2495 }
2496
2497 /* Skip over the extended Node ID option */
2498 if( sendpacket[i] == 0x04 ){
2499 i += 8;
2500 }
2501
2502 /* We also want to turn off all header compression opt.
2503 */
2504 for(; sendpacket[i] == 0x80 ;){
2505 sendpacket[i + 1] = 0;
2506 i += (sendpacket[i + 2] << 8) + (sendpacket[i + 3]) + 4;
2507 }
2508
2509 /* Set the packet type to timer response */
2510 sendpacket[42] = 0x01;
2511
2512 printk(KERN_INFO "%s: Sending IPXWAN Timer Response\n",
2513 devname);
2514
2515 } else if( sendpacket[42] == 0x02 ){
2516
2517 /* This is an information request packet */
2518 printk(KERN_INFO
2519 "%s: Received IPXWAN Information Request packet\n",
2520 devname);
2521
2522 /* Set the packet type to information response */
2523 sendpacket[42] = 0x03;
2524
2525 /* Set the router name */
2526 sendpacket[59] = 'F';
2527 sendpacket[60] = 'P';
2528 sendpacket[61] = 'I';
2529 sendpacket[62] = 'P';
2530 sendpacket[63] = 'E';
2531 sendpacket[64] = '-';
2532 sendpacket[65] = CVHexToAscii(network_number >> 28);
2533 sendpacket[66] = CVHexToAscii((network_number & 0x0F000000)>> 24);
2534 sendpacket[67] = CVHexToAscii((network_number & 0x00F00000)>> 20);
2535 sendpacket[68] = CVHexToAscii((network_number & 0x000F0000)>> 16);
2536 sendpacket[69] = CVHexToAscii((network_number & 0x0000F000)>> 12);
2537 sendpacket[70] = CVHexToAscii((network_number & 0x00000F00)>> 8);
2538 sendpacket[71] = CVHexToAscii((network_number & 0x000000F0)>> 4);
2539 sendpacket[72] = CVHexToAscii(network_number & 0x0000000F);
2540 for(i = 73; i < 107; i+= 1)
2541 {
2542 sendpacket[i] = 0;
2543 }
2544
2545 printk(KERN_INFO "%s: Sending IPXWAN Information Response packet\n",
2546 devname);
2547 } else {
2548
2549 printk(KERN_INFO "%s: Unknown IPXWAN packet!\n",devname);
2550 return 0;
2551 }
2552
2553 /* Set the WNodeID to our network address */
2554 sendpacket[43] = (unsigned char)(network_number >> 24);
2555 sendpacket[44] = (unsigned char)((network_number & 0x00FF0000) >> 16);
2556 sendpacket[45] = (unsigned char)((network_number & 0x0000FF00) >> 8);
2557 sendpacket[46] = (unsigned char)(network_number & 0x000000FF);
2558
2559 return 1;
2560 }
2561
2562 /* If we get here, it's an IPX-data packet so it'll get passed up the
2563 * stack.
2564 * switch the network numbers
2565 */
2566 switch_net_numbers(sendpacket, network_number ,1);
2567 return 0;
2568}
2569/*============================================================================
2570 * process_route
2571 *
2572 * Rationale:
2573 * If the interface goes down, or we receive an ARP request,
2574 * we have to change the network interface ip addresses.
2575 * This cannot be done within the interrupt.
2576 *
2577 * Description:
2578 *
2579 * This routine is called as a polling routine to dynamically
2580 * add/delete routes negotiated by inverse ARP. It is in this
2581 * "task" because we don't want routes to be added while in
2582 * interrupt context.
2583 *
2584 * Usage:
2585 * This function is called by fr_poll() polling funtion.
2586 */
2587
2588static void process_route(struct net_device *dev)
2589{
2590 fr_channel_t *chan = dev->priv;
2591 sdla_t *card = chan->card;
2592
2593 struct ifreq if_info;
2594 struct sockaddr_in *if_data;
2595 mm_segment_t fs = get_fs();
2596 u32 ip_tmp;
2597 int err;
2598
2599
2600 switch(chan->route_flag){
2601
2602 case ADD_ROUTE:
2603
2604 /* Set remote addresses */
2605 memset(&if_info, 0, sizeof(if_info));
2606 strcpy(if_info.ifr_name, dev->name);
2607
2608 set_fs(get_ds()); /* get user space block */
2609
2610 if_data = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2611 if_data->sin_addr.s_addr = chan->ip_remote;
2612 if_data->sin_family = AF_INET;
2613 err = devinet_ioctl( SIOCSIFDSTADDR, &if_info );
2614
2615 set_fs(fs); /* restore old block */
2616
2617 if (err) {
2618 printk(KERN_INFO
2619 "%s: Route Add failed. Error: %d\n",
2620 card->devname,err);
2621 printk(KERN_INFO "%s: Address: %u.%u.%u.%u\n",
2622 chan->name, NIPQUAD(chan->ip_remote));
2623
2624 }else {
2625 printk(KERN_INFO "%s: Route Added Successfully: %u.%u.%u.%u\n",
2626 card->devname,NIPQUAD(chan->ip_remote));
2627 chan->route_flag = ROUTE_ADDED;
2628 }
2629 break;
2630
2631 case REMOVE_ROUTE:
2632
2633 /* Set remote addresses */
2634 memset(&if_info, 0, sizeof(if_info));
2635 strcpy(if_info.ifr_name, dev->name);
2636
2637 ip_tmp = get_ip_address(dev,WAN_POINTOPOINT_IP);
2638
2639 set_fs(get_ds()); /* get user space block */
2640
2641 if_data = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2642 if_data->sin_addr.s_addr = 0;
2643 if_data->sin_family = AF_INET;
2644 err = devinet_ioctl( SIOCSIFDSTADDR, &if_info );
2645
2646 set_fs(fs);
2647
2648 if (err) {
2649 printk(KERN_INFO
2650 "%s: Deleting of route failed. Error: %d\n",
2651 card->devname,err);
2652 printk(KERN_INFO "%s: Address: %u.%u.%u.%u\n",
2653 dev->name,NIPQUAD(chan->ip_remote) );
2654
2655 } else {
2656 printk(KERN_INFO "%s: Route Removed Sucessfuly: %u.%u.%u.%u\n",
2657 card->devname,NIPQUAD(ip_tmp));
2658 chan->route_flag = NO_ROUTE;
2659 }
2660 break;
2661
2662 } /* Case Statement */
2663
2664}
2665
2666
2667
2668/****** Frame Relay Firmware-Specific Functions *****************************/
2669
2670/*============================================================================
2671 * Read firmware code version.
2672 * o fill string str with firmware version info.
2673 */
2674static int fr_read_version (sdla_t* card, char* str)
2675{
2676 fr_mbox_t* mbox = card->mbox;
2677 int retry = MAX_CMD_RETRY;
2678 int err;
2679
2680 do
2681 {
2682 mbox->cmd.command = FR_READ_CODE_VERSION;
2683 mbox->cmd.length = 0;
2684 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2685 } while (err && retry-- && fr_event(card, err, mbox));
2686
2687 if (!err && str) {
2688 int len = mbox->cmd.length;
2689 memcpy(str, mbox->data, len);
2690 str[len] = '\0';
2691 }
2692 return err;
2693}
2694
2695/*============================================================================
2696 * Set global configuration.
2697 */
2698static int fr_configure (sdla_t* card, fr_conf_t *conf)
2699{
2700 fr_mbox_t* mbox = card->mbox;
2701 int retry = MAX_CMD_RETRY;
2702 int dlci_num = card->u.f.dlci_num;
2703 int err, i;
2704
2705 do
2706 {
2707 memcpy(mbox->data, conf, sizeof(fr_conf_t));
2708
2709 if (dlci_num) for (i = 0; i < dlci_num; ++i)
2710 ((fr_conf_t*)mbox->data)->dlci[i] =
2711 card->u.f.node_dlci[i];
2712
2713 mbox->cmd.command = FR_SET_CONFIG;
2714 mbox->cmd.length =
2715 sizeof(fr_conf_t) + dlci_num * sizeof(short);
2716
2717 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2718
2719 } while (err && retry-- && fr_event(card, err, mbox));
2720
2721 /*NC Oct 12 2000 */
2722 if (err != CMD_OK){
2723 printk(KERN_ERR "%s: Frame Relay Configuration Failed: rc=0x%x\n",
2724 card->devname,err);
2725 }
2726
2727 return err;
2728}
2729
2730/*============================================================================
2731 * Set DLCI configuration.
2732 */
2733static int fr_dlci_configure (sdla_t* card, fr_dlc_conf_t *conf, unsigned dlci)
2734{
2735 fr_mbox_t* mbox = card->mbox;
2736 int retry = MAX_CMD_RETRY;
2737 int err;
2738
2739 do
2740 {
2741 memcpy(mbox->data, conf, sizeof(fr_dlc_conf_t));
2742 mbox->cmd.dlci = (unsigned short) dlci;
2743 mbox->cmd.command = FR_SET_CONFIG;
2744 mbox->cmd.length = sizeof(fr_dlc_conf_t);
2745 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2746 } while (err && retry--);
2747
2748 return err;
2749}
2750/*============================================================================
2751 * Set interrupt mode.
2752 */
2753static int fr_set_intr_mode (sdla_t* card, unsigned mode, unsigned mtu,
2754 unsigned short timeout)
2755{
2756 fr_mbox_t* mbox = card->mbox;
2757 fr508_intr_ctl_t* ictl = (void*)mbox->data;
2758 int retry = MAX_CMD_RETRY;
2759 int err;
2760
2761 do
2762 {
2763 memset(ictl, 0, sizeof(fr508_intr_ctl_t));
2764 ictl->mode = mode;
2765 ictl->tx_len = mtu;
2766 ictl->irq = card->hw.irq;
2767
2768 /* indicate timeout on timer */
2769 if (mode & 0x20) ictl->timeout = timeout;
2770
2771 mbox->cmd.length = sizeof(fr508_intr_ctl_t);
2772 mbox->cmd.command = FR_SET_INTR_MODE;
2773 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2774
2775 } while (err && retry-- && fr_event(card, err, mbox));
2776
2777 return err;
2778}
2779
2780/*============================================================================
2781 * Enable communications.
2782 */
2783static int fr_comm_enable (sdla_t* card)
2784{
2785 fr_mbox_t* mbox = card->mbox;
2786 int retry = MAX_CMD_RETRY;
2787 int err;
2788
2789 do
2790 {
2791 mbox->cmd.command = FR_COMM_ENABLE;
2792 mbox->cmd.length = 0;
2793 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2794 } while (err && retry-- && fr_event(card, err, mbox));
2795
2796 return err;
2797}
2798
2799/*============================================================================
2800 * fr_comm_disable
2801 *
2802 * Warning: This functin is called by the shutdown() procedure. It is void
2803 * since dev->priv are has already been deallocated and no
2804 * error checking is possible using fr_event() function.
2805 */
2806static void fr_comm_disable (sdla_t* card)
2807{
2808 fr_mbox_t* mbox = card->mbox;
2809 int retry = MAX_CMD_RETRY;
2810 int err;
2811
2812 do {
2813 mbox->cmd.command = FR_SET_MODEM_STATUS;
2814 mbox->cmd.length = 1;
2815 mbox->data[0] = 0;
2816 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2817 } while (err && retry--);
2818
2819 retry = MAX_CMD_RETRY;
2820
2821 do
2822 {
2823 mbox->cmd.command = FR_COMM_DISABLE;
2824 mbox->cmd.length = 0;
2825 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2826 } while (err && retry--);
2827
2828 return;
2829}
2830
2831
2832
2833/*============================================================================
2834 * Get communications error statistics.
2835 */
2836static int fr_get_err_stats (sdla_t* card)
2837{
2838 fr_mbox_t* mbox = card->mbox;
2839 int retry = MAX_CMD_RETRY;
2840 int err;
2841
2842
2843 do
2844 {
2845 mbox->cmd.command = FR_READ_ERROR_STATS;
2846 mbox->cmd.length = 0;
2847 mbox->cmd.dlci = 0;
2848 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2849 } while (err && retry-- && fr_event(card, err, mbox));
2850
2851 if (!err) {
2852 fr_comm_stat_t* stats = (void*)mbox->data;
2853 card->wandev.stats.rx_over_errors = stats->rx_overruns;
2854 card->wandev.stats.rx_crc_errors = stats->rx_bad_crc;
2855 card->wandev.stats.rx_missed_errors = stats->rx_aborts;
2856 card->wandev.stats.rx_length_errors = stats->rx_too_long;
2857 card->wandev.stats.tx_aborted_errors = stats->tx_aborts;
2858
2859 }
2860
2861 return err;
2862}
2863
2864/*============================================================================
2865 * Get statistics.
2866 */
2867static int fr_get_stats (sdla_t* card)
2868{
2869 fr_mbox_t* mbox = card->mbox;
2870 int retry = MAX_CMD_RETRY;
2871 int err;
2872
2873
2874 do
2875 {
2876 mbox->cmd.command = FR_READ_STATISTICS;
2877 mbox->cmd.length = 0;
2878 mbox->cmd.dlci = 0;
2879 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2880 } while (err && retry-- && fr_event(card, err, mbox));
2881
2882 if (!err) {
2883 fr_link_stat_t* stats = (void*)mbox->data;
2884 card->wandev.stats.rx_frame_errors = stats->rx_bad_format;
2885 card->wandev.stats.rx_dropped =
2886 stats->rx_dropped + stats->rx_dropped2;
2887 }
2888
2889 return err;
2890}
2891
2892/*============================================================================
2893 * Add DLCI(s) (Access Node only!).
2894 * This routine will perform the ADD_DLCIs command for the specified DLCI.
2895 */
2896static int fr_add_dlci (sdla_t* card, int dlci)
2897{
2898 fr_mbox_t* mbox = card->mbox;
2899 int retry = MAX_CMD_RETRY;
2900 int err;
2901
2902 do
2903 {
2904 unsigned short* dlci_list = (void*)mbox->data;
2905
2906 mbox->cmd.length = sizeof(short);
2907 dlci_list[0] = dlci;
2908 mbox->cmd.command = FR_ADD_DLCI;
2909 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2910
2911 } while (err && retry-- && fr_event(card, err, mbox));
2912
2913 return err;
2914}
2915
2916/*============================================================================
2917 * Activate DLCI(s) (Access Node only!).
2918 * This routine will perform the ACTIVATE_DLCIs command with a DLCI number.
2919 */
2920static int fr_activate_dlci (sdla_t* card, int dlci)
2921{
2922 fr_mbox_t* mbox = card->mbox;
2923 int retry = MAX_CMD_RETRY;
2924 int err;
2925
2926 do
2927 {
2928 unsigned short* dlci_list = (void*)mbox->data;
2929
2930 mbox->cmd.length = sizeof(short);
2931 dlci_list[0] = dlci;
2932 mbox->cmd.command = FR_ACTIVATE_DLCI;
2933 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2934
2935 } while (err && retry-- && fr_event(card, err, mbox));
2936
2937 return err;
2938}
2939
2940/*============================================================================
2941 * Delete DLCI(s) (Access Node only!).
2942 * This routine will perform the DELETE_DLCIs command with a DLCI number.
2943 */
2944static int fr_delete_dlci (sdla_t* card, int dlci)
2945{
2946 fr_mbox_t* mbox = card->mbox;
2947 int retry = MAX_CMD_RETRY;
2948 int err;
2949
2950 do
2951 {
2952 unsigned short* dlci_list = (void*)mbox->data;
2953
2954 mbox->cmd.length = sizeof(short);
2955 dlci_list[0] = dlci;
2956 mbox->cmd.command = FR_DELETE_DLCI;
2957 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2958
2959 } while (err && retry-- && fr_event(card, err, mbox));
2960
2961 return err;
2962}
2963
2964
2965
2966/*============================================================================
2967 * Issue in-channel signalling frame.
2968 */
2969static int fr_issue_isf (sdla_t* card, int isf)
2970{
2971 fr_mbox_t* mbox = card->mbox;
2972 int retry = MAX_CMD_RETRY;
2973 int err;
2974
2975 do
2976 {
2977 mbox->data[0] = isf;
2978 mbox->cmd.length = 1;
2979 mbox->cmd.command = FR_ISSUE_IS_FRAME;
2980 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2981 } while (err && retry-- && fr_event(card, err, mbox));
2982
2983 return err;
2984}
2985
2986
2987static unsigned int fr_send_hdr (sdla_t*card, int dlci, unsigned int offset)
2988{
2989 struct net_device *dev = find_channel(card,dlci);
2990 fr_channel_t *chan;
2991
2992 if (!dev || !(chan=dev->priv))
2993 return offset;
2994
2995 if (chan->fr_header_len){
2996 sdla_poke(&card->hw, offset, chan->fr_header, chan->fr_header_len);
2997 }
2998
2999 return offset+chan->fr_header_len;
3000}
3001
3002/*============================================================================
3003 * Send a frame on a selected DLCI.
3004 */
3005static int fr_send_data_header (sdla_t* card, int dlci, unsigned char attr, int len,
3006 void *buf, unsigned char hdr_len)
3007{
3008 fr_mbox_t* mbox = card->mbox + 0x800;
3009 int retry = MAX_CMD_RETRY;
3010 int err;
3011
3012 do
3013 {
3014 mbox->cmd.dlci = dlci;
3015 mbox->cmd.attr = attr;
3016 mbox->cmd.length = len+hdr_len;
3017 mbox->cmd.command = FR_WRITE;
3018 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
3019 } while (err && retry-- && fr_event(card, err, mbox));
3020
3021 if (!err) {
3022 fr_tx_buf_ctl_t* frbuf;
3023
3024 if(card->hw.type == SDLA_S514)
3025 frbuf = (void*)(*(unsigned long*)mbox->data +
3026 card->hw.dpmbase);
3027 else
3028 frbuf = (void*)(*(unsigned long*)mbox->data -
3029 FR_MB_VECTOR + card->hw.dpmbase);
3030
3031 sdla_poke(&card->hw, fr_send_hdr(card,dlci,frbuf->offset), buf, len);
3032 frbuf->flag = 0x01;
3033 }
3034
3035 return err;
3036}
3037
3038static int fr_send (sdla_t* card, int dlci, unsigned char attr, int len,
3039 void *buf)
3040{
3041 fr_mbox_t* mbox = card->mbox + 0x800;
3042 int retry = MAX_CMD_RETRY;
3043 int err;
3044
3045 do
3046 {
3047 mbox->cmd.dlci = dlci;
3048 mbox->cmd.attr = attr;
3049 mbox->cmd.length = len;
3050 mbox->cmd.command = FR_WRITE;
3051 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
3052 } while (err && retry-- && fr_event(card, err, mbox));
3053
3054 if (!err) {
3055 fr_tx_buf_ctl_t* frbuf;
3056
3057 if(card->hw.type == SDLA_S514)
3058 frbuf = (void*)(*(unsigned long*)mbox->data +
3059 card->hw.dpmbase);
3060 else
3061 frbuf = (void*)(*(unsigned long*)mbox->data -
3062 FR_MB_VECTOR + card->hw.dpmbase);
3063
3064 sdla_poke(&card->hw, frbuf->offset, buf, len);
3065 frbuf->flag = 0x01;
3066 }
3067
3068 return err;
3069}
3070
3071
3072/****** Firmware Asynchronous Event Handlers ********************************/
3073
3074/*============================================================================
3075 * Main asyncronous event/error handler.
3076 * This routine is called whenever firmware command returns non-zero
3077 * return code.
3078 *
3079 * Return zero if previous command has to be cancelled.
3080 */
3081static int fr_event (sdla_t *card, int event, fr_mbox_t* mbox)
3082{
3083 fr508_flags_t* flags = card->flags;
3084 char *ptr = &flags->iflag;
3085 int i;
3086
3087 switch (event) {
3088
3089 case FRRES_MODEM_FAILURE:
3090 return fr_modem_failure(card, mbox);
3091
3092 case FRRES_CHANNEL_DOWN: {
3093 struct net_device *dev;
3094
3095 /* Remove all routes from associated DLCI's */
3096 for (dev = card->wandev.dev; dev;
3097 dev = *((struct net_device **)dev->priv)) {
3098 fr_channel_t *chan = dev->priv;
3099 if (chan->route_flag == ROUTE_ADDED) {
3100 chan->route_flag = REMOVE_ROUTE;
3101 }
3102
3103 if (chan->inarp == INARP_CONFIGURED) {
3104 chan->inarp = INARP_REQUEST;
3105 }
3106
3107 /* If the link becomes disconnected then,
3108 * all channels will be disconnected
3109 * as well.
3110 */
3111 set_chan_state(dev,WAN_DISCONNECTED);
3112 }
3113
3114 wanpipe_set_state(card, WAN_DISCONNECTED);
3115 return 1;
3116 }
3117
3118 case FRRES_CHANNEL_UP: {
3119 struct net_device *dev;
3120
3121 /* FIXME: Only startup devices that are on the list */
3122
3123 for (dev = card->wandev.dev; dev;
3124 dev = *((struct net_device **)dev->priv)) {
3125
3126 set_chan_state(dev,WAN_CONNECTED);
3127 }
3128
3129 wanpipe_set_state(card, WAN_CONNECTED);
3130 return 1;
3131 }
3132
3133 case FRRES_DLCI_CHANGE:
3134 return fr_dlci_change(card, mbox);
3135
3136 case FRRES_DLCI_MISMATCH:
3137 printk(KERN_INFO "%s: DLCI list mismatch!\n",
3138 card->devname);
3139 return 1;
3140
3141 case CMD_TIMEOUT:
3142 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
3143 card->devname, mbox->cmd.command);
3144 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
3145 for(i = 0; i < 8; i ++)
3146 printk(KERN_INFO "0x%02X ", *(ptr + 0x18 + i));
3147 printk(KERN_INFO "\n");
3148
3149 break;
3150
3151 case FRRES_DLCI_INACTIVE:
3152 break;
3153
3154 case FRRES_CIR_OVERFLOW:
3155 break;
3156
3157 case FRRES_BUFFER_OVERFLOW:
3158 break;
3159
3160 default:
3161 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n"
3162 , card->devname, mbox->cmd.command, event);
3163 }
3164
3165 return 0;
3166}
3167
3168/*============================================================================
3169 * Handle modem error.
3170 *
3171 * Return zero if previous command has to be cancelled.
3172 */
3173static int fr_modem_failure (sdla_t *card, fr_mbox_t* mbox)
3174{
3175 printk(KERN_INFO "%s: physical link down! (modem error 0x%02X)\n",
3176 card->devname, mbox->data[0]);
3177
3178 switch (mbox->cmd.command){
3179 case FR_WRITE:
3180
3181 case FR_READ:
3182 return 0;
3183 }
3184
3185 return 1;
3186}
3187
3188/*============================================================================
3189 * Handle DLCI status change.
3190 *
3191 * Return zero if previous command has to be cancelled.
3192 */
3193static int fr_dlci_change (sdla_t *card, fr_mbox_t* mbox)
3194{
3195 dlci_status_t* status = (void*)mbox->data;
3196 int cnt = mbox->cmd.length / sizeof(dlci_status_t);
3197 fr_channel_t *chan;
3198 struct net_device* dev2;
3199
3200
3201 for (; cnt; --cnt, ++status) {
3202
3203 unsigned short dlci= status->dlci;
3204 struct net_device* dev = find_channel(card, dlci);
3205
3206 if (dev == NULL){
3207 printk(KERN_INFO
3208 "%s: CPE contains unconfigured DLCI= %d\n",
3209 card->devname, dlci);
3210
3211 printk(KERN_INFO
3212 "%s: unconfigured DLCI %d reported by network\n"
3213 , card->devname, dlci);
3214
3215 }else{
3216 if (status->state == FR_LINK_INOPER) {
3217 printk(KERN_INFO
3218 "%s: DLCI %u is inactive!\n",
3219 card->devname, dlci);
3220
3221 if (dev && netif_running(dev))
3222 set_chan_state(dev, WAN_DISCONNECTED);
3223 }
3224
3225 if (status->state & FR_DLCI_DELETED) {
3226
3227 printk(KERN_INFO
3228 "%s: DLCI %u has been deleted!\n",
3229 card->devname, dlci);
3230
3231 if (dev && netif_running(dev)){
3232
3233 fr_channel_t *chan = dev->priv;
3234
3235 if (chan->route_flag == ROUTE_ADDED) {
3236 chan->route_flag = REMOVE_ROUTE;
3237 /* The state change will trigger
3238 * the fr polling routine */
3239 }
3240
3241 if (chan->inarp == INARP_CONFIGURED) {
3242 chan->inarp = INARP_REQUEST;
3243 }
3244
3245 set_chan_state(dev, WAN_DISCONNECTED);
3246 }
3247
3248 } else if (status->state & FR_DLCI_ACTIVE) {
3249
3250 chan = dev->priv;
3251
3252 /* This flag is used for configuring specific
3253 DLCI(s) when they become active.
3254 */
3255 chan->dlci_configured = DLCI_CONFIG_PENDING;
3256
3257 set_chan_state(dev, WAN_CONNECTED);
3258
3259 }
3260 }
3261 }
3262
3263 for (dev2 = card->wandev.dev; dev2;
3264 dev2 = *((struct net_device **)dev2->priv)){
3265
3266 chan = dev2->priv;
3267
3268 if (chan->dlci_configured == DLCI_CONFIG_PENDING) {
3269 if (fr_init_dlci(card, chan)){
3270 return 1;
3271 }
3272 }
3273
3274 }
3275 return 1;
3276}
3277
3278
3279static int fr_init_dlci (sdla_t *card, fr_channel_t *chan)
3280{
3281 fr_dlc_conf_t cfg;
3282
3283 memset(&cfg, 0, sizeof(cfg));
3284
3285 if ( chan->cir_status == CIR_DISABLED) {
3286
3287 cfg.cir_fwd = cfg.cir_bwd = 16;
3288 cfg.bc_fwd = cfg.bc_bwd = 16;
3289 cfg.conf_flags = 0x0001;
3290
3291 }else if (chan->cir_status == CIR_ENABLED) {
3292
3293 cfg.cir_fwd = cfg.cir_bwd = chan->cir;
3294 cfg.bc_fwd = cfg.bc_bwd = chan->bc;
3295 cfg.be_fwd = cfg.be_bwd = chan->be;
3296 cfg.conf_flags = 0x0000;
3297 }
3298
3299 if (fr_dlci_configure( card, &cfg , chan->dlci)){
3300 printk(KERN_INFO
3301 "%s: DLCI Configure failed for %d\n",
3302 card->devname, chan->dlci);
3303 return 1;
3304 }
3305
3306 chan->dlci_configured = DLCI_CONFIGURED;
3307
3308 /* Read the interface byte mapping into the channel
3309 * structure.
3310 */
3311 read_DLCI_IB_mapping( card, chan );
3312
3313 return 0;
3314}
3315/******* Miscellaneous ******************************************************/
3316
3317/*============================================================================
3318 * Update channel state.
3319 */
3320static int update_chan_state(struct net_device* dev)
3321{
3322 fr_channel_t* chan = dev->priv;
3323 sdla_t* card = chan->card;
3324 fr_mbox_t* mbox = card->mbox;
3325 int retry = MAX_CMD_RETRY;
3326 int err;
3327
3328 do
3329 {
3330 mbox->cmd.command = FR_LIST_ACTIVE_DLCI;
3331 mbox->cmd.length = 0;
3332 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
3333 } while (err && retry-- && fr_event(card, err, mbox));
3334
3335 if (!err) {
3336
3337 unsigned short* list = (void*)mbox->data;
3338 int cnt = mbox->cmd.length / sizeof(short);
3339
3340 err=1;
3341
3342 for (; cnt; --cnt, ++list) {
3343
3344 if (*list == chan->dlci) {
3345 set_chan_state(dev, WAN_CONNECTED);
3346
3347
3348 /* May 23 2000. NC
3349 * When a dlci is added or restarted,
3350 * the dlci_int_interface pointer must
3351 * be reinitialized. */
3352 if (!chan->dlci_int_interface){
3353 err=fr_init_dlci (card,chan);
3354 }
3355 break;
3356 }
3357 }
3358 }
3359
3360 return err;
3361}
3362
3363/*============================================================================
3364 * Set channel state.
3365 */
3366static void set_chan_state(struct net_device* dev, int state)
3367{
3368 fr_channel_t* chan = dev->priv;
3369 sdla_t* card = chan->card;
3370
3371 if (chan->common.state != state) {
3372
3373 switch (state) {
3374
3375 case WAN_CONNECTED:
3376 printk(KERN_INFO
3377 "%s: Interface %s: DLCI %d connected\n",
3378 card->devname, dev->name, chan->dlci);
3379
3380 /* If the interface was previoulsy down,
3381 * bring it up, since the channel is active */
3382
3383 trigger_fr_poll (dev);
3384 trigger_fr_arp (dev);
3385 break;
3386
3387 case WAN_CONNECTING:
3388 printk(KERN_INFO
3389 "%s: Interface %s: DLCI %d connecting\n",
3390 card->devname, dev->name, chan->dlci);
3391 break;
3392
3393 case WAN_DISCONNECTED:
3394 printk (KERN_INFO
3395 "%s: Interface %s: DLCI %d disconnected!\n",
3396 card->devname, dev->name, chan->dlci);
3397
3398 /* If the interface is up, bring it down,
3399 * since the channel is now disconnected */
3400 trigger_fr_poll (dev);
3401 break;
3402 }
3403
3404 chan->common.state = state;
3405 }
3406
3407 chan->state_tick = jiffies;
3408}
3409
3410/*============================================================================
3411 * Find network device by its channel number.
3412 *
3413 * We need this critical flag because we change
3414 * the dlci_to_dev_map outside the interrupt.
3415 *
3416 * NOTE: del_if() functions updates this array, it uses
3417 * the spin locks to avoid corruption.
3418 */
3419static struct net_device* find_channel(sdla_t* card, unsigned dlci)
3420{
3421 if(dlci > HIGHEST_VALID_DLCI)
3422 return NULL;
3423
3424 return(card->u.f.dlci_to_dev_map[dlci]);
3425}
3426
3427/*============================================================================
3428 * Check to see if a frame can be sent. If no transmit buffers available,
3429 * enable transmit interrupts.
3430 *
3431 * Return: 1 - Tx buffer(s) available
3432 * 0 - no buffers available
3433 */
3434static int is_tx_ready (sdla_t* card, fr_channel_t* chan)
3435{
3436 unsigned char sb;
3437
3438 if(card->hw.type == SDLA_S514)
3439 return 1;
3440
3441 sb = inb(card->hw.port);
3442 if (sb & 0x02)
3443 return 1;
3444
3445 return 0;
3446}
3447
3448/*============================================================================
3449 * Convert decimal string to unsigned integer.
3450 * If len != 0 then only 'len' characters of the string are converted.
3451 */
3452static unsigned int dec_to_uint (unsigned char* str, int len)
3453{
3454 unsigned val;
3455
3456 if (!len)
3457 len = strlen(str);
3458
3459 for (val = 0; len && isdigit(*str); ++str, --len)
3460 val = (val * 10) + (*str - (unsigned)'0');
3461
3462 return val;
3463}
3464
3465
3466
3467/*=============================================================================
3468 * Store a UDP management packet for later processing.
3469 */
3470
3471static int store_udp_mgmt_pkt(int udp_type, char udp_pkt_src, sdla_t* card,
3472 struct sk_buff *skb, int dlci)
3473{
3474 int udp_pkt_stored = 0;
3475
3476 struct net_device *dev = find_channel(card, dlci);
3477 fr_channel_t *chan;
3478
3479 if (!dev || !(chan=dev->priv))
3480 return 1;
3481
3482 if(!card->u.f.udp_pkt_lgth && (skb->len <= MAX_LGTH_UDP_MGNT_PKT)){
3483 card->u.f.udp_pkt_lgth = skb->len + chan->fr_header_len;
3484 card->u.f.udp_type = udp_type;
3485 card->u.f.udp_pkt_src = udp_pkt_src;
3486 card->u.f.udp_dlci = dlci;
3487 memcpy(card->u.f.udp_pkt_data, skb->data, skb->len);
3488 card->u.f.timer_int_enabled |= TMR_INT_ENABLED_UDP;
3489 udp_pkt_stored = 1;
3490
3491 }else{
3492 printk(KERN_INFO "ERROR: UDP packet not stored for DLCI %d\n",
3493 dlci);
3494 }
3495
3496 if(udp_pkt_src == UDP_PKT_FRM_STACK){
3497 dev_kfree_skb_any(skb);
3498 }else{
3499 dev_kfree_skb_any(skb);
3500 }
3501
3502 return(udp_pkt_stored);
3503}
3504
3505
3506/*==============================================================================
3507 * Process UDP call of type FPIPE8ND
3508 */
3509static int process_udp_mgmt_pkt(sdla_t* card)
3510{
3511
3512 int c_retry = MAX_CMD_RETRY;
3513 unsigned char *buf;
3514 unsigned char frames;
3515 unsigned int len;
3516 unsigned short buffer_length;
3517 struct sk_buff *new_skb;
3518 fr_mbox_t* mbox = card->mbox;
3519 int err;
3520 struct timeval tv;
3521 int udp_mgmt_req_valid = 1;
3522 struct net_device* dev;
3523 fr_channel_t* chan;
3524 fr_udp_pkt_t *fr_udp_pkt;
3525 unsigned short num_trc_els;
3526 fr_trc_el_t* ptr_trc_el;
3527 fr_trc_el_t trc_el;
3528 fpipemon_trc_t* fpipemon_trc;
3529
3530 char udp_pkt_src = card->u.f.udp_pkt_src;
3531 int dlci = card->u.f.udp_dlci;
3532
3533 /* Find network interface for this packet */
3534 dev = find_channel(card, dlci);
3535 if (!dev){
3536 card->u.f.udp_pkt_lgth = 0;
3537 return 1;
3538 }
3539 if ((chan = dev->priv) == NULL){
3540 card->u.f.udp_pkt_lgth = 0;
3541 return 1;
3542 }
3543
3544 /* If the UDP packet is from the network, we are going to have to
3545 transmit a response. Before doing so, we must check to see that
3546 we are not currently transmitting a frame (in 'if_send()') and
3547 that we are not already in a 'delayed transmit' state.
3548 */
3549 if(udp_pkt_src == UDP_PKT_FRM_NETWORK) {
3550 if (check_tx_status(card,dev)){
3551 card->u.f.udp_pkt_lgth = 0;
3552 return 1;
3553 }
3554 }
3555
3556 fr_udp_pkt = (fr_udp_pkt_t *)card->u.f.udp_pkt_data;
3557
3558 if(udp_pkt_src == UDP_PKT_FRM_NETWORK) {
3559
3560 switch(fr_udp_pkt->cblock.command) {
3561
3562 case FR_READ_MODEM_STATUS:
3563 case FR_READ_STATUS:
3564 case FPIPE_ROUTER_UP_TIME:
3565 case FR_READ_ERROR_STATS:
3566 case FPIPE_DRIVER_STAT_GEN:
3567 case FR_READ_STATISTICS:
3568 case FR_READ_ADD_DLC_STATS:
3569 case FR_READ_CONFIG:
3570 case FR_READ_CODE_VERSION:
3571 udp_mgmt_req_valid = 1;
3572 break;
3573 default:
3574 udp_mgmt_req_valid = 0;
3575 break;
3576 }
3577 }
3578
3579 if(!udp_mgmt_req_valid) {
3580 /* set length to 0 */
3581 fr_udp_pkt->cblock.length = 0;
3582 /* set return code */
3583 fr_udp_pkt->cblock.result = 0xCD;
3584
3585 chan->drvstats_gen.UDP_PIPE_mgmt_direction_err ++;
3586
3587 if (net_ratelimit()){
3588 printk(KERN_INFO
3589 "%s: Warning, Illegal UDP command attempted from network: %x\n",
3590 card->devname,fr_udp_pkt->cblock.command);
3591 }
3592
3593 } else {
3594
3595 switch(fr_udp_pkt->cblock.command) {
3596
3597 case FPIPE_ENABLE_TRACING:
3598 if(!card->TracingEnabled) {
3599 do {
3600 mbox->cmd.command = FR_SET_TRACE_CONFIG;
3601 mbox->cmd.length = 1;
3602 mbox->cmd.dlci = 0x00;
3603 mbox->data[0] = fr_udp_pkt->data[0] |
3604 RESET_TRC;
3605 err = sdla_exec(mbox) ?
3606 mbox->cmd.result : CMD_TIMEOUT;
3607 } while (err && c_retry-- && fr_event(card, err,
3608 mbox));
3609
3610 if(err) {
3611 card->TracingEnabled = 0;
3612 /* set the return code */
3613 fr_udp_pkt->cblock.result =
3614 mbox->cmd.result;
3615 mbox->cmd.length = 0;
3616 break;
3617 }
3618
3619 sdla_peek(&card->hw, NO_TRC_ELEMENTS_OFF,
3620 &num_trc_els, 2);
3621 sdla_peek(&card->hw, BASE_TRC_ELEMENTS_OFF,
3622 &card->u.f.trc_el_base, 4);
3623 card->u.f.curr_trc_el = card->u.f.trc_el_base;
3624 card->u.f.trc_el_last = card->u.f.curr_trc_el +
3625 ((num_trc_els - 1) *
3626 sizeof(fr_trc_el_t));
3627
3628 /* Calculate the maximum trace data area in */
3629 /* the UDP packet */
3630 card->u.f.trc_bfr_space=(MAX_LGTH_UDP_MGNT_PKT -
3631 //sizeof(fr_encap_hdr_t) -
3632 sizeof(ip_pkt_t) -
3633 sizeof(udp_pkt_t) -
3634 sizeof(wp_mgmt_t) -
3635 sizeof(cblock_t));
3636
3637 /* set return code */
3638 fr_udp_pkt->cblock.result = 0;
3639
3640 } else {
3641 /* set return code to line trace already
3642 enabled */
3643 fr_udp_pkt->cblock.result = 1;
3644 }
3645
3646 mbox->cmd.length = 0;
3647 card->TracingEnabled = 1;
3648 break;
3649
3650
3651 case FPIPE_DISABLE_TRACING:
3652 if(card->TracingEnabled) {
3653
3654 do {
3655 mbox->cmd.command = FR_SET_TRACE_CONFIG;
3656 mbox->cmd.length = 1;
3657 mbox->cmd.dlci = 0x00;
3658 mbox->data[0] = ~ACTIVATE_TRC;
3659 err = sdla_exec(mbox) ?
3660 mbox->cmd.result : CMD_TIMEOUT;
3661 } while (err && c_retry-- && fr_event(card, err, mbox));
3662 }
3663
3664 /* set return code */
3665 fr_udp_pkt->cblock.result = 0;
3666 mbox->cmd.length = 0;
3667 card->TracingEnabled = 0;
3668 break;
3669
3670 case FPIPE_GET_TRACE_INFO:
3671
3672 /* Line trace cannot be performed on the 502 */
3673 if(!card->TracingEnabled) {
3674 /* set return code */
3675 fr_udp_pkt->cblock.result = 1;
3676 mbox->cmd.length = 0;
3677 break;
3678 }
3679
3680 ptr_trc_el = (void *)card->u.f.curr_trc_el;
3681
3682 buffer_length = 0;
3683 fr_udp_pkt->data[0x00] = 0x00;
3684
3685 for(frames = 0; frames < MAX_FRMS_TRACED; frames ++) {
3686
3687 sdla_peek(&card->hw, (unsigned long)ptr_trc_el,
3688 (void *)&trc_el.flag,
3689 sizeof(fr_trc_el_t));
3690 if(trc_el.flag == 0x00) {
3691 break;
3692 }
3693 if((card->u.f.trc_bfr_space - buffer_length)
3694 < sizeof(fpipemon_trc_hdr_t)) {
3695 fr_udp_pkt->data[0x00] |= MORE_TRC_DATA;
3696 break;
3697 }
3698
3699 fpipemon_trc =
3700 (fpipemon_trc_t *)&fr_udp_pkt->data[buffer_length];
3701 fpipemon_trc->fpipemon_trc_hdr.status =
3702 trc_el.attr;
3703 fpipemon_trc->fpipemon_trc_hdr.tmstamp =
3704 trc_el.tmstamp;
3705 fpipemon_trc->fpipemon_trc_hdr.length =
3706 trc_el.length;
3707
3708 if(!trc_el.offset || !trc_el.length) {
3709
3710 fpipemon_trc->fpipemon_trc_hdr.data_passed = 0x00;
3711
3712 }else if((trc_el.length + sizeof(fpipemon_trc_hdr_t) + 1) >
3713 (card->u.f.trc_bfr_space - buffer_length)){
3714
3715 fpipemon_trc->fpipemon_trc_hdr.data_passed = 0x00;
3716 fr_udp_pkt->data[0x00] |= MORE_TRC_DATA;
3717
3718 }else {
3719 fpipemon_trc->fpipemon_trc_hdr.data_passed = 0x01;
3720 sdla_peek(&card->hw, trc_el.offset,
3721 fpipemon_trc->data,
3722 trc_el.length);
3723 }
3724
3725 trc_el.flag = 0x00;
3726 sdla_poke(&card->hw, (unsigned long)ptr_trc_el,
3727 &trc_el.flag, 1);
3728
3729 ptr_trc_el ++;
3730 if((void *)ptr_trc_el > card->u.f.trc_el_last)
3731 ptr_trc_el = (void*)card->u.f.trc_el_base;
3732
3733 buffer_length += sizeof(fpipemon_trc_hdr_t);
3734 if(fpipemon_trc->fpipemon_trc_hdr.data_passed) {
3735 buffer_length += trc_el.length;
3736 }
3737
3738 if(fr_udp_pkt->data[0x00] & MORE_TRC_DATA) {
3739 break;
3740 }
3741 }
3742
3743 if(frames == MAX_FRMS_TRACED) {
3744 fr_udp_pkt->data[0x00] |= MORE_TRC_DATA;
3745 }
3746
3747 card->u.f.curr_trc_el = (void *)ptr_trc_el;
3748
3749 /* set the total number of frames passed */
3750 fr_udp_pkt->data[0x00] |=
3751 ((frames << 1) & (MAX_FRMS_TRACED << 1));
3752
3753 /* set the data length and return code */
3754 fr_udp_pkt->cblock.length = mbox->cmd.length = buffer_length;
3755 fr_udp_pkt->cblock.result = 0;
3756 break;
3757
3758 case FPIPE_FT1_READ_STATUS:
3759 sdla_peek(&card->hw, 0xF020,
3760 &fr_udp_pkt->data[0x00] , 2);
3761 fr_udp_pkt->cblock.length = mbox->cmd.length = 2;
3762 fr_udp_pkt->cblock.result = 0;
3763 break;
3764
3765 case FPIPE_FLUSH_DRIVER_STATS:
3766 init_chan_statistics(chan);
3767 init_global_statistics(card);
3768 mbox->cmd.length = 0;
3769 break;
3770
3771 case FPIPE_ROUTER_UP_TIME:
3772 do_gettimeofday(&tv);
3773 chan->router_up_time = tv.tv_sec -
3774 chan->router_start_time;
3775 *(unsigned long *)&fr_udp_pkt->data =
3776 chan->router_up_time;
3777 mbox->cmd.length = fr_udp_pkt->cblock.length = 4;
3778 fr_udp_pkt->cblock.result = 0;
3779 break;
3780
3781 case FPIPE_DRIVER_STAT_IFSEND:
3782 memcpy(fr_udp_pkt->data,
3783 &chan->drvstats_if_send.if_send_entry,
3784 sizeof(if_send_stat_t));
3785 mbox->cmd.length = fr_udp_pkt->cblock.length =sizeof(if_send_stat_t);
3786 fr_udp_pkt->cblock.result = 0;
3787 break;
3788
3789 case FPIPE_DRIVER_STAT_INTR:
3790
3791 memcpy(fr_udp_pkt->data,
3792 &card->statistics.isr_entry,
3793 sizeof(global_stats_t));
3794
3795 memcpy(&fr_udp_pkt->data[sizeof(global_stats_t)],
3796 &chan->drvstats_rx_intr.rx_intr_no_socket,
3797 sizeof(rx_intr_stat_t));
3798
3799 mbox->cmd.length = fr_udp_pkt->cblock.length =
3800 sizeof(global_stats_t) +
3801 sizeof(rx_intr_stat_t);
3802 fr_udp_pkt->cblock.result = 0;
3803 break;
3804
3805 case FPIPE_DRIVER_STAT_GEN:
3806 memcpy(fr_udp_pkt->data,
3807 &chan->drvstats_gen.UDP_PIPE_mgmt_kmalloc_err,
3808 sizeof(pipe_mgmt_stat_t));
3809
3810 memcpy(&fr_udp_pkt->data[sizeof(pipe_mgmt_stat_t)],
3811 &card->statistics, sizeof(global_stats_t));
3812
3813 mbox->cmd.length = fr_udp_pkt->cblock.length = sizeof(global_stats_t)+
3814 sizeof(rx_intr_stat_t);
3815 fr_udp_pkt->cblock.result = 0;
3816 break;
3817
3818
3819 case FR_FT1_STATUS_CTRL:
3820 if(fr_udp_pkt->data[0] == 1) {
3821 if(rCount++ != 0 ){
3822 fr_udp_pkt->cblock.result = 0;
3823 mbox->cmd.length = 1;
3824 break;
3825 }
3826 }
3827
3828 /* Disable FT1 MONITOR STATUS */
3829 if(fr_udp_pkt->data[0] == 0) {
3830 if( --rCount != 0) {
3831 fr_udp_pkt->cblock.result = 0;
3832 mbox->cmd.length = 1;
3833 break;
3834 }
3835 }
3836 goto udp_mgmt_dflt;
3837
3838
3839 default:
3840udp_mgmt_dflt:
3841 do {
3842 memcpy(&mbox->cmd,
3843 &fr_udp_pkt->cblock.command,
3844 sizeof(fr_cmd_t));
3845 if(mbox->cmd.length) {
3846 memcpy(&mbox->data,
3847 (char *)fr_udp_pkt->data,
3848 mbox->cmd.length);
3849 }
3850
3851 err = sdla_exec(mbox) ? mbox->cmd.result :
3852 CMD_TIMEOUT;
3853 } while (err && c_retry-- && fr_event(card, err, mbox));
3854
3855 if(!err)
3856 chan->drvstats_gen.
3857 UDP_PIPE_mgmt_adptr_cmnd_OK ++;
3858 else
3859 chan->drvstats_gen.
3860 UDP_PIPE_mgmt_adptr_cmnd_timeout ++;
3861
3862 /* copy the result back to our buffer */
3863 memcpy(&fr_udp_pkt->cblock.command,
3864 &mbox->cmd, sizeof(fr_cmd_t));
3865
3866 if(mbox->cmd.length) {
3867 memcpy(&fr_udp_pkt->data,
3868 &mbox->data, mbox->cmd.length);
3869 }
3870 }
3871 }
3872
3873 /* Fill UDP TTL */
3874 fr_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
3875 len = reply_udp(card->u.f.udp_pkt_data, mbox->cmd.length);
3876
3877 if(udp_pkt_src == UDP_PKT_FRM_NETWORK) {
3878
3879 chan->fr_header_len=2;
3880 chan->fr_header[0]=Q922_UI;
3881 chan->fr_header[1]=NLPID_IP;
3882
3883 err = fr_send_data_header(card, dlci, 0, len,
3884 card->u.f.udp_pkt_data,chan->fr_header_len);
3885 if (err){
3886 chan->drvstats_gen.UDP_PIPE_mgmt_adptr_send_passed ++;
3887 }else{
3888 chan->drvstats_gen.UDP_PIPE_mgmt_adptr_send_failed ++;
3889 }
3890
3891 } else {
3892 /* Allocate socket buffer */
3893 if((new_skb = dev_alloc_skb(len)) != NULL) {
3894
3895 /* copy data into new_skb */
3896 buf = skb_put(new_skb, len);
3897 memcpy(buf, card->u.f.udp_pkt_data, len);
3898
3899 chan->drvstats_gen.
3900 UDP_PIPE_mgmt_passed_to_stack ++;
3901 new_skb->dev = dev;
3902 new_skb->protocol = htons(ETH_P_IP);
3903 new_skb->mac.raw = new_skb->data;
3904 netif_rx(new_skb);
3905
3906 } else {
3907 chan->drvstats_gen.UDP_PIPE_mgmt_no_socket ++;
3908 printk(KERN_INFO
3909 "%s: UDP mgmt cmnd, no socket buffers available!\n",
3910 card->devname);
3911 }
3912 }
3913
3914 card->u.f.udp_pkt_lgth = 0;
3915
3916 return 1;
3917}
3918
3919/*==============================================================================
3920 * Send Inverse ARP Request
3921 */
3922
3923int send_inarp_request(sdla_t *card, struct net_device *dev)
3924{
3925 int err=0;
3926
3927 arphdr_1490_t *ArpPacket;
3928 arphdr_fr_t *arphdr;
3929 fr_channel_t *chan = dev->priv;
3930 struct in_device *in_dev;
3931
3932 in_dev = dev->ip_ptr;
3933
3934 if(in_dev != NULL ) {
3935
3936 ArpPacket = kmalloc(sizeof(arphdr_1490_t) + sizeof(arphdr_fr_t), GFP_ATOMIC);
3937 /* SNAP Header indicating ARP */
3938 ArpPacket->control = 0x03;
3939 ArpPacket->pad = 0x00;
3940 ArpPacket->NLPID = 0x80;
3941 ArpPacket->OUI[0] = 0;
3942 ArpPacket->OUI[1] = 0;
3943 ArpPacket->OUI[2] = 0;
3944 ArpPacket->PID = 0x0608;
3945
3946 arphdr = (arphdr_fr_t *)(ArpPacket + 1); // Go to ARP Packet
3947
3948 /* InARP request */
3949 arphdr->ar_hrd = 0x0F00; /* Frame Relay HW type */
3950 arphdr->ar_pro = 0x0008; /* IP Protocol */
3951 arphdr->ar_hln = 2; /* HW addr length */
3952 arphdr->ar_pln = 4; /* IP addr length */
3953 arphdr->ar_op = htons(0x08); /* InARP Request */
3954 arphdr->ar_sha = 0; /* src HW DLCI - Doesn't matter */
3955 if(in_dev->ifa_list != NULL)
3956 arphdr->ar_sip = in_dev->ifa_list->ifa_local; /* Local Address */else
3957 arphdr->ar_sip = 0;
3958 arphdr->ar_tha = 0; /* dst HW DLCI - Doesn't matter */
3959 arphdr->ar_tip = 0; /* Remote Address -- what we want */
3960
3961 err = fr_send(card, chan->dlci, 0, sizeof(arphdr_1490_t) + sizeof(arphdr_fr_t),
3962 (void *)ArpPacket);
3963
3964 if (!err){
3965 printk(KERN_INFO "\n%s: Sending InARP request on DLCI %d.\n",
3966 card->devname, chan->dlci);
3967 clear_bit(ARP_CRIT,&card->wandev.critical);
3968 }
3969
3970 kfree(ArpPacket);
3971 }else{
3972 printk(KERN_INFO "%s: INARP ERROR: %s doesn't have a local IP address!\n",
3973 card->devname,dev->name);
3974 return 1;
3975 }
3976
3977 return 0;
3978}
3979
3980
3981/*==============================================================================
3982 * Check packet for ARP Type
3983 */
3984
3985int is_arp(void *buf)
3986{
3987 arphdr_1490_t *arphdr = (arphdr_1490_t *)buf;
3988
3989 if (arphdr->pad == 0x00 &&
3990 arphdr->NLPID == 0x80 &&
3991 arphdr->PID == 0x0608)
3992 return 1;
3993 else return 0;
3994}
3995
3996/*==============================================================================
3997 * Process ARP Packet Type
3998 */
3999
4000int process_ARP(arphdr_1490_t *ArpPacket, sdla_t *card, struct net_device* dev)
4001{
4002
4003
4004 arphdr_fr_t *arphdr = (arphdr_fr_t *)(ArpPacket + 1); /* Skip header */
4005 fr_rx_buf_ctl_t* frbuf = card->rxmb;
4006 struct in_device *in_dev;
4007 fr_channel_t *chan = dev->priv;
4008
4009 /* Before we transmit ARP packet, we must check
4010 * to see that we are not currently transmitting a
4011 * frame (in 'if_send()') and that we are not
4012 * already in a 'delayed transmit' state. */
4013 if (check_tx_status(card,dev)){
4014 if (net_ratelimit()){
4015 printk(KERN_INFO "%s: Disabling comminication to process ARP\n",
4016 card->devname);
4017 }
4018 set_bit(ARP_CRIT,&card->wandev.critical);
4019 return 0;
4020 }
4021
4022 in_dev = dev->ip_ptr;
4023
4024 /* Check that IP addresses exist for our network address */
4025 if (in_dev == NULL || in_dev->ifa_list == NULL)
4026 return -1;
4027
4028 switch (ntohs(arphdr->ar_op)) {
4029
4030 case 0x08: // Inverse ARP request -- Send Reply, add route.
4031
4032 /* Check for valid Address */
4033 printk(KERN_INFO "%s: Recvd PtP addr -InArp Req: %u.%u.%u.%u\n",
4034 card->devname, NIPQUAD(arphdr->ar_sip));
4035
4036
4037 /* Check that the network address is the same as ours, only
4038 * if the netowrk mask is not 255.255.255.255. Otherwise
4039 * this check would not make sense */
4040
4041 if (in_dev->ifa_list->ifa_mask != 0xFFFFFFFF &&
4042 (in_dev->ifa_list->ifa_mask & arphdr->ar_sip) !=
4043 (in_dev->ifa_list->ifa_mask & in_dev->ifa_list->ifa_local)){
4044 printk(KERN_INFO
4045 "%s: Invalid PtP address. %u.%u.%u.%u InARP ignored.\n",
4046 card->devname,NIPQUAD(arphdr->ar_sip));
4047
4048 printk(KERN_INFO "%s: mask %u.%u.%u.%u\n",
4049 card->devname, NIPQUAD(in_dev->ifa_list->ifa_mask));
4050 printk(KERN_INFO "%s: local %u.%u.%u.%u\n",
4051 card->devname,NIPQUAD(in_dev->ifa_list->ifa_local));
4052 return -1;
4053 }
4054
4055 if (in_dev->ifa_list->ifa_local == arphdr->ar_sip){
4056 printk(KERN_INFO
4057 "%s: Local addr = PtP addr. InARP ignored.\n",
4058 card->devname);
4059 return -1;
4060 }
4061
4062 arphdr->ar_op = htons(0x09); /* InARP Reply */
4063
4064 /* Set addresses */
4065 arphdr->ar_tip = arphdr->ar_sip;
4066 arphdr->ar_sip = in_dev->ifa_list->ifa_local;
4067
4068 chan->ip_local = in_dev->ifa_list->ifa_local;
4069 chan->ip_remote = arphdr->ar_sip;
4070
4071 fr_send(card, frbuf->dlci, 0, frbuf->length, (void *)ArpPacket);
4072
4073 if (test_bit(ARP_CRIT,&card->wandev.critical)){
4074 if (net_ratelimit()){
4075 printk(KERN_INFO "%s: ARP Processed Enabling Communication!\n",
4076 card->devname);
4077 }
4078 }
4079 clear_bit(ARP_CRIT,&card->wandev.critical);
4080
4081 chan->ip_local = in_dev->ifa_list->ifa_local;
4082 chan->ip_remote = arphdr->ar_sip;
4083
4084 /* Add Route Flag */
4085 /* The route will be added in the polling routine so
4086 that it is not interrupt context. */
4087
4088 chan->route_flag = ADD_ROUTE;
4089 trigger_fr_poll (dev);
4090
4091 break;
4092
4093 case 0x09: // Inverse ARP reply
4094
4095 /* Check for valid Address */
4096 printk(KERN_INFO "%s: Recvd PtP addr %u.%u.%u.%u -InArp Reply\n",
4097 card->devname, NIPQUAD(arphdr->ar_sip));
4098
4099
4100 /* Compare network addresses, only if network mask
4101 * is not 255.255.255.255 It would not make sense
4102 * to perform this test if the mask was all 1's */
4103
4104 if (in_dev->ifa_list->ifa_mask != 0xffffffff &&
4105 (in_dev->ifa_list->ifa_mask & arphdr->ar_sip) !=
4106 (in_dev->ifa_list->ifa_mask & in_dev->ifa_list->ifa_local)) {
4107
4108 printk(KERN_INFO "%s: Invalid PtP address. InARP ignored.\n",
4109 card->devname);
4110 return -1;
4111 }
4112
4113 /* Make sure that the received IP address is not
4114 * the same as our own local address */
4115 if (in_dev->ifa_list->ifa_local == arphdr->ar_sip) {
4116 printk(KERN_INFO "%s: Local addr = PtP addr. InARP ignored.\n",
4117 card->devname);
4118 return -1;
4119 }
4120
4121 chan->ip_local = in_dev->ifa_list->ifa_local;
4122 chan->ip_remote = arphdr->ar_sip;
4123
4124 /* Add Route Flag */
4125 /* The route will be added in the polling routine so
4126 that it is not interrupt context. */
4127
4128 chan->route_flag = ADD_ROUTE;
4129 chan->inarp = INARP_CONFIGURED;
4130 trigger_fr_poll(dev);
4131
4132 break;
4133 default:
4134 break; // ARP's and RARP's -- Shouldn't happen.
4135 }
4136
4137 return 0;
4138}
4139
4140
4141/*============================================================
4142 * trigger_fr_arp
4143 *
4144 * Description:
4145 * Add an fr_arp() task into a arp
4146 * timer handler for a specific dlci/interface.
4147 * This will kick the fr_arp() routine
4148 * within the specified time interval.
4149 *
4150 * Usage:
4151 * This timer is used to send ARP requests at
4152 * certain time intervals.
4153 * Called by an interrupt to request an action
4154 * at a later date.
4155 */
4156
4157static void trigger_fr_arp(struct net_device *dev)
4158{
4159 fr_channel_t* chan = dev->priv;
4160
4161 mod_timer(&chan->fr_arp_timer, jiffies + chan->inarp_interval * HZ);
4162 return;
4163}
4164
4165
4166
4167/*==============================================================================
4168 * ARP Request Action
4169 *
4170 * This funciton is called by timer interrupt to send an arp request
4171 * to the remote end.
4172 */
4173
4174static void fr_arp (unsigned long data)
4175{
4176 struct net_device *dev = (struct net_device *)data;
4177 fr_channel_t *chan = dev->priv;
4178 volatile sdla_t *card = chan->card;
4179 fr508_flags_t* flags = card->flags;
4180
4181 /* Send ARP packets for all devs' until
4182 * ARP state changes to CONFIGURED */
4183
4184 if (chan->inarp == INARP_REQUEST &&
4185 chan->common.state == WAN_CONNECTED &&
4186 card->wandev.state == WAN_CONNECTED){
4187 set_bit(0,&chan->inarp_ready);
4188 card->u.f.timer_int_enabled |= TMR_INT_ENABLED_ARP;
4189 flags->imask |= FR_INTR_TIMER;
4190 }
4191
4192 return;
4193}
4194
4195
4196/*==============================================================================
4197 * Perform the Interrupt Test by running the READ_CODE_VERSION command MAX_INTR_
4198 * TEST_COUNTER times.
4199 */
4200static int intr_test( sdla_t* card )
4201{
4202 fr_mbox_t* mb = card->mbox;
4203 int err,i;
4204
4205 err = fr_set_intr_mode(card, FR_INTR_READY, card->wandev.mtu, 0 );
4206
4207 if (err == CMD_OK) {
4208
4209 for ( i = 0; i < MAX_INTR_TEST_COUNTER; i++ ) {
4210 /* Run command READ_CODE_VERSION */
4211 mb->cmd.length = 0;
4212 mb->cmd.command = FR_READ_CODE_VERSION;
4213 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
4214 if (err != CMD_OK)
4215 fr_event(card, err, mb);
4216 }
4217
4218 } else {
4219 return err;
4220 }
4221
4222 err = fr_set_intr_mode( card, 0, card->wandev.mtu, 0 );
4223
4224 if( err != CMD_OK )
4225 return err;
4226
4227 return 0;
4228}
4229
4230/*==============================================================================
4231 * Determine what type of UDP call it is. FPIPE8ND ?
4232 */
4233static int udp_pkt_type( struct sk_buff *skb, sdla_t* card )
4234{
4235 fr_udp_pkt_t *fr_udp_pkt = (fr_udp_pkt_t *)skb->data;
4236
4237 /* Quick HACK */
4238
4239
4240 if((fr_udp_pkt->ip_pkt.protocol == UDPMGMT_UDP_PROTOCOL) &&
4241 (fr_udp_pkt->ip_pkt.ver_inet_hdr_length == 0x45) &&
4242 (fr_udp_pkt->udp_pkt.udp_dst_port ==
4243 ntohs(card->wandev.udp_port)) &&
4244 (fr_udp_pkt->wp_mgmt.request_reply ==
4245 UDPMGMT_REQUEST)) {
4246 if(!strncmp(fr_udp_pkt->wp_mgmt.signature,
4247 UDPMGMT_FPIPE_SIGNATURE, 8)){
4248 return UDP_FPIPE_TYPE;
4249 }
4250 }
4251 return UDP_INVALID_TYPE;
4252}
4253
4254
4255/*==============================================================================
4256 * Initializes the Statistics values in the fr_channel structure.
4257 */
4258void init_chan_statistics( fr_channel_t* chan)
4259{
4260 memset(&chan->drvstats_if_send.if_send_entry, 0,
4261 sizeof(if_send_stat_t));
4262 memset(&chan->drvstats_rx_intr.rx_intr_no_socket, 0,
4263 sizeof(rx_intr_stat_t));
4264 memset(&chan->drvstats_gen.UDP_PIPE_mgmt_kmalloc_err, 0,
4265 sizeof(pipe_mgmt_stat_t));
4266}
4267
4268/*==============================================================================
4269 * Initializes the Statistics values in the Sdla_t structure.
4270 */
4271void init_global_statistics( sdla_t* card )
4272{
4273 /* Intialize global statistics for a card */
4274 memset(&card->statistics.isr_entry, 0, sizeof(global_stats_t));
4275}
4276
4277static void read_DLCI_IB_mapping( sdla_t* card, fr_channel_t* chan )
4278{
4279 fr_mbox_t* mbox = card->mbox;
4280 int retry = MAX_CMD_RETRY;
4281 dlci_IB_mapping_t* result;
4282 int err, counter, found;
4283
4284 do {
4285 mbox->cmd.command = FR_READ_DLCI_IB_MAPPING;
4286 mbox->cmd.length = 0;
4287 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4288 } while (err && retry-- && fr_event(card, err, mbox));
4289
4290 if( mbox->cmd.result != 0){
4291 printk(KERN_INFO "%s: Read DLCI IB Mapping failed\n",
4292 chan->name);
4293 }
4294
4295 counter = mbox->cmd.length / sizeof(dlci_IB_mapping_t);
4296 result = (void *)mbox->data;
4297
4298 found = 0;
4299 for (; counter; --counter, ++result) {
4300 if ( result->dlci == chan->dlci ) {
4301 chan->IB_addr = result->addr_value;
4302 if(card->hw.type == SDLA_S514){
4303 chan->dlci_int_interface =
4304 (void*)(card->hw.dpmbase +
4305 chan->IB_addr);
4306 }else{
4307 chan->dlci_int_interface =
4308 (void*)(card->hw.dpmbase +
4309 (chan->IB_addr & 0x00001FFF));
4310
4311 }
4312 found = 1;
4313 break;
4314 }
4315 }
4316 if (!found)
4317 printk( KERN_INFO "%s: DLCI %d not found by IB MAPPING cmd\n",
4318 card->devname, chan->dlci);
4319}
4320
4321
4322
4323void s508_s514_lock(sdla_t *card, unsigned long *smp_flags)
4324{
4325 if (card->hw.type != SDLA_S514){
4326
4327 spin_lock_irqsave(&card->wandev.lock, *smp_flags);
4328 }else{
4329 spin_lock(&card->u.f.if_send_lock);
4330 }
4331 return;
4332}
4333
4334
4335void s508_s514_unlock(sdla_t *card, unsigned long *smp_flags)
4336{
4337 if (card->hw.type != SDLA_S514){
4338
4339 spin_unlock_irqrestore (&card->wandev.lock, *smp_flags);
4340 }else{
4341 spin_unlock(&card->u.f.if_send_lock);
4342 }
4343 return;
4344}
4345
4346
4347
4348/*----------------------------------------------------------------------
4349 RECEIVE INTERRUPT: BOTTOM HALF HANDLERS
4350 ----------------------------------------------------------------------*/
4351
4352
4353/*========================================================
4354 * bh_enqueue
4355 *
4356 * Description:
4357 * Insert a received packet into a circular
4358 * rx queue. This packet will be picked up
4359 * by fr_bh() and sent up the stack to the
4360 * user.
4361 *
4362 * Usage:
4363 * This function is called by rx interrupt,
4364 * in API mode.
4365 *
4366 */
4367
4368static int bh_enqueue(struct net_device *dev, struct sk_buff *skb)
4369{
4370 /* Check for full */
4371 fr_channel_t* chan = dev->priv;
4372 sdla_t *card = chan->card;
4373
4374
4375 if (atomic_read(&chan->bh_buff_used) == MAX_BH_BUFF){
4376 ++card->wandev.stats.rx_dropped;
4377 dev_kfree_skb_any(skb);
4378 return 1;
4379 }
4380
4381 ((bh_data_t *)&chan->bh_head[chan->bh_write])->skb = skb;
4382
4383 if (chan->bh_write == (MAX_BH_BUFF-1)){
4384 chan->bh_write=0;
4385 }else{
4386 ++chan->bh_write;
4387 }
4388
4389 atomic_inc(&chan->bh_buff_used);
4390
4391 return 0;
4392}
4393
4394
4395/*========================================================
4396 * trigger_fr_bh
4397 *
4398 * Description:
4399 * Kick the fr_bh() handler
4400 *
4401 * Usage:
4402 * rx interrupt calls this function during
4403 * the API mode.
4404 */
4405
4406static void trigger_fr_bh (fr_channel_t *chan)
4407{
4408 if (!test_and_set_bit(0,&chan->tq_working)){
4409 wanpipe_queue_work(&chan->common.wanpipe_work);
4410 }
4411}
4412
4413
4414/*========================================================
4415 * fr_bh
4416 *
4417 * Description:
4418 * Frame relay receive BH handler.
4419 * Dequeue data from the BH circular
4420 * buffer and pass it up the API sock.
4421 *
4422 * Rationale:
4423 * This fuction is used to offload the
4424 * rx_interrupt during API operation mode.
4425 * The fr_bh() function executes for each
4426 * dlci/interface.
4427 *
4428 * Once receive interrupt copies data from the
4429 * card into an skb buffer, the skb buffer
4430 * is appended to a circular BH buffer.
4431 * Then the interrupt kicks fr_bh() to finish the
4432 * job at a later time (not within the interrupt).
4433 *
4434 * Usage:
4435 * Interrupts use this to defer a task to
4436 * a polling routine.
4437 *
4438 */
4439
4440static void fr_bh(struct net_device * dev)
4441{
4442 fr_channel_t* chan = dev->priv;
4443 sdla_t *card = chan->card;
4444 struct sk_buff *skb;
4445
4446 if (atomic_read(&chan->bh_buff_used) == 0){
4447 clear_bit(0, &chan->tq_working);
4448 return;
4449 }
4450
4451 while (atomic_read(&chan->bh_buff_used)){
4452
4453 if (chan->common.sk == NULL || chan->common.func == NULL){
4454 clear_bit(0, &chan->tq_working);
4455 return;
4456 }
4457
4458 skb = ((bh_data_t *)&chan->bh_head[chan->bh_read])->skb;
4459
4460 if (skb != NULL){
4461
4462 if (chan->common.sk == NULL || chan->common.func == NULL){
4463 ++card->wandev.stats.rx_dropped;
4464 ++chan->ifstats.rx_dropped;
4465 dev_kfree_skb_any(skb);
4466 fr_bh_cleanup(dev);
4467 continue;
4468 }
4469
4470 if (chan->common.func(skb,dev,chan->common.sk) != 0){
4471 /* Sock full cannot send, queue us for
4472 * another try */
4473 atomic_set(&chan->common.receive_block,1);
4474 return;
4475 }else{
4476 fr_bh_cleanup(dev);
4477 }
4478 }else{
4479 fr_bh_cleanup(dev);
4480 }
4481 }
4482 clear_bit(0, &chan->tq_working);
4483
4484 return;
4485}
4486
4487static int fr_bh_cleanup(struct net_device *dev)
4488{
4489 fr_channel_t* chan = dev->priv;
4490
4491 ((bh_data_t *)&chan->bh_head[chan->bh_read])->skb = NULL;
4492
4493 if (chan->bh_read == (MAX_BH_BUFF-1)){
4494 chan->bh_read=0;
4495 }else{
4496 ++chan->bh_read;
4497 }
4498
4499 atomic_dec(&chan->bh_buff_used);
4500 return 0;
4501}
4502
4503
4504/*----------------------------------------------------------------------
4505 POLL BH HANDLERS AND KICK ROUTINES
4506 ----------------------------------------------------------------------*/
4507
4508/*============================================================
4509 * trigger_fr_poll
4510 *
4511 * Description:
4512 * Add a fr_poll() task into a tq_scheduler bh handler
4513 * for a specific dlci/interface. This will kick
4514 * the fr_poll() routine at a later time.
4515 *
4516 * Usage:
4517 * Interrupts use this to defer a taks to
4518 * a polling routine.
4519 *
4520 */
4521static void trigger_fr_poll(struct net_device *dev)
4522{
4523 fr_channel_t* chan = dev->priv;
4524 schedule_work(&chan->fr_poll_work);
4525 return;
4526}
4527
4528
4529/*============================================================
4530 * fr_poll
4531 *
4532 * Rationale:
4533 * We cannot manipulate the routing tables, or
4534 * ip addresses withing the interrupt. Therefore
4535 * we must perform such actons outside an interrupt
4536 * at a later time.
4537 *
4538 * Description:
4539 * Frame relay polling routine, responsible for
4540 * shutting down interfaces upon disconnect
4541 * and adding/removing routes.
4542 *
4543 * Usage:
4544 * This function is executed for each frame relay
4545 * dlci/interface through a tq_schedule bottom half.
4546 *
4547 * trigger_fr_poll() function is used to kick
4548 * the fr_poll routine.
4549 */
4550
4551static void fr_poll(struct net_device *dev)
4552{
4553
4554 fr_channel_t* chan;
4555 sdla_t *card;
4556 u8 check_gateway=0;
4557
4558 if (!dev || (chan = dev->priv) == NULL)
4559 return;
4560
4561 card = chan->card;
4562
4563 /* (Re)Configuraiton is in progress, stop what you are
4564 * doing and get out */
4565 if (test_bit(PERI_CRIT,&card->wandev.critical)){
4566 return;
4567 }
4568
4569 switch (chan->common.state){
4570
4571 case WAN_DISCONNECTED:
4572
4573 if (test_bit(DYN_OPT_ON,&chan->interface_down) &&
4574 !test_bit(DEV_DOWN, &chan->interface_down) &&
4575 dev->flags&IFF_UP){
4576
4577 printk(KERN_INFO "%s: Interface %s is Down.\n",
4578 card->devname,dev->name);
4579 change_dev_flags(dev,dev->flags&~IFF_UP);
4580 set_bit(DEV_DOWN, &chan->interface_down);
4581 chan->route_flag = NO_ROUTE;
4582
4583 }else{
4584 if (chan->inarp != INARP_NONE)
4585 process_route(dev);
4586 }
4587 break;
4588
4589 case WAN_CONNECTED:
4590
4591 if (test_bit(DYN_OPT_ON,&chan->interface_down) &&
4592 test_bit(DEV_DOWN, &chan->interface_down) &&
4593 !(dev->flags&IFF_UP)){
4594
4595 printk(KERN_INFO "%s: Interface %s is Up.\n",
4596 card->devname,dev->name);
4597
4598 change_dev_flags(dev,dev->flags|IFF_UP);
4599 clear_bit(DEV_DOWN, &chan->interface_down);
4600 check_gateway=1;
4601 }
4602
4603 if (chan->inarp != INARP_NONE){
4604 process_route(dev);
4605 check_gateway=1;
4606 }
4607
4608 if (chan->gateway && check_gateway)
4609 add_gateway(card,dev);
4610
4611 break;
4612
4613 }
4614
4615 return;
4616}
4617
4618/*==============================================================
4619 * check_tx_status
4620 *
4621 * Rationale:
4622 * We cannot transmit from an interrupt while
4623 * the if_send is transmitting data. Therefore,
4624 * we must check whether the tx buffers are
4625 * begin used, before we transmit from an
4626 * interrupt.
4627 *
4628 * Description:
4629 * Checks whether it's safe to use the transmit
4630 * buffers.
4631 *
4632 * Usage:
4633 * ARP and UDP handling routines use this function
4634 * because, they need to transmit data during
4635 * an interrupt.
4636 */
4637
4638static int check_tx_status(sdla_t *card, struct net_device *dev)
4639{
4640
4641 if (card->hw.type == SDLA_S514){
4642 if (test_bit(SEND_CRIT, (void*)&card->wandev.critical) ||
4643 test_bit(SEND_TXIRQ_CRIT, (void*)&card->wandev.critical)) {
4644 return 1;
4645 }
4646 }
4647
4648 if (netif_queue_stopped(dev) || (card->u.f.tx_interrupts_pending))
4649 return 1;
4650
4651 return 0;
4652}
4653
4654/*===============================================================
4655 * move_dev_to_next
4656 *
4657 * Description:
4658 * Move the dev pointer to the next location in the
4659 * link list. Check if we are at the end of the
4660 * list, if so start from the begining.
4661 *
4662 * Usage:
4663 * Timer interrupt uses this function to efficiently
4664 * step through the devices that need to send ARP data.
4665 *
4666 */
4667
4668struct net_device *move_dev_to_next(sdla_t *card, struct net_device *dev)
4669{
4670 if (card->wandev.new_if_cnt != 1){
4671 if (!*((struct net_device **)dev->priv))
4672 return card->wandev.dev;
4673 else
4674 return *((struct net_device **)dev->priv);
4675 }
4676 return dev;
4677}
4678
4679/*==============================================================
4680 * trigger_config_fr
4681 *
4682 * Rationale:
4683 * All commands must be performed inside of a
4684 * interrupt.
4685 *
4686 * Description:
4687 * Kick the config_fr() routine throught the
4688 * timer interrupt.
4689 */
4690
4691
4692static void trigger_config_fr (sdla_t *card)
4693{
4694 fr508_flags_t* flags = card->flags;
4695
4696 card->u.f.timer_int_enabled |= TMR_INT_ENABLED_CONFIG;
4697 flags->imask |= FR_INTR_TIMER;
4698}
4699
4700
4701/*==============================================================
4702 * config_fr
4703 *
4704 * Rationale:
4705 * All commands must be performed inside of a
4706 * interrupt.
4707 &
4708 * Description:
4709 * Configure a DLCI. This function is executed
4710 * by a timer_interrupt. The if_open() function
4711 * triggers it.
4712 *
4713 * Usage:
4714 * new_if() collects all data necessary to
4715 * configure the DLCI. It sets the chan->dlci_ready
4716 * bit. When the if_open() function is executed
4717 * it checks this bit, and if its set it triggers
4718 * the timer interrupt to execute the config_fr()
4719 * function.
4720 */
4721
4722static void config_fr (sdla_t *card)
4723{
4724 struct net_device *dev;
4725 fr_channel_t *chan;
4726
4727 for (dev = card->wandev.dev; dev;
4728 dev = *((struct net_device **)dev->priv)) {
4729
4730 if ((chan=dev->priv) == NULL)
4731 continue;
4732
4733 if (!test_bit(0,&chan->config_dlci))
4734 continue;
4735
4736 clear_bit(0,&chan->config_dlci);
4737
4738 /* If signalling is set to NO, then setup
4739 * DLCI addresses right away. Don't have to wait for
4740 * link to connect.
4741 */
4742 if (card->wandev.signalling == WANOPT_NO){
4743 printk(KERN_INFO "%s: Signalling set to NO: Mapping DLCI's\n",
4744 card->wandev.name);
4745 if (fr_init_dlci(card,chan)){
4746 printk(KERN_INFO "%s: ERROR: Failed to configure DLCI %i !\n",
4747 card->devname, chan->dlci);
4748 return;
4749 }
4750 }
4751
4752 if (card->wandev.station == WANOPT_CPE) {
4753
4754 update_chan_state(dev);
4755
4756 /* CPE: issue full status enquiry */
4757 fr_issue_isf(card, FR_ISF_FSE);
4758
4759 } else {
4760 /* FR switch: activate DLCI(s) */
4761
4762 /* For Switch emulation we have to ADD and ACTIVATE
4763 * the DLCI(s) that were configured with the SET_DLCI_
4764 * CONFIGURATION command. Add and Activate will fail if
4765 * DLCI specified is not included in the list.
4766 *
4767 * Also If_open is called once for each interface. But
4768 * it does not get in here for all the interface. So
4769 * we have to pass the entire list of DLCI(s) to add
4770 * activate routines.
4771 */
4772
4773 if (!check_dlci_config (card, chan)){
4774 fr_add_dlci(card, chan->dlci);
4775 fr_activate_dlci(card, chan->dlci);
4776 }
4777 }
4778
4779 card->u.f.dlci_to_dev_map[chan->dlci] = dev;
4780 }
4781 return;
4782}
4783
4784
4785/*==============================================================
4786 * config_fr
4787 *
4788 * Rationale:
4789 * All commands must be executed during an interrupt.
4790 *
4791 * Description:
4792 * Trigger uncofig_fr() function through
4793 * the timer interrupt.
4794 *
4795 */
4796
4797static void trigger_unconfig_fr(struct net_device *dev)
4798{
4799 fr_channel_t *chan = dev->priv;
4800 volatile sdla_t *card = chan->card;
4801 unsigned long timeout;
4802 fr508_flags_t* flags = card->flags;
4803 int reset_critical=0;
4804
4805 if (test_bit(PERI_CRIT,(void*)&card->wandev.critical)){
4806 clear_bit(PERI_CRIT,(void*)&card->wandev.critical);
4807 reset_critical=1;
4808 }
4809
4810 /* run unconfig_dlci() function
4811 * throught the timer interrupt */
4812 set_bit(0,(void*)&chan->unconfig_dlci);
4813 card->u.f.timer_int_enabled |= TMR_INT_ENABLED_UNCONFIG;
4814 flags->imask |= FR_INTR_TIMER;
4815
4816 /* Wait for the command to complete */
4817 timeout = jiffies;
4818 for(;;) {
4819
4820 if(!(card->u.f.timer_int_enabled & TMR_INT_ENABLED_UNCONFIG))
4821 break;
4822
4823 if (time_after(jiffies, timeout + 1 * HZ)){
4824 card->u.f.timer_int_enabled &= ~TMR_INT_ENABLED_UNCONFIG;
4825 printk(KERN_INFO "%s: Failed to delete DLCI %i\n",
4826 card->devname,chan->dlci);
4827 break;
4828 }
4829 }
4830
4831 if (reset_critical){
4832 set_bit(PERI_CRIT,(void*)&card->wandev.critical);
4833 }
4834}
4835
4836/*==============================================================
4837 * unconfig_fr
4838 *
4839 * Rationale:
4840 * All commands must be executed during an interrupt.
4841 *
4842 * Description:
4843 * Remove the dlci from firmware.
4844 * This funciton is used in NODE shutdown.
4845 */
4846
4847static void unconfig_fr (sdla_t *card)
4848{
4849 struct net_device *dev;
4850 fr_channel_t *chan;
4851
4852 for (dev = card->wandev.dev; dev;
4853 dev = *((struct net_device **)dev->priv)){
4854
4855 if ((chan=dev->priv) == NULL)
4856 continue;
4857
4858 if (!test_bit(0,&chan->unconfig_dlci))
4859 continue;
4860
4861 clear_bit(0,&chan->unconfig_dlci);
4862
4863 if (card->wandev.station == WANOPT_NODE){
4864 printk(KERN_INFO "%s: Unconfiguring DLCI %i\n",
4865 card->devname,chan->dlci);
4866 fr_delete_dlci(card,chan->dlci);
4867 }
4868 card->u.f.dlci_to_dev_map[chan->dlci] = NULL;
4869 }
4870}
4871
4872static int setup_fr_header(struct sk_buff *skb, struct net_device* dev,
4873 char op_mode)
4874{
4875 fr_channel_t *chan=dev->priv;
4876
4877 if (op_mode == WANPIPE) {
4878 chan->fr_header[0]=Q922_UI;
4879
4880 switch (htons(skb->protocol)){
4881 case ETH_P_IP:
4882 chan->fr_header[1]=NLPID_IP;
4883 break;
4884 default:
4885 return -EINVAL;
4886 }
4887
4888 return 2;
4889 }
4890
4891 /* If we are in bridging mode, we must apply
4892 * an Ethernet header
4893 */
4894 if (op_mode == BRIDGE || op_mode == BRIDGE_NODE) {
4895 /* Encapsulate the packet as a bridged Ethernet frame. */
4896#ifdef DEBUG
4897 printk(KERN_INFO "%s: encapsulating skb for frame relay\n",
4898 dev->name);
4899#endif
4900 chan->fr_header[0] = 0x03;
4901 chan->fr_header[1] = 0x00;
4902 chan->fr_header[2] = 0x80;
4903 chan->fr_header[3] = 0x00;
4904 chan->fr_header[4] = 0x80;
4905 chan->fr_header[5] = 0xC2;
4906 chan->fr_header[6] = 0x00;
4907 chan->fr_header[7] = 0x07;
4908
4909 /* Yuck. */
4910 skb->protocol = ETH_P_802_3;
4911 return 8;
4912 }
4913
4914 return 0;
4915}
4916
4917
4918static int check_dlci_config (sdla_t *card, fr_channel_t *chan)
4919{
4920 fr_mbox_t* mbox = card->mbox;
4921 int err=0;
4922 fr_conf_t *conf=NULL;
4923 unsigned short dlci_num = chan->dlci;
4924 int dlci_offset=0;
4925 struct net_device *dev = NULL;
4926
4927 mbox->cmd.command = FR_READ_CONFIG;
4928 mbox->cmd.length = 0;
4929 mbox->cmd.dlci = dlci_num;
4930
4931 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4932
4933 if (err == CMD_OK){
4934 return 0;
4935 }
4936
4937 for (dev = card->wandev.dev; dev;
4938 dev=*((struct net_device **)dev->priv))
4939 set_chan_state(dev,WAN_DISCONNECTED);
4940
4941 printk(KERN_INFO "DLCI %i Not configured, configuring\n",dlci_num);
4942
4943 mbox->cmd.command = FR_COMM_DISABLE;
4944 mbox->cmd.length = 0;
4945 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4946 if (err != CMD_OK){
4947 fr_event(card, err, mbox);
4948 return 2;
4949 }
4950
4951 printk(KERN_INFO "Disabled Communications \n");
4952
4953 mbox->cmd.command = FR_READ_CONFIG;
4954 mbox->cmd.length = 0;
4955 mbox->cmd.dlci = 0;
4956
4957 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4958
4959 if (err != CMD_OK){
4960 fr_event(card, err, mbox);
4961 return 2;
4962 }
4963
4964 conf = (fr_conf_t *)mbox->data;
4965
4966 dlci_offset=0;
4967 for (dev = card->wandev.dev; dev;
4968 dev = *((struct net_device **)dev->priv)) {
4969 fr_channel_t *chan_tmp = dev->priv;
4970 conf->dlci[dlci_offset] = chan_tmp->dlci;
4971 dlci_offset++;
4972 }
4973
4974 printk(KERN_INFO "Got Fr configuration Buffer Length is %x Dlci %i Dlci Off %i\n",
4975 mbox->cmd.length,
4976 mbox->cmd.length > 0x20 ? conf->dlci[0] : -1,
4977 dlci_offset );
4978
4979 mbox->cmd.length = 0x20 + dlci_offset*2;
4980
4981 mbox->cmd.command = FR_SET_CONFIG;
4982 mbox->cmd.dlci = 0;
4983
4984 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4985
4986 if (err != CMD_OK){
4987 fr_event(card, err, mbox);
4988 return 2;
4989 }
4990
4991 initialize_rx_tx_buffers (card);
4992
4993
4994 printk(KERN_INFO "Configuraiton Succeded for new DLCI %i\n",dlci_num);
4995
4996 if (fr_comm_enable (card)){
4997 return 2;
4998 }
4999
5000 printk(KERN_INFO "Enabling Communications \n");
5001
5002 for (dev = card->wandev.dev; dev;
5003 dev = *((struct net_device **)dev->priv)) {
5004 fr_channel_t *chan_tmp = dev->priv;
5005 fr_init_dlci(card,chan_tmp);
5006 fr_add_dlci(card, chan_tmp->dlci);
5007 fr_activate_dlci(card, chan_tmp->dlci);
5008 }
5009
5010 printk(KERN_INFO "END OF CONFIGURAITON %i\n",dlci_num);
5011
5012 return 1;
5013}
5014
5015static void initialize_rx_tx_buffers (sdla_t *card)
5016{
5017 fr_buf_info_t* buf_info;
5018
5019 if (card->hw.type == SDLA_S514) {
5020
5021 buf_info = (void*)(card->hw.dpmbase + FR_MB_VECTOR +
5022 FR508_RXBC_OFFS);
5023
5024 card->rxmb = (void*)(buf_info->rse_next + card->hw.dpmbase);
5025
5026 card->u.f.rxmb_base =
5027 (void*)(buf_info->rse_base + card->hw.dpmbase);
5028
5029 card->u.f.rxmb_last =
5030 (void*)(buf_info->rse_base +
5031 (buf_info->rse_num - 1) * sizeof(fr_rx_buf_ctl_t) +
5032 card->hw.dpmbase);
5033 }else{
5034 buf_info = (void*)(card->hw.dpmbase + FR508_RXBC_OFFS);
5035
5036 card->rxmb = (void*)(buf_info->rse_next -
5037 FR_MB_VECTOR + card->hw.dpmbase);
5038
5039 card->u.f.rxmb_base =
5040 (void*)(buf_info->rse_base -
5041 FR_MB_VECTOR + card->hw.dpmbase);
5042
5043 card->u.f.rxmb_last =
5044 (void*)(buf_info->rse_base +
5045 (buf_info->rse_num - 1) * sizeof(fr_rx_buf_ctl_t) -
5046 FR_MB_VECTOR + card->hw.dpmbase);
5047 }
5048
5049 card->u.f.rx_base = buf_info->buf_base;
5050 card->u.f.rx_top = buf_info->buf_top;
5051
5052 card->u.f.tx_interrupts_pending = 0;
5053
5054 return;
5055}
5056
5057
5058
5059MODULE_LICENSE("GPL");
5060
5061/****** End *****************************************************************/
diff --git a/drivers/net/wan/sdla_ft1.c b/drivers/net/wan/sdla_ft1.c
deleted file mode 100644
index 9d6528a50f7b..000000000000
--- a/drivers/net/wan/sdla_ft1.c
+++ /dev/null
@@ -1,345 +0,0 @@
1/*****************************************************************************
2* sdla_chdlc.c WANPIPE(tm) Multiprotocol WAN Link Driver. Cisco HDLC module.
3*
4* Authors: Nenad Corbic <ncorbic@sangoma.com>
5* Gideon Hack
6*
7* Copyright: (c) 1995-1999 Sangoma Technologies Inc.
8*
9* This program is free software; you can redistribute it and/or
10* modify it under the terms of the GNU General Public License
11* as published by the Free Software Foundation; either version
12* 2 of the License, or (at your option) any later version.
13* ============================================================================
14* Sep 30, 1999 Nenad Corbic Fixed dynamic IP and route setup.
15* Sep 23, 1999 Nenad Corbic Added SMP support, fixed tracing
16* Sep 13, 1999 Nenad Corbic Split up Port 0 and 1 into separate devices.
17* Jun 02, 1999 Gideon Hack Added support for the S514 adapter.
18* Oct 30, 1998 Jaspreet Singh Added Support for CHDLC API (HDLC STREAMING).
19* Oct 28, 1998 Jaspreet Singh Added Support for Dual Port CHDLC.
20* Aug 07, 1998 David Fong Initial version.
21*****************************************************************************/
22
23#include <linux/module.h>
24#include <linux/kernel.h> /* printk(), and other useful stuff */
25#include <linux/stddef.h> /* offsetof(), etc. */
26#include <linux/errno.h> /* return codes */
27#include <linux/string.h> /* inline memset(), etc. */
28#include <linux/slab.h> /* kmalloc(), kfree() */
29#include <linux/wanrouter.h> /* WAN router definitions */
30#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
31#include <linux/if_arp.h> /* ARPHRD_* defines */
32#include <linux/jiffies.h> /* time_after() macro */
33
34#include <linux/inetdevice.h>
35#include <asm/uaccess.h>
36
37#include <linux/in.h> /* sockaddr_in */
38#include <linux/inet.h>
39#include <linux/if.h>
40#include <asm/byteorder.h> /* htons(), etc. */
41#include <linux/sdlapci.h>
42#include <asm/io.h>
43
44#include <linux/sdla_chdlc.h> /* CHDLC firmware API definitions */
45
46/****** Defines & Macros ****************************************************/
47
48/* reasons for enabling the timer interrupt on the adapter */
49#define TMR_INT_ENABLED_UDP 0x0001
50#define TMR_INT_ENABLED_UPDATE 0x0002
51
52#define CHDLC_DFLT_DATA_LEN 1500 /* default MTU */
53#define CHDLC_HDR_LEN 1
54
55#define IFF_POINTTOPOINT 0x10
56
57#define WANPIPE 0x00
58#define API 0x01
59#define CHDLC_API 0x01
60
61#define PORT(x) (x == 0 ? "PRIMARY" : "SECONDARY" )
62
63
64/******Data Structures*****************************************************/
65
66/* This structure is placed in the private data area of the device structure.
67 * The card structure used to occupy the private area but now the following
68 * structure will incorporate the card structure along with CHDLC specific data
69 */
70
71typedef struct chdlc_private_area
72{
73 struct net_device *slave;
74 sdla_t *card;
75 int TracingEnabled; /* For enabling Tracing */
76 unsigned long curr_trace_addr; /* Used for Tracing */
77 unsigned long start_trace_addr;
78 unsigned long end_trace_addr;
79 unsigned long base_addr_trace_buffer;
80 unsigned long end_addr_trace_buffer;
81 unsigned short number_trace_elements;
82 unsigned available_buffer_space;
83 unsigned long router_start_time;
84 unsigned char route_status;
85 unsigned char route_removed;
86 unsigned long tick_counter; /* For 5s timeout counter */
87 unsigned long router_up_time;
88 u32 IP_address; /* IP addressing */
89 u32 IP_netmask;
90 unsigned char mc; /* Mulitcast support on/off */
91 unsigned short udp_pkt_lgth; /* udp packet processing */
92 char udp_pkt_src;
93 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
94 unsigned short timer_int_enabled;
95 char update_comms_stats; /* updating comms stats */
96 //FIXME: add driver stats as per frame relay!
97
98} chdlc_private_area_t;
99
100/* Route Status options */
101#define NO_ROUTE 0x00
102#define ADD_ROUTE 0x01
103#define ROUTE_ADDED 0x02
104#define REMOVE_ROUTE 0x03
105
106
107/****** Function Prototypes *************************************************/
108/* WAN link driver entry points. These are called by the WAN router module. */
109static int wpft1_exec (struct sdla *card, void *u_cmd, void *u_data);
110static int chdlc_read_version (sdla_t* card, char* str);
111static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb);
112
113/****** Public Functions ****************************************************/
114
115/*============================================================================
116 * Cisco HDLC protocol initialization routine.
117 *
118 * This routine is called by the main WANPIPE module during setup. At this
119 * point adapter is completely initialized and firmware is running.
120 * o read firmware version (to make sure it's alive)
121 * o configure adapter
122 * o initialize protocol-specific fields of the adapter data space.
123 *
124 * Return: 0 o.k.
125 * < 0 failure.
126 */
127int wpft1_init (sdla_t* card, wandev_conf_t* conf)
128{
129 unsigned char port_num;
130 int err;
131
132 union
133 {
134 char str[80];
135 } u;
136 volatile CHDLC_MAILBOX_STRUCT* mb;
137 CHDLC_MAILBOX_STRUCT* mb1;
138 unsigned long timeout;
139
140 /* Verify configuration ID */
141 if (conf->config_id != WANCONFIG_CHDLC) {
142 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
143 card->devname, conf->config_id);
144 return -EINVAL;
145 }
146
147 /* Use primary port */
148 card->u.c.comm_port = 0;
149
150
151 /* Initialize protocol-specific fields */
152 if(card->hw.type != SDLA_S514){
153 card->mbox = (void *) card->hw.dpmbase;
154 }else{
155 card->mbox = (void *) card->hw.dpmbase + PRI_BASE_ADDR_MB_STRUCT;
156 }
157
158 mb = mb1 = card->mbox;
159
160 if (!card->configured){
161
162 /* The board will place an 'I' in the return code to indicate that it is
163 ready to accept commands. We expect this to be completed in less
164 than 1 second. */
165
166 timeout = jiffies;
167 while (mb->return_code != 'I') /* Wait 1s for board to initialize */
168 if (time_after(jiffies, timeout + 1*HZ)) break;
169
170 if (mb->return_code != 'I') {
171 printk(KERN_INFO
172 "%s: Initialization not completed by adapter\n",
173 card->devname);
174 printk(KERN_INFO "Please contact Sangoma representative.\n");
175 return -EIO;
176 }
177 }
178
179 /* Read firmware version. Note that when adapter initializes, it
180 * clears the mailbox, so it may appear that the first command was
181 * executed successfully when in fact it was merely erased. To work
182 * around this, we execute the first command twice.
183 */
184
185 if (chdlc_read_version(card, u.str))
186 return -EIO;
187
188 printk(KERN_INFO "%s: Running FT1 Configuration firmware v%s\n",
189 card->devname, u.str);
190
191 card->isr = NULL;
192 card->poll = NULL;
193 card->exec = &wpft1_exec;
194 card->wandev.update = NULL;
195 card->wandev.new_if = NULL;
196 card->wandev.del_if = NULL;
197 card->wandev.state = WAN_DUALPORT;
198 card->wandev.udp_port = conf->udp_port;
199
200 card->wandev.new_if_cnt = 0;
201
202 /* This is for the ports link state */
203 card->u.c.state = WAN_DISCONNECTED;
204
205 /* reset the number of times the 'update()' proc has been called */
206 card->u.c.update_call_count = 0;
207
208 card->wandev.ttl = 0x7F;
209 card->wandev.interface = 0;
210
211 card->wandev.clocking = 0;
212
213 port_num = card->u.c.comm_port;
214
215 /* Setup Port Bps */
216
217 card->wandev.bps = 0;
218
219 card->wandev.mtu = MIN_LGTH_CHDLC_DATA_CFG;
220
221 /* Set up the interrupt status area */
222 /* Read the CHDLC Configuration and obtain:
223 * Ptr to shared memory infor struct
224 * Use this pointer to calculate the value of card->u.c.flags !
225 */
226 mb1->buffer_length = 0;
227 mb1->command = READ_CHDLC_CONFIGURATION;
228 err = sdla_exec(mb1) ? mb1->return_code : CMD_TIMEOUT;
229 if(err != COMMAND_OK) {
230 chdlc_error(card, err, mb1);
231 return -EIO;
232 }
233
234 if(card->hw.type == SDLA_S514){
235 card->u.c.flags = (void *)(card->hw.dpmbase +
236 (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
237 ptr_shared_mem_info_struct));
238 }else{
239 card->u.c.flags = (void *)(card->hw.dpmbase +
240 (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
241 ptr_shared_mem_info_struct % SDLA_WINDOWSIZE));
242 }
243
244 card->wandev.state = WAN_FT1_READY;
245 printk(KERN_INFO "%s: FT1 Config Ready !\n",card->devname);
246
247 return 0;
248}
249
250static int wpft1_exec(sdla_t *card, void *u_cmd, void *u_data)
251{
252 CHDLC_MAILBOX_STRUCT* mbox = card->mbox;
253 int len;
254
255 if (copy_from_user((void*)&mbox->command, u_cmd, sizeof(ft1_exec_cmd_t))){
256 return -EFAULT;
257 }
258
259 len = mbox->buffer_length;
260
261 if (len) {
262 if( copy_from_user((void*)&mbox->data, u_data, len)){
263 return -EFAULT;
264 }
265 }
266
267 /* execute command */
268 if (!sdla_exec(mbox)){
269 return -EIO;
270 }
271
272 /* return result */
273 if( copy_to_user(u_cmd, (void*)&mbox->command, sizeof(ft1_exec_cmd_t))){
274 return -EFAULT;
275 }
276
277 len = mbox->buffer_length;
278
279 if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len)){
280 return -EFAULT;
281 }
282
283 return 0;
284
285}
286
287/*============================================================================
288 * Read firmware code version.
289 * Put code version as ASCII string in str.
290 */
291static int chdlc_read_version (sdla_t* card, char* str)
292{
293 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
294 int len;
295 char err;
296 mb->buffer_length = 0;
297 mb->command = READ_CHDLC_CODE_VERSION;
298 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
299
300 if(err != COMMAND_OK) {
301 chdlc_error(card,err,mb);
302 }
303 else if (str) { /* is not null */
304 len = mb->buffer_length;
305 memcpy(str, mb->data, len);
306 str[len] = '\0';
307 }
308 return (err);
309}
310
311/*============================================================================
312 * Firmware error handler.
313 * This routine is called whenever firmware command returns non-zero
314 * return code.
315 *
316 * Return zero if previous command has to be cancelled.
317 */
318static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb)
319{
320 unsigned cmd = mb->command;
321
322 switch (err) {
323
324 case CMD_TIMEOUT:
325 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
326 card->devname, cmd);
327 break;
328
329 case S514_BOTH_PORTS_SAME_CLK_MODE:
330 if(cmd == SET_CHDLC_CONFIGURATION) {
331 printk(KERN_INFO
332 "%s: Configure both ports for the same clock source\n",
333 card->devname);
334 break;
335 }
336
337 default:
338 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n",
339 card->devname, cmd, err);
340 }
341
342 return 0;
343}
344
345MODULE_LICENSE("GPL");
diff --git a/drivers/net/wan/sdla_ppp.c b/drivers/net/wan/sdla_ppp.c
deleted file mode 100644
index a4b489cccbbf..000000000000
--- a/drivers/net/wan/sdla_ppp.c
+++ /dev/null
@@ -1,3430 +0,0 @@
1/*****************************************************************************
2* sdla_ppp.c WANPIPE(tm) Multiprotocol WAN Link Driver. PPP module.
3*
4* Author: Nenad Corbic <ncorbic@sangoma.com>
5*
6* Copyright: (c) 1995-2001 Sangoma Technologies Inc.
7*
8* This program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public License
10* as published by the Free Software Foundation; either version
11* 2 of the License, or (at your option) any later version.
12* ============================================================================
13* Feb 28, 2001 Nenad Corbic o Updated if_tx_timeout() routine for
14* 2.4.X kernels.
15* Nov 29, 2000 Nenad Corbic o Added the 2.4.x kernel support:
16* get_ip_address() function has moved
17* into the ppp_poll() routine. It cannot
18* be called from an interrupt.
19* Nov 07, 2000 Nenad Corbic o Added security features for UDP debugging:
20* Deny all and specify allowed requests.
21* May 02, 2000 Nenad Corbic o Added the dynamic interface shutdown
22* option. When the link goes down, the
23* network interface IFF_UP flag is reset.
24* Mar 06, 2000 Nenad Corbic o Bug Fix: corrupted mbox recovery.
25* Feb 25, 2000 Nenad Corbic o Fixed the FT1 UDP debugger problem.
26* Feb 09, 2000 Nenad Coribc o Shutdown bug fix. update() was called
27* with NULL dev pointer: no check.
28* Jan 24, 2000 Nenad Corbic o Disabled use of CMD complete inter.
29* Dev 15, 1999 Nenad Corbic o Fixed up header files for 2.0.X kernels
30* Oct 25, 1999 Nenad Corbic o Support for 2.0.X kernels
31* Moved dynamic route processing into
32* a polling routine.
33* Oct 07, 1999 Nenad Corbic o Support for S514 PCI card.
34* Gideon Hack o UPD and Updates executed using timer interrupt
35* Sep 10, 1999 Nenad Corbic o Fixed up the /proc statistics
36* Jul 20, 1999 Nenad Corbic o Remove the polling routines and use
37* interrupts instead.
38* Sep 17, 1998 Jaspreet Singh o Updates for 2.2.X Kernels.
39* Aug 13, 1998 Jaspreet Singh o Improved Line Tracing.
40* Jun 22, 1998 David Fong o Added remote IP address assignment
41* Mar 15, 1998 Alan Cox o 2.1.8x basic port.
42* Apr 16, 1998 Jaspreet Singh o using htons() for the IPX protocol.
43* Dec 09, 1997 Jaspreet Singh o Added PAP and CHAP.
44* o Implemented new routines like
45* ppp_set_inbnd_auth(), ppp_set_outbnd_auth(),
46* tokenize() and strstrip().
47* Nov 27, 1997 Jaspreet Singh o Added protection against enabling of irqs
48* while they have been disabled.
49* Nov 24, 1997 Jaspreet Singh o Fixed another RACE condition caused by
50* disabling and enabling of irqs.
51* o Added new counters for stats on disable/enable
52* IRQs.
53* Nov 10, 1997 Jaspreet Singh o Initialized 'skb->mac.raw' to 'skb->data'
54* before every netif_rx().
55* o Free up the device structure in del_if().
56* Nov 07, 1997 Jaspreet Singh o Changed the delay to zero for Line tracing
57* command.
58* Oct 20, 1997 Jaspreet Singh o Added hooks in for Router UP time.
59* Oct 16, 1997 Jaspreet Singh o The critical flag is used to maintain flow
60* control by avoiding RACE conditions. The
61* cli() and restore_flags() are taken out.
62* A new structure, "ppp_private_area", is added
63* to provide Driver Statistics.
64* Jul 21, 1997 Jaspreet Singh o Protected calls to sdla_peek() by adding
65* save_flags(), cli() and restore_flags().
66* Jul 07, 1997 Jaspreet Singh o Added configurable TTL for UDP packets
67* o Added ability to discard mulitcast and
68* broacast source addressed packets.
69* Jun 27, 1997 Jaspreet Singh o Added FT1 monitor capabilities
70* New case (0x25) statement in if_send routine.
71* Added a global variable rCount to keep track
72* of FT1 status enabled on the board.
73* May 22, 1997 Jaspreet Singh o Added change in the PPP_SET_CONFIG command for
74* 508 card to reflect changes in the new
75* ppp508.sfm for supporting:continous transmission
76* of Configure-Request packets without receiving a
77* reply
78* OR-ed 0x300 to conf_flags
79* o Changed connect_tmout from 900 to 0
80* May 21, 1997 Jaspreet Singh o Fixed UDP Management for multiple boards
81* Apr 25, 1997 Farhan Thawar o added UDP Management stuff
82* Mar 11, 1997 Farhan Thawar Version 3.1.1
83* o fixed (+1) bug in rx_intr()
84* o changed if_send() to return 0 if
85* wandev.critical() is true
86* o free socket buffer in if_send() if
87* returning 0
88* Jan 15, 1997 Gene Kozin Version 3.1.0
89* o implemented exec() entry point
90* Jan 06, 1997 Gene Kozin Initial version.
91*****************************************************************************/
92
93#include <linux/module.h>
94#include <linux/kernel.h> /* printk(), and other useful stuff */
95#include <linux/stddef.h> /* offsetof(), etc. */
96#include <linux/errno.h> /* return codes */
97#include <linux/string.h> /* inline memset(), etc. */
98#include <linux/slab.h> /* kmalloc(), kfree() */
99#include <linux/wanrouter.h> /* WAN router definitions */
100#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
101#include <linux/if_arp.h> /* ARPHRD_* defines */
102#include <asm/byteorder.h> /* htons(), etc. */
103#include <linux/in.h> /* sockaddr_in */
104#include <linux/jiffies.h> /* time_after() macro */
105
106
107#include <asm/uaccess.h>
108#include <linux/inetdevice.h>
109#include <linux/netdevice.h>
110
111#include <linux/if.h>
112#include <linux/sdla_ppp.h> /* PPP firmware API definitions */
113#include <linux/sdlasfm.h> /* S514 Type Definition */
114/****** Defines & Macros ****************************************************/
115
116#define PPP_DFLT_MTU 1500 /* default MTU */
117#define PPP_MAX_MTU 4000 /* maximum MTU */
118#define PPP_HDR_LEN 1
119
120#define MAX_IP_ERRORS 100
121
122#define CONNECT_TIMEOUT (90*HZ) /* link connection timeout */
123#define HOLD_DOWN_TIME (5*HZ) /* link hold down time : Changed from 30 to 5 */
124
125/* For handle_IPXWAN() */
126#define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))
127
128/* Macro for enabling/disabling debugging comments */
129//#define NEX_DEBUG
130#ifdef NEX_DEBUG
131#define NEX_PRINTK(format, a...) printk(format, ## a)
132#else
133#define NEX_PRINTK(format, a...)
134#endif /* NEX_DEBUG */
135
136#define DCD(a) ( a & 0x08 ? "HIGH" : "LOW" )
137#define CTS(a) ( a & 0x20 ? "HIGH" : "LOW" )
138#define LCP(a) ( a == 0x09 ? "OPEN" : "CLOSED" )
139#define IP(a) ( a == 0x09 ? "ENABLED" : "DISABLED" )
140
141#define TMR_INT_ENABLED_UPDATE 0x01
142#define TMR_INT_ENABLED_PPP_EVENT 0x02
143#define TMR_INT_ENABLED_UDP 0x04
144#define TMR_INT_ENABLED_CONFIG 0x20
145
146/* Set Configuraton Command Definitions */
147#define PERCENT_TX_BUFF 60
148#define TIME_BETWEEN_CONF_REQ 30
149#define TIME_BETWEEN_PAP_CHAP_REQ 30
150#define WAIT_PAP_CHAP_WITHOUT_REPLY 300
151#define WAIT_AFTER_DCD_CTS_LOW 5
152#define TIME_DCD_CTS_LOW_AFTER_LNK_DOWN 10
153#define WAIT_DCD_HIGH_AFTER_ENABLE_COMM 900
154#define MAX_CONF_REQ_WITHOUT_REPLY 10
155#define MAX_TERM_REQ_WITHOUT_REPLY 2
156#define NUM_CONF_NAK_WITHOUT_REPLY 5
157#define NUM_AUTH_REQ_WITHOUT_REPLY 10
158
159#define END_OFFSET 0x1F0
160
161
162/******Data Structures*****************************************************/
163
164/* This structure is placed in the private data area of the device structure.
165 * The card structure used to occupy the private area but now the following
166 * structure will incorporate the card structure along with PPP specific data
167 */
168
169typedef struct ppp_private_area
170{
171 struct net_device *slave;
172 sdla_t* card;
173 unsigned long router_start_time; /*router start time in sec */
174 unsigned long tick_counter; /*used for 5 second counter*/
175 unsigned mc; /*multicast support on or off*/
176 unsigned char enable_IPX;
177 unsigned long network_number;
178 unsigned char pap;
179 unsigned char chap;
180 unsigned char sysname[31]; /* system name for in-bnd auth*/
181 unsigned char userid[511]; /* list of user ids */
182 unsigned char passwd[511]; /* list of passwords */
183 unsigned protocol; /* SKB Protocol */
184 u32 ip_local; /* Local IP Address */
185 u32 ip_remote; /* remote IP Address */
186
187 u32 ip_local_tmp;
188 u32 ip_remote_tmp;
189
190 unsigned char timer_int_enabled; /* Who enabled the timer inter*/
191 unsigned char update_comms_stats; /* Used by update function */
192 unsigned long curr_trace_addr; /* Trace information */
193 unsigned long start_trace_addr;
194 unsigned long end_trace_addr;
195
196 unsigned char interface_down; /* Brind down interface when channel
197 goes down */
198 unsigned long config_wait_timeout; /* After if_open() if in dynamic if mode,
199 wait a few seconds before configuring */
200
201 unsigned short udp_pkt_lgth;
202 char udp_pkt_src;
203 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
204
205 /* PPP specific statistics */
206
207 if_send_stat_t if_send_stat;
208 rx_intr_stat_t rx_intr_stat;
209 pipe_mgmt_stat_t pipe_mgmt_stat;
210
211 unsigned long router_up_time;
212
213 /* Polling work queue entry. Each interface
214 * has its own work queue entry, which is used
215 * to defer events from the interrupt */
216 struct work_struct poll_work;
217 struct timer_list poll_delay_timer;
218
219 u8 gateway;
220 u8 config_ppp;
221 u8 ip_error;
222
223}ppp_private_area_t;
224
225/* variable for keeping track of enabling/disabling FT1 monitor status */
226static int rCount = 0;
227
228extern void disable_irq(unsigned int);
229extern void enable_irq(unsigned int);
230
231/****** Function Prototypes *************************************************/
232
233/* WAN link driver entry points. These are called by the WAN router module. */
234static int update(struct wan_device *wandev);
235static int new_if(struct wan_device *wandev, struct net_device *dev,
236 wanif_conf_t *conf);
237static int del_if(struct wan_device *wandev, struct net_device *dev);
238
239/* WANPIPE-specific entry points */
240static int wpp_exec (struct sdla *card, void *u_cmd, void *u_data);
241
242/* Network device interface */
243static int if_init(struct net_device *dev);
244static int if_open(struct net_device *dev);
245static int if_close(struct net_device *dev);
246static int if_header(struct sk_buff *skb, struct net_device *dev,
247 unsigned short type,
248 void *daddr, void *saddr, unsigned len);
249
250static void if_tx_timeout(struct net_device *dev);
251
252static int if_rebuild_hdr(struct sk_buff *skb);
253static struct net_device_stats *if_stats(struct net_device *dev);
254static int if_send(struct sk_buff *skb, struct net_device *dev);
255
256
257/* PPP firmware interface functions */
258static int ppp_read_version(sdla_t *card, char *str);
259static int ppp_set_outbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
260static int ppp_set_inbnd_auth(sdla_t *card, ppp_private_area_t *ppp_priv_area);
261static int ppp_configure(sdla_t *card, void *data);
262static int ppp_set_intr_mode(sdla_t *card, unsigned char mode);
263static int ppp_comm_enable(sdla_t *card);
264static int ppp_comm_disable(sdla_t *card);
265static int ppp_comm_disable_shutdown(sdla_t *card);
266static int ppp_get_err_stats(sdla_t *card);
267static int ppp_send(sdla_t *card, void *data, unsigned len, unsigned proto);
268static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb);
269
270static void wpp_isr(sdla_t *card);
271static void rx_intr(sdla_t *card);
272static void event_intr(sdla_t *card);
273static void timer_intr(sdla_t *card);
274
275/* Background polling routines */
276static void process_route(sdla_t *card);
277static void retrigger_comm(sdla_t *card);
278
279/* Miscellaneous functions */
280static int read_info( sdla_t *card );
281static int read_connection_info (sdla_t *card);
282static void remove_route( sdla_t *card );
283static int config508(struct net_device *dev, sdla_t *card);
284static void show_disc_cause(sdla_t * card, unsigned cause);
285static int reply_udp( unsigned char *data, unsigned int mbox_len );
286static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
287 ppp_private_area_t *ppp_priv_area);
288static void init_ppp_tx_rx_buff( sdla_t *card );
289static int intr_test( sdla_t *card );
290static int udp_pkt_type( struct sk_buff *skb , sdla_t *card);
291static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area);
292static void init_global_statistics( sdla_t *card );
293static int tokenize(char *str, char **tokens);
294static char* strstrip(char *str, char *s);
295static int chk_bcast_mcast_addr(sdla_t* card, struct net_device* dev,
296 struct sk_buff *skb);
297
298static int config_ppp (sdla_t *);
299static void ppp_poll(struct net_device *dev);
300static void trigger_ppp_poll(struct net_device *dev);
301static void ppp_poll_delay (unsigned long dev_ptr);
302
303
304static int Read_connection_info;
305static int Intr_test_counter;
306static unsigned short available_buffer_space;
307
308
309/* IPX functions */
310static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number,
311 unsigned char incoming);
312static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_PX,
313 unsigned long network_number, unsigned short proto);
314
315/* Lock Functions */
316static void s508_lock (sdla_t *card, unsigned long *smp_flags);
317static void s508_unlock (sdla_t *card, unsigned long *smp_flags);
318
319static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
320 struct sk_buff *skb, struct net_device* dev,
321 ppp_private_area_t* ppp_priv_area );
322static unsigned short calc_checksum (char *data, int len);
323static void disable_comm (sdla_t *card);
324static int detect_and_fix_tx_bug (sdla_t *card);
325
326/****** Public Functions ****************************************************/
327
328/*============================================================================
329 * PPP protocol initialization routine.
330 *
331 * This routine is called by the main WANPIPE module during setup. At this
332 * point adapter is completely initialized and firmware is running.
333 * o read firmware version (to make sure it's alive)
334 * o configure adapter
335 * o initialize protocol-specific fields of the adapter data space.
336 *
337 * Return: 0 o.k.
338 * < 0 failure.
339 */
340int wpp_init(sdla_t *card, wandev_conf_t *conf)
341{
342 ppp_flags_t *flags;
343 union
344 {
345 char str[80];
346 } u;
347
348 /* Verify configuration ID */
349 if (conf->config_id != WANCONFIG_PPP) {
350
351 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
352 card->devname, conf->config_id);
353 return -EINVAL;
354
355 }
356
357 /* Initialize miscellaneous pointers to structures on the adapter */
358 switch (card->hw.type) {
359
360 case SDLA_S508:
361 card->mbox =(void*)(card->hw.dpmbase + PPP508_MB_OFFS);
362 card->flags=(void*)(card->hw.dpmbase + PPP508_FLG_OFFS);
363 break;
364
365 case SDLA_S514:
366 card->mbox =(void*)(card->hw.dpmbase + PPP514_MB_OFFS);
367 card->flags=(void*)(card->hw.dpmbase + PPP514_FLG_OFFS);
368 break;
369
370 default:
371 return -EINVAL;
372
373 }
374 flags = card->flags;
375
376 /* Read firmware version. Note that when adapter initializes, it
377 * clears the mailbox, so it may appear that the first command was
378 * executed successfully when in fact it was merely erased. To work
379 * around this, we execute the first command twice.
380 */
381 if (ppp_read_version(card, NULL) || ppp_read_version(card, u.str))
382 return -EIO;
383
384 printk(KERN_INFO "%s: running PPP firmware v%s\n",card->devname, u.str);
385 /* Adjust configuration and set defaults */
386 card->wandev.mtu = (conf->mtu) ?
387 min_t(unsigned int, conf->mtu, PPP_MAX_MTU) : PPP_DFLT_MTU;
388
389 card->wandev.bps = conf->bps;
390 card->wandev.interface = conf->interface;
391 card->wandev.clocking = conf->clocking;
392 card->wandev.station = conf->station;
393 card->isr = &wpp_isr;
394 card->poll = NULL;
395 card->exec = &wpp_exec;
396 card->wandev.update = &update;
397 card->wandev.new_if = &new_if;
398 card->wandev.del_if = &del_if;
399 card->wandev.udp_port = conf->udp_port;
400 card->wandev.ttl = conf->ttl;
401 card->wandev.state = WAN_DISCONNECTED;
402 card->disable_comm = &disable_comm;
403 card->irq_dis_if_send_count = 0;
404 card->irq_dis_poll_count = 0;
405 card->u.p.authenticator = conf->u.ppp.authenticator;
406 card->u.p.ip_mode = conf->u.ppp.ip_mode ?
407 conf->u.ppp.ip_mode : WANOPT_PPP_STATIC;
408 card->TracingEnabled = 0;
409 Read_connection_info = 1;
410
411 /* initialize global statistics */
412 init_global_statistics( card );
413
414
415
416 if (!card->configured){
417 int err;
418
419 Intr_test_counter = 0;
420 err = intr_test(card);
421
422 if(err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
423 printk("%s: Interrupt Test Failed, Counter: %i\n",
424 card->devname, Intr_test_counter);
425 printk( "%s: Please choose another interrupt\n",card->devname);
426 return -EIO;
427 }
428
429 printk(KERN_INFO "%s: Interrupt Test Passed, Counter: %i\n",
430 card->devname, Intr_test_counter);
431 card->configured = 1;
432 }
433
434 ppp_set_intr_mode(card, PPP_INTR_TIMER);
435
436 /* Turn off the transmit and timer interrupt */
437 flags->imask &= ~PPP_INTR_TIMER;
438
439 printk(KERN_INFO "\n");
440
441 return 0;
442}
443
444/******* WAN Device Driver Entry Points *************************************/
445
446/*============================================================================
447 * Update device status & statistics.
448 */
449static int update(struct wan_device *wandev)
450{
451 sdla_t* card = wandev->private;
452 struct net_device* dev;
453 volatile ppp_private_area_t *ppp_priv_area;
454 ppp_flags_t *flags = card->flags;
455 unsigned long timeout;
456
457 /* sanity checks */
458 if ((wandev == NULL) || (wandev->private == NULL))
459 return -EFAULT;
460
461 if (wandev->state == WAN_UNCONFIGURED)
462 return -ENODEV;
463
464 /* Shutdown bug fix. This function can be
465 * called with NULL dev pointer during
466 * shutdown
467 */
468 if ((dev=card->wandev.dev) == NULL){
469 return -ENODEV;
470 }
471
472 if ((ppp_priv_area=dev->priv) == NULL){
473 return -ENODEV;
474 }
475
476 ppp_priv_area->update_comms_stats = 2;
477 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
478 flags->imask |= PPP_INTR_TIMER;
479
480 /* wait a maximum of 1 second for the statistics to be updated */
481 timeout = jiffies;
482 for(;;) {
483 if(ppp_priv_area->update_comms_stats == 0){
484 break;
485 }
486 if (time_after(jiffies, timeout + 1 * HZ)){
487 ppp_priv_area->update_comms_stats = 0;
488 ppp_priv_area->timer_int_enabled &=
489 ~TMR_INT_ENABLED_UPDATE;
490 return -EAGAIN;
491 }
492 }
493
494 return 0;
495}
496
497/*============================================================================
498 * Create new logical channel.
499 * This routine is called by the router when ROUTER_IFNEW IOCTL is being
500 * handled.
501 * o parse media- and hardware-specific configuration
502 * o make sure that a new channel can be created
503 * o allocate resources, if necessary
504 * o prepare network device structure for registaration.
505 *
506 * Return: 0 o.k.
507 * < 0 failure (channel will not be created)
508 */
509static int new_if(struct wan_device *wandev, struct net_device *dev,
510 wanif_conf_t *conf)
511{
512 sdla_t *card = wandev->private;
513 ppp_private_area_t *ppp_priv_area;
514
515 if (wandev->ndev)
516 return -EEXIST;
517
518
519 printk(KERN_INFO "%s: Configuring Interface: %s\n",
520 card->devname, conf->name);
521
522 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
523
524 printk(KERN_INFO "%s: Invalid interface name!\n",
525 card->devname);
526 return -EINVAL;
527
528 }
529
530 /* allocate and initialize private data */
531 ppp_priv_area = kmalloc(sizeof(ppp_private_area_t), GFP_KERNEL);
532
533 if( ppp_priv_area == NULL )
534 return -ENOMEM;
535
536 memset(ppp_priv_area, 0, sizeof(ppp_private_area_t));
537
538 ppp_priv_area->card = card;
539
540 /* initialize data */
541 strcpy(card->u.p.if_name, conf->name);
542
543 /* initialize data in ppp_private_area structure */
544
545 init_ppp_priv_struct( ppp_priv_area );
546
547 ppp_priv_area->mc = conf->mc;
548 ppp_priv_area->pap = conf->pap;
549 ppp_priv_area->chap = conf->chap;
550
551 /* Option to bring down the interface when
552 * the link goes down */
553 if (conf->if_down){
554 set_bit(DYN_OPT_ON,&ppp_priv_area->interface_down);
555 printk("%s: Dynamic interface configuration enabled\n",
556 card->devname);
557 }
558
559 /* If no user ids are specified */
560 if(!strlen(conf->userid) && (ppp_priv_area->pap||ppp_priv_area->chap)){
561 kfree(ppp_priv_area);
562 return -EINVAL;
563 }
564
565 /* If no passwords are specified */
566 if(!strlen(conf->passwd) && (ppp_priv_area->pap||ppp_priv_area->chap)){
567 kfree(ppp_priv_area);
568 return -EINVAL;
569 }
570
571 if(strlen(conf->sysname) > 31){
572 kfree(ppp_priv_area);
573 return -EINVAL;
574 }
575
576 /* If no system name is specified */
577 if(!strlen(conf->sysname) && (card->u.p.authenticator)){
578 kfree(ppp_priv_area);
579 return -EINVAL;
580 }
581
582 /* copy the data into the ppp private structure */
583 memcpy(ppp_priv_area->userid, conf->userid, strlen(conf->userid));
584 memcpy(ppp_priv_area->passwd, conf->passwd, strlen(conf->passwd));
585 memcpy(ppp_priv_area->sysname, conf->sysname, strlen(conf->sysname));
586
587
588 ppp_priv_area->enable_IPX = conf->enable_IPX;
589 if (conf->network_number){
590 ppp_priv_area->network_number = conf->network_number;
591 }else{
592 ppp_priv_area->network_number = 0xDEADBEEF;
593 }
594
595 /* Tells us that if this interface is a
596 * gateway or not */
597 if ((ppp_priv_area->gateway = conf->gateway) == WANOPT_YES){
598 printk(KERN_INFO "%s: Interface %s is set as a gateway.\n",
599 card->devname,card->u.p.if_name);
600 }
601
602 /* prepare network device data space for registration */
603 strcpy(dev->name,card->u.p.if_name);
604
605 dev->init = &if_init;
606 dev->priv = ppp_priv_area;
607 dev->mtu = min_t(unsigned int, dev->mtu, card->wandev.mtu);
608
609 /* Initialize the polling work routine */
610 INIT_WORK(&ppp_priv_area->poll_work, (void*)(void*)ppp_poll, dev);
611
612 /* Initialize the polling delay timer */
613 init_timer(&ppp_priv_area->poll_delay_timer);
614 ppp_priv_area->poll_delay_timer.data = (unsigned long)dev;
615 ppp_priv_area->poll_delay_timer.function = ppp_poll_delay;
616
617
618 /* Since we start with dummy IP addresses we can say
619 * that route exists */
620 printk(KERN_INFO "\n");
621
622 return 0;
623}
624
625/*============================================================================
626 * Delete logical channel.
627 */
628static int del_if(struct wan_device *wandev, struct net_device *dev)
629{
630 return 0;
631}
632
633static void disable_comm (sdla_t *card)
634{
635 ppp_comm_disable_shutdown(card);
636 return;
637}
638
639/****** WANPIPE-specific entry points ***************************************/
640
641/*============================================================================
642 * Execute adapter interface command.
643 */
644
645//FIXME: Why do we need this ????
646static int wpp_exec(struct sdla *card, void *u_cmd, void *u_data)
647{
648 ppp_mbox_t *mbox = card->mbox;
649 int len;
650
651 if (copy_from_user((void*)&mbox->cmd, u_cmd, sizeof(ppp_cmd_t)))
652 return -EFAULT;
653
654 len = mbox->cmd.length;
655
656 if (len) {
657
658 if( copy_from_user((void*)&mbox->data, u_data, len))
659 return -EFAULT;
660
661 }
662
663 /* execute command */
664 if (!sdla_exec(mbox))
665 return -EIO;
666
667 /* return result */
668 if( copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(ppp_cmd_t)))
669 return -EFAULT;
670 len = mbox->cmd.length;
671
672 if (len && u_data && copy_to_user(u_data, (void*)&mbox->data, len))
673 return -EFAULT;
674
675 return 0;
676}
677
678/****** Network Device Interface ********************************************/
679
680/*============================================================================
681 * Initialize Linux network interface.
682 *
683 * This routine is called only once for each interface, during Linux network
684 * interface registration. Returning anything but zero will fail interface
685 * registration.
686 */
687static int if_init(struct net_device *dev)
688{
689 ppp_private_area_t *ppp_priv_area = dev->priv;
690 sdla_t *card = ppp_priv_area->card;
691 struct wan_device *wandev = &card->wandev;
692
693 /* Initialize device driver entry points */
694 dev->open = &if_open;
695 dev->stop = &if_close;
696 dev->hard_header = &if_header;
697 dev->rebuild_header = &if_rebuild_hdr;
698 dev->hard_start_xmit = &if_send;
699 dev->get_stats = &if_stats;
700 dev->tx_timeout = &if_tx_timeout;
701 dev->watchdog_timeo = TX_TIMEOUT;
702
703 /* Initialize media-specific parameters */
704 dev->type = ARPHRD_PPP; /* ARP h/w type */
705 dev->flags |= IFF_POINTOPOINT;
706 dev->flags |= IFF_NOARP;
707
708 /* Enable Mulitcasting if specified by user*/
709 if (ppp_priv_area->mc == WANOPT_YES){
710 dev->flags |= IFF_MULTICAST;
711 }
712
713 dev->mtu = wandev->mtu;
714 dev->hard_header_len = PPP_HDR_LEN; /* media header length */
715
716 /* Initialize hardware parameters (just for reference) */
717 dev->irq = wandev->irq;
718 dev->dma = wandev->dma;
719 dev->base_addr = wandev->ioport;
720 dev->mem_start = wandev->maddr;
721 dev->mem_end = wandev->maddr + wandev->msize - 1;
722
723 /* Set transmit buffer queue length */
724 dev->tx_queue_len = 100;
725 SET_MODULE_OWNER(dev);
726
727 return 0;
728}
729
730/*============================================================================
731 * Open network interface.
732 * o enable communications and interrupts.
733 * o prevent module from unloading by incrementing use count
734 *
735 * Return 0 if O.k. or errno.
736 */
737static int if_open(struct net_device *dev)
738{
739 ppp_private_area_t *ppp_priv_area = dev->priv;
740 sdla_t *card = ppp_priv_area->card;
741 struct timeval tv;
742 //unsigned long smp_flags;
743
744 if (netif_running(dev))
745 return -EBUSY;
746
747 wanpipe_open(card);
748
749 netif_start_queue(dev);
750
751 do_gettimeofday( &tv );
752 ppp_priv_area->router_start_time = tv.tv_sec;
753
754 /* We cannot configure the card here because we don't
755 * have access to the interface IP addresses.
756 * Once the interface initilization is complete, we will be
757 * able to access the IP addresses. Therefore,
758 * configure the ppp link in the poll routine */
759 set_bit(0,&ppp_priv_area->config_ppp);
760 ppp_priv_area->config_wait_timeout=jiffies;
761
762 /* Start the PPP configuration after 1sec delay.
763 * This will give the interface initilization time
764 * to finish its configuration */
765 mod_timer(&ppp_priv_area->poll_delay_timer, jiffies + HZ);
766 return 0;
767}
768
769/*============================================================================
770 * Close network interface.
771 * o if this is the last open, then disable communications and interrupts.
772 * o reset flags.
773 */
774static int if_close(struct net_device *dev)
775{
776 ppp_private_area_t *ppp_priv_area = dev->priv;
777 sdla_t *card = ppp_priv_area->card;
778
779 netif_stop_queue(dev);
780 wanpipe_close(card);
781
782 del_timer (&ppp_priv_area->poll_delay_timer);
783 return 0;
784}
785
786/*============================================================================
787 * Build media header.
788 *
789 * The trick here is to put packet type (Ethertype) into 'protocol' field of
790 * the socket buffer, so that we don't forget it. If packet type is not
791 * supported, set skb->protocol to 0 and discard packet later.
792 *
793 * Return: media header length.
794 */
795static int if_header(struct sk_buff *skb, struct net_device *dev,
796 unsigned short type, void *daddr, void *saddr, unsigned len)
797{
798 switch (type)
799 {
800 case ETH_P_IP:
801 case ETH_P_IPX:
802 skb->protocol = htons(type);
803 break;
804
805 default:
806 skb->protocol = 0;
807 }
808
809 return PPP_HDR_LEN;
810}
811
812/*============================================================================
813 * Re-build media header.
814 *
815 * Return: 1 physical address resolved.
816 * 0 physical address not resolved
817 */
818static int if_rebuild_hdr (struct sk_buff *skb)
819{
820 struct net_device *dev = skb->dev;
821 ppp_private_area_t *ppp_priv_area = dev->priv;
822 sdla_t *card = ppp_priv_area->card;
823
824 printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
825 card->devname, dev->name);
826 return 1;
827}
828
829/*============================================================================
830 * Handle transmit timeout event from netif watchdog
831 */
832static void if_tx_timeout(struct net_device *dev)
833{
834 ppp_private_area_t* chan = dev->priv;
835 sdla_t *card = chan->card;
836
837 /* If our device stays busy for at least 5 seconds then we will
838 * kick start the device by making dev->tbusy = 0. We expect
839 * that our device never stays busy more than 5 seconds. So this
840 * is only used as a last resort.
841 */
842
843 ++ chan->if_send_stat.if_send_tbusy;
844 ++card->wandev.stats.collisions;
845
846 printk (KERN_INFO "%s: Transmit timed out on %s\n", card->devname,dev->name);
847 ++chan->if_send_stat.if_send_tbusy_timeout;
848 netif_wake_queue (dev);
849}
850
851
852
853/*============================================================================
854 * Send a packet on a network interface.
855 * o set tbusy flag (marks start of the transmission) to block a timer-based
856 * transmit from overlapping.
857 * o check link state. If link is not up, then drop the packet.
858 * o execute adapter send command.
859 * o free socket buffer
860 *
861 * Return: 0 complete (socket buffer must be freed)
862 * non-0 packet may be re-transmitted (tbusy must be set)
863 *
864 * Notes:
865 * 1. This routine is called either by the protocol stack or by the "net
866 * bottom half" (with interrupts enabled).
867 * 2. Setting tbusy flag will inhibit further transmit requests from the
868 * protocol stack and can be used for flow control with protocol layer.
869 */
870static int if_send (struct sk_buff *skb, struct net_device *dev)
871{
872 ppp_private_area_t *ppp_priv_area = dev->priv;
873 sdla_t *card = ppp_priv_area->card;
874 unsigned char *sendpacket;
875 unsigned long smp_flags;
876 ppp_flags_t *flags = card->flags;
877 int udp_type;
878 int err=0;
879
880 ++ppp_priv_area->if_send_stat.if_send_entry;
881
882 netif_stop_queue(dev);
883
884 if (skb == NULL) {
885
886 /* If we get here, some higher layer thinks we've missed an
887 * tx-done interrupt.
888 */
889 printk(KERN_INFO "%s: interface %s got kicked!\n",
890 card->devname, dev->name);
891
892 ++ppp_priv_area->if_send_stat.if_send_skb_null;
893
894 netif_wake_queue(dev);
895 return 0;
896 }
897
898 sendpacket = skb->data;
899
900 udp_type = udp_pkt_type( skb, card );
901
902
903 if (udp_type == UDP_PTPIPE_TYPE){
904 if(store_udp_mgmt_pkt(UDP_PKT_FRM_STACK, card, skb, dev,
905 ppp_priv_area)){
906 flags->imask |= PPP_INTR_TIMER;
907 }
908 ++ppp_priv_area->if_send_stat.if_send_PIPE_request;
909 netif_start_queue(dev);
910 return 0;
911 }
912
913 /* Check for broadcast and multicast addresses
914 * If found, drop (deallocate) a packet and return.
915 */
916 if(chk_bcast_mcast_addr(card, dev, skb)){
917 ++card->wandev.stats.tx_dropped;
918 dev_kfree_skb_any(skb);
919 netif_start_queue(dev);
920 return 0;
921 }
922
923
924 if(card->hw.type != SDLA_S514){
925 s508_lock(card,&smp_flags);
926 }
927
928 if (test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
929
930 printk(KERN_INFO "%s: Critical in if_send: %lx\n",
931 card->wandev.name,card->wandev.critical);
932
933 ++card->wandev.stats.tx_dropped;
934 ++ppp_priv_area->if_send_stat.if_send_critical_non_ISR;
935 netif_start_queue(dev);
936 goto if_send_exit_crit;
937 }
938
939 if (card->wandev.state != WAN_CONNECTED) {
940
941 ++ppp_priv_area->if_send_stat.if_send_wan_disconnected;
942 ++card->wandev.stats.tx_dropped;
943 netif_start_queue(dev);
944
945 } else if (!skb->protocol) {
946 ++ppp_priv_area->if_send_stat.if_send_protocol_error;
947 ++card->wandev.stats.tx_errors;
948 netif_start_queue(dev);
949
950 } else {
951
952 /*If it's IPX change the network numbers to 0 if they're ours.*/
953 if( skb->protocol == htons(ETH_P_IPX) ) {
954 if(ppp_priv_area->enable_IPX) {
955 switch_net_numbers( skb->data,
956 ppp_priv_area->network_number, 0);
957 } else {
958 ++card->wandev.stats.tx_dropped;
959 netif_start_queue(dev);
960 goto if_send_exit_crit;
961 }
962 }
963
964 if (ppp_send(card, skb->data, skb->len, skb->protocol)) {
965 netif_stop_queue(dev);
966 ++ppp_priv_area->if_send_stat.if_send_adptr_bfrs_full;
967 ++ppp_priv_area->if_send_stat.if_send_tx_int_enabled;
968 } else {
969 ++ppp_priv_area->if_send_stat.if_send_bfr_passed_to_adptr;
970 ++card->wandev.stats.tx_packets;
971 card->wandev.stats.tx_bytes += skb->len;
972 netif_start_queue(dev);
973 dev->trans_start = jiffies;
974 }
975 }
976
977if_send_exit_crit:
978
979 if (!(err=netif_queue_stopped(dev))){
980 dev_kfree_skb_any(skb);
981 }else{
982 ppp_priv_area->tick_counter = jiffies;
983 flags->imask |= PPP_INTR_TXRDY; /* unmask Tx interrupts */
984 }
985
986 clear_bit(SEND_CRIT,&card->wandev.critical);
987 if(card->hw.type != SDLA_S514){
988 s508_unlock(card,&smp_flags);
989 }
990
991 return err;
992}
993
994
995/*=============================================================================
996 * Store a UDP management packet for later processing.
997 */
998
999static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
1000 struct sk_buff *skb, struct net_device* dev,
1001 ppp_private_area_t* ppp_priv_area )
1002{
1003 int udp_pkt_stored = 0;
1004
1005 if(!ppp_priv_area->udp_pkt_lgth && (skb->len<=MAX_LGTH_UDP_MGNT_PKT)){
1006 ppp_priv_area->udp_pkt_lgth = skb->len;
1007 ppp_priv_area->udp_pkt_src = udp_pkt_src;
1008 memcpy(ppp_priv_area->udp_pkt_data, skb->data, skb->len);
1009 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_UDP;
1010 ppp_priv_area->protocol = skb->protocol;
1011 udp_pkt_stored = 1;
1012 }else{
1013 if (skb->len > MAX_LGTH_UDP_MGNT_PKT){
1014 printk(KERN_INFO "%s: PIPEMON UDP request too long : %i\n",
1015 card->devname, skb->len);
1016 }else{
1017 printk(KERN_INFO "%s: PIPEMON UPD request already pending\n",
1018 card->devname);
1019 }
1020 ppp_priv_area->udp_pkt_lgth = 0;
1021 }
1022
1023 if(udp_pkt_src == UDP_PKT_FRM_STACK){
1024 dev_kfree_skb_any(skb);
1025 }else{
1026 dev_kfree_skb_any(skb);
1027 }
1028
1029 return(udp_pkt_stored);
1030}
1031
1032
1033
1034/*============================================================================
1035 * Reply to UDP Management system.
1036 * Return length of reply.
1037 */
1038static int reply_udp( unsigned char *data, unsigned int mbox_len )
1039{
1040 unsigned short len, udp_length, temp, ip_length;
1041 unsigned long ip_temp;
1042 int even_bound = 0;
1043 ppp_udp_pkt_t *p_udp_pkt = (ppp_udp_pkt_t *)data;
1044
1045 /* Set length of packet */
1046 len = sizeof(ip_pkt_t)+
1047 sizeof(udp_pkt_t)+
1048 sizeof(wp_mgmt_t)+
1049 sizeof(cblock_t)+
1050 mbox_len;
1051
1052 /* fill in UDP reply */
1053 p_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
1054
1055 /* fill in UDP length */
1056 udp_length = sizeof(udp_pkt_t)+
1057 sizeof(wp_mgmt_t)+
1058 sizeof(cblock_t)+
1059 mbox_len;
1060
1061
1062 /* put it on an even boundary */
1063 if ( udp_length & 0x0001 ) {
1064 udp_length += 1;
1065 len += 1;
1066 even_bound=1;
1067 }
1068
1069 temp = (udp_length<<8)|(udp_length>>8);
1070 p_udp_pkt->udp_pkt.udp_length = temp;
1071
1072
1073 /* swap UDP ports */
1074 temp = p_udp_pkt->udp_pkt.udp_src_port;
1075 p_udp_pkt->udp_pkt.udp_src_port =
1076 p_udp_pkt->udp_pkt.udp_dst_port;
1077 p_udp_pkt->udp_pkt.udp_dst_port = temp;
1078
1079
1080 /* add UDP pseudo header */
1081 temp = 0x1100;
1082 *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound)) = temp;
1083 temp = (udp_length<<8)|(udp_length>>8);
1084 *((unsigned short *)(p_udp_pkt->data+mbox_len+even_bound+2)) = temp;
1085
1086 /* calculate UDP checksum */
1087 p_udp_pkt->udp_pkt.udp_checksum = 0;
1088 p_udp_pkt->udp_pkt.udp_checksum =
1089 calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
1090
1091 /* fill in IP length */
1092 ip_length = udp_length + sizeof(ip_pkt_t);
1093 temp = (ip_length<<8)|(ip_length>>8);
1094 p_udp_pkt->ip_pkt.total_length = temp;
1095
1096 /* swap IP addresses */
1097 ip_temp = p_udp_pkt->ip_pkt.ip_src_address;
1098 p_udp_pkt->ip_pkt.ip_src_address = p_udp_pkt->ip_pkt.ip_dst_address;
1099 p_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
1100
1101 /* fill in IP checksum */
1102 p_udp_pkt->ip_pkt.hdr_checksum = 0;
1103 p_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
1104
1105 return len;
1106
1107} /* reply_udp */
1108
1109unsigned short calc_checksum (char *data, int len)
1110{
1111 unsigned short temp;
1112 unsigned long sum=0;
1113 int i;
1114
1115 for( i = 0; i <len; i+=2 ) {
1116 memcpy(&temp,&data[i],2);
1117 sum += (unsigned long)temp;
1118 }
1119
1120 while (sum >> 16 ) {
1121 sum = (sum & 0xffffUL) + (sum >> 16);
1122 }
1123
1124 temp = (unsigned short)sum;
1125 temp = ~temp;
1126
1127 if( temp == 0 )
1128 temp = 0xffff;
1129
1130 return temp;
1131}
1132
1133/*
1134 If incoming is 0 (outgoing)- if the net numbers is ours make it 0
1135 if incoming is 1 - if the net number is 0 make it ours
1136
1137*/
1138static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming)
1139{
1140 unsigned long pnetwork_number;
1141
1142 pnetwork_number = (unsigned long)((sendpacket[6] << 24) +
1143 (sendpacket[7] << 16) + (sendpacket[8] << 8) +
1144 sendpacket[9]);
1145
1146 if (!incoming) {
1147 //If the destination network number is ours, make it 0
1148 if( pnetwork_number == network_number) {
1149 sendpacket[6] = sendpacket[7] = sendpacket[8] =
1150 sendpacket[9] = 0x00;
1151 }
1152 } else {
1153 //If the incoming network is 0, make it ours
1154 if( pnetwork_number == 0) {
1155 sendpacket[6] = (unsigned char)(network_number >> 24);
1156 sendpacket[7] = (unsigned char)((network_number &
1157 0x00FF0000) >> 16);
1158 sendpacket[8] = (unsigned char)((network_number &
1159 0x0000FF00) >> 8);
1160 sendpacket[9] = (unsigned char)(network_number &
1161 0x000000FF);
1162 }
1163 }
1164
1165
1166 pnetwork_number = (unsigned long)((sendpacket[18] << 24) +
1167 (sendpacket[19] << 16) + (sendpacket[20] << 8) +
1168 sendpacket[21]);
1169
1170 if( !incoming ) {
1171 //If the source network is ours, make it 0
1172 if( pnetwork_number == network_number) {
1173 sendpacket[18] = sendpacket[19] = sendpacket[20] =
1174 sendpacket[21] = 0x00;
1175 }
1176 } else {
1177 //If the source network is 0, make it ours
1178 if( pnetwork_number == 0 ) {
1179 sendpacket[18] = (unsigned char)(network_number >> 24);
1180 sendpacket[19] = (unsigned char)((network_number &
1181 0x00FF0000) >> 16);
1182 sendpacket[20] = (unsigned char)((network_number &
1183 0x0000FF00) >> 8);
1184 sendpacket[21] = (unsigned char)(network_number &
1185 0x000000FF);
1186 }
1187 }
1188} /* switch_net_numbers */
1189
1190/*============================================================================
1191 * Get ethernet-style interface statistics.
1192 * Return a pointer to struct net_device_stats.
1193 */
1194static struct net_device_stats *if_stats(struct net_device *dev)
1195{
1196
1197 ppp_private_area_t *ppp_priv_area = dev->priv;
1198 sdla_t* card;
1199
1200 if( ppp_priv_area == NULL )
1201 return NULL;
1202
1203 card = ppp_priv_area->card;
1204 return &card->wandev.stats;
1205}
1206
1207/****** PPP Firmware Interface Functions ************************************/
1208
1209/*============================================================================
1210 * Read firmware code version.
1211 * Put code version as ASCII string in str.
1212 */
1213static int ppp_read_version(sdla_t *card, char *str)
1214{
1215 ppp_mbox_t *mb = card->mbox;
1216 int err;
1217
1218 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1219 mb->cmd.command = PPP_READ_CODE_VERSION;
1220 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1221
1222 if (err != CMD_OK)
1223
1224 ppp_error(card, err, mb);
1225
1226 else if (str) {
1227
1228 int len = mb->cmd.length;
1229
1230 memcpy(str, mb->data, len);
1231 str[len] = '\0';
1232
1233 }
1234
1235 return err;
1236}
1237/*===========================================================================
1238 * Set Out-Bound Authentication.
1239*/
1240static int ppp_set_outbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
1241{
1242 ppp_mbox_t *mb = card->mbox;
1243 int err;
1244
1245 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1246 memset(&mb->data, 0, (strlen(ppp_priv_area->userid) +
1247 strlen(ppp_priv_area->passwd) + 2 ) );
1248 memcpy(mb->data, ppp_priv_area->userid, strlen(ppp_priv_area->userid));
1249 memcpy((mb->data + strlen(ppp_priv_area->userid) + 1),
1250 ppp_priv_area->passwd, strlen(ppp_priv_area->passwd));
1251
1252 mb->cmd.length = strlen(ppp_priv_area->userid) +
1253 strlen(ppp_priv_area->passwd) + 2 ;
1254
1255 mb->cmd.command = PPP_SET_OUTBOUND_AUTH;
1256
1257 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1258
1259 if (err != CMD_OK)
1260 ppp_error(card, err, mb);
1261
1262 return err;
1263}
1264
1265/*===========================================================================
1266 * Set In-Bound Authentication.
1267*/
1268static int ppp_set_inbnd_auth (sdla_t *card, ppp_private_area_t *ppp_priv_area)
1269{
1270 ppp_mbox_t *mb = card->mbox;
1271 int err, i;
1272 char* user_tokens[32];
1273 char* pass_tokens[32];
1274 int userids, passwds;
1275 int add_ptr;
1276
1277 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1278 memset(&mb->data, 0, 1008);
1279 memcpy(mb->data, ppp_priv_area->sysname,
1280 strlen(ppp_priv_area->sysname));
1281
1282 /* Parse the userid string and the password string and build a string
1283 to copy it to the data area of the command structure. The string
1284 will look like "SYS_NAME<NULL>USER1<NULL>PASS1<NULL>USER2<NULL>PASS2
1285 ....<NULL> "
1286 */
1287 userids = tokenize( ppp_priv_area->userid, user_tokens);
1288 passwds = tokenize( ppp_priv_area->passwd, pass_tokens);
1289
1290 if (userids != passwds){
1291 printk(KERN_INFO "%s: Number of passwords does not equal the number of user ids\n", card->devname);
1292 return 1;
1293 }
1294
1295 add_ptr = strlen(ppp_priv_area->sysname) + 1;
1296 for (i=0; i<userids; i++){
1297 memcpy((mb->data + add_ptr), user_tokens[i],
1298 strlen(user_tokens[i]));
1299 memcpy((mb->data + add_ptr + strlen(user_tokens[i]) + 1),
1300 pass_tokens[i], strlen(pass_tokens[i]));
1301 add_ptr = add_ptr + strlen(user_tokens[i]) + 1 +
1302 strlen(pass_tokens[i]) + 1;
1303 }
1304
1305 mb->cmd.length = add_ptr + 1;
1306 mb->cmd.command = PPP_SET_INBOUND_AUTH;
1307
1308 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1309
1310 if (err != CMD_OK)
1311 ppp_error(card, err, mb);
1312
1313 return err;
1314}
1315
1316
1317/*============================================================================
1318 * Tokenize string.
1319 * Parse a string of the following syntax:
1320 * <arg1>,<arg2>,...
1321 * and fill array of tokens with pointers to string elements.
1322 *
1323 */
1324static int tokenize (char *str, char **tokens)
1325{
1326 int cnt = 0;
1327
1328 tokens[0] = strsep(&str, "/");
1329 while (tokens[cnt] && (cnt < 32 - 1))
1330 {
1331 tokens[cnt] = strstrip(tokens[cnt], " \t");
1332 tokens[++cnt] = strsep(&str, "/");
1333 }
1334 return cnt;
1335}
1336
1337/*============================================================================
1338 * Strip leading and trailing spaces off the string str.
1339 */
1340static char* strstrip (char *str, char* s)
1341{
1342 char *eos = str + strlen(str); /* -> end of string */
1343
1344 while (*str && strchr(s, *str))
1345 ++str /* strip leading spaces */
1346 ;
1347 while ((eos > str) && strchr(s, *(eos - 1)))
1348 --eos /* strip trailing spaces */
1349 ;
1350 *eos = '\0';
1351 return str;
1352}
1353/*============================================================================
1354 * Configure PPP firmware.
1355 */
1356static int ppp_configure(sdla_t *card, void *data)
1357{
1358 ppp_mbox_t *mb = card->mbox;
1359 int data_len = sizeof(ppp508_conf_t);
1360 int err;
1361
1362 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1363 memcpy(mb->data, data, data_len);
1364 mb->cmd.length = data_len;
1365 mb->cmd.command = PPP_SET_CONFIG;
1366 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1367
1368 if (err != CMD_OK)
1369 ppp_error(card, err, mb);
1370
1371 return err;
1372}
1373
1374/*============================================================================
1375 * Set interrupt mode.
1376 */
1377static int ppp_set_intr_mode(sdla_t *card, unsigned char mode)
1378{
1379 ppp_mbox_t *mb = card->mbox;
1380 ppp_intr_info_t *ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
1381 int err;
1382
1383 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1384 ppp_intr_data->i_enable = mode;
1385
1386 ppp_intr_data->irq = card->hw.irq;
1387 mb->cmd.length = 2;
1388
1389 /* If timer has been enabled, set the timer delay to 1sec */
1390 if (mode & 0x80){
1391 ppp_intr_data->timer_len = 250; //5;//100; //250;
1392 mb->cmd.length = 4;
1393 }
1394
1395 mb->cmd.command = PPP_SET_INTR_FLAGS;
1396 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1397
1398 if (err != CMD_OK)
1399 ppp_error(card, err, mb);
1400
1401
1402 return err;
1403}
1404
1405/*============================================================================
1406 * Enable communications.
1407 */
1408static int ppp_comm_enable(sdla_t *card)
1409{
1410 ppp_mbox_t *mb = card->mbox;
1411 int err;
1412
1413 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1414 mb->cmd.command = PPP_COMM_ENABLE;
1415 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1416
1417 if (err != CMD_OK)
1418 ppp_error(card, err, mb);
1419 else
1420 card->u.p.comm_enabled = 1;
1421
1422 return err;
1423}
1424
1425/*============================================================================
1426 * Disable communications.
1427 */
1428static int ppp_comm_disable(sdla_t *card)
1429{
1430 ppp_mbox_t *mb = card->mbox;
1431 int err;
1432
1433 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1434 mb->cmd.command = PPP_COMM_DISABLE;
1435 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1436 if (err != CMD_OK)
1437 ppp_error(card, err, mb);
1438 else
1439 card->u.p.comm_enabled = 0;
1440
1441 return err;
1442}
1443
1444static int ppp_comm_disable_shutdown(sdla_t *card)
1445{
1446 ppp_mbox_t *mb = card->mbox;
1447 ppp_intr_info_t *ppp_intr_data;
1448 int err;
1449
1450 if (!mb){
1451 return 1;
1452 }
1453
1454 ppp_intr_data = (ppp_intr_info_t *) &mb->data[0];
1455
1456 /* Disable all interrupts */
1457 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1458 ppp_intr_data->i_enable = 0;
1459
1460 ppp_intr_data->irq = card->hw.irq;
1461 mb->cmd.length = 2;
1462
1463 mb->cmd.command = PPP_SET_INTR_FLAGS;
1464 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1465
1466 /* Disable communicatinons */
1467 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1468 mb->cmd.command = PPP_COMM_DISABLE;
1469 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1470
1471 card->u.p.comm_enabled = 0;
1472
1473 return 0;
1474}
1475
1476
1477
1478/*============================================================================
1479 * Get communications error statistics.
1480 */
1481static int ppp_get_err_stats(sdla_t *card)
1482{
1483 ppp_mbox_t *mb = card->mbox;
1484 int err;
1485
1486 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
1487 mb->cmd.command = PPP_READ_ERROR_STATS;
1488 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
1489
1490 if (err == CMD_OK) {
1491
1492 ppp_err_stats_t* stats = (void*)mb->data;
1493 card->wandev.stats.rx_over_errors = stats->rx_overrun;
1494 card->wandev.stats.rx_crc_errors = stats->rx_bad_crc;
1495 card->wandev.stats.rx_missed_errors = stats->rx_abort;
1496 card->wandev.stats.rx_length_errors = stats->rx_lost;
1497 card->wandev.stats.tx_aborted_errors = stats->tx_abort;
1498
1499 } else
1500 ppp_error(card, err, mb);
1501
1502 return err;
1503}
1504
1505/*============================================================================
1506 * Send packet.
1507 * Return: 0 - o.k.
1508 * 1 - no transmit buffers available
1509 */
1510static int ppp_send (sdla_t *card, void *data, unsigned len, unsigned proto)
1511{
1512 ppp_buf_ctl_t *txbuf = card->u.p.txbuf;
1513
1514 if (txbuf->flag)
1515 return 1;
1516
1517 sdla_poke(&card->hw, txbuf->buf.ptr, data, len);
1518
1519 txbuf->length = len; /* frame length */
1520
1521 if (proto == htons(ETH_P_IPX))
1522 txbuf->proto = 0x01; /* protocol ID */
1523 else
1524 txbuf->proto = 0x00; /* protocol ID */
1525
1526 txbuf->flag = 1; /* start transmission */
1527
1528 /* Update transmit buffer control fields */
1529 card->u.p.txbuf = ++txbuf;
1530
1531 if ((void*)txbuf > card->u.p.txbuf_last)
1532 card->u.p.txbuf = card->u.p.txbuf_base;
1533
1534 return 0;
1535}
1536
1537/****** Firmware Error Handler **********************************************/
1538
1539/*============================================================================
1540 * Firmware error handler.
1541 * This routine is called whenever firmware command returns non-zero
1542 * return code.
1543 *
1544 * Return zero if previous command has to be cancelled.
1545 */
1546static int ppp_error(sdla_t *card, int err, ppp_mbox_t *mb)
1547{
1548 unsigned cmd = mb->cmd.command;
1549
1550 switch (err) {
1551
1552 case CMD_TIMEOUT:
1553 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
1554 card->devname, cmd);
1555 break;
1556
1557 default:
1558 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n"
1559 , card->devname, cmd, err);
1560 }
1561
1562 return 0;
1563}
1564
1565/****** Interrupt Handlers **************************************************/
1566
1567/*============================================================================
1568 * PPP interrupt service routine.
1569 */
1570static void wpp_isr (sdla_t *card)
1571{
1572 ppp_flags_t *flags = card->flags;
1573 char *ptr = &flags->iflag;
1574 struct net_device *dev = card->wandev.dev;
1575 int i;
1576
1577 card->in_isr = 1;
1578 ++card->statistics.isr_entry;
1579
1580 if (!dev && flags->iflag != PPP_INTR_CMD){
1581 card->in_isr = 0;
1582 flags->iflag = 0;
1583 return;
1584 }
1585
1586 if (test_bit(PERI_CRIT, (void*)&card->wandev.critical)) {
1587 card->in_isr = 0;
1588 flags->iflag = 0;
1589 return;
1590 }
1591
1592
1593 if(card->hw.type != SDLA_S514){
1594 if (test_bit(SEND_CRIT, (void*)&card->wandev.critical)) {
1595 ++card->statistics.isr_already_critical;
1596 printk (KERN_INFO "%s: Critical while in ISR!\n",
1597 card->devname);
1598 card->in_isr = 0;
1599 flags->iflag = 0;
1600 return;
1601 }
1602 }
1603
1604 switch (flags->iflag) {
1605
1606 case PPP_INTR_RXRDY: /* receive interrupt 0x01 (bit 0)*/
1607 ++card->statistics.isr_rx;
1608 rx_intr(card);
1609 break;
1610
1611 case PPP_INTR_TXRDY: /* transmit interrupt 0x02 (bit 1)*/
1612 ++card->statistics.isr_tx;
1613 flags->imask &= ~PPP_INTR_TXRDY;
1614 netif_wake_queue(dev);
1615 break;
1616
1617 case PPP_INTR_CMD: /* interface command completed */
1618 ++Intr_test_counter;
1619 ++card->statistics.isr_intr_test;
1620 break;
1621
1622 case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
1623 case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
1624 case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
1625 case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
1626 event_intr(card);
1627 break;
1628
1629 case PPP_INTR_TIMER:
1630 timer_intr(card);
1631 break;
1632
1633 default: /* unexpected interrupt */
1634 ++card->statistics.isr_spurious;
1635 printk(KERN_INFO "%s: spurious interrupt 0x%02X!\n",
1636 card->devname, flags->iflag);
1637 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1638 for(i = 0; i < 8; i ++)
1639 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1640 printk(KERN_INFO "\n");
1641 }
1642
1643 card->in_isr = 0;
1644 flags->iflag = 0;
1645 return;
1646}
1647
1648/*============================================================================
1649 * Receive interrupt handler.
1650 */
1651static void rx_intr(sdla_t *card)
1652{
1653 ppp_buf_ctl_t *rxbuf = card->rxmb;
1654 struct net_device *dev = card->wandev.dev;
1655 ppp_private_area_t *ppp_priv_area;
1656 struct sk_buff *skb;
1657 unsigned len;
1658 void *buf;
1659 int i;
1660 ppp_flags_t *flags = card->flags;
1661 char *ptr = &flags->iflag;
1662 int udp_type;
1663
1664
1665 if (rxbuf->flag != 0x01) {
1666
1667 printk(KERN_INFO
1668 "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
1669 card->devname, (unsigned)rxbuf, rxbuf->flag);
1670
1671 printk(KERN_INFO "%s: ID Bytes = ",card->devname);
1672
1673 for(i = 0; i < 8; i ++)
1674 printk(KERN_INFO "0x%02X ", *(ptr + 0x28 + i));
1675 printk(KERN_INFO "\n");
1676
1677 ++card->statistics.rx_intr_corrupt_rx_bfr;
1678
1679
1680 /* Bug Fix: Mar 6 2000
1681 * If we get a corrupted mailbox, it means that driver
1682 * is out of sync with the firmware. There is no recovery.
1683 * If we don't turn off all interrupts for this card
1684 * the machine will crash.
1685 */
1686 printk(KERN_INFO "%s: Critical router failure ...!!!\n", card->devname);
1687 printk(KERN_INFO "Please contact Sangoma Technologies !\n");
1688 ppp_set_intr_mode(card,0);
1689 return;
1690 }
1691
1692 if (dev && netif_running(dev) && dev->priv){
1693
1694 len = rxbuf->length;
1695 ppp_priv_area = dev->priv;
1696
1697 /* Allocate socket buffer */
1698 skb = dev_alloc_skb(len);
1699
1700 if (skb != NULL) {
1701
1702 /* Copy data to the socket buffer */
1703 unsigned addr = rxbuf->buf.ptr;
1704
1705 if ((addr + len) > card->u.p.rx_top + 1) {
1706
1707 unsigned tmp = card->u.p.rx_top - addr + 1;
1708 buf = skb_put(skb, tmp);
1709 sdla_peek(&card->hw, addr, buf, tmp);
1710 addr = card->u.p.rx_base;
1711 len -= tmp;
1712 }
1713 buf = skb_put(skb, len);
1714 sdla_peek(&card->hw, addr, buf, len);
1715
1716 /* Decapsulate packet */
1717 switch (rxbuf->proto) {
1718
1719 case 0x00:
1720 skb->protocol = htons(ETH_P_IP);
1721 break;
1722
1723 case 0x01:
1724 skb->protocol = htons(ETH_P_IPX);
1725 break;
1726 }
1727
1728 udp_type = udp_pkt_type( skb, card );
1729
1730 if (udp_type == UDP_PTPIPE_TYPE){
1731
1732 /* Handle a UDP Request in Timer Interrupt */
1733 if(store_udp_mgmt_pkt(UDP_PKT_FRM_NETWORK, card, skb, dev,
1734 ppp_priv_area)){
1735 flags->imask |= PPP_INTR_TIMER;
1736 }
1737 ++ppp_priv_area->rx_intr_stat.rx_intr_PIPE_request;
1738
1739
1740 } else if (handle_IPXWAN(skb->data,card->devname,
1741 ppp_priv_area->enable_IPX,
1742 ppp_priv_area->network_number,
1743 skb->protocol)) {
1744
1745 /* Handle an IPXWAN packet */
1746 if( ppp_priv_area->enable_IPX) {
1747
1748 /* Make sure we are not already sending */
1749 if (!test_bit(SEND_CRIT, &card->wandev.critical)){
1750 ppp_send(card, skb->data, skb->len, htons(ETH_P_IPX));
1751 }
1752 dev_kfree_skb_any(skb);
1753
1754 } else {
1755 ++card->wandev.stats.rx_dropped;
1756 }
1757 } else {
1758 /* Pass data up the protocol stack */
1759 skb->dev = dev;
1760 skb->mac.raw = skb->data;
1761
1762 ++card->wandev.stats.rx_packets;
1763 card->wandev.stats.rx_bytes += skb->len;
1764 ++ppp_priv_area->rx_intr_stat.rx_intr_bfr_passed_to_stack;
1765 netif_rx(skb);
1766 dev->last_rx = jiffies;
1767 }
1768
1769 } else {
1770
1771 if (net_ratelimit()){
1772 printk(KERN_INFO "%s: no socket buffers available!\n",
1773 card->devname);
1774 }
1775 ++card->wandev.stats.rx_dropped;
1776 ++ppp_priv_area->rx_intr_stat.rx_intr_no_socket;
1777 }
1778
1779 } else {
1780 ++card->statistics.rx_intr_dev_not_started;
1781 }
1782
1783 /* Release buffer element and calculate a pointer to the next one */
1784 rxbuf->flag = 0x00;
1785 card->rxmb = ++rxbuf;
1786 if ((void*)rxbuf > card->u.p.rxbuf_last)
1787 card->rxmb = card->u.p.rxbuf_base;
1788}
1789
1790
1791void event_intr (sdla_t *card)
1792{
1793
1794 struct net_device* dev = card->wandev.dev;
1795 ppp_private_area_t* ppp_priv_area = dev->priv;
1796 volatile ppp_flags_t *flags = card->flags;
1797
1798 switch (flags->iflag){
1799
1800 case PPP_INTR_MODEM: /* modem status change (DCD, CTS) 0x04 (bit 2)*/
1801
1802 if (net_ratelimit()){
1803 printk (KERN_INFO "%s: Modem status: DCD=%s CTS=%s\n",
1804 card->devname, DCD(flags->mstatus), CTS(flags->mstatus));
1805 }
1806 break;
1807
1808 case PPP_INTR_DISC: /* Data link disconnected 0x10 (bit 4)*/
1809
1810 NEX_PRINTK (KERN_INFO "Data link disconnected intr Cause %X\n",
1811 flags->disc_cause);
1812
1813 if (flags->disc_cause &
1814 (PPP_LOCAL_TERMINATION | PPP_DCD_CTS_DROP |
1815 PPP_REMOTE_TERMINATION)) {
1816
1817 if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
1818 set_bit(0,&Read_connection_info);
1819 }
1820 wanpipe_set_state(card, WAN_DISCONNECTED);
1821
1822 show_disc_cause(card, flags->disc_cause);
1823 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
1824 flags->imask |= PPP_INTR_TIMER;
1825 trigger_ppp_poll(dev);
1826 }
1827 break;
1828
1829 case PPP_INTR_OPEN: /* Data link open 0x20 (bit 5)*/
1830
1831 NEX_PRINTK (KERN_INFO "%s: PPP Link Open, LCP=%s IP=%s\n",
1832 card->devname,LCP(flags->lcp_state),
1833 IP(flags->ip_state));
1834
1835 if (flags->lcp_state == 0x09 &&
1836 (flags->ip_state == 0x09 || flags->ipx_state == 0x09)){
1837
1838 /* Initialize the polling timer and set the state
1839 * to WAN_CONNNECTED */
1840
1841
1842 /* BUG FIX: When the protocol restarts, during heavy
1843 * traffic, board tx buffers and driver tx buffers
1844 * can go out of sync. This checks the condition
1845 * and if the tx buffers are out of sync, the
1846 * protocols are restarted.
1847 * I don't know why the board tx buffer is out
1848 * of sync. It could be that a packets is tx
1849 * while the link is down, but that is not
1850 * possible. The other possiblility is that the
1851 * firmware doesn't reinitialize properly.
1852 * FIXME: A better fix should be found.
1853 */
1854 if (detect_and_fix_tx_bug(card)){
1855
1856 ppp_comm_disable(card);
1857
1858 wanpipe_set_state(card, WAN_DISCONNECTED);
1859
1860 ppp_priv_area->timer_int_enabled |=
1861 TMR_INT_ENABLED_PPP_EVENT;
1862 flags->imask |= PPP_INTR_TIMER;
1863 break;
1864 }
1865
1866 card->state_tick = jiffies;
1867 wanpipe_set_state(card, WAN_CONNECTED);
1868
1869 NEX_PRINTK(KERN_INFO "CON: L Tx: %lx B Tx: %lx || L Rx %lx B Rx %lx\n",
1870 (unsigned long)card->u.p.txbuf, *card->u.p.txbuf_next,
1871 (unsigned long)card->rxmb, *card->u.p.rxbuf_next);
1872
1873 /* Tell timer interrupt that PPP event occurred */
1874 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
1875 flags->imask |= PPP_INTR_TIMER;
1876
1877 /* If we are in PEER mode, we must first obtain the
1878 * IP information and then go into the poll routine */
1879 if (card->u.p.ip_mode != WANOPT_PPP_PEER){
1880 trigger_ppp_poll(dev);
1881 }
1882 }
1883 break;
1884
1885 case PPP_INTR_DROP_DTR: /* DTR drop timeout expired 0x40 bit 6 */
1886
1887 NEX_PRINTK(KERN_INFO "DTR Drop Timeout Interrrupt \n");
1888
1889 if (card->u.p.ip_mode == WANOPT_PPP_PEER) {
1890 set_bit(0,&Read_connection_info);
1891 }
1892
1893 wanpipe_set_state(card, WAN_DISCONNECTED);
1894
1895 show_disc_cause(card, flags->disc_cause);
1896 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_PPP_EVENT;
1897 flags->imask |= PPP_INTR_TIMER;
1898 trigger_ppp_poll(dev);
1899 break;
1900
1901 default:
1902 printk(KERN_INFO "%s: Error, Invalid PPP Event\n",card->devname);
1903 }
1904}
1905
1906
1907
1908/* TIMER INTERRUPT */
1909
1910void timer_intr (sdla_t *card)
1911{
1912
1913 struct net_device* dev = card->wandev.dev;
1914 ppp_private_area_t* ppp_priv_area = dev->priv;
1915 ppp_flags_t *flags = card->flags;
1916
1917
1918 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_CONFIG){
1919 if (!config_ppp(card)){
1920 ppp_priv_area->timer_int_enabled &=
1921 ~TMR_INT_ENABLED_CONFIG;
1922 }
1923 }
1924
1925 /* Update statistics */
1926 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UPDATE){
1927 ppp_get_err_stats(card);
1928 if(!(--ppp_priv_area->update_comms_stats)){
1929 ppp_priv_area->timer_int_enabled &=
1930 ~TMR_INT_ENABLED_UPDATE;
1931 }
1932 }
1933
1934 /* PPIPEMON UDP request */
1935
1936 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_UDP){
1937 process_udp_mgmt_pkt(card,dev, ppp_priv_area);
1938 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UDP;
1939 }
1940
1941 /* PPP Event */
1942 if (ppp_priv_area->timer_int_enabled & TMR_INT_ENABLED_PPP_EVENT){
1943
1944 if (card->wandev.state == WAN_DISCONNECTED){
1945 retrigger_comm(card);
1946 }
1947
1948 /* If the state is CONNECTING, it means that communicatins were
1949 * enabled. When the remote side enables its comminication we
1950 * should get an interrupt PPP_INTR_OPEN, thus turn off polling
1951 */
1952
1953 else if (card->wandev.state == WAN_CONNECTING){
1954 /* Turn off the timer interrupt */
1955 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
1956 }
1957
1958 /* If state is connected and we are in PEER mode
1959 * poll for an IP address which will be provided by remote end.
1960 */
1961 else if ((card->wandev.state == WAN_CONNECTED &&
1962 card->u.p.ip_mode == WANOPT_PPP_PEER) &&
1963 test_bit(0,&Read_connection_info)){
1964
1965 card->state_tick = jiffies;
1966 if (read_connection_info (card)){
1967 printk(KERN_INFO "%s: Failed to read PEER IP Addresses\n",
1968 card->devname);
1969 }else{
1970 clear_bit(0,&Read_connection_info);
1971 set_bit(1,&Read_connection_info);
1972 trigger_ppp_poll(dev);
1973 }
1974 }else{
1975 //FIXME Put the comment back int
1976 ppp_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_PPP_EVENT;
1977 }
1978
1979 }/* End of PPP_EVENT */
1980
1981
1982 /* Only disable the timer interrupt if there are no udp, statistic */
1983 /* updates or events pending */
1984 if(!ppp_priv_area->timer_int_enabled) {
1985 flags->imask &= ~PPP_INTR_TIMER;
1986 }
1987}
1988
1989
1990static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_IPX, unsigned long network_number, unsigned short proto)
1991{
1992 int i;
1993
1994 if( proto == htons(ETH_P_IPX) ) {
1995 //It's an IPX packet
1996 if(!enable_IPX) {
1997 //Return 1 so we don't pass it up the stack.
1998 return 1;
1999 }
2000 } else {
2001 //It's not IPX so pass it up the stack.
2002 return 0;
2003 }
2004
2005 if( sendpacket[16] == 0x90 &&
2006 sendpacket[17] == 0x04)
2007 {
2008 //It's IPXWAN
2009
2010 if( sendpacket[2] == 0x02 &&
2011 sendpacket[34] == 0x00)
2012 {
2013 //It's a timer request packet
2014 printk(KERN_INFO "%s: Received IPXWAN Timer Request packet\n",devname);
2015
2016 //Go through the routing options and answer no to every
2017 //option except Unnumbered RIP/SAP
2018 for(i = 41; sendpacket[i] == 0x00; i += 5)
2019 {
2020 //0x02 is the option for Unnumbered RIP/SAP
2021 if( sendpacket[i + 4] != 0x02)
2022 {
2023 sendpacket[i + 1] = 0;
2024 }
2025 }
2026
2027 //Skip over the extended Node ID option
2028 if( sendpacket[i] == 0x04 )
2029 {
2030 i += 8;
2031 }
2032
2033 //We also want to turn off all header compression opt.
2034 for(; sendpacket[i] == 0x80 ;)
2035 {
2036 sendpacket[i + 1] = 0;
2037 i += (sendpacket[i + 2] << 8) + (sendpacket[i + 3]) + 4;
2038 }
2039
2040 //Set the packet type to timer response
2041 sendpacket[34] = 0x01;
2042
2043 printk(KERN_INFO "%s: Sending IPXWAN Timer Response\n",devname);
2044 }
2045 else if( sendpacket[34] == 0x02 )
2046 {
2047 //This is an information request packet
2048 printk(KERN_INFO "%s: Received IPXWAN Information Request packet\n",devname);
2049
2050 //Set the packet type to information response
2051 sendpacket[34] = 0x03;
2052
2053 //Set the router name
2054 sendpacket[51] = 'P';
2055 sendpacket[52] = 'T';
2056 sendpacket[53] = 'P';
2057 sendpacket[54] = 'I';
2058 sendpacket[55] = 'P';
2059 sendpacket[56] = 'E';
2060 sendpacket[57] = '-';
2061 sendpacket[58] = CVHexToAscii(network_number >> 28);
2062 sendpacket[59] = CVHexToAscii((network_number & 0x0F000000)>> 24);
2063 sendpacket[60] = CVHexToAscii((network_number & 0x00F00000)>> 20);
2064 sendpacket[61] = CVHexToAscii((network_number & 0x000F0000)>> 16);
2065 sendpacket[62] = CVHexToAscii((network_number & 0x0000F000)>> 12);
2066 sendpacket[63] = CVHexToAscii((network_number & 0x00000F00)>> 8);
2067 sendpacket[64] = CVHexToAscii((network_number & 0x000000F0)>> 4);
2068 sendpacket[65] = CVHexToAscii(network_number & 0x0000000F);
2069 for(i = 66; i < 99; i+= 1)
2070 {
2071 sendpacket[i] = 0;
2072 }
2073
2074 printk(KERN_INFO "%s: Sending IPXWAN Information Response packet\n",devname);
2075 }
2076 else
2077 {
2078 printk(KERN_INFO "%s: Unknown IPXWAN packet!\n",devname);
2079 return 0;
2080 }
2081
2082 //Set the WNodeID to our network address
2083 sendpacket[35] = (unsigned char)(network_number >> 24);
2084 sendpacket[36] = (unsigned char)((network_number & 0x00FF0000) >> 16);
2085 sendpacket[37] = (unsigned char)((network_number & 0x0000FF00) >> 8);
2086 sendpacket[38] = (unsigned char)(network_number & 0x000000FF);
2087
2088 return 1;
2089 } else {
2090 //If we get here it's an IPX-data packet, so it'll get passed up the stack.
2091
2092 //switch the network numbers
2093 switch_net_numbers(sendpacket, network_number, 1);
2094 return 0;
2095 }
2096}
2097
2098/****** Background Polling Routines ****************************************/
2099
2100/* All polling functions are invoked by the TIMER interrupt in the wpp_isr
2101 * routine.
2102 */
2103
2104/*============================================================================
2105 * Monitor active link phase.
2106 */
2107static void process_route (sdla_t *card)
2108{
2109 ppp_flags_t *flags = card->flags;
2110 struct net_device *dev = card->wandev.dev;
2111 ppp_private_area_t *ppp_priv_area = dev->priv;
2112
2113 if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
2114 (flags->ip_state == 0x09)){
2115
2116 /* We get ip_local from the firmware in PEER mode.
2117 * Therefore, if ip_local is 0, we failed to obtain
2118 * the remote IP address. */
2119 if (ppp_priv_area->ip_local == 0)
2120 return;
2121
2122 printk(KERN_INFO "%s: IPCP State Opened.\n", card->devname);
2123 if (read_info( card )) {
2124 printk(KERN_INFO
2125 "%s: An error occurred in IP assignment.\n",
2126 card->devname);
2127 } else {
2128 struct in_device *in_dev = dev->ip_ptr;
2129 if (in_dev != NULL ) {
2130 struct in_ifaddr *ifa = in_dev->ifa_list;
2131
2132 printk(KERN_INFO "%s: Assigned Lcl. Addr: %u.%u.%u.%u\n",
2133 card->devname, NIPQUAD(ifa->ifa_local));
2134 printk(KERN_INFO "%s: Assigned Rmt. Addr: %u.%u.%u.%u\n",
2135 card->devname, NIPQUAD(ifa->ifa_address));
2136 }else{
2137 printk(KERN_INFO
2138 "%s: Error: Failed to add a route for PPP interface %s\n",
2139 card->devname,dev->name);
2140 }
2141 }
2142 }
2143}
2144
2145/*============================================================================
2146 * Monitor physical link disconnected phase.
2147 * o if interface is up and the hold-down timeout has expired, then retry
2148 * connection.
2149 */
2150static void retrigger_comm(sdla_t *card)
2151{
2152 struct net_device *dev = card->wandev.dev;
2153
2154 if (dev && ((jiffies - card->state_tick) > HOLD_DOWN_TIME)) {
2155
2156 wanpipe_set_state(card, WAN_CONNECTING);
2157
2158 if(ppp_comm_enable(card) == CMD_OK){
2159 init_ppp_tx_rx_buff( card );
2160 }
2161 }
2162}
2163
2164/****** Miscellaneous Functions *********************************************/
2165
2166/*============================================================================
2167 * Configure S508 adapter.
2168 */
2169static int config508(struct net_device *dev, sdla_t *card)
2170{
2171 ppp508_conf_t cfg;
2172 struct in_device *in_dev = dev->ip_ptr;
2173 ppp_private_area_t *ppp_priv_area = dev->priv;
2174
2175 /* Prepare PPP configuration structure */
2176 memset(&cfg, 0, sizeof(ppp508_conf_t));
2177
2178 if (card->wandev.clocking)
2179 cfg.line_speed = card->wandev.bps;
2180
2181 if (card->wandev.interface == WANOPT_RS232)
2182 cfg.conf_flags |= INTERFACE_LEVEL_RS232;
2183
2184
2185 cfg.conf_flags |= DONT_TERMINATE_LNK_MAX_CONFIG; /*send Configure-Request packets forever*/
2186 cfg.txbuf_percent = PERCENT_TX_BUFF; /* % of Tx bufs */
2187 cfg.mtu_local = card->wandev.mtu;
2188 cfg.mtu_remote = card->wandev.mtu; /* Default */
2189 cfg.restart_tmr = TIME_BETWEEN_CONF_REQ; /* 30 = 3sec */
2190 cfg.auth_rsrt_tmr = TIME_BETWEEN_PAP_CHAP_REQ; /* 30 = 3sec */
2191 cfg.auth_wait_tmr = WAIT_PAP_CHAP_WITHOUT_REPLY; /* 300 = 30s */
2192 cfg.mdm_fail_tmr = WAIT_AFTER_DCD_CTS_LOW; /* 5 = 0.5s */
2193 cfg.dtr_drop_tmr = TIME_DCD_CTS_LOW_AFTER_LNK_DOWN; /* 10 = 1s */
2194 cfg.connect_tmout = WAIT_DCD_HIGH_AFTER_ENABLE_COMM; /* 900 = 90s */
2195 cfg.conf_retry = MAX_CONF_REQ_WITHOUT_REPLY; /* 10 = 1s */
2196 cfg.term_retry = MAX_TERM_REQ_WITHOUT_REPLY; /* 2 times */
2197 cfg.fail_retry = NUM_CONF_NAK_WITHOUT_REPLY; /* 5 times */
2198 cfg.auth_retry = NUM_AUTH_REQ_WITHOUT_REPLY; /* 10 times */
2199
2200
2201 if( !card->u.p.authenticator ) {
2202 printk(KERN_INFO "%s: Device is not configured as an authenticator\n",
2203 card->devname);
2204 cfg.auth_options = NO_AUTHENTICATION;
2205 }else{
2206 printk(KERN_INFO "%s: Device is configured as an authenticator\n",
2207 card->devname);
2208 cfg.auth_options = INBOUND_AUTH;
2209 }
2210
2211 if( ppp_priv_area->pap == WANOPT_YES){
2212 cfg.auth_options |=PAP_AUTH;
2213 printk(KERN_INFO "%s: Pap enabled\n", card->devname);
2214 }
2215 if( ppp_priv_area->chap == WANOPT_YES){
2216 cfg.auth_options |= CHAP_AUTH;
2217 printk(KERN_INFO "%s: Chap enabled\n", card->devname);
2218 }
2219
2220
2221 if (ppp_priv_area->enable_IPX == WANOPT_YES){
2222 printk(KERN_INFO "%s: Enabling IPX Protocol\n",card->devname);
2223 cfg.ipx_options = ENABLE_IPX | ROUTING_PROT_DEFAULT;
2224 }else{
2225 cfg.ipx_options = DISABLE_IPX;
2226 }
2227
2228 switch (card->u.p.ip_mode) {
2229
2230 case WANOPT_PPP_STATIC:
2231
2232 printk(KERN_INFO "%s: PPP IP Mode: STATIC\n",card->devname);
2233 cfg.ip_options = L_AND_R_IP_NO_ASSIG |
2234 ENABLE_IP;
2235 cfg.ip_local = in_dev->ifa_list->ifa_local;
2236 cfg.ip_remote = in_dev->ifa_list->ifa_address;
2237 /* Debugging code used to check that IP addresses
2238 * obtained from the kernel are correct */
2239
2240 NEX_PRINTK(KERN_INFO "Local %u.%u.%u.%u Remote %u.%u.%u.%u Name %s\n",
2241 NIPQUAD(ip_local),NIPQUAD(ip_remote), dev->name);
2242 break;
2243
2244 case WANOPT_PPP_HOST:
2245
2246 printk(KERN_INFO "%s: PPP IP Mode: HOST\n",card->devname);
2247 cfg.ip_options = L_IP_LOCAL_ASSIG |
2248 R_IP_LOCAL_ASSIG |
2249 ENABLE_IP;
2250 cfg.ip_local = in_dev->ifa_list->ifa_local;
2251 cfg.ip_remote = in_dev->ifa_list->ifa_address;
2252 /* Debugging code used to check that IP addresses
2253 * obtained from the kernel are correct */
2254 NEX_PRINTK (KERN_INFO "Local %u.%u.%u.%u Remote %u.%u.%u.%u Name %s\n",
2255 NIPQUAD(ip_local),NIPQUAD(ip_remote), dev->name);
2256
2257 break;
2258
2259 case WANOPT_PPP_PEER:
2260
2261 printk(KERN_INFO "%s: PPP IP Mode: PEER\n",card->devname);
2262 cfg.ip_options = L_IP_REMOTE_ASSIG |
2263 R_IP_REMOTE_ASSIG |
2264 ENABLE_IP;
2265 cfg.ip_local = 0x00;
2266 cfg.ip_remote = 0x00;
2267 break;
2268
2269 default:
2270 printk(KERN_INFO "%s: ERROR: Unsupported PPP Mode Selected\n",
2271 card->devname);
2272 printk(KERN_INFO "%s: PPP IP Modes: STATIC, PEER or HOST\n",
2273 card->devname);
2274 return 1;
2275 }
2276
2277 return ppp_configure(card, &cfg);
2278}
2279
2280/*============================================================================
2281 * Show disconnection cause.
2282 */
2283static void show_disc_cause(sdla_t *card, unsigned cause)
2284{
2285 if (cause & 0x0802)
2286
2287 printk(KERN_INFO "%s: link terminated by peer\n",
2288 card->devname);
2289
2290 else if (cause & 0x0004)
2291
2292 printk(KERN_INFO "%s: link terminated by user\n",
2293 card->devname);
2294
2295 else if (cause & 0x0008)
2296
2297 printk(KERN_INFO "%s: authentication failed\n", card->devname);
2298
2299 else if (cause & 0x0010)
2300
2301 printk(KERN_INFO
2302 "%s: authentication protocol negotiation failed\n",
2303 card->devname);
2304
2305 else if (cause & 0x0020)
2306
2307 printk(KERN_INFO
2308 "%s: peer's request for authentication rejected\n",
2309 card->devname);
2310
2311 else if (cause & 0x0040)
2312
2313 printk(KERN_INFO "%s: MRU option rejected by peer\n",
2314 card->devname);
2315
2316 else if (cause & 0x0080)
2317
2318 printk(KERN_INFO "%s: peer's MRU was too small\n",
2319 card->devname);
2320
2321 else if (cause & 0x0100)
2322
2323 printk(KERN_INFO "%s: failed to negotiate peer's LCP options\n",
2324 card->devname);
2325
2326 else if (cause & 0x0200)
2327
2328 printk(KERN_INFO "%s: failed to negotiate peer's IPCP options\n"
2329 , card->devname);
2330
2331 else if (cause & 0x0400)
2332
2333 printk(KERN_INFO
2334 "%s: failed to negotiate peer's IPXCP options\n",
2335 card->devname);
2336}
2337
2338/*=============================================================================
2339 * Process UDP call of type PTPIPEAB.
2340 */
2341static void process_udp_mgmt_pkt(sdla_t *card, struct net_device *dev,
2342 ppp_private_area_t *ppp_priv_area )
2343{
2344 unsigned char buf2[5];
2345 unsigned char *buf;
2346 unsigned int frames, len;
2347 struct sk_buff *new_skb;
2348 unsigned short data_length, buffer_length, real_len;
2349 unsigned long data_ptr;
2350 int udp_mgmt_req_valid = 1;
2351 ppp_mbox_t *mbox = card->mbox;
2352 struct timeval tv;
2353 int err;
2354 ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t*)&ppp_priv_area->udp_pkt_data;
2355
2356 memcpy(&buf2, &card->wandev.udp_port, 2 );
2357
2358
2359 if(ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2360
2361 switch(ppp_udp_pkt->cblock.command) {
2362
2363 case PPIPE_GET_IBA_DATA:
2364 case PPP_READ_CONFIG:
2365 case PPP_GET_CONNECTION_INFO:
2366 case PPIPE_ROUTER_UP_TIME:
2367 case PPP_READ_STATISTICS:
2368 case PPP_READ_ERROR_STATS:
2369 case PPP_READ_PACKET_STATS:
2370 case PPP_READ_LCP_STATS:
2371 case PPP_READ_IPCP_STATS:
2372 case PPP_READ_IPXCP_STATS:
2373 case PPP_READ_PAP_STATS:
2374 case PPP_READ_CHAP_STATS:
2375 case PPP_READ_CODE_VERSION:
2376 udp_mgmt_req_valid = 1;
2377 break;
2378
2379 default:
2380 udp_mgmt_req_valid = 0;
2381 break;
2382 }
2383 }
2384
2385 if(!udp_mgmt_req_valid) {
2386
2387 /* set length to 0 */
2388 ppp_udp_pkt->cblock.length = 0x00;
2389
2390 /* set return code */
2391 ppp_udp_pkt->cblock.result = 0xCD;
2392 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_direction_err;
2393
2394 if (net_ratelimit()){
2395 printk(KERN_INFO
2396 "%s: Warning, Illegal UDP command attempted from network: %x\n",
2397 card->devname,ppp_udp_pkt->cblock.command);
2398 }
2399 } else {
2400 /* Initialize the trace element */
2401 trace_element_t trace_element;
2402
2403 switch (ppp_udp_pkt->cblock.command){
2404
2405 /* PPIPE_ENABLE_TRACING */
2406 case PPIPE_ENABLE_TRACING:
2407 if (!card->TracingEnabled) {
2408
2409 /* OPERATE_DATALINE_MONITOR */
2410 mbox->cmd.command = PPP_DATALINE_MONITOR;
2411 mbox->cmd.length = 0x01;
2412 mbox->data[0] = ppp_udp_pkt->data[0];
2413 err = sdla_exec(mbox) ?
2414 mbox->cmd.result : CMD_TIMEOUT;
2415
2416 if (err != CMD_OK) {
2417
2418 ppp_error(card, err, mbox);
2419 card->TracingEnabled = 0;
2420
2421 /* set the return code */
2422
2423 ppp_udp_pkt->cblock.result = mbox->cmd.result;
2424 mbox->cmd.length = 0;
2425 break;
2426 }
2427
2428 sdla_peek(&card->hw, 0xC000, &buf2, 2);
2429
2430 ppp_priv_area->curr_trace_addr = 0;
2431 memcpy(&ppp_priv_area->curr_trace_addr, &buf2, 2);
2432 ppp_priv_area->start_trace_addr =
2433 ppp_priv_area->curr_trace_addr;
2434 ppp_priv_area->end_trace_addr =
2435 ppp_priv_area->start_trace_addr + END_OFFSET;
2436
2437 /* MAX_SEND_BUFFER_SIZE - 28 (IP header)
2438 - 32 (ppipemon CBLOCK) */
2439 available_buffer_space = MAX_LGTH_UDP_MGNT_PKT -
2440 sizeof(ip_pkt_t)-
2441 sizeof(udp_pkt_t)-
2442 sizeof(wp_mgmt_t)-
2443 sizeof(cblock_t);
2444 }
2445 ppp_udp_pkt->cblock.result = 0;
2446 mbox->cmd.length = 0;
2447 card->TracingEnabled = 1;
2448 break;
2449
2450 /* PPIPE_DISABLE_TRACING */
2451 case PPIPE_DISABLE_TRACING:
2452
2453 if(card->TracingEnabled) {
2454
2455 /* OPERATE_DATALINE_MONITOR */
2456 mbox->cmd.command = 0x33;
2457 mbox->cmd.length = 1;
2458 mbox->data[0] = 0x00;
2459 err = sdla_exec(mbox) ?
2460 mbox->cmd.result : CMD_TIMEOUT;
2461
2462 }
2463
2464 /*set return code*/
2465 ppp_udp_pkt->cblock.result = 0;
2466 mbox->cmd.length = 0;
2467 card->TracingEnabled = 0;
2468 break;
2469
2470 /* PPIPE_GET_TRACE_INFO */
2471 case PPIPE_GET_TRACE_INFO:
2472
2473 if(!card->TracingEnabled) {
2474 /* set return code */
2475 ppp_udp_pkt->cblock.result = 1;
2476 mbox->cmd.length = 0;
2477 }
2478
2479 buffer_length = 0;
2480
2481 /* frames < 62, where 62 is the number of trace
2482 information elements. There is in total 496
2483 bytes of space and each trace information
2484 element is 8 bytes.
2485 */
2486 for ( frames=0; frames<62; frames++) {
2487
2488 trace_pkt_t *trace_pkt = (trace_pkt_t *)
2489 &ppp_udp_pkt->data[buffer_length];
2490
2491 /* Read the whole trace packet */
2492 sdla_peek(&card->hw, ppp_priv_area->curr_trace_addr,
2493 &trace_element, sizeof(trace_element_t));
2494
2495 /* no data on board so exit */
2496 if( trace_element.opp_flag == 0x00 )
2497 break;
2498
2499 data_ptr = trace_element.trace_data_ptr;
2500
2501 /* See if there is actual data on the trace buffer */
2502 if (data_ptr){
2503 data_length = trace_element.trace_length;
2504 }else{
2505 data_length = 0;
2506 ppp_udp_pkt->data[0] |= 0x02;
2507 }
2508
2509 //FIXME: Do we need this check
2510 if ((available_buffer_space - buffer_length)
2511 < (sizeof(trace_element_t)+1)){
2512
2513 /*indicate we have more frames
2514 * on board and exit
2515 */
2516 ppp_udp_pkt->data[0] |= 0x02;
2517 break;
2518 }
2519
2520 trace_pkt->status = trace_element.trace_type;
2521 trace_pkt->time_stamp = trace_element.trace_time_stamp;
2522 trace_pkt->real_length = trace_element.trace_length;
2523
2524 real_len = trace_element.trace_length;
2525
2526 if(data_ptr == 0){
2527 trace_pkt->data_avail = 0x00;
2528 }else{
2529 /* we can take it next time */
2530 if ((available_buffer_space - buffer_length)<
2531 (real_len + sizeof(trace_pkt_t))){
2532
2533 ppp_udp_pkt->data[0] |= 0x02;
2534 break;
2535 }
2536 trace_pkt->data_avail = 0x01;
2537
2538 /* get the data */
2539 sdla_peek(&card->hw, data_ptr,
2540 &trace_pkt->data,
2541 real_len);
2542 }
2543 /* zero the opp flag to
2544 show we got the frame */
2545 buf2[0] = 0x00;
2546 sdla_poke(&card->hw, ppp_priv_area->curr_trace_addr,
2547 &buf2, 1);
2548
2549 /* now move onto the next
2550 frame */
2551 ppp_priv_area->curr_trace_addr += 8;
2552
2553 /* check if we passed the last address */
2554 if ( ppp_priv_area->curr_trace_addr >=
2555 ppp_priv_area->end_trace_addr){
2556
2557 ppp_priv_area->curr_trace_addr =
2558 ppp_priv_area->start_trace_addr;
2559 }
2560
2561 /* update buffer length and make sure its even */
2562
2563 if ( trace_pkt->data_avail == 0x01 ) {
2564 buffer_length += real_len - 1;
2565 }
2566
2567 /* for the header */
2568 buffer_length += 8;
2569
2570 if( buffer_length & 0x0001 )
2571 buffer_length += 1;
2572 }
2573
2574 /* ok now set the total number of frames passed
2575 in the high 5 bits */
2576 ppp_udp_pkt->data[0] |= (frames << 2);
2577
2578 /* set the data length */
2579 mbox->cmd.length = buffer_length;
2580 ppp_udp_pkt->cblock.length = buffer_length;
2581
2582 /* set return code */
2583 ppp_udp_pkt->cblock.result = 0;
2584 break;
2585
2586 /* PPIPE_GET_IBA_DATA */
2587 case PPIPE_GET_IBA_DATA:
2588
2589 mbox->cmd.length = 0x09;
2590
2591 sdla_peek(&card->hw, 0xF003, &ppp_udp_pkt->data,
2592 mbox->cmd.length);
2593
2594 /* set the length of the data */
2595 ppp_udp_pkt->cblock.length = 0x09;
2596
2597 /* set return code */
2598 ppp_udp_pkt->cblock.result = 0x00;
2599 ppp_udp_pkt->cblock.result = 0;
2600 break;
2601
2602 /* PPIPE_FT1_READ_STATUS */
2603 case PPIPE_FT1_READ_STATUS:
2604 sdla_peek(&card->hw, 0xF020, &ppp_udp_pkt->data[0], 2);
2605 ppp_udp_pkt->cblock.length = mbox->cmd.length = 2;
2606 ppp_udp_pkt->cblock.result = 0;
2607 break;
2608
2609 case PPIPE_FLUSH_DRIVER_STATS:
2610 init_ppp_priv_struct( ppp_priv_area );
2611 init_global_statistics( card );
2612 mbox->cmd.length = 0;
2613 ppp_udp_pkt->cblock.result = 0;
2614 break;
2615
2616
2617 case PPIPE_ROUTER_UP_TIME:
2618
2619 do_gettimeofday( &tv );
2620 ppp_priv_area->router_up_time = tv.tv_sec -
2621 ppp_priv_area->router_start_time;
2622 *(unsigned long *)&ppp_udp_pkt->data = ppp_priv_area->router_up_time;
2623 mbox->cmd.length = 4;
2624 ppp_udp_pkt->cblock.result = 0;
2625 break;
2626
2627 /* PPIPE_DRIVER_STATISTICS */
2628 case PPIPE_DRIVER_STAT_IFSEND:
2629 memcpy(&ppp_udp_pkt->data, &ppp_priv_area->if_send_stat,
2630 sizeof(if_send_stat_t));
2631
2632
2633 ppp_udp_pkt->cblock.result = 0;
2634 ppp_udp_pkt->cblock.length = sizeof(if_send_stat_t);
2635 mbox->cmd.length = sizeof(if_send_stat_t);
2636 break;
2637
2638 case PPIPE_DRIVER_STAT_INTR:
2639 memcpy(&ppp_udp_pkt->data, &card->statistics,
2640 sizeof(global_stats_t));
2641
2642 memcpy(&ppp_udp_pkt->data+sizeof(global_stats_t),
2643 &ppp_priv_area->rx_intr_stat,
2644 sizeof(rx_intr_stat_t));
2645
2646 ppp_udp_pkt->cblock.result = 0;
2647 ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
2648 sizeof(rx_intr_stat_t);
2649 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2650 break;
2651
2652 case PPIPE_DRIVER_STAT_GEN:
2653 memcpy( &ppp_udp_pkt->data,
2654 &ppp_priv_area->pipe_mgmt_stat,
2655 sizeof(pipe_mgmt_stat_t));
2656
2657 memcpy(&ppp_udp_pkt->data+sizeof(pipe_mgmt_stat_t),
2658 &card->statistics, sizeof(global_stats_t));
2659
2660 ppp_udp_pkt->cblock.result = 0;
2661 ppp_udp_pkt->cblock.length = sizeof(global_stats_t)+
2662 sizeof(rx_intr_stat_t);
2663 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2664 break;
2665
2666
2667 /* FT1 MONITOR STATUS */
2668 case FT1_MONITOR_STATUS_CTRL:
2669
2670 /* Enable FT1 MONITOR STATUS */
2671 if( ppp_udp_pkt->data[0] == 1) {
2672
2673 if( rCount++ != 0 ) {
2674 ppp_udp_pkt->cblock.result = 0;
2675 mbox->cmd.length = 1;
2676 break;
2677 }
2678 }
2679
2680 /* Disable FT1 MONITOR STATUS */
2681 if( ppp_udp_pkt->data[0] == 0) {
2682
2683 if( --rCount != 0) {
2684 ppp_udp_pkt->cblock.result = 0;
2685 mbox->cmd.length = 1;
2686 break;
2687 }
2688 }
2689 goto udp_dflt_cmd;
2690
2691 /* WARNING: FIXME: This should be fixed.
2692 * The FT1 Status Ctrl doesn't have a break
2693 * statment. Thus, no code must be inserted
2694 * HERE: between default and above case statement */
2695
2696 default:
2697udp_dflt_cmd:
2698
2699 /* it's a board command */
2700 mbox->cmd.command = ppp_udp_pkt->cblock.command;
2701 mbox->cmd.length = ppp_udp_pkt->cblock.length;
2702
2703 if(mbox->cmd.length) {
2704 memcpy(&mbox->data,(unsigned char *)ppp_udp_pkt->data,
2705 mbox->cmd.length);
2706 }
2707
2708 /* run the command on the board */
2709 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2710
2711 if (err != CMD_OK) {
2712
2713 ppp_error(card, err, mbox);
2714 ++ppp_priv_area->pipe_mgmt_stat.
2715 UDP_PIPE_mgmt_adptr_cmnd_timeout;
2716 break;
2717 }
2718
2719 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_cmnd_OK;
2720
2721 /* copy the result back to our buffer */
2722 memcpy(&ppp_udp_pkt->cblock,mbox, sizeof(cblock_t));
2723
2724 if(mbox->cmd.length) {
2725 memcpy(&ppp_udp_pkt->data,&mbox->data,mbox->cmd.length);
2726 }
2727
2728 } /* end of switch */
2729 } /* end of else */
2730
2731 /* Fill UDP TTL */
2732 ppp_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
2733 len = reply_udp(ppp_priv_area->udp_pkt_data, mbox->cmd.length);
2734
2735 if (ppp_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2736
2737 /* Make sure we are not already sending */
2738 if (!test_bit(SEND_CRIT,&card->wandev.critical)){
2739 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_adptr;
2740 ppp_send(card,ppp_priv_area->udp_pkt_data,len,ppp_priv_area->protocol);
2741 }
2742
2743 } else {
2744
2745 /* Pass it up the stack
2746 Allocate socket buffer */
2747 if ((new_skb = dev_alloc_skb(len)) != NULL) {
2748
2749 /* copy data into new_skb */
2750
2751 buf = skb_put(new_skb, len);
2752 memcpy(buf,ppp_priv_area->udp_pkt_data, len);
2753
2754 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_stack;
2755
2756 /* Decapsulate packet and pass it up the protocol
2757 stack */
2758 new_skb->protocol = htons(ETH_P_IP);
2759 new_skb->dev = dev;
2760 new_skb->mac.raw = new_skb->data;
2761 netif_rx(new_skb);
2762 dev->last_rx = jiffies;
2763
2764 } else {
2765
2766 ++ppp_priv_area->pipe_mgmt_stat.UDP_PIPE_mgmt_no_socket;
2767 printk(KERN_INFO "no socket buffers available!\n");
2768 }
2769 }
2770
2771 ppp_priv_area->udp_pkt_lgth = 0;
2772
2773 return;
2774}
2775
2776/*=============================================================================
2777 * Initial the ppp_private_area structure.
2778 */
2779static void init_ppp_priv_struct( ppp_private_area_t *ppp_priv_area )
2780{
2781
2782 memset(&ppp_priv_area->if_send_stat, 0, sizeof(if_send_stat_t));
2783 memset(&ppp_priv_area->rx_intr_stat, 0, sizeof(rx_intr_stat_t));
2784 memset(&ppp_priv_area->pipe_mgmt_stat, 0, sizeof(pipe_mgmt_stat_t));
2785}
2786
2787/*============================================================================
2788 * Initialize Global Statistics
2789 */
2790static void init_global_statistics( sdla_t *card )
2791{
2792 memset(&card->statistics, 0, sizeof(global_stats_t));
2793}
2794
2795/*============================================================================
2796 * Initialize Receive and Transmit Buffers.
2797 */
2798static void init_ppp_tx_rx_buff( sdla_t *card )
2799{
2800 ppp508_buf_info_t* info;
2801
2802 if (card->hw.type == SDLA_S514) {
2803
2804 info = (void*)(card->hw.dpmbase + PPP514_BUF_OFFS);
2805
2806 card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
2807 info->txb_ptr);
2808
2809 card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
2810 (info->txb_num - 1);
2811
2812 card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
2813 info->rxb_ptr);
2814
2815 card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
2816 (info->rxb_num - 1);
2817
2818 } else {
2819
2820 info = (void*)(card->hw.dpmbase + PPP508_BUF_OFFS);
2821
2822 card->u.p.txbuf_base = (void*)(card->hw.dpmbase +
2823 (info->txb_ptr - PPP508_MB_VECT));
2824
2825 card->u.p.txbuf_last = (ppp_buf_ctl_t*)card->u.p.txbuf_base +
2826 (info->txb_num - 1);
2827
2828 card->u.p.rxbuf_base = (void*)(card->hw.dpmbase +
2829 (info->rxb_ptr - PPP508_MB_VECT));
2830
2831 card->u.p.rxbuf_last = (ppp_buf_ctl_t*)card->u.p.rxbuf_base +
2832 (info->rxb_num - 1);
2833 }
2834
2835 card->u.p.txbuf_next = (unsigned long*)&info->txb_nxt;
2836 card->u.p.rxbuf_next = (unsigned long*)&info->rxb1_ptr;
2837
2838 card->u.p.rx_base = info->rxb_base;
2839 card->u.p.rx_top = info->rxb_end;
2840
2841 card->u.p.txbuf = card->u.p.txbuf_base;
2842 card->rxmb = card->u.p.rxbuf_base;
2843
2844}
2845
2846/*=============================================================================
2847 * Read Connection Information (ie for Remote IP address assginment).
2848 * Called when ppp interface connected.
2849 */
2850static int read_info( sdla_t *card )
2851{
2852 struct net_device *dev = card->wandev.dev;
2853 ppp_private_area_t *ppp_priv_area = dev->priv;
2854 int err;
2855
2856 struct ifreq if_info;
2857 struct sockaddr_in *if_data1, *if_data2;
2858 mm_segment_t fs;
2859
2860 /* Set Local and remote addresses */
2861 memset(&if_info, 0, sizeof(if_info));
2862 strcpy(if_info.ifr_name, dev->name);
2863
2864
2865 fs = get_fs();
2866 set_fs(get_ds()); /* get user space block */
2867
2868 /* Change the local and remote ip address of the interface.
2869 * This will also add in the destination route.
2870 */
2871 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2872 if_data1->sin_addr.s_addr = ppp_priv_area->ip_local;
2873 if_data1->sin_family = AF_INET;
2874 err = devinet_ioctl( SIOCSIFADDR, &if_info );
2875 if_data2 = (struct sockaddr_in *)&if_info.ifr_dstaddr;
2876 if_data2->sin_addr.s_addr = ppp_priv_area->ip_remote;
2877 if_data2->sin_family = AF_INET;
2878 err = devinet_ioctl( SIOCSIFDSTADDR, &if_info );
2879
2880 set_fs(fs); /* restore old block */
2881
2882 if (err) {
2883 printk (KERN_INFO "%s: Adding of route failed: %i\n",
2884 card->devname,err);
2885 printk (KERN_INFO "%s: Local : %u.%u.%u.%u\n",
2886 card->devname,NIPQUAD(ppp_priv_area->ip_local));
2887 printk (KERN_INFO "%s: Remote: %u.%u.%u.%u\n",
2888 card->devname,NIPQUAD(ppp_priv_area->ip_remote));
2889 }
2890 return err;
2891}
2892
2893/*=============================================================================
2894 * Remove Dynamic Route.
2895 * Called when ppp interface disconnected.
2896 */
2897
2898static void remove_route( sdla_t *card )
2899{
2900
2901 struct net_device *dev = card->wandev.dev;
2902 long ip_addr;
2903 int err;
2904
2905 mm_segment_t fs;
2906 struct ifreq if_info;
2907 struct sockaddr_in *if_data1;
2908 struct in_device *in_dev = dev->ip_ptr;
2909 struct in_ifaddr *ifa = in_dev->ifa_list;
2910
2911 ip_addr = ifa->ifa_local;
2912
2913 /* Set Local and remote addresses */
2914 memset(&if_info, 0, sizeof(if_info));
2915 strcpy(if_info.ifr_name, dev->name);
2916
2917 fs = get_fs();
2918 set_fs(get_ds()); /* get user space block */
2919
2920 /* Change the local ip address of the interface to 0.
2921 * This will also delete the destination route.
2922 */
2923 if_data1 = (struct sockaddr_in *)&if_info.ifr_addr;
2924 if_data1->sin_addr.s_addr = 0;
2925 if_data1->sin_family = AF_INET;
2926 err = devinet_ioctl( SIOCSIFADDR, &if_info );
2927
2928 set_fs(fs); /* restore old block */
2929
2930
2931 if (err) {
2932 printk (KERN_INFO "%s: Deleting dynamic route failed %d!\n",
2933 card->devname, err);
2934 return;
2935 }else{
2936 printk (KERN_INFO "%s: PPP Deleting dynamic route %u.%u.%u.%u successfuly\n",
2937 card->devname, NIPQUAD(ip_addr));
2938 }
2939 return;
2940}
2941
2942/*=============================================================================
2943 * Perform the Interrupt Test by running the READ_CODE_VERSION command MAX_INTR
2944 * _TEST_COUNTER times.
2945 */
2946static int intr_test( sdla_t *card )
2947{
2948 ppp_mbox_t *mb = card->mbox;
2949 int err,i;
2950
2951 err = ppp_set_intr_mode( card, 0x08 );
2952
2953 if (err == CMD_OK) {
2954
2955 for (i = 0; i < MAX_INTR_TEST_COUNTER; i ++) {
2956 /* Run command READ_CODE_VERSION */
2957 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
2958 mb->cmd.length = 0;
2959 mb->cmd.command = PPP_READ_CODE_VERSION;
2960 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
2961 if (err != CMD_OK)
2962 ppp_error(card, err, mb);
2963 }
2964 }
2965 else return err;
2966
2967 err = ppp_set_intr_mode( card, 0 );
2968 if (err != CMD_OK)
2969 return err;
2970
2971 return 0;
2972}
2973
2974/*==============================================================================
2975 * Determine what type of UDP call it is. DRVSTATS or PTPIPEAB ?
2976 */
2977static int udp_pkt_type( struct sk_buff *skb, sdla_t *card )
2978{
2979 unsigned char *sendpacket;
2980 unsigned char buf2[5];
2981 ppp_udp_pkt_t *ppp_udp_pkt = (ppp_udp_pkt_t *)skb->data;
2982
2983 sendpacket = skb->data;
2984 memcpy(&buf2, &card->wandev.udp_port, 2);
2985
2986 if( ppp_udp_pkt->ip_pkt.ver_inet_hdr_length == 0x45 && /* IP packet */
2987 sendpacket[9] == 0x11 && /* UDP packet */
2988 sendpacket[22] == buf2[1] && /* UDP Port */
2989 sendpacket[23] == buf2[0] &&
2990 sendpacket[36] == 0x01 ) {
2991
2992 if ( sendpacket[28] == 0x50 && /* PTPIPEAB: Signature */
2993 sendpacket[29] == 0x54 &&
2994 sendpacket[30] == 0x50 &&
2995 sendpacket[31] == 0x49 &&
2996 sendpacket[32] == 0x50 &&
2997 sendpacket[33] == 0x45 &&
2998 sendpacket[34] == 0x41 &&
2999 sendpacket[35] == 0x42 ){
3000
3001 return UDP_PTPIPE_TYPE;
3002
3003 } else if(sendpacket[28] == 0x44 && /* DRVSTATS: Signature */
3004 sendpacket[29] == 0x52 &&
3005 sendpacket[30] == 0x56 &&
3006 sendpacket[31] == 0x53 &&
3007 sendpacket[32] == 0x54 &&
3008 sendpacket[33] == 0x41 &&
3009 sendpacket[34] == 0x54 &&
3010 sendpacket[35] == 0x53 ){
3011
3012 return UDP_DRVSTATS_TYPE;
3013
3014 } else
3015 return UDP_INVALID_TYPE;
3016
3017 } else
3018 return UDP_INVALID_TYPE;
3019
3020}
3021
3022/*============================================================================
3023 * Check to see if the packet to be transmitted contains a broadcast or
3024 * multicast source IP address.
3025 */
3026
3027static int chk_bcast_mcast_addr(sdla_t *card, struct net_device* dev,
3028 struct sk_buff *skb)
3029{
3030 u32 src_ip_addr;
3031 u32 broadcast_ip_addr = 0;
3032 struct in_device *in_dev;
3033
3034 /* read the IP source address from the outgoing packet */
3035 src_ip_addr = *(u32 *)(skb->data + 12);
3036
3037 /* read the IP broadcast address for the device */
3038 in_dev = dev->ip_ptr;
3039 if(in_dev != NULL) {
3040 struct in_ifaddr *ifa= in_dev->ifa_list;
3041 if(ifa != NULL)
3042 broadcast_ip_addr = ifa->ifa_broadcast;
3043 else
3044 return 0;
3045 }
3046
3047 /* check if the IP Source Address is a Broadcast address */
3048 if((dev->flags & IFF_BROADCAST) && (src_ip_addr == broadcast_ip_addr)) {
3049 printk(KERN_INFO "%s: Broadcast Source Address silently discarded\n",
3050 card->devname);
3051 return 1;
3052 }
3053
3054 /* check if the IP Source Address is a Multicast address */
3055 if((ntohl(src_ip_addr) >= 0xE0000001) &&
3056 (ntohl(src_ip_addr) <= 0xFFFFFFFE)) {
3057 printk(KERN_INFO "%s: Multicast Source Address silently discarded\n",
3058 card->devname);
3059 return 1;
3060 }
3061
3062 return 0;
3063}
3064
3065void s508_lock (sdla_t *card, unsigned long *smp_flags)
3066{
3067 spin_lock_irqsave(&card->wandev.lock, *smp_flags);
3068}
3069
3070void s508_unlock (sdla_t *card, unsigned long *smp_flags)
3071{
3072 spin_unlock_irqrestore(&card->wandev.lock, *smp_flags);
3073}
3074
3075static int read_connection_info (sdla_t *card)
3076{
3077 ppp_mbox_t *mb = card->mbox;
3078 struct net_device *dev = card->wandev.dev;
3079 ppp_private_area_t *ppp_priv_area = dev->priv;
3080 ppp508_connect_info_t *ppp508_connect_info;
3081 int err;
3082
3083 memset(&mb->cmd, 0, sizeof(ppp_cmd_t));
3084 mb->cmd.length = 0;
3085 mb->cmd.command = PPP_GET_CONNECTION_INFO;
3086 err = sdla_exec(mb) ? mb->cmd.result : CMD_TIMEOUT;
3087
3088 if (err != CMD_OK) {
3089 ppp_error(card, err, mb);
3090 ppp_priv_area->ip_remote = 0;
3091 ppp_priv_area->ip_local = 0;
3092 }
3093 else {
3094 ppp508_connect_info = (ppp508_connect_info_t *)mb->data;
3095 ppp_priv_area->ip_remote = ppp508_connect_info->ip_remote;
3096 ppp_priv_area->ip_local = ppp508_connect_info->ip_local;
3097
3098 NEX_PRINTK(KERN_INFO "READ CONNECTION GOT IP ADDRESS %x, %x\n",
3099 ppp_priv_area->ip_remote,
3100 ppp_priv_area->ip_local);
3101 }
3102
3103 return err;
3104}
3105
3106/*===============================================================================
3107 * config_ppp
3108 *
3109 * Configure the ppp protocol and enable communications.
3110 *
3111 * The if_open function binds this function to the poll routine.
3112 * Therefore, this function will run every time the ppp interface
3113 * is brought up.
3114 *
3115 * If the communications are not enabled, proceed to configure
3116 * the card and enable communications.
3117 *
3118 * If the communications are enabled, it means that the interface
3119 * was shutdown by ether the user or driver. In this case, we
3120 * have to check that the IP addresses have not changed. If
3121 * the IP addresses changed, we have to reconfigure the firmware
3122 * and update the changed IP addresses. Otherwise, just exit.
3123 */
3124static int config_ppp (sdla_t *card)
3125{
3126
3127 struct net_device *dev = card->wandev.dev;
3128 ppp_flags_t *flags = card->flags;
3129 ppp_private_area_t *ppp_priv_area = dev->priv;
3130
3131 if (card->u.p.comm_enabled){
3132
3133 if (ppp_priv_area->ip_local_tmp != ppp_priv_area->ip_local ||
3134 ppp_priv_area->ip_remote_tmp != ppp_priv_area->ip_remote){
3135
3136 /* The IP addersses have changed, we must
3137 * stop the communications and reconfigure
3138 * the card. Reason: the firmware must know
3139 * the local and remote IP addresses. */
3140 disable_comm(card);
3141 wanpipe_set_state(card, WAN_DISCONNECTED);
3142 printk(KERN_INFO
3143 "%s: IP addresses changed!\n",
3144 card->devname);
3145 printk(KERN_INFO "%s: Restarting communications ...\n",
3146 card->devname);
3147 }else{
3148 /* IP addresses are the same and the link is up,
3149 * we don't have to do anything here. Therefore, exit */
3150 return 0;
3151 }
3152 }
3153
3154 /* Record the new IP addreses */
3155 ppp_priv_area->ip_local = ppp_priv_area->ip_local_tmp;
3156 ppp_priv_area->ip_remote = ppp_priv_area->ip_remote_tmp;
3157
3158 if (config508(dev, card)){
3159 printk(KERN_INFO "%s: Failed to configure PPP device\n",
3160 card->devname);
3161 return 0;
3162 }
3163
3164 if (ppp_set_intr_mode(card, PPP_INTR_RXRDY|
3165 PPP_INTR_TXRDY|
3166 PPP_INTR_MODEM|
3167 PPP_INTR_DISC |
3168 PPP_INTR_OPEN |
3169 PPP_INTR_DROP_DTR |
3170 PPP_INTR_TIMER)) {
3171
3172 printk(KERN_INFO "%s: Failed to configure board interrupts !\n",
3173 card->devname);
3174 return 0;
3175 }
3176
3177 /* Turn off the transmit and timer interrupt */
3178 flags->imask &= ~(PPP_INTR_TXRDY | PPP_INTR_TIMER) ;
3179
3180
3181 /* If you are not the authenticator and any one of the protocol is
3182 * enabled then we call the set_out_bound_authentication.
3183 */
3184 if ( !card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)) {
3185 if ( ppp_set_outbnd_auth(card, ppp_priv_area) ){
3186 printk(KERN_INFO "%s: Outbound authentication failed !\n",
3187 card->devname);
3188 return 0;
3189 }
3190 }
3191
3192 /* If you are the authenticator and any one of the protocol is enabled
3193 * then we call the set_in_bound_authentication.
3194 */
3195 if (card->u.p.authenticator && (ppp_priv_area->pap || ppp_priv_area->chap)){
3196 if (ppp_set_inbnd_auth(card, ppp_priv_area)){
3197 printk(KERN_INFO "%s: Inbound authentication failed !\n",
3198 card->devname);
3199 return 0;
3200 }
3201 }
3202
3203 /* If we fail to enable communications here it's OK,
3204 * since the DTR timer will cause a disconnected, which
3205 * will retrigger communication in timer_intr() */
3206 if (ppp_comm_enable(card) == CMD_OK) {
3207 wanpipe_set_state(card, WAN_CONNECTING);
3208 init_ppp_tx_rx_buff(card);
3209 }
3210
3211 return 0;
3212}
3213
3214/*============================================================
3215 * ppp_poll
3216 *
3217 * Rationale:
3218 * We cannot manipulate the routing tables, or
3219 * ip addresses withing the interrupt. Therefore
3220 * we must perform such actons outside an interrupt
3221 * at a later time.
3222 *
3223 * Description:
3224 * PPP polling routine, responsible for
3225 * shutting down interfaces upon disconnect
3226 * and adding/removing routes.
3227 *
3228 * Usage:
3229 * This function is executed for each ppp
3230 * interface through a tq_schedule bottom half.
3231 *
3232 * trigger_ppp_poll() function is used to kick
3233 * the ppp_poll routine.
3234 */
3235static void ppp_poll(struct net_device *dev)
3236{
3237 ppp_private_area_t *ppp_priv_area;
3238 sdla_t *card;
3239 u8 check_gateway=0;
3240 ppp_flags_t *flags;
3241
3242 if (!dev || (ppp_priv_area = dev->priv) == NULL)
3243 return;
3244
3245 card = ppp_priv_area->card;
3246 flags = card->flags;
3247
3248 /* Shutdown is in progress, stop what you are
3249 * doing and get out */
3250 if (test_bit(PERI_CRIT,&card->wandev.critical)){
3251 clear_bit(POLL_CRIT,&card->wandev.critical);
3252 return;
3253 }
3254
3255 /* if_open() function has triggered the polling routine
3256 * to determine the configured IP addresses. Once the
3257 * addresses are found, trigger the chdlc configuration */
3258 if (test_bit(0,&ppp_priv_area->config_ppp)){
3259
3260 ppp_priv_area->ip_local_tmp = get_ip_address(dev,WAN_LOCAL_IP);
3261 ppp_priv_area->ip_remote_tmp = get_ip_address(dev,WAN_POINTOPOINT_IP);
3262
3263 if (ppp_priv_area->ip_local_tmp == ppp_priv_area->ip_remote_tmp &&
3264 card->u.p.ip_mode == WANOPT_PPP_HOST){
3265
3266 if (++ppp_priv_area->ip_error > MAX_IP_ERRORS){
3267 printk(KERN_INFO "\n%s: --- WARNING ---\n",
3268 card->devname);
3269 printk(KERN_INFO "%s: The local IP address is the same as the\n",
3270 card->devname);
3271 printk(KERN_INFO "%s: Point-to-Point IP address.\n",
3272 card->devname);
3273 printk(KERN_INFO "%s: --- WARNING ---\n\n",
3274 card->devname);
3275 }else{
3276 clear_bit(POLL_CRIT,&card->wandev.critical);
3277 ppp_priv_area->poll_delay_timer.expires = jiffies+HZ;
3278 add_timer(&ppp_priv_area->poll_delay_timer);
3279 return;
3280 }
3281 }
3282
3283 ppp_priv_area->timer_int_enabled |= TMR_INT_ENABLED_CONFIG;
3284 flags->imask |= PPP_INTR_TIMER;
3285 ppp_priv_area->ip_error=0;
3286
3287 clear_bit(0,&ppp_priv_area->config_ppp);
3288 clear_bit(POLL_CRIT,&card->wandev.critical);
3289 return;
3290 }
3291
3292 /* Dynamic interface implementation, as well as dynamic
3293 * routing. */
3294
3295 switch (card->wandev.state) {
3296
3297 case WAN_DISCONNECTED:
3298
3299 /* If the dynamic interface configuration is on, and interface
3300 * is up, then bring down the netowrk interface */
3301
3302 if (test_bit(DYN_OPT_ON,&ppp_priv_area->interface_down) &&
3303 !test_bit(DEV_DOWN,&ppp_priv_area->interface_down) &&
3304 card->wandev.dev->flags & IFF_UP){
3305
3306 printk(KERN_INFO "%s: Interface %s down.\n",
3307 card->devname,card->wandev.dev->name);
3308 change_dev_flags(card->wandev.dev,
3309 (card->wandev.dev->flags&~IFF_UP));
3310 set_bit(DEV_DOWN,&ppp_priv_area->interface_down);
3311 }else{
3312 /* We need to check if the local IP address is
3313 * zero. If it is, we shouldn't try to remove it.
3314 * For some reason the kernel crashes badly if
3315 * we try to remove the route twice */
3316
3317 if (card->wandev.dev->flags & IFF_UP &&
3318 get_ip_address(card->wandev.dev,WAN_LOCAL_IP) &&
3319 card->u.p.ip_mode == WANOPT_PPP_PEER){
3320
3321 remove_route(card);
3322 }
3323 }
3324 break;
3325
3326 case WAN_CONNECTED:
3327
3328 /* In SMP machine this code can execute before the interface
3329 * comes up. In this case, we must make sure that we do not
3330 * try to bring up the interface before dev_open() is finished */
3331
3332
3333 /* DEV_DOWN will be set only when we bring down the interface
3334 * for the very first time. This way we know that it was us
3335 * that brought the interface down */
3336
3337 if (test_bit(DYN_OPT_ON,&ppp_priv_area->interface_down) &&
3338 test_bit(DEV_DOWN, &ppp_priv_area->interface_down) &&
3339 !(card->wandev.dev->flags & IFF_UP)){
3340
3341 printk(KERN_INFO "%s: Interface %s up.\n",
3342 card->devname,card->wandev.dev->name);
3343
3344 change_dev_flags(card->wandev.dev,(card->wandev.dev->flags|IFF_UP));
3345 clear_bit(DEV_DOWN,&ppp_priv_area->interface_down);
3346 check_gateway=1;
3347 }
3348
3349 if ((card->u.p.ip_mode == WANOPT_PPP_PEER) &&
3350 test_bit(1,&Read_connection_info)) {
3351
3352 process_route(card);
3353 clear_bit(1,&Read_connection_info);
3354 check_gateway=1;
3355 }
3356
3357 if (ppp_priv_area->gateway && check_gateway)
3358 add_gateway(card,dev);
3359
3360 break;
3361 }
3362 clear_bit(POLL_CRIT,&card->wandev.critical);
3363 return;
3364}
3365
3366/*============================================================
3367 * trigger_ppp_poll
3368 *
3369 * Description:
3370 * Add a ppp_poll() task into a tq_scheduler bh handler
3371 * for a specific interface. This will kick
3372 * the ppp_poll() routine at a later time.
3373 *
3374 * Usage:
3375 * Interrupts use this to defer a taks to
3376 * a polling routine.
3377 *
3378 */
3379
3380static void trigger_ppp_poll(struct net_device *dev)
3381{
3382 ppp_private_area_t *ppp_priv_area;
3383 if ((ppp_priv_area=dev->priv) != NULL){
3384
3385 sdla_t *card = ppp_priv_area->card;
3386
3387 if (test_bit(PERI_CRIT,&card->wandev.critical)){
3388 return;
3389 }
3390
3391 if (test_and_set_bit(POLL_CRIT,&card->wandev.critical)){
3392 return;
3393 }
3394
3395 schedule_work(&ppp_priv_area->poll_work);
3396 }
3397 return;
3398}
3399
3400static void ppp_poll_delay (unsigned long dev_ptr)
3401{
3402 struct net_device *dev = (struct net_device *)dev_ptr;
3403 trigger_ppp_poll(dev);
3404}
3405
3406/*============================================================
3407 * detect_and_fix_tx_bug
3408 *
3409 * Description:
3410 * On connect, if the board tx buffer ptr is not the same
3411 * as the driver tx buffer ptr, we found a firmware bug.
3412 * Report the bug to the above layer. To fix the
3413 * error restart communications again.
3414 *
3415 * Usage:
3416 *
3417 */
3418
3419static int detect_and_fix_tx_bug (sdla_t *card)
3420{
3421 if (((unsigned long)card->u.p.txbuf_base&0xFFF) != ((*card->u.p.txbuf_next)&0xFFF)){
3422 NEX_PRINTK(KERN_INFO "Major Error, Fix the bug\n");
3423 return 1;
3424 }
3425 return 0;
3426}
3427
3428MODULE_LICENSE("GPL");
3429
3430/****** End *****************************************************************/
diff --git a/drivers/net/wan/sdla_x25.c b/drivers/net/wan/sdla_x25.c
deleted file mode 100644
index 63f846d6f3a6..000000000000
--- a/drivers/net/wan/sdla_x25.c
+++ /dev/null
@@ -1,5497 +0,0 @@
1/*****************************************************************************
2* sdla_x25.c WANPIPE(tm) Multiprotocol WAN Link Driver. X.25 module.
3*
4* Author: Nenad Corbic <ncorbic@sangoma.com>
5*
6* Copyright: (c) 1995-2001 Sangoma Technologies Inc.
7*
8* This program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public License
10* as published by the Free Software Foundation; either version
11* 2 of the License, or (at your option) any later version.
12* ============================================================================
13* Apr 03, 2001 Nenad Corbic o Fixed the rx_skb=NULL bug in x25 in rx_intr().
14* Dec 26, 2000 Nenad Corbic o Added a new polling routine, that uses
15* a kernel timer (more efficient).
16* Dec 25, 2000 Nenad Corbic o Updated for 2.4.X kernel
17* Jul 26, 2000 Nenad Corbic o Increased the local packet buffering
18* for API to 4096+header_size.
19* Jul 17, 2000 Nenad Corbic o Fixed the x25 startup bug. Enable
20* communications only after all interfaces
21* come up. HIGH SVC/PVC is used to calculate
22* the number of channels.
23* Enable protocol only after all interfaces
24* are enabled.
25* Jul 10, 2000 Nenad Corbic o Fixed the M_BIT bug.
26* Apr 25, 2000 Nenad Corbic o Pass Modem messages to the API.
27* Disable idle timeout in X25 API.
28* Apr 14, 2000 Nenad Corbic o Fixed: Large LCN number support.
29* Maximum LCN number is 4095.
30* Maximum number of X25 channels is 255.
31* Apr 06, 2000 Nenad Corbic o Added SMP Support.
32* Mar 29, 2000 Nenad Corbic o Added support for S514 PCI Card
33* Mar 23, 2000 Nenad Corbic o Improved task queue, BH handling.
34* Mar 14, 2000 Nenad Corbic o Updated Protocol Violation handling
35* routines. Bug Fix.
36* Mar 10, 2000 Nenad Corbic o Bug Fix: corrupted mbox recovery.
37* Mar 09, 2000 Nenad Corbic o Fixed the auto HDLC bug.
38* Mar 08, 2000 Nenad Corbic o Fixed LAPB HDLC startup problems.
39* Application must bring the link up
40* before tx/rx, and bring the
41* link down on close().
42* Mar 06, 2000 Nenad Corbic o Added an option for logging call setup
43* information.
44* Feb 29, 2000 Nenad Corbic o Added support for LAPB HDLC API
45* Feb 25, 2000 Nenad Corbic o Fixed the modem failure handling.
46* No Modem OOB message will be passed
47* to the user.
48* Feb 21, 2000 Nenad Corbic o Added Xpipemon Debug Support
49* Dec 30, 1999 Nenad Corbic o Socket based X25API
50* Sep 17, 1998 Jaspreet Singh o Updates for 2.2.X kernel
51* Mar 15, 1998 Alan Cox o 2.1.x porting
52* Dec 19, 1997 Jaspreet Singh o Added multi-channel IPX support
53* Nov 27, 1997 Jaspreet Singh o Added protection against enabling of irqs
54* when they are disabled.
55* Nov 17, 1997 Farhan Thawar o Added IPX support
56* o Changed if_send() to now buffer packets when
57* the board is busy
58* o Removed queueing of packets via the polling
59* routing
60* o Changed if_send() critical flags to properly
61* handle race conditions
62* Nov 06, 1997 Farhan Thawar o Added support for SVC timeouts
63* o Changed PVC encapsulation to ETH_P_IP
64* Jul 21, 1997 Jaspreet Singh o Fixed freeing up of buffers using kfree()
65* when packets are received.
66* Mar 11, 1997 Farhan Thawar Version 3.1.1
67* o added support for V35
68* o changed if_send() to return 0 if
69* wandev.critical() is true
70* o free socket buffer in if_send() if
71* returning 0
72* o added support for single '@' address to
73* accept all incoming calls
74* o fixed bug in set_chan_state() to disconnect
75* Jan 15, 1997 Gene Kozin Version 3.1.0
76* o implemented exec() entry point
77* Jan 07, 1997 Gene Kozin Initial version.
78*****************************************************************************/
79
80/*======================================================
81 * Includes
82 *=====================================================*/
83
84#include <linux/module.h>
85#include <linux/kernel.h> /* printk(), and other useful stuff */
86#include <linux/stddef.h> /* offsetof(), etc. */
87#include <linux/errno.h> /* return codes */
88#include <linux/string.h> /* inline memset(), etc. */
89#include <linux/ctype.h>
90#include <linux/slab.h> /* kmalloc(), kfree() */
91#include <linux/wanrouter.h> /* WAN router definitions */
92#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
93#include <linux/workqueue.h>
94#include <linux/jiffies.h> /* time_after() macro */
95#include <asm/byteorder.h> /* htons(), etc. */
96#include <asm/atomic.h>
97#include <linux/delay.h> /* Experimental delay */
98
99#include <asm/uaccess.h>
100
101#include <linux/if.h>
102#include <linux/if_arp.h>
103#include <linux/sdla_x25.h> /* X.25 firmware API definitions */
104#include <linux/if_wanpipe_common.h>
105#include <linux/if_wanpipe.h>
106
107
108/*======================================================
109 * Defines & Macros
110 *=====================================================*/
111
112
113#define CMD_OK 0 /* normal firmware return code */
114#define CMD_TIMEOUT 0xFF /* firmware command timed out */
115#define MAX_CMD_RETRY 10 /* max number of firmware retries */
116
117#define X25_CHAN_MTU 4096 /* unfragmented logical channel MTU */
118#define X25_HRDHDR_SZ 7 /* max encapsulation header size */
119#define X25_CONCT_TMOUT (90*HZ) /* link connection timeout */
120#define X25_RECON_TMOUT (10*HZ) /* link connection timeout */
121#define CONNECT_TIMEOUT (90*HZ) /* link connection timeout */
122#define HOLD_DOWN_TIME (30*HZ) /* link hold down time */
123#define MAX_BH_BUFF 10
124#define M_BIT 0x01
125
126//#define PRINT_DEBUG 1
127#ifdef PRINT_DEBUG
128#define DBG_PRINTK(format, a...) printk(format, ## a)
129#else
130#define DBG_PRINTK(format, a...)
131#endif
132
133#define TMR_INT_ENABLED_POLL_ACTIVE 0x01
134#define TMR_INT_ENABLED_POLL_CONNECT_ON 0x02
135#define TMR_INT_ENABLED_POLL_CONNECT_OFF 0x04
136#define TMR_INT_ENABLED_POLL_DISCONNECT 0x08
137#define TMR_INT_ENABLED_CMD_EXEC 0x10
138#define TMR_INT_ENABLED_UPDATE 0x20
139#define TMR_INT_ENABLED_UDP_PKT 0x40
140
141#define MAX_X25_ADDR_SIZE 16
142#define MAX_X25_DATA_SIZE 129
143#define MAX_X25_FACL_SIZE 110
144
145#define TRY_CMD_AGAIN 2
146#define DELAY_RESULT 1
147#define RETURN_RESULT 0
148
149#define DCD(x) (x & 0x03 ? "HIGH" : "LOW")
150#define CTS(x) (x & 0x05 ? "HIGH" : "LOW")
151
152
153/* Driver will not write log messages about
154 * modem status if defined.*/
155#define MODEM_NOT_LOG 1
156
157/*====================================================
158 * For IPXWAN
159 *===================================================*/
160
161#define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))
162
163
164/*====================================================
165 * MEMORY DEBUGGING FUNCTION
166 *====================================================
167
168#define KMEM_SAFETYZONE 8
169
170static void * dbg_kmalloc(unsigned int size, int prio, int line) {
171 int i = 0;
172 void * v = kmalloc(size+sizeof(unsigned int)+2*KMEM_SAFETYZONE*8,prio);
173 char * c1 = v;
174 c1 += sizeof(unsigned int);
175 *((unsigned int *)v) = size;
176
177 for (i = 0; i < KMEM_SAFETYZONE; i++) {
178 c1[0] = 'D'; c1[1] = 'E'; c1[2] = 'A'; c1[3] = 'D';
179 c1[4] = 'B'; c1[5] = 'E'; c1[6] = 'E'; c1[7] = 'F';
180 c1 += 8;
181 }
182 c1 += size;
183 for (i = 0; i < KMEM_SAFETYZONE; i++) {
184 c1[0] = 'M'; c1[1] = 'U'; c1[2] = 'N'; c1[3] = 'G';
185 c1[4] = 'W'; c1[5] = 'A'; c1[6] = 'L'; c1[7] = 'L';
186 c1 += 8;
187 }
188 v = ((char *)v) + sizeof(unsigned int) + KMEM_SAFETYZONE*8;
189 printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
190 return v;
191}
192static void dbg_kfree(void * v, int line) {
193 unsigned int * sp = (unsigned int *)(((char *)v) - (sizeof(unsigned int) + KMEM_SAFETYZONE*8));
194 unsigned int size = *sp;
195 char * c1 = ((char *)v) - KMEM_SAFETYZONE*8;
196 int i = 0;
197 for (i = 0; i < KMEM_SAFETYZONE; i++) {
198 if ( c1[0] != 'D' || c1[1] != 'E' || c1[2] != 'A' || c1[3] != 'D'
199 || c1[4] != 'B' || c1[5] != 'E' || c1[6] != 'E' || c1[7] != 'F') {
200 printk(KERN_INFO "kmalloced block at %p has been corrupted (underrun)!\n",v);
201 printk(KERN_INFO " %4x: %2x %2x %2x %2x %2x %2x %2x %2x\n", i*8,
202 c1[0],c1[1],c1[2],c1[3],c1[4],c1[5],c1[6],c1[7] );
203 }
204 c1 += 8;
205 }
206 c1 += size;
207 for (i = 0; i < KMEM_SAFETYZONE; i++) {
208 if ( c1[0] != 'M' || c1[1] != 'U' || c1[2] != 'N' || c1[3] != 'G'
209 || c1[4] != 'W' || c1[5] != 'A' || c1[6] != 'L' || c1[7] != 'L'
210 ) {
211 printk(KERN_INFO "kmalloced block at %p has been corrupted (overrun):\n",v);
212 printk(KERN_INFO " %4x: %2x %2x %2x %2x %2x %2x %2x %2x\n", i*8,
213 c1[0],c1[1],c1[2],c1[3],c1[4],c1[5],c1[6],c1[7] );
214 }
215 c1 += 8;
216 }
217 printk(KERN_INFO "line %d kfree(%p)\n",line,v);
218 v = ((char *)v) - (sizeof(unsigned int) + KMEM_SAFETYZONE*8);
219 kfree(v);
220}
221
222#define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
223#define kfree(x) dbg_kfree(x,__LINE__)
224
225==============================================================*/
226
227
228
229/*===============================================
230 * Data Structures
231 *===============================================*/
232
233
234/*========================================================
235 * Name: x25_channel
236 *
237 * Purpose: To hold private informaton for each
238 * logical channel.
239 *
240 * Rationale: Per-channel debugging is possible if each
241 * channel has its own private area.
242 *
243 * Assumptions:
244 *
245 * Description: This is an extention of the struct net_device
246 * we create for each network interface to keep
247 * the rest of X.25 channel-specific data.
248 *
249 * Construct: Typedef
250 */
251typedef struct x25_channel
252{
253 wanpipe_common_t common; /* common area for x25api and socket */
254 char name[WAN_IFNAME_SZ+1]; /* interface name, ASCIIZ */
255 char addr[WAN_ADDRESS_SZ+1]; /* media address, ASCIIZ */
256 unsigned tx_pkt_size;
257 unsigned short protocol; /* ethertype, 0 - multiplexed */
258 char drop_sequence; /* mark sequence for dropping */
259 unsigned long state_tick; /* time of the last state change */
260 unsigned idle_timeout; /* sec, before disconnecting */
261 unsigned long i_timeout_sofar; /* # of sec's we've been idle */
262 unsigned hold_timeout; /* sec, before re-connecting */
263 unsigned long tick_counter; /* counter for transmit time out */
264 char devtint; /* Weather we should dev_tint() */
265 struct sk_buff* rx_skb; /* receive socket buffer */
266 struct sk_buff* tx_skb; /* transmit socket buffer */
267
268 bh_data_t *bh_head; /* Circular buffer for x25api_bh */
269 unsigned long tq_working;
270 volatile int bh_write;
271 volatile int bh_read;
272 atomic_t bh_buff_used;
273
274 sdla_t* card; /* -> owner */
275 struct net_device *dev; /* -> bound devce */
276
277 int ch_idx;
278 unsigned char enable_IPX;
279 unsigned long network_number;
280 struct net_device_stats ifstats; /* interface statistics */
281 unsigned short transmit_length;
282 unsigned short tx_offset;
283 char transmit_buffer[X25_CHAN_MTU+sizeof(x25api_hdr_t)];
284
285 if_send_stat_t if_send_stat;
286 rx_intr_stat_t rx_intr_stat;
287 pipe_mgmt_stat_t pipe_mgmt_stat;
288
289 unsigned long router_start_time; /* Router start time in seconds */
290 unsigned long router_up_time;
291
292} x25_channel_t;
293
294/* FIXME Take this out */
295
296#ifdef NEX_OLD_CALL_INFO
297typedef struct x25_call_info
298{
299 char dest[17]; PACKED;/* ASCIIZ destination address */
300 char src[17]; PACKED;/* ASCIIZ source address */
301 char nuser; PACKED;/* number of user data bytes */
302 unsigned char user[127]; PACKED;/* user data */
303 char nfacil; PACKED;/* number of facilities */
304 struct
305 {
306 unsigned char code; PACKED;
307 unsigned char parm; PACKED;
308 } facil[64]; /* facilities */
309} x25_call_info_t;
310#else
311typedef struct x25_call_info
312{
313 char dest[MAX_X25_ADDR_SIZE] PACKED;/* ASCIIZ destination address */
314 char src[MAX_X25_ADDR_SIZE] PACKED;/* ASCIIZ source address */
315 unsigned char nuser PACKED;
316 unsigned char user[MAX_X25_DATA_SIZE] PACKED;/* user data */
317 unsigned char nfacil PACKED;
318 unsigned char facil[MAX_X25_FACL_SIZE] PACKED;
319 unsigned short lcn PACKED;
320} x25_call_info_t;
321#endif
322
323
324
325/*===============================================
326 * Private Function Prototypes
327 *==============================================*/
328
329
330/*=================================================
331 * WAN link driver entry points. These are
332 * called by the WAN router module.
333 */
334static int update(struct wan_device* wandev);
335static int new_if(struct wan_device* wandev, struct net_device* dev,
336 wanif_conf_t* conf);
337static int del_if(struct wan_device* wandev, struct net_device* dev);
338static void disable_comm (sdla_t* card);
339static void disable_comm_shutdown(sdla_t *card);
340
341
342
343/*=================================================
344 * WANPIPE-specific entry points
345 */
346static int wpx_exec (struct sdla* card, void* u_cmd, void* u_data);
347static void x25api_bh(struct net_device *dev);
348static int x25api_bh_cleanup(struct net_device *dev);
349static int bh_enqueue(struct net_device *dev, struct sk_buff *skb);
350
351
352/*=================================================
353 * Network device interface
354 */
355static int if_init(struct net_device* dev);
356static int if_open(struct net_device* dev);
357static int if_close(struct net_device* dev);
358static int if_header(struct sk_buff* skb, struct net_device* dev,
359 unsigned short type, void* daddr, void* saddr, unsigned len);
360static int if_rebuild_hdr (struct sk_buff* skb);
361static int if_send(struct sk_buff* skb, struct net_device* dev);
362static struct net_device_stats *if_stats(struct net_device* dev);
363
364static void if_tx_timeout(struct net_device *dev);
365
366/*=================================================
367 * Interrupt handlers
368 */
369static void wpx_isr (sdla_t *);
370static void rx_intr (sdla_t *);
371static void tx_intr (sdla_t *);
372static void status_intr (sdla_t *);
373static void event_intr (sdla_t *);
374static void spur_intr (sdla_t *);
375static void timer_intr (sdla_t *);
376
377static int tx_intr_send(sdla_t *card, struct net_device *dev);
378static struct net_device *move_dev_to_next(sdla_t *card,
379 struct net_device *dev);
380
381/*=================================================
382 * Background polling routines
383 */
384static void wpx_poll (sdla_t* card);
385static void poll_disconnected (sdla_t* card);
386static void poll_connecting (sdla_t* card);
387static void poll_active (sdla_t* card);
388static void trigger_x25_poll(sdla_t *card);
389static void x25_timer_routine(unsigned long data);
390
391
392
393/*=================================================
394 * X.25 firmware interface functions
395 */
396static int x25_get_version (sdla_t* card, char* str);
397static int x25_configure (sdla_t* card, TX25Config* conf);
398static int hdlc_configure (sdla_t* card, TX25Config* conf);
399static int set_hdlc_level (sdla_t* card);
400static int x25_get_err_stats (sdla_t* card);
401static int x25_get_stats (sdla_t* card);
402static int x25_set_intr_mode (sdla_t* card, int mode);
403static int x25_close_hdlc (sdla_t* card);
404static int x25_open_hdlc (sdla_t* card);
405static int x25_setup_hdlc (sdla_t* card);
406static int x25_set_dtr (sdla_t* card, int dtr);
407static int x25_get_chan_conf (sdla_t* card, x25_channel_t* chan);
408static int x25_place_call (sdla_t* card, x25_channel_t* chan);
409static int x25_accept_call (sdla_t* card, int lcn, int qdm);
410static int x25_clear_call (sdla_t* card, int lcn, int cause, int diagn);
411static int x25_send (sdla_t* card, int lcn, int qdm, int len, void* buf);
412static int x25_fetch_events (sdla_t* card);
413static int x25_error (sdla_t* card, int err, int cmd, int lcn);
414
415/*=================================================
416 * X.25 asynchronous event handlers
417 */
418static int incoming_call (sdla_t* card, int cmd, int lcn, TX25Mbox* mb);
419static int call_accepted (sdla_t* card, int cmd, int lcn, TX25Mbox* mb);
420static int call_cleared (sdla_t* card, int cmd, int lcn, TX25Mbox* mb);
421static int timeout_event (sdla_t* card, int cmd, int lcn, TX25Mbox* mb);
422static int restart_event (sdla_t* card, int cmd, int lcn, TX25Mbox* mb);
423
424
425/*=================================================
426 * Miscellaneous functions
427 */
428static int connect (sdla_t* card);
429static int disconnect (sdla_t* card);
430static struct net_device* get_dev_by_lcn(struct wan_device* wandev,
431 unsigned lcn);
432static int chan_connect(struct net_device* dev);
433static int chan_disc(struct net_device* dev);
434static void set_chan_state(struct net_device* dev, int state);
435static int chan_send(struct net_device *dev, void* buff, unsigned data_len,
436 unsigned char tx_intr);
437static unsigned char bps_to_speed_code (unsigned long bps);
438static unsigned int dec_to_uint (unsigned char* str, int len);
439static unsigned int hex_to_uint (unsigned char*, int);
440static void parse_call_info (unsigned char*, x25_call_info_t*);
441static struct net_device *find_channel(sdla_t *card, unsigned lcn);
442static void bind_lcn_to_dev(sdla_t *card, struct net_device *dev, unsigned lcn);
443static void setup_for_delayed_transmit(struct net_device *dev,
444 void *buf, unsigned len);
445
446
447/*=================================================
448 * X25 API Functions
449 */
450static int wanpipe_pull_data_in_skb(sdla_t *card, struct net_device *dev,
451 struct sk_buff **);
452static void timer_intr_exec(sdla_t *, unsigned char);
453static int execute_delayed_cmd(sdla_t *card, struct net_device *dev,
454 mbox_cmd_t *usr_cmd, char bad_cmd);
455static int api_incoming_call (sdla_t*, TX25Mbox *, int);
456static int alloc_and_init_skb_buf (sdla_t *,struct sk_buff **, int);
457static void send_delayed_cmd_result(sdla_t *card, struct net_device *dev,
458 TX25Mbox* mbox);
459static int clear_confirm_event (sdla_t *, TX25Mbox*);
460static void send_oob_msg (sdla_t *card, struct net_device *dev, TX25Mbox *mbox);
461static int timer_intr_cmd_exec(sdla_t *card);
462static void api_oob_event (sdla_t *card,TX25Mbox *mbox);
463static int check_bad_command(sdla_t *card, struct net_device *dev);
464static int channel_disconnect(sdla_t* card, struct net_device *dev);
465static void hdlc_link_down (sdla_t*);
466
467/*=================================================
468 * XPIPEMON Functions
469 */
470static int process_udp_mgmt_pkt(sdla_t *);
471static int udp_pkt_type( struct sk_buff *, sdla_t*);
472static int reply_udp( unsigned char *, unsigned int);
473static void init_x25_channel_struct( x25_channel_t *);
474static void init_global_statistics( sdla_t *);
475static int store_udp_mgmt_pkt(int udp_type, char udp_pkt_src, sdla_t *card,
476 struct net_device *dev,
477 struct sk_buff *skb, int lcn);
478static unsigned short calc_checksum (char *, int);
479
480
481
482/*=================================================
483 * IPX functions
484 */
485static void switch_net_numbers(unsigned char *, unsigned long, unsigned char);
486static int handle_IPXWAN(unsigned char *, char *, unsigned char ,
487 unsigned long , unsigned short );
488
489extern void disable_irq(unsigned int);
490extern void enable_irq(unsigned int);
491
492static void S508_S514_lock(sdla_t *, unsigned long *);
493static void S508_S514_unlock(sdla_t *, unsigned long *);
494
495
496/*=================================================
497 * Global Variables
498 *=================================================*/
499
500
501
502/*=================================================
503 * Public Functions
504 *=================================================*/
505
506
507
508
509/*===================================================================
510 * wpx_init: X.25 Protocol Initialization routine.
511 *
512 * Purpose: To initialize the protocol/firmware.
513 *
514 * Rationale: This function is called by setup() function, in
515 * sdlamain.c, to dynamically setup the x25 protocol.
516 * This is the first protocol specific function, which
517 * executes once on startup.
518 *
519 * Description: This procedure initializes the x25 firmware and
520 * sets up the mailbox, transmit and receive buffer
521 * pointers. It also initializes all debugging structures
522 * and sets up the X25 environment.
523 *
524 * Sets up hardware options defined by user in [wanpipe#]
525 * section of wanpipe#.conf configuration file.
526 *
527 * At this point adapter is completely initialized
528 * and X.25 firmware is running.
529 * o read firmware version (to make sure it's alive)
530 * o configure adapter
531 * o initialize protocol-specific fields of the
532 * adapter data space.
533 *
534 * Called by: setup() function in sdlamain.c
535 *
536 * Assumptions: None
537 *
538 * Warnings: None
539 *
540 * Return: 0 o.k.
541 * < 0 failure.
542 */
543
544int wpx_init (sdla_t* card, wandev_conf_t* conf)
545{
546 union{
547 char str[80];
548 TX25Config cfg;
549 } u;
550
551 /* Verify configuration ID */
552 if (conf->config_id != WANCONFIG_X25){
553 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
554 card->devname, conf->config_id)
555 ;
556 return -EINVAL;
557 }
558
559 /* Initialize protocol-specific fields */
560 card->mbox = (void*)(card->hw.dpmbase + X25_MBOX_OFFS);
561 card->rxmb = (void*)(card->hw.dpmbase + X25_RXMBOX_OFFS);
562 card->flags = (void*)(card->hw.dpmbase + X25_STATUS_OFFS);
563
564 /* Initialize for S514 Card */
565 if(card->hw.type == SDLA_S514) {
566 card->mbox += X25_MB_VECTOR;
567 card->flags += X25_MB_VECTOR;
568 card->rxmb += X25_MB_VECTOR;
569 }
570
571
572 /* Read firmware version. Note that when adapter initializes, it
573 * clears the mailbox, so it may appear that the first command was
574 * executed successfully when in fact it was merely erased. To work
575 * around this, we execute the first command twice.
576 */
577 if (x25_get_version(card, NULL) || x25_get_version(card, u.str))
578 return -EIO;
579
580
581 /* X25 firmware can run ether in X25 or LAPB HDLC mode.
582 * Check the user defined option and configure accordingly */
583 if (conf->u.x25.LAPB_hdlc_only == WANOPT_YES){
584 if (set_hdlc_level(card) != CMD_OK){
585 return -EIO;
586 }else{
587 printk(KERN_INFO "%s: running LAP_B HDLC firmware v%s\n",
588 card->devname, u.str);
589 }
590 card->u.x.LAPB_hdlc = 1;
591 }else{
592 printk(KERN_INFO "%s: running X.25 firmware v%s\n",
593 card->devname, u.str);
594 card->u.x.LAPB_hdlc = 0;
595 }
596
597 /* Configure adapter. Here we set resonable defaults, then parse
598 * device configuration structure and set configuration options.
599 * Most configuration options are verified and corrected (if
600 * necessary) since we can't rely on the adapter to do so.
601 */
602 memset(&u.cfg, 0, sizeof(u.cfg));
603 u.cfg.t1 = 3;
604 u.cfg.n2 = 10;
605 u.cfg.autoHdlc = 1; /* automatic HDLC connection */
606 u.cfg.hdlcWindow = 7;
607 u.cfg.pktWindow = 2;
608 u.cfg.station = 1; /* DTE */
609 u.cfg.options = 0x0090; /* disable D-bit pragmatics */
610 u.cfg.ccittCompat = 1988;
611 u.cfg.t10t20 = 30;
612 u.cfg.t11t21 = 30;
613 u.cfg.t12t22 = 30;
614 u.cfg.t13t23 = 30;
615 u.cfg.t16t26 = 30;
616 u.cfg.t28 = 30;
617 u.cfg.r10r20 = 5;
618 u.cfg.r12r22 = 5;
619 u.cfg.r13r23 = 5;
620 u.cfg.responseOpt = 1; /* RR's after every packet */
621
622 if (card->u.x.LAPB_hdlc){
623 u.cfg.hdlcMTU = 1027;
624 }
625
626 if (conf->u.x25.x25_conf_opt){
627 u.cfg.options = conf->u.x25.x25_conf_opt;
628 }
629
630 if (conf->clocking != WANOPT_EXTERNAL)
631 u.cfg.baudRate = bps_to_speed_code(conf->bps);
632
633 if (conf->station != WANOPT_DTE){
634 u.cfg.station = 0; /* DCE mode */
635 }
636
637 if (conf->interface != WANOPT_RS232 ){
638 u.cfg.hdlcOptions |= 0x80; /* V35 mode */
639 }
640
641 /* adjust MTU */
642 if (!conf->mtu || (conf->mtu >= 1024))
643 card->wandev.mtu = 1024;
644 else if (conf->mtu >= 512)
645 card->wandev.mtu = 512;
646 else if (conf->mtu >= 256)
647 card->wandev.mtu = 256;
648 else if (conf->mtu >= 128)
649 card->wandev.mtu = 128;
650 else
651 card->wandev.mtu = 64;
652
653 u.cfg.defPktSize = u.cfg.pktMTU = card->wandev.mtu;
654
655 if (conf->u.x25.hi_pvc){
656 card->u.x.hi_pvc = min_t(unsigned int, conf->u.x25.hi_pvc, MAX_LCN_NUM);
657 card->u.x.lo_pvc = min_t(unsigned int, conf->u.x25.lo_pvc, card->u.x.hi_pvc);
658 }
659
660 if (conf->u.x25.hi_svc){
661 card->u.x.hi_svc = min_t(unsigned int, conf->u.x25.hi_svc, MAX_LCN_NUM);
662 card->u.x.lo_svc = min_t(unsigned int, conf->u.x25.lo_svc, card->u.x.hi_svc);
663 }
664
665 /* Figure out the total number of channels to configure */
666 card->u.x.num_of_ch = 0;
667 if (card->u.x.hi_svc != 0){
668 card->u.x.num_of_ch = (card->u.x.hi_svc - card->u.x.lo_svc) + 1;
669 }
670 if (card->u.x.hi_pvc != 0){
671 card->u.x.num_of_ch += (card->u.x.hi_pvc - card->u.x.lo_pvc) + 1;
672 }
673
674 if (card->u.x.num_of_ch == 0){
675 printk(KERN_INFO "%s: ERROR, Minimum number of PVC/SVC channels is 1 !\n"
676 "%s: Please set the Lowest/Highest PVC/SVC values !\n",
677 card->devname,card->devname);
678 return -ECHRNG;
679 }
680
681 u.cfg.loPVC = card->u.x.lo_pvc;
682 u.cfg.hiPVC = card->u.x.hi_pvc;
683 u.cfg.loTwoWaySVC = card->u.x.lo_svc;
684 u.cfg.hiTwoWaySVC = card->u.x.hi_svc;
685
686 if (conf->u.x25.hdlc_window)
687 u.cfg.hdlcWindow = min_t(unsigned int, conf->u.x25.hdlc_window, 7);
688 if (conf->u.x25.pkt_window)
689 u.cfg.pktWindow = min_t(unsigned int, conf->u.x25.pkt_window, 7);
690
691 if (conf->u.x25.t1)
692 u.cfg.t1 = min_t(unsigned int, conf->u.x25.t1, 30);
693 if (conf->u.x25.t2)
694 u.cfg.t2 = min_t(unsigned int, conf->u.x25.t2, 29);
695 if (conf->u.x25.t4)
696 u.cfg.t4 = min_t(unsigned int, conf->u.x25.t4, 240);
697 if (conf->u.x25.n2)
698 u.cfg.n2 = min_t(unsigned int, conf->u.x25.n2, 30);
699
700 if (conf->u.x25.t10_t20)
701 u.cfg.t10t20 = min_t(unsigned int, conf->u.x25.t10_t20,255);
702 if (conf->u.x25.t11_t21)
703 u.cfg.t11t21 = min_t(unsigned int, conf->u.x25.t11_t21,255);
704 if (conf->u.x25.t12_t22)
705 u.cfg.t12t22 = min_t(unsigned int, conf->u.x25.t12_t22,255);
706 if (conf->u.x25.t13_t23)
707 u.cfg.t13t23 = min_t(unsigned int, conf->u.x25.t13_t23,255);
708 if (conf->u.x25.t16_t26)
709 u.cfg.t16t26 = min_t(unsigned int, conf->u.x25.t16_t26, 255);
710 if (conf->u.x25.t28)
711 u.cfg.t28 = min_t(unsigned int, conf->u.x25.t28, 255);
712
713 if (conf->u.x25.r10_r20)
714 u.cfg.r10r20 = min_t(unsigned int, conf->u.x25.r10_r20,250);
715 if (conf->u.x25.r12_r22)
716 u.cfg.r12r22 = min_t(unsigned int, conf->u.x25.r12_r22,250);
717 if (conf->u.x25.r13_r23)
718 u.cfg.r13r23 = min_t(unsigned int, conf->u.x25.r13_r23,250);
719
720
721 if (conf->u.x25.ccitt_compat)
722 u.cfg.ccittCompat = conf->u.x25.ccitt_compat;
723
724 /* initialize adapter */
725 if (card->u.x.LAPB_hdlc){
726 if (hdlc_configure(card, &u.cfg) != CMD_OK)
727 return -EIO;
728 }else{
729 if (x25_configure(card, &u.cfg) != CMD_OK)
730 return -EIO;
731 }
732
733 if ((x25_close_hdlc(card) != CMD_OK) || /* close HDLC link */
734 (x25_set_dtr(card, 0) != CMD_OK)) /* drop DTR */
735 return -EIO;
736
737 /* Initialize protocol-specific fields of adapter data space */
738 card->wandev.bps = conf->bps;
739 card->wandev.interface = conf->interface;
740 card->wandev.clocking = conf->clocking;
741 card->wandev.station = conf->station;
742 card->isr = &wpx_isr;
743 card->poll = NULL; //&wpx_poll;
744 card->disable_comm = &disable_comm;
745 card->exec = &wpx_exec;
746 card->wandev.update = &update;
747 card->wandev.new_if = &new_if;
748 card->wandev.del_if = &del_if;
749
750 /* WARNING: This function cannot exit with an error
751 * after the change of state */
752 card->wandev.state = WAN_DISCONNECTED;
753
754 card->wandev.enable_tx_int = 0;
755 card->irq_dis_if_send_count = 0;
756 card->irq_dis_poll_count = 0;
757 card->u.x.tx_dev = NULL;
758 card->u.x.no_dev = 0;
759
760
761 /* Configure for S514 PCI Card */
762 if (card->hw.type == SDLA_S514) {
763 card->u.x.hdlc_buf_status =
764 (volatile unsigned char *)
765 (card->hw.dpmbase + X25_MB_VECTOR+ X25_MISC_HDLC_BITS);
766 }else{
767 card->u.x.hdlc_buf_status =
768 (volatile unsigned char *)(card->hw.dpmbase + X25_MISC_HDLC_BITS);
769 }
770
771 card->u.x.poll_device=NULL;
772 card->wandev.udp_port = conf->udp_port;
773
774 /* Enable or disable call setup logging */
775 if (conf->u.x25.logging == WANOPT_YES){
776 printk(KERN_INFO "%s: Enabling Call Logging.\n",
777 card->devname);
778 card->u.x.logging = 1;
779 }else{
780 card->u.x.logging = 0;
781 }
782
783 /* Enable or disable modem status reporting */
784 if (conf->u.x25.oob_on_modem == WANOPT_YES){
785 printk(KERN_INFO "%s: Enabling OOB on Modem change.\n",
786 card->devname);
787 card->u.x.oob_on_modem = 1;
788 }else{
789 card->u.x.oob_on_modem = 0;
790 }
791
792 init_global_statistics(card);
793
794 INIT_WORK(&card->u.x.x25_poll_work, (void *)wpx_poll, card);
795
796 init_timer(&card->u.x.x25_timer);
797 card->u.x.x25_timer.data = (unsigned long)card;
798 card->u.x.x25_timer.function = x25_timer_routine;
799
800 return 0;
801}
802
803/*=========================================================
804 * WAN Device Driver Entry Points
805 *========================================================*/
806
807/*============================================================
808 * Name: update(), Update device status & statistics.
809 *
810 * Purpose: To provide debugging and statitical
811 * information to the /proc file system.
812 * /proc/net/wanrouter/wanpipe#
813 *
814 * Rationale: The /proc file system is used to collect
815 * information about the kernel and drivers.
816 * Using the /proc file system the user
817 * can see exactly what the sangoma drivers are
818 * doing. And in what state they are in.
819 *
820 * Description: Collect all driver statistical information
821 * and pass it to the top laywer.
822 *
823 * Since we have to execute a debugging command,
824 * to obtain firmware statitics, we trigger a
825 * UPDATE function within the timer interrtup.
826 * We wait until the timer update is complete.
827 * Once complete return the appropriate return
828 * code to indicate that the update was successful.
829 *
830 * Called by: device_stat() in wanmain.c
831 *
832 * Assumptions:
833 *
834 * Warnings: This function will degrade the performance
835 * of the router, since it uses the mailbox.
836 *
837 * Return: 0 OK
838 * <0 Failed (or busy).
839 */
840
841static int update(struct wan_device* wandev)
842{
843 volatile sdla_t* card;
844 TX25Status* status;
845 unsigned long timeout;
846
847 /* sanity checks */
848 if ((wandev == NULL) || (wandev->private == NULL))
849 return -EFAULT;
850
851 if (wandev->state == WAN_UNCONFIGURED)
852 return -ENODEV;
853
854 if (test_bit(SEND_CRIT, (void*)&wandev->critical))
855 return -EAGAIN;
856
857 if (!wandev->dev)
858 return -ENODEV;
859
860 card = wandev->private;
861 status = card->flags;
862
863 card->u.x.timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
864 status->imask |= INTR_ON_TIMER;
865 timeout = jiffies;
866
867 for (;;){
868 if (!(card->u.x.timer_int_enabled & TMR_INT_ENABLED_UPDATE)){
869 break;
870 }
871 if (time_after(jiffies, timeout + 1*HZ)){
872 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE;
873 return -EAGAIN;
874 }
875 }
876 return 0;
877}
878
879
880/*===================================================================
881 * Name: new_if
882 *
883 * Purpose: To allocate and initialize resources for a
884 * new logical channel.
885 *
886 * Rationale: A new channel can be added dynamically via
887 * ioctl call.
888 *
889 * Description: Allocate a private channel structure, x25_channel_t.
890 * Parse the user interface options from wanpipe#.conf
891 * configuration file.
892 * Bind the private are into the network device private
893 * area pointer (dev->priv).
894 * Prepare the network device structure for registration.
895 *
896 * Called by: ROUTER_IFNEW Ioctl call, from wanrouter_ioctl()
897 * (wanmain.c)
898 *
899 * Assumptions: None
900 *
901 * Warnings: None
902 *
903 * Return: 0 Ok
904 * <0 Failed (channel will not be created)
905 */
906static int new_if(struct wan_device* wandev, struct net_device* dev,
907 wanif_conf_t* conf)
908{
909 sdla_t* card = wandev->private;
910 x25_channel_t* chan;
911 int err = 0;
912
913 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)){
914 printk(KERN_INFO "%s: invalid interface name!\n",
915 card->devname);
916 return -EINVAL;
917 }
918
919 if(card->wandev.new_if_cnt++ > 0 && card->u.x.LAPB_hdlc) {
920 printk(KERN_INFO "%s: Error: Running LAPB HDLC Mode !\n",
921 card->devname);
922 printk(KERN_INFO
923 "%s: Maximum number of network interfaces must be one !\n",
924 card->devname);
925 return -EEXIST;
926 }
927
928 /* allocate and initialize private data */
929 chan = kmalloc(sizeof(x25_channel_t), GFP_ATOMIC);
930 if (chan == NULL){
931 return -ENOMEM;
932 }
933
934 memset(chan, 0, sizeof(x25_channel_t));
935
936 /* Bug Fix: Seg Err on PVC startup
937 * It must be here since bind_lcn_to_dev expects
938 * it bellow */
939 dev->priv = chan;
940
941 strcpy(chan->name, conf->name);
942 chan->card = card;
943 chan->dev = dev;
944 chan->common.sk = NULL;
945 chan->common.func = NULL;
946 chan->common.rw_bind = 0;
947 chan->tx_skb = chan->rx_skb = NULL;
948
949 /* verify media address */
950 if (conf->addr[0] == '@'){ /* SVC */
951 chan->common.svc = 1;
952 strncpy(chan->addr, &conf->addr[1], WAN_ADDRESS_SZ);
953
954 /* Set channel timeouts (default if not specified) */
955 chan->idle_timeout = (conf->idle_timeout) ?
956 conf->idle_timeout : 90;
957 chan->hold_timeout = (conf->hold_timeout) ?
958 conf->hold_timeout : 10;
959
960 }else if (isdigit(conf->addr[0])){ /* PVC */
961 int lcn = dec_to_uint(conf->addr, 0);
962
963 if ((lcn >= card->u.x.lo_pvc) && (lcn <= card->u.x.hi_pvc)){
964 bind_lcn_to_dev (card, dev, lcn);
965 }else{
966 printk(KERN_ERR
967 "%s: PVC %u is out of range on interface %s!\n",
968 wandev->name, lcn, chan->name);
969 err = -EINVAL;
970 }
971 }else{
972 printk(KERN_ERR
973 "%s: invalid media address on interface %s!\n",
974 wandev->name, chan->name);
975 err = -EINVAL;
976 }
977
978 if(strcmp(conf->usedby, "WANPIPE") == 0){
979 printk(KERN_INFO "%s: Running in WANPIPE mode %s\n",
980 wandev->name, chan->name);
981 chan->common.usedby = WANPIPE;
982 chan->protocol = htons(ETH_P_IP);
983
984 }else if(strcmp(conf->usedby, "API") == 0){
985 chan->common.usedby = API;
986 printk(KERN_INFO "%s: Running in API mode %s\n",
987 wandev->name, chan->name);
988 chan->protocol = htons(X25_PROT);
989 }
990
991
992 if (err){
993 kfree(chan);
994 dev->priv = NULL;
995 return err;
996 }
997
998 chan->enable_IPX = conf->enable_IPX;
999
1000 if (chan->enable_IPX)
1001 chan->protocol = htons(ETH_P_IPX);
1002
1003 if (conf->network_number)
1004 chan->network_number = conf->network_number;
1005 else
1006 chan->network_number = 0xDEADBEEF;
1007
1008 /* prepare network device data space for registration */
1009 strcpy(dev->name,chan->name);
1010
1011 dev->init = &if_init;
1012
1013 init_x25_channel_struct(chan);
1014
1015 return 0;
1016}
1017
1018/*===================================================================
1019 * Name: del_if(), Remove a logical channel.
1020 *
1021 * Purpose: To dynamically remove a logical channel.
1022 *
1023 * Rationale: Each logical channel should be dynamically
1024 * removable. This functin is called by an
1025 * IOCTL_IFDEL ioctl call or shutdown().
1026 *
1027 * Description: Do nothing.
1028 *
1029 * Called by: IOCTL_IFDEL : wanrouter_ioctl() from wanmain.c
1030 * shutdown() from sdlamain.c
1031 *
1032 * Assumptions:
1033 *
1034 * Warnings:
1035 *
1036 * Return: 0 Ok. Void function.
1037 */
1038
1039//FIXME Del IF Should be taken out now.
1040
1041static int del_if(struct wan_device* wandev, struct net_device* dev)
1042{
1043 return 0;
1044}
1045
1046
1047/*============================================================
1048 * Name: wpx_exec
1049 *
1050 * Description: Execute adapter interface command.
1051 * This option is currently dissabled.
1052 *===========================================================*/
1053
1054static int wpx_exec (struct sdla* card, void* u_cmd, void* u_data)
1055{
1056 return 0;
1057}
1058
1059/*============================================================
1060 * Name: disable_comm
1061 *
1062 * Description: Disable communications during shutdown.
1063 * Dont check return code because there is
1064 * nothing we can do about it.
1065 *
1066 * Warning: Dev and private areas are gone at this point.
1067 *===========================================================*/
1068
1069static void disable_comm(sdla_t* card)
1070{
1071 disable_comm_shutdown(card);
1072 del_timer(&card->u.x.x25_timer);
1073 return;
1074}
1075
1076
1077/*============================================================
1078 * Network Device Interface
1079 *===========================================================*/
1080
1081/*===================================================================
1082 * Name: if_init(), Netowrk Interface Initialization
1083 *
1084 * Purpose: To initialize a network interface device structure.
1085 *
1086 * Rationale: During network interface startup, the if_init
1087 * is called by the kernel to initialize the
1088 * netowrk device structure. Thus a driver
1089 * can customze a network device.
1090 *
1091 * Description: Initialize the netowrk device call back
1092 * routines. This is where we tell the kernel
1093 * which function to use when it wants to send
1094 * via our interface.
1095 * Furthermore, we initialize the device flags,
1096 * MTU and physical address of the board.
1097 *
1098 * Called by: Kernel (/usr/src/linux/net/core/dev.c)
1099 * (dev->init())
1100 *
1101 * Assumptions: None
1102 *
1103 * Warnings: None
1104 *
1105 * Return: 0 Ok : Void function.
1106 */
1107static int if_init(struct net_device* dev)
1108{
1109 x25_channel_t* chan = dev->priv;
1110 sdla_t* card = chan->card;
1111 struct wan_device* wandev = &card->wandev;
1112
1113 /* Initialize device driver entry points */
1114 dev->open = &if_open;
1115 dev->stop = &if_close;
1116 dev->hard_header = &if_header;
1117 dev->rebuild_header = &if_rebuild_hdr;
1118 dev->hard_start_xmit = &if_send;
1119 dev->get_stats = &if_stats;
1120 dev->tx_timeout = &if_tx_timeout;
1121 dev->watchdog_timeo = TX_TIMEOUT;
1122
1123 /* Initialize media-specific parameters */
1124 dev->type = ARPHRD_PPP; /* ARP h/w type */
1125 dev->flags |= IFF_POINTOPOINT;
1126 dev->flags |= IFF_NOARP;
1127
1128 if (chan->common.usedby == API){
1129 dev->mtu = X25_CHAN_MTU+sizeof(x25api_hdr_t);
1130 }else{
1131 dev->mtu = card->wandev.mtu;
1132 }
1133
1134 dev->hard_header_len = X25_HRDHDR_SZ; /* media header length */
1135 dev->addr_len = 2; /* hardware address length */
1136
1137 if (!chan->common.svc){
1138 *(unsigned short*)dev->dev_addr = htons(chan->common.lcn);
1139 }
1140
1141 /* Initialize hardware parameters (just for reference) */
1142 dev->irq = wandev->irq;
1143 dev->dma = wandev->dma;
1144 dev->base_addr = wandev->ioport;
1145 dev->mem_start = (unsigned long)wandev->maddr;
1146 dev->mem_end = wandev->maddr + wandev->msize - 1;
1147
1148 /* Set transmit buffer queue length */
1149 dev->tx_queue_len = 100;
1150 SET_MODULE_OWNER(dev);
1151
1152 /* FIXME Why are we doing this */
1153 set_chan_state(dev, WAN_DISCONNECTED);
1154 return 0;
1155}
1156
1157
1158/*===================================================================
1159 * Name: if_open(), Open/Bring up the Netowrk Interface
1160 *
1161 * Purpose: To bring up a network interface.
1162 *
1163 * Rationale:
1164 *
1165 * Description: Open network interface.
1166 * o prevent module from unloading by incrementing use count
1167 * o if link is disconnected then initiate connection
1168 *
1169 * Called by: Kernel (/usr/src/linux/net/core/dev.c)
1170 * (dev->open())
1171 *
1172 * Assumptions: None
1173 *
1174 * Warnings: None
1175 *
1176 * Return: 0 Ok
1177 * <0 Failure: Interface will not come up.
1178 */
1179
1180static int if_open(struct net_device* dev)
1181{
1182 x25_channel_t* chan = dev->priv;
1183 sdla_t* card = chan->card;
1184 struct timeval tv;
1185 unsigned long smp_flags;
1186
1187 if (netif_running(dev))
1188 return -EBUSY;
1189
1190 chan->tq_working = 0;
1191
1192 /* Initialize the workqueue */
1193 INIT_WORK(&chan->common.wanpipe_work, (void *)x25api_bh, dev);
1194
1195 /* Allocate and initialize BH circular buffer */
1196 /* Add 1 to MAX_BH_BUFF so we don't have test with (MAX_BH_BUFF-1) */
1197 chan->bh_head = kmalloc((sizeof(bh_data_t)*(MAX_BH_BUFF+1)),GFP_ATOMIC);
1198
1199 if (chan->bh_head == NULL){
1200 printk(KERN_INFO "%s: ERROR, failed to allocate memory ! BH_BUFFERS !\n",
1201 card->devname);
1202
1203 return -ENOBUFS;
1204 }
1205 memset(chan->bh_head,0,(sizeof(bh_data_t)*(MAX_BH_BUFF+1)));
1206 atomic_set(&chan->bh_buff_used, 0);
1207
1208 /* Increment the number of interfaces */
1209 ++card->u.x.no_dev;
1210
1211 wanpipe_open(card);
1212
1213 /* LAPB protocol only uses one interface, thus
1214 * start the protocol after it comes up. */
1215 if (card->u.x.LAPB_hdlc){
1216 if (card->open_cnt == 1){
1217 TX25Status* status = card->flags;
1218 S508_S514_lock(card, &smp_flags);
1219 x25_set_intr_mode(card, INTR_ON_TIMER);
1220 status->imask &= ~INTR_ON_TIMER;
1221 S508_S514_unlock(card, &smp_flags);
1222 }
1223 }else{
1224 /* X25 can have multiple interfaces thus, start the
1225 * protocol once all interfaces are up */
1226
1227 //FIXME: There is a bug here. If interface is
1228 //brought down and up, it will try to enable comm.
1229 if (card->open_cnt == card->u.x.num_of_ch){
1230
1231 S508_S514_lock(card, &smp_flags);
1232 connect(card);
1233 S508_S514_unlock(card, &smp_flags);
1234
1235 mod_timer(&card->u.x.x25_timer, jiffies + HZ);
1236 }
1237 }
1238 /* Device is not up until the we are in connected state */
1239 do_gettimeofday( &tv );
1240 chan->router_start_time = tv.tv_sec;
1241
1242 netif_start_queue(dev);
1243
1244 return 0;
1245}
1246
1247/*===================================================================
1248 * Name: if_close(), Close/Bring down the Netowrk Interface
1249 *
1250 * Purpose: To bring down a network interface.
1251 *
1252 * Rationale:
1253 *
1254 * Description: Close network interface.
1255 * o decrement use module use count
1256 *
1257 * Called by: Kernel (/usr/src/linux/net/core/dev.c)
1258 * (dev->close())
1259 * ifconfig <name> down: will trigger the kernel
1260 * which will call this function.
1261 *
1262 * Assumptions: None
1263 *
1264 * Warnings: None
1265 *
1266 * Return: 0 Ok
1267 * <0 Failure: Interface will not exit properly.
1268 */
1269static int if_close(struct net_device* dev)
1270{
1271 x25_channel_t* chan = dev->priv;
1272 sdla_t* card = chan->card;
1273 unsigned long smp_flags;
1274
1275 netif_stop_queue(dev);
1276
1277 if ((chan->common.state == WAN_CONNECTED) ||
1278 (chan->common.state == WAN_CONNECTING)){
1279 S508_S514_lock(card, &smp_flags);
1280 chan_disc(dev);
1281 S508_S514_unlock(card, &smp_flags);
1282 }
1283
1284 wanpipe_close(card);
1285
1286 S508_S514_lock(card, &smp_flags);
1287 if (chan->bh_head){
1288 int i;
1289 struct sk_buff *skb;
1290
1291 for (i=0; i<(MAX_BH_BUFF+1); i++){
1292 skb = ((bh_data_t *)&chan->bh_head[i])->skb;
1293 if (skb != NULL){
1294 dev_kfree_skb_any(skb);
1295 }
1296 }
1297 kfree(chan->bh_head);
1298 chan->bh_head=NULL;
1299 }
1300 S508_S514_unlock(card, &smp_flags);
1301
1302 /* If this is the last close, disconnect physical link */
1303 if (!card->open_cnt){
1304 S508_S514_lock(card, &smp_flags);
1305 disconnect(card);
1306 x25_set_intr_mode(card, 0);
1307 S508_S514_unlock(card, &smp_flags);
1308 }
1309
1310 /* Decrement the number of interfaces */
1311 --card->u.x.no_dev;
1312 return 0;
1313}
1314
1315/*======================================================================
1316 * Build media header.
1317 * o encapsulate packet according to encapsulation type.
1318 *
1319 * The trick here is to put packet type (Ethertype) into 'protocol'
1320 * field of the socket buffer, so that we don't forget it.
1321 * If encapsulation fails, set skb->protocol to 0 and discard
1322 * packet later.
1323 *
1324 * Return: media header length.
1325 *======================================================================*/
1326
1327static int if_header(struct sk_buff* skb, struct net_device* dev,
1328 unsigned short type, void* daddr, void* saddr,
1329 unsigned len)
1330{
1331 x25_channel_t* chan = dev->priv;
1332 int hdr_len = dev->hard_header_len;
1333
1334 skb->protocol = htons(type);
1335 if (!chan->protocol){
1336 hdr_len = wanrouter_encapsulate(skb, dev, type);
1337 if (hdr_len < 0){
1338 hdr_len = 0;
1339 skb->protocol = htons(0);
1340 }
1341 }
1342 return hdr_len;
1343}
1344
1345/*===============================================================
1346 * Re-build media header.
1347 *
1348 * Return: 1 physical address resolved.
1349 * 0 physical address not resolved
1350 *==============================================================*/
1351
1352static int if_rebuild_hdr (struct sk_buff* skb)
1353{
1354 struct net_device *dev = skb->dev;
1355 x25_channel_t* chan = dev->priv;
1356 sdla_t* card = chan->card;
1357
1358 printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
1359 card->devname, dev->name);
1360 return 1;
1361}
1362
1363
1364/*============================================================================
1365 * Handle transmit timeout event from netif watchdog
1366 */
1367static void if_tx_timeout(struct net_device *dev)
1368{
1369 x25_channel_t* chan = dev->priv;
1370 sdla_t *card = chan->card;
1371
1372 /* If our device stays busy for at least 5 seconds then we will
1373 * kick start the device by making dev->tbusy = 0. We expect
1374 * that our device never stays busy more than 5 seconds. So this
1375 * is only used as a last resort.
1376 */
1377
1378 ++chan->if_send_stat.if_send_tbusy_timeout;
1379 printk (KERN_INFO "%s: Transmit timed out on %s\n",
1380 card->devname, dev->name);
1381 netif_wake_queue (dev);
1382}
1383
1384
1385/*=========================================================================
1386 * Send a packet on a network interface.
1387 * o set tbusy flag (marks start of the transmission).
1388 * o check link state. If link is not up, then drop the packet.
1389 * o check channel status. If it's down then initiate a call.
1390 * o pass a packet to corresponding WAN device.
1391 * o free socket buffer
1392 *
1393 * Return: 0 complete (socket buffer must be freed)
1394 * non-0 packet may be re-transmitted (tbusy must be set)
1395 *
1396 * Notes:
1397 * 1. This routine is called either by the protocol stack or by the "net
1398 * bottom half" (with interrupts enabled).
1399 * 2. Setting tbusy flag will inhibit further transmit requests from the
1400 * protocol stack and can be used for flow control with protocol layer.
1401 *
1402 *========================================================================*/
1403
1404static int if_send(struct sk_buff* skb, struct net_device* dev)
1405{
1406 x25_channel_t* chan = dev->priv;
1407 sdla_t* card = chan->card;
1408 TX25Status* status = card->flags;
1409 int udp_type;
1410 unsigned long smp_flags=0;
1411
1412 ++chan->if_send_stat.if_send_entry;
1413
1414 netif_stop_queue(dev);
1415
1416 /* No need to check frame length, since socket code
1417 * will perform the check for us */
1418
1419 chan->tick_counter = jiffies;
1420
1421 /* Critical region starts here */
1422 S508_S514_lock(card, &smp_flags);
1423
1424 if (test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)){
1425 printk(KERN_INFO "Hit critical in if_send()! %lx\n",card->wandev.critical);
1426 goto if_send_crit_exit;
1427 }
1428
1429 udp_type = udp_pkt_type(skb, card);
1430
1431 if(udp_type != UDP_INVALID_TYPE) {
1432
1433 if(store_udp_mgmt_pkt(udp_type, UDP_PKT_FRM_STACK, card, dev, skb,
1434 chan->common.lcn)) {
1435
1436 status->imask |= INTR_ON_TIMER;
1437 if (udp_type == UDP_XPIPE_TYPE){
1438 chan->if_send_stat.if_send_PIPE_request++;
1439 }
1440 }
1441 netif_start_queue(dev);
1442 clear_bit(SEND_CRIT,(void*)&card->wandev.critical);
1443 S508_S514_unlock(card, &smp_flags);
1444 return 0;
1445 }
1446
1447 if (chan->transmit_length){
1448 //FIXME: This check doesn't make sense any more
1449 if (chan->common.state != WAN_CONNECTED){
1450 chan->transmit_length=0;
1451 atomic_set(&chan->common.driver_busy,0);
1452 }else{
1453 netif_stop_queue(dev);
1454 ++card->u.x.tx_interrupts_pending;
1455 status->imask |= INTR_ON_TX_FRAME;
1456 clear_bit(SEND_CRIT,(void*)&card->wandev.critical);
1457 S508_S514_unlock(card, &smp_flags);
1458 return 1;
1459 }
1460 }
1461
1462 if (card->wandev.state != WAN_CONNECTED){
1463 ++chan->ifstats.tx_dropped;
1464 ++card->wandev.stats.tx_dropped;
1465 ++chan->if_send_stat.if_send_wan_disconnected;
1466
1467 }else if ( chan->protocol && (chan->protocol != skb->protocol)){
1468 printk(KERN_INFO
1469 "%s: unsupported Ethertype 0x%04X on interface %s!\n",
1470 chan->name, htons(skb->protocol), dev->name);
1471
1472 printk(KERN_INFO "PROTO %Xn", htons(chan->protocol));
1473 ++chan->ifstats.tx_errors;
1474 ++chan->ifstats.tx_dropped;
1475 ++card->wandev.stats.tx_dropped;
1476 ++chan->if_send_stat.if_send_protocol_error;
1477
1478 }else switch (chan->common.state){
1479
1480 case WAN_DISCONNECTED:
1481 /* Try to establish connection. If succeded, then start
1482 * transmission, else drop a packet.
1483 */
1484 if (chan->common.usedby == API){
1485 ++chan->ifstats.tx_dropped;
1486 ++card->wandev.stats.tx_dropped;
1487 break;
1488 }else{
1489 if (chan_connect(dev) != 0){
1490 ++chan->ifstats.tx_dropped;
1491 ++card->wandev.stats.tx_dropped;
1492 break;
1493 }
1494 }
1495 /* fall through */
1496
1497 case WAN_CONNECTED:
1498 if( skb->protocol == htons(ETH_P_IPX)) {
1499 if(chan->enable_IPX) {
1500 switch_net_numbers( skb->data,
1501 chan->network_number, 0);
1502 } else {
1503 ++card->wandev.stats.tx_dropped;
1504 ++chan->ifstats.tx_dropped;
1505 ++chan->if_send_stat.if_send_protocol_error;
1506 goto if_send_crit_exit;
1507 }
1508 }
1509 /* We never drop here, if cannot send than, copy
1510 * a packet into a transmit buffer
1511 */
1512 chan_send(dev, skb->data, skb->len, 0);
1513 break;
1514
1515 default:
1516 ++chan->ifstats.tx_dropped;
1517 ++card->wandev.stats.tx_dropped;
1518 break;
1519 }
1520
1521
1522if_send_crit_exit:
1523
1524 dev_kfree_skb_any(skb);
1525
1526 netif_start_queue(dev);
1527 clear_bit(SEND_CRIT,(void*)&card->wandev.critical);
1528 S508_S514_unlock(card, &smp_flags);
1529 return 0;
1530}
1531
1532/*============================================================================
1533 * Setup so that a frame can be transmitted on the occurrence of a transmit
1534 * interrupt.
1535 *===========================================================================*/
1536
1537static void setup_for_delayed_transmit(struct net_device* dev, void* buf,
1538 unsigned len)
1539{
1540 x25_channel_t* chan = dev->priv;
1541 sdla_t* card = chan->card;
1542 TX25Status* status = card->flags;
1543
1544 ++chan->if_send_stat.if_send_adptr_bfrs_full;
1545
1546 if(chan->transmit_length) {
1547 printk(KERN_INFO "%s: Error, transmit length set in delayed transmit!\n",
1548 card->devname);
1549 return;
1550 }
1551
1552 if (chan->common.usedby == API){
1553 if (len > X25_CHAN_MTU+sizeof(x25api_hdr_t)) {
1554 ++chan->ifstats.tx_dropped;
1555 ++card->wandev.stats.tx_dropped;
1556 printk(KERN_INFO "%s: Length is too big for delayed transmit\n",
1557 card->devname);
1558 return;
1559 }
1560 }else{
1561 if (len > X25_MAX_DATA) {
1562 ++chan->ifstats.tx_dropped;
1563 ++card->wandev.stats.tx_dropped;
1564 printk(KERN_INFO "%s: Length is too big for delayed transmit\n",
1565 card->devname);
1566 return;
1567 }
1568 }
1569
1570 chan->transmit_length = len;
1571 atomic_set(&chan->common.driver_busy,1);
1572 memcpy(chan->transmit_buffer, buf, len);
1573
1574 ++chan->if_send_stat.if_send_tx_int_enabled;
1575
1576 /* Enable Transmit Interrupt */
1577 ++card->u.x.tx_interrupts_pending;
1578 status->imask |= INTR_ON_TX_FRAME;
1579}
1580
1581
1582/*===============================================================
1583 * net_device_stats
1584 *
1585 * Get ethernet-style interface statistics.
1586 * Return a pointer to struct enet_statistics.
1587 *
1588 *==============================================================*/
1589static struct net_device_stats *if_stats(struct net_device* dev)
1590{
1591 x25_channel_t *chan = dev->priv;
1592
1593 if(chan == NULL)
1594 return NULL;
1595
1596 return &chan->ifstats;
1597}
1598
1599
1600/*
1601 * Interrupt Handlers
1602 */
1603
1604/*
1605 * X.25 Interrupt Service Routine.
1606 */
1607
1608static void wpx_isr (sdla_t* card)
1609{
1610 TX25Status* status = card->flags;
1611
1612 card->in_isr = 1;
1613 ++card->statistics.isr_entry;
1614
1615 if (test_bit(PERI_CRIT,(void*)&card->wandev.critical)){
1616 card->in_isr=0;
1617 status->iflags = 0;
1618 return;
1619 }
1620
1621 if (test_bit(SEND_CRIT, (void*)&card->wandev.critical)){
1622
1623 printk(KERN_INFO "%s: wpx_isr: wandev.critical set to 0x%02lx, int type = 0x%02x\n",
1624 card->devname, card->wandev.critical, status->iflags);
1625 card->in_isr = 0;
1626 status->iflags = 0;
1627 return;
1628 }
1629
1630 /* For all interrupts set the critical flag to CRITICAL_RX_INTR.
1631 * If the if_send routine is called with this flag set it will set
1632 * the enable transmit flag to 1. (for a delayed interrupt)
1633 */
1634 switch (status->iflags){
1635
1636 case RX_INTR_PENDING: /* receive interrupt */
1637 rx_intr(card);
1638 break;
1639
1640 case TX_INTR_PENDING: /* transmit interrupt */
1641 tx_intr(card);
1642 break;
1643
1644 case MODEM_INTR_PENDING: /* modem status interrupt */
1645 status_intr(card);
1646 break;
1647
1648 case X25_ASY_TRANS_INTR_PENDING: /* network event interrupt */
1649 event_intr(card);
1650 break;
1651
1652 case TIMER_INTR_PENDING:
1653 timer_intr(card);
1654 break;
1655
1656 default: /* unwanted interrupt */
1657 spur_intr(card);
1658 }
1659
1660 card->in_isr = 0;
1661 status->iflags = 0; /* clear interrupt condition */
1662}
1663
1664/*
1665 * Receive interrupt handler.
1666 * This routine handles fragmented IP packets using M-bit according to the
1667 * RFC1356.
1668 * o map ligical channel number to network interface.
1669 * o allocate socket buffer or append received packet to the existing one.
1670 * o if M-bit is reset (i.e. it's the last packet in a sequence) then
1671 * decapsulate packet and pass socket buffer to the protocol stack.
1672 *
1673 * Notes:
1674 * 1. When allocating a socket buffer, if M-bit is set then more data is
1675 * coming and we have to allocate buffer for the maximum IP packet size
1676 * expected on this channel.
1677 * 2. If something goes wrong and X.25 packet has to be dropped (e.g. no
1678 * socket buffers available) the whole packet sequence must be discarded.
1679 */
1680
1681static void rx_intr (sdla_t* card)
1682{
1683 TX25Mbox* rxmb = card->rxmb;
1684 unsigned lcn = rxmb->cmd.lcn;
1685 struct net_device* dev = find_channel(card,lcn);
1686 x25_channel_t* chan;
1687 struct sk_buff* skb=NULL;
1688
1689 if (dev == NULL){
1690 /* Invalid channel, discard packet */
1691 printk(KERN_INFO "%s: receiving on orphaned LCN %d!\n",
1692 card->devname, lcn);
1693 return;
1694 }
1695
1696 chan = dev->priv;
1697 chan->i_timeout_sofar = jiffies;
1698
1699
1700 /* Copy the data from the board, into an
1701 * skb buffer
1702 */
1703 if (wanpipe_pull_data_in_skb(card,dev,&skb)){
1704 ++chan->ifstats.rx_dropped;
1705 ++card->wandev.stats.rx_dropped;
1706 ++chan->rx_intr_stat.rx_intr_no_socket;
1707 ++chan->rx_intr_stat.rx_intr_bfr_not_passed_to_stack;
1708 return;
1709 }
1710
1711 dev->last_rx = jiffies; /* timestamp */
1712
1713
1714 /* ------------ API ----------------*/
1715
1716 if (chan->common.usedby == API){
1717
1718 if (bh_enqueue(dev, skb)){
1719 ++chan->ifstats.rx_dropped;
1720 ++card->wandev.stats.rx_dropped;
1721 ++chan->rx_intr_stat.rx_intr_bfr_not_passed_to_stack;
1722 dev_kfree_skb_any(skb);
1723 return;
1724 }
1725
1726 ++chan->ifstats.rx_packets;
1727 chan->ifstats.rx_bytes += skb->len;
1728
1729
1730 chan->rx_skb = NULL;
1731 if (!test_and_set_bit(0, &chan->tq_working)){
1732 wanpipe_queue_work(&chan->common.wanpipe_work);
1733 }
1734 return;
1735 }
1736
1737
1738 /* ------------- WANPIPE -------------------*/
1739
1740 /* set rx_skb to NULL so we won't access it later when kernel already owns it */
1741 chan->rx_skb=NULL;
1742
1743 /* Decapsulate packet, if necessary */
1744 if (!skb->protocol && !wanrouter_type_trans(skb, dev)){
1745 /* can't decapsulate packet */
1746 dev_kfree_skb_any(skb);
1747 ++chan->ifstats.rx_errors;
1748 ++chan->ifstats.rx_dropped;
1749 ++card->wandev.stats.rx_dropped;
1750 ++chan->rx_intr_stat.rx_intr_bfr_not_passed_to_stack;
1751
1752 }else{
1753 if( handle_IPXWAN(skb->data, chan->name,
1754 chan->enable_IPX, chan->network_number,
1755 skb->protocol)){
1756
1757 if( chan->enable_IPX ){
1758 if(chan_send(dev, skb->data, skb->len,0)){
1759 chan->tx_skb = skb;
1760 }else{
1761 dev_kfree_skb_any(skb);
1762 ++chan->rx_intr_stat.rx_intr_bfr_not_passed_to_stack;
1763 }
1764 }else{
1765 /* increment IPX packet dropped statistic */
1766 ++chan->ifstats.rx_dropped;
1767 ++chan->rx_intr_stat.rx_intr_bfr_not_passed_to_stack;
1768 }
1769 }else{
1770 skb->mac.raw = skb->data;
1771 chan->ifstats.rx_bytes += skb->len;
1772 ++chan->ifstats.rx_packets;
1773 ++chan->rx_intr_stat.rx_intr_bfr_passed_to_stack;
1774 netif_rx(skb);
1775 }
1776 }
1777
1778 return;
1779}
1780
1781
1782static int wanpipe_pull_data_in_skb(sdla_t *card, struct net_device *dev,
1783 struct sk_buff **skb)
1784{
1785 void *bufptr;
1786 TX25Mbox* rxmb = card->rxmb;
1787 unsigned len = rxmb->cmd.length; /* packet length */
1788 unsigned qdm = rxmb->cmd.qdm; /* Q,D and M bits */
1789 x25_channel_t *chan = dev->priv;
1790 struct sk_buff *new_skb = *skb;
1791
1792 if (chan->common.usedby == WANPIPE){
1793 if (chan->drop_sequence){
1794 if (!(qdm & 0x01)){
1795 chan->drop_sequence = 0;
1796 }
1797 return 1;
1798 }
1799 new_skb = chan->rx_skb;
1800 }else{
1801 /* Add on the API header to the received
1802 * data
1803 */
1804 len += sizeof(x25api_hdr_t);
1805 }
1806
1807 if (new_skb == NULL){
1808 int bufsize;
1809
1810 if (chan->common.usedby == WANPIPE){
1811 bufsize = (qdm & 0x01) ? dev->mtu : len;
1812 }else{
1813 bufsize = len;
1814 }
1815
1816 /* Allocate new socket buffer */
1817 new_skb = dev_alloc_skb(bufsize + dev->hard_header_len);
1818 if (new_skb == NULL){
1819 printk(KERN_INFO "%s: no socket buffers available!\n",
1820 card->devname);
1821 chan->drop_sequence = 1; /* set flag */
1822 ++chan->ifstats.rx_dropped;
1823 return 1;
1824 }
1825 }
1826
1827 if (skb_tailroom(new_skb) < len){
1828 /* No room for the packet. Call off the whole thing! */
1829 dev_kfree_skb_any(new_skb);
1830 if (chan->common.usedby == WANPIPE){
1831 chan->rx_skb = NULL;
1832 if (qdm & 0x01){
1833 chan->drop_sequence = 1;
1834 }
1835 }
1836
1837 printk(KERN_INFO "%s: unexpectedly long packet sequence "
1838 "on interface %s!\n", card->devname, dev->name);
1839 ++chan->ifstats.rx_length_errors;
1840 return 1;
1841 }
1842
1843 bufptr = skb_put(new_skb,len);
1844
1845
1846 if (chan->common.usedby == API){
1847 /* Fill in the x25api header
1848 */
1849 x25api_t * api_data = (x25api_t*)bufptr;
1850 api_data->hdr.qdm = rxmb->cmd.qdm;
1851 api_data->hdr.cause = rxmb->cmd.cause;
1852 api_data->hdr.diagn = rxmb->cmd.diagn;
1853 api_data->hdr.length = rxmb->cmd.length;
1854 memcpy(api_data->data, rxmb->data, rxmb->cmd.length);
1855 }else{
1856 memcpy(bufptr, rxmb->data, len);
1857 }
1858
1859 new_skb->dev = dev;
1860
1861 if (chan->common.usedby == API){
1862 new_skb->mac.raw = new_skb->data;
1863 new_skb->protocol = htons(X25_PROT);
1864 new_skb->pkt_type = WAN_PACKET_DATA;
1865 }else{
1866 new_skb->protocol = chan->protocol;
1867 chan->rx_skb = new_skb;
1868 }
1869
1870 /* If qdm bit is set, more data is coming
1871 * thus, exit and wait for more data before
1872 * sending the packet up. (Used by router only)
1873 */
1874 if ((qdm & 0x01) && (chan->common.usedby == WANPIPE))
1875 return 1;
1876
1877 *skb = new_skb;
1878
1879 return 0;
1880}
1881
1882/*===============================================================
1883 * tx_intr
1884 *
1885 * Transmit interrupt handler.
1886 * For each dev, check that there is something to send.
1887 * If data available, transmit.
1888 *
1889 *===============================================================*/
1890
1891static void tx_intr (sdla_t* card)
1892{
1893 struct net_device *dev;
1894 TX25Status* status = card->flags;
1895 unsigned char more_to_tx=0;
1896 x25_channel_t *chan=NULL;
1897 int i=0;
1898
1899 if (card->u.x.tx_dev == NULL){
1900 card->u.x.tx_dev = card->wandev.dev;
1901 }
1902
1903 dev = card->u.x.tx_dev;
1904
1905 for (;;){
1906
1907 chan = dev->priv;
1908 if (chan->transmit_length){
1909 /* Device was set to transmit, check if the TX
1910 * buffers are available
1911 */
1912 if (chan->common.state != WAN_CONNECTED){
1913 chan->transmit_length = 0;
1914 atomic_set(&chan->common.driver_busy,0);
1915 chan->tx_offset=0;
1916 if (netif_queue_stopped(dev)){
1917 if (chan->common.usedby == API){
1918 netif_start_queue(dev);
1919 wakeup_sk_bh(dev);
1920 }else{
1921 netif_wake_queue(dev);
1922 }
1923 }
1924 dev = move_dev_to_next(card,dev);
1925 break;
1926 }
1927
1928 if ((status->cflags[chan->ch_idx] & 0x40 || card->u.x.LAPB_hdlc) &&
1929 (*card->u.x.hdlc_buf_status & 0x40) ){
1930 /* Tx buffer available, we can send */
1931
1932 if (tx_intr_send(card, dev)){
1933 more_to_tx=1;
1934 }
1935
1936 /* If more than one interface present, move the
1937 * device pointer to the next interface, so on the
1938 * next TX interrupt we will try sending from it.
1939 */
1940 dev = move_dev_to_next(card,dev);
1941 break;
1942 }else{
1943 /* Tx buffers not available, but device set
1944 * the TX interrupt. Set more_to_tx and try
1945 * to transmit for other devices.
1946 */
1947 more_to_tx=1;
1948 dev = move_dev_to_next(card,dev);
1949 }
1950
1951 }else{
1952 /* This device was not set to transmit,
1953 * go to next
1954 */
1955 dev = move_dev_to_next(card,dev);
1956 }
1957
1958 if (++i == card->u.x.no_dev){
1959 if (!more_to_tx){
1960 DBG_PRINTK(KERN_INFO "%s: Nothing to Send in TX INTR\n",
1961 card->devname);
1962 }
1963 break;
1964 }
1965
1966 } //End of FOR
1967
1968 card->u.x.tx_dev = dev;
1969
1970 if (!more_to_tx){
1971 /* if any other interfaces have transmit interrupts pending, */
1972 /* do not disable the global transmit interrupt */
1973 if (!(--card->u.x.tx_interrupts_pending)){
1974 status->imask &= ~INTR_ON_TX_FRAME;
1975 }
1976 }
1977 return;
1978}
1979
1980/*===============================================================
1981 * move_dev_to_next
1982 *
1983 *
1984 *===============================================================*/
1985
1986
1987struct net_device *move_dev_to_next(sdla_t *card, struct net_device *dev)
1988{
1989 if (card->u.x.no_dev != 1){
1990 if (!*((struct net_device **)dev->priv))
1991 return card->wandev.dev;
1992 else
1993 return *((struct net_device **)dev->priv);
1994 }
1995 return dev;
1996}
1997
1998/*===============================================================
1999 * tx_intr_send
2000 *
2001 *
2002 *===============================================================*/
2003
2004static int tx_intr_send(sdla_t *card, struct net_device *dev)
2005{
2006 x25_channel_t* chan = dev->priv;
2007
2008 if (chan_send (dev,chan->transmit_buffer,chan->transmit_length,1)){
2009
2010 /* Packet was split up due to its size, do not disable
2011 * tx_intr
2012 */
2013 return 1;
2014 }
2015
2016 chan->transmit_length=0;
2017 atomic_set(&chan->common.driver_busy,0);
2018 chan->tx_offset=0;
2019
2020 /* If we are in API mode, wakeup the
2021 * sock BH handler, not the NET_BH */
2022 if (netif_queue_stopped(dev)){
2023 if (chan->common.usedby == API){
2024 netif_start_queue(dev);
2025 wakeup_sk_bh(dev);
2026 }else{
2027 netif_wake_queue(dev);
2028 }
2029 }
2030 return 0;
2031}
2032
2033
2034/*===============================================================
2035 * timer_intr
2036 *
2037 * Timer interrupt handler.
2038 * Check who called the timer interrupt and perform
2039 * action accordingly.
2040 *
2041 *===============================================================*/
2042
2043static void timer_intr (sdla_t *card)
2044{
2045 TX25Status* status = card->flags;
2046
2047 if (card->u.x.timer_int_enabled & TMR_INT_ENABLED_CMD_EXEC){
2048
2049 if (timer_intr_cmd_exec(card) == 0){
2050 card->u.x.timer_int_enabled &=
2051 ~TMR_INT_ENABLED_CMD_EXEC;
2052 }
2053
2054 }else if(card->u.x.timer_int_enabled & TMR_INT_ENABLED_UDP_PKT) {
2055
2056 if ((*card->u.x.hdlc_buf_status & 0x40) &&
2057 card->u.x.udp_type == UDP_XPIPE_TYPE){
2058
2059 if(process_udp_mgmt_pkt(card)) {
2060 card->u.x.timer_int_enabled &=
2061 ~TMR_INT_ENABLED_UDP_PKT;
2062 }
2063 }
2064
2065 }else if (card->u.x.timer_int_enabled & TMR_INT_ENABLED_POLL_ACTIVE) {
2066
2067 struct net_device *dev = card->u.x.poll_device;
2068 x25_channel_t *chan = NULL;
2069
2070 if (!dev){
2071 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_POLL_ACTIVE;
2072 return;
2073 }
2074 chan = dev->priv;
2075
2076 printk(KERN_INFO
2077 "%s: Closing down Idle link %s on LCN %d\n",
2078 card->devname,chan->name,chan->common.lcn);
2079 chan->i_timeout_sofar = jiffies;
2080 chan_disc(dev);
2081 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_POLL_ACTIVE;
2082 card->u.x.poll_device=NULL;
2083
2084 }else if (card->u.x.timer_int_enabled & TMR_INT_ENABLED_POLL_CONNECT_ON) {
2085
2086 wanpipe_set_state(card, WAN_CONNECTED);
2087 if (card->u.x.LAPB_hdlc){
2088 struct net_device *dev = card->wandev.dev;
2089 set_chan_state(dev,WAN_CONNECTED);
2090 send_delayed_cmd_result(card,dev,card->mbox);
2091 }
2092
2093 /* 0x8F enable all interrupts */
2094 x25_set_intr_mode(card, INTR_ON_RX_FRAME|
2095 INTR_ON_TX_FRAME|
2096 INTR_ON_MODEM_STATUS_CHANGE|
2097 //INTR_ON_COMMAND_COMPLETE|
2098 X25_ASY_TRANS_INTR_PENDING |
2099 INTR_ON_TIMER |
2100 DIRECT_RX_INTR_USAGE
2101 );
2102
2103 status->imask &= ~INTR_ON_TX_FRAME; /* mask Tx interrupts */
2104 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_POLL_CONNECT_ON;
2105
2106 }else if (card->u.x.timer_int_enabled & TMR_INT_ENABLED_POLL_CONNECT_OFF) {
2107
2108 //printk(KERN_INFO "Poll connect, Turning OFF\n");
2109 disconnect(card);
2110 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_POLL_CONNECT_OFF;
2111
2112 }else if (card->u.x.timer_int_enabled & TMR_INT_ENABLED_POLL_DISCONNECT) {
2113
2114 //printk(KERN_INFO "POll disconnect, trying to connect\n");
2115 connect(card);
2116 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_POLL_DISCONNECT;
2117
2118 }else if (card->u.x.timer_int_enabled & TMR_INT_ENABLED_UPDATE){
2119
2120 if (*card->u.x.hdlc_buf_status & 0x40){
2121 x25_get_err_stats(card);
2122 x25_get_stats(card);
2123 card->u.x.timer_int_enabled &= ~TMR_INT_ENABLED_UPDATE;
2124 }
2125 }
2126
2127 if(!card->u.x.timer_int_enabled){
2128 //printk(KERN_INFO "Turning Timer Off \n");
2129 status->imask &= ~INTR_ON_TIMER;
2130 }
2131}
2132
2133/*====================================================================
2134 * Modem status interrupt handler.
2135 *===================================================================*/
2136static void status_intr (sdla_t* card)
2137{
2138
2139 /* Added to avoid Modem status message flooding */
2140 static TX25ModemStatus last_stat;
2141
2142 TX25Mbox* mbox = card->mbox;
2143 TX25ModemStatus *modem_status;
2144 struct net_device *dev;
2145 x25_channel_t *chan;
2146 int err;
2147
2148 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2149 mbox->cmd.command = X25_READ_MODEM_STATUS;
2150 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2151 if (err){
2152 x25_error(card, err, X25_READ_MODEM_STATUS, 0);
2153 }else{
2154
2155 modem_status = (TX25ModemStatus*)mbox->data;
2156
2157 /* Check if the last status was the same
2158 * if it was, do NOT print message again */
2159
2160 if (last_stat.status != modem_status->status){
2161
2162 printk(KERN_INFO "%s: Modem Status Change: DCD=%s, CTS=%s\n",
2163 card->devname,DCD(modem_status->status),CTS(modem_status->status));
2164
2165 last_stat.status = modem_status->status;
2166
2167 if (card->u.x.oob_on_modem){
2168
2169 mbox->cmd.pktType = mbox->cmd.command;
2170 mbox->cmd.result = 0x08;
2171
2172 /* Send a OOB to all connected sockets */
2173 for (dev = card->wandev.dev; dev;
2174 dev = *((struct net_device**)dev->priv)) {
2175 chan=dev->priv;
2176 if (chan->common.usedby == API){
2177 send_oob_msg(card,dev,mbox);
2178 }
2179 }
2180
2181 /* The modem OOB message will probably kill the
2182 * the link. If we don't clear the flag here,
2183 * a deadlock could occur */
2184 if (atomic_read(&card->u.x.command_busy)){
2185 atomic_set(&card->u.x.command_busy,0);
2186 }
2187 }
2188 }
2189 }
2190
2191 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2192 mbox->cmd.command = X25_HDLC_LINK_STATUS;
2193 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2194 if (err){
2195 x25_error(card, err, X25_HDLC_LINK_STATUS, 0);
2196 }
2197
2198}
2199
2200/*====================================================================
2201 * Network event interrupt handler.
2202 *===================================================================*/
2203static void event_intr (sdla_t* card)
2204{
2205 x25_fetch_events(card);
2206}
2207
2208/*====================================================================
2209 * Spurious interrupt handler.
2210 * o print a warning
2211 * o
2212 *====================================================================*/
2213
2214static void spur_intr (sdla_t* card)
2215{
2216 printk(KERN_INFO "%s: spurious interrupt!\n", card->devname);
2217}
2218
2219
2220/*
2221 * Background Polling Routines
2222 */
2223
2224/*====================================================================
2225 * Main polling routine.
2226 * This routine is repeatedly called by the WANPIPE 'thread' to allow for
2227 * time-dependent housekeeping work.
2228 *
2229 * Notes:
2230 * 1. This routine may be called on interrupt context with all interrupts
2231 * enabled. Beware!
2232 *====================================================================*/
2233
2234static void wpx_poll (sdla_t *card)
2235{
2236 if (!card->wandev.dev){
2237 goto wpx_poll_exit;
2238 }
2239
2240 if (card->open_cnt != card->u.x.num_of_ch){
2241 goto wpx_poll_exit;
2242 }
2243
2244 if (test_bit(PERI_CRIT,&card->wandev.critical)){
2245 goto wpx_poll_exit;
2246 }
2247
2248 if (test_bit(SEND_CRIT,&card->wandev.critical)){
2249 goto wpx_poll_exit;
2250 }
2251
2252 switch(card->wandev.state){
2253 case WAN_CONNECTED:
2254 poll_active(card);
2255 break;
2256
2257 case WAN_CONNECTING:
2258 poll_connecting(card);
2259 break;
2260
2261 case WAN_DISCONNECTED:
2262 poll_disconnected(card);
2263 break;
2264 }
2265
2266wpx_poll_exit:
2267 clear_bit(POLL_CRIT,&card->wandev.critical);
2268 return;
2269}
2270
2271static void trigger_x25_poll(sdla_t *card)
2272{
2273 schedule_work(&card->u.x.x25_poll_work);
2274}
2275
2276/*====================================================================
2277 * Handle physical link establishment phase.
2278 * o if connection timed out, disconnect the link.
2279 *===================================================================*/
2280
2281static void poll_connecting (sdla_t* card)
2282{
2283 volatile TX25Status* status = card->flags;
2284
2285 if (status->gflags & X25_HDLC_ABM){
2286
2287 timer_intr_exec (card, TMR_INT_ENABLED_POLL_CONNECT_ON);
2288
2289 }else if ((jiffies - card->state_tick) > CONNECT_TIMEOUT){
2290
2291 timer_intr_exec (card, TMR_INT_ENABLED_POLL_CONNECT_OFF);
2292
2293 }
2294}
2295
2296/*====================================================================
2297 * Handle physical link disconnected phase.
2298 * o if hold-down timeout has expired and there are open interfaces,
2299 * connect link.
2300 *===================================================================*/
2301
2302static void poll_disconnected (sdla_t* card)
2303{
2304 struct net_device *dev;
2305 x25_channel_t *chan;
2306 TX25Status* status = card->flags;
2307
2308 if (!card->u.x.LAPB_hdlc && card->open_cnt &&
2309 ((jiffies - card->state_tick) > HOLD_DOWN_TIME)){
2310 timer_intr_exec(card, TMR_INT_ENABLED_POLL_DISCONNECT);
2311 }
2312
2313
2314 if ((dev=card->wandev.dev) == NULL)
2315 return;
2316
2317 if ((chan=dev->priv) == NULL)
2318 return;
2319
2320 if (chan->common.usedby == API &&
2321 atomic_read(&chan->common.command) &&
2322 card->u.x.LAPB_hdlc){
2323
2324 if (!(card->u.x.timer_int_enabled & TMR_INT_ENABLED_CMD_EXEC))
2325 card->u.x.timer_int_enabled |= TMR_INT_ENABLED_CMD_EXEC;
2326
2327 if (!(status->imask & INTR_ON_TIMER))
2328 status->imask |= INTR_ON_TIMER;
2329 }
2330
2331}
2332
2333/*====================================================================
2334 * Handle active link phase.
2335 * o fetch X.25 asynchronous events.
2336 * o kick off transmission on all interfaces.
2337 *===================================================================*/
2338
2339static void poll_active (sdla_t* card)
2340{
2341 struct net_device* dev;
2342 TX25Status* status = card->flags;
2343
2344 for (dev = card->wandev.dev; dev;
2345 dev = *((struct net_device **)dev->priv)){
2346 x25_channel_t* chan = dev->priv;
2347
2348 /* If SVC has been idle long enough, close virtual circuit */
2349 if ( chan->common.svc &&
2350 chan->common.state == WAN_CONNECTED &&
2351 chan->common.usedby == WANPIPE ){
2352
2353 if( (jiffies - chan->i_timeout_sofar) / HZ > chan->idle_timeout ){
2354 /* Close svc */
2355 card->u.x.poll_device=dev;
2356 timer_intr_exec (card, TMR_INT_ENABLED_POLL_ACTIVE);
2357 }
2358 }
2359
2360#ifdef PRINT_DEBUG
2361 chan->ifstats.tx_compressed = atomic_read(&chan->common.command);
2362 chan->ifstats.tx_errors = chan->common.state;
2363 chan->ifstats.rx_fifo_errors = atomic_read(&card->u.x.command_busy);
2364 ++chan->ifstats.tx_bytes;
2365
2366 chan->ifstats.rx_fifo_errors=atomic_read(&chan->common.disconnect);
2367 chan->ifstats.multicast=atomic_read(&chan->bh_buff_used);
2368 chan->ifstats.rx_length_errors=*card->u.x.hdlc_buf_status;
2369#endif
2370
2371 if (chan->common.usedby == API &&
2372 atomic_read(&chan->common.command) &&
2373 !card->u.x.LAPB_hdlc){
2374
2375 if (!(card->u.x.timer_int_enabled & TMR_INT_ENABLED_CMD_EXEC))
2376 card->u.x.timer_int_enabled |= TMR_INT_ENABLED_CMD_EXEC;
2377
2378 if (!(status->imask & INTR_ON_TIMER))
2379 status->imask |= INTR_ON_TIMER;
2380 }
2381
2382 if ((chan->common.usedby == API) &&
2383 atomic_read(&chan->common.disconnect)){
2384
2385 if (chan->common.state == WAN_DISCONNECTED){
2386 atomic_set(&chan->common.disconnect,0);
2387 return;
2388 }
2389
2390 atomic_set(&chan->common.command,X25_CLEAR_CALL);
2391 if (!(card->u.x.timer_int_enabled & TMR_INT_ENABLED_CMD_EXEC))
2392 card->u.x.timer_int_enabled |= TMR_INT_ENABLED_CMD_EXEC;
2393
2394 if (!(status->imask & INTR_ON_TIMER))
2395 status->imask |= INTR_ON_TIMER;
2396 }
2397 }
2398}
2399
2400static void timer_intr_exec(sdla_t *card, unsigned char TYPE)
2401{
2402 TX25Status* status = card->flags;
2403 card->u.x.timer_int_enabled |= TYPE;
2404 if (!(status->imask & INTR_ON_TIMER))
2405 status->imask |= INTR_ON_TIMER;
2406}
2407
2408
2409/*====================================================================
2410 * SDLA Firmware-Specific Functions
2411 *
2412 * Almost all X.25 commands can unexpetedly fail due to so called 'X.25
2413 * asynchronous events' such as restart, interrupt, incoming call request,
2414 * call clear request, etc. They can't be ignored and have to be delt with
2415 * immediately. To tackle with this problem we execute each interface
2416 * command in a loop until good return code is received or maximum number
2417 * of retries is reached. Each interface command returns non-zero return
2418 * code, an asynchronous event/error handler x25_error() is called.
2419 *====================================================================*/
2420
2421/*====================================================================
2422 * Read X.25 firmware version.
2423 * Put code version as ASCII string in str.
2424 *===================================================================*/
2425
2426static int x25_get_version (sdla_t* card, char* str)
2427{
2428 TX25Mbox* mbox = card->mbox;
2429 int retry = MAX_CMD_RETRY;
2430 int err;
2431
2432 do
2433 {
2434 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2435 mbox->cmd.command = X25_READ_CODE_VERSION;
2436 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2437 } while (err && retry-- &&
2438 x25_error(card, err, X25_READ_CODE_VERSION, 0));
2439
2440 if (!err && str)
2441 {
2442 int len = mbox->cmd.length;
2443
2444 memcpy(str, mbox->data, len);
2445 str[len] = '\0';
2446 }
2447 return err;
2448}
2449
2450/*====================================================================
2451 * Configure adapter.
2452 *===================================================================*/
2453
2454static int x25_configure (sdla_t* card, TX25Config* conf)
2455{
2456 TX25Mbox* mbox = card->mbox;
2457 int retry = MAX_CMD_RETRY;
2458 int err;
2459
2460 do{
2461 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2462 memcpy(mbox->data, (void*)conf, sizeof(TX25Config));
2463 mbox->cmd.length = sizeof(TX25Config);
2464 mbox->cmd.command = X25_SET_CONFIGURATION;
2465 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2466 } while (err && retry-- && x25_error(card, err, X25_SET_CONFIGURATION, 0));
2467 return err;
2468}
2469
2470/*====================================================================
2471 * Configure adapter for HDLC only.
2472 *===================================================================*/
2473
2474static int hdlc_configure (sdla_t* card, TX25Config* conf)
2475{
2476 TX25Mbox* mbox = card->mbox;
2477 int retry = MAX_CMD_RETRY;
2478 int err;
2479
2480 do{
2481 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2482 memcpy(mbox->data, (void*)conf, sizeof(TX25Config));
2483 mbox->cmd.length = sizeof(TX25Config);
2484 mbox->cmd.command = X25_HDLC_SET_CONFIG;
2485 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2486 } while (err && retry-- && x25_error(card, err, X25_SET_CONFIGURATION, 0));
2487
2488 return err;
2489}
2490
2491static int set_hdlc_level (sdla_t* card)
2492{
2493
2494 TX25Mbox* mbox = card->mbox;
2495 int retry = MAX_CMD_RETRY;
2496 int err;
2497
2498 do{
2499 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2500 mbox->cmd.command = SET_PROTOCOL_LEVEL;
2501 mbox->cmd.length = 1;
2502 mbox->data[0] = HDLC_LEVEL; //| DO_HDLC_LEVEL_ERROR_CHECKING;
2503 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2504 } while (err && retry-- && x25_error(card, err, SET_PROTOCOL_LEVEL, 0));
2505
2506 return err;
2507}
2508
2509
2510
2511/*====================================================================
2512 * Get communications error statistics.
2513 *====================================================================*/
2514
2515static int x25_get_err_stats (sdla_t* card)
2516{
2517 TX25Mbox* mbox = card->mbox;
2518 int retry = MAX_CMD_RETRY;
2519 int err;
2520
2521 do
2522 {
2523 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2524 mbox->cmd.command = X25_HDLC_READ_COMM_ERR;
2525 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2526 } while (err && retry-- && x25_error(card, err, X25_HDLC_READ_COMM_ERR, 0));
2527
2528 if (!err)
2529 {
2530 THdlcCommErr* stats = (void*)mbox->data;
2531
2532 card->wandev.stats.rx_over_errors = stats->rxOverrun;
2533 card->wandev.stats.rx_crc_errors = stats->rxBadCrc;
2534 card->wandev.stats.rx_missed_errors = stats->rxAborted;
2535 card->wandev.stats.tx_aborted_errors = stats->txAborted;
2536 }
2537 return err;
2538}
2539
2540/*====================================================================
2541 * Get protocol statistics.
2542 *===================================================================*/
2543
2544static int x25_get_stats (sdla_t* card)
2545{
2546 TX25Mbox* mbox = card->mbox;
2547 int retry = MAX_CMD_RETRY;
2548 int err;
2549
2550 do
2551 {
2552 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2553 mbox->cmd.command = X25_READ_STATISTICS;
2554 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2555 } while (err && retry-- && x25_error(card, err, X25_READ_STATISTICS, 0)) ;
2556
2557 if (!err)
2558 {
2559 TX25Stats* stats = (void*)mbox->data;
2560
2561 card->wandev.stats.rx_packets = stats->rxData;
2562 card->wandev.stats.tx_packets = stats->txData;
2563 }
2564 return err;
2565}
2566
2567/*====================================================================
2568 * Close HDLC link.
2569 *===================================================================*/
2570
2571static int x25_close_hdlc (sdla_t* card)
2572{
2573 TX25Mbox* mbox = card->mbox;
2574 int retry = MAX_CMD_RETRY;
2575 int err;
2576
2577 do
2578 {
2579 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2580 mbox->cmd.command = X25_HDLC_LINK_CLOSE;
2581 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2582 } while (err && retry-- && x25_error(card, err, X25_HDLC_LINK_CLOSE, 0));
2583
2584 return err;
2585}
2586
2587
2588/*====================================================================
2589 * Open HDLC link.
2590 *===================================================================*/
2591
2592static int x25_open_hdlc (sdla_t* card)
2593{
2594 TX25Mbox* mbox = card->mbox;
2595 int retry = MAX_CMD_RETRY;
2596 int err;
2597
2598 do
2599 {
2600 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2601 mbox->cmd.command = X25_HDLC_LINK_OPEN;
2602 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2603 } while (err && retry-- && x25_error(card, err, X25_HDLC_LINK_OPEN, 0));
2604
2605 return err;
2606}
2607
2608/*=====================================================================
2609 * Setup HDLC link.
2610 *====================================================================*/
2611static int x25_setup_hdlc (sdla_t* card)
2612{
2613 TX25Mbox* mbox = card->mbox;
2614 int retry = MAX_CMD_RETRY;
2615 int err;
2616
2617 do
2618 {
2619 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2620 mbox->cmd.command = X25_HDLC_LINK_SETUP;
2621 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2622 } while (err && retry-- && x25_error(card, err, X25_HDLC_LINK_SETUP, 0));
2623
2624 return err;
2625}
2626
2627/*====================================================================
2628 * Set (raise/drop) DTR.
2629 *===================================================================*/
2630
2631static int x25_set_dtr (sdla_t* card, int dtr)
2632{
2633 TX25Mbox* mbox = card->mbox;
2634 int retry = MAX_CMD_RETRY;
2635 int err;
2636
2637 do
2638 {
2639 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2640 mbox->data[0] = 0;
2641 mbox->data[2] = 0;
2642 mbox->data[1] = dtr ? 0x02 : 0x01;
2643 mbox->cmd.length = 3;
2644 mbox->cmd.command = X25_SET_GLOBAL_VARS;
2645 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2646 } while (err && retry-- && x25_error(card, err, X25_SET_GLOBAL_VARS, 0));
2647
2648 return err;
2649}
2650
2651/*====================================================================
2652 * Set interrupt mode.
2653 *===================================================================*/
2654
2655static int x25_set_intr_mode (sdla_t* card, int mode)
2656{
2657 TX25Mbox* mbox = card->mbox;
2658 int retry = MAX_CMD_RETRY;
2659 int err;
2660
2661 do
2662 {
2663 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2664 mbox->data[0] = mode;
2665 if (card->hw.fwid == SFID_X25_508){
2666 mbox->data[1] = card->hw.irq;
2667 mbox->data[2] = 2;
2668 mbox->cmd.length = 3;
2669 }else {
2670 mbox->cmd.length = 1;
2671 }
2672 mbox->cmd.command = X25_SET_INTERRUPT_MODE;
2673 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2674 } while (err && retry-- && x25_error(card, err, X25_SET_INTERRUPT_MODE, 0));
2675
2676 return err;
2677}
2678
2679/*====================================================================
2680 * Read X.25 channel configuration.
2681 *===================================================================*/
2682
2683static int x25_get_chan_conf (sdla_t* card, x25_channel_t* chan)
2684{
2685 TX25Mbox* mbox = card->mbox;
2686 int retry = MAX_CMD_RETRY;
2687 int lcn = chan->common.lcn;
2688 int err;
2689
2690 do{
2691 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2692 mbox->cmd.lcn = lcn;
2693 mbox->cmd.command = X25_READ_CHANNEL_CONFIG;
2694 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2695 } while (err && retry-- && x25_error(card, err, X25_READ_CHANNEL_CONFIG, lcn));
2696
2697 if (!err)
2698 {
2699 TX25Status* status = card->flags;
2700
2701 /* calculate an offset into the array of status bytes */
2702 if (card->u.x.hi_svc <= X25_MAX_CHAN){
2703
2704 chan->ch_idx = lcn - 1;
2705
2706 }else{
2707 int offset;
2708
2709 /* FIX: Apr 14 2000 : Nenad Corbic
2710 * The data field was being compared to 0x1F using
2711 * '&&' instead of '&'.
2712 * This caused X25API to fail for LCNs greater than 255.
2713 */
2714 switch (mbox->data[0] & 0x1F)
2715 {
2716 case 0x01:
2717 offset = status->pvc_map; break;
2718 case 0x03:
2719 offset = status->icc_map; break;
2720 case 0x07:
2721 offset = status->twc_map; break;
2722 case 0x0B:
2723 offset = status->ogc_map; break;
2724 default:
2725 offset = 0;
2726 }
2727 chan->ch_idx = lcn - 1 - offset;
2728 }
2729
2730 /* get actual transmit packet size on this channel */
2731 switch(mbox->data[1] & 0x38)
2732 {
2733 case 0x00:
2734 chan->tx_pkt_size = 16;
2735 break;
2736 case 0x08:
2737 chan->tx_pkt_size = 32;
2738 break;
2739 case 0x10:
2740 chan->tx_pkt_size = 64;
2741 break;
2742 case 0x18:
2743 chan->tx_pkt_size = 128;
2744 break;
2745 case 0x20:
2746 chan->tx_pkt_size = 256;
2747 break;
2748 case 0x28:
2749 chan->tx_pkt_size = 512;
2750 break;
2751 case 0x30:
2752 chan->tx_pkt_size = 1024;
2753 break;
2754 }
2755 if (card->u.x.logging)
2756 printk(KERN_INFO "%s: X.25 packet size on LCN %d is %d.\n",
2757 card->devname, lcn, chan->tx_pkt_size);
2758 }
2759 return err;
2760}
2761
2762/*====================================================================
2763 * Place X.25 call.
2764 *====================================================================*/
2765
2766static int x25_place_call (sdla_t* card, x25_channel_t* chan)
2767{
2768 TX25Mbox* mbox = card->mbox;
2769 int retry = MAX_CMD_RETRY;
2770 int err;
2771 char str[64];
2772
2773
2774 if (chan->protocol == htons(ETH_P_IP)){
2775 sprintf(str, "-d%s -uCC", chan->addr);
2776
2777 }else if (chan->protocol == htons(ETH_P_IPX)){
2778 sprintf(str, "-d%s -u800000008137", chan->addr);
2779
2780 }
2781
2782 do
2783 {
2784 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2785 strcpy(mbox->data, str);
2786 mbox->cmd.length = strlen(str);
2787 mbox->cmd.command = X25_PLACE_CALL;
2788 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2789 } while (err && retry-- && x25_error(card, err, X25_PLACE_CALL, 0));
2790
2791 if (!err){
2792 bind_lcn_to_dev (card, chan->dev, mbox->cmd.lcn);
2793 }
2794 return err;
2795}
2796
2797/*====================================================================
2798 * Accept X.25 call.
2799 *====================================================================*/
2800
2801static int x25_accept_call (sdla_t* card, int lcn, int qdm)
2802{
2803 TX25Mbox* mbox = card->mbox;
2804 int retry = MAX_CMD_RETRY;
2805 int err;
2806
2807 do
2808 {
2809 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2810 mbox->cmd.lcn = lcn;
2811 mbox->cmd.qdm = qdm;
2812 mbox->cmd.command = X25_ACCEPT_CALL;
2813 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2814 } while (err && retry-- && x25_error(card, err, X25_ACCEPT_CALL, lcn));
2815
2816 return err;
2817}
2818
2819/*====================================================================
2820 * Clear X.25 call.
2821 *====================================================================*/
2822
2823static int x25_clear_call (sdla_t* card, int lcn, int cause, int diagn)
2824{
2825 TX25Mbox* mbox = card->mbox;
2826 int retry = MAX_CMD_RETRY;
2827 int err;
2828
2829 do
2830 {
2831 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2832 mbox->cmd.lcn = lcn;
2833 mbox->cmd.cause = cause;
2834 mbox->cmd.diagn = diagn;
2835 mbox->cmd.command = X25_CLEAR_CALL;
2836 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2837 } while (err && retry-- && x25_error(card, err, X25_CLEAR_CALL, lcn));
2838
2839 return err;
2840}
2841
2842/*====================================================================
2843 * Send X.25 data packet.
2844 *====================================================================*/
2845
2846static int x25_send (sdla_t* card, int lcn, int qdm, int len, void* buf)
2847{
2848 TX25Mbox* mbox = card->mbox;
2849 int retry = MAX_CMD_RETRY;
2850 int err;
2851 unsigned char cmd;
2852
2853 if (card->u.x.LAPB_hdlc)
2854 cmd = X25_HDLC_WRITE;
2855 else
2856 cmd = X25_WRITE;
2857
2858 do
2859 {
2860 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2861 memcpy(mbox->data, buf, len);
2862 mbox->cmd.length = len;
2863 mbox->cmd.lcn = lcn;
2864
2865 if (card->u.x.LAPB_hdlc){
2866 mbox->cmd.pf = qdm;
2867 }else{
2868 mbox->cmd.qdm = qdm;
2869 }
2870
2871 mbox->cmd.command = cmd;
2872 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2873 } while (err && retry-- && x25_error(card, err, cmd , lcn));
2874
2875
2876 /* If buffers are busy the return code for LAPB HDLC is
2877 * 1. The above functions are looking for return code
2878 * of X25RES_NOT_READY if busy. */
2879
2880 if (card->u.x.LAPB_hdlc && err == 1){
2881 err = X25RES_NOT_READY;
2882 }
2883
2884 return err;
2885}
2886
2887/*====================================================================
2888 * Fetch X.25 asynchronous events.
2889 *===================================================================*/
2890
2891static int x25_fetch_events (sdla_t* card)
2892{
2893 TX25Status* status = card->flags;
2894 TX25Mbox* mbox = card->mbox;
2895 int err = 0;
2896
2897 if (status->gflags & 0x20)
2898 {
2899 memset(&mbox->cmd, 0, sizeof(TX25Cmd));
2900 mbox->cmd.command = X25_IS_DATA_AVAILABLE;
2901 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
2902 if (err) x25_error(card, err, X25_IS_DATA_AVAILABLE, 0);
2903 }
2904 return err;
2905}
2906
2907/*====================================================================
2908 * X.25 asynchronous event/error handler.
2909 * This routine is called each time interface command returns
2910 * non-zero return code to handle X.25 asynchronous events and
2911 * common errors. Return non-zero to repeat command or zero to
2912 * cancel it.
2913 *
2914 * Notes:
2915 * 1. This function may be called recursively, as handling some of the
2916 * asynchronous events (e.g. call request) requires execution of the
2917 * interface command(s) that, in turn, may also return asynchronous
2918 * events. To avoid re-entrancy problems we copy mailbox to dynamically
2919 * allocated memory before processing events.
2920 *====================================================================*/
2921
2922static int x25_error (sdla_t* card, int err, int cmd, int lcn)
2923{
2924 int retry = 1;
2925 unsigned dlen = ((TX25Mbox*)card->mbox)->cmd.length;
2926 TX25Mbox* mb;
2927
2928 mb = kmalloc(sizeof(TX25Mbox) + dlen, GFP_ATOMIC);
2929 if (mb == NULL)
2930 {
2931 printk(KERN_ERR "%s: x25_error() out of memory!\n",
2932 card->devname);
2933 return 0;
2934 }
2935 memcpy(mb, card->mbox, sizeof(TX25Mbox) + dlen);
2936 switch (err){
2937
2938 case X25RES_ASYNC_PACKET: /* X.25 asynchronous packet was received */
2939
2940 mb->data[dlen] = '\0';
2941
2942 switch (mb->cmd.pktType & 0x7F){
2943
2944 case ASE_CALL_RQST: /* incoming call */
2945 retry = incoming_call(card, cmd, lcn, mb);
2946 break;
2947
2948 case ASE_CALL_ACCEPTED: /* connected */
2949 retry = call_accepted(card, cmd, lcn, mb);
2950 break;
2951
2952 case ASE_CLEAR_RQST: /* call clear request */
2953 retry = call_cleared(card, cmd, lcn, mb);
2954 break;
2955
2956 case ASE_RESET_RQST: /* reset request */
2957 printk(KERN_INFO "%s: X.25 reset request on LCN %d! "
2958 "Cause:0x%02X Diagn:0x%02X\n",
2959 card->devname, mb->cmd.lcn, mb->cmd.cause,
2960 mb->cmd.diagn);
2961 api_oob_event (card,mb);
2962 break;
2963
2964 case ASE_RESTART_RQST: /* restart request */
2965 retry = restart_event(card, cmd, lcn, mb);
2966 break;
2967
2968 case ASE_CLEAR_CONFRM:
2969 if (clear_confirm_event (card,mb))
2970 break;
2971
2972 /* I use the goto statement here so if
2973 * somebody inserts code between the
2974 * case and default, we will not have
2975 * ghost problems */
2976
2977 goto dflt_1;
2978
2979 default:
2980dflt_1:
2981 printk(KERN_INFO "%s: X.25 event 0x%02X on LCN %d! "
2982 "Cause:0x%02X Diagn:0x%02X\n",
2983 card->devname, mb->cmd.pktType,
2984 mb->cmd.lcn, mb->cmd.cause, mb->cmd.diagn);
2985 }
2986 break;
2987
2988 case X25RES_PROTO_VIOLATION: /* X.25 protocol violation indication */
2989
2990 /* Bug Fix: Mar 14 2000
2991 * The Protocol violation error conditions were
2992 * not handled previously */
2993
2994 switch (mb->cmd.pktType & 0x7F){
2995
2996 case PVE_CLEAR_RQST: /* Clear request */
2997 retry = call_cleared(card, cmd, lcn, mb);
2998 break;
2999
3000 case PVE_RESET_RQST: /* Reset request */
3001 printk(KERN_INFO "%s: X.25 reset request on LCN %d! "
3002 "Cause:0x%02X Diagn:0x%02X\n",
3003 card->devname, mb->cmd.lcn, mb->cmd.cause,
3004 mb->cmd.diagn);
3005 api_oob_event (card,mb);
3006 break;
3007
3008 case PVE_RESTART_RQST: /* Restart request */
3009 retry = restart_event(card, cmd, lcn, mb);
3010 break;
3011
3012 default :
3013 printk(KERN_INFO
3014 "%s: X.25 protocol violation on LCN %d! "
3015 "Packet:0x%02X Cause:0x%02X Diagn:0x%02X\n",
3016 card->devname, mb->cmd.lcn,
3017 mb->cmd.pktType & 0x7F, mb->cmd.cause, mb->cmd.diagn);
3018 api_oob_event(card,mb);
3019 }
3020 break;
3021
3022 case 0x42: /* X.25 timeout */
3023 retry = timeout_event(card, cmd, lcn, mb);
3024 break;
3025
3026 case 0x43: /* X.25 retry limit exceeded */
3027 printk(KERN_INFO
3028 "%s: exceeded X.25 retry limit on LCN %d! "
3029 "Packet:0x%02X Diagn:0x%02X\n", card->devname,
3030 mb->cmd.lcn, mb->cmd.pktType, mb->cmd.diagn)
3031 ;
3032 break;
3033
3034 case 0x08: /* modem failure */
3035#ifndef MODEM_NOT_LOG
3036 printk(KERN_INFO "%s: modem failure!\n", card->devname);
3037#endif /* MODEM_NOT_LOG */
3038 api_oob_event(card,mb);
3039 break;
3040
3041 case 0x09: /* N2 retry limit */
3042 printk(KERN_INFO "%s: exceeded HDLC retry limit!\n",
3043 card->devname);
3044 api_oob_event(card,mb);
3045 break;
3046
3047 case 0x06: /* unnumbered frame was received while in ABM */
3048 printk(KERN_INFO "%s: received Unnumbered frame 0x%02X!\n",
3049 card->devname, mb->data[0]);
3050 api_oob_event(card,mb);
3051 break;
3052
3053 case CMD_TIMEOUT:
3054 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
3055 card->devname, cmd)
3056 ;
3057 retry = 0; /* abort command */
3058 break;
3059
3060 case X25RES_NOT_READY:
3061 retry = 1;
3062 break;
3063
3064 case 0x01:
3065 if (card->u.x.LAPB_hdlc)
3066 break;
3067
3068 if (mb->cmd.command == 0x16)
3069 break;
3070 /* I use the goto statement here so if
3071 * somebody inserts code between the
3072 * case and default, we will not have
3073 * ghost problems */
3074 goto dflt_2;
3075
3076 default:
3077dflt_2:
3078 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X! Lcn %i\n",
3079 card->devname, cmd, err, mb->cmd.lcn)
3080 ;
3081 retry = 0; /* abort command */
3082 }
3083 kfree(mb);
3084 return retry;
3085}
3086
3087/*====================================================================
3088 * X.25 Asynchronous Event Handlers
3089 * These functions are called by the x25_error() and should return 0, if
3090 * the command resulting in the asynchronous event must be aborted.
3091 *====================================================================*/
3092
3093
3094
3095/*====================================================================
3096 *Handle X.25 incoming call request.
3097 * RFC 1356 establishes the following rules:
3098 * 1. The first octet in the Call User Data (CUD) field of the call
3099 * request packet contains NLPID identifying protocol encapsulation
3100 * 2. Calls MUST NOT be accepted unless router supports requested
3101 * protocol encapsulation.
3102 * 3. A diagnostic code 249 defined by ISO/IEC 8208 may be used
3103 * when clearing a call because protocol encapsulation is not
3104 * supported.
3105 * 4. If an incoming call is received while a call request is
3106 * pending (i.e. call collision has occurred), the incoming call
3107 * shall be rejected and call request shall be retried.
3108 *====================================================================*/
3109
3110static int incoming_call (sdla_t* card, int cmd, int lcn, TX25Mbox* mb)
3111{
3112 struct wan_device* wandev = &card->wandev;
3113 int new_lcn = mb->cmd.lcn;
3114 struct net_device* dev = get_dev_by_lcn(wandev, new_lcn);
3115 x25_channel_t* chan = NULL;
3116 int accept = 0; /* set to '1' if o.k. to accept call */
3117 unsigned int user_data;
3118 x25_call_info_t* info;
3119
3120 /* Make sure there is no call collision */
3121 if (dev != NULL)
3122 {
3123 printk(KERN_INFO
3124 "%s: X.25 incoming call collision on LCN %d!\n",
3125 card->devname, new_lcn);
3126
3127 x25_clear_call(card, new_lcn, 0, 0);
3128 return 1;
3129 }
3130
3131 /* Make sure D bit is not set in call request */
3132//FIXME: THIS IS NOT TURE !!!! TAKE IT OUT
3133// if (mb->cmd.qdm & 0x02)
3134// {
3135// printk(KERN_INFO
3136// "%s: X.25 incoming call on LCN %d with D-bit set!\n",
3137// card->devname, new_lcn);
3138//
3139// x25_clear_call(card, new_lcn, 0, 0);
3140// return 1;
3141// }
3142
3143 /* Parse call request data */
3144 info = kmalloc(sizeof(x25_call_info_t), GFP_ATOMIC);
3145 if (info == NULL)
3146 {
3147 printk(KERN_ERR
3148 "%s: not enough memory to parse X.25 incoming call "
3149 "on LCN %d!\n", card->devname, new_lcn);
3150 x25_clear_call(card, new_lcn, 0, 0);
3151 return 1;
3152 }
3153
3154 parse_call_info(mb->data, info);
3155
3156 if (card->u.x.logging)
3157 printk(KERN_INFO "\n%s: X.25 incoming call on LCN %d!\n",
3158 card->devname, new_lcn);
3159
3160 /* Conver the first two ASCII characters into an
3161 * interger. Used to check the incoming protocol
3162 */
3163 user_data = hex_to_uint(info->user,2);
3164
3165 /* Find available channel */
3166 for (dev = wandev->dev; dev; dev = *((struct net_device **)dev->priv)) {
3167 chan = dev->priv;
3168
3169 if (chan->common.usedby == API)
3170 continue;
3171
3172 if (!chan->common.svc || (chan->common.state != WAN_DISCONNECTED))
3173 continue;
3174
3175 if (user_data == NLPID_IP && chan->protocol != htons(ETH_P_IP)){
3176 printk(KERN_INFO "IP packet but configured for IPX : %x, %x\n",
3177 htons(chan->protocol), info->user[0]);
3178 continue;
3179 }
3180
3181 if (user_data == NLPID_SNAP && chan->protocol != htons(ETH_P_IPX)){
3182 printk(KERN_INFO "IPX packet but configured for IP: %x\n",
3183 htons(chan->protocol));
3184 continue;
3185 }
3186 if (strcmp(info->src, chan->addr) == 0)
3187 break;
3188
3189 /* If just an '@' is specified, accept all incoming calls */
3190 if (strcmp(chan->addr, "") == 0)
3191 break;
3192 }
3193
3194 if (dev == NULL){
3195
3196 /* If the call is not for any WANPIPE interfaces
3197 * check to see if there is an API listening queue
3198 * waiting for data. If there is send the packet
3199 * up the stack.
3200 */
3201 if (card->sk != NULL && card->func != NULL){
3202 if (api_incoming_call(card,mb,new_lcn)){
3203 x25_clear_call(card, new_lcn, 0, 0);
3204 }
3205 accept = 0;
3206 }else{
3207 printk(KERN_INFO "%s: no channels available!\n",
3208 card->devname);
3209
3210 x25_clear_call(card, new_lcn, 0, 0);
3211 }
3212
3213 }else if (info->nuser == 0){
3214
3215 printk(KERN_INFO
3216 "%s: no user data in incoming call on LCN %d!\n",
3217 card->devname, new_lcn)
3218 ;
3219 x25_clear_call(card, new_lcn, 0, 0);
3220
3221 }else switch (info->user[0]){
3222
3223 case 0: /* multiplexed */
3224 chan->protocol = htons(0);
3225 accept = 1;
3226 break;
3227
3228 case NLPID_IP: /* IP datagrams */
3229 accept = 1;
3230 break;
3231
3232 case NLPID_SNAP: /* IPX datagrams */
3233 accept = 1;
3234 break;
3235
3236 default:
3237 printk(KERN_INFO
3238 "%s: unsupported NLPID 0x%02X in incoming call "
3239 "on LCN %d!\n", card->devname, info->user[0], new_lcn);
3240 x25_clear_call(card, new_lcn, 0, 249);
3241 }
3242
3243 if (accept && (x25_accept_call(card, new_lcn, 0) == CMD_OK)){
3244
3245 bind_lcn_to_dev (card, chan->dev, new_lcn);
3246
3247 if (x25_get_chan_conf(card, chan) == CMD_OK)
3248 set_chan_state(dev, WAN_CONNECTED);
3249 else
3250 x25_clear_call(card, new_lcn, 0, 0);
3251 }
3252 kfree(info);
3253 return 1;
3254}
3255
3256/*====================================================================
3257 * Handle accepted call.
3258 *====================================================================*/
3259
3260static int call_accepted (sdla_t* card, int cmd, int lcn, TX25Mbox* mb)
3261{
3262 unsigned new_lcn = mb->cmd.lcn;
3263 struct net_device* dev = find_channel(card, new_lcn);
3264 x25_channel_t* chan;
3265
3266 if (dev == NULL){
3267 printk(KERN_INFO
3268 "%s: clearing orphaned connection on LCN %d!\n",
3269 card->devname, new_lcn);
3270 x25_clear_call(card, new_lcn, 0, 0);
3271 return 1;
3272 }
3273
3274 if (card->u.x.logging)
3275 printk(KERN_INFO "%s: X.25 call accepted on Dev %s and LCN %d!\n",
3276 card->devname, dev->name, new_lcn);
3277
3278 /* Get channel configuration and notify router */
3279 chan = dev->priv;
3280 if (x25_get_chan_conf(card, chan) != CMD_OK)
3281 {
3282 x25_clear_call(card, new_lcn, 0, 0);
3283 return 1;
3284 }
3285
3286 set_chan_state(dev, WAN_CONNECTED);
3287
3288 if (chan->common.usedby == API){
3289 send_delayed_cmd_result(card,dev,mb);
3290 bind_lcn_to_dev (card, dev, new_lcn);
3291 }
3292
3293 return 1;
3294}
3295
3296/*====================================================================
3297 * Handle cleared call.
3298 *====================================================================*/
3299
3300static int call_cleared (sdla_t* card, int cmd, int lcn, TX25Mbox* mb)
3301{
3302 unsigned new_lcn = mb->cmd.lcn;
3303 struct net_device* dev = find_channel(card, new_lcn);
3304 x25_channel_t *chan;
3305 unsigned char old_state;
3306
3307 if (card->u.x.logging){
3308 printk(KERN_INFO "%s: X.25 clear request on LCN %d! Cause:0x%02X "
3309 "Diagn:0x%02X\n",
3310 card->devname, new_lcn, mb->cmd.cause, mb->cmd.diagn);
3311 }
3312
3313 if (dev == NULL){
3314 printk(KERN_INFO "%s: X.25 clear request : No device for clear\n",
3315 card->devname);
3316 return 1;
3317 }
3318
3319 chan=dev->priv;
3320
3321 old_state = chan->common.state;
3322
3323 set_chan_state(dev, WAN_DISCONNECTED);
3324
3325 if (chan->common.usedby == API){
3326
3327 switch (old_state){
3328
3329 case WAN_CONNECTING:
3330 send_delayed_cmd_result(card,dev,mb);
3331 break;
3332 case WAN_CONNECTED:
3333 send_oob_msg(card,dev,mb);
3334 break;
3335 }
3336 }
3337
3338 return ((cmd == X25_WRITE) && (lcn == new_lcn)) ? 0 : 1;
3339}
3340
3341/*====================================================================
3342 * Handle X.25 restart event.
3343 *====================================================================*/
3344
3345static int restart_event (sdla_t* card, int cmd, int lcn, TX25Mbox* mb)
3346{
3347 struct wan_device* wandev = &card->wandev;
3348 struct net_device* dev;
3349 x25_channel_t *chan;
3350 unsigned char old_state;
3351
3352 printk(KERN_INFO
3353 "%s: X.25 restart request! Cause:0x%02X Diagn:0x%02X\n",
3354 card->devname, mb->cmd.cause, mb->cmd.diagn);
3355
3356 /* down all logical channels */
3357 for (dev = wandev->dev; dev; dev = *((struct net_device **)dev->priv)) {
3358 chan=dev->priv;
3359 old_state = chan->common.state;
3360
3361 set_chan_state(dev, WAN_DISCONNECTED);
3362
3363 if (chan->common.usedby == API){
3364 switch (old_state){
3365
3366 case WAN_CONNECTING:
3367 send_delayed_cmd_result(card,dev,mb);
3368 break;
3369 case WAN_CONNECTED:
3370 send_oob_msg(card,dev,mb);
3371 break;
3372 }
3373 }
3374 }
3375 return (cmd == X25_WRITE) ? 0 : 1;
3376}
3377
3378/*====================================================================
3379 * Handle timeout event.
3380 *====================================================================*/
3381
3382static int timeout_event (sdla_t* card, int cmd, int lcn, TX25Mbox* mb)
3383{
3384 unsigned new_lcn = mb->cmd.lcn;
3385
3386 if (mb->cmd.pktType == 0x05) /* call request time out */
3387 {
3388 struct net_device* dev = find_channel(card,new_lcn);
3389
3390 printk(KERN_INFO "%s: X.25 call timed timeout on LCN %d!\n",
3391 card->devname, new_lcn);
3392
3393 if (dev){
3394 x25_channel_t *chan = dev->priv;
3395 set_chan_state(dev, WAN_DISCONNECTED);
3396
3397 if (chan->common.usedby == API){
3398 send_delayed_cmd_result(card,dev,card->mbox);
3399 }
3400 }
3401 }else{
3402 printk(KERN_INFO "%s: X.25 packet 0x%02X timeout on LCN %d!\n",
3403 card->devname, mb->cmd.pktType, new_lcn);
3404 }
3405 return 1;
3406}
3407
3408/*
3409 * Miscellaneous
3410 */
3411
3412/*====================================================================
3413 * Establish physical connection.
3414 * o open HDLC and raise DTR
3415 *
3416 * Return: 0 connection established
3417 * 1 connection is in progress
3418 * <0 error
3419 *===================================================================*/
3420
3421static int connect (sdla_t* card)
3422{
3423 TX25Status* status = card->flags;
3424
3425 if (x25_open_hdlc(card) || x25_setup_hdlc(card))
3426 return -EIO;
3427
3428 wanpipe_set_state(card, WAN_CONNECTING);
3429
3430 x25_set_intr_mode(card, INTR_ON_TIMER);
3431 status->imask &= ~INTR_ON_TIMER;
3432
3433 return 1;
3434}
3435
3436/*
3437 * Tear down physical connection.
3438 * o close HDLC link
3439 * o drop DTR
3440 *
3441 * Return: 0
3442 * <0 error
3443 */
3444
3445static int disconnect (sdla_t* card)
3446{
3447 wanpipe_set_state(card, WAN_DISCONNECTED);
3448 x25_set_intr_mode(card, INTR_ON_TIMER); /* disable all interrupt except timer */
3449 x25_close_hdlc(card); /* close HDLC link */
3450 x25_set_dtr(card, 0); /* drop DTR */
3451 return 0;
3452}
3453
3454/*
3455 * Find network device by its channel number.
3456 */
3457
3458static struct net_device* get_dev_by_lcn(struct wan_device* wandev,
3459 unsigned lcn)
3460{
3461 struct net_device* dev;
3462
3463 for (dev = wandev->dev; dev; dev = *((struct net_device **)dev->priv))
3464 if (((x25_channel_t*)dev->priv)->common.lcn == lcn)
3465 break;
3466 return dev;
3467}
3468
3469/*
3470 * Initiate connection on the logical channel.
3471 * o for PVC we just get channel configuration
3472 * o for SVCs place an X.25 call
3473 *
3474 * Return: 0 connected
3475 * >0 connection in progress
3476 * <0 failure
3477 */
3478
3479static int chan_connect(struct net_device* dev)
3480{
3481 x25_channel_t* chan = dev->priv;
3482 sdla_t* card = chan->card;
3483
3484 if (chan->common.svc && chan->common.usedby == WANPIPE){
3485 if (!chan->addr[0]){
3486 printk(KERN_INFO "%s: No Destination Address\n",
3487 card->devname);
3488 return -EINVAL; /* no destination address */
3489 }
3490 printk(KERN_INFO "%s: placing X.25 call to %s ...\n",
3491 card->devname, chan->addr);
3492
3493 if (x25_place_call(card, chan) != CMD_OK)
3494 return -EIO;
3495
3496 set_chan_state(dev, WAN_CONNECTING);
3497 return 1;
3498 }else{
3499 if (x25_get_chan_conf(card, chan) != CMD_OK)
3500 return -EIO;
3501
3502 set_chan_state(dev, WAN_CONNECTED);
3503 }
3504 return 0;
3505}
3506
3507/*
3508 * Disconnect logical channel.
3509 * o if SVC then clear X.25 call
3510 */
3511
3512static int chan_disc(struct net_device* dev)
3513{
3514 x25_channel_t* chan = dev->priv;
3515
3516 if (chan->common.svc){
3517 x25_clear_call(chan->card, chan->common.lcn, 0, 0);
3518
3519 /* For API we disconnect on clear
3520 * confirmation.
3521 */
3522 if (chan->common.usedby == API)
3523 return 0;
3524 }
3525
3526 set_chan_state(dev, WAN_DISCONNECTED);
3527
3528 return 0;
3529}
3530
3531/*
3532 * Set logical channel state.
3533 */
3534
3535static void set_chan_state(struct net_device* dev, int state)
3536{
3537 x25_channel_t* chan = dev->priv;
3538 sdla_t* card = chan->card;
3539 unsigned long flags;
3540
3541 save_flags(flags);
3542 cli();
3543 if (chan->common.state != state)
3544 {
3545 switch (state)
3546 {
3547 case WAN_CONNECTED:
3548 if (card->u.x.logging){
3549 printk (KERN_INFO
3550 "%s: interface %s connected, lcn %i !\n",
3551 card->devname, dev->name,chan->common.lcn);
3552 }
3553 *(unsigned short*)dev->dev_addr = htons(chan->common.lcn);
3554 chan->i_timeout_sofar = jiffies;
3555
3556 /* LAPB is PVC Based */
3557 if (card->u.x.LAPB_hdlc)
3558 chan->common.svc=0;
3559 break;
3560
3561 case WAN_CONNECTING:
3562 if (card->u.x.logging){
3563 printk (KERN_INFO
3564 "%s: interface %s connecting, lcn %i ...\n",
3565 card->devname, dev->name, chan->common.lcn);
3566 }
3567 break;
3568
3569 case WAN_DISCONNECTED:
3570 if (card->u.x.logging){
3571 printk (KERN_INFO
3572 "%s: interface %s disconnected, lcn %i !\n",
3573 card->devname, dev->name,chan->common.lcn);
3574 }
3575 atomic_set(&chan->common.disconnect,0);
3576
3577 if (chan->common.svc) {
3578 *(unsigned short*)dev->dev_addr = 0;
3579 card->u.x.svc_to_dev_map[(chan->common.lcn%X25_MAX_CHAN)]=NULL;
3580 chan->common.lcn = 0;
3581 }
3582
3583 if (chan->transmit_length){
3584 chan->transmit_length=0;
3585 atomic_set(&chan->common.driver_busy,0);
3586 chan->tx_offset=0;
3587 if (netif_queue_stopped(dev)){
3588 netif_wake_queue(dev);
3589 }
3590 }
3591 atomic_set(&chan->common.command,0);
3592 break;
3593
3594 case WAN_DISCONNECTING:
3595 if (card->u.x.logging){
3596 printk (KERN_INFO
3597 "\n%s: interface %s disconnecting, lcn %i ...\n",
3598 card->devname, dev->name,chan->common.lcn);
3599 }
3600 atomic_set(&chan->common.disconnect,0);
3601 break;
3602 }
3603 chan->common.state = state;
3604 }
3605 chan->state_tick = jiffies;
3606 restore_flags(flags);
3607}
3608
3609/*
3610 * Send packet on a logical channel.
3611 * When this function is called, tx_skb field of the channel data
3612 * space points to the transmit socket buffer. When transmission
3613 * is complete, release socket buffer and reset 'tbusy' flag.
3614 *
3615 * Return: 0 - transmission complete
3616 * 1 - busy
3617 *
3618 * Notes:
3619 * 1. If packet length is greater than MTU for this channel, we'll fragment
3620 * the packet into 'complete sequence' using M-bit.
3621 * 2. When transmission is complete, an event notification should be issued
3622 * to the router.
3623 */
3624
3625static int chan_send(struct net_device* dev, void* buff, unsigned data_len,
3626 unsigned char tx_intr)
3627{
3628 x25_channel_t* chan = dev->priv;
3629 sdla_t* card = chan->card;
3630 TX25Status* status = card->flags;
3631 unsigned len=0, qdm=0, res=0, orig_len = 0;
3632 void *data;
3633
3634 /* Check to see if channel is ready */
3635 if ((!(status->cflags[chan->ch_idx] & 0x40) && !card->u.x.LAPB_hdlc) ||
3636 !(*card->u.x.hdlc_buf_status & 0x40)){
3637
3638 if (!tx_intr){
3639 setup_for_delayed_transmit (dev, buff, data_len);
3640 return 0;
3641 }else{
3642 /* By returning 0 to tx_intr the packet will be dropped */
3643 ++card->wandev.stats.tx_dropped;
3644 ++chan->ifstats.tx_dropped;
3645 printk(KERN_INFO "%s: ERROR, Tx intr could not send, dropping %s:\n",
3646 card->devname,dev->name);
3647 ++chan->if_send_stat.if_send_bfr_not_passed_to_adptr;
3648 return 0;
3649 }
3650 }
3651
3652 if (chan->common.usedby == API){
3653 /* Remove the API Header */
3654 x25api_hdr_t *api_data = (x25api_hdr_t *)buff;
3655
3656 /* Set the qdm bits from the packet header
3657 * User has the option to set the qdm bits
3658 */
3659 qdm = api_data->qdm;
3660
3661 orig_len = len = data_len - sizeof(x25api_hdr_t);
3662 data = (unsigned char*)buff + sizeof(x25api_hdr_t);
3663 }else{
3664 data = buff;
3665 orig_len = len = data_len;
3666 }
3667
3668 if (tx_intr){
3669 /* We are in tx_intr, minus the tx_offset from
3670 * the total length. The tx_offset part of the
3671 * data has already been sent. Also, move the
3672 * data pointer to proper offset location.
3673 */
3674 len -= chan->tx_offset;
3675 data = (unsigned char*)data + chan->tx_offset;
3676 }
3677
3678 /* Check if the packet length is greater than MTU
3679 * If YES: Cut the len to MTU and set the M bit
3680 */
3681 if (len > chan->tx_pkt_size && !card->u.x.LAPB_hdlc){
3682 len = chan->tx_pkt_size;
3683 qdm |= M_BIT;
3684 }
3685
3686
3687 /* Pass only first three bits of the qdm byte to the send
3688 * routine. In case user sets any other bit which might
3689 * cause errors.
3690 */
3691
3692 switch(x25_send(card, chan->common.lcn, (qdm&0x07), len, data)){
3693 case 0x00: /* success */
3694 chan->i_timeout_sofar = jiffies;
3695
3696 dev->trans_start=jiffies;
3697
3698 if ((qdm & M_BIT) && !card->u.x.LAPB_hdlc){
3699 if (!tx_intr){
3700 /* The M bit was set, which means that part of the
3701 * packet has been sent. Copy the packet into a buffer
3702 * and set the offset to len, so on next tx_inter
3703 * the packet will be sent using the below offset.
3704 */
3705 chan->tx_offset += len;
3706
3707 ++chan->ifstats.tx_packets;
3708 chan->ifstats.tx_bytes += len;
3709
3710 if (chan->tx_offset < orig_len){
3711 setup_for_delayed_transmit (dev, buff, data_len);
3712 }
3713 res=0;
3714 }else{
3715 /* We are already in tx_inter, thus data is already
3716 * in the buffer. Update the offset and wait for
3717 * next tx_intr. We add on to the offset, since data can
3718 * be X number of times larger than max data size.
3719 */
3720 ++chan->ifstats.tx_packets;
3721 chan->ifstats.tx_bytes += len;
3722
3723 ++chan->if_send_stat.if_send_bfr_passed_to_adptr;
3724 chan->tx_offset += len;
3725
3726 /* The user can set the qdm bit as well.
3727 * If the entire packet was sent and qdm is still
3728 * set, than it's the user who has set the M bit. In that,
3729 * case indicate that the packet was send by returning
3730 * 0 and wait for a new packet. Otherwise, wait for next
3731 * tx interrupt to send the rest of the packet */
3732
3733 if (chan->tx_offset < orig_len){
3734 res=1;
3735 }else{
3736 res=0;
3737 }
3738 }
3739 }else{
3740 ++chan->ifstats.tx_packets;
3741 chan->ifstats.tx_bytes += len;
3742 ++chan->if_send_stat.if_send_bfr_passed_to_adptr;
3743 res=0;
3744 }
3745 break;
3746
3747 case 0x33: /* Tx busy */
3748 if (tx_intr){
3749 printk(KERN_INFO "%s: Tx_intr: Big Error dropping packet %s\n",
3750 card->devname,dev->name);
3751 ++chan->ifstats.tx_dropped;
3752 ++card->wandev.stats.tx_dropped;
3753 ++chan->if_send_stat.if_send_bfr_not_passed_to_adptr;
3754 res=0;
3755 }else{
3756 DBG_PRINTK(KERN_INFO
3757 "%s: Send: Big Error should have tx: storring %s\n",
3758 card->devname,dev->name);
3759 setup_for_delayed_transmit (dev, buff, data_len);
3760 res=1;
3761 }
3762 break;
3763
3764 default: /* failure */
3765 ++chan->ifstats.tx_errors;
3766 if (tx_intr){
3767 printk(KERN_INFO "%s: Tx_intr: Failure to send, dropping %s\n",
3768 card->devname,dev->name);
3769 ++chan->ifstats.tx_dropped;
3770 ++card->wandev.stats.tx_dropped;
3771 ++chan->if_send_stat.if_send_bfr_not_passed_to_adptr;
3772 res=0;
3773 }else{
3774 DBG_PRINTK(KERN_INFO "%s: Send: Failure to send !!!, storing %s\n",
3775 card->devname,dev->name);
3776 setup_for_delayed_transmit (dev, buff, data_len);
3777 res=1;
3778 }
3779 break;
3780 }
3781 return res;
3782}
3783
3784
3785/*
3786 * Parse X.25 call request data and fill x25_call_info_t structure.
3787 */
3788
3789static void parse_call_info (unsigned char* str, x25_call_info_t* info)
3790{
3791 memset(info, 0, sizeof(x25_call_info_t));
3792 for (; *str; ++str)
3793 {
3794 int i;
3795 unsigned char ch;
3796
3797 if (*str == '-') switch (str[1]) {
3798
3799 /* Take minus 2 off the maximum size so that
3800 * last byte is 0. This way we can use string
3801 * manipulaton functions on call information.
3802 */
3803
3804 case 'd': /* destination address */
3805 for (i = 0; i < (MAX_X25_ADDR_SIZE-2); ++i){
3806 ch = str[2+i];
3807 if (isspace(ch)) break;
3808 info->dest[i] = ch;
3809 }
3810 break;
3811
3812 case 's': /* source address */
3813 for (i = 0; i < (MAX_X25_ADDR_SIZE-2); ++i){
3814 ch = str[2+i];
3815 if (isspace(ch)) break;
3816 info->src[i] = ch;
3817 }
3818 break;
3819
3820 case 'u': /* user data */
3821 for (i = 0; i < (MAX_X25_DATA_SIZE-2); ++i){
3822 ch = str[2+i];
3823 if (isspace(ch)) break;
3824 info->user[i] = ch;
3825 }
3826 info->nuser = i;
3827 break;
3828
3829 case 'f': /* facilities */
3830 for (i = 0; i < (MAX_X25_FACL_SIZE-2); ++i){
3831 ch = str[2+i];
3832 if (isspace(ch)) break;
3833 info->facil[i] = ch;
3834 }
3835 info->nfacil = i;
3836 break;
3837 }
3838 }
3839}
3840
3841/*
3842 * Convert line speed in bps to a number used by S502 code.
3843 */
3844
3845static unsigned char bps_to_speed_code (unsigned long bps)
3846{
3847 unsigned char number;
3848
3849 if (bps <= 1200) number = 0x01;
3850 else if (bps <= 2400) number = 0x02;
3851 else if (bps <= 4800) number = 0x03;
3852 else if (bps <= 9600) number = 0x04;
3853 else if (bps <= 19200) number = 0x05;
3854 else if (bps <= 38400) number = 0x06;
3855 else if (bps <= 45000) number = 0x07;
3856 else if (bps <= 56000) number = 0x08;
3857 else if (bps <= 64000) number = 0x09;
3858 else if (bps <= 74000) number = 0x0A;
3859 else if (bps <= 112000) number = 0x0B;
3860 else if (bps <= 128000) number = 0x0C;
3861 else number = 0x0D;
3862
3863 return number;
3864}
3865
3866/*
3867 * Convert decimal string to unsigned integer.
3868 * If len != 0 then only 'len' characters of the string are converted.
3869 */
3870
3871static unsigned int dec_to_uint (unsigned char* str, int len)
3872{
3873 unsigned val;
3874
3875 if (!len)
3876 len = strlen(str);
3877
3878 for (val = 0; len && isdigit(*str); ++str, --len)
3879 val = (val * 10) + (*str - (unsigned)'0');
3880
3881 return val;
3882}
3883
3884/*
3885 * Convert hex string to unsigned integer.
3886 * If len != 0 then only 'len' characters of the string are conferted.
3887 */
3888
3889static unsigned int hex_to_uint (unsigned char* str, int len)
3890{
3891 unsigned val, ch;
3892
3893 if (!len)
3894 len = strlen(str);
3895
3896 for (val = 0; len; ++str, --len)
3897 {
3898 ch = *str;
3899 if (isdigit(ch))
3900 val = (val << 4) + (ch - (unsigned)'0');
3901 else if (isxdigit(ch))
3902 val = (val << 4) + ((ch & 0xDF) - (unsigned)'A' + 10);
3903 else break;
3904 }
3905 return val;
3906}
3907
3908
3909static int handle_IPXWAN(unsigned char *sendpacket, char *devname, unsigned char enable_IPX, unsigned long network_number, unsigned short proto)
3910{
3911 int i;
3912
3913 if( proto == ETH_P_IPX) {
3914 /* It's an IPX packet */
3915 if(!enable_IPX) {
3916 /* Return 1 so we don't pass it up the stack. */
3917 return 1;
3918 }
3919 } else {
3920 /* It's not IPX so pass it up the stack.*/
3921 return 0;
3922 }
3923
3924 if( sendpacket[16] == 0x90 &&
3925 sendpacket[17] == 0x04)
3926 {
3927 /* It's IPXWAN */
3928
3929 if( sendpacket[2] == 0x02 &&
3930 sendpacket[34] == 0x00)
3931 {
3932 /* It's a timer request packet */
3933 printk(KERN_INFO "%s: Received IPXWAN Timer Request packet\n",devname);
3934
3935 /* Go through the routing options and answer no to every
3936 * option except Unnumbered RIP/SAP
3937 */
3938 for(i = 41; sendpacket[i] == 0x00; i += 5)
3939 {
3940 /* 0x02 is the option for Unnumbered RIP/SAP */
3941 if( sendpacket[i + 4] != 0x02)
3942 {
3943 sendpacket[i + 1] = 0;
3944 }
3945 }
3946
3947 /* Skip over the extended Node ID option */
3948 if( sendpacket[i] == 0x04 )
3949 {
3950 i += 8;
3951 }
3952
3953 /* We also want to turn off all header compression opt. */
3954 for(; sendpacket[i] == 0x80 ;)
3955 {
3956 sendpacket[i + 1] = 0;
3957 i += (sendpacket[i + 2] << 8) + (sendpacket[i + 3]) + 4;
3958 }
3959
3960 /* Set the packet type to timer response */
3961 sendpacket[34] = 0x01;
3962
3963 printk(KERN_INFO "%s: Sending IPXWAN Timer Response\n",devname);
3964 }
3965 else if( sendpacket[34] == 0x02 )
3966 {
3967 /* This is an information request packet */
3968 printk(KERN_INFO "%s: Received IPXWAN Information Request packet\n",devname);
3969
3970 /* Set the packet type to information response */
3971 sendpacket[34] = 0x03;
3972
3973 /* Set the router name */
3974 sendpacket[51] = 'X';
3975 sendpacket[52] = 'T';
3976 sendpacket[53] = 'P';
3977 sendpacket[54] = 'I';
3978 sendpacket[55] = 'P';
3979 sendpacket[56] = 'E';
3980 sendpacket[57] = '-';
3981 sendpacket[58] = CVHexToAscii(network_number >> 28);
3982 sendpacket[59] = CVHexToAscii((network_number & 0x0F000000)>> 24);
3983 sendpacket[60] = CVHexToAscii((network_number & 0x00F00000)>> 20);
3984 sendpacket[61] = CVHexToAscii((network_number & 0x000F0000)>> 16);
3985 sendpacket[62] = CVHexToAscii((network_number & 0x0000F000)>> 12);
3986 sendpacket[63] = CVHexToAscii((network_number & 0x00000F00)>> 8);
3987 sendpacket[64] = CVHexToAscii((network_number & 0x000000F0)>> 4);
3988 sendpacket[65] = CVHexToAscii(network_number & 0x0000000F);
3989 for(i = 66; i < 99; i+= 1)
3990 {
3991 sendpacket[i] = 0;
3992 }
3993
3994 printk(KERN_INFO "%s: Sending IPXWAN Information Response packet\n",devname);
3995 }
3996 else
3997 {
3998 printk(KERN_INFO "%s: Unknown IPXWAN packet!\n",devname);
3999 return 0;
4000 }
4001
4002 /* Set the WNodeID to our network address */
4003 sendpacket[35] = (unsigned char)(network_number >> 24);
4004 sendpacket[36] = (unsigned char)((network_number & 0x00FF0000) >> 16);
4005 sendpacket[37] = (unsigned char)((network_number & 0x0000FF00) >> 8);
4006 sendpacket[38] = (unsigned char)(network_number & 0x000000FF);
4007
4008 return 1;
4009 } else {
4010 /*If we get here it's an IPX-data packet, so it'll get passed up the stack.
4011 */
4012 /* switch the network numbers */
4013 switch_net_numbers(sendpacket, network_number, 1);
4014 return 0;
4015 }
4016}
4017
4018/*
4019 * If incoming is 0 (outgoing)- if the net numbers is ours make it 0
4020 * if incoming is 1 - if the net number is 0 make it ours
4021 */
4022
4023static void switch_net_numbers(unsigned char *sendpacket, unsigned long network_number, unsigned char incoming)
4024{
4025 unsigned long pnetwork_number;
4026
4027 pnetwork_number = (unsigned long)((sendpacket[6] << 24) +
4028 (sendpacket[7] << 16) + (sendpacket[8] << 8) +
4029 sendpacket[9]);
4030
4031
4032 if (!incoming) {
4033 /*If the destination network number is ours, make it 0 */
4034 if( pnetwork_number == network_number) {
4035 sendpacket[6] = sendpacket[7] = sendpacket[8] =
4036 sendpacket[9] = 0x00;
4037 }
4038 } else {
4039 /* If the incoming network is 0, make it ours */
4040 if( pnetwork_number == 0) {
4041 sendpacket[6] = (unsigned char)(network_number >> 24);
4042 sendpacket[7] = (unsigned char)((network_number &
4043 0x00FF0000) >> 16);
4044 sendpacket[8] = (unsigned char)((network_number &
4045 0x0000FF00) >> 8);
4046 sendpacket[9] = (unsigned char)(network_number &
4047 0x000000FF);
4048 }
4049 }
4050
4051
4052 pnetwork_number = (unsigned long)((sendpacket[18] << 24) +
4053 (sendpacket[19] << 16) + (sendpacket[20] << 8) +
4054 sendpacket[21]);
4055
4056
4057 if( !incoming ) {
4058 /* If the source network is ours, make it 0 */
4059 if( pnetwork_number == network_number) {
4060 sendpacket[18] = sendpacket[19] = sendpacket[20] =
4061 sendpacket[21] = 0x00;
4062 }
4063 } else {
4064 /* If the source network is 0, make it ours */
4065 if( pnetwork_number == 0 ) {
4066 sendpacket[18] = (unsigned char)(network_number >> 24);
4067 sendpacket[19] = (unsigned char)((network_number &
4068 0x00FF0000) >> 16);
4069 sendpacket[20] = (unsigned char)((network_number &
4070 0x0000FF00) >> 8);
4071 sendpacket[21] = (unsigned char)(network_number &
4072 0x000000FF);
4073 }
4074 }
4075} /* switch_net_numbers */
4076
4077
4078
4079
4080/********************* X25API SPECIFIC FUNCTIONS ****************/
4081
4082
4083/*===============================================================
4084 * find_channel
4085 *
4086 * Manages the lcn to device map. It increases performance
4087 * because it eliminates the need to search through the link
4088 * list for a device which is bounded to a specific lcn.
4089 *
4090 *===============================================================*/
4091
4092
4093struct net_device *find_channel(sdla_t *card, unsigned lcn)
4094{
4095 if (card->u.x.LAPB_hdlc){
4096
4097 return card->wandev.dev;
4098
4099 }else{
4100 /* We don't know whether the incoming lcn
4101 * is a PVC or an SVC channel. But we do know that
4102 * the lcn cannot be for both the PVC and the SVC
4103 * channel.
4104
4105 * If the lcn number is greater or equal to 255,
4106 * take the modulo 255 of that number. We only have
4107 * 255 locations, thus higher numbers must be mapped
4108 * to a number between 0 and 245.
4109
4110 * We must separate pvc's and svc's since two don't
4111 * have to be contiguous. Meaning pvc's can start
4112 * from 1 to 10 and svc's can start from 256 to 266.
4113 * But 256%255 is 1, i.e. CONFLICT.
4114 */
4115
4116
4117 /* Highest LCN number must be less or equal to 4096 */
4118 if ((lcn <= MAX_LCN_NUM) && (lcn > 0)){
4119
4120 if (lcn < X25_MAX_CHAN){
4121 if (card->u.x.svc_to_dev_map[lcn])
4122 return card->u.x.svc_to_dev_map[lcn];
4123
4124 if (card->u.x.pvc_to_dev_map[lcn])
4125 return card->u.x.pvc_to_dev_map[lcn];
4126
4127 }else{
4128 int new_lcn = lcn%X25_MAX_CHAN;
4129 if (card->u.x.svc_to_dev_map[new_lcn])
4130 return card->u.x.svc_to_dev_map[new_lcn];
4131
4132 if (card->u.x.pvc_to_dev_map[new_lcn])
4133 return card->u.x.pvc_to_dev_map[new_lcn];
4134 }
4135 }
4136 return NULL;
4137 }
4138}
4139
4140void bind_lcn_to_dev(sdla_t *card, struct net_device *dev, unsigned lcn)
4141{
4142 x25_channel_t *chan = dev->priv;
4143
4144 /* Modulo the lcn number by X25_MAX_CHAN (255)
4145 * because the lcn number can be greater than 255
4146 *
4147 * We need to split svc and pvc since they don't have
4148 * to be contigous.
4149 */
4150
4151 if (chan->common.svc){
4152 card->u.x.svc_to_dev_map[(lcn % X25_MAX_CHAN)] = dev;
4153 }else{
4154 card->u.x.pvc_to_dev_map[(lcn % X25_MAX_CHAN)] = dev;
4155 }
4156 chan->common.lcn = lcn;
4157}
4158
4159
4160
4161/*===============================================================
4162 * x25api_bh
4163 *
4164 *
4165 *==============================================================*/
4166
4167static void x25api_bh(struct net_device* dev)
4168{
4169 x25_channel_t* chan = dev->priv;
4170 sdla_t* card = chan->card;
4171 struct sk_buff *skb;
4172
4173 if (atomic_read(&chan->bh_buff_used) == 0){
4174 printk(KERN_INFO "%s: BH Buffer Empty in BH\n",
4175 card->devname);
4176 clear_bit(0, &chan->tq_working);
4177 return;
4178 }
4179
4180 while (atomic_read(&chan->bh_buff_used)){
4181
4182 /* If the sock is in the process of unlinking the
4183 * driver from the socket, we must get out.
4184 * This never happends but is a sanity check. */
4185 if (test_bit(0,&chan->common.common_critical)){
4186 clear_bit(0, &chan->tq_working);
4187 return;
4188 }
4189
4190 /* If LAPB HDLC, do not drop packets if socket is
4191 * not connected. Let the buffer fill up and
4192 * turn off rx interrupt */
4193 if (card->u.x.LAPB_hdlc){
4194 if (chan->common.sk == NULL || chan->common.func == NULL){
4195 clear_bit(0, &chan->tq_working);
4196 return;
4197 }
4198 }
4199
4200 skb = ((bh_data_t *)&chan->bh_head[chan->bh_read])->skb;
4201
4202 if (skb == NULL){
4203 printk(KERN_INFO "%s: BH Skb empty for read %i\n",
4204 card->devname,chan->bh_read);
4205 }else{
4206
4207 if (chan->common.sk == NULL || chan->common.func == NULL){
4208 printk(KERN_INFO "%s: BH: Socket disconnected, dropping\n",
4209 card->devname);
4210 dev_kfree_skb_any(skb);
4211 x25api_bh_cleanup(dev);
4212 ++chan->ifstats.rx_dropped;
4213 ++chan->rx_intr_stat.rx_intr_bfr_not_passed_to_stack;
4214 continue;
4215 }
4216
4217
4218 if (chan->common.func(skb,dev,chan->common.sk) != 0){
4219 /* Sock full cannot send, queue us for another
4220 * try
4221 */
4222 printk(KERN_INFO "%s: BH: !!! Packet failed to send !!!!! \n",
4223 card->devname);
4224 atomic_set(&chan->common.receive_block,1);
4225 return;
4226 }else{
4227 x25api_bh_cleanup(dev);
4228 ++chan->rx_intr_stat.rx_intr_bfr_passed_to_stack;
4229 }
4230 }
4231 }
4232 clear_bit(0, &chan->tq_working);
4233
4234 return;
4235}
4236
4237/*===============================================================
4238 * x25api_bh_cleanup
4239 *
4240 *
4241 *==============================================================*/
4242
4243static int x25api_bh_cleanup(struct net_device *dev)
4244{
4245 x25_channel_t* chan = dev->priv;
4246 sdla_t *card = chan->card;
4247 TX25Status* status = card->flags;
4248
4249
4250 ((bh_data_t *)&chan->bh_head[chan->bh_read])->skb = NULL;
4251
4252 if (chan->bh_read == MAX_BH_BUFF){
4253 chan->bh_read=0;
4254 }else{
4255 ++chan->bh_read;
4256 }
4257
4258 /* If the Receive interrupt was off, it means
4259 * that we filled up our circular buffer. Check
4260 * that we have space in the buffer. If so
4261 * turn the RX interrupt back on.
4262 */
4263 if (!(status->imask & INTR_ON_RX_FRAME)){
4264 if (atomic_read(&chan->bh_buff_used) < (MAX_BH_BUFF+1)){
4265 printk(KERN_INFO "%s: BH: Turning on the interrupt\n",
4266 card->devname);
4267 status->imask |= INTR_ON_RX_FRAME;
4268 }
4269 }
4270
4271 atomic_dec(&chan->bh_buff_used);
4272 return 0;
4273}
4274
4275
4276/*===============================================================
4277 * bh_enqueue
4278 *
4279 *
4280 *==============================================================*/
4281
4282static int bh_enqueue(struct net_device *dev, struct sk_buff *skb)
4283{
4284 x25_channel_t* chan = dev->priv;
4285 sdla_t *card = chan->card;
4286 TX25Status* status = card->flags;
4287
4288 if (atomic_read(&chan->bh_buff_used) == (MAX_BH_BUFF+1)){
4289 printk(KERN_INFO "%s: Bottom half buffer FULL\n",
4290 card->devname);
4291 return 1;
4292 }
4293
4294 ((bh_data_t *)&chan->bh_head[chan->bh_write])->skb = skb;
4295
4296 if (chan->bh_write == MAX_BH_BUFF){
4297 chan->bh_write=0;
4298 }else{
4299 ++chan->bh_write;
4300 }
4301
4302 atomic_inc(&chan->bh_buff_used);
4303
4304 if (atomic_read(&chan->bh_buff_used) == (MAX_BH_BUFF+1)){
4305 printk(KERN_INFO "%s: Buffer is now full, Turning off RX Intr\n",
4306 card->devname);
4307 status->imask &= ~INTR_ON_RX_FRAME;
4308 }
4309
4310 return 0;
4311}
4312
4313
4314/*===============================================================
4315 * timer_intr_cmd_exec
4316 *
4317 * Called by timer interrupt to execute a command
4318 *===============================================================*/
4319
4320static int timer_intr_cmd_exec (sdla_t* card)
4321{
4322 struct net_device *dev;
4323 unsigned char more_to_exec=0;
4324 volatile x25_channel_t *chan=NULL;
4325 int i=0,bad_cmd=0,err=0;
4326
4327 if (card->u.x.cmd_dev == NULL){
4328 card->u.x.cmd_dev = card->wandev.dev;
4329 }
4330
4331 dev = card->u.x.cmd_dev;
4332
4333 for (;;){
4334
4335 chan = dev->priv;
4336
4337 if (atomic_read(&chan->common.command)){
4338
4339 bad_cmd = check_bad_command(card,dev);
4340
4341 if ((!chan->common.mbox || atomic_read(&chan->common.disconnect)) &&
4342 !bad_cmd){
4343
4344 /* Socket has died or exited, We must bring the
4345 * channel down before anybody else tries to
4346 * use it */
4347 err = channel_disconnect(card,dev);
4348 }else{
4349 err = execute_delayed_cmd(card, dev,
4350 (mbox_cmd_t*)chan->common.mbox,
4351 bad_cmd);
4352 }
4353
4354 switch (err){
4355
4356 case RETURN_RESULT:
4357
4358 /* Return the result to the socket without
4359 * delay. NO_WAIT Command */
4360 atomic_set(&chan->common.command,0);
4361 if (atomic_read(&card->u.x.command_busy))
4362 atomic_set(&card->u.x.command_busy,0);
4363
4364 send_delayed_cmd_result(card,dev,card->mbox);
4365
4366 more_to_exec=0;
4367 break;
4368 case DELAY_RESULT:
4369
4370 /* Wait for the remote to respond, before
4371 * sending the result up to the socket.
4372 * WAIT command */
4373 if (atomic_read(&card->u.x.command_busy))
4374 atomic_set(&card->u.x.command_busy,0);
4375
4376 atomic_set(&chan->common.command,0);
4377 more_to_exec=0;
4378 break;
4379 default:
4380
4381 /* If command could not be executed for
4382 * some reason (i.e return code 0x33 busy)
4383 * set the more_to_exec bit which will
4384 * indicate that this command must be exectued
4385 * again during next timer interrupt
4386 */
4387 more_to_exec=1;
4388 if (atomic_read(&card->u.x.command_busy) == 0)
4389 atomic_set(&card->u.x.command_busy,1);
4390 break;
4391 }
4392
4393 bad_cmd=0;
4394
4395 /* If flags is set, there are no hdlc buffers,
4396 * thus, wait for the next pass and try the
4397 * same command again. Otherwise, start searching
4398 * from next device on the next pass.
4399 */
4400 if (!more_to_exec){
4401 dev = move_dev_to_next(card,dev);
4402 }
4403 break;
4404 }else{
4405 /* This device has nothing to execute,
4406 * go to next.
4407 */
4408 if (atomic_read(&card->u.x.command_busy))
4409 atomic_set(&card->u.x.command_busy,0);
4410 dev = move_dev_to_next(card,dev);
4411 }
4412
4413 if (++i == card->u.x.no_dev){
4414 if (!more_to_exec){
4415 DBG_PRINTK(KERN_INFO "%s: Nothing to execute in Timer\n",
4416 card->devname);
4417 if (atomic_read(&card->u.x.command_busy)){
4418 atomic_set(&card->u.x.command_busy,0);
4419 }
4420 }
4421 break;
4422 }
4423
4424 } //End of FOR
4425
4426 card->u.x.cmd_dev = dev;
4427
4428 if (more_to_exec){
4429 /* If more commands are pending, do not turn off timer
4430 * interrupt */
4431 return 1;
4432 }else{
4433 /* No more commands, turn off timer interrupt */
4434 return 0;
4435 }
4436}
4437
4438/*===============================================================
4439 * execute_delayed_cmd
4440 *
4441 * Execute an API command which was passed down from the
4442 * sock. Sock is very limited in which commands it can
4443 * execute. Wait and No Wait commands are supported.
4444 * Place Call, Clear Call and Reset wait commands, where
4445 * Accept Call is a no_wait command.
4446 *
4447 *===============================================================*/
4448
4449static int execute_delayed_cmd(sdla_t* card, struct net_device *dev,
4450 mbox_cmd_t *usr_cmd, char bad_cmd)
4451{
4452 TX25Mbox* mbox = card->mbox;
4453 int err;
4454 x25_channel_t *chan = dev->priv;
4455 int delay=RETURN_RESULT;
4456
4457 if (!(*card->u.x.hdlc_buf_status & 0x40) && !bad_cmd){
4458 return TRY_CMD_AGAIN;
4459 }
4460
4461 /* This way a command is guaranteed to be executed for
4462 * a specific lcn, the network interface is bound to. */
4463 usr_cmd->cmd.lcn = chan->common.lcn;
4464
4465
4466 /* If channel is pvc, instead of place call
4467 * run x25_channel configuration. If running LAPB HDLC
4468 * enable communications.
4469 */
4470 if ((!chan->common.svc) && (usr_cmd->cmd.command == X25_PLACE_CALL)){
4471
4472 if (card->u.x.LAPB_hdlc){
4473 DBG_PRINTK(KERN_INFO "LAPB: Connecting\n");
4474 connect(card);
4475 set_chan_state(dev,WAN_CONNECTING);
4476 return DELAY_RESULT;
4477 }else{
4478 DBG_PRINTK(KERN_INFO "%s: PVC is CONNECTING\n",card->devname);
4479 if (x25_get_chan_conf(card, chan) == CMD_OK){
4480 set_chan_state(dev, WAN_CONNECTED);
4481 }else{
4482 set_chan_state(dev, WAN_DISCONNECTED);
4483 }
4484 return RETURN_RESULT;
4485 }
4486 }
4487
4488 /* Copy the socket mbox command onto the board */
4489
4490 memcpy(&mbox->cmd, &usr_cmd->cmd, sizeof(TX25Cmd));
4491 if (usr_cmd->cmd.length){
4492 memcpy(mbox->data, usr_cmd->data, usr_cmd->cmd.length);
4493 }
4494
4495 /* Check if command is bad. We need to copy the cmd into
4496 * the buffer regardless since we return the, mbox to
4497 * the user */
4498 if (bad_cmd){
4499 mbox->cmd.result=0x01;
4500 return RETURN_RESULT;
4501 }
4502
4503 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4504
4505 if (err != CMD_OK && err != X25RES_NOT_READY)
4506 x25_error(card, err, usr_cmd->cmd.command, usr_cmd->cmd.lcn);
4507
4508 if (mbox->cmd.result == X25RES_NOT_READY){
4509 return TRY_CMD_AGAIN;
4510 }
4511
4512 switch (mbox->cmd.command){
4513
4514 case X25_PLACE_CALL:
4515
4516 switch (mbox->cmd.result){
4517
4518 case CMD_OK:
4519
4520 /* Check if Place call is a wait command or a
4521 * no wait command */
4522 if (atomic_read(&chan->common.command) & 0x80)
4523 delay=RETURN_RESULT;
4524 else
4525 delay=DELAY_RESULT;
4526
4527
4528 DBG_PRINTK(KERN_INFO "\n%s: PLACE CALL Binding dev %s to lcn %i\n",
4529 card->devname,dev->name, mbox->cmd.lcn);
4530
4531 bind_lcn_to_dev (card, dev, mbox->cmd.lcn);
4532 set_chan_state(dev, WAN_CONNECTING);
4533 break;
4534
4535
4536 default:
4537 delay=RETURN_RESULT;
4538 set_chan_state(dev, WAN_DISCONNECTED);
4539 break;
4540 }
4541 break;
4542
4543 case X25_ACCEPT_CALL:
4544
4545 switch (mbox->cmd.result){
4546
4547 case CMD_OK:
4548
4549 DBG_PRINTK(KERN_INFO "\n%s: ACCEPT Binding dev %s to lcn %i\n",
4550 card->devname,dev->name,mbox->cmd.lcn);
4551
4552 bind_lcn_to_dev (card, dev, mbox->cmd.lcn);
4553
4554 if (x25_get_chan_conf(card, chan) == CMD_OK){
4555
4556 set_chan_state(dev, WAN_CONNECTED);
4557 delay=RETURN_RESULT;
4558
4559 }else{
4560 if (x25_clear_call(card, usr_cmd->cmd.lcn, 0, 0) == CMD_OK){
4561 /* if clear is successful, wait for clear confirm
4562 */
4563 delay=DELAY_RESULT;
4564 }else{
4565 /* Do not change the state here. If we fail
4566 * the accept the return code is send up
4567 *the stack, which will ether retry
4568 * or clear the call
4569 */
4570 DBG_PRINTK(KERN_INFO
4571 "%s: ACCEPT: STATE MAY BE CURRUPTED 2 !!!!!\n",
4572 card->devname);
4573 delay=RETURN_RESULT;
4574 }
4575 }
4576 break;
4577
4578
4579 case X25RES_ASYNC_PACKET:
4580 delay=TRY_CMD_AGAIN;
4581 break;
4582
4583 default:
4584 DBG_PRINTK(KERN_INFO "%s: ACCEPT FAILED\n",card->devname);
4585 if (x25_clear_call(card, usr_cmd->cmd.lcn, 0, 0) == CMD_OK){
4586 delay=DELAY_RESULT;
4587 }else{
4588 /* Do not change the state here. If we fail the accept. The
4589 * return code is send up the stack, which will ether retry
4590 * or clear the call */
4591 DBG_PRINTK(KERN_INFO
4592 "%s: ACCEPT: STATE MAY BE CORRUPTED 1 !!!!!\n",
4593 card->devname);
4594 delay=RETURN_RESULT;
4595 }
4596 }
4597 break;
4598
4599 case X25_CLEAR_CALL:
4600
4601 switch (mbox->cmd.result){
4602
4603 case CMD_OK:
4604 DBG_PRINTK(KERN_INFO
4605 "CALL CLEAR OK: Dev %s Mbox Lcn %i Chan Lcn %i\n",
4606 dev->name,mbox->cmd.lcn,chan->common.lcn);
4607 set_chan_state(dev, WAN_DISCONNECTING);
4608 delay = DELAY_RESULT;
4609 break;
4610
4611 case X25RES_CHANNEL_IN_USE:
4612 case X25RES_ASYNC_PACKET:
4613 delay = TRY_CMD_AGAIN;
4614 break;
4615
4616 case X25RES_LINK_NOT_IN_ABM:
4617 case X25RES_INVAL_LCN:
4618 case X25RES_INVAL_STATE:
4619 set_chan_state(dev, WAN_DISCONNECTED);
4620 delay = RETURN_RESULT;
4621 break;
4622
4623 default:
4624 /* If command did not execute because of user
4625 * fault, do not change the state. This will
4626 * signal the socket that clear command failed.
4627 * User can retry or close the socket.
4628 * When socket gets killed, it will set the
4629 * chan->disconnect which will signal
4630 * driver to clear the call */
4631 printk(KERN_INFO "%s: Clear Command Failed, Rc %x\n",
4632 card->devname,mbox->cmd.command);
4633 delay = RETURN_RESULT;
4634 }
4635 break;
4636 }
4637
4638 return delay;
4639}
4640
4641/*===============================================================
4642 * api_incoming_call
4643 *
4644 * Pass an incoming call request up the listening
4645 * sock. If the API sock is not listening reject the
4646 * call.
4647 *
4648 *===============================================================*/
4649
4650static int api_incoming_call (sdla_t* card, TX25Mbox *mbox, int lcn)
4651{
4652 struct sk_buff *skb;
4653 int len = sizeof(TX25Cmd)+mbox->cmd.length;
4654
4655 if (alloc_and_init_skb_buf(card, &skb, len)){
4656 printk(KERN_INFO "%s: API incoming call, no memory\n",card->devname);
4657 return 1;
4658 }
4659
4660 memcpy(skb_put(skb,len),&mbox->cmd,len);
4661
4662 skb->mac.raw = skb->data;
4663 skb->protocol = htons(X25_PROT);
4664 skb->pkt_type = WAN_PACKET_ASYNC;
4665
4666 if (card->func(skb,card->sk) < 0){
4667 printk(KERN_INFO "%s: MAJOR ERROR: Failed to send up place call \n",card->devname);
4668 dev_kfree_skb_any(skb);
4669 return 1;
4670 }
4671
4672 return 0;
4673}
4674
4675/*===============================================================
4676 * send_delayed_cmd_result
4677 *
4678 * Wait commands like PLEACE CALL or CLEAR CALL must wait
4679 * until the result arrives. This function passes
4680 * the result to a waiting sock.
4681 *
4682 *===============================================================*/
4683static void send_delayed_cmd_result(sdla_t *card, struct net_device *dev,
4684 TX25Mbox* mbox)
4685{
4686 x25_channel_t *chan = dev->priv;
4687 mbox_cmd_t *usr_cmd = (mbox_cmd_t *)chan->common.mbox;
4688 struct sk_buff *skb;
4689 int len=sizeof(unsigned char);
4690
4691 atomic_set(&chan->common.command,0);
4692
4693 /* If the sock is in the process of unlinking the
4694 * driver from the socket, we must get out.
4695 * This never happends but is a sanity check. */
4696 if (test_bit(0,&chan->common.common_critical)){
4697 return;
4698 }
4699
4700 if (!usr_cmd || !chan->common.sk || !chan->common.func){
4701 DBG_PRINTK(KERN_INFO "Delay result: Sock not bounded sk: %u, func: %u, mbox: %u\n",
4702 (unsigned int)chan->common.sk,
4703 (unsigned int)chan->common.func,
4704 (unsigned int)usr_cmd);
4705 return;
4706 }
4707
4708 memcpy(&usr_cmd->cmd, &mbox->cmd, sizeof(TX25Cmd));
4709 if (mbox->cmd.length > 0){
4710 memcpy(usr_cmd->data, mbox->data, mbox->cmd.length);
4711 }
4712
4713 if (alloc_and_init_skb_buf(card,&skb,len)){
4714 printk(KERN_INFO "Delay result: No sock buffers\n");
4715 return;
4716 }
4717
4718 memcpy(skb_put(skb,len),&mbox->cmd.command,len);
4719
4720 skb->mac.raw = skb->data;
4721 skb->pkt_type = WAN_PACKET_CMD;
4722
4723 chan->common.func(skb,dev,chan->common.sk);
4724}
4725
4726/*===============================================================
4727 * clear_confirm_event
4728 *
4729 * Pass the clear confirmation event up the sock. The
4730 * API will disconnect only after the clear confirmation
4731 * has been received.
4732 *
4733 * Depending on the state, clear confirmation could
4734 * be an OOB event, or a result of an API command.
4735 *===============================================================*/
4736
4737static int clear_confirm_event (sdla_t *card, TX25Mbox* mb)
4738{
4739 struct net_device *dev;
4740 x25_channel_t *chan;
4741 unsigned char old_state;
4742
4743 dev = find_channel(card,mb->cmd.lcn);
4744 if (!dev){
4745 DBG_PRINTK(KERN_INFO "%s: *** GOT CLEAR BUT NO DEV %i\n",
4746 card->devname,mb->cmd.lcn);
4747 return 0;
4748 }
4749
4750 chan=dev->priv;
4751 DBG_PRINTK(KERN_INFO "%s: GOT CLEAR CONFIRM %s: Mbox lcn %i Chan lcn %i\n",
4752 card->devname, dev->name, mb->cmd.lcn, chan->common.lcn);
4753
4754 /* If not API fall through to default.
4755 * If API, send the result to a waiting
4756 * socket.
4757 */
4758
4759 old_state = chan->common.state;
4760 set_chan_state(dev, WAN_DISCONNECTED);
4761
4762 if (chan->common.usedby == API){
4763 switch (old_state) {
4764
4765 case WAN_DISCONNECTING:
4766 case WAN_CONNECTING:
4767 send_delayed_cmd_result(card,dev,mb);
4768 break;
4769 case WAN_CONNECTED:
4770 send_oob_msg(card,dev,mb);
4771 break;
4772 }
4773 return 1;
4774 }
4775
4776 return 0;
4777}
4778
4779/*===============================================================
4780 * send_oob_msg
4781 *
4782 * Construct an NEM Message and pass it up the connected
4783 * sock. If the sock is not bounded discard the NEM.
4784 *
4785 *===============================================================*/
4786
4787static void send_oob_msg(sdla_t *card, struct net_device *dev, TX25Mbox *mbox)
4788{
4789 x25_channel_t *chan = dev->priv;
4790 mbox_cmd_t *usr_cmd = (mbox_cmd_t *)chan->common.mbox;
4791 struct sk_buff *skb;
4792 int len=sizeof(x25api_hdr_t)+mbox->cmd.length;
4793 x25api_t *api_hdr;
4794
4795 /* If the sock is in the process of unlinking the
4796 * driver from the socket, we must get out.
4797 * This never happends but is a sanity check. */
4798 if (test_bit(0,&chan->common.common_critical)){
4799 return;
4800 }
4801
4802 if (!usr_cmd || !chan->common.sk || !chan->common.func){
4803 DBG_PRINTK(KERN_INFO "OOB MSG: Sock not bounded\n");
4804 return;
4805 }
4806
4807 memcpy(&usr_cmd->cmd, &mbox->cmd, sizeof(TX25Cmd));
4808 if (mbox->cmd.length > 0){
4809 memcpy(usr_cmd->data, mbox->data, mbox->cmd.length);
4810 }
4811
4812 if (alloc_and_init_skb_buf(card,&skb,len)){
4813 printk(KERN_INFO "%s: OOB MSG: No sock buffers\n",card->devname);
4814 return;
4815 }
4816
4817 api_hdr = (x25api_t*)skb_put(skb,len);
4818 api_hdr->hdr.pktType = mbox->cmd.pktType & 0x7F;
4819 api_hdr->hdr.qdm = mbox->cmd.qdm;
4820 api_hdr->hdr.cause = mbox->cmd.cause;
4821 api_hdr->hdr.diagn = mbox->cmd.diagn;
4822 api_hdr->hdr.length = mbox->cmd.length;
4823 api_hdr->hdr.result = mbox->cmd.result;
4824 api_hdr->hdr.lcn = mbox->cmd.lcn;
4825
4826 if (mbox->cmd.length > 0){
4827 memcpy(api_hdr->data,mbox->data,mbox->cmd.length);
4828 }
4829
4830 skb->mac.raw = skb->data;
4831 skb->pkt_type = WAN_PACKET_ERR;
4832
4833 if (chan->common.func(skb,dev,chan->common.sk) < 0){
4834 if (bh_enqueue(dev,skb)){
4835 printk(KERN_INFO "%s: Dropping OOB MSG\n",card->devname);
4836 dev_kfree_skb_any(skb);
4837 }
4838 }
4839
4840 DBG_PRINTK(KERN_INFO "%s: OOB MSG OK, %s, lcn %i\n",
4841 card->devname, dev->name, mbox->cmd.lcn);
4842}
4843
4844/*===============================================================
4845 * alloc_and_init_skb_buf
4846 *
4847 * Allocate and initialize an skb buffer.
4848 *
4849 *===============================================================*/
4850
4851static int alloc_and_init_skb_buf (sdla_t *card, struct sk_buff **skb, int len)
4852{
4853 struct sk_buff *new_skb = *skb;
4854
4855 new_skb = dev_alloc_skb(len + X25_HRDHDR_SZ);
4856 if (new_skb == NULL){
4857 printk(KERN_INFO "%s: no socket buffers available!\n",
4858 card->devname);
4859 return 1;
4860 }
4861
4862 if (skb_tailroom(new_skb) < len){
4863 /* No room for the packet. Call off the whole thing! */
4864 dev_kfree_skb_any(new_skb);
4865 printk(KERN_INFO "%s: Listen: unexpectedly long packet sequence\n"
4866 ,card->devname);
4867 *skb = NULL;
4868 return 1;
4869 }
4870
4871 *skb = new_skb;
4872 return 0;
4873
4874}
4875
4876/*===============================================================
4877 * api_oob_event
4878 *
4879 * Send an OOB event up to the sock
4880 *
4881 *===============================================================*/
4882
4883static void api_oob_event (sdla_t *card,TX25Mbox *mbox)
4884{
4885 struct net_device *dev = find_channel(card, mbox->cmd.lcn);
4886 x25_channel_t *chan;
4887
4888 if (!dev)
4889 return;
4890
4891 chan=dev->priv;
4892
4893 if (chan->common.usedby == API)
4894 send_oob_msg(card,dev,mbox);
4895
4896}
4897
4898
4899
4900
4901static int channel_disconnect(sdla_t* card, struct net_device *dev)
4902{
4903
4904 int err;
4905 x25_channel_t *chan = dev->priv;
4906
4907 DBG_PRINTK(KERN_INFO "%s: TIMER: %s, Device down disconnecting\n",
4908 card->devname,dev->name);
4909
4910 if (chan->common.svc){
4911 err = x25_clear_call(card,chan->common.lcn,0,0);
4912 }else{
4913 /* If channel is PVC or LAPB HDLC, there is no call
4914 * to be cleared, thus drop down to the default
4915 * area
4916 */
4917 err = 1;
4918 }
4919
4920 switch (err){
4921
4922 case X25RES_CHANNEL_IN_USE:
4923 case X25RES_NOT_READY:
4924 err = TRY_CMD_AGAIN;
4925 break;
4926 case CMD_OK:
4927 DBG_PRINTK(KERN_INFO "CALL CLEAR OK: Dev %s Chan Lcn %i\n",
4928 dev->name,chan->common.lcn);
4929
4930 set_chan_state(dev,WAN_DISCONNECTING);
4931 atomic_set(&chan->common.command,0);
4932 err = DELAY_RESULT;
4933 break;
4934 default:
4935 /* If LAPB HDLC protocol, bring the whole link down
4936 * once the application terminates
4937 */
4938
4939 set_chan_state(dev,WAN_DISCONNECTED);
4940
4941 if (card->u.x.LAPB_hdlc){
4942 DBG_PRINTK(KERN_INFO "LAPB: Disconnecting Link\n");
4943 hdlc_link_down (card);
4944 }
4945 atomic_set(&chan->common.command,0);
4946 err = RETURN_RESULT;
4947 break;
4948 }
4949
4950 return err;
4951}
4952
4953static void hdlc_link_down (sdla_t *card)
4954{
4955 TX25Mbox* mbox = card->mbox;
4956 int retry = 5;
4957 int err=0;
4958
4959 do {
4960 memset(mbox,0,sizeof(TX25Mbox));
4961 mbox->cmd.command = X25_HDLC_LINK_DISC;
4962 mbox->cmd.length = 1;
4963 mbox->data[0]=0;
4964 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
4965
4966 } while (err && retry-- && x25_error(card, err, X25_HDLC_LINK_DISC, 0));
4967
4968 if (err)
4969 printk(KERN_INFO "%s: Hdlc Link Down Failed %x\n",card->devname,err);
4970
4971 disconnect (card);
4972
4973}
4974
4975static int check_bad_command(sdla_t* card, struct net_device *dev)
4976{
4977 x25_channel_t *chan = dev->priv;
4978 int bad_cmd = 0;
4979
4980 switch (atomic_read(&chan->common.command)&0x7F){
4981
4982 case X25_PLACE_CALL:
4983 if (chan->common.state != WAN_DISCONNECTED)
4984 bad_cmd=1;
4985 break;
4986 case X25_CLEAR_CALL:
4987 if (chan->common.state == WAN_DISCONNECTED)
4988 bad_cmd=1;
4989 break;
4990 case X25_ACCEPT_CALL:
4991 if (chan->common.state != WAN_CONNECTING)
4992 bad_cmd=1;
4993 break;
4994 case X25_RESET:
4995 if (chan->common.state != WAN_CONNECTED)
4996 bad_cmd=1;
4997 break;
4998 default:
4999 bad_cmd=1;
5000 break;
5001 }
5002
5003 if (bad_cmd){
5004 printk(KERN_INFO "%s: Invalid State, BAD Command %x, dev %s, lcn %i, st %i\n",
5005 card->devname,atomic_read(&chan->common.command),dev->name,
5006 chan->common.lcn, chan->common.state);
5007 }
5008
5009 return bad_cmd;
5010}
5011
5012
5013
5014/*************************** XPIPEMON FUNCTIONS **************************/
5015
5016/*==============================================================================
5017 * Process UDP call of type XPIPE
5018 */
5019
5020static int process_udp_mgmt_pkt(sdla_t *card)
5021{
5022 int c_retry = MAX_CMD_RETRY;
5023 unsigned int len;
5024 struct sk_buff *new_skb;
5025 TX25Mbox *mbox = card->mbox;
5026 int err;
5027 int udp_mgmt_req_valid = 1;
5028 struct net_device *dev;
5029 x25_channel_t *chan;
5030 unsigned short lcn;
5031 struct timeval tv;
5032
5033
5034 x25_udp_pkt_t *x25_udp_pkt;
5035 x25_udp_pkt = (x25_udp_pkt_t *)card->u.x.udp_pkt_data;
5036
5037 dev = card->u.x.udp_dev;
5038 chan = dev->priv;
5039 lcn = chan->common.lcn;
5040
5041 switch(x25_udp_pkt->cblock.command) {
5042
5043 /* XPIPE_ENABLE_TRACE */
5044 case XPIPE_ENABLE_TRACING:
5045
5046 /* XPIPE_GET_TRACE_INFO */
5047 case XPIPE_GET_TRACE_INFO:
5048
5049 /* SET FT1 MODE */
5050 case XPIPE_SET_FT1_MODE:
5051
5052 if(card->u.x.udp_pkt_src == UDP_PKT_FRM_NETWORK) {
5053 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_direction_err;
5054 udp_mgmt_req_valid = 0;
5055 break;
5056 }
5057
5058 /* XPIPE_FT1_READ_STATUS */
5059 case XPIPE_FT1_READ_STATUS:
5060
5061 /* FT1 MONITOR STATUS */
5062 case XPIPE_FT1_STATUS_CTRL:
5063 if(card->hw.fwid != SFID_X25_508) {
5064 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_type_err;
5065 udp_mgmt_req_valid = 0;
5066 break;
5067 }
5068 default:
5069 break;
5070 }
5071
5072 if(!udp_mgmt_req_valid) {
5073 /* set length to 0 */
5074 x25_udp_pkt->cblock.length = 0;
5075 /* set return code */
5076 x25_udp_pkt->cblock.result = (card->hw.fwid != SFID_X25_508) ? 0x1F : 0xCD;
5077
5078 } else {
5079
5080 switch (x25_udp_pkt->cblock.command) {
5081
5082
5083 case XPIPE_FLUSH_DRIVER_STATS:
5084 init_x25_channel_struct(chan);
5085 init_global_statistics(card);
5086 mbox->cmd.length = 0;
5087 break;
5088
5089
5090 case XPIPE_DRIVER_STAT_IFSEND:
5091 memcpy(x25_udp_pkt->data, &chan->if_send_stat, sizeof(if_send_stat_t));
5092 mbox->cmd.length = sizeof(if_send_stat_t);
5093 x25_udp_pkt->cblock.length = mbox->cmd.length;
5094 break;
5095
5096 case XPIPE_DRIVER_STAT_INTR:
5097 memcpy(&x25_udp_pkt->data[0], &card->statistics, sizeof(global_stats_t));
5098 memcpy(&x25_udp_pkt->data[sizeof(global_stats_t)],
5099 &chan->rx_intr_stat, sizeof(rx_intr_stat_t));
5100
5101 mbox->cmd.length = sizeof(global_stats_t) +
5102 sizeof(rx_intr_stat_t);
5103 x25_udp_pkt->cblock.length = mbox->cmd.length;
5104 break;
5105
5106 case XPIPE_DRIVER_STAT_GEN:
5107 memcpy(x25_udp_pkt->data,
5108 &chan->pipe_mgmt_stat.UDP_PIPE_mgmt_kmalloc_err,
5109 sizeof(pipe_mgmt_stat_t));
5110
5111 memcpy(&x25_udp_pkt->data[sizeof(pipe_mgmt_stat_t)],
5112 &card->statistics, sizeof(global_stats_t));
5113
5114 x25_udp_pkt->cblock.result = 0;
5115 x25_udp_pkt->cblock.length = sizeof(global_stats_t)+
5116 sizeof(rx_intr_stat_t);
5117 mbox->cmd.length = x25_udp_pkt->cblock.length;
5118 break;
5119
5120 case XPIPE_ROUTER_UP_TIME:
5121 do_gettimeofday(&tv);
5122 chan->router_up_time = tv.tv_sec - chan->router_start_time;
5123 *(unsigned long *)&x25_udp_pkt->data = chan->router_up_time;
5124 x25_udp_pkt->cblock.length = mbox->cmd.length = 4;
5125 x25_udp_pkt->cblock.result = 0;
5126 break;
5127
5128 default :
5129
5130 do {
5131 memcpy(&mbox->cmd, &x25_udp_pkt->cblock.command, sizeof(TX25Cmd));
5132 if(mbox->cmd.length){
5133 memcpy(&mbox->data,
5134 (char *)x25_udp_pkt->data,
5135 mbox->cmd.length);
5136 }
5137
5138 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
5139 } while (err && c_retry-- && x25_error(card, err, mbox->cmd.command, 0));
5140
5141
5142 if ( err == CMD_OK ||
5143 (err == 1 &&
5144 (mbox->cmd.command == 0x06 ||
5145 mbox->cmd.command == 0x16) ) ){
5146
5147 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_cmnd_OK;
5148 } else {
5149 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_cmnd_timeout;
5150 }
5151
5152 /* copy the result back to our buffer */
5153 memcpy(&x25_udp_pkt->cblock.command, &mbox->cmd, sizeof(TX25Cmd));
5154
5155 if(mbox->cmd.length) {
5156 memcpy(&x25_udp_pkt->data, &mbox->data, mbox->cmd.length);
5157 }
5158 break;
5159
5160 } //switch
5161
5162 }
5163
5164 /* Fill UDP TTL */
5165
5166 x25_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
5167 len = reply_udp(card->u.x.udp_pkt_data, mbox->cmd.length);
5168
5169
5170 if(card->u.x.udp_pkt_src == UDP_PKT_FRM_NETWORK) {
5171
5172 err = x25_send(card, lcn, 0, len, card->u.x.udp_pkt_data);
5173 if (!err)
5174 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_send_passed;
5175 else
5176 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_adptr_send_failed;
5177
5178 } else {
5179
5180 /* Allocate socket buffer */
5181 if((new_skb = dev_alloc_skb(len)) != NULL) {
5182 void *buf;
5183
5184 /* copy data into new_skb */
5185 buf = skb_put(new_skb, len);
5186 memcpy(buf, card->u.x.udp_pkt_data, len);
5187
5188 /* Decapsulate packet and pass it up the protocol
5189 stack */
5190 new_skb->dev = dev;
5191
5192 if (chan->common.usedby == API)
5193 new_skb->protocol = htons(X25_PROT);
5194 else
5195 new_skb->protocol = htons(ETH_P_IP);
5196
5197 new_skb->mac.raw = new_skb->data;
5198
5199 netif_rx(new_skb);
5200 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_passed_to_stack;
5201
5202 } else {
5203 ++chan->pipe_mgmt_stat.UDP_PIPE_mgmt_no_socket;
5204 printk(KERN_INFO
5205 "%s: UDP mgmt cmnd, no socket buffers available!\n",
5206 card->devname);
5207 }
5208 }
5209
5210 card->u.x.udp_pkt_lgth = 0;
5211
5212 return 1;
5213}
5214
5215
5216/*==============================================================================
5217 * Determine what type of UDP call it is. DRVSTATS or XPIPE8ND ?
5218 */
5219static int udp_pkt_type( struct sk_buff *skb, sdla_t* card )
5220{
5221 x25_udp_pkt_t *x25_udp_pkt = (x25_udp_pkt_t *)skb->data;
5222
5223 if((x25_udp_pkt->ip_pkt.protocol == UDPMGMT_UDP_PROTOCOL) &&
5224 (x25_udp_pkt->ip_pkt.ver_inet_hdr_length == 0x45) &&
5225 (x25_udp_pkt->udp_pkt.udp_dst_port == ntohs(card->wandev.udp_port)) &&
5226 (x25_udp_pkt->wp_mgmt.request_reply == UDPMGMT_REQUEST)) {
5227
5228 if(!strncmp(x25_udp_pkt->wp_mgmt.signature,
5229 UDPMGMT_XPIPE_SIGNATURE, 8)){
5230 return UDP_XPIPE_TYPE;
5231 }else{
5232 printk(KERN_INFO "%s: UDP Packet, Failed Signature !\n",
5233 card->devname);
5234 }
5235 }
5236
5237 return UDP_INVALID_TYPE;
5238}
5239
5240
5241/*============================================================================
5242 * Reply to UDP Management system.
5243 * Return nothing.
5244 */
5245static int reply_udp( unsigned char *data, unsigned int mbox_len )
5246{
5247 unsigned short len, udp_length, temp, ip_length;
5248 unsigned long ip_temp;
5249 int even_bound = 0;
5250
5251
5252 x25_udp_pkt_t *x25_udp_pkt = (x25_udp_pkt_t *)data;
5253
5254 /* Set length of packet */
5255 len = sizeof(ip_pkt_t)+
5256 sizeof(udp_pkt_t)+
5257 sizeof(wp_mgmt_t)+
5258 sizeof(cblock_t)+
5259 mbox_len;
5260
5261
5262 /* fill in UDP reply */
5263 x25_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
5264
5265 /* fill in UDP length */
5266 udp_length = sizeof(udp_pkt_t)+
5267 sizeof(wp_mgmt_t)+
5268 sizeof(cblock_t)+
5269 mbox_len;
5270
5271
5272 /* put it on an even boundary */
5273 if ( udp_length & 0x0001 ) {
5274 udp_length += 1;
5275 len += 1;
5276 even_bound = 1;
5277 }
5278
5279 temp = (udp_length<<8)|(udp_length>>8);
5280 x25_udp_pkt->udp_pkt.udp_length = temp;
5281
5282 /* swap UDP ports */
5283 temp = x25_udp_pkt->udp_pkt.udp_src_port;
5284 x25_udp_pkt->udp_pkt.udp_src_port =
5285 x25_udp_pkt->udp_pkt.udp_dst_port;
5286 x25_udp_pkt->udp_pkt.udp_dst_port = temp;
5287
5288
5289
5290 /* add UDP pseudo header */
5291 temp = 0x1100;
5292 *((unsigned short *)
5293 (x25_udp_pkt->data+mbox_len+even_bound)) = temp;
5294 temp = (udp_length<<8)|(udp_length>>8);
5295 *((unsigned short *)
5296 (x25_udp_pkt->data+mbox_len+even_bound+2)) = temp;
5297
5298 /* calculate UDP checksum */
5299 x25_udp_pkt->udp_pkt.udp_checksum = 0;
5300
5301 x25_udp_pkt->udp_pkt.udp_checksum =
5302 calc_checksum(&data[UDP_OFFSET], udp_length+UDP_OFFSET);
5303
5304 /* fill in IP length */
5305 ip_length = len;
5306 temp = (ip_length<<8)|(ip_length>>8);
5307 x25_udp_pkt->ip_pkt.total_length = temp;
5308
5309 /* swap IP addresses */
5310 ip_temp = x25_udp_pkt->ip_pkt.ip_src_address;
5311 x25_udp_pkt->ip_pkt.ip_src_address =
5312 x25_udp_pkt->ip_pkt.ip_dst_address;
5313 x25_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
5314
5315
5316 /* fill in IP checksum */
5317 x25_udp_pkt->ip_pkt.hdr_checksum = 0;
5318 x25_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data, sizeof(ip_pkt_t));
5319
5320 return len;
5321} /* reply_udp */
5322
5323unsigned short calc_checksum (char *data, int len)
5324{
5325 unsigned short temp;
5326 unsigned long sum=0;
5327 int i;
5328
5329 for( i = 0; i <len; i+=2 ) {
5330 memcpy(&temp,&data[i],2);
5331 sum += (unsigned long)temp;
5332 }
5333
5334 while (sum >> 16 ) {
5335 sum = (sum & 0xffffUL) + (sum >> 16);
5336 }
5337
5338 temp = (unsigned short)sum;
5339 temp = ~temp;
5340
5341 if( temp == 0 )
5342 temp = 0xffff;
5343
5344 return temp;
5345}
5346
5347/*=============================================================================
5348 * Store a UDP management packet for later processing.
5349 */
5350
5351static int store_udp_mgmt_pkt(int udp_type, char udp_pkt_src, sdla_t* card,
5352 struct net_device *dev, struct sk_buff *skb,
5353 int lcn)
5354{
5355 int udp_pkt_stored = 0;
5356
5357 if(!card->u.x.udp_pkt_lgth && (skb->len <= MAX_LGTH_UDP_MGNT_PKT)){
5358 card->u.x.udp_pkt_lgth = skb->len;
5359 card->u.x.udp_type = udp_type;
5360 card->u.x.udp_pkt_src = udp_pkt_src;
5361 card->u.x.udp_lcn = lcn;
5362 card->u.x.udp_dev = dev;
5363 memcpy(card->u.x.udp_pkt_data, skb->data, skb->len);
5364 card->u.x.timer_int_enabled |= TMR_INT_ENABLED_UDP_PKT;
5365 udp_pkt_stored = 1;
5366
5367 }else{
5368 printk(KERN_INFO "%s: ERROR: UDP packet not stored for LCN %d\n",
5369 card->devname,lcn);
5370 }
5371
5372 if(udp_pkt_src == UDP_PKT_FRM_STACK){
5373 dev_kfree_skb_any(skb);
5374 }else{
5375 dev_kfree_skb_any(skb);
5376 }
5377
5378 return(udp_pkt_stored);
5379}
5380
5381
5382
5383/*=============================================================================
5384 * Initial the ppp_private_area structure.
5385 */
5386static void init_x25_channel_struct( x25_channel_t *chan )
5387{
5388 memset(&chan->if_send_stat.if_send_entry,0,sizeof(if_send_stat_t));
5389 memset(&chan->rx_intr_stat.rx_intr_no_socket,0,sizeof(rx_intr_stat_t));
5390 memset(&chan->pipe_mgmt_stat.UDP_PIPE_mgmt_kmalloc_err,0,sizeof(pipe_mgmt_stat_t));
5391}
5392
5393/*============================================================================
5394 * Initialize Global Statistics
5395 */
5396static void init_global_statistics( sdla_t *card )
5397{
5398 memset(&card->statistics.isr_entry,0,sizeof(global_stats_t));
5399}
5400
5401
5402/*===============================================================
5403 * SMP Support
5404 * ==============================================================*/
5405
5406static void S508_S514_lock(sdla_t *card, unsigned long *smp_flags)
5407{
5408 spin_lock_irqsave(&card->wandev.lock, *smp_flags);
5409}
5410static void S508_S514_unlock(sdla_t *card, unsigned long *smp_flags)
5411{
5412 spin_unlock_irqrestore(&card->wandev.lock, *smp_flags);
5413}
5414
5415/*===============================================================
5416 * x25_timer_routine
5417 *
5418 * A more efficient polling routine. Each half a second
5419 * queue a polling task. We want to do the polling in a
5420 * task not timer, because timer runs in interrupt time.
5421 *
5422 * FIXME Polling should be rethinked.
5423 *==============================================================*/
5424
5425static void x25_timer_routine(unsigned long data)
5426{
5427 sdla_t *card = (sdla_t*)data;
5428
5429 if (!card->wandev.dev){
5430 printk(KERN_INFO "%s: Stopping the X25 Poll Timer: No Dev.\n",
5431 card->devname);
5432 return;
5433 }
5434
5435 if (card->open_cnt != card->u.x.num_of_ch){
5436 printk(KERN_INFO "%s: Stopping the X25 Poll Timer: Interface down.\n",
5437 card->devname);
5438 return;
5439 }
5440
5441 if (test_bit(PERI_CRIT,&card->wandev.critical)){
5442 printk(KERN_INFO "%s: Stopping the X25 Poll Timer: Shutting down.\n",
5443 card->devname);
5444 return;
5445 }
5446
5447 if (!test_and_set_bit(POLL_CRIT,&card->wandev.critical)){
5448 trigger_x25_poll(card);
5449 }
5450
5451 card->u.x.x25_timer.expires=jiffies+(HZ>>1);
5452 add_timer(&card->u.x.x25_timer);
5453 return;
5454}
5455
5456void disable_comm_shutdown(sdla_t *card)
5457{
5458 TX25Mbox* mbox = card->mbox;
5459 int err;
5460
5461 /* Turn of interrutps */
5462 mbox->data[0] = 0;
5463 if (card->hw.fwid == SFID_X25_508){
5464 mbox->data[1] = card->hw.irq;
5465 mbox->data[2] = 2;
5466 mbox->cmd.length = 3;
5467 }else {
5468 mbox->cmd.length = 1;
5469 }
5470 mbox->cmd.command = X25_SET_INTERRUPT_MODE;
5471 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
5472 if (err)
5473 printk(KERN_INFO "INTERRUPT OFF FAIED %x\n",err);
5474
5475 /* Bring down HDLC */
5476 mbox->cmd.command = X25_HDLC_LINK_CLOSE;
5477 mbox->cmd.length = 0;
5478 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
5479 if (err)
5480 printk(KERN_INFO "LINK CLOSED FAILED %x\n",err);
5481
5482
5483 /* Brind down DTR */
5484 mbox->data[0] = 0;
5485 mbox->data[2] = 0;
5486 mbox->data[1] = 0x01;
5487 mbox->cmd.length = 3;
5488 mbox->cmd.command = X25_SET_GLOBAL_VARS;
5489 err = sdla_exec(mbox) ? mbox->cmd.result : CMD_TIMEOUT;
5490 if (err)
5491 printk(KERN_INFO "DTR DOWN FAILED %x\n",err);
5492
5493}
5494
5495MODULE_LICENSE("GPL");
5496
5497/****** End *****************************************************************/
diff --git a/drivers/net/wan/sdladrv.c b/drivers/net/wan/sdladrv.c
deleted file mode 100644
index 032c0f81928e..000000000000
--- a/drivers/net/wan/sdladrv.c
+++ /dev/null
@@ -1,2314 +0,0 @@
1/*****************************************************************************
2* sdladrv.c SDLA Support Module. Main module.
3*
4* This module is a library of common hardware-specific functions
5* used by all Sangoma drivers.
6*
7* Author: Gideon Hack
8*
9* Copyright: (c) 1995-2000 Sangoma Technologies Inc.
10*
11* This program is free software; you can redistribute it and/or
12* modify it under the terms of the GNU General Public License
13* as published by the Free Software Foundation; either version
14* 2 of the License, or (at your option) any later version.
15* ============================================================================
16* Mar 20, 2001 Nenad Corbic Added the auto_pci_cfg filed, to support
17* the PCISLOT #0.
18* Apr 04, 2000 Nenad Corbic Fixed the auto memory detection code.
19* The memory test at address 0xC8000.
20* Mar 09, 2000 Nenad Corbic Added Gideon's Bug Fix: clear pci
21* interrupt flags on initial load.
22* Jun 02, 1999 Gideon Hack Added support for the S514 adapter.
23* Updates for Linux 2.2.X kernels.
24* Sep 17, 1998 Jaspreet Singh Updates for linux 2.2.X kernels
25* Dec 20, 1996 Gene Kozin Version 3.0.0. Complete overhaul.
26* Jul 12, 1996 Gene Kozin Changes for Linux 2.0 compatibility.
27* Jun 12, 1996 Gene Kozin Added support for S503 card.
28* Apr 30, 1996 Gene Kozin SDLA hardware interrupt is acknowledged before
29* calling protocolspecific ISR.
30* Register I/O ports with Linux kernel.
31* Miscellaneous bug fixes.
32* Dec 20, 1995 Gene Kozin Fixed a bug in interrupt routine.
33* Oct 14, 1995 Gene Kozin Initial version.
34*****************************************************************************/
35
36/*****************************************************************************
37 * Notes:
38 * ------
39 * 1. This code is ment to be system-independent (as much as possible). To
40 * achive this, various macros are used to hide system-specific interfaces.
41 * To compile this code, one of the following constants must be defined:
42 *
43 * Platform Define
44 * -------- ------
45 * Linux _LINUX_
46 * SCO Unix _SCO_UNIX_
47 *
48 * 2. Supported adapter types:
49 *
50 * S502A
51 * ES502A (S502E)
52 * S503
53 * S507
54 * S508 (S509)
55 *
56 * 3. S502A Notes:
57 *
58 * There is no separate DPM window enable/disable control in S502A. It
59 * opens immediately after a window number it written to the HMCR
60 * register. To close the window, HMCR has to be written a value
61 * ????1111b (e.g. 0x0F or 0xFF).
62 *
63 * S502A DPM window cannot be located at offset E000 (e.g. 0xAE000).
64 *
65 * There should be a delay of ??? before reading back S502A status
66 * register.
67 *
68 * 4. S502E Notes:
69 *
70 * S502E has a h/w bug: although default IRQ line state is HIGH, enabling
71 * interrupts by setting bit 1 of the control register (BASE) to '1'
72 * causes it to go LOW! Therefore, disabling interrupts by setting that
73 * bit to '0' causes low-to-high transition on IRQ line (ghosty
74 * interrupt). The same occurs when disabling CPU by resetting bit 0 of
75 * CPU control register (BASE+3) - see the next note.
76 *
77 * S502E CPU and DPM control is limited:
78 *
79 * o CPU cannot be stopped independently. Resetting bit 0 of the CPUi
80 * control register (BASE+3) shuts the board down entirely, including
81 * DPM;
82 *
83 * o DPM access cannot be controlled dynamically. Ones CPU is started,
84 * bit 1 of the control register (BASE) is used to enable/disable IRQ,
85 * so that access to shared memory cannot be disabled while CPU is
86 * running.
87 ****************************************************************************/
88
89#define _LINUX_
90
91#if defined(_LINUX_) /****** Linux *******************************/
92
93#include <linux/config.h>
94#include <linux/kernel.h> /* printk(), and other useful stuff */
95#include <linux/stddef.h> /* offsetof(), etc. */
96#include <linux/errno.h> /* return codes */
97#include <linux/string.h> /* inline memset(), etc. */
98#include <linux/module.h> /* support for loadable modules */
99#include <linux/jiffies.h> /* for jiffies, HZ, etc. */
100#include <linux/sdladrv.h> /* API definitions */
101#include <linux/sdlasfm.h> /* SDLA firmware module definitions */
102#include <linux/sdlapci.h> /* SDLA PCI hardware definitions */
103#include <linux/pci.h> /* PCI defines and function prototypes */
104#include <asm/io.h> /* for inb(), outb(), etc. */
105
106#define _INB(port) (inb(port))
107#define _OUTB(port, byte) (outb((byte),(port)))
108#define SYSTEM_TICK jiffies
109
110#include <linux/init.h>
111
112
113#elif defined(_SCO_UNIX_) /****** SCO Unix ****************************/
114
115#if !defined(INKERNEL)
116#error This code MUST be compiled in kernel mode!
117#endif
118#include <sys/sdladrv.h> /* API definitions */
119#include <sys/sdlasfm.h> /* SDLA firmware module definitions */
120#include <sys/inline.h> /* for inb(), outb(), etc. */
121#define _INB(port) (inb(port))
122#define _OUTB(port, byte) (outb((port),(byte)))
123#define SYSTEM_TICK lbolt
124
125#else
126#error Unknown system type!
127#endif
128
129#define MOD_VERSION 3
130#define MOD_RELEASE 0
131
132#define SDLA_IODELAY 100 /* I/O Rd/Wr delay, 10 works for 486DX2-66 */
133#define EXEC_DELAY 20 /* shared memory access delay, mks */
134#define EXEC_TIMEOUT (HZ*2) /* command timeout, in ticks */
135
136/* I/O port address range */
137#define S502A_IORANGE 3
138#define S502E_IORANGE 4
139#define S503_IORANGE 3
140#define S507_IORANGE 4
141#define S508_IORANGE 4
142
143/* Maximum amount of memory */
144#define S502_MAXMEM 0x10000L
145#define S503_MAXMEM 0x10000L
146#define S507_MAXMEM 0x40000L
147#define S508_MAXMEM 0x40000L
148
149/* Minimum amount of memory */
150#define S502_MINMEM 0x8000L
151#define S503_MINMEM 0x8000L
152#define S507_MINMEM 0x20000L
153#define S508_MINMEM 0x20000L
154#define NO_PORT -1
155
156
157
158
159
160/****** Function Prototypes *************************************************/
161
162/* Hardware-specific functions */
163static int sdla_detect (sdlahw_t* hw);
164static int sdla_autodpm (sdlahw_t* hw);
165static int sdla_setdpm (sdlahw_t* hw);
166static int sdla_load (sdlahw_t* hw, sfm_t* sfm, unsigned len);
167static int sdla_init (sdlahw_t* hw);
168static unsigned long sdla_memtest (sdlahw_t* hw);
169static int sdla_bootcfg (sdlahw_t* hw, sfm_info_t* sfminfo);
170static unsigned char make_config_byte (sdlahw_t* hw);
171static int sdla_start (sdlahw_t* hw, unsigned addr);
172
173static int init_s502a (sdlahw_t* hw);
174static int init_s502e (sdlahw_t* hw);
175static int init_s503 (sdlahw_t* hw);
176static int init_s507 (sdlahw_t* hw);
177static int init_s508 (sdlahw_t* hw);
178
179static int detect_s502a (int port);
180static int detect_s502e (int port);
181static int detect_s503 (int port);
182static int detect_s507 (int port);
183static int detect_s508 (int port);
184static int detect_s514 (sdlahw_t* hw);
185static int find_s514_adapter(sdlahw_t* hw, char find_first_S514_card);
186
187/* Miscellaneous functions */
188static void peek_by_4 (unsigned long src, void* buf, unsigned len);
189static void poke_by_4 (unsigned long dest, void* buf, unsigned len);
190static int calibrate_delay (int mks);
191static int get_option_index (unsigned* optlist, unsigned optval);
192static unsigned check_memregion (void* ptr, unsigned len);
193static unsigned test_memregion (void* ptr, unsigned len);
194static unsigned short checksum (unsigned char* buf, unsigned len);
195static int init_pci_slot(sdlahw_t *);
196
197static int pci_probe(sdlahw_t *hw);
198
199/****** Global Data **********************************************************
200 * Note: All data must be explicitly initialized!!!
201 */
202
203static struct pci_device_id sdladrv_pci_tbl[] = {
204 { V3_VENDOR_ID, V3_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, },
205 { } /* Terminating entry */
206};
207MODULE_DEVICE_TABLE(pci, sdladrv_pci_tbl);
208
209MODULE_LICENSE("GPL");
210
211/* private data */
212static char modname[] = "sdladrv";
213static char fullname[] = "SDLA Support Module";
214static char copyright[] = "(c) 1995-1999 Sangoma Technologies Inc.";
215static unsigned exec_idle;
216
217/* Hardware configuration options.
218 * These are arrays of configuration options used by verification routines.
219 * The first element of each array is its size (i.e. number of options).
220 */
221static unsigned s502_port_options[] =
222 { 4, 0x250, 0x300, 0x350, 0x360 }
223;
224static unsigned s503_port_options[] =
225 { 8, 0x250, 0x254, 0x300, 0x304, 0x350, 0x354, 0x360, 0x364 }
226;
227static unsigned s508_port_options[] =
228 { 8, 0x250, 0x270, 0x280, 0x300, 0x350, 0x360, 0x380, 0x390 }
229;
230
231static unsigned s502a_irq_options[] = { 0 };
232static unsigned s502e_irq_options[] = { 4, 2, 3, 5, 7 };
233static unsigned s503_irq_options[] = { 5, 2, 3, 4, 5, 7 };
234static unsigned s508_irq_options[] = { 8, 3, 4, 5, 7, 10, 11, 12, 15 };
235
236static unsigned s502a_dpmbase_options[] =
237{
238 28,
239 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000,
240 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000,
241 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000,
242 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000,
243};
244static unsigned s507_dpmbase_options[] =
245{
246 32,
247 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
248 0xB0000, 0xB2000, 0xB4000, 0xB6000, 0xB8000, 0xBA000, 0xBC000, 0xBE000,
249 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
250 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000,
251};
252static unsigned s508_dpmbase_options[] = /* incl. S502E and S503 */
253{
254 32,
255 0xA0000, 0xA2000, 0xA4000, 0xA6000, 0xA8000, 0xAA000, 0xAC000, 0xAE000,
256 0xC0000, 0xC2000, 0xC4000, 0xC6000, 0xC8000, 0xCA000, 0xCC000, 0xCE000,
257 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000,
258 0xE0000, 0xE2000, 0xE4000, 0xE6000, 0xE8000, 0xEA000, 0xEC000, 0xEE000,
259};
260
261/*
262static unsigned s502_dpmsize_options[] = { 2, 0x2000, 0x10000 };
263static unsigned s507_dpmsize_options[] = { 2, 0x2000, 0x4000 };
264static unsigned s508_dpmsize_options[] = { 1, 0x2000 };
265*/
266
267static unsigned s502a_pclk_options[] = { 2, 3600, 7200 };
268static unsigned s502e_pclk_options[] = { 5, 3600, 5000, 7200, 8000, 10000 };
269static unsigned s503_pclk_options[] = { 3, 7200, 8000, 10000 };
270static unsigned s507_pclk_options[] = { 1, 12288 };
271static unsigned s508_pclk_options[] = { 1, 16000 };
272
273/* Host memory control register masks */
274static unsigned char s502a_hmcr[] =
275{
276 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, /* A0000 - AC000 */
277 0x20, 0x22, 0x24, 0x26, 0x28, 0x2A, 0x2C, /* C0000 - CC000 */
278 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, /* D0000 - DC000 */
279 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, /* E0000 - EC000 */
280};
281static unsigned char s502e_hmcr[] =
282{
283 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x1E, /* A0000 - AE000 */
284 0x20, 0x22, 0x24, 0x26, 0x28, 0x2A, 0x2C, 0x2E, /* C0000 - CE000 */
285 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, /* D0000 - DE000 */
286 0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, /* E0000 - EE000 */
287};
288static unsigned char s507_hmcr[] =
289{
290 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, /* A0000 - AE000 */
291 0x40, 0x42, 0x44, 0x46, 0x48, 0x4A, 0x4C, 0x4E, /* B0000 - BE000 */
292 0x80, 0x82, 0x84, 0x86, 0x88, 0x8A, 0x8C, 0x8E, /* C0000 - CE000 */
293 0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE, /* E0000 - EE000 */
294};
295static unsigned char s508_hmcr[] =
296{
297 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* A0000 - AE000 */
298 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* C0000 - CE000 */
299 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, /* D0000 - DE000 */
300 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, /* E0000 - EE000 */
301};
302
303static unsigned char s507_irqmask[] =
304{
305 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0, 0xE0
306};
307
308static int pci_slot_ar[MAX_S514_CARDS];
309
310/******* Kernel Loadable Module Entry Points ********************************/
311
312/*============================================================================
313 * Module 'insert' entry point.
314 * o print announcement
315 * o initialize static data
316 * o calibrate SDLA shared memory access delay.
317 *
318 * Return: 0 Ok
319 * < 0 error.
320 * Context: process
321 */
322
323static int __init sdladrv_init(void)
324{
325 int i=0;
326
327 printk(KERN_INFO "%s v%u.%u %s\n",
328 fullname, MOD_VERSION, MOD_RELEASE, copyright);
329 exec_idle = calibrate_delay(EXEC_DELAY);
330#ifdef WANDEBUG
331 printk(KERN_DEBUG "%s: exec_idle = %d\n", modname, exec_idle);
332#endif
333
334 /* Initialize the PCI Card array, which
335 * will store flags, used to mark
336 * card initialization state */
337 for (i=0; i<MAX_S514_CARDS; i++)
338 pci_slot_ar[i] = 0xFF;
339
340 return 0;
341}
342
343/*============================================================================
344 * Module 'remove' entry point.
345 * o release all remaining system resources
346 */
347static void __exit sdladrv_cleanup(void)
348{
349}
350
351module_init(sdladrv_init);
352module_exit(sdladrv_cleanup);
353
354/******* Kernel APIs ********************************************************/
355
356/*============================================================================
357 * Set up adapter.
358 * o detect adapter type
359 * o verify hardware configuration options
360 * o check for hardware conflicts
361 * o set up adapter shared memory
362 * o test adapter memory
363 * o load firmware
364 * Return: 0 ok.
365 * < 0 error
366 */
367
368EXPORT_SYMBOL(sdla_setup);
369
370int sdla_setup (sdlahw_t* hw, void* sfm, unsigned len)
371{
372 unsigned* irq_opt = NULL; /* IRQ options */
373 unsigned* dpmbase_opt = NULL; /* DPM window base options */
374 unsigned* pclk_opt = NULL; /* CPU clock rate options */
375 int err=0;
376
377 if (sdla_detect(hw)) {
378 if(hw->type != SDLA_S514)
379 printk(KERN_INFO "%s: no SDLA card found at port 0x%X\n",
380 modname, hw->port);
381 return -EINVAL;
382 }
383
384 if(hw->type != SDLA_S514) {
385 printk(KERN_INFO "%s: found S%04u card at port 0x%X.\n",
386 modname, hw->type, hw->port);
387
388 hw->dpmsize = SDLA_WINDOWSIZE;
389 switch (hw->type) {
390 case SDLA_S502A:
391 hw->io_range = S502A_IORANGE;
392 irq_opt = s502a_irq_options;
393 dpmbase_opt = s502a_dpmbase_options;
394 pclk_opt = s502a_pclk_options;
395 break;
396
397 case SDLA_S502E:
398 hw->io_range = S502E_IORANGE;
399 irq_opt = s502e_irq_options;
400 dpmbase_opt = s508_dpmbase_options;
401 pclk_opt = s502e_pclk_options;
402 break;
403
404 case SDLA_S503:
405 hw->io_range = S503_IORANGE;
406 irq_opt = s503_irq_options;
407 dpmbase_opt = s508_dpmbase_options;
408 pclk_opt = s503_pclk_options;
409 break;
410
411 case SDLA_S507:
412 hw->io_range = S507_IORANGE;
413 irq_opt = s508_irq_options;
414 dpmbase_opt = s507_dpmbase_options;
415 pclk_opt = s507_pclk_options;
416 break;
417
418 case SDLA_S508:
419 hw->io_range = S508_IORANGE;
420 irq_opt = s508_irq_options;
421 dpmbase_opt = s508_dpmbase_options;
422 pclk_opt = s508_pclk_options;
423 break;
424 }
425
426 /* Verify IRQ configuration options */
427 if (!get_option_index(irq_opt, hw->irq)) {
428 printk(KERN_INFO "%s: IRQ %d is invalid!\n",
429 modname, hw->irq);
430 return -EINVAL;
431 }
432
433 /* Verify CPU clock rate configuration options */
434 if (hw->pclk == 0)
435 hw->pclk = pclk_opt[1]; /* use default */
436
437 else if (!get_option_index(pclk_opt, hw->pclk)) {
438 printk(KERN_INFO "%s: CPU clock %u is invalid!\n",
439 modname, hw->pclk);
440 return -EINVAL;
441 }
442 printk(KERN_INFO "%s: assuming CPU clock rate of %u kHz.\n",
443 modname, hw->pclk);
444
445 /* Setup adapter dual-port memory window and test memory */
446 if (hw->dpmbase == 0) {
447 err = sdla_autodpm(hw);
448 if (err) {
449 printk(KERN_INFO
450 "%s: can't find available memory region!\n",
451 modname);
452 return err;
453 }
454 }
455 else if (!get_option_index(dpmbase_opt,
456 virt_to_phys(hw->dpmbase))) {
457 printk(KERN_INFO
458 "%s: memory address 0x%lX is invalid!\n",
459 modname, virt_to_phys(hw->dpmbase));
460 return -EINVAL;
461 }
462 else if (sdla_setdpm(hw)) {
463 printk(KERN_INFO
464 "%s: 8K memory region at 0x%lX is not available!\n",
465 modname, virt_to_phys(hw->dpmbase));
466 return -EINVAL;
467 }
468 printk(KERN_INFO
469 "%s: dual-port memory window is set at 0x%lX.\n",
470 modname, virt_to_phys(hw->dpmbase));
471
472
473 /* If we find memory in 0xE**** Memory region,
474 * warn the user to disable the SHADOW RAM.
475 * Since memory corruption can occur if SHADOW is
476 * enabled. This can causes random crashes ! */
477 if (virt_to_phys(hw->dpmbase) >= 0xE0000){
478 printk(KERN_WARNING "\n%s: !!!!!!!! WARNING !!!!!!!!\n",modname);
479 printk(KERN_WARNING "%s: WANPIPE is using 0x%lX memory region !!!\n",
480 modname, virt_to_phys(hw->dpmbase));
481 printk(KERN_WARNING " Please disable the SHADOW RAM, otherwise\n");
482 printk(KERN_WARNING " your system might crash randomly from time to time !\n");
483 printk(KERN_WARNING "%s: !!!!!!!! WARNING !!!!!!!!\n\n",modname);
484 }
485 }
486
487 else {
488 hw->memory = test_memregion((void*)hw->dpmbase,
489 MAX_SIZEOF_S514_MEMORY);
490 if(hw->memory < (256 * 1024)) {
491 printk(KERN_INFO
492 "%s: error in testing S514 memory (0x%lX)\n",
493 modname, hw->memory);
494 sdla_down(hw);
495 return -EINVAL;
496 }
497 }
498
499 printk(KERN_INFO "%s: found %luK bytes of on-board memory\n",
500 modname, hw->memory / 1024);
501
502 /* Load firmware. If loader fails then shut down adapter */
503 err = sdla_load(hw, sfm, len);
504 if (err) sdla_down(hw); /* shutdown adapter */
505
506 return err;
507}
508
509/*============================================================================
510 * Shut down SDLA: disable shared memory access and interrupts, stop CPU, etc.
511 */
512
513EXPORT_SYMBOL(sdla_down);
514
515int sdla_down (sdlahw_t* hw)
516{
517 unsigned port = hw->port;
518 int i;
519 unsigned char CPU_no;
520 u32 int_config, int_status;
521
522 if(!port && (hw->type != SDLA_S514))
523 return -EFAULT;
524
525 switch (hw->type) {
526 case SDLA_S502A:
527 _OUTB(port, 0x08); /* halt CPU */
528 _OUTB(port, 0x08);
529 _OUTB(port, 0x08);
530 hw->regs[0] = 0x08;
531 _OUTB(port + 1, 0xFF); /* close memory window */
532 hw->regs[1] = 0xFF;
533 break;
534
535 case SDLA_S502E:
536 _OUTB(port + 3, 0); /* stop CPU */
537 _OUTB(port, 0); /* reset board */
538 for (i = 0; i < S502E_IORANGE; ++i)
539 hw->regs[i] = 0
540 ;
541 break;
542
543 case SDLA_S503:
544 case SDLA_S507:
545 case SDLA_S508:
546 _OUTB(port, 0); /* reset board logic */
547 hw->regs[0] = 0;
548 break;
549
550 case SDLA_S514:
551 /* halt the adapter */
552 *(char *)hw->vector = S514_CPU_HALT;
553 CPU_no = hw->S514_cpu_no[0];
554
555 /* disable the PCI IRQ and disable memory access */
556 pci_read_config_dword(hw->pci_dev, PCI_INT_CONFIG, &int_config);
557 int_config &= (CPU_no == S514_CPU_A) ? ~PCI_DISABLE_IRQ_CPU_A : ~PCI_DISABLE_IRQ_CPU_B;
558 pci_write_config_dword(hw->pci_dev, PCI_INT_CONFIG, int_config);
559 read_S514_int_stat(hw, &int_status);
560 S514_intack(hw, int_status);
561 if(CPU_no == S514_CPU_A)
562 pci_write_config_dword(hw->pci_dev, PCI_MAP0_DWORD,
563 PCI_CPU_A_MEM_DISABLE);
564 else
565 pci_write_config_dword(hw->pci_dev, PCI_MAP1_DWORD,
566 PCI_CPU_B_MEM_DISABLE);
567
568 /* free up the allocated virtual memory */
569 iounmap((void *)hw->dpmbase);
570 iounmap((void *)hw->vector);
571 break;
572
573
574 default:
575 return -EINVAL;
576 }
577 return 0;
578}
579
580/*============================================================================
581 * Map shared memory window into SDLA address space.
582 */
583
584EXPORT_SYMBOL(sdla_mapmem);
585
586int sdla_mapmem (sdlahw_t* hw, unsigned long addr)
587{
588 unsigned port = hw->port;
589 register int tmp;
590
591 switch (hw->type) {
592 case SDLA_S502A:
593 case SDLA_S502E:
594 if (addr < S502_MAXMEM) { /* verify parameter */
595 tmp = addr >> 13; /* convert to register mask */
596 _OUTB(port + 2, tmp);
597 hw->regs[2] = tmp;
598 }
599 else return -EINVAL;
600 break;
601
602 case SDLA_S503:
603 if (addr < S503_MAXMEM) { /* verify parameter */
604 tmp = (hw->regs[0] & 0x8F) | ((addr >> 9) & 0x70);
605 _OUTB(port, tmp);
606 hw->regs[0] = tmp;
607 }
608 else return -EINVAL;
609 break;
610
611 case SDLA_S507:
612 if (addr < S507_MAXMEM) {
613 if (!(_INB(port) & 0x02))
614 return -EIO;
615 tmp = addr >> 13; /* convert to register mask */
616 _OUTB(port + 2, tmp);
617 hw->regs[2] = tmp;
618 }
619 else return -EINVAL;
620 break;
621
622 case SDLA_S508:
623 if (addr < S508_MAXMEM) {
624 tmp = addr >> 13; /* convert to register mask */
625 _OUTB(port + 2, tmp);
626 hw->regs[2] = tmp;
627 }
628 else return -EINVAL;
629 break;
630
631 case SDLA_S514:
632 return 0;
633
634 default:
635 return -EINVAL;
636 }
637 hw->vector = addr & 0xFFFFE000L;
638 return 0;
639}
640
641/*============================================================================
642 * Enable interrupt generation.
643 */
644
645static int sdla_inten (sdlahw_t* hw)
646{
647 unsigned port = hw->port;
648 int tmp, i;
649
650 switch (hw->type) {
651 case SDLA_S502E:
652 /* Note thar interrupt control operations on S502E are allowed
653 * only if CPU is enabled (bit 0 of status register is set).
654 */
655 if (_INB(port) & 0x01) {
656 _OUTB(port, 0x02); /* bit1 = 1, bit2 = 0 */
657 _OUTB(port, 0x06); /* bit1 = 1, bit2 = 1 */
658 hw->regs[0] = 0x06;
659 }
660 else return -EIO;
661 break;
662
663 case SDLA_S503:
664 tmp = hw->regs[0] | 0x04;
665 _OUTB(port, tmp);
666 hw->regs[0] = tmp; /* update mirror */
667 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
668 if (!(_INB(port) & 0x02)) /* verify */
669 return -EIO;
670 break;
671
672 case SDLA_S508:
673 tmp = hw->regs[0] | 0x10;
674 _OUTB(port, tmp);
675 hw->regs[0] = tmp; /* update mirror */
676 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
677 if (!(_INB(port + 1) & 0x10)) /* verify */
678 return -EIO;
679 break;
680
681 case SDLA_S502A:
682 case SDLA_S507:
683 break;
684
685 case SDLA_S514:
686 break;
687
688 default:
689 return -EINVAL;
690
691 }
692 return 0;
693}
694
695/*============================================================================
696 * Disable interrupt generation.
697 */
698
699#if 0
700int sdla_intde (sdlahw_t* hw)
701{
702 unsigned port = hw->port;
703 int tmp, i;
704
705 switch (hw->type) {
706 case SDLA_S502E:
707 /* Notes:
708 * 1) interrupt control operations are allowed only if CPU is
709 * enabled (bit 0 of status register is set).
710 * 2) disabling interrupts using bit 1 of control register
711 * causes IRQ line go high, therefore we are going to use
712 * 0x04 instead: lower it to inhibit interrupts to PC.
713 */
714 if (_INB(port) & 0x01) {
715 _OUTB(port, hw->regs[0] & ~0x04);
716 hw->regs[0] &= ~0x04;
717 }
718 else return -EIO;
719 break;
720
721 case SDLA_S503:
722 tmp = hw->regs[0] & ~0x04;
723 _OUTB(port, tmp);
724 hw->regs[0] = tmp; /* update mirror */
725 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
726 if (_INB(port) & 0x02) /* verify */
727 return -EIO;
728 break;
729
730 case SDLA_S508:
731 tmp = hw->regs[0] & ~0x10;
732 _OUTB(port, tmp);
733 hw->regs[0] = tmp; /* update mirror */
734 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
735 if (_INB(port) & 0x10) /* verify */
736 return -EIO;
737 break;
738
739 case SDLA_S502A:
740 case SDLA_S507:
741 break;
742
743 default:
744 return -EINVAL;
745 }
746 return 0;
747}
748#endif /* 0 */
749
750/*============================================================================
751 * Acknowledge SDLA hardware interrupt.
752 */
753
754static int sdla_intack (sdlahw_t* hw)
755{
756 unsigned port = hw->port;
757 int tmp;
758
759 switch (hw->type) {
760 case SDLA_S502E:
761 /* To acknoledge hardware interrupt we have to toggle bit 3 of
762 * control register: \_/
763 * Note that interrupt control operations on S502E are allowed
764 * only if CPU is enabled (bit 1 of status register is set).
765 */
766 if (_INB(port) & 0x01) {
767 tmp = hw->regs[0] & ~0x04;
768 _OUTB(port, tmp);
769 tmp |= 0x04;
770 _OUTB(port, tmp);
771 hw->regs[0] = tmp;
772 }
773 else return -EIO;
774 break;
775
776 case SDLA_S503:
777 if (_INB(port) & 0x04) {
778 tmp = hw->regs[0] & ~0x08;
779 _OUTB(port, tmp);
780 tmp |= 0x08;
781 _OUTB(port, tmp);
782 hw->regs[0] = tmp;
783 }
784 break;
785
786 case SDLA_S502A:
787 case SDLA_S507:
788 case SDLA_S508:
789 break;
790
791 default:
792 return -EINVAL;
793 }
794 return 0;
795}
796
797
798/*============================================================================
799 * Acknowledge S514 hardware interrupt.
800 */
801
802EXPORT_SYMBOL(S514_intack);
803
804void S514_intack (sdlahw_t* hw, u32 int_status)
805{
806 pci_write_config_dword(hw->pci_dev, PCI_INT_STATUS, int_status);
807}
808
809
810/*============================================================================
811 * Read the S514 hardware interrupt status.
812 */
813
814EXPORT_SYMBOL(read_S514_int_stat);
815
816void read_S514_int_stat (sdlahw_t* hw, u32* int_status)
817{
818 pci_read_config_dword(hw->pci_dev, PCI_INT_STATUS, int_status);
819}
820
821
822/*============================================================================
823 * Generate an interrupt to adapter's CPU.
824 */
825
826#if 0
827int sdla_intr (sdlahw_t* hw)
828{
829 unsigned port = hw->port;
830
831 switch (hw->type) {
832 case SDLA_S502A:
833 if (!(_INB(port) & 0x40)) {
834 _OUTB(port, 0x10); /* issue NMI to CPU */
835 hw->regs[0] = 0x10;
836 }
837 else return -EIO;
838 break;
839
840 case SDLA_S507:
841 if ((_INB(port) & 0x06) == 0x06) {
842 _OUTB(port + 3, 0);
843 }
844 else return -EIO;
845 break;
846
847 case SDLA_S508:
848 if (_INB(port + 1) & 0x02) {
849 _OUTB(port, 0x08);
850 }
851 else return -EIO;
852 break;
853
854 case SDLA_S502E:
855 case SDLA_S503:
856 default:
857 return -EINVAL;
858 }
859 return 0;
860}
861#endif /* 0 */
862
863/*============================================================================
864 * Execute Adapter Command.
865 * o Set exec flag.
866 * o Busy-wait until flag is reset.
867 * o Return number of loops made, or 0 if command timed out.
868 */
869
870EXPORT_SYMBOL(sdla_exec);
871
872int sdla_exec (void* opflag)
873{
874 volatile unsigned char* flag = opflag;
875 unsigned long tstop;
876 int nloops;
877
878 if(readb(flag) != 0x00) {
879 printk(KERN_INFO
880 "WANPIPE: opp flag set on entry to sdla_exec\n");
881 return 0;
882 }
883
884 writeb(0x01, flag);
885
886 tstop = SYSTEM_TICK + EXEC_TIMEOUT;
887
888 for (nloops = 1; (readb(flag) == 0x01); ++ nloops) {
889 unsigned delay = exec_idle;
890 while (-- delay); /* delay */
891 if (SYSTEM_TICK > tstop) return 0; /* time is up! */
892 }
893 return nloops;
894}
895
896/*============================================================================
897 * Read absolute adapter memory.
898 * Transfer data from adapter's memory to data buffer.
899 *
900 * Note:
901 * Care should be taken when crossing dual-port memory window boundary.
902 * This function is not atomic, so caller must disable interrupt if
903 * interrupt routines are accessing adapter shared memory.
904 */
905
906EXPORT_SYMBOL(sdla_peek);
907
908int sdla_peek (sdlahw_t* hw, unsigned long addr, void* buf, unsigned len)
909{
910
911 if (addr + len > hw->memory) /* verify arguments */
912 return -EINVAL;
913
914 if(hw->type == SDLA_S514) { /* copy data for the S514 adapter */
915 peek_by_4 ((unsigned long)hw->dpmbase + addr, buf, len);
916 return 0;
917 }
918
919 else { /* copy data for the S508 adapter */
920 unsigned long oldvec = hw->vector;
921 unsigned winsize = hw->dpmsize;
922 unsigned curpos, curlen; /* current offset and block size */
923 unsigned long curvec; /* current DPM window vector */
924 int err = 0;
925
926 while (len && !err) {
927 curpos = addr % winsize; /* current window offset */
928 curvec = addr - curpos; /* current window vector */
929 curlen = (len > (winsize - curpos)) ?
930 (winsize - curpos) : len;
931 /* Relocate window and copy block of data */
932 err = sdla_mapmem(hw, curvec);
933 peek_by_4 ((unsigned long)hw->dpmbase + curpos, buf,
934 curlen);
935 addr += curlen;
936 buf = (char*)buf + curlen;
937 len -= curlen;
938 }
939
940 /* Restore DPM window position */
941 sdla_mapmem(hw, oldvec);
942 return err;
943 }
944}
945
946
947/*============================================================================
948 * Read data from adapter's memory to a data buffer in 4-byte chunks.
949 * Note that we ensure that the SDLA memory address is on a 4-byte boundary
950 * before we begin moving the data in 4-byte chunks.
951*/
952
953static void peek_by_4 (unsigned long src, void* buf, unsigned len)
954{
955
956 /* byte copy data until we get to a 4-byte boundary */
957 while (len && (src & 0x03)) {
958 *(char *)buf ++ = readb(src ++);
959 len --;
960 }
961
962 /* copy data in 4-byte chunks */
963 while (len >= 4) {
964 *(unsigned long *)buf = readl(src);
965 buf += 4;
966 src += 4;
967 len -= 4;
968 }
969
970 /* byte copy any remaining data */
971 while (len) {
972 *(char *)buf ++ = readb(src ++);
973 len --;
974 }
975}
976
977
978/*============================================================================
979 * Write Absolute Adapter Memory.
980 * Transfer data from data buffer to adapter's memory.
981 *
982 * Note:
983 * Care should be taken when crossing dual-port memory window boundary.
984 * This function is not atomic, so caller must disable interrupt if
985 * interrupt routines are accessing adapter shared memory.
986 */
987
988EXPORT_SYMBOL(sdla_poke);
989
990int sdla_poke (sdlahw_t* hw, unsigned long addr, void* buf, unsigned len)
991{
992
993 if (addr + len > hw->memory) /* verify arguments */
994 return -EINVAL;
995
996 if(hw->type == SDLA_S514) { /* copy data for the S514 adapter */
997 poke_by_4 ((unsigned long)hw->dpmbase + addr, buf, len);
998 return 0;
999 }
1000
1001 else { /* copy data for the S508 adapter */
1002 unsigned long oldvec = hw->vector;
1003 unsigned winsize = hw->dpmsize;
1004 unsigned curpos, curlen; /* current offset and block size */
1005 unsigned long curvec; /* current DPM window vector */
1006 int err = 0;
1007
1008 while (len && !err) {
1009 curpos = addr % winsize; /* current window offset */
1010 curvec = addr - curpos; /* current window vector */
1011 curlen = (len > (winsize - curpos)) ?
1012 (winsize - curpos) : len;
1013 /* Relocate window and copy block of data */
1014 sdla_mapmem(hw, curvec);
1015 poke_by_4 ((unsigned long)hw->dpmbase + curpos, buf,
1016 curlen);
1017 addr += curlen;
1018 buf = (char*)buf + curlen;
1019 len -= curlen;
1020 }
1021
1022 /* Restore DPM window position */
1023 sdla_mapmem(hw, oldvec);
1024 return err;
1025 }
1026}
1027
1028
1029/*============================================================================
1030 * Write from a data buffer to adapter's memory in 4-byte chunks.
1031 * Note that we ensure that the SDLA memory address is on a 4-byte boundary
1032 * before we begin moving the data in 4-byte chunks.
1033*/
1034
1035static void poke_by_4 (unsigned long dest, void* buf, unsigned len)
1036{
1037
1038 /* byte copy data until we get to a 4-byte boundary */
1039 while (len && (dest & 0x03)) {
1040 writeb (*(char *)buf ++, dest ++);
1041 len --;
1042 }
1043
1044 /* copy data in 4-byte chunks */
1045 while (len >= 4) {
1046 writel (*(unsigned long *)buf, dest);
1047 dest += 4;
1048 buf += 4;
1049 len -= 4;
1050 }
1051
1052 /* byte copy any remaining data */
1053 while (len) {
1054 writeb (*(char *)buf ++ , dest ++);
1055 len --;
1056 }
1057}
1058
1059
1060#ifdef DONT_COMPIPLE_THIS
1061#endif /* DONT_COMPIPLE_THIS */
1062
1063/****** Hardware-Specific Functions *****************************************/
1064
1065/*============================================================================
1066 * Detect adapter type.
1067 * o if adapter type is specified then call detection routine for that adapter
1068 * type. Otherwise call detection routines for every adapter types until
1069 * adapter is detected.
1070 *
1071 * Notes:
1072 * 1) Detection tests are destructive! Adapter will be left in shutdown state
1073 * after the test.
1074 */
1075static int sdla_detect (sdlahw_t* hw)
1076{
1077 unsigned port = hw->port;
1078 int err = 0;
1079
1080 if (!port && (hw->type != SDLA_S514))
1081 return -EFAULT;
1082
1083 switch (hw->type) {
1084 case SDLA_S502A:
1085 if (!detect_s502a(port)) err = -ENODEV;
1086 break;
1087
1088 case SDLA_S502E:
1089 if (!detect_s502e(port)) err = -ENODEV;
1090 break;
1091
1092 case SDLA_S503:
1093 if (!detect_s503(port)) err = -ENODEV;
1094 break;
1095
1096 case SDLA_S507:
1097 if (!detect_s507(port)) err = -ENODEV;
1098 break;
1099
1100 case SDLA_S508:
1101 if (!detect_s508(port)) err = -ENODEV;
1102 break;
1103
1104 case SDLA_S514:
1105 if (!detect_s514(hw)) err = -ENODEV;
1106 break;
1107
1108 default:
1109 if (detect_s502a(port))
1110 hw->type = SDLA_S502A;
1111 else if (detect_s502e(port))
1112 hw->type = SDLA_S502E;
1113 else if (detect_s503(port))
1114 hw->type = SDLA_S503;
1115 else if (detect_s507(port))
1116 hw->type = SDLA_S507;
1117 else if (detect_s508(port))
1118 hw->type = SDLA_S508;
1119 else err = -ENODEV;
1120 }
1121 return err;
1122}
1123
1124/*============================================================================
1125 * Autoselect memory region.
1126 * o try all available DMP address options from the top down until success.
1127 */
1128static int sdla_autodpm (sdlahw_t* hw)
1129{
1130 int i, err = -EINVAL;
1131 unsigned* opt;
1132
1133 switch (hw->type) {
1134 case SDLA_S502A:
1135 opt = s502a_dpmbase_options;
1136 break;
1137
1138 case SDLA_S502E:
1139 case SDLA_S503:
1140 case SDLA_S508:
1141 opt = s508_dpmbase_options;
1142 break;
1143
1144 case SDLA_S507:
1145 opt = s507_dpmbase_options;
1146 break;
1147
1148 default:
1149 return -EINVAL;
1150 }
1151
1152 /* Start testing from 8th position, address
1153 * 0xC8000 from the 508 address table.
1154 * We don't want to test A**** addresses, since
1155 * they are usually used for Video */
1156 for (i = 8; i <= opt[0] && err; i++) {
1157 hw->dpmbase = phys_to_virt(opt[i]);
1158 err = sdla_setdpm(hw);
1159 }
1160 return err;
1161}
1162
1163/*============================================================================
1164 * Set up adapter dual-port memory window.
1165 * o shut down adapter
1166 * o make sure that no physical memory exists in this region, i.e entire
1167 * region reads 0xFF and is not writable when adapter is shut down.
1168 * o initialize adapter hardware
1169 * o make sure that region is usable with SDLA card, i.e. we can write to it
1170 * when adapter is configured.
1171 */
1172static int sdla_setdpm (sdlahw_t* hw)
1173{
1174 int err;
1175
1176 /* Shut down card and verify memory region */
1177 sdla_down(hw);
1178 if (check_memregion(hw->dpmbase, hw->dpmsize))
1179 return -EINVAL;
1180
1181 /* Initialize adapter and test on-board memory segment by segment.
1182 * If memory size appears to be less than shared memory window size,
1183 * assume that memory region is unusable.
1184 */
1185 err = sdla_init(hw);
1186 if (err) return err;
1187
1188 if (sdla_memtest(hw) < hw->dpmsize) { /* less than window size */
1189 sdla_down(hw);
1190 return -EIO;
1191 }
1192 sdla_mapmem(hw, 0L); /* set window vector at bottom */
1193 return 0;
1194}
1195
1196/*============================================================================
1197 * Load adapter from the memory image of the SDLA firmware module.
1198 * o verify firmware integrity and compatibility
1199 * o start adapter up
1200 */
1201static int sdla_load (sdlahw_t* hw, sfm_t* sfm, unsigned len)
1202{
1203
1204 int i;
1205
1206 /* Verify firmware signature */
1207 if (strcmp(sfm->signature, SFM_SIGNATURE)) {
1208 printk(KERN_INFO "%s: not SDLA firmware!\n",
1209 modname);
1210 return -EINVAL;
1211 }
1212
1213 /* Verify firmware module format version */
1214 if (sfm->version != SFM_VERSION) {
1215 printk(KERN_INFO
1216 "%s: firmware format %u rejected! Expecting %u.\n",
1217 modname, sfm->version, SFM_VERSION);
1218 return -EINVAL;
1219 }
1220
1221 /* Verify firmware module length and checksum */
1222 if ((len - offsetof(sfm_t, image) != sfm->info.codesize) ||
1223 (checksum((void*)&sfm->info,
1224 sizeof(sfm_info_t) + sfm->info.codesize) != sfm->checksum)) {
1225 printk(KERN_INFO "%s: firmware corrupted!\n", modname);
1226 return -EINVAL;
1227 }
1228
1229 /* Announce */
1230 printk(KERN_INFO "%s: loading %s (ID=%u)...\n", modname,
1231 (sfm->descr[0] != '\0') ? sfm->descr : "unknown firmware",
1232 sfm->info.codeid);
1233
1234 if(hw->type == SDLA_S514)
1235 printk(KERN_INFO "%s: loading S514 adapter, CPU %c\n",
1236 modname, hw->S514_cpu_no[0]);
1237
1238 /* Scan through the list of compatible adapters and make sure our
1239 * adapter type is listed.
1240 */
1241 for (i = 0;
1242 (i < SFM_MAX_SDLA) && (sfm->info.adapter[i] != hw->type);
1243 ++i);
1244
1245 if (i == SFM_MAX_SDLA) {
1246 printk(KERN_INFO "%s: firmware is not compatible with S%u!\n",
1247 modname, hw->type);
1248 return -EINVAL;
1249 }
1250
1251
1252 /* Make sure there is enough on-board memory */
1253 if (hw->memory < sfm->info.memsize) {
1254 printk(KERN_INFO
1255 "%s: firmware needs %lu bytes of on-board memory!\n",
1256 modname, sfm->info.memsize);
1257 return -EINVAL;
1258 }
1259
1260 /* Move code onto adapter */
1261 if (sdla_poke(hw, sfm->info.codeoffs, sfm->image, sfm->info.codesize)) {
1262 printk(KERN_INFO "%s: failed to load code segment!\n",
1263 modname);
1264 return -EIO;
1265 }
1266
1267 /* Prepare boot-time configuration data and kick-off CPU */
1268 sdla_bootcfg(hw, &sfm->info);
1269 if (sdla_start(hw, sfm->info.startoffs)) {
1270 printk(KERN_INFO "%s: Damn... Adapter won't start!\n",
1271 modname);
1272 return -EIO;
1273 }
1274
1275 /* position DPM window over the mailbox and enable interrupts */
1276 if (sdla_mapmem(hw, sfm->info.winoffs) || sdla_inten(hw)) {
1277 printk(KERN_INFO "%s: adapter hardware failure!\n",
1278 modname);
1279 return -EIO;
1280 }
1281 hw->fwid = sfm->info.codeid; /* set firmware ID */
1282 return 0;
1283}
1284
1285/*============================================================================
1286 * Initialize SDLA hardware: setup memory window, IRQ, etc.
1287 */
1288static int sdla_init (sdlahw_t* hw)
1289{
1290 int i;
1291
1292 for (i = 0; i < SDLA_MAXIORANGE; ++i)
1293 hw->regs[i] = 0;
1294
1295 switch (hw->type) {
1296 case SDLA_S502A: return init_s502a(hw);
1297 case SDLA_S502E: return init_s502e(hw);
1298 case SDLA_S503: return init_s503(hw);
1299 case SDLA_S507: return init_s507(hw);
1300 case SDLA_S508: return init_s508(hw);
1301 }
1302 return -EINVAL;
1303}
1304
1305/*============================================================================
1306 * Test adapter on-board memory.
1307 * o slide DPM window from the bottom up and test adapter memory segment by
1308 * segment.
1309 * Return adapter memory size.
1310 */
1311static unsigned long sdla_memtest (sdlahw_t* hw)
1312{
1313 unsigned long memsize;
1314 unsigned winsize;
1315
1316 for (memsize = 0, winsize = hw->dpmsize;
1317 !sdla_mapmem(hw, memsize) &&
1318 (test_memregion(hw->dpmbase, winsize) == winsize)
1319 ;
1320 memsize += winsize)
1321 ;
1322 hw->memory = memsize;
1323 return memsize;
1324}
1325
1326/*============================================================================
1327 * Prepare boot-time firmware configuration data.
1328 * o position DPM window
1329 * o initialize configuration data area
1330 */
1331static int sdla_bootcfg (sdlahw_t* hw, sfm_info_t* sfminfo)
1332{
1333 unsigned char* data;
1334
1335 if (!sfminfo->datasize) return 0; /* nothing to do */
1336
1337 if (sdla_mapmem(hw, sfminfo->dataoffs) != 0)
1338 return -EIO;
1339
1340 if(hw->type == SDLA_S514)
1341 data = (void*)(hw->dpmbase + sfminfo->dataoffs);
1342 else
1343 data = (void*)((u8 *)hw->dpmbase +
1344 (sfminfo->dataoffs - hw->vector));
1345
1346 memset_io (data, 0, sfminfo->datasize);
1347
1348 writeb (make_config_byte(hw), &data[0x00]);
1349
1350 switch (sfminfo->codeid) {
1351 case SFID_X25_502:
1352 case SFID_X25_508:
1353 writeb (3, &data[0x01]); /* T1 timer */
1354 writeb (10, &data[0x03]); /* N2 */
1355 writeb (7, &data[0x06]); /* HDLC window size */
1356 writeb (1, &data[0x0B]); /* DTE */
1357 writeb (2, &data[0x0C]); /* X.25 packet window size */
1358 writew (128, &data[0x0D]); /* default X.25 data size */
1359 writew (128, &data[0x0F]); /* maximum X.25 data size */
1360 break;
1361 }
1362 return 0;
1363}
1364
1365/*============================================================================
1366 * Prepare configuration byte identifying adapter type and CPU clock rate.
1367 */
1368static unsigned char make_config_byte (sdlahw_t* hw)
1369{
1370 unsigned char byte = 0;
1371
1372 switch (hw->pclk) {
1373 case 5000: byte = 0x01; break;
1374 case 7200: byte = 0x02; break;
1375 case 8000: byte = 0x03; break;
1376 case 10000: byte = 0x04; break;
1377 case 16000: byte = 0x05; break;
1378 }
1379
1380 switch (hw->type) {
1381 case SDLA_S502E: byte |= 0x80; break;
1382 case SDLA_S503: byte |= 0x40; break;
1383 }
1384 return byte;
1385}
1386
1387/*============================================================================
1388 * Start adapter's CPU.
1389 * o calculate a pointer to adapter's cold boot entry point
1390 * o position DPM window
1391 * o place boot instruction (jp addr) at cold boot entry point
1392 * o start CPU
1393 */
1394static int sdla_start (sdlahw_t* hw, unsigned addr)
1395{
1396 unsigned port = hw->port;
1397 unsigned char *bootp;
1398 int err, tmp, i;
1399
1400 if (!port && (hw->type != SDLA_S514)) return -EFAULT;
1401
1402 switch (hw->type) {
1403 case SDLA_S502A:
1404 bootp = hw->dpmbase;
1405 bootp += 0x66;
1406 break;
1407
1408 case SDLA_S502E:
1409 case SDLA_S503:
1410 case SDLA_S507:
1411 case SDLA_S508:
1412 case SDLA_S514:
1413 bootp = hw->dpmbase;
1414 break;
1415
1416 default:
1417 return -EINVAL;
1418 }
1419
1420 err = sdla_mapmem(hw, 0);
1421 if (err) return err;
1422
1423 writeb (0xC3, bootp); /* Z80: 'jp' opcode */
1424 bootp ++;
1425 writew (addr, bootp);
1426
1427 switch (hw->type) {
1428 case SDLA_S502A:
1429 _OUTB(port, 0x10); /* issue NMI to CPU */
1430 hw->regs[0] = 0x10;
1431 break;
1432
1433 case SDLA_S502E:
1434 _OUTB(port + 3, 0x01); /* start CPU */
1435 hw->regs[3] = 0x01;
1436 for (i = 0; i < SDLA_IODELAY; ++i);
1437 if (_INB(port) & 0x01) { /* verify */
1438 /*
1439 * Enabling CPU changes functionality of the
1440 * control register, so we have to reset its
1441 * mirror.
1442 */
1443 _OUTB(port, 0); /* disable interrupts */
1444 hw->regs[0] = 0;
1445 }
1446 else return -EIO;
1447 break;
1448
1449 case SDLA_S503:
1450 tmp = hw->regs[0] | 0x09; /* set bits 0 and 3 */
1451 _OUTB(port, tmp);
1452 hw->regs[0] = tmp; /* update mirror */
1453 for (i = 0; i < SDLA_IODELAY; ++i);
1454 if (!(_INB(port) & 0x01)) /* verify */
1455 return -EIO;
1456 break;
1457
1458 case SDLA_S507:
1459 tmp = hw->regs[0] | 0x02;
1460 _OUTB(port, tmp);
1461 hw->regs[0] = tmp; /* update mirror */
1462 for (i = 0; i < SDLA_IODELAY; ++i);
1463 if (!(_INB(port) & 0x04)) /* verify */
1464 return -EIO;
1465 break;
1466
1467 case SDLA_S508:
1468 tmp = hw->regs[0] | 0x02;
1469 _OUTB(port, tmp);
1470 hw->regs[0] = tmp; /* update mirror */
1471 for (i = 0; i < SDLA_IODELAY; ++i);
1472 if (!(_INB(port + 1) & 0x02)) /* verify */
1473 return -EIO;
1474 break;
1475
1476 case SDLA_S514:
1477 writeb (S514_CPU_START, hw->vector);
1478 break;
1479
1480 default:
1481 return -EINVAL;
1482 }
1483 return 0;
1484}
1485
1486/*============================================================================
1487 * Initialize S502A adapter.
1488 */
1489static int init_s502a (sdlahw_t* hw)
1490{
1491 unsigned port = hw->port;
1492 int tmp, i;
1493
1494 if (!detect_s502a(port))
1495 return -ENODEV;
1496
1497 hw->regs[0] = 0x08;
1498 hw->regs[1] = 0xFF;
1499
1500 /* Verify configuration options */
1501 i = get_option_index(s502a_dpmbase_options, virt_to_phys(hw->dpmbase));
1502 if (i == 0)
1503 return -EINVAL;
1504
1505 tmp = s502a_hmcr[i - 1];
1506 switch (hw->dpmsize) {
1507 case 0x2000:
1508 tmp |= 0x01;
1509 break;
1510
1511 case 0x10000L:
1512 break;
1513
1514 default:
1515 return -EINVAL;
1516 }
1517
1518 /* Setup dual-port memory window (this also enables memory access) */
1519 _OUTB(port + 1, tmp);
1520 hw->regs[1] = tmp;
1521 hw->regs[0] = 0x08;
1522 return 0;
1523}
1524
1525/*============================================================================
1526 * Initialize S502E adapter.
1527 */
1528static int init_s502e (sdlahw_t* hw)
1529{
1530 unsigned port = hw->port;
1531 int tmp, i;
1532
1533 if (!detect_s502e(port))
1534 return -ENODEV;
1535
1536 /* Verify configuration options */
1537 i = get_option_index(s508_dpmbase_options, virt_to_phys(hw->dpmbase));
1538 if (i == 0)
1539 return -EINVAL;
1540
1541 tmp = s502e_hmcr[i - 1];
1542 switch (hw->dpmsize) {
1543 case 0x2000:
1544 tmp |= 0x01;
1545 break;
1546
1547 case 0x10000L:
1548 break;
1549
1550 default:
1551 return -EINVAL;
1552 }
1553
1554 /* Setup dual-port memory window */
1555 _OUTB(port + 1, tmp);
1556 hw->regs[1] = tmp;
1557
1558 /* Enable memory access */
1559 _OUTB(port, 0x02);
1560 hw->regs[0] = 0x02;
1561 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1562 return (_INB(port) & 0x02) ? 0 : -EIO;
1563}
1564
1565/*============================================================================
1566 * Initialize S503 adapter.
1567 * ---------------------------------------------------------------------------
1568 */
1569static int init_s503 (sdlahw_t* hw)
1570{
1571 unsigned port = hw->port;
1572 int tmp, i;
1573
1574 if (!detect_s503(port))
1575 return -ENODEV;
1576
1577 /* Verify configuration options */
1578 i = get_option_index(s508_dpmbase_options, virt_to_phys(hw->dpmbase));
1579 if (i == 0)
1580 return -EINVAL;
1581
1582 tmp = s502e_hmcr[i - 1];
1583 switch (hw->dpmsize) {
1584 case 0x2000:
1585 tmp |= 0x01;
1586 break;
1587
1588 case 0x10000L:
1589 break;
1590
1591 default:
1592 return -EINVAL;
1593 }
1594
1595 /* Setup dual-port memory window */
1596 _OUTB(port + 1, tmp);
1597 hw->regs[1] = tmp;
1598
1599 /* Enable memory access */
1600 _OUTB(port, 0x02);
1601 hw->regs[0] = 0x02; /* update mirror */
1602 return 0;
1603}
1604
1605/*============================================================================
1606 * Initialize S507 adapter.
1607 */
1608static int init_s507 (sdlahw_t* hw)
1609{
1610 unsigned port = hw->port;
1611 int tmp, i;
1612
1613 if (!detect_s507(port))
1614 return -ENODEV;
1615
1616 /* Verify configuration options */
1617 i = get_option_index(s507_dpmbase_options, virt_to_phys(hw->dpmbase));
1618 if (i == 0)
1619 return -EINVAL;
1620
1621 tmp = s507_hmcr[i - 1];
1622 switch (hw->dpmsize) {
1623 case 0x2000:
1624 tmp |= 0x01;
1625 break;
1626
1627 case 0x10000L:
1628 break;
1629
1630 default:
1631 return -EINVAL;
1632 }
1633
1634 /* Enable adapter's logic */
1635 _OUTB(port, 0x01);
1636 hw->regs[0] = 0x01;
1637 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1638 if (!(_INB(port) & 0x20))
1639 return -EIO;
1640
1641 /* Setup dual-port memory window */
1642 _OUTB(port + 1, tmp);
1643 hw->regs[1] = tmp;
1644
1645 /* Enable memory access */
1646 tmp = hw->regs[0] | 0x04;
1647 if (hw->irq) {
1648 i = get_option_index(s508_irq_options, hw->irq);
1649 if (i) tmp |= s507_irqmask[i - 1];
1650 }
1651 _OUTB(port, tmp);
1652 hw->regs[0] = tmp; /* update mirror */
1653 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1654 return (_INB(port) & 0x08) ? 0 : -EIO;
1655}
1656
1657/*============================================================================
1658 * Initialize S508 adapter.
1659 */
1660static int init_s508 (sdlahw_t* hw)
1661{
1662 unsigned port = hw->port;
1663 int tmp, i;
1664
1665 if (!detect_s508(port))
1666 return -ENODEV;
1667
1668 /* Verify configuration options */
1669 i = get_option_index(s508_dpmbase_options, virt_to_phys(hw->dpmbase));
1670 if (i == 0)
1671 return -EINVAL;
1672
1673 /* Setup memory configuration */
1674 tmp = s508_hmcr[i - 1];
1675 _OUTB(port + 1, tmp);
1676 hw->regs[1] = tmp;
1677
1678 /* Enable memory access */
1679 _OUTB(port, 0x04);
1680 hw->regs[0] = 0x04; /* update mirror */
1681 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1682 return (_INB(port + 1) & 0x04) ? 0 : -EIO;
1683}
1684
1685/*============================================================================
1686 * Detect S502A adapter.
1687 * Following tests are used to detect S502A adapter:
1688 * 1. All registers other than status (BASE) should read 0xFF
1689 * 2. After writing 00001000b to control register, status register should
1690 * read 01000000b.
1691 * 3. After writing 0 to control register, status register should still
1692 * read 01000000b.
1693 * 4. After writing 00000100b to control register, status register should
1694 * read 01000100b.
1695 * Return 1 if detected o.k. or 0 if failed.
1696 * Note: This test is destructive! Adapter will be left in shutdown
1697 * state after the test.
1698 */
1699static int detect_s502a (int port)
1700{
1701 int i, j;
1702
1703 if (!get_option_index(s502_port_options, port))
1704 return 0;
1705
1706 for (j = 1; j < SDLA_MAXIORANGE; ++j) {
1707 if (_INB(port + j) != 0xFF)
1708 return 0;
1709 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1710 }
1711
1712 _OUTB(port, 0x08); /* halt CPU */
1713 _OUTB(port, 0x08);
1714 _OUTB(port, 0x08);
1715 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1716 if (_INB(port) != 0x40)
1717 return 0;
1718 _OUTB(port, 0x00);
1719 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1720 if (_INB(port) != 0x40)
1721 return 0;
1722 _OUTB(port, 0x04);
1723 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1724 if (_INB(port) != 0x44)
1725 return 0;
1726
1727 /* Reset adapter */
1728 _OUTB(port, 0x08);
1729 _OUTB(port, 0x08);
1730 _OUTB(port, 0x08);
1731 _OUTB(port + 1, 0xFF);
1732 return 1;
1733}
1734
1735/*============================================================================
1736 * Detect S502E adapter.
1737 * Following tests are used to verify adapter presence:
1738 * 1. All registers other than status (BASE) should read 0xFF.
1739 * 2. After writing 0 to CPU control register (BASE+3), status register
1740 * (BASE) should read 11111000b.
1741 * 3. After writing 00000100b to port BASE (set bit 2), status register
1742 * (BASE) should read 11111100b.
1743 * Return 1 if detected o.k. or 0 if failed.
1744 * Note: This test is destructive! Adapter will be left in shutdown
1745 * state after the test.
1746 */
1747static int detect_s502e (int port)
1748{
1749 int i, j;
1750
1751 if (!get_option_index(s502_port_options, port))
1752 return 0;
1753 for (j = 1; j < SDLA_MAXIORANGE; ++j) {
1754 if (_INB(port + j) != 0xFF)
1755 return 0;
1756 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1757 }
1758
1759 _OUTB(port + 3, 0); /* CPU control reg. */
1760 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1761 if (_INB(port) != 0xF8) /* read status */
1762 return 0;
1763 _OUTB(port, 0x04); /* set bit 2 */
1764 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1765 if (_INB(port) != 0xFC) /* verify */
1766 return 0;
1767
1768 /* Reset adapter */
1769 _OUTB(port, 0);
1770 return 1;
1771}
1772
1773/*============================================================================
1774 * Detect s503 adapter.
1775 * Following tests are used to verify adapter presence:
1776 * 1. All registers other than status (BASE) should read 0xFF.
1777 * 2. After writing 0 to control register (BASE), status register (BASE)
1778 * should read 11110000b.
1779 * 3. After writing 00000100b (set bit 2) to control register (BASE),
1780 * status register should read 11110010b.
1781 * Return 1 if detected o.k. or 0 if failed.
1782 * Note: This test is destructive! Adapter will be left in shutdown
1783 * state after the test.
1784 */
1785static int detect_s503 (int port)
1786{
1787 int i, j;
1788
1789 if (!get_option_index(s503_port_options, port))
1790 return 0;
1791 for (j = 1; j < SDLA_MAXIORANGE; ++j) {
1792 if (_INB(port + j) != 0xFF)
1793 return 0;
1794 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1795 }
1796
1797 _OUTB(port, 0); /* reset control reg.*/
1798 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1799 if (_INB(port) != 0xF0) /* read status */
1800 return 0;
1801 _OUTB(port, 0x04); /* set bit 2 */
1802 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1803 if (_INB(port) != 0xF2) /* verify */
1804 return 0;
1805
1806 /* Reset adapter */
1807 _OUTB(port, 0);
1808 return 1;
1809}
1810
1811/*============================================================================
1812 * Detect s507 adapter.
1813 * Following tests are used to detect s507 adapter:
1814 * 1. All ports should read the same value.
1815 * 2. After writing 0x00 to control register, status register should read
1816 * ?011000?b.
1817 * 3. After writing 0x01 to control register, status register should read
1818 * ?011001?b.
1819 * Return 1 if detected o.k. or 0 if failed.
1820 * Note: This test is destructive! Adapter will be left in shutdown
1821 * state after the test.
1822 */
1823static int detect_s507 (int port)
1824{
1825 int tmp, i, j;
1826
1827 if (!get_option_index(s508_port_options, port))
1828 return 0;
1829 tmp = _INB(port);
1830 for (j = 1; j < S507_IORANGE; ++j) {
1831 if (_INB(port + j) != tmp)
1832 return 0;
1833 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1834 }
1835
1836 _OUTB(port, 0x00);
1837 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1838 if ((_INB(port) & 0x7E) != 0x30)
1839 return 0;
1840 _OUTB(port, 0x01);
1841 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1842 if ((_INB(port) & 0x7E) != 0x32)
1843 return 0;
1844
1845 /* Reset adapter */
1846 _OUTB(port, 0x00);
1847 return 1;
1848}
1849
1850/*============================================================================
1851 * Detect s508 adapter.
1852 * Following tests are used to detect s508 adapter:
1853 * 1. After writing 0x00 to control register, status register should read
1854 * ??000000b.
1855 * 2. After writing 0x10 to control register, status register should read
1856 * ??010000b
1857 * Return 1 if detected o.k. or 0 if failed.
1858 * Note: This test is destructive! Adapter will be left in shutdown
1859 * state after the test.
1860 */
1861static int detect_s508 (int port)
1862{
1863 int i;
1864
1865 if (!get_option_index(s508_port_options, port))
1866 return 0;
1867 _OUTB(port, 0x00);
1868 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1869 if ((_INB(port + 1) & 0x3F) != 0x00)
1870 return 0;
1871 _OUTB(port, 0x10);
1872 for (i = 0; i < SDLA_IODELAY; ++i); /* delay */
1873 if ((_INB(port + 1) & 0x3F) != 0x10)
1874 return 0;
1875
1876 /* Reset adapter */
1877 _OUTB(port, 0x00);
1878 return 1;
1879}
1880
1881/*============================================================================
1882 * Detect s514 PCI adapter.
1883 * Return 1 if detected o.k. or 0 if failed.
1884 * Note: This test is destructive! Adapter will be left in shutdown
1885 * state after the test.
1886 */
1887static int detect_s514 (sdlahw_t* hw)
1888{
1889 unsigned char CPU_no, slot_no, auto_slot_cfg;
1890 int number_S514_cards = 0;
1891 u32 S514_mem_base_addr = 0;
1892 u32 ut_u32;
1893 struct pci_dev *pci_dev;
1894
1895
1896#ifndef CONFIG_PCI
1897 printk(KERN_INFO "%s: Linux not compiled for PCI usage!\n", modname);
1898 return 0;
1899#endif
1900
1901 /*
1902 The 'setup()' procedure in 'sdlamain.c' passes the CPU number and the
1903 slot number defined in 'router.conf' via the 'port' definition.
1904 */
1905 CPU_no = hw->S514_cpu_no[0];
1906 slot_no = hw->S514_slot_no;
1907 auto_slot_cfg = hw->auto_pci_cfg;
1908
1909 if (auto_slot_cfg){
1910 printk(KERN_INFO "%s: srch... S514 card, CPU %c, Slot=Auto\n",
1911 modname, CPU_no);
1912
1913 }else{
1914 printk(KERN_INFO "%s: srch... S514 card, CPU %c, Slot #%d\n",
1915 modname, CPU_no, slot_no);
1916 }
1917
1918 /* check to see that CPU A or B has been selected in 'router.conf' */
1919 switch(CPU_no) {
1920 case S514_CPU_A:
1921 case S514_CPU_B:
1922 break;
1923
1924 default:
1925 printk(KERN_INFO "%s: S514 CPU definition invalid.\n",
1926 modname);
1927 printk(KERN_INFO "Must be 'A' or 'B'\n");
1928 return 0;
1929 }
1930
1931 number_S514_cards = find_s514_adapter(hw, 0);
1932 if(!number_S514_cards)
1933 return 0;
1934
1935 /* we are using a single S514 adapter with a slot of 0 so re-read the */
1936 /* location of this adapter */
1937 if((number_S514_cards == 1) && auto_slot_cfg) {
1938 number_S514_cards = find_s514_adapter(hw, 1);
1939 if(!number_S514_cards) {
1940 printk(KERN_INFO "%s: Error finding PCI card\n",
1941 modname);
1942 return 0;
1943 }
1944 }
1945
1946 pci_dev = hw->pci_dev;
1947 /* read the physical memory base address */
1948 S514_mem_base_addr = (CPU_no == S514_CPU_A) ?
1949 (pci_dev->resource[1].start) :
1950 (pci_dev->resource[2].start);
1951
1952 printk(KERN_INFO "%s: S514 PCI memory at 0x%X\n",
1953 modname, S514_mem_base_addr);
1954 if(!S514_mem_base_addr) {
1955 if(CPU_no == S514_CPU_B)
1956 printk(KERN_INFO "%s: CPU #B not present on the card\n", modname);
1957 else
1958 printk(KERN_INFO "%s: No PCI memory allocated to card\n", modname);
1959 return 0;
1960 }
1961
1962 /* enable the PCI memory */
1963 pci_read_config_dword(pci_dev,
1964 (CPU_no == S514_CPU_A) ? PCI_MAP0_DWORD : PCI_MAP1_DWORD,
1965 &ut_u32);
1966 pci_write_config_dword(pci_dev,
1967 (CPU_no == S514_CPU_A) ? PCI_MAP0_DWORD : PCI_MAP1_DWORD,
1968 (ut_u32 | PCI_MEMORY_ENABLE));
1969
1970 /* check the IRQ allocated and enable IRQ usage */
1971 if(!(hw->irq = pci_dev->irq)) {
1972 printk(KERN_INFO "%s: IRQ not allocated to S514 adapter\n",
1973 modname);
1974 return 0;
1975 }
1976
1977 /* BUG FIX : Mar 6 2000
1978 * On a initial loading of the card, we must check
1979 * and clear PCI interrupt bits, due to a reset
1980 * problem on some other boards. i.e. An interrupt
1981 * might be pending, even after system bootup,
1982 * in which case, when starting wanrouter the machine
1983 * would crash.
1984 */
1985 if (init_pci_slot(hw))
1986 return 0;
1987
1988 pci_read_config_dword(pci_dev, PCI_INT_CONFIG, &ut_u32);
1989 ut_u32 |= (CPU_no == S514_CPU_A) ?
1990 PCI_ENABLE_IRQ_CPU_A : PCI_ENABLE_IRQ_CPU_B;
1991 pci_write_config_dword(pci_dev, PCI_INT_CONFIG, ut_u32);
1992
1993 printk(KERN_INFO "%s: IRQ %d allocated to the S514 card\n",
1994 modname, hw->irq);
1995
1996 /* map the physical PCI memory to virtual memory */
1997 hw->dpmbase = ioremap((unsigned long)S514_mem_base_addr,
1998 (unsigned long)MAX_SIZEOF_S514_MEMORY);
1999 /* map the physical control register memory to virtual memory */
2000 hw->vector = (unsigned long)ioremap(
2001 (unsigned long)(S514_mem_base_addr + S514_CTRL_REG_BYTE),
2002 (unsigned long)16);
2003
2004 if(!hw->dpmbase || !hw->vector) {
2005 printk(KERN_INFO "%s: PCI virtual memory allocation failed\n",
2006 modname);
2007 return 0;
2008 }
2009
2010 /* halt the adapter */
2011 writeb (S514_CPU_HALT, hw->vector);
2012
2013 return 1;
2014}
2015
2016/*============================================================================
2017 * Find the S514 PCI adapter in the PCI bus.
2018 * Return the number of S514 adapters found (0 if no adapter found).
2019 */
2020static int find_s514_adapter(sdlahw_t* hw, char find_first_S514_card)
2021{
2022 unsigned char slot_no;
2023 int number_S514_cards = 0;
2024 char S514_found_in_slot = 0;
2025 u16 PCI_subsys_vendor;
2026
2027 struct pci_dev *pci_dev = NULL;
2028
2029 slot_no = hw->S514_slot_no;
2030
2031 while ((pci_dev = pci_find_device(V3_VENDOR_ID, V3_DEVICE_ID, pci_dev))
2032 != NULL) {
2033
2034 pci_read_config_word(pci_dev, PCI_SUBSYS_VENDOR_WORD,
2035 &PCI_subsys_vendor);
2036
2037 if(PCI_subsys_vendor != SANGOMA_SUBSYS_VENDOR)
2038 continue;
2039
2040 hw->pci_dev = pci_dev;
2041
2042 if(find_first_S514_card)
2043 return(1);
2044
2045 number_S514_cards ++;
2046
2047 printk(KERN_INFO
2048 "%s: S514 card found, slot #%d (devfn 0x%X)\n",
2049 modname, ((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK),
2050 pci_dev->devfn);
2051
2052 if (hw->auto_pci_cfg){
2053 hw->S514_slot_no = ((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK);
2054 slot_no = hw->S514_slot_no;
2055
2056 }else if (((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK) == slot_no){
2057 S514_found_in_slot = 1;
2058 break;
2059 }
2060 }
2061
2062 /* if no S514 adapter has been found, then exit */
2063 if (!number_S514_cards) {
2064 printk(KERN_INFO "%s: Error, no S514 adapters found\n", modname);
2065 return 0;
2066 }
2067 /* if more than one S514 card has been found, then the user must have */ /* defined a slot number so that the correct adapter is used */
2068 else if ((number_S514_cards > 1) && hw->auto_pci_cfg) {
2069 printk(KERN_INFO "%s: Error, PCI Slot autodetect Failed! \n"
2070 "%s: More than one S514 adapter found.\n"
2071 "%s: Disable the Autodetect feature and supply\n"
2072 "%s: the PCISLOT numbers for each card.\n",
2073 modname,modname,modname,modname);
2074 return 0;
2075 }
2076 /* if the user has specified a slot number and the S514 adapter has */
2077 /* not been found in that slot, then exit */
2078 else if (!hw->auto_pci_cfg && !S514_found_in_slot) {
2079 printk(KERN_INFO
2080 "%s: Error, S514 card not found in specified slot #%d\n",
2081 modname, slot_no);
2082 return 0;
2083 }
2084
2085 return (number_S514_cards);
2086}
2087
2088
2089
2090/******* Miscellaneous ******************************************************/
2091
2092/*============================================================================
2093 * Calibrate SDLA memory access delay.
2094 * Count number of idle loops made within 1 second and then calculate the
2095 * number of loops that should be made to achive desired delay.
2096 */
2097static int calibrate_delay (int mks)
2098{
2099 unsigned int delay;
2100 unsigned long stop;
2101
2102 for (delay = 0, stop = SYSTEM_TICK + HZ; SYSTEM_TICK < stop; ++delay);
2103 return (delay/(1000000L/mks) + 1);
2104}
2105
2106/*============================================================================
2107 * Get option's index into the options list.
2108 * Return option's index (1 .. N) or zero if option is invalid.
2109 */
2110static int get_option_index (unsigned* optlist, unsigned optval)
2111{
2112 int i;
2113
2114 for (i = 1; i <= optlist[0]; ++i)
2115 if ( optlist[i] == optval)
2116 return i;
2117 return 0;
2118}
2119
2120/*============================================================================
2121 * Check memory region to see if it's available.
2122 * Return: 0 ok.
2123 */
2124static unsigned check_memregion (void* ptr, unsigned len)
2125{
2126 volatile unsigned char* p = ptr;
2127
2128 for (; len && (readb (p) == 0xFF); --len, ++p) {
2129 writeb (0, p); /* attempt to write 0 */
2130 if (readb(p) != 0xFF) { /* still has to read 0xFF */
2131 writeb (0xFF, p);/* restore original value */
2132 break; /* not good */
2133 }
2134 }
2135
2136 return len;
2137}
2138
2139/*============================================================================
2140 * Test memory region.
2141 * Return: size of the region that passed the test.
2142 * Note: Region size must be multiple of 2 !
2143 */
2144static unsigned test_memregion (void* ptr, unsigned len)
2145{
2146 volatile unsigned short* w_ptr;
2147 unsigned len_w = len >> 1; /* region len in words */
2148 unsigned i;
2149
2150 for (i = 0, w_ptr = ptr; i < len_w; ++i, ++w_ptr)
2151 writew (0xAA55, w_ptr);
2152
2153 for (i = 0, w_ptr = ptr; i < len_w; ++i, ++w_ptr)
2154 if (readw (w_ptr) != 0xAA55) {
2155 len_w = i;
2156 break;
2157 }
2158
2159 for (i = 0, w_ptr = ptr; i < len_w; ++i, ++w_ptr)
2160 writew (0x55AA, w_ptr);
2161
2162 for (i = 0, w_ptr = ptr; i < len_w; ++i, ++w_ptr)
2163 if (readw(w_ptr) != 0x55AA) {
2164 len_w = i;
2165 break;
2166 }
2167
2168 for (i = 0, w_ptr = ptr; i < len_w; ++i, ++w_ptr)
2169 writew (0, w_ptr);
2170
2171 return len_w << 1;
2172}
2173
2174/*============================================================================
2175 * Calculate 16-bit CRC using CCITT polynomial.
2176 */
2177static unsigned short checksum (unsigned char* buf, unsigned len)
2178{
2179 unsigned short crc = 0;
2180 unsigned mask, flag;
2181
2182 for (; len; --len, ++buf) {
2183 for (mask = 0x80; mask; mask >>= 1) {
2184 flag = (crc & 0x8000);
2185 crc <<= 1;
2186 crc |= ((*buf & mask) ? 1 : 0);
2187 if (flag) crc ^= 0x1021;
2188 }
2189 }
2190 return crc;
2191}
2192
2193static int init_pci_slot(sdlahw_t *hw)
2194{
2195
2196 u32 int_status;
2197 int volatile found=0;
2198 int i=0;
2199
2200 /* Check if this is a very first load for a specific
2201 * pci card. If it is, clear the interrput bits, and
2202 * set the flag indicating that this card was initialized.
2203 */
2204
2205 for (i=0; (i<MAX_S514_CARDS) && !found; i++){
2206 if (pci_slot_ar[i] == hw->S514_slot_no){
2207 found=1;
2208 break;
2209 }
2210 if (pci_slot_ar[i] == 0xFF){
2211 break;
2212 }
2213 }
2214
2215 if (!found){
2216 read_S514_int_stat(hw,&int_status);
2217 S514_intack(hw,int_status);
2218 if (i == MAX_S514_CARDS){
2219 printk(KERN_INFO "%s: Critical Error !!!\n",modname);
2220 printk(KERN_INFO
2221 "%s: Number of Sangoma PCI cards exceeded maximum limit.\n",
2222 modname);
2223 printk(KERN_INFO "Please contact Sangoma Technologies\n");
2224 return 1;
2225 }
2226 pci_slot_ar[i] = hw->S514_slot_no;
2227 }
2228 return 0;
2229}
2230
2231static int pci_probe(sdlahw_t *hw)
2232{
2233
2234 unsigned char slot_no;
2235 int number_S514_cards = 0;
2236 u16 PCI_subsys_vendor;
2237 u16 PCI_card_type;
2238
2239 struct pci_dev *pci_dev = NULL;
2240 struct pci_bus *bus = NULL;
2241
2242 slot_no = 0;
2243
2244 while ((pci_dev = pci_find_device(V3_VENDOR_ID, V3_DEVICE_ID, pci_dev))
2245 != NULL) {
2246
2247 pci_read_config_word(pci_dev, PCI_SUBSYS_VENDOR_WORD,
2248 &PCI_subsys_vendor);
2249
2250 if(PCI_subsys_vendor != SANGOMA_SUBSYS_VENDOR)
2251 continue;
2252
2253 pci_read_config_word(pci_dev, PCI_CARD_TYPE,
2254 &PCI_card_type);
2255
2256 bus = pci_dev->bus;
2257
2258 /* A dual cpu card can support up to 4 physical connections,
2259 * where a single cpu card can support up to 2 physical
2260 * connections. The FT1 card can only support a single
2261 * connection, however we cannot distinguish between a Single
2262 * CPU card and an FT1 card. */
2263 if (PCI_card_type == S514_DUAL_CPU){
2264 number_S514_cards += 4;
2265 printk(KERN_INFO
2266 "wanpipe: S514-PCI card found, cpu(s) 2, bus #%d, slot #%d, irq #%d\n",
2267 bus->number,((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK),
2268 pci_dev->irq);
2269 }else{
2270 number_S514_cards += 2;
2271 printk(KERN_INFO
2272 "wanpipe: S514-PCI card found, cpu(s) 1, bus #%d, slot #%d, irq #%d\n",
2273 bus->number,((pci_dev->devfn >> 3) & PCI_DEV_SLOT_MASK),
2274 pci_dev->irq);
2275 }
2276 }
2277
2278 return number_S514_cards;
2279
2280}
2281
2282
2283
2284EXPORT_SYMBOL(wanpipe_hw_probe);
2285
2286unsigned wanpipe_hw_probe(void)
2287{
2288 sdlahw_t hw;
2289 unsigned* opt = s508_port_options;
2290 unsigned cardno=0;
2291 int i;
2292
2293 memset(&hw, 0, sizeof(hw));
2294
2295 for (i = 1; i <= opt[0]; i++) {
2296 if (detect_s508(opt[i])){
2297 /* S508 card can support up to two physical links */
2298 cardno+=2;
2299 printk(KERN_INFO "wanpipe: S508-ISA card found, port 0x%x\n",opt[i]);
2300 }
2301 }
2302
2303 #ifdef CONFIG_PCI
2304 hw.S514_slot_no = 0;
2305 cardno += pci_probe(&hw);
2306 #else
2307 printk(KERN_INFO "wanpipe: Warning, Kernel not compiled for PCI support!\n");
2308 printk(KERN_INFO "wanpipe: PCI Hardware Probe Failed!\n");
2309 #endif
2310
2311 return cardno;
2312}
2313
2314/****** End *****************************************************************/
diff --git a/drivers/net/wan/sdlamain.c b/drivers/net/wan/sdlamain.c
deleted file mode 100644
index 7a8b22a7ea31..000000000000
--- a/drivers/net/wan/sdlamain.c
+++ /dev/null
@@ -1,1346 +0,0 @@
1/****************************************************************************
2* sdlamain.c WANPIPE(tm) Multiprotocol WAN Link Driver. Main module.
3*
4* Author: Nenad Corbic <ncorbic@sangoma.com>
5* Gideon Hack
6*
7* Copyright: (c) 1995-2000 Sangoma Technologies Inc.
8*
9* This program is free software; you can redistribute it and/or
10* modify it under the terms of the GNU General Public License
11* as published by the Free Software Foundation; either version
12* 2 of the License, or (at your option) any later version.
13* ============================================================================
14* Dec 22, 2000 Nenad Corbic Updated for 2.4.X kernels.
15* Removed the polling routine.
16* Nov 13, 2000 Nenad Corbic Added hw probing on module load and dynamic
17* device allocation.
18* Nov 7, 2000 Nenad Corbic Fixed the Multi-Port PPP for kernels
19* 2.2.16 and above.
20* Aug 2, 2000 Nenad Corbic Block the Multi-Port PPP from running on
21* kernels 2.2.16 or greater. The SyncPPP
22* has changed.
23* Jul 25, 2000 Nenad Corbic Updated the Piggiback support for MultPPPP.
24* Jul 13, 2000 Nenad Corbic Added Multi-PPP support.
25* Feb 02, 2000 Nenad Corbic Fixed up piggyback probing and selection.
26* Sep 23, 1999 Nenad Corbic Added support for SMP
27* Sep 13, 1999 Nenad Corbic Each port is treated as a separate device.
28* Jun 02, 1999 Gideon Hack Added support for the S514 adapter.
29* Updates for Linux 2.2.X kernels.
30* Sep 17, 1998 Jaspreet Singh Updated for 2.1.121+ kernel
31* Nov 28, 1997 Jaspreet Singh Changed DRV_RELEASE to 1
32* Nov 10, 1997 Jaspreet Singh Changed sti() to restore_flags();
33* Nov 06, 1997 Jaspreet Singh Changed DRV_VERSION to 4 and DRV_RELEASE to 0
34* Oct 20, 1997 Jaspreet Singh Modified sdla_isr routine so that card->in_isr
35* assignments are taken out and placed in the
36* sdla_ppp.c, sdla_fr.c and sdla_x25.c isr
37* routines. Took out 'wandev->tx_int_enabled' and
38* replaced it with 'wandev->enable_tx_int'.
39* May 29, 1997 Jaspreet Singh Flow Control Problem
40* added "wandev->tx_int_enabled=1" line in the
41* init module. This line initializes the flag for
42* preventing Interrupt disabled with device set to
43* busy
44* Jan 15, 1997 Gene Kozin Version 3.1.0
45* o added UDP management stuff
46* Jan 02, 1997 Gene Kozin Initial version.
47*****************************************************************************/
48
49#include <linux/config.h> /* OS configuration options */
50#include <linux/stddef.h> /* offsetof(), etc. */
51#include <linux/errno.h> /* return codes */
52#include <linux/string.h> /* inline memset(), etc. */
53#include <linux/init.h>
54#include <linux/slab.h> /* kmalloc(), kfree() */
55#include <linux/kernel.h> /* printk(), and other useful stuff */
56#include <linux/module.h> /* support for loadable modules */
57#include <linux/ioport.h> /* request_region(), release_region() */
58#include <linux/wanrouter.h> /* WAN router definitions */
59#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
60#include <linux/rcupdate.h>
61
62#include <linux/in.h>
63#include <asm/io.h> /* phys_to_virt() */
64#include <linux/pci.h>
65#include <linux/sdlapci.h>
66#include <linux/if_wanpipe_common.h>
67
68#include <asm/uaccess.h> /* kernel <-> user copy */
69#include <linux/inetdevice.h>
70
71#include <linux/ip.h>
72#include <net/route.h>
73
74#define KMEM_SAFETYZONE 8
75
76
77#ifndef CONFIG_WANPIPE_FR
78 #define wpf_init(a,b) (-EPROTONOSUPPORT)
79#endif
80
81#ifndef CONFIG_WANPIPE_CHDLC
82 #define wpc_init(a,b) (-EPROTONOSUPPORT)
83#endif
84
85#ifndef CONFIG_WANPIPE_X25
86 #define wpx_init(a,b) (-EPROTONOSUPPORT)
87#endif
88
89#ifndef CONFIG_WANPIPE_PPP
90 #define wpp_init(a,b) (-EPROTONOSUPPORT)
91#endif
92
93#ifndef CONFIG_WANPIPE_MULTPPP
94 #define wsppp_init(a,b) (-EPROTONOSUPPORT)
95#endif
96
97
98/***********FOR DEBUGGING PURPOSES*********************************************
99static void * dbg_kmalloc(unsigned int size, int prio, int line) {
100 int i = 0;
101 void * v = kmalloc(size+sizeof(unsigned int)+2*KMEM_SAFETYZONE*8,prio);
102 char * c1 = v;
103 c1 += sizeof(unsigned int);
104 *((unsigned int *)v) = size;
105
106 for (i = 0; i < KMEM_SAFETYZONE; i++) {
107 c1[0] = 'D'; c1[1] = 'E'; c1[2] = 'A'; c1[3] = 'D';
108 c1[4] = 'B'; c1[5] = 'E'; c1[6] = 'E'; c1[7] = 'F';
109 c1 += 8;
110 }
111 c1 += size;
112 for (i = 0; i < KMEM_SAFETYZONE; i++) {
113 c1[0] = 'M'; c1[1] = 'U'; c1[2] = 'N'; c1[3] = 'G';
114 c1[4] = 'W'; c1[5] = 'A'; c1[6] = 'L'; c1[7] = 'L';
115 c1 += 8;
116 }
117 v = ((char *)v) + sizeof(unsigned int) + KMEM_SAFETYZONE*8;
118 printk(KERN_INFO "line %d kmalloc(%d,%d) = %p\n",line,size,prio,v);
119 return v;
120}
121static void dbg_kfree(void * v, int line) {
122 unsigned int * sp = (unsigned int *)(((char *)v) - (sizeof(unsigned int) + KMEM_SAFETYZONE*8));
123 unsigned int size = *sp;
124 char * c1 = ((char *)v) - KMEM_SAFETYZONE*8;
125 int i = 0;
126 for (i = 0; i < KMEM_SAFETYZONE; i++) {
127 if ( c1[0] != 'D' || c1[1] != 'E' || c1[2] != 'A' || c1[3] != 'D'
128 || c1[4] != 'B' || c1[5] != 'E' || c1[6] != 'E' || c1[7] != 'F') {
129 printk(KERN_INFO "kmalloced block at %p has been corrupted (underrun)!\n",v);
130 printk(KERN_INFO " %4x: %2x %2x %2x %2x %2x %2x %2x %2x\n", i*8,
131 c1[0],c1[1],c1[2],c1[3],c1[4],c1[5],c1[6],c1[7] );
132 }
133 c1 += 8;
134 }
135 c1 += size;
136 for (i = 0; i < KMEM_SAFETYZONE; i++) {
137 if ( c1[0] != 'M' || c1[1] != 'U' || c1[2] != 'N' || c1[3] != 'G'
138 || c1[4] != 'W' || c1[5] != 'A' || c1[6] != 'L' || c1[7] != 'L'
139 ) {
140 printk(KERN_INFO "kmalloced block at %p has been corrupted (overrun):\n",v);
141 printk(KERN_INFO " %4x: %2x %2x %2x %2x %2x %2x %2x %2x\n", i*8,
142 c1[0],c1[1],c1[2],c1[3],c1[4],c1[5],c1[6],c1[7] );
143 }
144 c1 += 8;
145 }
146 printk(KERN_INFO "line %d kfree(%p)\n",line,v);
147 v = ((char *)v) - (sizeof(unsigned int) + KMEM_SAFETYZONE*8);
148 kfree(v);
149}
150
151#define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
152#define kfree(x) dbg_kfree(x,__LINE__)
153******************************************************************************/
154
155
156
157/****** Defines & Macros ****************************************************/
158
159#ifdef _DEBUG_
160#define STATIC
161#else
162#define STATIC static
163#endif
164
165#define DRV_VERSION 5 /* version number */
166#define DRV_RELEASE 0 /* release (minor version) number */
167#define MAX_CARDS 16 /* max number of adapters */
168
169#ifndef CONFIG_WANPIPE_CARDS /* configurable option */
170#define CONFIG_WANPIPE_CARDS 1
171#endif
172
173#define CMD_OK 0 /* normal firmware return code */
174#define CMD_TIMEOUT 0xFF /* firmware command timed out */
175#define MAX_CMD_RETRY 10 /* max number of firmware retries */
176/****** Function Prototypes *************************************************/
177
178extern void disable_irq(unsigned int);
179extern void enable_irq(unsigned int);
180
181/* WAN link driver entry points */
182static int setup(struct wan_device* wandev, wandev_conf_t* conf);
183static int shutdown(struct wan_device* wandev);
184static int ioctl(struct wan_device* wandev, unsigned cmd, unsigned long arg);
185
186/* IOCTL handlers */
187static int ioctl_dump (sdla_t* card, sdla_dump_t* u_dump);
188static int ioctl_exec (sdla_t* card, sdla_exec_t* u_exec, int);
189
190/* Miscellaneous functions */
191STATIC irqreturn_t sdla_isr (int irq, void* dev_id, struct pt_regs *regs);
192static void release_hw (sdla_t *card);
193
194static int check_s508_conflicts (sdla_t* card,wandev_conf_t* conf, int*);
195static int check_s514_conflicts (sdla_t* card,wandev_conf_t* conf, int*);
196
197
198/****** Global Data **********************************************************
199 * Note: All data must be explicitly initialized!!!
200 */
201
202/* private data */
203static char drvname[] = "wanpipe";
204static char fullname[] = "WANPIPE(tm) Multiprotocol Driver";
205static char copyright[] = "(c) 1995-2000 Sangoma Technologies Inc.";
206static int ncards;
207static sdla_t* card_array; /* adapter data space */
208
209/* Wanpipe's own workqueue, used for all API's.
210 * All protocol specific tasks will be inserted
211 * into the "wanpipe_wq" workqueue.
212
213 * The kernel workqueue mechanism will execute
214 * all pending tasks in the "wanpipe_wq" workqueue.
215 */
216
217struct workqueue_struct *wanpipe_wq;
218DECLARE_WORK(wanpipe_work, NULL, NULL);
219
220static int wanpipe_bh_critical;
221
222/******* Kernel Loadable Module Entry Points ********************************/
223
224/*============================================================================
225 * Module 'insert' entry point.
226 * o print announcement
227 * o allocate adapter data space
228 * o initialize static data
229 * o register all cards with WAN router
230 * o calibrate SDLA shared memory access delay.
231 *
232 * Return: 0 Ok
233 * < 0 error.
234 * Context: process
235 */
236
237static int __init wanpipe_init(void)
238{
239 int cnt, err = 0;
240
241 printk(KERN_INFO "%s v%u.%u %s\n",
242 fullname, DRV_VERSION, DRV_RELEASE, copyright);
243
244 wanpipe_wq = create_workqueue("wanpipe_wq");
245 if (!wanpipe_wq)
246 return -ENOMEM;
247
248 /* Probe for wanpipe cards and return the number found */
249 printk(KERN_INFO "wanpipe: Probing for WANPIPE hardware.\n");
250 ncards = wanpipe_hw_probe();
251 if (ncards){
252 printk(KERN_INFO "wanpipe: Allocating maximum %i devices: wanpipe%i - wanpipe%i.\n",ncards,1,ncards);
253 }else{
254 printk(KERN_INFO "wanpipe: No S514/S508 cards found, unloading modules!\n");
255 destroy_workqueue(wanpipe_wq);
256 return -ENODEV;
257 }
258
259 /* Verify number of cards and allocate adapter data space */
260 card_array = kmalloc(sizeof(sdla_t) * ncards, GFP_KERNEL);
261 if (card_array == NULL) {
262 destroy_workqueue(wanpipe_wq);
263 return -ENOMEM;
264 }
265
266 memset(card_array, 0, sizeof(sdla_t) * ncards);
267
268 /* Register adapters with WAN router */
269 for (cnt = 0; cnt < ncards; ++ cnt) {
270 sdla_t* card = &card_array[cnt];
271 struct wan_device* wandev = &card->wandev;
272
273 card->next = NULL;
274 sprintf(card->devname, "%s%d", drvname, cnt + 1);
275 wandev->magic = ROUTER_MAGIC;
276 wandev->name = card->devname;
277 wandev->private = card;
278 wandev->enable_tx_int = 0;
279 wandev->setup = &setup;
280 wandev->shutdown = &shutdown;
281 wandev->ioctl = &ioctl;
282 err = register_wan_device(wandev);
283 if (err) {
284 printk(KERN_INFO
285 "%s: %s registration failed with error %d!\n",
286 drvname, card->devname, err);
287 break;
288 }
289 }
290 if (cnt){
291 ncards = cnt; /* adjust actual number of cards */
292 }else {
293 kfree(card_array);
294 destroy_workqueue(wanpipe_wq);
295 printk(KERN_INFO "IN Init Module: NO Cards registered\n");
296 err = -ENODEV;
297 }
298
299 return err;
300}
301
302/*============================================================================
303 * Module 'remove' entry point.
304 * o unregister all adapters from the WAN router
305 * o release all remaining system resources
306 */
307static void __exit wanpipe_cleanup(void)
308{
309 int i;
310
311 if (!ncards)
312 return;
313
314 for (i = 0; i < ncards; ++i) {
315 sdla_t* card = &card_array[i];
316 unregister_wan_device(card->devname);
317 }
318 destroy_workqueue(wanpipe_wq);
319 kfree(card_array);
320
321 printk(KERN_INFO "\nwanpipe: WANPIPE Modules Unloaded.\n");
322}
323
324module_init(wanpipe_init);
325module_exit(wanpipe_cleanup);
326
327/******* WAN Device Driver Entry Points *************************************/
328
329/*============================================================================
330 * Setup/configure WAN link driver.
331 * o check adapter state
332 * o make sure firmware is present in configuration
333 * o make sure I/O port and IRQ are specified
334 * o make sure I/O region is available
335 * o allocate interrupt vector
336 * o setup SDLA hardware
337 * o call appropriate routine to perform protocol-specific initialization
338 * o mark I/O region as used
339 * o if this is the first active card, then schedule background task
340 *
341 * This function is called when router handles ROUTER_SETUP IOCTL. The
342 * configuration structure is in kernel memory (including extended data, if
343 * any).
344 */
345
346static int setup(struct wan_device* wandev, wandev_conf_t* conf)
347{
348 sdla_t* card;
349 int err = 0;
350 int irq=0;
351
352 /* Sanity checks */
353 if ((wandev == NULL) || (wandev->private == NULL) || (conf == NULL)){
354 printk(KERN_INFO
355 "%s: Failed Sdlamain Setup wandev %u, card %u, conf %u !\n",
356 wandev->name,
357 (unsigned int)wandev,(unsigned int)wandev->private,
358 (unsigned int)conf);
359 return -EFAULT;
360 }
361
362 printk(KERN_INFO "%s: Starting WAN Setup\n", wandev->name);
363
364 card = wandev->private;
365 if (wandev->state != WAN_UNCONFIGURED){
366 printk(KERN_INFO "%s: failed sdlamain setup, busy!\n",
367 wandev->name);
368 return -EBUSY; /* already configured */
369 }
370
371 printk(KERN_INFO "\nProcessing WAN device %s...\n", wandev->name);
372
373 /* Initialize the counters for each wandev
374 * Used for counting number of times new_if and
375 * del_if get called.
376 */
377 wandev->del_if_cnt = 0;
378 wandev->new_if_cnt = 0;
379 wandev->config_id = conf->config_id;
380
381 if (!conf->data_size || (conf->data == NULL)) {
382 printk(KERN_INFO
383 "%s: firmware not found in configuration data!\n",
384 wandev->name);
385 return -EINVAL;
386 }
387
388 /* Check for resource conflicts and setup the
389 * card for piggibacking if necessary */
390 if(!conf->S514_CPU_no[0]) {
391 if ((err=check_s508_conflicts(card,conf,&irq)) != 0){
392 return err;
393 }
394 }else {
395 if ((err=check_s514_conflicts(card,conf,&irq)) != 0){
396 return err;
397 }
398 }
399
400 /* If the current card has already been configured
401 * or it's a piggyback card, do not try to allocate
402 * resources.
403 */
404 if (!card->wandev.piggyback && !card->configured){
405
406 /* Configure hardware, load firmware, etc. */
407 memset(&card->hw, 0, sizeof(sdlahw_t));
408
409 /* for an S514 adapter, pass the CPU number and the slot number read */
410 /* from 'router.conf' to the 'sdla_setup()' function via the 'port' */
411 /* parameter */
412 if (conf->S514_CPU_no[0]){
413
414 card->hw.S514_cpu_no[0] = conf->S514_CPU_no[0];
415 card->hw.S514_slot_no = conf->PCI_slot_no;
416 card->hw.auto_pci_cfg = conf->auto_pci_cfg;
417
418 if (card->hw.auto_pci_cfg == WANOPT_YES){
419 printk(KERN_INFO "%s: Setting CPU to %c and Slot to Auto\n",
420 card->devname, card->hw.S514_cpu_no[0]);
421 }else{
422 printk(KERN_INFO "%s: Setting CPU to %c and Slot to %i\n",
423 card->devname, card->hw.S514_cpu_no[0], card->hw.S514_slot_no);
424 }
425
426 }else{
427 /* 508 Card io port and irq initialization */
428 card->hw.port = conf->ioport;
429 card->hw.irq = (conf->irq == 9) ? 2 : conf->irq;
430 }
431
432
433 /* Compute the virtual address of the card in kernel space */
434 if(conf->maddr){
435 card->hw.dpmbase = phys_to_virt(conf->maddr);
436 }else{
437 card->hw.dpmbase = (void *)conf->maddr;
438 }
439
440 card->hw.dpmsize = SDLA_WINDOWSIZE;
441
442 /* set the adapter type if using an S514 adapter */
443 card->hw.type = (conf->S514_CPU_no[0]) ? SDLA_S514 : conf->hw_opt[0];
444 card->hw.pclk = conf->hw_opt[1];
445
446 err = sdla_setup(&card->hw, conf->data, conf->data_size);
447 if (err){
448 printk(KERN_INFO "%s: Hardware setup Failed %i\n",
449 card->devname,err);
450 return err;
451 }
452
453 if(card->hw.type != SDLA_S514)
454 irq = (conf->irq == 2) ? 9 : conf->irq; /* IRQ2 -> IRQ9 */
455 else
456 irq = card->hw.irq;
457
458 /* request an interrupt vector - note that interrupts may be shared */
459 /* when using the S514 PCI adapter */
460
461 if(request_irq(irq, sdla_isr,
462 (card->hw.type == SDLA_S514) ? SA_SHIRQ : 0,
463 wandev->name, card)){
464
465 printk(KERN_INFO "%s: Can't reserve IRQ %d!\n", wandev->name, irq);
466 return -EINVAL;
467 }
468
469 }else{
470 printk(KERN_INFO "%s: Card Configured %lu or Piggybacking %i!\n",
471 wandev->name,card->configured,card->wandev.piggyback);
472 }
473
474
475 if (!card->configured){
476
477 /* Initialize the Spin lock */
478 printk(KERN_INFO "%s: Initializing for SMP\n",wandev->name);
479
480 /* Piggyback spin lock has already been initialized,
481 * in check_s514/s508_conflicts() */
482 if (!card->wandev.piggyback){
483 spin_lock_init(&card->wandev.lock);
484 }
485
486 /* Intialize WAN device data space */
487 wandev->irq = irq;
488 wandev->dma = 0;
489 if(card->hw.type != SDLA_S514){
490 wandev->ioport = card->hw.port;
491 }else{
492 wandev->S514_cpu_no[0] = card->hw.S514_cpu_no[0];
493 wandev->S514_slot_no = card->hw.S514_slot_no;
494 }
495 wandev->maddr = (unsigned long)card->hw.dpmbase;
496 wandev->msize = card->hw.dpmsize;
497 wandev->hw_opt[0] = card->hw.type;
498 wandev->hw_opt[1] = card->hw.pclk;
499 wandev->hw_opt[2] = card->hw.memory;
500 wandev->hw_opt[3] = card->hw.fwid;
501 }
502
503 /* Protocol-specific initialization */
504 switch (card->hw.fwid) {
505
506 case SFID_X25_502:
507 case SFID_X25_508:
508 printk(KERN_INFO "%s: Starting X.25 Protocol Init.\n",
509 card->devname);
510 err = wpx_init(card, conf);
511 break;
512 case SFID_FR502:
513 case SFID_FR508:
514 printk(KERN_INFO "%s: Starting Frame Relay Protocol Init.\n",
515 card->devname);
516 err = wpf_init(card, conf);
517 break;
518 case SFID_PPP502:
519 case SFID_PPP508:
520 printk(KERN_INFO "%s: Starting PPP Protocol Init.\n",
521 card->devname);
522 err = wpp_init(card, conf);
523 break;
524
525 case SFID_CHDLC508:
526 case SFID_CHDLC514:
527 if (conf->ft1){
528 printk(KERN_INFO "%s: Starting FT1 CSU/DSU Config Driver.\n",
529 card->devname);
530 err = wpft1_init(card, conf);
531 break;
532
533 }else if (conf->config_id == WANCONFIG_MPPP){
534 printk(KERN_INFO "%s: Starting Multi-Port PPP Protocol Init.\n",
535 card->devname);
536 err = wsppp_init(card,conf);
537 break;
538
539 }else{
540 printk(KERN_INFO "%s: Starting CHDLC Protocol Init.\n",
541 card->devname);
542 err = wpc_init(card, conf);
543 break;
544 }
545 default:
546 printk(KERN_INFO "%s: Error, Firmware is not supported %X %X!\n",
547 wandev->name,card->hw.fwid,SFID_CHDLC508);
548 err = -EPROTONOSUPPORT;
549 }
550
551 if (err != 0){
552 if (err == -EPROTONOSUPPORT){
553 printk(KERN_INFO
554 "%s: Error, Protocol selected has not been compiled!\n",
555 card->devname);
556 printk(KERN_INFO
557 "%s: Re-configure the kernel and re-build the modules!\n",
558 card->devname);
559 }
560
561 release_hw(card);
562 wandev->state = WAN_UNCONFIGURED;
563 return err;
564 }
565
566
567 /* Reserve I/O region and schedule background task */
568 if(card->hw.type != SDLA_S514 && !card->wandev.piggyback)
569 if (!request_region(card->hw.port, card->hw.io_range,
570 wandev->name)) {
571 printk(KERN_WARNING "port 0x%04x busy\n", card->hw.port);
572 release_hw(card);
573 wandev->state = WAN_UNCONFIGURED;
574 return -EBUSY;
575 }
576
577 /* Only use the polling routine for the X25 protocol */
578
579 card->wandev.critical=0;
580 return 0;
581}
582
583/*==================================================================
584 * configure_s508_card
585 *
586 * For a S508 adapter, check for a possible configuration error in that
587 * we are loading an adapter in the same IO port as a previously loaded S508
588 * card.
589 */
590
591static int check_s508_conflicts (sdla_t* card,wandev_conf_t* conf, int *irq)
592{
593 unsigned long smp_flags;
594 int i;
595
596 if (conf->ioport <= 0) {
597 printk(KERN_INFO
598 "%s: can't configure without I/O port address!\n",
599 card->wandev.name);
600 return -EINVAL;
601 }
602
603 if (conf->irq <= 0) {
604 printk(KERN_INFO "%s: can't configure without IRQ!\n",
605 card->wandev.name);
606 return -EINVAL;
607 }
608
609 if (test_bit(0,&card->configured))
610 return 0;
611
612
613 /* Check for already loaded card with the same IO port and IRQ
614 * If found, copy its hardware configuration and use its
615 * resources (i.e. piggybacking)
616 */
617
618 for (i = 0; i < ncards; i++) {
619 sdla_t *nxt_card = &card_array[i];
620
621 /* Skip the current card ptr */
622 if (nxt_card == card)
623 continue;
624
625
626 /* Find a card that is already configured with the
627 * same IO Port */
628 if ((nxt_card->hw.type == SDLA_S508) &&
629 (nxt_card->hw.port == conf->ioport) &&
630 (nxt_card->next == NULL)){
631
632 /* We found a card the card that has same configuration
633 * as us. This means, that we must setup this card in
634 * piggibacking mode. However, only CHDLC and MPPP protocol
635 * support this setup */
636
637 if ((conf->config_id == WANCONFIG_CHDLC ||
638 conf->config_id == WANCONFIG_MPPP) &&
639 (nxt_card->wandev.config_id == WANCONFIG_CHDLC ||
640 nxt_card->wandev.config_id == WANCONFIG_MPPP)){
641
642 *irq = nxt_card->hw.irq;
643 memcpy(&card->hw, &nxt_card->hw, sizeof(sdlahw_t));
644
645 /* The master could already be running, we must
646 * set this as a critical area */
647 lock_adapter_irq(&nxt_card->wandev.lock, &smp_flags);
648
649 nxt_card->next = card;
650 card->next = nxt_card;
651
652 card->wandev.piggyback = WANOPT_YES;
653
654 /* We must initialise the piggiback spin lock here
655 * since isr will try to lock card->next if it
656 * exists */
657 spin_lock_init(&card->wandev.lock);
658
659 unlock_adapter_irq(&nxt_card->wandev.lock, &smp_flags);
660 break;
661 }else{
662 /* Trying to run piggibacking with a wrong protocol */
663 printk(KERN_INFO "%s: ERROR: Resource busy, ioport: 0x%x\n"
664 "%s: This protocol doesn't support\n"
665 "%s: multi-port operation!\n",
666 card->devname,nxt_card->hw.port,
667 card->devname,card->devname);
668 return -EEXIST;
669 }
670 }
671 }
672
673
674 /* Make sure I/O port region is available only if we are the
675 * master device. If we are running in piggybacking mode,
676 * we will use the resources of the master card. */
677 if (!card->wandev.piggyback) {
678 struct resource *rr =
679 request_region(conf->ioport, SDLA_MAXIORANGE, "sdlamain");
680 release_region(conf->ioport, SDLA_MAXIORANGE);
681
682 if (!rr) {
683 printk(KERN_INFO
684 "%s: I/O region 0x%X - 0x%X is in use!\n",
685 card->wandev.name, conf->ioport,
686 conf->ioport + SDLA_MAXIORANGE - 1);
687 return -EINVAL;
688 }
689 }
690
691 return 0;
692}
693
694/*==================================================================
695 * configure_s514_card
696 *
697 * For a S514 adapter, check for a possible configuration error in that
698 * we are loading an adapter in the same slot as a previously loaded S514
699 * card.
700 */
701
702
703static int check_s514_conflicts(sdla_t* card,wandev_conf_t* conf, int *irq)
704{
705 unsigned long smp_flags;
706 int i;
707
708 if (test_bit(0,&card->configured))
709 return 0;
710
711
712 /* Check for already loaded card with the same IO port and IRQ
713 * If found, copy its hardware configuration and use its
714 * resources (i.e. piggybacking)
715 */
716
717 for (i = 0; i < ncards; i ++) {
718
719 sdla_t* nxt_card = &card_array[i];
720 if(nxt_card == card)
721 continue;
722
723 if((nxt_card->hw.type == SDLA_S514) &&
724 (nxt_card->hw.S514_slot_no == conf->PCI_slot_no) &&
725 (nxt_card->hw.S514_cpu_no[0] == conf->S514_CPU_no[0])&&
726 (nxt_card->next == NULL)){
727
728
729 if ((conf->config_id == WANCONFIG_CHDLC ||
730 conf->config_id == WANCONFIG_MPPP) &&
731 (nxt_card->wandev.config_id == WANCONFIG_CHDLC ||
732 nxt_card->wandev.config_id == WANCONFIG_MPPP)){
733
734 *irq = nxt_card->hw.irq;
735 memcpy(&card->hw, &nxt_card->hw, sizeof(sdlahw_t));
736
737 /* The master could already be running, we must
738 * set this as a critical area */
739 lock_adapter_irq(&nxt_card->wandev.lock,&smp_flags);
740 nxt_card->next = card;
741 card->next = nxt_card;
742
743 card->wandev.piggyback = WANOPT_YES;
744
745 /* We must initialise the piggiback spin lock here
746 * since isr will try to lock card->next if it
747 * exists */
748 spin_lock_init(&card->wandev.lock);
749
750 unlock_adapter_irq(&nxt_card->wandev.lock,&smp_flags);
751
752 }else{
753 /* Trying to run piggibacking with a wrong protocol */
754 printk(KERN_INFO "%s: ERROR: Resource busy: CPU %c PCISLOT %i\n"
755 "%s: This protocol doesn't support\n"
756 "%s: multi-port operation!\n",
757 card->devname,
758 conf->S514_CPU_no[0],conf->PCI_slot_no,
759 card->devname,card->devname);
760 return -EEXIST;
761 }
762 }
763 }
764
765 return 0;
766}
767
768
769
770/*============================================================================
771 * Shut down WAN link driver.
772 * o shut down adapter hardware
773 * o release system resources.
774 *
775 * This function is called by the router when device is being unregistered or
776 * when it handles ROUTER_DOWN IOCTL.
777 */
778static int shutdown(struct wan_device* wandev)
779{
780 sdla_t *card;
781 int err=0;
782
783 /* sanity checks */
784 if ((wandev == NULL) || (wandev->private == NULL)){
785 return -EFAULT;
786 }
787
788 if (wandev->state == WAN_UNCONFIGURED){
789 return 0;
790 }
791
792 card = wandev->private;
793
794 if (card->tty_opt){
795 if (card->tty_open){
796 printk(KERN_INFO
797 "%s: Shutdown Failed: TTY is still open\n",
798 card->devname);
799 return -EBUSY;
800 }
801 }
802
803 wandev->state = WAN_UNCONFIGURED;
804
805 set_bit(PERI_CRIT,(void*)&wandev->critical);
806
807 /* In case of piggibacking, make sure that
808 * we never try to shutdown both devices at the same
809 * time, because they depend on one another */
810
811 if (card->disable_comm){
812 card->disable_comm(card);
813 }
814
815 /* Release Resources */
816 release_hw(card);
817
818 /* only free the allocated I/O range if not an S514 adapter */
819 if (wandev->hw_opt[0] != SDLA_S514 && !card->configured){
820 release_region(card->hw.port, card->hw.io_range);
821 }
822
823 if (!card->configured){
824 memset(&card->hw, 0, sizeof(sdlahw_t));
825 if (card->next){
826 memset(&card->next->hw, 0, sizeof(sdlahw_t));
827 }
828 }
829
830
831 clear_bit(PERI_CRIT,(void*)&wandev->critical);
832 return err;
833}
834
835static void release_hw (sdla_t *card)
836{
837 sdla_t *nxt_card;
838
839
840 /* Check if next device exists */
841 if (card->next){
842 nxt_card = card->next;
843 /* If next device is down then release resources */
844 if (nxt_card->wandev.state == WAN_UNCONFIGURED){
845 if (card->wandev.piggyback){
846 /* If this device is piggyback then use
847 * information of the master device
848 */
849 printk(KERN_INFO "%s: Piggyback shutting down\n",card->devname);
850 sdla_down(&card->next->hw);
851 free_irq(card->wandev.irq, card->next);
852 card->configured = 0;
853 card->next->configured = 0;
854 card->wandev.piggyback = 0;
855 }else{
856 /* Master device shutting down */
857 printk(KERN_INFO "%s: Master shutting down\n",card->devname);
858 sdla_down(&card->hw);
859 free_irq(card->wandev.irq, card);
860 card->configured = 0;
861 card->next->configured = 0;
862 }
863 }else{
864 printk(KERN_INFO "%s: Device still running %i\n",
865 nxt_card->devname,nxt_card->wandev.state);
866
867 card->configured = 1;
868 }
869 }else{
870 printk(KERN_INFO "%s: Master shutting down\n",card->devname);
871 sdla_down(&card->hw);
872 free_irq(card->wandev.irq, card);
873 card->configured = 0;
874 }
875 return;
876}
877
878
879/*============================================================================
880 * Driver I/O control.
881 * o verify arguments
882 * o perform requested action
883 *
884 * This function is called when router handles one of the reserved user
885 * IOCTLs. Note that 'arg' stil points to user address space.
886 */
887static int ioctl(struct wan_device* wandev, unsigned cmd, unsigned long arg)
888{
889 sdla_t* card;
890 int err;
891
892 /* sanity checks */
893 if ((wandev == NULL) || (wandev->private == NULL))
894 return -EFAULT;
895 if (wandev->state == WAN_UNCONFIGURED)
896 return -ENODEV;
897
898 card = wandev->private;
899
900 if(card->hw.type != SDLA_S514){
901 disable_irq(card->hw.irq);
902 }
903
904 if (test_bit(SEND_CRIT, (void*)&wandev->critical)) {
905 return -EAGAIN;
906 }
907
908 switch (cmd) {
909 case WANPIPE_DUMP:
910 err = ioctl_dump(wandev->private, (void*)arg);
911 break;
912
913 case WANPIPE_EXEC:
914 err = ioctl_exec(wandev->private, (void*)arg, cmd);
915 break;
916 default:
917 err = -EINVAL;
918 }
919
920 return err;
921}
922
923/****** Driver IOCTL Handlers ***********************************************/
924
925/*============================================================================
926 * Dump adapter memory to user buffer.
927 * o verify request structure
928 * o copy request structure to kernel data space
929 * o verify length/offset
930 * o verify user buffer
931 * o copy adapter memory image to user buffer
932 *
933 * Note: when dumping memory, this routine switches curent dual-port memory
934 * vector, so care must be taken to avoid racing conditions.
935 */
936static int ioctl_dump (sdla_t* card, sdla_dump_t* u_dump)
937{
938 sdla_dump_t dump;
939 unsigned winsize;
940 unsigned long oldvec; /* DPM window vector */
941 unsigned long smp_flags;
942 int err = 0;
943
944 if(copy_from_user((void*)&dump, (void*)u_dump, sizeof(sdla_dump_t)))
945 return -EFAULT;
946
947 if ((dump.magic != WANPIPE_MAGIC) ||
948 (dump.offset + dump.length > card->hw.memory))
949 return -EINVAL;
950
951 winsize = card->hw.dpmsize;
952
953 if(card->hw.type != SDLA_S514) {
954
955 lock_adapter_irq(&card->wandev.lock, &smp_flags);
956
957 oldvec = card->hw.vector;
958 while (dump.length) {
959 /* current offset */
960 unsigned pos = dump.offset % winsize;
961 /* current vector */
962 unsigned long vec = dump.offset - pos;
963 unsigned len = (dump.length > (winsize - pos)) ?
964 (winsize - pos) : dump.length;
965 /* relocate window */
966 if (sdla_mapmem(&card->hw, vec) != 0) {
967 err = -EIO;
968 break;
969 }
970
971 if(copy_to_user((void *)dump.ptr,
972 (u8 *)card->hw.dpmbase + pos, len)){
973
974 unlock_adapter_irq(&card->wandev.lock, &smp_flags);
975 return -EFAULT;
976 }
977
978 dump.length -= len;
979 dump.offset += len;
980 dump.ptr = (char*)dump.ptr + len;
981 }
982
983 sdla_mapmem(&card->hw, oldvec);/* restore DPM window position */
984 unlock_adapter_irq(&card->wandev.lock, &smp_flags);
985
986 }else {
987
988 if(copy_to_user((void *)dump.ptr,
989 (u8 *)card->hw.dpmbase + dump.offset, dump.length)){
990 return -EFAULT;
991 }
992 }
993
994 return err;
995}
996
997/*============================================================================
998 * Execute adapter firmware command.
999 * o verify request structure
1000 * o copy request structure to kernel data space
1001 * o call protocol-specific 'exec' function
1002 */
1003static int ioctl_exec (sdla_t* card, sdla_exec_t* u_exec, int cmd)
1004{
1005 sdla_exec_t exec;
1006 int err=0;
1007
1008 if (card->exec == NULL && cmd == WANPIPE_EXEC){
1009 return -ENODEV;
1010 }
1011
1012 if(copy_from_user((void*)&exec, (void*)u_exec, sizeof(sdla_exec_t)))
1013 return -EFAULT;
1014
1015 if ((exec.magic != WANPIPE_MAGIC) || (exec.cmd == NULL))
1016 return -EINVAL;
1017
1018 switch (cmd) {
1019 case WANPIPE_EXEC:
1020 err = card->exec(card, exec.cmd, exec.data);
1021 break;
1022 }
1023 return err;
1024}
1025
1026/******* Miscellaneous ******************************************************/
1027
1028/*============================================================================
1029 * SDLA Interrupt Service Routine.
1030 * o acknowledge SDLA hardware interrupt.
1031 * o call protocol-specific interrupt service routine, if any.
1032 */
1033STATIC irqreturn_t sdla_isr (int irq, void* dev_id, struct pt_regs *regs)
1034{
1035#define card ((sdla_t*)dev_id)
1036
1037 if(card->hw.type == SDLA_S514) { /* handle interrrupt on S514 */
1038 u32 int_status;
1039 unsigned char CPU_no = card->hw.S514_cpu_no[0];
1040 unsigned char card_found_for_IRQ;
1041 u8 IRQ_count = 0;
1042
1043 for(;;) {
1044
1045 read_S514_int_stat(&card->hw, &int_status);
1046
1047 /* check if the interrupt is for this device */
1048 if(!((unsigned char)int_status &
1049 (IRQ_CPU_A | IRQ_CPU_B)))
1050 return IRQ_HANDLED;
1051
1052 /* if the IRQ is for both CPUs on the same adapter, */
1053 /* then alter the interrupt status so as to handle */
1054 /* one CPU at a time */
1055 if(((unsigned char)int_status & (IRQ_CPU_A | IRQ_CPU_B))
1056 == (IRQ_CPU_A | IRQ_CPU_B)) {
1057 int_status &= (CPU_no == S514_CPU_A) ?
1058 ~IRQ_CPU_B : ~IRQ_CPU_A;
1059 }
1060
1061 card_found_for_IRQ = 0;
1062
1063 /* check to see that the CPU number for this device */
1064 /* corresponds to the interrupt status read */
1065 switch (CPU_no) {
1066 case S514_CPU_A:
1067 if((unsigned char)int_status &
1068 IRQ_CPU_A)
1069 card_found_for_IRQ = 1;
1070 break;
1071
1072 case S514_CPU_B:
1073 if((unsigned char)int_status &
1074 IRQ_CPU_B)
1075 card_found_for_IRQ = 1;
1076 break;
1077 }
1078
1079 /* exit if the interrupt is for another CPU on the */
1080 /* same IRQ */
1081 if(!card_found_for_IRQ)
1082 return IRQ_HANDLED;
1083
1084 if (!card ||
1085 (card->wandev.state == WAN_UNCONFIGURED && !card->configured)){
1086 printk(KERN_INFO
1087 "Received IRQ %d for CPU #%c\n",
1088 irq, CPU_no);
1089 printk(KERN_INFO
1090 "IRQ for unconfigured adapter\n");
1091 S514_intack(&card->hw, int_status);
1092 return IRQ_HANDLED;
1093 }
1094
1095 if (card->in_isr) {
1096 printk(KERN_INFO
1097 "%s: interrupt re-entrancy on IRQ %d\n",
1098 card->devname, card->wandev.irq);
1099 S514_intack(&card->hw, int_status);
1100 return IRQ_HANDLED;
1101 }
1102
1103 spin_lock(&card->wandev.lock);
1104 if (card->next){
1105 spin_lock(&card->next->wandev.lock);
1106 }
1107
1108 S514_intack(&card->hw, int_status);
1109 if (card->isr)
1110 card->isr(card);
1111
1112 if (card->next){
1113 spin_unlock(&card->next->wandev.lock);
1114 }
1115 spin_unlock(&card->wandev.lock);
1116
1117 /* handle a maximum of two interrupts (one for each */
1118 /* CPU on the adapter) before returning */
1119 if((++ IRQ_count) == 2)
1120 return IRQ_HANDLED;
1121 }
1122 }
1123
1124 else { /* handle interrupt on S508 adapter */
1125
1126 if (!card || ((card->wandev.state == WAN_UNCONFIGURED) && !card->configured))
1127 return IRQ_HANDLED;
1128
1129 if (card->in_isr) {
1130 printk(KERN_INFO
1131 "%s: interrupt re-entrancy on IRQ %d!\n",
1132 card->devname, card->wandev.irq);
1133 return IRQ_HANDLED;
1134 }
1135
1136 spin_lock(&card->wandev.lock);
1137 if (card->next){
1138 spin_lock(&card->next->wandev.lock);
1139 }
1140
1141 sdla_intack(&card->hw);
1142 if (card->isr)
1143 card->isr(card);
1144
1145 if (card->next){
1146 spin_unlock(&card->next->wandev.lock);
1147 }
1148 spin_unlock(&card->wandev.lock);
1149
1150 }
1151 return IRQ_HANDLED;
1152#undef card
1153}
1154
1155/*============================================================================
1156 * This routine is called by the protocol-specific modules when network
1157 * interface is being open. The only reason we need this, is because we
1158 * have to call MOD_INC_USE_COUNT, but cannot include 'module.h' where it's
1159 * defined more than once into the same kernel module.
1160 */
1161void wanpipe_open (sdla_t* card)
1162{
1163 ++card->open_cnt;
1164}
1165
1166/*============================================================================
1167 * This routine is called by the protocol-specific modules when network
1168 * interface is being closed. The only reason we need this, is because we
1169 * have to call MOD_DEC_USE_COUNT, but cannot include 'module.h' where it's
1170 * defined more than once into the same kernel module.
1171 */
1172void wanpipe_close (sdla_t* card)
1173{
1174 --card->open_cnt;
1175}
1176
1177/*============================================================================
1178 * Set WAN device state.
1179 */
1180void wanpipe_set_state (sdla_t* card, int state)
1181{
1182 if (card->wandev.state != state) {
1183 switch (state) {
1184 case WAN_CONNECTED:
1185 printk (KERN_INFO "%s: link connected!\n",
1186 card->devname);
1187 break;
1188
1189 case WAN_CONNECTING:
1190 printk (KERN_INFO "%s: link connecting...\n",
1191 card->devname);
1192 break;
1193
1194 case WAN_DISCONNECTED:
1195 printk (KERN_INFO "%s: link disconnected!\n",
1196 card->devname);
1197 break;
1198 }
1199 card->wandev.state = state;
1200 }
1201 card->state_tick = jiffies;
1202}
1203
1204sdla_t * wanpipe_find_card (char *name)
1205{
1206 int cnt;
1207 for (cnt = 0; cnt < ncards; ++ cnt) {
1208 sdla_t* card = &card_array[cnt];
1209 if (!strcmp(card->devname,name))
1210 return card;
1211 }
1212 return NULL;
1213}
1214
1215sdla_t * wanpipe_find_card_num (int num)
1216{
1217 if (num < 1 || num > ncards)
1218 return NULL;
1219 num--;
1220 return &card_array[num];
1221}
1222
1223/*
1224 * @work_pointer: work_struct to be done;
1225 * should already have PREPARE_WORK() or
1226 * INIT_WORK() done on it by caller;
1227 */
1228void wanpipe_queue_work (struct work_struct *work_pointer)
1229{
1230 if (test_and_set_bit(1, (void*)&wanpipe_bh_critical))
1231 printk(KERN_INFO "CRITICAL IN QUEUING WORK\n");
1232
1233 queue_work(wanpipe_wq, work_pointer);
1234 clear_bit(1,(void*)&wanpipe_bh_critical);
1235}
1236
1237void wakeup_sk_bh(struct net_device *dev)
1238{
1239 wanpipe_common_t *chan = dev->priv;
1240
1241 if (test_bit(0,&chan->common_critical))
1242 return;
1243
1244 if (chan->sk && chan->tx_timer){
1245 chan->tx_timer->expires=jiffies+1;
1246 add_timer(chan->tx_timer);
1247 }
1248}
1249
1250int change_dev_flags(struct net_device *dev, unsigned flags)
1251{
1252 struct ifreq if_info;
1253 mm_segment_t fs = get_fs();
1254 int err;
1255
1256 memset(&if_info, 0, sizeof(if_info));
1257 strcpy(if_info.ifr_name, dev->name);
1258 if_info.ifr_flags = flags;
1259
1260 set_fs(get_ds()); /* get user space block */
1261 err = devinet_ioctl(SIOCSIFFLAGS, &if_info);
1262 set_fs(fs);
1263
1264 return err;
1265}
1266
1267unsigned long get_ip_address(struct net_device *dev, int option)
1268{
1269
1270 struct in_ifaddr *ifaddr;
1271 struct in_device *in_dev;
1272 unsigned long addr = 0;
1273
1274 rcu_read_lock();
1275 if ((in_dev = __in_dev_get_rcu(dev)) == NULL){
1276 goto out;
1277 }
1278
1279 if ((ifaddr = in_dev->ifa_list)== NULL ){
1280 goto out;
1281 }
1282
1283 switch (option){
1284
1285 case WAN_LOCAL_IP:
1286 addr = ifaddr->ifa_local;
1287 break;
1288
1289 case WAN_POINTOPOINT_IP:
1290 addr = ifaddr->ifa_address;
1291 break;
1292
1293 case WAN_NETMASK_IP:
1294 addr = ifaddr->ifa_mask;
1295 break;
1296
1297 case WAN_BROADCAST_IP:
1298 addr = ifaddr->ifa_broadcast;
1299 break;
1300 default:
1301 break;
1302 }
1303
1304out:
1305 rcu_read_unlock();
1306 return addr;
1307}
1308
1309void add_gateway(sdla_t *card, struct net_device *dev)
1310{
1311 mm_segment_t oldfs;
1312 struct rtentry route;
1313 int res;
1314
1315 memset((char*)&route,0,sizeof(struct rtentry));
1316
1317 ((struct sockaddr_in *)
1318 &(route.rt_dst))->sin_addr.s_addr = 0;
1319 ((struct sockaddr_in *)
1320 &(route.rt_dst))->sin_family = AF_INET;
1321
1322 ((struct sockaddr_in *)
1323 &(route.rt_genmask))->sin_addr.s_addr = 0;
1324 ((struct sockaddr_in *)
1325 &(route.rt_genmask)) ->sin_family = AF_INET;
1326
1327
1328 route.rt_flags = 0;
1329 route.rt_dev = dev->name;
1330
1331 oldfs = get_fs();
1332 set_fs(get_ds());
1333 res = ip_rt_ioctl(SIOCADDRT,&route);
1334 set_fs(oldfs);
1335
1336 if (res == 0){
1337 printk(KERN_INFO "%s: Gateway added for %s\n",
1338 card->devname,dev->name);
1339 }
1340
1341 return;
1342}
1343
1344MODULE_LICENSE("GPL");
1345
1346/****** End *********************************************************/
diff --git a/drivers/net/wan/wanpipe_multppp.c b/drivers/net/wan/wanpipe_multppp.c
deleted file mode 100644
index 812a1183c502..000000000000
--- a/drivers/net/wan/wanpipe_multppp.c
+++ /dev/null
@@ -1,2358 +0,0 @@
1/*****************************************************************************
2* wanpipe_multppp.c Multi-Port PPP driver module.
3*
4* Authors: Nenad Corbic <ncorbic@sangoma.com>
5*
6* Copyright: (c) 1995-2001 Sangoma Technologies Inc.
7*
8* This program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public License
10* as published by the Free Software Foundation; either version
11* 2 of the License, or (at your option) any later version.
12* ============================================================================
13* Dec 15 2000 Updated for 2.4.X kernel
14* Nov 15 2000 Fixed the SyncPPP support for kernels 2.2.16 and higher.
15* The pppstruct has changed.
16* Jul 13 2000 Using the kernel Syncppp module on top of RAW Wanpipe CHDLC
17* module.
18*****************************************************************************/
19
20#include <linux/module.h>
21#include <linux/kernel.h> /* printk(), and other useful stuff */
22#include <linux/stddef.h> /* offsetof(), etc. */
23#include <linux/errno.h> /* return codes */
24#include <linux/string.h> /* inline memset(), etc. */
25#include <linux/slab.h> /* kmalloc(), kfree() */
26#include <linux/wanrouter.h> /* WAN router definitions */
27#include <linux/wanpipe.h> /* WANPIPE common user API definitions */
28#include <linux/if_arp.h> /* ARPHRD_* defines */
29#include <linux/jiffies.h> /* time_after() macro */
30
31#include <linux/in.h> /* sockaddr_in */
32#include <linux/inet.h>
33#include <linux/if.h>
34#include <asm/byteorder.h> /* htons(), etc. */
35#include <linux/sdlapci.h>
36#include <asm/io.h>
37
38#include <linux/sdla_chdlc.h> /* CHDLC firmware API definitions */
39#include <linux/sdla_asy.h> /* CHDLC (async) API definitions */
40
41#include <linux/if_wanpipe_common.h> /* Socket Driver common area */
42#include <linux/if_wanpipe.h>
43
44
45#include <linux/inetdevice.h>
46#include <asm/uaccess.h>
47
48#include <net/syncppp.h>
49
50
51/****** Defines & Macros ****************************************************/
52
53#ifdef _DEBUG_
54#define STATIC
55#else
56#define STATIC static
57#endif
58
59/* reasons for enabling the timer interrupt on the adapter */
60#define TMR_INT_ENABLED_UDP 0x01
61#define TMR_INT_ENABLED_UPDATE 0x02
62#define TMR_INT_ENABLED_CONFIG 0x04
63
64#define CHDLC_DFLT_DATA_LEN 1500 /* default MTU */
65#define CHDLC_HDR_LEN 1
66
67#define IFF_POINTTOPOINT 0x10
68
69#define CHDLC_API 0x01
70
71#define PORT(x) (x == 0 ? "PRIMARY" : "SECONDARY" )
72#define MAX_BH_BUFF 10
73
74#define CRC_LENGTH 2
75#define PPP_HEADER_LEN 4
76
77/******Data Structures*****************************************************/
78
79/* This structure is placed in the private data area of the device structure.
80 * The card structure used to occupy the private area but now the following
81 * structure will incorporate the card structure along with CHDLC specific data
82 */
83
84typedef struct chdlc_private_area
85{
86 void *if_ptr; /* General Pointer used by SPPP */
87 wanpipe_common_t common;
88 sdla_t *card;
89 int TracingEnabled; /* For enabling Tracing */
90 unsigned long curr_trace_addr; /* Used for Tracing */
91 unsigned long start_trace_addr;
92 unsigned long end_trace_addr;
93 unsigned long base_addr_trace_buffer;
94 unsigned long end_addr_trace_buffer;
95 unsigned short number_trace_elements;
96 unsigned available_buffer_space;
97 unsigned long router_start_time;
98 unsigned char route_status;
99 unsigned char route_removed;
100 unsigned long tick_counter; /* For 5s timeout counter */
101 unsigned long router_up_time;
102 u32 IP_address; /* IP addressing */
103 u32 IP_netmask;
104 unsigned char mc; /* Mulitcast support on/off */
105 unsigned short udp_pkt_lgth; /* udp packet processing */
106 char udp_pkt_src;
107 char udp_pkt_data[MAX_LGTH_UDP_MGNT_PKT];
108 unsigned short timer_int_enabled;
109 char update_comms_stats; /* updating comms stats */
110
111 //FIXME: add driver stats as per frame relay!
112
113} chdlc_private_area_t;
114
115/* Route Status options */
116#define NO_ROUTE 0x00
117#define ADD_ROUTE 0x01
118#define ROUTE_ADDED 0x02
119#define REMOVE_ROUTE 0x03
120
121
122/* variable for keeping track of enabling/disabling FT1 monitor status */
123static int rCount = 0;
124
125/* variable for tracking how many interfaces to open for WANPIPE on the
126 two ports */
127
128extern void disable_irq(unsigned int);
129extern void enable_irq(unsigned int);
130
131/****** Function Prototypes *************************************************/
132/* WAN link driver entry points. These are called by the WAN router module. */
133static int update(struct wan_device* wandev);
134static int new_if(struct wan_device* wandev, struct net_device* dev,
135 wanif_conf_t* conf);
136static int del_if(struct wan_device* wandev, struct net_device* dev);
137
138/* Network device interface */
139static int if_init(struct net_device* dev);
140static int if_open(struct net_device* dev);
141static int if_close(struct net_device* dev);
142static int if_send(struct sk_buff* skb, struct net_device* dev);
143static struct net_device_stats* if_stats(struct net_device* dev);
144
145static void if_tx_timeout(struct net_device *dev);
146
147/* CHDLC Firmware interface functions */
148static int chdlc_configure (sdla_t* card, void* data);
149static int chdlc_comm_enable (sdla_t* card);
150static int chdlc_comm_disable (sdla_t* card);
151static int chdlc_read_version (sdla_t* card, char* str);
152static int chdlc_set_intr_mode (sdla_t* card, unsigned mode);
153static int chdlc_send (sdla_t* card, void* data, unsigned len);
154static int chdlc_read_comm_err_stats (sdla_t* card);
155static int chdlc_read_op_stats (sdla_t* card);
156static int config_chdlc (sdla_t *card);
157
158
159/* Miscellaneous CHDLC Functions */
160static int set_chdlc_config (sdla_t* card);
161static void init_chdlc_tx_rx_buff(sdla_t* card, struct net_device *dev);
162static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb);
163static int process_chdlc_exception(sdla_t *card);
164static int process_global_exception(sdla_t *card);
165static int update_comms_stats(sdla_t* card,
166 chdlc_private_area_t* chdlc_priv_area);
167static void port_set_state (sdla_t *card, int);
168
169/* Interrupt handlers */
170static void wsppp_isr (sdla_t* card);
171static void rx_intr (sdla_t* card);
172static void timer_intr(sdla_t *);
173
174/* Miscellaneous functions */
175static int reply_udp( unsigned char *data, unsigned int mbox_len );
176static int intr_test( sdla_t* card);
177static int udp_pkt_type( struct sk_buff *skb , sdla_t* card);
178static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
179 struct sk_buff *skb, struct net_device* dev,
180 chdlc_private_area_t* chdlc_priv_area);
181static int process_udp_mgmt_pkt(sdla_t* card, struct net_device* dev,
182 chdlc_private_area_t* chdlc_priv_area);
183static unsigned short calc_checksum (char *, int);
184static void s508_lock (sdla_t *card, unsigned long *smp_flags);
185static void s508_unlock (sdla_t *card, unsigned long *smp_flags);
186static void send_ppp_term_request(struct net_device *dev);
187
188
189static int Intr_test_counter;
190/****** Public Functions ****************************************************/
191
192/*============================================================================
193 * Cisco HDLC protocol initialization routine.
194 *
195 * This routine is called by the main WANPIPE module during setup. At this
196 * point adapter is completely initialized and firmware is running.
197 * o read firmware version (to make sure it's alive)
198 * o configure adapter
199 * o initialize protocol-specific fields of the adapter data space.
200 *
201 * Return: 0 o.k.
202 * < 0 failure.
203 */
204int wsppp_init (sdla_t* card, wandev_conf_t* conf)
205{
206 unsigned char port_num;
207 int err;
208 unsigned long max_permitted_baud = 0;
209 SHARED_MEMORY_INFO_STRUCT *flags;
210
211 union
212 {
213 char str[80];
214 } u;
215 volatile CHDLC_MAILBOX_STRUCT* mb;
216 CHDLC_MAILBOX_STRUCT* mb1;
217 unsigned long timeout;
218
219 /* Verify configuration ID */
220 if (conf->config_id != WANCONFIG_MPPP) {
221 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
222 card->devname, conf->config_id);
223 return -EINVAL;
224 }
225
226 /* Find out which Port to use */
227 if ((conf->comm_port == WANOPT_PRI) || (conf->comm_port == WANOPT_SEC)){
228 if (card->next){
229
230 if (conf->comm_port != card->next->u.c.comm_port){
231 card->u.c.comm_port = conf->comm_port;
232 }else{
233 printk(KERN_ERR "%s: ERROR - %s port used!\n",
234 card->wandev.name, PORT(conf->comm_port));
235 return -EINVAL;
236 }
237 }else{
238 card->u.c.comm_port = conf->comm_port;
239 }
240 }else{
241 printk(KERN_ERR "%s: ERROR - Invalid Port Selected!\n",
242 card->wandev.name);
243 return -EINVAL;
244 }
245
246
247 /* Initialize protocol-specific fields */
248 if(card->hw.type != SDLA_S514){
249
250 if (card->u.c.comm_port == WANOPT_PRI){
251 card->mbox = (void *) card->hw.dpmbase;
252 }else{
253 card->mbox = (void *) card->hw.dpmbase +
254 SEC_BASE_ADDR_MB_STRUCT - PRI_BASE_ADDR_MB_STRUCT;
255 }
256 }else{
257 /* for a S514 adapter, set a pointer to the actual mailbox in the */
258 /* allocated virtual memory area */
259 if (card->u.c.comm_port == WANOPT_PRI){
260 card->mbox = (void *) card->hw.dpmbase + PRI_BASE_ADDR_MB_STRUCT;
261 }else{
262 card->mbox = (void *) card->hw.dpmbase + SEC_BASE_ADDR_MB_STRUCT;
263 }
264 }
265
266 mb = mb1 = card->mbox;
267
268 if (!card->configured){
269
270 /* The board will place an 'I' in the return code to indicate that it is
271 ready to accept commands. We expect this to be completed in less
272 than 1 second. */
273
274 timeout = jiffies + 1 * HZ;
275 while (mb->return_code != 'I') /* Wait 1s for board to initialize */
276 if (time_after(jiffies, timeout)) break;
277
278 if (mb->return_code != 'I') {
279 printk(KERN_INFO
280 "%s: Initialization not completed by adapter\n",
281 card->devname);
282 printk(KERN_INFO "Please contact Sangoma representative.\n");
283 return -EIO;
284 }
285 }
286
287 /* Read firmware version. Note that when adapter initializes, it
288 * clears the mailbox, so it may appear that the first command was
289 * executed successfully when in fact it was merely erased. To work
290 * around this, we execute the first command twice.
291 */
292
293 if (chdlc_read_version(card, u.str))
294 return -EIO;
295
296 printk(KERN_INFO "%s: Running Raw CHDLC firmware v%s\n"
297 "%s: for Multi-Port PPP protocol.\n",
298 card->devname,u.str,card->devname);
299
300 card->isr = &wsppp_isr;
301 card->poll = NULL;
302 card->exec = NULL;
303 card->wandev.update = &update;
304 card->wandev.new_if = &new_if;
305 card->wandev.del_if = &del_if;
306 card->wandev.udp_port = conf->udp_port;
307
308 card->wandev.new_if_cnt = 0;
309
310 /* reset the number of times the 'update()' proc has been called */
311 card->u.c.update_call_count = 0;
312
313 card->wandev.ttl = conf->ttl;
314 card->wandev.interface = conf->interface;
315
316 if ((card->u.c.comm_port == WANOPT_SEC && conf->interface == WANOPT_V35)&&
317 card->hw.type != SDLA_S514){
318 printk(KERN_INFO "%s: ERROR - V35 Interface not supported on S508 %s port \n",
319 card->devname, PORT(card->u.c.comm_port));
320 return -EIO;
321 }
322
323
324 card->wandev.clocking = conf->clocking;
325
326 port_num = card->u.c.comm_port;
327
328 /* Setup Port Bps */
329
330 if(card->wandev.clocking) {
331 if((port_num == WANOPT_PRI) || card->u.c.receive_only) {
332 /* For Primary Port 0 */
333 max_permitted_baud =
334 (card->hw.type == SDLA_S514) ?
335 PRI_MAX_BAUD_RATE_S514 :
336 PRI_MAX_BAUD_RATE_S508;
337 }
338 else if(port_num == WANOPT_SEC) {
339 /* For Secondary Port 1 */
340 max_permitted_baud =
341 (card->hw.type == SDLA_S514) ?
342 SEC_MAX_BAUD_RATE_S514 :
343 SEC_MAX_BAUD_RATE_S508;
344 }
345
346 if(conf->bps > max_permitted_baud) {
347 conf->bps = max_permitted_baud;
348 printk(KERN_INFO "%s: Baud too high!\n",
349 card->wandev.name);
350 printk(KERN_INFO "%s: Baud rate set to %lu bps\n",
351 card->wandev.name, max_permitted_baud);
352 }
353
354 card->wandev.bps = conf->bps;
355 }else{
356 card->wandev.bps = 0;
357 }
358
359 /* Setup the Port MTU */
360 if((port_num == WANOPT_PRI) || card->u.c.receive_only) {
361
362 /* For Primary Port 0 */
363 card->wandev.mtu =
364 (conf->mtu >= MIN_LGTH_CHDLC_DATA_CFG) ?
365 min_t(unsigned int, conf->mtu, PRI_MAX_NO_DATA_BYTES_IN_FRAME) :
366 CHDLC_DFLT_DATA_LEN;
367 } else if(port_num == WANOPT_SEC) {
368 /* For Secondary Port 1 */
369 card->wandev.mtu =
370 (conf->mtu >= MIN_LGTH_CHDLC_DATA_CFG) ?
371 min_t(unsigned int, conf->mtu, SEC_MAX_NO_DATA_BYTES_IN_FRAME) :
372 CHDLC_DFLT_DATA_LEN;
373 }
374
375 /* Add on a PPP Header */
376 card->wandev.mtu += PPP_HEADER_LEN;
377
378 /* Set up the interrupt status area */
379 /* Read the CHDLC Configuration and obtain:
380 * Ptr to shared memory infor struct
381 * Use this pointer to calculate the value of card->u.c.flags !
382 */
383 mb1->buffer_length = 0;
384 mb1->command = READ_CHDLC_CONFIGURATION;
385 err = sdla_exec(mb1) ? mb1->return_code : CMD_TIMEOUT;
386 if(err != COMMAND_OK) {
387 clear_bit(1, (void*)&card->wandev.critical);
388
389 if(card->hw.type != SDLA_S514)
390 enable_irq(card->hw.irq);
391
392 chdlc_error(card, err, mb1);
393 return -EIO;
394 }
395
396 if(card->hw.type == SDLA_S514){
397 card->u.c.flags = (void *)(card->hw.dpmbase +
398 (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
399 ptr_shared_mem_info_struct));
400 }else{
401 card->u.c.flags = (void *)(card->hw.dpmbase +
402 (((CHDLC_CONFIGURATION_STRUCT *)mb1->data)->
403 ptr_shared_mem_info_struct % SDLA_WINDOWSIZE));
404 }
405
406 flags = card->u.c.flags;
407
408 /* This is for the ports link state */
409 card->wandev.state = WAN_DUALPORT;
410 card->u.c.state = WAN_DISCONNECTED;
411
412
413 if (!card->wandev.piggyback){
414 err = intr_test(card);
415
416 if(err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
417 printk(KERN_ERR "%s: Interrupt test failed (%i)\n",
418 card->devname, Intr_test_counter);
419 printk(KERN_ERR "%s: Please choose another interrupt\n",
420 card->devname);
421 return -EIO;
422 }
423
424 printk(KERN_INFO "%s: Interrupt test passed (%i)\n",
425 card->devname, Intr_test_counter);
426 }
427
428
429 if (chdlc_set_intr_mode(card, APP_INT_ON_TIMER)){
430 printk (KERN_INFO "%s: Failed to set interrupt triggers!\n",
431 card->devname);
432 return -EIO;
433 }
434
435 /* Mask the Timer interrupt */
436 flags->interrupt_info_struct.interrupt_permission &=
437 ~APP_INT_ON_TIMER;
438
439 printk(KERN_INFO "\n");
440
441 return 0;
442}
443
444/******* WAN Device Driver Entry Points *************************************/
445
446/*============================================================================
447 * Update device status & statistics
448 * This procedure is called when updating the PROC file system and returns
449 * various communications statistics. These statistics are accumulated from 3
450 * different locations:
451 * 1) The 'if_stats' recorded for the device.
452 * 2) Communication error statistics on the adapter.
453 * 3) CHDLC operational statistics on the adapter.
454 * The board level statistics are read during a timer interrupt. Note that we
455 * read the error and operational statistics during consecitive timer ticks so
456 * as to minimize the time that we are inside the interrupt handler.
457 *
458 */
459static int update(struct wan_device* wandev)
460{
461 sdla_t* card = wandev->private;
462 struct net_device* dev;
463 volatile chdlc_private_area_t* chdlc_priv_area;
464 SHARED_MEMORY_INFO_STRUCT *flags;
465 unsigned long timeout;
466
467 /* sanity checks */
468 if((wandev == NULL) || (wandev->private == NULL))
469 return -EFAULT;
470
471 if(wandev->state == WAN_UNCONFIGURED)
472 return -ENODEV;
473
474 /* more sanity checks */
475 if(!card->u.c.flags)
476 return -ENODEV;
477
478 if((dev=card->wandev.dev) == NULL)
479 return -ENODEV;
480
481 if((chdlc_priv_area=dev->priv) == NULL)
482 return -ENODEV;
483
484 flags = card->u.c.flags;
485
486 if(chdlc_priv_area->update_comms_stats){
487 return -EAGAIN;
488 }
489
490 /* we will need 2 timer interrupts to complete the */
491 /* reading of the statistics */
492 chdlc_priv_area->update_comms_stats = 2;
493 flags->interrupt_info_struct.interrupt_permission |= APP_INT_ON_TIMER;
494 chdlc_priv_area->timer_int_enabled = TMR_INT_ENABLED_UPDATE;
495
496 /* wait a maximum of 1 second for the statistics to be updated */
497 timeout = jiffies + 1 * HZ;
498 for(;;) {
499 if(chdlc_priv_area->update_comms_stats == 0)
500 break;
501 if (time_after(jiffies, timeout)){
502 chdlc_priv_area->update_comms_stats = 0;
503 chdlc_priv_area->timer_int_enabled &=
504 ~TMR_INT_ENABLED_UPDATE;
505 return -EAGAIN;
506 }
507 }
508
509 return 0;
510}
511
512
513/*============================================================================
514 * Create new logical channel.
515 * This routine is called by the router when ROUTER_IFNEW IOCTL is being
516 * handled.
517 * o parse media- and hardware-specific configuration
518 * o make sure that a new channel can be created
519 * o allocate resources, if necessary
520 * o prepare network device structure for registaration.
521 *
522 * Return: 0 o.k.
523 * < 0 failure (channel will not be created)
524 */
525static int new_if(struct wan_device* wandev, struct net_device* pdev,
526 wanif_conf_t* conf)
527{
528
529 struct ppp_device *pppdev = (struct ppp_device *)pdev;
530 struct net_device *dev = NULL;
531 struct sppp *sp;
532 sdla_t* card = wandev->private;
533 chdlc_private_area_t* chdlc_priv_area;
534
535 if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
536 printk(KERN_INFO "%s: invalid interface name!\n",
537 card->devname);
538 return -EINVAL;
539 }
540
541 /* allocate and initialize private data */
542 chdlc_priv_area = kmalloc(sizeof(chdlc_private_area_t), GFP_KERNEL);
543
544 if(chdlc_priv_area == NULL)
545 return -ENOMEM;
546
547 memset(chdlc_priv_area, 0, sizeof(chdlc_private_area_t));
548
549 chdlc_priv_area->card = card;
550
551 /* initialize data */
552 strcpy(card->u.c.if_name, conf->name);
553
554 if(card->wandev.new_if_cnt > 0) {
555 kfree(chdlc_priv_area);
556 return -EEXIST;
557 }
558
559 card->wandev.new_if_cnt++;
560
561 chdlc_priv_area->TracingEnabled = 0;
562
563 //We don't need this any more
564 chdlc_priv_area->route_status = NO_ROUTE;
565 chdlc_priv_area->route_removed = 0;
566
567 printk(KERN_INFO "%s: Firmware running in HDLC STREAMING Mode\n",
568 wandev->name);
569
570 /* Setup wanpipe as a router (WANPIPE) or as an API */
571 if( strcmp(conf->usedby, "WANPIPE") == 0) {
572 printk(KERN_INFO "%s: Driver running in WANPIPE mode!\n",
573 wandev->name);
574 card->u.c.usedby = WANPIPE;
575 } else {
576 printk(KERN_INFO
577 "%s: API Mode is not supported for SyncPPP!\n",
578 wandev->name);
579 kfree(chdlc_priv_area);
580 return -EINVAL;
581 }
582
583 /* Get Multicast Information */
584 chdlc_priv_area->mc = conf->mc;
585
586
587 chdlc_priv_area->if_ptr = pppdev;
588
589 /* prepare network device data space for registration */
590
591 strcpy(dev->name,card->u.c.if_name);
592
593 /* Attach PPP protocol layer to pppdev
594 * The sppp_attach() will initilize the dev structure
595 * and setup ppp layer protocols.
596 * All we have to do is to bind in:
597 * if_open(), if_close(), if_send() and get_stats() functions.
598 */
599 sppp_attach(pppdev);
600 dev = pppdev->dev;
601 sp = &pppdev->sppp;
602
603 /* Enable PPP Debugging */
604 // FIXME Fix this up somehow
605 //sp->pp_flags |= PP_DEBUG;
606 sp->pp_flags &= ~PP_CISCO;
607
608 dev->init = &if_init;
609 dev->priv = chdlc_priv_area;
610
611 return 0;
612}
613
614
615
616
617/*============================================================================
618 * Delete logical channel.
619 */
620static int del_if(struct wan_device* wandev, struct net_device* dev)
621{
622 chdlc_private_area_t *chdlc_priv_area = dev->priv;
623 sdla_t *card = chdlc_priv_area->card;
624 unsigned long smp_lock;
625
626 /* Detach the PPP layer */
627 printk(KERN_INFO "%s: Detaching SyncPPP Module from %s\n",
628 wandev->name,dev->name);
629
630 lock_adapter_irq(&wandev->lock,&smp_lock);
631
632 sppp_detach(dev);
633 chdlc_priv_area->if_ptr=NULL;
634
635 chdlc_set_intr_mode(card, 0);
636 if (card->u.c.comm_enabled)
637 chdlc_comm_disable(card);
638 unlock_adapter_irq(&wandev->lock,&smp_lock);
639
640 port_set_state(card, WAN_DISCONNECTED);
641
642 return 0;
643}
644
645
646/****** Network Device Interface ********************************************/
647
648/*============================================================================
649 * Initialize Linux network interface.
650 *
651 * This routine is called only once for each interface, during Linux network
652 * interface registration. Returning anything but zero will fail interface
653 * registration.
654 */
655static int if_init(struct net_device* dev)
656{
657 chdlc_private_area_t* chdlc_priv_area = dev->priv;
658 sdla_t* card = chdlc_priv_area->card;
659 struct wan_device* wandev = &card->wandev;
660
661 /* NOTE: Most of the dev initialization was
662 * done in sppp_attach(), called by new_if()
663 * function. All we have to do here is
664 * to link four major routines below.
665 */
666
667 /* Initialize device driver entry points */
668 dev->open = &if_open;
669 dev->stop = &if_close;
670 dev->hard_start_xmit = &if_send;
671 dev->get_stats = &if_stats;
672 dev->tx_timeout = &if_tx_timeout;
673 dev->watchdog_timeo = TX_TIMEOUT;
674
675
676 /* Initialize hardware parameters */
677 dev->irq = wandev->irq;
678 dev->dma = wandev->dma;
679 dev->base_addr = wandev->ioport;
680 dev->mem_start = wandev->maddr;
681 dev->mem_end = wandev->maddr + wandev->msize - 1;
682
683 /* Set transmit buffer queue length
684 * If we over fill this queue the packets will
685 * be droped by the kernel.
686 * sppp_attach() sets this to 10, but
687 * 100 will give us more room at low speeds.
688 */
689 dev->tx_queue_len = 100;
690
691 return 0;
692}
693
694
695/*============================================================================
696 * Handle transmit timeout event from netif watchdog
697 */
698static void if_tx_timeout(struct net_device *dev)
699{
700 chdlc_private_area_t* chan = dev->priv;
701 sdla_t *card = chan->card;
702
703 /* If our device stays busy for at least 5 seconds then we will
704 * kick start the device by making dev->tbusy = 0. We expect
705 * that our device never stays busy more than 5 seconds. So this
706 * is only used as a last resort.
707 */
708
709 ++card->wandev.stats.collisions;
710
711 printk (KERN_INFO "%s: Transmit timed out on %s\n", card->devname,dev->name);
712 netif_wake_queue (dev);
713}
714
715
716/*============================================================================
717 * Open network interface.
718 * o enable communications and interrupts.
719 * o prevent module from unloading by incrementing use count
720 *
721 * Return 0 if O.k. or errno.
722 */
723static int if_open(struct net_device* dev)
724{
725 chdlc_private_area_t* chdlc_priv_area = dev->priv;
726 sdla_t* card = chdlc_priv_area->card;
727 struct timeval tv;
728 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
729
730 /* Only one open per interface is allowed */
731 if (netif_running(dev))
732 return -EBUSY;
733
734 /* Start PPP Layer */
735 if (sppp_open(dev)){
736 return -EIO;
737 }
738
739 do_gettimeofday(&tv);
740 chdlc_priv_area->router_start_time = tv.tv_sec;
741
742 netif_start_queue(dev);
743
744 wanpipe_open(card);
745
746 chdlc_priv_area->timer_int_enabled |= TMR_INT_ENABLED_CONFIG;
747 flags->interrupt_info_struct.interrupt_permission |= APP_INT_ON_TIMER;
748 return 0;
749}
750
751/*============================================================================
752 * Close network interface.
753 * o if this is the last close, then disable communications and interrupts.
754 * o reset flags.
755 */
756static int if_close(struct net_device* dev)
757{
758 chdlc_private_area_t* chdlc_priv_area = dev->priv;
759 sdla_t* card = chdlc_priv_area->card;
760
761 /* Stop the PPP Layer */
762 sppp_close(dev);
763 netif_stop_queue(dev);
764
765 wanpipe_close(card);
766
767 return 0;
768}
769
770/*============================================================================
771 * Send a packet on a network interface.
772 * o set tbusy flag (marks start of the transmission) to block a timer-based
773 * transmit from overlapping.
774 * o check link state. If link is not up, then drop the packet.
775 * o execute adapter send command.
776 * o free socket buffer
777 *
778 * Return: 0 complete (socket buffer must be freed)
779 * non-0 packet may be re-transmitted (tbusy must be set)
780 *
781 * Notes:
782 * 1. This routine is called either by the protocol stack or by the "net
783 * bottom half" (with interrupts enabled).
784 * 2. Setting tbusy flag will inhibit further transmit requests from the
785 * protocol stack and can be used for flow control with protocol layer.
786 */
787static int if_send(struct sk_buff* skb, struct net_device* dev)
788{
789 chdlc_private_area_t *chdlc_priv_area = dev->priv;
790 sdla_t *card = chdlc_priv_area->card;
791 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
792 INTERRUPT_INFORMATION_STRUCT *chdlc_int = &flags->interrupt_info_struct;
793 int udp_type = 0;
794 unsigned long smp_flags;
795 int err=0;
796
797 netif_stop_queue(dev);
798
799
800 if (skb == NULL){
801 /* If we get here, some higher layer thinks we've missed an
802 * tx-done interrupt.
803 */
804 printk(KERN_INFO "%s: Received NULL skb buffer! interface %s got kicked!\n",
805 card->devname, dev->name);
806
807 netif_wake_queue(dev);
808 return 0;
809 }
810
811 if (ntohs(skb->protocol) != htons(PVC_PROT)){
812 /* check the udp packet type */
813
814 udp_type = udp_pkt_type(skb, card);
815 if (udp_type == UDP_CPIPE_TYPE){
816 if(store_udp_mgmt_pkt(UDP_PKT_FRM_STACK, card, skb, dev,
817 chdlc_priv_area)){
818 chdlc_int->interrupt_permission |=
819 APP_INT_ON_TIMER;
820 }
821 netif_start_queue(dev);
822 return 0;
823 }
824 }
825
826 /* Lock the 508 Card: SMP is supported */
827 if(card->hw.type != SDLA_S514){
828 s508_lock(card,&smp_flags);
829 }
830
831 if (test_and_set_bit(SEND_CRIT, (void*)&card->wandev.critical)){
832
833 printk(KERN_INFO "%s: Critical in if_send: %lx\n",
834 card->wandev.name,card->wandev.critical);
835 ++card->wandev.stats.tx_dropped;
836 netif_start_queue(dev);
837 goto if_send_crit_exit;
838 }
839
840 if (card->wandev.state != WAN_CONNECTED){
841 ++card->wandev.stats.tx_dropped;
842 netif_start_queue(dev);
843 goto if_send_crit_exit;
844 }
845
846 if (chdlc_send(card, skb->data, skb->len)){
847 netif_stop_queue(dev);
848
849 }else{
850 ++card->wandev.stats.tx_packets;
851 card->wandev.stats.tx_bytes += skb->len;
852 dev->trans_start = jiffies;
853 netif_start_queue(dev);
854 }
855
856if_send_crit_exit:
857 if (!(err=netif_queue_stopped(dev))){
858 dev_kfree_skb_any(skb);
859 }else{
860 chdlc_priv_area->tick_counter = jiffies;
861 chdlc_int->interrupt_permission |= APP_INT_ON_TX_FRAME;
862 }
863
864 clear_bit(SEND_CRIT, (void*)&card->wandev.critical);
865 if(card->hw.type != SDLA_S514){
866 s508_unlock(card,&smp_flags);
867 }
868
869 return err;
870}
871
872
873/*============================================================================
874 * Reply to UDP Management system.
875 * Return length of reply.
876 */
877static int reply_udp( unsigned char *data, unsigned int mbox_len )
878{
879
880 unsigned short len, udp_length, temp, ip_length;
881 unsigned long ip_temp;
882 int even_bound = 0;
883 chdlc_udp_pkt_t *c_udp_pkt = (chdlc_udp_pkt_t *)data;
884
885 /* Set length of packet */
886 len = sizeof(ip_pkt_t)+
887 sizeof(udp_pkt_t)+
888 sizeof(wp_mgmt_t)+
889 sizeof(cblock_t)+
890 sizeof(trace_info_t)+
891 mbox_len;
892
893 /* fill in UDP reply */
894 c_udp_pkt->wp_mgmt.request_reply = UDPMGMT_REPLY;
895
896 /* fill in UDP length */
897 udp_length = sizeof(udp_pkt_t)+
898 sizeof(wp_mgmt_t)+
899 sizeof(cblock_t)+
900 sizeof(trace_info_t)+
901 mbox_len;
902
903 /* put it on an even boundary */
904 if ( udp_length & 0x0001 ) {
905 udp_length += 1;
906 len += 1;
907 even_bound = 1;
908 }
909
910 temp = (udp_length<<8)|(udp_length>>8);
911 c_udp_pkt->udp_pkt.udp_length = temp;
912
913 /* swap UDP ports */
914 temp = c_udp_pkt->udp_pkt.udp_src_port;
915 c_udp_pkt->udp_pkt.udp_src_port =
916 c_udp_pkt->udp_pkt.udp_dst_port;
917 c_udp_pkt->udp_pkt.udp_dst_port = temp;
918
919 /* add UDP pseudo header */
920 temp = 0x1100;
921 *((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound)) = temp;
922 temp = (udp_length<<8)|(udp_length>>8);
923 *((unsigned short *)(c_udp_pkt->data+mbox_len+even_bound+2)) = temp;
924
925
926 /* calculate UDP checksum */
927 c_udp_pkt->udp_pkt.udp_checksum = 0;
928 c_udp_pkt->udp_pkt.udp_checksum = calc_checksum(&data[UDP_OFFSET],udp_length+UDP_OFFSET);
929
930 /* fill in IP length */
931 ip_length = len;
932 temp = (ip_length<<8)|(ip_length>>8);
933 c_udp_pkt->ip_pkt.total_length = temp;
934
935 /* swap IP addresses */
936 ip_temp = c_udp_pkt->ip_pkt.ip_src_address;
937 c_udp_pkt->ip_pkt.ip_src_address = c_udp_pkt->ip_pkt.ip_dst_address;
938 c_udp_pkt->ip_pkt.ip_dst_address = ip_temp;
939
940 /* fill in IP checksum */
941 c_udp_pkt->ip_pkt.hdr_checksum = 0;
942 c_udp_pkt->ip_pkt.hdr_checksum = calc_checksum(data,sizeof(ip_pkt_t));
943
944 return len;
945
946} /* reply_udp */
947
948unsigned short calc_checksum (char *data, int len)
949{
950 unsigned short temp;
951 unsigned long sum=0;
952 int i;
953
954 for( i = 0; i <len; i+=2 ) {
955 memcpy(&temp,&data[i],2);
956 sum += (unsigned long)temp;
957 }
958
959 while (sum >> 16 ) {
960 sum = (sum & 0xffffUL) + (sum >> 16);
961 }
962
963 temp = (unsigned short)sum;
964 temp = ~temp;
965
966 if( temp == 0 )
967 temp = 0xffff;
968
969 return temp;
970}
971
972
973/*============================================================================
974 * Get ethernet-style interface statistics.
975 * Return a pointer to struct enet_statistics.
976 */
977static struct net_device_stats* if_stats(struct net_device* dev)
978{
979 sdla_t *my_card;
980 chdlc_private_area_t* chdlc_priv_area;
981
982 /* Shutdown bug fix. In del_if() we kill
983 * dev->priv pointer. This function, gets
984 * called after del_if(), thus check
985 * if pointer has been deleted */
986 if ((chdlc_priv_area=dev->priv) == NULL)
987 return NULL;
988
989 my_card = chdlc_priv_area->card;
990 return &my_card->wandev.stats;
991}
992
993
994/****** Cisco HDLC Firmware Interface Functions *******************************/
995
996/*============================================================================
997 * Read firmware code version.
998 * Put code version as ASCII string in str.
999 */
1000static int chdlc_read_version (sdla_t* card, char* str)
1001{
1002 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1003 int len;
1004 char err;
1005 mb->buffer_length = 0;
1006 mb->command = READ_CHDLC_CODE_VERSION;
1007 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1008
1009 if(err != COMMAND_OK) {
1010 chdlc_error(card,err,mb);
1011 }
1012 else if (str) { /* is not null */
1013 len = mb->buffer_length;
1014 memcpy(str, mb->data, len);
1015 str[len] = '\0';
1016 }
1017 return (err);
1018}
1019
1020/*-----------------------------------------------------------------------------
1021 * Configure CHDLC firmware.
1022 */
1023static int chdlc_configure (sdla_t* card, void* data)
1024{
1025 int err;
1026 CHDLC_MAILBOX_STRUCT *mailbox = card->mbox;
1027 int data_length = sizeof(CHDLC_CONFIGURATION_STRUCT);
1028
1029 mailbox->buffer_length = data_length;
1030 memcpy(mailbox->data, data, data_length);
1031 mailbox->command = SET_CHDLC_CONFIGURATION;
1032 err = sdla_exec(mailbox) ? mailbox->return_code : CMD_TIMEOUT;
1033
1034 if (err != COMMAND_OK) chdlc_error (card, err, mailbox);
1035
1036 return err;
1037}
1038
1039
1040/*============================================================================
1041 * Set interrupt mode -- HDLC Version.
1042 */
1043
1044static int chdlc_set_intr_mode (sdla_t* card, unsigned mode)
1045{
1046 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1047 CHDLC_INT_TRIGGERS_STRUCT* int_data =
1048 (CHDLC_INT_TRIGGERS_STRUCT *)mb->data;
1049 int err;
1050
1051 int_data->CHDLC_interrupt_triggers = mode;
1052 int_data->IRQ = card->hw.irq;
1053 int_data->interrupt_timer = 1;
1054
1055 mb->buffer_length = sizeof(CHDLC_INT_TRIGGERS_STRUCT);
1056 mb->command = SET_CHDLC_INTERRUPT_TRIGGERS;
1057 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1058 if (err != COMMAND_OK)
1059 chdlc_error (card, err, mb);
1060 return err;
1061}
1062
1063
1064/*============================================================================
1065 * Enable communications.
1066 */
1067
1068static int chdlc_comm_enable (sdla_t* card)
1069{
1070 int err;
1071 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1072
1073 mb->buffer_length = 0;
1074 mb->command = ENABLE_CHDLC_COMMUNICATIONS;
1075 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1076 if (err != COMMAND_OK)
1077 chdlc_error(card, err, mb);
1078 else
1079 card->u.c.comm_enabled=1;
1080
1081 return err;
1082}
1083
1084/*============================================================================
1085 * Disable communications and Drop the Modem lines (DCD and RTS).
1086 */
1087static int chdlc_comm_disable (sdla_t* card)
1088{
1089 int err;
1090 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1091
1092 mb->buffer_length = 0;
1093 mb->command = DISABLE_CHDLC_COMMUNICATIONS;
1094 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1095 if (err != COMMAND_OK)
1096 chdlc_error(card,err,mb);
1097
1098 return err;
1099}
1100
1101/*============================================================================
1102 * Read communication error statistics.
1103 */
1104static int chdlc_read_comm_err_stats (sdla_t* card)
1105{
1106 int err;
1107 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1108
1109 mb->buffer_length = 0;
1110 mb->command = READ_COMMS_ERROR_STATS;
1111 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1112 if (err != COMMAND_OK)
1113 chdlc_error(card,err,mb);
1114 return err;
1115}
1116
1117
1118/*============================================================================
1119 * Read CHDLC operational statistics.
1120 */
1121static int chdlc_read_op_stats (sdla_t* card)
1122{
1123 int err;
1124 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1125
1126 mb->buffer_length = 0;
1127 mb->command = READ_CHDLC_OPERATIONAL_STATS;
1128 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1129 if (err != COMMAND_OK)
1130 chdlc_error(card,err,mb);
1131 return err;
1132}
1133
1134
1135/*============================================================================
1136 * Update communications error and general packet statistics.
1137 */
1138static int update_comms_stats(sdla_t* card,
1139 chdlc_private_area_t* chdlc_priv_area)
1140{
1141 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1142 COMMS_ERROR_STATS_STRUCT* err_stats;
1143 CHDLC_OPERATIONAL_STATS_STRUCT *op_stats;
1144
1145 /* on the first timer interrupt, read the comms error statistics */
1146 if(chdlc_priv_area->update_comms_stats == 2) {
1147 if(chdlc_read_comm_err_stats(card))
1148 return 1;
1149 err_stats = (COMMS_ERROR_STATS_STRUCT *)mb->data;
1150 card->wandev.stats.rx_over_errors =
1151 err_stats->Rx_overrun_err_count;
1152 card->wandev.stats.rx_crc_errors =
1153 err_stats->CRC_err_count;
1154 card->wandev.stats.rx_frame_errors =
1155 err_stats->Rx_abort_count;
1156 card->wandev.stats.rx_fifo_errors =
1157 err_stats->Rx_dis_pri_bfrs_full_count;
1158 card->wandev.stats.rx_missed_errors =
1159 card->wandev.stats.rx_fifo_errors;
1160 card->wandev.stats.tx_aborted_errors =
1161 err_stats->sec_Tx_abort_count;
1162 }
1163
1164 /* on the second timer interrupt, read the operational statistics */
1165 else {
1166 if(chdlc_read_op_stats(card))
1167 return 1;
1168 op_stats = (CHDLC_OPERATIONAL_STATS_STRUCT *)mb->data;
1169 card->wandev.stats.rx_length_errors =
1170 (op_stats->Rx_Data_discard_short_count +
1171 op_stats->Rx_Data_discard_long_count);
1172 }
1173
1174 return 0;
1175}
1176
1177/*============================================================================
1178 * Send packet.
1179 * Return: 0 - o.k.
1180 * 1 - no transmit buffers available
1181 */
1182static int chdlc_send (sdla_t* card, void* data, unsigned len)
1183{
1184 CHDLC_DATA_TX_STATUS_EL_STRUCT *txbuf = card->u.c.txbuf;
1185
1186 if (txbuf->opp_flag)
1187 return 1;
1188
1189 sdla_poke(&card->hw, txbuf->ptr_data_bfr, data, len);
1190
1191 txbuf->frame_length = len;
1192 txbuf->opp_flag = 1; /* start transmission */
1193
1194 /* Update transmit buffer control fields */
1195 card->u.c.txbuf = ++txbuf;
1196
1197 if ((void*)txbuf > card->u.c.txbuf_last)
1198 card->u.c.txbuf = card->u.c.txbuf_base;
1199
1200 return 0;
1201}
1202
1203/****** Firmware Error Handler **********************************************/
1204
1205/*============================================================================
1206 * Firmware error handler.
1207 * This routine is called whenever firmware command returns non-zero
1208 * return code.
1209 *
1210 * Return zero if previous command has to be cancelled.
1211 */
1212static int chdlc_error (sdla_t *card, int err, CHDLC_MAILBOX_STRUCT *mb)
1213{
1214 unsigned cmd = mb->command;
1215
1216 switch (err) {
1217
1218 case CMD_TIMEOUT:
1219 printk(KERN_ERR "%s: command 0x%02X timed out!\n",
1220 card->devname, cmd);
1221 break;
1222
1223 case S514_BOTH_PORTS_SAME_CLK_MODE:
1224 if(cmd == SET_CHDLC_CONFIGURATION) {
1225 printk(KERN_INFO
1226 "%s: Configure both ports for the same clock source\n",
1227 card->devname);
1228 break;
1229 }
1230
1231 default:
1232 printk(KERN_INFO "%s: command 0x%02X returned 0x%02X!\n",
1233 card->devname, cmd, err);
1234 }
1235
1236 return 0;
1237}
1238
1239/****** Interrupt Handlers **************************************************/
1240
1241/*============================================================================
1242 * Cisco HDLC interrupt service routine.
1243 */
1244STATIC void wsppp_isr (sdla_t* card)
1245{
1246 struct net_device* dev;
1247 SHARED_MEMORY_INFO_STRUCT* flags = NULL;
1248 int i;
1249 sdla_t *my_card;
1250
1251
1252 /* Check for which port the interrupt has been generated
1253 * Since Secondary Port is piggybacking on the Primary
1254 * the check must be done here.
1255 */
1256
1257 flags = card->u.c.flags;
1258 if (!flags->interrupt_info_struct.interrupt_type){
1259 /* Check for a second port (piggybacking) */
1260 if((my_card = card->next)){
1261 flags = my_card->u.c.flags;
1262 if (flags->interrupt_info_struct.interrupt_type){
1263 card = my_card;
1264 card->isr(card);
1265 return;
1266 }
1267 }
1268 }
1269
1270 dev = card->wandev.dev;
1271 card->in_isr = 1;
1272 flags = card->u.c.flags;
1273
1274 /* If we get an interrupt with no network device, stop the interrupts
1275 * and issue an error */
1276 if ((!dev || !dev->priv) && flags->interrupt_info_struct.interrupt_type !=
1277 COMMAND_COMPLETE_APP_INT_PEND){
1278 goto isr_done;
1279 }
1280
1281
1282 /* if critical due to peripheral operations
1283 * ie. update() or getstats() then reset the interrupt and
1284 * wait for the board to retrigger.
1285 */
1286 if(test_bit(PERI_CRIT, (void*)&card->wandev.critical)) {
1287 flags->interrupt_info_struct.
1288 interrupt_type = 0;
1289 goto isr_done;
1290 }
1291
1292
1293 /* On a 508 Card, if critical due to if_send
1294 * Major Error !!!
1295 */
1296 if(card->hw.type != SDLA_S514) {
1297 if(test_bit(0, (void*)&card->wandev.critical)) {
1298 printk(KERN_INFO "%s: Critical while in ISR: %lx\n",
1299 card->devname, card->wandev.critical);
1300 goto isr_done;
1301 }
1302 }
1303
1304 switch(flags->interrupt_info_struct.interrupt_type) {
1305
1306 case RX_APP_INT_PEND: /* 0x01: receive interrupt */
1307 rx_intr(card);
1308 break;
1309
1310 case TX_APP_INT_PEND: /* 0x02: transmit interrupt */
1311 flags->interrupt_info_struct.interrupt_permission &=
1312 ~APP_INT_ON_TX_FRAME;
1313
1314 netif_wake_queue(dev);
1315 break;
1316
1317 case COMMAND_COMPLETE_APP_INT_PEND:/* 0x04: cmd cplt */
1318 ++ Intr_test_counter;
1319 break;
1320
1321 case CHDLC_EXCEP_COND_APP_INT_PEND: /* 0x20 */
1322 process_chdlc_exception(card);
1323 break;
1324
1325 case GLOBAL_EXCEP_COND_APP_INT_PEND:
1326 process_global_exception(card);
1327 break;
1328
1329 case TIMER_APP_INT_PEND:
1330 timer_intr(card);
1331 break;
1332
1333 default:
1334 printk(KERN_INFO "%s: spurious interrupt 0x%02X!\n",
1335 card->devname,
1336 flags->interrupt_info_struct.interrupt_type);
1337 printk(KERN_INFO "Code name: ");
1338 for(i = 0; i < 4; i ++)
1339 printk(KERN_INFO "%c",
1340 flags->global_info_struct.codename[i]);
1341 printk(KERN_INFO "\nCode version: ");
1342 for(i = 0; i < 4; i ++)
1343 printk(KERN_INFO "%c",
1344 flags->global_info_struct.codeversion[i]);
1345 printk(KERN_INFO "\n");
1346 break;
1347 }
1348
1349isr_done:
1350 card->in_isr = 0;
1351 flags->interrupt_info_struct.interrupt_type = 0;
1352}
1353
1354/*============================================================================
1355 * Receive interrupt handler.
1356 */
1357static void rx_intr (sdla_t* card)
1358{
1359 struct net_device *dev;
1360 chdlc_private_area_t *chdlc_priv_area;
1361 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
1362 CHDLC_DATA_RX_STATUS_EL_STRUCT *rxbuf = card->u.c.rxmb;
1363 struct sk_buff *skb;
1364 unsigned len;
1365 unsigned addr = rxbuf->ptr_data_bfr;
1366 void *buf;
1367 int i,udp_type;
1368
1369 if (rxbuf->opp_flag != 0x01) {
1370 printk(KERN_INFO
1371 "%s: corrupted Rx buffer @ 0x%X, flag = 0x%02X!\n",
1372 card->devname, (unsigned)rxbuf, rxbuf->opp_flag);
1373 printk(KERN_INFO "Code name: ");
1374 for(i = 0; i < 4; i ++)
1375 printk(KERN_INFO "%c",
1376 flags->global_info_struct.codename[i]);
1377 printk(KERN_INFO "\nCode version: ");
1378 for(i = 0; i < 4; i ++)
1379 printk(KERN_INFO "%c",
1380 flags->global_info_struct.codeversion[i]);
1381 printk(KERN_INFO "\n");
1382
1383
1384 /* Bug Fix: Mar 6 2000
1385 * If we get a corrupted mailbox, it measn that driver
1386 * is out of sync with the firmware. There is no recovery.
1387 * If we don't turn off all interrupts for this card
1388 * the machine will crash.
1389 */
1390 printk(KERN_INFO "%s: Critical router failure ...!!!\n", card->devname);
1391 printk(KERN_INFO "Please contact Sangoma Technologies !\n");
1392 chdlc_set_intr_mode(card,0);
1393 return;
1394 }
1395
1396 dev = card->wandev.dev;
1397
1398 if (!dev){
1399 goto rx_exit;
1400 }
1401
1402 if (!netif_running(dev)){
1403 goto rx_exit;
1404 }
1405
1406 chdlc_priv_area = dev->priv;
1407
1408 if (rxbuf->error_flag){
1409 goto rx_exit;
1410 }
1411 /* Take off two CRC bytes */
1412
1413 if (rxbuf->frame_length < 7 || rxbuf->frame_length > 1506 ){
1414 goto rx_exit;
1415 }
1416
1417 len = rxbuf->frame_length - CRC_LENGTH;
1418
1419 /* Allocate socket buffer */
1420 skb = dev_alloc_skb(len);
1421
1422 if (skb == NULL) {
1423 if (net_ratelimit()){
1424 printk(KERN_INFO "%s: no socket buffers available!\n",
1425 card->devname);
1426 }
1427 ++card->wandev.stats.rx_dropped;
1428 goto rx_exit;
1429 }
1430
1431 /* Copy data to the socket buffer */
1432 if((addr + len) > card->u.c.rx_top + 1) {
1433 unsigned tmp = card->u.c.rx_top - addr + 1;
1434 buf = skb_put(skb, tmp);
1435 sdla_peek(&card->hw, addr, buf, tmp);
1436 addr = card->u.c.rx_base;
1437 len -= tmp;
1438 }
1439
1440 buf = skb_put(skb, len);
1441 sdla_peek(&card->hw, addr, buf, len);
1442
1443 skb->protocol = htons(ETH_P_WAN_PPP);
1444
1445 card->wandev.stats.rx_packets ++;
1446 card->wandev.stats.rx_bytes += skb->len;
1447 udp_type = udp_pkt_type( skb, card );
1448
1449 if(udp_type == UDP_CPIPE_TYPE) {
1450 if(store_udp_mgmt_pkt(UDP_PKT_FRM_NETWORK,
1451 card, skb, dev, chdlc_priv_area)) {
1452 flags->interrupt_info_struct.
1453 interrupt_permission |=
1454 APP_INT_ON_TIMER;
1455 }
1456 }else{
1457 /* Pass it up the protocol stack */
1458 skb->dev = dev;
1459 skb->mac.raw = skb->data;
1460 netif_rx(skb);
1461 dev->last_rx = jiffies;
1462 }
1463
1464rx_exit:
1465 /* Release buffer element and calculate a pointer to the next one */
1466 rxbuf->opp_flag = 0x00;
1467 card->u.c.rxmb = ++ rxbuf;
1468 if((void*)rxbuf > card->u.c.rxbuf_last){
1469 card->u.c.rxmb = card->u.c.rxbuf_base;
1470 }
1471}
1472
1473/*============================================================================
1474 * Timer interrupt handler.
1475 * The timer interrupt is used for two purposes:
1476 * 1) Processing udp calls from 'cpipemon'.
1477 * 2) Reading board-level statistics for updating the proc file system.
1478 */
1479void timer_intr(sdla_t *card)
1480{
1481 struct net_device* dev;
1482 chdlc_private_area_t* chdlc_priv_area = NULL;
1483 SHARED_MEMORY_INFO_STRUCT* flags = NULL;
1484
1485 dev = card->wandev.dev;
1486 chdlc_priv_area = dev->priv;
1487
1488 if (chdlc_priv_area->timer_int_enabled & TMR_INT_ENABLED_CONFIG) {
1489 if (!config_chdlc(card)){
1490 chdlc_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_CONFIG;
1491 }
1492 }
1493
1494 /* process a udp call if pending */
1495 if(chdlc_priv_area->timer_int_enabled & TMR_INT_ENABLED_UDP) {
1496 process_udp_mgmt_pkt(card, dev,
1497 chdlc_priv_area);
1498 chdlc_priv_area->timer_int_enabled &= ~TMR_INT_ENABLED_UDP;
1499 }
1500
1501
1502 /* read the communications statistics if required */
1503 if(chdlc_priv_area->timer_int_enabled & TMR_INT_ENABLED_UPDATE) {
1504 update_comms_stats(card, chdlc_priv_area);
1505 if(!(-- chdlc_priv_area->update_comms_stats)) {
1506 chdlc_priv_area->timer_int_enabled &=
1507 ~TMR_INT_ENABLED_UPDATE;
1508 }
1509 }
1510
1511 /* only disable the timer interrupt if there are no udp or statistic */
1512 /* updates pending */
1513 if(!chdlc_priv_area->timer_int_enabled) {
1514 flags = card->u.c.flags;
1515 flags->interrupt_info_struct.interrupt_permission &=
1516 ~APP_INT_ON_TIMER;
1517 }
1518}
1519
1520/*------------------------------------------------------------------------------
1521 Miscellaneous Functions
1522 - set_chdlc_config() used to set configuration options on the board
1523------------------------------------------------------------------------------*/
1524
1525static int set_chdlc_config(sdla_t* card)
1526{
1527
1528 CHDLC_CONFIGURATION_STRUCT cfg;
1529
1530 memset(&cfg, 0, sizeof(CHDLC_CONFIGURATION_STRUCT));
1531
1532 if(card->wandev.clocking)
1533 cfg.baud_rate = card->wandev.bps;
1534
1535 cfg.line_config_options = (card->wandev.interface == WANOPT_RS232) ?
1536 INTERFACE_LEVEL_RS232 : INTERFACE_LEVEL_V35;
1537
1538 cfg.modem_config_options = 0;
1539 //API OPTIONS
1540 cfg.CHDLC_API_options = DISCARD_RX_ERROR_FRAMES;
1541 cfg.modem_status_timer = 100;
1542 cfg.CHDLC_protocol_options = HDLC_STREAMING_MODE;
1543 cfg.percent_data_buffer_for_Tx = 50;
1544 cfg.CHDLC_statistics_options = (CHDLC_TX_DATA_BYTE_COUNT_STAT |
1545 CHDLC_RX_DATA_BYTE_COUNT_STAT);
1546 cfg.max_CHDLC_data_field_length = card->wandev.mtu;
1547
1548 cfg.transmit_keepalive_timer = 0;
1549 cfg.receive_keepalive_timer = 0;
1550 cfg.keepalive_error_tolerance = 0;
1551 cfg.SLARP_request_timer = 0;
1552
1553 cfg.IP_address = 0;
1554 cfg.IP_netmask = 0;
1555
1556 return chdlc_configure(card, &cfg);
1557}
1558
1559/*============================================================================
1560 * Process global exception condition
1561 */
1562static int process_global_exception(sdla_t *card)
1563{
1564 CHDLC_MAILBOX_STRUCT* mbox = card->mbox;
1565 int err;
1566
1567 mbox->buffer_length = 0;
1568 mbox->command = READ_GLOBAL_EXCEPTION_CONDITION;
1569 err = sdla_exec(mbox) ? mbox->return_code : CMD_TIMEOUT;
1570
1571 if(err != CMD_TIMEOUT ){
1572
1573 switch(mbox->return_code) {
1574
1575 case EXCEP_MODEM_STATUS_CHANGE:
1576
1577 printk(KERN_INFO "%s: Modem status change\n",
1578 card->devname);
1579
1580 switch(mbox->data[0] & (DCD_HIGH | CTS_HIGH)) {
1581 case (DCD_HIGH):
1582 printk(KERN_INFO "%s: DCD high, CTS low\n",card->devname);
1583 break;
1584 case (CTS_HIGH):
1585 printk(KERN_INFO "%s: DCD low, CTS high\n",card->devname);
1586 break;
1587 case ((DCD_HIGH | CTS_HIGH)):
1588 printk(KERN_INFO "%s: DCD high, CTS high\n",card->devname);
1589 break;
1590 default:
1591 printk(KERN_INFO "%s: DCD low, CTS low\n",card->devname);
1592 break;
1593 }
1594
1595 if (!(mbox->data[0] & DCD_HIGH) || !(mbox->data[0] & DCD_HIGH)){
1596 //printk(KERN_INFO "Sending TERM Request Manually !\n");
1597 send_ppp_term_request(card->wandev.dev);
1598 }
1599 break;
1600
1601 case EXCEP_TRC_DISABLED:
1602 printk(KERN_INFO "%s: Line trace disabled\n",
1603 card->devname);
1604 break;
1605
1606 case EXCEP_IRQ_TIMEOUT:
1607 printk(KERN_INFO "%s: IRQ timeout occurred\n",
1608 card->devname);
1609 break;
1610
1611 default:
1612 printk(KERN_INFO "%s: Global exception %x\n",
1613 card->devname, mbox->return_code);
1614 break;
1615 }
1616 }
1617 return 0;
1618}
1619
1620
1621/*============================================================================
1622 * Process chdlc exception condition
1623 */
1624static int process_chdlc_exception(sdla_t *card)
1625{
1626 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
1627 int err;
1628
1629 mb->buffer_length = 0;
1630 mb->command = READ_CHDLC_EXCEPTION_CONDITION;
1631 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1632 if(err != CMD_TIMEOUT) {
1633
1634 switch (err) {
1635
1636 case EXCEP_LINK_ACTIVE:
1637 port_set_state(card, WAN_CONNECTED);
1638 break;
1639
1640 case EXCEP_LINK_INACTIVE_MODEM:
1641 port_set_state(card, WAN_DISCONNECTED);
1642 break;
1643
1644 case EXCEP_LOOPBACK_CONDITION:
1645 printk(KERN_INFO "%s: Loopback Condition Detected.\n",
1646 card->devname);
1647 break;
1648
1649 case NO_CHDLC_EXCEP_COND_TO_REPORT:
1650 printk(KERN_INFO "%s: No exceptions reported.\n",
1651 card->devname);
1652 break;
1653 default:
1654 printk(KERN_INFO "%s: Exception Condition %x!\n",
1655 card->devname,err);
1656 break;
1657 }
1658
1659 }
1660 return 0;
1661}
1662
1663
1664/*=============================================================================
1665 * Store a UDP management packet for later processing.
1666 */
1667
1668static int store_udp_mgmt_pkt(char udp_pkt_src, sdla_t* card,
1669 struct sk_buff *skb, struct net_device* dev,
1670 chdlc_private_area_t* chdlc_priv_area )
1671{
1672 int udp_pkt_stored = 0;
1673
1674 if(!chdlc_priv_area->udp_pkt_lgth &&
1675 (skb->len <= MAX_LGTH_UDP_MGNT_PKT)) {
1676 chdlc_priv_area->udp_pkt_lgth = skb->len;
1677 chdlc_priv_area->udp_pkt_src = udp_pkt_src;
1678 memcpy(chdlc_priv_area->udp_pkt_data, skb->data, skb->len);
1679 chdlc_priv_area->timer_int_enabled = TMR_INT_ENABLED_UDP;
1680 udp_pkt_stored = 1;
1681 }
1682
1683 if(udp_pkt_src == UDP_PKT_FRM_STACK)
1684 dev_kfree_skb_any(skb);
1685 else
1686 dev_kfree_skb_any(skb);
1687
1688 return(udp_pkt_stored);
1689}
1690
1691
1692/*=============================================================================
1693 * Process UDP management packet.
1694 */
1695
1696static int process_udp_mgmt_pkt(sdla_t* card, struct net_device* dev,
1697 chdlc_private_area_t* chdlc_priv_area )
1698{
1699 unsigned char *buf;
1700 unsigned int frames, len;
1701 struct sk_buff *new_skb;
1702 unsigned short buffer_length, real_len;
1703 unsigned long data_ptr;
1704 unsigned data_length;
1705 int udp_mgmt_req_valid = 1;
1706 CHDLC_MAILBOX_STRUCT *mb = card->mbox;
1707 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
1708 chdlc_udp_pkt_t *chdlc_udp_pkt;
1709 struct timeval tv;
1710 int err;
1711 char ut_char;
1712
1713 chdlc_udp_pkt = (chdlc_udp_pkt_t *) chdlc_priv_area->udp_pkt_data;
1714
1715 if(chdlc_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
1716
1717 switch(chdlc_udp_pkt->cblock.command) {
1718 case READ_GLOBAL_STATISTICS:
1719 case READ_MODEM_STATUS:
1720 case READ_CHDLC_LINK_STATUS:
1721 case CPIPE_ROUTER_UP_TIME:
1722 case READ_COMMS_ERROR_STATS:
1723 case READ_CHDLC_OPERATIONAL_STATS:
1724
1725 /* These two commands are executed for
1726 * each request */
1727 case READ_CHDLC_CONFIGURATION:
1728 case READ_CHDLC_CODE_VERSION:
1729 udp_mgmt_req_valid = 1;
1730 break;
1731 default:
1732 udp_mgmt_req_valid = 0;
1733 break;
1734 }
1735 }
1736
1737 if(!udp_mgmt_req_valid) {
1738
1739 /* set length to 0 */
1740 chdlc_udp_pkt->cblock.buffer_length = 0;
1741
1742 /* set return code */
1743 chdlc_udp_pkt->cblock.return_code = 0xCD;
1744
1745 if (net_ratelimit()){
1746 printk(KERN_INFO
1747 "%s: Warning, Illegal UDP command attempted from network: %x\n",
1748 card->devname,chdlc_udp_pkt->cblock.command);
1749 }
1750
1751 } else {
1752 unsigned long trace_status_cfg_addr = 0;
1753 TRACE_STATUS_EL_CFG_STRUCT trace_cfg_struct;
1754 TRACE_STATUS_ELEMENT_STRUCT trace_element_struct;
1755
1756 switch(chdlc_udp_pkt->cblock.command) {
1757
1758 case CPIPE_ENABLE_TRACING:
1759 if (!chdlc_priv_area->TracingEnabled) {
1760
1761 /* OPERATE_DATALINE_MONITOR */
1762
1763 mb->buffer_length = sizeof(LINE_TRACE_CONFIG_STRUCT);
1764 mb->command = SET_TRACE_CONFIGURATION;
1765
1766 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->
1767 trace_config = TRACE_ACTIVE;
1768 /* Trace delay mode is not used because it slows
1769 down transfer and results in a standoff situation
1770 when there is a lot of data */
1771
1772 /* Configure the Trace based on user inputs */
1773 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->trace_config |=
1774 chdlc_udp_pkt->data[0];
1775
1776 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->
1777 trace_deactivation_timer = 4000;
1778
1779
1780 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1781 if (err != COMMAND_OK) {
1782 chdlc_error(card,err,mb);
1783 card->TracingEnabled = 0;
1784 chdlc_udp_pkt->cblock.return_code = err;
1785 mb->buffer_length = 0;
1786 break;
1787 }
1788
1789 /* Get the base address of the trace element list */
1790 mb->buffer_length = 0;
1791 mb->command = READ_TRACE_CONFIGURATION;
1792 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1793
1794 if (err != COMMAND_OK) {
1795 chdlc_error(card,err,mb);
1796 chdlc_priv_area->TracingEnabled = 0;
1797 chdlc_udp_pkt->cblock.return_code = err;
1798 mb->buffer_length = 0;
1799 break;
1800 }
1801
1802 trace_status_cfg_addr =((LINE_TRACE_CONFIG_STRUCT *)
1803 mb->data) -> ptr_trace_stat_el_cfg_struct;
1804
1805 sdla_peek(&card->hw, trace_status_cfg_addr,
1806 &trace_cfg_struct, sizeof(trace_cfg_struct));
1807
1808 chdlc_priv_area->start_trace_addr = trace_cfg_struct.
1809 base_addr_trace_status_elements;
1810
1811 chdlc_priv_area->number_trace_elements =
1812 trace_cfg_struct.number_trace_status_elements;
1813
1814 chdlc_priv_area->end_trace_addr = (unsigned long)
1815 ((TRACE_STATUS_ELEMENT_STRUCT *)
1816 chdlc_priv_area->start_trace_addr +
1817 (chdlc_priv_area->number_trace_elements - 1));
1818
1819 chdlc_priv_area->base_addr_trace_buffer =
1820 trace_cfg_struct.base_addr_trace_buffer;
1821
1822 chdlc_priv_area->end_addr_trace_buffer =
1823 trace_cfg_struct.end_addr_trace_buffer;
1824
1825 chdlc_priv_area->curr_trace_addr =
1826 trace_cfg_struct.next_trace_element_to_use;
1827
1828 chdlc_priv_area->available_buffer_space = 2000 -
1829 sizeof(ip_pkt_t) -
1830 sizeof(udp_pkt_t) -
1831 sizeof(wp_mgmt_t) -
1832 sizeof(cblock_t) -
1833 sizeof(trace_info_t);
1834 }
1835 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
1836 mb->buffer_length = 0;
1837 chdlc_priv_area->TracingEnabled = 1;
1838 break;
1839
1840
1841 case CPIPE_DISABLE_TRACING:
1842 if (chdlc_priv_area->TracingEnabled) {
1843
1844 /* OPERATE_DATALINE_MONITOR */
1845 mb->buffer_length = sizeof(LINE_TRACE_CONFIG_STRUCT);
1846 mb->command = SET_TRACE_CONFIGURATION;
1847 ((LINE_TRACE_CONFIG_STRUCT *)mb->data)->
1848 trace_config = TRACE_INACTIVE;
1849 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
1850 }
1851
1852 chdlc_priv_area->TracingEnabled = 0;
1853 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
1854 mb->buffer_length = 0;
1855 break;
1856
1857
1858 case CPIPE_GET_TRACE_INFO:
1859
1860 if (!chdlc_priv_area->TracingEnabled) {
1861 chdlc_udp_pkt->cblock.return_code = 1;
1862 mb->buffer_length = 0;
1863 break;
1864 }
1865
1866 chdlc_udp_pkt->trace_info.ismoredata = 0x00;
1867 buffer_length = 0; /* offset of packet already occupied */
1868
1869 for (frames=0; frames < chdlc_priv_area->number_trace_elements; frames++){
1870
1871 trace_pkt_t *trace_pkt = (trace_pkt_t *)
1872 &chdlc_udp_pkt->data[buffer_length];
1873
1874 sdla_peek(&card->hw, chdlc_priv_area->curr_trace_addr,
1875 (unsigned char *)&trace_element_struct,
1876 sizeof(TRACE_STATUS_ELEMENT_STRUCT));
1877
1878 if (trace_element_struct.opp_flag == 0x00) {
1879 break;
1880 }
1881
1882 /* get pointer to real data */
1883 data_ptr = trace_element_struct.ptr_data_bfr;
1884
1885 /* See if there is actual data on the trace buffer */
1886 if (data_ptr){
1887 data_length = trace_element_struct.trace_length;
1888 }else{
1889 data_length = 0;
1890 chdlc_udp_pkt->trace_info.ismoredata = 0x01;
1891 }
1892
1893 if( (chdlc_priv_area->available_buffer_space - buffer_length)
1894 < ( sizeof(trace_pkt_t) + data_length) ) {
1895
1896 /* indicate there are more frames on board & exit */
1897 chdlc_udp_pkt->trace_info.ismoredata = 0x01;
1898 break;
1899 }
1900
1901 trace_pkt->status = trace_element_struct.trace_type;
1902
1903 trace_pkt->time_stamp =
1904 trace_element_struct.trace_time_stamp;
1905
1906 trace_pkt->real_length =
1907 trace_element_struct.trace_length;
1908
1909 /* see if we can fit the frame into the user buffer */
1910 real_len = trace_pkt->real_length;
1911
1912 if (data_ptr == 0) {
1913 trace_pkt->data_avail = 0x00;
1914 } else {
1915 unsigned tmp = 0;
1916
1917 /* get the data from circular buffer
1918 must check for end of buffer */
1919 trace_pkt->data_avail = 0x01;
1920
1921 if ((data_ptr + real_len) >
1922 chdlc_priv_area->end_addr_trace_buffer + 1){
1923
1924 tmp = chdlc_priv_area->end_addr_trace_buffer - data_ptr + 1;
1925 sdla_peek(&card->hw, data_ptr,
1926 trace_pkt->data,tmp);
1927 data_ptr = chdlc_priv_area->base_addr_trace_buffer;
1928 }
1929
1930 sdla_peek(&card->hw, data_ptr,
1931 &trace_pkt->data[tmp], real_len - tmp);
1932 }
1933
1934 /* zero the opp flag to show we got the frame */
1935 ut_char = 0x00;
1936 sdla_poke(&card->hw, chdlc_priv_area->curr_trace_addr, &ut_char, 1);
1937
1938 /* now move onto the next frame */
1939 chdlc_priv_area->curr_trace_addr += sizeof(TRACE_STATUS_ELEMENT_STRUCT);
1940
1941 /* check if we went over the last address */
1942 if ( chdlc_priv_area->curr_trace_addr > chdlc_priv_area->end_trace_addr ) {
1943 chdlc_priv_area->curr_trace_addr = chdlc_priv_area->start_trace_addr;
1944 }
1945
1946 if(trace_pkt->data_avail == 0x01) {
1947 buffer_length += real_len - 1;
1948 }
1949
1950 /* for the header */
1951 buffer_length += sizeof(trace_pkt_t);
1952
1953 } /* For Loop */
1954
1955 if (frames == chdlc_priv_area->number_trace_elements){
1956 chdlc_udp_pkt->trace_info.ismoredata = 0x01;
1957 }
1958 chdlc_udp_pkt->trace_info.num_frames = frames;
1959
1960 mb->buffer_length = buffer_length;
1961 chdlc_udp_pkt->cblock.buffer_length = buffer_length;
1962
1963 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
1964
1965 break;
1966
1967
1968 case CPIPE_FT1_READ_STATUS:
1969 ((unsigned char *)chdlc_udp_pkt->data )[0] =
1970 flags->FT1_info_struct.parallel_port_A_input;
1971
1972 ((unsigned char *)chdlc_udp_pkt->data )[1] =
1973 flags->FT1_info_struct.parallel_port_B_input;
1974
1975 chdlc_udp_pkt->cblock.return_code = COMMAND_OK;
1976 mb->buffer_length = 2;
1977 break;
1978
1979 case CPIPE_ROUTER_UP_TIME:
1980 do_gettimeofday( &tv );
1981 chdlc_priv_area->router_up_time = tv.tv_sec -
1982 chdlc_priv_area->router_start_time;
1983 *(unsigned long *)&chdlc_udp_pkt->data =
1984 chdlc_priv_area->router_up_time;
1985 mb->buffer_length = sizeof(unsigned long);
1986 break;
1987
1988 case FT1_MONITOR_STATUS_CTRL:
1989 /* Enable FT1 MONITOR STATUS */
1990 if ((chdlc_udp_pkt->data[0] & ENABLE_READ_FT1_STATUS) ||
1991 (chdlc_udp_pkt->data[0] & ENABLE_READ_FT1_OP_STATS)) {
1992
1993 if( rCount++ != 0 ) {
1994 chdlc_udp_pkt->cblock.
1995 return_code = COMMAND_OK;
1996 mb->buffer_length = 1;
1997 break;
1998 }
1999 }
2000
2001 /* Disable FT1 MONITOR STATUS */
2002 if( chdlc_udp_pkt->data[0] == 0) {
2003
2004 if( --rCount != 0) {
2005 chdlc_udp_pkt->cblock.
2006 return_code = COMMAND_OK;
2007 mb->buffer_length = 1;
2008 break;
2009 }
2010 }
2011
2012 default:
2013 /* it's a board command */
2014 mb->command = chdlc_udp_pkt->cblock.command;
2015 mb->buffer_length = chdlc_udp_pkt->cblock.buffer_length;
2016 if (mb->buffer_length) {
2017 memcpy(&mb->data, (unsigned char *) chdlc_udp_pkt->
2018 data, mb->buffer_length);
2019 }
2020 /* run the command on the board */
2021 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2022 if (err != COMMAND_OK) {
2023 break;
2024 }
2025
2026 /* copy the result back to our buffer */
2027 memcpy(&chdlc_udp_pkt->cblock, mb, sizeof(cblock_t));
2028
2029 if (mb->buffer_length) {
2030 memcpy(&chdlc_udp_pkt->data, &mb->data,
2031 mb->buffer_length);
2032 }
2033
2034 } /* end of switch */
2035 } /* end of else */
2036
2037 /* Fill UDP TTL */
2038 chdlc_udp_pkt->ip_pkt.ttl = card->wandev.ttl;
2039
2040 len = reply_udp(chdlc_priv_area->udp_pkt_data, mb->buffer_length);
2041
2042 if(chdlc_priv_area->udp_pkt_src == UDP_PKT_FRM_NETWORK) {
2043 if(!chdlc_send(card, chdlc_priv_area->udp_pkt_data, len)) {
2044 ++ card->wandev.stats.tx_packets;
2045 card->wandev.stats.tx_bytes += len;
2046 }
2047 } else {
2048
2049 /* Pass it up the stack
2050 Allocate socket buffer */
2051 if ((new_skb = dev_alloc_skb(len)) != NULL) {
2052 /* copy data into new_skb */
2053
2054 buf = skb_put(new_skb, len);
2055 memcpy(buf, chdlc_priv_area->udp_pkt_data, len);
2056
2057 /* Decapsulate pkt and pass it up the protocol stack */
2058 new_skb->protocol = htons(ETH_P_IP);
2059 new_skb->dev = dev;
2060 new_skb->mac.raw = new_skb->data;
2061
2062 netif_rx(new_skb);
2063 dev->last_rx = jiffies;
2064 } else {
2065
2066 printk(KERN_INFO "%s: no socket buffers available!\n",
2067 card->devname);
2068 }
2069 }
2070
2071 chdlc_priv_area->udp_pkt_lgth = 0;
2072
2073 return 0;
2074}
2075
2076/*============================================================================
2077 * Initialize Receive and Transmit Buffers.
2078 */
2079
2080static void init_chdlc_tx_rx_buff(sdla_t* card, struct net_device *dev)
2081{
2082 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
2083 CHDLC_TX_STATUS_EL_CFG_STRUCT *tx_config;
2084 CHDLC_RX_STATUS_EL_CFG_STRUCT *rx_config;
2085 char err;
2086
2087 mb->buffer_length = 0;
2088 mb->command = READ_CHDLC_CONFIGURATION;
2089 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2090
2091 if(err != COMMAND_OK) {
2092 chdlc_error(card,err,mb);
2093 return;
2094 }
2095
2096 if(card->hw.type == SDLA_S514) {
2097 tx_config = (CHDLC_TX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
2098 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
2099 ptr_CHDLC_Tx_stat_el_cfg_struct));
2100 rx_config = (CHDLC_RX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
2101 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
2102 ptr_CHDLC_Rx_stat_el_cfg_struct));
2103
2104 /* Setup Head and Tails for buffers */
2105 card->u.c.txbuf_base = (void *)(card->hw.dpmbase +
2106 tx_config->base_addr_Tx_status_elements);
2107 card->u.c.txbuf_last =
2108 (CHDLC_DATA_TX_STATUS_EL_STRUCT *)
2109 card->u.c.txbuf_base +
2110 (tx_config->number_Tx_status_elements - 1);
2111
2112 card->u.c.rxbuf_base = (void *)(card->hw.dpmbase +
2113 rx_config->base_addr_Rx_status_elements);
2114 card->u.c.rxbuf_last =
2115 (CHDLC_DATA_RX_STATUS_EL_STRUCT *)
2116 card->u.c.rxbuf_base +
2117 (rx_config->number_Rx_status_elements - 1);
2118
2119 /* Set up next pointer to be used */
2120 card->u.c.txbuf = (void *)(card->hw.dpmbase +
2121 tx_config->next_Tx_status_element_to_use);
2122 card->u.c.rxmb = (void *)(card->hw.dpmbase +
2123 rx_config->next_Rx_status_element_to_use);
2124 }
2125 else {
2126 tx_config = (CHDLC_TX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
2127 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
2128 ptr_CHDLC_Tx_stat_el_cfg_struct % SDLA_WINDOWSIZE));
2129
2130 rx_config = (CHDLC_RX_STATUS_EL_CFG_STRUCT *)(card->hw.dpmbase +
2131 (((CHDLC_CONFIGURATION_STRUCT *)mb->data)->
2132 ptr_CHDLC_Rx_stat_el_cfg_struct % SDLA_WINDOWSIZE));
2133
2134 /* Setup Head and Tails for buffers */
2135 card->u.c.txbuf_base = (void *)(card->hw.dpmbase +
2136 (tx_config->base_addr_Tx_status_elements % SDLA_WINDOWSIZE));
2137 card->u.c.txbuf_last =
2138 (CHDLC_DATA_TX_STATUS_EL_STRUCT *)card->u.c.txbuf_base
2139 + (tx_config->number_Tx_status_elements - 1);
2140 card->u.c.rxbuf_base = (void *)(card->hw.dpmbase +
2141 (rx_config->base_addr_Rx_status_elements % SDLA_WINDOWSIZE));
2142 card->u.c.rxbuf_last =
2143 (CHDLC_DATA_RX_STATUS_EL_STRUCT *)card->u.c.rxbuf_base
2144 + (rx_config->number_Rx_status_elements - 1);
2145
2146 /* Set up next pointer to be used */
2147 card->u.c.txbuf = (void *)(card->hw.dpmbase +
2148 (tx_config->next_Tx_status_element_to_use % SDLA_WINDOWSIZE));
2149 card->u.c.rxmb = (void *)(card->hw.dpmbase +
2150 (rx_config->next_Rx_status_element_to_use % SDLA_WINDOWSIZE));
2151 }
2152
2153 /* Setup Actual Buffer Start and end addresses */
2154 card->u.c.rx_base = rx_config->base_addr_Rx_buffer;
2155 card->u.c.rx_top = rx_config->end_addr_Rx_buffer;
2156
2157}
2158
2159/*=============================================================================
2160 * Perform Interrupt Test by running READ_CHDLC_CODE_VERSION command MAX_INTR
2161 * _TEST_COUNTER times.
2162 */
2163static int intr_test( sdla_t* card)
2164{
2165 CHDLC_MAILBOX_STRUCT* mb = card->mbox;
2166 int err,i;
2167
2168 Intr_test_counter = 0;
2169
2170 /* The critical flag is unset because during initialization (if_open)
2171 * we want the interrupts to be enabled so that when the wpc_isr is
2172 * called it does not exit due to critical flag set.
2173 */
2174
2175 err = chdlc_set_intr_mode(card, APP_INT_ON_COMMAND_COMPLETE);
2176
2177 if (err == CMD_OK) {
2178 for (i = 0; i < MAX_INTR_TEST_COUNTER; i ++) {
2179 mb->buffer_length = 0;
2180 mb->command = READ_CHDLC_CODE_VERSION;
2181 err = sdla_exec(mb) ? mb->return_code : CMD_TIMEOUT;
2182 }
2183 }
2184 else {
2185 return err;
2186 }
2187
2188 err = chdlc_set_intr_mode(card, 0);
2189
2190 if (err != CMD_OK)
2191 return err;
2192
2193 return 0;
2194}
2195
2196/*==============================================================================
2197 * Determine what type of UDP call it is. CPIPEAB ?
2198 */
2199static int udp_pkt_type(struct sk_buff *skb, sdla_t* card)
2200{
2201 chdlc_udp_pkt_t *chdlc_udp_pkt = (chdlc_udp_pkt_t *)skb->data;
2202
2203 if (!strncmp(chdlc_udp_pkt->wp_mgmt.signature,UDPMGMT_SIGNATURE,8) &&
2204 (chdlc_udp_pkt->udp_pkt.udp_dst_port == ntohs(card->wandev.udp_port)) &&
2205 (chdlc_udp_pkt->ip_pkt.protocol == UDPMGMT_UDP_PROTOCOL) &&
2206 (chdlc_udp_pkt->wp_mgmt.request_reply == UDPMGMT_REQUEST)) {
2207 return UDP_CPIPE_TYPE;
2208 }
2209 else return UDP_INVALID_TYPE;
2210}
2211
2212/*============================================================================
2213 * Set PORT state.
2214 */
2215static void port_set_state (sdla_t *card, int state)
2216{
2217 struct net_device *dev = card->wandev.dev;
2218 chdlc_private_area_t *chdlc_priv_area = dev->priv;
2219
2220 if (card->u.c.state != state)
2221 {
2222 switch (state)
2223 {
2224 case WAN_CONNECTED:
2225 printk (KERN_INFO "%s: HDLC link connected!\n",
2226 card->devname);
2227 break;
2228
2229 case WAN_CONNECTING:
2230 printk (KERN_INFO "%s: HDLC link connecting...\n",
2231 card->devname);
2232 break;
2233
2234 case WAN_DISCONNECTED:
2235 printk (KERN_INFO "%s: HDLC link disconnected!\n",
2236 card->devname);
2237 break;
2238 }
2239
2240 card->wandev.state = card->u.c.state = state;
2241 chdlc_priv_area->common.state = state;
2242 }
2243}
2244
2245void s508_lock (sdla_t *card, unsigned long *smp_flags)
2246{
2247 spin_lock_irqsave(&card->wandev.lock, *smp_flags);
2248 if (card->next){
2249 /* It is ok to use spin_lock here, since we
2250 * already turned off interrupts */
2251 spin_lock(&card->next->wandev.lock);
2252 }
2253}
2254
2255void s508_unlock (sdla_t *card, unsigned long *smp_flags)
2256{
2257 if (card->next){
2258 spin_unlock(&card->next->wandev.lock);
2259 }
2260 spin_unlock_irqrestore(&card->wandev.lock, *smp_flags);
2261}
2262
2263
2264
2265/*===========================================================================
2266 * config_chdlc
2267 *
2268 * Configure the chdlc protocol and enable communications.
2269 *
2270 * The if_open() function binds this function to the poll routine.
2271 * Therefore, this function will run every time the chdlc interface
2272 * is brought up. We cannot run this function from the if_open
2273 * because if_open does not have access to the remote IP address.
2274 *
2275 * If the communications are not enabled, proceed to configure
2276 * the card and enable communications.
2277 *
2278 * If the communications are enabled, it means that the interface
2279 * was shutdown by ether the user or driver. In this case, we
2280 * have to check that the IP addresses have not changed. If
2281 * the IP addresses have changed, we have to reconfigure the firmware
2282 * and update the changed IP addresses. Otherwise, just exit.
2283 *
2284 */
2285
2286static int config_chdlc (sdla_t *card)
2287{
2288 struct net_device *dev = card->wandev.dev;
2289 SHARED_MEMORY_INFO_STRUCT *flags = card->u.c.flags;
2290
2291 if (card->u.c.comm_enabled){
2292 chdlc_comm_disable(card);
2293 port_set_state(card, WAN_DISCONNECTED);
2294 }
2295
2296 if (set_chdlc_config(card)) {
2297 printk(KERN_INFO "%s: CHDLC Configuration Failed!\n",
2298 card->devname);
2299 return 0;
2300 }
2301 init_chdlc_tx_rx_buff(card, dev);
2302
2303 /* Set interrupt mode and mask */
2304 if (chdlc_set_intr_mode(card, APP_INT_ON_RX_FRAME |
2305 APP_INT_ON_GLOBAL_EXCEP_COND |
2306 APP_INT_ON_TX_FRAME |
2307 APP_INT_ON_CHDLC_EXCEP_COND | APP_INT_ON_TIMER)){
2308 printk (KERN_INFO "%s: Failed to set interrupt triggers!\n",
2309 card->devname);
2310 return 0;
2311 }
2312
2313
2314 /* Mask the Transmit and Timer interrupt */
2315 flags->interrupt_info_struct.interrupt_permission &=
2316 ~(APP_INT_ON_TX_FRAME | APP_INT_ON_TIMER);
2317
2318
2319 if (chdlc_comm_enable(card) != 0) {
2320 printk(KERN_INFO "%s: Failed to enable chdlc communications!\n",
2321 card->devname);
2322 flags->interrupt_info_struct.interrupt_permission = 0;
2323 card->u.c.comm_enabled=0;
2324 chdlc_set_intr_mode(card,0);
2325 return 0;
2326 }
2327
2328 /* Initialize Rx/Tx buffer control fields */
2329 port_set_state(card, WAN_CONNECTING);
2330 return 0;
2331}
2332
2333
2334static void send_ppp_term_request(struct net_device *dev)
2335{
2336 struct sk_buff *new_skb;
2337 unsigned char *buf;
2338
2339 if ((new_skb = dev_alloc_skb(8)) != NULL) {
2340 /* copy data into new_skb */
2341
2342 buf = skb_put(new_skb, 8);
2343 sprintf(buf,"%c%c%c%c%c%c%c%c", 0xFF,0x03,0xC0,0x21,0x05,0x98,0x00,0x07);
2344
2345 /* Decapsulate pkt and pass it up the protocol stack */
2346 new_skb->protocol = htons(ETH_P_WAN_PPP);
2347 new_skb->dev = dev;
2348 new_skb->mac.raw = new_skb->data;
2349
2350 netif_rx(new_skb);
2351 dev->last_rx = jiffies;
2352 }
2353}
2354
2355
2356MODULE_LICENSE("GPL");
2357
2358/****** End ****************************************************************/
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index fd17aa8491b6..bad09ebdb50b 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -309,7 +309,10 @@ config APPLE_AIRPORT
309 Say Y here to support the Airport 802.11b wireless Ethernet hardware 309 Say Y here to support the Airport 802.11b wireless Ethernet hardware
310 built into the Macintosh iBook and other recent PowerPC-based 310 built into the Macintosh iBook and other recent PowerPC-based
311 Macintosh machines. This is essentially a Lucent Orinoco card with 311 Macintosh machines. This is essentially a Lucent Orinoco card with
312 a non-standard interface 312 a non-standard interface.
313
314 This driver does not support the Airport Extreme (802.11b/g). Use
315 the BCM43xx driver for Airport Extreme cards.
313 316
314config PLX_HERMES 317config PLX_HERMES
315 tristate "Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.)" 318 tristate "Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.)"
@@ -353,7 +356,7 @@ config PCI_HERMES
353 356
354config ATMEL 357config ATMEL
355 tristate "Atmel at76c50x chipset 802.11b support" 358 tristate "Atmel at76c50x chipset 802.11b support"
356 depends on NET_RADIO 359 depends on NET_RADIO && (PCI || PCMCIA)
357 select FW_LOADER 360 select FW_LOADER
358 select CRC32 361 select CRC32
359 ---help--- 362 ---help---
@@ -401,6 +404,7 @@ config PCMCIA_HERMES
401config PCMCIA_SPECTRUM 404config PCMCIA_SPECTRUM
402 tristate "Symbol Spectrum24 Trilogy PCMCIA card support" 405 tristate "Symbol Spectrum24 Trilogy PCMCIA card support"
403 depends on NET_RADIO && PCMCIA && HERMES 406 depends on NET_RADIO && PCMCIA && HERMES
407 select FW_LOADER
404 ---help--- 408 ---help---
405 409
406 This is a driver for 802.11b cards using RAM-loadable Symbol 410 This is a driver for 802.11b cards using RAM-loadable Symbol
@@ -500,6 +504,7 @@ config PRISM54
500 will be called prism54.ko. 504 will be called prism54.ko.
501 505
502source "drivers/net/wireless/hostap/Kconfig" 506source "drivers/net/wireless/hostap/Kconfig"
507source "drivers/net/wireless/bcm43xx/Kconfig"
503 508
504# yes, this works even when no drivers are selected 509# yes, this works even when no drivers are selected
505config NET_WIRELESS 510config NET_WIRELESS
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 3a6f7ba326ca..c86779879361 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_PCMCIA_ATMEL) += atmel_cs.o
35obj-$(CONFIG_PRISM54) += prism54/ 35obj-$(CONFIG_PRISM54) += prism54/
36 36
37obj-$(CONFIG_HOSTAP) += hostap/ 37obj-$(CONFIG_HOSTAP) += hostap/
38obj-$(CONFIG_BCM43XX) += bcm43xx/
38 39
39# 16-bit wireless PCMCIA client drivers 40# 16-bit wireless PCMCIA client drivers
40obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o 41obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index a496460ce224..af0cbb6c5c0c 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -80,8 +80,8 @@ MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
80 event handler. 80 event handler.
81*/ 81*/
82 82
83static void airo_config(dev_link_t *link); 83static int airo_config(struct pcmcia_device *link);
84static void airo_release(dev_link_t *link); 84static void airo_release(struct pcmcia_device *link);
85 85
86/* 86/*
87 The attach() and detach() entry points are used to create and destroy 87 The attach() and detach() entry points are used to create and destroy
@@ -101,10 +101,10 @@ static void airo_detach(struct pcmcia_device *p_dev);
101/* 101/*
102 A linked list of "instances" of the aironet device. Each actual 102 A linked list of "instances" of the aironet device. Each actual
103 PCMCIA card corresponds to one device instance, and is described 103 PCMCIA card corresponds to one device instance, and is described
104 by one dev_link_t structure (defined in ds.h). 104 by one struct pcmcia_device structure (defined in ds.h).
105 105
106 You may not want to use a linked list for this -- for example, the 106 You may not want to use a linked list for this -- for example, the
107 memory card driver uses an array of dev_link_t pointers, where minor 107 memory card driver uses an array of struct pcmcia_device pointers, where minor
108 device numbers are used to derive the corresponding array index. 108 device numbers are used to derive the corresponding array index.
109*/ 109*/
110 110
@@ -114,7 +114,7 @@ static void airo_detach(struct pcmcia_device *p_dev);
114 example, ethernet cards, modems). In other cases, there may be 114 example, ethernet cards, modems). In other cases, there may be
115 many actual or logical devices (SCSI adapters, memory cards with 115 many actual or logical devices (SCSI adapters, memory cards with
116 multiple partitions). The dev_node_t structures need to be kept 116 multiple partitions). The dev_node_t structures need to be kept
117 in a linked list starting at the 'dev' field of a dev_link_t 117 in a linked list starting at the 'dev' field of a struct pcmcia_device
118 structure. We allocate them in the card's private data structure, 118 structure. We allocate them in the card's private data structure,
119 because they generally shouldn't be allocated dynamically. 119 because they generally shouldn't be allocated dynamically.
120 120
@@ -141,24 +141,16 @@ typedef struct local_info_t {
141 141
142 ======================================================================*/ 142 ======================================================================*/
143 143
144static int airo_attach(struct pcmcia_device *p_dev) 144static int airo_probe(struct pcmcia_device *p_dev)
145{ 145{
146 dev_link_t *link;
147 local_info_t *local; 146 local_info_t *local;
148 147
149 DEBUG(0, "airo_attach()\n"); 148 DEBUG(0, "airo_attach()\n");
150 149
151 /* Initialize the dev_link_t structure */
152 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
153 if (!link) {
154 printk(KERN_ERR "airo_cs: no memory for new device\n");
155 return -ENOMEM;
156 }
157
158 /* Interrupt setup */ 150 /* Interrupt setup */
159 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 151 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
160 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 152 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
161 link->irq.Handler = NULL; 153 p_dev->irq.Handler = NULL;
162 154
163 /* 155 /*
164 General socket configuration defaults can go here. In this 156 General socket configuration defaults can go here. In this
@@ -167,26 +159,18 @@ static int airo_attach(struct pcmcia_device *p_dev)
167 and attributes of IO windows) are fixed by the nature of the 159 and attributes of IO windows) are fixed by the nature of the
168 device, and can be hard-wired here. 160 device, and can be hard-wired here.
169 */ 161 */
170 link->conf.Attributes = 0; 162 p_dev->conf.Attributes = 0;
171 link->conf.Vcc = 50; 163 p_dev->conf.IntType = INT_MEMORY_AND_IO;
172 link->conf.IntType = INT_MEMORY_AND_IO;
173 164
174 /* Allocate space for private device-specific data */ 165 /* Allocate space for private device-specific data */
175 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 166 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
176 if (!local) { 167 if (!local) {
177 printk(KERN_ERR "airo_cs: no memory for new device\n"); 168 printk(KERN_ERR "airo_cs: no memory for new device\n");
178 kfree (link);
179 return -ENOMEM; 169 return -ENOMEM;
180 } 170 }
181 link->priv = local; 171 p_dev->priv = local;
182 172
183 link->handle = p_dev; 173 return airo_config(p_dev);
184 p_dev->instance = link;
185
186 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
187 airo_config(link);
188
189 return 0;
190} /* airo_attach */ 174} /* airo_attach */
191 175
192/*====================================================================== 176/*======================================================================
@@ -198,14 +182,11 @@ static int airo_attach(struct pcmcia_device *p_dev)
198 182
199 ======================================================================*/ 183 ======================================================================*/
200 184
201static void airo_detach(struct pcmcia_device *p_dev) 185static void airo_detach(struct pcmcia_device *link)
202{ 186{
203 dev_link_t *link = dev_to_instance(p_dev);
204
205 DEBUG(0, "airo_detach(0x%p)\n", link); 187 DEBUG(0, "airo_detach(0x%p)\n", link);
206 188
207 if (link->state & DEV_CONFIG) 189 airo_release(link);
208 airo_release(link);
209 190
210 if ( ((local_info_t*)link->priv)->eth_dev ) { 191 if ( ((local_info_t*)link->priv)->eth_dev ) {
211 stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 ); 192 stop_airo_card( ((local_info_t*)link->priv)->eth_dev, 0 );
@@ -213,7 +194,6 @@ static void airo_detach(struct pcmcia_device *p_dev)
213 ((local_info_t*)link->priv)->eth_dev = NULL; 194 ((local_info_t*)link->priv)->eth_dev = NULL;
214 195
215 kfree(link->priv); 196 kfree(link->priv);
216 kfree(link);
217} /* airo_detach */ 197} /* airo_detach */
218 198
219/*====================================================================== 199/*======================================================================
@@ -227,9 +207,8 @@ static void airo_detach(struct pcmcia_device *p_dev)
227#define CS_CHECK(fn, ret) \ 207#define CS_CHECK(fn, ret) \
228do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 208do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
229 209
230static void airo_config(dev_link_t *link) 210static int airo_config(struct pcmcia_device *link)
231{ 211{
232 client_handle_t handle;
233 tuple_t tuple; 212 tuple_t tuple;
234 cisparse_t parse; 213 cisparse_t parse;
235 local_info_t *dev; 214 local_info_t *dev;
@@ -237,8 +216,7 @@ static void airo_config(dev_link_t *link)
237 u_char buf[64]; 216 u_char buf[64];
238 win_req_t req; 217 win_req_t req;
239 memreq_t map; 218 memreq_t map;
240 219
241 handle = link->handle;
242 dev = link->priv; 220 dev = link->priv;
243 221
244 DEBUG(0, "airo_config(0x%p)\n", link); 222 DEBUG(0, "airo_config(0x%p)\n", link);
@@ -252,15 +230,12 @@ static void airo_config(dev_link_t *link)
252 tuple.TupleData = buf; 230 tuple.TupleData = buf;
253 tuple.TupleDataMax = sizeof(buf); 231 tuple.TupleDataMax = sizeof(buf);
254 tuple.TupleOffset = 0; 232 tuple.TupleOffset = 0;
255 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 233 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
256 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 234 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
257 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 235 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
258 link->conf.ConfigBase = parse.config.base; 236 link->conf.ConfigBase = parse.config.base;
259 link->conf.Present = parse.config.rmask[0]; 237 link->conf.Present = parse.config.rmask[0];
260 238
261 /* Configure card */
262 link->state |= DEV_CONFIG;
263
264 /* 239 /*
265 In this loop, we scan the CIS for configuration table entries, 240 In this loop, we scan the CIS for configuration table entries,
266 each of which describes a valid card configuration, including 241 each of which describes a valid card configuration, including
@@ -274,12 +249,12 @@ static void airo_config(dev_link_t *link)
274 will only use the CIS to fill in implementation-defined details. 249 will only use the CIS to fill in implementation-defined details.
275 */ 250 */
276 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 251 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
277 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 252 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
278 while (1) { 253 while (1) {
279 cistpl_cftable_entry_t dflt = { 0 }; 254 cistpl_cftable_entry_t dflt = { 0 };
280 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 255 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
281 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 256 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
282 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 257 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
283 goto next_entry; 258 goto next_entry;
284 259
285 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 260 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -294,16 +269,11 @@ static void airo_config(dev_link_t *link)
294 269
295 /* Use power settings for Vcc and Vpp if present */ 270 /* Use power settings for Vcc and Vpp if present */
296 /* Note that the CIS values need to be rescaled */ 271 /* Note that the CIS values need to be rescaled */
297 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
298 link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
299 else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
300 link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
301
302 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 272 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
303 link->conf.Vpp1 = link->conf.Vpp2 = 273 link->conf.Vpp =
304 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 274 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
305 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 275 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
306 link->conf.Vpp1 = link->conf.Vpp2 = 276 link->conf.Vpp =
307 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 277 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
308 278
309 /* Do we need to allocate an interrupt? */ 279 /* Do we need to allocate an interrupt? */
@@ -329,12 +299,12 @@ static void airo_config(dev_link_t *link)
329 } 299 }
330 300
331 /* This reserves IO space but doesn't actually enable it */ 301 /* This reserves IO space but doesn't actually enable it */
332 if (pcmcia_request_io(link->handle, &link->io) != 0) 302 if (pcmcia_request_io(link, &link->io) != 0)
333 goto next_entry; 303 goto next_entry;
334 304
335 /* 305 /*
336 Now set up a common memory window, if needed. There is room 306 Now set up a common memory window, if needed. There is room
337 in the dev_link_t structure for one memory window handle, 307 in the struct pcmcia_device structure for one memory window handle,
338 but if the base addresses need to be saved, or if multiple 308 but if the base addresses need to be saved, or if multiple
339 windows are needed, the info should go in the private data 309 windows are needed, the info should go in the private data
340 structure for this device. 310 structure for this device.
@@ -350,7 +320,7 @@ static void airo_config(dev_link_t *link)
350 req.Base = mem->win[0].host_addr; 320 req.Base = mem->win[0].host_addr;
351 req.Size = mem->win[0].len; 321 req.Size = mem->win[0].len;
352 req.AccessSpeed = 0; 322 req.AccessSpeed = 0;
353 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 323 if (pcmcia_request_window(&link, &req, &link->win) != 0)
354 goto next_entry; 324 goto next_entry;
355 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 325 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
356 if (pcmcia_map_mem_page(link->win, &map) != 0) 326 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -360,7 +330,7 @@ static void airo_config(dev_link_t *link)
360 break; 330 break;
361 331
362 next_entry: 332 next_entry:
363 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 333 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
364 } 334 }
365 335
366 /* 336 /*
@@ -369,33 +339,32 @@ static void airo_config(dev_link_t *link)
369 irq structure is initialized. 339 irq structure is initialized.
370 */ 340 */
371 if (link->conf.Attributes & CONF_ENABLE_IRQ) 341 if (link->conf.Attributes & CONF_ENABLE_IRQ)
372 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 342 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
373 343
374 /* 344 /*
375 This actually configures the PCMCIA socket -- setting up 345 This actually configures the PCMCIA socket -- setting up
376 the I/O windows and the interrupt mapping, and putting the 346 the I/O windows and the interrupt mapping, and putting the
377 card and host interface into "Memory and IO" mode. 347 card and host interface into "Memory and IO" mode.
378 */ 348 */
379 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 349 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
380 ((local_info_t*)link->priv)->eth_dev = 350 ((local_info_t*)link->priv)->eth_dev =
381 init_airo_card( link->irq.AssignedIRQ, 351 init_airo_card( link->irq.AssignedIRQ,
382 link->io.BasePort1, 1, &handle_to_dev(handle) ); 352 link->io.BasePort1, 1, &handle_to_dev(link) );
383 if (!((local_info_t*)link->priv)->eth_dev) goto cs_failed; 353 if (!((local_info_t*)link->priv)->eth_dev) goto cs_failed;
384 354
385 /* 355 /*
386 At this point, the dev_node_t structure(s) need to be 356 At this point, the dev_node_t structure(s) need to be
387 initialized and arranged in a linked list at link->dev. 357 initialized and arranged in a linked list at link->dev_node.
388 */ 358 */
389 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name ); 359 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
390 dev->node.major = dev->node.minor = 0; 360 dev->node.major = dev->node.minor = 0;
391 link->dev = &dev->node; 361 link->dev_node = &dev->node;
392 362
393 /* Finally, report what we've done */ 363 /* Finally, report what we've done */
394 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 364 printk(KERN_INFO "%s: index 0x%02x: ",
395 dev->node.dev_name, link->conf.ConfigIndex, 365 dev->node.dev_name, link->conf.ConfigIndex);
396 link->conf.Vcc/10, link->conf.Vcc%10); 366 if (link->conf.Vpp)
397 if (link->conf.Vpp1) 367 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
398 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
399 if (link->conf.Attributes & CONF_ENABLE_IRQ) 368 if (link->conf.Attributes & CONF_ENABLE_IRQ)
400 printk(", irq %d", link->irq.AssignedIRQ); 369 printk(", irq %d", link->irq.AssignedIRQ);
401 if (link->io.NumPorts1) 370 if (link->io.NumPorts1)
@@ -408,14 +377,12 @@ static void airo_config(dev_link_t *link)
408 printk(", mem 0x%06lx-0x%06lx", req.Base, 377 printk(", mem 0x%06lx-0x%06lx", req.Base,
409 req.Base+req.Size-1); 378 req.Base+req.Size-1);
410 printk("\n"); 379 printk("\n");
411 380 return 0;
412 link->state &= ~DEV_CONFIG_PENDING; 381
413 return;
414
415 cs_failed: 382 cs_failed:
416 cs_error(link->handle, last_fn, last_ret); 383 cs_error(link, last_fn, last_ret);
417 airo_release(link); 384 airo_release(link);
418 385 return -ENODEV;
419} /* airo_config */ 386} /* airo_config */
420 387
421/*====================================================================== 388/*======================================================================
@@ -426,51 +393,26 @@ static void airo_config(dev_link_t *link)
426 393
427 ======================================================================*/ 394 ======================================================================*/
428 395
429static void airo_release(dev_link_t *link) 396static void airo_release(struct pcmcia_device *link)
430{ 397{
431 DEBUG(0, "airo_release(0x%p)\n", link); 398 DEBUG(0, "airo_release(0x%p)\n", link);
432 399 pcmcia_disable_device(link);
433 /* Unlink the device chain */
434 link->dev = NULL;
435
436 /*
437 In a normal driver, additional code may be needed to release
438 other kernel data structures associated with this device.
439 */
440
441 /* Don't bother checking to see if these succeed or not */
442 if (link->win)
443 pcmcia_release_window(link->win);
444 pcmcia_release_configuration(link->handle);
445 if (link->io.NumPorts1)
446 pcmcia_release_io(link->handle, &link->io);
447 if (link->irq.AssignedIRQ)
448 pcmcia_release_irq(link->handle, &link->irq);
449 link->state &= ~DEV_CONFIG;
450} 400}
451 401
452static int airo_suspend(struct pcmcia_device *p_dev) 402static int airo_suspend(struct pcmcia_device *link)
453{ 403{
454 dev_link_t *link = dev_to_instance(p_dev);
455 local_info_t *local = link->priv; 404 local_info_t *local = link->priv;
456 405
457 link->state |= DEV_SUSPEND; 406 netif_device_detach(local->eth_dev);
458 if (link->state & DEV_CONFIG) {
459 netif_device_detach(local->eth_dev);
460 pcmcia_release_configuration(link->handle);
461 }
462 407
463 return 0; 408 return 0;
464} 409}
465 410
466static int airo_resume(struct pcmcia_device *p_dev) 411static int airo_resume(struct pcmcia_device *link)
467{ 412{
468 dev_link_t *link = dev_to_instance(p_dev);
469 local_info_t *local = link->priv; 413 local_info_t *local = link->priv;
470 414
471 link->state &= ~DEV_SUSPEND; 415 if (link->open) {
472 if (link->state & DEV_CONFIG) {
473 pcmcia_request_configuration(link->handle, &link->conf);
474 reset_airo_card(local->eth_dev); 416 reset_airo_card(local->eth_dev);
475 netif_device_attach(local->eth_dev); 417 netif_device_attach(local->eth_dev);
476 } 418 }
@@ -492,7 +434,7 @@ static struct pcmcia_driver airo_driver = {
492 .drv = { 434 .drv = {
493 .name = "airo_cs", 435 .name = "airo_cs",
494 }, 436 },
495 .probe = airo_attach, 437 .probe = airo_probe,
496 .remove = airo_detach, 438 .remove = airo_detach,
497 .id_table = airo_ids, 439 .id_table = airo_ids,
498 .suspend = airo_suspend, 440 .suspend = airo_suspend,
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index d6f4a5a3e55a..26bf1127524d 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -91,8 +91,8 @@ MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards");
91 event handler. 91 event handler.
92*/ 92*/
93 93
94static void atmel_config(dev_link_t *link); 94static int atmel_config(struct pcmcia_device *link);
95static void atmel_release(dev_link_t *link); 95static void atmel_release(struct pcmcia_device *link);
96 96
97/* 97/*
98 The attach() and detach() entry points are used to create and destroy 98 The attach() and detach() entry points are used to create and destroy
@@ -112,10 +112,10 @@ static void atmel_detach(struct pcmcia_device *p_dev);
112/* 112/*
113 A linked list of "instances" of the atmelnet device. Each actual 113 A linked list of "instances" of the atmelnet device. Each actual
114 PCMCIA card corresponds to one device instance, and is described 114 PCMCIA card corresponds to one device instance, and is described
115 by one dev_link_t structure (defined in ds.h). 115 by one struct pcmcia_device structure (defined in ds.h).
116 116
117 You may not want to use a linked list for this -- for example, the 117 You may not want to use a linked list for this -- for example, the
118 memory card driver uses an array of dev_link_t pointers, where minor 118 memory card driver uses an array of struct pcmcia_device pointers, where minor
119 device numbers are used to derive the corresponding array index. 119 device numbers are used to derive the corresponding array index.
120*/ 120*/
121 121
@@ -125,7 +125,7 @@ static void atmel_detach(struct pcmcia_device *p_dev);
125 example, ethernet cards, modems). In other cases, there may be 125 example, ethernet cards, modems). In other cases, there may be
126 many actual or logical devices (SCSI adapters, memory cards with 126 many actual or logical devices (SCSI adapters, memory cards with
127 multiple partitions). The dev_node_t structures need to be kept 127 multiple partitions). The dev_node_t structures need to be kept
128 in a linked list starting at the 'dev' field of a dev_link_t 128 in a linked list starting at the 'dev' field of a struct pcmcia_device
129 structure. We allocate them in the card's private data structure, 129 structure. We allocate them in the card's private data structure,
130 because they generally shouldn't be allocated dynamically. 130 because they generally shouldn't be allocated dynamically.
131 131
@@ -152,24 +152,16 @@ typedef struct local_info_t {
152 152
153 ======================================================================*/ 153 ======================================================================*/
154 154
155static int atmel_attach(struct pcmcia_device *p_dev) 155static int atmel_probe(struct pcmcia_device *p_dev)
156{ 156{
157 dev_link_t *link;
158 local_info_t *local; 157 local_info_t *local;
159 158
160 DEBUG(0, "atmel_attach()\n"); 159 DEBUG(0, "atmel_attach()\n");
161 160
162 /* Initialize the dev_link_t structure */
163 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
164 if (!link) {
165 printk(KERN_ERR "atmel_cs: no memory for new device\n");
166 return -ENOMEM;
167 }
168
169 /* Interrupt setup */ 161 /* Interrupt setup */
170 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 162 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
171 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 163 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
172 link->irq.Handler = NULL; 164 p_dev->irq.Handler = NULL;
173 165
174 /* 166 /*
175 General socket configuration defaults can go here. In this 167 General socket configuration defaults can go here. In this
@@ -178,26 +170,18 @@ static int atmel_attach(struct pcmcia_device *p_dev)
178 and attributes of IO windows) are fixed by the nature of the 170 and attributes of IO windows) are fixed by the nature of the
179 device, and can be hard-wired here. 171 device, and can be hard-wired here.
180 */ 172 */
181 link->conf.Attributes = 0; 173 p_dev->conf.Attributes = 0;
182 link->conf.Vcc = 50; 174 p_dev->conf.IntType = INT_MEMORY_AND_IO;
183 link->conf.IntType = INT_MEMORY_AND_IO;
184 175
185 /* Allocate space for private device-specific data */ 176 /* Allocate space for private device-specific data */
186 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 177 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
187 if (!local) { 178 if (!local) {
188 printk(KERN_ERR "atmel_cs: no memory for new device\n"); 179 printk(KERN_ERR "atmel_cs: no memory for new device\n");
189 kfree (link);
190 return -ENOMEM; 180 return -ENOMEM;
191 } 181 }
192 link->priv = local; 182 p_dev->priv = local;
193 183
194 link->handle = p_dev; 184 return atmel_config(p_dev);
195 p_dev->instance = link;
196
197 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
198 atmel_config(link);
199
200 return 0;
201} /* atmel_attach */ 185} /* atmel_attach */
202 186
203/*====================================================================== 187/*======================================================================
@@ -209,17 +193,13 @@ static int atmel_attach(struct pcmcia_device *p_dev)
209 193
210 ======================================================================*/ 194 ======================================================================*/
211 195
212static void atmel_detach(struct pcmcia_device *p_dev) 196static void atmel_detach(struct pcmcia_device *link)
213{ 197{
214 dev_link_t *link = dev_to_instance(p_dev);
215
216 DEBUG(0, "atmel_detach(0x%p)\n", link); 198 DEBUG(0, "atmel_detach(0x%p)\n", link);
217 199
218 if (link->state & DEV_CONFIG) 200 atmel_release(link);
219 atmel_release(link);
220 201
221 kfree(link->priv); 202 kfree(link->priv);
222 kfree(link);
223} 203}
224 204
225/*====================================================================== 205/*======================================================================
@@ -236,19 +216,17 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
236/* Call-back function to interrogate PCMCIA-specific information 216/* Call-back function to interrogate PCMCIA-specific information
237 about the current existance of the card */ 217 about the current existance of the card */
238static int card_present(void *arg) 218static int card_present(void *arg)
239{ 219{
240 dev_link_t *link = (dev_link_t *)arg; 220 struct pcmcia_device *link = (struct pcmcia_device *)arg;
241 if (link->state & DEV_SUSPEND) 221
242 return 0; 222 if (pcmcia_dev_present(link))
243 else if (link->state & DEV_PRESENT)
244 return 1; 223 return 1;
245 224
246 return 0; 225 return 0;
247} 226}
248 227
249static void atmel_config(dev_link_t *link) 228static int atmel_config(struct pcmcia_device *link)
250{ 229{
251 client_handle_t handle;
252 tuple_t tuple; 230 tuple_t tuple;
253 cisparse_t parse; 231 cisparse_t parse;
254 local_info_t *dev; 232 local_info_t *dev;
@@ -256,9 +234,8 @@ static void atmel_config(dev_link_t *link)
256 u_char buf[64]; 234 u_char buf[64];
257 struct pcmcia_device_id *did; 235 struct pcmcia_device_id *did;
258 236
259 handle = link->handle;
260 dev = link->priv; 237 dev = link->priv;
261 did = handle_to_dev(handle).driver_data; 238 did = handle_to_dev(link).driver_data;
262 239
263 DEBUG(0, "atmel_config(0x%p)\n", link); 240 DEBUG(0, "atmel_config(0x%p)\n", link);
264 241
@@ -272,15 +249,12 @@ static void atmel_config(dev_link_t *link)
272 registers. 249 registers.
273 */ 250 */
274 tuple.DesiredTuple = CISTPL_CONFIG; 251 tuple.DesiredTuple = CISTPL_CONFIG;
275 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 252 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
276 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 253 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
277 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 254 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
278 link->conf.ConfigBase = parse.config.base; 255 link->conf.ConfigBase = parse.config.base;
279 link->conf.Present = parse.config.rmask[0]; 256 link->conf.Present = parse.config.rmask[0];
280 257
281 /* Configure card */
282 link->state |= DEV_CONFIG;
283
284 /* 258 /*
285 In this loop, we scan the CIS for configuration table entries, 259 In this loop, we scan the CIS for configuration table entries,
286 each of which describes a valid card configuration, including 260 each of which describes a valid card configuration, including
@@ -294,12 +268,12 @@ static void atmel_config(dev_link_t *link)
294 will only use the CIS to fill in implementation-defined details. 268 will only use the CIS to fill in implementation-defined details.
295 */ 269 */
296 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 270 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
297 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 271 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
298 while (1) { 272 while (1) {
299 cistpl_cftable_entry_t dflt = { 0 }; 273 cistpl_cftable_entry_t dflt = { 0 };
300 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 274 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
301 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 275 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
302 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 276 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
303 goto next_entry; 277 goto next_entry;
304 278
305 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 279 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
@@ -314,16 +288,11 @@ static void atmel_config(dev_link_t *link)
314 288
315 /* Use power settings for Vcc and Vpp if present */ 289 /* Use power settings for Vcc and Vpp if present */
316 /* Note that the CIS values need to be rescaled */ 290 /* Note that the CIS values need to be rescaled */
317 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM))
318 link->conf.Vcc = cfg->vcc.param[CISTPL_POWER_VNOM]/10000;
319 else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM))
320 link->conf.Vcc = dflt.vcc.param[CISTPL_POWER_VNOM]/10000;
321
322 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 291 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
323 link->conf.Vpp1 = link->conf.Vpp2 = 292 link->conf.Vpp =
324 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 293 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
325 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 294 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
326 link->conf.Vpp1 = link->conf.Vpp2 = 295 link->conf.Vpp =
327 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 296 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
328 297
329 /* Do we need to allocate an interrupt? */ 298 /* Do we need to allocate an interrupt? */
@@ -349,14 +318,14 @@ static void atmel_config(dev_link_t *link)
349 } 318 }
350 319
351 /* This reserves IO space but doesn't actually enable it */ 320 /* This reserves IO space but doesn't actually enable it */
352 if (pcmcia_request_io(link->handle, &link->io) != 0) 321 if (pcmcia_request_io(link, &link->io) != 0)
353 goto next_entry; 322 goto next_entry;
354 323
355 /* If we got this far, we're cool! */ 324 /* If we got this far, we're cool! */
356 break; 325 break;
357 326
358 next_entry: 327 next_entry:
359 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 328 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
360 } 329 }
361 330
362 /* 331 /*
@@ -365,14 +334,14 @@ static void atmel_config(dev_link_t *link)
365 irq structure is initialized. 334 irq structure is initialized.
366 */ 335 */
367 if (link->conf.Attributes & CONF_ENABLE_IRQ) 336 if (link->conf.Attributes & CONF_ENABLE_IRQ)
368 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 337 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
369 338
370 /* 339 /*
371 This actually configures the PCMCIA socket -- setting up 340 This actually configures the PCMCIA socket -- setting up
372 the I/O windows and the interrupt mapping, and putting the 341 the I/O windows and the interrupt mapping, and putting the
373 card and host interface into "Memory and IO" mode. 342 card and host interface into "Memory and IO" mode.
374 */ 343 */
375 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 344 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
376 345
377 if (link->irq.AssignedIRQ == 0) { 346 if (link->irq.AssignedIRQ == 0) {
378 printk(KERN_ALERT 347 printk(KERN_ALERT
@@ -384,7 +353,7 @@ static void atmel_config(dev_link_t *link)
384 init_atmel_card(link->irq.AssignedIRQ, 353 init_atmel_card(link->irq.AssignedIRQ,
385 link->io.BasePort1, 354 link->io.BasePort1,
386 did ? did->driver_info : ATMEL_FW_TYPE_NONE, 355 did ? did->driver_info : ATMEL_FW_TYPE_NONE,
387 &handle_to_dev(handle), 356 &handle_to_dev(link),
388 card_present, 357 card_present,
389 link); 358 link);
390 if (!((local_info_t*)link->priv)->eth_dev) 359 if (!((local_info_t*)link->priv)->eth_dev)
@@ -393,18 +362,18 @@ static void atmel_config(dev_link_t *link)
393 362
394 /* 363 /*
395 At this point, the dev_node_t structure(s) need to be 364 At this point, the dev_node_t structure(s) need to be
396 initialized and arranged in a linked list at link->dev. 365 initialized and arranged in a linked list at link->dev_node.
397 */ 366 */
398 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name ); 367 strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
399 dev->node.major = dev->node.minor = 0; 368 dev->node.major = dev->node.minor = 0;
400 link->dev = &dev->node; 369 link->dev_node = &dev->node;
401 370
402 link->state &= ~DEV_CONFIG_PENDING; 371 return 0;
403 return; 372
404
405 cs_failed: 373 cs_failed:
406 cs_error(link->handle, last_fn, last_ret); 374 cs_error(link, last_fn, last_ret);
407 atmel_release(link); 375 atmel_release(link);
376 return -ENODEV;
408} 377}
409 378
410/*====================================================================== 379/*======================================================================
@@ -415,53 +384,34 @@ static void atmel_config(dev_link_t *link)
415 384
416 ======================================================================*/ 385 ======================================================================*/
417 386
418static void atmel_release(dev_link_t *link) 387static void atmel_release(struct pcmcia_device *link)
419{ 388{
420 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev; 389 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
421 390
422 DEBUG(0, "atmel_release(0x%p)\n", link); 391 DEBUG(0, "atmel_release(0x%p)\n", link);
423 392
424 /* Unlink the device chain */ 393 if (dev)
425 link->dev = NULL;
426
427 if (dev)
428 stop_atmel_card(dev); 394 stop_atmel_card(dev);
429 ((local_info_t*)link->priv)->eth_dev = NULL; 395 ((local_info_t*)link->priv)->eth_dev = NULL;
430 396
431 /* Don't bother checking to see if these succeed or not */ 397 pcmcia_disable_device(link);
432 pcmcia_release_configuration(link->handle);
433 if (link->io.NumPorts1)
434 pcmcia_release_io(link->handle, &link->io);
435 if (link->irq.AssignedIRQ)
436 pcmcia_release_irq(link->handle, &link->irq);
437 link->state &= ~DEV_CONFIG;
438} 398}
439 399
440static int atmel_suspend(struct pcmcia_device *dev) 400static int atmel_suspend(struct pcmcia_device *link)
441{ 401{
442 dev_link_t *link = dev_to_instance(dev);
443 local_info_t *local = link->priv; 402 local_info_t *local = link->priv;
444 403
445 link->state |= DEV_SUSPEND; 404 netif_device_detach(local->eth_dev);
446 if (link->state & DEV_CONFIG) {
447 netif_device_detach(local->eth_dev);
448 pcmcia_release_configuration(link->handle);
449 }
450 405
451 return 0; 406 return 0;
452} 407}
453 408
454static int atmel_resume(struct pcmcia_device *dev) 409static int atmel_resume(struct pcmcia_device *link)
455{ 410{
456 dev_link_t *link = dev_to_instance(dev);
457 local_info_t *local = link->priv; 411 local_info_t *local = link->priv;
458 412
459 link->state &= ~DEV_SUSPEND; 413 atmel_open(local->eth_dev);
460 if (link->state & DEV_CONFIG) { 414 netif_device_attach(local->eth_dev);
461 pcmcia_request_configuration(link->handle, &link->conf);
462 atmel_open(local->eth_dev);
463 netif_device_attach(local->eth_dev);
464 }
465 415
466 return 0; 416 return 0;
467} 417}
@@ -515,7 +465,7 @@ static struct pcmcia_driver atmel_driver = {
515 .drv = { 465 .drv = {
516 .name = "atmel_cs", 466 .name = "atmel_cs",
517 }, 467 },
518 .probe = atmel_attach, 468 .probe = atmel_probe,
519 .remove = atmel_detach, 469 .remove = atmel_detach,
520 .id_table = atmel_ids, 470 .id_table = atmel_ids,
521 .suspend = atmel_suspend, 471 .suspend = atmel_suspend,
diff --git a/drivers/net/wireless/bcm43xx/Kconfig b/drivers/net/wireless/bcm43xx/Kconfig
new file mode 100644
index 000000000000..418465600a77
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/Kconfig
@@ -0,0 +1,62 @@
1config BCM43XX
2 tristate "Broadcom BCM43xx wireless support"
3 depends on PCI && IEEE80211 && IEEE80211_SOFTMAC && NET_RADIO && EXPERIMENTAL
4 select FW_LOADER
5 ---help---
6 This is an experimental driver for the Broadcom 43xx wireless chip,
7 found in the Apple Airport Extreme and various other devices.
8
9config BCM43XX_DEBUG
10 bool "Broadcom BCM43xx debugging (RECOMMENDED)"
11 depends on BCM43XX
12 default y
13 ---help---
14 Broadcom 43xx debugging messages.
15 Say Y, because the driver is still very experimental and
16 this will help you get it running.
17
18config BCM43XX_DMA
19 bool
20config BCM43XX_PIO
21 bool
22
23choice
24 prompt "BCM43xx data transfer mode"
25 depends on BCM43XX
26 default BCM43XX_DMA_AND_PIO_MODE
27
28config BCM43XX_DMA_AND_PIO_MODE
29 bool "DMA + PIO"
30 select BCM43XX_DMA
31 select BCM43XX_PIO
32 ---help---
33 Include both, Direct Memory Access (DMA) and Programmed I/O (PIO)
34 data transfer modes.
35 The actually used mode is selectable through the module
36 parameter "pio". If the module parameter is pio=0, DMA is used.
37 Otherwise PIO is used. DMA is default.
38
39 If unsure, choose this option.
40
41config BCM43XX_DMA_MODE
42 bool "DMA (Direct Memory Access) only"
43 select BCM43XX_DMA
44 ---help---
45 Only include Direct Memory Access (DMA).
46 This reduces the size of the driver module, by omitting the PIO code.
47
48config BCM43XX_PIO_MODE
49 bool "PIO (Programmed I/O) only"
50 select BCM43XX_PIO
51 ---help---
52 Only include Programmed I/O (PIO).
53 This reduces the size of the driver module, by omitting the DMA code.
54 Please note that PIO transfers are slow (compared to DMA).
55
56 Also note that not all devices of the 43xx series support PIO.
57 The 4306 (Apple Airport Extreme and others) supports PIO, while
58 the 4318 is known to _not_ support PIO.
59
60 Only use PIO, if DMA does not work for you.
61
62endchoice
diff --git a/drivers/net/wireless/bcm43xx/Makefile b/drivers/net/wireless/bcm43xx/Makefile
new file mode 100644
index 000000000000..bb5220c629d2
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/Makefile
@@ -0,0 +1,12 @@
1obj-$(CONFIG_BCM43XX) += bcm43xx.o
2bcm43xx-obj-$(CONFIG_BCM43XX_DEBUG) += bcm43xx_debugfs.o
3
4bcm43xx-obj-$(CONFIG_BCM43XX_DMA) += bcm43xx_dma.o
5bcm43xx-obj-$(CONFIG_BCM43XX_PIO) += bcm43xx_pio.o
6
7bcm43xx-objs := bcm43xx_main.o bcm43xx_ilt.o \
8 bcm43xx_radio.o bcm43xx_phy.o \
9 bcm43xx_power.o bcm43xx_wx.o \
10 bcm43xx_leds.o bcm43xx_ethtool.o \
11 bcm43xx_xmit.o bcm43xx_sysfs.o \
12 $(bcm43xx-obj-y)
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
new file mode 100644
index 000000000000..dcadd295de4f
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -0,0 +1,926 @@
1#ifndef BCM43xx_H_
2#define BCM43xx_H_
3
4#include <linux/version.h>
5#include <linux/kernel.h>
6#include <linux/spinlock.h>
7#include <linux/interrupt.h>
8#include <linux/stringify.h>
9#include <linux/pci.h>
10#include <net/ieee80211.h>
11#include <net/ieee80211softmac.h>
12#include <asm/atomic.h>
13#include <asm/io.h>
14
15
16#include "bcm43xx_debugfs.h"
17#include "bcm43xx_leds.h"
18#include "bcm43xx_sysfs.h"
19
20
21#define PFX KBUILD_MODNAME ": "
22
23#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
24#define BCM43xx_IRQWAIT_MAX_RETRIES 50
25
26#define BCM43xx_IO_SIZE 8192
27
28/* Active Core PCI Configuration Register. */
29#define BCM43xx_PCICFG_ACTIVE_CORE 0x80
30/* SPROM control register. */
31#define BCM43xx_PCICFG_SPROMCTL 0x88
32/* Interrupt Control PCI Configuration Register. (Only on PCI cores with rev >= 6) */
33#define BCM43xx_PCICFG_ICR 0x94
34
35/* MMIO offsets */
36#define BCM43xx_MMIO_DMA1_REASON 0x20
37#define BCM43xx_MMIO_DMA1_IRQ_MASK 0x24
38#define BCM43xx_MMIO_DMA2_REASON 0x28
39#define BCM43xx_MMIO_DMA2_IRQ_MASK 0x2C
40#define BCM43xx_MMIO_DMA3_REASON 0x30
41#define BCM43xx_MMIO_DMA3_IRQ_MASK 0x34
42#define BCM43xx_MMIO_DMA4_REASON 0x38
43#define BCM43xx_MMIO_DMA4_IRQ_MASK 0x3C
44#define BCM43xx_MMIO_STATUS_BITFIELD 0x120
45#define BCM43xx_MMIO_STATUS2_BITFIELD 0x124
46#define BCM43xx_MMIO_GEN_IRQ_REASON 0x128
47#define BCM43xx_MMIO_GEN_IRQ_MASK 0x12C
48#define BCM43xx_MMIO_RAM_CONTROL 0x130
49#define BCM43xx_MMIO_RAM_DATA 0x134
50#define BCM43xx_MMIO_PS_STATUS 0x140
51#define BCM43xx_MMIO_RADIO_HWENABLED_HI 0x158
52#define BCM43xx_MMIO_SHM_CONTROL 0x160
53#define BCM43xx_MMIO_SHM_DATA 0x164
54#define BCM43xx_MMIO_SHM_DATA_UNALIGNED 0x166
55#define BCM43xx_MMIO_XMITSTAT_0 0x170
56#define BCM43xx_MMIO_XMITSTAT_1 0x174
57#define BCM43xx_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
58#define BCM43xx_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
59#define BCM43xx_MMIO_DMA1_BASE 0x200
60#define BCM43xx_MMIO_DMA2_BASE 0x220
61#define BCM43xx_MMIO_DMA3_BASE 0x240
62#define BCM43xx_MMIO_DMA4_BASE 0x260
63#define BCM43xx_MMIO_PIO1_BASE 0x300
64#define BCM43xx_MMIO_PIO2_BASE 0x310
65#define BCM43xx_MMIO_PIO3_BASE 0x320
66#define BCM43xx_MMIO_PIO4_BASE 0x330
67#define BCM43xx_MMIO_PHY_VER 0x3E0
68#define BCM43xx_MMIO_PHY_RADIO 0x3E2
69#define BCM43xx_MMIO_ANTENNA 0x3E8
70#define BCM43xx_MMIO_CHANNEL 0x3F0
71#define BCM43xx_MMIO_CHANNEL_EXT 0x3F4
72#define BCM43xx_MMIO_RADIO_CONTROL 0x3F6
73#define BCM43xx_MMIO_RADIO_DATA_HIGH 0x3F8
74#define BCM43xx_MMIO_RADIO_DATA_LOW 0x3FA
75#define BCM43xx_MMIO_PHY_CONTROL 0x3FC
76#define BCM43xx_MMIO_PHY_DATA 0x3FE
77#define BCM43xx_MMIO_MACFILTER_CONTROL 0x420
78#define BCM43xx_MMIO_MACFILTER_DATA 0x422
79#define BCM43xx_MMIO_RADIO_HWENABLED_LO 0x49A
80#define BCM43xx_MMIO_GPIO_CONTROL 0x49C
81#define BCM43xx_MMIO_GPIO_MASK 0x49E
82#define BCM43xx_MMIO_TSF_0 0x632 /* core rev < 3 only */
83#define BCM43xx_MMIO_TSF_1 0x634 /* core rev < 3 only */
84#define BCM43xx_MMIO_TSF_2 0x636 /* core rev < 3 only */
85#define BCM43xx_MMIO_TSF_3 0x638 /* core rev < 3 only */
86#define BCM43xx_MMIO_POWERUP_DELAY 0x6A8
87
88/* SPROM offsets. */
89#define BCM43xx_SPROM_BASE 0x1000
90#define BCM43xx_SPROM_BOARDFLAGS2 0x1c
91#define BCM43xx_SPROM_IL0MACADDR 0x24
92#define BCM43xx_SPROM_ET0MACADDR 0x27
93#define BCM43xx_SPROM_ET1MACADDR 0x2a
94#define BCM43xx_SPROM_ETHPHY 0x2d
95#define BCM43xx_SPROM_BOARDREV 0x2e
96#define BCM43xx_SPROM_PA0B0 0x2f
97#define BCM43xx_SPROM_PA0B1 0x30
98#define BCM43xx_SPROM_PA0B2 0x31
99#define BCM43xx_SPROM_WL0GPIO0 0x32
100#define BCM43xx_SPROM_WL0GPIO2 0x33
101#define BCM43xx_SPROM_MAXPWR 0x34
102#define BCM43xx_SPROM_PA1B0 0x35
103#define BCM43xx_SPROM_PA1B1 0x36
104#define BCM43xx_SPROM_PA1B2 0x37
105#define BCM43xx_SPROM_IDL_TSSI_TGT 0x38
106#define BCM43xx_SPROM_BOARDFLAGS 0x39
107#define BCM43xx_SPROM_ANTENNA_GAIN 0x3a
108#define BCM43xx_SPROM_VERSION 0x3f
109
110/* BCM43xx_SPROM_BOARDFLAGS values */
111#define BCM43xx_BFL_BTCOEXIST 0x0001 /* implements Bluetooth coexistance */
112#define BCM43xx_BFL_PACTRL 0x0002 /* GPIO 9 controlling the PA */
113#define BCM43xx_BFL_AIRLINEMODE 0x0004 /* implements GPIO 13 radio disable indication */
114#define BCM43xx_BFL_RSSI 0x0008 /* software calculates nrssi slope. */
115#define BCM43xx_BFL_ENETSPI 0x0010 /* has ephy roboswitch spi */
116#define BCM43xx_BFL_XTAL_NOSLOW 0x0020 /* no slow clock available */
117#define BCM43xx_BFL_CCKHIPWR 0x0040 /* can do high power CCK transmission */
118#define BCM43xx_BFL_ENETADM 0x0080 /* has ADMtek switch */
119#define BCM43xx_BFL_ENETVLAN 0x0100 /* can do vlan */
120#define BCM43xx_BFL_AFTERBURNER 0x0200 /* supports Afterburner mode */
121#define BCM43xx_BFL_NOPCI 0x0400 /* leaves PCI floating */
122#define BCM43xx_BFL_FEM 0x0800 /* supports the Front End Module */
123#define BCM43xx_BFL_EXTLNA 0x1000 /* has an external LNA */
124#define BCM43xx_BFL_HGPA 0x2000 /* had high gain PA */
125#define BCM43xx_BFL_BTCMOD 0x4000 /* BFL_BTCOEXIST is given in alternate GPIOs */
126#define BCM43xx_BFL_ALTIQ 0x8000 /* alternate I/Q settings */
127
128/* GPIO register offset, in both ChipCommon and PCI core. */
129#define BCM43xx_GPIO_CONTROL 0x6c
130
131/* SHM Routing */
132#define BCM43xx_SHM_SHARED 0x0001
133#define BCM43xx_SHM_WIRELESS 0x0002
134#define BCM43xx_SHM_PCM 0x0003
135#define BCM43xx_SHM_HWMAC 0x0004
136#define BCM43xx_SHM_UCODE 0x0300
137
138/* MacFilter offsets. */
139#define BCM43xx_MACFILTER_SELF 0x0000
140#define BCM43xx_MACFILTER_ASSOC 0x0003
141
142/* Chipcommon registers. */
143#define BCM43xx_CHIPCOMMON_CAPABILITIES 0x04
144#define BCM43xx_CHIPCOMMON_PLLONDELAY 0xB0
145#define BCM43xx_CHIPCOMMON_FREFSELDELAY 0xB4
146#define BCM43xx_CHIPCOMMON_SLOWCLKCTL 0xB8
147#define BCM43xx_CHIPCOMMON_SYSCLKCTL 0xC0
148
149/* PCI core specific registers. */
150#define BCM43xx_PCICORE_BCAST_ADDR 0x50
151#define BCM43xx_PCICORE_BCAST_DATA 0x54
152#define BCM43xx_PCICORE_SBTOPCI2 0x108
153
154/* SBTOPCI2 values. */
155#define BCM43xx_SBTOPCI2_PREFETCH 0x4
156#define BCM43xx_SBTOPCI2_BURST 0x8
157
158/* Chipcommon capabilities. */
159#define BCM43xx_CAPABILITIES_PCTL 0x00040000
160#define BCM43xx_CAPABILITIES_PLLMASK 0x00030000
161#define BCM43xx_CAPABILITIES_PLLSHIFT 16
162#define BCM43xx_CAPABILITIES_FLASHMASK 0x00000700
163#define BCM43xx_CAPABILITIES_FLASHSHIFT 8
164#define BCM43xx_CAPABILITIES_EXTBUSPRESENT 0x00000040
165#define BCM43xx_CAPABILITIES_UARTGPIO 0x00000020
166#define BCM43xx_CAPABILITIES_UARTCLOCKMASK 0x00000018
167#define BCM43xx_CAPABILITIES_UARTCLOCKSHIFT 3
168#define BCM43xx_CAPABILITIES_MIPSBIGENDIAN 0x00000004
169#define BCM43xx_CAPABILITIES_NRUARTSMASK 0x00000003
170
171/* PowerControl */
172#define BCM43xx_PCTL_IN 0xB0
173#define BCM43xx_PCTL_OUT 0xB4
174#define BCM43xx_PCTL_OUTENABLE 0xB8
175#define BCM43xx_PCTL_XTAL_POWERUP 0x40
176#define BCM43xx_PCTL_PLL_POWERDOWN 0x80
177
178/* PowerControl Clock Modes */
179#define BCM43xx_PCTL_CLK_FAST 0x00
180#define BCM43xx_PCTL_CLK_SLOW 0x01
181#define BCM43xx_PCTL_CLK_DYNAMIC 0x02
182
183#define BCM43xx_PCTL_FORCE_SLOW 0x0800
184#define BCM43xx_PCTL_FORCE_PLL 0x1000
185#define BCM43xx_PCTL_DYN_XTAL 0x2000
186
187/* COREIDs */
188#define BCM43xx_COREID_CHIPCOMMON 0x800
189#define BCM43xx_COREID_ILINE20 0x801
190#define BCM43xx_COREID_SDRAM 0x803
191#define BCM43xx_COREID_PCI 0x804
192#define BCM43xx_COREID_MIPS 0x805
193#define BCM43xx_COREID_ETHERNET 0x806
194#define BCM43xx_COREID_V90 0x807
195#define BCM43xx_COREID_USB11_HOSTDEV 0x80a
196#define BCM43xx_COREID_IPSEC 0x80b
197#define BCM43xx_COREID_PCMCIA 0x80d
198#define BCM43xx_COREID_EXT_IF 0x80f
199#define BCM43xx_COREID_80211 0x812
200#define BCM43xx_COREID_MIPS_3302 0x816
201#define BCM43xx_COREID_USB11_HOST 0x817
202#define BCM43xx_COREID_USB11_DEV 0x818
203#define BCM43xx_COREID_USB20_HOST 0x819
204#define BCM43xx_COREID_USB20_DEV 0x81a
205#define BCM43xx_COREID_SDIO_HOST 0x81b
206
207/* Core Information Registers */
208#define BCM43xx_CIR_BASE 0xf00
209#define BCM43xx_CIR_SBTPSFLAG (BCM43xx_CIR_BASE + 0x18)
210#define BCM43xx_CIR_SBIMSTATE (BCM43xx_CIR_BASE + 0x90)
211#define BCM43xx_CIR_SBINTVEC (BCM43xx_CIR_BASE + 0x94)
212#define BCM43xx_CIR_SBTMSTATELOW (BCM43xx_CIR_BASE + 0x98)
213#define BCM43xx_CIR_SBTMSTATEHIGH (BCM43xx_CIR_BASE + 0x9c)
214#define BCM43xx_CIR_SBIMCONFIGLOW (BCM43xx_CIR_BASE + 0xa8)
215#define BCM43xx_CIR_SB_ID_HI (BCM43xx_CIR_BASE + 0xfc)
216
217/* Mask to get the Backplane Flag Number from SBTPSFLAG. */
218#define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
219
220/* SBIMCONFIGLOW values/masks. */
221#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK 0x00000007
222#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT 0
223#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK 0x00000070
224#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT 4
225#define BCM43xx_SBIMCONFIGLOW_CONNID_MASK 0x00ff0000
226#define BCM43xx_SBIMCONFIGLOW_CONNID_SHIFT 16
227
228/* sbtmstatelow state flags */
229#define BCM43xx_SBTMSTATELOW_RESET 0x01
230#define BCM43xx_SBTMSTATELOW_REJECT 0x02
231#define BCM43xx_SBTMSTATELOW_CLOCK 0x10000
232#define BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK 0x20000
233
234/* sbtmstatehigh state flags */
235#define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
236#define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
237
238/* sbimstate flags */
239#define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
240#define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
241
242/* PHYVersioning */
243#define BCM43xx_PHYTYPE_A 0x00
244#define BCM43xx_PHYTYPE_B 0x01
245#define BCM43xx_PHYTYPE_G 0x02
246
247/* PHYRegisters */
248#define BCM43xx_PHY_ILT_A_CTRL 0x0072
249#define BCM43xx_PHY_ILT_A_DATA1 0x0073
250#define BCM43xx_PHY_ILT_A_DATA2 0x0074
251#define BCM43xx_PHY_G_LO_CONTROL 0x0810
252#define BCM43xx_PHY_ILT_G_CTRL 0x0472
253#define BCM43xx_PHY_ILT_G_DATA1 0x0473
254#define BCM43xx_PHY_ILT_G_DATA2 0x0474
255#define BCM43xx_PHY_A_PCTL 0x007B
256#define BCM43xx_PHY_G_PCTL 0x0029
257#define BCM43xx_PHY_A_CRS 0x0029
258#define BCM43xx_PHY_RADIO_BITFIELD 0x0401
259#define BCM43xx_PHY_G_CRS 0x0429
260#define BCM43xx_PHY_NRSSILT_CTRL 0x0803
261#define BCM43xx_PHY_NRSSILT_DATA 0x0804
262
263/* RadioRegisters */
264#define BCM43xx_RADIOCTL_ID 0x01
265
266/* StatusBitField */
267#define BCM43xx_SBF_MAC_ENABLED 0x00000001
268#define BCM43xx_SBF_2 0x00000002 /*FIXME: fix name*/
269#define BCM43xx_SBF_CORE_READY 0x00000004
270#define BCM43xx_SBF_400 0x00000400 /*FIXME: fix name*/
271#define BCM43xx_SBF_4000 0x00004000 /*FIXME: fix name*/
272#define BCM43xx_SBF_8000 0x00008000 /*FIXME: fix name*/
273#define BCM43xx_SBF_XFER_REG_BYTESWAP 0x00010000
274#define BCM43xx_SBF_MODE_NOTADHOC 0x00020000
275#define BCM43xx_SBF_MODE_AP 0x00040000
276#define BCM43xx_SBF_RADIOREG_LOCK 0x00080000
277#define BCM43xx_SBF_MODE_MONITOR 0x00400000
278#define BCM43xx_SBF_MODE_PROMISC 0x01000000
279#define BCM43xx_SBF_PS1 0x02000000
280#define BCM43xx_SBF_PS2 0x04000000
281#define BCM43xx_SBF_NO_SSID_BCAST 0x08000000
282#define BCM43xx_SBF_TIME_UPDATE 0x10000000
283#define BCM43xx_SBF_80000000 0x80000000 /*FIXME: fix name*/
284
285/* MicrocodeFlagsBitfield (addr + lo-word values?)*/
286#define BCM43xx_UCODEFLAGS_OFFSET 0x005E
287
288#define BCM43xx_UCODEFLAG_AUTODIV 0x0001
289#define BCM43xx_UCODEFLAG_UNKBGPHY 0x0002
290#define BCM43xx_UCODEFLAG_UNKBPHY 0x0004
291#define BCM43xx_UCODEFLAG_UNKGPHY 0x0020
292#define BCM43xx_UCODEFLAG_UNKPACTRL 0x0040
293#define BCM43xx_UCODEFLAG_JAPAN 0x0080
294
295/* Generic-Interrupt reasons. */
296#define BCM43xx_IRQ_READY (1 << 0)
297#define BCM43xx_IRQ_BEACON (1 << 1)
298#define BCM43xx_IRQ_PS (1 << 2)
299#define BCM43xx_IRQ_REG124 (1 << 5)
300#define BCM43xx_IRQ_PMQ (1 << 6)
301#define BCM43xx_IRQ_PIO_WORKAROUND (1 << 8)
302#define BCM43xx_IRQ_XMIT_ERROR (1 << 11)
303#define BCM43xx_IRQ_RX (1 << 15)
304#define BCM43xx_IRQ_SCAN (1 << 16)
305#define BCM43xx_IRQ_NOISE (1 << 18)
306#define BCM43xx_IRQ_XMIT_STATUS (1 << 29)
307
308#define BCM43xx_IRQ_ALL 0xffffffff
309#define BCM43xx_IRQ_INITIAL (BCM43xx_IRQ_PS | \
310 BCM43xx_IRQ_REG124 | \
311 BCM43xx_IRQ_PMQ | \
312 BCM43xx_IRQ_XMIT_ERROR | \
313 BCM43xx_IRQ_RX | \
314 BCM43xx_IRQ_SCAN | \
315 BCM43xx_IRQ_NOISE | \
316 BCM43xx_IRQ_XMIT_STATUS)
317
318
319/* Initial default iw_mode */
320#define BCM43xx_INITIAL_IWMODE IW_MODE_INFRA
321
322/* Bus type PCI. */
323#define BCM43xx_BUSTYPE_PCI 0
324/* Bus type Silicone Backplane Bus. */
325#define BCM43xx_BUSTYPE_SB 1
326/* Bus type PCMCIA. */
327#define BCM43xx_BUSTYPE_PCMCIA 2
328
329/* Threshold values. */
330#define BCM43xx_MIN_RTS_THRESHOLD 1U
331#define BCM43xx_MAX_RTS_THRESHOLD 2304U
332#define BCM43xx_DEFAULT_RTS_THRESHOLD BCM43xx_MAX_RTS_THRESHOLD
333
334#define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
335#define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
336
337/* Max size of a security key */
338#define BCM43xx_SEC_KEYSIZE 16
339/* Security algorithms. */
340enum {
341 BCM43xx_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
342 BCM43xx_SEC_ALGO_WEP,
343 BCM43xx_SEC_ALGO_UNKNOWN,
344 BCM43xx_SEC_ALGO_AES,
345 BCM43xx_SEC_ALGO_WEP104,
346 BCM43xx_SEC_ALGO_TKIP,
347};
348
349#ifdef assert
350# undef assert
351#endif
352#ifdef CONFIG_BCM43XX_DEBUG
353#define assert(expr) \
354 do { \
355 if (unlikely(!(expr))) { \
356 printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
357 #expr, __FILE__, __LINE__, __FUNCTION__); \
358 } \
359 } while (0)
360#else
361#define assert(expr) do { /* nothing */ } while (0)
362#endif
363
364/* rate limited printk(). */
365#ifdef printkl
366# undef printkl
367#endif
368#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
369/* rate limited printk() for debugging */
370#ifdef dprintkl
371# undef dprintkl
372#endif
373#ifdef CONFIG_BCM43XX_DEBUG
374# define dprintkl printkl
375#else
376# define dprintkl(f, x...) do { /* nothing */ } while (0)
377#endif
378
379/* Helper macro for if branches.
380 * An if branch marked with this macro is only taken in DEBUG mode.
381 * Example:
382 * if (DEBUG_ONLY(foo == bar)) {
383 * do something
384 * }
385 * In DEBUG mode, the branch will be taken if (foo == bar).
386 * In non-DEBUG mode, the branch will never be taken.
387 */
388#ifdef DEBUG_ONLY
389# undef DEBUG_ONLY
390#endif
391#ifdef CONFIG_BCM43XX_DEBUG
392# define DEBUG_ONLY(x) (x)
393#else
394# define DEBUG_ONLY(x) 0
395#endif
396
397/* debugging printk() */
398#ifdef dprintk
399# undef dprintk
400#endif
401#ifdef CONFIG_BCM43XX_DEBUG
402# define dprintk(f, x...) do { printk(f ,##x); } while (0)
403#else
404# define dprintk(f, x...) do { /* nothing */ } while (0)
405#endif
406
407
408struct net_device;
409struct pci_dev;
410struct bcm43xx_dmaring;
411struct bcm43xx_pioqueue;
412
413struct bcm43xx_initval {
414 u16 offset;
415 u16 size;
416 u32 value;
417} __attribute__((__packed__));
418
419/* Values for bcm430x_sprominfo.locale */
420enum {
421 BCM43xx_LOCALE_WORLD = 0,
422 BCM43xx_LOCALE_THAILAND,
423 BCM43xx_LOCALE_ISRAEL,
424 BCM43xx_LOCALE_JORDAN,
425 BCM43xx_LOCALE_CHINA,
426 BCM43xx_LOCALE_JAPAN,
427 BCM43xx_LOCALE_USA_CANADA_ANZ,
428 BCM43xx_LOCALE_EUROPE,
429 BCM43xx_LOCALE_USA_LOW,
430 BCM43xx_LOCALE_JAPAN_HIGH,
431 BCM43xx_LOCALE_ALL,
432 BCM43xx_LOCALE_NONE,
433};
434
435#define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
436struct bcm43xx_sprominfo {
437 u16 boardflags2;
438 u8 il0macaddr[6];
439 u8 et0macaddr[6];
440 u8 et1macaddr[6];
441 u8 et0phyaddr:5;
442 u8 et1phyaddr:5;
443 u8 et0mdcport:1;
444 u8 et1mdcport:1;
445 u8 boardrev;
446 u8 locale:4;
447 u8 antennas_aphy:2;
448 u8 antennas_bgphy:2;
449 u16 pa0b0;
450 u16 pa0b1;
451 u16 pa0b2;
452 u8 wl0gpio0;
453 u8 wl0gpio1;
454 u8 wl0gpio2;
455 u8 wl0gpio3;
456 u8 maxpower_aphy;
457 u8 maxpower_bgphy;
458 u16 pa1b0;
459 u16 pa1b1;
460 u16 pa1b2;
461 u8 idle_tssi_tgt_aphy;
462 u8 idle_tssi_tgt_bgphy;
463 u16 boardflags;
464 u16 antennagain_aphy;
465 u16 antennagain_bgphy;
466};
467
468/* Value pair to measure the LocalOscillator. */
469struct bcm43xx_lopair {
470 s8 low;
471 s8 high;
472 u8 used:1;
473};
474#define BCM43xx_LO_COUNT (14*4)
475
476struct bcm43xx_phyinfo {
477 /* Hardware Data */
478 u8 version;
479 u8 type;
480 u8 rev;
481 u16 antenna_diversity;
482 u16 savedpctlreg;
483 u16 minlowsig[2];
484 u16 minlowsigpos[2];
485 u8 connected:1,
486 calibrated:1,
487 is_locked:1, /* used in bcm43xx_phy_{un}lock() */
488 dyn_tssi_tbl:1; /* used in bcm43xx_phy_init_tssi2dbm_table() */
489 /* LO Measurement Data.
490 * Use bcm43xx_get_lopair() to get a value.
491 */
492 struct bcm43xx_lopair *_lo_pairs;
493
494 /* TSSI to dBm table in use */
495 const s8 *tssi2dbm;
496 /* idle TSSI value */
497 s8 idle_tssi;
498
499 /* Values from bcm43xx_calc_loopback_gain() */
500 u16 loopback_gain[2];
501
502 /* PHY lock for core.rev < 3
503 * This lock is only used by bcm43xx_phy_{un}lock()
504 */
505 spinlock_t lock;
506};
507
508
509struct bcm43xx_radioinfo {
510 u16 manufact;
511 u16 version;
512 u8 revision;
513
514 /* Desired TX power in dBm Q5.2 */
515 u16 txpower_desired;
516 /* TX Power control values. */
517 union {
518 /* B/G PHY */
519 struct {
520 u16 baseband_atten;
521 u16 radio_atten;
522 u16 txctl1;
523 u16 txctl2;
524 };
525 /* A PHY */
526 struct {
527 u16 txpwr_offset;
528 };
529 };
530
531 /* Current Interference Mitigation mode */
532 int interfmode;
533 /* Stack of saved values from the Interference Mitigation code.
534 * Each value in the stack is layed out as follows:
535 * bit 0-11: offset
536 * bit 12-15: register ID
537 * bit 16-32: value
538 * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
539 */
540#define BCM43xx_INTERFSTACK_SIZE 26
541 u32 interfstack[BCM43xx_INTERFSTACK_SIZE];
542
543 /* Saved values from the NRSSI Slope calculation */
544 s16 nrssi[2];
545 s32 nrssislope;
546 /* In memory nrssi lookup table. */
547 s8 nrssi_lt[64];
548
549 /* current channel */
550 u8 channel;
551 u8 initial_channel;
552
553 u16 lofcal;
554
555 u16 initval;
556
557 u8 enabled:1;
558 /* ACI (adjacent channel interference) flags. */
559 u8 aci_enable:1,
560 aci_wlan_automatic:1,
561 aci_hw_rssi:1;
562};
563
564/* Data structures for DMA transmission, per 80211 core. */
565struct bcm43xx_dma {
566 struct bcm43xx_dmaring *tx_ring0;
567 struct bcm43xx_dmaring *tx_ring1;
568 struct bcm43xx_dmaring *tx_ring2;
569 struct bcm43xx_dmaring *tx_ring3;
570 struct bcm43xx_dmaring *rx_ring0;
571 struct bcm43xx_dmaring *rx_ring1; /* only available on core.rev < 5 */
572};
573
574/* Data structures for PIO transmission, per 80211 core. */
575struct bcm43xx_pio {
576 struct bcm43xx_pioqueue *queue0;
577 struct bcm43xx_pioqueue *queue1;
578 struct bcm43xx_pioqueue *queue2;
579 struct bcm43xx_pioqueue *queue3;
580};
581
582#define BCM43xx_MAX_80211_CORES 2
583
584#ifdef CONFIG_BCM947XX
585#define core_offset(bcm) (bcm)->current_core_offset
586#else
587#define core_offset(bcm) 0
588#endif
589
590/* Generic information about a core. */
591struct bcm43xx_coreinfo {
592 u8 available:1,
593 enabled:1,
594 initialized:1;
595 /** core_id ID number */
596 u16 id;
597 /** core_rev revision number */
598 u8 rev;
599 /** Index number for _switch_core() */
600 u8 index;
601};
602
603/* Additional information for each 80211 core. */
604struct bcm43xx_coreinfo_80211 {
605 /* PHY device. */
606 struct bcm43xx_phyinfo phy;
607 /* Radio device. */
608 struct bcm43xx_radioinfo radio;
609 union {
610 /* DMA context. */
611 struct bcm43xx_dma dma;
612 /* PIO context. */
613 struct bcm43xx_pio pio;
614 };
615};
616
617/* Context information for a noise calculation (Link Quality). */
618struct bcm43xx_noise_calculation {
619 struct bcm43xx_coreinfo *core_at_start;
620 u8 channel_at_start;
621 u8 calculation_running:1;
622 u8 nr_samples;
623 s8 samples[8][4];
624};
625
626struct bcm43xx_stats {
627 u8 link_quality;
628 u8 noise;
629 struct iw_statistics wstats;
630 /* Store the last TX/RX times here for updating the leds. */
631 unsigned long last_tx;
632 unsigned long last_rx;
633};
634
635struct bcm43xx_key {
636 u8 enabled:1;
637 u8 algorithm;
638};
639
640struct bcm43xx_private {
641 struct bcm43xx_sysfs sysfs;
642
643 struct ieee80211_device *ieee;
644 struct ieee80211softmac_device *softmac;
645
646 struct net_device *net_dev;
647 struct pci_dev *pci_dev;
648 unsigned int irq;
649
650 void __iomem *mmio_addr;
651 unsigned int mmio_len;
652
653 /* Do not use the lock directly. Use the bcm43xx_lock* helper
654 * functions, to be MMIO-safe. */
655 spinlock_t _lock;
656
657 /* Driver status flags. */
658 u32 initialized:1, /* init_board() succeed */
659 was_initialized:1, /* for PCI suspend/resume. */
660 shutting_down:1, /* free_board() in progress */
661 __using_pio:1, /* Internal, use bcm43xx_using_pio(). */
662 bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
663 reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */
664 powersaving:1, /* TRUE if we are in PowerSaving mode. FALSE otherwise. */
665 short_preamble:1, /* TRUE, if short preamble is enabled. */
666 firmware_norelease:1; /* Do not release the firmware. Used on suspend. */
667
668 struct bcm43xx_stats stats;
669
670 /* Bus type we are connected to.
671 * This is currently always BCM43xx_BUSTYPE_PCI
672 */
673 u8 bustype;
674
675 u16 board_vendor;
676 u16 board_type;
677 u16 board_revision;
678
679 u16 chip_id;
680 u8 chip_rev;
681 u8 chip_package;
682
683 struct bcm43xx_sprominfo sprom;
684#define BCM43xx_NR_LEDS 4
685 struct bcm43xx_led leds[BCM43xx_NR_LEDS];
686
687 /* The currently active core. */
688 struct bcm43xx_coreinfo *current_core;
689#ifdef CONFIG_BCM947XX
690 /** current core memory offset */
691 u32 current_core_offset;
692#endif
693 struct bcm43xx_coreinfo *active_80211_core;
694 /* coreinfo structs for all possible cores follow.
695 * Note that a core might not exist.
696 * So check the coreinfo flags before using it.
697 */
698 struct bcm43xx_coreinfo core_chipcommon;
699 struct bcm43xx_coreinfo core_pci;
700 struct bcm43xx_coreinfo core_80211[ BCM43xx_MAX_80211_CORES ];
701 /* Additional information, specific to the 80211 cores. */
702 struct bcm43xx_coreinfo_80211 core_80211_ext[ BCM43xx_MAX_80211_CORES ];
703 /* Index of the current 80211 core. If current_core is not
704 * an 80211 core, this is -1.
705 */
706 int current_80211_core_idx;
707 /* Number of available 80211 cores. */
708 int nr_80211_available;
709
710 u32 chipcommon_capabilities;
711
712 /* Reason code of the last interrupt. */
713 u32 irq_reason;
714 u32 dma_reason[4];
715 /* saved irq enable/disable state bitfield. */
716 u32 irq_savedstate;
717 /* Link Quality calculation context. */
718 struct bcm43xx_noise_calculation noisecalc;
719
720 /* Threshold values. */
721 //TODO: The RTS thr has to be _used_. Currently, it is only set via WX.
722 u32 rts_threshold;
723
724 /* Interrupt Service Routine tasklet (bottom-half) */
725 struct tasklet_struct isr_tasklet;
726
727 /* Periodic tasks */
728 struct timer_list periodic_tasks;
729 unsigned int periodic_state;
730
731 struct work_struct restart_work;
732
733 /* Informational stuff. */
734 char nick[IW_ESSID_MAX_SIZE + 1];
735
736 /* encryption/decryption */
737 u16 security_offset;
738 struct bcm43xx_key key[54];
739 u8 default_key_idx;
740
741 /* Firmware. */
742 const struct firmware *ucode;
743 const struct firmware *pcm;
744 const struct firmware *initvals0;
745 const struct firmware *initvals1;
746
747 /* Debugging stuff follows. */
748#ifdef CONFIG_BCM43XX_DEBUG
749 struct bcm43xx_dfsentry *dfsentry;
750#endif
751};
752
753/* bcm43xx_(un)lock() protect struct bcm43xx_private.
754 * Note that _NO_ MMIO writes are allowed. If you want to
755 * write to the device through MMIO in the critical section, use
756 * the *_mmio lock functions.
757 * MMIO read-access is allowed, though.
758 */
759#define bcm43xx_lock(bcm, flags) spin_lock_irqsave(&(bcm)->_lock, flags)
760#define bcm43xx_unlock(bcm, flags) spin_unlock_irqrestore(&(bcm)->_lock, flags)
761/* bcm43xx_(un)lock_mmio() protect struct bcm43xx_private and MMIO.
762 * MMIO write-access to the device is allowed.
763 * All MMIO writes are flushed on unlock, so it is guaranteed to not
764 * interfere with other threads writing MMIO registers.
765 */
766#define bcm43xx_lock_mmio(bcm, flags) bcm43xx_lock(bcm, flags)
767#define bcm43xx_unlock_mmio(bcm, flags) do { mmiowb(); bcm43xx_unlock(bcm, flags); } while (0)
768
769static inline
770struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
771{
772 return ieee80211softmac_priv(dev);
773}
774
775
776/* Helper function, which returns a boolean.
777 * TRUE, if PIO is used; FALSE, if DMA is used.
778 */
779#if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
780static inline
781int bcm43xx_using_pio(struct bcm43xx_private *bcm)
782{
783 return bcm->__using_pio;
784}
785#elif defined(CONFIG_BCM43XX_DMA)
786static inline
787int bcm43xx_using_pio(struct bcm43xx_private *bcm)
788{
789 return 0;
790}
791#elif defined(CONFIG_BCM43XX_PIO)
792static inline
793int bcm43xx_using_pio(struct bcm43xx_private *bcm)
794{
795 return 1;
796}
797#else
798# error "Using neither DMA nor PIO? Confused..."
799#endif
800
801/* Helper functions to access data structures private to the 80211 cores.
802 * Note that we _must_ have an 80211 core mapped when calling
803 * any of these functions.
804 */
805static inline
806struct bcm43xx_pio * bcm43xx_current_pio(struct bcm43xx_private *bcm)
807{
808 assert(bcm43xx_using_pio(bcm));
809 assert(bcm->current_80211_core_idx >= 0);
810 assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
811 return &(bcm->core_80211_ext[bcm->current_80211_core_idx].pio);
812}
813static inline
814struct bcm43xx_dma * bcm43xx_current_dma(struct bcm43xx_private *bcm)
815{
816 assert(!bcm43xx_using_pio(bcm));
817 assert(bcm->current_80211_core_idx >= 0);
818 assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
819 return &(bcm->core_80211_ext[bcm->current_80211_core_idx].dma);
820}
821static inline
822struct bcm43xx_phyinfo * bcm43xx_current_phy(struct bcm43xx_private *bcm)
823{
824 assert(bcm->current_80211_core_idx >= 0);
825 assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
826 return &(bcm->core_80211_ext[bcm->current_80211_core_idx].phy);
827}
828static inline
829struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm)
830{
831 assert(bcm->current_80211_core_idx >= 0);
832 assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
833 return &(bcm->core_80211_ext[bcm->current_80211_core_idx].radio);
834}
835
836/* Are we running in init_board() context? */
837static inline
838int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
839{
840 if (bcm->initialized)
841 return 0;
842 if (bcm->shutting_down)
843 return 0;
844 return 1;
845}
846
847static inline
848struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
849 u16 radio_attenuation,
850 u16 baseband_attenuation)
851{
852 return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
853}
854
855
856static inline
857u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
858{
859 return ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
860}
861
862static inline
863void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
864{
865 iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
866}
867
868static inline
869u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
870{
871 return ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
872}
873
874static inline
875void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
876{
877 iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
878}
879
880static inline
881int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
882{
883 return pci_read_config_word(bcm->pci_dev, offset, value);
884}
885
886static inline
887int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
888{
889 return pci_read_config_dword(bcm->pci_dev, offset, value);
890}
891
892static inline
893int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
894{
895 return pci_write_config_word(bcm->pci_dev, offset, value);
896}
897
898static inline
899int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
900{
901 return pci_write_config_dword(bcm->pci_dev, offset, value);
902}
903
904/** Limit a value between two limits */
905#ifdef limit_value
906# undef limit_value
907#endif
908#define limit_value(value, min, max) \
909 ({ \
910 typeof(value) __value = (value); \
911 typeof(value) __min = (min); \
912 typeof(value) __max = (max); \
913 if (__value < __min) \
914 __value = __min; \
915 else if (__value > __max) \
916 __value = __max; \
917 __value; \
918 })
919
920/** Helpers to print MAC addresses. */
921#define BCM43xx_MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
922#define BCM43xx_MACARG(x) ((u8*)(x))[0], ((u8*)(x))[1], \
923 ((u8*)(x))[2], ((u8*)(x))[3], \
924 ((u8*)(x))[4], ((u8*)(x))[5]
925
926#endif /* BCM43xx_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
new file mode 100644
index 000000000000..d2c3401e9b70
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
@@ -0,0 +1,499 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 debugfs driver debugging code
6
7 Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23
24*/
25
26
27
28#include <linux/fs.h>
29#include <linux/debugfs.h>
30#include <linux/slab.h>
31#include <linux/netdevice.h>
32#include <linux/pci.h>
33#include <asm/io.h>
34
35#include "bcm43xx.h"
36#include "bcm43xx_main.h"
37#include "bcm43xx_debugfs.h"
38#include "bcm43xx_dma.h"
39#include "bcm43xx_pio.h"
40#include "bcm43xx_xmit.h"
41
42#define REALLY_BIG_BUFFER_SIZE (1024*256)
43
44static struct bcm43xx_debugfs fs;
45static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
46static DECLARE_MUTEX(big_buffer_sem);
47
48
49static ssize_t write_file_dummy(struct file *file, const char __user *buf,
50 size_t count, loff_t *ppos)
51{
52 return count;
53}
54
55static int open_file_generic(struct inode *inode, struct file *file)
56{
57 file->private_data = inode->u.generic_ip;
58 return 0;
59}
60
61#define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
62
63static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
64 size_t count, loff_t *ppos)
65{
66 const size_t len = REALLY_BIG_BUFFER_SIZE;
67
68 struct bcm43xx_private *bcm = file->private_data;
69 char *buf = really_big_buffer;
70 size_t pos = 0;
71 ssize_t res;
72 struct net_device *net_dev;
73 struct pci_dev *pci_dev;
74 unsigned long flags;
75 u16 tmp16;
76 int i;
77
78 down(&big_buffer_sem);
79
80 bcm43xx_lock_mmio(bcm, flags);
81 if (!bcm->initialized) {
82 fappend("Board not initialized.\n");
83 goto out;
84 }
85 net_dev = bcm->net_dev;
86 pci_dev = bcm->pci_dev;
87
88 /* This is where the information is written to the "devinfo" file */
89 fappend("*** %s devinfo ***\n", net_dev->name);
90 fappend("vendor: 0x%04x device: 0x%04x\n",
91 pci_dev->vendor, pci_dev->device);
92 fappend("subsystem_vendor: 0x%04x subsystem_device: 0x%04x\n",
93 pci_dev->subsystem_vendor, pci_dev->subsystem_device);
94 fappend("IRQ: %d\n", bcm->irq);
95 fappend("mmio_addr: 0x%p mmio_len: %u\n", bcm->mmio_addr, bcm->mmio_len);
96 fappend("chip_id: 0x%04x chip_rev: 0x%02x\n", bcm->chip_id, bcm->chip_rev);
97 if ((bcm->core_80211[0].rev >= 3) && (bcm43xx_read32(bcm, 0x0158) & (1 << 16)))
98 fappend("Radio disabled by hardware!\n");
99 if ((bcm->core_80211[0].rev < 3) && !(bcm43xx_read16(bcm, 0x049A) & (1 << 4)))
100 fappend("Radio disabled by hardware!\n");
101 fappend("board_vendor: 0x%04x board_type: 0x%04x\n", bcm->board_vendor,
102 bcm->board_type);
103
104 fappend("\nCores:\n");
105#define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, " \
106 "rev: 0x%02x, index: 0x%02x\n", \
107 (info).available \
108 ? "available" : "nonavailable", \
109 (info).enabled \
110 ? "enabled" : "disabled", \
111 (info).id, (info).rev, (info).index)
112 fappend_core("CHIPCOMMON", bcm->core_chipcommon);
113 fappend_core("PCI", bcm->core_pci);
114 fappend_core("first 80211", bcm->core_80211[0]);
115 fappend_core("second 80211", bcm->core_80211[1]);
116#undef fappend_core
117 tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
118 fappend("LEDs: ");
119 for (i = 0; i < BCM43xx_NR_LEDS; i++)
120 fappend("%d ", !!(tmp16 & (1 << i)));
121 fappend("\n");
122
123out:
124 bcm43xx_unlock_mmio(bcm, flags);
125 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
126 up(&big_buffer_sem);
127 return res;
128}
129
130static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
131 size_t count, loff_t *ppos)
132{
133 const size_t len = REALLY_BIG_BUFFER_SIZE;
134
135 char *buf = really_big_buffer;
136 size_t pos = 0;
137 ssize_t res;
138
139 down(&big_buffer_sem);
140
141 /* This is where the information is written to the "driver" file */
142 fappend(KBUILD_MODNAME " driver\n");
143 fappend("Compiled at: %s %s\n", __DATE__, __TIME__);
144
145 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
146 up(&big_buffer_sem);
147 return res;
148}
149
150static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
151 size_t count, loff_t *ppos)
152{
153 const size_t len = REALLY_BIG_BUFFER_SIZE;
154
155 struct bcm43xx_private *bcm = file->private_data;
156 char *buf = really_big_buffer;
157 size_t pos = 0;
158 ssize_t res;
159 unsigned long flags;
160
161 down(&big_buffer_sem);
162 bcm43xx_lock_mmio(bcm, flags);
163 if (!bcm->initialized) {
164 fappend("Board not initialized.\n");
165 goto out;
166 }
167
168 /* This is where the information is written to the "sprom_dump" file */
169 fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
170
171out:
172 bcm43xx_unlock_mmio(bcm, flags);
173 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
174 up(&big_buffer_sem);
175 return res;
176}
177
178static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
179 size_t count, loff_t *ppos)
180{
181 const size_t len = REALLY_BIG_BUFFER_SIZE;
182
183 struct bcm43xx_private *bcm = file->private_data;
184 char *buf = really_big_buffer;
185 size_t pos = 0;
186 ssize_t res;
187 unsigned long flags;
188 u64 tsf;
189
190 down(&big_buffer_sem);
191 bcm43xx_lock_mmio(bcm, flags);
192 if (!bcm->initialized) {
193 fappend("Board not initialized.\n");
194 goto out;
195 }
196 bcm43xx_tsf_read(bcm, &tsf);
197 fappend("0x%08x%08x\n",
198 (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
199 (unsigned int)(tsf & 0xFFFFFFFFULL));
200
201out:
202 bcm43xx_unlock_mmio(bcm, flags);
203 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
204 up(&big_buffer_sem);
205 return res;
206}
207
208static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
209 size_t count, loff_t *ppos)
210{
211 struct bcm43xx_private *bcm = file->private_data;
212 char *buf = really_big_buffer;
213 ssize_t buf_size;
214 ssize_t res;
215 unsigned long flags;
216 u64 tsf;
217
218 buf_size = min(count, sizeof (really_big_buffer) - 1);
219 down(&big_buffer_sem);
220 if (copy_from_user(buf, user_buf, buf_size)) {
221 res = -EFAULT;
222 goto out_up;
223 }
224 bcm43xx_lock_mmio(bcm, flags);
225 if (!bcm->initialized) {
226 printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
227 res = -EFAULT;
228 goto out_unlock;
229 }
230 if (sscanf(buf, "%lli", &tsf) != 1) {
231 printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
232 res = -EINVAL;
233 goto out_unlock;
234 }
235 bcm43xx_tsf_write(bcm, tsf);
236 res = buf_size;
237
238out_unlock:
239 bcm43xx_unlock_mmio(bcm, flags);
240out_up:
241 up(&big_buffer_sem);
242 return res;
243}
244
245static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
246 size_t count, loff_t *ppos)
247{
248 const size_t len = REALLY_BIG_BUFFER_SIZE;
249
250 struct bcm43xx_private *bcm = file->private_data;
251 char *buf = really_big_buffer;
252 size_t pos = 0;
253 ssize_t res;
254 unsigned long flags;
255 struct bcm43xx_dfsentry *e;
256 struct bcm43xx_xmitstatus *status;
257 int i, cnt, j = 0;
258
259 down(&big_buffer_sem);
260 bcm43xx_lock(bcm, flags);
261
262 fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
263 BCM43xx_NR_LOGGED_XMITSTATUS);
264 e = bcm->dfsentry;
265 if (e->xmitstatus_printing == 0) {
266 /* At the beginning, make a copy of all data to avoid
267 * concurrency, as this function is called multiple
268 * times for big logs. Without copying, the data might
269 * change between reads. This would result in total trash.
270 */
271 e->xmitstatus_printing = 1;
272 e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
273 e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
274 memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
275 BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
276 }
277 i = e->saved_xmitstatus_ptr - 1;
278 if (i < 0)
279 i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
280 cnt = e->saved_xmitstatus_cnt;
281 while (cnt) {
282 status = e->xmitstatus_print_buffer + i;
283 fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
284 "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
285 "unk: 0x%04x\n", j,
286 status->cookie, status->flags,
287 status->cnt1, status->cnt2, status->seq,
288 status->unknown);
289 j++;
290 cnt--;
291 i--;
292 if (i < 0)
293 i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
294 }
295
296 bcm43xx_unlock(bcm, flags);
297 res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
298 bcm43xx_lock(bcm, flags);
299 if (*ppos == pos) {
300 /* Done. Drop the copied data. */
301 e->xmitstatus_printing = 0;
302 }
303 bcm43xx_unlock(bcm, flags);
304 up(&big_buffer_sem);
305 return res;
306}
307
308#undef fappend
309
310
311static struct file_operations devinfo_fops = {
312 .read = devinfo_read_file,
313 .write = write_file_dummy,
314 .open = open_file_generic,
315};
316
317static struct file_operations spromdump_fops = {
318 .read = spromdump_read_file,
319 .write = write_file_dummy,
320 .open = open_file_generic,
321};
322
323static struct file_operations drvinfo_fops = {
324 .read = drvinfo_read_file,
325 .write = write_file_dummy,
326 .open = open_file_generic,
327};
328
329static struct file_operations tsf_fops = {
330 .read = tsf_read_file,
331 .write = tsf_write_file,
332 .open = open_file_generic,
333};
334
335static struct file_operations txstat_fops = {
336 .read = txstat_read_file,
337 .write = write_file_dummy,
338 .open = open_file_generic,
339};
340
341
342void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
343{
344 struct bcm43xx_dfsentry *e;
345 char devdir[IFNAMSIZ];
346
347 assert(bcm);
348 e = kzalloc(sizeof(*e), GFP_KERNEL);
349 if (!e) {
350 printk(KERN_ERR PFX "out of memory\n");
351 return;
352 }
353 e->bcm = bcm;
354 e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
355 * sizeof(*(e->xmitstatus_buffer)),
356 GFP_KERNEL);
357 if (!e->xmitstatus_buffer) {
358 printk(KERN_ERR PFX "out of memory\n");
359 kfree(e);
360 return;
361 }
362 e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
363 * sizeof(*(e->xmitstatus_buffer)),
364 GFP_KERNEL);
365 if (!e->xmitstatus_print_buffer) {
366 printk(KERN_ERR PFX "out of memory\n");
367 kfree(e);
368 return;
369 }
370
371
372 bcm->dfsentry = e;
373
374 strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
375 e->subdir = debugfs_create_dir(devdir, fs.root);
376 e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
377 bcm, &devinfo_fops);
378 if (!e->dentry_devinfo)
379 printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
380 e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
381 bcm, &spromdump_fops);
382 if (!e->dentry_spromdump)
383 printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
384 e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
385 bcm, &tsf_fops);
386 if (!e->dentry_tsf)
387 printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
388 e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
389 bcm, &txstat_fops);
390 if (!e->dentry_txstat)
391 printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
392}
393
394void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
395{
396 struct bcm43xx_dfsentry *e;
397
398 if (!bcm)
399 return;
400
401 e = bcm->dfsentry;
402 assert(e);
403 debugfs_remove(e->dentry_spromdump);
404 debugfs_remove(e->dentry_devinfo);
405 debugfs_remove(e->dentry_tsf);
406 debugfs_remove(e->dentry_txstat);
407 debugfs_remove(e->subdir);
408 kfree(e->xmitstatus_buffer);
409 kfree(e->xmitstatus_print_buffer);
410 kfree(e);
411}
412
413void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
414 struct bcm43xx_xmitstatus *status)
415{
416 struct bcm43xx_dfsentry *e;
417 struct bcm43xx_xmitstatus *savedstatus;
418
419 /* This is protected by bcm->_lock */
420 e = bcm->dfsentry;
421 assert(e);
422 savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
423 memcpy(savedstatus, status, sizeof(*status));
424 e->xmitstatus_ptr++;
425 if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
426 e->xmitstatus_ptr = 0;
427 if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
428 e->xmitstatus_cnt++;
429}
430
431void bcm43xx_debugfs_init(void)
432{
433 memset(&fs, 0, sizeof(fs));
434 fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
435 if (!fs.root)
436 printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "\" subdir failed!\n");
437 fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
438 if (!fs.dentry_driverinfo)
439 printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "/driver\" failed!\n");
440}
441
442void bcm43xx_debugfs_exit(void)
443{
444 debugfs_remove(fs.dentry_driverinfo);
445 debugfs_remove(fs.root);
446}
447
448void bcm43xx_printk_dump(const char *data,
449 size_t size,
450 const char *description)
451{
452 size_t i;
453 char c;
454
455 printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
456 description, size);
457 for (i = 0; i < size; i++) {
458 c = data[i];
459 if (i % 8 == 0)
460 printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
461 else
462 printk("0x%02x, ", c & 0xff);
463 }
464 printk("\n");
465}
466
467void bcm43xx_printk_bitdump(const unsigned char *data,
468 size_t bytes, int msb_to_lsb,
469 const char *description)
470{
471 size_t i;
472 int j;
473 const unsigned char *d;
474
475 printk(KERN_INFO PFX "*** Bitdump (%s, %u bytes, %s) ***",
476 description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
477 for (i = 0; i < bytes; i++) {
478 d = data + i;
479 if (i % 8 == 0)
480 printk("\n" KERN_INFO PFX "0x%08x: ", i);
481 if (msb_to_lsb) {
482 for (j = 7; j >= 0; j--) {
483 if (*d & (1 << j))
484 printk("1");
485 else
486 printk("0");
487 }
488 } else {
489 for (j = 0; j < 8; j++) {
490 if (*d & (1 << j))
491 printk("1");
492 else
493 printk("0");
494 }
495 }
496 printk(" ");
497 }
498 printk("\n");
499}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.h b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.h
new file mode 100644
index 000000000000..50ce267f794d
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.h
@@ -0,0 +1,117 @@
1#ifndef BCM43xx_DEBUGFS_H_
2#define BCM43xx_DEBUGFS_H_
3
4struct bcm43xx_private;
5struct bcm43xx_xmitstatus;
6
7#ifdef CONFIG_BCM43XX_DEBUG
8
9#include <linux/list.h>
10#include <asm/semaphore.h>
11
12struct dentry;
13
14/* limited by the size of the "really_big_buffer" */
15#define BCM43xx_NR_LOGGED_XMITSTATUS 100
16
17struct bcm43xx_dfsentry {
18 struct dentry *subdir;
19 struct dentry *dentry_devinfo;
20 struct dentry *dentry_spromdump;
21 struct dentry *dentry_tsf;
22 struct dentry *dentry_txstat;
23
24 struct bcm43xx_private *bcm;
25
26 /* saved xmitstatus. */
27 struct bcm43xx_xmitstatus *xmitstatus_buffer;
28 int xmitstatus_ptr;
29 int xmitstatus_cnt;
30 /* We need a seperate buffer while printing to avoid
31 * concurrency issues. (New xmitstatus can arrive
32 * while we are printing).
33 */
34 struct bcm43xx_xmitstatus *xmitstatus_print_buffer;
35 int saved_xmitstatus_ptr;
36 int saved_xmitstatus_cnt;
37 int xmitstatus_printing;
38};
39
40struct bcm43xx_debugfs {
41 struct dentry *root;
42 struct dentry *dentry_driverinfo;
43};
44
45void bcm43xx_debugfs_init(void);
46void bcm43xx_debugfs_exit(void);
47void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm);
48void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm);
49void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
50 struct bcm43xx_xmitstatus *status);
51
52/* Debug helper: Dump binary data through printk. */
53void bcm43xx_printk_dump(const char *data,
54 size_t size,
55 const char *description);
56/* Debug helper: Dump bitwise binary data through printk. */
57void bcm43xx_printk_bitdump(const unsigned char *data,
58 size_t bytes, int msb_to_lsb,
59 const char *description);
60#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) \
61 do { \
62 bcm43xx_printk_bitdump((const unsigned char *)(pointer), \
63 sizeof(*(pointer)), \
64 (msb_to_lsb), \
65 (description)); \
66 } while (0)
67
68#else /* CONFIG_BCM43XX_DEBUG*/
69
70static inline
71void bcm43xx_debugfs_init(void) { }
72static inline
73void bcm43xx_debugfs_exit(void) { }
74static inline
75void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm) { }
76static inline
77void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm) { }
78static inline
79void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
80 struct bcm43xx_xmitstatus *status) { }
81
82static inline
83void bcm43xx_printk_dump(const char *data,
84 size_t size,
85 const char *description)
86{
87}
88static inline
89void bcm43xx_printk_bitdump(const unsigned char *data,
90 size_t bytes, int msb_to_lsb,
91 const char *description)
92{
93}
94#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) do { /* nothing */ } while (0)
95
96#endif /* CONFIG_BCM43XX_DEBUG*/
97
98/* Ugly helper macros to make incomplete code more verbose on runtime */
99#ifdef TODO
100# undef TODO
101#endif
102#define TODO() \
103 do { \
104 printk(KERN_INFO PFX "TODO: Incomplete code in %s() at %s:%d\n", \
105 __FUNCTION__, __FILE__, __LINE__); \
106 } while (0)
107
108#ifdef FIXME
109# undef FIXME
110#endif
111#define FIXME() \
112 do { \
113 printk(KERN_INFO PFX "FIXME: Possibly broken code in %s() at %s:%d\n", \
114 __FUNCTION__, __FILE__, __LINE__); \
115 } while (0)
116
117#endif /* BCM43xx_DEBUGFS_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
new file mode 100644
index 000000000000..c3681b8f09b4
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
@@ -0,0 +1,968 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 DMA ringbuffer and descriptor allocation/management
6
7 Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
8
9 Some code in this file is derived from the b44.c driver
10 Copyright (C) 2002 David S. Miller
11 Copyright (C) Pekka Pietikainen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; see the file COPYING. If not, write to
25 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
26 Boston, MA 02110-1301, USA.
27
28*/
29
30#include "bcm43xx.h"
31#include "bcm43xx_dma.h"
32#include "bcm43xx_main.h"
33#include "bcm43xx_debugfs.h"
34#include "bcm43xx_power.h"
35#include "bcm43xx_xmit.h"
36
37#include <linux/dma-mapping.h>
38#include <linux/pci.h>
39#include <linux/delay.h>
40#include <linux/skbuff.h>
41
42
43static inline int free_slots(struct bcm43xx_dmaring *ring)
44{
45 return (ring->nr_slots - ring->used_slots);
46}
47
48static inline int next_slot(struct bcm43xx_dmaring *ring, int slot)
49{
50 assert(slot >= -1 && slot <= ring->nr_slots - 1);
51 if (slot == ring->nr_slots - 1)
52 return 0;
53 return slot + 1;
54}
55
56static inline int prev_slot(struct bcm43xx_dmaring *ring, int slot)
57{
58 assert(slot >= 0 && slot <= ring->nr_slots - 1);
59 if (slot == 0)
60 return ring->nr_slots - 1;
61 return slot - 1;
62}
63
64/* Request a slot for usage. */
65static inline
66int request_slot(struct bcm43xx_dmaring *ring)
67{
68 int slot;
69
70 assert(ring->tx);
71 assert(!ring->suspended);
72 assert(free_slots(ring) != 0);
73
74 slot = next_slot(ring, ring->current_slot);
75 ring->current_slot = slot;
76 ring->used_slots++;
77
78 /* Check the number of available slots and suspend TX,
79 * if we are running low on free slots.
80 */
81 if (unlikely(free_slots(ring) < ring->suspend_mark)) {
82 netif_stop_queue(ring->bcm->net_dev);
83 ring->suspended = 1;
84 }
85#ifdef CONFIG_BCM43XX_DEBUG
86 if (ring->used_slots > ring->max_used_slots)
87 ring->max_used_slots = ring->used_slots;
88#endif /* CONFIG_BCM43XX_DEBUG*/
89
90 return slot;
91}
92
93/* Return a slot to the free slots. */
94static inline
95void return_slot(struct bcm43xx_dmaring *ring, int slot)
96{
97 assert(ring->tx);
98
99 ring->used_slots--;
100
101 /* Check if TX is suspended and check if we have
102 * enough free slots to resume it again.
103 */
104 if (unlikely(ring->suspended)) {
105 if (free_slots(ring) >= ring->resume_mark) {
106 ring->suspended = 0;
107 netif_wake_queue(ring->bcm->net_dev);
108 }
109 }
110}
111
112static inline
113dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
114 unsigned char *buf,
115 size_t len,
116 int tx)
117{
118 dma_addr_t dmaaddr;
119
120 if (tx) {
121 dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
122 buf, len,
123 DMA_TO_DEVICE);
124 } else {
125 dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
126 buf, len,
127 DMA_FROM_DEVICE);
128 }
129
130 return dmaaddr;
131}
132
133static inline
134void unmap_descbuffer(struct bcm43xx_dmaring *ring,
135 dma_addr_t addr,
136 size_t len,
137 int tx)
138{
139 if (tx) {
140 dma_unmap_single(&ring->bcm->pci_dev->dev,
141 addr, len,
142 DMA_TO_DEVICE);
143 } else {
144 dma_unmap_single(&ring->bcm->pci_dev->dev,
145 addr, len,
146 DMA_FROM_DEVICE);
147 }
148}
149
150static inline
151void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
152 dma_addr_t addr,
153 size_t len)
154{
155 assert(!ring->tx);
156
157 dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev,
158 addr, len, DMA_FROM_DEVICE);
159}
160
161static inline
162void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
163 dma_addr_t addr,
164 size_t len)
165{
166 assert(!ring->tx);
167
168 dma_sync_single_for_device(&ring->bcm->pci_dev->dev,
169 addr, len, DMA_FROM_DEVICE);
170}
171
172/* Unmap and free a descriptor buffer. */
173static inline
174void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
175 struct bcm43xx_dmadesc *desc,
176 struct bcm43xx_dmadesc_meta *meta,
177 int irq_context)
178{
179 assert(meta->skb);
180 if (irq_context)
181 dev_kfree_skb_irq(meta->skb);
182 else
183 dev_kfree_skb(meta->skb);
184 meta->skb = NULL;
185}
186
187static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
188{
189 struct device *dev = &(ring->bcm->pci_dev->dev);
190
191 ring->vbase = dma_alloc_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
192 &(ring->dmabase), GFP_KERNEL);
193 if (!ring->vbase) {
194 printk(KERN_ERR PFX "DMA ringmemory allocation failed\n");
195 return -ENOMEM;
196 }
197 if (ring->dmabase + BCM43xx_DMA_RINGMEMSIZE > BCM43xx_DMA_BUSADDRMAX) {
198 printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA RINGMEMORY >1G "
199 "(0x%08x, len: %lu)\n",
200 ring->dmabase, BCM43xx_DMA_RINGMEMSIZE);
201 dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
202 ring->vbase, ring->dmabase);
203 return -ENOMEM;
204 }
205 assert(!(ring->dmabase & 0x000003FF));
206 memset(ring->vbase, 0, BCM43xx_DMA_RINGMEMSIZE);
207
208 return 0;
209}
210
211static void free_ringmemory(struct bcm43xx_dmaring *ring)
212{
213 struct device *dev = &(ring->bcm->pci_dev->dev);
214
215 dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
216 ring->vbase, ring->dmabase);
217}
218
219/* Reset the RX DMA channel */
220int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
221 u16 mmio_base)
222{
223 int i;
224 u32 value;
225
226 bcm43xx_write32(bcm,
227 mmio_base + BCM43xx_DMA_RX_CONTROL,
228 0x00000000);
229 for (i = 0; i < 1000; i++) {
230 value = bcm43xx_read32(bcm,
231 mmio_base + BCM43xx_DMA_RX_STATUS);
232 value &= BCM43xx_DMA_RXSTAT_STAT_MASK;
233 if (value == BCM43xx_DMA_RXSTAT_STAT_DISABLED) {
234 i = -1;
235 break;
236 }
237 udelay(10);
238 }
239 if (i != -1) {
240 printk(KERN_ERR PFX "Error: Wait on DMA RX status timed out.\n");
241 return -ENODEV;
242 }
243
244 return 0;
245}
246
247/* Reset the RX DMA channel */
248int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
249 u16 mmio_base)
250{
251 int i;
252 u32 value;
253
254 for (i = 0; i < 1000; i++) {
255 value = bcm43xx_read32(bcm,
256 mmio_base + BCM43xx_DMA_TX_STATUS);
257 value &= BCM43xx_DMA_TXSTAT_STAT_MASK;
258 if (value == BCM43xx_DMA_TXSTAT_STAT_DISABLED ||
259 value == BCM43xx_DMA_TXSTAT_STAT_IDLEWAIT ||
260 value == BCM43xx_DMA_TXSTAT_STAT_STOPPED)
261 break;
262 udelay(10);
263 }
264 bcm43xx_write32(bcm,
265 mmio_base + BCM43xx_DMA_TX_CONTROL,
266 0x00000000);
267 for (i = 0; i < 1000; i++) {
268 value = bcm43xx_read32(bcm,
269 mmio_base + BCM43xx_DMA_TX_STATUS);
270 value &= BCM43xx_DMA_TXSTAT_STAT_MASK;
271 if (value == BCM43xx_DMA_TXSTAT_STAT_DISABLED) {
272 i = -1;
273 break;
274 }
275 udelay(10);
276 }
277 if (i != -1) {
278 printk(KERN_ERR PFX "Error: Wait on DMA TX status timed out.\n");
279 return -ENODEV;
280 }
281 /* ensure the reset is completed. */
282 udelay(300);
283
284 return 0;
285}
286
287static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
288 struct bcm43xx_dmadesc *desc,
289 struct bcm43xx_dmadesc_meta *meta,
290 gfp_t gfp_flags)
291{
292 struct bcm43xx_rxhdr *rxhdr;
293 dma_addr_t dmaaddr;
294 u32 desc_addr;
295 u32 desc_ctl;
296 const int slot = (int)(desc - ring->vbase);
297 struct sk_buff *skb;
298
299 assert(slot >= 0 && slot < ring->nr_slots);
300 assert(!ring->tx);
301
302 skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
303 if (unlikely(!skb))
304 return -ENOMEM;
305 dmaaddr = map_descbuffer(ring, skb->data, ring->rx_buffersize, 0);
306 if (unlikely(dmaaddr + ring->rx_buffersize > BCM43xx_DMA_BUSADDRMAX)) {
307 unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
308 dev_kfree_skb_any(skb);
309 printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA RX SKB >1G "
310 "(0x%08x, len: %u)\n",
311 dmaaddr, ring->rx_buffersize);
312 return -ENOMEM;
313 }
314 meta->skb = skb;
315 meta->dmaaddr = dmaaddr;
316 skb->dev = ring->bcm->net_dev;
317 desc_addr = (u32)(dmaaddr + ring->memoffset);
318 desc_ctl = (BCM43xx_DMADTOR_BYTECNT_MASK &
319 (u32)(ring->rx_buffersize - ring->frameoffset));
320 if (slot == ring->nr_slots - 1)
321 desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
322 set_desc_addr(desc, desc_addr);
323 set_desc_ctl(desc, desc_ctl);
324
325 rxhdr = (struct bcm43xx_rxhdr *)(skb->data);
326 rxhdr->frame_length = 0;
327 rxhdr->flags1 = 0;
328
329 return 0;
330}
331
332/* Allocate the initial descbuffers.
333 * This is used for an RX ring only.
334 */
335static int alloc_initial_descbuffers(struct bcm43xx_dmaring *ring)
336{
337 int i, err = -ENOMEM;
338 struct bcm43xx_dmadesc *desc;
339 struct bcm43xx_dmadesc_meta *meta;
340
341 for (i = 0; i < ring->nr_slots; i++) {
342 desc = ring->vbase + i;
343 meta = ring->meta + i;
344
345 err = setup_rx_descbuffer(ring, desc, meta, GFP_KERNEL);
346 if (err)
347 goto err_unwind;
348 }
349 ring->used_slots = ring->nr_slots;
350 err = 0;
351out:
352 return err;
353
354err_unwind:
355 for (i--; i >= 0; i--) {
356 desc = ring->vbase + i;
357 meta = ring->meta + i;
358
359 unmap_descbuffer(ring, meta->dmaaddr, ring->rx_buffersize, 0);
360 dev_kfree_skb(meta->skb);
361 }
362 goto out;
363}
364
365/* Do initial setup of the DMA controller.
366 * Reset the controller, write the ring busaddress
367 * and switch the "enable" bit on.
368 */
369static int dmacontroller_setup(struct bcm43xx_dmaring *ring)
370{
371 int err = 0;
372 u32 value;
373
374 if (ring->tx) {
375 /* Set Transmit Control register to "transmit enable" */
376 bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
377 BCM43xx_DMA_TXCTRL_ENABLE);
378 /* Set Transmit Descriptor ring address. */
379 bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_RING,
380 ring->dmabase + ring->memoffset);
381 } else {
382 err = alloc_initial_descbuffers(ring);
383 if (err)
384 goto out;
385 /* Set Receive Control "receive enable" and frame offset */
386 value = (ring->frameoffset << BCM43xx_DMA_RXCTRL_FRAMEOFF_SHIFT);
387 value |= BCM43xx_DMA_RXCTRL_ENABLE;
388 bcm43xx_dma_write(ring, BCM43xx_DMA_RX_CONTROL, value);
389 /* Set Receive Descriptor ring address. */
390 bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_RING,
391 ring->dmabase + ring->memoffset);
392 /* Init the descriptor pointer. */
393 bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX, 200);
394 }
395
396out:
397 return err;
398}
399
400/* Shutdown the DMA controller. */
401static void dmacontroller_cleanup(struct bcm43xx_dmaring *ring)
402{
403 if (ring->tx) {
404 bcm43xx_dmacontroller_tx_reset(ring->bcm, ring->mmio_base);
405 /* Zero out Transmit Descriptor ring address. */
406 bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_RING, 0);
407 } else {
408 bcm43xx_dmacontroller_rx_reset(ring->bcm, ring->mmio_base);
409 /* Zero out Receive Descriptor ring address. */
410 bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_RING, 0);
411 }
412}
413
414static void free_all_descbuffers(struct bcm43xx_dmaring *ring)
415{
416 struct bcm43xx_dmadesc *desc;
417 struct bcm43xx_dmadesc_meta *meta;
418 int i;
419
420 if (!ring->used_slots)
421 return;
422 for (i = 0; i < ring->nr_slots; i++) {
423 desc = ring->vbase + i;
424 meta = ring->meta + i;
425
426 if (!meta->skb) {
427 assert(ring->tx);
428 continue;
429 }
430 if (ring->tx) {
431 unmap_descbuffer(ring, meta->dmaaddr,
432 meta->skb->len, 1);
433 } else {
434 unmap_descbuffer(ring, meta->dmaaddr,
435 ring->rx_buffersize, 0);
436 }
437 free_descriptor_buffer(ring, desc, meta, 0);
438 }
439}
440
441/* Main initialization function. */
442static
443struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
444 u16 dma_controller_base,
445 int nr_descriptor_slots,
446 int tx)
447{
448 struct bcm43xx_dmaring *ring;
449 int err;
450
451 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
452 if (!ring)
453 goto out;
454
455 ring->meta = kzalloc(sizeof(*ring->meta) * nr_descriptor_slots,
456 GFP_KERNEL);
457 if (!ring->meta)
458 goto err_kfree_ring;
459
460 ring->memoffset = BCM43xx_DMA_DMABUSADDROFFSET;
461#ifdef CONFIG_BCM947XX
462 if (bcm->pci_dev->bus->number == 0)
463 ring->memoffset = 0;
464#endif
465
466 ring->bcm = bcm;
467 ring->nr_slots = nr_descriptor_slots;
468 ring->suspend_mark = ring->nr_slots * BCM43xx_TXSUSPEND_PERCENT / 100;
469 ring->resume_mark = ring->nr_slots * BCM43xx_TXRESUME_PERCENT / 100;
470 assert(ring->suspend_mark < ring->resume_mark);
471 ring->mmio_base = dma_controller_base;
472 if (tx) {
473 ring->tx = 1;
474 ring->current_slot = -1;
475 } else {
476 switch (dma_controller_base) {
477 case BCM43xx_MMIO_DMA1_BASE:
478 ring->rx_buffersize = BCM43xx_DMA1_RXBUFFERSIZE;
479 ring->frameoffset = BCM43xx_DMA1_RX_FRAMEOFFSET;
480 break;
481 case BCM43xx_MMIO_DMA4_BASE:
482 ring->rx_buffersize = BCM43xx_DMA4_RXBUFFERSIZE;
483 ring->frameoffset = BCM43xx_DMA4_RX_FRAMEOFFSET;
484 break;
485 default:
486 assert(0);
487 }
488 }
489
490 err = alloc_ringmemory(ring);
491 if (err)
492 goto err_kfree_meta;
493 err = dmacontroller_setup(ring);
494 if (err)
495 goto err_free_ringmemory;
496
497out:
498 return ring;
499
500err_free_ringmemory:
501 free_ringmemory(ring);
502err_kfree_meta:
503 kfree(ring->meta);
504err_kfree_ring:
505 kfree(ring);
506 ring = NULL;
507 goto out;
508}
509
510/* Main cleanup function. */
511static void bcm43xx_destroy_dmaring(struct bcm43xx_dmaring *ring)
512{
513 if (!ring)
514 return;
515
516 dprintk(KERN_INFO PFX "DMA 0x%04x (%s) max used slots: %d/%d\n",
517 ring->mmio_base,
518 (ring->tx) ? "TX" : "RX",
519 ring->max_used_slots, ring->nr_slots);
520 /* Device IRQs are disabled prior entering this function,
521 * so no need to take care of concurrency with rx handler stuff.
522 */
523 dmacontroller_cleanup(ring);
524 free_all_descbuffers(ring);
525 free_ringmemory(ring);
526
527 kfree(ring->meta);
528 kfree(ring);
529}
530
531void bcm43xx_dma_free(struct bcm43xx_private *bcm)
532{
533 struct bcm43xx_dma *dma;
534
535 if (bcm43xx_using_pio(bcm))
536 return;
537 dma = bcm43xx_current_dma(bcm);
538
539 bcm43xx_destroy_dmaring(dma->rx_ring1);
540 dma->rx_ring1 = NULL;
541 bcm43xx_destroy_dmaring(dma->rx_ring0);
542 dma->rx_ring0 = NULL;
543 bcm43xx_destroy_dmaring(dma->tx_ring3);
544 dma->tx_ring3 = NULL;
545 bcm43xx_destroy_dmaring(dma->tx_ring2);
546 dma->tx_ring2 = NULL;
547 bcm43xx_destroy_dmaring(dma->tx_ring1);
548 dma->tx_ring1 = NULL;
549 bcm43xx_destroy_dmaring(dma->tx_ring0);
550 dma->tx_ring0 = NULL;
551}
552
553int bcm43xx_dma_init(struct bcm43xx_private *bcm)
554{
555 struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
556 struct bcm43xx_dmaring *ring;
557 int err = -ENOMEM;
558
559 /* setup TX DMA channels. */
560 ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
561 BCM43xx_TXRING_SLOTS, 1);
562 if (!ring)
563 goto out;
564 dma->tx_ring0 = ring;
565
566 ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA2_BASE,
567 BCM43xx_TXRING_SLOTS, 1);
568 if (!ring)
569 goto err_destroy_tx0;
570 dma->tx_ring1 = ring;
571
572 ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA3_BASE,
573 BCM43xx_TXRING_SLOTS, 1);
574 if (!ring)
575 goto err_destroy_tx1;
576 dma->tx_ring2 = ring;
577
578 ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
579 BCM43xx_TXRING_SLOTS, 1);
580 if (!ring)
581 goto err_destroy_tx2;
582 dma->tx_ring3 = ring;
583
584 /* setup RX DMA channels. */
585 ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
586 BCM43xx_RXRING_SLOTS, 0);
587 if (!ring)
588 goto err_destroy_tx3;
589 dma->rx_ring0 = ring;
590
591 if (bcm->current_core->rev < 5) {
592 ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
593 BCM43xx_RXRING_SLOTS, 0);
594 if (!ring)
595 goto err_destroy_rx0;
596 dma->rx_ring1 = ring;
597 }
598
599 dprintk(KERN_INFO PFX "DMA initialized\n");
600 err = 0;
601out:
602 return err;
603
604err_destroy_rx0:
605 bcm43xx_destroy_dmaring(dma->rx_ring0);
606 dma->rx_ring0 = NULL;
607err_destroy_tx3:
608 bcm43xx_destroy_dmaring(dma->tx_ring3);
609 dma->tx_ring3 = NULL;
610err_destroy_tx2:
611 bcm43xx_destroy_dmaring(dma->tx_ring2);
612 dma->tx_ring2 = NULL;
613err_destroy_tx1:
614 bcm43xx_destroy_dmaring(dma->tx_ring1);
615 dma->tx_ring1 = NULL;
616err_destroy_tx0:
617 bcm43xx_destroy_dmaring(dma->tx_ring0);
618 dma->tx_ring0 = NULL;
619 goto out;
620}
621
622/* Generate a cookie for the TX header. */
623static u16 generate_cookie(struct bcm43xx_dmaring *ring,
624 int slot)
625{
626 u16 cookie = 0x0000;
627
628 /* Use the upper 4 bits of the cookie as
629 * DMA controller ID and store the slot number
630 * in the lower 12 bits
631 */
632 switch (ring->mmio_base) {
633 default:
634 assert(0);
635 case BCM43xx_MMIO_DMA1_BASE:
636 break;
637 case BCM43xx_MMIO_DMA2_BASE:
638 cookie = 0x1000;
639 break;
640 case BCM43xx_MMIO_DMA3_BASE:
641 cookie = 0x2000;
642 break;
643 case BCM43xx_MMIO_DMA4_BASE:
644 cookie = 0x3000;
645 break;
646 }
647 assert(((u16)slot & 0xF000) == 0x0000);
648 cookie |= (u16)slot;
649
650 return cookie;
651}
652
653/* Inspect a cookie and find out to which controller/slot it belongs. */
654static
655struct bcm43xx_dmaring * parse_cookie(struct bcm43xx_private *bcm,
656 u16 cookie, int *slot)
657{
658 struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
659 struct bcm43xx_dmaring *ring = NULL;
660
661 switch (cookie & 0xF000) {
662 case 0x0000:
663 ring = dma->tx_ring0;
664 break;
665 case 0x1000:
666 ring = dma->tx_ring1;
667 break;
668 case 0x2000:
669 ring = dma->tx_ring2;
670 break;
671 case 0x3000:
672 ring = dma->tx_ring3;
673 break;
674 default:
675 assert(0);
676 }
677 *slot = (cookie & 0x0FFF);
678 assert(*slot >= 0 && *slot < ring->nr_slots);
679
680 return ring;
681}
682
683static void dmacontroller_poke_tx(struct bcm43xx_dmaring *ring,
684 int slot)
685{
686 /* Everything is ready to start. Buffers are DMA mapped and
687 * associated with slots.
688 * "slot" is the last slot of the new frame we want to transmit.
689 * Close your seat belts now, please.
690 */
691 wmb();
692 slot = next_slot(ring, slot);
693 bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_INDEX,
694 (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
695}
696
697static int dma_tx_fragment(struct bcm43xx_dmaring *ring,
698 struct sk_buff *skb,
699 u8 cur_frag)
700{
701 int slot;
702 struct bcm43xx_dmadesc *desc;
703 struct bcm43xx_dmadesc_meta *meta;
704 u32 desc_ctl;
705 u32 desc_addr;
706
707 assert(skb_shinfo(skb)->nr_frags == 0);
708
709 slot = request_slot(ring);
710 desc = ring->vbase + slot;
711 meta = ring->meta + slot;
712
713 /* Add a device specific TX header. */
714 assert(skb_headroom(skb) >= sizeof(struct bcm43xx_txhdr));
715 /* Reserve enough headroom for the device tx header. */
716 __skb_push(skb, sizeof(struct bcm43xx_txhdr));
717 /* Now calculate and add the tx header.
718 * The tx header includes the PLCP header.
719 */
720 bcm43xx_generate_txhdr(ring->bcm,
721 (struct bcm43xx_txhdr *)skb->data,
722 skb->data + sizeof(struct bcm43xx_txhdr),
723 skb->len - sizeof(struct bcm43xx_txhdr),
724 (cur_frag == 0),
725 generate_cookie(ring, slot));
726
727 meta->skb = skb;
728 meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
729 if (unlikely(meta->dmaaddr + skb->len > BCM43xx_DMA_BUSADDRMAX)) {
730 return_slot(ring, slot);
731 printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA TX SKB >1G "
732 "(0x%08x, len: %u)\n",
733 meta->dmaaddr, skb->len);
734 return -ENOMEM;
735 }
736
737 desc_addr = (u32)(meta->dmaaddr + ring->memoffset);
738 desc_ctl = BCM43xx_DMADTOR_FRAMESTART | BCM43xx_DMADTOR_FRAMEEND;
739 desc_ctl |= BCM43xx_DMADTOR_COMPIRQ;
740 desc_ctl |= (BCM43xx_DMADTOR_BYTECNT_MASK &
741 (u32)(meta->skb->len - ring->frameoffset));
742 if (slot == ring->nr_slots - 1)
743 desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
744
745 set_desc_ctl(desc, desc_ctl);
746 set_desc_addr(desc, desc_addr);
747 /* Now transfer the whole frame. */
748 dmacontroller_poke_tx(ring, slot);
749
750 return 0;
751}
752
753int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
754 struct ieee80211_txb *txb)
755{
756 /* We just received a packet from the kernel network subsystem.
757 * Add headers and DMA map the memory. Poke
758 * the device to send the stuff.
759 * Note that this is called from atomic context.
760 */
761 struct bcm43xx_dmaring *ring = bcm43xx_current_dma(bcm)->tx_ring1;
762 u8 i;
763 struct sk_buff *skb;
764
765 assert(ring->tx);
766 if (unlikely(free_slots(ring) < txb->nr_frags)) {
767 /* The queue should be stopped,
768 * if we are low on free slots.
769 * If this ever triggers, we have to lower the suspend_mark.
770 */
771 dprintkl(KERN_ERR PFX "Out of DMA descriptor slots!\n");
772 return -ENOMEM;
773 }
774
775 for (i = 0; i < txb->nr_frags; i++) {
776 skb = txb->fragments[i];
777 /* Take skb from ieee80211_txb_free */
778 txb->fragments[i] = NULL;
779 dma_tx_fragment(ring, skb, i);
780 //TODO: handle failure of dma_tx_fragment
781 }
782 ieee80211_txb_free(txb);
783
784 return 0;
785}
786
787void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
788 struct bcm43xx_xmitstatus *status)
789{
790 struct bcm43xx_dmaring *ring;
791 struct bcm43xx_dmadesc *desc;
792 struct bcm43xx_dmadesc_meta *meta;
793 int is_last_fragment;
794 int slot;
795
796 ring = parse_cookie(bcm, status->cookie, &slot);
797 assert(ring);
798 assert(ring->tx);
799 assert(get_desc_ctl(ring->vbase + slot) & BCM43xx_DMADTOR_FRAMESTART);
800 while (1) {
801 assert(slot >= 0 && slot < ring->nr_slots);
802 desc = ring->vbase + slot;
803 meta = ring->meta + slot;
804
805 is_last_fragment = !!(get_desc_ctl(desc) & BCM43xx_DMADTOR_FRAMEEND);
806 unmap_descbuffer(ring, meta->dmaaddr, meta->skb->len, 1);
807 free_descriptor_buffer(ring, desc, meta, 1);
808 /* Everything belonging to the slot is unmapped
809 * and freed, so we can return it.
810 */
811 return_slot(ring, slot);
812
813 if (is_last_fragment)
814 break;
815 slot = next_slot(ring, slot);
816 }
817 bcm->stats.last_tx = jiffies;
818}
819
820static void dma_rx(struct bcm43xx_dmaring *ring,
821 int *slot)
822{
823 struct bcm43xx_dmadesc *desc;
824 struct bcm43xx_dmadesc_meta *meta;
825 struct bcm43xx_rxhdr *rxhdr;
826 struct sk_buff *skb;
827 u16 len;
828 int err;
829 dma_addr_t dmaaddr;
830
831 desc = ring->vbase + *slot;
832 meta = ring->meta + *slot;
833
834 sync_descbuffer_for_cpu(ring, meta->dmaaddr, ring->rx_buffersize);
835 skb = meta->skb;
836
837 if (ring->mmio_base == BCM43xx_MMIO_DMA4_BASE) {
838 /* We received an xmit status. */
839 struct bcm43xx_hwxmitstatus *hw = (struct bcm43xx_hwxmitstatus *)skb->data;
840 struct bcm43xx_xmitstatus stat;
841
842 stat.cookie = le16_to_cpu(hw->cookie);
843 stat.flags = hw->flags;
844 stat.cnt1 = hw->cnt1;
845 stat.cnt2 = hw->cnt2;
846 stat.seq = le16_to_cpu(hw->seq);
847 stat.unknown = le16_to_cpu(hw->unknown);
848
849 bcm43xx_debugfs_log_txstat(ring->bcm, &stat);
850 bcm43xx_dma_handle_xmitstatus(ring->bcm, &stat);
851 /* recycle the descriptor buffer. */
852 sync_descbuffer_for_device(ring, meta->dmaaddr, ring->rx_buffersize);
853
854 return;
855 }
856 rxhdr = (struct bcm43xx_rxhdr *)skb->data;
857 len = le16_to_cpu(rxhdr->frame_length);
858 if (len == 0) {
859 int i = 0;
860
861 do {
862 udelay(2);
863 barrier();
864 len = le16_to_cpu(rxhdr->frame_length);
865 } while (len == 0 && i++ < 5);
866 if (unlikely(len == 0)) {
867 /* recycle the descriptor buffer. */
868 sync_descbuffer_for_device(ring, meta->dmaaddr,
869 ring->rx_buffersize);
870 goto drop;
871 }
872 }
873 if (unlikely(len > ring->rx_buffersize)) {
874 /* The data did not fit into one descriptor buffer
875 * and is split over multiple buffers.
876 * This should never happen, as we try to allocate buffers
877 * big enough. So simply ignore this packet.
878 */
879 int cnt = 0;
880 s32 tmp = len;
881
882 while (1) {
883 desc = ring->vbase + *slot;
884 meta = ring->meta + *slot;
885 /* recycle the descriptor buffer. */
886 sync_descbuffer_for_device(ring, meta->dmaaddr,
887 ring->rx_buffersize);
888 *slot = next_slot(ring, *slot);
889 cnt++;
890 tmp -= ring->rx_buffersize;
891 if (tmp <= 0)
892 break;
893 }
894 printkl(KERN_ERR PFX "DMA RX buffer too small "
895 "(len: %u, buffer: %u, nr-dropped: %d)\n",
896 len, ring->rx_buffersize, cnt);
897 goto drop;
898 }
899 len -= IEEE80211_FCS_LEN;
900
901 dmaaddr = meta->dmaaddr;
902 err = setup_rx_descbuffer(ring, desc, meta, GFP_ATOMIC);
903 if (unlikely(err)) {
904 dprintkl(KERN_ERR PFX "DMA RX: setup_rx_descbuffer() failed\n");
905 sync_descbuffer_for_device(ring, dmaaddr,
906 ring->rx_buffersize);
907 goto drop;
908 }
909
910 unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
911 skb_put(skb, len + ring->frameoffset);
912 skb_pull(skb, ring->frameoffset);
913
914 err = bcm43xx_rx(ring->bcm, skb, rxhdr);
915 if (err) {
916 dev_kfree_skb_irq(skb);
917 goto drop;
918 }
919
920drop:
921 return;
922}
923
924void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
925{
926 u32 status;
927 u16 descptr;
928 int slot, current_slot;
929#ifdef CONFIG_BCM43XX_DEBUG
930 int used_slots = 0;
931#endif
932
933 assert(!ring->tx);
934 status = bcm43xx_dma_read(ring, BCM43xx_DMA_RX_STATUS);
935 descptr = (status & BCM43xx_DMA_RXSTAT_DPTR_MASK);
936 current_slot = descptr / sizeof(struct bcm43xx_dmadesc);
937 assert(current_slot >= 0 && current_slot < ring->nr_slots);
938
939 slot = ring->current_slot;
940 for ( ; slot != current_slot; slot = next_slot(ring, slot)) {
941 dma_rx(ring, &slot);
942#ifdef CONFIG_BCM43XX_DEBUG
943 if (++used_slots > ring->max_used_slots)
944 ring->max_used_slots = used_slots;
945#endif
946 }
947 bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX,
948 (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
949 ring->current_slot = slot;
950}
951
952void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring)
953{
954 assert(ring->tx);
955 bcm43xx_power_saving_ctl_bits(ring->bcm, -1, 1);
956 bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
957 bcm43xx_dma_read(ring, BCM43xx_DMA_TX_CONTROL)
958 | BCM43xx_DMA_TXCTRL_SUSPEND);
959}
960
961void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring)
962{
963 assert(ring->tx);
964 bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
965 bcm43xx_dma_read(ring, BCM43xx_DMA_TX_CONTROL)
966 & ~BCM43xx_DMA_TXCTRL_SUSPEND);
967 bcm43xx_power_saving_ctl_bits(ring->bcm, -1, -1);
968}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_dma.h b/drivers/net/wireless/bcm43xx/bcm43xx_dma.h
new file mode 100644
index 000000000000..2d520e4b0276
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_dma.h
@@ -0,0 +1,218 @@
1#ifndef BCM43xx_DMA_H_
2#define BCM43xx_DMA_H_
3
4#include <linux/list.h>
5#include <linux/spinlock.h>
6#include <linux/workqueue.h>
7#include <linux/linkage.h>
8#include <asm/atomic.h>
9
10
11/* DMA-Interrupt reasons. */
12#define BCM43xx_DMAIRQ_FATALMASK ((1 << 10) | (1 << 11) | (1 << 12) \
13 | (1 << 14) | (1 << 15))
14#define BCM43xx_DMAIRQ_NONFATALMASK (1 << 13)
15#define BCM43xx_DMAIRQ_RX_DONE (1 << 16)
16
17/* DMA controller register offsets. (relative to BCM43xx_DMA#_BASE) */
18#define BCM43xx_DMA_TX_CONTROL 0x00
19#define BCM43xx_DMA_TX_DESC_RING 0x04
20#define BCM43xx_DMA_TX_DESC_INDEX 0x08
21#define BCM43xx_DMA_TX_STATUS 0x0c
22#define BCM43xx_DMA_RX_CONTROL 0x10
23#define BCM43xx_DMA_RX_DESC_RING 0x14
24#define BCM43xx_DMA_RX_DESC_INDEX 0x18
25#define BCM43xx_DMA_RX_STATUS 0x1c
26
27/* DMA controller channel control word values. */
28#define BCM43xx_DMA_TXCTRL_ENABLE (1 << 0)
29#define BCM43xx_DMA_TXCTRL_SUSPEND (1 << 1)
30#define BCM43xx_DMA_TXCTRL_LOOPBACK (1 << 2)
31#define BCM43xx_DMA_TXCTRL_FLUSH (1 << 4)
32#define BCM43xx_DMA_RXCTRL_ENABLE (1 << 0)
33#define BCM43xx_DMA_RXCTRL_FRAMEOFF_MASK 0x000000fe
34#define BCM43xx_DMA_RXCTRL_FRAMEOFF_SHIFT 1
35#define BCM43xx_DMA_RXCTRL_PIO (1 << 8)
36/* DMA controller channel status word values. */
37#define BCM43xx_DMA_TXSTAT_DPTR_MASK 0x00000fff
38#define BCM43xx_DMA_TXSTAT_STAT_MASK 0x0000f000
39#define BCM43xx_DMA_TXSTAT_STAT_DISABLED 0x00000000
40#define BCM43xx_DMA_TXSTAT_STAT_ACTIVE 0x00001000
41#define BCM43xx_DMA_TXSTAT_STAT_IDLEWAIT 0x00002000
42#define BCM43xx_DMA_TXSTAT_STAT_STOPPED 0x00003000
43#define BCM43xx_DMA_TXSTAT_STAT_SUSP 0x00004000
44#define BCM43xx_DMA_TXSTAT_ERROR_MASK 0x000f0000
45#define BCM43xx_DMA_TXSTAT_FLUSHED (1 << 20)
46#define BCM43xx_DMA_RXSTAT_DPTR_MASK 0x00000fff
47#define BCM43xx_DMA_RXSTAT_STAT_MASK 0x0000f000
48#define BCM43xx_DMA_RXSTAT_STAT_DISABLED 0x00000000
49#define BCM43xx_DMA_RXSTAT_STAT_ACTIVE 0x00001000
50#define BCM43xx_DMA_RXSTAT_STAT_IDLEWAIT 0x00002000
51#define BCM43xx_DMA_RXSTAT_STAT_RESERVED 0x00003000
52#define BCM43xx_DMA_RXSTAT_STAT_ERRORS 0x00004000
53#define BCM43xx_DMA_RXSTAT_ERROR_MASK 0x000f0000
54
55/* DMA descriptor control field values. */
56#define BCM43xx_DMADTOR_BYTECNT_MASK 0x00001fff
57#define BCM43xx_DMADTOR_DTABLEEND (1 << 28) /* End of descriptor table */
58#define BCM43xx_DMADTOR_COMPIRQ (1 << 29) /* IRQ on completion request */
59#define BCM43xx_DMADTOR_FRAMEEND (1 << 30)
60#define BCM43xx_DMADTOR_FRAMESTART (1 << 31)
61
62/* Misc DMA constants */
63#define BCM43xx_DMA_RINGMEMSIZE PAGE_SIZE
64#define BCM43xx_DMA_BUSADDRMAX 0x3FFFFFFF
65#define BCM43xx_DMA_DMABUSADDROFFSET (1 << 30)
66#define BCM43xx_DMA1_RX_FRAMEOFFSET 30
67#define BCM43xx_DMA4_RX_FRAMEOFFSET 0
68
69/* DMA engine tuning knobs */
70#define BCM43xx_TXRING_SLOTS 512
71#define BCM43xx_RXRING_SLOTS 64
72#define BCM43xx_DMA1_RXBUFFERSIZE (2304 + 100)
73#define BCM43xx_DMA4_RXBUFFERSIZE 16
74/* Suspend the tx queue, if less than this percent slots are free. */
75#define BCM43xx_TXSUSPEND_PERCENT 20
76/* Resume the tx queue, if more than this percent slots are free. */
77#define BCM43xx_TXRESUME_PERCENT 50
78
79
80
81#ifdef CONFIG_BCM43XX_DMA
82
83
84struct sk_buff;
85struct bcm43xx_private;
86struct bcm43xx_xmitstatus;
87
88
89struct bcm43xx_dmadesc {
90 __le32 _control;
91 __le32 _address;
92} __attribute__((__packed__));
93
94/* Macros to access the bcm43xx_dmadesc struct */
95#define get_desc_ctl(desc) le32_to_cpu((desc)->_control)
96#define set_desc_ctl(desc, ctl) do { (desc)->_control = cpu_to_le32(ctl); } while (0)
97#define get_desc_addr(desc) le32_to_cpu((desc)->_address)
98#define set_desc_addr(desc, addr) do { (desc)->_address = cpu_to_le32(addr); } while (0)
99
100struct bcm43xx_dmadesc_meta {
101 /* The kernel DMA-able buffer. */
102 struct sk_buff *skb;
103 /* DMA base bus-address of the descriptor buffer. */
104 dma_addr_t dmaaddr;
105};
106
107struct bcm43xx_dmaring {
108 struct bcm43xx_private *bcm;
109 /* Kernel virtual base address of the ring memory. */
110 struct bcm43xx_dmadesc *vbase;
111 /* DMA memory offset */
112 dma_addr_t memoffset;
113 /* (Unadjusted) DMA base bus-address of the ring memory. */
114 dma_addr_t dmabase;
115 /* Meta data about all descriptors. */
116 struct bcm43xx_dmadesc_meta *meta;
117 /* Number of descriptor slots in the ring. */
118 int nr_slots;
119 /* Number of used descriptor slots. */
120 int used_slots;
121 /* Currently used slot in the ring. */
122 int current_slot;
123 /* Marks to suspend/resume the queue. */
124 int suspend_mark;
125 int resume_mark;
126 /* Frameoffset in octets. */
127 u32 frameoffset;
128 /* Descriptor buffer size. */
129 u16 rx_buffersize;
130 /* The MMIO base register of the DMA controller, this
131 * ring is posted to.
132 */
133 u16 mmio_base;
134 u8 tx:1, /* TRUE, if this is a TX ring. */
135 suspended:1; /* TRUE, if transfers are suspended on this ring. */
136#ifdef CONFIG_BCM43XX_DEBUG
137 /* Maximum number of used slots. */
138 int max_used_slots;
139#endif /* CONFIG_BCM43XX_DEBUG*/
140};
141
142
143static inline
144u32 bcm43xx_dma_read(struct bcm43xx_dmaring *ring,
145 u16 offset)
146{
147 return bcm43xx_read32(ring->bcm, ring->mmio_base + offset);
148}
149
150static inline
151void bcm43xx_dma_write(struct bcm43xx_dmaring *ring,
152 u16 offset, u32 value)
153{
154 bcm43xx_write32(ring->bcm, ring->mmio_base + offset, value);
155}
156
157
158int bcm43xx_dma_init(struct bcm43xx_private *bcm);
159void bcm43xx_dma_free(struct bcm43xx_private *bcm);
160
161int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
162 u16 dmacontroller_mmio_base);
163int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
164 u16 dmacontroller_mmio_base);
165
166void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring);
167void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring);
168
169void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
170 struct bcm43xx_xmitstatus *status);
171
172int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
173 struct ieee80211_txb *txb);
174void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring);
175
176
177#else /* CONFIG_BCM43XX_DMA */
178
179
180static inline
181int bcm43xx_dma_init(struct bcm43xx_private *bcm)
182{
183 return 0;
184}
185static inline
186void bcm43xx_dma_free(struct bcm43xx_private *bcm)
187{
188}
189static inline
190int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
191 u16 dmacontroller_mmio_base)
192{
193 return 0;
194}
195static inline
196int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
197 u16 dmacontroller_mmio_base)
198{
199 return 0;
200}
201static inline
202int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
203 struct ieee80211_txb *txb)
204{
205 return 0;
206}
207static inline
208void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
209 struct bcm43xx_xmitstatus *status)
210{
211}
212static inline
213void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
214{
215}
216
217#endif /* CONFIG_BCM43XX_DMA */
218#endif /* BCM43xx_DMA_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c b/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c
new file mode 100644
index 000000000000..b3ffcf501311
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.c
@@ -0,0 +1,50 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 ethtool support
6
7 Copyright (c) 2006 Jason Lunz <lunz@falooley.org>
8
9 Some code in this file is derived from the 8139too.c driver
10 Copyright (C) 2002 Jeff Garzik
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; see the file COPYING. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
25 Boston, MA 02110-1301, USA.
26
27*/
28
29#include "bcm43xx.h"
30#include "bcm43xx_ethtool.h"
31
32#include <linux/netdevice.h>
33#include <linux/pci.h>
34#include <linux/string.h>
35#include <linux/version.h>
36
37
38static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
39{
40 struct bcm43xx_private *bcm = bcm43xx_priv(dev);
41
42 strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
43 strncpy(info->version, UTS_RELEASE, sizeof(info->version));
44 strncpy(info->bus_info, pci_name(bcm->pci_dev), ETHTOOL_BUSINFO_LEN);
45}
46
47struct ethtool_ops bcm43xx_ethtool_ops = {
48 .get_drvinfo = bcm43xx_get_drvinfo,
49 .get_link = ethtool_op_get_link,
50};
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.h b/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.h
new file mode 100644
index 000000000000..813704991f62
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ethtool.h
@@ -0,0 +1,8 @@
1#ifndef BCM43xx_ETHTOOL_H_
2#define BCM43xx_ETHTOOL_H_
3
4#include <linux/ethtool.h>
5
6extern struct ethtool_ops bcm43xx_ethtool_ops;
7
8#endif /* BCM43xx_ETHTOOL_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c
new file mode 100644
index 000000000000..ad8e569d1faf
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.c
@@ -0,0 +1,337 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; see the file COPYING. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
24 Boston, MA 02110-1301, USA.
25
26*/
27
28#include "bcm43xx.h"
29#include "bcm43xx_ilt.h"
30#include "bcm43xx_phy.h"
31
32
33/**** Initial Internal Lookup Tables ****/
34
35const u32 bcm43xx_ilt_rotor[BCM43xx_ILT_ROTOR_SIZE] = {
36 0xFEB93FFD, 0xFEC63FFD, /* 0 */
37 0xFED23FFD, 0xFEDF3FFD,
38 0xFEEC3FFE, 0xFEF83FFE,
39 0xFF053FFE, 0xFF113FFE,
40 0xFF1E3FFE, 0xFF2A3FFF, /* 8 */
41 0xFF373FFF, 0xFF443FFF,
42 0xFF503FFF, 0xFF5D3FFF,
43 0xFF693FFF, 0xFF763FFF,
44 0xFF824000, 0xFF8F4000, /* 16 */
45 0xFF9B4000, 0xFFA84000,
46 0xFFB54000, 0xFFC14000,
47 0xFFCE4000, 0xFFDA4000,
48 0xFFE74000, 0xFFF34000, /* 24 */
49 0x00004000, 0x000D4000,
50 0x00194000, 0x00264000,
51 0x00324000, 0x003F4000,
52 0x004B4000, 0x00584000, /* 32 */
53 0x00654000, 0x00714000,
54 0x007E4000, 0x008A3FFF,
55 0x00973FFF, 0x00A33FFF,
56 0x00B03FFF, 0x00BC3FFF, /* 40 */
57 0x00C93FFF, 0x00D63FFF,
58 0x00E23FFE, 0x00EF3FFE,
59 0x00FB3FFE, 0x01083FFE,
60 0x01143FFE, 0x01213FFD, /* 48 */
61 0x012E3FFD, 0x013A3FFD,
62 0x01473FFD,
63};
64
65const u32 bcm43xx_ilt_retard[BCM43xx_ILT_RETARD_SIZE] = {
66 0xDB93CB87, 0xD666CF64, /* 0 */
67 0xD1FDD358, 0xCDA6D826,
68 0xCA38DD9F, 0xC729E2B4,
69 0xC469E88E, 0xC26AEE2B,
70 0xC0DEF46C, 0xC073FA62, /* 8 */
71 0xC01D00D5, 0xC0760743,
72 0xC1560D1E, 0xC2E51369,
73 0xC4ED18FF, 0xC7AC1ED7,
74 0xCB2823B2, 0xCEFA28D9, /* 16 */
75 0xD2F62D3F, 0xD7BB3197,
76 0xDCE53568, 0xE1FE3875,
77 0xE7D13B35, 0xED663D35,
78 0xF39B3EC4, 0xF98E3FA7, /* 24 */
79 0x00004000, 0x06723FA7,
80 0x0C653EC4, 0x129A3D35,
81 0x182F3B35, 0x1E023875,
82 0x231B3568, 0x28453197, /* 32 */
83 0x2D0A2D3F, 0x310628D9,
84 0x34D823B2, 0x38541ED7,
85 0x3B1318FF, 0x3D1B1369,
86 0x3EAA0D1E, 0x3F8A0743, /* 40 */
87 0x3FE300D5, 0x3F8DFA62,
88 0x3F22F46C, 0x3D96EE2B,
89 0x3B97E88E, 0x38D7E2B4,
90 0x35C8DD9F, 0x325AD826, /* 48 */
91 0x2E03D358, 0x299ACF64,
92 0x246DCB87,
93};
94
95const u16 bcm43xx_ilt_finefreqa[BCM43xx_ILT_FINEFREQA_SIZE] = {
96 0x0082, 0x0082, 0x0102, 0x0182, /* 0 */
97 0x0202, 0x0282, 0x0302, 0x0382,
98 0x0402, 0x0482, 0x0502, 0x0582,
99 0x05E2, 0x0662, 0x06E2, 0x0762,
100 0x07E2, 0x0842, 0x08C2, 0x0942, /* 16 */
101 0x09C2, 0x0A22, 0x0AA2, 0x0B02,
102 0x0B82, 0x0BE2, 0x0C62, 0x0CC2,
103 0x0D42, 0x0DA2, 0x0E02, 0x0E62,
104 0x0EE2, 0x0F42, 0x0FA2, 0x1002, /* 32 */
105 0x1062, 0x10C2, 0x1122, 0x1182,
106 0x11E2, 0x1242, 0x12A2, 0x12E2,
107 0x1342, 0x13A2, 0x1402, 0x1442,
108 0x14A2, 0x14E2, 0x1542, 0x1582, /* 48 */
109 0x15E2, 0x1622, 0x1662, 0x16C1,
110 0x1701, 0x1741, 0x1781, 0x17E1,
111 0x1821, 0x1861, 0x18A1, 0x18E1,
112 0x1921, 0x1961, 0x19A1, 0x19E1, /* 64 */
113 0x1A21, 0x1A61, 0x1AA1, 0x1AC1,
114 0x1B01, 0x1B41, 0x1B81, 0x1BA1,
115 0x1BE1, 0x1C21, 0x1C41, 0x1C81,
116 0x1CA1, 0x1CE1, 0x1D01, 0x1D41, /* 80 */
117 0x1D61, 0x1DA1, 0x1DC1, 0x1E01,
118 0x1E21, 0x1E61, 0x1E81, 0x1EA1,
119 0x1EE1, 0x1F01, 0x1F21, 0x1F41,
120 0x1F81, 0x1FA1, 0x1FC1, 0x1FE1, /* 96 */
121 0x2001, 0x2041, 0x2061, 0x2081,
122 0x20A1, 0x20C1, 0x20E1, 0x2101,
123 0x2121, 0x2141, 0x2161, 0x2181,
124 0x21A1, 0x21C1, 0x21E1, 0x2201, /* 112 */
125 0x2221, 0x2241, 0x2261, 0x2281,
126 0x22A1, 0x22C1, 0x22C1, 0x22E1,
127 0x2301, 0x2321, 0x2341, 0x2361,
128 0x2361, 0x2381, 0x23A1, 0x23C1, /* 128 */
129 0x23E1, 0x23E1, 0x2401, 0x2421,
130 0x2441, 0x2441, 0x2461, 0x2481,
131 0x2481, 0x24A1, 0x24C1, 0x24C1,
132 0x24E1, 0x2501, 0x2501, 0x2521, /* 144 */
133 0x2541, 0x2541, 0x2561, 0x2561,
134 0x2581, 0x25A1, 0x25A1, 0x25C1,
135 0x25C1, 0x25E1, 0x2601, 0x2601,
136 0x2621, 0x2621, 0x2641, 0x2641, /* 160 */
137 0x2661, 0x2661, 0x2681, 0x2681,
138 0x26A1, 0x26A1, 0x26C1, 0x26C1,
139 0x26E1, 0x26E1, 0x2701, 0x2701,
140 0x2721, 0x2721, 0x2740, 0x2740, /* 176 */
141 0x2760, 0x2760, 0x2780, 0x2780,
142 0x2780, 0x27A0, 0x27A0, 0x27C0,
143 0x27C0, 0x27E0, 0x27E0, 0x27E0,
144 0x2800, 0x2800, 0x2820, 0x2820, /* 192 */
145 0x2820, 0x2840, 0x2840, 0x2840,
146 0x2860, 0x2860, 0x2880, 0x2880,
147 0x2880, 0x28A0, 0x28A0, 0x28A0,
148 0x28C0, 0x28C0, 0x28C0, 0x28E0, /* 208 */
149 0x28E0, 0x28E0, 0x2900, 0x2900,
150 0x2900, 0x2920, 0x2920, 0x2920,
151 0x2940, 0x2940, 0x2940, 0x2960,
152 0x2960, 0x2960, 0x2960, 0x2980, /* 224 */
153 0x2980, 0x2980, 0x29A0, 0x29A0,
154 0x29A0, 0x29A0, 0x29C0, 0x29C0,
155 0x29C0, 0x29E0, 0x29E0, 0x29E0,
156 0x29E0, 0x2A00, 0x2A00, 0x2A00, /* 240 */
157 0x2A00, 0x2A20, 0x2A20, 0x2A20,
158 0x2A20, 0x2A40, 0x2A40, 0x2A40,
159 0x2A40, 0x2A60, 0x2A60, 0x2A60,
160};
161
162const u16 bcm43xx_ilt_finefreqg[BCM43xx_ILT_FINEFREQG_SIZE] = {
163 0x0089, 0x02E9, 0x0409, 0x04E9, /* 0 */
164 0x05A9, 0x0669, 0x0709, 0x0789,
165 0x0829, 0x08A9, 0x0929, 0x0989,
166 0x0A09, 0x0A69, 0x0AC9, 0x0B29,
167 0x0BA9, 0x0BE9, 0x0C49, 0x0CA9, /* 16 */
168 0x0D09, 0x0D69, 0x0DA9, 0x0E09,
169 0x0E69, 0x0EA9, 0x0F09, 0x0F49,
170 0x0FA9, 0x0FE9, 0x1029, 0x1089,
171 0x10C9, 0x1109, 0x1169, 0x11A9, /* 32 */
172 0x11E9, 0x1229, 0x1289, 0x12C9,
173 0x1309, 0x1349, 0x1389, 0x13C9,
174 0x1409, 0x1449, 0x14A9, 0x14E9,
175 0x1529, 0x1569, 0x15A9, 0x15E9, /* 48 */
176 0x1629, 0x1669, 0x16A9, 0x16E8,
177 0x1728, 0x1768, 0x17A8, 0x17E8,
178 0x1828, 0x1868, 0x18A8, 0x18E8,
179 0x1928, 0x1968, 0x19A8, 0x19E8, /* 64 */
180 0x1A28, 0x1A68, 0x1AA8, 0x1AE8,
181 0x1B28, 0x1B68, 0x1BA8, 0x1BE8,
182 0x1C28, 0x1C68, 0x1CA8, 0x1CE8,
183 0x1D28, 0x1D68, 0x1DC8, 0x1E08, /* 80 */
184 0x1E48, 0x1E88, 0x1EC8, 0x1F08,
185 0x1F48, 0x1F88, 0x1FE8, 0x2028,
186 0x2068, 0x20A8, 0x2108, 0x2148,
187 0x2188, 0x21C8, 0x2228, 0x2268, /* 96 */
188 0x22C8, 0x2308, 0x2348, 0x23A8,
189 0x23E8, 0x2448, 0x24A8, 0x24E8,
190 0x2548, 0x25A8, 0x2608, 0x2668,
191 0x26C8, 0x2728, 0x2787, 0x27E7, /* 112 */
192 0x2847, 0x28C7, 0x2947, 0x29A7,
193 0x2A27, 0x2AC7, 0x2B47, 0x2BE7,
194 0x2CA7, 0x2D67, 0x2E47, 0x2F67,
195 0x3247, 0x3526, 0x3646, 0x3726, /* 128 */
196 0x3806, 0x38A6, 0x3946, 0x39E6,
197 0x3A66, 0x3AE6, 0x3B66, 0x3BC6,
198 0x3C45, 0x3CA5, 0x3D05, 0x3D85,
199 0x3DE5, 0x3E45, 0x3EA5, 0x3EE5, /* 144 */
200 0x3F45, 0x3FA5, 0x4005, 0x4045,
201 0x40A5, 0x40E5, 0x4145, 0x4185,
202 0x41E5, 0x4225, 0x4265, 0x42C5,
203 0x4305, 0x4345, 0x43A5, 0x43E5, /* 160 */
204 0x4424, 0x4464, 0x44C4, 0x4504,
205 0x4544, 0x4584, 0x45C4, 0x4604,
206 0x4644, 0x46A4, 0x46E4, 0x4724,
207 0x4764, 0x47A4, 0x47E4, 0x4824, /* 176 */
208 0x4864, 0x48A4, 0x48E4, 0x4924,
209 0x4964, 0x49A4, 0x49E4, 0x4A24,
210 0x4A64, 0x4AA4, 0x4AE4, 0x4B23,
211 0x4B63, 0x4BA3, 0x4BE3, 0x4C23, /* 192 */
212 0x4C63, 0x4CA3, 0x4CE3, 0x4D23,
213 0x4D63, 0x4DA3, 0x4DE3, 0x4E23,
214 0x4E63, 0x4EA3, 0x4EE3, 0x4F23,
215 0x4F63, 0x4FC3, 0x5003, 0x5043, /* 208 */
216 0x5083, 0x50C3, 0x5103, 0x5143,
217 0x5183, 0x51E2, 0x5222, 0x5262,
218 0x52A2, 0x52E2, 0x5342, 0x5382,
219 0x53C2, 0x5402, 0x5462, 0x54A2, /* 224 */
220 0x5502, 0x5542, 0x55A2, 0x55E2,
221 0x5642, 0x5682, 0x56E2, 0x5722,
222 0x5782, 0x57E1, 0x5841, 0x58A1,
223 0x5901, 0x5961, 0x59C1, 0x5A21, /* 240 */
224 0x5AA1, 0x5B01, 0x5B81, 0x5BE1,
225 0x5C61, 0x5D01, 0x5D80, 0x5E20,
226 0x5EE0, 0x5FA0, 0x6080, 0x61C0,
227};
228
229const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE] = {
230 0x0001, 0x0001, 0x0001, 0xFFFE,
231 0xFFFE, 0x3FFF, 0x1000, 0x0393,
232};
233
234const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE] = {
235 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
236 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
237};
238
239const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE] = {
240 0x013C, 0x01F5, 0x031A, 0x0631,
241 0x0001, 0x0001, 0x0001, 0x0001,
242};
243
244const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE] = {
245 0x5484, 0x3C40, 0x0000, 0x0000,
246 0x0000, 0x0000, 0x0000, 0x0000,
247};
248
249const u16 bcm43xx_ilt_noisescaleg1[BCM43xx_ILT_NOISESCALEG_SIZE] = {
250 0x6C77, 0x5162, 0x3B40, 0x3335, /* 0 */
251 0x2F2D, 0x2A2A, 0x2527, 0x1F21,
252 0x1A1D, 0x1719, 0x1616, 0x1414,
253 0x1414, 0x1400, 0x1414, 0x1614,
254 0x1716, 0x1A19, 0x1F1D, 0x2521, /* 16 */
255 0x2A27, 0x2F2A, 0x332D, 0x3B35,
256 0x5140, 0x6C62, 0x0077,
257};
258
259const u16 bcm43xx_ilt_noisescaleg2[BCM43xx_ILT_NOISESCALEG_SIZE] = {
260 0xD8DD, 0xCBD4, 0xBCC0, 0XB6B7, /* 0 */
261 0xB2B0, 0xADAD, 0xA7A9, 0x9FA1,
262 0x969B, 0x9195, 0x8F8F, 0x8A8A,
263 0x8A8A, 0x8A00, 0x8A8A, 0x8F8A,
264 0x918F, 0x9695, 0x9F9B, 0xA7A1, /* 16 */
265 0xADA9, 0xB2AD, 0xB6B0, 0xBCB7,
266 0xCBC0, 0xD8D4, 0x00DD,
267};
268
269const u16 bcm43xx_ilt_noisescaleg3[BCM43xx_ILT_NOISESCALEG_SIZE] = {
270 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 0 */
271 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
272 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
273 0xA4A4, 0xA400, 0xA4A4, 0xA4A4,
274 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 16 */
275 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
276 0xA4A4, 0xA4A4, 0x00A4,
277};
278
279const u16 bcm43xx_ilt_sigmasqr1[BCM43xx_ILT_SIGMASQR_SIZE] = {
280 0x007A, 0x0075, 0x0071, 0x006C, /* 0 */
281 0x0067, 0x0063, 0x005E, 0x0059,
282 0x0054, 0x0050, 0x004B, 0x0046,
283 0x0042, 0x003D, 0x003D, 0x003D,
284 0x003D, 0x003D, 0x003D, 0x003D, /* 16 */
285 0x003D, 0x003D, 0x003D, 0x003D,
286 0x003D, 0x003D, 0x0000, 0x003D,
287 0x003D, 0x003D, 0x003D, 0x003D,
288 0x003D, 0x003D, 0x003D, 0x003D, /* 32 */
289 0x003D, 0x003D, 0x003D, 0x003D,
290 0x0042, 0x0046, 0x004B, 0x0050,
291 0x0054, 0x0059, 0x005E, 0x0063,
292 0x0067, 0x006C, 0x0071, 0x0075, /* 48 */
293 0x007A,
294};
295
296const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE] = {
297 0x00DE, 0x00DC, 0x00DA, 0x00D8, /* 0 */
298 0x00D6, 0x00D4, 0x00D2, 0x00CF,
299 0x00CD, 0x00CA, 0x00C7, 0x00C4,
300 0x00C1, 0x00BE, 0x00BE, 0x00BE,
301 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 16 */
302 0x00BE, 0x00BE, 0x00BE, 0x00BE,
303 0x00BE, 0x00BE, 0x0000, 0x00BE,
304 0x00BE, 0x00BE, 0x00BE, 0x00BE,
305 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 32 */
306 0x00BE, 0x00BE, 0x00BE, 0x00BE,
307 0x00C1, 0x00C4, 0x00C7, 0x00CA,
308 0x00CD, 0x00CF, 0x00D2, 0x00D4,
309 0x00D6, 0x00D8, 0x00DA, 0x00DC, /* 48 */
310 0x00DE,
311};
312
313/**** Helper functions to access the device Internal Lookup Tables ****/
314
315void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
316{
317 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
318 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
319 mmiowb();
320 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, val);
321 } else {
322 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
323 mmiowb();
324 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA1, val);
325 }
326}
327
328u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset)
329{
330 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
331 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
332 return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_A_DATA1);
333 } else {
334 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
335 return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_G_DATA1);
336 }
337}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h
new file mode 100644
index 000000000000..464521abf73c
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_ilt.h
@@ -0,0 +1,32 @@
1#ifndef BCM43xx_ILT_H_
2#define BCM43xx_ILT_H_
3
4#define BCM43xx_ILT_ROTOR_SIZE 53
5extern const u32 bcm43xx_ilt_rotor[BCM43xx_ILT_ROTOR_SIZE];
6#define BCM43xx_ILT_RETARD_SIZE 53
7extern const u32 bcm43xx_ilt_retard[BCM43xx_ILT_RETARD_SIZE];
8#define BCM43xx_ILT_FINEFREQA_SIZE 256
9extern const u16 bcm43xx_ilt_finefreqa[BCM43xx_ILT_FINEFREQA_SIZE];
10#define BCM43xx_ILT_FINEFREQG_SIZE 256
11extern const u16 bcm43xx_ilt_finefreqg[BCM43xx_ILT_FINEFREQG_SIZE];
12#define BCM43xx_ILT_NOISEA2_SIZE 8
13extern const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE];
14#define BCM43xx_ILT_NOISEA3_SIZE 8
15extern const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE];
16#define BCM43xx_ILT_NOISEG1_SIZE 8
17extern const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE];
18#define BCM43xx_ILT_NOISEG2_SIZE 8
19extern const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE];
20#define BCM43xx_ILT_NOISESCALEG_SIZE 27
21extern const u16 bcm43xx_ilt_noisescaleg1[BCM43xx_ILT_NOISESCALEG_SIZE];
22extern const u16 bcm43xx_ilt_noisescaleg2[BCM43xx_ILT_NOISESCALEG_SIZE];
23extern const u16 bcm43xx_ilt_noisescaleg3[BCM43xx_ILT_NOISESCALEG_SIZE];
24#define BCM43xx_ILT_SIGMASQR_SIZE 53
25extern const u16 bcm43xx_ilt_sigmasqr1[BCM43xx_ILT_SIGMASQR_SIZE];
26extern const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE];
27
28
29void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
30u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset);
31
32#endif /* BCM43xx_ILT_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_leds.c b/drivers/net/wireless/bcm43xx/bcm43xx_leds.c
new file mode 100644
index 000000000000..4b2c02c0b31e
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_leds.c
@@ -0,0 +1,293 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; see the file COPYING. If not, write to
23 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
24 Boston, MA 02110-1301, USA.
25
26*/
27
28#include "bcm43xx_leds.h"
29#include "bcm43xx.h"
30
31#include <asm/bitops.h>
32
33
34static void bcm43xx_led_changestate(struct bcm43xx_led *led)
35{
36 struct bcm43xx_private *bcm = led->bcm;
37 const int index = bcm43xx_led_index(led);
38 const u16 mask = (1 << index);
39 u16 ledctl;
40
41 assert(index >= 0 && index < BCM43xx_NR_LEDS);
42 assert(led->blink_interval);
43 ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
44 ledctl = (ledctl & mask) ? (ledctl & ~mask) : (ledctl | mask);
45 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
46}
47
48static void bcm43xx_led_blink(unsigned long d)
49{
50 struct bcm43xx_led *led = (struct bcm43xx_led *)d;
51 struct bcm43xx_private *bcm = led->bcm;
52 unsigned long flags;
53
54 bcm43xx_lock_mmio(bcm, flags);
55 if (led->blink_interval) {
56 bcm43xx_led_changestate(led);
57 mod_timer(&led->blink_timer, jiffies + led->blink_interval);
58 }
59 bcm43xx_unlock_mmio(bcm, flags);
60}
61
62static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
63 unsigned long interval)
64{
65 if (led->blink_interval)
66 return;
67 led->blink_interval = interval;
68 bcm43xx_led_changestate(led);
69 led->blink_timer.expires = jiffies + interval;
70 add_timer(&led->blink_timer);
71}
72
73static void bcm43xx_led_blink_stop(struct bcm43xx_led *led, int sync)
74{
75 struct bcm43xx_private *bcm = led->bcm;
76 const int index = bcm43xx_led_index(led);
77 u16 ledctl;
78
79 if (!led->blink_interval)
80 return;
81 if (unlikely(sync))
82 del_timer_sync(&led->blink_timer);
83 else
84 del_timer(&led->blink_timer);
85 led->blink_interval = 0;
86
87 /* Make sure the LED is turned off. */
88 assert(index >= 0 && index < BCM43xx_NR_LEDS);
89 ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
90 if (led->activelow)
91 ledctl |= (1 << index);
92 else
93 ledctl &= ~(1 << index);
94 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
95}
96
97static void bcm43xx_led_init_hardcoded(struct bcm43xx_private *bcm,
98 struct bcm43xx_led *led,
99 int led_index)
100{
101 /* This function is called, if the behaviour (and activelow)
102 * information for a LED is missing in the SPROM.
103 * We hardcode the behaviour values for various devices here.
104 * Note that the BCM43xx_LED_TEST_XXX behaviour values can
105 * be used to figure out which led is mapped to which index.
106 */
107
108 switch (led_index) {
109 case 0:
110 led->behaviour = BCM43xx_LED_ACTIVITY;
111 if (bcm->board_vendor == PCI_VENDOR_ID_COMPAQ)
112 led->behaviour = BCM43xx_LED_RADIO_ALL;
113 break;
114 case 1:
115 led->behaviour = BCM43xx_LED_RADIO_B;
116 if (bcm->board_vendor == PCI_VENDOR_ID_ASUSTEK)
117 led->behaviour = BCM43xx_LED_ASSOC;
118 break;
119 case 2:
120 led->behaviour = BCM43xx_LED_RADIO_A;
121 break;
122 case 3:
123 led->behaviour = BCM43xx_LED_OFF;
124 break;
125 default:
126 assert(0);
127 }
128}
129
130int bcm43xx_leds_init(struct bcm43xx_private *bcm)
131{
132 struct bcm43xx_led *led;
133 u8 sprom[4];
134 int i;
135
136 sprom[0] = bcm->sprom.wl0gpio0;
137 sprom[1] = bcm->sprom.wl0gpio1;
138 sprom[2] = bcm->sprom.wl0gpio2;
139 sprom[3] = bcm->sprom.wl0gpio3;
140
141 for (i = 0; i < BCM43xx_NR_LEDS; i++) {
142 led = &(bcm->leds[i]);
143 led->bcm = bcm;
144 setup_timer(&led->blink_timer,
145 bcm43xx_led_blink,
146 (unsigned long)led);
147
148 if (sprom[i] == 0xFF) {
149 bcm43xx_led_init_hardcoded(bcm, led, i);
150 } else {
151 led->behaviour = sprom[i] & BCM43xx_LED_BEHAVIOUR;
152 led->activelow = !!(sprom[i] & BCM43xx_LED_ACTIVELOW);
153 }
154 }
155
156 return 0;
157}
158
159void bcm43xx_leds_exit(struct bcm43xx_private *bcm)
160{
161 struct bcm43xx_led *led;
162 int i;
163
164 for (i = 0; i < BCM43xx_NR_LEDS; i++) {
165 led = &(bcm->leds[i]);
166 bcm43xx_led_blink_stop(led, 1);
167 }
168 bcm43xx_leds_switch_all(bcm, 0);
169}
170
171void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
172{
173 struct bcm43xx_led *led;
174 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
175 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
176 const int transferring = (jiffies - bcm->stats.last_tx) < BCM43xx_LED_XFER_THRES;
177 int i, turn_on;
178 unsigned long interval = 0;
179 u16 ledctl;
180
181 ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
182 for (i = 0; i < BCM43xx_NR_LEDS; i++) {
183 led = &(bcm->leds[i]);
184
185 turn_on = 0;
186 switch (led->behaviour) {
187 case BCM43xx_LED_INACTIVE:
188 continue;
189 case BCM43xx_LED_OFF:
190 break;
191 case BCM43xx_LED_ON:
192 turn_on = 1;
193 break;
194 case BCM43xx_LED_ACTIVITY:
195 turn_on = activity;
196 break;
197 case BCM43xx_LED_RADIO_ALL:
198 turn_on = radio->enabled;
199 break;
200 case BCM43xx_LED_RADIO_A:
201 turn_on = (radio->enabled && phy->type == BCM43xx_PHYTYPE_A);
202 break;
203 case BCM43xx_LED_RADIO_B:
204 turn_on = (radio->enabled &&
205 (phy->type == BCM43xx_PHYTYPE_B ||
206 phy->type == BCM43xx_PHYTYPE_G));
207 break;
208 case BCM43xx_LED_MODE_BG:
209 if (phy->type == BCM43xx_PHYTYPE_G &&
210 1/*FIXME: using G rates.*/)
211 turn_on = 1;
212 break;
213 case BCM43xx_LED_TRANSFER:
214 if (transferring)
215 bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
216 else
217 bcm43xx_led_blink_stop(led, 0);
218 continue;
219 case BCM43xx_LED_APTRANSFER:
220 if (bcm->ieee->iw_mode == IW_MODE_MASTER) {
221 if (transferring) {
222 interval = BCM43xx_LEDBLINK_FAST;
223 turn_on = 1;
224 }
225 } else {
226 turn_on = 1;
227 if (0/*TODO: not assoc*/)
228 interval = BCM43xx_LEDBLINK_SLOW;
229 else if (transferring)
230 interval = BCM43xx_LEDBLINK_FAST;
231 else
232 turn_on = 0;
233 }
234 if (turn_on)
235 bcm43xx_led_blink_start(led, interval);
236 else
237 bcm43xx_led_blink_stop(led, 0);
238 continue;
239 case BCM43xx_LED_WEIRD:
240 //TODO
241 break;
242 case BCM43xx_LED_ASSOC:
243 if (bcm->softmac->associated)
244 turn_on = 1;
245 break;
246#ifdef CONFIG_BCM43XX_DEBUG
247 case BCM43xx_LED_TEST_BLINKSLOW:
248 bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_SLOW);
249 continue;
250 case BCM43xx_LED_TEST_BLINKMEDIUM:
251 bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
252 continue;
253 case BCM43xx_LED_TEST_BLINKFAST:
254 bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_FAST);
255 continue;
256#endif /* CONFIG_BCM43XX_DEBUG */
257 default:
258 assert(0);
259 };
260
261 if (led->activelow)
262 turn_on = !turn_on;
263 if (turn_on)
264 ledctl |= (1 << i);
265 else
266 ledctl &= ~(1 << i);
267 }
268 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
269}
270
271void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
272{
273 struct bcm43xx_led *led;
274 u16 ledctl;
275 int i;
276 int bit_on;
277
278 ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
279 for (i = 0; i < BCM43xx_NR_LEDS; i++) {
280 led = &(bcm->leds[i]);
281 if (led->behaviour == BCM43xx_LED_INACTIVE)
282 continue;
283 if (on)
284 bit_on = led->activelow ? 0 : 1;
285 else
286 bit_on = led->activelow ? 1 : 0;
287 if (bit_on)
288 ledctl |= (1 << i);
289 else
290 ledctl &= ~(1 << i);
291 }
292 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
293}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_leds.h b/drivers/net/wireless/bcm43xx/bcm43xx_leds.h
new file mode 100644
index 000000000000..d3716cf3aebc
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_leds.h
@@ -0,0 +1,56 @@
1#ifndef BCM43xx_LEDS_H_
2#define BCM43xx_LEDS_H_
3
4#include <linux/types.h>
5#include <linux/timer.h>
6
7
8struct bcm43xx_led {
9 u8 behaviour:7;
10 u8 activelow:1;
11
12 struct bcm43xx_private *bcm;
13 struct timer_list blink_timer;
14 unsigned long blink_interval;
15};
16#define bcm43xx_led_index(led) ((int)((led) - (led)->bcm->leds))
17
18/* Delay between state changes when blinking in jiffies */
19#define BCM43xx_LEDBLINK_SLOW (HZ / 1)
20#define BCM43xx_LEDBLINK_MEDIUM (HZ / 4)
21#define BCM43xx_LEDBLINK_FAST (HZ / 8)
22
23#define BCM43xx_LED_XFER_THRES (HZ / 100)
24
25#define BCM43xx_LED_BEHAVIOUR 0x7F
26#define BCM43xx_LED_ACTIVELOW 0x80
27enum { /* LED behaviour values */
28 BCM43xx_LED_OFF,
29 BCM43xx_LED_ON,
30 BCM43xx_LED_ACTIVITY,
31 BCM43xx_LED_RADIO_ALL,
32 BCM43xx_LED_RADIO_A,
33 BCM43xx_LED_RADIO_B,
34 BCM43xx_LED_MODE_BG,
35 BCM43xx_LED_TRANSFER,
36 BCM43xx_LED_APTRANSFER,
37 BCM43xx_LED_WEIRD,//FIXME
38 BCM43xx_LED_ASSOC,
39 BCM43xx_LED_INACTIVE,
40
41 /* Behaviour values for testing.
42 * With these values it is easier to figure out
43 * the real behaviour of leds, in case the SPROM
44 * is missing information.
45 */
46 BCM43xx_LED_TEST_BLINKSLOW,
47 BCM43xx_LED_TEST_BLINKMEDIUM,
48 BCM43xx_LED_TEST_BLINKFAST,
49};
50
51int bcm43xx_leds_init(struct bcm43xx_private *bcm);
52void bcm43xx_leds_exit(struct bcm43xx_private *bcm);
53void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity);
54void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on);
55
56#endif /* BCM43xx_LEDS_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
new file mode 100644
index 000000000000..c37371fc9e01
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -0,0 +1,3973 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#include <linux/delay.h>
32#include <linux/init.h>
33#include <linux/moduleparam.h>
34#include <linux/if_arp.h>
35#include <linux/etherdevice.h>
36#include <linux/version.h>
37#include <linux/firmware.h>
38#include <linux/wireless.h>
39#include <linux/workqueue.h>
40#include <linux/skbuff.h>
41#include <linux/dma-mapping.h>
42#include <net/iw_handler.h>
43
44#include "bcm43xx.h"
45#include "bcm43xx_main.h"
46#include "bcm43xx_debugfs.h"
47#include "bcm43xx_radio.h"
48#include "bcm43xx_phy.h"
49#include "bcm43xx_dma.h"
50#include "bcm43xx_pio.h"
51#include "bcm43xx_power.h"
52#include "bcm43xx_wx.h"
53#include "bcm43xx_ethtool.h"
54#include "bcm43xx_xmit.h"
55
56
57MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
58MODULE_AUTHOR("Martin Langer");
59MODULE_AUTHOR("Stefano Brivio");
60MODULE_AUTHOR("Michael Buesch");
61MODULE_LICENSE("GPL");
62
63#ifdef CONFIG_BCM947XX
64extern char *nvram_get(char *name);
65#endif
66
67#if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
68static int modparam_pio;
69module_param_named(pio, modparam_pio, int, 0444);
70MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
71#elif defined(CONFIG_BCM43XX_DMA)
72# define modparam_pio 0
73#elif defined(CONFIG_BCM43XX_PIO)
74# define modparam_pio 1
75#endif
76
77static int modparam_bad_frames_preempt;
78module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
79MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames Preemption");
80
81static int modparam_short_retry = BCM43xx_DEFAULT_SHORT_RETRY_LIMIT;
82module_param_named(short_retry, modparam_short_retry, int, 0444);
83MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
84
85static int modparam_long_retry = BCM43xx_DEFAULT_LONG_RETRY_LIMIT;
86module_param_named(long_retry, modparam_long_retry, int, 0444);
87MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
88
89static int modparam_locale = -1;
90module_param_named(locale, modparam_locale, int, 0444);
91MODULE_PARM_DESC(country, "Select LocaleCode 0-11 (For travelers)");
92
93static int modparam_noleds;
94module_param_named(noleds, modparam_noleds, int, 0444);
95MODULE_PARM_DESC(noleds, "Turn off all LED activity");
96
97#ifdef CONFIG_BCM43XX_DEBUG
98static char modparam_fwpostfix[64];
99module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
100MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging.");
101#else
102# define modparam_fwpostfix ""
103#endif /* CONFIG_BCM43XX_DEBUG*/
104
105
106/* If you want to debug with just a single device, enable this,
107 * where the string is the pci device ID (as given by the kernel's
108 * pci_name function) of the device to be used.
109 */
110//#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
111
112/* If you want to enable printing of each MMIO access, enable this. */
113//#define DEBUG_ENABLE_MMIO_PRINT
114
115/* If you want to enable printing of MMIO access within
116 * ucode/pcm upload, initvals write, enable this.
117 */
118//#define DEBUG_ENABLE_UCODE_MMIO_PRINT
119
120/* If you want to enable printing of PCI Config Space access, enable this */
121//#define DEBUG_ENABLE_PCILOG
122
123
124/* Detailed list maintained at:
125 * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
126 */
127 static struct pci_device_id bcm43xx_pci_tbl[] = {
128 /* Broadcom 4303 802.11b */
129 { PCI_VENDOR_ID_BROADCOM, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
130 /* Broadcom 4307 802.11b */
131 { PCI_VENDOR_ID_BROADCOM, 0x4307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
132 /* Broadcom 4318 802.11b/g */
133 { PCI_VENDOR_ID_BROADCOM, 0x4318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
134 /* Broadcom 4306 802.11b/g */
135 { PCI_VENDOR_ID_BROADCOM, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
136 /* Broadcom 4306 802.11a */
137// { PCI_VENDOR_ID_BROADCOM, 0x4321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
138 /* Broadcom 4309 802.11a/b/g */
139 { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
140 /* Broadcom 43XG 802.11b/g */
141 { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
142#ifdef CONFIG_BCM947XX
143 /* SB bus on BCM947xx */
144 { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
145#endif
146 { 0 },
147};
148MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
149
150static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
151{
152 u32 status;
153
154 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
155 if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
156 val = swab32(val);
157
158 bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
159 mmiowb();
160 bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
161}
162
163static inline
164void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
165 u16 routing, u16 offset)
166{
167 u32 control;
168
169 /* "offset" is the WORD offset. */
170
171 control = routing;
172 control <<= 16;
173 control |= offset;
174 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
175}
176
177u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
178 u16 routing, u16 offset)
179{
180 u32 ret;
181
182 if (routing == BCM43xx_SHM_SHARED) {
183 if (offset & 0x0003) {
184 /* Unaligned access */
185 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
186 ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
187 ret <<= 16;
188 bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
189 ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
190
191 return ret;
192 }
193 offset >>= 2;
194 }
195 bcm43xx_shm_control_word(bcm, routing, offset);
196 ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
197
198 return ret;
199}
200
201u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
202 u16 routing, u16 offset)
203{
204 u16 ret;
205
206 if (routing == BCM43xx_SHM_SHARED) {
207 if (offset & 0x0003) {
208 /* Unaligned access */
209 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
210 ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
211
212 return ret;
213 }
214 offset >>= 2;
215 }
216 bcm43xx_shm_control_word(bcm, routing, offset);
217 ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
218
219 return ret;
220}
221
222void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
223 u16 routing, u16 offset,
224 u32 value)
225{
226 if (routing == BCM43xx_SHM_SHARED) {
227 if (offset & 0x0003) {
228 /* Unaligned access */
229 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
230 mmiowb();
231 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
232 (value >> 16) & 0xffff);
233 mmiowb();
234 bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
235 mmiowb();
236 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
237 value & 0xffff);
238 return;
239 }
240 offset >>= 2;
241 }
242 bcm43xx_shm_control_word(bcm, routing, offset);
243 mmiowb();
244 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
245}
246
247void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
248 u16 routing, u16 offset,
249 u16 value)
250{
251 if (routing == BCM43xx_SHM_SHARED) {
252 if (offset & 0x0003) {
253 /* Unaligned access */
254 bcm43xx_shm_control_word(bcm, routing, offset >> 2);
255 mmiowb();
256 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
257 value);
258 return;
259 }
260 offset >>= 2;
261 }
262 bcm43xx_shm_control_word(bcm, routing, offset);
263 mmiowb();
264 bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
265}
266
267void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
268{
269 /* We need to be careful. As we read the TSF from multiple
270 * registers, we should take care of register overflows.
271 * In theory, the whole tsf read process should be atomic.
272 * We try to be atomic here, by restaring the read process,
273 * if any of the high registers changed (overflew).
274 */
275 if (bcm->current_core->rev >= 3) {
276 u32 low, high, high2;
277
278 do {
279 high = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
280 low = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW);
281 high2 = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
282 } while (unlikely(high != high2));
283
284 *tsf = high;
285 *tsf <<= 32;
286 *tsf |= low;
287 } else {
288 u64 tmp;
289 u16 v0, v1, v2, v3;
290 u16 test1, test2, test3;
291
292 do {
293 v3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
294 v2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
295 v1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
296 v0 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_0);
297
298 test3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
299 test2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
300 test1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
301 } while (v3 != test3 || v2 != test2 || v1 != test1);
302
303 *tsf = v3;
304 *tsf <<= 48;
305 tmp = v2;
306 tmp <<= 32;
307 *tsf |= tmp;
308 tmp = v1;
309 tmp <<= 16;
310 *tsf |= tmp;
311 *tsf |= v0;
312 }
313}
314
315void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
316{
317 u32 status;
318
319 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
320 status |= BCM43xx_SBF_TIME_UPDATE;
321 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
322 mmiowb();
323
324 /* Be careful with the in-progress timer.
325 * First zero out the low register, so we have a full
326 * register-overflow duration to complete the operation.
327 */
328 if (bcm->current_core->rev >= 3) {
329 u32 lo = (tsf & 0x00000000FFFFFFFFULL);
330 u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
331
332 bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
333 mmiowb();
334 bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
335 mmiowb();
336 bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
337 } else {
338 u16 v0 = (tsf & 0x000000000000FFFFULL);
339 u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
340 u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
341 u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
342
343 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
344 mmiowb();
345 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
346 mmiowb();
347 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
348 mmiowb();
349 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
350 mmiowb();
351 bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
352 }
353
354 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
355 status &= ~BCM43xx_SBF_TIME_UPDATE;
356 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
357}
358
359static
360void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
361 u16 offset,
362 const u8 *mac)
363{
364 u16 data;
365
366 offset |= 0x0020;
367 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
368
369 data = mac[0];
370 data |= mac[1] << 8;
371 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
372 data = mac[2];
373 data |= mac[3] << 8;
374 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
375 data = mac[4];
376 data |= mac[5] << 8;
377 bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
378}
379
380static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
381 u16 offset)
382{
383 const u8 zero_addr[ETH_ALEN] = { 0 };
384
385 bcm43xx_macfilter_set(bcm, offset, zero_addr);
386}
387
388static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
389{
390 const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
391 const u8 *bssid = (const u8 *)(bcm->ieee->bssid);
392 u8 mac_bssid[ETH_ALEN * 2];
393 int i;
394
395 memcpy(mac_bssid, mac, ETH_ALEN);
396 memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
397
398 /* Write our MAC address and BSSID to template ram */
399 for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
400 bcm43xx_ram_write(bcm, 0x20 + i, *((u32 *)(mac_bssid + i)));
401 for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
402 bcm43xx_ram_write(bcm, 0x78 + i, *((u32 *)(mac_bssid + i)));
403 for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
404 bcm43xx_ram_write(bcm, 0x478 + i, *((u32 *)(mac_bssid + i)));
405}
406
407//FIXME: Well, we should probably call them from somewhere.
408#if 0
409static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
410{
411 /* slot_time is in usec. */
412 if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
413 return;
414 bcm43xx_write16(bcm, 0x684, 510 + slot_time);
415 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
416}
417
418static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
419{
420 bcm43xx_set_slot_time(bcm, 9);
421}
422
423static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
424{
425 bcm43xx_set_slot_time(bcm, 20);
426}
427#endif
428
429/* FIXME: To get the MAC-filter working, we need to implement the
430 * following functions (and rename them :)
431 */
432#if 0
433static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
434{
435 bcm43xx_mac_suspend(bcm);
436 bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
437
438 bcm43xx_ram_write(bcm, 0x0026, 0x0000);
439 bcm43xx_ram_write(bcm, 0x0028, 0x0000);
440 bcm43xx_ram_write(bcm, 0x007E, 0x0000);
441 bcm43xx_ram_write(bcm, 0x0080, 0x0000);
442 bcm43xx_ram_write(bcm, 0x047E, 0x0000);
443 bcm43xx_ram_write(bcm, 0x0480, 0x0000);
444
445 if (bcm->current_core->rev < 3) {
446 bcm43xx_write16(bcm, 0x0610, 0x8000);
447 bcm43xx_write16(bcm, 0x060E, 0x0000);
448 } else
449 bcm43xx_write32(bcm, 0x0188, 0x80000000);
450
451 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
452
453 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G &&
454 ieee80211_is_ofdm_rate(bcm->softmac->txrates.default_rate))
455 bcm43xx_short_slot_timing_enable(bcm);
456
457 bcm43xx_mac_enable(bcm);
458}
459
460static void bcm43xx_associate(struct bcm43xx_private *bcm,
461 const u8 *mac)
462{
463 memcpy(bcm->ieee->bssid, mac, ETH_ALEN);
464
465 bcm43xx_mac_suspend(bcm);
466 bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_ASSOC, mac);
467 bcm43xx_write_mac_bssid_templates(bcm);
468 bcm43xx_mac_enable(bcm);
469}
470#endif
471
472/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
473 * Returns the _previously_ enabled IRQ mask.
474 */
475static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
476{
477 u32 old_mask;
478
479 old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
480 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
481
482 return old_mask;
483}
484
485/* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
486 * Returns the _previously_ enabled IRQ mask.
487 */
488static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
489{
490 u32 old_mask;
491
492 old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
493 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
494
495 return old_mask;
496}
497
498/* Make sure we don't receive more data from the device. */
499static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *oldstate)
500{
501 u32 old;
502 unsigned long flags;
503
504 bcm43xx_lock_mmio(bcm, flags);
505 if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) {
506 bcm43xx_unlock_mmio(bcm, flags);
507 return -EBUSY;
508 }
509 old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
510 tasklet_disable(&bcm->isr_tasklet);
511 bcm43xx_unlock_mmio(bcm, flags);
512 if (oldstate)
513 *oldstate = old;
514
515 return 0;
516}
517
518static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
519{
520 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
521 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
522 u32 radio_id;
523 u16 manufact;
524 u16 version;
525 u8 revision;
526 s8 i;
527
528 if (bcm->chip_id == 0x4317) {
529 if (bcm->chip_rev == 0x00)
530 radio_id = 0x3205017F;
531 else if (bcm->chip_rev == 0x01)
532 radio_id = 0x4205017F;
533 else
534 radio_id = 0x5205017F;
535 } else {
536 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
537 radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
538 radio_id <<= 16;
539 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
540 radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
541 }
542
543 manufact = (radio_id & 0x00000FFF);
544 version = (radio_id & 0x0FFFF000) >> 12;
545 revision = (radio_id & 0xF0000000) >> 28;
546
547 dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
548 radio_id, manufact, version, revision);
549
550 switch (phy->type) {
551 case BCM43xx_PHYTYPE_A:
552 if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
553 goto err_unsupported_radio;
554 break;
555 case BCM43xx_PHYTYPE_B:
556 if ((version & 0xFFF0) != 0x2050)
557 goto err_unsupported_radio;
558 break;
559 case BCM43xx_PHYTYPE_G:
560 if (version != 0x2050)
561 goto err_unsupported_radio;
562 break;
563 }
564
565 radio->manufact = manufact;
566 radio->version = version;
567 radio->revision = revision;
568
569 /* Set default attenuation values. */
570 radio->baseband_atten = bcm43xx_default_baseband_attenuation(bcm);
571 radio->radio_atten = bcm43xx_default_radio_attenuation(bcm);
572 radio->txctl1 = bcm43xx_default_txctl1(bcm);
573 radio->txctl2 = 0xFFFF;
574 if (phy->type == BCM43xx_PHYTYPE_A)
575 radio->txpower_desired = bcm->sprom.maxpower_aphy;
576 else
577 radio->txpower_desired = bcm->sprom.maxpower_bgphy;
578
579 /* Initialize the in-memory nrssi Lookup Table. */
580 for (i = 0; i < 64; i++)
581 radio->nrssi_lt[i] = i;
582
583 return 0;
584
585err_unsupported_radio:
586 printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
587 return -ENODEV;
588}
589
590static const char * bcm43xx_locale_iso(u8 locale)
591{
592 /* ISO 3166-1 country codes.
593 * Note that there aren't ISO 3166-1 codes for
594 * all or locales. (Not all locales are countries)
595 */
596 switch (locale) {
597 case BCM43xx_LOCALE_WORLD:
598 case BCM43xx_LOCALE_ALL:
599 return "XX";
600 case BCM43xx_LOCALE_THAILAND:
601 return "TH";
602 case BCM43xx_LOCALE_ISRAEL:
603 return "IL";
604 case BCM43xx_LOCALE_JORDAN:
605 return "JO";
606 case BCM43xx_LOCALE_CHINA:
607 return "CN";
608 case BCM43xx_LOCALE_JAPAN:
609 case BCM43xx_LOCALE_JAPAN_HIGH:
610 return "JP";
611 case BCM43xx_LOCALE_USA_CANADA_ANZ:
612 case BCM43xx_LOCALE_USA_LOW:
613 return "US";
614 case BCM43xx_LOCALE_EUROPE:
615 return "EU";
616 case BCM43xx_LOCALE_NONE:
617 return " ";
618 }
619 assert(0);
620 return " ";
621}
622
623static const char * bcm43xx_locale_string(u8 locale)
624{
625 switch (locale) {
626 case BCM43xx_LOCALE_WORLD:
627 return "World";
628 case BCM43xx_LOCALE_THAILAND:
629 return "Thailand";
630 case BCM43xx_LOCALE_ISRAEL:
631 return "Israel";
632 case BCM43xx_LOCALE_JORDAN:
633 return "Jordan";
634 case BCM43xx_LOCALE_CHINA:
635 return "China";
636 case BCM43xx_LOCALE_JAPAN:
637 return "Japan";
638 case BCM43xx_LOCALE_USA_CANADA_ANZ:
639 return "USA/Canada/ANZ";
640 case BCM43xx_LOCALE_EUROPE:
641 return "Europe";
642 case BCM43xx_LOCALE_USA_LOW:
643 return "USAlow";
644 case BCM43xx_LOCALE_JAPAN_HIGH:
645 return "JapanHigh";
646 case BCM43xx_LOCALE_ALL:
647 return "All";
648 case BCM43xx_LOCALE_NONE:
649 return "None";
650 }
651 assert(0);
652 return "";
653}
654
655static inline u8 bcm43xx_crc8(u8 crc, u8 data)
656{
657 static const u8 t[] = {
658 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
659 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
660 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
661 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
662 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
663 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
664 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
665 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
666 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
667 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
668 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
669 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
670 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
671 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
672 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
673 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
674 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
675 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
676 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
677 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
678 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
679 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
680 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
681 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
682 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
683 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
684 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
685 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
686 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
687 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
688 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
689 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
690 };
691 return t[crc ^ data];
692}
693
694static u8 bcm43xx_sprom_crc(const u16 *sprom)
695{
696 int word;
697 u8 crc = 0xFF;
698
699 for (word = 0; word < BCM43xx_SPROM_SIZE - 1; word++) {
700 crc = bcm43xx_crc8(crc, sprom[word] & 0x00FF);
701 crc = bcm43xx_crc8(crc, (sprom[word] & 0xFF00) >> 8);
702 }
703 crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
704 crc ^= 0xFF;
705
706 return crc;
707}
708
709int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
710{
711 int i;
712 u8 crc, expected_crc;
713
714 for (i = 0; i < BCM43xx_SPROM_SIZE; i++)
715 sprom[i] = bcm43xx_read16(bcm, BCM43xx_SPROM_BASE + (i * 2));
716 /* CRC-8 check. */
717 crc = bcm43xx_sprom_crc(sprom);
718 expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
719 if (crc != expected_crc) {
720 printk(KERN_WARNING PFX "WARNING: Invalid SPROM checksum "
721 "(0x%02X, expected: 0x%02X)\n",
722 crc, expected_crc);
723 return -EINVAL;
724 }
725
726 return 0;
727}
728
729int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
730{
731 int i, err;
732 u8 crc, expected_crc;
733 u32 spromctl;
734
735 /* CRC-8 validation of the input data. */
736 crc = bcm43xx_sprom_crc(sprom);
737 expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
738 if (crc != expected_crc) {
739 printk(KERN_ERR PFX "SPROM input data: Invalid CRC\n");
740 return -EINVAL;
741 }
742
743 printk(KERN_INFO PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n");
744 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_SPROMCTL, &spromctl);
745 if (err)
746 goto err_ctlreg;
747 spromctl |= 0x10; /* SPROM WRITE enable. */
748 bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
749 if (err)
750 goto err_ctlreg;
751 /* We must burn lots of CPU cycles here, but that does not
752 * really matter as one does not write the SPROM every other minute...
753 */
754 printk(KERN_INFO PFX "[ 0%%");
755 mdelay(500);
756 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
757 if (i == 16)
758 printk("25%%");
759 else if (i == 32)
760 printk("50%%");
761 else if (i == 48)
762 printk("75%%");
763 else if (i % 2)
764 printk(".");
765 bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
766 mmiowb();
767 mdelay(20);
768 }
769 spromctl &= ~0x10; /* SPROM WRITE enable. */
770 bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
771 if (err)
772 goto err_ctlreg;
773 mdelay(500);
774 printk("100%% ]\n");
775 printk(KERN_INFO PFX "SPROM written.\n");
776 bcm43xx_controller_restart(bcm, "SPROM update");
777
778 return 0;
779err_ctlreg:
780 printk(KERN_ERR PFX "Could not access SPROM control register.\n");
781 return -ENODEV;
782}
783
784static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
785{
786 u16 value;
787 u16 *sprom;
788#ifdef CONFIG_BCM947XX
789 char *c;
790#endif
791
792 sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
793 GFP_KERNEL);
794 if (!sprom) {
795 printk(KERN_ERR PFX "sprom_extract OOM\n");
796 return -ENOMEM;
797 }
798#ifdef CONFIG_BCM947XX
799 sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
800 sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
801
802 if ((c = nvram_get("il0macaddr")) != NULL)
803 e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
804
805 if ((c = nvram_get("et1macaddr")) != NULL)
806 e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
807
808 sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
809 sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
810 sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
811
812 sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
813 sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
814 sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
815
816 sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
817#else
818 bcm43xx_sprom_read(bcm, sprom);
819#endif
820
821 /* boardflags2 */
822 value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
823 bcm->sprom.boardflags2 = value;
824
825 /* il0macaddr */
826 value = sprom[BCM43xx_SPROM_IL0MACADDR + 0];
827 *(((u16 *)bcm->sprom.il0macaddr) + 0) = cpu_to_be16(value);
828 value = sprom[BCM43xx_SPROM_IL0MACADDR + 1];
829 *(((u16 *)bcm->sprom.il0macaddr) + 1) = cpu_to_be16(value);
830 value = sprom[BCM43xx_SPROM_IL0MACADDR + 2];
831 *(((u16 *)bcm->sprom.il0macaddr) + 2) = cpu_to_be16(value);
832
833 /* et0macaddr */
834 value = sprom[BCM43xx_SPROM_ET0MACADDR + 0];
835 *(((u16 *)bcm->sprom.et0macaddr) + 0) = cpu_to_be16(value);
836 value = sprom[BCM43xx_SPROM_ET0MACADDR + 1];
837 *(((u16 *)bcm->sprom.et0macaddr) + 1) = cpu_to_be16(value);
838 value = sprom[BCM43xx_SPROM_ET0MACADDR + 2];
839 *(((u16 *)bcm->sprom.et0macaddr) + 2) = cpu_to_be16(value);
840
841 /* et1macaddr */
842 value = sprom[BCM43xx_SPROM_ET1MACADDR + 0];
843 *(((u16 *)bcm->sprom.et1macaddr) + 0) = cpu_to_be16(value);
844 value = sprom[BCM43xx_SPROM_ET1MACADDR + 1];
845 *(((u16 *)bcm->sprom.et1macaddr) + 1) = cpu_to_be16(value);
846 value = sprom[BCM43xx_SPROM_ET1MACADDR + 2];
847 *(((u16 *)bcm->sprom.et1macaddr) + 2) = cpu_to_be16(value);
848
849 /* ethernet phy settings */
850 value = sprom[BCM43xx_SPROM_ETHPHY];
851 bcm->sprom.et0phyaddr = (value & 0x001F);
852 bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
853 bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
854 bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
855
856 /* boardrev, antennas, locale */
857 value = sprom[BCM43xx_SPROM_BOARDREV];
858 bcm->sprom.boardrev = (value & 0x00FF);
859 bcm->sprom.locale = (value & 0x0F00) >> 8;
860 bcm->sprom.antennas_aphy = (value & 0x3000) >> 12;
861 bcm->sprom.antennas_bgphy = (value & 0xC000) >> 14;
862 if (modparam_locale != -1) {
863 if (modparam_locale >= 0 && modparam_locale <= 11) {
864 bcm->sprom.locale = modparam_locale;
865 printk(KERN_WARNING PFX "Operating with modified "
866 "LocaleCode %u (%s)\n",
867 bcm->sprom.locale,
868 bcm43xx_locale_string(bcm->sprom.locale));
869 } else {
870 printk(KERN_WARNING PFX "Module parameter \"locale\" "
871 "invalid value. (0 - 11)\n");
872 }
873 }
874
875 /* pa0b* */
876 value = sprom[BCM43xx_SPROM_PA0B0];
877 bcm->sprom.pa0b0 = value;
878 value = sprom[BCM43xx_SPROM_PA0B1];
879 bcm->sprom.pa0b1 = value;
880 value = sprom[BCM43xx_SPROM_PA0B2];
881 bcm->sprom.pa0b2 = value;
882
883 /* wl0gpio* */
884 value = sprom[BCM43xx_SPROM_WL0GPIO0];
885 if (value == 0x0000)
886 value = 0xFFFF;
887 bcm->sprom.wl0gpio0 = value & 0x00FF;
888 bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
889 value = sprom[BCM43xx_SPROM_WL0GPIO2];
890 if (value == 0x0000)
891 value = 0xFFFF;
892 bcm->sprom.wl0gpio2 = value & 0x00FF;
893 bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
894
895 /* maxpower */
896 value = sprom[BCM43xx_SPROM_MAXPWR];
897 bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
898 bcm->sprom.maxpower_bgphy = value & 0x00FF;
899
900 /* pa1b* */
901 value = sprom[BCM43xx_SPROM_PA1B0];
902 bcm->sprom.pa1b0 = value;
903 value = sprom[BCM43xx_SPROM_PA1B1];
904 bcm->sprom.pa1b1 = value;
905 value = sprom[BCM43xx_SPROM_PA1B2];
906 bcm->sprom.pa1b2 = value;
907
908 /* idle tssi target */
909 value = sprom[BCM43xx_SPROM_IDL_TSSI_TGT];
910 bcm->sprom.idle_tssi_tgt_aphy = value & 0x00FF;
911 bcm->sprom.idle_tssi_tgt_bgphy = (value & 0xFF00) >> 8;
912
913 /* boardflags */
914 value = sprom[BCM43xx_SPROM_BOARDFLAGS];
915 if (value == 0xFFFF)
916 value = 0x0000;
917 bcm->sprom.boardflags = value;
918 /* boardflags workarounds */
919 if (bcm->board_vendor == PCI_VENDOR_ID_DELL &&
920 bcm->chip_id == 0x4301 &&
921 bcm->board_revision == 0x74)
922 bcm->sprom.boardflags |= BCM43xx_BFL_BTCOEXIST;
923 if (bcm->board_vendor == PCI_VENDOR_ID_APPLE &&
924 bcm->board_type == 0x4E &&
925 bcm->board_revision > 0x40)
926 bcm->sprom.boardflags |= BCM43xx_BFL_PACTRL;
927
928 /* antenna gain */
929 value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
930 if (value == 0x0000 || value == 0xFFFF)
931 value = 0x0202;
932 /* convert values to Q5.2 */
933 bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
934 bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
935
936 kfree(sprom);
937
938 return 0;
939}
940
941static void bcm43xx_geo_init(struct bcm43xx_private *bcm)
942{
943 struct ieee80211_geo geo;
944 struct ieee80211_channel *chan;
945 int have_a = 0, have_bg = 0;
946 int i;
947 u8 channel;
948 struct bcm43xx_phyinfo *phy;
949 const char *iso_country;
950
951 memset(&geo, 0, sizeof(geo));
952 for (i = 0; i < bcm->nr_80211_available; i++) {
953 phy = &(bcm->core_80211_ext[i].phy);
954 switch (phy->type) {
955 case BCM43xx_PHYTYPE_B:
956 case BCM43xx_PHYTYPE_G:
957 have_bg = 1;
958 break;
959 case BCM43xx_PHYTYPE_A:
960 have_a = 1;
961 break;
962 default:
963 assert(0);
964 }
965 }
966 iso_country = bcm43xx_locale_iso(bcm->sprom.locale);
967
968 if (have_a) {
969 for (i = 0, channel = 0; channel < 201; channel++) {
970 chan = &geo.a[i++];
971 chan->freq = bcm43xx_channel_to_freq_a(channel);
972 chan->channel = channel;
973 }
974 geo.a_channels = i;
975 }
976 if (have_bg) {
977 for (i = 0, channel = 1; channel < 15; channel++) {
978 chan = &geo.bg[i++];
979 chan->freq = bcm43xx_channel_to_freq_bg(channel);
980 chan->channel = channel;
981 }
982 geo.bg_channels = i;
983 }
984 memcpy(geo.name, iso_country, 2);
985 if (0 /*TODO: Outdoor use only */)
986 geo.name[2] = 'O';
987 else if (0 /*TODO: Indoor use only */)
988 geo.name[2] = 'I';
989 else
990 geo.name[2] = ' ';
991 geo.name[3] = '\0';
992
993 ieee80211_set_geo(bcm->ieee, &geo);
994}
995
996/* DummyTransmission function, as documented on
997 * http://bcm-specs.sipsolutions.net/DummyTransmission
998 */
999void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
1000{
1001 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1002 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1003 unsigned int i, max_loop;
1004 u16 value = 0;
1005 u32 buffer[5] = {
1006 0x00000000,
1007 0x0000D400,
1008 0x00000000,
1009 0x00000001,
1010 0x00000000,
1011 };
1012
1013 switch (phy->type) {
1014 case BCM43xx_PHYTYPE_A:
1015 max_loop = 0x1E;
1016 buffer[0] = 0xCC010200;
1017 break;
1018 case BCM43xx_PHYTYPE_B:
1019 case BCM43xx_PHYTYPE_G:
1020 max_loop = 0xFA;
1021 buffer[0] = 0x6E840B00;
1022 break;
1023 default:
1024 assert(0);
1025 return;
1026 }
1027
1028 for (i = 0; i < 5; i++)
1029 bcm43xx_ram_write(bcm, i * 4, buffer[i]);
1030
1031 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
1032
1033 bcm43xx_write16(bcm, 0x0568, 0x0000);
1034 bcm43xx_write16(bcm, 0x07C0, 0x0000);
1035 bcm43xx_write16(bcm, 0x050C, ((phy->type == BCM43xx_PHYTYPE_A) ? 1 : 0));
1036 bcm43xx_write16(bcm, 0x0508, 0x0000);
1037 bcm43xx_write16(bcm, 0x050A, 0x0000);
1038 bcm43xx_write16(bcm, 0x054C, 0x0000);
1039 bcm43xx_write16(bcm, 0x056A, 0x0014);
1040 bcm43xx_write16(bcm, 0x0568, 0x0826);
1041 bcm43xx_write16(bcm, 0x0500, 0x0000);
1042 bcm43xx_write16(bcm, 0x0502, 0x0030);
1043
1044 if (radio->version == 0x2050 && radio->revision <= 0x5)
1045 bcm43xx_radio_write16(bcm, 0x0051, 0x0017);
1046 for (i = 0x00; i < max_loop; i++) {
1047 value = bcm43xx_read16(bcm, 0x050E);
1048 if (value & 0x0080)
1049 break;
1050 udelay(10);
1051 }
1052 for (i = 0x00; i < 0x0A; i++) {
1053 value = bcm43xx_read16(bcm, 0x050E);
1054 if (value & 0x0400)
1055 break;
1056 udelay(10);
1057 }
1058 for (i = 0x00; i < 0x0A; i++) {
1059 value = bcm43xx_read16(bcm, 0x0690);
1060 if (!(value & 0x0100))
1061 break;
1062 udelay(10);
1063 }
1064 if (radio->version == 0x2050 && radio->revision <= 0x5)
1065 bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
1066}
1067
1068static void key_write(struct bcm43xx_private *bcm,
1069 u8 index, u8 algorithm, const u16 *key)
1070{
1071 unsigned int i, basic_wep = 0;
1072 u32 offset;
1073 u16 value;
1074
1075 /* Write associated key information */
1076 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
1077 ((index << 4) | (algorithm & 0x0F)));
1078
1079 /* The first 4 WEP keys need extra love */
1080 if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
1081 (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
1082 basic_wep = 1;
1083
1084 /* Write key payload, 8 little endian words */
1085 offset = bcm->security_offset + (index * BCM43xx_SEC_KEYSIZE);
1086 for (i = 0; i < (BCM43xx_SEC_KEYSIZE / sizeof(u16)); i++) {
1087 value = cpu_to_le16(key[i]);
1088 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1089 offset + (i * 2), value);
1090
1091 if (!basic_wep)
1092 continue;
1093
1094 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1095 offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
1096 value);
1097 }
1098}
1099
1100static void keymac_write(struct bcm43xx_private *bcm,
1101 u8 index, const u32 *addr)
1102{
1103 /* for keys 0-3 there is no associated mac address */
1104 if (index < 4)
1105 return;
1106
1107 index -= 4;
1108 if (bcm->current_core->rev >= 5) {
1109 bcm43xx_shm_write32(bcm,
1110 BCM43xx_SHM_HWMAC,
1111 index * 2,
1112 cpu_to_be32(*addr));
1113 bcm43xx_shm_write16(bcm,
1114 BCM43xx_SHM_HWMAC,
1115 (index * 2) + 1,
1116 cpu_to_be16(*((u16 *)(addr + 1))));
1117 } else {
1118 if (index < 8) {
1119 TODO(); /* Put them in the macaddress filter */
1120 } else {
1121 TODO();
1122 /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
1123 Keep in mind to update the count of keymacs in 0x003E as well! */
1124 }
1125 }
1126}
1127
1128static int bcm43xx_key_write(struct bcm43xx_private *bcm,
1129 u8 index, u8 algorithm,
1130 const u8 *_key, int key_len,
1131 const u8 *mac_addr)
1132{
1133 u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
1134
1135 if (index >= ARRAY_SIZE(bcm->key))
1136 return -EINVAL;
1137 if (key_len > ARRAY_SIZE(key))
1138 return -EINVAL;
1139 if (algorithm < 1 || algorithm > 5)
1140 return -EINVAL;
1141
1142 memcpy(key, _key, key_len);
1143 key_write(bcm, index, algorithm, (const u16 *)key);
1144 keymac_write(bcm, index, (const u32 *)mac_addr);
1145
1146 bcm->key[index].algorithm = algorithm;
1147
1148 return 0;
1149}
1150
1151static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
1152{
1153 static const u32 zero_mac[2] = { 0 };
1154 unsigned int i,j, nr_keys = 54;
1155 u16 offset;
1156
1157 if (bcm->current_core->rev < 5)
1158 nr_keys = 16;
1159 assert(nr_keys <= ARRAY_SIZE(bcm->key));
1160
1161 for (i = 0; i < nr_keys; i++) {
1162 bcm->key[i].enabled = 0;
1163 /* returns for i < 4 immediately */
1164 keymac_write(bcm, i, zero_mac);
1165 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1166 0x100 + (i * 2), 0x0000);
1167 for (j = 0; j < 8; j++) {
1168 offset = bcm->security_offset + (j * 4) + (i * BCM43xx_SEC_KEYSIZE);
1169 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
1170 offset, 0x0000);
1171 }
1172 }
1173 dprintk(KERN_INFO PFX "Keys cleared\n");
1174}
1175
1176/* Lowlevel core-switch function. This is only to be used in
1177 * bcm43xx_switch_core() and bcm43xx_probe_cores()
1178 */
1179static int _switch_core(struct bcm43xx_private *bcm, int core)
1180{
1181 int err;
1182 int attempts = 0;
1183 u32 current_core;
1184
1185 assert(core >= 0);
1186 while (1) {
1187 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
1188 (core * 0x1000) + 0x18000000);
1189 if (unlikely(err))
1190 goto error;
1191 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
1192 &current_core);
1193 if (unlikely(err))
1194 goto error;
1195 current_core = (current_core - 0x18000000) / 0x1000;
1196 if (current_core == core)
1197 break;
1198
1199 if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
1200 goto error;
1201 udelay(10);
1202 }
1203#ifdef CONFIG_BCM947XX
1204 if (bcm->pci_dev->bus->number == 0)
1205 bcm->current_core_offset = 0x1000 * core;
1206 else
1207 bcm->current_core_offset = 0;
1208#endif
1209
1210 return 0;
1211error:
1212 printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
1213 return -ENODEV;
1214}
1215
1216int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
1217{
1218 int err;
1219
1220 if (unlikely(!new_core))
1221 return 0;
1222 if (!new_core->available)
1223 return -ENODEV;
1224 if (bcm->current_core == new_core)
1225 return 0;
1226 err = _switch_core(bcm, new_core->index);
1227 if (unlikely(err))
1228 goto out;
1229
1230 bcm->current_core = new_core;
1231 bcm->current_80211_core_idx = -1;
1232 if (new_core->id == BCM43xx_COREID_80211)
1233 bcm->current_80211_core_idx = (int)(new_core - &(bcm->core_80211[0]));
1234
1235out:
1236 return err;
1237}
1238
1239static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
1240{
1241 u32 value;
1242
1243 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1244 value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
1245 | BCM43xx_SBTMSTATELOW_REJECT;
1246
1247 return (value == BCM43xx_SBTMSTATELOW_CLOCK);
1248}
1249
1250/* disable current core */
1251static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
1252{
1253 u32 sbtmstatelow;
1254 u32 sbtmstatehigh;
1255 int i;
1256
1257 /* fetch sbtmstatelow from core information registers */
1258 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1259
1260 /* core is already in reset */
1261 if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
1262 goto out;
1263
1264 if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
1265 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
1266 BCM43xx_SBTMSTATELOW_REJECT;
1267 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1268
1269 for (i = 0; i < 1000; i++) {
1270 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1271 if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
1272 i = -1;
1273 break;
1274 }
1275 udelay(10);
1276 }
1277 if (i != -1) {
1278 printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
1279 return -EBUSY;
1280 }
1281
1282 for (i = 0; i < 1000; i++) {
1283 sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
1284 if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
1285 i = -1;
1286 break;
1287 }
1288 udelay(10);
1289 }
1290 if (i != -1) {
1291 printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
1292 return -EBUSY;
1293 }
1294
1295 sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
1296 BCM43xx_SBTMSTATELOW_REJECT |
1297 BCM43xx_SBTMSTATELOW_RESET |
1298 BCM43xx_SBTMSTATELOW_CLOCK |
1299 core_flags;
1300 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1301 udelay(10);
1302 }
1303
1304 sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
1305 BCM43xx_SBTMSTATELOW_REJECT |
1306 core_flags;
1307 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1308
1309out:
1310 bcm->current_core->enabled = 0;
1311
1312 return 0;
1313}
1314
1315/* enable (reset) current core */
1316static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
1317{
1318 u32 sbtmstatelow;
1319 u32 sbtmstatehigh;
1320 u32 sbimstate;
1321 int err;
1322
1323 err = bcm43xx_core_disable(bcm, core_flags);
1324 if (err)
1325 goto out;
1326
1327 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
1328 BCM43xx_SBTMSTATELOW_RESET |
1329 BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
1330 core_flags;
1331 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1332 udelay(1);
1333
1334 sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
1335 if (sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_SERROR) {
1336 sbtmstatehigh = 0x00000000;
1337 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATEHIGH, sbtmstatehigh);
1338 }
1339
1340 sbimstate = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMSTATE);
1341 if (sbimstate & (BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT)) {
1342 sbimstate &= ~(BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT);
1343 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMSTATE, sbimstate);
1344 }
1345
1346 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
1347 BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
1348 core_flags;
1349 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1350 udelay(1);
1351
1352 sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
1353 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1354 udelay(1);
1355
1356 bcm->current_core->enabled = 1;
1357 assert(err == 0);
1358out:
1359 return err;
1360}
1361
1362/* http://bcm-specs.sipsolutions.net/80211CoreReset */
1363void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
1364{
1365 u32 flags = 0x00040000;
1366
1367 if ((bcm43xx_core_enabled(bcm)) &&
1368 !bcm43xx_using_pio(bcm)) {
1369//FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
1370#ifndef CONFIG_BCM947XX
1371 /* reset all used DMA controllers. */
1372 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
1373 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
1374 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
1375 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
1376 bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
1377 if (bcm->current_core->rev < 5)
1378 bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
1379#endif
1380 }
1381 if (bcm->shutting_down) {
1382 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
1383 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
1384 & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
1385 } else {
1386 if (connect_phy)
1387 flags |= 0x20000000;
1388 bcm43xx_phy_connect(bcm, connect_phy);
1389 bcm43xx_core_enable(bcm, flags);
1390 bcm43xx_write16(bcm, 0x03E6, 0x0000);
1391 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
1392 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
1393 | BCM43xx_SBF_400);
1394 }
1395}
1396
1397static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
1398{
1399 bcm43xx_radio_turn_off(bcm);
1400 bcm43xx_write16(bcm, 0x03E6, 0x00F4);
1401 bcm43xx_core_disable(bcm, 0);
1402}
1403
1404/* Mark the current 80211 core inactive.
1405 * "active_80211_core" is the other 80211 core, which is used.
1406 */
1407static int bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm,
1408 struct bcm43xx_coreinfo *active_80211_core)
1409{
1410 u32 sbtmstatelow;
1411 struct bcm43xx_coreinfo *old_core;
1412 int err = 0;
1413
1414 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
1415 bcm43xx_radio_turn_off(bcm);
1416 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1417 sbtmstatelow &= ~0x200a0000;
1418 sbtmstatelow |= 0xa0000;
1419 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1420 udelay(1);
1421 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1422 sbtmstatelow &= ~0xa0000;
1423 sbtmstatelow |= 0x80000;
1424 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1425 udelay(1);
1426
1427 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
1428 old_core = bcm->current_core;
1429 err = bcm43xx_switch_core(bcm, active_80211_core);
1430 if (err)
1431 goto out;
1432 sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
1433 sbtmstatelow &= ~0x20000000;
1434 sbtmstatelow |= 0x20000000;
1435 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
1436 err = bcm43xx_switch_core(bcm, old_core);
1437 }
1438
1439out:
1440 return err;
1441}
1442
1443static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
1444{
1445 u32 v0, v1;
1446 u16 tmp;
1447 struct bcm43xx_xmitstatus stat;
1448
1449 while (1) {
1450 v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
1451 if (!v0)
1452 break;
1453 v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
1454
1455 stat.cookie = (v0 >> 16) & 0x0000FFFF;
1456 tmp = (u16)((v0 & 0xFFF0) | ((v0 & 0xF) >> 1));
1457 stat.flags = tmp & 0xFF;
1458 stat.cnt1 = (tmp & 0x0F00) >> 8;
1459 stat.cnt2 = (tmp & 0xF000) >> 12;
1460 stat.seq = (u16)(v1 & 0xFFFF);
1461 stat.unknown = (u16)((v1 >> 16) & 0xFF);
1462
1463 bcm43xx_debugfs_log_txstat(bcm, &stat);
1464
1465 if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
1466 continue;
1467 if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK)) {
1468 //TODO: packet was not acked (was lost)
1469 }
1470 //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
1471
1472 if (bcm43xx_using_pio(bcm))
1473 bcm43xx_pio_handle_xmitstatus(bcm, &stat);
1474 else
1475 bcm43xx_dma_handle_xmitstatus(bcm, &stat);
1476 }
1477}
1478
1479static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
1480{
1481 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x408, 0x7F7F);
1482 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x40A, 0x7F7F);
1483 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
1484 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD) | (1 << 4));
1485 assert(bcm->noisecalc.core_at_start == bcm->current_core);
1486 assert(bcm->noisecalc.channel_at_start == bcm43xx_current_radio(bcm)->channel);
1487}
1488
1489static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
1490{
1491 /* Top half of Link Quality calculation. */
1492
1493 if (bcm->noisecalc.calculation_running)
1494 return;
1495 bcm->noisecalc.core_at_start = bcm->current_core;
1496 bcm->noisecalc.channel_at_start = bcm43xx_current_radio(bcm)->channel;
1497 bcm->noisecalc.calculation_running = 1;
1498 bcm->noisecalc.nr_samples = 0;
1499
1500 bcm43xx_generate_noise_sample(bcm);
1501}
1502
1503static void handle_irq_noise(struct bcm43xx_private *bcm)
1504{
1505 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1506 u16 tmp;
1507 u8 noise[4];
1508 u8 i, j;
1509 s32 average;
1510
1511 /* Bottom half of Link Quality calculation. */
1512
1513 assert(bcm->noisecalc.calculation_running);
1514 if (bcm->noisecalc.core_at_start != bcm->current_core ||
1515 bcm->noisecalc.channel_at_start != radio->channel)
1516 goto drop_calculation;
1517 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x408);
1518 noise[0] = (tmp & 0x00FF);
1519 noise[1] = (tmp & 0xFF00) >> 8;
1520 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40A);
1521 noise[2] = (tmp & 0x00FF);
1522 noise[3] = (tmp & 0xFF00) >> 8;
1523 if (noise[0] == 0x7F || noise[1] == 0x7F ||
1524 noise[2] == 0x7F || noise[3] == 0x7F)
1525 goto generate_new;
1526
1527 /* Get the noise samples. */
1528 assert(bcm->noisecalc.nr_samples <= 8);
1529 i = bcm->noisecalc.nr_samples;
1530 noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1531 noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1532 noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1533 noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
1534 bcm->noisecalc.samples[i][0] = radio->nrssi_lt[noise[0]];
1535 bcm->noisecalc.samples[i][1] = radio->nrssi_lt[noise[1]];
1536 bcm->noisecalc.samples[i][2] = radio->nrssi_lt[noise[2]];
1537 bcm->noisecalc.samples[i][3] = radio->nrssi_lt[noise[3]];
1538 bcm->noisecalc.nr_samples++;
1539 if (bcm->noisecalc.nr_samples == 8) {
1540 /* Calculate the Link Quality by the noise samples. */
1541 average = 0;
1542 for (i = 0; i < 8; i++) {
1543 for (j = 0; j < 4; j++)
1544 average += bcm->noisecalc.samples[i][j];
1545 }
1546 average /= (8 * 4);
1547 average *= 125;
1548 average += 64;
1549 average /= 128;
1550
1551 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
1552 tmp = (tmp / 128) & 0x1F;
1553 if (tmp >= 8)
1554 average += 2;
1555 else
1556 average -= 25;
1557 if (tmp == 8)
1558 average -= 72;
1559 else
1560 average -= 48;
1561
1562/* FIXME: This is wrong, but people want fancy stats. well... */
1563bcm->stats.noise = average;
1564 if (average > -65)
1565 bcm->stats.link_quality = 0;
1566 else if (average > -75)
1567 bcm->stats.link_quality = 1;
1568 else if (average > -85)
1569 bcm->stats.link_quality = 2;
1570 else
1571 bcm->stats.link_quality = 3;
1572// dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
1573drop_calculation:
1574 bcm->noisecalc.calculation_running = 0;
1575 return;
1576 }
1577generate_new:
1578 bcm43xx_generate_noise_sample(bcm);
1579}
1580
1581static void handle_irq_ps(struct bcm43xx_private *bcm)
1582{
1583 if (bcm->ieee->iw_mode == IW_MODE_MASTER) {
1584 ///TODO: PS TBTT
1585 } else {
1586 if (1/*FIXME: the last PSpoll frame was sent successfully */)
1587 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
1588 }
1589 if (bcm->ieee->iw_mode == IW_MODE_ADHOC)
1590 bcm->reg124_set_0x4 = 1;
1591 //FIXME else set to false?
1592}
1593
1594static void handle_irq_reg124(struct bcm43xx_private *bcm)
1595{
1596 if (!bcm->reg124_set_0x4)
1597 return;
1598 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
1599 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
1600 | 0x4);
1601 //FIXME: reset reg124_set_0x4 to false?
1602}
1603
1604static void handle_irq_pmq(struct bcm43xx_private *bcm)
1605{
1606 u32 tmp;
1607
1608 //TODO: AP mode.
1609
1610 while (1) {
1611 tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
1612 if (!(tmp & 0x00000008))
1613 break;
1614 }
1615 /* 16bit write is odd, but correct. */
1616 bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
1617}
1618
1619static void bcm43xx_generate_beacon_template(struct bcm43xx_private *bcm,
1620 u16 ram_offset, u16 shm_size_offset)
1621{
1622 u32 value;
1623 u16 size = 0;
1624
1625 /* Timestamp. */
1626 //FIXME: assumption: The chip sets the timestamp
1627 value = 0;
1628 bcm43xx_ram_write(bcm, ram_offset++, value);
1629 bcm43xx_ram_write(bcm, ram_offset++, value);
1630 size += 8;
1631
1632 /* Beacon Interval / Capability Information */
1633 value = 0x0000;//FIXME: Which interval?
1634 value |= (1 << 0) << 16; /* ESS */
1635 value |= (1 << 2) << 16; /* CF Pollable */ //FIXME?
1636 value |= (1 << 3) << 16; /* CF Poll Request */ //FIXME?
1637 if (!bcm->ieee->open_wep)
1638 value |= (1 << 4) << 16; /* Privacy */
1639 bcm43xx_ram_write(bcm, ram_offset++, value);
1640 size += 4;
1641
1642 /* SSID */
1643 //TODO
1644
1645 /* FH Parameter Set */
1646 //TODO
1647
1648 /* DS Parameter Set */
1649 //TODO
1650
1651 /* CF Parameter Set */
1652 //TODO
1653
1654 /* TIM */
1655 //TODO
1656
1657 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
1658}
1659
1660static void handle_irq_beacon(struct bcm43xx_private *bcm)
1661{
1662 u32 status;
1663
1664 bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
1665 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
1666
1667 if ((status & 0x1) && (status & 0x2)) {
1668 /* ACK beacon IRQ. */
1669 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
1670 BCM43xx_IRQ_BEACON);
1671 bcm->irq_savedstate |= BCM43xx_IRQ_BEACON;
1672 return;
1673 }
1674 if (!(status & 0x1)) {
1675 bcm43xx_generate_beacon_template(bcm, 0x68, 0x18);
1676 status |= 0x1;
1677 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
1678 }
1679 if (!(status & 0x2)) {
1680 bcm43xx_generate_beacon_template(bcm, 0x468, 0x1A);
1681 status |= 0x2;
1682 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
1683 }
1684}
1685
1686/* Interrupt handler bottom-half */
1687static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
1688{
1689 u32 reason;
1690 u32 dma_reason[4];
1691 int activity = 0;
1692 unsigned long flags;
1693
1694#ifdef CONFIG_BCM43XX_DEBUG
1695 u32 _handled = 0x00000000;
1696# define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
1697#else
1698# define bcmirq_handled(irq) do { /* nothing */ } while (0)
1699#endif /* CONFIG_BCM43XX_DEBUG*/
1700
1701 bcm43xx_lock_mmio(bcm, flags);
1702 reason = bcm->irq_reason;
1703 dma_reason[0] = bcm->dma_reason[0];
1704 dma_reason[1] = bcm->dma_reason[1];
1705 dma_reason[2] = bcm->dma_reason[2];
1706 dma_reason[3] = bcm->dma_reason[3];
1707
1708 if (unlikely(reason & BCM43xx_IRQ_XMIT_ERROR)) {
1709 /* TX error. We get this when Template Ram is written in wrong endianess
1710 * in dummy_tx(). We also get this if something is wrong with the TX header
1711 * on DMA or PIO queues.
1712 * Maybe we get this in other error conditions, too.
1713 */
1714 printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
1715 bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
1716 }
1717 if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_FATALMASK) |
1718 (dma_reason[1] & BCM43xx_DMAIRQ_FATALMASK) |
1719 (dma_reason[2] & BCM43xx_DMAIRQ_FATALMASK) |
1720 (dma_reason[3] & BCM43xx_DMAIRQ_FATALMASK))) {
1721 printkl(KERN_ERR PFX "FATAL ERROR: Fatal DMA error: "
1722 "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
1723 dma_reason[0], dma_reason[1],
1724 dma_reason[2], dma_reason[3]);
1725 bcm43xx_controller_restart(bcm, "DMA error");
1726 bcm43xx_unlock_mmio(bcm, flags);
1727 return;
1728 }
1729 if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) |
1730 (dma_reason[1] & BCM43xx_DMAIRQ_NONFATALMASK) |
1731 (dma_reason[2] & BCM43xx_DMAIRQ_NONFATALMASK) |
1732 (dma_reason[3] & BCM43xx_DMAIRQ_NONFATALMASK))) {
1733 printkl(KERN_ERR PFX "DMA error: "
1734 "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
1735 dma_reason[0], dma_reason[1],
1736 dma_reason[2], dma_reason[3]);
1737 }
1738
1739 if (reason & BCM43xx_IRQ_PS) {
1740 handle_irq_ps(bcm);
1741 bcmirq_handled(BCM43xx_IRQ_PS);
1742 }
1743
1744 if (reason & BCM43xx_IRQ_REG124) {
1745 handle_irq_reg124(bcm);
1746 bcmirq_handled(BCM43xx_IRQ_REG124);
1747 }
1748
1749 if (reason & BCM43xx_IRQ_BEACON) {
1750 if (bcm->ieee->iw_mode == IW_MODE_MASTER)
1751 handle_irq_beacon(bcm);
1752 bcmirq_handled(BCM43xx_IRQ_BEACON);
1753 }
1754
1755 if (reason & BCM43xx_IRQ_PMQ) {
1756 handle_irq_pmq(bcm);
1757 bcmirq_handled(BCM43xx_IRQ_PMQ);
1758 }
1759
1760 if (reason & BCM43xx_IRQ_SCAN) {
1761 /*TODO*/
1762 //bcmirq_handled(BCM43xx_IRQ_SCAN);
1763 }
1764
1765 if (reason & BCM43xx_IRQ_NOISE) {
1766 handle_irq_noise(bcm);
1767 bcmirq_handled(BCM43xx_IRQ_NOISE);
1768 }
1769
1770 /* Check the DMA reason registers for received data. */
1771 assert(!(dma_reason[1] & BCM43xx_DMAIRQ_RX_DONE));
1772 assert(!(dma_reason[2] & BCM43xx_DMAIRQ_RX_DONE));
1773 if (dma_reason[0] & BCM43xx_DMAIRQ_RX_DONE) {
1774 if (bcm43xx_using_pio(bcm))
1775 bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue0);
1776 else
1777 bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
1778 /* We intentionally don't set "activity" to 1, here. */
1779 }
1780 if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
1781 if (bcm43xx_using_pio(bcm))
1782 bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
1783 else
1784 bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring1);
1785 activity = 1;
1786 }
1787 bcmirq_handled(BCM43xx_IRQ_RX);
1788
1789 if (reason & BCM43xx_IRQ_XMIT_STATUS) {
1790 handle_irq_transmit_status(bcm);
1791 activity = 1;
1792 //TODO: In AP mode, this also causes sending of powersave responses.
1793 bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
1794 }
1795
1796 /* IRQ_PIO_WORKAROUND is handled in the top-half. */
1797 bcmirq_handled(BCM43xx_IRQ_PIO_WORKAROUND);
1798#ifdef CONFIG_BCM43XX_DEBUG
1799 if (unlikely(reason & ~_handled)) {
1800 printkl(KERN_WARNING PFX
1801 "Unhandled IRQ! Reason: 0x%08x, Unhandled: 0x%08x, "
1802 "DMA: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
1803 reason, (reason & ~_handled),
1804 dma_reason[0], dma_reason[1],
1805 dma_reason[2], dma_reason[3]);
1806 }
1807#endif
1808#undef bcmirq_handled
1809
1810 if (!modparam_noleds)
1811 bcm43xx_leds_update(bcm, activity);
1812 bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
1813 bcm43xx_unlock_mmio(bcm, flags);
1814}
1815
1816static void pio_irq_workaround(struct bcm43xx_private *bcm,
1817 u16 base, int queueidx)
1818{
1819 u16 rxctl;
1820
1821 rxctl = bcm43xx_read16(bcm, base + BCM43xx_PIO_RXCTL);
1822 if (rxctl & BCM43xx_PIO_RXCTL_DATAAVAILABLE)
1823 bcm->dma_reason[queueidx] |= BCM43xx_DMAIRQ_RX_DONE;
1824 else
1825 bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
1826}
1827
1828static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
1829{
1830 if (bcm43xx_using_pio(bcm) &&
1831 (bcm->current_core->rev < 3) &&
1832 (!(reason & BCM43xx_IRQ_PIO_WORKAROUND))) {
1833 /* Apply a PIO specific workaround to the dma_reasons */
1834 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO1_BASE, 0);
1835 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO2_BASE, 1);
1836 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO3_BASE, 2);
1837 pio_irq_workaround(bcm, BCM43xx_MMIO_PIO4_BASE, 3);
1838 }
1839
1840 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
1841
1842 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_REASON,
1843 bcm->dma_reason[0]);
1844 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_REASON,
1845 bcm->dma_reason[1]);
1846 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_REASON,
1847 bcm->dma_reason[2]);
1848 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_REASON,
1849 bcm->dma_reason[3]);
1850}
1851
1852/* Interrupt handler top-half */
1853static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
1854{
1855 irqreturn_t ret = IRQ_HANDLED;
1856 struct bcm43xx_private *bcm = dev_id;
1857 u32 reason;
1858
1859 if (!bcm)
1860 return IRQ_NONE;
1861
1862 spin_lock(&bcm->_lock);
1863
1864 reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
1865 if (reason == 0xffffffff) {
1866 /* irq not for us (shared irq) */
1867 ret = IRQ_NONE;
1868 goto out;
1869 }
1870 reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
1871 if (!reason)
1872 goto out;
1873
1874 bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
1875 & 0x0001dc00;
1876 bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
1877 & 0x0000dc00;
1878 bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
1879 & 0x0000dc00;
1880 bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
1881 & 0x0001dc00;
1882
1883 bcm43xx_interrupt_ack(bcm, reason);
1884
1885 /* Only accept IRQs, if we are initialized properly.
1886 * This avoids an RX race while initializing.
1887 * We should probably not enable IRQs before we are initialized
1888 * completely, but some careful work is needed to fix this. I think it
1889 * is best to stay with this cheap workaround for now... .
1890 */
1891 if (likely(bcm->initialized)) {
1892 /* disable all IRQs. They are enabled again in the bottom half. */
1893 bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
1894 /* save the reason code and call our bottom half. */
1895 bcm->irq_reason = reason;
1896 tasklet_schedule(&bcm->isr_tasklet);
1897 }
1898
1899out:
1900 mmiowb();
1901 spin_unlock(&bcm->_lock);
1902
1903 return ret;
1904}
1905
1906static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
1907{
1908 if (bcm->firmware_norelease && !force)
1909 return; /* Suspending or controller reset. */
1910 release_firmware(bcm->ucode);
1911 bcm->ucode = NULL;
1912 release_firmware(bcm->pcm);
1913 bcm->pcm = NULL;
1914 release_firmware(bcm->initvals0);
1915 bcm->initvals0 = NULL;
1916 release_firmware(bcm->initvals1);
1917 bcm->initvals1 = NULL;
1918}
1919
1920static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
1921{
1922 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1923 u8 rev = bcm->current_core->rev;
1924 int err = 0;
1925 int nr;
1926 char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
1927
1928 if (!bcm->ucode) {
1929 snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_microcode%d%s.fw",
1930 (rev >= 5 ? 5 : rev),
1931 modparam_fwpostfix);
1932 err = request_firmware(&bcm->ucode, buf, &bcm->pci_dev->dev);
1933 if (err) {
1934 printk(KERN_ERR PFX
1935 "Error: Microcode \"%s\" not available or load failed.\n",
1936 buf);
1937 goto error;
1938 }
1939 }
1940
1941 if (!bcm->pcm) {
1942 snprintf(buf, ARRAY_SIZE(buf),
1943 "bcm43xx_pcm%d%s.fw",
1944 (rev < 5 ? 4 : 5),
1945 modparam_fwpostfix);
1946 err = request_firmware(&bcm->pcm, buf, &bcm->pci_dev->dev);
1947 if (err) {
1948 printk(KERN_ERR PFX
1949 "Error: PCM \"%s\" not available or load failed.\n",
1950 buf);
1951 goto error;
1952 }
1953 }
1954
1955 if (!bcm->initvals0) {
1956 if (rev == 2 || rev == 4) {
1957 switch (phy->type) {
1958 case BCM43xx_PHYTYPE_A:
1959 nr = 3;
1960 break;
1961 case BCM43xx_PHYTYPE_B:
1962 case BCM43xx_PHYTYPE_G:
1963 nr = 1;
1964 break;
1965 default:
1966 goto err_noinitval;
1967 }
1968
1969 } else if (rev >= 5) {
1970 switch (phy->type) {
1971 case BCM43xx_PHYTYPE_A:
1972 nr = 7;
1973 break;
1974 case BCM43xx_PHYTYPE_B:
1975 case BCM43xx_PHYTYPE_G:
1976 nr = 5;
1977 break;
1978 default:
1979 goto err_noinitval;
1980 }
1981 } else
1982 goto err_noinitval;
1983 snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
1984 nr, modparam_fwpostfix);
1985
1986 err = request_firmware(&bcm->initvals0, buf, &bcm->pci_dev->dev);
1987 if (err) {
1988 printk(KERN_ERR PFX
1989 "Error: InitVals \"%s\" not available or load failed.\n",
1990 buf);
1991 goto error;
1992 }
1993 if (bcm->initvals0->size % sizeof(struct bcm43xx_initval)) {
1994 printk(KERN_ERR PFX "InitVals fileformat error.\n");
1995 goto error;
1996 }
1997 }
1998
1999 if (!bcm->initvals1) {
2000 if (rev >= 5) {
2001 u32 sbtmstatehigh;
2002
2003 switch (phy->type) {
2004 case BCM43xx_PHYTYPE_A:
2005 sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
2006 if (sbtmstatehigh & 0x00010000)
2007 nr = 9;
2008 else
2009 nr = 10;
2010 break;
2011 case BCM43xx_PHYTYPE_B:
2012 case BCM43xx_PHYTYPE_G:
2013 nr = 6;
2014 break;
2015 default:
2016 goto err_noinitval;
2017 }
2018 snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
2019 nr, modparam_fwpostfix);
2020
2021 err = request_firmware(&bcm->initvals1, buf, &bcm->pci_dev->dev);
2022 if (err) {
2023 printk(KERN_ERR PFX
2024 "Error: InitVals \"%s\" not available or load failed.\n",
2025 buf);
2026 goto error;
2027 }
2028 if (bcm->initvals1->size % sizeof(struct bcm43xx_initval)) {
2029 printk(KERN_ERR PFX "InitVals fileformat error.\n");
2030 goto error;
2031 }
2032 }
2033 }
2034
2035out:
2036 return err;
2037error:
2038 bcm43xx_release_firmware(bcm, 1);
2039 goto out;
2040err_noinitval:
2041 printk(KERN_ERR PFX "Error: No InitVals available!\n");
2042 err = -ENOENT;
2043 goto error;
2044}
2045
2046static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
2047{
2048 const u32 *data;
2049 unsigned int i, len;
2050
2051 /* Upload Microcode. */
2052 data = (u32 *)(bcm->ucode->data);
2053 len = bcm->ucode->size / sizeof(u32);
2054 bcm43xx_shm_control_word(bcm, BCM43xx_SHM_UCODE, 0x0000);
2055 for (i = 0; i < len; i++) {
2056 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
2057 be32_to_cpu(data[i]));
2058 udelay(10);
2059 }
2060
2061 /* Upload PCM data. */
2062 data = (u32 *)(bcm->pcm->data);
2063 len = bcm->pcm->size / sizeof(u32);
2064 bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01ea);
2065 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, 0x00004000);
2066 bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01eb);
2067 for (i = 0; i < len; i++) {
2068 bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
2069 be32_to_cpu(data[i]));
2070 udelay(10);
2071 }
2072}
2073
2074static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
2075 const struct bcm43xx_initval *data,
2076 const unsigned int len)
2077{
2078 u16 offset, size;
2079 u32 value;
2080 unsigned int i;
2081
2082 for (i = 0; i < len; i++) {
2083 offset = be16_to_cpu(data[i].offset);
2084 size = be16_to_cpu(data[i].size);
2085 value = be32_to_cpu(data[i].value);
2086
2087 if (unlikely(offset >= 0x1000))
2088 goto err_format;
2089 if (size == 2) {
2090 if (unlikely(value & 0xFFFF0000))
2091 goto err_format;
2092 bcm43xx_write16(bcm, offset, (u16)value);
2093 } else if (size == 4) {
2094 bcm43xx_write32(bcm, offset, value);
2095 } else
2096 goto err_format;
2097 }
2098
2099 return 0;
2100
2101err_format:
2102 printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
2103 "Please fix your bcm43xx firmware files.\n");
2104 return -EPROTO;
2105}
2106
2107static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
2108{
2109 int err;
2110
2111 err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals0->data,
2112 bcm->initvals0->size / sizeof(struct bcm43xx_initval));
2113 if (err)
2114 goto out;
2115 if (bcm->initvals1) {
2116 err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals1->data,
2117 bcm->initvals1->size / sizeof(struct bcm43xx_initval));
2118 if (err)
2119 goto out;
2120 }
2121out:
2122 return err;
2123}
2124
2125static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
2126{
2127 int res;
2128 unsigned int i;
2129 u32 data;
2130
2131 bcm->irq = bcm->pci_dev->irq;
2132#ifdef CONFIG_BCM947XX
2133 if (bcm->pci_dev->bus->number == 0) {
2134 struct pci_dev *d = NULL;
2135 /* FIXME: we will probably need more device IDs here... */
2136 d = pci_find_device(PCI_VENDOR_ID_BROADCOM, 0x4324, NULL);
2137 if (d != NULL) {
2138 bcm->irq = d->irq;
2139 }
2140 }
2141#endif
2142 res = request_irq(bcm->irq, bcm43xx_interrupt_handler,
2143 SA_SHIRQ, KBUILD_MODNAME, bcm);
2144 if (res) {
2145 printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
2146 return -ENODEV;
2147 }
2148 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xffffffff);
2149 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
2150 i = 0;
2151 while (1) {
2152 data = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2153 if (data == BCM43xx_IRQ_READY)
2154 break;
2155 i++;
2156 if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
2157 printk(KERN_ERR PFX "Card IRQ register not responding. "
2158 "Giving up.\n");
2159 free_irq(bcm->irq, bcm);
2160 return -ENODEV;
2161 }
2162 udelay(10);
2163 }
2164 // dummy read
2165 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2166
2167 return 0;
2168}
2169
2170/* Switch to the core used to write the GPIO register.
2171 * This is either the ChipCommon, or the PCI core.
2172 */
2173static int switch_to_gpio_core(struct bcm43xx_private *bcm)
2174{
2175 int err;
2176
2177 /* Where to find the GPIO register depends on the chipset.
2178 * If it has a ChipCommon, its register at offset 0x6c is the GPIO
2179 * control register. Otherwise the register at offset 0x6c in the
2180 * PCI core is the GPIO control register.
2181 */
2182 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
2183 if (err == -ENODEV) {
2184 err = bcm43xx_switch_core(bcm, &bcm->core_pci);
2185 if (unlikely(err == -ENODEV)) {
2186 printk(KERN_ERR PFX "gpio error: "
2187 "Neither ChipCommon nor PCI core available!\n");
2188 }
2189 }
2190
2191 return err;
2192}
2193
2194/* Initialize the GPIOs
2195 * http://bcm-specs.sipsolutions.net/GPIO
2196 */
2197static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
2198{
2199 struct bcm43xx_coreinfo *old_core;
2200 int err;
2201 u32 mask, set;
2202
2203 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2204 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
2205 & 0xFFFF3FFF);
2206
2207 bcm43xx_leds_switch_all(bcm, 0);
2208 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
2209 bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
2210
2211 mask = 0x0000001F;
2212 set = 0x0000000F;
2213 if (bcm->chip_id == 0x4301) {
2214 mask |= 0x0060;
2215 set |= 0x0060;
2216 }
2217 if (0 /* FIXME: conditional unknown */) {
2218 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
2219 bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
2220 | 0x0100);
2221 mask |= 0x0180;
2222 set |= 0x0180;
2223 }
2224 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
2225 bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
2226 bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
2227 | 0x0200);
2228 mask |= 0x0200;
2229 set |= 0x0200;
2230 }
2231 if (bcm->current_core->rev >= 2)
2232 mask |= 0x0010; /* FIXME: This is redundant. */
2233
2234 old_core = bcm->current_core;
2235 err = switch_to_gpio_core(bcm);
2236 if (err)
2237 goto out;
2238 bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
2239 (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
2240 err = bcm43xx_switch_core(bcm, old_core);
2241out:
2242 return err;
2243}
2244
2245/* Turn off all GPIO stuff. Call this on module unload, for example. */
2246static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
2247{
2248 struct bcm43xx_coreinfo *old_core;
2249 int err;
2250
2251 old_core = bcm->current_core;
2252 err = switch_to_gpio_core(bcm);
2253 if (err)
2254 return err;
2255 bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
2256 err = bcm43xx_switch_core(bcm, old_core);
2257 assert(err == 0);
2258
2259 return 0;
2260}
2261
2262/* http://bcm-specs.sipsolutions.net/EnableMac */
2263void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
2264{
2265 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2266 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
2267 | BCM43xx_SBF_MAC_ENABLED);
2268 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, BCM43xx_IRQ_READY);
2269 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
2270 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
2271 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
2272}
2273
2274/* http://bcm-specs.sipsolutions.net/SuspendMAC */
2275void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
2276{
2277 int i;
2278 u32 tmp;
2279
2280 bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
2281 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2282 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
2283 & ~BCM43xx_SBF_MAC_ENABLED);
2284 bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
2285 for (i = 100000; i; i--) {
2286 tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2287 if (tmp & BCM43xx_IRQ_READY)
2288 return;
2289 udelay(10);
2290 }
2291 printkl(KERN_ERR PFX "MAC suspend failed\n");
2292}
2293
2294void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
2295 int iw_mode)
2296{
2297 unsigned long flags;
2298 struct net_device *net_dev = bcm->net_dev;
2299 u32 status;
2300 u16 value;
2301
2302 spin_lock_irqsave(&bcm->ieee->lock, flags);
2303 bcm->ieee->iw_mode = iw_mode;
2304 spin_unlock_irqrestore(&bcm->ieee->lock, flags);
2305 if (iw_mode == IW_MODE_MONITOR)
2306 net_dev->type = ARPHRD_IEEE80211;
2307 else
2308 net_dev->type = ARPHRD_ETHER;
2309
2310 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2311 /* Reset status to infrastructured mode */
2312 status &= ~(BCM43xx_SBF_MODE_AP | BCM43xx_SBF_MODE_MONITOR);
2313 status &= ~BCM43xx_SBF_MODE_PROMISC;
2314 status |= BCM43xx_SBF_MODE_NOTADHOC;
2315
2316/* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
2317status |= BCM43xx_SBF_MODE_PROMISC;
2318
2319 switch (iw_mode) {
2320 case IW_MODE_MONITOR:
2321 status |= BCM43xx_SBF_MODE_MONITOR;
2322 status |= BCM43xx_SBF_MODE_PROMISC;
2323 break;
2324 case IW_MODE_ADHOC:
2325 status &= ~BCM43xx_SBF_MODE_NOTADHOC;
2326 break;
2327 case IW_MODE_MASTER:
2328 status |= BCM43xx_SBF_MODE_AP;
2329 break;
2330 case IW_MODE_SECOND:
2331 case IW_MODE_REPEAT:
2332 TODO(); /* TODO */
2333 break;
2334 case IW_MODE_INFRA:
2335 /* nothing to be done here... */
2336 break;
2337 default:
2338 dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
2339 }
2340 if (net_dev->flags & IFF_PROMISC)
2341 status |= BCM43xx_SBF_MODE_PROMISC;
2342 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
2343
2344 value = 0x0002;
2345 if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
2346 if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
2347 value = 0x0064;
2348 else
2349 value = 0x0032;
2350 }
2351 bcm43xx_write16(bcm, 0x0612, value);
2352}
2353
2354/* This is the opposite of bcm43xx_chip_init() */
2355static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
2356{
2357 bcm43xx_radio_turn_off(bcm);
2358 if (!modparam_noleds)
2359 bcm43xx_leds_exit(bcm);
2360 bcm43xx_gpio_cleanup(bcm);
2361 free_irq(bcm->irq, bcm);
2362 bcm43xx_release_firmware(bcm, 0);
2363}
2364
2365/* Initialize the chip
2366 * http://bcm-specs.sipsolutions.net/ChipInit
2367 */
2368static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
2369{
2370 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2371 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2372 int err;
2373 int tmp;
2374 u32 value32;
2375 u16 value16;
2376
2377 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
2378 BCM43xx_SBF_CORE_READY
2379 | BCM43xx_SBF_400);
2380
2381 err = bcm43xx_request_firmware(bcm);
2382 if (err)
2383 goto out;
2384 bcm43xx_upload_microcode(bcm);
2385
2386 err = bcm43xx_initialize_irq(bcm);
2387 if (err)
2388 goto err_release_fw;
2389
2390 err = bcm43xx_gpio_init(bcm);
2391 if (err)
2392 goto err_free_irq;
2393
2394 err = bcm43xx_upload_initvals(bcm);
2395 if (err)
2396 goto err_gpio_cleanup;
2397 bcm43xx_radio_turn_on(bcm);
2398
2399 bcm43xx_write16(bcm, 0x03E6, 0x0000);
2400 err = bcm43xx_phy_init(bcm);
2401 if (err)
2402 goto err_radio_off;
2403
2404 /* Select initial Interference Mitigation. */
2405 tmp = radio->interfmode;
2406 radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
2407 bcm43xx_radio_set_interference_mitigation(bcm, tmp);
2408
2409 bcm43xx_phy_set_antenna_diversity(bcm);
2410 bcm43xx_radio_set_txantenna(bcm, BCM43xx_RADIO_TXANTENNA_DEFAULT);
2411 if (phy->type == BCM43xx_PHYTYPE_B) {
2412 value16 = bcm43xx_read16(bcm, 0x005E);
2413 value16 |= 0x0004;
2414 bcm43xx_write16(bcm, 0x005E, value16);
2415 }
2416 bcm43xx_write32(bcm, 0x0100, 0x01000000);
2417 if (bcm->current_core->rev < 5)
2418 bcm43xx_write32(bcm, 0x010C, 0x01000000);
2419
2420 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2421 value32 &= ~ BCM43xx_SBF_MODE_NOTADHOC;
2422 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
2423 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2424 value32 |= BCM43xx_SBF_MODE_NOTADHOC;
2425 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
2426
2427 value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2428 value32 |= 0x100000;
2429 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
2430
2431 if (bcm43xx_using_pio(bcm)) {
2432 bcm43xx_write32(bcm, 0x0210, 0x00000100);
2433 bcm43xx_write32(bcm, 0x0230, 0x00000100);
2434 bcm43xx_write32(bcm, 0x0250, 0x00000100);
2435 bcm43xx_write32(bcm, 0x0270, 0x00000100);
2436 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0034, 0x0000);
2437 }
2438
2439 /* Probe Response Timeout value */
2440 /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
2441 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0074, 0x0000);
2442
2443 /* Initially set the wireless operation mode. */
2444 bcm43xx_set_iwmode(bcm, bcm->ieee->iw_mode);
2445
2446 if (bcm->current_core->rev < 3) {
2447 bcm43xx_write16(bcm, 0x060E, 0x0000);
2448 bcm43xx_write16(bcm, 0x0610, 0x8000);
2449 bcm43xx_write16(bcm, 0x0604, 0x0000);
2450 bcm43xx_write16(bcm, 0x0606, 0x0200);
2451 } else {
2452 bcm43xx_write32(bcm, 0x0188, 0x80000000);
2453 bcm43xx_write32(bcm, 0x018C, 0x02000000);
2454 }
2455 bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0x00004000);
2456 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_IRQ_MASK, 0x0001DC00);
2457 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
2458 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_IRQ_MASK, 0x0000DC00);
2459 bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_IRQ_MASK, 0x0001DC00);
2460
2461 value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
2462 value32 |= 0x00100000;
2463 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
2464
2465 bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
2466
2467 assert(err == 0);
2468 dprintk(KERN_INFO PFX "Chip initialized\n");
2469out:
2470 return err;
2471
2472err_radio_off:
2473 bcm43xx_radio_turn_off(bcm);
2474err_gpio_cleanup:
2475 bcm43xx_gpio_cleanup(bcm);
2476err_free_irq:
2477 free_irq(bcm->irq, bcm);
2478err_release_fw:
2479 bcm43xx_release_firmware(bcm, 1);
2480 goto out;
2481}
2482
2483/* Validate chip access
2484 * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
2485static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
2486{
2487 u32 value;
2488 u32 shm_backup;
2489
2490 shm_backup = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000);
2491 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0xAA5555AA);
2492 if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0xAA5555AA)
2493 goto error;
2494 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
2495 if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
2496 goto error;
2497 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
2498
2499 value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
2500 if ((value | 0x80000000) != 0x80000400)
2501 goto error;
2502
2503 value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
2504 if (value != 0x00000000)
2505 goto error;
2506
2507 return 0;
2508error:
2509 printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
2510 return -ENODEV;
2511}
2512
2513static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
2514{
2515 /* Initialize a "phyinfo" structure. The structure is already
2516 * zeroed out.
2517 */
2518 phy->antenna_diversity = 0xFFFF;
2519 phy->savedpctlreg = 0xFFFF;
2520 phy->minlowsig[0] = 0xFFFF;
2521 phy->minlowsig[1] = 0xFFFF;
2522 spin_lock_init(&phy->lock);
2523}
2524
2525static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
2526{
2527 /* Initialize a "radioinfo" structure. The structure is already
2528 * zeroed out.
2529 */
2530 radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
2531 radio->channel = 0xFF;
2532 radio->initial_channel = 0xFF;
2533 radio->lofcal = 0xFFFF;
2534 radio->initval = 0xFFFF;
2535 radio->nrssi[0] = -1000;
2536 radio->nrssi[1] = -1000;
2537}
2538
2539static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
2540{
2541 int err, i;
2542 int current_core;
2543 u32 core_vendor, core_id, core_rev;
2544 u32 sb_id_hi, chip_id_32 = 0;
2545 u16 pci_device, chip_id_16;
2546 u8 core_count;
2547
2548 memset(&bcm->core_chipcommon, 0, sizeof(struct bcm43xx_coreinfo));
2549 memset(&bcm->core_pci, 0, sizeof(struct bcm43xx_coreinfo));
2550 memset(&bcm->core_80211, 0, sizeof(struct bcm43xx_coreinfo)
2551 * BCM43xx_MAX_80211_CORES);
2552 memset(&bcm->core_80211_ext, 0, sizeof(struct bcm43xx_coreinfo_80211)
2553 * BCM43xx_MAX_80211_CORES);
2554 bcm->current_80211_core_idx = -1;
2555 bcm->nr_80211_available = 0;
2556 bcm->current_core = NULL;
2557 bcm->active_80211_core = NULL;
2558
2559 /* map core 0 */
2560 err = _switch_core(bcm, 0);
2561 if (err)
2562 goto out;
2563
2564 /* fetch sb_id_hi from core information registers */
2565 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
2566
2567 core_id = (sb_id_hi & 0xFFF0) >> 4;
2568 core_rev = (sb_id_hi & 0xF);
2569 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
2570
2571 /* if present, chipcommon is always core 0; read the chipid from it */
2572 if (core_id == BCM43xx_COREID_CHIPCOMMON) {
2573 chip_id_32 = bcm43xx_read32(bcm, 0);
2574 chip_id_16 = chip_id_32 & 0xFFFF;
2575 bcm->core_chipcommon.available = 1;
2576 bcm->core_chipcommon.id = core_id;
2577 bcm->core_chipcommon.rev = core_rev;
2578 bcm->core_chipcommon.index = 0;
2579 /* While we are at it, also read the capabilities. */
2580 bcm->chipcommon_capabilities = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_CAPABILITIES);
2581 } else {
2582 /* without a chipCommon, use a hard coded table. */
2583 pci_device = bcm->pci_dev->device;
2584 if (pci_device == 0x4301)
2585 chip_id_16 = 0x4301;
2586 else if ((pci_device >= 0x4305) && (pci_device <= 0x4307))
2587 chip_id_16 = 0x4307;
2588 else if ((pci_device >= 0x4402) && (pci_device <= 0x4403))
2589 chip_id_16 = 0x4402;
2590 else if ((pci_device >= 0x4610) && (pci_device <= 0x4615))
2591 chip_id_16 = 0x4610;
2592 else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
2593 chip_id_16 = 0x4710;
2594#ifdef CONFIG_BCM947XX
2595 else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
2596 chip_id_16 = 0x4309;
2597#endif
2598 else {
2599 printk(KERN_ERR PFX "Could not determine Chip ID\n");
2600 return -ENODEV;
2601 }
2602 }
2603
2604 /* ChipCommon with Core Rev >=4 encodes number of cores,
2605 * otherwise consult hardcoded table */
2606 if ((core_id == BCM43xx_COREID_CHIPCOMMON) && (core_rev >= 4)) {
2607 core_count = (chip_id_32 & 0x0F000000) >> 24;
2608 } else {
2609 switch (chip_id_16) {
2610 case 0x4610:
2611 case 0x4704:
2612 case 0x4710:
2613 core_count = 9;
2614 break;
2615 case 0x4310:
2616 core_count = 8;
2617 break;
2618 case 0x5365:
2619 core_count = 7;
2620 break;
2621 case 0x4306:
2622 core_count = 6;
2623 break;
2624 case 0x4301:
2625 case 0x4307:
2626 core_count = 5;
2627 break;
2628 case 0x4402:
2629 core_count = 3;
2630 break;
2631 default:
2632 /* SOL if we get here */
2633 assert(0);
2634 core_count = 1;
2635 }
2636 }
2637
2638 bcm->chip_id = chip_id_16;
2639 bcm->chip_rev = (chip_id_32 & 0x000F0000) >> 16;
2640 bcm->chip_package = (chip_id_32 & 0x00F00000) >> 20;
2641
2642 dprintk(KERN_INFO PFX "Chip ID 0x%x, rev 0x%x\n",
2643 bcm->chip_id, bcm->chip_rev);
2644 dprintk(KERN_INFO PFX "Number of cores: %d\n", core_count);
2645 if (bcm->core_chipcommon.available) {
2646 dprintk(KERN_INFO PFX "Core 0: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
2647 core_id, core_rev, core_vendor,
2648 bcm43xx_core_enabled(bcm) ? "enabled" : "disabled");
2649 }
2650
2651 if (bcm->core_chipcommon.available)
2652 current_core = 1;
2653 else
2654 current_core = 0;
2655 for ( ; current_core < core_count; current_core++) {
2656 struct bcm43xx_coreinfo *core;
2657 struct bcm43xx_coreinfo_80211 *ext_80211;
2658
2659 err = _switch_core(bcm, current_core);
2660 if (err)
2661 goto out;
2662 /* Gather information */
2663 /* fetch sb_id_hi from core information registers */
2664 sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
2665
2666 /* extract core_id, core_rev, core_vendor */
2667 core_id = (sb_id_hi & 0xFFF0) >> 4;
2668 core_rev = (sb_id_hi & 0xF);
2669 core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
2670
2671 dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
2672 current_core, core_id, core_rev, core_vendor,
2673 bcm43xx_core_enabled(bcm) ? "enabled" : "disabled" );
2674
2675 core = NULL;
2676 switch (core_id) {
2677 case BCM43xx_COREID_PCI:
2678 core = &bcm->core_pci;
2679 if (core->available) {
2680 printk(KERN_WARNING PFX "Multiple PCI cores found.\n");
2681 continue;
2682 }
2683 break;
2684 case BCM43xx_COREID_80211:
2685 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
2686 core = &(bcm->core_80211[i]);
2687 ext_80211 = &(bcm->core_80211_ext[i]);
2688 if (!core->available)
2689 break;
2690 core = NULL;
2691 }
2692 if (!core) {
2693 printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
2694 BCM43xx_MAX_80211_CORES);
2695 continue;
2696 }
2697 if (i != 0) {
2698 /* More than one 80211 core is only supported
2699 * by special chips.
2700 * There are chips with two 80211 cores, but with
2701 * dangling pins on the second core. Be careful
2702 * and ignore these cores here.
2703 */
2704 if (bcm->pci_dev->device != 0x4324) {
2705 dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
2706 continue;
2707 }
2708 }
2709 switch (core_rev) {
2710 case 2:
2711 case 4:
2712 case 5:
2713 case 6:
2714 case 7:
2715 case 9:
2716 break;
2717 default:
2718 printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
2719 core_rev);
2720 err = -ENODEV;
2721 goto out;
2722 }
2723 bcm->nr_80211_available++;
2724 bcm43xx_init_struct_phyinfo(&ext_80211->phy);
2725 bcm43xx_init_struct_radioinfo(&ext_80211->radio);
2726 break;
2727 case BCM43xx_COREID_CHIPCOMMON:
2728 printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
2729 break;
2730 }
2731 if (core) {
2732 core->available = 1;
2733 core->id = core_id;
2734 core->rev = core_rev;
2735 core->index = current_core;
2736 }
2737 }
2738
2739 if (!bcm->core_80211[0].available) {
2740 printk(KERN_ERR PFX "Error: No 80211 core found!\n");
2741 err = -ENODEV;
2742 goto out;
2743 }
2744
2745 err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
2746
2747 assert(err == 0);
2748out:
2749 return err;
2750}
2751
2752static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
2753{
2754 const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
2755 u8 *bssid = bcm->ieee->bssid;
2756
2757 switch (bcm->ieee->iw_mode) {
2758 case IW_MODE_ADHOC:
2759 random_ether_addr(bssid);
2760 break;
2761 case IW_MODE_MASTER:
2762 case IW_MODE_INFRA:
2763 case IW_MODE_REPEAT:
2764 case IW_MODE_SECOND:
2765 case IW_MODE_MONITOR:
2766 memcpy(bssid, mac, ETH_ALEN);
2767 break;
2768 default:
2769 assert(0);
2770 }
2771}
2772
2773static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
2774 u16 rate,
2775 int is_ofdm)
2776{
2777 u16 offset;
2778
2779 if (is_ofdm) {
2780 offset = 0x480;
2781 offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
2782 }
2783 else {
2784 offset = 0x4C0;
2785 offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
2786 }
2787 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
2788 bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
2789}
2790
2791static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
2792{
2793 switch (bcm43xx_current_phy(bcm)->type) {
2794 case BCM43xx_PHYTYPE_A:
2795 case BCM43xx_PHYTYPE_G:
2796 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_6MB, 1);
2797 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_12MB, 1);
2798 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_18MB, 1);
2799 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_24MB, 1);
2800 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_36MB, 1);
2801 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_48MB, 1);
2802 bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_54MB, 1);
2803 case BCM43xx_PHYTYPE_B:
2804 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_1MB, 0);
2805 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_2MB, 0);
2806 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_5MB, 0);
2807 bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_11MB, 0);
2808 break;
2809 default:
2810 assert(0);
2811 }
2812}
2813
2814static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
2815{
2816 bcm43xx_chip_cleanup(bcm);
2817 bcm43xx_pio_free(bcm);
2818 bcm43xx_dma_free(bcm);
2819
2820 bcm->current_core->initialized = 0;
2821}
2822
2823/* http://bcm-specs.sipsolutions.net/80211Init */
2824static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm)
2825{
2826 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2827 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2828 u32 ucodeflags;
2829 int err;
2830 u32 sbimconfiglow;
2831 u8 limit;
2832
2833 if (bcm->chip_rev < 5) {
2834 sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
2835 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
2836 sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
2837 if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
2838 sbimconfiglow |= 0x32;
2839 else if (bcm->bustype == BCM43xx_BUSTYPE_SB)
2840 sbimconfiglow |= 0x53;
2841 else
2842 assert(0);
2843 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
2844 }
2845
2846 bcm43xx_phy_calibrate(bcm);
2847 err = bcm43xx_chip_init(bcm);
2848 if (err)
2849 goto out;
2850
2851 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0016, bcm->current_core->rev);
2852 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, BCM43xx_UCODEFLAGS_OFFSET);
2853
2854 if (0 /*FIXME: which condition has to be used here? */)
2855 ucodeflags |= 0x00000010;
2856
2857 /* HW decryption needs to be set now */
2858 ucodeflags |= 0x40000000;
2859
2860 if (phy->type == BCM43xx_PHYTYPE_G) {
2861 ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
2862 if (phy->rev == 1)
2863 ucodeflags |= BCM43xx_UCODEFLAG_UNKGPHY;
2864 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
2865 ucodeflags |= BCM43xx_UCODEFLAG_UNKPACTRL;
2866 } else if (phy->type == BCM43xx_PHYTYPE_B) {
2867 ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
2868 if (phy->rev >= 2 && radio->version == 0x2050)
2869 ucodeflags &= ~BCM43xx_UCODEFLAG_UNKGPHY;
2870 }
2871
2872 if (ucodeflags != bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2873 BCM43xx_UCODEFLAGS_OFFSET)) {
2874 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2875 BCM43xx_UCODEFLAGS_OFFSET, ucodeflags);
2876 }
2877
2878 /* Short/Long Retry Limit.
2879 * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
2880 * the chip-internal counter.
2881 */
2882 limit = limit_value(modparam_short_retry, 0, 0xF);
2883 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0006, limit);
2884 limit = limit_value(modparam_long_retry, 0, 0xF);
2885 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0007, limit);
2886
2887 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
2888 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
2889
2890 bcm43xx_rate_memory_init(bcm);
2891
2892 /* Minimum Contention Window */
2893 if (phy->type == BCM43xx_PHYTYPE_B)
2894 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
2895 else
2896 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
2897 /* Maximum Contention Window */
2898 bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
2899
2900 bcm43xx_gen_bssid(bcm);
2901 bcm43xx_write_mac_bssid_templates(bcm);
2902
2903 if (bcm->current_core->rev >= 5)
2904 bcm43xx_write16(bcm, 0x043C, 0x000C);
2905
2906 if (bcm43xx_using_pio(bcm))
2907 err = bcm43xx_pio_init(bcm);
2908 else
2909 err = bcm43xx_dma_init(bcm);
2910 if (err)
2911 goto err_chip_cleanup;
2912 bcm43xx_write16(bcm, 0x0612, 0x0050);
2913 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0416, 0x0050);
2914 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0414, 0x01F4);
2915
2916 bcm43xx_mac_enable(bcm);
2917 bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
2918
2919 bcm->current_core->initialized = 1;
2920out:
2921 return err;
2922
2923err_chip_cleanup:
2924 bcm43xx_chip_cleanup(bcm);
2925 goto out;
2926}
2927
2928static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
2929{
2930 int err;
2931 u16 pci_status;
2932
2933 err = bcm43xx_pctl_set_crystal(bcm, 1);
2934 if (err)
2935 goto out;
2936 bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
2937 bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
2938
2939out:
2940 return err;
2941}
2942
2943static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
2944{
2945 bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
2946 bcm43xx_pctl_set_crystal(bcm, 0);
2947}
2948
2949static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
2950 u32 address,
2951 u32 data)
2952{
2953 bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
2954 bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
2955}
2956
2957static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
2958{
2959 int err;
2960 struct bcm43xx_coreinfo *old_core;
2961
2962 old_core = bcm->current_core;
2963 err = bcm43xx_switch_core(bcm, &bcm->core_pci);
2964 if (err)
2965 goto out;
2966
2967 bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
2968
2969 bcm43xx_switch_core(bcm, old_core);
2970 assert(err == 0);
2971out:
2972 return err;
2973}
2974
2975/* Make an I/O Core usable. "core_mask" is the bitmask of the cores to enable.
2976 * To enable core 0, pass a core_mask of 1<<0
2977 */
2978static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
2979 u32 core_mask)
2980{
2981 u32 backplane_flag_nr;
2982 u32 value;
2983 struct bcm43xx_coreinfo *old_core;
2984 int err = 0;
2985
2986 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
2987 backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
2988
2989 old_core = bcm->current_core;
2990 err = bcm43xx_switch_core(bcm, &bcm->core_pci);
2991 if (err)
2992 goto out;
2993
2994 if (bcm->core_pci.rev < 6) {
2995 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
2996 value |= (1 << backplane_flag_nr);
2997 bcm43xx_write32(bcm, BCM43xx_CIR_SBINTVEC, value);
2998 } else {
2999 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
3000 if (err) {
3001 printk(KERN_ERR PFX "Error: ICR setup failure!\n");
3002 goto out_switch_back;
3003 }
3004 value |= core_mask << 8;
3005 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
3006 if (err) {
3007 printk(KERN_ERR PFX "Error: ICR setup failure!\n");
3008 goto out_switch_back;
3009 }
3010 }
3011
3012 value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
3013 value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
3014 bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
3015
3016 if (bcm->core_pci.rev < 5) {
3017 value = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
3018 value |= (2 << BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT)
3019 & BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
3020 value |= (3 << BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT)
3021 & BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
3022 bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, value);
3023 err = bcm43xx_pcicore_commit_settings(bcm);
3024 assert(err == 0);
3025 }
3026
3027out_switch_back:
3028 err = bcm43xx_switch_core(bcm, old_core);
3029out:
3030 return err;
3031}
3032
3033static void bcm43xx_softmac_init(struct bcm43xx_private *bcm)
3034{
3035 ieee80211softmac_start(bcm->net_dev);
3036}
3037
3038static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
3039{
3040 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3041
3042 if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
3043 return;
3044
3045 bcm43xx_mac_suspend(bcm);
3046 bcm43xx_phy_lo_g_measure(bcm);
3047 bcm43xx_mac_enable(bcm);
3048}
3049
3050static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
3051{
3052 bcm43xx_phy_lo_mark_all_unused(bcm);
3053 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
3054 bcm43xx_mac_suspend(bcm);
3055 bcm43xx_calc_nrssi_slope(bcm);
3056 bcm43xx_mac_enable(bcm);
3057 }
3058}
3059
3060static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
3061{
3062 /* Update device statistics. */
3063 bcm43xx_calculate_link_quality(bcm);
3064}
3065
3066static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
3067{
3068 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3069 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
3070
3071 if (phy->type == BCM43xx_PHYTYPE_G) {
3072 //TODO: update_aci_moving_average
3073 if (radio->aci_enable && radio->aci_wlan_automatic) {
3074 bcm43xx_mac_suspend(bcm);
3075 if (!radio->aci_enable && 1 /*TODO: not scanning? */) {
3076 if (0 /*TODO: bunch of conditions*/) {
3077 bcm43xx_radio_set_interference_mitigation(bcm,
3078 BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
3079 }
3080 } else if (1/*TODO*/) {
3081 /*
3082 if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
3083 bcm43xx_radio_set_interference_mitigation(bcm,
3084 BCM43xx_RADIO_INTERFMODE_NONE);
3085 }
3086 */
3087 }
3088 bcm43xx_mac_enable(bcm);
3089 } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
3090 phy->rev == 1) {
3091 //TODO: implement rev1 workaround
3092 }
3093 }
3094 bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
3095 //TODO for APHY (temperature?)
3096}
3097
3098static void bcm43xx_periodic_task_handler(unsigned long d)
3099{
3100 struct bcm43xx_private *bcm = (struct bcm43xx_private *)d;
3101 unsigned long flags;
3102 unsigned int state;
3103
3104 bcm43xx_lock_mmio(bcm, flags);
3105
3106 assert(bcm->initialized);
3107 state = bcm->periodic_state;
3108 if (state % 8 == 0)
3109 bcm43xx_periodic_every120sec(bcm);
3110 if (state % 4 == 0)
3111 bcm43xx_periodic_every60sec(bcm);
3112 if (state % 2 == 0)
3113 bcm43xx_periodic_every30sec(bcm);
3114 bcm43xx_periodic_every15sec(bcm);
3115 bcm->periodic_state = state + 1;
3116
3117 mod_timer(&bcm->periodic_tasks, jiffies + (HZ * 15));
3118
3119 bcm43xx_unlock_mmio(bcm, flags);
3120}
3121
3122static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
3123{
3124 del_timer_sync(&bcm->periodic_tasks);
3125}
3126
3127static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
3128{
3129 struct timer_list *timer = &(bcm->periodic_tasks);
3130
3131 assert(bcm->initialized);
3132 setup_timer(timer,
3133 bcm43xx_periodic_task_handler,
3134 (unsigned long)bcm);
3135 timer->expires = jiffies;
3136 add_timer(timer);
3137}
3138
3139static void bcm43xx_security_init(struct bcm43xx_private *bcm)
3140{
3141 bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
3142 0x0056) * 2;
3143 bcm43xx_clear_keys(bcm);
3144}
3145
3146/* This is the opposite of bcm43xx_init_board() */
3147static void bcm43xx_free_board(struct bcm43xx_private *bcm)
3148{
3149 int i, err;
3150 unsigned long flags;
3151
3152 bcm43xx_sysfs_unregister(bcm);
3153
3154 bcm43xx_periodic_tasks_delete(bcm);
3155
3156 bcm43xx_lock(bcm, flags);
3157 bcm->initialized = 0;
3158 bcm->shutting_down = 1;
3159 bcm43xx_unlock(bcm, flags);
3160
3161 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
3162 if (!bcm->core_80211[i].available)
3163 continue;
3164 if (!bcm->core_80211[i].initialized)
3165 continue;
3166
3167 err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
3168 assert(err == 0);
3169 bcm43xx_wireless_core_cleanup(bcm);
3170 }
3171
3172 bcm43xx_pctl_set_crystal(bcm, 0);
3173
3174 bcm43xx_lock(bcm, flags);
3175 bcm->shutting_down = 0;
3176 bcm43xx_unlock(bcm, flags);
3177}
3178
3179static int bcm43xx_init_board(struct bcm43xx_private *bcm)
3180{
3181 int i, err;
3182 int connect_phy;
3183 unsigned long flags;
3184
3185 might_sleep();
3186
3187 bcm43xx_lock(bcm, flags);
3188 bcm->initialized = 0;
3189 bcm->shutting_down = 0;
3190 bcm43xx_unlock(bcm, flags);
3191
3192 err = bcm43xx_pctl_set_crystal(bcm, 1);
3193 if (err)
3194 goto out;
3195 err = bcm43xx_pctl_init(bcm);
3196 if (err)
3197 goto err_crystal_off;
3198 err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
3199 if (err)
3200 goto err_crystal_off;
3201
3202 tasklet_enable(&bcm->isr_tasklet);
3203 for (i = 0; i < bcm->nr_80211_available; i++) {
3204 err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
3205 assert(err != -ENODEV);
3206 if (err)
3207 goto err_80211_unwind;
3208
3209 /* Enable the selected wireless core.
3210 * Connect PHY only on the first core.
3211 */
3212 if (!bcm43xx_core_enabled(bcm)) {
3213 if (bcm->nr_80211_available == 1) {
3214 connect_phy = bcm43xx_current_phy(bcm)->connected;
3215 } else {
3216 if (i == 0)
3217 connect_phy = 1;
3218 else
3219 connect_phy = 0;
3220 }
3221 bcm43xx_wireless_core_reset(bcm, connect_phy);
3222 }
3223
3224 if (i != 0)
3225 bcm43xx_wireless_core_mark_inactive(bcm, &bcm->core_80211[0]);
3226
3227 err = bcm43xx_wireless_core_init(bcm);
3228 if (err)
3229 goto err_80211_unwind;
3230
3231 if (i != 0) {
3232 bcm43xx_mac_suspend(bcm);
3233 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
3234 bcm43xx_radio_turn_off(bcm);
3235 }
3236 }
3237 bcm->active_80211_core = &bcm->core_80211[0];
3238 if (bcm->nr_80211_available >= 2) {
3239 bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
3240 bcm43xx_mac_enable(bcm);
3241 }
3242 bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
3243 bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr));
3244 dprintk(KERN_INFO PFX "80211 cores initialized\n");
3245 bcm43xx_security_init(bcm);
3246 bcm43xx_softmac_init(bcm);
3247
3248 bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
3249
3250 if (bcm43xx_current_radio(bcm)->initial_channel != 0xFF) {
3251 bcm43xx_mac_suspend(bcm);
3252 bcm43xx_radio_selectchannel(bcm, bcm43xx_current_radio(bcm)->initial_channel, 0);
3253 bcm43xx_mac_enable(bcm);
3254 }
3255
3256 /* Initialization of the board is done. Flag it as such. */
3257 bcm43xx_lock(bcm, flags);
3258 bcm->initialized = 1;
3259 bcm43xx_unlock(bcm, flags);
3260
3261 bcm43xx_periodic_tasks_setup(bcm);
3262 bcm43xx_sysfs_register(bcm);
3263 //FIXME: check for bcm43xx_sysfs_register failure. This function is a bit messy regarding unwinding, though...
3264
3265 assert(err == 0);
3266out:
3267 return err;
3268
3269err_80211_unwind:
3270 tasklet_disable(&bcm->isr_tasklet);
3271 /* unwind all 80211 initialization */
3272 for (i = 0; i < bcm->nr_80211_available; i++) {
3273 if (!bcm->core_80211[i].initialized)
3274 continue;
3275 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
3276 bcm43xx_wireless_core_cleanup(bcm);
3277 }
3278err_crystal_off:
3279 bcm43xx_pctl_set_crystal(bcm, 0);
3280 goto out;
3281}
3282
3283static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
3284{
3285 struct pci_dev *pci_dev = bcm->pci_dev;
3286 int i;
3287
3288 bcm43xx_chipset_detach(bcm);
3289 /* Do _not_ access the chip, after it is detached. */
3290 iounmap(bcm->mmio_addr);
3291
3292 pci_release_regions(pci_dev);
3293 pci_disable_device(pci_dev);
3294
3295 /* Free allocated structures/fields */
3296 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
3297 kfree(bcm->core_80211_ext[i].phy._lo_pairs);
3298 if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
3299 kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
3300 }
3301}
3302
3303static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
3304{
3305 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3306 u16 value;
3307 u8 phy_version;
3308 u8 phy_type;
3309 u8 phy_rev;
3310 int phy_rev_ok = 1;
3311 void *p;
3312
3313 value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
3314
3315 phy_version = (value & 0xF000) >> 12;
3316 phy_type = (value & 0x0F00) >> 8;
3317 phy_rev = (value & 0x000F);
3318
3319 dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
3320 phy_version, phy_type, phy_rev);
3321
3322 switch (phy_type) {
3323 case BCM43xx_PHYTYPE_A:
3324 if (phy_rev >= 4)
3325 phy_rev_ok = 0;
3326 /*FIXME: We need to switch the ieee->modulation, etc.. flags,
3327 * if we switch 80211 cores after init is done.
3328 * As we do not implement on the fly switching between
3329 * wireless cores, I will leave this as a future task.
3330 */
3331 bcm->ieee->modulation = IEEE80211_OFDM_MODULATION;
3332 bcm->ieee->mode = IEEE_A;
3333 bcm->ieee->freq_band = IEEE80211_52GHZ_BAND |
3334 IEEE80211_24GHZ_BAND;
3335 break;
3336 case BCM43xx_PHYTYPE_B:
3337 if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
3338 phy_rev_ok = 0;
3339 bcm->ieee->modulation = IEEE80211_CCK_MODULATION;
3340 bcm->ieee->mode = IEEE_B;
3341 bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
3342 break;
3343 case BCM43xx_PHYTYPE_G:
3344 if (phy_rev > 7)
3345 phy_rev_ok = 0;
3346 bcm->ieee->modulation = IEEE80211_OFDM_MODULATION |
3347 IEEE80211_CCK_MODULATION;
3348 bcm->ieee->mode = IEEE_G;
3349 bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
3350 break;
3351 default:
3352 printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
3353 phy_type);
3354 return -ENODEV;
3355 };
3356 if (!phy_rev_ok) {
3357 printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
3358 phy_rev);
3359 }
3360
3361 phy->version = phy_version;
3362 phy->type = phy_type;
3363 phy->rev = phy_rev;
3364 if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
3365 p = kzalloc(sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT,
3366 GFP_KERNEL);
3367 if (!p)
3368 return -ENOMEM;
3369 phy->_lo_pairs = p;
3370 }
3371
3372 return 0;
3373}
3374
3375static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
3376{
3377 struct pci_dev *pci_dev = bcm->pci_dev;
3378 struct net_device *net_dev = bcm->net_dev;
3379 int err;
3380 int i;
3381 unsigned long mmio_start, mmio_flags, mmio_len;
3382 u32 coremask;
3383
3384 err = pci_enable_device(pci_dev);
3385 if (err) {
3386 printk(KERN_ERR PFX "unable to wake up pci device (%i)\n", err);
3387 goto out;
3388 }
3389 mmio_start = pci_resource_start(pci_dev, 0);
3390 mmio_flags = pci_resource_flags(pci_dev, 0);
3391 mmio_len = pci_resource_len(pci_dev, 0);
3392 if (!(mmio_flags & IORESOURCE_MEM)) {
3393 printk(KERN_ERR PFX
3394 "%s, region #0 not an MMIO resource, aborting\n",
3395 pci_name(pci_dev));
3396 err = -ENODEV;
3397 goto err_pci_disable;
3398 }
3399 err = pci_request_regions(pci_dev, KBUILD_MODNAME);
3400 if (err) {
3401 printk(KERN_ERR PFX
3402 "could not access PCI resources (%i)\n", err);
3403 goto err_pci_disable;
3404 }
3405 /* enable PCI bus-mastering */
3406 pci_set_master(pci_dev);
3407 bcm->mmio_addr = ioremap(mmio_start, mmio_len);
3408 if (!bcm->mmio_addr) {
3409 printk(KERN_ERR PFX "%s: cannot remap MMIO, aborting\n",
3410 pci_name(pci_dev));
3411 err = -EIO;
3412 goto err_pci_release;
3413 }
3414 bcm->mmio_len = mmio_len;
3415 net_dev->base_addr = (unsigned long)bcm->mmio_addr;
3416
3417 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
3418 &bcm->board_vendor);
3419 bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
3420 &bcm->board_type);
3421 bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
3422 &bcm->board_revision);
3423
3424 err = bcm43xx_chipset_attach(bcm);
3425 if (err)
3426 goto err_iounmap;
3427 err = bcm43xx_pctl_init(bcm);
3428 if (err)
3429 goto err_chipset_detach;
3430 err = bcm43xx_probe_cores(bcm);
3431 if (err)
3432 goto err_chipset_detach;
3433
3434 /* Attach all IO cores to the backplane. */
3435 coremask = 0;
3436 for (i = 0; i < bcm->nr_80211_available; i++)
3437 coremask |= (1 << bcm->core_80211[i].index);
3438 //FIXME: Also attach some non80211 cores?
3439 err = bcm43xx_setup_backplane_pci_connection(bcm, coremask);
3440 if (err) {
3441 printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
3442 goto err_chipset_detach;
3443 }
3444
3445 err = bcm43xx_sprom_extract(bcm);
3446 if (err)
3447 goto err_chipset_detach;
3448 err = bcm43xx_leds_init(bcm);
3449 if (err)
3450 goto err_chipset_detach;
3451
3452 for (i = 0; i < bcm->nr_80211_available; i++) {
3453 err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
3454 assert(err != -ENODEV);
3455 if (err)
3456 goto err_80211_unwind;
3457
3458 /* Enable the selected wireless core.
3459 * Connect PHY only on the first core.
3460 */
3461 bcm43xx_wireless_core_reset(bcm, (i == 0));
3462
3463 err = bcm43xx_read_phyinfo(bcm);
3464 if (err && (i == 0))
3465 goto err_80211_unwind;
3466
3467 err = bcm43xx_read_radioinfo(bcm);
3468 if (err && (i == 0))
3469 goto err_80211_unwind;
3470
3471 err = bcm43xx_validate_chip(bcm);
3472 if (err && (i == 0))
3473 goto err_80211_unwind;
3474
3475 bcm43xx_radio_turn_off(bcm);
3476 err = bcm43xx_phy_init_tssi2dbm_table(bcm);
3477 if (err)
3478 goto err_80211_unwind;
3479 bcm43xx_wireless_core_disable(bcm);
3480 }
3481 bcm43xx_pctl_set_crystal(bcm, 0);
3482
3483 /* Set the MAC address in the networking subsystem */
3484 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
3485 memcpy(bcm->net_dev->dev_addr, bcm->sprom.et1macaddr, 6);
3486 else
3487 memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
3488
3489 bcm43xx_geo_init(bcm);
3490
3491 snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
3492 "Broadcom %04X", bcm->chip_id);
3493
3494 assert(err == 0);
3495out:
3496 return err;
3497
3498err_80211_unwind:
3499 for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
3500 kfree(bcm->core_80211_ext[i].phy._lo_pairs);
3501 if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
3502 kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
3503 }
3504err_chipset_detach:
3505 bcm43xx_chipset_detach(bcm);
3506err_iounmap:
3507 iounmap(bcm->mmio_addr);
3508err_pci_release:
3509 pci_release_regions(pci_dev);
3510err_pci_disable:
3511 pci_disable_device(pci_dev);
3512 goto out;
3513}
3514
3515/* Do the Hardware IO operations to send the txb */
3516static inline int bcm43xx_tx(struct bcm43xx_private *bcm,
3517 struct ieee80211_txb *txb)
3518{
3519 int err = -ENODEV;
3520
3521 if (bcm43xx_using_pio(bcm))
3522 err = bcm43xx_pio_tx(bcm, txb);
3523 else
3524 err = bcm43xx_dma_tx(bcm, txb);
3525
3526 return err;
3527}
3528
3529static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev,
3530 u8 channel)
3531{
3532 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3533 struct bcm43xx_radioinfo *radio;
3534 unsigned long flags;
3535
3536 bcm43xx_lock_mmio(bcm, flags);
3537 if (bcm->initialized) {
3538 bcm43xx_mac_suspend(bcm);
3539 bcm43xx_radio_selectchannel(bcm, channel, 0);
3540 bcm43xx_mac_enable(bcm);
3541 } else {
3542 radio = bcm43xx_current_radio(bcm);
3543 radio->initial_channel = channel;
3544 }
3545 bcm43xx_unlock_mmio(bcm, flags);
3546}
3547
3548/* set_security() callback in struct ieee80211_device */
3549static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
3550 struct ieee80211_security *sec)
3551{
3552 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3553 struct ieee80211_security *secinfo = &bcm->ieee->sec;
3554 unsigned long flags;
3555 int keyidx;
3556
3557 dprintk(KERN_INFO PFX "set security called\n");
3558
3559 bcm43xx_lock_mmio(bcm, flags);
3560
3561 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
3562 if (sec->flags & (1<<keyidx)) {
3563 secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
3564 secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
3565 memcpy(secinfo->keys[keyidx], sec->keys[keyidx], SCM_KEY_LEN);
3566 }
3567
3568 if (sec->flags & SEC_ACTIVE_KEY) {
3569 secinfo->active_key = sec->active_key;
3570 dprintk(KERN_INFO PFX " .active_key = %d\n", sec->active_key);
3571 }
3572 if (sec->flags & SEC_UNICAST_GROUP) {
3573 secinfo->unicast_uses_group = sec->unicast_uses_group;
3574 dprintk(KERN_INFO PFX " .unicast_uses_group = %d\n", sec->unicast_uses_group);
3575 }
3576 if (sec->flags & SEC_LEVEL) {
3577 secinfo->level = sec->level;
3578 dprintk(KERN_INFO PFX " .level = %d\n", sec->level);
3579 }
3580 if (sec->flags & SEC_ENABLED) {
3581 secinfo->enabled = sec->enabled;
3582 dprintk(KERN_INFO PFX " .enabled = %d\n", sec->enabled);
3583 }
3584 if (sec->flags & SEC_ENCRYPT) {
3585 secinfo->encrypt = sec->encrypt;
3586 dprintk(KERN_INFO PFX " .encrypt = %d\n", sec->encrypt);
3587 }
3588 if (bcm->initialized && !bcm->ieee->host_encrypt) {
3589 if (secinfo->enabled) {
3590 /* upload WEP keys to hardware */
3591 char null_address[6] = { 0 };
3592 u8 algorithm = 0;
3593 for (keyidx = 0; keyidx<WEP_KEYS; keyidx++) {
3594 if (!(sec->flags & (1<<keyidx)))
3595 continue;
3596 switch (sec->encode_alg[keyidx]) {
3597 case SEC_ALG_NONE: algorithm = BCM43xx_SEC_ALGO_NONE; break;
3598 case SEC_ALG_WEP:
3599 algorithm = BCM43xx_SEC_ALGO_WEP;
3600 if (secinfo->key_sizes[keyidx] == 13)
3601 algorithm = BCM43xx_SEC_ALGO_WEP104;
3602 break;
3603 case SEC_ALG_TKIP:
3604 FIXME();
3605 algorithm = BCM43xx_SEC_ALGO_TKIP;
3606 break;
3607 case SEC_ALG_CCMP:
3608 FIXME();
3609 algorithm = BCM43xx_SEC_ALGO_AES;
3610 break;
3611 default:
3612 assert(0);
3613 break;
3614 }
3615 bcm43xx_key_write(bcm, keyidx, algorithm, sec->keys[keyidx], secinfo->key_sizes[keyidx], &null_address[0]);
3616 bcm->key[keyidx].enabled = 1;
3617 bcm->key[keyidx].algorithm = algorithm;
3618 }
3619 } else
3620 bcm43xx_clear_keys(bcm);
3621 }
3622 bcm43xx_unlock_mmio(bcm, flags);
3623}
3624
3625/* hard_start_xmit() callback in struct ieee80211_device */
3626static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb,
3627 struct net_device *net_dev,
3628 int pri)
3629{
3630 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3631 int err = -ENODEV;
3632 unsigned long flags;
3633
3634 bcm43xx_lock_mmio(bcm, flags);
3635 if (likely(bcm->initialized))
3636 err = bcm43xx_tx(bcm, txb);
3637 bcm43xx_unlock_mmio(bcm, flags);
3638
3639 return err;
3640}
3641
3642static struct net_device_stats * bcm43xx_net_get_stats(struct net_device *net_dev)
3643{
3644 return &(bcm43xx_priv(net_dev)->ieee->stats);
3645}
3646
3647static void bcm43xx_net_tx_timeout(struct net_device *net_dev)
3648{
3649 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3650 unsigned long flags;
3651
3652 bcm43xx_lock_mmio(bcm, flags);
3653 bcm43xx_controller_restart(bcm, "TX timeout");
3654 bcm43xx_unlock_mmio(bcm, flags);
3655}
3656
3657#ifdef CONFIG_NET_POLL_CONTROLLER
3658static void bcm43xx_net_poll_controller(struct net_device *net_dev)
3659{
3660 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3661 unsigned long flags;
3662
3663 local_irq_save(flags);
3664 bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
3665 local_irq_restore(flags);
3666}
3667#endif /* CONFIG_NET_POLL_CONTROLLER */
3668
3669static int bcm43xx_net_open(struct net_device *net_dev)
3670{
3671 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3672
3673 return bcm43xx_init_board(bcm);
3674}
3675
3676static int bcm43xx_net_stop(struct net_device *net_dev)
3677{
3678 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3679
3680 ieee80211softmac_stop(net_dev);
3681 bcm43xx_disable_interrupts_sync(bcm, NULL);
3682 bcm43xx_free_board(bcm);
3683
3684 return 0;
3685}
3686
3687static int bcm43xx_init_private(struct bcm43xx_private *bcm,
3688 struct net_device *net_dev,
3689 struct pci_dev *pci_dev)
3690{
3691 int err;
3692
3693 bcm->ieee = netdev_priv(net_dev);
3694 bcm->softmac = ieee80211_priv(net_dev);
3695 bcm->softmac->set_channel = bcm43xx_ieee80211_set_chan;
3696
3697 bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
3698 bcm->pci_dev = pci_dev;
3699 bcm->net_dev = net_dev;
3700 bcm->bad_frames_preempt = modparam_bad_frames_preempt;
3701 spin_lock_init(&bcm->_lock);
3702 tasklet_init(&bcm->isr_tasklet,
3703 (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
3704 (unsigned long)bcm);
3705 tasklet_disable_nosync(&bcm->isr_tasklet);
3706 if (modparam_pio) {
3707 bcm->__using_pio = 1;
3708 } else {
3709 err = pci_set_dma_mask(pci_dev, DMA_30BIT_MASK);
3710 err |= pci_set_consistent_dma_mask(pci_dev, DMA_30BIT_MASK);
3711 if (err) {
3712#ifdef CONFIG_BCM43XX_PIO
3713 printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
3714 bcm->__using_pio = 1;
3715#else
3716 printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
3717 "Recompile the driver with PIO support, please.\n");
3718 return -ENODEV;
3719#endif /* CONFIG_BCM43XX_PIO */
3720 }
3721 }
3722 bcm->rts_threshold = BCM43xx_DEFAULT_RTS_THRESHOLD;
3723
3724 /* default to sw encryption for now */
3725 bcm->ieee->host_build_iv = 0;
3726 bcm->ieee->host_encrypt = 1;
3727 bcm->ieee->host_decrypt = 1;
3728
3729 bcm->ieee->iw_mode = BCM43xx_INITIAL_IWMODE;
3730 bcm->ieee->tx_headroom = sizeof(struct bcm43xx_txhdr);
3731 bcm->ieee->set_security = bcm43xx_ieee80211_set_security;
3732 bcm->ieee->hard_start_xmit = bcm43xx_ieee80211_hard_start_xmit;
3733
3734 return 0;
3735}
3736
3737static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
3738 const struct pci_device_id *ent)
3739{
3740 struct net_device *net_dev;
3741 struct bcm43xx_private *bcm;
3742 int err;
3743
3744#ifdef CONFIG_BCM947XX
3745 if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
3746 return -ENODEV;
3747#endif
3748
3749#ifdef DEBUG_SINGLE_DEVICE_ONLY
3750 if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
3751 return -ENODEV;
3752#endif
3753
3754 net_dev = alloc_ieee80211softmac(sizeof(*bcm));
3755 if (!net_dev) {
3756 printk(KERN_ERR PFX
3757 "could not allocate ieee80211 device %s\n",
3758 pci_name(pdev));
3759 err = -ENOMEM;
3760 goto out;
3761 }
3762 /* initialize the net_device struct */
3763 SET_MODULE_OWNER(net_dev);
3764 SET_NETDEV_DEV(net_dev, &pdev->dev);
3765
3766 net_dev->open = bcm43xx_net_open;
3767 net_dev->stop = bcm43xx_net_stop;
3768 net_dev->get_stats = bcm43xx_net_get_stats;
3769 net_dev->tx_timeout = bcm43xx_net_tx_timeout;
3770#ifdef CONFIG_NET_POLL_CONTROLLER
3771 net_dev->poll_controller = bcm43xx_net_poll_controller;
3772#endif
3773 net_dev->wireless_handlers = &bcm43xx_wx_handlers_def;
3774 net_dev->irq = pdev->irq;
3775 SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
3776
3777 /* initialize the bcm43xx_private struct */
3778 bcm = bcm43xx_priv(net_dev);
3779 memset(bcm, 0, sizeof(*bcm));
3780 err = bcm43xx_init_private(bcm, net_dev, pdev);
3781 if (err)
3782 goto err_free_netdev;
3783
3784 pci_set_drvdata(pdev, net_dev);
3785
3786 err = bcm43xx_attach_board(bcm);
3787 if (err)
3788 goto err_free_netdev;
3789
3790 err = register_netdev(net_dev);
3791 if (err) {
3792 printk(KERN_ERR PFX "Cannot register net device, "
3793 "aborting.\n");
3794 err = -ENOMEM;
3795 goto err_detach_board;
3796 }
3797
3798 bcm43xx_debugfs_add_device(bcm);
3799
3800 assert(err == 0);
3801out:
3802 return err;
3803
3804err_detach_board:
3805 bcm43xx_detach_board(bcm);
3806err_free_netdev:
3807 free_ieee80211softmac(net_dev);
3808 goto out;
3809}
3810
3811static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
3812{
3813 struct net_device *net_dev = pci_get_drvdata(pdev);
3814 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3815
3816 bcm43xx_debugfs_remove_device(bcm);
3817 unregister_netdev(net_dev);
3818 bcm43xx_detach_board(bcm);
3819 assert(bcm->ucode == NULL);
3820 free_ieee80211softmac(net_dev);
3821}
3822
3823/* Hard-reset the chip. Do not call this directly.
3824 * Use bcm43xx_controller_restart()
3825 */
3826static void bcm43xx_chip_reset(void *_bcm)
3827{
3828 struct bcm43xx_private *bcm = _bcm;
3829 struct net_device *net_dev = bcm->net_dev;
3830 struct pci_dev *pci_dev = bcm->pci_dev;
3831 int err;
3832 int was_initialized = bcm->initialized;
3833
3834 netif_stop_queue(bcm->net_dev);
3835 tasklet_disable(&bcm->isr_tasklet);
3836
3837 bcm->firmware_norelease = 1;
3838 if (was_initialized)
3839 bcm43xx_free_board(bcm);
3840 bcm->firmware_norelease = 0;
3841 bcm43xx_detach_board(bcm);
3842 err = bcm43xx_init_private(bcm, net_dev, pci_dev);
3843 if (err)
3844 goto failure;
3845 err = bcm43xx_attach_board(bcm);
3846 if (err)
3847 goto failure;
3848 if (was_initialized) {
3849 err = bcm43xx_init_board(bcm);
3850 if (err)
3851 goto failure;
3852 }
3853 netif_wake_queue(bcm->net_dev);
3854 printk(KERN_INFO PFX "Controller restarted\n");
3855
3856 return;
3857failure:
3858 printk(KERN_ERR PFX "Controller restart failed\n");
3859}
3860
3861/* Hard-reset the chip.
3862 * This can be called from interrupt or process context.
3863 * Make sure to _not_ re-enable device interrupts after this has been called.
3864*/
3865void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
3866{
3867 bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
3868 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
3869 printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
3870 INIT_WORK(&bcm->restart_work, bcm43xx_chip_reset, bcm);
3871 schedule_work(&bcm->restart_work);
3872}
3873
3874#ifdef CONFIG_PM
3875
3876static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
3877{
3878 struct net_device *net_dev = pci_get_drvdata(pdev);
3879 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3880 unsigned long flags;
3881 int try_to_shutdown = 0, err;
3882
3883 dprintk(KERN_INFO PFX "Suspending...\n");
3884
3885 bcm43xx_lock(bcm, flags);
3886 bcm->was_initialized = bcm->initialized;
3887 if (bcm->initialized)
3888 try_to_shutdown = 1;
3889 bcm43xx_unlock(bcm, flags);
3890
3891 netif_device_detach(net_dev);
3892 if (try_to_shutdown) {
3893 ieee80211softmac_stop(net_dev);
3894 err = bcm43xx_disable_interrupts_sync(bcm, &bcm->irq_savedstate);
3895 if (unlikely(err)) {
3896 dprintk(KERN_ERR PFX "Suspend failed.\n");
3897 return -EAGAIN;
3898 }
3899 bcm->firmware_norelease = 1;
3900 bcm43xx_free_board(bcm);
3901 bcm->firmware_norelease = 0;
3902 }
3903 bcm43xx_chipset_detach(bcm);
3904
3905 pci_save_state(pdev);
3906 pci_disable_device(pdev);
3907 pci_set_power_state(pdev, pci_choose_state(pdev, state));
3908
3909 dprintk(KERN_INFO PFX "Device suspended.\n");
3910
3911 return 0;
3912}
3913
3914static int bcm43xx_resume(struct pci_dev *pdev)
3915{
3916 struct net_device *net_dev = pci_get_drvdata(pdev);
3917 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
3918 int err = 0;
3919
3920 dprintk(KERN_INFO PFX "Resuming...\n");
3921
3922 pci_set_power_state(pdev, 0);
3923 pci_enable_device(pdev);
3924 pci_restore_state(pdev);
3925
3926 bcm43xx_chipset_attach(bcm);
3927 if (bcm->was_initialized) {
3928 bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
3929 err = bcm43xx_init_board(bcm);
3930 }
3931 if (err) {
3932 printk(KERN_ERR PFX "Resume failed!\n");
3933 return err;
3934 }
3935
3936 netif_device_attach(net_dev);
3937
3938 /*FIXME: This should be handled by softmac instead. */
3939 schedule_work(&bcm->softmac->associnfo.work);
3940
3941 dprintk(KERN_INFO PFX "Device resumed.\n");
3942
3943 return 0;
3944}
3945
3946#endif /* CONFIG_PM */
3947
3948static struct pci_driver bcm43xx_pci_driver = {
3949 .name = KBUILD_MODNAME,
3950 .id_table = bcm43xx_pci_tbl,
3951 .probe = bcm43xx_init_one,
3952 .remove = __devexit_p(bcm43xx_remove_one),
3953#ifdef CONFIG_PM
3954 .suspend = bcm43xx_suspend,
3955 .resume = bcm43xx_resume,
3956#endif /* CONFIG_PM */
3957};
3958
3959static int __init bcm43xx_init(void)
3960{
3961 printk(KERN_INFO KBUILD_MODNAME " driver\n");
3962 bcm43xx_debugfs_init();
3963 return pci_register_driver(&bcm43xx_pci_driver);
3964}
3965
3966static void __exit bcm43xx_exit(void)
3967{
3968 pci_unregister_driver(&bcm43xx_pci_driver);
3969 bcm43xx_debugfs_exit();
3970}
3971
3972module_init(bcm43xx_init)
3973module_exit(bcm43xx_exit)
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.h b/drivers/net/wireless/bcm43xx/bcm43xx_main.h
new file mode 100644
index 000000000000..eca79a38594a
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.h
@@ -0,0 +1,168 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#ifndef BCM43xx_MAIN_H_
32#define BCM43xx_MAIN_H_
33
34#include "bcm43xx.h"
35
36#ifdef CONFIG_BCM947XX
37#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
38
39static inline void e_aton(char *str, char *dest)
40{
41 int i = 0;
42 u16 *d = (u16 *) dest;
43
44 for (;;) {
45 dest[i++] = (char) simple_strtoul(str, NULL, 16);
46 str += 2;
47 if (!*str++ || i == 6)
48 break;
49 }
50 for (i = 0; i < 3; i++)
51 d[i] = cpu_to_be16(d[i]);
52}
53#endif
54
55#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
56#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
57/* Magic helper macro to pad structures. Ignore those above. It's magic. */
58#define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes))
59
60
61/* Lightweight function to convert a frequency (in Mhz) to a channel number. */
62static inline
63u8 bcm43xx_freq_to_channel_a(int freq)
64{
65 return ((freq - 5000) / 5);
66}
67static inline
68u8 bcm43xx_freq_to_channel_bg(int freq)
69{
70 u8 channel;
71
72 if (freq == 2484)
73 channel = 14;
74 else
75 channel = (freq - 2407) / 5;
76
77 return channel;
78}
79static inline
80u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
81 int freq)
82{
83 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
84 return bcm43xx_freq_to_channel_a(freq);
85 return bcm43xx_freq_to_channel_bg(freq);
86}
87
88/* Lightweight function to convert a channel number to a frequency (in Mhz). */
89static inline
90int bcm43xx_channel_to_freq_a(u8 channel)
91{
92 return (5000 + (5 * channel));
93}
94static inline
95int bcm43xx_channel_to_freq_bg(u8 channel)
96{
97 int freq;
98
99 if (channel == 14)
100 freq = 2484;
101 else
102 freq = 2407 + (5 * channel);
103
104 return freq;
105}
106static inline
107int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
108 u8 channel)
109{
110 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
111 return bcm43xx_channel_to_freq_a(channel);
112 return bcm43xx_channel_to_freq_bg(channel);
113}
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 <= 200);
122}
123static inline
124int bcm43xx_is_valid_channel_bg(u8 channel)
125{
126 return (channel >= 1 && channel <= 14);
127}
128static inline
129int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
130 u8 channel)
131{
132 if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
133 return bcm43xx_is_valid_channel_a(channel);
134 return bcm43xx_is_valid_channel_bg(channel);
135}
136
137void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
138void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
139
140void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
141 int iw_mode);
142
143u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
144 u16 routing, u16 offset);
145u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
146 u16 routing, u16 offset);
147void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
148 u16 routing, u16 offset,
149 u32 value);
150void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
151 u16 routing, u16 offset,
152 u16 value);
153
154void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
155
156int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
157
158void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
159
160void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
161void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
162
163void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
164
165int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
166int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
167
168#endif /* BCM43xx_MAIN_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_phy.c b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
new file mode 100644
index 000000000000..0a66f43ca0c0
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_phy.c
@@ -0,0 +1,2345 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#include <linux/delay.h>
32#include <linux/pci.h>
33#include <linux/types.h>
34
35#include "bcm43xx.h"
36#include "bcm43xx_phy.h"
37#include "bcm43xx_main.h"
38#include "bcm43xx_radio.h"
39#include "bcm43xx_ilt.h"
40#include "bcm43xx_power.h"
41
42
43static const s8 bcm43xx_tssi2dbm_b_table[] = {
44 0x4D, 0x4C, 0x4B, 0x4A,
45 0x4A, 0x49, 0x48, 0x47,
46 0x47, 0x46, 0x45, 0x45,
47 0x44, 0x43, 0x42, 0x42,
48 0x41, 0x40, 0x3F, 0x3E,
49 0x3D, 0x3C, 0x3B, 0x3A,
50 0x39, 0x38, 0x37, 0x36,
51 0x35, 0x34, 0x32, 0x31,
52 0x30, 0x2F, 0x2D, 0x2C,
53 0x2B, 0x29, 0x28, 0x26,
54 0x25, 0x23, 0x21, 0x1F,
55 0x1D, 0x1A, 0x17, 0x14,
56 0x10, 0x0C, 0x06, 0x00,
57 -7, -7, -7, -7,
58 -7, -7, -7, -7,
59 -7, -7, -7, -7,
60};
61
62static const s8 bcm43xx_tssi2dbm_g_table[] = {
63 77, 77, 77, 76,
64 76, 76, 75, 75,
65 74, 74, 73, 73,
66 73, 72, 72, 71,
67 71, 70, 70, 69,
68 68, 68, 67, 67,
69 66, 65, 65, 64,
70 63, 63, 62, 61,
71 60, 59, 58, 57,
72 56, 55, 54, 53,
73 52, 50, 49, 47,
74 45, 43, 40, 37,
75 33, 28, 22, 14,
76 5, -7, -20, -20,
77 -20, -20, -20, -20,
78 -20, -20, -20, -20,
79};
80
81static void bcm43xx_phy_initg(struct bcm43xx_private *bcm);
82
83
84void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
85{
86 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
87
88 assert(irqs_disabled());
89 if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
90 phy->is_locked = 0;
91 return;
92 }
93 if (bcm->current_core->rev < 3) {
94 bcm43xx_mac_suspend(bcm);
95 spin_lock(&phy->lock);
96 } else {
97 if (bcm->ieee->iw_mode != IW_MODE_MASTER)
98 bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
99 }
100 phy->is_locked = 1;
101}
102
103void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
104{
105 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
106
107 assert(irqs_disabled());
108 if (bcm->current_core->rev < 3) {
109 if (phy->is_locked) {
110 spin_unlock(&phy->lock);
111 bcm43xx_mac_enable(bcm);
112 }
113 } else {
114 if (bcm->ieee->iw_mode != IW_MODE_MASTER)
115 bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
116 }
117 phy->is_locked = 0;
118}
119
120u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
121{
122 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
123 return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
124}
125
126void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
127{
128 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
129 mmiowb();
130 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
131}
132
133void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
134{
135 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
136 unsigned long flags;
137
138 bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
139 if (phy->calibrated)
140 return;
141 if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
142 /* We do not want to be preempted while calibrating
143 * the hardware.
144 */
145 local_irq_save(flags);
146
147 bcm43xx_wireless_core_reset(bcm, 0);
148 bcm43xx_phy_initg(bcm);
149 bcm43xx_wireless_core_reset(bcm, 1);
150
151 local_irq_restore(flags);
152 }
153 phy->calibrated = 1;
154}
155
156/* Connect the PHY
157 * http://bcm-specs.sipsolutions.net/SetPHY
158 */
159int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
160{
161 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
162 u32 flags;
163
164 if (bcm->current_core->rev < 5)
165 goto out;
166
167 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
168 if (connect) {
169 if (!(flags & 0x00010000))
170 return -ENODEV;
171 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
172 flags |= (0x800 << 18);
173 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
174 } else {
175 if (!(flags & 0x00020000))
176 return -ENODEV;
177 flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
178 flags &= ~(0x800 << 18);
179 bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
180 }
181out:
182 phy->connected = connect;
183 if (connect)
184 dprintk(KERN_INFO PFX "PHY connected\n");
185 else
186 dprintk(KERN_INFO PFX "PHY disconnected\n");
187
188 return 0;
189}
190
191/* intialize B PHY power control
192 * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
193 */
194static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
195{
196 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
197 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
198 u16 saved_batt = 0, saved_ratt = 0, saved_txctl1 = 0;
199 int must_reset_txpower = 0;
200
201 assert(phy->type != BCM43xx_PHYTYPE_A);
202 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
203 (bcm->board_type == 0x0416))
204 return;
205
206 bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
207 bcm43xx_phy_write(bcm, 0x0028, 0x8018);
208
209 if (phy->type == BCM43xx_PHYTYPE_G) {
210 if (!phy->connected)
211 return;
212 bcm43xx_phy_write(bcm, 0x047A, 0xC111);
213 }
214 if (phy->savedpctlreg != 0xFFFF)
215 return;
216
217 if (phy->type == BCM43xx_PHYTYPE_B &&
218 phy->rev >= 2 &&
219 radio->version == 0x2050) {
220 bcm43xx_radio_write16(bcm, 0x0076,
221 bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
222 } else {
223 saved_batt = radio->baseband_atten;
224 saved_ratt = radio->radio_atten;
225 saved_txctl1 = radio->txctl1;
226 if ((radio->revision >= 6) && (radio->revision <= 8)
227 && /*FIXME: incomplete specs for 5 < revision < 9 */ 0)
228 bcm43xx_radio_set_txpower_bg(bcm, 0xB, 0x1F, 0);
229 else
230 bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
231 must_reset_txpower = 1;
232 }
233 bcm43xx_dummy_transmission(bcm);
234
235 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
236
237 if (must_reset_txpower)
238 bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
239 else
240 bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
241 bcm43xx_radio_clear_tssi(bcm);
242}
243
244static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
245{
246 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
247 u16 offset = 0x0000;
248
249 if (phy->rev == 1)
250 offset = 0x4C00;
251
252 bcm43xx_ilt_write(bcm, offset, 0x00FE);
253 bcm43xx_ilt_write(bcm, offset + 1, 0x000D);
254 bcm43xx_ilt_write(bcm, offset + 2, 0x0013);
255 bcm43xx_ilt_write(bcm, offset + 3, 0x0019);
256
257 if (phy->rev == 1) {
258 bcm43xx_ilt_write(bcm, 0x1800, 0x2710);
259 bcm43xx_ilt_write(bcm, 0x1801, 0x9B83);
260 bcm43xx_ilt_write(bcm, 0x1802, 0x9B83);
261 bcm43xx_ilt_write(bcm, 0x1803, 0x0F8D);
262 bcm43xx_phy_write(bcm, 0x0455, 0x0004);
263 }
264
265 bcm43xx_phy_write(bcm, 0x04A5, (bcm43xx_phy_read(bcm, 0x04A5) & 0x00FF) | 0x5700);
266 bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xFF80) | 0x000F);
267 bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xC07F) | 0x2B80);
268 bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xF0FF) | 0x0300);
269
270 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
271
272 bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xFFF0) | 0x0008);
273 bcm43xx_phy_write(bcm, 0x04A1, (bcm43xx_phy_read(bcm, 0x04A1) & 0xF0FF) | 0x0600);
274 bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xF0FF) | 0x0700);
275 bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xF0FF) | 0x0100);
276
277 if (phy->rev == 1)
278 bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
279
280 bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xFF00) | 0x001C);
281 bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xC0FF) | 0x0200);
282 bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0xFF00) | 0x001C);
283 bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xFF00) | 0x0020);
284 bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xC0FF) | 0x0200);
285 bcm43xx_phy_write(bcm, 0x0482, (bcm43xx_phy_read(bcm, 0x0482) & 0xFF00) | 0x002E);
286 bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0x00FF) | 0x1A00);
287 bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0xFF00) | 0x0028);
288 bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0x00FF) | 0x2C00);
289
290 if (phy->rev == 1) {
291 bcm43xx_phy_write(bcm, 0x0430, 0x092B);
292 bcm43xx_phy_write(bcm, 0x041B, (bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1) | 0x0002);
293 } else {
294 bcm43xx_phy_write(bcm, 0x041B, bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1);
295 bcm43xx_phy_write(bcm, 0x041F, 0x287A);
296 bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0xFFF0) | 0x0004);
297 }
298
299 if (phy->rev > 2) {
300 bcm43xx_phy_write(bcm, 0x0422, 0x287A);
301 bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0x0FFF) | 0x3000);
302 }
303
304 bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
305 bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
306
307 if (phy->rev == 1) {
308 bcm43xx_phy_write(bcm, 0x04AB, (bcm43xx_phy_read(bcm, 0x04AB) & 0xF0FF) | 0x0600);
309 bcm43xx_phy_write(bcm, 0x048B, 0x005E);
310 bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xFF00) | 0x001E);
311 bcm43xx_phy_write(bcm, 0x048D, 0x0002);
312 }
313
314 bcm43xx_ilt_write(bcm, offset + 0x0800, 0);
315 bcm43xx_ilt_write(bcm, offset + 0x0801, 7);
316 bcm43xx_ilt_write(bcm, offset + 0x0802, 16);
317 bcm43xx_ilt_write(bcm, offset + 0x0803, 28);
318}
319
320static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
321{
322 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
323 u16 i;
324
325 assert(phy->type == BCM43xx_PHYTYPE_G);
326 if (phy->rev == 1) {
327 bcm43xx_phy_write(bcm, 0x0406, 0x4F19);
328 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
329 (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0xFC3F) | 0x0340);
330 bcm43xx_phy_write(bcm, 0x042C, 0x005A);
331 bcm43xx_phy_write(bcm, 0x0427, 0x001A);
332
333 for (i = 0; i < BCM43xx_ILT_FINEFREQG_SIZE; i++)
334 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqg[i]);
335 for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
336 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
337 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
338 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
339 } else {
340 /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
341 bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
342
343 if (phy->rev == 2) {
344 bcm43xx_phy_write(bcm, 0x04C0, 0x1861);
345 bcm43xx_phy_write(bcm, 0x04C1, 0x0271);
346 } else if (phy->rev > 2) {
347 bcm43xx_phy_write(bcm, 0x04C0, 0x0098);
348 bcm43xx_phy_write(bcm, 0x04C1, 0x0070);
349 bcm43xx_phy_write(bcm, 0x04C9, 0x0080);
350 }
351 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
352
353 for (i = 0; i < 64; i++)
354 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
355 for (i = 0; i < BCM43xx_ILT_NOISEG2_SIZE; i++)
356 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg2[i]);
357 }
358
359 if (phy->rev <= 2)
360 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
361 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
362 else if ((phy->rev == 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
363 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
364 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
365 else
366 for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
367 bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
368
369 if (phy->rev == 2)
370 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
371 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
372 else if ((phy->rev > 2) && (phy->rev <= 7))
373 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
374 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
375
376 if (phy->rev == 1) {
377 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
378 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
379 for (i = 0; i < 4; i++) {
380 bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
381 bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
382 bcm43xx_ilt_write(bcm, 0x540C + i, 0x0020);
383 bcm43xx_ilt_write(bcm, 0x5410 + i, 0x0020);
384 }
385 bcm43xx_phy_agcsetup(bcm);
386
387 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
388 (bcm->board_type == 0x0416) &&
389 (bcm->board_revision == 0x0017))
390 return;
391
392 bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
393 bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
394 } else {
395 for (i = 0; i <= 0x2F; i++)
396 bcm43xx_ilt_write(bcm, 0x1000 + i, 0x0820);
397 bcm43xx_phy_agcsetup(bcm);
398 bcm43xx_phy_read(bcm, 0x0400); /* dummy read */
399 bcm43xx_phy_write(bcm, 0x0403, 0x1000);
400 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
401 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
402
403 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
404 (bcm->board_type == 0x0416) &&
405 (bcm->board_revision == 0x0017))
406 return;
407
408 bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
409 bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
410 }
411}
412
413/* Initialize the noisescaletable for APHY */
414static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
415{
416 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
417 int i;
418
419 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, 0x1400);
420 for (i = 0; i < 12; i++) {
421 if (phy->rev == 2)
422 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
423 else
424 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
425 }
426 if (phy->rev == 2)
427 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
428 else
429 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2300);
430 for (i = 0; i < 11; i++) {
431 if (phy->rev == 2)
432 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
433 else
434 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
435 }
436 if (phy->rev == 2)
437 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
438 else
439 bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
440}
441
442static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
443{
444 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
445 u16 i;
446
447 assert(phy->type == BCM43xx_PHYTYPE_A);
448 switch (phy->rev) {
449 case 2:
450 bcm43xx_phy_write(bcm, 0x008E, 0x3800);
451 bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
452 bcm43xx_phy_write(bcm, 0x0036, 0x0400);
453
454 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
455
456 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
457 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
458 bcm43xx_ilt_write(bcm, 0x3C0C, 0x07BF);
459 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
460
461 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
462 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
463 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
464 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
465
466 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
467 bcm43xx_phy_write(bcm, 0x002B, bcm43xx_phy_read(bcm, 0x002B) & 0xFBFF);
468 bcm43xx_phy_write(bcm, 0x008E, 0x58C1);
469
470 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
471 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
472 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
473 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
474 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
475
476 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
477 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
478 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
479 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
480 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
481 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
482 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
483
484 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
485 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
486 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
487
488 for (i = 0; i < 16; i++)
489 bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
490
491 bcm43xx_ilt_write(bcm, 0x3003, 0x1044);
492 bcm43xx_ilt_write(bcm, 0x3004, 0x7201);
493 bcm43xx_ilt_write(bcm, 0x3006, 0x0040);
494 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
495
496 for (i = 0; i < BCM43xx_ILT_FINEFREQA_SIZE; i++)
497 bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqa[i]);
498 for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
499 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
500 for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
501 bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
502 bcm43xx_phy_init_noisescaletbl(bcm);
503 for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
504 bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
505 break;
506 case 3:
507 for (i = 0; i < 64; i++)
508 bcm43xx_ilt_write(bcm, 0x4000 + i, i);
509
510 bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
511
512 bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
513 bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
514 bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
515
516 bcm43xx_phy_write(bcm, 0x0024, 0x4680);
517 bcm43xx_phy_write(bcm, 0x0020, 0x0003);
518 bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
519 bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
520 bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
521
522 bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
523 for (i = 0; i < BCM43xx_ILT_NOISEA3_SIZE; i++)
524 bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea3[i]);
525 bcm43xx_phy_init_noisescaletbl(bcm);
526 for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
527 bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
528
529 bcm43xx_phy_write(bcm, 0x0003, 0x1808);
530
531 bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
532 bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
533 bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
534 bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
535 bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
536
537 bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
538 bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
539 bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
540 bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
541 bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
542 bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
543 bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
544
545 bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
546 bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
547 bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
548
549 bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
550 bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
551 break;
552 default:
553 assert(0);
554 }
555}
556
557/* Initialize APHY. This is also called for the GPHY in some cases. */
558static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
559{
560 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
561 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
562 u16 tval;
563
564 if (phy->type == BCM43xx_PHYTYPE_A) {
565 bcm43xx_phy_setupa(bcm);
566 } else {
567 bcm43xx_phy_setupg(bcm);
568 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
569 bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
570 return;
571 }
572
573 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
574 (bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) & 0xF83C) | 0x0340);
575 bcm43xx_phy_write(bcm, 0x0034, 0x0001);
576
577 TODO();//TODO: RSSI AGC
578 bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
579 bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) | (1 << 14));
580 bcm43xx_radio_init2060(bcm);
581
582 if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM)
583 && ((bcm->board_type == 0x0416) || (bcm->board_type == 0x040A))) {
584 if (radio->lofcal == 0xFFFF) {
585 TODO();//TODO: LOF Cal
586 bcm43xx_radio_set_tx_iq(bcm);
587 } else
588 bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
589 }
590
591 bcm43xx_phy_write(bcm, 0x007A, 0xF111);
592
593 if (phy->savedpctlreg == 0xFFFF) {
594 bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
595 bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
596
597 tval = bcm43xx_ilt_read(bcm, 0x3001);
598 if (phy->rev == 1) {
599 bcm43xx_ilt_write(bcm, 0x3001,
600 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFF87)
601 | 0x0058);
602 } else {
603 bcm43xx_ilt_write(bcm, 0x3001,
604 (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
605 | 0x002C);
606 }
607 bcm43xx_dummy_transmission(bcm);
608 phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
609 bcm43xx_ilt_write(bcm, 0x3001, tval);
610
611 bcm43xx_radio_set_txpower_a(bcm, 0x0018);
612 }
613 bcm43xx_radio_clear_tssi(bcm);
614}
615
616static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
617{
618 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
619 u16 offset, val;
620
621 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
622 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
623 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
624 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
625 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
626 val = 0x3C3D;
627 for (offset = 0x0089; offset < 0x00A7; offset++) {
628 bcm43xx_phy_write(bcm, offset, val);
629 val -= 0x0202;
630 }
631 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
632 if (radio->channel == 0xFF)
633 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
634 else
635 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
636 if (radio->version != 0x2050) {
637 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
638 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
639 }
640 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
641 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
642 if (radio->version == 0x2050) {
643 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
644 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
645 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
646 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
647 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
648 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
649 bcm43xx_radio_init2050(bcm);
650 }
651 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
652 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
653 bcm43xx_phy_write(bcm, 0x0032, 0x00CC);
654 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
655 bcm43xx_phy_lo_b_measure(bcm);
656 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
657 if (radio->version != 0x2050)
658 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
659 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1000);
660 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
661 if (radio->version != 0x2050)
662 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
663 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
664 bcm43xx_phy_init_pctl(bcm);
665}
666
667static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
668{
669 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
670 u16 offset, val;
671
672 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
673 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
674 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
675 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
676 bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
677 val = 0x3C3D;
678 for (offset = 0x0089; offset < 0x00A7; offset++) {
679 bcm43xx_phy_write(bcm, offset, val);
680 val -= 0x0202;
681 }
682 bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
683 if (radio->channel == 0xFF)
684 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
685 else
686 bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
687 if (radio->version != 0x2050) {
688 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
689 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
690 }
691 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
692 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
693 if (radio->version == 0x2050) {
694 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
695 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
696 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
697 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
698 bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
699 bcm43xx_phy_write(bcm, 0x0038, 0x0677);
700 bcm43xx_radio_init2050(bcm);
701 }
702 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
703 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
704 if (radio->version == 0x2050)
705 bcm43xx_phy_write(bcm, 0x0032, 0x00E0);
706 bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
707
708 bcm43xx_phy_lo_b_measure(bcm);
709
710 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
711 if (radio->version == 0x2050)
712 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
713 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1100);
714 bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
715 if (radio->version == 0x2050)
716 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
717 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
718 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
719 bcm43xx_calc_nrssi_slope(bcm);
720 bcm43xx_calc_nrssi_threshold(bcm);
721 }
722 bcm43xx_phy_init_pctl(bcm);
723}
724
725static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
726{
727 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
728 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
729 u16 offset;
730
731 if (phy->version == 1 &&
732 radio->version == 0x2050) {
733 bcm43xx_radio_write16(bcm, 0x007A,
734 bcm43xx_radio_read16(bcm, 0x007A)
735 | 0x0050);
736 }
737 if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
738 (bcm->board_type != 0x0416)) {
739 for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
740 bcm43xx_phy_write(bcm, offset,
741 (bcm43xx_phy_read(bcm, offset) + 0x2020)
742 & 0x3F3F);
743 }
744 }
745 bcm43xx_phy_write(bcm, 0x0035,
746 (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
747 | 0x0700);
748 if (radio->version == 0x2050)
749 bcm43xx_phy_write(bcm, 0x0038, 0x0667);
750
751 if (phy->connected) {
752 if (radio->version == 0x2050) {
753 bcm43xx_radio_write16(bcm, 0x007A,
754 bcm43xx_radio_read16(bcm, 0x007A)
755 | 0x0020);
756 bcm43xx_radio_write16(bcm, 0x0051,
757 bcm43xx_radio_read16(bcm, 0x0051)
758 | 0x0004);
759 }
760 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
761
762 bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
763 bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
764
765 bcm43xx_phy_write(bcm, 0x001C, 0x186A);
766
767 bcm43xx_phy_write(bcm, 0x0013, (bcm43xx_phy_read(bcm, 0x0013) & 0x00FF) | 0x1900);
768 bcm43xx_phy_write(bcm, 0x0035, (bcm43xx_phy_read(bcm, 0x0035) & 0xFFC0) | 0x0064);
769 bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D) & 0xFF80) | 0x000A);
770 }
771
772 if (bcm->bad_frames_preempt) {
773 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
774 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
775 }
776
777 if (phy->version == 1 && radio->version == 0x2050) {
778 bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
779 bcm43xx_phy_write(bcm, 0x0021, 0x3763);
780 bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
781 bcm43xx_phy_write(bcm, 0x0023, 0x06F9);
782 bcm43xx_phy_write(bcm, 0x0024, 0x037E);
783 } else
784 bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
785 bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
786 bcm43xx_write16(bcm, 0x03EC, 0x3F22);
787
788 if (phy->version == 1 && radio->version == 0x2050)
789 bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
790 else
791 bcm43xx_phy_write(bcm, 0x0020, 0x301C);
792
793 if (phy->version == 0)
794 bcm43xx_write16(bcm, 0x03E4, 0x3000);
795
796 /* Force to channel 7, even if not supported. */
797 bcm43xx_radio_selectchannel(bcm, 7, 0);
798
799 if (radio->version != 0x2050) {
800 bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
801 bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
802 }
803
804 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
805 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
806
807 if (radio->version == 0x2050) {
808 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
809 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
810 }
811
812 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
813 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
814
815 bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
816
817 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
818
819 bcm43xx_phy_write(bcm, 0x0014, 0x0080);
820 bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
821 bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
822
823 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
824
825 if (radio->version == 0x2050)
826 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
827
828 bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
829}
830
831static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
832{
833 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
834 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
835 u16 offset, val;
836
837 bcm43xx_phy_write(bcm, 0x003E, 0x817A);
838 bcm43xx_radio_write16(bcm, 0x007A,
839 (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
840 if ((radio->manufact == 0x17F) &&
841 (radio->version == 0x2050) &&
842 (radio->revision == 3 ||
843 radio->revision == 4 ||
844 radio->revision == 5)) {
845 bcm43xx_radio_write16(bcm, 0x0051, 0x001F);
846 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
847 bcm43xx_radio_write16(bcm, 0x0053, 0x005B);
848 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
849 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
850 bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
851 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
852 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
853 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
854 }
855 if ((radio->manufact == 0x17F) &&
856 (radio->version == 0x2050) &&
857 (radio->revision == 6)) {
858 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
859 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
860 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
861 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
862 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
863 bcm43xx_radio_write16(bcm, 0x005B, 0x008B);
864 bcm43xx_radio_write16(bcm, 0x005C, 0x00B5);
865 bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
866 bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
867 bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
868 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
869 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
870 }
871 if ((radio->manufact == 0x17F) &&
872 (radio->version == 0x2050) &&
873 (radio->revision == 7)) {
874 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
875 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
876 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
877 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
878 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
879 bcm43xx_radio_write16(bcm, 0x005B, 0x00A8);
880 bcm43xx_radio_write16(bcm, 0x005C, 0x0075);
881 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
882 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
883 bcm43xx_radio_write16(bcm, 0x007D, 0x00E8);
884 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
885 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
886 bcm43xx_radio_write16(bcm, 0x007B, 0x0000);
887 }
888 if ((radio->manufact == 0x17F) &&
889 (radio->version == 0x2050) &&
890 (radio->revision == 8)) {
891 bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
892 bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
893 bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
894 bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
895 bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
896 bcm43xx_radio_write16(bcm, 0x005B, 0x006B);
897 bcm43xx_radio_write16(bcm, 0x005C, 0x000F);
898 if (bcm->sprom.boardflags & 0x8000) {
899 bcm43xx_radio_write16(bcm, 0x005D, 0x00FA);
900 bcm43xx_radio_write16(bcm, 0x005E, 0x00D8);
901 } else {
902 bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
903 bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
904 }
905 bcm43xx_radio_write16(bcm, 0x0073, 0x0003);
906 bcm43xx_radio_write16(bcm, 0x007D, 0x00A8);
907 bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
908 bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
909 }
910 val = 0x1E1F;
911 for (offset = 0x0088; offset < 0x0098; offset++) {
912 bcm43xx_phy_write(bcm, offset, val);
913 val -= 0x0202;
914 }
915 val = 0x3E3F;
916 for (offset = 0x0098; offset < 0x00A8; offset++) {
917 bcm43xx_phy_write(bcm, offset, val);
918 val -= 0x0202;
919 }
920 val = 0x2120;
921 for (offset = 0x00A8; offset < 0x00C8; offset++) {
922 bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
923 val += 0x0202;
924 }
925 if (phy->type == BCM43xx_PHYTYPE_G) {
926 bcm43xx_radio_write16(bcm, 0x007A,
927 bcm43xx_radio_read16(bcm, 0x007A) | 0x0020);
928 bcm43xx_radio_write16(bcm, 0x0051,
929 bcm43xx_radio_read16(bcm, 0x0051) | 0x0004);
930 bcm43xx_phy_write(bcm, 0x0802,
931 bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
932 bcm43xx_phy_write(bcm, 0x042B,
933 bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
934 }
935
936 /* Force to channel 7, even if not supported. */
937 bcm43xx_radio_selectchannel(bcm, 7, 0);
938
939 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
940 bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
941 udelay(40);
942 bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C) | 0x0002));
943 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
944 if (radio->manufact == 0x17F &&
945 radio->version == 0x2050 &&
946 radio->revision <= 2) {
947 bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
948 bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
949 bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
950 bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
951 }
952 bcm43xx_radio_write16(bcm, 0x007A,
953 (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
954
955 bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
956
957 bcm43xx_phy_write(bcm, 0x0014, 0x0200);
958 if (radio->version == 0x2050){
959 if (radio->revision == 3 ||
960 radio->revision == 4 ||
961 radio->revision == 5)
962 bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
963 else
964 bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
965 }
966 bcm43xx_phy_write(bcm, 0x0038, 0x0668);
967 bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
968 if (radio->version == 0x2050) {
969 if (radio->revision == 3 ||
970 radio->revision == 4 ||
971 radio->revision == 5)
972 bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003);
973 else if (radio->revision <= 2)
974 bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
975 }
976
977 if (phy->rev == 4)
978 bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
979 else
980 bcm43xx_write16(bcm, 0x03E4, 0x0009);
981 if (phy->type == BCM43xx_PHYTYPE_B) {
982 bcm43xx_write16(bcm, 0x03E6, 0x8140);
983 bcm43xx_phy_write(bcm, 0x0016, 0x0410);
984 bcm43xx_phy_write(bcm, 0x0017, 0x0820);
985 bcm43xx_phy_write(bcm, 0x0062, 0x0007);
986 (void) bcm43xx_radio_calibrationvalue(bcm);
987 bcm43xx_phy_lo_b_measure(bcm);
988 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
989 bcm43xx_calc_nrssi_slope(bcm);
990 bcm43xx_calc_nrssi_threshold(bcm);
991 }
992 bcm43xx_phy_init_pctl(bcm);
993 } else
994 bcm43xx_write16(bcm, 0x03E6, 0x0);
995}
996
997static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
998{
999 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1000 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1001 u16 backup_phy[15];
1002 u16 backup_radio[3];
1003 u16 backup_bband;
1004 u16 i;
1005 u16 loop1_cnt, loop1_done, loop1_omitted;
1006 u16 loop2_done;
1007
1008 backup_phy[0] = bcm43xx_phy_read(bcm, 0x0429);
1009 backup_phy[1] = bcm43xx_phy_read(bcm, 0x0001);
1010 backup_phy[2] = bcm43xx_phy_read(bcm, 0x0811);
1011 backup_phy[3] = bcm43xx_phy_read(bcm, 0x0812);
1012 backup_phy[4] = bcm43xx_phy_read(bcm, 0x0814);
1013 backup_phy[5] = bcm43xx_phy_read(bcm, 0x0815);
1014 backup_phy[6] = bcm43xx_phy_read(bcm, 0x005A);
1015 backup_phy[7] = bcm43xx_phy_read(bcm, 0x0059);
1016 backup_phy[8] = bcm43xx_phy_read(bcm, 0x0058);
1017 backup_phy[9] = bcm43xx_phy_read(bcm, 0x000A);
1018 backup_phy[10] = bcm43xx_phy_read(bcm, 0x0003);
1019 backup_phy[11] = bcm43xx_phy_read(bcm, 0x080F);
1020 backup_phy[12] = bcm43xx_phy_read(bcm, 0x0810);
1021 backup_phy[13] = bcm43xx_phy_read(bcm, 0x002B);
1022 backup_phy[14] = bcm43xx_phy_read(bcm, 0x0015);
1023 bcm43xx_phy_read(bcm, 0x002D); /* dummy read */
1024 backup_bband = radio->baseband_atten;
1025 backup_radio[0] = bcm43xx_radio_read16(bcm, 0x0052);
1026 backup_radio[1] = bcm43xx_radio_read16(bcm, 0x0043);
1027 backup_radio[2] = bcm43xx_radio_read16(bcm, 0x007A);
1028
1029 bcm43xx_phy_write(bcm, 0x0429,
1030 bcm43xx_phy_read(bcm, 0x0429) & 0x3FFF);
1031 bcm43xx_phy_write(bcm, 0x0001,
1032 bcm43xx_phy_read(bcm, 0x0001) & 0x8000);
1033 bcm43xx_phy_write(bcm, 0x0811,
1034 bcm43xx_phy_read(bcm, 0x0811) | 0x0002);
1035 bcm43xx_phy_write(bcm, 0x0812,
1036 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFD);
1037 bcm43xx_phy_write(bcm, 0x0811,
1038 bcm43xx_phy_read(bcm, 0x0811) | 0x0001);
1039 bcm43xx_phy_write(bcm, 0x0812,
1040 bcm43xx_phy_read(bcm, 0x0812) & 0xFFFE);
1041 bcm43xx_phy_write(bcm, 0x0814,
1042 bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
1043 bcm43xx_phy_write(bcm, 0x0815,
1044 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
1045 bcm43xx_phy_write(bcm, 0x0814,
1046 bcm43xx_phy_read(bcm, 0x0814) | 0x0002);
1047 bcm43xx_phy_write(bcm, 0x0815,
1048 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFD);
1049 bcm43xx_phy_write(bcm, 0x0811,
1050 bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
1051 bcm43xx_phy_write(bcm, 0x0812,
1052 bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
1053
1054 bcm43xx_phy_write(bcm, 0x0811,
1055 (bcm43xx_phy_read(bcm, 0x0811)
1056 & 0xFFCF) | 0x0030);
1057 bcm43xx_phy_write(bcm, 0x0812,
1058 (bcm43xx_phy_read(bcm, 0x0812)
1059 & 0xFFCF) | 0x0010);
1060
1061 bcm43xx_phy_write(bcm, 0x005A, 0x0780);
1062 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1063 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1064 if (phy->version == 0) {
1065 bcm43xx_phy_write(bcm, 0x0003, 0x0122);
1066 } else {
1067 bcm43xx_phy_write(bcm, 0x000A,
1068 bcm43xx_phy_read(bcm, 0x000A)
1069 | 0x2000);
1070 }
1071 bcm43xx_phy_write(bcm, 0x0814,
1072 bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
1073 bcm43xx_phy_write(bcm, 0x0815,
1074 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
1075 bcm43xx_phy_write(bcm, 0x0003,
1076 (bcm43xx_phy_read(bcm, 0x0003)
1077 & 0xFF9F) | 0x0040);
1078 if (radio->version == 0x2050 && radio->revision == 2) {
1079 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1080 bcm43xx_radio_write16(bcm, 0x0043,
1081 (bcm43xx_radio_read16(bcm, 0x0043)
1082 & 0xFFF0) | 0x0009);
1083 loop1_cnt = 9;
1084 } else if (radio->revision == 8) {
1085 bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
1086 loop1_cnt = 15;
1087 } else
1088 loop1_cnt = 0;
1089
1090 bcm43xx_phy_set_baseband_attenuation(bcm, 11);
1091
1092 if (phy->rev >= 3)
1093 bcm43xx_phy_write(bcm, 0x080F, 0xC020);
1094 else
1095 bcm43xx_phy_write(bcm, 0x080F, 0x8020);
1096 bcm43xx_phy_write(bcm, 0x0810, 0x0000);
1097
1098 bcm43xx_phy_write(bcm, 0x002B,
1099 (bcm43xx_phy_read(bcm, 0x002B)
1100 & 0xFFC0) | 0x0001);
1101 bcm43xx_phy_write(bcm, 0x002B,
1102 (bcm43xx_phy_read(bcm, 0x002B)
1103 & 0xC0FF) | 0x0800);
1104 bcm43xx_phy_write(bcm, 0x0811,
1105 bcm43xx_phy_read(bcm, 0x0811) | 0x0100);
1106 bcm43xx_phy_write(bcm, 0x0812,
1107 bcm43xx_phy_read(bcm, 0x0812) & 0xCFFF);
1108 if (bcm->sprom.boardflags & BCM43xx_BFL_EXTLNA) {
1109 if (phy->rev >= 7) {
1110 bcm43xx_phy_write(bcm, 0x0811,
1111 bcm43xx_phy_read(bcm, 0x0811)
1112 | 0x0800);
1113 bcm43xx_phy_write(bcm, 0x0812,
1114 bcm43xx_phy_read(bcm, 0x0812)
1115 | 0x8000);
1116 }
1117 }
1118 bcm43xx_radio_write16(bcm, 0x007A,
1119 bcm43xx_radio_read16(bcm, 0x007A)
1120 & 0x00F7);
1121
1122 for (i = 0; i < loop1_cnt; i++) {
1123 bcm43xx_radio_write16(bcm, 0x0043, loop1_cnt);
1124 bcm43xx_phy_write(bcm, 0x0812,
1125 (bcm43xx_phy_read(bcm, 0x0812)
1126 & 0xF0FF) | (i << 8));
1127 bcm43xx_phy_write(bcm, 0x0015,
1128 (bcm43xx_phy_read(bcm, 0x0015)
1129 & 0x0FFF) | 0xA000);
1130 bcm43xx_phy_write(bcm, 0x0015,
1131 (bcm43xx_phy_read(bcm, 0x0015)
1132 & 0x0FFF) | 0xF000);
1133 udelay(20);
1134 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1135 break;
1136 }
1137 loop1_done = i;
1138 loop1_omitted = loop1_cnt - loop1_done;
1139
1140 loop2_done = 0;
1141 if (loop1_done >= 8) {
1142 bcm43xx_phy_write(bcm, 0x0812,
1143 bcm43xx_phy_read(bcm, 0x0812)
1144 | 0x0030);
1145 for (i = loop1_done - 8; i < 16; i++) {
1146 bcm43xx_phy_write(bcm, 0x0812,
1147 (bcm43xx_phy_read(bcm, 0x0812)
1148 & 0xF0FF) | (i << 8));
1149 bcm43xx_phy_write(bcm, 0x0015,
1150 (bcm43xx_phy_read(bcm, 0x0015)
1151 & 0x0FFF) | 0xA000);
1152 bcm43xx_phy_write(bcm, 0x0015,
1153 (bcm43xx_phy_read(bcm, 0x0015)
1154 & 0x0FFF) | 0xF000);
1155 udelay(20);
1156 if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
1157 break;
1158 }
1159 }
1160
1161 bcm43xx_phy_write(bcm, 0x0814, backup_phy[4]);
1162 bcm43xx_phy_write(bcm, 0x0815, backup_phy[5]);
1163 bcm43xx_phy_write(bcm, 0x005A, backup_phy[6]);
1164 bcm43xx_phy_write(bcm, 0x0059, backup_phy[7]);
1165 bcm43xx_phy_write(bcm, 0x0058, backup_phy[8]);
1166 bcm43xx_phy_write(bcm, 0x000A, backup_phy[9]);
1167 bcm43xx_phy_write(bcm, 0x0003, backup_phy[10]);
1168 bcm43xx_phy_write(bcm, 0x080F, backup_phy[11]);
1169 bcm43xx_phy_write(bcm, 0x0810, backup_phy[12]);
1170 bcm43xx_phy_write(bcm, 0x002B, backup_phy[13]);
1171 bcm43xx_phy_write(bcm, 0x0015, backup_phy[14]);
1172
1173 bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
1174
1175 bcm43xx_radio_write16(bcm, 0x0052, backup_radio[0]);
1176 bcm43xx_radio_write16(bcm, 0x0043, backup_radio[1]);
1177 bcm43xx_radio_write16(bcm, 0x007A, backup_radio[2]);
1178
1179 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
1180 udelay(10);
1181 bcm43xx_phy_write(bcm, 0x0811, backup_phy[2]);
1182 bcm43xx_phy_write(bcm, 0x0812, backup_phy[3]);
1183 bcm43xx_phy_write(bcm, 0x0429, backup_phy[0]);
1184 bcm43xx_phy_write(bcm, 0x0001, backup_phy[1]);
1185
1186 phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
1187 phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
1188}
1189
1190static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
1191{
1192 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1193 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1194 u16 tmp;
1195
1196 if (phy->rev == 1)
1197 bcm43xx_phy_initb5(bcm);
1198 else if (phy->rev >= 2 && phy->rev <= 7)
1199 bcm43xx_phy_initb6(bcm);
1200 if (phy->rev >= 2 || phy->connected)
1201 bcm43xx_phy_inita(bcm);
1202
1203 if (phy->rev >= 2) {
1204 bcm43xx_phy_write(bcm, 0x0814, 0x0000);
1205 bcm43xx_phy_write(bcm, 0x0815, 0x0000);
1206 if (phy->rev == 2)
1207 bcm43xx_phy_write(bcm, 0x0811, 0x0000);
1208 else if (phy->rev >= 3)
1209 bcm43xx_phy_write(bcm, 0x0811, 0x0400);
1210 bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
1211 if (phy->connected) {
1212 tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
1213 if (tmp < 6) {
1214 bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
1215 bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
1216 if (tmp != 3) {
1217 bcm43xx_phy_write(bcm, 0x04CC,
1218 (bcm43xx_phy_read(bcm, 0x04CC)
1219 & 0x00FF) | 0x1F00);
1220 }
1221 }
1222 }
1223 }
1224 if (phy->rev < 3 && phy->connected)
1225 bcm43xx_phy_write(bcm, 0x047E, 0x0078);
1226 if (phy->rev >= 6 && phy->rev <= 8) {
1227 bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
1228 bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
1229 }
1230 if (phy->rev >= 2 && phy->connected)
1231 bcm43xx_calc_loopback_gain(bcm);
1232 if (radio->revision != 8) {
1233 if (radio->initval == 0xFFFF)
1234 radio->initval = bcm43xx_radio_init2050(bcm);
1235 else
1236 bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
1237 }
1238 if (radio->txctl2 == 0xFFFF) {
1239 bcm43xx_phy_lo_g_measure(bcm);
1240 } else {
1241 if (radio->version == 0x2050 && radio->revision == 8) {
1242 //FIXME
1243 } else {
1244 bcm43xx_radio_write16(bcm, 0x0052,
1245 (bcm43xx_radio_read16(bcm, 0x0052)
1246 & 0xFFF0) | radio->txctl1);
1247 }
1248 if (phy->rev >= 6) {
1249 /*
1250 bcm43xx_phy_write(bcm, 0x0036,
1251 (bcm43xx_phy_read(bcm, 0x0036)
1252 & 0xF000) | (FIXME << 12));
1253 */
1254 }
1255 if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
1256 bcm43xx_phy_write(bcm, 0x002E, 0x8075);
1257 else
1258 bcm43xx_phy_write(bcm, 0x003E, 0x807F);
1259 if (phy->rev < 2)
1260 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1261 else
1262 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1263 }
1264 if (phy->connected) {
1265 bcm43xx_phy_lo_adjust(bcm, 0);
1266 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1267 }
1268
1269 if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
1270 /* The specs state to update the NRSSI LT with
1271 * the value 0x7FFFFFFF here. I think that is some weird
1272 * compiler optimization in the original driver.
1273 * Essentially, what we do here is resetting all NRSSI LT
1274 * entries to -32 (see the limit_value() in nrssi_hw_update())
1275 */
1276 bcm43xx_nrssi_hw_update(bcm, 0xFFFF);
1277 bcm43xx_calc_nrssi_threshold(bcm);
1278 } else if (phy->connected) {
1279 if (radio->nrssi[0] == -1000) {
1280 assert(radio->nrssi[1] == -1000);
1281 bcm43xx_calc_nrssi_slope(bcm);
1282 } else {
1283 assert(radio->nrssi[1] != -1000);
1284 bcm43xx_calc_nrssi_threshold(bcm);
1285 }
1286 }
1287 if (radio->revision == 8)
1288 bcm43xx_phy_write(bcm, 0x0805, 0x3230);
1289 bcm43xx_phy_init_pctl(bcm);
1290 if (bcm->chip_id == 0x4306 && bcm->chip_package != 2) {
1291 bcm43xx_phy_write(bcm, 0x0429,
1292 bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);
1293 bcm43xx_phy_write(bcm, 0x04C3,
1294 bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);
1295 }
1296}
1297
1298static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
1299{
1300 int i;
1301 u16 ret = 0;
1302
1303 for (i = 0; i < 10; i++){
1304 bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
1305 udelay(1);
1306 bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
1307 udelay(10);
1308 bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
1309 udelay(40);
1310 ret += bcm43xx_phy_read(bcm, 0x002C);
1311 }
1312
1313 return ret;
1314}
1315
1316void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
1317{
1318 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1319 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1320 u16 regstack[12] = { 0 };
1321 u16 mls;
1322 u16 fval;
1323 int i, j;
1324
1325 regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
1326 regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
1327
1328 if (radio->version == 0x2053) {
1329 regstack[2] = bcm43xx_phy_read(bcm, 0x000A);
1330 regstack[3] = bcm43xx_phy_read(bcm, 0x002A);
1331 regstack[4] = bcm43xx_phy_read(bcm, 0x0035);
1332 regstack[5] = bcm43xx_phy_read(bcm, 0x0003);
1333 regstack[6] = bcm43xx_phy_read(bcm, 0x0001);
1334 regstack[7] = bcm43xx_phy_read(bcm, 0x0030);
1335
1336 regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);
1337 regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);
1338 regstack[10] = bcm43xx_read16(bcm, 0x03EC);
1339 regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;
1340
1341 bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
1342 bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
1343 bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);
1344 bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);
1345 }
1346 bcm43xx_phy_write(bcm, 0x0015, 0xB000);
1347 bcm43xx_phy_write(bcm, 0x002B, 0x0004);
1348
1349 if (radio->version == 0x2053) {
1350 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1351 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1352 }
1353
1354 phy->minlowsig[0] = 0xFFFF;
1355
1356 for (i = 0; i < 4; i++) {
1357 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1358 bcm43xx_phy_lo_b_r15_loop(bcm);
1359 }
1360 for (i = 0; i < 10; i++) {
1361 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
1362 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1363 if (mls < phy->minlowsig[0]) {
1364 phy->minlowsig[0] = mls;
1365 phy->minlowsigpos[0] = i;
1366 }
1367 }
1368 bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
1369
1370 phy->minlowsig[1] = 0xFFFF;
1371
1372 for (i = -4; i < 5; i += 2) {
1373 for (j = -4; j < 5; j += 2) {
1374 if (j < 0)
1375 fval = (0x0100 * i) + j + 0x0100;
1376 else
1377 fval = (0x0100 * i) + j;
1378 bcm43xx_phy_write(bcm, 0x002F, fval);
1379 mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
1380 if (mls < phy->minlowsig[1]) {
1381 phy->minlowsig[1] = mls;
1382 phy->minlowsigpos[1] = fval;
1383 }
1384 }
1385 }
1386 phy->minlowsigpos[1] += 0x0101;
1387
1388 bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);
1389 if (radio->version == 0x2053) {
1390 bcm43xx_phy_write(bcm, 0x000A, regstack[2]);
1391 bcm43xx_phy_write(bcm, 0x002A, regstack[3]);
1392 bcm43xx_phy_write(bcm, 0x0035, regstack[4]);
1393 bcm43xx_phy_write(bcm, 0x0003, regstack[5]);
1394 bcm43xx_phy_write(bcm, 0x0001, regstack[6]);
1395 bcm43xx_phy_write(bcm, 0x0030, regstack[7]);
1396
1397 bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
1398 bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
1399
1400 bcm43xx_radio_write16(bcm, 0x0052,
1401 (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
1402 | regstack[11]);
1403
1404 bcm43xx_write16(bcm, 0x03EC, regstack[10]);
1405 }
1406 bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
1407}
1408
1409static inline
1410u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
1411{
1412 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1413
1414 if (phy->connected) {
1415 bcm43xx_phy_write(bcm, 0x15, 0xE300);
1416 control <<= 8;
1417 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
1418 udelay(5);
1419 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
1420 udelay(2);
1421 bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
1422 udelay(4);
1423 bcm43xx_phy_write(bcm, 0x0015, 0xF300);
1424 udelay(8);
1425 } else {
1426 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
1427 udelay(2);
1428 bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
1429 udelay(4);
1430 bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
1431 udelay(8);
1432 }
1433
1434 return bcm43xx_phy_read(bcm, 0x002D);
1435}
1436
1437static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
1438{
1439 int i;
1440 u32 ret = 0;
1441
1442 for (i = 0; i < 8; i++)
1443 ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
1444
1445 return ret;
1446}
1447
1448/* Write the LocalOscillator CONTROL */
1449static inline
1450void bcm43xx_lo_write(struct bcm43xx_private *bcm,
1451 struct bcm43xx_lopair *pair)
1452{
1453 u16 value;
1454
1455 value = (u8)(pair->low);
1456 value |= ((u8)(pair->high)) << 8;
1457
1458#ifdef CONFIG_BCM43XX_DEBUG
1459 /* Sanity check. */
1460 if (pair->low < -8 || pair->low > 8 ||
1461 pair->high < -8 || pair->high > 8) {
1462 printk(KERN_WARNING PFX
1463 "WARNING: Writing invalid LOpair "
1464 "(low: %d, high: %d, index: %lu)\n",
1465 pair->low, pair->high,
1466 (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));
1467 dump_stack();
1468 }
1469#endif
1470
1471 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
1472}
1473
1474static inline
1475struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
1476 u16 baseband_attenuation,
1477 u16 radio_attenuation,
1478 u16 tx)
1479{
1480 static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
1481 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1482
1483 if (baseband_attenuation > 6)
1484 baseband_attenuation = 6;
1485 assert(radio_attenuation < 10);
1486
1487 if (tx == 3) {
1488 return bcm43xx_get_lopair(phy,
1489 radio_attenuation,
1490 baseband_attenuation);
1491 }
1492 return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
1493}
1494
1495static inline
1496struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
1497{
1498 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1499
1500 return bcm43xx_find_lopair(bcm,
1501 radio->baseband_atten,
1502 radio->radio_atten,
1503 radio->txctl1);
1504}
1505
1506/* Adjust B/G LO */
1507void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
1508{
1509 struct bcm43xx_lopair *pair;
1510
1511 if (fixed) {
1512 /* Use fixed values. Only for initialization. */
1513 pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
1514 } else
1515 pair = bcm43xx_current_lopair(bcm);
1516 bcm43xx_lo_write(bcm, pair);
1517}
1518
1519static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
1520{
1521 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1522 u16 txctl2 = 0, i;
1523 u32 smallest, tmp;
1524
1525 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1526 udelay(10);
1527 smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1528 for (i = 0; i < 16; i++) {
1529 bcm43xx_radio_write16(bcm, 0x0052, i);
1530 udelay(10);
1531 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
1532 if (tmp < smallest) {
1533 smallest = tmp;
1534 txctl2 = i;
1535 }
1536 }
1537 radio->txctl2 = txctl2;
1538}
1539
1540static
1541void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
1542 const struct bcm43xx_lopair *in_pair,
1543 struct bcm43xx_lopair *out_pair,
1544 u16 r27)
1545{
1546 static const struct bcm43xx_lopair transitions[8] = {
1547 { .high = 1, .low = 1, },
1548 { .high = 1, .low = 0, },
1549 { .high = 1, .low = -1, },
1550 { .high = 0, .low = -1, },
1551 { .high = -1, .low = -1, },
1552 { .high = -1, .low = 0, },
1553 { .high = -1, .low = 1, },
1554 { .high = 0, .low = 1, },
1555 };
1556 struct bcm43xx_lopair lowest_transition = {
1557 .high = in_pair->high,
1558 .low = in_pair->low,
1559 };
1560 struct bcm43xx_lopair tmp_pair;
1561 struct bcm43xx_lopair transition;
1562 int i = 12;
1563 int state = 0;
1564 int found_lower;
1565 int j, begin, end;
1566 u32 lowest_deviation;
1567 u32 tmp;
1568
1569 /* Note that in_pair and out_pair can point to the same pair. Be careful. */
1570
1571 bcm43xx_lo_write(bcm, &lowest_transition);
1572 lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1573 do {
1574 found_lower = 0;
1575 assert(state >= 0 && state <= 8);
1576 if (state == 0) {
1577 begin = 1;
1578 end = 8;
1579 } else if (state % 2 == 0) {
1580 begin = state - 1;
1581 end = state + 1;
1582 } else {
1583 begin = state - 2;
1584 end = state + 2;
1585 }
1586 if (begin < 1)
1587 begin += 8;
1588 if (end > 8)
1589 end -= 8;
1590
1591 j = begin;
1592 tmp_pair.high = lowest_transition.high;
1593 tmp_pair.low = lowest_transition.low;
1594 while (1) {
1595 assert(j >= 1 && j <= 8);
1596 transition.high = tmp_pair.high + transitions[j - 1].high;
1597 transition.low = tmp_pair.low + transitions[j - 1].low;
1598 if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {
1599 bcm43xx_lo_write(bcm, &transition);
1600 tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
1601 if (tmp < lowest_deviation) {
1602 lowest_deviation = tmp;
1603 state = j;
1604 found_lower = 1;
1605
1606 lowest_transition.high = transition.high;
1607 lowest_transition.low = transition.low;
1608 }
1609 }
1610 if (j == end)
1611 break;
1612 if (j == 8)
1613 j = 1;
1614 else
1615 j++;
1616 }
1617 } while (i-- && found_lower);
1618
1619 out_pair->high = lowest_transition.high;
1620 out_pair->low = lowest_transition.low;
1621}
1622
1623/* Set the baseband attenuation value on chip. */
1624void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
1625 u16 baseband_attenuation)
1626{
1627 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1628 u16 value;
1629
1630 if (phy->version == 0) {
1631 value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
1632 value |= (baseband_attenuation & 0x000F);
1633 bcm43xx_write16(bcm, 0x03E6, value);
1634 return;
1635 }
1636
1637 if (phy->version > 1) {
1638 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
1639 value |= (baseband_attenuation << 2) & 0x003C;
1640 } else {
1641 value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
1642 value |= (baseband_attenuation << 3) & 0x0078;
1643 }
1644 bcm43xx_phy_write(bcm, 0x0060, value);
1645}
1646
1647/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
1648void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
1649{
1650 static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
1651 const int is_initializing = bcm43xx_is_initializing(bcm);
1652 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1653 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1654 u16 h, i, oldi = 0, j;
1655 struct bcm43xx_lopair control;
1656 struct bcm43xx_lopair *tmp_control;
1657 u16 tmp;
1658 u16 regstack[16] = { 0 };
1659 u8 oldchannel;
1660
1661 //XXX: What are these?
1662 u8 r27 = 0, r31;
1663
1664 oldchannel = radio->channel;
1665 /* Setup */
1666 if (phy->connected) {
1667 regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
1668 regstack[1] = bcm43xx_phy_read(bcm, 0x0802);
1669 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1670 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1671 }
1672 regstack[3] = bcm43xx_read16(bcm, 0x03E2);
1673 bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);
1674 regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
1675 regstack[5] = bcm43xx_phy_read(bcm, 0x15);
1676 regstack[6] = bcm43xx_phy_read(bcm, 0x2A);
1677 regstack[7] = bcm43xx_phy_read(bcm, 0x35);
1678 regstack[8] = bcm43xx_phy_read(bcm, 0x60);
1679 regstack[9] = bcm43xx_radio_read16(bcm, 0x43);
1680 regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);
1681 regstack[11] = bcm43xx_radio_read16(bcm, 0x52);
1682 if (phy->connected) {
1683 regstack[12] = bcm43xx_phy_read(bcm, 0x0811);
1684 regstack[13] = bcm43xx_phy_read(bcm, 0x0812);
1685 regstack[14] = bcm43xx_phy_read(bcm, 0x0814);
1686 regstack[15] = bcm43xx_phy_read(bcm, 0x0815);
1687 }
1688 bcm43xx_radio_selectchannel(bcm, 6, 0);
1689 if (phy->connected) {
1690 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
1691 bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
1692 bcm43xx_dummy_transmission(bcm);
1693 }
1694 bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
1695
1696 bcm43xx_phy_set_baseband_attenuation(bcm, 2);
1697
1698 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);
1699 bcm43xx_phy_write(bcm, 0x002E, 0x007F);
1700 bcm43xx_phy_write(bcm, 0x080F, 0x0078);
1701 bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));
1702 bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);
1703 bcm43xx_phy_write(bcm, 0x002B, 0x0203);
1704 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
1705 if (phy->connected) {
1706 bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);
1707 bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);
1708 bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
1709 bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
1710 }
1711 if (is_initializing)
1712 bcm43xx_phy_lo_g_measure_txctl2(bcm);
1713 bcm43xx_phy_write(bcm, 0x080F, 0x8078);
1714
1715 /* Measure */
1716 control.low = 0;
1717 control.high = 0;
1718 for (h = 0; h < 10; h++) {
1719 /* Loop over each possible RadioAttenuation (0-9) */
1720 i = pairorder[h];
1721 if (is_initializing) {
1722 if (i == 3) {
1723 control.low = 0;
1724 control.high = 0;
1725 } else if (((i % 2 == 1) && (oldi % 2 == 1)) ||
1726 ((i % 2 == 0) && (oldi % 2 == 0))) {
1727 tmp_control = bcm43xx_get_lopair(phy, oldi, 0);
1728 memcpy(&control, tmp_control, sizeof(control));
1729 } else {
1730 tmp_control = bcm43xx_get_lopair(phy, 3, 0);
1731 memcpy(&control, tmp_control, sizeof(control));
1732 }
1733 }
1734 /* Loop over each possible BasebandAttenuation/2 */
1735 for (j = 0; j < 4; j++) {
1736 if (is_initializing) {
1737 tmp = i * 2 + j;
1738 r27 = 0;
1739 r31 = 0;
1740 if (tmp > 14) {
1741 r31 = 1;
1742 if (tmp > 17)
1743 r27 = 1;
1744 if (tmp > 19)
1745 r27 = 2;
1746 }
1747 } else {
1748 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1749 if (!tmp_control->used)
1750 continue;
1751 memcpy(&control, tmp_control, sizeof(control));
1752 r27 = 3;
1753 r31 = 0;
1754 }
1755 bcm43xx_radio_write16(bcm, 0x43, i);
1756 bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
1757 udelay(10);
1758
1759 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1760
1761 tmp = (regstack[10] & 0xFFF0);
1762 if (r31)
1763 tmp |= 0x0008;
1764 bcm43xx_radio_write16(bcm, 0x007A, tmp);
1765
1766 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1767 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1768 }
1769 oldi = i;
1770 }
1771 /* Loop over each possible RadioAttenuation (10-13) */
1772 for (i = 10; i < 14; i++) {
1773 /* Loop over each possible BasebandAttenuation/2 */
1774 for (j = 0; j < 4; j++) {
1775 if (is_initializing) {
1776 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1777 memcpy(&control, tmp_control, sizeof(control));
1778 tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.
1779 r27 = 0;
1780 r31 = 0;
1781 if (tmp > 14) {
1782 r31 = 1;
1783 if (tmp > 17)
1784 r27 = 1;
1785 if (tmp > 19)
1786 r27 = 2;
1787 }
1788 } else {
1789 tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
1790 if (!tmp_control->used)
1791 continue;
1792 memcpy(&control, tmp_control, sizeof(control));
1793 r27 = 3;
1794 r31 = 0;
1795 }
1796 bcm43xx_radio_write16(bcm, 0x43, i - 9);
1797 bcm43xx_radio_write16(bcm, 0x52,
1798 radio->txctl2
1799 | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
1800 udelay(10);
1801
1802 bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
1803
1804 tmp = (regstack[10] & 0xFFF0);
1805 if (r31)
1806 tmp |= 0x0008;
1807 bcm43xx_radio_write16(bcm, 0x7A, tmp);
1808
1809 tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
1810 bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
1811 }
1812 }
1813
1814 /* Restoration */
1815 if (phy->connected) {
1816 bcm43xx_phy_write(bcm, 0x0015, 0xE300);
1817 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
1818 udelay(5);
1819 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
1820 udelay(2);
1821 bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
1822 } else
1823 bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);
1824 bcm43xx_phy_lo_adjust(bcm, is_initializing);
1825 bcm43xx_phy_write(bcm, 0x002E, 0x807F);
1826 if (phy->connected)
1827 bcm43xx_phy_write(bcm, 0x002F, 0x0202);
1828 else
1829 bcm43xx_phy_write(bcm, 0x002F, 0x0101);
1830 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);
1831 bcm43xx_phy_write(bcm, 0x0015, regstack[5]);
1832 bcm43xx_phy_write(bcm, 0x002A, regstack[6]);
1833 bcm43xx_phy_write(bcm, 0x0035, regstack[7]);
1834 bcm43xx_phy_write(bcm, 0x0060, regstack[8]);
1835 bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);
1836 bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);
1837 regstack[11] &= 0x00F0;
1838 regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);
1839 bcm43xx_radio_write16(bcm, 0x52, regstack[11]);
1840 bcm43xx_write16(bcm, 0x03E2, regstack[3]);
1841 if (phy->connected) {
1842 bcm43xx_phy_write(bcm, 0x0811, regstack[12]);
1843 bcm43xx_phy_write(bcm, 0x0812, regstack[13]);
1844 bcm43xx_phy_write(bcm, 0x0814, regstack[14]);
1845 bcm43xx_phy_write(bcm, 0x0815, regstack[15]);
1846 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);
1847 bcm43xx_phy_write(bcm, 0x0802, regstack[1]);
1848 }
1849 bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
1850
1851#ifdef CONFIG_BCM43XX_DEBUG
1852 {
1853 /* Sanity check for all lopairs. */
1854 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1855 tmp_control = phy->_lo_pairs + i;
1856 if (tmp_control->low < -8 || tmp_control->low > 8 ||
1857 tmp_control->high < -8 || tmp_control->high > 8) {
1858 printk(KERN_WARNING PFX
1859 "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
1860 tmp_control->low, tmp_control->high, i);
1861 }
1862 }
1863 }
1864#endif /* CONFIG_BCM43XX_DEBUG */
1865}
1866
1867static
1868void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
1869{
1870 struct bcm43xx_lopair *pair;
1871
1872 pair = bcm43xx_current_lopair(bcm);
1873 pair->used = 1;
1874}
1875
1876void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
1877{
1878 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1879 struct bcm43xx_lopair *pair;
1880 int i;
1881
1882 for (i = 0; i < BCM43xx_LO_COUNT; i++) {
1883 pair = phy->_lo_pairs + i;
1884 pair->used = 0;
1885 }
1886}
1887
1888/* http://bcm-specs.sipsolutions.net/EstimatePowerOut
1889 * This function converts a TSSI value to dBm in Q5.2
1890 */
1891static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
1892{
1893 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1894 s8 dbm = 0;
1895 s32 tmp;
1896
1897 tmp = phy->idle_tssi;
1898 tmp += tssi;
1899 tmp -= phy->savedpctlreg;
1900
1901 switch (phy->type) {
1902 case BCM43xx_PHYTYPE_A:
1903 tmp += 0x80;
1904 tmp = limit_value(tmp, 0x00, 0xFF);
1905 dbm = phy->tssi2dbm[tmp];
1906 TODO(); //TODO: There's a FIXME on the specs
1907 break;
1908 case BCM43xx_PHYTYPE_B:
1909 case BCM43xx_PHYTYPE_G:
1910 tmp = limit_value(tmp, 0x00, 0x3F);
1911 dbm = phy->tssi2dbm[tmp];
1912 break;
1913 default:
1914 assert(0);
1915 }
1916
1917 return dbm;
1918}
1919
1920/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
1921void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
1922{
1923 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1924 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1925
1926 if (phy->savedpctlreg == 0xFFFF)
1927 return;
1928 if ((bcm->board_type == 0x0416) &&
1929 (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
1930 return;
1931
1932 switch (phy->type) {
1933 case BCM43xx_PHYTYPE_A: {
1934
1935 TODO(); //TODO: Nothing for A PHYs yet :-/
1936
1937 break;
1938 }
1939 case BCM43xx_PHYTYPE_B:
1940 case BCM43xx_PHYTYPE_G: {
1941 u16 tmp;
1942 u16 txpower;
1943 s8 v0, v1, v2, v3;
1944 s8 average;
1945 u8 max_pwr;
1946 s16 desired_pwr, estimated_pwr, pwr_adjust;
1947 s16 radio_att_delta, baseband_att_delta;
1948 s16 radio_attenuation, baseband_attenuation;
1949 unsigned long phylock_flags;
1950
1951 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0058);
1952 v0 = (s8)(tmp & 0x00FF);
1953 v1 = (s8)((tmp & 0xFF00) >> 8);
1954 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005A);
1955 v2 = (s8)(tmp & 0x00FF);
1956 v3 = (s8)((tmp & 0xFF00) >> 8);
1957 tmp = 0;
1958
1959 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F) {
1960 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0070);
1961 v0 = (s8)(tmp & 0x00FF);
1962 v1 = (s8)((tmp & 0xFF00) >> 8);
1963 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0072);
1964 v2 = (s8)(tmp & 0x00FF);
1965 v3 = (s8)((tmp & 0xFF00) >> 8);
1966 if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F)
1967 return;
1968 v0 = (v0 + 0x20) & 0x3F;
1969 v1 = (v1 + 0x20) & 0x3F;
1970 v2 = (v2 + 0x20) & 0x3F;
1971 v3 = (v3 + 0x20) & 0x3F;
1972 tmp = 1;
1973 }
1974 bcm43xx_radio_clear_tssi(bcm);
1975
1976 average = (v0 + v1 + v2 + v3 + 2) / 4;
1977
1978 if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
1979 average -= 13;
1980
1981 estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
1982
1983 max_pwr = bcm->sprom.maxpower_bgphy;
1984
1985 if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
1986 (phy->type == BCM43xx_PHYTYPE_G))
1987 max_pwr -= 0x3;
1988
1989 /*TODO:
1990 max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
1991 where REG is the max power as per the regulatory domain
1992 */
1993
1994 desired_pwr = limit_value(radio->txpower_desired, 0, max_pwr);
1995 /* Check if we need to adjust the current power. */
1996 pwr_adjust = desired_pwr - estimated_pwr;
1997 radio_att_delta = -(pwr_adjust + 7) >> 3;
1998 baseband_att_delta = -(pwr_adjust >> 1) - (4 * radio_att_delta);
1999 if ((radio_att_delta == 0) && (baseband_att_delta == 0)) {
2000 bcm43xx_phy_lo_mark_current_used(bcm);
2001 return;
2002 }
2003
2004 /* Calculate the new attenuation values. */
2005 baseband_attenuation = radio->baseband_atten;
2006 baseband_attenuation += baseband_att_delta;
2007 radio_attenuation = radio->radio_atten;
2008 radio_attenuation += radio_att_delta;
2009
2010 /* Get baseband and radio attenuation values into their permitted ranges.
2011 * baseband 0-11, radio 0-9.
2012 * Radio attenuation affects power level 4 times as much as baseband.
2013 */
2014 if (radio_attenuation < 0) {
2015 baseband_attenuation -= (4 * -radio_attenuation);
2016 radio_attenuation = 0;
2017 } else if (radio_attenuation > 9) {
2018 baseband_attenuation += (4 * (radio_attenuation - 9));
2019 radio_attenuation = 9;
2020 } else {
2021 while (baseband_attenuation < 0 && radio_attenuation > 0) {
2022 baseband_attenuation += 4;
2023 radio_attenuation--;
2024 }
2025 while (baseband_attenuation > 11 && radio_attenuation < 9) {
2026 baseband_attenuation -= 4;
2027 radio_attenuation++;
2028 }
2029 }
2030 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2031
2032 txpower = radio->txctl1;
2033 if ((radio->version == 0x2050) && (radio->revision == 2)) {
2034 if (radio_attenuation <= 1) {
2035 if (txpower == 0) {
2036 txpower = 3;
2037 radio_attenuation += 2;
2038 baseband_attenuation += 2;
2039 } else if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
2040 baseband_attenuation += 4 * (radio_attenuation - 2);
2041 radio_attenuation = 2;
2042 }
2043 } else if (radio_attenuation > 4 && txpower != 0) {
2044 txpower = 0;
2045 if (baseband_attenuation < 3) {
2046 radio_attenuation -= 3;
2047 baseband_attenuation += 2;
2048 } else {
2049 radio_attenuation -= 2;
2050 baseband_attenuation -= 2;
2051 }
2052 }
2053 }
2054 radio->txctl1 = txpower;
2055 baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
2056 radio_attenuation = limit_value(radio_attenuation, 0, 9);
2057
2058 bcm43xx_phy_lock(bcm, phylock_flags);
2059 bcm43xx_radio_lock(bcm);
2060 bcm43xx_radio_set_txpower_bg(bcm, baseband_attenuation,
2061 radio_attenuation, txpower);
2062 bcm43xx_phy_lo_mark_current_used(bcm);
2063 bcm43xx_radio_unlock(bcm);
2064 bcm43xx_phy_unlock(bcm, phylock_flags);
2065 break;
2066 }
2067 default:
2068 assert(0);
2069 }
2070}
2071
2072static inline
2073s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
2074{
2075 if (num < 0)
2076 return num/den;
2077 else
2078 return (num+den/2)/den;
2079}
2080
2081static inline
2082s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
2083{
2084 s32 m1, m2, f = 256, q, delta;
2085 s8 i = 0;
2086
2087 m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
2088 m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
2089 do {
2090 if (i > 15)
2091 return -EINVAL;
2092 q = bcm43xx_tssi2dbm_ad(f * 4096 -
2093 bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
2094 delta = abs(q - f);
2095 f = q;
2096 i++;
2097 } while (delta >= 2);
2098 entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
2099 return 0;
2100}
2101
2102/* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
2103int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
2104{
2105 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2106 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
2107 s16 pab0, pab1, pab2;
2108 u8 idx;
2109 s8 *dyn_tssi2dbm;
2110
2111 if (phy->type == BCM43xx_PHYTYPE_A) {
2112 pab0 = (s16)(bcm->sprom.pa1b0);
2113 pab1 = (s16)(bcm->sprom.pa1b1);
2114 pab2 = (s16)(bcm->sprom.pa1b2);
2115 } else {
2116 pab0 = (s16)(bcm->sprom.pa0b0);
2117 pab1 = (s16)(bcm->sprom.pa0b1);
2118 pab2 = (s16)(bcm->sprom.pa0b2);
2119 }
2120
2121 if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
2122 phy->idle_tssi = 0x34;
2123 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2124 return 0;
2125 }
2126
2127 if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
2128 pab0 != -1 && pab1 != -1 && pab2 != -1) {
2129 /* The pabX values are set in SPROM. Use them. */
2130 if (phy->type == BCM43xx_PHYTYPE_A) {
2131 if ((s8)bcm->sprom.idle_tssi_tgt_aphy != 0 &&
2132 (s8)bcm->sprom.idle_tssi_tgt_aphy != -1)
2133 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_aphy);
2134 else
2135 phy->idle_tssi = 62;
2136 } else {
2137 if ((s8)bcm->sprom.idle_tssi_tgt_bgphy != 0 &&
2138 (s8)bcm->sprom.idle_tssi_tgt_bgphy != -1)
2139 phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_bgphy);
2140 else
2141 phy->idle_tssi = 62;
2142 }
2143 dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
2144 if (dyn_tssi2dbm == NULL) {
2145 printk(KERN_ERR PFX "Could not allocate memory"
2146 "for tssi2dbm table\n");
2147 return -ENOMEM;
2148 }
2149 for (idx = 0; idx < 64; idx++)
2150 if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
2151 phy->tssi2dbm = NULL;
2152 printk(KERN_ERR PFX "Could not generate "
2153 "tssi2dBm table\n");
2154 return -ENODEV;
2155 }
2156 phy->tssi2dbm = dyn_tssi2dbm;
2157 phy->dyn_tssi_tbl = 1;
2158 } else {
2159 /* pabX values not set in SPROM. */
2160 switch (phy->type) {
2161 case BCM43xx_PHYTYPE_A:
2162 /* APHY needs a generated table. */
2163 phy->tssi2dbm = NULL;
2164 printk(KERN_ERR PFX "Could not generate tssi2dBm "
2165 "table (wrong SPROM info)!\n");
2166 return -ENODEV;
2167 case BCM43xx_PHYTYPE_B:
2168 phy->idle_tssi = 0x34;
2169 phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
2170 break;
2171 case BCM43xx_PHYTYPE_G:
2172 phy->idle_tssi = 0x34;
2173 phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
2174 break;
2175 }
2176 }
2177
2178 return 0;
2179}
2180
2181int bcm43xx_phy_init(struct bcm43xx_private *bcm)
2182{
2183 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2184 int err = -ENODEV;
2185 unsigned long flags;
2186
2187 /* We do not want to be preempted while calibrating
2188 * the hardware.
2189 */
2190 local_irq_save(flags);
2191
2192 switch (phy->type) {
2193 case BCM43xx_PHYTYPE_A:
2194 if (phy->rev == 2 || phy->rev == 3) {
2195 bcm43xx_phy_inita(bcm);
2196 err = 0;
2197 }
2198 break;
2199 case BCM43xx_PHYTYPE_B:
2200 switch (phy->rev) {
2201 case 2:
2202 bcm43xx_phy_initb2(bcm);
2203 err = 0;
2204 break;
2205 case 4:
2206 bcm43xx_phy_initb4(bcm);
2207 err = 0;
2208 break;
2209 case 5:
2210 bcm43xx_phy_initb5(bcm);
2211 err = 0;
2212 break;
2213 case 6:
2214 bcm43xx_phy_initb6(bcm);
2215 err = 0;
2216 break;
2217 }
2218 break;
2219 case BCM43xx_PHYTYPE_G:
2220 bcm43xx_phy_initg(bcm);
2221 err = 0;
2222 break;
2223 }
2224 local_irq_restore(flags);
2225 if (err)
2226 printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
2227
2228 return err;
2229}
2230
2231void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
2232{
2233 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2234 u16 antennadiv;
2235 u16 offset;
2236 u16 value;
2237 u32 ucodeflags;
2238
2239 antennadiv = phy->antenna_diversity;
2240
2241 if (antennadiv == 0xFFFF)
2242 antennadiv = 3;
2243 assert(antennadiv <= 3);
2244
2245 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2246 BCM43xx_UCODEFLAGS_OFFSET);
2247 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2248 BCM43xx_UCODEFLAGS_OFFSET,
2249 ucodeflags & ~BCM43xx_UCODEFLAG_AUTODIV);
2250
2251 switch (phy->type) {
2252 case BCM43xx_PHYTYPE_A:
2253 case BCM43xx_PHYTYPE_G:
2254 if (phy->type == BCM43xx_PHYTYPE_A)
2255 offset = 0x0000;
2256 else
2257 offset = 0x0400;
2258
2259 if (antennadiv == 2)
2260 value = (3/*automatic*/ << 7);
2261 else
2262 value = (antennadiv << 7);
2263 bcm43xx_phy_write(bcm, offset + 1,
2264 (bcm43xx_phy_read(bcm, offset + 1)
2265 & 0x7E7F) | value);
2266
2267 if (antennadiv >= 2) {
2268 if (antennadiv == 2)
2269 value = (antennadiv << 7);
2270 else
2271 value = (0/*force0*/ << 7);
2272 bcm43xx_phy_write(bcm, offset + 0x2B,
2273 (bcm43xx_phy_read(bcm, offset + 0x2B)
2274 & 0xFEFF) | value);
2275 }
2276
2277 if (phy->type == BCM43xx_PHYTYPE_G) {
2278 if (antennadiv >= 2)
2279 bcm43xx_phy_write(bcm, 0x048C,
2280 bcm43xx_phy_read(bcm, 0x048C)
2281 | 0x2000);
2282 else
2283 bcm43xx_phy_write(bcm, 0x048C,
2284 bcm43xx_phy_read(bcm, 0x048C)
2285 & ~0x2000);
2286 if (phy->rev >= 2) {
2287 bcm43xx_phy_write(bcm, 0x0461,
2288 bcm43xx_phy_read(bcm, 0x0461)
2289 | 0x0010);
2290 bcm43xx_phy_write(bcm, 0x04AD,
2291 (bcm43xx_phy_read(bcm, 0x04AD)
2292 & 0x00FF) | 0x0015);
2293 if (phy->rev == 2)
2294 bcm43xx_phy_write(bcm, 0x0427, 0x0008);
2295 else
2296 bcm43xx_phy_write(bcm, 0x0427,
2297 (bcm43xx_phy_read(bcm, 0x0427)
2298 & 0x00FF) | 0x0008);
2299 }
2300 else if (phy->rev >= 6)
2301 bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
2302 } else {
2303 if (phy->rev < 3)
2304 bcm43xx_phy_write(bcm, 0x002B,
2305 (bcm43xx_phy_read(bcm, 0x002B)
2306 & 0x00FF) | 0x0024);
2307 else {
2308 bcm43xx_phy_write(bcm, 0x0061,
2309 bcm43xx_phy_read(bcm, 0x0061)
2310 | 0x0010);
2311 if (phy->rev == 3) {
2312 bcm43xx_phy_write(bcm, 0x0093, 0x001D);
2313 bcm43xx_phy_write(bcm, 0x0027, 0x0008);
2314 } else {
2315 bcm43xx_phy_write(bcm, 0x0093, 0x003A);
2316 bcm43xx_phy_write(bcm, 0x0027,
2317 (bcm43xx_phy_read(bcm, 0x0027)
2318 & 0x00FF) | 0x0008);
2319 }
2320 }
2321 }
2322 break;
2323 case BCM43xx_PHYTYPE_B:
2324 if (bcm->current_core->rev == 2)
2325 value = (3/*automatic*/ << 7);
2326 else
2327 value = (antennadiv << 7);
2328 bcm43xx_phy_write(bcm, 0x03E2,
2329 (bcm43xx_phy_read(bcm, 0x03E2)
2330 & 0xFE7F) | value);
2331 break;
2332 default:
2333 assert(0);
2334 }
2335
2336 if (antennadiv >= 2) {
2337 ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
2338 BCM43xx_UCODEFLAGS_OFFSET);
2339 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
2340 BCM43xx_UCODEFLAGS_OFFSET,
2341 ucodeflags | BCM43xx_UCODEFLAG_AUTODIV);
2342 }
2343
2344 phy->antenna_diversity = antennadiv;
2345}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_phy.h b/drivers/net/wireless/bcm43xx/bcm43xx_phy.h
new file mode 100644
index 000000000000..1f321ef42be8
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_phy.h
@@ -0,0 +1,74 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#ifndef BCM43xx_PHY_H_
32#define BCM43xx_PHY_H_
33
34#include <linux/types.h>
35
36struct bcm43xx_private;
37
38void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm);
39#define bcm43xx_phy_lock(bcm, flags) \
40 do { \
41 local_irq_save(flags); \
42 bcm43xx_raw_phy_lock(bcm); \
43 } while (0)
44void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm);
45#define bcm43xx_phy_unlock(bcm, flags) \
46 do { \
47 bcm43xx_raw_phy_unlock(bcm); \
48 local_irq_restore(flags); \
49 } while (0)
50
51u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset);
52void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
53
54int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm);
55int bcm43xx_phy_init(struct bcm43xx_private *bcm);
56
57void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm);
58void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm);
59int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect);
60
61void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm);
62void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm);
63void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm);
64
65/* Adjust the LocalOscillator to the saved values.
66 * "fixed" is only set to 1 once in initialization. Set to 0 otherwise.
67 */
68void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed);
69void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm);
70
71void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
72 u16 baseband_attenuation);
73
74#endif /* BCM43xx_PHY_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_pio.c b/drivers/net/wireless/bcm43xx/bcm43xx_pio.c
new file mode 100644
index 000000000000..c59ddd40680d
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_pio.c
@@ -0,0 +1,606 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 PIO Transmission
6
7 Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23
24*/
25
26#include "bcm43xx.h"
27#include "bcm43xx_pio.h"
28#include "bcm43xx_main.h"
29#include "bcm43xx_xmit.h"
30
31#include <linux/delay.h>
32
33
34static void tx_start(struct bcm43xx_pioqueue *queue)
35{
36 bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
37 BCM43xx_PIO_TXCTL_INIT);
38}
39
40static void tx_octet(struct bcm43xx_pioqueue *queue,
41 u8 octet)
42{
43 if (queue->need_workarounds) {
44 bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
45 octet);
46 bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
47 BCM43xx_PIO_TXCTL_WRITEHI);
48 } else {
49 bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
50 BCM43xx_PIO_TXCTL_WRITEHI);
51 bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
52 octet);
53 }
54}
55
56static u16 tx_get_next_word(struct bcm43xx_txhdr *txhdr,
57 const u8 *packet,
58 unsigned int *pos)
59{
60 const u8 *source;
61 unsigned int i = *pos;
62 u16 ret;
63
64 if (i < sizeof(*txhdr)) {
65 source = (const u8 *)txhdr;
66 } else {
67 source = packet;
68 i -= sizeof(*txhdr);
69 }
70 ret = le16_to_cpu( *((u16 *)(source + i)) );
71 *pos += 2;
72
73 return ret;
74}
75
76static void tx_data(struct bcm43xx_pioqueue *queue,
77 struct bcm43xx_txhdr *txhdr,
78 const u8 *packet,
79 unsigned int octets)
80{
81 u16 data;
82 unsigned int i = 0;
83
84 if (queue->need_workarounds) {
85 data = tx_get_next_word(txhdr, packet, &i);
86 bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
87 }
88 bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
89 BCM43xx_PIO_TXCTL_WRITELO |
90 BCM43xx_PIO_TXCTL_WRITEHI);
91 while (i < octets - 1) {
92 data = tx_get_next_word(txhdr, packet, &i);
93 bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
94 }
95 if (octets % 2)
96 tx_octet(queue, packet[octets - sizeof(*txhdr) - 1]);
97}
98
99static void tx_complete(struct bcm43xx_pioqueue *queue,
100 struct sk_buff *skb)
101{
102 if (queue->need_workarounds) {
103 bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
104 skb->data[skb->len - 1]);
105 bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
106 BCM43xx_PIO_TXCTL_WRITEHI |
107 BCM43xx_PIO_TXCTL_COMPLETE);
108 } else {
109 bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
110 BCM43xx_PIO_TXCTL_COMPLETE);
111 }
112}
113
114static u16 generate_cookie(struct bcm43xx_pioqueue *queue,
115 int packetindex)
116{
117 u16 cookie = 0x0000;
118
119 /* We use the upper 4 bits for the PIO
120 * controller ID and the lower 12 bits
121 * for the packet index (in the cache).
122 */
123 switch (queue->mmio_base) {
124 case BCM43xx_MMIO_PIO1_BASE:
125 break;
126 case BCM43xx_MMIO_PIO2_BASE:
127 cookie = 0x1000;
128 break;
129 case BCM43xx_MMIO_PIO3_BASE:
130 cookie = 0x2000;
131 break;
132 case BCM43xx_MMIO_PIO4_BASE:
133 cookie = 0x3000;
134 break;
135 default:
136 assert(0);
137 }
138 assert(((u16)packetindex & 0xF000) == 0x0000);
139 cookie |= (u16)packetindex;
140
141 return cookie;
142}
143
144static
145struct bcm43xx_pioqueue * parse_cookie(struct bcm43xx_private *bcm,
146 u16 cookie,
147 struct bcm43xx_pio_txpacket **packet)
148{
149 struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
150 struct bcm43xx_pioqueue *queue = NULL;
151 int packetindex;
152
153 switch (cookie & 0xF000) {
154 case 0x0000:
155 queue = pio->queue0;
156 break;
157 case 0x1000:
158 queue = pio->queue1;
159 break;
160 case 0x2000:
161 queue = pio->queue2;
162 break;
163 case 0x3000:
164 queue = pio->queue3;
165 break;
166 default:
167 assert(0);
168 }
169 packetindex = (cookie & 0x0FFF);
170 assert(packetindex >= 0 && packetindex < BCM43xx_PIO_MAXTXPACKETS);
171 *packet = &(queue->tx_packets_cache[packetindex]);
172
173 return queue;
174}
175
176static void pio_tx_write_fragment(struct bcm43xx_pioqueue *queue,
177 struct sk_buff *skb,
178 struct bcm43xx_pio_txpacket *packet)
179{
180 struct bcm43xx_txhdr txhdr;
181 unsigned int octets;
182
183 assert(skb_shinfo(skb)->nr_frags == 0);
184 bcm43xx_generate_txhdr(queue->bcm,
185 &txhdr, skb->data, skb->len,
186 (packet->xmitted_frags == 0),
187 generate_cookie(queue, pio_txpacket_getindex(packet)));
188
189 tx_start(queue);
190 octets = skb->len + sizeof(txhdr);
191 if (queue->need_workarounds)
192 octets--;
193 tx_data(queue, &txhdr, (u8 *)skb->data, octets);
194 tx_complete(queue, skb);
195}
196
197static void free_txpacket(struct bcm43xx_pio_txpacket *packet,
198 int irq_context)
199{
200 struct bcm43xx_pioqueue *queue = packet->queue;
201
202 ieee80211_txb_free(packet->txb);
203 list_move(&packet->list, &queue->txfree);
204 queue->nr_txfree++;
205
206 assert(queue->tx_devq_used >= packet->xmitted_octets);
207 assert(queue->tx_devq_packets >= packet->xmitted_frags);
208 queue->tx_devq_used -= packet->xmitted_octets;
209 queue->tx_devq_packets -= packet->xmitted_frags;
210}
211
212static int pio_tx_packet(struct bcm43xx_pio_txpacket *packet)
213{
214 struct bcm43xx_pioqueue *queue = packet->queue;
215 struct ieee80211_txb *txb = packet->txb;
216 struct sk_buff *skb;
217 u16 octets;
218 int i;
219
220 for (i = packet->xmitted_frags; i < txb->nr_frags; i++) {
221 skb = txb->fragments[i];
222
223 octets = (u16)skb->len + sizeof(struct bcm43xx_txhdr);
224 assert(queue->tx_devq_size >= octets);
225 assert(queue->tx_devq_packets <= BCM43xx_PIO_MAXTXDEVQPACKETS);
226 assert(queue->tx_devq_used <= queue->tx_devq_size);
227 /* Check if there is sufficient free space on the device
228 * TX queue. If not, return and let the TX tasklet
229 * retry later.
230 */
231 if (queue->tx_devq_packets == BCM43xx_PIO_MAXTXDEVQPACKETS)
232 return -EBUSY;
233 if (queue->tx_devq_used + octets > queue->tx_devq_size)
234 return -EBUSY;
235 /* Now poke the device. */
236 pio_tx_write_fragment(queue, skb, packet);
237
238 /* Account for the packet size.
239 * (We must not overflow the device TX queue)
240 */
241 queue->tx_devq_packets++;
242 queue->tx_devq_used += octets;
243
244 assert(packet->xmitted_frags <= packet->txb->nr_frags);
245 packet->xmitted_frags++;
246 packet->xmitted_octets += octets;
247 }
248 list_move_tail(&packet->list, &queue->txrunning);
249
250 return 0;
251}
252
253static void tx_tasklet(unsigned long d)
254{
255 struct bcm43xx_pioqueue *queue = (struct bcm43xx_pioqueue *)d;
256 struct bcm43xx_private *bcm = queue->bcm;
257 unsigned long flags;
258 struct bcm43xx_pio_txpacket *packet, *tmp_packet;
259 int err;
260
261 bcm43xx_lock_mmio(bcm, flags);
262 list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) {
263 assert(packet->xmitted_frags < packet->txb->nr_frags);
264 if (packet->xmitted_frags == 0) {
265 int i;
266 struct sk_buff *skb;
267
268 /* Check if the device queue is big
269 * enough for every fragment. If not, drop the
270 * whole packet.
271 */
272 for (i = 0; i < packet->txb->nr_frags; i++) {
273 skb = packet->txb->fragments[i];
274 if (unlikely(skb->len > queue->tx_devq_size)) {
275 dprintkl(KERN_ERR PFX "PIO TX device queue too small. "
276 "Dropping packet.\n");
277 free_txpacket(packet, 1);
278 goto next_packet;
279 }
280 }
281 }
282 /* Try to transmit the packet.
283 * This may not completely succeed.
284 */
285 err = pio_tx_packet(packet);
286 if (err)
287 break;
288 next_packet:
289 continue;
290 }
291 bcm43xx_unlock_mmio(bcm, flags);
292}
293
294static void setup_txqueues(struct bcm43xx_pioqueue *queue)
295{
296 struct bcm43xx_pio_txpacket *packet;
297 int i;
298
299 queue->nr_txfree = BCM43xx_PIO_MAXTXPACKETS;
300 for (i = 0; i < BCM43xx_PIO_MAXTXPACKETS; i++) {
301 packet = &(queue->tx_packets_cache[i]);
302
303 packet->queue = queue;
304 INIT_LIST_HEAD(&packet->list);
305
306 list_add(&packet->list, &queue->txfree);
307 }
308}
309
310static
311struct bcm43xx_pioqueue * bcm43xx_setup_pioqueue(struct bcm43xx_private *bcm,
312 u16 pio_mmio_base)
313{
314 struct bcm43xx_pioqueue *queue;
315 u32 value;
316 u16 qsize;
317
318 queue = kzalloc(sizeof(*queue), GFP_KERNEL);
319 if (!queue)
320 goto out;
321
322 queue->bcm = bcm;
323 queue->mmio_base = pio_mmio_base;
324 queue->need_workarounds = (bcm->current_core->rev < 3);
325
326 INIT_LIST_HEAD(&queue->txfree);
327 INIT_LIST_HEAD(&queue->txqueue);
328 INIT_LIST_HEAD(&queue->txrunning);
329 tasklet_init(&queue->txtask, tx_tasklet,
330 (unsigned long)queue);
331
332 value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
333 value |= BCM43xx_SBF_XFER_REG_BYTESWAP;
334 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value);
335
336 qsize = bcm43xx_read16(bcm, queue->mmio_base + BCM43xx_PIO_TXQBUFSIZE);
337 if (qsize <= BCM43xx_PIO_TXQADJUST) {
338 printk(KERN_ERR PFX "PIO tx device-queue too small (%u)\n", qsize);
339 goto err_freequeue;
340 }
341 qsize -= BCM43xx_PIO_TXQADJUST;
342 queue->tx_devq_size = qsize;
343
344 setup_txqueues(queue);
345
346out:
347 return queue;
348
349err_freequeue:
350 kfree(queue);
351 queue = NULL;
352 goto out;
353}
354
355static void cancel_transfers(struct bcm43xx_pioqueue *queue)
356{
357 struct bcm43xx_pio_txpacket *packet, *tmp_packet;
358
359 netif_tx_disable(queue->bcm->net_dev);
360 assert(queue->bcm->shutting_down);
361 tasklet_disable(&queue->txtask);
362
363 list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list)
364 free_txpacket(packet, 0);
365 list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list)
366 free_txpacket(packet, 0);
367}
368
369static void bcm43xx_destroy_pioqueue(struct bcm43xx_pioqueue *queue)
370{
371 if (!queue)
372 return;
373
374 cancel_transfers(queue);
375 kfree(queue);
376}
377
378void bcm43xx_pio_free(struct bcm43xx_private *bcm)
379{
380 struct bcm43xx_pio *pio;
381
382 if (!bcm43xx_using_pio(bcm))
383 return;
384 pio = bcm43xx_current_pio(bcm);
385
386 bcm43xx_destroy_pioqueue(pio->queue3);
387 pio->queue3 = NULL;
388 bcm43xx_destroy_pioqueue(pio->queue2);
389 pio->queue2 = NULL;
390 bcm43xx_destroy_pioqueue(pio->queue1);
391 pio->queue1 = NULL;
392 bcm43xx_destroy_pioqueue(pio->queue0);
393 pio->queue0 = NULL;
394}
395
396int bcm43xx_pio_init(struct bcm43xx_private *bcm)
397{
398 struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
399 struct bcm43xx_pioqueue *queue;
400 int err = -ENOMEM;
401
402 queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO1_BASE);
403 if (!queue)
404 goto out;
405 pio->queue0 = queue;
406
407 queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO2_BASE);
408 if (!queue)
409 goto err_destroy0;
410 pio->queue1 = queue;
411
412 queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO3_BASE);
413 if (!queue)
414 goto err_destroy1;
415 pio->queue2 = queue;
416
417 queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO4_BASE);
418 if (!queue)
419 goto err_destroy2;
420 pio->queue3 = queue;
421
422 if (bcm->current_core->rev < 3)
423 bcm->irq_savedstate |= BCM43xx_IRQ_PIO_WORKAROUND;
424
425 dprintk(KERN_INFO PFX "PIO initialized\n");
426 err = 0;
427out:
428 return err;
429
430err_destroy2:
431 bcm43xx_destroy_pioqueue(pio->queue2);
432 pio->queue2 = NULL;
433err_destroy1:
434 bcm43xx_destroy_pioqueue(pio->queue1);
435 pio->queue1 = NULL;
436err_destroy0:
437 bcm43xx_destroy_pioqueue(pio->queue0);
438 pio->queue0 = NULL;
439 goto out;
440}
441
442int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
443 struct ieee80211_txb *txb)
444{
445 struct bcm43xx_pioqueue *queue = bcm43xx_current_pio(bcm)->queue1;
446 struct bcm43xx_pio_txpacket *packet;
447 u16 tmp;
448
449 assert(!queue->tx_suspended);
450 assert(!list_empty(&queue->txfree));
451
452 tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL);
453 if (tmp & BCM43xx_PIO_TXCTL_SUSPEND)
454 return -EBUSY;
455
456 packet = list_entry(queue->txfree.next, struct bcm43xx_pio_txpacket, list);
457 packet->txb = txb;
458 packet->xmitted_frags = 0;
459 packet->xmitted_octets = 0;
460 list_move_tail(&packet->list, &queue->txqueue);
461 queue->nr_txfree--;
462 assert(queue->nr_txfree < BCM43xx_PIO_MAXTXPACKETS);
463
464 /* Suspend TX, if we are out of packets in the "free" queue. */
465 if (unlikely(list_empty(&queue->txfree))) {
466 netif_stop_queue(queue->bcm->net_dev);
467 queue->tx_suspended = 1;
468 }
469
470 tasklet_schedule(&queue->txtask);
471
472 return 0;
473}
474
475void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
476 struct bcm43xx_xmitstatus *status)
477{
478 struct bcm43xx_pioqueue *queue;
479 struct bcm43xx_pio_txpacket *packet;
480
481 queue = parse_cookie(bcm, status->cookie, &packet);
482 assert(queue);
483//TODO
484if (!queue)
485return;
486 free_txpacket(packet, 1);
487 if (unlikely(queue->tx_suspended)) {
488 queue->tx_suspended = 0;
489 netif_wake_queue(queue->bcm->net_dev);
490 }
491 /* If there are packets on the txqueue, poke the tasklet. */
492 if (!list_empty(&queue->txqueue))
493 tasklet_schedule(&queue->txtask);
494}
495
496static void pio_rx_error(struct bcm43xx_pioqueue *queue,
497 int clear_buffers,
498 const char *error)
499{
500 int i;
501
502 printkl("PIO RX error: %s\n", error);
503 bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
504 BCM43xx_PIO_RXCTL_READY);
505 if (clear_buffers) {
506 assert(queue->mmio_base == BCM43xx_MMIO_PIO1_BASE);
507 for (i = 0; i < 15; i++) {
508 /* Dummy read. */
509 bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
510 }
511 }
512}
513
514void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
515{
516 u16 preamble[21] = { 0 };
517 struct bcm43xx_rxhdr *rxhdr;
518 u16 tmp, len, rxflags2;
519 int i, preamble_readwords;
520 struct sk_buff *skb;
521
522return;
523 tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
524 if (!(tmp & BCM43xx_PIO_RXCTL_DATAAVAILABLE)) {
525 dprintkl(KERN_ERR PFX "PIO RX: No data available\n");//TODO: remove this printk.
526 return;
527 }
528 bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
529 BCM43xx_PIO_RXCTL_DATAAVAILABLE);
530
531 for (i = 0; i < 10; i++) {
532 tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
533 if (tmp & BCM43xx_PIO_RXCTL_READY)
534 goto data_ready;
535 udelay(10);
536 }
537 dprintkl(KERN_ERR PFX "PIO RX timed out\n");
538 return;
539data_ready:
540
541//FIXME: endianess in this function.
542 len = le16_to_cpu(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA));
543 if (unlikely(len > 0x700)) {
544 pio_rx_error(queue, 0, "len > 0x700");
545 return;
546 }
547 if (unlikely(len == 0 && queue->mmio_base != BCM43xx_MMIO_PIO4_BASE)) {
548 pio_rx_error(queue, 0, "len == 0");
549 return;
550 }
551 preamble[0] = cpu_to_le16(len);
552 if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE)
553 preamble_readwords = 14 / sizeof(u16);
554 else
555 preamble_readwords = 18 / sizeof(u16);
556 for (i = 0; i < preamble_readwords; i++) {
557 tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
558 preamble[i + 1] = cpu_to_be16(tmp);//FIXME?
559 }
560 rxhdr = (struct bcm43xx_rxhdr *)preamble;
561 rxflags2 = le16_to_cpu(rxhdr->flags2);
562 if (unlikely(rxflags2 & BCM43xx_RXHDR_FLAGS2_INVALIDFRAME)) {
563 pio_rx_error(queue,
564 (queue->mmio_base == BCM43xx_MMIO_PIO1_BASE),
565 "invalid frame");
566 return;
567 }
568 if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE) {
569 /* We received an xmit status. */
570 struct bcm43xx_hwxmitstatus *hw;
571 struct bcm43xx_xmitstatus stat;
572
573 hw = (struct bcm43xx_hwxmitstatus *)(preamble + 1);
574 stat.cookie = le16_to_cpu(hw->cookie);
575 stat.flags = hw->flags;
576 stat.cnt1 = hw->cnt1;
577 stat.cnt2 = hw->cnt2;
578 stat.seq = le16_to_cpu(hw->seq);
579 stat.unknown = le16_to_cpu(hw->unknown);
580
581 bcm43xx_debugfs_log_txstat(queue->bcm, &stat);
582 bcm43xx_pio_handle_xmitstatus(queue->bcm, &stat);
583
584 return;
585 }
586
587 skb = dev_alloc_skb(len);
588 if (unlikely(!skb)) {
589 pio_rx_error(queue, 1, "OOM");
590 return;
591 }
592 skb_put(skb, len);
593 for (i = 0; i < len - 1; i += 2) {
594 tmp = cpu_to_be16(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA));
595 *((u16 *)(skb->data + i)) = tmp;
596 }
597 if (len % 2) {
598 tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
599 skb->data[len - 1] = (tmp & 0x00FF);
600 if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME)
601 skb->data[0x20] = (tmp & 0xFF00) >> 8;
602 else
603 skb->data[0x1E] = (tmp & 0xFF00) >> 8;
604 }
605 bcm43xx_rx(queue->bcm, skb, rxhdr);
606}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_pio.h b/drivers/net/wireless/bcm43xx/bcm43xx_pio.h
new file mode 100644
index 000000000000..970627bc1769
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_pio.h
@@ -0,0 +1,138 @@
1#ifndef BCM43xx_PIO_H_
2#define BCM43xx_PIO_H_
3
4#include "bcm43xx.h"
5
6#include <linux/interrupt.h>
7#include <linux/list.h>
8#include <linux/skbuff.h>
9
10
11#define BCM43xx_PIO_TXCTL 0x00
12#define BCM43xx_PIO_TXDATA 0x02
13#define BCM43xx_PIO_TXQBUFSIZE 0x04
14#define BCM43xx_PIO_RXCTL 0x08
15#define BCM43xx_PIO_RXDATA 0x0A
16
17#define BCM43xx_PIO_TXCTL_WRITEHI (1 << 0)
18#define BCM43xx_PIO_TXCTL_WRITELO (1 << 1)
19#define BCM43xx_PIO_TXCTL_COMPLETE (1 << 2)
20#define BCM43xx_PIO_TXCTL_INIT (1 << 3)
21#define BCM43xx_PIO_TXCTL_SUSPEND (1 << 7)
22
23#define BCM43xx_PIO_RXCTL_DATAAVAILABLE (1 << 0)
24#define BCM43xx_PIO_RXCTL_READY (1 << 1)
25
26/* PIO constants */
27#define BCM43xx_PIO_MAXTXDEVQPACKETS 31
28#define BCM43xx_PIO_TXQADJUST 80
29
30/* PIO tuning knobs */
31#define BCM43xx_PIO_MAXTXPACKETS 256
32
33
34
35#ifdef CONFIG_BCM43XX_PIO
36
37
38struct bcm43xx_pioqueue;
39struct bcm43xx_xmitstatus;
40
41struct bcm43xx_pio_txpacket {
42 struct bcm43xx_pioqueue *queue;
43 struct ieee80211_txb *txb;
44 struct list_head list;
45
46 u8 xmitted_frags;
47 u16 xmitted_octets;
48};
49
50#define pio_txpacket_getindex(packet) ((int)((packet) - (packet)->queue->tx_packets_cache))
51
52struct bcm43xx_pioqueue {
53 struct bcm43xx_private *bcm;
54 u16 mmio_base;
55
56 u8 tx_suspended:1,
57 need_workarounds:1; /* Workarounds needed for core.rev < 3 */
58
59 /* Adjusted size of the device internal TX buffer. */
60 u16 tx_devq_size;
61 /* Used octets of the device internal TX buffer. */
62 u16 tx_devq_used;
63 /* Used packet slots in the device internal TX buffer. */
64 u8 tx_devq_packets;
65 /* Packets from the txfree list can
66 * be taken on incoming TX requests.
67 */
68 struct list_head txfree;
69 unsigned int nr_txfree;
70 /* Packets on the txqueue are queued,
71 * but not completely written to the chip, yet.
72 */
73 struct list_head txqueue;
74 /* Packets on the txrunning queue are completely
75 * posted to the device. We are waiting for the txstatus.
76 */
77 struct list_head txrunning;
78 /* Total number or packets sent.
79 * (This counter can obviously wrap).
80 */
81 unsigned int nr_tx_packets;
82 struct tasklet_struct txtask;
83 struct bcm43xx_pio_txpacket tx_packets_cache[BCM43xx_PIO_MAXTXPACKETS];
84};
85
86static inline
87u16 bcm43xx_pio_read(struct bcm43xx_pioqueue *queue,
88 u16 offset)
89{
90 return bcm43xx_read16(queue->bcm, queue->mmio_base + offset);
91}
92
93static inline
94void bcm43xx_pio_write(struct bcm43xx_pioqueue *queue,
95 u16 offset, u16 value)
96{
97 bcm43xx_write16(queue->bcm, queue->mmio_base + offset, value);
98}
99
100
101int bcm43xx_pio_init(struct bcm43xx_private *bcm);
102void bcm43xx_pio_free(struct bcm43xx_private *bcm);
103
104int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
105 struct ieee80211_txb *txb);
106void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
107 struct bcm43xx_xmitstatus *status);
108void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue);
109
110#else /* CONFIG_BCM43XX_PIO */
111
112static inline
113int bcm43xx_pio_init(struct bcm43xx_private *bcm)
114{
115 return 0;
116}
117static inline
118void bcm43xx_pio_free(struct bcm43xx_private *bcm)
119{
120}
121static inline
122int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
123 struct ieee80211_txb *txb)
124{
125 return 0;
126}
127static inline
128void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
129 struct bcm43xx_xmitstatus *status)
130{
131}
132static inline
133void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
134{
135}
136
137#endif /* CONFIG_BCM43XX_PIO */
138#endif /* BCM43xx_PIO_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_power.c b/drivers/net/wireless/bcm43xx/bcm43xx_power.c
new file mode 100644
index 000000000000..3c92b62807c5
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_power.c
@@ -0,0 +1,358 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#include <linux/delay.h>
32
33#include "bcm43xx.h"
34#include "bcm43xx_power.h"
35#include "bcm43xx_main.h"
36
37
38/* Get max/min slowclock frequency
39 * as described in http://bcm-specs.sipsolutions.net/PowerControl
40 */
41static int bcm43xx_pctl_clockfreqlimit(struct bcm43xx_private *bcm,
42 int get_max)
43{
44 int limit = 0;
45 int divisor;
46 int selection;
47 int err;
48 u32 tmp;
49 struct bcm43xx_coreinfo *old_core;
50
51 if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
52 goto out;
53 old_core = bcm->current_core;
54 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
55 if (err)
56 goto out;
57
58 if (bcm->current_core->rev < 6) {
59 if ((bcm->bustype == BCM43xx_BUSTYPE_PCMCIA) ||
60 (bcm->bustype == BCM43xx_BUSTYPE_SB)) {
61 selection = 1;
62 divisor = 32;
63 } else {
64 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &tmp);
65 if (err) {
66 printk(KERN_ERR PFX "clockfreqlimit pcicfg read failure\n");
67 goto out_switchback;
68 }
69 if (tmp & 0x10) {
70 /* PCI */
71 selection = 2;
72 divisor = 64;
73 } else {
74 /* XTAL */
75 selection = 1;
76 divisor = 32;
77 }
78 }
79 } else if (bcm->current_core->rev < 10) {
80 selection = (tmp & 0x07);
81 if (selection) {
82 tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
83 divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
84 } else
85 divisor = 1;
86 } else {
87 tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SYSCLKCTL);
88 divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
89 selection = 1;
90 }
91
92 switch (selection) {
93 case 0:
94 /* LPO */
95 if (get_max)
96 limit = 43000;
97 else
98 limit = 25000;
99 break;
100 case 1:
101 /* XTAL */
102 if (get_max)
103 limit = 20200000;
104 else
105 limit = 19800000;
106 break;
107 case 2:
108 /* PCI */
109 if (get_max)
110 limit = 34000000;
111 else
112 limit = 25000000;
113 break;
114 default:
115 assert(0);
116 }
117 limit /= divisor;
118
119out_switchback:
120 err = bcm43xx_switch_core(bcm, old_core);
121 assert(err == 0);
122
123out:
124 return limit;
125}
126
127/* init power control
128 * as described in http://bcm-specs.sipsolutions.net/PowerControl
129 */
130int bcm43xx_pctl_init(struct bcm43xx_private *bcm)
131{
132 int err, maxfreq;
133 struct bcm43xx_coreinfo *old_core;
134
135 if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
136 return 0;
137 old_core = bcm->current_core;
138 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
139 if (err == -ENODEV)
140 return 0;
141 if (err)
142 goto out;
143
144 maxfreq = bcm43xx_pctl_clockfreqlimit(bcm, 1);
145 bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_PLLONDELAY,
146 (maxfreq * 150 + 999999) / 1000000);
147 bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_FREFSELDELAY,
148 (maxfreq * 15 + 999999) / 1000000);
149
150 err = bcm43xx_switch_core(bcm, old_core);
151 assert(err == 0);
152
153out:
154 return err;
155}
156
157u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm)
158{
159 u16 delay = 0;
160 int err;
161 u32 pll_on_delay;
162 struct bcm43xx_coreinfo *old_core;
163 int minfreq;
164
165 if (bcm->bustype != BCM43xx_BUSTYPE_PCI)
166 goto out;
167 if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
168 goto out;
169 old_core = bcm->current_core;
170 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
171 if (err == -ENODEV)
172 goto out;
173
174 minfreq = bcm43xx_pctl_clockfreqlimit(bcm, 0);
175 pll_on_delay = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_PLLONDELAY);
176 delay = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq;
177
178 err = bcm43xx_switch_core(bcm, old_core);
179 assert(err == 0);
180
181out:
182 return delay;
183}
184
185/* set the powercontrol clock
186 * as described in http://bcm-specs.sipsolutions.net/PowerControl
187 */
188int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode)
189{
190 int err;
191 struct bcm43xx_coreinfo *old_core;
192 u32 tmp;
193
194 old_core = bcm->current_core;
195 err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
196 if (err == -ENODEV)
197 return 0;
198 if (err)
199 goto out;
200
201 if (bcm->core_chipcommon.rev < 6) {
202 if (mode == BCM43xx_PCTL_CLK_FAST) {
203 err = bcm43xx_pctl_set_crystal(bcm, 1);
204 if (err)
205 goto out;
206 }
207 } else {
208 if ((bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL) &&
209 (bcm->core_chipcommon.rev < 10)) {
210 switch (mode) {
211 case BCM43xx_PCTL_CLK_FAST:
212 tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
213 tmp = (tmp & ~BCM43xx_PCTL_FORCE_SLOW) | BCM43xx_PCTL_FORCE_PLL;
214 bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
215 break;
216 case BCM43xx_PCTL_CLK_SLOW:
217 tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
218 tmp |= BCM43xx_PCTL_FORCE_SLOW;
219 bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
220 break;
221 case BCM43xx_PCTL_CLK_DYNAMIC:
222 tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
223 tmp &= ~BCM43xx_PCTL_FORCE_SLOW;
224 tmp |= BCM43xx_PCTL_FORCE_PLL;
225 tmp &= ~BCM43xx_PCTL_DYN_XTAL;
226 bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
227 }
228 }
229 }
230
231 err = bcm43xx_switch_core(bcm, old_core);
232 assert(err == 0);
233
234out:
235 return err;
236}
237
238int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on)
239{
240 int err;
241 u32 in, out, outenable;
242
243 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_IN, &in);
244 if (err)
245 goto err_pci;
246 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &out);
247 if (err)
248 goto err_pci;
249 err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUTENABLE, &outenable);
250 if (err)
251 goto err_pci;
252
253 outenable |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
254
255 if (on) {
256 if (in & 0x40)
257 return 0;
258
259 out |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
260
261 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
262 if (err)
263 goto err_pci;
264 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
265 if (err)
266 goto err_pci;
267 udelay(1000);
268
269 out &= ~BCM43xx_PCTL_PLL_POWERDOWN;
270 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
271 if (err)
272 goto err_pci;
273 udelay(5000);
274 } else {
275 if (bcm->current_core->rev < 5)
276 return 0;
277 if (bcm->sprom.boardflags & BCM43xx_BFL_XTAL_NOSLOW)
278 return 0;
279
280/* XXX: Why BCM43xx_MMIO_RADIO_HWENABLED_xx can't be read at this time?
281 * err = bcm43xx_switch_core(bcm, bcm->active_80211_core);
282 * if (err)
283 * return err;
284 * if (((bcm->current_core->rev >= 3) &&
285 * (bcm43xx_read32(bcm, BCM43xx_MMIO_RADIO_HWENABLED_HI) & (1 << 16))) ||
286 * ((bcm->current_core->rev < 3) &&
287 * !(bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_HWENABLED_LO) & (1 << 4))))
288 * return 0;
289 * err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
290 * if (err)
291 * return err;
292 */
293
294 err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
295 if (err)
296 goto out;
297 out &= ~BCM43xx_PCTL_XTAL_POWERUP;
298 out |= BCM43xx_PCTL_PLL_POWERDOWN;
299 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
300 if (err)
301 goto err_pci;
302 err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
303 if (err)
304 goto err_pci;
305 }
306
307out:
308 return err;
309
310err_pci:
311 printk(KERN_ERR PFX "Error: pctl_set_clock() could not access PCI config space!\n");
312 err = -EBUSY;
313 goto out;
314}
315
316/* Set the PowerSavingControlBits.
317 * Bitvalues:
318 * 0 => unset the bit
319 * 1 => set the bit
320 * -1 => calculate the bit
321 */
322void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
323 int bit25, int bit26)
324{
325 int i;
326 u32 status;
327
328//FIXME: Force 25 to off and 26 to on for now:
329bit25 = 0;
330bit26 = 1;
331
332 if (bit25 == -1) {
333 //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
334 // and thus is not an AP and we are associated, set bit 25
335 }
336 if (bit26 == -1) {
337 //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
338 // or we are associated, or FIXME, or the latest PS-Poll packet sent was
339 // successful, set bit26
340 }
341 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
342 if (bit25)
343 status |= BCM43xx_SBF_PS1;
344 else
345 status &= ~BCM43xx_SBF_PS1;
346 if (bit26)
347 status |= BCM43xx_SBF_PS2;
348 else
349 status &= ~BCM43xx_SBF_PS2;
350 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
351 if (bit26 && bcm->current_core->rev >= 5) {
352 for (i = 0; i < 100; i++) {
353 if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0040) != 4)
354 break;
355 udelay(10);
356 }
357 }
358}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_power.h b/drivers/net/wireless/bcm43xx/bcm43xx_power.h
new file mode 100644
index 000000000000..5f63640810bd
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_power.h
@@ -0,0 +1,47 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#ifndef BCM43xx_POWER_H_
32#define BCM43xx_POWER_H_
33
34#include <linux/types.h>
35
36
37struct bcm43xx_private;
38
39int bcm43xx_pctl_init(struct bcm43xx_private *bcm);
40int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode);
41int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on);
42u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm);
43
44void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
45 int bit25, int bit26);
46
47#endif /* BCM43xx_POWER_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_radio.c b/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
new file mode 100644
index 000000000000..af5c0bff1696
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_radio.c
@@ -0,0 +1,2026 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#include <linux/delay.h>
32
33#include "bcm43xx.h"
34#include "bcm43xx_main.h"
35#include "bcm43xx_phy.h"
36#include "bcm43xx_radio.h"
37#include "bcm43xx_ilt.h"
38
39
40/* Table for bcm43xx_radio_calibrationvalue() */
41static const u16 rcc_table[16] = {
42 0x0002, 0x0003, 0x0001, 0x000F,
43 0x0006, 0x0007, 0x0005, 0x000F,
44 0x000A, 0x000B, 0x0009, 0x000F,
45 0x000E, 0x000F, 0x000D, 0x000F,
46};
47
48/* Reverse the bits of a 4bit value.
49 * Example: 1101 is flipped 1011
50 */
51static u16 flip_4bit(u16 value)
52{
53 u16 flipped = 0x0000;
54
55 assert((value & ~0x000F) == 0x0000);
56
57 flipped |= (value & 0x0001) << 3;
58 flipped |= (value & 0x0002) << 1;
59 flipped |= (value & 0x0004) >> 1;
60 flipped |= (value & 0x0008) >> 3;
61
62 return flipped;
63}
64
65/* Get the freq, as it has to be written to the device. */
66static inline
67u16 channel2freq_bg(u8 channel)
68{
69 /* Frequencies are given as frequencies_bg[index] + 2.4GHz
70 * Starting with channel 1
71 */
72 static const u16 frequencies_bg[14] = {
73 12, 17, 22, 27,
74 32, 37, 42, 47,
75 52, 57, 62, 67,
76 72, 84,
77 };
78
79 assert(channel >= 1 && channel <= 14);
80
81 return frequencies_bg[channel - 1];
82}
83
84/* Get the freq, as it has to be written to the device. */
85static inline
86u16 channel2freq_a(u8 channel)
87{
88 assert(channel <= 200);
89
90 return (5000 + 5 * channel);
91}
92
93void bcm43xx_radio_lock(struct bcm43xx_private *bcm)
94{
95 u32 status;
96
97 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
98 status |= BCM43xx_SBF_RADIOREG_LOCK;
99 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
100 mmiowb();
101 udelay(10);
102}
103
104void bcm43xx_radio_unlock(struct bcm43xx_private *bcm)
105{
106 u32 status;
107
108 bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER); /* dummy read */
109 status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
110 status &= ~BCM43xx_SBF_RADIOREG_LOCK;
111 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
112 mmiowb();
113}
114
115u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset)
116{
117 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
118 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
119
120 switch (phy->type) {
121 case BCM43xx_PHYTYPE_A:
122 offset |= 0x0040;
123 break;
124 case BCM43xx_PHYTYPE_B:
125 if (radio->version == 0x2053) {
126 if (offset < 0x70)
127 offset += 0x80;
128 else if (offset < 0x80)
129 offset += 0x70;
130 } else if (radio->version == 0x2050) {
131 offset |= 0x80;
132 } else
133 assert(0);
134 break;
135 case BCM43xx_PHYTYPE_G:
136 offset |= 0x80;
137 break;
138 }
139
140 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
141 return bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
142}
143
144void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val)
145{
146 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
147 mmiowb();
148 bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW, val);
149}
150
151static void bcm43xx_set_all_gains(struct bcm43xx_private *bcm,
152 s16 first, s16 second, s16 third)
153{
154 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
155 u16 i;
156 u16 start = 0x08, end = 0x18;
157 u16 offset = 0x0400;
158 u16 tmp;
159
160 if (phy->rev <= 1) {
161 offset = 0x5000;
162 start = 0x10;
163 end = 0x20;
164 }
165
166 for (i = 0; i < 4; i++)
167 bcm43xx_ilt_write(bcm, offset + i, first);
168
169 for (i = start; i < end; i++)
170 bcm43xx_ilt_write(bcm, offset + i, second);
171
172 if (third != -1) {
173 tmp = ((u16)third << 14) | ((u16)third << 6);
174 bcm43xx_phy_write(bcm, 0x04A0,
175 (bcm43xx_phy_read(bcm, 0x04A0) & 0xBFBF) | tmp);
176 bcm43xx_phy_write(bcm, 0x04A1,
177 (bcm43xx_phy_read(bcm, 0x04A1) & 0xBFBF) | tmp);
178 bcm43xx_phy_write(bcm, 0x04A2,
179 (bcm43xx_phy_read(bcm, 0x04A2) & 0xBFBF) | tmp);
180 }
181 bcm43xx_dummy_transmission(bcm);
182}
183
184static void bcm43xx_set_original_gains(struct bcm43xx_private *bcm)
185{
186 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
187 u16 i, tmp;
188 u16 offset = 0x0400;
189 u16 start = 0x0008, end = 0x0018;
190
191 if (phy->rev <= 1) {
192 offset = 0x5000;
193 start = 0x0010;
194 end = 0x0020;
195 }
196
197 for (i = 0; i < 4; i++) {
198 tmp = (i & 0xFFFC);
199 tmp |= (i & 0x0001) << 1;
200 tmp |= (i & 0x0002) >> 1;
201
202 bcm43xx_ilt_write(bcm, offset + i, tmp);
203 }
204
205 for (i = start; i < end; i++)
206 bcm43xx_ilt_write(bcm, offset + i, i - start);
207
208 bcm43xx_phy_write(bcm, 0x04A0,
209 (bcm43xx_phy_read(bcm, 0x04A0) & 0xBFBF) | 0x4040);
210 bcm43xx_phy_write(bcm, 0x04A1,
211 (bcm43xx_phy_read(bcm, 0x04A1) & 0xBFBF) | 0x4040);
212 bcm43xx_phy_write(bcm, 0x04A2,
213 (bcm43xx_phy_read(bcm, 0x04A2) & 0xBFBF) | 0x4000);
214 bcm43xx_dummy_transmission(bcm);
215}
216
217/* Synthetic PU workaround */
218static void bcm43xx_synth_pu_workaround(struct bcm43xx_private *bcm, u8 channel)
219{
220 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
221
222 if (radio->version != 0x2050 || radio->revision >= 6) {
223 /* We do not need the workaround. */
224 return;
225 }
226
227 if (channel <= 10) {
228 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
229 channel2freq_bg(channel + 4));
230 } else {
231 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
232 channel2freq_bg(1));
233 }
234 udelay(100);
235 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
236 channel2freq_bg(channel));
237}
238
239u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel)
240{
241 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
242 u8 ret = 0;
243 u16 saved, rssi, temp;
244 int i, j = 0;
245
246 saved = bcm43xx_phy_read(bcm, 0x0403);
247 bcm43xx_radio_selectchannel(bcm, channel, 0);
248 bcm43xx_phy_write(bcm, 0x0403, (saved & 0xFFF8) | 5);
249 if (radio->aci_hw_rssi)
250 rssi = bcm43xx_phy_read(bcm, 0x048A) & 0x3F;
251 else
252 rssi = saved & 0x3F;
253 /* clamp temp to signed 5bit */
254 if (rssi > 32)
255 rssi -= 64;
256 for (i = 0;i < 100; i++) {
257 temp = (bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x3F;
258 if (temp > 32)
259 temp -= 64;
260 if (temp < rssi)
261 j++;
262 if (j >= 20)
263 ret = 1;
264 }
265 bcm43xx_phy_write(bcm, 0x0403, saved);
266
267 return ret;
268}
269
270u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm)
271{
272 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
273 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
274 u8 ret[13];
275 unsigned int channel = radio->channel;
276 unsigned int i, j, start, end;
277 unsigned long phylock_flags;
278
279 if (!((phy->type == BCM43xx_PHYTYPE_G) && (phy->rev > 0)))
280 return 0;
281
282 bcm43xx_phy_lock(bcm, phylock_flags);
283 bcm43xx_radio_lock(bcm);
284 bcm43xx_phy_write(bcm, 0x0802,
285 bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC);
286 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
287 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF);
288 bcm43xx_set_all_gains(bcm, 3, 8, 1);
289
290 start = (channel - 5 > 0) ? channel - 5 : 1;
291 end = (channel + 5 < 14) ? channel + 5 : 13;
292
293 for (i = start; i <= end; i++) {
294 if (abs(channel - i) > 2)
295 ret[i-1] = bcm43xx_radio_aci_detect(bcm, i);
296 }
297 bcm43xx_radio_selectchannel(bcm, channel, 0);
298 bcm43xx_phy_write(bcm, 0x0802,
299 (bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC) | 0x0003);
300 bcm43xx_phy_write(bcm, 0x0403,
301 bcm43xx_phy_read(bcm, 0x0403) & 0xFFF8);
302 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
303 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x8000);
304 bcm43xx_set_original_gains(bcm);
305 for (i = 0; i < 13; i++) {
306 if (!ret[i])
307 continue;
308 end = (i + 5 < 13) ? i + 5 : 13;
309 for (j = i; j < end; j++)
310 ret[j] = 1;
311 }
312 bcm43xx_radio_unlock(bcm);
313 bcm43xx_phy_unlock(bcm, phylock_flags);
314
315 return ret[channel - 1];
316}
317
318/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
319void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val)
320{
321 bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
322 mmiowb();
323 bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_DATA, (u16)val);
324}
325
326/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
327s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset)
328{
329 u16 val;
330
331 bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
332 val = bcm43xx_phy_read(bcm, BCM43xx_PHY_NRSSILT_DATA);
333
334 return (s16)val;
335}
336
337/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
338void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val)
339{
340 u16 i;
341 s16 tmp;
342
343 for (i = 0; i < 64; i++) {
344 tmp = bcm43xx_nrssi_hw_read(bcm, i);
345 tmp -= val;
346 tmp = limit_value(tmp, -32, 31);
347 bcm43xx_nrssi_hw_write(bcm, i, tmp);
348 }
349}
350
351/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
352void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm)
353{
354 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
355 s16 i, delta;
356 s32 tmp;
357
358 delta = 0x1F - radio->nrssi[0];
359 for (i = 0; i < 64; i++) {
360 tmp = (i - delta) * radio->nrssislope;
361 tmp /= 0x10000;
362 tmp += 0x3A;
363 tmp = limit_value(tmp, 0, 0x3F);
364 radio->nrssi_lt[i] = tmp;
365 }
366}
367
368static void bcm43xx_calc_nrssi_offset(struct bcm43xx_private *bcm)
369{
370 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
371 u16 backup[20] = { 0 };
372 s16 v47F;
373 u16 i;
374 u16 saved = 0xFFFF;
375
376 backup[0] = bcm43xx_phy_read(bcm, 0x0001);
377 backup[1] = bcm43xx_phy_read(bcm, 0x0811);
378 backup[2] = bcm43xx_phy_read(bcm, 0x0812);
379 backup[3] = bcm43xx_phy_read(bcm, 0x0814);
380 backup[4] = bcm43xx_phy_read(bcm, 0x0815);
381 backup[5] = bcm43xx_phy_read(bcm, 0x005A);
382 backup[6] = bcm43xx_phy_read(bcm, 0x0059);
383 backup[7] = bcm43xx_phy_read(bcm, 0x0058);
384 backup[8] = bcm43xx_phy_read(bcm, 0x000A);
385 backup[9] = bcm43xx_phy_read(bcm, 0x0003);
386 backup[10] = bcm43xx_radio_read16(bcm, 0x007A);
387 backup[11] = bcm43xx_radio_read16(bcm, 0x0043);
388
389 bcm43xx_phy_write(bcm, 0x0429,
390 bcm43xx_phy_read(bcm, 0x0429) & 0x7FFF);
391 bcm43xx_phy_write(bcm, 0x0001,
392 (bcm43xx_phy_read(bcm, 0x0001) & 0x3FFF) | 0x4000);
393 bcm43xx_phy_write(bcm, 0x0811,
394 bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
395 bcm43xx_phy_write(bcm, 0x0812,
396 (bcm43xx_phy_read(bcm, 0x0812) & 0xFFF3) | 0x0004);
397 bcm43xx_phy_write(bcm, 0x0802,
398 bcm43xx_phy_read(bcm, 0x0802) & ~(0x1 | 0x2));
399 if (phy->rev >= 6) {
400 backup[12] = bcm43xx_phy_read(bcm, 0x002E);
401 backup[13] = bcm43xx_phy_read(bcm, 0x002F);
402 backup[14] = bcm43xx_phy_read(bcm, 0x080F);
403 backup[15] = bcm43xx_phy_read(bcm, 0x0810);
404 backup[16] = bcm43xx_phy_read(bcm, 0x0801);
405 backup[17] = bcm43xx_phy_read(bcm, 0x0060);
406 backup[18] = bcm43xx_phy_read(bcm, 0x0014);
407 backup[19] = bcm43xx_phy_read(bcm, 0x0478);
408
409 bcm43xx_phy_write(bcm, 0x002E, 0);
410 bcm43xx_phy_write(bcm, 0x002F, 0);
411 bcm43xx_phy_write(bcm, 0x080F, 0);
412 bcm43xx_phy_write(bcm, 0x0810, 0);
413 bcm43xx_phy_write(bcm, 0x0478,
414 bcm43xx_phy_read(bcm, 0x0478) | 0x0100);
415 bcm43xx_phy_write(bcm, 0x0801,
416 bcm43xx_phy_read(bcm, 0x0801) | 0x0040);
417 bcm43xx_phy_write(bcm, 0x0060,
418 bcm43xx_phy_read(bcm, 0x0060) | 0x0040);
419 bcm43xx_phy_write(bcm, 0x0014,
420 bcm43xx_phy_read(bcm, 0x0014) | 0x0200);
421 }
422 bcm43xx_radio_write16(bcm, 0x007A,
423 bcm43xx_radio_read16(bcm, 0x007A) | 0x0070);
424 bcm43xx_radio_write16(bcm, 0x007A,
425 bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
426 udelay(30);
427
428 v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
429 if (v47F >= 0x20)
430 v47F -= 0x40;
431 if (v47F == 31) {
432 for (i = 7; i >= 4; i--) {
433 bcm43xx_radio_write16(bcm, 0x007B, i);
434 udelay(20);
435 v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
436 if (v47F >= 0x20)
437 v47F -= 0x40;
438 if (v47F < 31 && saved == 0xFFFF)
439 saved = i;
440 }
441 if (saved == 0xFFFF)
442 saved = 4;
443 } else {
444 bcm43xx_radio_write16(bcm, 0x007A,
445 bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
446 bcm43xx_phy_write(bcm, 0x0814,
447 bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
448 bcm43xx_phy_write(bcm, 0x0815,
449 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
450 bcm43xx_phy_write(bcm, 0x0811,
451 bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
452 bcm43xx_phy_write(bcm, 0x0812,
453 bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
454 bcm43xx_phy_write(bcm, 0x0811,
455 bcm43xx_phy_read(bcm, 0x0811) | 0x0030);
456 bcm43xx_phy_write(bcm, 0x0812,
457 bcm43xx_phy_read(bcm, 0x0812) | 0x0030);
458 bcm43xx_phy_write(bcm, 0x005A, 0x0480);
459 bcm43xx_phy_write(bcm, 0x0059, 0x0810);
460 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
461 if (phy->rev == 0) {
462 bcm43xx_phy_write(bcm, 0x0003, 0x0122);
463 } else {
464 bcm43xx_phy_write(bcm, 0x000A,
465 bcm43xx_phy_read(bcm, 0x000A)
466 | 0x2000);
467 }
468 bcm43xx_phy_write(bcm, 0x0814,
469 bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
470 bcm43xx_phy_write(bcm, 0x0815,
471 bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
472 bcm43xx_phy_write(bcm, 0x0003,
473 (bcm43xx_phy_read(bcm, 0x0003) & 0xFF9F)
474 | 0x0040);
475 bcm43xx_radio_write16(bcm, 0x007A,
476 bcm43xx_radio_read16(bcm, 0x007A) | 0x000F);
477 bcm43xx_set_all_gains(bcm, 3, 0, 1);
478 bcm43xx_radio_write16(bcm, 0x0043,
479 (bcm43xx_radio_read16(bcm, 0x0043)
480 & 0x00F0) | 0x000F);
481 udelay(30);
482 v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
483 if (v47F >= 0x20)
484 v47F -= 0x40;
485 if (v47F == -32) {
486 for (i = 0; i < 4; i++) {
487 bcm43xx_radio_write16(bcm, 0x007B, i);
488 udelay(20);
489 v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
490 if (v47F >= 0x20)
491 v47F -= 0x40;
492 if (v47F > -31 && saved == 0xFFFF)
493 saved = i;
494 }
495 if (saved == 0xFFFF)
496 saved = 3;
497 } else
498 saved = 0;
499 }
500 bcm43xx_radio_write16(bcm, 0x007B, saved);
501
502 if (phy->rev >= 6) {
503 bcm43xx_phy_write(bcm, 0x002E, backup[12]);
504 bcm43xx_phy_write(bcm, 0x002F, backup[13]);
505 bcm43xx_phy_write(bcm, 0x080F, backup[14]);
506 bcm43xx_phy_write(bcm, 0x0810, backup[15]);
507 }
508 bcm43xx_phy_write(bcm, 0x0814, backup[3]);
509 bcm43xx_phy_write(bcm, 0x0815, backup[4]);
510 bcm43xx_phy_write(bcm, 0x005A, backup[5]);
511 bcm43xx_phy_write(bcm, 0x0059, backup[6]);
512 bcm43xx_phy_write(bcm, 0x0058, backup[7]);
513 bcm43xx_phy_write(bcm, 0x000A, backup[8]);
514 bcm43xx_phy_write(bcm, 0x0003, backup[9]);
515 bcm43xx_radio_write16(bcm, 0x0043, backup[11]);
516 bcm43xx_radio_write16(bcm, 0x007A, backup[10]);
517 bcm43xx_phy_write(bcm, 0x0802,
518 bcm43xx_phy_read(bcm, 0x0802) | 0x1 | 0x2);
519 bcm43xx_phy_write(bcm, 0x0429,
520 bcm43xx_phy_read(bcm, 0x0429) | 0x8000);
521 bcm43xx_set_original_gains(bcm);
522 if (phy->rev >= 6) {
523 bcm43xx_phy_write(bcm, 0x0801, backup[16]);
524 bcm43xx_phy_write(bcm, 0x0060, backup[17]);
525 bcm43xx_phy_write(bcm, 0x0014, backup[18]);
526 bcm43xx_phy_write(bcm, 0x0478, backup[19]);
527 }
528 bcm43xx_phy_write(bcm, 0x0001, backup[0]);
529 bcm43xx_phy_write(bcm, 0x0812, backup[2]);
530 bcm43xx_phy_write(bcm, 0x0811, backup[1]);
531}
532
533void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm)
534{
535 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
536 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
537 u16 backup[18] = { 0 };
538 u16 tmp;
539 s16 nrssi0, nrssi1;
540
541 switch (phy->type) {
542 case BCM43xx_PHYTYPE_B:
543 backup[0] = bcm43xx_radio_read16(bcm, 0x007A);
544 backup[1] = bcm43xx_radio_read16(bcm, 0x0052);
545 backup[2] = bcm43xx_radio_read16(bcm, 0x0043);
546 backup[3] = bcm43xx_phy_read(bcm, 0x0030);
547 backup[4] = bcm43xx_phy_read(bcm, 0x0026);
548 backup[5] = bcm43xx_phy_read(bcm, 0x0015);
549 backup[6] = bcm43xx_phy_read(bcm, 0x002A);
550 backup[7] = bcm43xx_phy_read(bcm, 0x0020);
551 backup[8] = bcm43xx_phy_read(bcm, 0x005A);
552 backup[9] = bcm43xx_phy_read(bcm, 0x0059);
553 backup[10] = bcm43xx_phy_read(bcm, 0x0058);
554 backup[11] = bcm43xx_read16(bcm, 0x03E2);
555 backup[12] = bcm43xx_read16(bcm, 0x03E6);
556 backup[13] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
557
558 tmp = bcm43xx_radio_read16(bcm, 0x007A);
559 tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
560 bcm43xx_radio_write16(bcm, 0x007A, tmp);
561 bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
562 bcm43xx_write16(bcm, 0x03EC, 0x7F7F);
563 bcm43xx_phy_write(bcm, 0x0026, 0x0000);
564 bcm43xx_phy_write(bcm, 0x0015,
565 bcm43xx_phy_read(bcm, 0x0015) | 0x0020);
566 bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
567 bcm43xx_radio_write16(bcm, 0x007A,
568 bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
569
570 nrssi0 = (s16)bcm43xx_phy_read(bcm, 0x0027);
571 bcm43xx_radio_write16(bcm, 0x007A,
572 bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
573 if (phy->rev >= 2) {
574 bcm43xx_write16(bcm, 0x03E6, 0x0040);
575 } else if (phy->rev == 0) {
576 bcm43xx_write16(bcm, 0x03E6, 0x0122);
577 } else {
578 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
579 bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) & 0x2000);
580 }
581 bcm43xx_phy_write(bcm, 0x0020, 0x3F3F);
582 bcm43xx_phy_write(bcm, 0x0015, 0xF330);
583 bcm43xx_radio_write16(bcm, 0x005A, 0x0060);
584 bcm43xx_radio_write16(bcm, 0x0043,
585 bcm43xx_radio_read16(bcm, 0x0043) & 0x00F0);
586 bcm43xx_phy_write(bcm, 0x005A, 0x0480);
587 bcm43xx_phy_write(bcm, 0x0059, 0x0810);
588 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
589 udelay(20);
590
591 nrssi1 = (s16)bcm43xx_phy_read(bcm, 0x0027);
592 bcm43xx_phy_write(bcm, 0x0030, backup[3]);
593 bcm43xx_radio_write16(bcm, 0x007A, backup[0]);
594 bcm43xx_write16(bcm, 0x03E2, backup[11]);
595 bcm43xx_phy_write(bcm, 0x0026, backup[4]);
596 bcm43xx_phy_write(bcm, 0x0015, backup[5]);
597 bcm43xx_phy_write(bcm, 0x002A, backup[6]);
598 bcm43xx_synth_pu_workaround(bcm, radio->channel);
599 if (phy->rev != 0)
600 bcm43xx_write16(bcm, 0x03F4, backup[13]);
601
602 bcm43xx_phy_write(bcm, 0x0020, backup[7]);
603 bcm43xx_phy_write(bcm, 0x005A, backup[8]);
604 bcm43xx_phy_write(bcm, 0x0059, backup[9]);
605 bcm43xx_phy_write(bcm, 0x0058, backup[10]);
606 bcm43xx_radio_write16(bcm, 0x0052, backup[1]);
607 bcm43xx_radio_write16(bcm, 0x0043, backup[2]);
608
609 if (nrssi0 == nrssi1)
610 radio->nrssislope = 0x00010000;
611 else
612 radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
613
614 if (nrssi0 <= -4) {
615 radio->nrssi[0] = nrssi0;
616 radio->nrssi[1] = nrssi1;
617 }
618 break;
619 case BCM43xx_PHYTYPE_G:
620 if (radio->revision >= 9)
621 return;
622 if (radio->revision == 8)
623 bcm43xx_calc_nrssi_offset(bcm);
624
625 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
626 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF);
627 bcm43xx_phy_write(bcm, 0x0802,
628 bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC);
629 backup[7] = bcm43xx_read16(bcm, 0x03E2);
630 bcm43xx_write16(bcm, 0x03E2,
631 bcm43xx_read16(bcm, 0x03E2) | 0x8000);
632 backup[0] = bcm43xx_radio_read16(bcm, 0x007A);
633 backup[1] = bcm43xx_radio_read16(bcm, 0x0052);
634 backup[2] = bcm43xx_radio_read16(bcm, 0x0043);
635 backup[3] = bcm43xx_phy_read(bcm, 0x0015);
636 backup[4] = bcm43xx_phy_read(bcm, 0x005A);
637 backup[5] = bcm43xx_phy_read(bcm, 0x0059);
638 backup[6] = bcm43xx_phy_read(bcm, 0x0058);
639 backup[8] = bcm43xx_read16(bcm, 0x03E6);
640 backup[9] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
641 if (phy->rev >= 3) {
642 backup[10] = bcm43xx_phy_read(bcm, 0x002E);
643 backup[11] = bcm43xx_phy_read(bcm, 0x002F);
644 backup[12] = bcm43xx_phy_read(bcm, 0x080F);
645 backup[13] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_LO_CONTROL);
646 backup[14] = bcm43xx_phy_read(bcm, 0x0801);
647 backup[15] = bcm43xx_phy_read(bcm, 0x0060);
648 backup[16] = bcm43xx_phy_read(bcm, 0x0014);
649 backup[17] = bcm43xx_phy_read(bcm, 0x0478);
650 bcm43xx_phy_write(bcm, 0x002E, 0);
651 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, 0);
652 switch (phy->rev) {
653 case 4: case 6: case 7:
654 bcm43xx_phy_write(bcm, 0x0478,
655 bcm43xx_phy_read(bcm, 0x0478)
656 | 0x0100);
657 bcm43xx_phy_write(bcm, 0x0801,
658 bcm43xx_phy_read(bcm, 0x0801)
659 | 0x0040);
660 break;
661 case 3: case 5:
662 bcm43xx_phy_write(bcm, 0x0801,
663 bcm43xx_phy_read(bcm, 0x0801)
664 & 0xFFBF);
665 break;
666 }
667 bcm43xx_phy_write(bcm, 0x0060,
668 bcm43xx_phy_read(bcm, 0x0060)
669 | 0x0040);
670 bcm43xx_phy_write(bcm, 0x0014,
671 bcm43xx_phy_read(bcm, 0x0014)
672 | 0x0200);
673 }
674 bcm43xx_radio_write16(bcm, 0x007A,
675 bcm43xx_radio_read16(bcm, 0x007A) | 0x0070);
676 bcm43xx_set_all_gains(bcm, 0, 8, 0);
677 bcm43xx_radio_write16(bcm, 0x007A,
678 bcm43xx_radio_read16(bcm, 0x007A) & 0x00F7);
679 if (phy->rev >= 2) {
680 bcm43xx_phy_write(bcm, 0x0811,
681 (bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF) | 0x0030);
682 bcm43xx_phy_write(bcm, 0x0812,
683 (bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF) | 0x0010);
684 }
685 bcm43xx_radio_write16(bcm, 0x007A,
686 bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
687 udelay(20);
688
689 nrssi0 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
690 if (nrssi0 >= 0x0020)
691 nrssi0 -= 0x0040;
692
693 bcm43xx_radio_write16(bcm, 0x007A,
694 bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
695 if (phy->rev >= 2) {
696 bcm43xx_phy_write(bcm, 0x0003,
697 (bcm43xx_phy_read(bcm, 0x0003)
698 & 0xFF9F) | 0x0040);
699 }
700
701 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
702 bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
703 | 0x2000);
704 bcm43xx_radio_write16(bcm, 0x007A,
705 bcm43xx_radio_read16(bcm, 0x007A) | 0x000F);
706 bcm43xx_phy_write(bcm, 0x0015, 0xF330);
707 if (phy->rev >= 2) {
708 bcm43xx_phy_write(bcm, 0x0812,
709 (bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF) | 0x0020);
710 bcm43xx_phy_write(bcm, 0x0811,
711 (bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF) | 0x0020);
712 }
713
714 bcm43xx_set_all_gains(bcm, 3, 0, 1);
715 if (radio->revision == 8) {
716 bcm43xx_radio_write16(bcm, 0x0043, 0x001F);
717 } else {
718 tmp = bcm43xx_radio_read16(bcm, 0x0052) & 0xFF0F;
719 bcm43xx_radio_write16(bcm, 0x0052, tmp | 0x0060);
720 tmp = bcm43xx_radio_read16(bcm, 0x0043) & 0xFFF0;
721 bcm43xx_radio_write16(bcm, 0x0043, tmp | 0x0009);
722 }
723 bcm43xx_phy_write(bcm, 0x005A, 0x0480);
724 bcm43xx_phy_write(bcm, 0x0059, 0x0810);
725 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
726 udelay(20);
727 nrssi1 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
728 if (nrssi1 >= 0x0020)
729 nrssi1 -= 0x0040;
730 if (nrssi0 == nrssi1)
731 radio->nrssislope = 0x00010000;
732 else
733 radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
734 if (nrssi0 >= -4) {
735 radio->nrssi[0] = nrssi1;
736 radio->nrssi[1] = nrssi0;
737 }
738 if (phy->rev >= 3) {
739 bcm43xx_phy_write(bcm, 0x002E, backup[10]);
740 bcm43xx_phy_write(bcm, 0x002F, backup[11]);
741 bcm43xx_phy_write(bcm, 0x080F, backup[12]);
742 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, backup[13]);
743 }
744 if (phy->rev >= 2) {
745 bcm43xx_phy_write(bcm, 0x0812,
746 bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF);
747 bcm43xx_phy_write(bcm, 0x0811,
748 bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF);
749 }
750
751 bcm43xx_radio_write16(bcm, 0x007A, backup[0]);
752 bcm43xx_radio_write16(bcm, 0x0052, backup[1]);
753 bcm43xx_radio_write16(bcm, 0x0043, backup[2]);
754 bcm43xx_write16(bcm, 0x03E2, backup[7]);
755 bcm43xx_write16(bcm, 0x03E6, backup[8]);
756 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[9]);
757 bcm43xx_phy_write(bcm, 0x0015, backup[3]);
758 bcm43xx_phy_write(bcm, 0x005A, backup[4]);
759 bcm43xx_phy_write(bcm, 0x0059, backup[5]);
760 bcm43xx_phy_write(bcm, 0x0058, backup[6]);
761 bcm43xx_synth_pu_workaround(bcm, radio->channel);
762 bcm43xx_phy_write(bcm, 0x0802,
763 bcm43xx_phy_read(bcm, 0x0802) | (0x0001 | 0x0002));
764 bcm43xx_set_original_gains(bcm);
765 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
766 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x8000);
767 if (phy->rev >= 3) {
768 bcm43xx_phy_write(bcm, 0x0801, backup[14]);
769 bcm43xx_phy_write(bcm, 0x0060, backup[15]);
770 bcm43xx_phy_write(bcm, 0x0014, backup[16]);
771 bcm43xx_phy_write(bcm, 0x0478, backup[17]);
772 }
773 bcm43xx_nrssi_mem_update(bcm);
774 bcm43xx_calc_nrssi_threshold(bcm);
775 break;
776 default:
777 assert(0);
778 }
779}
780
781void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm)
782{
783 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
784 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
785 s32 threshold;
786 s32 a, b;
787 s16 tmp16;
788 u16 tmp_u16;
789
790 switch (phy->type) {
791 case BCM43xx_PHYTYPE_B: {
792 if (radio->version != 0x2050)
793 return;
794 if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI))
795 return;
796
797 if (radio->revision >= 6) {
798 threshold = (radio->nrssi[1] - radio->nrssi[0]) * 32;
799 threshold += 20 * (radio->nrssi[0] + 1);
800 threshold /= 40;
801 } else
802 threshold = radio->nrssi[1] - 5;
803
804 threshold = limit_value(threshold, 0, 0x3E);
805 bcm43xx_phy_read(bcm, 0x0020); /* dummy read */
806 bcm43xx_phy_write(bcm, 0x0020, (((u16)threshold) << 8) | 0x001C);
807
808 if (radio->revision >= 6) {
809 bcm43xx_phy_write(bcm, 0x0087, 0x0E0D);
810 bcm43xx_phy_write(bcm, 0x0086, 0x0C0B);
811 bcm43xx_phy_write(bcm, 0x0085, 0x0A09);
812 bcm43xx_phy_write(bcm, 0x0084, 0x0808);
813 bcm43xx_phy_write(bcm, 0x0083, 0x0808);
814 bcm43xx_phy_write(bcm, 0x0082, 0x0604);
815 bcm43xx_phy_write(bcm, 0x0081, 0x0302);
816 bcm43xx_phy_write(bcm, 0x0080, 0x0100);
817 }
818 break;
819 }
820 case BCM43xx_PHYTYPE_G:
821 if (!phy->connected ||
822 !(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
823 tmp16 = bcm43xx_nrssi_hw_read(bcm, 0x20);
824 if (tmp16 >= 0x20)
825 tmp16 -= 0x40;
826 if (tmp16 < 3) {
827 bcm43xx_phy_write(bcm, 0x048A,
828 (bcm43xx_phy_read(bcm, 0x048A)
829 & 0xF000) | 0x09EB);
830 } else {
831 bcm43xx_phy_write(bcm, 0x048A,
832 (bcm43xx_phy_read(bcm, 0x048A)
833 & 0xF000) | 0x0AED);
834 }
835 } else {
836 if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN) {
837 a = 0xE;
838 b = 0xA;
839 } else if (!radio->aci_wlan_automatic && radio->aci_enable) {
840 a = 0x13;
841 b = 0x12;
842 } else {
843 a = 0xE;
844 b = 0x11;
845 }
846
847 a = a * (radio->nrssi[1] - radio->nrssi[0]);
848 a += (radio->nrssi[0] << 6);
849 if (a < 32)
850 a += 31;
851 else
852 a += 32;
853 a = a >> 6;
854 a = limit_value(a, -31, 31);
855
856 b = b * (radio->nrssi[1] - radio->nrssi[0]);
857 b += (radio->nrssi[0] << 6);
858 if (b < 32)
859 b += 31;
860 else
861 b += 32;
862 b = b >> 6;
863 b = limit_value(b, -31, 31);
864
865 tmp_u16 = bcm43xx_phy_read(bcm, 0x048A) & 0xF000;
866 tmp_u16 |= ((u32)b & 0x0000003F);
867 tmp_u16 |= (((u32)a & 0x0000003F) << 6);
868 bcm43xx_phy_write(bcm, 0x048A, tmp_u16);
869 }
870 break;
871 default:
872 assert(0);
873 }
874}
875
876/* Stack implementation to save/restore values from the
877 * interference mitigation code.
878 * It is save to restore values in random order.
879 */
880static void _stack_save(u32 *_stackptr, size_t *stackidx,
881 u8 id, u16 offset, u16 value)
882{
883 u32 *stackptr = &(_stackptr[*stackidx]);
884
885 assert((offset & 0xF000) == 0x0000);
886 assert((id & 0xF0) == 0x00);
887 *stackptr = offset;
888 *stackptr |= ((u32)id) << 12;
889 *stackptr |= ((u32)value) << 16;
890 (*stackidx)++;
891 assert(*stackidx < BCM43xx_INTERFSTACK_SIZE);
892}
893
894static u16 _stack_restore(u32 *stackptr,
895 u8 id, u16 offset)
896{
897 size_t i;
898
899 assert((offset & 0xF000) == 0x0000);
900 assert((id & 0xF0) == 0x00);
901 for (i = 0; i < BCM43xx_INTERFSTACK_SIZE; i++, stackptr++) {
902 if ((*stackptr & 0x00000FFF) != offset)
903 continue;
904 if (((*stackptr & 0x0000F000) >> 12) != id)
905 continue;
906 return ((*stackptr & 0xFFFF0000) >> 16);
907 }
908 assert(0);
909
910 return 0;
911}
912
913#define phy_stacksave(offset) \
914 do { \
915 _stack_save(stack, &stackidx, 0x1, (offset), \
916 bcm43xx_phy_read(bcm, (offset))); \
917 } while (0)
918#define phy_stackrestore(offset) \
919 do { \
920 bcm43xx_phy_write(bcm, (offset), \
921 _stack_restore(stack, 0x1, \
922 (offset))); \
923 } while (0)
924#define radio_stacksave(offset) \
925 do { \
926 _stack_save(stack, &stackidx, 0x2, (offset), \
927 bcm43xx_radio_read16(bcm, (offset))); \
928 } while (0)
929#define radio_stackrestore(offset) \
930 do { \
931 bcm43xx_radio_write16(bcm, (offset), \
932 _stack_restore(stack, 0x2, \
933 (offset))); \
934 } while (0)
935#define ilt_stacksave(offset) \
936 do { \
937 _stack_save(stack, &stackidx, 0x3, (offset), \
938 bcm43xx_ilt_read(bcm, (offset))); \
939 } while (0)
940#define ilt_stackrestore(offset) \
941 do { \
942 bcm43xx_ilt_write(bcm, (offset), \
943 _stack_restore(stack, 0x3, \
944 (offset))); \
945 } while (0)
946
947static void
948bcm43xx_radio_interference_mitigation_enable(struct bcm43xx_private *bcm,
949 int mode)
950{
951 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
952 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
953 u16 tmp, flipped;
954 u32 tmp32;
955 size_t stackidx = 0;
956 u32 *stack = radio->interfstack;
957
958 switch (mode) {
959 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
960 if (phy->rev != 1) {
961 bcm43xx_phy_write(bcm, 0x042B,
962 bcm43xx_phy_read(bcm, 0x042B) | 0x0800);
963 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
964 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & ~0x4000);
965 break;
966 }
967 radio_stacksave(0x0078);
968 tmp = (bcm43xx_radio_read16(bcm, 0x0078) & 0x001E);
969 flipped = flip_4bit(tmp);
970 if (flipped < 10 && flipped >= 8)
971 flipped = 7;
972 else if (flipped >= 10)
973 flipped -= 3;
974 flipped = flip_4bit(flipped);
975 flipped = (flipped << 1) | 0x0020;
976 bcm43xx_radio_write16(bcm, 0x0078, flipped);
977
978 bcm43xx_calc_nrssi_threshold(bcm);
979
980 phy_stacksave(0x0406);
981 bcm43xx_phy_write(bcm, 0x0406, 0x7E28);
982
983 bcm43xx_phy_write(bcm, 0x042B,
984 bcm43xx_phy_read(bcm, 0x042B) | 0x0800);
985 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
986 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | 0x1000);
987
988 phy_stacksave(0x04A0);
989 bcm43xx_phy_write(bcm, 0x04A0,
990 (bcm43xx_phy_read(bcm, 0x04A0) & 0xC0C0) | 0x0008);
991 phy_stacksave(0x04A1);
992 bcm43xx_phy_write(bcm, 0x04A1,
993 (bcm43xx_phy_read(bcm, 0x04A1) & 0xC0C0) | 0x0605);
994 phy_stacksave(0x04A2);
995 bcm43xx_phy_write(bcm, 0x04A2,
996 (bcm43xx_phy_read(bcm, 0x04A2) & 0xC0C0) | 0x0204);
997 phy_stacksave(0x04A8);
998 bcm43xx_phy_write(bcm, 0x04A8,
999 (bcm43xx_phy_read(bcm, 0x04A8) & 0xC0C0) | 0x0803);
1000 phy_stacksave(0x04AB);
1001 bcm43xx_phy_write(bcm, 0x04AB,
1002 (bcm43xx_phy_read(bcm, 0x04AB) & 0xC0C0) | 0x0605);
1003
1004 phy_stacksave(0x04A7);
1005 bcm43xx_phy_write(bcm, 0x04A7, 0x0002);
1006 phy_stacksave(0x04A3);
1007 bcm43xx_phy_write(bcm, 0x04A3, 0x287A);
1008 phy_stacksave(0x04A9);
1009 bcm43xx_phy_write(bcm, 0x04A9, 0x2027);
1010 phy_stacksave(0x0493);
1011 bcm43xx_phy_write(bcm, 0x0493, 0x32F5);
1012 phy_stacksave(0x04AA);
1013 bcm43xx_phy_write(bcm, 0x04AA, 0x2027);
1014 phy_stacksave(0x04AC);
1015 bcm43xx_phy_write(bcm, 0x04AC, 0x32F5);
1016 break;
1017 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
1018 if (bcm43xx_phy_read(bcm, 0x0033) & 0x0800)
1019 break;
1020
1021 radio->aci_enable = 1;
1022
1023 phy_stacksave(BCM43xx_PHY_RADIO_BITFIELD);
1024 phy_stacksave(BCM43xx_PHY_G_CRS);
1025 if (phy->rev < 2) {
1026 phy_stacksave(0x0406);
1027 } else {
1028 phy_stacksave(0x04C0);
1029 phy_stacksave(0x04C1);
1030 }
1031 phy_stacksave(0x0033);
1032 phy_stacksave(0x04A7);
1033 phy_stacksave(0x04A3);
1034 phy_stacksave(0x04A9);
1035 phy_stacksave(0x04AA);
1036 phy_stacksave(0x04AC);
1037 phy_stacksave(0x0493);
1038 phy_stacksave(0x04A1);
1039 phy_stacksave(0x04A0);
1040 phy_stacksave(0x04A2);
1041 phy_stacksave(0x048A);
1042 phy_stacksave(0x04A8);
1043 phy_stacksave(0x04AB);
1044 if (phy->rev == 2) {
1045 phy_stacksave(0x04AD);
1046 phy_stacksave(0x04AE);
1047 } else if (phy->rev >= 3) {
1048 phy_stacksave(0x04AD);
1049 phy_stacksave(0x0415);
1050 phy_stacksave(0x0416);
1051 phy_stacksave(0x0417);
1052 ilt_stacksave(0x1A00 + 0x2);
1053 ilt_stacksave(0x1A00 + 0x3);
1054 }
1055 phy_stacksave(0x042B);
1056 phy_stacksave(0x048C);
1057
1058 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
1059 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
1060 & ~0x1000);
1061 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
1062 (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS)
1063 & 0xFFFC) | 0x0002);
1064
1065 bcm43xx_phy_write(bcm, 0x0033, 0x0800);
1066 bcm43xx_phy_write(bcm, 0x04A3, 0x2027);
1067 bcm43xx_phy_write(bcm, 0x04A9, 0x1CA8);
1068 bcm43xx_phy_write(bcm, 0x0493, 0x287A);
1069 bcm43xx_phy_write(bcm, 0x04AA, 0x1CA8);
1070 bcm43xx_phy_write(bcm, 0x04AC, 0x287A);
1071
1072 bcm43xx_phy_write(bcm, 0x04A0,
1073 (bcm43xx_phy_read(bcm, 0x04A0)
1074 & 0xFFC0) | 0x001A);
1075 bcm43xx_phy_write(bcm, 0x04A7, 0x000D);
1076
1077 if (phy->rev < 2) {
1078 bcm43xx_phy_write(bcm, 0x0406, 0xFF0D);
1079 } else if (phy->rev == 2) {
1080 bcm43xx_phy_write(bcm, 0x04C0, 0xFFFF);
1081 bcm43xx_phy_write(bcm, 0x04C1, 0x00A9);
1082 } else {
1083 bcm43xx_phy_write(bcm, 0x04C0, 0x00C1);
1084 bcm43xx_phy_write(bcm, 0x04C1, 0x0059);
1085 }
1086
1087 bcm43xx_phy_write(bcm, 0x04A1,
1088 (bcm43xx_phy_read(bcm, 0x04A1)
1089 & 0xC0FF) | 0x1800);
1090 bcm43xx_phy_write(bcm, 0x04A1,
1091 (bcm43xx_phy_read(bcm, 0x04A1)
1092 & 0xFFC0) | 0x0015);
1093 bcm43xx_phy_write(bcm, 0x04A8,
1094 (bcm43xx_phy_read(bcm, 0x04A8)
1095 & 0xCFFF) | 0x1000);
1096 bcm43xx_phy_write(bcm, 0x04A8,
1097 (bcm43xx_phy_read(bcm, 0x04A8)
1098 & 0xF0FF) | 0x0A00);
1099 bcm43xx_phy_write(bcm, 0x04AB,
1100 (bcm43xx_phy_read(bcm, 0x04AB)
1101 & 0xCFFF) | 0x1000);
1102 bcm43xx_phy_write(bcm, 0x04AB,
1103 (bcm43xx_phy_read(bcm, 0x04AB)
1104 & 0xF0FF) | 0x0800);
1105 bcm43xx_phy_write(bcm, 0x04AB,
1106 (bcm43xx_phy_read(bcm, 0x04AB)
1107 & 0xFFCF) | 0x0010);
1108 bcm43xx_phy_write(bcm, 0x04AB,
1109 (bcm43xx_phy_read(bcm, 0x04AB)
1110 & 0xFFF0) | 0x0005);
1111 bcm43xx_phy_write(bcm, 0x04A8,
1112 (bcm43xx_phy_read(bcm, 0x04A8)
1113 & 0xFFCF) | 0x0010);
1114 bcm43xx_phy_write(bcm, 0x04A8,
1115 (bcm43xx_phy_read(bcm, 0x04A8)
1116 & 0xFFF0) | 0x0006);
1117 bcm43xx_phy_write(bcm, 0x04A2,
1118 (bcm43xx_phy_read(bcm, 0x04A2)
1119 & 0xF0FF) | 0x0800);
1120 bcm43xx_phy_write(bcm, 0x04A0,
1121 (bcm43xx_phy_read(bcm, 0x04A0)
1122 & 0xF0FF) | 0x0500);
1123 bcm43xx_phy_write(bcm, 0x04A2,
1124 (bcm43xx_phy_read(bcm, 0x04A2)
1125 & 0xFFF0) | 0x000B);
1126
1127 if (phy->rev >= 3) {
1128 bcm43xx_phy_write(bcm, 0x048A,
1129 bcm43xx_phy_read(bcm, 0x048A)
1130 & ~0x8000);
1131 bcm43xx_phy_write(bcm, 0x0415,
1132 (bcm43xx_phy_read(bcm, 0x0415)
1133 & 0x8000) | 0x36D8);
1134 bcm43xx_phy_write(bcm, 0x0416,
1135 (bcm43xx_phy_read(bcm, 0x0416)
1136 & 0x8000) | 0x36D8);
1137 bcm43xx_phy_write(bcm, 0x0417,
1138 (bcm43xx_phy_read(bcm, 0x0417)
1139 & 0xFE00) | 0x016D);
1140 } else {
1141 bcm43xx_phy_write(bcm, 0x048A,
1142 bcm43xx_phy_read(bcm, 0x048A)
1143 | 0x1000);
1144 bcm43xx_phy_write(bcm, 0x048A,
1145 (bcm43xx_phy_read(bcm, 0x048A)
1146 & 0x9FFF) | 0x2000);
1147 tmp32 = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
1148 BCM43xx_UCODEFLAGS_OFFSET);
1149 if (!(tmp32 & 0x800)) {
1150 tmp32 |= 0x800;
1151 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
1152 BCM43xx_UCODEFLAGS_OFFSET,
1153 tmp32);
1154 }
1155 }
1156 if (phy->rev >= 2) {
1157 bcm43xx_phy_write(bcm, 0x042B,
1158 bcm43xx_phy_read(bcm, 0x042B)
1159 | 0x0800);
1160 }
1161 bcm43xx_phy_write(bcm, 0x048C,
1162 (bcm43xx_phy_read(bcm, 0x048C)
1163 & 0xF0FF) | 0x0200);
1164 if (phy->rev == 2) {
1165 bcm43xx_phy_write(bcm, 0x04AE,
1166 (bcm43xx_phy_read(bcm, 0x04AE)
1167 & 0xFF00) | 0x007F);
1168 bcm43xx_phy_write(bcm, 0x04AD,
1169 (bcm43xx_phy_read(bcm, 0x04AD)
1170 & 0x00FF) | 0x1300);
1171 } else if (phy->rev >= 6) {
1172 bcm43xx_ilt_write(bcm, 0x1A00 + 0x3, 0x007F);
1173 bcm43xx_ilt_write(bcm, 0x1A00 + 0x2, 0x007F);
1174 bcm43xx_phy_write(bcm, 0x04AD,
1175 bcm43xx_phy_read(bcm, 0x04AD)
1176 & 0x00FF);
1177 }
1178 bcm43xx_calc_nrssi_slope(bcm);
1179 break;
1180 default:
1181 assert(0);
1182 }
1183}
1184
1185static void
1186bcm43xx_radio_interference_mitigation_disable(struct bcm43xx_private *bcm,
1187 int mode)
1188{
1189 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1190 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1191 u32 tmp32;
1192 u32 *stack = radio->interfstack;
1193
1194 switch (mode) {
1195 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
1196 if (phy->rev != 1) {
1197 bcm43xx_phy_write(bcm, 0x042B,
1198 bcm43xx_phy_read(bcm, 0x042B) & ~0x0800);
1199 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
1200 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x4000);
1201 break;
1202 }
1203 phy_stackrestore(0x0078);
1204 bcm43xx_calc_nrssi_threshold(bcm);
1205 phy_stackrestore(0x0406);
1206 bcm43xx_phy_write(bcm, 0x042B,
1207 bcm43xx_phy_read(bcm, 0x042B) & ~0x0800);
1208 if (!bcm->bad_frames_preempt) {
1209 bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
1210 bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
1211 & ~(1 << 11));
1212 }
1213 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
1214 bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x4000);
1215 phy_stackrestore(0x04A0);
1216 phy_stackrestore(0x04A1);
1217 phy_stackrestore(0x04A2);
1218 phy_stackrestore(0x04A8);
1219 phy_stackrestore(0x04AB);
1220 phy_stackrestore(0x04A7);
1221 phy_stackrestore(0x04A3);
1222 phy_stackrestore(0x04A9);
1223 phy_stackrestore(0x0493);
1224 phy_stackrestore(0x04AA);
1225 phy_stackrestore(0x04AC);
1226 break;
1227 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
1228 if (!(bcm43xx_phy_read(bcm, 0x0033) & 0x0800))
1229 break;
1230
1231 radio->aci_enable = 0;
1232
1233 phy_stackrestore(BCM43xx_PHY_RADIO_BITFIELD);
1234 phy_stackrestore(BCM43xx_PHY_G_CRS);
1235 phy_stackrestore(0x0033);
1236 phy_stackrestore(0x04A3);
1237 phy_stackrestore(0x04A9);
1238 phy_stackrestore(0x0493);
1239 phy_stackrestore(0x04AA);
1240 phy_stackrestore(0x04AC);
1241 phy_stackrestore(0x04A0);
1242 phy_stackrestore(0x04A7);
1243 if (phy->rev >= 2) {
1244 phy_stackrestore(0x04C0);
1245 phy_stackrestore(0x04C1);
1246 } else
1247 phy_stackrestore(0x0406);
1248 phy_stackrestore(0x04A1);
1249 phy_stackrestore(0x04AB);
1250 phy_stackrestore(0x04A8);
1251 if (phy->rev == 2) {
1252 phy_stackrestore(0x04AD);
1253 phy_stackrestore(0x04AE);
1254 } else if (phy->rev >= 3) {
1255 phy_stackrestore(0x04AD);
1256 phy_stackrestore(0x0415);
1257 phy_stackrestore(0x0416);
1258 phy_stackrestore(0x0417);
1259 ilt_stackrestore(0x1A00 + 0x2);
1260 ilt_stackrestore(0x1A00 + 0x3);
1261 }
1262 phy_stackrestore(0x04A2);
1263 phy_stackrestore(0x04A8);
1264 phy_stackrestore(0x042B);
1265 phy_stackrestore(0x048C);
1266 tmp32 = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
1267 BCM43xx_UCODEFLAGS_OFFSET);
1268 if (tmp32 & 0x800) {
1269 tmp32 &= ~0x800;
1270 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
1271 BCM43xx_UCODEFLAGS_OFFSET,
1272 tmp32);
1273 }
1274 bcm43xx_calc_nrssi_slope(bcm);
1275 break;
1276 default:
1277 assert(0);
1278 }
1279}
1280
1281#undef phy_stacksave
1282#undef phy_stackrestore
1283#undef radio_stacksave
1284#undef radio_stackrestore
1285#undef ilt_stacksave
1286#undef ilt_stackrestore
1287
1288int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm,
1289 int mode)
1290{
1291 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1292 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1293 int currentmode;
1294
1295 if ((phy->type != BCM43xx_PHYTYPE_G) ||
1296 (phy->rev == 0) ||
1297 (!phy->connected))
1298 return -ENODEV;
1299
1300 radio->aci_wlan_automatic = 0;
1301 switch (mode) {
1302 case BCM43xx_RADIO_INTERFMODE_AUTOWLAN:
1303 radio->aci_wlan_automatic = 1;
1304 if (radio->aci_enable)
1305 mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
1306 else
1307 mode = BCM43xx_RADIO_INTERFMODE_NONE;
1308 break;
1309 case BCM43xx_RADIO_INTERFMODE_NONE:
1310 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
1311 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
1312 break;
1313 default:
1314 return -EINVAL;
1315 }
1316
1317 currentmode = radio->interfmode;
1318 if (currentmode == mode)
1319 return 0;
1320 if (currentmode != BCM43xx_RADIO_INTERFMODE_NONE)
1321 bcm43xx_radio_interference_mitigation_disable(bcm, currentmode);
1322
1323 if (mode == BCM43xx_RADIO_INTERFMODE_NONE) {
1324 radio->aci_enable = 0;
1325 radio->aci_hw_rssi = 0;
1326 } else
1327 bcm43xx_radio_interference_mitigation_enable(bcm, mode);
1328 radio->interfmode = mode;
1329
1330 return 0;
1331}
1332
1333u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm)
1334{
1335 u16 reg, index, ret;
1336
1337 reg = bcm43xx_radio_read16(bcm, 0x0060);
1338 index = (reg & 0x001E) >> 1;
1339 ret = rcc_table[index] << 1;
1340 ret |= (reg & 0x0001);
1341 ret |= 0x0020;
1342
1343 return ret;
1344}
1345
1346u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
1347{
1348 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1349 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1350 u16 backup[19] = { 0 };
1351 u16 ret;
1352 u16 i, j;
1353 u32 tmp1 = 0, tmp2 = 0;
1354
1355 backup[0] = bcm43xx_radio_read16(bcm, 0x0043);
1356 backup[14] = bcm43xx_radio_read16(bcm, 0x0051);
1357 backup[15] = bcm43xx_radio_read16(bcm, 0x0052);
1358 backup[1] = bcm43xx_phy_read(bcm, 0x0015);
1359 backup[16] = bcm43xx_phy_read(bcm, 0x005A);
1360 backup[17] = bcm43xx_phy_read(bcm, 0x0059);
1361 backup[18] = bcm43xx_phy_read(bcm, 0x0058);
1362 if (phy->type == BCM43xx_PHYTYPE_B) {
1363 backup[2] = bcm43xx_phy_read(bcm, 0x0030);
1364 backup[3] = bcm43xx_read16(bcm, 0x03EC);
1365 bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
1366 bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
1367 } else {
1368 if (phy->connected) {
1369 backup[4] = bcm43xx_phy_read(bcm, 0x0811);
1370 backup[5] = bcm43xx_phy_read(bcm, 0x0812);
1371 backup[6] = bcm43xx_phy_read(bcm, 0x0814);
1372 backup[7] = bcm43xx_phy_read(bcm, 0x0815);
1373 backup[8] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
1374 backup[9] = bcm43xx_phy_read(bcm, 0x0802);
1375 bcm43xx_phy_write(bcm, 0x0814,
1376 (bcm43xx_phy_read(bcm, 0x0814) | 0x0003));
1377 bcm43xx_phy_write(bcm, 0x0815,
1378 (bcm43xx_phy_read(bcm, 0x0815) & 0xFFFC));
1379 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
1380 (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF));
1381 bcm43xx_phy_write(bcm, 0x0802,
1382 (bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC));
1383 bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
1384 bcm43xx_phy_write(bcm, 0x0812, 0x0FB2);
1385 }
1386 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
1387 (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) | 0x8000));
1388 }
1389 backup[10] = bcm43xx_phy_read(bcm, 0x0035);
1390 bcm43xx_phy_write(bcm, 0x0035,
1391 (bcm43xx_phy_read(bcm, 0x0035) & 0xFF7F));
1392 backup[11] = bcm43xx_read16(bcm, 0x03E6);
1393 backup[12] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
1394
1395 // Initialization
1396 if (phy->version == 0) {
1397 bcm43xx_write16(bcm, 0x03E6, 0x0122);
1398 } else {
1399 if (phy->version >= 2)
1400 bcm43xx_write16(bcm, 0x03E6, 0x0040);
1401 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
1402 (bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) | 0x2000));
1403 }
1404
1405 ret = bcm43xx_radio_calibrationvalue(bcm);
1406
1407 if (phy->type == BCM43xx_PHYTYPE_B)
1408 bcm43xx_radio_write16(bcm, 0x0078, 0x0003);
1409
1410 bcm43xx_phy_write(bcm, 0x0015, 0xBFAF);
1411 bcm43xx_phy_write(bcm, 0x002B, 0x1403);
1412 if (phy->connected)
1413 bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
1414 bcm43xx_phy_write(bcm, 0x0015, 0xBFA0);
1415 bcm43xx_radio_write16(bcm, 0x0051,
1416 (bcm43xx_radio_read16(bcm, 0x0051) | 0x0004));
1417 bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
1418 bcm43xx_radio_write16(bcm, 0x0043,
1419 bcm43xx_radio_read16(bcm, 0x0043) | 0x0009);
1420 bcm43xx_phy_write(bcm, 0x0058, 0x0000);
1421
1422 for (i = 0; i < 16; i++) {
1423 bcm43xx_phy_write(bcm, 0x005A, 0x0480);
1424 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1425 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1426 if (phy->connected)
1427 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1428 bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
1429 udelay(10);
1430 if (phy->connected)
1431 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1432 bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
1433 udelay(10);
1434 if (phy->connected)
1435 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1436 bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
1437 udelay(10);
1438 tmp1 += bcm43xx_phy_read(bcm, 0x002D);
1439 bcm43xx_phy_write(bcm, 0x0058, 0x0000);
1440 if (phy->connected)
1441 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1442 bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
1443 }
1444
1445 tmp1++;
1446 tmp1 >>= 9;
1447 udelay(10);
1448 bcm43xx_phy_write(bcm, 0x0058, 0x0000);
1449
1450 for (i = 0; i < 16; i++) {
1451 bcm43xx_radio_write16(bcm, 0x0078, (flip_4bit(i) << 1) | 0x0020);
1452 backup[13] = bcm43xx_radio_read16(bcm, 0x0078);
1453 udelay(10);
1454 for (j = 0; j < 16; j++) {
1455 bcm43xx_phy_write(bcm, 0x005A, 0x0D80);
1456 bcm43xx_phy_write(bcm, 0x0059, 0xC810);
1457 bcm43xx_phy_write(bcm, 0x0058, 0x000D);
1458 if (phy->connected)
1459 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1460 bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
1461 udelay(10);
1462 if (phy->connected)
1463 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1464 bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
1465 udelay(10);
1466 if (phy->connected)
1467 bcm43xx_phy_write(bcm, 0x0812, 0x30B3); /* 0x30B3 is not a typo */
1468 bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
1469 udelay(10);
1470 tmp2 += bcm43xx_phy_read(bcm, 0x002D);
1471 bcm43xx_phy_write(bcm, 0x0058, 0x0000);
1472 if (phy->connected)
1473 bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
1474 bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
1475 }
1476 tmp2++;
1477 tmp2 >>= 8;
1478 if (tmp1 < tmp2)
1479 break;
1480 }
1481
1482 /* Restore the registers */
1483 bcm43xx_phy_write(bcm, 0x0015, backup[1]);
1484 bcm43xx_radio_write16(bcm, 0x0051, backup[14]);
1485 bcm43xx_radio_write16(bcm, 0x0052, backup[15]);
1486 bcm43xx_radio_write16(bcm, 0x0043, backup[0]);
1487 bcm43xx_phy_write(bcm, 0x005A, backup[16]);
1488 bcm43xx_phy_write(bcm, 0x0059, backup[17]);
1489 bcm43xx_phy_write(bcm, 0x0058, backup[18]);
1490 bcm43xx_write16(bcm, 0x03E6, backup[11]);
1491 if (phy->version != 0)
1492 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[12]);
1493 bcm43xx_phy_write(bcm, 0x0035, backup[10]);
1494 bcm43xx_radio_selectchannel(bcm, radio->channel, 1);
1495 if (phy->type == BCM43xx_PHYTYPE_B) {
1496 bcm43xx_phy_write(bcm, 0x0030, backup[2]);
1497 bcm43xx_write16(bcm, 0x03EC, backup[3]);
1498 } else {
1499 bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
1500 (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) & 0x7FFF));
1501 if (phy->connected) {
1502 bcm43xx_phy_write(bcm, 0x0811, backup[4]);
1503 bcm43xx_phy_write(bcm, 0x0812, backup[5]);
1504 bcm43xx_phy_write(bcm, 0x0814, backup[6]);
1505 bcm43xx_phy_write(bcm, 0x0815, backup[7]);
1506 bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, backup[8]);
1507 bcm43xx_phy_write(bcm, 0x0802, backup[9]);
1508 }
1509 }
1510 if (i >= 15)
1511 ret = backup[13];
1512
1513 return ret;
1514}
1515
1516void bcm43xx_radio_init2060(struct bcm43xx_private *bcm)
1517{
1518 int err;
1519
1520 bcm43xx_radio_write16(bcm, 0x0004, 0x00C0);
1521 bcm43xx_radio_write16(bcm, 0x0005, 0x0008);
1522 bcm43xx_radio_write16(bcm, 0x0009, 0x0040);
1523 bcm43xx_radio_write16(bcm, 0x0005, 0x00AA);
1524 bcm43xx_radio_write16(bcm, 0x0032, 0x008F);
1525 bcm43xx_radio_write16(bcm, 0x0006, 0x008F);
1526 bcm43xx_radio_write16(bcm, 0x0034, 0x008F);
1527 bcm43xx_radio_write16(bcm, 0x002C, 0x0007);
1528 bcm43xx_radio_write16(bcm, 0x0082, 0x0080);
1529 bcm43xx_radio_write16(bcm, 0x0080, 0x0000);
1530 bcm43xx_radio_write16(bcm, 0x003F, 0x00DA);
1531 bcm43xx_radio_write16(bcm, 0x0005, bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008);
1532 bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0010);
1533 bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020);
1534 bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020);
1535 udelay(400);
1536
1537 bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020) | 0x0010);
1538 udelay(400);
1539
1540 bcm43xx_radio_write16(bcm, 0x0005, (bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008) | 0x0008);
1541 bcm43xx_radio_write16(bcm, 0x0085, bcm43xx_radio_read16(bcm, 0x0085) & ~0x0010);
1542 bcm43xx_radio_write16(bcm, 0x0005, bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008);
1543 bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0040);
1544 bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0040) | 0x0040);
1545 bcm43xx_radio_write16(bcm, 0x0005, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0008) | 0x0008);
1546 bcm43xx_phy_write(bcm, 0x0063, 0xDDC6);
1547 bcm43xx_phy_write(bcm, 0x0069, 0x07BE);
1548 bcm43xx_phy_write(bcm, 0x006A, 0x0000);
1549
1550 err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_A, 0);
1551 assert(err == 0);
1552 udelay(1000);
1553}
1554
1555static inline
1556u16 freq_r3A_value(u16 frequency)
1557{
1558 u16 value;
1559
1560 if (frequency < 5091)
1561 value = 0x0040;
1562 else if (frequency < 5321)
1563 value = 0x0000;
1564 else if (frequency < 5806)
1565 value = 0x0080;
1566 else
1567 value = 0x0040;
1568
1569 return value;
1570}
1571
1572void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm)
1573{
1574 static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
1575 static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
1576 u16 tmp = bcm43xx_radio_read16(bcm, 0x001E);
1577 int i, j;
1578
1579 for (i = 0; i < 5; i++) {
1580 for (j = 0; j < 5; j++) {
1581 if (tmp == (data_high[i] << 4 | data_low[j])) {
1582 bcm43xx_phy_write(bcm, 0x0069, (i - j) << 8 | 0x00C0);
1583 return;
1584 }
1585 }
1586 }
1587}
1588
1589int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
1590 u8 channel,
1591 int synthetic_pu_workaround)
1592{
1593 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1594 u16 r8, tmp;
1595 u16 freq;
1596
1597 if ((radio->manufact == 0x17F) &&
1598 (radio->version == 0x2060) &&
1599 (radio->revision == 1)) {
1600 if (channel > 200)
1601 return -EINVAL;
1602 freq = channel2freq_a(channel);
1603
1604 r8 = bcm43xx_radio_read16(bcm, 0x0008);
1605 bcm43xx_write16(bcm, 0x03F0, freq);
1606 bcm43xx_radio_write16(bcm, 0x0008, r8);
1607
1608 TODO();//TODO: write max channel TX power? to Radio 0x2D
1609 tmp = bcm43xx_radio_read16(bcm, 0x002E);
1610 tmp &= 0x0080;
1611 TODO();//TODO: OR tmp with the Power out estimation for this channel?
1612 bcm43xx_radio_write16(bcm, 0x002E, tmp);
1613
1614 if (freq >= 4920 && freq <= 5500) {
1615 /*
1616 * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
1617 * = (freq * 0.025862069
1618 */
1619 r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
1620 }
1621 bcm43xx_radio_write16(bcm, 0x0007, (r8 << 4) | r8);
1622 bcm43xx_radio_write16(bcm, 0x0020, (r8 << 4) | r8);
1623 bcm43xx_radio_write16(bcm, 0x0021, (r8 << 4) | r8);
1624 bcm43xx_radio_write16(bcm, 0x0022,
1625 (bcm43xx_radio_read16(bcm, 0x0022)
1626 & 0x000F) | (r8 << 4));
1627 bcm43xx_radio_write16(bcm, 0x002A, (r8 << 4));
1628 bcm43xx_radio_write16(bcm, 0x002B, (r8 << 4));
1629 bcm43xx_radio_write16(bcm, 0x0008,
1630 (bcm43xx_radio_read16(bcm, 0x0008)
1631 & 0x00F0) | (r8 << 4));
1632 bcm43xx_radio_write16(bcm, 0x0029,
1633 (bcm43xx_radio_read16(bcm, 0x0029)
1634 & 0xFF0F) | 0x00B0);
1635 bcm43xx_radio_write16(bcm, 0x0035, 0x00AA);
1636 bcm43xx_radio_write16(bcm, 0x0036, 0x0085);
1637 bcm43xx_radio_write16(bcm, 0x003A,
1638 (bcm43xx_radio_read16(bcm, 0x003A)
1639 & 0xFF20) | freq_r3A_value(freq));
1640 bcm43xx_radio_write16(bcm, 0x003D,
1641 bcm43xx_radio_read16(bcm, 0x003D) & 0x00FF);
1642 bcm43xx_radio_write16(bcm, 0x0081,
1643 (bcm43xx_radio_read16(bcm, 0x0081)
1644 & 0xFF7F) | 0x0080);
1645 bcm43xx_radio_write16(bcm, 0x0035,
1646 bcm43xx_radio_read16(bcm, 0x0035) & 0xFFEF);
1647 bcm43xx_radio_write16(bcm, 0x0035,
1648 (bcm43xx_radio_read16(bcm, 0x0035)
1649 & 0xFFEF) | 0x0010);
1650 bcm43xx_radio_set_tx_iq(bcm);
1651 TODO(); //TODO: TSSI2dbm workaround
1652 bcm43xx_phy_xmitpower(bcm);//FIXME correct?
1653 } else {
1654 if ((channel < 1) || (channel > 14))
1655 return -EINVAL;
1656
1657 if (synthetic_pu_workaround)
1658 bcm43xx_synth_pu_workaround(bcm, channel);
1659
1660 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
1661 channel2freq_bg(channel));
1662
1663 if (channel == 14) {
1664 if (bcm->sprom.locale == BCM43xx_LOCALE_JAPAN) {
1665 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
1666 BCM43xx_UCODEFLAGS_OFFSET,
1667 bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
1668 BCM43xx_UCODEFLAGS_OFFSET)
1669 & ~(1 << 7));
1670 } else {
1671 bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
1672 BCM43xx_UCODEFLAGS_OFFSET,
1673 bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
1674 BCM43xx_UCODEFLAGS_OFFSET)
1675 | (1 << 7));
1676 }
1677 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
1678 bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
1679 | (1 << 11));
1680 } else {
1681 bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
1682 bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
1683 & 0xF7BF);
1684 }
1685 }
1686
1687 radio->channel = channel;
1688 //XXX: Using the longer of 2 timeouts (8000 vs 2000 usecs). Specs states
1689 // that 2000 usecs might suffice.
1690 udelay(8000);
1691
1692 return 0;
1693}
1694
1695void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val)
1696{
1697 u16 tmp;
1698
1699 val <<= 8;
1700 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0022) & 0xFCFF;
1701 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0022, tmp | val);
1702 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x03A8) & 0xFCFF;
1703 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x03A8, tmp | val);
1704 tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0054) & 0xFCFF;
1705 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0054, tmp | val);
1706}
1707
1708/* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
1709static u16 bcm43xx_get_txgain_base_band(u16 txpower)
1710{
1711 u16 ret;
1712
1713 assert(txpower <= 63);
1714
1715 if (txpower >= 54)
1716 ret = 2;
1717 else if (txpower >= 49)
1718 ret = 4;
1719 else if (txpower >= 44)
1720 ret = 5;
1721 else
1722 ret = 6;
1723
1724 return ret;
1725}
1726
1727/* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
1728static u16 bcm43xx_get_txgain_freq_power_amp(u16 txpower)
1729{
1730 u16 ret;
1731
1732 assert(txpower <= 63);
1733
1734 if (txpower >= 32)
1735 ret = 0;
1736 else if (txpower >= 25)
1737 ret = 1;
1738 else if (txpower >= 20)
1739 ret = 2;
1740 else if (txpower >= 12)
1741 ret = 3;
1742 else
1743 ret = 4;
1744
1745 return ret;
1746}
1747
1748/* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
1749static u16 bcm43xx_get_txgain_dac(u16 txpower)
1750{
1751 u16 ret;
1752
1753 assert(txpower <= 63);
1754
1755 if (txpower >= 54)
1756 ret = txpower - 53;
1757 else if (txpower >= 49)
1758 ret = txpower - 42;
1759 else if (txpower >= 44)
1760 ret = txpower - 37;
1761 else if (txpower >= 32)
1762 ret = txpower - 32;
1763 else if (txpower >= 25)
1764 ret = txpower - 20;
1765 else if (txpower >= 20)
1766 ret = txpower - 13;
1767 else if (txpower >= 12)
1768 ret = txpower - 8;
1769 else
1770 ret = txpower;
1771
1772 return ret;
1773}
1774
1775void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower)
1776{
1777 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1778 u16 pamp, base, dac, ilt;
1779
1780 txpower = limit_value(txpower, 0, 63);
1781
1782 pamp = bcm43xx_get_txgain_freq_power_amp(txpower);
1783 pamp <<= 5;
1784 pamp &= 0x00E0;
1785 bcm43xx_phy_write(bcm, 0x0019, pamp);
1786
1787 base = bcm43xx_get_txgain_base_band(txpower);
1788 base &= 0x000F;
1789 bcm43xx_phy_write(bcm, 0x0017, base | 0x0020);
1790
1791 ilt = bcm43xx_ilt_read(bcm, 0x3001);
1792 ilt &= 0x0007;
1793
1794 dac = bcm43xx_get_txgain_dac(txpower);
1795 dac <<= 3;
1796 dac |= ilt;
1797
1798 bcm43xx_ilt_write(bcm, 0x3001, dac);
1799
1800 radio->txpwr_offset = txpower;
1801
1802 TODO();
1803 //TODO: FuncPlaceholder (Adjust BB loft cancel)
1804}
1805
1806void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
1807 u16 baseband_attenuation, u16 radio_attenuation,
1808 u16 txpower)
1809{
1810 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1811 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1812
1813 if (baseband_attenuation == 0xFFFF)
1814 baseband_attenuation = radio->baseband_atten;
1815 if (radio_attenuation == 0xFFFF)
1816 radio_attenuation = radio->radio_atten;
1817 if (txpower == 0xFFFF)
1818 txpower = radio->txctl1;
1819 radio->baseband_atten = baseband_attenuation;
1820 radio->radio_atten = radio_attenuation;
1821 radio->txctl1 = txpower;
1822
1823 assert(/*baseband_attenuation >= 0 &&*/ baseband_attenuation <= 11);
1824 if (radio->revision < 6)
1825 assert(/*radio_attenuation >= 0 &&*/ radio_attenuation <= 9);
1826 else
1827 assert(/* radio_attenuation >= 0 &&*/ radio_attenuation <= 31);
1828 assert(/*txpower >= 0 &&*/ txpower <= 7);
1829
1830 bcm43xx_phy_set_baseband_attenuation(bcm, baseband_attenuation);
1831 bcm43xx_radio_write16(bcm, 0x0043, radio_attenuation);
1832 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0064, radio_attenuation);
1833 if (radio->version == 0x2050) {
1834 bcm43xx_radio_write16(bcm, 0x0052,
1835 (bcm43xx_radio_read16(bcm, 0x0052) & ~0x0070)
1836 | ((txpower << 4) & 0x0070));
1837 }
1838 //FIXME: The spec is very weird and unclear here.
1839 if (phy->type == BCM43xx_PHYTYPE_G)
1840 bcm43xx_phy_lo_adjust(bcm, 0);
1841}
1842
1843u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm)
1844{
1845 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1846
1847 if (radio->version == 0x2050 && radio->revision < 6)
1848 return 0;
1849 return 2;
1850}
1851
1852u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm)
1853{
1854 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1855 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1856 u16 att = 0xFFFF;
1857
1858 if (phy->type == BCM43xx_PHYTYPE_A)
1859 return 0x60;
1860
1861 switch (radio->version) {
1862 case 0x2053:
1863 switch (radio->revision) {
1864 case 1:
1865 att = 6;
1866 break;
1867 }
1868 break;
1869 case 0x2050:
1870 switch (radio->revision) {
1871 case 0:
1872 att = 5;
1873 break;
1874 case 1:
1875 if (phy->type == BCM43xx_PHYTYPE_G) {
1876 if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
1877 bcm->board_type == 0x421 &&
1878 bcm->board_revision >= 30)
1879 att = 3;
1880 else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
1881 bcm->board_type == 0x416)
1882 att = 3;
1883 else
1884 att = 1;
1885 } else {
1886 if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
1887 bcm->board_type == 0x421 &&
1888 bcm->board_revision >= 30)
1889 att = 7;
1890 else
1891 att = 6;
1892 }
1893 break;
1894 case 2:
1895 if (phy->type == BCM43xx_PHYTYPE_G) {
1896 if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
1897 bcm->board_type == 0x421 &&
1898 bcm->board_revision >= 30)
1899 att = 3;
1900 else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
1901 bcm->board_type == 0x416)
1902 att = 5;
1903 else if (bcm->chip_id == 0x4320)
1904 att = 4;
1905 else
1906 att = 3;
1907 } else
1908 att = 6;
1909 break;
1910 case 3:
1911 att = 5;
1912 break;
1913 case 4:
1914 case 5:
1915 att = 1;
1916 break;
1917 case 6:
1918 case 7:
1919 att = 5;
1920 break;
1921 case 8:
1922 att = 0x1A;
1923 break;
1924 case 9:
1925 default:
1926 att = 5;
1927 }
1928 }
1929 if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
1930 bcm->board_type == 0x421) {
1931 if (bcm->board_revision < 0x43)
1932 att = 2;
1933 else if (bcm->board_revision < 0x51)
1934 att = 3;
1935 }
1936 if (att == 0xFFFF)
1937 att = 5;
1938
1939 return att;
1940}
1941
1942u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm)
1943{
1944 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1945
1946 if (radio->version != 0x2050)
1947 return 0;
1948 if (radio->revision == 1)
1949 return 3;
1950 if (radio->revision < 6)
1951 return 2;
1952 if (radio->revision == 8)
1953 return 1;
1954 return 0;
1955}
1956
1957void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm)
1958{
1959 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1960 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1961 int err;
1962
1963 if (radio->enabled)
1964 return;
1965
1966 switch (phy->type) {
1967 case BCM43xx_PHYTYPE_A:
1968 bcm43xx_radio_write16(bcm, 0x0004, 0x00C0);
1969 bcm43xx_radio_write16(bcm, 0x0005, 0x0008);
1970 bcm43xx_phy_write(bcm, 0x0010, bcm43xx_phy_read(bcm, 0x0010) & 0xFFF7);
1971 bcm43xx_phy_write(bcm, 0x0011, bcm43xx_phy_read(bcm, 0x0011) & 0xFFF7);
1972 bcm43xx_radio_init2060(bcm);
1973 break;
1974 case BCM43xx_PHYTYPE_B:
1975 case BCM43xx_PHYTYPE_G:
1976 bcm43xx_phy_write(bcm, 0x0015, 0x8000);
1977 bcm43xx_phy_write(bcm, 0x0015, 0xCC00);
1978 bcm43xx_phy_write(bcm, 0x0015, (phy->connected ? 0x00C0 : 0x0000));
1979 err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 1);
1980 assert(err == 0);
1981 break;
1982 default:
1983 assert(0);
1984 }
1985 radio->enabled = 1;
1986 dprintk(KERN_INFO PFX "Radio turned on\n");
1987}
1988
1989void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
1990{
1991 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
1992 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
1993
1994 if (phy->type == BCM43xx_PHYTYPE_A) {
1995 bcm43xx_radio_write16(bcm, 0x0004, 0x00FF);
1996 bcm43xx_radio_write16(bcm, 0x0005, 0x00FB);
1997 bcm43xx_phy_write(bcm, 0x0010, bcm43xx_phy_read(bcm, 0x0010) | 0x0008);
1998 bcm43xx_phy_write(bcm, 0x0011, bcm43xx_phy_read(bcm, 0x0011) | 0x0008);
1999 }
2000 if (phy->type == BCM43xx_PHYTYPE_G && bcm->current_core->rev >= 5) {
2001 bcm43xx_phy_write(bcm, 0x0811, bcm43xx_phy_read(bcm, 0x0811) | 0x008C);
2002 bcm43xx_phy_write(bcm, 0x0812, bcm43xx_phy_read(bcm, 0x0812) & 0xFF73);
2003 } else
2004 bcm43xx_phy_write(bcm, 0x0015, 0xAA00);
2005 radio->enabled = 0;
2006 dprintk(KERN_INFO PFX "Radio turned off\n");
2007}
2008
2009void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm)
2010{
2011 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
2012
2013 switch (phy->type) {
2014 case BCM43xx_PHYTYPE_A:
2015 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0068, 0x7F7F);
2016 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x006a, 0x7F7F);
2017 break;
2018 case BCM43xx_PHYTYPE_B:
2019 case BCM43xx_PHYTYPE_G:
2020 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0058, 0x7F7F);
2021 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x005a, 0x7F7F);
2022 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0070, 0x7F7F);
2023 bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0072, 0x7F7F);
2024 break;
2025 }
2026}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_radio.h b/drivers/net/wireless/bcm43xx/bcm43xx_radio.h
new file mode 100644
index 000000000000..9ed18039fa3e
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_radio.h
@@ -0,0 +1,99 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#ifndef BCM43xx_RADIO_H_
32#define BCM43xx_RADIO_H_
33
34#include "bcm43xx.h"
35
36
37#define BCM43xx_RADIO_DEFAULT_CHANNEL_A 36
38#define BCM43xx_RADIO_DEFAULT_CHANNEL_BG 6
39
40/* Force antenna 0. */
41#define BCM43xx_RADIO_TXANTENNA_0 0
42/* Force antenna 1. */
43#define BCM43xx_RADIO_TXANTENNA_1 1
44/* Use the RX antenna, that was selected for the most recently
45 * received good PLCP header.
46 */
47#define BCM43xx_RADIO_TXANTENNA_LASTPLCP 3
48#define BCM43xx_RADIO_TXANTENNA_DEFAULT BCM43xx_RADIO_TXANTENNA_LASTPLCP
49
50#define BCM43xx_RADIO_INTERFMODE_NONE 0
51#define BCM43xx_RADIO_INTERFMODE_NONWLAN 1
52#define BCM43xx_RADIO_INTERFMODE_MANUALWLAN 2
53#define BCM43xx_RADIO_INTERFMODE_AUTOWLAN 3
54
55
56void bcm43xx_radio_lock(struct bcm43xx_private *bcm);
57void bcm43xx_radio_unlock(struct bcm43xx_private *bcm);
58
59u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset);
60void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val);
61
62u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm);
63void bcm43xx_radio_init2060(struct bcm43xx_private *bcm);
64
65void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm);
66void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm);
67
68int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm, u8 channel,
69 int synthetic_pu_workaround);
70
71void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower);
72void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
73 u16 baseband_attenuation, u16 attenuation,
74 u16 txpower);
75
76u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm);
77u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm);
78u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm);
79
80void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val);
81
82void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm);
83
84u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel);
85u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm);
86
87int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm, int mode);
88
89void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm);
90void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm);
91s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset);
92void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val);
93void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val);
94void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm);
95
96void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm);
97u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm);
98
99#endif /* BCM43xx_RADIO_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
new file mode 100644
index 000000000000..c44d890b949b
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.c
@@ -0,0 +1,322 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 SYSFS support routines
6
7 Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23
24*/
25
26#include "bcm43xx_sysfs.h"
27#include "bcm43xx.h"
28#include "bcm43xx_main.h"
29#include "bcm43xx_radio.h"
30
31#include <linux/capability.h>
32
33
34#define GENERIC_FILESIZE 64
35
36
37static int get_integer(const char *buf, size_t count)
38{
39 char tmp[10 + 1] = { 0 };
40 int ret = -EINVAL;
41
42 if (count == 0)
43 goto out;
44 count = min(count, (size_t)10);
45 memcpy(tmp, buf, count);
46 ret = simple_strtol(tmp, NULL, 10);
47out:
48 return ret;
49}
50
51static int get_boolean(const char *buf, size_t count)
52{
53 if (count != 0) {
54 if (buf[0] == '1')
55 return 1;
56 if (buf[0] == '0')
57 return 0;
58 if (count >= 4 && memcmp(buf, "true", 4) == 0)
59 return 1;
60 if (count >= 5 && memcmp(buf, "false", 5) == 0)
61 return 0;
62 if (count >= 3 && memcmp(buf, "yes", 3) == 0)
63 return 1;
64 if (count >= 2 && memcmp(buf, "no", 2) == 0)
65 return 0;
66 if (count >= 2 && memcmp(buf, "on", 2) == 0)
67 return 1;
68 if (count >= 3 && memcmp(buf, "off", 3) == 0)
69 return 0;
70 }
71 return -EINVAL;
72}
73
74static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
75 struct device_attribute *attr,
76 char *buf)
77{
78 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
79 u16 *sprom;
80 unsigned long flags;
81 int i, err;
82
83 if (!capable(CAP_NET_ADMIN))
84 return -EPERM;
85
86 assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
87 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
88 GFP_KERNEL);
89 if (!sprom)
90 return -ENOMEM;
91 bcm43xx_lock_mmio(bcm, flags);
92 assert(bcm->initialized);
93 err = bcm43xx_sprom_read(bcm, sprom);
94 if (!err) {
95 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
96 buf[i * 2] = sprom[i] & 0x00FF;
97 buf[i * 2 + 1] = (sprom[i] & 0xFF00) >> 8;
98 }
99 }
100 bcm43xx_unlock_mmio(bcm, flags);
101 kfree(sprom);
102
103 return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16);
104}
105
106static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
107 struct device_attribute *attr,
108 const char *buf, size_t count)
109{
110 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
111 u16 *sprom;
112 unsigned long flags;
113 int i, err;
114
115 if (!capable(CAP_NET_ADMIN))
116 return -EPERM;
117
118 if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
119 return -EINVAL;
120 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
121 GFP_KERNEL);
122 if (!sprom)
123 return -ENOMEM;
124 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
125 sprom[i] = buf[i * 2] & 0xFF;
126 sprom[i] |= ((u16)(buf[i * 2 + 1] & 0xFF)) << 8;
127 }
128 bcm43xx_lock_mmio(bcm, flags);
129 assert(bcm->initialized);
130 err = bcm43xx_sprom_write(bcm, sprom);
131 bcm43xx_unlock_mmio(bcm, flags);
132 kfree(sprom);
133
134 return err ? err : count;
135
136}
137
138static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
139 struct device_attribute *attr,
140 char *buf)
141{
142 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
143 unsigned long flags;
144 int err;
145 ssize_t count = 0;
146
147 if (!capable(CAP_NET_ADMIN))
148 return -EPERM;
149
150 bcm43xx_lock(bcm, flags);
151 assert(bcm->initialized);
152
153 switch (bcm43xx_current_radio(bcm)->interfmode) {
154 case BCM43xx_RADIO_INTERFMODE_NONE:
155 count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
156 break;
157 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
158 count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
159 break;
160 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
161 count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
162 break;
163 default:
164 assert(0);
165 }
166 err = 0;
167
168 bcm43xx_unlock(bcm, flags);
169
170 return err ? err : count;
171
172}
173
174static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
175 struct device_attribute *attr,
176 const char *buf, size_t count)
177{
178 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
179 unsigned long flags;
180 int err;
181 int mode;
182
183 if (!capable(CAP_NET_ADMIN))
184 return -EPERM;
185
186 mode = get_integer(buf, count);
187 switch (mode) {
188 case 0:
189 mode = BCM43xx_RADIO_INTERFMODE_NONE;
190 break;
191 case 1:
192 mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
193 break;
194 case 2:
195 mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
196 break;
197 case 3:
198 mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
199 break;
200 default:
201 return -EINVAL;
202 }
203
204 bcm43xx_lock_mmio(bcm, flags);
205 assert(bcm->initialized);
206
207 err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
208 if (err) {
209 printk(KERN_ERR PFX "Interference Mitigation not "
210 "supported by device\n");
211 }
212
213 bcm43xx_unlock_mmio(bcm, flags);
214
215 return err ? err : count;
216}
217
218static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
219 struct device_attribute *attr,
220 char *buf)
221{
222 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
223 unsigned long flags;
224 int err;
225 ssize_t count;
226
227 if (!capable(CAP_NET_ADMIN))
228 return -EPERM;
229
230 bcm43xx_lock(bcm, flags);
231 assert(bcm->initialized);
232
233 if (bcm->short_preamble)
234 count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
235 else
236 count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
237
238 err = 0;
239 bcm43xx_unlock(bcm, flags);
240
241 return err ? err : count;
242}
243
244static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
245 struct device_attribute *attr,
246 const char *buf, size_t count)
247{
248 struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
249 unsigned long flags;
250 int err;
251 int value;
252
253 if (!capable(CAP_NET_ADMIN))
254 return -EPERM;
255
256 value = get_boolean(buf, count);
257 if (value < 0)
258 return value;
259 bcm43xx_lock(bcm, flags);
260 assert(bcm->initialized);
261
262 bcm->short_preamble = !!value;
263
264 err = 0;
265 bcm43xx_unlock(bcm, flags);
266
267 return err ? err : count;
268}
269
270int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
271{
272 struct device *dev = &bcm->pci_dev->dev;
273 struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
274 int err;
275
276 assert(bcm->initialized);
277
278 sysfs->attr_sprom.attr.name = "sprom";
279 sysfs->attr_sprom.attr.owner = THIS_MODULE;
280 sysfs->attr_sprom.attr.mode = 0600;
281 sysfs->attr_sprom.show = bcm43xx_attr_sprom_show;
282 sysfs->attr_sprom.store = bcm43xx_attr_sprom_store;
283 err = device_create_file(dev, &sysfs->attr_sprom);
284 if (err)
285 goto out;
286
287 sysfs->attr_interfmode.attr.name = "interference";
288 sysfs->attr_interfmode.attr.owner = THIS_MODULE;
289 sysfs->attr_interfmode.attr.mode = 0600;
290 sysfs->attr_interfmode.show = bcm43xx_attr_interfmode_show;
291 sysfs->attr_interfmode.store = bcm43xx_attr_interfmode_store;
292 err = device_create_file(dev, &sysfs->attr_interfmode);
293 if (err)
294 goto err_remove_sprom;
295
296 sysfs->attr_preamble.attr.name = "shortpreamble";
297 sysfs->attr_preamble.attr.owner = THIS_MODULE;
298 sysfs->attr_preamble.attr.mode = 0600;
299 sysfs->attr_preamble.show = bcm43xx_attr_preamble_show;
300 sysfs->attr_preamble.store = bcm43xx_attr_preamble_store;
301 err = device_create_file(dev, &sysfs->attr_preamble);
302 if (err)
303 goto err_remove_interfmode;
304
305out:
306 return err;
307err_remove_interfmode:
308 device_remove_file(dev, &sysfs->attr_interfmode);
309err_remove_sprom:
310 device_remove_file(dev, &sysfs->attr_sprom);
311 goto out;
312}
313
314void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
315{
316 struct device *dev = &bcm->pci_dev->dev;
317 struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
318
319 device_remove_file(dev, &sysfs->attr_preamble);
320 device_remove_file(dev, &sysfs->attr_interfmode);
321 device_remove_file(dev, &sysfs->attr_sprom);
322}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
new file mode 100644
index 000000000000..57f14514e3e0
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_sysfs.h
@@ -0,0 +1,25 @@
1#ifndef BCM43xx_SYSFS_H_
2#define BCM43xx_SYSFS_H_
3
4#include <linux/device.h>
5
6
7struct bcm43xx_sysfs {
8 struct device_attribute attr_sprom;
9 struct device_attribute attr_interfmode;
10 struct device_attribute attr_preamble;
11};
12
13#define devattr_to_bcm(attr, attr_name) ({ \
14 struct bcm43xx_sysfs *__s; struct bcm43xx_private *__p; \
15 __s = container_of((attr), struct bcm43xx_sysfs, attr_name); \
16 __p = container_of(__s, struct bcm43xx_private, sysfs); \
17 __p; \
18 })
19
20struct bcm43xx_private;
21
22int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);
23void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm);
24
25#endif /* BCM43xx_SYSFS_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_wx.c b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
new file mode 100644
index 000000000000..3daee828ef4b
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_wx.c
@@ -0,0 +1,1002 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#include <linux/wireless.h>
32#include <net/iw_handler.h>
33#include <net/ieee80211softmac.h>
34#include <net/ieee80211softmac_wx.h>
35#include <linux/capability.h>
36#include <linux/sched.h> /* for capable() */
37#include <linux/delay.h>
38
39#include "bcm43xx.h"
40#include "bcm43xx_wx.h"
41#include "bcm43xx_main.h"
42#include "bcm43xx_radio.h"
43#include "bcm43xx_phy.h"
44
45
46/* The WIRELESS_EXT version, which is implemented by this driver. */
47#define BCM43xx_WX_VERSION 18
48
49#define MAX_WX_STRING 80
50
51
52static int bcm43xx_wx_get_name(struct net_device *net_dev,
53 struct iw_request_info *info,
54 union iwreq_data *data,
55 char *extra)
56{
57 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
58 unsigned long flags;
59 int i;
60 struct bcm43xx_phyinfo *phy;
61 char suffix[7] = { 0 };
62 int have_a = 0, have_b = 0, have_g = 0;
63
64 bcm43xx_lock(bcm, flags);
65 for (i = 0; i < bcm->nr_80211_available; i++) {
66 phy = &(bcm->core_80211_ext[i].phy);
67 switch (phy->type) {
68 case BCM43xx_PHYTYPE_A:
69 have_a = 1;
70 break;
71 case BCM43xx_PHYTYPE_G:
72 have_g = 1;
73 case BCM43xx_PHYTYPE_B:
74 have_b = 1;
75 break;
76 default:
77 assert(0);
78 }
79 }
80 bcm43xx_unlock(bcm, flags);
81
82 i = 0;
83 if (have_a) {
84 suffix[i++] = 'a';
85 suffix[i++] = '/';
86 }
87 if (have_b) {
88 suffix[i++] = 'b';
89 suffix[i++] = '/';
90 }
91 if (have_g) {
92 suffix[i++] = 'g';
93 suffix[i++] = '/';
94 }
95 if (i != 0)
96 suffix[i - 1] = '\0';
97
98 snprintf(data->name, IFNAMSIZ, "IEEE 802.11%s", suffix);
99
100 return 0;
101}
102
103static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
104 struct iw_request_info *info,
105 union iwreq_data *data,
106 char *extra)
107{
108 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
109 unsigned long flags;
110 u8 channel;
111 int freq;
112 int err = -EINVAL;
113
114 bcm43xx_lock_mmio(bcm, flags);
115 if ((data->freq.m >= 0) && (data->freq.m <= 1000)) {
116 channel = data->freq.m;
117 freq = bcm43xx_channel_to_freq(bcm, channel);
118 } else {
119 channel = bcm43xx_freq_to_channel(bcm, data->freq.m);
120 freq = data->freq.m;
121 }
122 if (!bcm43xx_is_valid_channel(bcm, channel))
123 goto out_unlock;
124 if (bcm->initialized) {
125 //ieee80211softmac_disassoc(softmac, $REASON);
126 bcm43xx_mac_suspend(bcm);
127 err = bcm43xx_radio_selectchannel(bcm, channel, 0);
128 bcm43xx_mac_enable(bcm);
129 } else {
130 bcm43xx_current_radio(bcm)->initial_channel = channel;
131 err = 0;
132 }
133out_unlock:
134 bcm43xx_unlock_mmio(bcm, flags);
135
136 return err;
137}
138
139static int bcm43xx_wx_get_channelfreq(struct net_device *net_dev,
140 struct iw_request_info *info,
141 union iwreq_data *data,
142 char *extra)
143{
144 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
145 struct bcm43xx_radioinfo *radio;
146 unsigned long flags;
147 int err = -ENODEV;
148 u16 channel;
149
150 bcm43xx_lock(bcm, flags);
151 radio = bcm43xx_current_radio(bcm);
152 channel = radio->channel;
153 if (channel == 0xFF) {
154 assert(!bcm->initialized);
155 channel = radio->initial_channel;
156 if (channel == 0xFF)
157 goto out_unlock;
158 }
159 assert(channel > 0 && channel <= 1000);
160 data->freq.e = 1;
161 data->freq.m = bcm43xx_channel_to_freq(bcm, channel) * 100000;
162 data->freq.flags = 1;
163
164 err = 0;
165out_unlock:
166 bcm43xx_unlock(bcm, flags);
167
168 return err;
169}
170
171static int bcm43xx_wx_set_mode(struct net_device *net_dev,
172 struct iw_request_info *info,
173 union iwreq_data *data,
174 char *extra)
175{
176 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
177 unsigned long flags;
178 int mode;
179
180 mode = data->mode;
181 if (mode == IW_MODE_AUTO)
182 mode = BCM43xx_INITIAL_IWMODE;
183
184 bcm43xx_lock_mmio(bcm, flags);
185 if (bcm->ieee->iw_mode != mode)
186 bcm43xx_set_iwmode(bcm, mode);
187 bcm43xx_unlock_mmio(bcm, flags);
188
189 return 0;
190}
191
192static int bcm43xx_wx_get_mode(struct net_device *net_dev,
193 struct iw_request_info *info,
194 union iwreq_data *data,
195 char *extra)
196{
197 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
198 unsigned long flags;
199
200 bcm43xx_lock(bcm, flags);
201 data->mode = bcm->ieee->iw_mode;
202 bcm43xx_unlock(bcm, flags);
203
204 return 0;
205}
206
207static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
208 struct iw_request_info *info,
209 union iwreq_data *data,
210 char *extra)
211{
212 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
213 struct iw_range *range = (struct iw_range *)extra;
214 const struct ieee80211_geo *geo;
215 unsigned long flags;
216 int i, j;
217 struct bcm43xx_phyinfo *phy;
218
219 data->data.length = sizeof(*range);
220 memset(range, 0, sizeof(*range));
221
222 //TODO: What about 802.11b?
223 /* 54Mb/s == ~27Mb/s payload throughput (802.11g) */
224 range->throughput = 27 * 1000 * 1000;
225
226 range->max_qual.qual = 100;
227 /* TODO: Real max RSSI */
228 range->max_qual.level = 3;
229 range->max_qual.noise = 100;
230 range->max_qual.updated = 7;
231
232 range->avg_qual.qual = 70;
233 range->avg_qual.level = 2;
234 range->avg_qual.noise = 40;
235 range->avg_qual.updated = 7;
236
237 range->min_rts = BCM43xx_MIN_RTS_THRESHOLD;
238 range->max_rts = BCM43xx_MAX_RTS_THRESHOLD;
239 range->min_frag = MIN_FRAG_THRESHOLD;
240 range->max_frag = MAX_FRAG_THRESHOLD;
241
242 range->encoding_size[0] = 5;
243 range->encoding_size[1] = 13;
244 range->num_encoding_sizes = 2;
245 range->max_encoding_tokens = WEP_KEYS;
246
247 range->we_version_compiled = WIRELESS_EXT;
248 range->we_version_source = BCM43xx_WX_VERSION;
249
250 range->enc_capa = IW_ENC_CAPA_WPA |
251 IW_ENC_CAPA_WPA2 |
252 IW_ENC_CAPA_CIPHER_TKIP |
253 IW_ENC_CAPA_CIPHER_CCMP;
254
255 bcm43xx_lock(bcm, flags);
256 phy = bcm43xx_current_phy(bcm);
257
258 range->num_bitrates = 0;
259 i = 0;
260 if (phy->type == BCM43xx_PHYTYPE_A ||
261 phy->type == BCM43xx_PHYTYPE_G) {
262 range->num_bitrates = 8;
263 range->bitrate[i++] = IEEE80211_OFDM_RATE_6MB;
264 range->bitrate[i++] = IEEE80211_OFDM_RATE_9MB;
265 range->bitrate[i++] = IEEE80211_OFDM_RATE_12MB;
266 range->bitrate[i++] = IEEE80211_OFDM_RATE_18MB;
267 range->bitrate[i++] = IEEE80211_OFDM_RATE_24MB;
268 range->bitrate[i++] = IEEE80211_OFDM_RATE_36MB;
269 range->bitrate[i++] = IEEE80211_OFDM_RATE_48MB;
270 range->bitrate[i++] = IEEE80211_OFDM_RATE_54MB;
271 }
272 if (phy->type == BCM43xx_PHYTYPE_B ||
273 phy->type == BCM43xx_PHYTYPE_G) {
274 range->num_bitrates += 4;
275 range->bitrate[i++] = IEEE80211_CCK_RATE_1MB;
276 range->bitrate[i++] = IEEE80211_CCK_RATE_2MB;
277 range->bitrate[i++] = IEEE80211_CCK_RATE_5MB;
278 range->bitrate[i++] = IEEE80211_CCK_RATE_11MB;
279 }
280
281 geo = ieee80211_get_geo(bcm->ieee);
282 range->num_channels = geo->a_channels + geo->bg_channels;
283 j = 0;
284 for (i = 0; i < geo->a_channels; i++) {
285 if (j == IW_MAX_FREQUENCIES)
286 break;
287 range->freq[j].i = j + 1;
288 range->freq[j].m = geo->a[i].freq;//FIXME?
289 range->freq[j].e = 1;
290 j++;
291 }
292 for (i = 0; i < geo->bg_channels; i++) {
293 if (j == IW_MAX_FREQUENCIES)
294 break;
295 range->freq[j].i = j + 1;
296 range->freq[j].m = geo->bg[i].freq;//FIXME?
297 range->freq[j].e = 1;
298 j++;
299 }
300 range->num_frequency = j;
301
302 bcm43xx_unlock(bcm, flags);
303
304 return 0;
305}
306
307static int bcm43xx_wx_set_nick(struct net_device *net_dev,
308 struct iw_request_info *info,
309 union iwreq_data *data,
310 char *extra)
311{
312 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
313 unsigned long flags;
314 size_t len;
315
316 bcm43xx_lock(bcm, flags);
317 len = min((size_t)data->data.length, (size_t)IW_ESSID_MAX_SIZE);
318 memcpy(bcm->nick, extra, len);
319 bcm->nick[len] = '\0';
320 bcm43xx_unlock(bcm, flags);
321
322 return 0;
323}
324
325static int bcm43xx_wx_get_nick(struct net_device *net_dev,
326 struct iw_request_info *info,
327 union iwreq_data *data,
328 char *extra)
329{
330 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
331 unsigned long flags;
332 size_t len;
333
334 bcm43xx_lock(bcm, flags);
335 len = strlen(bcm->nick) + 1;
336 memcpy(extra, bcm->nick, len);
337 data->data.length = (__u16)len;
338 data->data.flags = 1;
339 bcm43xx_unlock(bcm, flags);
340
341 return 0;
342}
343
344static int bcm43xx_wx_set_rts(struct net_device *net_dev,
345 struct iw_request_info *info,
346 union iwreq_data *data,
347 char *extra)
348{
349 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
350 unsigned long flags;
351 int err = -EINVAL;
352
353 bcm43xx_lock(bcm, flags);
354 if (data->rts.disabled) {
355 bcm->rts_threshold = BCM43xx_MAX_RTS_THRESHOLD;
356 err = 0;
357 } else {
358 if (data->rts.value >= BCM43xx_MIN_RTS_THRESHOLD &&
359 data->rts.value <= BCM43xx_MAX_RTS_THRESHOLD) {
360 bcm->rts_threshold = data->rts.value;
361 err = 0;
362 }
363 }
364 bcm43xx_unlock(bcm, flags);
365
366 return err;
367}
368
369static int bcm43xx_wx_get_rts(struct net_device *net_dev,
370 struct iw_request_info *info,
371 union iwreq_data *data,
372 char *extra)
373{
374 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
375 unsigned long flags;
376
377 bcm43xx_lock(bcm, flags);
378 data->rts.value = bcm->rts_threshold;
379 data->rts.fixed = 0;
380 data->rts.disabled = (bcm->rts_threshold == BCM43xx_MAX_RTS_THRESHOLD);
381 bcm43xx_unlock(bcm, flags);
382
383 return 0;
384}
385
386static int bcm43xx_wx_set_frag(struct net_device *net_dev,
387 struct iw_request_info *info,
388 union iwreq_data *data,
389 char *extra)
390{
391 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
392 unsigned long flags;
393 int err = -EINVAL;
394
395 bcm43xx_lock(bcm, flags);
396 if (data->frag.disabled) {
397 bcm->ieee->fts = MAX_FRAG_THRESHOLD;
398 err = 0;
399 } else {
400 if (data->frag.value >= MIN_FRAG_THRESHOLD &&
401 data->frag.value <= MAX_FRAG_THRESHOLD) {
402 bcm->ieee->fts = data->frag.value & ~0x1;
403 err = 0;
404 }
405 }
406 bcm43xx_unlock(bcm, flags);
407
408 return err;
409}
410
411static int bcm43xx_wx_get_frag(struct net_device *net_dev,
412 struct iw_request_info *info,
413 union iwreq_data *data,
414 char *extra)
415{
416 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
417 unsigned long flags;
418
419 bcm43xx_lock(bcm, flags);
420 data->frag.value = bcm->ieee->fts;
421 data->frag.fixed = 0;
422 data->frag.disabled = (bcm->ieee->fts == MAX_FRAG_THRESHOLD);
423 bcm43xx_unlock(bcm, flags);
424
425 return 0;
426}
427
428static int bcm43xx_wx_set_xmitpower(struct net_device *net_dev,
429 struct iw_request_info *info,
430 union iwreq_data *data,
431 char *extra)
432{
433 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
434 struct bcm43xx_radioinfo *radio;
435 struct bcm43xx_phyinfo *phy;
436 unsigned long flags;
437 int err = -ENODEV;
438 u16 maxpower;
439
440 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
441 printk(PFX KERN_ERR "TX power not in dBm.\n");
442 return -EOPNOTSUPP;
443 }
444
445 bcm43xx_lock_mmio(bcm, flags);
446 if (!bcm->initialized)
447 goto out_unlock;
448 radio = bcm43xx_current_radio(bcm);
449 phy = bcm43xx_current_phy(bcm);
450 if (data->txpower.disabled != (!(radio->enabled))) {
451 if (data->txpower.disabled)
452 bcm43xx_radio_turn_off(bcm);
453 else
454 bcm43xx_radio_turn_on(bcm);
455 }
456 if (data->txpower.value > 0) {
457 /* desired and maxpower dBm values are in Q5.2 */
458 if (phy->type == BCM43xx_PHYTYPE_A)
459 maxpower = bcm->sprom.maxpower_aphy;
460 else
461 maxpower = bcm->sprom.maxpower_bgphy;
462 radio->txpower_desired = limit_value(data->txpower.value << 2,
463 0, maxpower);
464 bcm43xx_phy_xmitpower(bcm);
465 }
466 err = 0;
467
468out_unlock:
469 bcm43xx_unlock_mmio(bcm, flags);
470
471 return err;
472}
473
474static int bcm43xx_wx_get_xmitpower(struct net_device *net_dev,
475 struct iw_request_info *info,
476 union iwreq_data *data,
477 char *extra)
478{
479 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
480 struct bcm43xx_radioinfo *radio;
481 unsigned long flags;
482 int err = -ENODEV;
483
484 bcm43xx_lock(bcm, flags);
485 if (!bcm->initialized)
486 goto out_unlock;
487 radio = bcm43xx_current_radio(bcm);
488 /* desired dBm value is in Q5.2 */
489 data->txpower.value = radio->txpower_desired >> 2;
490 data->txpower.fixed = 1;
491 data->txpower.flags = IW_TXPOW_DBM;
492 data->txpower.disabled = !(radio->enabled);
493
494 err = 0;
495out_unlock:
496 bcm43xx_unlock(bcm, flags);
497
498 return err;
499}
500
501static int bcm43xx_wx_set_encoding(struct net_device *net_dev,
502 struct iw_request_info *info,
503 union iwreq_data *data,
504 char *extra)
505{
506 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
507 int err;
508
509 err = ieee80211_wx_set_encode(bcm->ieee, info, data, extra);
510
511 return err;
512}
513
514static int bcm43xx_wx_set_encodingext(struct net_device *net_dev,
515 struct iw_request_info *info,
516 union iwreq_data *data,
517 char *extra)
518{
519 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
520 int err;
521
522 err = ieee80211_wx_set_encodeext(bcm->ieee, info, data, extra);
523
524 return err;
525}
526
527static int bcm43xx_wx_get_encoding(struct net_device *net_dev,
528 struct iw_request_info *info,
529 union iwreq_data *data,
530 char *extra)
531{
532 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
533 int err;
534
535 err = ieee80211_wx_get_encode(bcm->ieee, info, data, extra);
536
537 return err;
538}
539
540static int bcm43xx_wx_get_encodingext(struct net_device *net_dev,
541 struct iw_request_info *info,
542 union iwreq_data *data,
543 char *extra)
544{
545 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
546 int err;
547
548 err = ieee80211_wx_get_encodeext(bcm->ieee, info, data, extra);
549
550 return err;
551}
552
553static int bcm43xx_wx_set_interfmode(struct net_device *net_dev,
554 struct iw_request_info *info,
555 union iwreq_data *data,
556 char *extra)
557{
558 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
559 unsigned long flags;
560 int mode, err = 0;
561
562 mode = *((int *)extra);
563 switch (mode) {
564 case 0:
565 mode = BCM43xx_RADIO_INTERFMODE_NONE;
566 break;
567 case 1:
568 mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
569 break;
570 case 2:
571 mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
572 break;
573 case 3:
574 mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
575 break;
576 default:
577 printk(KERN_ERR PFX "set_interfmode allowed parameters are: "
578 "0 => None, 1 => Non-WLAN, 2 => WLAN, "
579 "3 => Auto-WLAN\n");
580 return -EINVAL;
581 }
582
583 bcm43xx_lock_mmio(bcm, flags);
584 if (bcm->initialized) {
585 err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
586 if (err) {
587 printk(KERN_ERR PFX "Interference Mitigation not "
588 "supported by device\n");
589 }
590 } else {
591 if (mode == BCM43xx_RADIO_INTERFMODE_AUTOWLAN) {
592 printk(KERN_ERR PFX "Interference Mitigation mode Auto-WLAN "
593 "not supported while the interface is down.\n");
594 err = -ENODEV;
595 } else
596 bcm43xx_current_radio(bcm)->interfmode = mode;
597 }
598 bcm43xx_unlock_mmio(bcm, flags);
599
600 return err;
601}
602
603static int bcm43xx_wx_get_interfmode(struct net_device *net_dev,
604 struct iw_request_info *info,
605 union iwreq_data *data,
606 char *extra)
607{
608 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
609 unsigned long flags;
610 int mode;
611
612 bcm43xx_lock(bcm, flags);
613 mode = bcm43xx_current_radio(bcm)->interfmode;
614 bcm43xx_unlock(bcm, flags);
615
616 switch (mode) {
617 case BCM43xx_RADIO_INTERFMODE_NONE:
618 strncpy(extra, "0 (No Interference Mitigation)", MAX_WX_STRING);
619 break;
620 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
621 strncpy(extra, "1 (Non-WLAN Interference Mitigation)", MAX_WX_STRING);
622 break;
623 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
624 strncpy(extra, "2 (WLAN Interference Mitigation)", MAX_WX_STRING);
625 break;
626 default:
627 assert(0);
628 }
629 data->data.length = strlen(extra) + 1;
630
631 return 0;
632}
633
634static int bcm43xx_wx_set_shortpreamble(struct net_device *net_dev,
635 struct iw_request_info *info,
636 union iwreq_data *data,
637 char *extra)
638{
639 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
640 unsigned long flags;
641 int on;
642
643 on = *((int *)extra);
644 bcm43xx_lock(bcm, flags);
645 bcm->short_preamble = !!on;
646 bcm43xx_unlock(bcm, flags);
647
648 return 0;
649}
650
651static int bcm43xx_wx_get_shortpreamble(struct net_device *net_dev,
652 struct iw_request_info *info,
653 union iwreq_data *data,
654 char *extra)
655{
656 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
657 unsigned long flags;
658 int on;
659
660 bcm43xx_lock(bcm, flags);
661 on = bcm->short_preamble;
662 bcm43xx_unlock(bcm, flags);
663
664 if (on)
665 strncpy(extra, "1 (Short Preamble enabled)", MAX_WX_STRING);
666 else
667 strncpy(extra, "0 (Short Preamble disabled)", MAX_WX_STRING);
668 data->data.length = strlen(extra) + 1;
669
670 return 0;
671}
672
673static int bcm43xx_wx_set_swencryption(struct net_device *net_dev,
674 struct iw_request_info *info,
675 union iwreq_data *data,
676 char *extra)
677{
678 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
679 unsigned long flags;
680 int on;
681
682 on = *((int *)extra);
683
684 bcm43xx_lock(bcm, flags);
685 bcm->ieee->host_encrypt = !!on;
686 bcm->ieee->host_decrypt = !!on;
687 bcm->ieee->host_build_iv = !on;
688 bcm43xx_unlock(bcm, flags);
689
690 return 0;
691}
692
693static int bcm43xx_wx_get_swencryption(struct net_device *net_dev,
694 struct iw_request_info *info,
695 union iwreq_data *data,
696 char *extra)
697{
698 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
699 unsigned long flags;
700 int on;
701
702 bcm43xx_lock(bcm, flags);
703 on = bcm->ieee->host_encrypt;
704 bcm43xx_unlock(bcm, flags);
705
706 if (on)
707 strncpy(extra, "1 (SW encryption enabled) ", MAX_WX_STRING);
708 else
709 strncpy(extra, "0 (SW encryption disabled) ", MAX_WX_STRING);
710 data->data.length = strlen(extra + 1);
711
712 return 0;
713}
714
715/* Enough buffer to hold a hexdump of the sprom data. */
716#define SPROM_BUFFERSIZE 512
717
718static int sprom2hex(const u16 *sprom, char *dump)
719{
720 int i, pos = 0;
721
722 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
723 pos += snprintf(dump + pos, SPROM_BUFFERSIZE - pos - 1,
724 "%04X", swab16(sprom[i]) & 0xFFFF);
725 }
726
727 return pos + 1;
728}
729
730static int hex2sprom(u16 *sprom, const char *dump, unsigned int len)
731{
732 char tmp[5] = { 0 };
733 int cnt = 0;
734 unsigned long parsed;
735
736 if (len < BCM43xx_SPROM_SIZE * sizeof(u16) * 2)
737 return -EINVAL;
738 while (cnt < BCM43xx_SPROM_SIZE) {
739 memcpy(tmp, dump, 4);
740 dump += 4;
741 parsed = simple_strtoul(tmp, NULL, 16);
742 sprom[cnt++] = swab16((u16)parsed);
743 }
744
745 return 0;
746}
747
748static int bcm43xx_wx_sprom_read(struct net_device *net_dev,
749 struct iw_request_info *info,
750 union iwreq_data *data,
751 char *extra)
752{
753 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
754 int err = -EPERM;
755 u16 *sprom;
756 unsigned long flags;
757
758 if (!capable(CAP_SYS_RAWIO))
759 goto out;
760
761 err = -ENOMEM;
762 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
763 GFP_KERNEL);
764 if (!sprom)
765 goto out;
766
767 bcm43xx_lock_mmio(bcm, flags);
768 err = -ENODEV;
769 if (bcm->initialized)
770 err = bcm43xx_sprom_read(bcm, sprom);
771 bcm43xx_unlock_mmio(bcm, flags);
772 if (!err)
773 data->data.length = sprom2hex(sprom, extra);
774 kfree(sprom);
775out:
776 return err;
777}
778
779static int bcm43xx_wx_sprom_write(struct net_device *net_dev,
780 struct iw_request_info *info,
781 union iwreq_data *data,
782 char *extra)
783{
784 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
785 int err = -EPERM;
786 u16 *sprom;
787 unsigned long flags;
788 char *input;
789 unsigned int len;
790
791 if (!capable(CAP_SYS_RAWIO))
792 goto out;
793
794 err = -ENOMEM;
795 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
796 GFP_KERNEL);
797 if (!sprom)
798 goto out;
799
800 len = data->data.length;
801 extra[len - 1] = '\0';
802 input = strchr(extra, ':');
803 if (input) {
804 input++;
805 len -= input - extra;
806 } else
807 input = extra;
808 err = hex2sprom(sprom, input, len);
809 if (err)
810 goto out_kfree;
811
812 bcm43xx_lock_mmio(bcm, flags);
813 err = -ENODEV;
814 if (bcm->initialized)
815 err = bcm43xx_sprom_write(bcm, sprom);
816 bcm43xx_unlock_mmio(bcm, flags);
817out_kfree:
818 kfree(sprom);
819out:
820 return err;
821}
822
823/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
824
825static struct iw_statistics *bcm43xx_get_wireless_stats(struct net_device *net_dev)
826{
827 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
828 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
829 struct iw_statistics *wstats;
830
831 wstats = &bcm->stats.wstats;
832 if (!mac->associated) {
833 wstats->miss.beacon = 0;
834// bcm->ieee->ieee_stats.tx_retry_limit_exceeded = 0; // FIXME: should this be cleared here?
835 wstats->discard.retries = 0;
836// bcm->ieee->ieee_stats.tx_discards_wrong_sa = 0; // FIXME: same question
837 wstats->discard.nwid = 0;
838// bcm->ieee->ieee_stats.rx_discards_undecryptable = 0; // FIXME: ditto
839 wstats->discard.code = 0;
840// bcm->ieee->ieee_stats.rx_fragments = 0; // FIXME: same here
841 wstats->discard.fragment = 0;
842 wstats->discard.misc = 0;
843 wstats->qual.qual = 0;
844 wstats->qual.level = 0;
845 wstats->qual.noise = 0;
846 wstats->qual.updated = 7;
847 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
848 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
849 return wstats;
850 }
851 /* fill in the real statistics when iface associated */
852 wstats->qual.qual = 100; // TODO: get the real signal quality
853 wstats->qual.level = 3 - bcm->stats.link_quality;
854 wstats->qual.noise = bcm->stats.noise;
855 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
856 IW_QUAL_NOISE_UPDATED;
857 wstats->discard.code = bcm->ieee->ieee_stats.rx_discards_undecryptable;
858 wstats->discard.retries = bcm->ieee->ieee_stats.tx_retry_limit_exceeded;
859 wstats->discard.nwid = bcm->ieee->ieee_stats.tx_discards_wrong_sa;
860 wstats->discard.fragment = bcm->ieee->ieee_stats.rx_fragments;
861 wstats->discard.misc = 0; // FIXME
862 wstats->miss.beacon = 0; // FIXME
863 return wstats;
864}
865
866
867#ifdef WX
868# undef WX
869#endif
870#define WX(ioctl) [(ioctl) - SIOCSIWCOMMIT]
871static const iw_handler bcm43xx_wx_handlers[] = {
872 /* Wireless Identification */
873 WX(SIOCGIWNAME) = bcm43xx_wx_get_name,
874 /* Basic operations */
875 WX(SIOCSIWFREQ) = bcm43xx_wx_set_channelfreq,
876 WX(SIOCGIWFREQ) = bcm43xx_wx_get_channelfreq,
877 WX(SIOCSIWMODE) = bcm43xx_wx_set_mode,
878 WX(SIOCGIWMODE) = bcm43xx_wx_get_mode,
879 /* Informative stuff */
880 WX(SIOCGIWRANGE) = bcm43xx_wx_get_rangeparams,
881 /* Access Point manipulation */
882 WX(SIOCSIWAP) = ieee80211softmac_wx_set_wap,
883 WX(SIOCGIWAP) = ieee80211softmac_wx_get_wap,
884 WX(SIOCSIWSCAN) = ieee80211softmac_wx_trigger_scan,
885 WX(SIOCGIWSCAN) = ieee80211softmac_wx_get_scan_results,
886 /* 802.11 specific support */
887 WX(SIOCSIWESSID) = ieee80211softmac_wx_set_essid,
888 WX(SIOCGIWESSID) = ieee80211softmac_wx_get_essid,
889 WX(SIOCSIWNICKN) = bcm43xx_wx_set_nick,
890 WX(SIOCGIWNICKN) = bcm43xx_wx_get_nick,
891 /* Other parameters */
892 WX(SIOCSIWRATE) = ieee80211softmac_wx_set_rate,
893 WX(SIOCGIWRATE) = ieee80211softmac_wx_get_rate,
894 WX(SIOCSIWRTS) = bcm43xx_wx_set_rts,
895 WX(SIOCGIWRTS) = bcm43xx_wx_get_rts,
896 WX(SIOCSIWFRAG) = bcm43xx_wx_set_frag,
897 WX(SIOCGIWFRAG) = bcm43xx_wx_get_frag,
898 WX(SIOCSIWTXPOW) = bcm43xx_wx_set_xmitpower,
899 WX(SIOCGIWTXPOW) = bcm43xx_wx_get_xmitpower,
900//TODO WX(SIOCSIWRETRY) = bcm43xx_wx_set_retry,
901//TODO WX(SIOCGIWRETRY) = bcm43xx_wx_get_retry,
902 /* Encoding */
903 WX(SIOCSIWENCODE) = bcm43xx_wx_set_encoding,
904 WX(SIOCGIWENCODE) = bcm43xx_wx_get_encoding,
905 WX(SIOCSIWENCODEEXT) = bcm43xx_wx_set_encodingext,
906 WX(SIOCGIWENCODEEXT) = bcm43xx_wx_get_encodingext,
907 /* Power saving */
908//TODO WX(SIOCSIWPOWER) = bcm43xx_wx_set_power,
909//TODO WX(SIOCGIWPOWER) = bcm43xx_wx_get_power,
910 WX(SIOCSIWGENIE) = ieee80211softmac_wx_set_genie,
911 WX(SIOCGIWGENIE) = ieee80211softmac_wx_get_genie,
912 WX(SIOCSIWAUTH) = ieee80211_wx_set_auth,
913 WX(SIOCGIWAUTH) = ieee80211_wx_get_auth,
914};
915#undef WX
916
917static const iw_handler bcm43xx_priv_wx_handlers[] = {
918 /* Set Interference Mitigation Mode. */
919 bcm43xx_wx_set_interfmode,
920 /* Get Interference Mitigation Mode. */
921 bcm43xx_wx_get_interfmode,
922 /* Enable/Disable Short Preamble mode. */
923 bcm43xx_wx_set_shortpreamble,
924 /* Get Short Preamble mode. */
925 bcm43xx_wx_get_shortpreamble,
926 /* Enable/Disable Software Encryption mode */
927 bcm43xx_wx_set_swencryption,
928 /* Get Software Encryption mode */
929 bcm43xx_wx_get_swencryption,
930 /* Write SRPROM data. */
931 bcm43xx_wx_sprom_write,
932 /* Read SPROM data. */
933 bcm43xx_wx_sprom_read,
934};
935
936#define PRIV_WX_SET_INTERFMODE (SIOCIWFIRSTPRIV + 0)
937#define PRIV_WX_GET_INTERFMODE (SIOCIWFIRSTPRIV + 1)
938#define PRIV_WX_SET_SHORTPREAMBLE (SIOCIWFIRSTPRIV + 2)
939#define PRIV_WX_GET_SHORTPREAMBLE (SIOCIWFIRSTPRIV + 3)
940#define PRIV_WX_SET_SWENCRYPTION (SIOCIWFIRSTPRIV + 4)
941#define PRIV_WX_GET_SWENCRYPTION (SIOCIWFIRSTPRIV + 5)
942#define PRIV_WX_SPROM_WRITE (SIOCIWFIRSTPRIV + 6)
943#define PRIV_WX_SPROM_READ (SIOCIWFIRSTPRIV + 7)
944
945#define PRIV_WX_DUMMY(ioctl) \
946 { \
947 .cmd = (ioctl), \
948 .name = "__unused" \
949 }
950
951static const struct iw_priv_args bcm43xx_priv_wx_args[] = {
952 {
953 .cmd = PRIV_WX_SET_INTERFMODE,
954 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
955 .name = "set_interfmode",
956 },
957 {
958 .cmd = PRIV_WX_GET_INTERFMODE,
959 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
960 .name = "get_interfmode",
961 },
962 {
963 .cmd = PRIV_WX_SET_SHORTPREAMBLE,
964 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
965 .name = "set_shortpreambl",
966 },
967 {
968 .cmd = PRIV_WX_GET_SHORTPREAMBLE,
969 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
970 .name = "get_shortpreambl",
971 },
972 {
973 .cmd = PRIV_WX_SET_SWENCRYPTION,
974 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
975 .name = "set_swencryption",
976 },
977 {
978 .cmd = PRIV_WX_GET_SWENCRYPTION,
979 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
980 .name = "get_swencryption",
981 },
982 {
983 .cmd = PRIV_WX_SPROM_WRITE,
984 .set_args = IW_PRIV_TYPE_CHAR | SPROM_BUFFERSIZE,
985 .name = "write_sprom",
986 },
987 {
988 .cmd = PRIV_WX_SPROM_READ,
989 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | SPROM_BUFFERSIZE,
990 .name = "read_sprom",
991 },
992};
993
994const struct iw_handler_def bcm43xx_wx_handlers_def = {
995 .standard = bcm43xx_wx_handlers,
996 .num_standard = ARRAY_SIZE(bcm43xx_wx_handlers),
997 .num_private = ARRAY_SIZE(bcm43xx_priv_wx_handlers),
998 .num_private_args = ARRAY_SIZE(bcm43xx_priv_wx_args),
999 .private = bcm43xx_priv_wx_handlers,
1000 .private_args = bcm43xx_priv_wx_args,
1001 .get_wireless_stats = bcm43xx_get_wireless_stats,
1002};
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_wx.h b/drivers/net/wireless/bcm43xx/bcm43xx_wx.h
new file mode 100644
index 000000000000..1f29ff3aa4c3
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_wx.h
@@ -0,0 +1,36 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
10
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
28
29*/
30
31#ifndef BCM43xx_WX_H_
32#define BCM43xx_WX_H_
33
34extern const struct iw_handler_def bcm43xx_wx_handlers_def;
35
36#endif /* BCM43xx_WX_H_ */
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
new file mode 100644
index 000000000000..d8ece28c079f
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c
@@ -0,0 +1,582 @@
1/*
2
3 Broadcom BCM43xx wireless driver
4
5 Transmission (TX/RX) related functions.
6
7 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
8 Stefano Brivio <st3@riseup.net>
9 Michael Buesch <mbuesch@freenet.de>
10 Danny van Dyk <kugelfang@gentoo.org>
11 Andreas Jaggi <andreas.jaggi@waterwave.ch>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; see the file COPYING. If not, write to
25 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
26 Boston, MA 02110-1301, USA.
27
28*/
29
30#include "bcm43xx_xmit.h"
31
32#include <linux/etherdevice.h>
33
34
35/* Extract the bitrate out of a CCK PLCP header. */
36static u8 bcm43xx_plcp_get_bitrate_cck(struct bcm43xx_plcp_hdr4 *plcp)
37{
38 switch (plcp->raw[0]) {
39 case 0x0A:
40 return IEEE80211_CCK_RATE_1MB;
41 case 0x14:
42 return IEEE80211_CCK_RATE_2MB;
43 case 0x37:
44 return IEEE80211_CCK_RATE_5MB;
45 case 0x6E:
46 return IEEE80211_CCK_RATE_11MB;
47 }
48 assert(0);
49 return 0;
50}
51
52/* Extract the bitrate out of an OFDM PLCP header. */
53static u8 bcm43xx_plcp_get_bitrate_ofdm(struct bcm43xx_plcp_hdr4 *plcp)
54{
55 switch (plcp->raw[0] & 0xF) {
56 case 0xB:
57 return IEEE80211_OFDM_RATE_6MB;
58 case 0xF:
59 return IEEE80211_OFDM_RATE_9MB;
60 case 0xA:
61 return IEEE80211_OFDM_RATE_12MB;
62 case 0xE:
63 return IEEE80211_OFDM_RATE_18MB;
64 case 0x9:
65 return IEEE80211_OFDM_RATE_24MB;
66 case 0xD:
67 return IEEE80211_OFDM_RATE_36MB;
68 case 0x8:
69 return IEEE80211_OFDM_RATE_48MB;
70 case 0xC:
71 return IEEE80211_OFDM_RATE_54MB;
72 }
73 assert(0);
74 return 0;
75}
76
77u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
78{
79 switch (bitrate) {
80 case IEEE80211_CCK_RATE_1MB:
81 return 0x0A;
82 case IEEE80211_CCK_RATE_2MB:
83 return 0x14;
84 case IEEE80211_CCK_RATE_5MB:
85 return 0x37;
86 case IEEE80211_CCK_RATE_11MB:
87 return 0x6E;
88 }
89 assert(0);
90 return 0;
91}
92
93u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
94{
95 switch (bitrate) {
96 case IEEE80211_OFDM_RATE_6MB:
97 return 0xB;
98 case IEEE80211_OFDM_RATE_9MB:
99 return 0xF;
100 case IEEE80211_OFDM_RATE_12MB:
101 return 0xA;
102 case IEEE80211_OFDM_RATE_18MB:
103 return 0xE;
104 case IEEE80211_OFDM_RATE_24MB:
105 return 0x9;
106 case IEEE80211_OFDM_RATE_36MB:
107 return 0xD;
108 case IEEE80211_OFDM_RATE_48MB:
109 return 0x8;
110 case IEEE80211_OFDM_RATE_54MB:
111 return 0xC;
112 }
113 assert(0);
114 return 0;
115}
116
117static void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
118 const u16 octets, const u8 bitrate,
119 const int ofdm_modulation)
120{
121 __le32 *data = &(plcp->data);
122 __u8 *raw = plcp->raw;
123
124 if (ofdm_modulation) {
125 *data = bcm43xx_plcp_get_ratecode_ofdm(bitrate);
126 assert(!(octets & 0xF000));
127 *data |= (octets << 5);
128 *data = cpu_to_le32(*data);
129 } else {
130 u32 plen;
131
132 plen = octets * 16 / bitrate;
133 if ((octets * 16 % bitrate) > 0) {
134 plen++;
135 if ((bitrate == IEEE80211_CCK_RATE_11MB)
136 && ((octets * 8 % 11) < 4)) {
137 raw[1] = 0x84;
138 } else
139 raw[1] = 0x04;
140 } else
141 raw[1] = 0x04;
142 *data |= cpu_to_le32(plen << 16);
143 raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
144 }
145}
146
147static u8 bcm43xx_calc_fallback_rate(u8 bitrate)
148{
149 switch (bitrate) {
150 case IEEE80211_CCK_RATE_1MB:
151 return IEEE80211_CCK_RATE_1MB;
152 case IEEE80211_CCK_RATE_2MB:
153 return IEEE80211_CCK_RATE_1MB;
154 case IEEE80211_CCK_RATE_5MB:
155 return IEEE80211_CCK_RATE_2MB;
156 case IEEE80211_CCK_RATE_11MB:
157 return IEEE80211_CCK_RATE_5MB;
158 case IEEE80211_OFDM_RATE_6MB:
159 return IEEE80211_CCK_RATE_5MB;
160 case IEEE80211_OFDM_RATE_9MB:
161 return IEEE80211_OFDM_RATE_6MB;
162 case IEEE80211_OFDM_RATE_12MB:
163 return IEEE80211_OFDM_RATE_9MB;
164 case IEEE80211_OFDM_RATE_18MB:
165 return IEEE80211_OFDM_RATE_12MB;
166 case IEEE80211_OFDM_RATE_24MB:
167 return IEEE80211_OFDM_RATE_18MB;
168 case IEEE80211_OFDM_RATE_36MB:
169 return IEEE80211_OFDM_RATE_24MB;
170 case IEEE80211_OFDM_RATE_48MB:
171 return IEEE80211_OFDM_RATE_36MB;
172 case IEEE80211_OFDM_RATE_54MB:
173 return IEEE80211_OFDM_RATE_48MB;
174 }
175 assert(0);
176 return 0;
177}
178
179static
180__le16 bcm43xx_calc_duration_id(const struct ieee80211_hdr *wireless_header,
181 u8 bitrate)
182{
183 const u16 frame_ctl = le16_to_cpu(wireless_header->frame_ctl);
184 __le16 duration_id = wireless_header->duration_id;
185
186 switch (WLAN_FC_GET_TYPE(frame_ctl)) {
187 case IEEE80211_FTYPE_DATA:
188 case IEEE80211_FTYPE_MGMT:
189 //TODO: Steal the code from ieee80211, once it is completed there.
190 break;
191 case IEEE80211_FTYPE_CTL:
192 /* Use the original duration/id. */
193 break;
194 default:
195 assert(0);
196 }
197
198 return duration_id;
199}
200
201static inline
202u16 ceiling_div(u16 dividend, u16 divisor)
203{
204 return ((dividend + divisor - 1) / divisor);
205}
206
207static void bcm43xx_generate_rts(const struct bcm43xx_phyinfo *phy,
208 struct bcm43xx_txhdr *txhdr,
209 u16 *flags,
210 u8 bitrate,
211 const struct ieee80211_hdr_4addr *wlhdr)
212{
213 u16 fctl;
214 u16 dur;
215 u8 fallback_bitrate;
216 int ofdm_modulation;
217 int fallback_ofdm_modulation;
218// u8 *sa, *da;
219 u16 flen;
220
221//FIXME sa = ieee80211_get_SA((struct ieee80211_hdr *)wlhdr);
222//FIXME da = ieee80211_get_DA((struct ieee80211_hdr *)wlhdr);
223 fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
224 ofdm_modulation = !(ieee80211_is_cck_rate(bitrate));
225 fallback_ofdm_modulation = !(ieee80211_is_cck_rate(fallback_bitrate));
226
227 flen = sizeof(u16) + sizeof(u16) + ETH_ALEN + ETH_ALEN + IEEE80211_FCS_LEN,
228 bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_cts_plcp),
229 flen, bitrate,
230 !ieee80211_is_cck_rate(bitrate));
231 bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_cts_fallback_plcp),
232 flen, fallback_bitrate,
233 !ieee80211_is_cck_rate(fallback_bitrate));
234 fctl = IEEE80211_FTYPE_CTL;
235 fctl |= IEEE80211_STYPE_RTS;
236 dur = le16_to_cpu(wlhdr->duration_id);
237/*FIXME: should we test for dur==0 here and let it unmodified in this case?
238 * The following assert checks for this case...
239 */
240assert(dur);
241/*FIXME: The duration calculation is not really correct.
242 * I am not 100% sure which bitrate to use. We use the RTS rate here,
243 * but this is likely to be wrong.
244 */
245 if (phy->type == BCM43xx_PHYTYPE_A) {
246 /* Three times SIFS */
247 dur += 16 * 3;
248 /* Add ACK duration. */
249 dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
250 bitrate * 4);
251 /* Add CTS duration. */
252 dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
253 bitrate * 4);
254 } else {
255 /* Three times SIFS */
256 dur += 10 * 3;
257 /* Add ACK duration. */
258 dur += ceiling_div(8 * (14 /*bytes*/) * 10,
259 bitrate);
260 /* Add CTS duration. */
261 dur += ceiling_div(8 * (14 /*bytes*/) * 10,
262 bitrate);
263 }
264
265 txhdr->rts_cts_frame_control = cpu_to_le16(fctl);
266 txhdr->rts_cts_dur = cpu_to_le16(dur);
267//printk(BCM43xx_MACFMT " " BCM43xx_MACFMT " " BCM43xx_MACFMT "\n", BCM43xx_MACARG(wlhdr->addr1), BCM43xx_MACARG(wlhdr->addr2), BCM43xx_MACARG(wlhdr->addr3));
268//printk(BCM43xx_MACFMT " " BCM43xx_MACFMT "\n", BCM43xx_MACARG(sa), BCM43xx_MACARG(da));
269 memcpy(txhdr->rts_cts_mac1, wlhdr->addr1, ETH_ALEN);//FIXME!
270// memcpy(txhdr->rts_cts_mac2, sa, ETH_ALEN);
271
272 *flags |= BCM43xx_TXHDRFLAG_RTSCTS;
273 *flags |= BCM43xx_TXHDRFLAG_RTS;
274 if (ofdm_modulation)
275 *flags |= BCM43xx_TXHDRFLAG_RTSCTS_OFDM;
276 if (fallback_ofdm_modulation)
277 *flags |= BCM43xx_TXHDRFLAG_RTSCTSFALLBACK_OFDM;
278}
279
280void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
281 struct bcm43xx_txhdr *txhdr,
282 const unsigned char *fragment_data,
283 const unsigned int fragment_len,
284 const int is_first_fragment,
285 const u16 cookie)
286{
287 const struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
288 const struct ieee80211_hdr_4addr *wireless_header = (const struct ieee80211_hdr_4addr *)fragment_data;
289 const struct ieee80211_security *secinfo = &bcm->ieee->sec;
290 u8 bitrate;
291 u8 fallback_bitrate;
292 int ofdm_modulation;
293 int fallback_ofdm_modulation;
294 u16 plcp_fragment_len = fragment_len;
295 u16 flags = 0;
296 u16 control = 0;
297 u16 wsec_rate = 0;
298 u16 encrypt_frame;
299
300 /* Now construct the TX header. */
301 memset(txhdr, 0, sizeof(*txhdr));
302
303 bitrate = bcm->softmac->txrates.default_rate;
304 ofdm_modulation = !(ieee80211_is_cck_rate(bitrate));
305 fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
306 fallback_ofdm_modulation = !(ieee80211_is_cck_rate(fallback_bitrate));
307
308 /* Set Frame Control from 80211 header. */
309 txhdr->frame_control = wireless_header->frame_ctl;
310 /* Copy address1 from 80211 header. */
311 memcpy(txhdr->mac1, wireless_header->addr1, 6);
312 /* Set the fallback duration ID. */
313 txhdr->fallback_dur_id = bcm43xx_calc_duration_id((const struct ieee80211_hdr *)wireless_header,
314 fallback_bitrate);
315 /* Set the cookie (used as driver internal ID for the frame) */
316 txhdr->cookie = cpu_to_le16(cookie);
317
318 /* Hardware appends FCS. */
319 plcp_fragment_len += IEEE80211_FCS_LEN;
320
321 /* Hardware encryption. */
322 encrypt_frame = le16_to_cpup(&wireless_header->frame_ctl) & IEEE80211_FCTL_PROTECTED;
323 if (encrypt_frame && !bcm->ieee->host_encrypt) {
324 const struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)wireless_header;
325 memcpy(txhdr->wep_iv, hdr->payload, 4);
326 /* Hardware appends ICV. */
327 plcp_fragment_len += 4;
328
329 wsec_rate |= (bcm->key[secinfo->active_key].algorithm << BCM43xx_TXHDR_WSEC_ALGO_SHIFT)
330 & BCM43xx_TXHDR_WSEC_ALGO_MASK;
331 wsec_rate |= (secinfo->active_key << BCM43xx_TXHDR_WSEC_KEYINDEX_SHIFT)
332 & BCM43xx_TXHDR_WSEC_KEYINDEX_MASK;
333 }
334
335 /* Generate the PLCP header and the fallback PLCP header. */
336 bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->plcp),
337 plcp_fragment_len,
338 bitrate, ofdm_modulation);
339 bcm43xx_generate_plcp_hdr(&txhdr->fallback_plcp, plcp_fragment_len,
340 fallback_bitrate, fallback_ofdm_modulation);
341
342 /* Set the CONTROL field */
343 if (ofdm_modulation)
344 control |= BCM43xx_TXHDRCTL_OFDM;
345 if (bcm->short_preamble) //FIXME: could be the other way around, please test
346 control |= BCM43xx_TXHDRCTL_SHORT_PREAMBLE;
347 control |= (phy->antenna_diversity << BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT)
348 & BCM43xx_TXHDRCTL_ANTENNADIV_MASK;
349
350 /* Set the FLAGS field */
351 if (!is_multicast_ether_addr(wireless_header->addr1) &&
352 !is_broadcast_ether_addr(wireless_header->addr1))
353 flags |= BCM43xx_TXHDRFLAG_EXPECTACK;
354 if (1 /* FIXME: PS poll?? */)
355 flags |= 0x10; // FIXME: unknown meaning.
356 if (fallback_ofdm_modulation)
357 flags |= BCM43xx_TXHDRFLAG_FALLBACKOFDM;
358 if (is_first_fragment)
359 flags |= BCM43xx_TXHDRFLAG_FIRSTFRAGMENT;
360
361 /* Set WSEC/RATE field */
362 wsec_rate |= (txhdr->plcp.raw[0] << BCM43xx_TXHDR_RATE_SHIFT)
363 & BCM43xx_TXHDR_RATE_MASK;
364
365 /* Generate the RTS/CTS packet, if required. */
366 /* FIXME: We should first try with CTS-to-self,
367 * if we are on 80211g. If we get too many
368 * failures (hidden nodes), we should switch back to RTS/CTS.
369 */
370 if (0/*FIXME txctl->use_rts_cts*/) {
371 bcm43xx_generate_rts(phy, txhdr, &flags,
372 0/*FIXME txctl->rts_cts_rate*/,
373 wireless_header);
374 }
375
376 txhdr->flags = cpu_to_le16(flags);
377 txhdr->control = cpu_to_le16(control);
378 txhdr->wsec_rate = cpu_to_le16(wsec_rate);
379}
380
381static s8 bcm43xx_rssi_postprocess(struct bcm43xx_private *bcm,
382 u8 in_rssi, int ofdm,
383 int adjust_2053, int adjust_2050)
384{
385 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
386 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
387 s32 tmp;
388
389 switch (radio->version) {
390 case 0x2050:
391 if (ofdm) {
392 tmp = in_rssi;
393 if (tmp > 127)
394 tmp -= 256;
395 tmp *= 73;
396 tmp /= 64;
397 if (adjust_2050)
398 tmp += 25;
399 else
400 tmp -= 3;
401 } else {
402 if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
403 if (in_rssi > 63)
404 in_rssi = 63;
405 tmp = radio->nrssi_lt[in_rssi];
406 tmp = 31 - tmp;
407 tmp *= -131;
408 tmp /= 128;
409 tmp -= 57;
410 } else {
411 tmp = in_rssi;
412 tmp = 31 - tmp;
413 tmp *= -149;
414 tmp /= 128;
415 tmp -= 68;
416 }
417 if (phy->type == BCM43xx_PHYTYPE_G &&
418 adjust_2050)
419 tmp += 25;
420 }
421 break;
422 case 0x2060:
423 if (in_rssi > 127)
424 tmp = in_rssi - 256;
425 else
426 tmp = in_rssi;
427 break;
428 default:
429 tmp = in_rssi;
430 tmp -= 11;
431 tmp *= 103;
432 tmp /= 64;
433 if (adjust_2053)
434 tmp -= 109;
435 else
436 tmp -= 83;
437 }
438
439 return (s8)tmp;
440}
441
442//TODO
443#if 0
444static s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_private *bcm,
445 u8 in_rssi)
446{
447 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
448 s8 ret;
449
450 if (phy->type == BCM43xx_PHYTYPE_A) {
451 //TODO: Incomplete specs.
452 ret = 0;
453 } else
454 ret = bcm43xx_rssi_postprocess(bcm, in_rssi, 0, 1, 1);
455
456 return ret;
457}
458#endif
459
460int bcm43xx_rx(struct bcm43xx_private *bcm,
461 struct sk_buff *skb,
462 struct bcm43xx_rxhdr *rxhdr)
463{
464 struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
465 struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
466 struct bcm43xx_plcp_hdr4 *plcp;
467 struct ieee80211_rx_stats stats;
468 struct ieee80211_hdr_4addr *wlhdr;
469 u16 frame_ctl;
470 int is_packet_for_us = 0;
471 int err = -EINVAL;
472 const u16 rxflags1 = le16_to_cpu(rxhdr->flags1);
473 const u16 rxflags2 = le16_to_cpu(rxhdr->flags2);
474 const u16 rxflags3 = le16_to_cpu(rxhdr->flags3);
475 const int is_ofdm = !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_OFDM);
476
477 if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME) {
478 plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data + 2);
479 /* Skip two unknown bytes and the PLCP header. */
480 skb_pull(skb, 2 + sizeof(struct bcm43xx_plcp_hdr6));
481 } else {
482 plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data);
483 /* Skip the PLCP header. */
484 skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6));
485 }
486 /* The SKB contains the PAYLOAD (wireless header + data)
487 * at this point. The FCS at the end is stripped.
488 */
489
490 memset(&stats, 0, sizeof(stats));
491 stats.mac_time = le16_to_cpu(rxhdr->mactime);
492 stats.rssi = bcm43xx_rssi_postprocess(bcm, rxhdr->rssi, is_ofdm,
493 !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_2053RSSIADJ),
494 !!(rxflags3 & BCM43xx_RXHDR_FLAGS3_2050RSSIADJ));
495 stats.signal = rxhdr->signal_quality; //FIXME
496//TODO stats.noise =
497 if (is_ofdm)
498 stats.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
499 else
500 stats.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
501//printk("RX ofdm %d, rate == %u\n", is_ofdm, stats.rate);
502 stats.received_channel = radio->channel;
503//TODO stats.control =
504 stats.mask = IEEE80211_STATMASK_SIGNAL |
505//TODO IEEE80211_STATMASK_NOISE |
506 IEEE80211_STATMASK_RATE |
507 IEEE80211_STATMASK_RSSI;
508 if (phy->type == BCM43xx_PHYTYPE_A)
509 stats.freq = IEEE80211_52GHZ_BAND;
510 else
511 stats.freq = IEEE80211_24GHZ_BAND;
512 stats.len = skb->len;
513
514 bcm->stats.last_rx = jiffies;
515 if (bcm->ieee->iw_mode == IW_MODE_MONITOR) {
516 err = ieee80211_rx(bcm->ieee, skb, &stats);
517 return (err == 0) ? -EINVAL : 0;
518 }
519
520 wlhdr = (struct ieee80211_hdr_4addr *)(skb->data);
521
522 switch (bcm->ieee->iw_mode) {
523 case IW_MODE_ADHOC:
524 if (memcmp(wlhdr->addr1, bcm->net_dev->dev_addr, ETH_ALEN) == 0 ||
525 memcmp(wlhdr->addr3, bcm->ieee->bssid, ETH_ALEN) == 0 ||
526 is_broadcast_ether_addr(wlhdr->addr1) ||
527 is_multicast_ether_addr(wlhdr->addr1) ||
528 bcm->net_dev->flags & IFF_PROMISC)
529 is_packet_for_us = 1;
530 break;
531 case IW_MODE_INFRA:
532 default:
533 /* When receiving multicast or broadcast packets, filter out
534 the packets we send ourself; we shouldn't see those */
535 if (memcmp(wlhdr->addr3, bcm->ieee->bssid, ETH_ALEN) == 0 ||
536 memcmp(wlhdr->addr1, bcm->net_dev->dev_addr, ETH_ALEN) == 0 ||
537 (memcmp(wlhdr->addr3, bcm->net_dev->dev_addr, ETH_ALEN) &&
538 (is_broadcast_ether_addr(wlhdr->addr1) ||
539 is_multicast_ether_addr(wlhdr->addr1) ||
540 bcm->net_dev->flags & IFF_PROMISC)))
541 is_packet_for_us = 1;
542 break;
543 }
544
545 frame_ctl = le16_to_cpu(wlhdr->frame_ctl);
546 if ((frame_ctl & IEEE80211_FCTL_PROTECTED) && !bcm->ieee->host_decrypt) {
547 frame_ctl &= ~IEEE80211_FCTL_PROTECTED;
548 wlhdr->frame_ctl = cpu_to_le16(frame_ctl);
549 /* trim IV and ICV */
550 /* FIXME: this must be done only for WEP encrypted packets */
551 if (skb->len < 32) {
552 dprintkl(KERN_ERR PFX "RX packet dropped (PROTECTED flag "
553 "set and length < 32)\n");
554 return -EINVAL;
555 } else {
556 memmove(skb->data + 4, skb->data, 24);
557 skb_pull(skb, 4);
558 skb_trim(skb, skb->len - 4);
559 stats.len -= 8;
560 }
561 wlhdr = (struct ieee80211_hdr_4addr *)(skb->data);
562 }
563
564 switch (WLAN_FC_GET_TYPE(frame_ctl)) {
565 case IEEE80211_FTYPE_MGMT:
566 ieee80211_rx_mgt(bcm->ieee, wlhdr, &stats);
567 break;
568 case IEEE80211_FTYPE_DATA:
569 if (is_packet_for_us) {
570 err = ieee80211_rx(bcm->ieee, skb, &stats);
571 err = (err == 0) ? -EINVAL : 0;
572 }
573 break;
574 case IEEE80211_FTYPE_CTL:
575 break;
576 default:
577 assert(0);
578 return -EINVAL;
579 }
580
581 return err;
582}
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h
new file mode 100644
index 000000000000..2aed19e35c77
--- /dev/null
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_xmit.h
@@ -0,0 +1,156 @@
1#ifndef BCM43xx_XMIT_H_
2#define BCM43xx_XMIT_H_
3
4#include "bcm43xx_main.h"
5
6
7#define _bcm43xx_declare_plcp_hdr(size) \
8 struct bcm43xx_plcp_hdr##size { \
9 union { \
10 __le32 data; \
11 __u8 raw[size]; \
12 } __attribute__((__packed__)); \
13 } __attribute__((__packed__))
14
15/* struct bcm43xx_plcp_hdr4 */
16_bcm43xx_declare_plcp_hdr(4);
17/* struct bcm43xx_plcp_hdr6 */
18_bcm43xx_declare_plcp_hdr(6);
19
20#undef _bcm43xx_declare_plcp_hdr
21
22/* Device specific TX header. To be prepended to TX frames. */
23struct bcm43xx_txhdr {
24 union {
25 struct {
26 __le16 flags;
27 __le16 wsec_rate;
28 __le16 frame_control;
29 u16 unknown_zeroed_0;
30 __le16 control;
31 u8 wep_iv[10];
32 u8 unknown_wsec_tkip_data[3]; //FIXME
33 PAD_BYTES(3);
34 u8 mac1[6];
35 u16 unknown_zeroed_1;
36 struct bcm43xx_plcp_hdr4 rts_cts_fallback_plcp;
37 __le16 rts_cts_dur_fallback;
38 struct bcm43xx_plcp_hdr4 fallback_plcp;
39 __le16 fallback_dur_id;
40 PAD_BYTES(2);
41 __le16 cookie;
42 __le16 unknown_scb_stuff; //FIXME
43 struct bcm43xx_plcp_hdr6 rts_cts_plcp;
44 __le16 rts_cts_frame_control;
45 __le16 rts_cts_dur;
46 u8 rts_cts_mac1[6];
47 u8 rts_cts_mac2[6];
48 PAD_BYTES(2);
49 struct bcm43xx_plcp_hdr6 plcp;
50 } __attribute__((__packed__));
51 u8 raw[82];
52 } __attribute__((__packed__));
53} __attribute__((__packed__));
54
55/* Values/Masks for the device TX header */
56#define BCM43xx_TXHDRFLAG_EXPECTACK 0x0001
57#define BCM43xx_TXHDRFLAG_RTSCTS 0x0002
58#define BCM43xx_TXHDRFLAG_RTS 0x0004
59#define BCM43xx_TXHDRFLAG_FIRSTFRAGMENT 0x0008
60#define BCM43xx_TXHDRFLAG_DESTPSMODE 0x0020
61#define BCM43xx_TXHDRFLAG_RTSCTS_OFDM 0x0080
62#define BCM43xx_TXHDRFLAG_FALLBACKOFDM 0x0100
63#define BCM43xx_TXHDRFLAG_RTSCTSFALLBACK_OFDM 0x0200
64#define BCM43xx_TXHDRFLAG_CTS 0x0400
65#define BCM43xx_TXHDRFLAG_FRAMEBURST 0x0800
66
67#define BCM43xx_TXHDRCTL_OFDM 0x0001
68#define BCM43xx_TXHDRCTL_SHORT_PREAMBLE 0x0010
69#define BCM43xx_TXHDRCTL_ANTENNADIV_MASK 0x0030
70#define BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT 8
71
72#define BCM43xx_TXHDR_RATE_MASK 0x0F00
73#define BCM43xx_TXHDR_RATE_SHIFT 8
74#define BCM43xx_TXHDR_RTSRATE_MASK 0xF000
75#define BCM43xx_TXHDR_RTSRATE_SHIFT 12
76#define BCM43xx_TXHDR_WSEC_KEYINDEX_MASK 0x00F0
77#define BCM43xx_TXHDR_WSEC_KEYINDEX_SHIFT 4
78#define BCM43xx_TXHDR_WSEC_ALGO_MASK 0x0003
79#define BCM43xx_TXHDR_WSEC_ALGO_SHIFT 0
80
81void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
82 struct bcm43xx_txhdr *txhdr,
83 const unsigned char *fragment_data,
84 const unsigned int fragment_len,
85 const int is_first_fragment,
86 const u16 cookie);
87
88/* RX header as received from the hardware. */
89struct bcm43xx_rxhdr {
90 /* Frame Length. Must be generated explicitely in PIO mode. */
91 __le16 frame_length;
92 PAD_BYTES(2);
93 /* Flags field 1 */
94 __le16 flags1;
95 u8 rssi;
96 u8 signal_quality;
97 PAD_BYTES(2);
98 /* Flags field 3 */
99 __le16 flags3;
100 /* Flags field 2 */
101 __le16 flags2;
102 /* Lower 16bits of the TSF at the time the frame started. */
103 __le16 mactime;
104 PAD_BYTES(14);
105} __attribute__((__packed__));
106
107#define BCM43xx_RXHDR_FLAGS1_OFDM (1 << 0)
108/*#define BCM43xx_RXHDR_FLAGS1_SIGNAL??? (1 << 3) FIXME */
109#define BCM43xx_RXHDR_FLAGS1_SHORTPREAMBLE (1 << 7)
110#define BCM43xx_RXHDR_FLAGS1_2053RSSIADJ (1 << 14)
111
112#define BCM43xx_RXHDR_FLAGS2_INVALIDFRAME (1 << 0)
113#define BCM43xx_RXHDR_FLAGS2_TYPE2FRAME (1 << 2)
114/*FIXME: WEP related flags */
115
116#define BCM43xx_RXHDR_FLAGS3_2050RSSIADJ (1 << 10)
117
118/* Transmit Status as received from the hardware. */
119struct bcm43xx_hwxmitstatus {
120 PAD_BYTES(4);
121 __le16 cookie;
122 u8 flags;
123 u8 cnt1:4,
124 cnt2:4;
125 PAD_BYTES(2);
126 __le16 seq;
127 __le16 unknown; //FIXME
128} __attribute__((__packed__));
129
130/* Transmit Status in CPU byteorder. */
131struct bcm43xx_xmitstatus {
132 u16 cookie;
133 u8 flags;
134 u8 cnt1:4,
135 cnt2:4;
136 u16 seq;
137 u16 unknown; //FIXME
138};
139
140#define BCM43xx_TXSTAT_FLAG_ACK 0x01
141//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x02
142//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x04
143//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x08
144//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x10
145#define BCM43xx_TXSTAT_FLAG_IGNORE 0x20
146//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x40
147//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x80
148
149u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate);
150u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate);
151
152int bcm43xx_rx(struct bcm43xx_private *bcm,
153 struct sk_buff *skb,
154 struct bcm43xx_rxhdr *rxhdr);
155
156#endif /* BCM43xx_XMIT_H_ */
diff --git a/drivers/net/wireless/hostap/hostap_80211.h b/drivers/net/wireless/hostap/hostap_80211.h
index 1fc72fe511e9..cc1ee7f4f5f8 100644
--- a/drivers/net/wireless/hostap/hostap_80211.h
+++ b/drivers/net/wireless/hostap/hostap_80211.h
@@ -92,8 +92,6 @@ void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
92void hostap_dump_tx_80211(const char *name, struct sk_buff *skb); 92void hostap_dump_tx_80211(const char *name, struct sk_buff *skb);
93int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev); 93int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev);
94int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev); 94int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev);
95struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
96 struct ieee80211_crypt_data *crypt);
97int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev); 95int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
98 96
99#endif /* HOSTAP_80211_H */ 97#endif /* HOSTAP_80211_H */
diff --git a/drivers/net/wireless/hostap/hostap_80211_tx.c b/drivers/net/wireless/hostap/hostap_80211_tx.c
index 4a85e63906f1..06a5214145e3 100644
--- a/drivers/net/wireless/hostap/hostap_80211_tx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_tx.c
@@ -299,8 +299,8 @@ int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
299 299
300 300
301/* Called only from software IRQ */ 301/* Called only from software IRQ */
302struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb, 302static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
303 struct ieee80211_crypt_data *crypt) 303 struct ieee80211_crypt_data *crypt)
304{ 304{
305 struct hostap_interface *iface; 305 struct hostap_interface *iface;
306 local_info_t *local; 306 local_info_t *local;
@@ -317,7 +317,7 @@ struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
317 } 317 }
318 318
319 if (local->tkip_countermeasures && 319 if (local->tkip_countermeasures &&
320 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) { 320 strcmp(crypt->ops->name, "TKIP") == 0) {
321 hdr = (struct ieee80211_hdr_4addr *) skb->data; 321 hdr = (struct ieee80211_hdr_4addr *) skb->data;
322 if (net_ratelimit()) { 322 if (net_ratelimit()) {
323 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped " 323 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
@@ -469,7 +469,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
469 } 469 }
470 470
471 if (local->ieee_802_1x && meta->ethertype == ETH_P_PAE && tx.crypt && 471 if (local->ieee_802_1x && meta->ethertype == ETH_P_PAE && tx.crypt &&
472 !(fc & IEEE80211_FCTL_VERS)) { 472 !(fc & IEEE80211_FCTL_PROTECTED)) {
473 no_encrypt = 1; 473 no_encrypt = 1;
474 PDEBUG(DEBUG_EXTRA2, "%s: TX: IEEE 802.1X - passing " 474 PDEBUG(DEBUG_EXTRA2, "%s: TX: IEEE 802.1X - passing "
475 "unencrypted EAPOL frame\n", dev->name); 475 "unencrypted EAPOL frame\n", dev->name);
@@ -535,5 +535,4 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
535 535
536 536
537EXPORT_SYMBOL(hostap_dump_tx_80211); 537EXPORT_SYMBOL(hostap_dump_tx_80211);
538EXPORT_SYMBOL(hostap_tx_encrypt);
539EXPORT_SYMBOL(hostap_master_start_xmit); 538EXPORT_SYMBOL(hostap_master_start_xmit);
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index d335b250923a..55bed923fbe9 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -42,7 +42,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
42/* struct local_info::hw_priv */ 42/* struct local_info::hw_priv */
43struct hostap_cs_priv { 43struct hostap_cs_priv {
44 dev_node_t node; 44 dev_node_t node;
45 dev_link_t *link; 45 struct pcmcia_device *link;
46 int sandisk_connectplus; 46 int sandisk_connectplus;
47}; 47};
48 48
@@ -204,15 +204,13 @@ static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
204 204
205static void prism2_detach(struct pcmcia_device *p_dev); 205static void prism2_detach(struct pcmcia_device *p_dev);
206static void prism2_release(u_long arg); 206static void prism2_release(u_long arg);
207static int prism2_config(dev_link_t *link); 207static int prism2_config(struct pcmcia_device *link);
208 208
209 209
210static int prism2_pccard_card_present(local_info_t *local) 210static int prism2_pccard_card_present(local_info_t *local)
211{ 211{
212 struct hostap_cs_priv *hw_priv = local->hw_priv; 212 struct hostap_cs_priv *hw_priv = local->hw_priv;
213 if (hw_priv != NULL && hw_priv->link != NULL && 213 if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link))
214 ((hw_priv->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
215 (DEV_PRESENT | DEV_CONFIG)))
216 return 1; 214 return 1;
217 return 0; 215 return 0;
218} 216}
@@ -237,7 +235,7 @@ static void sandisk_set_iobase(local_info_t *local)
237 reg.Action = CS_WRITE; 235 reg.Action = CS_WRITE;
238 reg.Offset = 0x10; /* 0x3f0 IO base 1 */ 236 reg.Offset = 0x10; /* 0x3f0 IO base 1 */
239 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff; 237 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
240 res = pcmcia_access_configuration_register(hw_priv->link->handle, 238 res = pcmcia_access_configuration_register(hw_priv->link,
241 &reg); 239 &reg);
242 if (res != CS_SUCCESS) { 240 if (res != CS_SUCCESS) {
243 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -" 241 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
@@ -249,7 +247,7 @@ static void sandisk_set_iobase(local_info_t *local)
249 reg.Action = CS_WRITE; 247 reg.Action = CS_WRITE;
250 reg.Offset = 0x12; /* 0x3f2 IO base 2 */ 248 reg.Offset = 0x12; /* 0x3f2 IO base 2 */
251 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8; 249 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
252 res = pcmcia_access_configuration_register(hw_priv->link->handle, 250 res = pcmcia_access_configuration_register(hw_priv->link,
253 &reg); 251 &reg);
254 if (res != CS_SUCCESS) { 252 if (res != CS_SUCCESS) {
255 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -" 253 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
@@ -301,9 +299,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
301 tuple.TupleData = buf; 299 tuple.TupleData = buf;
302 tuple.TupleDataMax = sizeof(buf); 300 tuple.TupleDataMax = sizeof(buf);
303 tuple.TupleOffset = 0; 301 tuple.TupleOffset = 0;
304 if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) || 302 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
305 pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) || 303 pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
306 pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) || 304 pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
307 parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) { 305 parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) {
308 /* No SanDisk manfid found */ 306 /* No SanDisk manfid found */
309 ret = -ENODEV; 307 ret = -ENODEV;
@@ -311,9 +309,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
311 } 309 }
312 310
313 tuple.DesiredTuple = CISTPL_LONGLINK_MFC; 311 tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
314 if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) || 312 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
315 pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) || 313 pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
316 pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) || 314 pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
317 parse->longlink_mfc.nfn < 2) { 315 parse->longlink_mfc.nfn < 2) {
318 /* No multi-function links found */ 316 /* No multi-function links found */
319 ret = -ENODEV; 317 ret = -ENODEV;
@@ -328,7 +326,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
328 reg.Action = CS_WRITE; 326 reg.Action = CS_WRITE;
329 reg.Offset = CISREG_COR; 327 reg.Offset = CISREG_COR;
330 reg.Value = COR_SOFT_RESET; 328 reg.Value = COR_SOFT_RESET;
331 res = pcmcia_access_configuration_register(hw_priv->link->handle, 329 res = pcmcia_access_configuration_register(hw_priv->link,
332 &reg); 330 &reg);
333 if (res != CS_SUCCESS) { 331 if (res != CS_SUCCESS) {
334 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", 332 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
@@ -345,7 +343,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
345 * will be enabled during the first cor_sreset call. 343 * will be enabled during the first cor_sreset call.
346 */ 344 */
347 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA; 345 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
348 res = pcmcia_access_configuration_register(hw_priv->link->handle, 346 res = pcmcia_access_configuration_register(hw_priv->link,
349 &reg); 347 &reg);
350 if (res != CS_SUCCESS) { 348 if (res != CS_SUCCESS) {
351 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", 349 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
@@ -380,7 +378,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
380 reg.Action = CS_READ; 378 reg.Action = CS_READ;
381 reg.Offset = CISREG_COR; 379 reg.Offset = CISREG_COR;
382 reg.Value = 0; 380 reg.Value = 0;
383 res = pcmcia_access_configuration_register(hw_priv->link->handle, 381 res = pcmcia_access_configuration_register(hw_priv->link,
384 &reg); 382 &reg);
385 if (res != CS_SUCCESS) { 383 if (res != CS_SUCCESS) {
386 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n", 384 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
@@ -392,7 +390,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
392 390
393 reg.Action = CS_WRITE; 391 reg.Action = CS_WRITE;
394 reg.Value |= COR_SOFT_RESET; 392 reg.Value |= COR_SOFT_RESET;
395 res = pcmcia_access_configuration_register(hw_priv->link->handle, 393 res = pcmcia_access_configuration_register(hw_priv->link,
396 &reg); 394 &reg);
397 if (res != CS_SUCCESS) { 395 if (res != CS_SUCCESS) {
398 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n", 396 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
@@ -405,7 +403,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
405 reg.Value &= ~COR_SOFT_RESET; 403 reg.Value &= ~COR_SOFT_RESET;
406 if (hw_priv->sandisk_connectplus) 404 if (hw_priv->sandisk_connectplus)
407 reg.Value |= COR_IREQ_ENA; 405 reg.Value |= COR_IREQ_ENA;
408 res = pcmcia_access_configuration_register(hw_priv->link->handle, 406 res = pcmcia_access_configuration_register(hw_priv->link,
409 &reg); 407 &reg);
410 if (res != CS_SUCCESS) { 408 if (res != CS_SUCCESS) {
411 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n", 409 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
@@ -439,7 +437,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
439 reg.Action = CS_READ; 437 reg.Action = CS_READ;
440 reg.Offset = CISREG_COR; 438 reg.Offset = CISREG_COR;
441 reg.Value = 0; 439 reg.Value = 0;
442 res = pcmcia_access_configuration_register(hw_priv->link->handle, 440 res = pcmcia_access_configuration_register(hw_priv->link,
443 &reg); 441 &reg);
444 if (res != CS_SUCCESS) { 442 if (res != CS_SUCCESS) {
445 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 " 443 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
@@ -452,7 +450,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
452 450
453 reg.Action = CS_WRITE; 451 reg.Action = CS_WRITE;
454 reg.Value |= COR_SOFT_RESET; 452 reg.Value |= COR_SOFT_RESET;
455 res = pcmcia_access_configuration_register(hw_priv->link->handle, 453 res = pcmcia_access_configuration_register(hw_priv->link,
456 &reg); 454 &reg);
457 if (res != CS_SUCCESS) { 455 if (res != CS_SUCCESS) {
458 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 " 456 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
@@ -466,7 +464,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
466 reg.Action = CS_WRITE; 464 reg.Action = CS_WRITE;
467 reg.Value = hcr; 465 reg.Value = hcr;
468 reg.Offset = CISREG_CCSR; 466 reg.Offset = CISREG_CCSR;
469 res = pcmcia_access_configuration_register(hw_priv->link->handle, 467 res = pcmcia_access_configuration_register(hw_priv->link,
470 &reg); 468 &reg);
471 if (res != CS_SUCCESS) { 469 if (res != CS_SUCCESS) {
472 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 " 470 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
@@ -478,7 +476,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
478 reg.Action = CS_WRITE; 476 reg.Action = CS_WRITE;
479 reg.Offset = CISREG_COR; 477 reg.Offset = CISREG_COR;
480 reg.Value = old_cor & ~COR_SOFT_RESET; 478 reg.Value = old_cor & ~COR_SOFT_RESET;
481 res = pcmcia_access_configuration_register(hw_priv->link->handle, 479 res = pcmcia_access_configuration_register(hw_priv->link,
482 &reg); 480 &reg);
483 if (res != CS_SUCCESS) { 481 if (res != CS_SUCCESS) {
484 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 " 482 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
@@ -501,40 +499,27 @@ static struct prism2_helper_functions prism2_pccard_funcs =
501 499
502/* allocate local data and register with CardServices 500/* allocate local data and register with CardServices
503 * initialize dev_link structure, but do not configure the card yet */ 501 * initialize dev_link structure, but do not configure the card yet */
504static int prism2_attach(struct pcmcia_device *p_dev) 502static int hostap_cs_probe(struct pcmcia_device *p_dev)
505{ 503{
506 dev_link_t *link; 504 int ret;
507
508 link = kmalloc(sizeof(dev_link_t), GFP_KERNEL);
509 if (link == NULL)
510 return -ENOMEM;
511
512 memset(link, 0, sizeof(dev_link_t));
513 505
514 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info); 506 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
515 link->conf.Vcc = 33; 507 p_dev->conf.IntType = INT_MEMORY_AND_IO;
516 link->conf.IntType = INT_MEMORY_AND_IO;
517
518 link->handle = p_dev;
519 p_dev->instance = link;
520 508
521 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 509 ret = prism2_config(p_dev);
522 if (prism2_config(link)) 510 if (ret) {
523 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); 511 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
512 }
524 513
525 return 0; 514 return ret;
526} 515}
527 516
528 517
529static void prism2_detach(struct pcmcia_device *p_dev) 518static void prism2_detach(struct pcmcia_device *link)
530{ 519{
531 dev_link_t *link = dev_to_instance(p_dev);
532
533 PDEBUG(DEBUG_FLOW, "prism2_detach\n"); 520 PDEBUG(DEBUG_FLOW, "prism2_detach\n");
534 521
535 if (link->state & DEV_CONFIG) { 522 prism2_release((u_long)link);
536 prism2_release((u_long)link);
537 }
538 523
539 /* release net devices */ 524 /* release net devices */
540 if (link->priv) { 525 if (link->priv) {
@@ -547,7 +532,6 @@ static void prism2_detach(struct pcmcia_device *p_dev)
547 prism2_free_local_data(dev); 532 prism2_free_local_data(dev);
548 kfree(hw_priv); 533 kfree(hw_priv);
549 } 534 }
550 kfree(link);
551} 535}
552 536
553 537
@@ -558,7 +542,7 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
558do { int ret = (retf); \ 542do { int ret = (retf); \
559if (ret != 0) { \ 543if (ret != 0) { \
560 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \ 544 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
561 cs_error(link->handle, fn, ret); \ 545 cs_error(link, fn, ret); \
562 goto next_entry; \ 546 goto next_entry; \
563} \ 547} \
564} while (0) 548} while (0)
@@ -566,7 +550,7 @@ if (ret != 0) { \
566 550
567/* run after a CARD_INSERTION event is received to configure the PCMCIA 551/* run after a CARD_INSERTION event is received to configure the PCMCIA
568 * socket and make the device available to the system */ 552 * socket and make the device available to the system */
569static int prism2_config(dev_link_t *link) 553static int prism2_config(struct pcmcia_device *link)
570{ 554{
571 struct net_device *dev; 555 struct net_device *dev;
572 struct hostap_interface *iface; 556 struct hostap_interface *iface;
@@ -595,27 +579,24 @@ static int prism2_config(dev_link_t *link)
595 tuple.TupleData = buf; 579 tuple.TupleData = buf;
596 tuple.TupleDataMax = sizeof(buf); 580 tuple.TupleDataMax = sizeof(buf);
597 tuple.TupleOffset = 0; 581 tuple.TupleOffset = 0;
598 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); 582 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
599 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple)); 583 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
600 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse)); 584 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, parse));
601 link->conf.ConfigBase = parse->config.base; 585 link->conf.ConfigBase = parse->config.base;
602 link->conf.Present = parse->config.rmask[0]; 586 link->conf.Present = parse->config.rmask[0];
603 587
604 CS_CHECK(GetConfigurationInfo, 588 CS_CHECK(GetConfigurationInfo,
605 pcmcia_get_configuration_info(link->handle, &conf)); 589 pcmcia_get_configuration_info(link, &conf));
606 PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info,
607 ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc);
608 link->conf.Vcc = conf.Vcc;
609 590
610 /* Look for an appropriate configuration table entry in the CIS */ 591 /* Look for an appropriate configuration table entry in the CIS */
611 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 592 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
612 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); 593 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
613 for (;;) { 594 for (;;) {
614 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry); 595 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
615 CFG_CHECK2(GetTupleData, 596 CFG_CHECK2(GetTupleData,
616 pcmcia_get_tuple_data(link->handle, &tuple)); 597 pcmcia_get_tuple_data(link, &tuple));
617 CFG_CHECK2(ParseTuple, 598 CFG_CHECK2(ParseTuple,
618 pcmcia_parse_tuple(link->handle, &tuple, parse)); 599 pcmcia_parse_tuple(link, &tuple, parse));
619 600
620 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 601 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
621 dflt = *cfg; 602 dflt = *cfg;
@@ -650,10 +631,10 @@ static int prism2_config(dev_link_t *link)
650 } 631 }
651 632
652 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 633 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
653 link->conf.Vpp1 = link->conf.Vpp2 = 634 link->conf.Vpp =
654 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 635 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
655 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 636 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
656 link->conf.Vpp1 = link->conf.Vpp2 = 637 link->conf.Vpp =
657 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 638 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
658 639
659 /* Do we need to allocate an interrupt? */ 640 /* Do we need to allocate an interrupt? */
@@ -695,19 +676,19 @@ static int prism2_config(dev_link_t *link)
695 676
696 /* This reserves IO space but doesn't actually enable it */ 677 /* This reserves IO space but doesn't actually enable it */
697 CFG_CHECK2(RequestIO, 678 CFG_CHECK2(RequestIO,
698 pcmcia_request_io(link->handle, &link->io)); 679 pcmcia_request_io(link, &link->io));
699 680
700 /* This configuration table entry is OK */ 681 /* This configuration table entry is OK */
701 break; 682 break;
702 683
703 next_entry: 684 next_entry:
704 CS_CHECK(GetNextTuple, 685 CS_CHECK(GetNextTuple,
705 pcmcia_get_next_tuple(link->handle, &tuple)); 686 pcmcia_get_next_tuple(link, &tuple));
706 } 687 }
707 688
708 /* Need to allocate net_device before requesting IRQ handler */ 689 /* Need to allocate net_device before requesting IRQ handler */
709 dev = prism2_init_local_data(&prism2_pccard_funcs, 0, 690 dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
710 &handle_to_dev(link->handle)); 691 &handle_to_dev(link));
711 if (dev == NULL) 692 if (dev == NULL)
712 goto failed; 693 goto failed;
713 link->priv = dev; 694 link->priv = dev;
@@ -717,7 +698,7 @@ static int prism2_config(dev_link_t *link)
717 local->hw_priv = hw_priv; 698 local->hw_priv = hw_priv;
718 hw_priv->link = link; 699 hw_priv->link = link;
719 strcpy(hw_priv->node.dev_name, dev->name); 700 strcpy(hw_priv->node.dev_name, dev->name);
720 link->dev = &hw_priv->node; 701 link->dev_node = &hw_priv->node;
721 702
722 /* 703 /*
723 * Allocate an interrupt line. Note that this does not assign a 704 * Allocate an interrupt line. Note that this does not assign a
@@ -730,7 +711,7 @@ static int prism2_config(dev_link_t *link)
730 link->irq.Handler = prism2_interrupt; 711 link->irq.Handler = prism2_interrupt;
731 link->irq.Instance = dev; 712 link->irq.Instance = dev;
732 CS_CHECK(RequestIRQ, 713 CS_CHECK(RequestIRQ,
733 pcmcia_request_irq(link->handle, &link->irq)); 714 pcmcia_request_irq(link, &link->irq));
734 } 715 }
735 716
736 /* 717 /*
@@ -739,18 +720,17 @@ static int prism2_config(dev_link_t *link)
739 * card and host interface into "Memory and IO" mode. 720 * card and host interface into "Memory and IO" mode.
740 */ 721 */
741 CS_CHECK(RequestConfiguration, 722 CS_CHECK(RequestConfiguration,
742 pcmcia_request_configuration(link->handle, &link->conf)); 723 pcmcia_request_configuration(link, &link->conf));
743 724
744 dev->irq = link->irq.AssignedIRQ; 725 dev->irq = link->irq.AssignedIRQ;
745 dev->base_addr = link->io.BasePort1; 726 dev->base_addr = link->io.BasePort1;
746 727
747 /* Finally, report what we've done */ 728 /* Finally, report what we've done */
748 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 729 printk(KERN_INFO "%s: index 0x%02x: ",
749 dev_info, link->conf.ConfigIndex, 730 dev_info, link->conf.ConfigIndex);
750 link->conf.Vcc / 10, link->conf.Vcc % 10); 731 if (link->conf.Vpp)
751 if (link->conf.Vpp1) 732 printk(", Vpp %d.%d", link->conf.Vpp / 10,
752 printk(", Vpp %d.%d", link->conf.Vpp1 / 10, 733 link->conf.Vpp % 10);
753 link->conf.Vpp1 % 10);
754 if (link->conf.Attributes & CONF_ENABLE_IRQ) 734 if (link->conf.Attributes & CONF_ENABLE_IRQ)
755 printk(", irq %d", link->irq.AssignedIRQ); 735 printk(", irq %d", link->irq.AssignedIRQ);
756 if (link->io.NumPorts1) 736 if (link->io.NumPorts1)
@@ -761,9 +741,6 @@ static int prism2_config(dev_link_t *link)
761 link->io.BasePort2+link->io.NumPorts2-1); 741 link->io.BasePort2+link->io.NumPorts2-1);
762 printk("\n"); 742 printk("\n");
763 743
764 link->state |= DEV_CONFIG;
765 link->state &= ~DEV_CONFIG_PENDING;
766
767 local->shutdown = 0; 744 local->shutdown = 0;
768 745
769 sandisk_enable_wireless(dev); 746 sandisk_enable_wireless(dev);
@@ -778,7 +755,7 @@ static int prism2_config(dev_link_t *link)
778 return ret; 755 return ret;
779 756
780 cs_failed: 757 cs_failed:
781 cs_error(link->handle, last_fn, last_ret); 758 cs_error(link, last_fn, last_ret);
782 759
783 failed: 760 failed:
784 kfree(parse); 761 kfree(parse);
@@ -790,7 +767,7 @@ static int prism2_config(dev_link_t *link)
790 767
791static void prism2_release(u_long arg) 768static void prism2_release(u_long arg)
792{ 769{
793 dev_link_t *link = (dev_link_t *)arg; 770 struct pcmcia_device *link = (struct pcmcia_device *)arg;
794 771
795 PDEBUG(DEBUG_FLOW, "prism2_release\n"); 772 PDEBUG(DEBUG_FLOW, "prism2_release\n");
796 773
@@ -799,71 +776,54 @@ static void prism2_release(u_long arg)
799 struct hostap_interface *iface; 776 struct hostap_interface *iface;
800 777
801 iface = netdev_priv(dev); 778 iface = netdev_priv(dev);
802 if (link->state & DEV_CONFIG) 779 prism2_hw_shutdown(dev, 0);
803 prism2_hw_shutdown(dev, 0);
804 iface->local->shutdown = 1; 780 iface->local->shutdown = 1;
805 } 781 }
806 782
807 if (link->win) 783 pcmcia_disable_device(link);
808 pcmcia_release_window(link->win);
809 pcmcia_release_configuration(link->handle);
810 if (link->io.NumPorts1)
811 pcmcia_release_io(link->handle, &link->io);
812 if (link->irq.AssignedIRQ)
813 pcmcia_release_irq(link->handle, &link->irq);
814
815 link->state &= ~DEV_CONFIG;
816
817 PDEBUG(DEBUG_FLOW, "release - done\n"); 784 PDEBUG(DEBUG_FLOW, "release - done\n");
818} 785}
819 786
820static int hostap_cs_suspend(struct pcmcia_device *p_dev) 787static int hostap_cs_suspend(struct pcmcia_device *link)
821{ 788{
822 dev_link_t *link = dev_to_instance(p_dev);
823 struct net_device *dev = (struct net_device *) link->priv; 789 struct net_device *dev = (struct net_device *) link->priv;
824 int dev_open = 0; 790 int dev_open = 0;
791 struct hostap_interface *iface = NULL;
825 792
826 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); 793 if (dev)
827 794 iface = netdev_priv(dev);
828 link->state |= DEV_SUSPEND;
829 795
830 if (link->state & DEV_CONFIG) { 796 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
831 struct hostap_interface *iface = netdev_priv(dev); 797 if (iface && iface->local)
832 if (iface && iface->local) 798 dev_open = iface->local->num_dev_open > 0;
833 dev_open = iface->local->num_dev_open > 0; 799 if (dev_open) {
834 if (dev_open) { 800 netif_stop_queue(dev);
835 netif_stop_queue(dev); 801 netif_device_detach(dev);
836 netif_device_detach(dev);
837 }
838 prism2_suspend(dev);
839 pcmcia_release_configuration(link->handle);
840 } 802 }
803 prism2_suspend(dev);
841 804
842 return 0; 805 return 0;
843} 806}
844 807
845static int hostap_cs_resume(struct pcmcia_device *p_dev) 808static int hostap_cs_resume(struct pcmcia_device *link)
846{ 809{
847 dev_link_t *link = dev_to_instance(p_dev);
848 struct net_device *dev = (struct net_device *) link->priv; 810 struct net_device *dev = (struct net_device *) link->priv;
849 int dev_open = 0; 811 int dev_open = 0;
812 struct hostap_interface *iface = NULL;
850 813
851 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); 814 if (dev)
815 iface = netdev_priv(dev);
852 816
853 link->state &= ~DEV_SUSPEND; 817 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
854 if (link->state & DEV_CONFIG) {
855 struct hostap_interface *iface = netdev_priv(dev);
856 if (iface && iface->local)
857 dev_open = iface->local->num_dev_open > 0;
858 818
859 pcmcia_request_configuration(link->handle, &link->conf); 819 if (iface && iface->local)
820 dev_open = iface->local->num_dev_open > 0;
860 821
861 prism2_hw_shutdown(dev, 1); 822 prism2_hw_shutdown(dev, 1);
862 prism2_hw_config(dev, dev_open ? 0 : 1); 823 prism2_hw_config(dev, dev_open ? 0 : 1);
863 if (dev_open) { 824 if (dev_open) {
864 netif_device_attach(dev); 825 netif_device_attach(dev);
865 netif_start_queue(dev); 826 netif_start_queue(dev);
866 }
867 } 827 }
868 828
869 return 0; 829 return 0;
@@ -930,7 +890,7 @@ static struct pcmcia_driver hostap_driver = {
930 .drv = { 890 .drv = {
931 .name = "hostap_cs", 891 .name = "hostap_cs",
932 }, 892 },
933 .probe = prism2_attach, 893 .probe = hostap_cs_probe,
934 .remove = prism2_detach, 894 .remove = prism2_detach,
935 .owner = THIS_MODULE, 895 .owner = THIS_MODULE,
936 .id_table = hostap_cs_ids, 896 .id_table = hostap_cs_ids,
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 9dce522526c5..bca89cff85a6 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -5573,8 +5573,7 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
5573 case IEEE80211_52GHZ_BAND: 5573 case IEEE80211_52GHZ_BAND:
5574 network->mode = IEEE_A; 5574 network->mode = IEEE_A;
5575 i = ieee80211_channel_to_index(priv->ieee, priv->channel); 5575 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5576 if (i == -1) 5576 BUG_ON(i == -1);
5577 BUG();
5578 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) { 5577 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5579 IPW_WARNING("Overriding invalid channel\n"); 5578 IPW_WARNING("Overriding invalid channel\n");
5580 priv->channel = geo->a[0].channel; 5579 priv->channel = geo->a[0].channel;
@@ -5587,8 +5586,7 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
5587 else 5586 else
5588 network->mode = IEEE_B; 5587 network->mode = IEEE_B;
5589 i = ieee80211_channel_to_index(priv->ieee, priv->channel); 5588 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5590 if (i == -1) 5589 BUG_ON(i == -1);
5591 BUG();
5592 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) { 5590 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5593 IPW_WARNING("Overriding invalid channel\n"); 5591 IPW_WARNING("Overriding invalid channel\n");
5594 priv->channel = geo->bg[0].channel; 5592 priv->channel = geo->bg[0].channel;
@@ -6715,8 +6713,7 @@ static int ipw_qos_association(struct ipw_priv *priv,
6715 6713
6716 switch (priv->ieee->iw_mode) { 6714 switch (priv->ieee->iw_mode) {
6717 case IW_MODE_ADHOC: 6715 case IW_MODE_ADHOC:
6718 if (!(network->capability & WLAN_CAPABILITY_IBSS)) 6716 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
6719 BUG();
6720 6717
6721 qos_data = &ibss_data; 6718 qos_data = &ibss_data;
6722 break; 6719 break;
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 75ce6ddb0cf5..9343d970537b 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -190,8 +190,8 @@ module_param(mem_speed, int, 0);
190/*====================================================================*/ 190/*====================================================================*/
191 191
192/* PCMCIA (Card Services) related functions */ 192/* PCMCIA (Card Services) related functions */
193static void netwave_release(dev_link_t *link); /* Card removal */ 193static void netwave_release(struct pcmcia_device *link); /* Card removal */
194static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card 194static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
195 insertion */ 195 insertion */
196static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */ 196static void netwave_detach(struct pcmcia_device *p_dev); /* Destroy instance */
197 197
@@ -221,10 +221,10 @@ static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
221static void set_multicast_list(struct net_device *dev); 221static void set_multicast_list(struct net_device *dev);
222 222
223/* 223/*
224 A dev_link_t structure has fields for most things that are needed 224 A struct pcmcia_device structure has fields for most things that are needed
225 to keep track of a socket, but there will usually be some device 225 to keep track of a socket, but there will usually be some device
226 specific information that also needs to be kept track of. The 226 specific information that also needs to be kept track of. The
227 'priv' pointer in a dev_link_t structure can be used to point to 227 'priv' pointer in a struct pcmcia_device structure can be used to point to
228 a device-specific private data structure, like this. 228 a device-specific private data structure, like this.
229 229
230 A driver needs to provide a dev_node_t structure for each device 230 A driver needs to provide a dev_node_t structure for each device
@@ -232,7 +232,7 @@ static void set_multicast_list(struct net_device *dev);
232 example, ethernet cards, modems). In other cases, there may be 232 example, ethernet cards, modems). In other cases, there may be
233 many actual or logical devices (SCSI adapters, memory cards with 233 many actual or logical devices (SCSI adapters, memory cards with
234 multiple partitions). The dev_node_t structures need to be kept 234 multiple partitions). The dev_node_t structures need to be kept
235 in a linked list starting at the 'dev' field of a dev_link_t 235 in a linked list starting at the 'dev' field of a struct pcmcia_device
236 structure. We allocate them in the card's private data structure, 236 structure. We allocate them in the card's private data structure,
237 because they generally can't be allocated dynamically. 237 because they generally can't be allocated dynamically.
238*/ 238*/
@@ -268,7 +268,7 @@ struct site_survey {
268}; 268};
269 269
270typedef struct netwave_private { 270typedef struct netwave_private {
271 dev_link_t link; 271 struct pcmcia_device *p_dev;
272 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */ 272 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
273 dev_node_t node; 273 dev_node_t node;
274 u_char __iomem *ramBase; 274 u_char __iomem *ramBase;
@@ -376,20 +376,19 @@ static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
376 * configure the card at this point -- we wait until we receive a 376 * configure the card at this point -- we wait until we receive a
377 * card insertion event. 377 * card insertion event.
378 */ 378 */
379static int netwave_attach(struct pcmcia_device *p_dev) 379static int netwave_probe(struct pcmcia_device *link)
380{ 380{
381 dev_link_t *link;
382 struct net_device *dev; 381 struct net_device *dev;
383 netwave_private *priv; 382 netwave_private *priv;
384 383
385 DEBUG(0, "netwave_attach()\n"); 384 DEBUG(0, "netwave_attach()\n");
386 385
387 /* Initialize the dev_link_t structure */ 386 /* Initialize the struct pcmcia_device structure */
388 dev = alloc_etherdev(sizeof(netwave_private)); 387 dev = alloc_etherdev(sizeof(netwave_private));
389 if (!dev) 388 if (!dev)
390 return -ENOMEM; 389 return -ENOMEM;
391 priv = netdev_priv(dev); 390 priv = netdev_priv(dev);
392 link = &priv->link; 391 priv->p_dev = link;
393 link->priv = dev; 392 link->priv = dev;
394 393
395 /* The io structure describes IO port mapping */ 394 /* The io structure describes IO port mapping */
@@ -406,7 +405,6 @@ static int netwave_attach(struct pcmcia_device *p_dev)
406 405
407 /* General socket configuration */ 406 /* General socket configuration */
408 link->conf.Attributes = CONF_ENABLE_IRQ; 407 link->conf.Attributes = CONF_ENABLE_IRQ;
409 link->conf.Vcc = 50;
410 link->conf.IntType = INT_MEMORY_AND_IO; 408 link->conf.IntType = INT_MEMORY_AND_IO;
411 link->conf.ConfigIndex = 1; 409 link->conf.ConfigIndex = 1;
412 link->conf.Present = PRESENT_OPTION; 410 link->conf.Present = PRESENT_OPTION;
@@ -430,13 +428,7 @@ static int netwave_attach(struct pcmcia_device *p_dev)
430 dev->stop = &netwave_close; 428 dev->stop = &netwave_close;
431 link->irq.Instance = dev; 429 link->irq.Instance = dev;
432 430
433 link->handle = p_dev; 431 return netwave_pcmcia_config( link);
434 p_dev->instance = link;
435
436 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
437 netwave_pcmcia_config( link);
438
439 return 0;
440} /* netwave_attach */ 432} /* netwave_attach */
441 433
442/* 434/*
@@ -447,17 +439,15 @@ static int netwave_attach(struct pcmcia_device *p_dev)
447 * structures are freed. Otherwise, the structures will be freed 439 * structures are freed. Otherwise, the structures will be freed
448 * when the device is released. 440 * when the device is released.
449 */ 441 */
450static void netwave_detach(struct pcmcia_device *p_dev) 442static void netwave_detach(struct pcmcia_device *link)
451{ 443{
452 dev_link_t *link = dev_to_instance(p_dev);
453 struct net_device *dev = link->priv; 444 struct net_device *dev = link->priv;
454 445
455 DEBUG(0, "netwave_detach(0x%p)\n", link); 446 DEBUG(0, "netwave_detach(0x%p)\n", link);
456 447
457 if (link->state & DEV_CONFIG) 448 netwave_release(link);
458 netwave_release(link);
459 449
460 if (link->dev) 450 if (link->dev_node)
461 unregister_netdev(dev); 451 unregister_netdev(dev);
462 452
463 free_netdev(dev); 453 free_netdev(dev);
@@ -743,8 +733,7 @@ static const struct iw_handler_def netwave_handler_def =
743#define CS_CHECK(fn, ret) \ 733#define CS_CHECK(fn, ret) \
744do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 734do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
745 735
746static void netwave_pcmcia_config(dev_link_t *link) { 736static int netwave_pcmcia_config(struct pcmcia_device *link) {
747 client_handle_t handle = link->handle;
748 struct net_device *dev = link->priv; 737 struct net_device *dev = link->priv;
749 netwave_private *priv = netdev_priv(dev); 738 netwave_private *priv = netdev_priv(dev);
750 tuple_t tuple; 739 tuple_t tuple;
@@ -766,15 +755,12 @@ static void netwave_pcmcia_config(dev_link_t *link) {
766 tuple.TupleDataMax = 64; 755 tuple.TupleDataMax = 64;
767 tuple.TupleOffset = 0; 756 tuple.TupleOffset = 0;
768 tuple.DesiredTuple = CISTPL_CONFIG; 757 tuple.DesiredTuple = CISTPL_CONFIG;
769 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 758 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
770 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 759 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
771 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 760 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
772 link->conf.ConfigBase = parse.config.base; 761 link->conf.ConfigBase = parse.config.base;
773 link->conf.Present = parse.config.rmask[0]; 762 link->conf.Present = parse.config.rmask[0];
774 763
775 /* Configure card */
776 link->state |= DEV_CONFIG;
777
778 /* 764 /*
779 * Try allocating IO ports. This tries a few fixed addresses. 765 * Try allocating IO ports. This tries a few fixed addresses.
780 * If you want, you can also read the card's config table to 766 * If you want, you can also read the card's config table to
@@ -782,11 +768,11 @@ static void netwave_pcmcia_config(dev_link_t *link) {
782 */ 768 */
783 for (i = j = 0x0; j < 0x400; j += 0x20) { 769 for (i = j = 0x0; j < 0x400; j += 0x20) {
784 link->io.BasePort1 = j ^ 0x300; 770 link->io.BasePort1 = j ^ 0x300;
785 i = pcmcia_request_io(link->handle, &link->io); 771 i = pcmcia_request_io(link, &link->io);
786 if (i == CS_SUCCESS) break; 772 if (i == CS_SUCCESS) break;
787 } 773 }
788 if (i != CS_SUCCESS) { 774 if (i != CS_SUCCESS) {
789 cs_error(link->handle, RequestIO, i); 775 cs_error(link, RequestIO, i);
790 goto failed; 776 goto failed;
791 } 777 }
792 778
@@ -794,16 +780,16 @@ static void netwave_pcmcia_config(dev_link_t *link) {
794 * Now allocate an interrupt line. Note that this does not 780 * Now allocate an interrupt line. Note that this does not
795 * actually assign a handler to the interrupt. 781 * actually assign a handler to the interrupt.
796 */ 782 */
797 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 783 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
798 784
799 /* 785 /*
800 * This actually configures the PCMCIA socket -- setting up 786 * This actually configures the PCMCIA socket -- setting up
801 * the I/O windows and the interrupt mapping. 787 * the I/O windows and the interrupt mapping.
802 */ 788 */
803 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 789 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
804 790
805 /* 791 /*
806 * Allocate a 32K memory window. Note that the dev_link_t 792 * Allocate a 32K memory window. Note that the struct pcmcia_device
807 * structure provides space for one window handle -- if your 793 * structure provides space for one window handle -- if your
808 * device needs several windows, you'll need to keep track of 794 * device needs several windows, you'll need to keep track of
809 * the handles in your private data structure, dev->priv. 795 * the handles in your private data structure, dev->priv.
@@ -813,7 +799,7 @@ static void netwave_pcmcia_config(dev_link_t *link) {
813 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE; 799 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
814 req.Base = 0; req.Size = 0x8000; 800 req.Base = 0; req.Size = 0x8000;
815 req.AccessSpeed = mem_speed; 801 req.AccessSpeed = mem_speed;
816 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 802 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
817 mem.CardOffset = 0x20000; mem.Page = 0; 803 mem.CardOffset = 0x20000; mem.Page = 0;
818 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 804 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
819 805
@@ -823,7 +809,7 @@ static void netwave_pcmcia_config(dev_link_t *link) {
823 809
824 dev->irq = link->irq.AssignedIRQ; 810 dev->irq = link->irq.AssignedIRQ;
825 dev->base_addr = link->io.BasePort1; 811 dev->base_addr = link->io.BasePort1;
826 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 812 SET_NETDEV_DEV(dev, &handle_to_dev(link));
827 813
828 if (register_netdev(dev) != 0) { 814 if (register_netdev(dev) != 0) {
829 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n"); 815 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
@@ -831,8 +817,7 @@ static void netwave_pcmcia_config(dev_link_t *link) {
831 } 817 }
832 818
833 strcpy(priv->node.dev_name, dev->name); 819 strcpy(priv->node.dev_name, dev->name);
834 link->dev = &priv->node; 820 link->dev_node = &priv->node;
835 link->state &= ~DEV_CONFIG_PENDING;
836 821
837 /* Reset card before reading physical address */ 822 /* Reset card before reading physical address */
838 netwave_doreset(dev->base_addr, ramBase); 823 netwave_doreset(dev->base_addr, ramBase);
@@ -852,12 +837,13 @@ static void netwave_pcmcia_config(dev_link_t *link) {
852 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n", 837 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
853 get_uint16(ramBase + NETWAVE_EREG_ARW), 838 get_uint16(ramBase + NETWAVE_EREG_ARW),
854 get_uint16(ramBase + NETWAVE_EREG_ARW+2)); 839 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
855 return; 840 return 0;
856 841
857cs_failed: 842cs_failed:
858 cs_error(link->handle, last_fn, last_ret); 843 cs_error(link, last_fn, last_ret);
859failed: 844failed:
860 netwave_release(link); 845 netwave_release(link);
846 return -ENODEV;
861} /* netwave_pcmcia_config */ 847} /* netwave_pcmcia_config */
862 848
863/* 849/*
@@ -867,52 +853,35 @@ failed:
867 * device, and release the PCMCIA configuration. If the device is 853 * device, and release the PCMCIA configuration. If the device is
868 * still open, this will be postponed until it is closed. 854 * still open, this will be postponed until it is closed.
869 */ 855 */
870static void netwave_release(dev_link_t *link) 856static void netwave_release(struct pcmcia_device *link)
871{ 857{
872 struct net_device *dev = link->priv; 858 struct net_device *dev = link->priv;
873 netwave_private *priv = netdev_priv(dev); 859 netwave_private *priv = netdev_priv(dev);
874
875 DEBUG(0, "netwave_release(0x%p)\n", link);
876 860
877 /* Don't bother checking to see if these succeed or not */ 861 DEBUG(0, "netwave_release(0x%p)\n", link);
878 if (link->win) {
879 iounmap(priv->ramBase);
880 pcmcia_release_window(link->win);
881 }
882 pcmcia_release_configuration(link->handle);
883 pcmcia_release_io(link->handle, &link->io);
884 pcmcia_release_irq(link->handle, &link->irq);
885 862
886 link->state &= ~DEV_CONFIG; 863 pcmcia_disable_device(link);
864 if (link->win)
865 iounmap(priv->ramBase);
887} 866}
888 867
889static int netwave_suspend(struct pcmcia_device *p_dev) 868static int netwave_suspend(struct pcmcia_device *link)
890{ 869{
891 dev_link_t *link = dev_to_instance(p_dev);
892 struct net_device *dev = link->priv; 870 struct net_device *dev = link->priv;
893 871
894 link->state |= DEV_SUSPEND; 872 if (link->open)
895 if (link->state & DEV_CONFIG) { 873 netif_device_detach(dev);
896 if (link->open)
897 netif_device_detach(dev);
898 pcmcia_release_configuration(link->handle);
899 }
900 874
901 return 0; 875 return 0;
902} 876}
903 877
904static int netwave_resume(struct pcmcia_device *p_dev) 878static int netwave_resume(struct pcmcia_device *link)
905{ 879{
906 dev_link_t *link = dev_to_instance(p_dev);
907 struct net_device *dev = link->priv; 880 struct net_device *dev = link->priv;
908 881
909 link->state &= ~DEV_SUSPEND; 882 if (link->open) {
910 if (link->state & DEV_CONFIG) { 883 netwave_reset(dev);
911 pcmcia_request_configuration(link->handle, &link->conf); 884 netif_device_attach(dev);
912 if (link->open) {
913 netwave_reset(dev);
914 netif_device_attach(dev);
915 }
916 } 885 }
917 886
918 return 0; 887 return 0;
@@ -1119,7 +1088,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs
1119 u_char __iomem *ramBase; 1088 u_char __iomem *ramBase;
1120 struct net_device *dev = (struct net_device *)dev_id; 1089 struct net_device *dev = (struct net_device *)dev_id;
1121 struct netwave_private *priv = netdev_priv(dev); 1090 struct netwave_private *priv = netdev_priv(dev);
1122 dev_link_t *link = &priv->link; 1091 struct pcmcia_device *link = priv->p_dev;
1123 int i; 1092 int i;
1124 1093
1125 if (!netif_device_present(dev)) 1094 if (!netif_device_present(dev))
@@ -1138,7 +1107,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs
1138 1107
1139 status = inb(iobase + NETWAVE_REG_ASR); 1108 status = inb(iobase + NETWAVE_REG_ASR);
1140 1109
1141 if (!DEV_OK(link)) { 1110 if (!pcmcia_dev_present(link)) {
1142 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x " 1111 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1143 "from removed or suspended card!\n", status); 1112 "from removed or suspended card!\n", status);
1144 break; 1113 break;
@@ -1373,11 +1342,11 @@ static int netwave_rx(struct net_device *dev)
1373 1342
1374static int netwave_open(struct net_device *dev) { 1343static int netwave_open(struct net_device *dev) {
1375 netwave_private *priv = netdev_priv(dev); 1344 netwave_private *priv = netdev_priv(dev);
1376 dev_link_t *link = &priv->link; 1345 struct pcmcia_device *link = priv->p_dev;
1377 1346
1378 DEBUG(1, "netwave_open: starting.\n"); 1347 DEBUG(1, "netwave_open: starting.\n");
1379 1348
1380 if (!DEV_OK(link)) 1349 if (!pcmcia_dev_present(link))
1381 return -ENODEV; 1350 return -ENODEV;
1382 1351
1383 link->open++; 1352 link->open++;
@@ -1390,7 +1359,7 @@ static int netwave_open(struct net_device *dev) {
1390 1359
1391static int netwave_close(struct net_device *dev) { 1360static int netwave_close(struct net_device *dev) {
1392 netwave_private *priv = netdev_priv(dev); 1361 netwave_private *priv = netdev_priv(dev);
1393 dev_link_t *link = &priv->link; 1362 struct pcmcia_device *link = priv->p_dev;
1394 1363
1395 DEBUG(1, "netwave_close: finishing.\n"); 1364 DEBUG(1, "netwave_close: finishing.\n");
1396 1365
@@ -1411,7 +1380,7 @@ static struct pcmcia_driver netwave_driver = {
1411 .drv = { 1380 .drv = {
1412 .name = "netwave_cs", 1381 .name = "netwave_cs",
1413 }, 1382 },
1414 .probe = netwave_attach, 1383 .probe = netwave_probe,
1415 .remove = netwave_detach, 1384 .remove = netwave_detach,
1416 .id_table = netwave_ids, 1385 .id_table = netwave_ids,
1417 .suspend = netwave_suspend, 1386 .suspend = netwave_suspend,
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index ec6f2a48895b..434f7d7ad841 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -49,7 +49,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
49/* PCMCIA specific device information (goes in the card field of 49/* PCMCIA specific device information (goes in the card field of
50 * struct orinoco_private */ 50 * struct orinoco_private */
51struct orinoco_pccard { 51struct orinoco_pccard {
52 dev_link_t link; 52 struct pcmcia_device *p_dev;
53 dev_node_t node; 53 dev_node_t node;
54 54
55 /* Used to handle hard reset */ 55 /* Used to handle hard reset */
@@ -63,8 +63,8 @@ struct orinoco_pccard {
63/* Function prototypes */ 63/* Function prototypes */
64/********************************************************************/ 64/********************************************************************/
65 65
66static void orinoco_cs_config(dev_link_t *link); 66static int orinoco_cs_config(struct pcmcia_device *link);
67static void orinoco_cs_release(dev_link_t *link); 67static void orinoco_cs_release(struct pcmcia_device *link);
68static void orinoco_cs_detach(struct pcmcia_device *p_dev); 68static void orinoco_cs_detach(struct pcmcia_device *p_dev);
69 69
70/********************************************************************/ 70/********************************************************************/
@@ -75,13 +75,13 @@ static int
75orinoco_cs_hard_reset(struct orinoco_private *priv) 75orinoco_cs_hard_reset(struct orinoco_private *priv)
76{ 76{
77 struct orinoco_pccard *card = priv->card; 77 struct orinoco_pccard *card = priv->card;
78 dev_link_t *link = &card->link; 78 struct pcmcia_device *link = card->p_dev;
79 int err; 79 int err;
80 80
81 /* We need atomic ops here, because we're not holding the lock */ 81 /* We need atomic ops here, because we're not holding the lock */
82 set_bit(0, &card->hard_reset_in_progress); 82 set_bit(0, &card->hard_reset_in_progress);
83 83
84 err = pcmcia_reset_card(link->handle, NULL); 84 err = pcmcia_reset_card(link, NULL);
85 if (err) 85 if (err)
86 return err; 86 return err;
87 87
@@ -104,12 +104,11 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
104 * configure the card at this point -- we wait until we receive a card 104 * configure the card at this point -- we wait until we receive a card
105 * insertion event. */ 105 * insertion event. */
106static int 106static int
107orinoco_cs_attach(struct pcmcia_device *p_dev) 107orinoco_cs_probe(struct pcmcia_device *link)
108{ 108{
109 struct net_device *dev; 109 struct net_device *dev;
110 struct orinoco_private *priv; 110 struct orinoco_private *priv;
111 struct orinoco_pccard *card; 111 struct orinoco_pccard *card;
112 dev_link_t *link;
113 112
114 dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset); 113 dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset);
115 if (! dev) 114 if (! dev)
@@ -118,7 +117,7 @@ orinoco_cs_attach(struct pcmcia_device *p_dev)
118 card = priv->card; 117 card = priv->card;
119 118
120 /* Link both structures together */ 119 /* Link both structures together */
121 link = &card->link; 120 card->p_dev = link;
122 link->priv = dev; 121 link->priv = dev;
123 122
124 /* Interrupt setup */ 123 /* Interrupt setup */
@@ -135,16 +134,7 @@ orinoco_cs_attach(struct pcmcia_device *p_dev)
135 link->conf.Attributes = 0; 134 link->conf.Attributes = 0;
136 link->conf.IntType = INT_MEMORY_AND_IO; 135 link->conf.IntType = INT_MEMORY_AND_IO;
137 136
138 /* Register with Card Services */ 137 return orinoco_cs_config(link);
139 link->next = NULL;
140
141 link->handle = p_dev;
142 p_dev->instance = link;
143
144 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
145 orinoco_cs_config(link);
146
147 return 0;
148} /* orinoco_cs_attach */ 138} /* orinoco_cs_attach */
149 139
150/* 140/*
@@ -153,16 +143,14 @@ orinoco_cs_attach(struct pcmcia_device *p_dev)
153 * are freed. Otherwise, the structures will be freed when the device 143 * are freed. Otherwise, the structures will be freed when the device
154 * is released. 144 * is released.
155 */ 145 */
156static void orinoco_cs_detach(struct pcmcia_device *p_dev) 146static void orinoco_cs_detach(struct pcmcia_device *link)
157{ 147{
158 dev_link_t *link = dev_to_instance(p_dev);
159 struct net_device *dev = link->priv; 148 struct net_device *dev = link->priv;
160 149
161 if (link->state & DEV_CONFIG) 150 orinoco_cs_release(link);
162 orinoco_cs_release(link);
163 151
164 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); 152 DEBUG(0, PFX "detach: link=%p link->dev_node=%p\n", link, link->dev_node);
165 if (link->dev) { 153 if (link->dev_node) {
166 DEBUG(0, PFX "About to unregister net device %p\n", 154 DEBUG(0, PFX "About to unregister net device %p\n",
167 dev); 155 dev);
168 unregister_netdev(dev); 156 unregister_netdev(dev);
@@ -180,11 +168,10 @@ static void orinoco_cs_detach(struct pcmcia_device *p_dev)
180 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \ 168 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \
181 } while (0) 169 } while (0)
182 170
183static void 171static int
184orinoco_cs_config(dev_link_t *link) 172orinoco_cs_config(struct pcmcia_device *link)
185{ 173{
186 struct net_device *dev = link->priv; 174 struct net_device *dev = link->priv;
187 client_handle_t handle = link->handle;
188 struct orinoco_private *priv = netdev_priv(dev); 175 struct orinoco_private *priv = netdev_priv(dev);
189 struct orinoco_pccard *card = priv->card; 176 struct orinoco_pccard *card = priv->card;
190 hermes_t *hw = &priv->hw; 177 hermes_t *hw = &priv->hw;
@@ -196,7 +183,7 @@ orinoco_cs_config(dev_link_t *link)
196 cisparse_t parse; 183 cisparse_t parse;
197 void __iomem *mem; 184 void __iomem *mem;
198 185
199 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info)); 186 CS_CHECK(ValidateCIS, pcmcia_validate_cis(link, &info));
200 187
201 /* 188 /*
202 * This reads the card's CONFIG tuple to find its 189 * This reads the card's CONFIG tuple to find its
@@ -207,19 +194,15 @@ orinoco_cs_config(dev_link_t *link)
207 tuple.TupleData = buf; 194 tuple.TupleData = buf;
208 tuple.TupleDataMax = sizeof(buf); 195 tuple.TupleDataMax = sizeof(buf);
209 tuple.TupleOffset = 0; 196 tuple.TupleOffset = 0;
210 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 197 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
211 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 198 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
212 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 199 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
213 link->conf.ConfigBase = parse.config.base; 200 link->conf.ConfigBase = parse.config.base;
214 link->conf.Present = parse.config.rmask[0]; 201 link->conf.Present = parse.config.rmask[0];
215 202
216 /* Configure card */
217 link->state |= DEV_CONFIG;
218
219 /* Look up the current Vcc */ 203 /* Look up the current Vcc */
220 CS_CHECK(GetConfigurationInfo, 204 CS_CHECK(GetConfigurationInfo,
221 pcmcia_get_configuration_info(handle, &conf)); 205 pcmcia_get_configuration_info(link, &conf));
222 link->conf.Vcc = conf.Vcc;
223 206
224 /* 207 /*
225 * In this loop, we scan the CIS for configuration table 208 * In this loop, we scan the CIS for configuration table
@@ -236,13 +219,13 @@ orinoco_cs_config(dev_link_t *link)
236 * implementation-defined details. 219 * implementation-defined details.
237 */ 220 */
238 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 221 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
239 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 222 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
240 while (1) { 223 while (1) {
241 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 224 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
242 cistpl_cftable_entry_t dflt = { .index = 0 }; 225 cistpl_cftable_entry_t dflt = { .index = 0 };
243 226
244 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0) 227 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
245 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0)) 228 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
246 goto next_entry; 229 goto next_entry;
247 230
248 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 231 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
@@ -274,10 +257,10 @@ orinoco_cs_config(dev_link_t *link)
274 } 257 }
275 258
276 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 259 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
277 link->conf.Vpp1 = link->conf.Vpp2 = 260 link->conf.Vpp =
278 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 261 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
279 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 262 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
280 link->conf.Vpp1 = link->conf.Vpp2 = 263 link->conf.Vpp =
281 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 264 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
282 265
283 /* Do we need to allocate an interrupt? */ 266 /* Do we need to allocate an interrupt? */
@@ -307,7 +290,7 @@ orinoco_cs_config(dev_link_t *link)
307 } 290 }
308 291
309 /* This reserves IO space but doesn't actually enable it */ 292 /* This reserves IO space but doesn't actually enable it */
310 if (pcmcia_request_io(link->handle, &link->io) != 0) 293 if (pcmcia_request_io(link, &link->io) != 0)
311 goto next_entry; 294 goto next_entry;
312 } 295 }
313 296
@@ -317,9 +300,8 @@ orinoco_cs_config(dev_link_t *link)
317 break; 300 break;
318 301
319 next_entry: 302 next_entry:
320 if (link->io.NumPorts1) 303 pcmcia_disable_device(link);
321 pcmcia_release_io(link->handle, &link->io); 304 last_ret = pcmcia_get_next_tuple(link, &tuple);
322 last_ret = pcmcia_get_next_tuple(handle, &tuple);
323 if (last_ret == CS_NO_MORE_ITEMS) { 305 if (last_ret == CS_NO_MORE_ITEMS) {
324 printk(KERN_ERR PFX "GetNextTuple(): No matching " 306 printk(KERN_ERR PFX "GetNextTuple(): No matching "
325 "CIS configuration. Maybe you need the " 307 "CIS configuration. Maybe you need the "
@@ -333,7 +315,7 @@ orinoco_cs_config(dev_link_t *link)
333 * a handler to the interrupt, unless the 'Handler' member of 315 * a handler to the interrupt, unless the 'Handler' member of
334 * the irq structure is initialized. 316 * the irq structure is initialized.
335 */ 317 */
336 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 318 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
337 319
338 /* We initialize the hermes structure before completing PCMCIA 320 /* We initialize the hermes structure before completing PCMCIA
339 * configuration just in case the interrupt handler gets 321 * configuration just in case the interrupt handler gets
@@ -350,7 +332,7 @@ orinoco_cs_config(dev_link_t *link)
350 * card and host interface into "Memory and IO" mode. 332 * card and host interface into "Memory and IO" mode.
351 */ 333 */
352 CS_CHECK(RequestConfiguration, 334 CS_CHECK(RequestConfiguration,
353 pcmcia_request_configuration(link->handle, &link->conf)); 335 pcmcia_request_configuration(link, &link->conf));
354 336
355 /* Ok, we have the configuration, prepare to register the netdev */ 337 /* Ok, we have the configuration, prepare to register the netdev */
356 dev->base_addr = link->io.BasePort1; 338 dev->base_addr = link->io.BasePort1;
@@ -358,7 +340,7 @@ orinoco_cs_config(dev_link_t *link)
358 SET_MODULE_OWNER(dev); 340 SET_MODULE_OWNER(dev);
359 card->node.major = card->node.minor = 0; 341 card->node.major = card->node.minor = 0;
360 342
361 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 343 SET_NETDEV_DEV(dev, &handle_to_dev(link));
362 /* Tell the stack we exist */ 344 /* Tell the stack we exist */
363 if (register_netdev(dev) != 0) { 345 if (register_netdev(dev) != 0) {
364 printk(KERN_ERR PFX "register_netdev() failed\n"); 346 printk(KERN_ERR PFX "register_netdev() failed\n");
@@ -366,20 +348,18 @@ orinoco_cs_config(dev_link_t *link)
366 } 348 }
367 349
368 /* At this point, the dev_node_t structure(s) needs to be 350 /* At this point, the dev_node_t structure(s) needs to be
369 * initialized and arranged in a linked list at link->dev. */ 351 * initialized and arranged in a linked list at link->dev_node. */
370 strcpy(card->node.dev_name, dev->name); 352 strcpy(card->node.dev_name, dev->name);
371 link->dev = &card->node; /* link->dev being non-NULL is also 353 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
372 used to indicate that the 354 used to indicate that the
373 net_device has been registered */ 355 net_device has been registered */
374 link->state &= ~DEV_CONFIG_PENDING;
375 356
376 /* Finally, report what we've done */ 357 /* Finally, report what we've done */
377 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d", 358 printk(KERN_DEBUG "%s: index 0x%02x: ",
378 dev->name, link->conf.ConfigIndex, 359 dev->name, link->conf.ConfigIndex);
379 link->conf.Vcc / 10, link->conf.Vcc % 10); 360 if (link->conf.Vpp)
380 if (link->conf.Vpp1) 361 printk(", Vpp %d.%d", link->conf.Vpp / 10,
381 printk(", Vpp %d.%d", link->conf.Vpp1 / 10, 362 link->conf.Vpp % 10);
382 link->conf.Vpp1 % 10);
383 printk(", irq %d", link->irq.AssignedIRQ); 363 printk(", irq %d", link->irq.AssignedIRQ);
384 if (link->io.NumPorts1) 364 if (link->io.NumPorts1)
385 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 365 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
@@ -389,13 +369,14 @@ orinoco_cs_config(dev_link_t *link)
389 link->io.BasePort2 + link->io.NumPorts2 - 1); 369 link->io.BasePort2 + link->io.NumPorts2 - 1);
390 printk("\n"); 370 printk("\n");
391 371
392 return; 372 return 0;
393 373
394 cs_failed: 374 cs_failed:
395 cs_error(link->handle, last_fn, last_ret); 375 cs_error(link, last_fn, last_ret);
396 376
397 failed: 377 failed:
398 orinoco_cs_release(link); 378 orinoco_cs_release(link);
379 return -ENODEV;
399} /* orinoco_cs_config */ 380} /* orinoco_cs_config */
400 381
401/* 382/*
@@ -404,7 +385,7 @@ orinoco_cs_config(dev_link_t *link)
404 * still open, this will be postponed until it is closed. 385 * still open, this will be postponed until it is closed.
405 */ 386 */
406static void 387static void
407orinoco_cs_release(dev_link_t *link) 388orinoco_cs_release(struct pcmcia_device *link)
408{ 389{
409 struct net_device *dev = link->priv; 390 struct net_device *dev = link->priv;
410 struct orinoco_private *priv = netdev_priv(dev); 391 struct orinoco_private *priv = netdev_priv(dev);
@@ -416,88 +397,68 @@ orinoco_cs_release(dev_link_t *link)
416 priv->hw_unavailable++; 397 priv->hw_unavailable++;
417 spin_unlock_irqrestore(&priv->lock, flags); 398 spin_unlock_irqrestore(&priv->lock, flags);
418 399
419 /* Don't bother checking to see if these succeed or not */ 400 pcmcia_disable_device(link);
420 pcmcia_release_configuration(link->handle);
421 if (link->io.NumPorts1)
422 pcmcia_release_io(link->handle, &link->io);
423 if (link->irq.AssignedIRQ)
424 pcmcia_release_irq(link->handle, &link->irq);
425 link->state &= ~DEV_CONFIG;
426 if (priv->hw.iobase) 401 if (priv->hw.iobase)
427 ioport_unmap(priv->hw.iobase); 402 ioport_unmap(priv->hw.iobase);
428} /* orinoco_cs_release */ 403} /* orinoco_cs_release */
429 404
430static int orinoco_cs_suspend(struct pcmcia_device *p_dev) 405static int orinoco_cs_suspend(struct pcmcia_device *link)
431{ 406{
432 dev_link_t *link = dev_to_instance(p_dev);
433 struct net_device *dev = link->priv; 407 struct net_device *dev = link->priv;
434 struct orinoco_private *priv = netdev_priv(dev); 408 struct orinoco_private *priv = netdev_priv(dev);
435 struct orinoco_pccard *card = priv->card; 409 struct orinoco_pccard *card = priv->card;
436 int err = 0; 410 int err = 0;
437 unsigned long flags; 411 unsigned long flags;
438 412
439 link->state |= DEV_SUSPEND; 413 /* This is probably racy, but I can't think of
440 if (link->state & DEV_CONFIG) { 414 a better way, short of rewriting the PCMCIA
441 /* This is probably racy, but I can't think of 415 layer to not suck :-( */
442 a better way, short of rewriting the PCMCIA 416 if (! test_bit(0, &card->hard_reset_in_progress)) {
443 layer to not suck :-( */ 417 spin_lock_irqsave(&priv->lock, flags);
444 if (! test_bit(0, &card->hard_reset_in_progress)) {
445 spin_lock_irqsave(&priv->lock, flags);
446 418
447 err = __orinoco_down(dev); 419 err = __orinoco_down(dev);
448 if (err) 420 if (err)
449 printk(KERN_WARNING "%s: Error %d downing interface\n", 421 printk(KERN_WARNING "%s: Error %d downing interface\n",
450 dev->name, err); 422 dev->name, err);
451 423
452 netif_device_detach(dev); 424 netif_device_detach(dev);
453 priv->hw_unavailable++; 425 priv->hw_unavailable++;
454 426
455 spin_unlock_irqrestore(&priv->lock, flags); 427 spin_unlock_irqrestore(&priv->lock, flags);
456 }
457
458 pcmcia_release_configuration(link->handle);
459 } 428 }
460 429
461 return 0; 430 return 0;
462} 431}
463 432
464static int orinoco_cs_resume(struct pcmcia_device *p_dev) 433static int orinoco_cs_resume(struct pcmcia_device *link)
465{ 434{
466 dev_link_t *link = dev_to_instance(p_dev);
467 struct net_device *dev = link->priv; 435 struct net_device *dev = link->priv;
468 struct orinoco_private *priv = netdev_priv(dev); 436 struct orinoco_private *priv = netdev_priv(dev);
469 struct orinoco_pccard *card = priv->card; 437 struct orinoco_pccard *card = priv->card;
470 int err = 0; 438 int err = 0;
471 unsigned long flags; 439 unsigned long flags;
472 440
473 link->state &= ~DEV_SUSPEND; 441 if (! test_bit(0, &card->hard_reset_in_progress)) {
474 if (link->state & DEV_CONFIG) { 442 err = orinoco_reinit_firmware(dev);
475 /* FIXME: should we double check that this is 443 if (err) {
476 * the same card as we had before */ 444 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
477 pcmcia_request_configuration(link->handle, &link->conf); 445 dev->name, err);
478 446 return -EIO;
479 if (! test_bit(0, &card->hard_reset_in_progress)) { 447 }
480 err = orinoco_reinit_firmware(dev);
481 if (err) {
482 printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
483 dev->name, err);
484 return -EIO;
485 }
486
487 spin_lock_irqsave(&priv->lock, flags);
488 448
489 netif_device_attach(dev); 449 spin_lock_irqsave(&priv->lock, flags);
490 priv->hw_unavailable--;
491 450
492 if (priv->open && ! priv->hw_unavailable) { 451 netif_device_attach(dev);
493 err = __orinoco_up(dev); 452 priv->hw_unavailable--;
494 if (err)
495 printk(KERN_ERR "%s: Error %d restarting card\n",
496 dev->name, err);
497 }
498 453
499 spin_unlock_irqrestore(&priv->lock, flags); 454 if (priv->open && ! priv->hw_unavailable) {
455 err = __orinoco_up(dev);
456 if (err)
457 printk(KERN_ERR "%s: Error %d restarting card\n",
458 dev->name, err);
500 } 459 }
460
461 spin_unlock_irqrestore(&priv->lock, flags);
501 } 462 }
502 463
503 return 0; 464 return 0;
@@ -604,7 +565,7 @@ static struct pcmcia_driver orinoco_driver = {
604 .drv = { 565 .drv = {
605 .name = DRIVER_NAME, 566 .name = DRIVER_NAME,
606 }, 567 },
607 .probe = orinoco_cs_attach, 568 .probe = orinoco_cs_probe,
608 .remove = orinoco_cs_detach, 569 .remove = orinoco_cs_detach,
609 .id_table = orinoco_cs_ids, 570 .id_table = orinoco_cs_ids,
610 .suspend = orinoco_cs_suspend, 571 .suspend = orinoco_cs_suspend,
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 7880d8c31aad..879eb427607c 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -90,8 +90,8 @@ module_param(pc_debug, int, 0);
90#define DEBUG(n, args...) 90#define DEBUG(n, args...)
91#endif 91#endif
92/** Prototypes based on PCMCIA skeleton driver *******************************/ 92/** Prototypes based on PCMCIA skeleton driver *******************************/
93static void ray_config(dev_link_t *link); 93static int ray_config(struct pcmcia_device *link);
94static void ray_release(dev_link_t *link); 94static void ray_release(struct pcmcia_device *link);
95static void ray_detach(struct pcmcia_device *p_dev); 95static void ray_detach(struct pcmcia_device *p_dev);
96 96
97/***** Prototypes indicated by device structure ******************************/ 97/***** Prototypes indicated by device structure ******************************/
@@ -190,20 +190,17 @@ static int bc;
190static char *phy_addr = NULL; 190static char *phy_addr = NULL;
191 191
192 192
193/* A linked list of "instances" of the ray device. Each actual 193/* A struct pcmcia_device structure has fields for most things that are needed
194 PCMCIA card corresponds to one device instance, and is described
195 by one dev_link_t structure (defined in ds.h).
196*/
197static dev_link_t *dev_list = NULL;
198
199/* A dev_link_t structure has fields for most things that are needed
200 to keep track of a socket, but there will usually be some device 194 to keep track of a socket, but there will usually be some device
201 specific information that also needs to be kept track of. The 195 specific information that also needs to be kept track of. The
202 'priv' pointer in a dev_link_t structure can be used to point to 196 'priv' pointer in a struct pcmcia_device structure can be used to point to
203 a device-specific private data structure, like this. 197 a device-specific private data structure, like this.
204*/ 198*/
205static unsigned int ray_mem_speed = 500; 199static unsigned int ray_mem_speed = 500;
206 200
201/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
202static struct pcmcia_device *this_device = NULL;
203
207MODULE_AUTHOR("Corey Thomas <corey@world.std.com>"); 204MODULE_AUTHOR("Corey Thomas <corey@world.std.com>");
208MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver"); 205MODULE_DESCRIPTION("Raylink/WebGear wireless LAN driver");
209MODULE_LICENSE("GPL"); 206MODULE_LICENSE("GPL");
@@ -306,56 +303,46 @@ static char rcsid[] = "Raylink/WebGear wireless LAN - Corey <Thomas corey@world.
306 configure the card at this point -- we wait until we receive a 303 configure the card at this point -- we wait until we receive a
307 card insertion event. 304 card insertion event.
308=============================================================================*/ 305=============================================================================*/
309static int ray_attach(struct pcmcia_device *p_dev) 306static int ray_probe(struct pcmcia_device *p_dev)
310{ 307{
311 dev_link_t *link;
312 ray_dev_t *local; 308 ray_dev_t *local;
313 struct net_device *dev; 309 struct net_device *dev;
314
315 DEBUG(1, "ray_attach()\n");
316 310
317 /* Initialize the dev_link_t structure */ 311 DEBUG(1, "ray_attach()\n");
318 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
319
320 if (!link)
321 return -ENOMEM;
322 312
323 /* Allocate space for private device-specific data */ 313 /* Allocate space for private device-specific data */
324 dev = alloc_etherdev(sizeof(ray_dev_t)); 314 dev = alloc_etherdev(sizeof(ray_dev_t));
325
326 if (!dev) 315 if (!dev)
327 goto fail_alloc_dev; 316 goto fail_alloc_dev;
328 317
329 local = dev->priv; 318 local = dev->priv;
330 319 local->finder = p_dev;
331 memset(link, 0, sizeof(struct dev_link_t));
332 320
333 /* The io structure describes IO port mapping. None used here */ 321 /* The io structure describes IO port mapping. None used here */
334 link->io.NumPorts1 = 0; 322 p_dev->io.NumPorts1 = 0;
335 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 323 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
336 link->io.IOAddrLines = 5; 324 p_dev->io.IOAddrLines = 5;
337 325
338 /* Interrupt setup. For PCMCIA, driver takes what's given */ 326 /* Interrupt setup. For PCMCIA, driver takes what's given */
339 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 327 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
340 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 328 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
341 link->irq.Handler = &ray_interrupt; 329 p_dev->irq.Handler = &ray_interrupt;
342 330
343 /* General socket configuration */ 331 /* General socket configuration */
344 link->conf.Attributes = CONF_ENABLE_IRQ; 332 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
345 link->conf.Vcc = 50; 333 p_dev->conf.IntType = INT_MEMORY_AND_IO;
346 link->conf.IntType = INT_MEMORY_AND_IO; 334 p_dev->conf.ConfigIndex = 1;
347 link->conf.ConfigIndex = 1; 335 p_dev->conf.Present = PRESENT_OPTION;
348 link->conf.Present = PRESENT_OPTION; 336
349 337 p_dev->priv = dev;
350 link->priv = dev; 338 p_dev->irq.Instance = dev;
351 link->irq.Instance = dev;
352 339
353 local->finder = link; 340 local->finder = p_dev;
354 local->card_status = CARD_INSERTED; 341 local->card_status = CARD_INSERTED;
355 local->authentication_state = UNAUTHENTICATED; 342 local->authentication_state = UNAUTHENTICATED;
356 local->num_multi = 0; 343 local->num_multi = 0;
357 DEBUG(2,"ray_attach link = %p, dev = %p, local = %p, intr = %p\n", 344 DEBUG(2,"ray_attach p_dev = %p, dev = %p, local = %p, intr = %p\n",
358 link,dev,local,&ray_interrupt); 345 p_dev,dev,local,&ray_interrupt);
359 346
360 /* Raylink entries in the device structure */ 347 /* Raylink entries in the device structure */
361 dev->hard_start_xmit = &ray_dev_start_xmit; 348 dev->hard_start_xmit = &ray_dev_start_xmit;
@@ -379,16 +366,10 @@ static int ray_attach(struct pcmcia_device *p_dev)
379 366
380 init_timer(&local->timer); 367 init_timer(&local->timer);
381 368
382 link->handle = p_dev; 369 this_device = p_dev;
383 p_dev->instance = link; 370 return ray_config(p_dev);
384
385 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
386 ray_config(link);
387
388 return 0;
389 371
390fail_alloc_dev: 372fail_alloc_dev:
391 kfree(link);
392 return -ENOMEM; 373 return -ENOMEM;
393} /* ray_attach */ 374} /* ray_attach */
394/*============================================================================= 375/*=============================================================================
@@ -397,37 +378,25 @@ fail_alloc_dev:
397 structures are freed. Otherwise, the structures will be freed 378 structures are freed. Otherwise, the structures will be freed
398 when the device is released. 379 when the device is released.
399=============================================================================*/ 380=============================================================================*/
400static void ray_detach(struct pcmcia_device *p_dev) 381static void ray_detach(struct pcmcia_device *link)
401{ 382{
402 dev_link_t *link = dev_to_instance(p_dev);
403 dev_link_t **linkp;
404 struct net_device *dev; 383 struct net_device *dev;
405 ray_dev_t *local; 384 ray_dev_t *local;
406 385
407 DEBUG(1, "ray_detach(0x%p)\n", link); 386 DEBUG(1, "ray_detach(0x%p)\n", link);
408
409 /* Locate device structure */
410 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
411 if (*linkp == link) break;
412 if (*linkp == NULL)
413 return;
414 387
388 this_device = NULL;
415 dev = link->priv; 389 dev = link->priv;
416 390
417 if (link->state & DEV_CONFIG) { 391 ray_release(link);
418 ray_release(link);
419 392
420 local = (ray_dev_t *)dev->priv; 393 local = (ray_dev_t *)dev->priv;
421 del_timer(&local->timer); 394 del_timer(&local->timer);
422 }
423 395
424 /* Unlink device structure, free pieces */
425 *linkp = link->next;
426 if (link->priv) { 396 if (link->priv) {
427 if (link->dev) unregister_netdev(dev); 397 if (link->dev_node) unregister_netdev(dev);
428 free_netdev(dev); 398 free_netdev(dev);
429 } 399 }
430 kfree(link);
431 DEBUG(2,"ray_cs ray_detach ending\n"); 400 DEBUG(2,"ray_cs ray_detach ending\n");
432} /* ray_detach */ 401} /* ray_detach */
433/*============================================================================= 402/*=============================================================================
@@ -438,9 +407,8 @@ static void ray_detach(struct pcmcia_device *p_dev)
438#define CS_CHECK(fn, ret) \ 407#define CS_CHECK(fn, ret) \
439do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 408do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
440#define MAX_TUPLE_SIZE 128 409#define MAX_TUPLE_SIZE 128
441static void ray_config(dev_link_t *link) 410static int ray_config(struct pcmcia_device *link)
442{ 411{
443 client_handle_t handle = link->handle;
444 tuple_t tuple; 412 tuple_t tuple;
445 cisparse_t parse; 413 cisparse_t parse;
446 int last_fn = 0, last_ret = 0; 414 int last_fn = 0, last_ret = 0;
@@ -455,48 +423,45 @@ static void ray_config(dev_link_t *link)
455 423
456 /* This reads the card's CONFIG tuple to find its configuration regs */ 424 /* This reads the card's CONFIG tuple to find its configuration regs */
457 tuple.DesiredTuple = CISTPL_CONFIG; 425 tuple.DesiredTuple = CISTPL_CONFIG;
458 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 426 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
459 tuple.TupleData = buf; 427 tuple.TupleData = buf;
460 tuple.TupleDataMax = MAX_TUPLE_SIZE; 428 tuple.TupleDataMax = MAX_TUPLE_SIZE;
461 tuple.TupleOffset = 0; 429 tuple.TupleOffset = 0;
462 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 430 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
463 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 431 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
464 link->conf.ConfigBase = parse.config.base; 432 link->conf.ConfigBase = parse.config.base;
465 link->conf.Present = parse.config.rmask[0]; 433 link->conf.Present = parse.config.rmask[0];
466 434
467 /* Determine card type and firmware version */ 435 /* Determine card type and firmware version */
468 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0; 436 buf[0] = buf[MAX_TUPLE_SIZE - 1] = 0;
469 tuple.DesiredTuple = CISTPL_VERS_1; 437 tuple.DesiredTuple = CISTPL_VERS_1;
470 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 438 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
471 tuple.TupleData = buf; 439 tuple.TupleData = buf;
472 tuple.TupleDataMax = MAX_TUPLE_SIZE; 440 tuple.TupleDataMax = MAX_TUPLE_SIZE;
473 tuple.TupleOffset = 2; 441 tuple.TupleOffset = 2;
474 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 442 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
475 443
476 for (i=0; i<tuple.TupleDataLen - 4; i++) 444 for (i=0; i<tuple.TupleDataLen - 4; i++)
477 if (buf[i] == 0) buf[i] = ' '; 445 if (buf[i] == 0) buf[i] = ' ';
478 printk(KERN_INFO "ray_cs Detected: %s\n",buf); 446 printk(KERN_INFO "ray_cs Detected: %s\n",buf);
479 447
480 /* Configure card */
481 link->state |= DEV_CONFIG;
482
483 /* Now allocate an interrupt line. Note that this does not 448 /* Now allocate an interrupt line. Note that this does not
484 actually assign a handler to the interrupt. 449 actually assign a handler to the interrupt.
485 */ 450 */
486 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 451 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
487 dev->irq = link->irq.AssignedIRQ; 452 dev->irq = link->irq.AssignedIRQ;
488 453
489 /* This actually configures the PCMCIA socket -- setting up 454 /* This actually configures the PCMCIA socket -- setting up
490 the I/O windows and the interrupt mapping. 455 the I/O windows and the interrupt mapping.
491 */ 456 */
492 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 457 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
493 458
494/*** Set up 32k window for shared memory (transmit and control) ************/ 459/*** Set up 32k window for shared memory (transmit and control) ************/
495 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; 460 req.Attributes = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
496 req.Base = 0; 461 req.Base = 0;
497 req.Size = 0x8000; 462 req.Size = 0x8000;
498 req.AccessSpeed = ray_mem_speed; 463 req.AccessSpeed = ray_mem_speed;
499 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &link->win)); 464 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
500 mem.CardOffset = 0x0000; mem.Page = 0; 465 mem.CardOffset = 0x0000; mem.Page = 0;
501 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem)); 466 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
502 local->sram = ioremap(req.Base,req.Size); 467 local->sram = ioremap(req.Base,req.Size);
@@ -506,7 +471,7 @@ static void ray_config(dev_link_t *link)
506 req.Base = 0; 471 req.Base = 0;
507 req.Size = 0x4000; 472 req.Size = 0x4000;
508 req.AccessSpeed = ray_mem_speed; 473 req.AccessSpeed = ray_mem_speed;
509 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &local->rmem_handle)); 474 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->rmem_handle));
510 mem.CardOffset = 0x8000; mem.Page = 0; 475 mem.CardOffset = 0x8000; mem.Page = 0;
511 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem)); 476 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->rmem_handle, &mem));
512 local->rmem = ioremap(req.Base,req.Size); 477 local->rmem = ioremap(req.Base,req.Size);
@@ -516,7 +481,7 @@ static void ray_config(dev_link_t *link)
516 req.Base = 0; 481 req.Base = 0;
517 req.Size = 0x1000; 482 req.Size = 0x1000;
518 req.AccessSpeed = ray_mem_speed; 483 req.AccessSpeed = ray_mem_speed;
519 CS_CHECK(RequestWindow, pcmcia_request_window(&link->handle, &req, &local->amem_handle)); 484 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &local->amem_handle));
520 mem.CardOffset = 0x0000; mem.Page = 0; 485 mem.CardOffset = 0x0000; mem.Page = 0;
521 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem)); 486 CS_CHECK(MapMemPage, pcmcia_map_mem_page(local->amem_handle, &mem));
522 local->amem = ioremap(req.Base,req.Size); 487 local->amem = ioremap(req.Base,req.Size);
@@ -526,32 +491,32 @@ static void ray_config(dev_link_t *link)
526 DEBUG(3,"ray_config amem=%p\n",local->amem); 491 DEBUG(3,"ray_config amem=%p\n",local->amem);
527 if (ray_init(dev) < 0) { 492 if (ray_init(dev) < 0) {
528 ray_release(link); 493 ray_release(link);
529 return; 494 return -ENODEV;
530 } 495 }
531 496
532 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 497 SET_NETDEV_DEV(dev, &handle_to_dev(link));
533 i = register_netdev(dev); 498 i = register_netdev(dev);
534 if (i != 0) { 499 if (i != 0) {
535 printk("ray_config register_netdev() failed\n"); 500 printk("ray_config register_netdev() failed\n");
536 ray_release(link); 501 ray_release(link);
537 return; 502 return i;
538 } 503 }
539 504
540 strcpy(local->node.dev_name, dev->name); 505 strcpy(local->node.dev_name, dev->name);
541 link->dev = &local->node; 506 link->dev_node = &local->node;
542 507
543 link->state &= ~DEV_CONFIG_PENDING;
544 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ", 508 printk(KERN_INFO "%s: RayLink, irq %d, hw_addr ",
545 dev->name, dev->irq); 509 dev->name, dev->irq);
546 for (i = 0; i < 6; i++) 510 for (i = 0; i < 6; i++)
547 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n")); 511 printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
548 512
549 return; 513 return 0;
550 514
551cs_failed: 515cs_failed:
552 cs_error(link->handle, last_fn, last_ret); 516 cs_error(link, last_fn, last_ret);
553 517
554 ray_release(link); 518 ray_release(link);
519 return -ENODEV;
555} /* ray_config */ 520} /* ray_config */
556 521
557static inline struct ccs __iomem *ccs_base(ray_dev_t *dev) 522static inline struct ccs __iomem *ccs_base(ray_dev_t *dev)
@@ -578,9 +543,9 @@ static int ray_init(struct net_device *dev)
578 UCHAR *p; 543 UCHAR *p;
579 struct ccs __iomem *pccs; 544 struct ccs __iomem *pccs;
580 ray_dev_t *local = (ray_dev_t *)dev->priv; 545 ray_dev_t *local = (ray_dev_t *)dev->priv;
581 dev_link_t *link = local->finder; 546 struct pcmcia_device *link = local->finder;
582 DEBUG(1, "ray_init(0x%p)\n", dev); 547 DEBUG(1, "ray_init(0x%p)\n", dev);
583 if (!(link->state & DEV_PRESENT)) { 548 if (!(pcmcia_dev_present(link))) {
584 DEBUG(0,"ray_init - device not present\n"); 549 DEBUG(0,"ray_init - device not present\n");
585 return -1; 550 return -1;
586 } 551 }
@@ -640,10 +605,10 @@ static int dl_startup_params(struct net_device *dev)
640 int ccsindex; 605 int ccsindex;
641 ray_dev_t *local = (ray_dev_t *)dev->priv; 606 ray_dev_t *local = (ray_dev_t *)dev->priv;
642 struct ccs __iomem *pccs; 607 struct ccs __iomem *pccs;
643 dev_link_t *link = local->finder; 608 struct pcmcia_device *link = local->finder;
644 609
645 DEBUG(1,"dl_startup_params entered\n"); 610 DEBUG(1,"dl_startup_params entered\n");
646 if (!(link->state & DEV_PRESENT)) { 611 if (!(pcmcia_dev_present(link))) {
647 DEBUG(2,"ray_cs dl_startup_params - device not present\n"); 612 DEBUG(2,"ray_cs dl_startup_params - device not present\n");
648 return -1; 613 return -1;
649 } 614 }
@@ -747,9 +712,9 @@ static void verify_dl_startup(u_long data)
747 ray_dev_t *local = (ray_dev_t *)data; 712 ray_dev_t *local = (ray_dev_t *)data;
748 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs; 713 struct ccs __iomem *pccs = ccs_base(local) + local->dl_param_ccs;
749 UCHAR status; 714 UCHAR status;
750 dev_link_t *link = local->finder; 715 struct pcmcia_device *link = local->finder;
751 716
752 if (!(link->state & DEV_PRESENT)) { 717 if (!(pcmcia_dev_present(link))) {
753 DEBUG(2,"ray_cs verify_dl_startup - device not present\n"); 718 DEBUG(2,"ray_cs verify_dl_startup - device not present\n");
754 return; 719 return;
755 } 720 }
@@ -787,8 +752,8 @@ static void start_net(u_long data)
787 ray_dev_t *local = (ray_dev_t *)data; 752 ray_dev_t *local = (ray_dev_t *)data;
788 struct ccs __iomem *pccs; 753 struct ccs __iomem *pccs;
789 int ccsindex; 754 int ccsindex;
790 dev_link_t *link = local->finder; 755 struct pcmcia_device *link = local->finder;
791 if (!(link->state & DEV_PRESENT)) { 756 if (!(pcmcia_dev_present(link))) {
792 DEBUG(2,"ray_cs start_net - device not present\n"); 757 DEBUG(2,"ray_cs start_net - device not present\n");
793 return; 758 return;
794 } 759 }
@@ -814,9 +779,9 @@ static void join_net(u_long data)
814 779
815 struct ccs __iomem *pccs; 780 struct ccs __iomem *pccs;
816 int ccsindex; 781 int ccsindex;
817 dev_link_t *link = local->finder; 782 struct pcmcia_device *link = local->finder;
818 783
819 if (!(link->state & DEV_PRESENT)) { 784 if (!(pcmcia_dev_present(link))) {
820 DEBUG(2,"ray_cs join_net - device not present\n"); 785 DEBUG(2,"ray_cs join_net - device not present\n");
821 return; 786 return;
822 } 787 }
@@ -840,7 +805,7 @@ static void join_net(u_long data)
840 device, and release the PCMCIA configuration. If the device is 805 device, and release the PCMCIA configuration. If the device is
841 still open, this will be postponed until it is closed. 806 still open, this will be postponed until it is closed.
842=============================================================================*/ 807=============================================================================*/
843static void ray_release(dev_link_t *link) 808static void ray_release(struct pcmcia_device *link)
844{ 809{
845 struct net_device *dev = link->priv; 810 struct net_device *dev = link->priv;
846 ray_dev_t *local = dev->priv; 811 ray_dev_t *local = dev->priv;
@@ -849,56 +814,38 @@ static void ray_release(dev_link_t *link)
849 DEBUG(1, "ray_release(0x%p)\n", link); 814 DEBUG(1, "ray_release(0x%p)\n", link);
850 815
851 del_timer(&local->timer); 816 del_timer(&local->timer);
852 link->state &= ~DEV_CONFIG;
853 817
854 iounmap(local->sram); 818 iounmap(local->sram);
855 iounmap(local->rmem); 819 iounmap(local->rmem);
856 iounmap(local->amem); 820 iounmap(local->amem);
857 /* Do bother checking to see if these succeed or not */ 821 /* Do bother checking to see if these succeed or not */
858 i = pcmcia_release_window(link->win);
859 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(link->win) ret = %x\n",i);
860 i = pcmcia_release_window(local->amem_handle); 822 i = pcmcia_release_window(local->amem_handle);
861 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i); 823 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
862 i = pcmcia_release_window(local->rmem_handle); 824 i = pcmcia_release_window(local->rmem_handle);
863 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i); 825 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
864 i = pcmcia_release_configuration(link->handle); 826 pcmcia_disable_device(link);
865 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseConfiguration ret = %x\n",i);
866 i = pcmcia_release_irq(link->handle, &link->irq);
867 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseIRQ ret = %x\n",i);
868 827
869 DEBUG(2,"ray_release ending\n"); 828 DEBUG(2,"ray_release ending\n");
870} 829}
871 830
872static int ray_suspend(struct pcmcia_device *p_dev) 831static int ray_suspend(struct pcmcia_device *link)
873{ 832{
874 dev_link_t *link = dev_to_instance(p_dev);
875 struct net_device *dev = link->priv; 833 struct net_device *dev = link->priv;
876 834
877 link->state |= DEV_SUSPEND; 835 if (link->open)
878 if (link->state & DEV_CONFIG) { 836 netif_device_detach(dev);
879 if (link->open)
880 netif_device_detach(dev);
881
882 pcmcia_release_configuration(link->handle);
883 }
884
885 837
886 return 0; 838 return 0;
887} 839}
888 840
889static int ray_resume(struct pcmcia_device *p_dev) 841static int ray_resume(struct pcmcia_device *link)
890{ 842{
891 dev_link_t *link = dev_to_instance(p_dev);
892 struct net_device *dev = link->priv; 843 struct net_device *dev = link->priv;
893 844
894 link->state &= ~DEV_SUSPEND; 845 if (link->open) {
895 if (link->state & DEV_CONFIG) { 846 ray_reset(dev);
896 pcmcia_request_configuration(link->handle, &link->conf); 847 netif_device_attach(dev);
897 if (link->open) { 848 }
898 ray_reset(dev);
899 netif_device_attach(dev);
900 }
901 }
902 849
903 return 0; 850 return 0;
904} 851}
@@ -910,10 +857,10 @@ int ray_dev_init(struct net_device *dev)
910 int i; 857 int i;
911#endif /* RAY_IMMEDIATE_INIT */ 858#endif /* RAY_IMMEDIATE_INIT */
912 ray_dev_t *local = dev->priv; 859 ray_dev_t *local = dev->priv;
913 dev_link_t *link = local->finder; 860 struct pcmcia_device *link = local->finder;
914 861
915 DEBUG(1,"ray_dev_init(dev=%p)\n",dev); 862 DEBUG(1,"ray_dev_init(dev=%p)\n",dev);
916 if (!(link->state & DEV_PRESENT)) { 863 if (!(pcmcia_dev_present(link))) {
917 DEBUG(2,"ray_dev_init - device not present\n"); 864 DEBUG(2,"ray_dev_init - device not present\n");
918 return -1; 865 return -1;
919 } 866 }
@@ -944,10 +891,10 @@ int ray_dev_init(struct net_device *dev)
944static int ray_dev_config(struct net_device *dev, struct ifmap *map) 891static int ray_dev_config(struct net_device *dev, struct ifmap *map)
945{ 892{
946 ray_dev_t *local = dev->priv; 893 ray_dev_t *local = dev->priv;
947 dev_link_t *link = local->finder; 894 struct pcmcia_device *link = local->finder;
948 /* Dummy routine to satisfy device structure */ 895 /* Dummy routine to satisfy device structure */
949 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map); 896 DEBUG(1,"ray_dev_config(dev=%p,ifmap=%p)\n",dev,map);
950 if (!(link->state & DEV_PRESENT)) { 897 if (!(pcmcia_dev_present(link))) {
951 DEBUG(2,"ray_dev_config - device not present\n"); 898 DEBUG(2,"ray_dev_config - device not present\n");
952 return -1; 899 return -1;
953 } 900 }
@@ -958,10 +905,10 @@ static int ray_dev_config(struct net_device *dev, struct ifmap *map)
958static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev) 905static int ray_dev_start_xmit(struct sk_buff *skb, struct net_device *dev)
959{ 906{
960 ray_dev_t *local = dev->priv; 907 ray_dev_t *local = dev->priv;
961 dev_link_t *link = local->finder; 908 struct pcmcia_device *link = local->finder;
962 short length = skb->len; 909 short length = skb->len;
963 910
964 if (!(link->state & DEV_PRESENT)) { 911 if (!(pcmcia_dev_present(link))) {
965 DEBUG(2,"ray_dev_start_xmit - device not present\n"); 912 DEBUG(2,"ray_dev_start_xmit - device not present\n");
966 return -1; 913 return -1;
967 } 914 }
@@ -1570,7 +1517,7 @@ static int ray_commit(struct net_device *dev,
1570static iw_stats * ray_get_wireless_stats(struct net_device * dev) 1517static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1571{ 1518{
1572 ray_dev_t * local = (ray_dev_t *) dev->priv; 1519 ray_dev_t * local = (ray_dev_t *) dev->priv;
1573 dev_link_t *link = local->finder; 1520 struct pcmcia_device *link = local->finder;
1574 struct status __iomem *p = local->sram + STATUS_BASE; 1521 struct status __iomem *p = local->sram + STATUS_BASE;
1575 1522
1576 if(local == (ray_dev_t *) NULL) 1523 if(local == (ray_dev_t *) NULL)
@@ -1588,7 +1535,7 @@ static iw_stats * ray_get_wireless_stats(struct net_device * dev)
1588 } 1535 }
1589#endif /* WIRELESS_SPY */ 1536#endif /* WIRELESS_SPY */
1590 1537
1591 if((link->state & DEV_PRESENT)) { 1538 if(pcmcia_dev_present(link)) {
1592 local->wstats.qual.noise = readb(&p->rxnoise); 1539 local->wstats.qual.noise = readb(&p->rxnoise);
1593 local->wstats.qual.updated |= 4; 1540 local->wstats.qual.updated |= 4;
1594 } 1541 }
@@ -1657,18 +1604,14 @@ static const struct iw_handler_def ray_handler_def =
1657/*===========================================================================*/ 1604/*===========================================================================*/
1658static int ray_open(struct net_device *dev) 1605static int ray_open(struct net_device *dev)
1659{ 1606{
1660 dev_link_t *link;
1661 ray_dev_t *local = (ray_dev_t *)dev->priv; 1607 ray_dev_t *local = (ray_dev_t *)dev->priv;
1608 struct pcmcia_device *link;
1609 link = local->finder;
1662 1610
1663 DEBUG(1, "ray_open('%s')\n", dev->name); 1611 DEBUG(1, "ray_open('%s')\n", dev->name);
1664 1612
1665 for (link = dev_list; link; link = link->next) 1613 if (link->open == 0)
1666 if (link->priv == dev) break; 1614 local->num_multi = 0;
1667 if (!DEV_OK(link)) {
1668 return -ENODEV;
1669 }
1670
1671 if (link->open == 0) local->num_multi = 0;
1672 link->open++; 1615 link->open++;
1673 1616
1674 /* If the card is not started, time to start it ! - Jean II */ 1617 /* If the card is not started, time to start it ! - Jean II */
@@ -1695,15 +1638,12 @@ static int ray_open(struct net_device *dev)
1695/*===========================================================================*/ 1638/*===========================================================================*/
1696static int ray_dev_close(struct net_device *dev) 1639static int ray_dev_close(struct net_device *dev)
1697{ 1640{
1698 dev_link_t *link; 1641 ray_dev_t *local = (ray_dev_t *)dev->priv;
1642 struct pcmcia_device *link;
1643 link = local->finder;
1699 1644
1700 DEBUG(1, "ray_dev_close('%s')\n", dev->name); 1645 DEBUG(1, "ray_dev_close('%s')\n", dev->name);
1701 1646
1702 for (link = dev_list; link; link = link->next)
1703 if (link->priv == dev) break;
1704 if (link == NULL)
1705 return -ENODEV;
1706
1707 link->open--; 1647 link->open--;
1708 netif_stop_queue(dev); 1648 netif_stop_queue(dev);
1709 1649
@@ -1725,9 +1665,9 @@ static void ray_reset(struct net_device *dev) {
1725static int interrupt_ecf(ray_dev_t *local, int ccs) 1665static int interrupt_ecf(ray_dev_t *local, int ccs)
1726{ 1666{
1727 int i = 50; 1667 int i = 50;
1728 dev_link_t *link = local->finder; 1668 struct pcmcia_device *link = local->finder;
1729 1669
1730 if (!(link->state & DEV_PRESENT)) { 1670 if (!(pcmcia_dev_present(link))) {
1731 DEBUG(2,"ray_cs interrupt_ecf - device not present\n"); 1671 DEBUG(2,"ray_cs interrupt_ecf - device not present\n");
1732 return -1; 1672 return -1;
1733 } 1673 }
@@ -1752,9 +1692,9 @@ static int get_free_tx_ccs(ray_dev_t *local)
1752{ 1692{
1753 int i; 1693 int i;
1754 struct ccs __iomem *pccs = ccs_base(local); 1694 struct ccs __iomem *pccs = ccs_base(local);
1755 dev_link_t *link = local->finder; 1695 struct pcmcia_device *link = local->finder;
1756 1696
1757 if (!(link->state & DEV_PRESENT)) { 1697 if (!(pcmcia_dev_present(link))) {
1758 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n"); 1698 DEBUG(2,"ray_cs get_free_tx_ccs - device not present\n");
1759 return ECARDGONE; 1699 return ECARDGONE;
1760 } 1700 }
@@ -1783,9 +1723,9 @@ static int get_free_ccs(ray_dev_t *local)
1783{ 1723{
1784 int i; 1724 int i;
1785 struct ccs __iomem *pccs = ccs_base(local); 1725 struct ccs __iomem *pccs = ccs_base(local);
1786 dev_link_t *link = local->finder; 1726 struct pcmcia_device *link = local->finder;
1787 1727
1788 if (!(link->state & DEV_PRESENT)) { 1728 if (!(pcmcia_dev_present(link))) {
1789 DEBUG(2,"ray_cs get_free_ccs - device not present\n"); 1729 DEBUG(2,"ray_cs get_free_ccs - device not present\n");
1790 return ECARDGONE; 1730 return ECARDGONE;
1791 } 1731 }
@@ -1858,9 +1798,9 @@ static int parse_addr(char *in_str, UCHAR *out)
1858static struct net_device_stats *ray_get_stats(struct net_device *dev) 1798static struct net_device_stats *ray_get_stats(struct net_device *dev)
1859{ 1799{
1860 ray_dev_t *local = (ray_dev_t *)dev->priv; 1800 ray_dev_t *local = (ray_dev_t *)dev->priv;
1861 dev_link_t *link = local->finder; 1801 struct pcmcia_device *link = local->finder;
1862 struct status __iomem *p = local->sram + STATUS_BASE; 1802 struct status __iomem *p = local->sram + STATUS_BASE;
1863 if (!(link->state & DEV_PRESENT)) { 1803 if (!(pcmcia_dev_present(link))) {
1864 DEBUG(2,"ray_cs net_device_stats - device not present\n"); 1804 DEBUG(2,"ray_cs net_device_stats - device not present\n");
1865 return &local->stats; 1805 return &local->stats;
1866 } 1806 }
@@ -1888,12 +1828,12 @@ static struct net_device_stats *ray_get_stats(struct net_device *dev)
1888static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len) 1828static void ray_update_parm(struct net_device *dev, UCHAR objid, UCHAR *value, int len)
1889{ 1829{
1890 ray_dev_t *local = (ray_dev_t *)dev->priv; 1830 ray_dev_t *local = (ray_dev_t *)dev->priv;
1891 dev_link_t *link = local->finder; 1831 struct pcmcia_device *link = local->finder;
1892 int ccsindex; 1832 int ccsindex;
1893 int i; 1833 int i;
1894 struct ccs __iomem *pccs; 1834 struct ccs __iomem *pccs;
1895 1835
1896 if (!(link->state & DEV_PRESENT)) { 1836 if (!(pcmcia_dev_present(link))) {
1897 DEBUG(2,"ray_update_parm - device not present\n"); 1837 DEBUG(2,"ray_update_parm - device not present\n");
1898 return; 1838 return;
1899 } 1839 }
@@ -1925,10 +1865,10 @@ static void ray_update_multi_list(struct net_device *dev, int all)
1925 struct ccs __iomem *pccs; 1865 struct ccs __iomem *pccs;
1926 int i = 0; 1866 int i = 0;
1927 ray_dev_t *local = (ray_dev_t *)dev->priv; 1867 ray_dev_t *local = (ray_dev_t *)dev->priv;
1928 dev_link_t *link = local->finder; 1868 struct pcmcia_device *link = local->finder;
1929 void __iomem *p = local->sram + HOST_TO_ECF_BASE; 1869 void __iomem *p = local->sram + HOST_TO_ECF_BASE;
1930 1870
1931 if (!(link->state & DEV_PRESENT)) { 1871 if (!(pcmcia_dev_present(link))) {
1932 DEBUG(2,"ray_update_multi_list - device not present\n"); 1872 DEBUG(2,"ray_update_multi_list - device not present\n");
1933 return; 1873 return;
1934 } 1874 }
@@ -2005,7 +1945,7 @@ static void set_multicast_list(struct net_device *dev)
2005static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs) 1945static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2006{ 1946{
2007 struct net_device *dev = (struct net_device *)dev_id; 1947 struct net_device *dev = (struct net_device *)dev_id;
2008 dev_link_t *link; 1948 struct pcmcia_device *link;
2009 ray_dev_t *local; 1949 ray_dev_t *local;
2010 struct ccs __iomem *pccs; 1950 struct ccs __iomem *pccs;
2011 struct rcs __iomem *prcs; 1951 struct rcs __iomem *prcs;
@@ -2020,8 +1960,8 @@ static irqreturn_t ray_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2020 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev); 1960 DEBUG(4,"ray_cs: interrupt for *dev=%p\n",dev);
2021 1961
2022 local = (ray_dev_t *)dev->priv; 1962 local = (ray_dev_t *)dev->priv;
2023 link = (dev_link_t *)local->finder; 1963 link = (struct pcmcia_device *)local->finder;
2024 if ( ! (link->state & DEV_PRESENT) || link->state & DEV_SUSPEND ) { 1964 if (!pcmcia_dev_present(link)) {
2025 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n"); 1965 DEBUG(2,"ray_cs interrupt from device not present or suspended.\n");
2026 return IRQ_NONE; 1966 return IRQ_NONE;
2027 } 1967 }
@@ -2540,9 +2480,9 @@ static void release_frag_chain(ray_dev_t *local, struct rcs __iomem * prcs)
2540/*===========================================================================*/ 2480/*===========================================================================*/
2541static void authenticate(ray_dev_t *local) 2481static void authenticate(ray_dev_t *local)
2542{ 2482{
2543 dev_link_t *link = local->finder; 2483 struct pcmcia_device *link = local->finder;
2544 DEBUG(0,"ray_cs Starting authentication.\n"); 2484 DEBUG(0,"ray_cs Starting authentication.\n");
2545 if (!(link->state & DEV_PRESENT)) { 2485 if (!(pcmcia_dev_present(link))) {
2546 DEBUG(2,"ray_cs authenticate - device not present\n"); 2486 DEBUG(2,"ray_cs authenticate - device not present\n");
2547 return; 2487 return;
2548 } 2488 }
@@ -2606,10 +2546,10 @@ static void rx_authenticate(ray_dev_t *local, struct rcs __iomem *prcs,
2606static void associate(ray_dev_t *local) 2546static void associate(ray_dev_t *local)
2607{ 2547{
2608 struct ccs __iomem *pccs; 2548 struct ccs __iomem *pccs;
2609 dev_link_t *link = local->finder; 2549 struct pcmcia_device *link = local->finder;
2610 struct net_device *dev = link->priv; 2550 struct net_device *dev = link->priv;
2611 int ccsindex; 2551 int ccsindex;
2612 if (!(link->state & DEV_PRESENT)) { 2552 if (!(pcmcia_dev_present(link))) {
2613 DEBUG(2,"ray_cs associate - device not present\n"); 2553 DEBUG(2,"ray_cs associate - device not present\n");
2614 return; 2554 return;
2615 } 2555 }
@@ -2689,14 +2629,14 @@ static int ray_cs_proc_read(char *buf, char **start, off_t offset, int len)
2689 * eg ifconfig 2629 * eg ifconfig
2690 */ 2630 */
2691 int i; 2631 int i;
2692 dev_link_t *link; 2632 struct pcmcia_device *link;
2693 struct net_device *dev; 2633 struct net_device *dev;
2694 ray_dev_t *local; 2634 ray_dev_t *local;
2695 UCHAR *p; 2635 UCHAR *p;
2696 struct freq_hop_element *pfh; 2636 struct freq_hop_element *pfh;
2697 UCHAR c[33]; 2637 UCHAR c[33];
2698 2638
2699 link = dev_list; 2639 link = this_device;
2700 if (!link) 2640 if (!link)
2701 return 0; 2641 return 0;
2702 dev = (struct net_device *)link->priv; 2642 dev = (struct net_device *)link->priv;
@@ -2898,7 +2838,7 @@ static struct pcmcia_driver ray_driver = {
2898 .drv = { 2838 .drv = {
2899 .name = "ray_cs", 2839 .name = "ray_cs",
2900 }, 2840 },
2901 .probe = ray_attach, 2841 .probe = ray_probe,
2902 .remove = ray_detach, 2842 .remove = ray_detach,
2903 .id_table = ray_ids, 2843 .id_table = ray_ids,
2904 .suspend = ray_suspend, 2844 .suspend = ray_suspend,
@@ -2940,7 +2880,6 @@ static void __exit exit_ray_cs(void)
2940#endif 2880#endif
2941 2881
2942 pcmcia_unregister_driver(&ray_driver); 2882 pcmcia_unregister_driver(&ray_driver);
2943 BUG_ON(dev_list != NULL);
2944} /* exit_ray_cs */ 2883} /* exit_ray_cs */
2945 2884
2946module_init(init_ray_cs); 2885module_init(init_ray_cs);
diff --git a/drivers/net/wireless/ray_cs.h b/drivers/net/wireless/ray_cs.h
index 42660fe64bfd..bd73ebf03340 100644
--- a/drivers/net/wireless/ray_cs.h
+++ b/drivers/net/wireless/ray_cs.h
@@ -31,7 +31,7 @@ typedef struct ray_dev_t {
31 void __iomem *sram; /* pointer to beginning of shared RAM */ 31 void __iomem *sram; /* pointer to beginning of shared RAM */
32 void __iomem *amem; /* pointer to attribute mem window */ 32 void __iomem *amem; /* pointer to attribute mem window */
33 void __iomem *rmem; /* pointer to receive buffer window */ 33 void __iomem *rmem; /* pointer to receive buffer window */
34 dev_link_t *finder; /* pointer back to dev_link_t for card */ 34 struct pcmcia_device *finder; /* pointer back to struct pcmcia_device for card */
35 struct timer_list timer; 35 struct timer_list timer;
36 long tx_ccs_lock; 36 long tx_ccs_lock;
37 long ccs_lock; 37 long ccs_lock;
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index 5fa6fbe35bb9..f7b77ce54d7b 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -63,7 +63,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
63/* PCMCIA specific device information (goes in the card field of 63/* PCMCIA specific device information (goes in the card field of
64 * struct orinoco_private */ 64 * struct orinoco_private */
65struct orinoco_pccard { 65struct orinoco_pccard {
66 dev_link_t link; 66 struct pcmcia_device *p_dev;
67 dev_node_t node; 67 dev_node_t node;
68}; 68};
69 69
@@ -71,8 +71,8 @@ struct orinoco_pccard {
71/* Function prototypes */ 71/* Function prototypes */
72/********************************************************************/ 72/********************************************************************/
73 73
74static void spectrum_cs_config(dev_link_t *link); 74static int spectrum_cs_config(struct pcmcia_device *link);
75static void spectrum_cs_release(dev_link_t *link); 75static void spectrum_cs_release(struct pcmcia_device *link);
76 76
77/********************************************************************/ 77/********************************************************************/
78/* Firmware downloader */ 78/* Firmware downloader */
@@ -238,14 +238,14 @@ spectrum_aux_open(hermes_t *hw)
238 * If IDLE is 1, stop the firmware, so that it can be safely rewritten. 238 * If IDLE is 1, stop the firmware, so that it can be safely rewritten.
239 */ 239 */
240static int 240static int
241spectrum_reset(dev_link_t *link, int idle) 241spectrum_reset(struct pcmcia_device *link, int idle)
242{ 242{
243 int last_ret, last_fn; 243 int last_ret, last_fn;
244 conf_reg_t reg; 244 conf_reg_t reg;
245 u_int save_cor; 245 u_int save_cor;
246 246
247 /* Doing it if hardware is gone is guaranteed crash */ 247 /* Doing it if hardware is gone is guaranteed crash */
248 if (!(link->state & DEV_CONFIG)) 248 if (pcmcia_dev_present(link))
249 return -ENODEV; 249 return -ENODEV;
250 250
251 /* Save original COR value */ 251 /* Save original COR value */
@@ -253,7 +253,7 @@ spectrum_reset(dev_link_t *link, int idle)
253 reg.Action = CS_READ; 253 reg.Action = CS_READ;
254 reg.Offset = CISREG_COR; 254 reg.Offset = CISREG_COR;
255 CS_CHECK(AccessConfigurationRegister, 255 CS_CHECK(AccessConfigurationRegister,
256 pcmcia_access_configuration_register(link->handle, &reg)); 256 pcmcia_access_configuration_register(link, &reg));
257 save_cor = reg.Value; 257 save_cor = reg.Value;
258 258
259 /* Soft-Reset card */ 259 /* Soft-Reset card */
@@ -261,14 +261,14 @@ spectrum_reset(dev_link_t *link, int idle)
261 reg.Offset = CISREG_COR; 261 reg.Offset = CISREG_COR;
262 reg.Value = (save_cor | COR_SOFT_RESET); 262 reg.Value = (save_cor | COR_SOFT_RESET);
263 CS_CHECK(AccessConfigurationRegister, 263 CS_CHECK(AccessConfigurationRegister,
264 pcmcia_access_configuration_register(link->handle, &reg)); 264 pcmcia_access_configuration_register(link, &reg));
265 udelay(1000); 265 udelay(1000);
266 266
267 /* Read CCSR */ 267 /* Read CCSR */
268 reg.Action = CS_READ; 268 reg.Action = CS_READ;
269 reg.Offset = CISREG_CCSR; 269 reg.Offset = CISREG_CCSR;
270 CS_CHECK(AccessConfigurationRegister, 270 CS_CHECK(AccessConfigurationRegister,
271 pcmcia_access_configuration_register(link->handle, &reg)); 271 pcmcia_access_configuration_register(link, &reg));
272 272
273 /* 273 /*
274 * Start or stop the firmware. Memory width bit should be 274 * Start or stop the firmware. Memory width bit should be
@@ -278,7 +278,7 @@ spectrum_reset(dev_link_t *link, int idle)
278 reg.Offset = CISREG_CCSR; 278 reg.Offset = CISREG_CCSR;
279 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16); 279 reg.Value = (idle ? HCR_IDLE : HCR_RUN) | (reg.Value & HCR_MEM16);
280 CS_CHECK(AccessConfigurationRegister, 280 CS_CHECK(AccessConfigurationRegister,
281 pcmcia_access_configuration_register(link->handle, &reg)); 281 pcmcia_access_configuration_register(link, &reg));
282 udelay(1000); 282 udelay(1000);
283 283
284 /* Restore original COR configuration index */ 284 /* Restore original COR configuration index */
@@ -286,12 +286,12 @@ spectrum_reset(dev_link_t *link, int idle)
286 reg.Offset = CISREG_COR; 286 reg.Offset = CISREG_COR;
287 reg.Value = (save_cor & ~COR_SOFT_RESET); 287 reg.Value = (save_cor & ~COR_SOFT_RESET);
288 CS_CHECK(AccessConfigurationRegister, 288 CS_CHECK(AccessConfigurationRegister,
289 pcmcia_access_configuration_register(link->handle, &reg)); 289 pcmcia_access_configuration_register(link, &reg));
290 udelay(1000); 290 udelay(1000);
291 return 0; 291 return 0;
292 292
293 cs_failed: 293 cs_failed:
294 cs_error(link->handle, last_fn, last_ret); 294 cs_error(link, last_fn, last_ret);
295 return -ENODEV; 295 return -ENODEV;
296} 296}
297 297
@@ -441,7 +441,7 @@ spectrum_load_blocks(hermes_t *hw, const struct dblock *first_block)
441 * care of the PDA - read it and then write it on top of the firmware. 441 * care of the PDA - read it and then write it on top of the firmware.
442 */ 442 */
443static int 443static int
444spectrum_dl_image(hermes_t *hw, dev_link_t *link, 444spectrum_dl_image(hermes_t *hw, struct pcmcia_device *link,
445 const unsigned char *image) 445 const unsigned char *image)
446{ 446{
447 int ret; 447 int ret;
@@ -505,14 +505,13 @@ spectrum_dl_image(hermes_t *hw, dev_link_t *link,
505 * reset on the card, to make sure it's in a sane state. 505 * reset on the card, to make sure it's in a sane state.
506 */ 506 */
507static int 507static int
508spectrum_dl_firmware(hermes_t *hw, dev_link_t *link) 508spectrum_dl_firmware(hermes_t *hw, struct pcmcia_device *link)
509{ 509{
510 int ret; 510 int ret;
511 client_handle_t handle = link->handle;
512 const struct firmware *fw_entry; 511 const struct firmware *fw_entry;
513 512
514 if (request_firmware(&fw_entry, primary_fw_name, 513 if (request_firmware(&fw_entry, primary_fw_name,
515 &handle_to_dev(handle)) == 0) { 514 &handle_to_dev(link)) == 0) {
516 primsym = fw_entry->data; 515 primsym = fw_entry->data;
517 } else { 516 } else {
518 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 517 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
@@ -521,7 +520,7 @@ spectrum_dl_firmware(hermes_t *hw, dev_link_t *link)
521 } 520 }
522 521
523 if (request_firmware(&fw_entry, secondary_fw_name, 522 if (request_firmware(&fw_entry, secondary_fw_name,
524 &handle_to_dev(handle)) == 0) { 523 &handle_to_dev(link)) == 0) {
525 secsym = fw_entry->data; 524 secsym = fw_entry->data;
526 } else { 525 } else {
527 printk(KERN_ERR PFX "Cannot find firmware: %s\n", 526 printk(KERN_ERR PFX "Cannot find firmware: %s\n",
@@ -554,12 +553,12 @@ static int
554spectrum_cs_hard_reset(struct orinoco_private *priv) 553spectrum_cs_hard_reset(struct orinoco_private *priv)
555{ 554{
556 struct orinoco_pccard *card = priv->card; 555 struct orinoco_pccard *card = priv->card;
557 dev_link_t *link = &card->link; 556 struct pcmcia_device *link = card->p_dev;
558 int err; 557 int err;
559 558
560 if (!hermes_present(&priv->hw)) { 559 if (!hermes_present(&priv->hw)) {
561 /* The firmware needs to be reloaded */ 560 /* The firmware needs to be reloaded */
562 if (spectrum_dl_firmware(&priv->hw, &card->link) != 0) { 561 if (spectrum_dl_firmware(&priv->hw, link) != 0) {
563 printk(KERN_ERR PFX "Firmware download failed\n"); 562 printk(KERN_ERR PFX "Firmware download failed\n");
564 err = -ENODEV; 563 err = -ENODEV;
565 } 564 }
@@ -584,12 +583,11 @@ spectrum_cs_hard_reset(struct orinoco_private *priv)
584 * configure the card at this point -- we wait until we receive a card 583 * configure the card at this point -- we wait until we receive a card
585 * insertion event. */ 584 * insertion event. */
586static int 585static int
587spectrum_cs_attach(struct pcmcia_device *p_dev) 586spectrum_cs_probe(struct pcmcia_device *link)
588{ 587{
589 struct net_device *dev; 588 struct net_device *dev;
590 struct orinoco_private *priv; 589 struct orinoco_private *priv;
591 struct orinoco_pccard *card; 590 struct orinoco_pccard *card;
592 dev_link_t *link;
593 591
594 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset); 592 dev = alloc_orinocodev(sizeof(*card), spectrum_cs_hard_reset);
595 if (! dev) 593 if (! dev)
@@ -598,7 +596,7 @@ spectrum_cs_attach(struct pcmcia_device *p_dev)
598 card = priv->card; 596 card = priv->card;
599 597
600 /* Link both structures together */ 598 /* Link both structures together */
601 link = &card->link; 599 card->p_dev = link;
602 link->priv = dev; 600 link->priv = dev;
603 601
604 /* Interrupt setup */ 602 /* Interrupt setup */
@@ -615,13 +613,7 @@ spectrum_cs_attach(struct pcmcia_device *p_dev)
615 link->conf.Attributes = 0; 613 link->conf.Attributes = 0;
616 link->conf.IntType = INT_MEMORY_AND_IO; 614 link->conf.IntType = INT_MEMORY_AND_IO;
617 615
618 link->handle = p_dev; 616 return spectrum_cs_config(link);
619 p_dev->instance = link;
620
621 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
622 spectrum_cs_config(link);
623
624 return 0;
625} /* spectrum_cs_attach */ 617} /* spectrum_cs_attach */
626 618
627/* 619/*
@@ -630,16 +622,14 @@ spectrum_cs_attach(struct pcmcia_device *p_dev)
630 * are freed. Otherwise, the structures will be freed when the device 622 * are freed. Otherwise, the structures will be freed when the device
631 * is released. 623 * is released.
632 */ 624 */
633static void spectrum_cs_detach(struct pcmcia_device *p_dev) 625static void spectrum_cs_detach(struct pcmcia_device *link)
634{ 626{
635 dev_link_t *link = dev_to_instance(p_dev);
636 struct net_device *dev = link->priv; 627 struct net_device *dev = link->priv;
637 628
638 if (link->state & DEV_CONFIG) 629 spectrum_cs_release(link);
639 spectrum_cs_release(link);
640 630
641 DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev); 631 DEBUG(0, PFX "detach: link=%p link->dev_node=%p\n", link, link->dev_node);
642 if (link->dev) { 632 if (link->dev_node) {
643 DEBUG(0, PFX "About to unregister net device %p\n", 633 DEBUG(0, PFX "About to unregister net device %p\n",
644 dev); 634 dev);
645 unregister_netdev(dev); 635 unregister_netdev(dev);
@@ -653,11 +643,10 @@ static void spectrum_cs_detach(struct pcmcia_device *p_dev)
653 * device available to the system. 643 * device available to the system.
654 */ 644 */
655 645
656static void 646static int
657spectrum_cs_config(dev_link_t *link) 647spectrum_cs_config(struct pcmcia_device *link)
658{ 648{
659 struct net_device *dev = link->priv; 649 struct net_device *dev = link->priv;
660 client_handle_t handle = link->handle;
661 struct orinoco_private *priv = netdev_priv(dev); 650 struct orinoco_private *priv = netdev_priv(dev);
662 struct orinoco_pccard *card = priv->card; 651 struct orinoco_pccard *card = priv->card;
663 hermes_t *hw = &priv->hw; 652 hermes_t *hw = &priv->hw;
@@ -669,7 +658,7 @@ spectrum_cs_config(dev_link_t *link)
669 cisparse_t parse; 658 cisparse_t parse;
670 void __iomem *mem; 659 void __iomem *mem;
671 660
672 CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info)); 661 CS_CHECK(ValidateCIS, pcmcia_validate_cis(link, &info));
673 662
674 /* 663 /*
675 * This reads the card's CONFIG tuple to find its 664 * This reads the card's CONFIG tuple to find its
@@ -680,19 +669,15 @@ spectrum_cs_config(dev_link_t *link)
680 tuple.TupleData = buf; 669 tuple.TupleData = buf;
681 tuple.TupleDataMax = sizeof(buf); 670 tuple.TupleDataMax = sizeof(buf);
682 tuple.TupleOffset = 0; 671 tuple.TupleOffset = 0;
683 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 672 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
684 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 673 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
685 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 674 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
686 link->conf.ConfigBase = parse.config.base; 675 link->conf.ConfigBase = parse.config.base;
687 link->conf.Present = parse.config.rmask[0]; 676 link->conf.Present = parse.config.rmask[0];
688 677
689 /* Configure card */
690 link->state |= DEV_CONFIG;
691
692 /* Look up the current Vcc */ 678 /* Look up the current Vcc */
693 CS_CHECK(GetConfigurationInfo, 679 CS_CHECK(GetConfigurationInfo,
694 pcmcia_get_configuration_info(handle, &conf)); 680 pcmcia_get_configuration_info(link, &conf));
695 link->conf.Vcc = conf.Vcc;
696 681
697 /* 682 /*
698 * In this loop, we scan the CIS for configuration table 683 * In this loop, we scan the CIS for configuration table
@@ -709,13 +694,13 @@ spectrum_cs_config(dev_link_t *link)
709 * implementation-defined details. 694 * implementation-defined details.
710 */ 695 */
711 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 696 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
712 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 697 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
713 while (1) { 698 while (1) {
714 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 699 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
715 cistpl_cftable_entry_t dflt = { .index = 0 }; 700 cistpl_cftable_entry_t dflt = { .index = 0 };
716 701
717 if ( (pcmcia_get_tuple_data(handle, &tuple) != 0) 702 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
718 || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0)) 703 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
719 goto next_entry; 704 goto next_entry;
720 705
721 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 706 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
@@ -747,10 +732,10 @@ spectrum_cs_config(dev_link_t *link)
747 } 732 }
748 733
749 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 734 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
750 link->conf.Vpp1 = link->conf.Vpp2 = 735 link->conf.Vpp =
751 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 736 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
752 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 737 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
753 link->conf.Vpp1 = link->conf.Vpp2 = 738 link->conf.Vpp =
754 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 739 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
755 740
756 /* Do we need to allocate an interrupt? */ 741 /* Do we need to allocate an interrupt? */
@@ -780,7 +765,7 @@ spectrum_cs_config(dev_link_t *link)
780 } 765 }
781 766
782 /* This reserves IO space but doesn't actually enable it */ 767 /* This reserves IO space but doesn't actually enable it */
783 if (pcmcia_request_io(link->handle, &link->io) != 0) 768 if (pcmcia_request_io(link, &link->io) != 0)
784 goto next_entry; 769 goto next_entry;
785 } 770 }
786 771
@@ -790,9 +775,8 @@ spectrum_cs_config(dev_link_t *link)
790 break; 775 break;
791 776
792 next_entry: 777 next_entry:
793 if (link->io.NumPorts1) 778 pcmcia_disable_device(link);
794 pcmcia_release_io(link->handle, &link->io); 779 last_ret = pcmcia_get_next_tuple(link, &tuple);
795 last_ret = pcmcia_get_next_tuple(handle, &tuple);
796 if (last_ret == CS_NO_MORE_ITEMS) { 780 if (last_ret == CS_NO_MORE_ITEMS) {
797 printk(KERN_ERR PFX "GetNextTuple(): No matching " 781 printk(KERN_ERR PFX "GetNextTuple(): No matching "
798 "CIS configuration. Maybe you need the " 782 "CIS configuration. Maybe you need the "
@@ -806,7 +790,7 @@ spectrum_cs_config(dev_link_t *link)
806 * a handler to the interrupt, unless the 'Handler' member of 790 * a handler to the interrupt, unless the 'Handler' member of
807 * the irq structure is initialized. 791 * the irq structure is initialized.
808 */ 792 */
809 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 793 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
810 794
811 /* We initialize the hermes structure before completing PCMCIA 795 /* We initialize the hermes structure before completing PCMCIA
812 * configuration just in case the interrupt handler gets 796 * configuration just in case the interrupt handler gets
@@ -823,7 +807,7 @@ spectrum_cs_config(dev_link_t *link)
823 * card and host interface into "Memory and IO" mode. 807 * card and host interface into "Memory and IO" mode.
824 */ 808 */
825 CS_CHECK(RequestConfiguration, 809 CS_CHECK(RequestConfiguration,
826 pcmcia_request_configuration(link->handle, &link->conf)); 810 pcmcia_request_configuration(link, &link->conf));
827 811
828 /* Ok, we have the configuration, prepare to register the netdev */ 812 /* Ok, we have the configuration, prepare to register the netdev */
829 dev->base_addr = link->io.BasePort1; 813 dev->base_addr = link->io.BasePort1;
@@ -836,7 +820,7 @@ spectrum_cs_config(dev_link_t *link)
836 goto failed; 820 goto failed;
837 } 821 }
838 822
839 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 823 SET_NETDEV_DEV(dev, &handle_to_dev(link));
840 /* Tell the stack we exist */ 824 /* Tell the stack we exist */
841 if (register_netdev(dev) != 0) { 825 if (register_netdev(dev) != 0) {
842 printk(KERN_ERR PFX "register_netdev() failed\n"); 826 printk(KERN_ERR PFX "register_netdev() failed\n");
@@ -844,20 +828,18 @@ spectrum_cs_config(dev_link_t *link)
844 } 828 }
845 829
846 /* At this point, the dev_node_t structure(s) needs to be 830 /* At this point, the dev_node_t structure(s) needs to be
847 * initialized and arranged in a linked list at link->dev. */ 831 * initialized and arranged in a linked list at link->dev_node. */
848 strcpy(card->node.dev_name, dev->name); 832 strcpy(card->node.dev_name, dev->name);
849 link->dev = &card->node; /* link->dev being non-NULL is also 833 link->dev_node = &card->node; /* link->dev_node being non-NULL is also
850 used to indicate that the 834 used to indicate that the
851 net_device has been registered */ 835 net_device has been registered */
852 link->state &= ~DEV_CONFIG_PENDING;
853 836
854 /* Finally, report what we've done */ 837 /* Finally, report what we've done */
855 printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d", 838 printk(KERN_DEBUG "%s: index 0x%02x: ",
856 dev->name, link->conf.ConfigIndex, 839 dev->name, link->conf.ConfigIndex);
857 link->conf.Vcc / 10, link->conf.Vcc % 10); 840 if (link->conf.Vpp)
858 if (link->conf.Vpp1) 841 printk(", Vpp %d.%d", link->conf.Vpp / 10,
859 printk(", Vpp %d.%d", link->conf.Vpp1 / 10, 842 link->conf.Vpp % 10);
860 link->conf.Vpp1 % 10);
861 printk(", irq %d", link->irq.AssignedIRQ); 843 printk(", irq %d", link->irq.AssignedIRQ);
862 if (link->io.NumPorts1) 844 if (link->io.NumPorts1)
863 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 845 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
@@ -867,13 +849,14 @@ spectrum_cs_config(dev_link_t *link)
867 link->io.BasePort2 + link->io.NumPorts2 - 1); 849 link->io.BasePort2 + link->io.NumPorts2 - 1);
868 printk("\n"); 850 printk("\n");
869 851
870 return; 852 return 0;
871 853
872 cs_failed: 854 cs_failed:
873 cs_error(link->handle, last_fn, last_ret); 855 cs_error(link, last_fn, last_ret);
874 856
875 failed: 857 failed:
876 spectrum_cs_release(link); 858 spectrum_cs_release(link);
859 return -ENODEV;
877} /* spectrum_cs_config */ 860} /* spectrum_cs_config */
878 861
879/* 862/*
@@ -882,7 +865,7 @@ spectrum_cs_config(dev_link_t *link)
882 * still open, this will be postponed until it is closed. 865 * still open, this will be postponed until it is closed.
883 */ 866 */
884static void 867static void
885spectrum_cs_release(dev_link_t *link) 868spectrum_cs_release(struct pcmcia_device *link)
886{ 869{
887 struct net_device *dev = link->priv; 870 struct net_device *dev = link->priv;
888 struct orinoco_private *priv = netdev_priv(dev); 871 struct orinoco_private *priv = netdev_priv(dev);
@@ -894,64 +877,46 @@ spectrum_cs_release(dev_link_t *link)
894 priv->hw_unavailable++; 877 priv->hw_unavailable++;
895 spin_unlock_irqrestore(&priv->lock, flags); 878 spin_unlock_irqrestore(&priv->lock, flags);
896 879
897 /* Don't bother checking to see if these succeed or not */ 880 pcmcia_disable_device(link);
898 pcmcia_release_configuration(link->handle);
899 if (link->io.NumPorts1)
900 pcmcia_release_io(link->handle, &link->io);
901 if (link->irq.AssignedIRQ)
902 pcmcia_release_irq(link->handle, &link->irq);
903 link->state &= ~DEV_CONFIG;
904 if (priv->hw.iobase) 881 if (priv->hw.iobase)
905 ioport_unmap(priv->hw.iobase); 882 ioport_unmap(priv->hw.iobase);
906} /* spectrum_cs_release */ 883} /* spectrum_cs_release */
907 884
908 885
909static int 886static int
910spectrum_cs_suspend(struct pcmcia_device *p_dev) 887spectrum_cs_suspend(struct pcmcia_device *link)
911{ 888{
912 dev_link_t *link = dev_to_instance(p_dev);
913 struct net_device *dev = link->priv; 889 struct net_device *dev = link->priv;
914 struct orinoco_private *priv = netdev_priv(dev); 890 struct orinoco_private *priv = netdev_priv(dev);
915 unsigned long flags; 891 unsigned long flags;
916 int err = 0; 892 int err = 0;
917 893
918 link->state |= DEV_SUSPEND;
919 /* Mark the device as stopped, to block IO until later */ 894 /* Mark the device as stopped, to block IO until later */
920 if (link->state & DEV_CONFIG) { 895 spin_lock_irqsave(&priv->lock, flags);
921 spin_lock_irqsave(&priv->lock, flags);
922
923 err = __orinoco_down(dev);
924 if (err)
925 printk(KERN_WARNING "%s: Error %d downing interface\n",
926 dev->name, err);
927 896
928 netif_device_detach(dev); 897 err = __orinoco_down(dev);
929 priv->hw_unavailable++; 898 if (err)
899 printk(KERN_WARNING "%s: Error %d downing interface\n",
900 dev->name, err);
930 901
931 spin_unlock_irqrestore(&priv->lock, flags); 902 netif_device_detach(dev);
903 priv->hw_unavailable++;
932 904
933 pcmcia_release_configuration(link->handle); 905 spin_unlock_irqrestore(&priv->lock, flags);
934 }
935 906
936 return 0; 907 return 0;
937} 908}
938 909
939static int 910static int
940spectrum_cs_resume(struct pcmcia_device *p_dev) 911spectrum_cs_resume(struct pcmcia_device *link)
941{ 912{
942 dev_link_t *link = dev_to_instance(p_dev);
943 struct net_device *dev = link->priv; 913 struct net_device *dev = link->priv;
944 struct orinoco_private *priv = netdev_priv(dev); 914 struct orinoco_private *priv = netdev_priv(dev);
945 915
946 link->state &= ~DEV_SUSPEND; 916 netif_device_attach(dev);
947 if (link->state & DEV_CONFIG) { 917 priv->hw_unavailable--;
948 /* FIXME: should we double check that this is 918 schedule_work(&priv->reset_work);
949 * the same card as we had before */ 919
950 pcmcia_request_configuration(link->handle, &link->conf);
951 netif_device_attach(dev);
952 priv->hw_unavailable--;
953 schedule_work(&priv->reset_work);
954 }
955 return 0; 920 return 0;
956} 921}
957 922
@@ -979,7 +944,7 @@ static struct pcmcia_driver orinoco_driver = {
979 .drv = { 944 .drv = {
980 .name = DRIVER_NAME, 945 .name = DRIVER_NAME,
981 }, 946 },
982 .probe = spectrum_cs_attach, 947 .probe = spectrum_cs_probe,
983 .remove = spectrum_cs_detach, 948 .remove = spectrum_cs_detach,
984 .suspend = spectrum_cs_suspend, 949 .suspend = spectrum_cs_suspend,
985 .resume = spectrum_cs_resume, 950 .resume = spectrum_cs_resume,
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 98122f3a4bc2..f7724eb2fa7e 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -1005,7 +1005,7 @@ static inline void
1005wv_82593_reconfig(struct net_device * dev) 1005wv_82593_reconfig(struct net_device * dev)
1006{ 1006{
1007 net_local * lp = netdev_priv(dev); 1007 net_local * lp = netdev_priv(dev);
1008 dev_link_t * link = lp->link; 1008 struct pcmcia_device * link = lp->link;
1009 unsigned long flags; 1009 unsigned long flags;
1010 1010
1011 /* Arm the flag, will be cleard in wv_82593_config() */ 1011 /* Arm the flag, will be cleard in wv_82593_config() */
@@ -3744,16 +3744,16 @@ wv_pcmcia_reset(struct net_device * dev)
3744{ 3744{
3745 int i; 3745 int i;
3746 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 }; 3746 conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
3747 dev_link_t * link = ((net_local *)netdev_priv(dev))->link; 3747 struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
3748 3748
3749#ifdef DEBUG_CONFIG_TRACE 3749#ifdef DEBUG_CONFIG_TRACE
3750 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name); 3750 printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
3751#endif 3751#endif
3752 3752
3753 i = pcmcia_access_configuration_register(link->handle, &reg); 3753 i = pcmcia_access_configuration_register(link, &reg);
3754 if(i != CS_SUCCESS) 3754 if(i != CS_SUCCESS)
3755 { 3755 {
3756 cs_error(link->handle, AccessConfigurationRegister, i); 3756 cs_error(link, AccessConfigurationRegister, i);
3757 return FALSE; 3757 return FALSE;
3758 } 3758 }
3759 3759
@@ -3764,19 +3764,19 @@ wv_pcmcia_reset(struct net_device * dev)
3764 3764
3765 reg.Action = CS_WRITE; 3765 reg.Action = CS_WRITE;
3766 reg.Value = reg.Value | COR_SW_RESET; 3766 reg.Value = reg.Value | COR_SW_RESET;
3767 i = pcmcia_access_configuration_register(link->handle, &reg); 3767 i = pcmcia_access_configuration_register(link, &reg);
3768 if(i != CS_SUCCESS) 3768 if(i != CS_SUCCESS)
3769 { 3769 {
3770 cs_error(link->handle, AccessConfigurationRegister, i); 3770 cs_error(link, AccessConfigurationRegister, i);
3771 return FALSE; 3771 return FALSE;
3772 } 3772 }
3773 3773
3774 reg.Action = CS_WRITE; 3774 reg.Action = CS_WRITE;
3775 reg.Value = COR_LEVEL_IRQ | COR_CONFIG; 3775 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3776 i = pcmcia_access_configuration_register(link->handle, &reg); 3776 i = pcmcia_access_configuration_register(link, &reg);
3777 if(i != CS_SUCCESS) 3777 if(i != CS_SUCCESS)
3778 { 3778 {
3779 cs_error(link->handle, AccessConfigurationRegister, i); 3779 cs_error(link, AccessConfigurationRegister, i);
3780 return FALSE; 3780 return FALSE;
3781 } 3781 }
3782 3782
@@ -3940,9 +3940,8 @@ wv_hw_reset(struct net_device * dev)
3940 * (called by wavelan_event()) 3940 * (called by wavelan_event())
3941 */ 3941 */
3942static inline int 3942static inline int
3943wv_pcmcia_config(dev_link_t * link) 3943wv_pcmcia_config(struct pcmcia_device * link)
3944{ 3944{
3945 client_handle_t handle = link->handle;
3946 tuple_t tuple; 3945 tuple_t tuple;
3947 cisparse_t parse; 3946 cisparse_t parse;
3948 struct net_device * dev = (struct net_device *) link->priv; 3947 struct net_device * dev = (struct net_device *) link->priv;
@@ -3965,16 +3964,16 @@ wv_pcmcia_config(dev_link_t * link)
3965 { 3964 {
3966 tuple.Attributes = 0; 3965 tuple.Attributes = 0;
3967 tuple.DesiredTuple = CISTPL_CONFIG; 3966 tuple.DesiredTuple = CISTPL_CONFIG;
3968 i = pcmcia_get_first_tuple(handle, &tuple); 3967 i = pcmcia_get_first_tuple(link, &tuple);
3969 if(i != CS_SUCCESS) 3968 if(i != CS_SUCCESS)
3970 break; 3969 break;
3971 tuple.TupleData = (cisdata_t *)buf; 3970 tuple.TupleData = (cisdata_t *)buf;
3972 tuple.TupleDataMax = 64; 3971 tuple.TupleDataMax = 64;
3973 tuple.TupleOffset = 0; 3972 tuple.TupleOffset = 0;
3974 i = pcmcia_get_tuple_data(handle, &tuple); 3973 i = pcmcia_get_tuple_data(link, &tuple);
3975 if(i != CS_SUCCESS) 3974 if(i != CS_SUCCESS)
3976 break; 3975 break;
3977 i = pcmcia_parse_tuple(handle, &tuple, &parse); 3976 i = pcmcia_parse_tuple(link, &tuple, &parse);
3978 if(i != CS_SUCCESS) 3977 if(i != CS_SUCCESS)
3979 break; 3978 break;
3980 link->conf.ConfigBase = parse.config.base; 3979 link->conf.ConfigBase = parse.config.base;
@@ -3983,19 +3982,16 @@ wv_pcmcia_config(dev_link_t * link)
3983 while(0); 3982 while(0);
3984 if(i != CS_SUCCESS) 3983 if(i != CS_SUCCESS)
3985 { 3984 {
3986 cs_error(link->handle, ParseTuple, i); 3985 cs_error(link, ParseTuple, i);
3987 link->state &= ~DEV_CONFIG_PENDING;
3988 return FALSE; 3986 return FALSE;
3989 } 3987 }
3990 3988
3991 /* Configure card */
3992 link->state |= DEV_CONFIG;
3993 do 3989 do
3994 { 3990 {
3995 i = pcmcia_request_io(link->handle, &link->io); 3991 i = pcmcia_request_io(link, &link->io);
3996 if(i != CS_SUCCESS) 3992 if(i != CS_SUCCESS)
3997 { 3993 {
3998 cs_error(link->handle, RequestIO, i); 3994 cs_error(link, RequestIO, i);
3999 break; 3995 break;
4000 } 3996 }
4001 3997
@@ -4003,10 +3999,10 @@ wv_pcmcia_config(dev_link_t * link)
4003 * Now allocate an interrupt line. Note that this does not 3999 * Now allocate an interrupt line. Note that this does not
4004 * actually assign a handler to the interrupt. 4000 * actually assign a handler to the interrupt.
4005 */ 4001 */
4006 i = pcmcia_request_irq(link->handle, &link->irq); 4002 i = pcmcia_request_irq(link, &link->irq);
4007 if(i != CS_SUCCESS) 4003 if(i != CS_SUCCESS)
4008 { 4004 {
4009 cs_error(link->handle, RequestIRQ, i); 4005 cs_error(link, RequestIRQ, i);
4010 break; 4006 break;
4011 } 4007 }
4012 4008
@@ -4015,15 +4011,15 @@ wv_pcmcia_config(dev_link_t * link)
4015 * the I/O windows and the interrupt mapping. 4011 * the I/O windows and the interrupt mapping.
4016 */ 4012 */
4017 link->conf.ConfigIndex = 1; 4013 link->conf.ConfigIndex = 1;
4018 i = pcmcia_request_configuration(link->handle, &link->conf); 4014 i = pcmcia_request_configuration(link, &link->conf);
4019 if(i != CS_SUCCESS) 4015 if(i != CS_SUCCESS)
4020 { 4016 {
4021 cs_error(link->handle, RequestConfiguration, i); 4017 cs_error(link, RequestConfiguration, i);
4022 break; 4018 break;
4023 } 4019 }
4024 4020
4025 /* 4021 /*
4026 * Allocate a small memory window. Note that the dev_link_t 4022 * Allocate a small memory window. Note that the struct pcmcia_device
4027 * structure provides space for one window handle -- if your 4023 * structure provides space for one window handle -- if your
4028 * device needs several windows, you'll need to keep track of 4024 * device needs several windows, you'll need to keep track of
4029 * the handles in your private data structure, link->priv. 4025 * the handles in your private data structure, link->priv.
@@ -4031,10 +4027,10 @@ wv_pcmcia_config(dev_link_t * link)
4031 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 4027 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
4032 req.Base = req.Size = 0; 4028 req.Base = req.Size = 0;
4033 req.AccessSpeed = mem_speed; 4029 req.AccessSpeed = mem_speed;
4034 i = pcmcia_request_window(&link->handle, &req, &link->win); 4030 i = pcmcia_request_window(&link, &req, &link->win);
4035 if(i != CS_SUCCESS) 4031 if(i != CS_SUCCESS)
4036 { 4032 {
4037 cs_error(link->handle, RequestWindow, i); 4033 cs_error(link, RequestWindow, i);
4038 break; 4034 break;
4039 } 4035 }
4040 4036
@@ -4046,7 +4042,7 @@ wv_pcmcia_config(dev_link_t * link)
4046 i = pcmcia_map_mem_page(link->win, &mem); 4042 i = pcmcia_map_mem_page(link->win, &mem);
4047 if(i != CS_SUCCESS) 4043 if(i != CS_SUCCESS)
4048 { 4044 {
4049 cs_error(link->handle, MapMemPage, i); 4045 cs_error(link, MapMemPage, i);
4050 break; 4046 break;
4051 } 4047 }
4052 4048
@@ -4060,7 +4056,7 @@ wv_pcmcia_config(dev_link_t * link)
4060 lp->mem, dev->irq, (u_int) dev->base_addr); 4056 lp->mem, dev->irq, (u_int) dev->base_addr);
4061#endif 4057#endif
4062 4058
4063 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 4059 SET_NETDEV_DEV(dev, &handle_to_dev(link));
4064 i = register_netdev(dev); 4060 i = register_netdev(dev);
4065 if(i != 0) 4061 if(i != 0)
4066 { 4062 {
@@ -4072,7 +4068,6 @@ wv_pcmcia_config(dev_link_t * link)
4072 } 4068 }
4073 while(0); /* Humm... Disguised goto !!! */ 4069 while(0); /* Humm... Disguised goto !!! */
4074 4070
4075 link->state &= ~DEV_CONFIG_PENDING;
4076 /* If any step failed, release any partially configured state */ 4071 /* If any step failed, release any partially configured state */
4077 if(i != 0) 4072 if(i != 0)
4078 { 4073 {
@@ -4081,7 +4076,7 @@ wv_pcmcia_config(dev_link_t * link)
4081 } 4076 }
4082 4077
4083 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name); 4078 strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
4084 link->dev = &((net_local *) netdev_priv(dev))->node; 4079 link->dev_node = &((net_local *) netdev_priv(dev))->node;
4085 4080
4086#ifdef DEBUG_CONFIG_TRACE 4081#ifdef DEBUG_CONFIG_TRACE
4087 printk(KERN_DEBUG "<-wv_pcmcia_config()\n"); 4082 printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
@@ -4096,26 +4091,20 @@ wv_pcmcia_config(dev_link_t * link)
4096 * still open, this will be postponed until it is closed. 4091 * still open, this will be postponed until it is closed.
4097 */ 4092 */
4098static void 4093static void
4099wv_pcmcia_release(dev_link_t *link) 4094wv_pcmcia_release(struct pcmcia_device *link)
4100{ 4095{
4101 struct net_device * dev = (struct net_device *) link->priv; 4096 struct net_device * dev = (struct net_device *) link->priv;
4102 net_local * lp = netdev_priv(dev); 4097 net_local * lp = netdev_priv(dev);
4103 4098
4104#ifdef DEBUG_CONFIG_TRACE 4099#ifdef DEBUG_CONFIG_TRACE
4105 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link); 4100 printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
4106#endif 4101#endif
4107 4102
4108 /* Don't bother checking to see if these succeed or not */ 4103 iounmap(lp->mem);
4109 iounmap(lp->mem); 4104 pcmcia_disable_device(link);
4110 pcmcia_release_window(link->win);
4111 pcmcia_release_configuration(link->handle);
4112 pcmcia_release_io(link->handle, &link->io);
4113 pcmcia_release_irq(link->handle, &link->irq);
4114
4115 link->state &= ~DEV_CONFIG;
4116 4105
4117#ifdef DEBUG_CONFIG_TRACE 4106#ifdef DEBUG_CONFIG_TRACE
4118 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name); 4107 printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
4119#endif 4108#endif
4120} 4109}
4121 4110
@@ -4479,7 +4468,7 @@ static int
4479wavelan_open(struct net_device * dev) 4468wavelan_open(struct net_device * dev)
4480{ 4469{
4481 net_local * lp = netdev_priv(dev); 4470 net_local * lp = netdev_priv(dev);
4482 dev_link_t * link = lp->link; 4471 struct pcmcia_device * link = lp->link;
4483 kio_addr_t base = dev->base_addr; 4472 kio_addr_t base = dev->base_addr;
4484 4473
4485#ifdef DEBUG_CALLBACK_TRACE 4474#ifdef DEBUG_CALLBACK_TRACE
@@ -4533,7 +4522,7 @@ wavelan_open(struct net_device * dev)
4533static int 4522static int
4534wavelan_close(struct net_device * dev) 4523wavelan_close(struct net_device * dev)
4535{ 4524{
4536 dev_link_t * link = ((net_local *)netdev_priv(dev))->link; 4525 struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
4537 kio_addr_t base = dev->base_addr; 4526 kio_addr_t base = dev->base_addr;
4538 4527
4539#ifdef DEBUG_CALLBACK_TRACE 4528#ifdef DEBUG_CALLBACK_TRACE
@@ -4587,45 +4576,36 @@ wavelan_close(struct net_device * dev)
4587 * card insertion event. 4576 * card insertion event.
4588 */ 4577 */
4589static int 4578static int
4590wavelan_attach(struct pcmcia_device *p_dev) 4579wavelan_probe(struct pcmcia_device *p_dev)
4591{ 4580{
4592 dev_link_t * link; /* Info for cardmgr */
4593 struct net_device * dev; /* Interface generic data */ 4581 struct net_device * dev; /* Interface generic data */
4594 net_local * lp; /* Interface specific data */ 4582 net_local * lp; /* Interface specific data */
4583 int ret;
4595 4584
4596#ifdef DEBUG_CALLBACK_TRACE 4585#ifdef DEBUG_CALLBACK_TRACE
4597 printk(KERN_DEBUG "-> wavelan_attach()\n"); 4586 printk(KERN_DEBUG "-> wavelan_attach()\n");
4598#endif 4587#endif
4599 4588
4600 /* Initialize the dev_link_t structure */
4601 link = kzalloc(sizeof(struct dev_link_t), GFP_KERNEL);
4602 if (!link) return -ENOMEM;
4603
4604 /* The io structure describes IO port mapping */ 4589 /* The io structure describes IO port mapping */
4605 link->io.NumPorts1 = 8; 4590 p_dev->io.NumPorts1 = 8;
4606 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 4591 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
4607 link->io.IOAddrLines = 3; 4592 p_dev->io.IOAddrLines = 3;
4608 4593
4609 /* Interrupt setup */ 4594 /* Interrupt setup */
4610 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 4595 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
4611 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 4596 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
4612 link->irq.Handler = wavelan_interrupt; 4597 p_dev->irq.Handler = wavelan_interrupt;
4613 4598
4614 /* General socket configuration */ 4599 /* General socket configuration */
4615 link->conf.Attributes = CONF_ENABLE_IRQ; 4600 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
4616 link->conf.Vcc = 50; 4601 p_dev->conf.IntType = INT_MEMORY_AND_IO;
4617 link->conf.IntType = INT_MEMORY_AND_IO;
4618
4619 /* Chain drivers */
4620 link->next = NULL;
4621 4602
4622 /* Allocate the generic data structure */ 4603 /* Allocate the generic data structure */
4623 dev = alloc_etherdev(sizeof(net_local)); 4604 dev = alloc_etherdev(sizeof(net_local));
4624 if (!dev) { 4605 if (!dev)
4625 kfree(link);
4626 return -ENOMEM; 4606 return -ENOMEM;
4627 } 4607
4628 link->priv = link->irq.Instance = dev; 4608 p_dev->priv = p_dev->irq.Instance = dev;
4629 4609
4630 lp = netdev_priv(dev); 4610 lp = netdev_priv(dev);
4631 4611
@@ -4642,7 +4622,6 @@ wavelan_attach(struct pcmcia_device *p_dev)
4642 spin_lock_init(&lp->spinlock); 4622 spin_lock_init(&lp->spinlock);
4643 4623
4644 /* back links */ 4624 /* back links */
4645 lp->link = link;
4646 lp->dev = dev; 4625 lp->dev = dev;
4647 4626
4648 /* wavelan NET3 callbacks */ 4627 /* wavelan NET3 callbacks */
@@ -4668,15 +4647,18 @@ wavelan_attach(struct pcmcia_device *p_dev)
4668 /* Other specific data */ 4647 /* Other specific data */
4669 dev->mtu = WAVELAN_MTU; 4648 dev->mtu = WAVELAN_MTU;
4670 4649
4671 link->handle = p_dev; 4650 ret = wv_pcmcia_config(p_dev);
4672 p_dev->instance = link; 4651 if (ret)
4652 return ret;
4673 4653
4674 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 4654 ret = wv_hw_config(dev);
4675 if(wv_pcmcia_config(link) && 4655 if (ret) {
4676 wv_hw_config(dev))
4677 wv_init_info(dev);
4678 else
4679 dev->irq = 0; 4656 dev->irq = 0;
4657 pcmcia_disable_device(p_dev);
4658 return ret;
4659 }
4660
4661 wv_init_info(dev);
4680 4662
4681#ifdef DEBUG_CALLBACK_TRACE 4663#ifdef DEBUG_CALLBACK_TRACE
4682 printk(KERN_DEBUG "<- wavelan_attach()\n"); 4664 printk(KERN_DEBUG "<- wavelan_attach()\n");
@@ -4693,25 +4675,14 @@ wavelan_attach(struct pcmcia_device *p_dev)
4693 * is released. 4675 * is released.
4694 */ 4676 */
4695static void 4677static void
4696wavelan_detach(struct pcmcia_device *p_dev) 4678wavelan_detach(struct pcmcia_device *link)
4697{ 4679{
4698 dev_link_t *link = dev_to_instance(p_dev);
4699
4700#ifdef DEBUG_CALLBACK_TRACE 4680#ifdef DEBUG_CALLBACK_TRACE
4701 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link); 4681 printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
4702#endif 4682#endif
4703 4683
4704 /* 4684 /* Some others haven't done their job : give them another chance */
4705 * If the device is currently configured and active, we won't 4685 wv_pcmcia_release(link);
4706 * actually delete it yet. Instead, it is marked so that when the
4707 * release() function is called, that will trigger a proper
4708 * detach().
4709 */
4710 if(link->state & DEV_CONFIG)
4711 {
4712 /* Some others haven't done their job : give them another chance */
4713 wv_pcmcia_release(link);
4714 }
4715 4686
4716 /* Free pieces */ 4687 /* Free pieces */
4717 if(link->priv) 4688 if(link->priv)
@@ -4720,23 +4691,21 @@ wavelan_detach(struct pcmcia_device *p_dev)
4720 4691
4721 /* Remove ourselves from the kernel list of ethernet devices */ 4692 /* Remove ourselves from the kernel list of ethernet devices */
4722 /* Warning : can't be called from interrupt, timer or wavelan_close() */ 4693 /* Warning : can't be called from interrupt, timer or wavelan_close() */
4723 if (link->dev) 4694 if (link->dev_node)
4724 unregister_netdev(dev); 4695 unregister_netdev(dev);
4725 link->dev = NULL; 4696 link->dev_node = NULL;
4726 ((net_local *)netdev_priv(dev))->link = NULL; 4697 ((net_local *)netdev_priv(dev))->link = NULL;
4727 ((net_local *)netdev_priv(dev))->dev = NULL; 4698 ((net_local *)netdev_priv(dev))->dev = NULL;
4728 free_netdev(dev); 4699 free_netdev(dev);
4729 } 4700 }
4730 kfree(link);
4731 4701
4732#ifdef DEBUG_CALLBACK_TRACE 4702#ifdef DEBUG_CALLBACK_TRACE
4733 printk(KERN_DEBUG "<- wavelan_detach()\n"); 4703 printk(KERN_DEBUG "<- wavelan_detach()\n");
4734#endif 4704#endif
4735} 4705}
4736 4706
4737static int wavelan_suspend(struct pcmcia_device *p_dev) 4707static int wavelan_suspend(struct pcmcia_device *link)
4738{ 4708{
4739 dev_link_t *link = dev_to_instance(p_dev);
4740 struct net_device * dev = (struct net_device *) link->priv; 4709 struct net_device * dev = (struct net_device *) link->priv;
4741 4710
4742 /* NB: wavelan_close will be called, but too late, so we are 4711 /* NB: wavelan_close will be called, but too late, so we are
@@ -4748,36 +4717,22 @@ static int wavelan_suspend(struct pcmcia_device *p_dev)
4748 /* Stop receiving new messages and wait end of transmission */ 4717 /* Stop receiving new messages and wait end of transmission */
4749 wv_ru_stop(dev); 4718 wv_ru_stop(dev);
4750 4719
4720 if (link->open)
4721 netif_device_detach(dev);
4722
4751 /* Power down the module */ 4723 /* Power down the module */
4752 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT)); 4724 hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
4753 4725
4754 /* The card is now suspended */
4755 link->state |= DEV_SUSPEND;
4756
4757 if(link->state & DEV_CONFIG)
4758 {
4759 if(link->open)
4760 netif_device_detach(dev);
4761 pcmcia_release_configuration(link->handle);
4762 }
4763
4764 return 0; 4726 return 0;
4765} 4727}
4766 4728
4767static int wavelan_resume(struct pcmcia_device *p_dev) 4729static int wavelan_resume(struct pcmcia_device *link)
4768{ 4730{
4769 dev_link_t *link = dev_to_instance(p_dev);
4770 struct net_device * dev = (struct net_device *) link->priv; 4731 struct net_device * dev = (struct net_device *) link->priv;
4771 4732
4772 link->state &= ~DEV_SUSPEND; 4733 if (link->open) {
4773 if(link->state & DEV_CONFIG) 4734 wv_hw_reset(dev);
4774 { 4735 netif_device_attach(dev);
4775 pcmcia_request_configuration(link->handle, &link->conf);
4776 if(link->open) /* If RESET -> True, If RESUME -> False ? */
4777 {
4778 wv_hw_reset(dev);
4779 netif_device_attach(dev);
4780 }
4781 } 4736 }
4782 4737
4783 return 0; 4738 return 0;
@@ -4798,7 +4753,7 @@ static struct pcmcia_driver wavelan_driver = {
4798 .drv = { 4753 .drv = {
4799 .name = "wavelan_cs", 4754 .name = "wavelan_cs",
4800 }, 4755 },
4801 .probe = wavelan_attach, 4756 .probe = wavelan_probe,
4802 .remove = wavelan_detach, 4757 .remove = wavelan_detach,
4803 .id_table = wavelan_ids, 4758 .id_table = wavelan_ids,
4804 .suspend = wavelan_suspend, 4759 .suspend = wavelan_suspend,
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index 451f6271dcbc..c65fe7a391ec 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -602,7 +602,7 @@ struct net_local
602 dev_node_t node; /* ???? What is this stuff ???? */ 602 dev_node_t node; /* ???? What is this stuff ???? */
603 struct net_device * dev; /* Reverse link... */ 603 struct net_device * dev; /* Reverse link... */
604 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */ 604 spinlock_t spinlock; /* Serialize access to the hardware (SMP) */
605 dev_link_t * link; /* pcmcia structure */ 605 struct pcmcia_device * link; /* pcmcia structure */
606 en_stats stats; /* Ethernet interface statistics */ 606 en_stats stats; /* Ethernet interface statistics */
607 int nresets; /* Number of hw resets */ 607 int nresets; /* Number of hw resets */
608 u_char configured; /* If it is configured */ 608 u_char configured; /* If it is configured */
@@ -733,9 +733,9 @@ static int
733static inline void 733static inline void
734 wv_hw_reset(struct net_device *); /* Same, + start receiver unit */ 734 wv_hw_reset(struct net_device *); /* Same, + start receiver unit */
735static inline int 735static inline int
736 wv_pcmcia_config(dev_link_t *); /* Configure the pcmcia interface */ 736 wv_pcmcia_config(struct pcmcia_device *); /* Configure the pcmcia interface */
737static void 737static void
738 wv_pcmcia_release(dev_link_t *);/* Remove a device */ 738 wv_pcmcia_release(struct pcmcia_device *);/* Remove a device */
739/* ---------------------- INTERRUPT HANDLING ---------------------- */ 739/* ---------------------- INTERRUPT HANDLING ---------------------- */
740static irqreturn_t 740static irqreturn_t
741 wavelan_interrupt(int, /* Interrupt handler */ 741 wavelan_interrupt(int, /* Interrupt handler */
diff --git a/drivers/net/wireless/wl3501.h b/drivers/net/wireless/wl3501.h
index 4303c50c2ab6..65ceb088f700 100644
--- a/drivers/net/wireless/wl3501.h
+++ b/drivers/net/wireless/wl3501.h
@@ -611,5 +611,6 @@ struct wl3501_card {
611 struct iw_spy_data spy_data; 611 struct iw_spy_data spy_data;
612 struct iw_public_data wireless_data; 612 struct iw_public_data wireless_data;
613 struct dev_node_t node; 613 struct dev_node_t node;
614 struct pcmcia_device *p_dev;
614}; 615};
615#endif 616#endif
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 48e10b0c7e74..e52a650f6737 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -103,8 +103,8 @@ module_param(pc_debug, int, 0);
103 * release a socket, in response to card insertion and ejection events. They 103 * release a socket, in response to card insertion and ejection events. They
104 * are invoked from the wl24 event handler. 104 * are invoked from the wl24 event handler.
105 */ 105 */
106static void wl3501_config(dev_link_t *link); 106static int wl3501_config(struct pcmcia_device *link);
107static void wl3501_release(dev_link_t *link); 107static void wl3501_release(struct pcmcia_device *link);
108 108
109/* 109/*
110 * The dev_info variable is the "key" that is used to match up this 110 * The dev_info variable is the "key" that is used to match up this
@@ -226,17 +226,6 @@ static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
226 iw_set_mgmt_info_element(from->id, to, from->data, from->len); 226 iw_set_mgmt_info_element(from->id, to, from->data, from->len);
227} 227}
228 228
229/*
230 * A linked list of "instances" of the wl24 device. Each actual PCMCIA card
231 * corresponds to one device instance, and is described by one dev_link_t
232 * structure (defined in ds.h).
233 *
234 * You may not want to use a linked list for this -- for example, the memory
235 * card driver uses an array of dev_link_t pointers, where minor device numbers
236 * are used to derive the corresponding array index.
237 */
238static dev_link_t *wl3501_dev_list;
239
240static inline void wl3501_switch_page(struct wl3501_card *this, u8 page) 229static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
241{ 230{
242 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS); 231 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
@@ -1281,15 +1270,10 @@ static int wl3501_close(struct net_device *dev)
1281 struct wl3501_card *this = dev->priv; 1270 struct wl3501_card *this = dev->priv;
1282 int rc = -ENODEV; 1271 int rc = -ENODEV;
1283 unsigned long flags; 1272 unsigned long flags;
1284 dev_link_t *link; 1273 struct pcmcia_device *link;
1274 link = this->p_dev;
1285 1275
1286 spin_lock_irqsave(&this->lock, flags); 1276 spin_lock_irqsave(&this->lock, flags);
1287 /* Check if the device is in wl3501_dev_list */
1288 for (link = wl3501_dev_list; link; link = link->next)
1289 if (link->priv == dev)
1290 break;
1291 if (!link)
1292 goto out;
1293 link->open--; 1277 link->open--;
1294 1278
1295 /* Stop wl3501_hard_start_xmit() from now on */ 1279 /* Stop wl3501_hard_start_xmit() from now on */
@@ -1301,7 +1285,6 @@ static int wl3501_close(struct net_device *dev)
1301 1285
1302 rc = 0; 1286 rc = 0;
1303 printk(KERN_INFO "%s: WL3501 closed\n", dev->name); 1287 printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
1304out:
1305 spin_unlock_irqrestore(&this->lock, flags); 1288 spin_unlock_irqrestore(&this->lock, flags);
1306 return rc; 1289 return rc;
1307} 1290}
@@ -1400,14 +1383,11 @@ static int wl3501_open(struct net_device *dev)
1400 int rc = -ENODEV; 1383 int rc = -ENODEV;
1401 struct wl3501_card *this = dev->priv; 1384 struct wl3501_card *this = dev->priv;
1402 unsigned long flags; 1385 unsigned long flags;
1403 dev_link_t *link; 1386 struct pcmcia_device *link;
1387 link = this->p_dev;
1404 1388
1405 spin_lock_irqsave(&this->lock, flags); 1389 spin_lock_irqsave(&this->lock, flags);
1406 /* Check if the device is in wl3501_dev_list */ 1390 if (!pcmcia_dev_present(link))
1407 for (link = wl3501_dev_list; link; link = link->next)
1408 if (link->priv == dev)
1409 break;
1410 if (!DEV_OK(link))
1411 goto out; 1391 goto out;
1412 netif_device_attach(dev); 1392 netif_device_attach(dev);
1413 link->open++; 1393 link->open++;
@@ -1497,38 +1477,23 @@ static struct ethtool_ops ops = {
1497 * Services. If it has been released, all local data structures are freed. 1477 * Services. If it has been released, all local data structures are freed.
1498 * Otherwise, the structures will be freed when the device is released. 1478 * Otherwise, the structures will be freed when the device is released.
1499 */ 1479 */
1500static void wl3501_detach(struct pcmcia_device *p_dev) 1480static void wl3501_detach(struct pcmcia_device *link)
1501{ 1481{
1502 dev_link_t *link = dev_to_instance(p_dev);
1503 dev_link_t **linkp;
1504 struct net_device *dev = link->priv; 1482 struct net_device *dev = link->priv;
1505 1483
1506 /* Locate device structure */
1507 for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
1508 if (*linkp == link)
1509 break;
1510 if (!*linkp)
1511 goto out;
1512
1513 /* If the device is currently configured and active, we won't actually 1484 /* If the device is currently configured and active, we won't actually
1514 * delete it yet. Instead, it is marked so that when the release() 1485 * delete it yet. Instead, it is marked so that when the release()
1515 * function is called, that will trigger a proper detach(). */ 1486 * function is called, that will trigger a proper detach(). */
1516 1487
1517 if (link->state & DEV_CONFIG) { 1488 while (link->open > 0)
1518 while (link->open > 0) 1489 wl3501_close(dev);
1519 wl3501_close(dev);
1520
1521 netif_device_detach(dev);
1522 wl3501_release(link);
1523 }
1524 1490
1525 /* Unlink device structure, free pieces */ 1491 netif_device_detach(dev);
1526 *linkp = link->next; 1492 wl3501_release(link);
1527 1493
1528 if (link->priv) 1494 if (link->priv)
1529 free_netdev(link->priv); 1495 free_netdev(link->priv);
1530 kfree(link); 1496
1531out:
1532 return; 1497 return;
1533} 1498}
1534 1499
@@ -1953,33 +1918,26 @@ static const struct iw_handler_def wl3501_handler_def = {
1953 * The dev_link structure is initialized, but we don't actually configure the 1918 * The dev_link structure is initialized, but we don't actually configure the
1954 * card at this point -- we wait until we receive a card insertion event. 1919 * card at this point -- we wait until we receive a card insertion event.
1955 */ 1920 */
1956static int wl3501_attach(struct pcmcia_device *p_dev) 1921static int wl3501_probe(struct pcmcia_device *p_dev)
1957{ 1922{
1958 dev_link_t *link;
1959 struct net_device *dev; 1923 struct net_device *dev;
1960 struct wl3501_card *this; 1924 struct wl3501_card *this;
1961 1925
1962 /* Initialize the dev_link_t structure */
1963 link = kzalloc(sizeof(*link), GFP_KERNEL);
1964 if (!link)
1965 return -ENOMEM;
1966
1967 /* The io structure describes IO port mapping */ 1926 /* The io structure describes IO port mapping */
1968 link->io.NumPorts1 = 16; 1927 p_dev->io.NumPorts1 = 16;
1969 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 1928 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1970 link->io.IOAddrLines = 5; 1929 p_dev->io.IOAddrLines = 5;
1971 1930
1972 /* Interrupt setup */ 1931 /* Interrupt setup */
1973 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; 1932 p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
1974 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 1933 p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
1975 link->irq.Handler = wl3501_interrupt; 1934 p_dev->irq.Handler = wl3501_interrupt;
1976 1935
1977 /* General socket configuration */ 1936 /* General socket configuration */
1978 link->conf.Attributes = CONF_ENABLE_IRQ; 1937 p_dev->conf.Attributes = CONF_ENABLE_IRQ;
1979 link->conf.Vcc = 50; 1938 p_dev->conf.IntType = INT_MEMORY_AND_IO;
1980 link->conf.IntType = INT_MEMORY_AND_IO; 1939 p_dev->conf.ConfigIndex = 1;
1981 link->conf.ConfigIndex = 1; 1940 p_dev->conf.Present = PRESENT_OPTION;
1982 link->conf.Present = PRESENT_OPTION;
1983 1941
1984 dev = alloc_etherdev(sizeof(struct wl3501_card)); 1942 dev = alloc_etherdev(sizeof(struct wl3501_card));
1985 if (!dev) 1943 if (!dev)
@@ -1992,22 +1950,15 @@ static int wl3501_attach(struct pcmcia_device *p_dev)
1992 dev->get_stats = wl3501_get_stats; 1950 dev->get_stats = wl3501_get_stats;
1993 this = dev->priv; 1951 this = dev->priv;
1994 this->wireless_data.spy_data = &this->spy_data; 1952 this->wireless_data.spy_data = &this->spy_data;
1953 this->p_dev = p_dev;
1995 dev->wireless_data = &this->wireless_data; 1954 dev->wireless_data = &this->wireless_data;
1996 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def; 1955 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def;
1997 SET_ETHTOOL_OPS(dev, &ops); 1956 SET_ETHTOOL_OPS(dev, &ops);
1998 netif_stop_queue(dev); 1957 netif_stop_queue(dev);
1999 link->priv = link->irq.Instance = dev; 1958 p_dev->priv = p_dev->irq.Instance = dev;
2000
2001 link->handle = p_dev;
2002 p_dev->instance = link;
2003
2004 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
2005 wl3501_config(link);
2006 1959
2007 return 0; 1960 return wl3501_config(p_dev);
2008out_link: 1961out_link:
2009 kfree(link);
2010 link = NULL;
2011 return -ENOMEM; 1962 return -ENOMEM;
2012} 1963}
2013 1964
@@ -2022,11 +1973,10 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
2022 * received, to configure the PCMCIA socket, and to make the ethernet device 1973 * received, to configure the PCMCIA socket, and to make the ethernet device
2023 * available to the system. 1974 * available to the system.
2024 */ 1975 */
2025static void wl3501_config(dev_link_t *link) 1976static int wl3501_config(struct pcmcia_device *link)
2026{ 1977{
2027 tuple_t tuple; 1978 tuple_t tuple;
2028 cisparse_t parse; 1979 cisparse_t parse;
2029 client_handle_t handle = link->handle;
2030 struct net_device *dev = link->priv; 1980 struct net_device *dev = link->priv;
2031 int i = 0, j, last_fn, last_ret; 1981 int i = 0, j, last_fn, last_ret;
2032 unsigned char bf[64]; 1982 unsigned char bf[64];
@@ -2035,18 +1985,15 @@ static void wl3501_config(dev_link_t *link)
2035 /* This reads the card's CONFIG tuple to find its config registers. */ 1985 /* This reads the card's CONFIG tuple to find its config registers. */
2036 tuple.Attributes = 0; 1986 tuple.Attributes = 0;
2037 tuple.DesiredTuple = CISTPL_CONFIG; 1987 tuple.DesiredTuple = CISTPL_CONFIG;
2038 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1988 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
2039 tuple.TupleData = bf; 1989 tuple.TupleData = bf;
2040 tuple.TupleDataMax = sizeof(bf); 1990 tuple.TupleDataMax = sizeof(bf);
2041 tuple.TupleOffset = 0; 1991 tuple.TupleOffset = 0;
2042 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 1992 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
2043 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 1993 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
2044 link->conf.ConfigBase = parse.config.base; 1994 link->conf.ConfigBase = parse.config.base;
2045 link->conf.Present = parse.config.rmask[0]; 1995 link->conf.Present = parse.config.rmask[0];
2046 1996
2047 /* Configure card */
2048 link->state |= DEV_CONFIG;
2049
2050 /* Try allocating IO ports. This tries a few fixed addresses. If you 1997 /* Try allocating IO ports. This tries a few fixed addresses. If you
2051 * want, you can also read the card's config table to pick addresses -- 1998 * want, you can also read the card's config table to pick addresses --
2052 * see the serial driver for an example. */ 1999 * see the serial driver for an example. */
@@ -2056,28 +2003,28 @@ static void wl3501_config(dev_link_t *link)
2056 * 0x200-0x2ff, and so on, because this seems safer */ 2003 * 0x200-0x2ff, and so on, because this seems safer */
2057 link->io.BasePort1 = j; 2004 link->io.BasePort1 = j;
2058 link->io.BasePort2 = link->io.BasePort1 + 0x10; 2005 link->io.BasePort2 = link->io.BasePort1 + 0x10;
2059 i = pcmcia_request_io(link->handle, &link->io); 2006 i = pcmcia_request_io(link, &link->io);
2060 if (i == CS_SUCCESS) 2007 if (i == CS_SUCCESS)
2061 break; 2008 break;
2062 } 2009 }
2063 if (i != CS_SUCCESS) { 2010 if (i != CS_SUCCESS) {
2064 cs_error(link->handle, RequestIO, i); 2011 cs_error(link, RequestIO, i);
2065 goto failed; 2012 goto failed;
2066 } 2013 }
2067 2014
2068 /* Now allocate an interrupt line. Note that this does not actually 2015 /* Now allocate an interrupt line. Note that this does not actually
2069 * assign a handler to the interrupt. */ 2016 * assign a handler to the interrupt. */
2070 2017
2071 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 2018 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
2072 2019
2073 /* This actually configures the PCMCIA socket -- setting up the I/O 2020 /* This actually configures the PCMCIA socket -- setting up the I/O
2074 * windows and the interrupt mapping. */ 2021 * windows and the interrupt mapping. */
2075 2022
2076 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf)); 2023 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
2077 2024
2078 dev->irq = link->irq.AssignedIRQ; 2025 dev->irq = link->irq.AssignedIRQ;
2079 dev->base_addr = link->io.BasePort1; 2026 dev->base_addr = link->io.BasePort1;
2080 SET_NETDEV_DEV(dev, &handle_to_dev(handle)); 2027 SET_NETDEV_DEV(dev, &handle_to_dev(link));
2081 if (register_netdev(dev)) { 2028 if (register_netdev(dev)) {
2082 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n"); 2029 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
2083 goto failed; 2030 goto failed;
@@ -2088,10 +2035,9 @@ static void wl3501_config(dev_link_t *link)
2088 this = dev->priv; 2035 this = dev->priv;
2089 /* 2036 /*
2090 * At this point, the dev_node_t structure(s) should be initialized and 2037 * At this point, the dev_node_t structure(s) should be initialized and
2091 * arranged in a linked list at link->dev. 2038 * arranged in a linked list at link->dev_node.
2092 */ 2039 */
2093 link->dev = &this->node; 2040 link->dev_node = &this->node;
2094 link->state &= ~DEV_CONFIG_PENDING;
2095 2041
2096 this->base_addr = dev->base_addr; 2042 this->base_addr = dev->base_addr;
2097 2043
@@ -2127,13 +2073,13 @@ static void wl3501_config(dev_link_t *link)
2127 spin_lock_init(&this->lock); 2073 spin_lock_init(&this->lock);
2128 init_waitqueue_head(&this->wait); 2074 init_waitqueue_head(&this->wait);
2129 netif_start_queue(dev); 2075 netif_start_queue(dev);
2130 goto out; 2076 return 0;
2077
2131cs_failed: 2078cs_failed:
2132 cs_error(link->handle, last_fn, last_ret); 2079 cs_error(link, last_fn, last_ret);
2133failed: 2080failed:
2134 wl3501_release(link); 2081 wl3501_release(link);
2135out: 2082 return -ENODEV;
2136 return;
2137} 2083}
2138 2084
2139/** 2085/**
@@ -2144,52 +2090,36 @@ out:
2144 * and release the PCMCIA configuration. If the device is still open, this 2090 * and release the PCMCIA configuration. If the device is still open, this
2145 * will be postponed until it is closed. 2091 * will be postponed until it is closed.
2146 */ 2092 */
2147static void wl3501_release(dev_link_t *link) 2093static void wl3501_release(struct pcmcia_device *link)
2148{ 2094{
2149 struct net_device *dev = link->priv; 2095 struct net_device *dev = link->priv;
2150 2096
2151 /* Unlink the device chain */ 2097 /* Unlink the device chain */
2152 if (link->dev) { 2098 if (link->dev_node)
2153 unregister_netdev(dev); 2099 unregister_netdev(dev);
2154 link->dev = NULL;
2155 }
2156 2100
2157 /* Don't bother checking to see if these succeed or not */ 2101 pcmcia_disable_device(link);
2158 pcmcia_release_configuration(link->handle);
2159 pcmcia_release_io(link->handle, &link->io);
2160 pcmcia_release_irq(link->handle, &link->irq);
2161 link->state &= ~DEV_CONFIG;
2162} 2102}
2163 2103
2164static int wl3501_suspend(struct pcmcia_device *p_dev) 2104static int wl3501_suspend(struct pcmcia_device *link)
2165{ 2105{
2166 dev_link_t *link = dev_to_instance(p_dev);
2167 struct net_device *dev = link->priv; 2106 struct net_device *dev = link->priv;
2168 2107
2169 link->state |= DEV_SUSPEND;
2170
2171 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND); 2108 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
2172 if (link->state & DEV_CONFIG) { 2109 if (link->open)
2173 if (link->open) 2110 netif_device_detach(dev);
2174 netif_device_detach(dev);
2175 pcmcia_release_configuration(link->handle);
2176 }
2177 2111
2178 return 0; 2112 return 0;
2179} 2113}
2180 2114
2181static int wl3501_resume(struct pcmcia_device *p_dev) 2115static int wl3501_resume(struct pcmcia_device *link)
2182{ 2116{
2183 dev_link_t *link = dev_to_instance(p_dev);
2184 struct net_device *dev = link->priv; 2117 struct net_device *dev = link->priv;
2185 2118
2186 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME); 2119 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
2187 if (link->state & DEV_CONFIG) { 2120 if (link->open) {
2188 pcmcia_request_configuration(link->handle, &link->conf); 2121 wl3501_reset(dev);
2189 if (link->open) { 2122 netif_device_attach(dev);
2190 wl3501_reset(dev);
2191 netif_device_attach(dev);
2192 }
2193 } 2123 }
2194 2124
2195 return 0; 2125 return 0;
@@ -2207,7 +2137,7 @@ static struct pcmcia_driver wl3501_driver = {
2207 .drv = { 2137 .drv = {
2208 .name = "wl3501_cs", 2138 .name = "wl3501_cs",
2209 }, 2139 },
2210 .probe = wl3501_attach, 2140 .probe = wl3501_probe,
2211 .remove = wl3501_detach, 2141 .remove = wl3501_detach,
2212 .id_table = wl3501_ids, 2142 .id_table = wl3501_ids,
2213 .suspend = wl3501_suspend, 2143 .suspend = wl3501_suspend,
@@ -2221,9 +2151,7 @@ static int __init wl3501_init_module(void)
2221 2151
2222static void __exit wl3501_exit_module(void) 2152static void __exit wl3501_exit_module(void)
2223{ 2153{
2224 dprintk(0, ": unloading");
2225 pcmcia_unregister_driver(&wl3501_driver); 2154 pcmcia_unregister_driver(&wl3501_driver);
2226 BUG_ON(wl3501_dev_list != NULL);
2227} 2155}
2228 2156
2229module_init(wl3501_init_module); 2157module_init(wl3501_init_module);
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index 75d56bfef0ee..fd0f43b7db5b 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -1441,8 +1441,7 @@ static void __devexit yellowfin_remove_one (struct pci_dev *pdev)
1441 struct net_device *dev = pci_get_drvdata(pdev); 1441 struct net_device *dev = pci_get_drvdata(pdev);
1442 struct yellowfin_private *np; 1442 struct yellowfin_private *np;
1443 1443
1444 if (!dev) 1444 BUG_ON(!dev);
1445 BUG();
1446 np = netdev_priv(dev); 1445 np = netdev_priv(dev);
1447 1446
1448 pci_free_consistent(pdev, STATUS_TOTAL_SIZE, np->tx_status, 1447 pci_free_consistent(pdev, STATUS_TOTAL_SIZE, np->tx_status,
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 93f8a8fa8890..a5d826237b26 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -1560,7 +1560,7 @@ static int ccio_probe(struct parisc_device *dev)
1560 *ioc_p = ioc; 1560 *ioc_p = ioc;
1561 1561
1562 ioc->hw_path = dev->hw_path; 1562 ioc->hw_path = dev->hw_path;
1563 ioc->ioc_regs = ioremap(dev->hpa.start, 4096); 1563 ioc->ioc_regs = ioremap_nocache(dev->hpa.start, 4096);
1564 ccio_ioc_init(ioc); 1564 ccio_ioc_init(ioc);
1565 ccio_init_resources(ioc); 1565 ccio_init_resources(ioc);
1566 hppa_dma_ops = &ccio_ops; 1566 hppa_dma_ops = &ccio_ops;
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index 3d1a7f98c676..6e8ed0c81a6c 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -5,6 +5,7 @@
5** (c) Copyright 1999 SuSE GmbH 5** (c) Copyright 1999 SuSE GmbH
6** (c) Copyright 1999,2000 Hewlett-Packard Company 6** (c) Copyright 1999,2000 Hewlett-Packard Company
7** (c) Copyright 2000 Grant Grundler 7** (c) Copyright 2000 Grant Grundler
8** (c) Copyright 2006 Helge Deller
8** 9**
9** This program is free software; you can redistribute it and/or modify 10** This program is free software; you can redistribute it and/or modify
10** it under the terms of the GNU General Public License as published by 11** it under the terms of the GNU General Public License as published by
@@ -785,7 +786,7 @@ dino_bridge_init(struct dino_device *dino_dev, const char *name)
785 if((io_addr & (1 << i)) == 0) 786 if((io_addr & (1 << i)) == 0)
786 continue; 787 continue;
787 788
788 start = (unsigned long)(signed int)(0xf0000000 | (i << 23)); 789 start = F_EXTEND(0xf0000000UL) | (i << 23);
789 end = start + 8 * 1024 * 1024 - 1; 790 end = start + 8 * 1024 * 1024 - 1;
790 791
791 DBG("DINO RANGE %d is at 0x%lx-0x%lx\n", count, 792 DBG("DINO RANGE %d is at 0x%lx-0x%lx\n", count,
@@ -996,7 +997,7 @@ static int __init dino_probe(struct parisc_device *dev)
996 } 997 }
997 998
998 dino_dev->hba.dev = dev; 999 dino_dev->hba.dev = dev;
999 dino_dev->hba.base_addr = ioremap(hpa, 4096); 1000 dino_dev->hba.base_addr = ioremap_nocache(hpa, 4096);
1000 dino_dev->hba.lmmio_space_offset = 0; /* CPU addrs == bus addrs */ 1001 dino_dev->hba.lmmio_space_offset = 0; /* CPU addrs == bus addrs */
1001 spin_lock_init(&dino_dev->dinosaur_pen); 1002 spin_lock_init(&dino_dev->dinosaur_pen);
1002 dino_dev->hba.iommu = ccio_get_iommu(dev); 1003 dino_dev->hba.iommu = ccio_get_iommu(dev);
diff --git a/drivers/parisc/eisa.c b/drivers/parisc/eisa.c
index 3d94d86c1c9f..9d3bd15bf53b 100644
--- a/drivers/parisc/eisa.c
+++ b/drivers/parisc/eisa.c
@@ -366,7 +366,7 @@ static int __devinit eisa_probe(struct parisc_device *dev)
366 eisa_dev.eeprom_addr = MIRAGE_EEPROM_BASE_ADDR; 366 eisa_dev.eeprom_addr = MIRAGE_EEPROM_BASE_ADDR;
367 } 367 }
368 } 368 }
369 eisa_eeprom_addr = ioremap(eisa_dev.eeprom_addr, HPEE_MAX_LENGTH); 369 eisa_eeprom_addr = ioremap_nocache(eisa_dev.eeprom_addr, HPEE_MAX_LENGTH);
370 result = eisa_enumerator(eisa_dev.eeprom_addr, &eisa_dev.hba.io_space, 370 result = eisa_enumerator(eisa_dev.eeprom_addr, &eisa_dev.hba.io_space,
371 &eisa_dev.hba.lmmio_space); 371 &eisa_dev.hba.lmmio_space);
372 init_eisa_pic(); 372 init_eisa_pic();
diff --git a/drivers/parisc/iosapic.c b/drivers/parisc/iosapic.c
index 8d7a36392eb8..7a458d5bc751 100644
--- a/drivers/parisc/iosapic.c
+++ b/drivers/parisc/iosapic.c
@@ -879,7 +879,7 @@ void *iosapic_register(unsigned long hpa)
879 return NULL; 879 return NULL;
880 } 880 }
881 881
882 isi->addr = ioremap(hpa, 4096); 882 isi->addr = ioremap_nocache(hpa, 4096);
883 isi->isi_hpa = hpa; 883 isi->isi_hpa = hpa;
884 isi->isi_version = iosapic_rd_version(isi); 884 isi->isi_version = iosapic_rd_version(isi);
885 isi->isi_num_vectors = IOSAPIC_IRDT_MAX_ENTRY(isi->isi_version) + 1; 885 isi->isi_num_vectors = IOSAPIC_IRDT_MAX_ENTRY(isi->isi_version) + 1;
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index e8a2a4a852f5..3fe4a77fa16a 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -1213,7 +1213,7 @@ lba_pat_resources(struct parisc_device *pa_dev, struct lba_device *lba_dev)
1213 ** Postable I/O port space is per PCI host adapter. 1213 ** Postable I/O port space is per PCI host adapter.
1214 ** base of 64MB PIOP region 1214 ** base of 64MB PIOP region
1215 */ 1215 */
1216 lba_dev->iop_base = ioremap(p->start, 64 * 1024 * 1024); 1216 lba_dev->iop_base = ioremap_nocache(p->start, 64 * 1024 * 1024);
1217 1217
1218 sprintf(lba_dev->hba.io_name, "PCI%02lx Ports", 1218 sprintf(lba_dev->hba.io_name, "PCI%02lx Ports",
1219 lba_dev->hba.bus_num.start); 1219 lba_dev->hba.bus_num.start);
@@ -1525,7 +1525,7 @@ lba_driver_probe(struct parisc_device *dev)
1525 u32 func_class; 1525 u32 func_class;
1526 void *tmp_obj; 1526 void *tmp_obj;
1527 char *version; 1527 char *version;
1528 void __iomem *addr = ioremap(dev->hpa.start, 4096); 1528 void __iomem *addr = ioremap_nocache(dev->hpa.start, 4096);
1529 1529
1530 /* Read HW Rev First */ 1530 /* Read HW Rev First */
1531 func_class = READ_REG32(addr + LBA_FCLASS); 1531 func_class = READ_REG32(addr + LBA_FCLASS);
@@ -1619,7 +1619,7 @@ lba_driver_probe(struct parisc_device *dev)
1619 } else { 1619 } else {
1620 if (!astro_iop_base) { 1620 if (!astro_iop_base) {
1621 /* Sprockets PDC uses NPIOP region */ 1621 /* Sprockets PDC uses NPIOP region */
1622 astro_iop_base = ioremap(LBA_PORT_BASE, 64 * 1024); 1622 astro_iop_base = ioremap_nocache(LBA_PORT_BASE, 64 * 1024);
1623 pci_port = &lba_astro_port_ops; 1623 pci_port = &lba_astro_port_ops;
1624 } 1624 }
1625 1625
@@ -1700,7 +1700,7 @@ void __init lba_init(void)
1700*/ 1700*/
1701void lba_set_iregs(struct parisc_device *lba, u32 ibase, u32 imask) 1701void lba_set_iregs(struct parisc_device *lba, u32 ibase, u32 imask)
1702{ 1702{
1703 void __iomem * base_addr = ioremap(lba->hpa.start, 4096); 1703 void __iomem * base_addr = ioremap_nocache(lba->hpa.start, 4096);
1704 1704
1705 imask <<= 2; /* adjust for hints - 2 more bits */ 1705 imask <<= 2; /* adjust for hints - 2 more bits */
1706 1706
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index a28e17898fbd..4e53be9c03ab 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -4,9 +4,8 @@
4 * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org> 4 * Copyright (C) 2005-2006 Thibaut VARENE <varenet@parisc-linux.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License, version 2, as
8 * the Free Software Foundation; either version 2 of the License, or 8 * published by the Free Software Foundation.
9 * (at your option) any later version.
10 * 9 *
11 * This program is distributed in the hope that it will be useful, 10 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index 0821747e44cf..42b32ff2fca6 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -1642,9 +1642,9 @@ sba_ioc_init(struct parisc_device *sba, struct ioc *ioc, int ioc_num)
1642** 1642**
1643**************************************************************************/ 1643**************************************************************************/
1644 1644
1645static void __iomem *ioc_remap(struct sba_device *sba_dev, int offset) 1645static void __iomem *ioc_remap(struct sba_device *sba_dev, unsigned int offset)
1646{ 1646{
1647 return ioremap(sba_dev->dev->hpa.start + offset, SBA_FUNC_SIZE); 1647 return ioremap_nocache(sba_dev->dev->hpa.start + offset, SBA_FUNC_SIZE);
1648} 1648}
1649 1649
1650static void sba_hw_init(struct sba_device *sba_dev) 1650static void sba_hw_init(struct sba_device *sba_dev)
@@ -2040,7 +2040,7 @@ sba_driver_callback(struct parisc_device *dev)
2040 u32 func_class; 2040 u32 func_class;
2041 int i; 2041 int i;
2042 char *version; 2042 char *version;
2043 void __iomem *sba_addr = ioremap(dev->hpa.start, SBA_FUNC_SIZE); 2043 void __iomem *sba_addr = ioremap_nocache(dev->hpa.start, SBA_FUNC_SIZE);
2044 struct proc_dir_entry *info_entry, *bitmap_entry, *root; 2044 struct proc_dir_entry *info_entry, *bitmap_entry, *root;
2045 2045
2046 sba_dump_ranges(sba_addr); 2046 sba_dump_ranges(sba_addr);
diff --git a/drivers/parisc/superio.c b/drivers/parisc/superio.c
index ad6d3b28a3a6..719b863bc20e 100644
--- a/drivers/parisc/superio.c
+++ b/drivers/parisc/superio.c
@@ -12,6 +12,7 @@
12 * (C) Copyright 2001 John Marvin <jsm fc hp com> 12 * (C) Copyright 2001 John Marvin <jsm fc hp com>
13 * (C) Copyright 2003 Grant Grundler <grundler parisc-linux org> 13 * (C) Copyright 2003 Grant Grundler <grundler parisc-linux org>
14 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org> 14 * (C) Copyright 2005 Kyle McMartin <kyle@parisc-linux.org>
15 * (C) Copyright 2006 Helge Deller <deller@gmx.de>
15 * 16 *
16 * This program is free software; you can redistribute it and/or 17 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as 18 * modify it under the terms of the GNU General Public License as
@@ -388,43 +389,34 @@ int superio_fixup_irq(struct pci_dev *pcidev)
388 return local_irq; 389 return local_irq;
389} 390}
390 391
391static struct uart_port serial[] = {
392 {
393 .iotype = UPIO_PORT,
394 .line = 0,
395 .type = PORT_16550A,
396 .uartclk = 115200*16,
397 .fifosize = 16,
398 },
399 {
400 .iotype = UPIO_PORT,
401 .line = 1,
402 .type = PORT_16550A,
403 .uartclk = 115200*16,
404 .fifosize = 16,
405 }
406};
407
408static void __devinit superio_serial_init(void) 392static void __devinit superio_serial_init(void)
409{ 393{
410#ifdef CONFIG_SERIAL_8250 394#ifdef CONFIG_SERIAL_8250
411 int retval; 395 int retval;
412 396 struct uart_port serial_port;
413 serial[0].iobase = sio_dev.sp1_base; 397
414 serial[0].irq = SP1_IRQ; 398 memset(&serial_port, 0, sizeof(serial_port));
415 spin_lock_init(&serial[0].lock); 399 serial_port.iotype = UPIO_PORT;
416 400 serial_port.type = PORT_16550A;
417 retval = early_serial_setup(&serial[0]); 401 serial_port.uartclk = 115200*16;
402 serial_port.fifosize = 16;
403 spin_lock_init(&serial_port.lock);
404
405 /* serial port #1 */
406 serial_port.iobase = sio_dev.sp1_base;
407 serial_port.irq = SP1_IRQ;
408 serial_port.line = 0;
409 retval = early_serial_setup(&serial_port);
418 if (retval < 0) { 410 if (retval < 0) {
419 printk(KERN_WARNING PFX "Register Serial #0 failed.\n"); 411 printk(KERN_WARNING PFX "Register Serial #0 failed.\n");
420 return; 412 return;
421 } 413 }
422 414
423 serial[1].iobase = sio_dev.sp2_base; 415 /* serial port #2 */
424 serial[1].irq = SP2_IRQ; 416 serial_port.iobase = sio_dev.sp2_base;
425 spin_lock_init(&serial[1].lock); 417 serial_port.irq = SP2_IRQ;
426 retval = early_serial_setup(&serial[1]); 418 serial_port.line = 1;
427 419 retval = early_serial_setup(&serial_port);
428 if (retval < 0) 420 if (retval < 0)
429 printk(KERN_WARNING PFX "Register Serial #1 failed.\n"); 421 printk(KERN_WARNING PFX "Register Serial #1 failed.\n");
430#endif /* CONFIG_SERIAL_8250 */ 422#endif /* CONFIG_SERIAL_8250 */
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 158d92563259..b953d5907c05 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -81,15 +81,15 @@ static char *version =
81#define FORCE_EPP_MODE 0x08 81#define FORCE_EPP_MODE 0x08
82 82
83typedef struct parport_info_t { 83typedef struct parport_info_t {
84 dev_link_t link; 84 struct pcmcia_device *p_dev;
85 int ndev; 85 int ndev;
86 dev_node_t node; 86 dev_node_t node;
87 struct parport *port; 87 struct parport *port;
88} parport_info_t; 88} parport_info_t;
89 89
90static void parport_detach(struct pcmcia_device *p_dev); 90static void parport_detach(struct pcmcia_device *p_dev);
91static void parport_config(dev_link_t *link); 91static int parport_config(struct pcmcia_device *link);
92static void parport_cs_release(dev_link_t *); 92static void parport_cs_release(struct pcmcia_device *);
93 93
94/*====================================================================== 94/*======================================================================
95 95
@@ -99,10 +99,9 @@ static void parport_cs_release(dev_link_t *);
99 99
100======================================================================*/ 100======================================================================*/
101 101
102static int parport_attach(struct pcmcia_device *p_dev) 102static int parport_probe(struct pcmcia_device *link)
103{ 103{
104 parport_info_t *info; 104 parport_info_t *info;
105 dev_link_t *link;
106 105
107 DEBUG(0, "parport_attach()\n"); 106 DEBUG(0, "parport_attach()\n");
108 107
@@ -110,23 +109,17 @@ static int parport_attach(struct pcmcia_device *p_dev)
110 info = kmalloc(sizeof(*info), GFP_KERNEL); 109 info = kmalloc(sizeof(*info), GFP_KERNEL);
111 if (!info) return -ENOMEM; 110 if (!info) return -ENOMEM;
112 memset(info, 0, sizeof(*info)); 111 memset(info, 0, sizeof(*info));
113 link = &info->link; link->priv = info; 112 link->priv = info;
113 info->p_dev = link;
114 114
115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 115 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
116 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 116 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
117 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 117 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
118 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 118 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
119 link->conf.Attributes = CONF_ENABLE_IRQ; 119 link->conf.Attributes = CONF_ENABLE_IRQ;
120 link->conf.Vcc = 50;
121 link->conf.IntType = INT_MEMORY_AND_IO; 120 link->conf.IntType = INT_MEMORY_AND_IO;
122 121
123 link->handle = p_dev; 122 return parport_config(link);
124 p_dev->instance = link;
125
126 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
127 parport_config(link);
128
129 return 0;
130} /* parport_attach */ 123} /* parport_attach */
131 124
132/*====================================================================== 125/*======================================================================
@@ -138,14 +131,11 @@ static int parport_attach(struct pcmcia_device *p_dev)
138 131
139======================================================================*/ 132======================================================================*/
140 133
141static void parport_detach(struct pcmcia_device *p_dev) 134static void parport_detach(struct pcmcia_device *link)
142{ 135{
143 dev_link_t *link = dev_to_instance(p_dev);
144
145 DEBUG(0, "parport_detach(0x%p)\n", link); 136 DEBUG(0, "parport_detach(0x%p)\n", link);
146 137
147 if (link->state & DEV_CONFIG) 138 parport_cs_release(link);
148 parport_cs_release(link);
149 139
150 kfree(link->priv); 140 kfree(link->priv);
151} /* parport_detach */ 141} /* parport_detach */
@@ -161,14 +151,12 @@ static void parport_detach(struct pcmcia_device *p_dev)
161#define CS_CHECK(fn, ret) \ 151#define CS_CHECK(fn, ret) \
162do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 152do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
163 153
164void parport_config(dev_link_t *link) 154static int parport_config(struct pcmcia_device *link)
165{ 155{
166 client_handle_t handle = link->handle;
167 parport_info_t *info = link->priv; 156 parport_info_t *info = link->priv;
168 tuple_t tuple; 157 tuple_t tuple;
169 u_short buf[128]; 158 u_short buf[128];
170 cisparse_t parse; 159 cisparse_t parse;
171 config_info_t conf;
172 cistpl_cftable_entry_t *cfg = &parse.cftable_entry; 160 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
173 cistpl_cftable_entry_t dflt = { 0 }; 161 cistpl_cftable_entry_t dflt = { 0 };
174 struct parport *p; 162 struct parport *p;
@@ -180,24 +168,18 @@ void parport_config(dev_link_t *link)
180 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 168 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
181 tuple.Attributes = 0; 169 tuple.Attributes = 0;
182 tuple.DesiredTuple = CISTPL_CONFIG; 170 tuple.DesiredTuple = CISTPL_CONFIG;
183 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 171 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
184 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 172 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
185 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 173 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
186 link->conf.ConfigBase = parse.config.base; 174 link->conf.ConfigBase = parse.config.base;
187 link->conf.Present = parse.config.rmask[0]; 175 link->conf.Present = parse.config.rmask[0];
188
189 /* Configure card */
190 link->state |= DEV_CONFIG;
191 176
192 /* Not sure if this is right... look up the current Vcc */
193 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
194
195 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 177 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
196 tuple.Attributes = 0; 178 tuple.Attributes = 0;
197 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 179 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
198 while (1) { 180 while (1) {
199 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 181 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
200 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 182 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
201 goto next_entry; 183 goto next_entry;
202 184
203 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 185 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
@@ -212,7 +194,7 @@ void parport_config(dev_link_t *link)
212 link->io.BasePort2 = io->win[1].base; 194 link->io.BasePort2 = io->win[1].base;
213 link->io.NumPorts2 = io->win[1].len; 195 link->io.NumPorts2 = io->win[1].len;
214 } 196 }
215 if (pcmcia_request_io(link->handle, &link->io) != 0) 197 if (pcmcia_request_io(link, &link->io) != 0)
216 goto next_entry; 198 goto next_entry;
217 /* If we've got this far, we're done */ 199 /* If we've got this far, we're done */
218 break; 200 break;
@@ -220,15 +202,12 @@ void parport_config(dev_link_t *link)
220 202
221 next_entry: 203 next_entry:
222 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 204 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
223 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 205 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
224 } 206 }
225 207
226 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 208 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
227 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 209 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
228 210
229 release_region(link->io.BasePort1, link->io.NumPorts1);
230 if (link->io.NumPorts2)
231 release_region(link->io.BasePort2, link->io.NumPorts2);
232 p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2, 211 p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2,
233 link->irq.AssignedIRQ, PARPORT_DMA_NONE, 212 link->irq.AssignedIRQ, PARPORT_DMA_NONE,
234 NULL); 213 NULL);
@@ -247,17 +226,15 @@ void parport_config(dev_link_t *link)
247 info->node.minor = p->number; 226 info->node.minor = p->number;
248 info->port = p; 227 info->port = p;
249 strcpy(info->node.dev_name, p->name); 228 strcpy(info->node.dev_name, p->name);
250 link->dev = &info->node; 229 link->dev_node = &info->node;
230
231 return 0;
251 232
252 link->state &= ~DEV_CONFIG_PENDING;
253 return;
254
255cs_failed: 233cs_failed:
256 cs_error(link->handle, last_fn, last_ret); 234 cs_error(link, last_fn, last_ret);
257failed: 235failed:
258 parport_cs_release(link); 236 parport_cs_release(link);
259 link->state &= ~DEV_CONFIG_PENDING; 237 return -ENODEV;
260
261} /* parport_config */ 238} /* parport_config */
262 239
263/*====================================================================== 240/*======================================================================
@@ -268,53 +245,21 @@ failed:
268 245
269======================================================================*/ 246======================================================================*/
270 247
271void parport_cs_release(dev_link_t *link) 248void parport_cs_release(struct pcmcia_device *link)
272{
273 parport_info_t *info = link->priv;
274
275 DEBUG(0, "parport_release(0x%p)\n", link);
276
277 if (info->ndev) {
278 struct parport *p = info->port;
279 parport_pc_unregister_port(p);
280 request_region(link->io.BasePort1, link->io.NumPorts1,
281 info->node.dev_name);
282 if (link->io.NumPorts2)
283 request_region(link->io.BasePort2, link->io.NumPorts2,
284 info->node.dev_name);
285 }
286 info->ndev = 0;
287 link->dev = NULL;
288
289 pcmcia_release_configuration(link->handle);
290 pcmcia_release_io(link->handle, &link->io);
291 pcmcia_release_irq(link->handle, &link->irq);
292
293 link->state &= ~DEV_CONFIG;
294
295} /* parport_cs_release */
296
297static int parport_suspend(struct pcmcia_device *dev)
298{ 249{
299 dev_link_t *link = dev_to_instance(dev); 250 parport_info_t *info = link->priv;
300 251
301 link->state |= DEV_SUSPEND; 252 DEBUG(0, "parport_release(0x%p)\n", link);
302 if (link->state & DEV_CONFIG)
303 pcmcia_release_configuration(link->handle);
304 253
305 return 0; 254 if (info->ndev) {
306} 255 struct parport *p = info->port;
307 256 parport_pc_unregister_port(p);
308static int parport_resume(struct pcmcia_device *dev) 257 }
309{ 258 info->ndev = 0;
310 dev_link_t *link = dev_to_instance(dev);
311 259
312 link->state &= ~DEV_SUSPEND; 260 pcmcia_disable_device(link);
313 if (DEV_OK(link)) 261} /* parport_cs_release */
314 pcmcia_request_configuration(link->handle, &link->conf);
315 262
316 return 0;
317}
318 263
319static struct pcmcia_device_id parport_ids[] = { 264static struct pcmcia_device_id parport_ids[] = {
320 PCMCIA_DEVICE_FUNC_ID(3), 265 PCMCIA_DEVICE_FUNC_ID(3),
@@ -328,11 +273,9 @@ static struct pcmcia_driver parport_cs_driver = {
328 .drv = { 273 .drv = {
329 .name = "parport_cs", 274 .name = "parport_cs",
330 }, 275 },
331 .probe = parport_attach, 276 .probe = parport_probe,
332 .remove = parport_detach, 277 .remove = parport_detach,
333 .id_table = parport_ids, 278 .id_table = parport_ids,
334 .suspend = parport_suspend,
335 .resume = parport_resume,
336}; 279};
337 280
338static int __init init_parport_cs(void) 281static int __init init_parport_cs(void)
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
index d121644646b9..98b83a85c60e 100644
--- a/drivers/parport/parport_serial.c
+++ b/drivers/parport/parport_serial.c
@@ -100,8 +100,6 @@ static struct pci_device_id parport_serial_pci_tbl[] = {
100 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, 100 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
101 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835, 101 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
102 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, 102 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
103 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
104 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
105 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845, 103 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845,
106 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, 104 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo },
107 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855, 105 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index 6e79f5675b0d..638004546700 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -360,9 +360,6 @@ static int __init rpaphp_init(void)
360 while ((dn = of_find_node_by_type(dn, "pci"))) 360 while ((dn = of_find_node_by_type(dn, "pci")))
361 rpaphp_add_slot(dn); 361 rpaphp_add_slot(dn);
362 362
363 if (!num_slots)
364 return -ENODEV;
365
366 return 0; 363 return 0;
367} 364}
368 365
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index a77e79c8c82e..2087a397ef16 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -504,6 +504,201 @@ void pci_scan_msi_device(struct pci_dev *dev)
504 nr_reserved_vectors++; 504 nr_reserved_vectors++;
505} 505}
506 506
507#ifdef CONFIG_PM
508int pci_save_msi_state(struct pci_dev *dev)
509{
510 int pos, i = 0;
511 u16 control;
512 struct pci_cap_saved_state *save_state;
513 u32 *cap;
514
515 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
516 if (pos <= 0 || dev->no_msi)
517 return 0;
518
519 pci_read_config_word(dev, msi_control_reg(pos), &control);
520 if (!(control & PCI_MSI_FLAGS_ENABLE))
521 return 0;
522
523 save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u32) * 5,
524 GFP_KERNEL);
525 if (!save_state) {
526 printk(KERN_ERR "Out of memory in pci_save_msi_state\n");
527 return -ENOMEM;
528 }
529 cap = &save_state->data[0];
530
531 pci_read_config_dword(dev, pos, &cap[i++]);
532 control = cap[0] >> 16;
533 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, &cap[i++]);
534 if (control & PCI_MSI_FLAGS_64BIT) {
535 pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, &cap[i++]);
536 pci_read_config_dword(dev, pos + PCI_MSI_DATA_64, &cap[i++]);
537 } else
538 pci_read_config_dword(dev, pos + PCI_MSI_DATA_32, &cap[i++]);
539 if (control & PCI_MSI_FLAGS_MASKBIT)
540 pci_read_config_dword(dev, pos + PCI_MSI_MASK_BIT, &cap[i++]);
541 disable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
542 save_state->cap_nr = PCI_CAP_ID_MSI;
543 pci_add_saved_cap(dev, save_state);
544 return 0;
545}
546
547void pci_restore_msi_state(struct pci_dev *dev)
548{
549 int i = 0, pos;
550 u16 control;
551 struct pci_cap_saved_state *save_state;
552 u32 *cap;
553
554 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSI);
555 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
556 if (!save_state || pos <= 0)
557 return;
558 cap = &save_state->data[0];
559
560 control = cap[i++] >> 16;
561 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, cap[i++]);
562 if (control & PCI_MSI_FLAGS_64BIT) {
563 pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, cap[i++]);
564 pci_write_config_dword(dev, pos + PCI_MSI_DATA_64, cap[i++]);
565 } else
566 pci_write_config_dword(dev, pos + PCI_MSI_DATA_32, cap[i++]);
567 if (control & PCI_MSI_FLAGS_MASKBIT)
568 pci_write_config_dword(dev, pos + PCI_MSI_MASK_BIT, cap[i++]);
569 pci_write_config_word(dev, pos + PCI_MSI_FLAGS, control);
570 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
571 pci_remove_saved_cap(save_state);
572 kfree(save_state);
573}
574
575int pci_save_msix_state(struct pci_dev *dev)
576{
577 int pos;
578 u16 control;
579 struct pci_cap_saved_state *save_state;
580
581 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
582 if (pos <= 0 || dev->no_msi)
583 return 0;
584
585 pci_read_config_word(dev, msi_control_reg(pos), &control);
586 if (!(control & PCI_MSIX_FLAGS_ENABLE))
587 return 0;
588 save_state = kzalloc(sizeof(struct pci_cap_saved_state) + sizeof(u16),
589 GFP_KERNEL);
590 if (!save_state) {
591 printk(KERN_ERR "Out of memory in pci_save_msix_state\n");
592 return -ENOMEM;
593 }
594 *((u16 *)&save_state->data[0]) = control;
595
596 disable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
597 save_state->cap_nr = PCI_CAP_ID_MSIX;
598 pci_add_saved_cap(dev, save_state);
599 return 0;
600}
601
602void pci_restore_msix_state(struct pci_dev *dev)
603{
604 u16 save;
605 int pos;
606 int vector, head, tail = 0;
607 void __iomem *base;
608 int j;
609 struct msg_address address;
610 struct msg_data data;
611 struct msi_desc *entry;
612 int temp;
613 struct pci_cap_saved_state *save_state;
614
615 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_MSIX);
616 if (!save_state)
617 return;
618 save = *((u16 *)&save_state->data[0]);
619 pci_remove_saved_cap(save_state);
620 kfree(save_state);
621
622 pos = pci_find_capability(dev, PCI_CAP_ID_MSIX);
623 if (pos <= 0)
624 return;
625
626 /* route the table */
627 temp = dev->irq;
628 if (msi_lookup_vector(dev, PCI_CAP_ID_MSIX))
629 return;
630 vector = head = dev->irq;
631 while (head != tail) {
632 entry = msi_desc[vector];
633 base = entry->mask_base;
634 j = entry->msi_attrib.entry_nr;
635
636 msi_address_init(&address);
637 msi_data_init(&data, vector);
638
639 address.lo_address.value &= MSI_ADDRESS_DEST_ID_MASK;
640 address.lo_address.value |= entry->msi_attrib.current_cpu <<
641 MSI_TARGET_CPU_SHIFT;
642
643 writel(address.lo_address.value,
644 base + j * PCI_MSIX_ENTRY_SIZE +
645 PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
646 writel(address.hi_address,
647 base + j * PCI_MSIX_ENTRY_SIZE +
648 PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
649 writel(*(u32*)&data,
650 base + j * PCI_MSIX_ENTRY_SIZE +
651 PCI_MSIX_ENTRY_DATA_OFFSET);
652
653 tail = msi_desc[vector]->link.tail;
654 vector = tail;
655 }
656 dev->irq = temp;
657
658 pci_write_config_word(dev, msi_control_reg(pos), save);
659 enable_msi_mode(dev, pos, PCI_CAP_ID_MSIX);
660}
661#endif
662
663static void msi_register_init(struct pci_dev *dev, struct msi_desc *entry)
664{
665 struct msg_address address;
666 struct msg_data data;
667 int pos, vector = dev->irq;
668 u16 control;
669
670 pos = pci_find_capability(dev, PCI_CAP_ID_MSI);
671 pci_read_config_word(dev, msi_control_reg(pos), &control);
672 /* Configure MSI capability structure */
673 msi_address_init(&address);
674 msi_data_init(&data, vector);
675 entry->msi_attrib.current_cpu = ((address.lo_address.u.dest_id >>
676 MSI_TARGET_CPU_SHIFT) & MSI_TARGET_CPU_MASK);
677 pci_write_config_dword(dev, msi_lower_address_reg(pos),
678 address.lo_address.value);
679 if (is_64bit_address(control)) {
680 pci_write_config_dword(dev,
681 msi_upper_address_reg(pos), address.hi_address);
682 pci_write_config_word(dev,
683 msi_data_reg(pos, 1), *((u32*)&data));
684 } else
685 pci_write_config_word(dev,
686 msi_data_reg(pos, 0), *((u32*)&data));
687 if (entry->msi_attrib.maskbit) {
688 unsigned int maskbits, temp;
689 /* All MSIs are unmasked by default, Mask them all */
690 pci_read_config_dword(dev,
691 msi_mask_bits_reg(pos, is_64bit_address(control)),
692 &maskbits);
693 temp = (1 << multi_msi_capable(control));
694 temp = ((temp - 1) & ~temp);
695 maskbits |= temp;
696 pci_write_config_dword(dev,
697 msi_mask_bits_reg(pos, is_64bit_address(control)),
698 maskbits);
699 }
700}
701
507/** 702/**
508 * msi_capability_init - configure device's MSI capability structure 703 * msi_capability_init - configure device's MSI capability structure
509 * @dev: pointer to the pci_dev data structure of MSI device function 704 * @dev: pointer to the pci_dev data structure of MSI device function
@@ -516,8 +711,6 @@ void pci_scan_msi_device(struct pci_dev *dev)
516static int msi_capability_init(struct pci_dev *dev) 711static int msi_capability_init(struct pci_dev *dev)
517{ 712{
518 struct msi_desc *entry; 713 struct msi_desc *entry;
519 struct msg_address address;
520 struct msg_data data;
521 int pos, vector; 714 int pos, vector;
522 u16 control; 715 u16 control;
523 716
@@ -549,33 +742,8 @@ static int msi_capability_init(struct pci_dev *dev)
549 /* Replace with MSI handler */ 742 /* Replace with MSI handler */
550 irq_handler_init(PCI_CAP_ID_MSI, vector, entry->msi_attrib.maskbit); 743 irq_handler_init(PCI_CAP_ID_MSI, vector, entry->msi_attrib.maskbit);
551 /* Configure MSI capability structure */ 744 /* Configure MSI capability structure */
552 msi_address_init(&address); 745 msi_register_init(dev, entry);
553 msi_data_init(&data, vector); 746
554 entry->msi_attrib.current_cpu = ((address.lo_address.u.dest_id >>
555 MSI_TARGET_CPU_SHIFT) & MSI_TARGET_CPU_MASK);
556 pci_write_config_dword(dev, msi_lower_address_reg(pos),
557 address.lo_address.value);
558 if (is_64bit_address(control)) {
559 pci_write_config_dword(dev,
560 msi_upper_address_reg(pos), address.hi_address);
561 pci_write_config_word(dev,
562 msi_data_reg(pos, 1), *((u32*)&data));
563 } else
564 pci_write_config_word(dev,
565 msi_data_reg(pos, 0), *((u32*)&data));
566 if (entry->msi_attrib.maskbit) {
567 unsigned int maskbits, temp;
568 /* All MSIs are unmasked by default, Mask them all */
569 pci_read_config_dword(dev,
570 msi_mask_bits_reg(pos, is_64bit_address(control)),
571 &maskbits);
572 temp = (1 << multi_msi_capable(control));
573 temp = ((temp - 1) & ~temp);
574 maskbits |= temp;
575 pci_write_config_dword(dev,
576 msi_mask_bits_reg(pos, is_64bit_address(control)),
577 maskbits);
578 }
579 attach_msi_entry(entry, vector); 747 attach_msi_entry(entry, vector);
580 /* Set MSI enabled bits */ 748 /* Set MSI enabled bits */
581 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); 749 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
@@ -731,6 +899,7 @@ int pci_enable_msi(struct pci_dev* dev)
731 vector_irq[dev->irq] = -1; 899 vector_irq[dev->irq] = -1;
732 nr_released_vectors--; 900 nr_released_vectors--;
733 spin_unlock_irqrestore(&msi_lock, flags); 901 spin_unlock_irqrestore(&msi_lock, flags);
902 msi_register_init(dev, msi_desc[dev->irq]);
734 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI); 903 enable_msi_mode(dev, pos, PCI_CAP_ID_MSI);
735 return 0; 904 return 0;
736 } 905 }
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index f22f69ac6445..1456759936c5 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -271,10 +271,12 @@ static int pci_device_suspend(struct device * dev, pm_message_t state)
271 struct pci_driver * drv = pci_dev->driver; 271 struct pci_driver * drv = pci_dev->driver;
272 int i = 0; 272 int i = 0;
273 273
274 if (drv && drv->suspend) 274 if (drv && drv->suspend) {
275 i = drv->suspend(pci_dev, state); 275 i = drv->suspend(pci_dev, state);
276 else 276 suspend_report_result(drv->suspend, i);
277 } else {
277 pci_save_state(pci_dev); 278 pci_save_state(pci_dev);
279 }
278 return i; 280 return i;
279} 281}
280 282
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index bea1ad1ad5ba..2329f941a0dc 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -307,9 +307,11 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state)
307 * Can enter D0 from any state, but if we can only go deeper 307 * Can enter D0 from any state, but if we can only go deeper
308 * to sleep if we're already in a low power state 308 * to sleep if we're already in a low power state
309 */ 309 */
310 if (state != PCI_D0 && dev->current_state > state) 310 if (state != PCI_D0 && dev->current_state > state) {
311 printk(KERN_ERR "%s(): %s: state=%d, current state=%d\n",
312 __FUNCTION__, pci_name(dev), state, dev->current_state);
311 return -EINVAL; 313 return -EINVAL;
312 else if (dev->current_state == state) 314 } else if (dev->current_state == state)
313 return 0; /* we're already there */ 315 return 0; /* we're already there */
314 316
315 /* find PCI PM capability in list */ 317 /* find PCI PM capability in list */
@@ -444,6 +446,10 @@ pci_save_state(struct pci_dev *dev)
444 /* XXX: 100% dword access ok here? */ 446 /* XXX: 100% dword access ok here? */
445 for (i = 0; i < 16; i++) 447 for (i = 0; i < 16; i++)
446 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); 448 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]);
449 if ((i = pci_save_msi_state(dev)) != 0)
450 return i;
451 if ((i = pci_save_msix_state(dev)) != 0)
452 return i;
447 return 0; 453 return 0;
448} 454}
449 455
@@ -458,6 +464,8 @@ pci_restore_state(struct pci_dev *dev)
458 464
459 for (i = 0; i < 16; i++) 465 for (i = 0; i < 16; i++)
460 pci_write_config_dword(dev,i * 4, dev->saved_config_space[i]); 466 pci_write_config_dword(dev,i * 4, dev->saved_config_space[i]);
467 pci_restore_msi_state(dev);
468 pci_restore_msix_state(dev);
461 return 0; 469 return 0;
462} 470}
463 471
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 8f3fb47ea671..30630cbe2fe3 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -55,6 +55,17 @@ void pci_no_msi(void);
55static inline void disable_msi_mode(struct pci_dev *dev, int pos, int type) { } 55static inline void disable_msi_mode(struct pci_dev *dev, int pos, int type) { }
56static inline void pci_no_msi(void) { } 56static inline void pci_no_msi(void) { }
57#endif 57#endif
58#if defined(CONFIG_PCI_MSI) && defined(CONFIG_PM)
59int pci_save_msi_state(struct pci_dev *dev);
60int pci_save_msix_state(struct pci_dev *dev);
61void pci_restore_msi_state(struct pci_dev *dev);
62void pci_restore_msix_state(struct pci_dev *dev);
63#else
64static inline int pci_save_msi_state(struct pci_dev *dev) { return 0; }
65static inline int pci_save_msix_state(struct pci_dev *dev) { return 0; }
66static inline void pci_restore_msi_state(struct pci_dev *dev) {}
67static inline void pci_restore_msix_state(struct pci_dev *dev) {}
68#endif
58 69
59extern int pcie_mch_quirk; 70extern int pcie_mch_quirk;
60extern struct device_attribute pci_dev_attrs[]; 71extern struct device_attribute pci_dev_attrs[];
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 4970f47be72c..827550d25c9e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -592,7 +592,7 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
592 pci_write_config_byte( dev, AMD8131_MISC, tmp); 592 pci_write_config_byte( dev, AMD8131_MISC, tmp);
593 } 593 }
594} 594}
595DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_APIC, quirk_amd_8131_ioapic ); 595DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
596 596
597static void __init quirk_svw_msi(struct pci_dev *dev) 597static void __init quirk_svw_msi(struct pci_dev *dev)
598{ 598{
@@ -921,6 +921,7 @@ static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
921 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) { 921 if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB) {
922 switch (dev->subsystem_device) { 922 switch (dev->subsystem_device) {
923 case 0x1882: /* M6V notebook */ 923 case 0x1882: /* M6V notebook */
924 case 0x1977: /* A6VA notebook */
924 asus_hides_smbus = 1; 925 asus_hides_smbus = 1;
925 } 926 }
926 } 927 }
@@ -999,6 +1000,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asu
999DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc ); 1000DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
1000DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc ); 1001DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
1001DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc ); 1002DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
1003DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc );
1002 1004
1003static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1005static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1004{ 1006{
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index 1f4ad0e7836e..cba6c9eef28e 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -263,6 +263,13 @@ config OMAP_CF
263 Say Y here to support the CompactFlash controller on OMAP. 263 Say Y here to support the CompactFlash controller on OMAP.
264 Note that this doesn't support "True IDE" mode. 264 Note that this doesn't support "True IDE" mode.
265 265
266config AT91_CF
267 tristate "AT91 CompactFlash Controller"
268 depends on PCMCIA && ARCH_AT91RM9200
269 help
270 Say Y here to support the CompactFlash controller on AT91 chips.
271 Or choose M to compile the driver as a module named "at91_cf".
272
266config PCCARD_NONSTATIC 273config PCCARD_NONSTATIC
267 tristate 274 tristate
268 275
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index bcecf5133b7e..4276965517f2 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -10,7 +10,7 @@ pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o
10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
11obj-$(CONFIG_PCCARD) += pcmcia_core.o 11obj-$(CONFIG_PCCARD) += pcmcia_core.o
12 12
13pcmcia-y += ds.o pcmcia_compat.o pcmcia_resource.o 13pcmcia-y += ds.o pcmcia_resource.o
14pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o 14pcmcia-$(CONFIG_PCMCIA_IOCTL) += pcmcia_ioctl.o
15obj-$(CONFIG_PCMCIA) += pcmcia.o 15obj-$(CONFIG_PCMCIA) += pcmcia.o
16 16
@@ -36,6 +36,7 @@ obj-$(CONFIG_PCMCIA_AU1X00) += au1x00_ss.o
36obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o 36obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o
37obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o 37obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o
38obj-$(CONFIG_OMAP_CF) += omap_cf.o 38obj-$(CONFIG_OMAP_CF) += omap_cf.o
39obj-$(CONFIG_AT91_CF) += at91_cf.o
39 40
40sa11xx_core-y += soc_common.o sa11xx_base.o 41sa11xx_core-y += soc_common.o sa11xx_base.o
41pxa2xx_core-y += soc_common.o pxa2xx_base.o 42pxa2xx_core-y += soc_common.o pxa2xx_base.o
diff --git a/drivers/pcmcia/at91_cf.c b/drivers/pcmcia/at91_cf.c
new file mode 100644
index 000000000000..a4d50940ebeb
--- /dev/null
+++ b/drivers/pcmcia/at91_cf.c
@@ -0,0 +1,376 @@
1/*
2 * at91_cf.c -- AT91 CompactFlash controller driver
3 *
4 * Copyright (C) 2005 David Brownell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/platform_device.h>
16#include <linux/errno.h>
17#include <linux/init.h>
18#include <linux/interrupt.h>
19
20#include <pcmcia/ss.h>
21
22#include <asm/hardware.h>
23#include <asm/io.h>
24#include <asm/sizes.h>
25
26#include <asm/arch/at91rm9200.h>
27#include <asm/arch/board.h>
28#include <asm/arch/gpio.h>
29
30
31/*
32 * A0..A10 work in each range; A23 indicates I/O space; A25 is CFRNW;
33 * some other bit in {A24,A22..A11} is nREG to flag memory access
34 * (vs attributes). So more than 2KB/region would just be waste.
35 */
36#define CF_ATTR_PHYS (AT91_CF_BASE)
37#define CF_IO_PHYS (AT91_CF_BASE + (1 << 23))
38#define CF_MEM_PHYS (AT91_CF_BASE + 0x017ff800)
39
40/*--------------------------------------------------------------------------*/
41
42static const char driver_name[] = "at91_cf";
43
44struct at91_cf_socket {
45 struct pcmcia_socket socket;
46
47 unsigned present:1;
48
49 struct platform_device *pdev;
50 struct at91_cf_data *board;
51};
52
53#define SZ_2K (2 * SZ_1K)
54
55static inline int at91_cf_present(struct at91_cf_socket *cf)
56{
57 return !at91_get_gpio_value(cf->board->det_pin);
58}
59
60/*--------------------------------------------------------------------------*/
61
62static int at91_cf_ss_init(struct pcmcia_socket *s)
63{
64 return 0;
65}
66
67static irqreturn_t at91_cf_irq(int irq, void *_cf, struct pt_regs *r)
68{
69 struct at91_cf_socket *cf = (struct at91_cf_socket *) _cf;
70
71 if (irq == cf->board->det_pin) {
72 unsigned present = at91_cf_present(cf);
73
74 /* kick pccard as needed */
75 if (present != cf->present) {
76 cf->present = present;
77 pr_debug("%s: card %s\n", driver_name,
78 present ? "present" : "gone");
79 pcmcia_parse_events(&cf->socket, SS_DETECT);
80 }
81 }
82
83 return IRQ_HANDLED;
84}
85
86static int at91_cf_get_status(struct pcmcia_socket *s, u_int *sp)
87{
88 struct at91_cf_socket *cf;
89
90 if (!sp)
91 return -EINVAL;
92
93 cf = container_of(s, struct at91_cf_socket, socket);
94
95 /* NOTE: CF is always 3VCARD */
96 if (at91_cf_present(cf)) {
97 int rdy = cf->board->irq_pin; /* RDY/nIRQ */
98 int vcc = cf->board->vcc_pin;
99
100 *sp = SS_DETECT | SS_3VCARD;
101 if (!rdy || at91_get_gpio_value(rdy))
102 *sp |= SS_READY;
103 if (!vcc || at91_get_gpio_value(vcc))
104 *sp |= SS_POWERON;
105 } else
106 *sp = 0;
107
108 return 0;
109}
110
111static int
112at91_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s)
113{
114 struct at91_cf_socket *cf;
115
116 cf = container_of(sock, struct at91_cf_socket, socket);
117
118 /* switch Vcc if needed and possible */
119 if (cf->board->vcc_pin) {
120 switch (s->Vcc) {
121 case 0:
122 at91_set_gpio_value(cf->board->vcc_pin, 0);
123 break;
124 case 33:
125 at91_set_gpio_value(cf->board->vcc_pin, 1);
126 break;
127 default:
128 return -EINVAL;
129 }
130 }
131
132 /* toggle reset if needed */
133 at91_set_gpio_value(cf->board->rst_pin, s->flags & SS_RESET);
134
135 pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n",
136 driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask);
137
138 return 0;
139}
140
141static int at91_cf_ss_suspend(struct pcmcia_socket *s)
142{
143 return at91_cf_set_socket(s, &dead_socket);
144}
145
146/* we already mapped the I/O region */
147static int at91_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io)
148{
149 struct at91_cf_socket *cf;
150 u32 csr;
151
152 cf = container_of(s, struct at91_cf_socket, socket);
153 io->flags &= (MAP_ACTIVE | MAP_16BIT | MAP_AUTOSZ);
154
155 /*
156 * Use 16 bit accesses unless/until we need 8-bit i/o space.
157 * Always set CSR4 ... PCMCIA won't always unmap things.
158 */
159 csr = at91_sys_read(AT91_SMC_CSR(4)) & ~AT91_SMC_DBW;
160
161 /*
162 * NOTE: this CF controller ignores IOIS16, so we can't really do
163 * MAP_AUTOSZ. The 16bit mode allows single byte access on either
164 * D0-D7 (even addr) or D8-D15 (odd), so it's close enough for many
165 * purposes (and handles ide-cs).
166 *
167 * The 8bit mode is needed for odd byte access on D0-D7. It seems
168 * some cards only like that way to get at the odd byte, despite
169 * CF 3.0 spec table 35 also giving the D8-D15 option.
170 */
171 if (!(io->flags & (MAP_16BIT|MAP_AUTOSZ))) {
172 csr |= AT91_SMC_DBW_8;
173 pr_debug("%s: 8bit i/o bus\n", driver_name);
174 } else {
175 csr |= AT91_SMC_DBW_16;
176 pr_debug("%s: 16bit i/o bus\n", driver_name);
177 }
178 at91_sys_write(AT91_SMC_CSR(4), csr);
179
180 io->start = cf->socket.io_offset;
181 io->stop = io->start + SZ_2K - 1;
182
183 return 0;
184}
185
186/* pcmcia layer maps/unmaps mem regions */
187static int
188at91_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map)
189{
190 struct at91_cf_socket *cf;
191
192 if (map->card_start)
193 return -EINVAL;
194
195 cf = container_of(s, struct at91_cf_socket, socket);
196
197 map->flags &= MAP_ACTIVE|MAP_ATTRIB|MAP_16BIT;
198 if (map->flags & MAP_ATTRIB)
199 map->static_start = CF_ATTR_PHYS;
200 else
201 map->static_start = CF_MEM_PHYS;
202
203 return 0;
204}
205
206static struct pccard_operations at91_cf_ops = {
207 .init = at91_cf_ss_init,
208 .suspend = at91_cf_ss_suspend,
209 .get_status = at91_cf_get_status,
210 .set_socket = at91_cf_set_socket,
211 .set_io_map = at91_cf_set_io_map,
212 .set_mem_map = at91_cf_set_mem_map,
213};
214
215/*--------------------------------------------------------------------------*/
216
217static int __init at91_cf_probe(struct device *dev)
218{
219 struct at91_cf_socket *cf;
220 struct at91_cf_data *board = dev->platform_data;
221 struct platform_device *pdev = to_platform_device(dev);
222 struct resource *io;
223 unsigned int csa;
224 int status;
225
226 if (!board || !board->det_pin || !board->rst_pin)
227 return -ENODEV;
228
229 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
230 if (!io)
231 return -ENODEV;
232
233 cf = kcalloc(1, sizeof *cf, GFP_KERNEL);
234 if (!cf)
235 return -ENOMEM;
236
237 cf->board = board;
238 cf->pdev = pdev;
239 dev_set_drvdata(dev, cf);
240
241 /* CF takes over CS4, CS5, CS6 */
242 csa = at91_sys_read(AT91_EBI_CSA);
243 at91_sys_write(AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
244
245 /* force poweron defaults for these pins ... */
246 (void) at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
247 (void) at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
248 (void) at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
249 (void) at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
250
251 /* nWAIT is _not_ a default setting */
252 (void) at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
253
254 /*
255 * Static memory controller timing adjustments.
256 * REVISIT: these timings are in terms of MCK cycles, so
257 * when MCK changes (cpufreq etc) so must these values...
258 */
259 at91_sys_write(AT91_SMC_CSR(4),
260 AT91_SMC_ACSS_STD
261 | AT91_SMC_DBW_16
262 | AT91_SMC_BAT
263 | AT91_SMC_WSEN
264 | AT91_SMC_NWS_(32) /* wait states */
265 | AT91_SMC_RWSETUP_(6) /* setup time */
266 | AT91_SMC_RWHOLD_(4) /* hold time */
267 );
268
269 /* must be a GPIO; ergo must trigger on both edges */
270 status = request_irq(board->det_pin, at91_cf_irq,
271 SA_SAMPLE_RANDOM, driver_name, cf);
272 if (status < 0)
273 goto fail0;
274
275 /*
276 * The card driver will request this irq later as needed.
277 * but it causes lots of "irqNN: nobody cared" messages
278 * unless we report that we handle everything (sigh).
279 * (Note: DK board doesn't wire the IRQ pin...)
280 */
281 if (board->irq_pin) {
282 status = request_irq(board->irq_pin, at91_cf_irq,
283 SA_SHIRQ, driver_name, cf);
284 if (status < 0)
285 goto fail0a;
286 cf->socket.pci_irq = board->irq_pin;
287 } else
288 cf->socket.pci_irq = NR_IRQS + 1;
289
290 /* pcmcia layer only remaps "real" memory not iospace */
291 cf->socket.io_offset = (unsigned long) ioremap(CF_IO_PHYS, SZ_2K);
292 if (!cf->socket.io_offset)
293 goto fail1;
294
295 /* reserve CS4, CS5, and CS6 regions; but use just CS4 */
296 if (!request_mem_region(io->start, io->end + 1 - io->start,
297 driver_name))
298 goto fail1;
299
300 pr_info("%s: irqs det #%d, io #%d\n", driver_name,
301 board->det_pin, board->irq_pin);
302
303 cf->socket.owner = THIS_MODULE;
304 cf->socket.dev.dev = dev;
305 cf->socket.ops = &at91_cf_ops;
306 cf->socket.resource_ops = &pccard_static_ops;
307 cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP
308 | SS_CAP_MEM_ALIGN;
309 cf->socket.map_size = SZ_2K;
310 cf->socket.io[0].res = io;
311
312 status = pcmcia_register_socket(&cf->socket);
313 if (status < 0)
314 goto fail2;
315
316 return 0;
317
318fail2:
319 iounmap((void __iomem *) cf->socket.io_offset);
320 release_mem_region(io->start, io->end + 1 - io->start);
321fail1:
322 if (board->irq_pin)
323 free_irq(board->irq_pin, cf);
324fail0a:
325 free_irq(board->det_pin, cf);
326fail0:
327 at91_sys_write(AT91_EBI_CSA, csa);
328 kfree(cf);
329 return status;
330}
331
332static int __exit at91_cf_remove(struct device *dev)
333{
334 struct at91_cf_socket *cf = dev_get_drvdata(dev);
335 struct resource *io = cf->socket.io[0].res;
336 unsigned int csa;
337
338 pcmcia_unregister_socket(&cf->socket);
339 free_irq(cf->board->irq_pin, cf);
340 free_irq(cf->board->det_pin, cf);
341 iounmap((void __iomem *) cf->socket.io_offset);
342 release_mem_region(io->start, io->end + 1 - io->start);
343
344 csa = at91_sys_read(AT91_EBI_CSA);
345 at91_sys_write(AT91_EBI_CSA, csa & ~AT91_EBI_CS4A);
346
347 kfree(cf);
348 return 0;
349}
350
351static struct device_driver at91_cf_driver = {
352 .name = (char *) driver_name,
353 .bus = &platform_bus_type,
354 .probe = at91_cf_probe,
355 .remove = __exit_p(at91_cf_remove),
356 .suspend = pcmcia_socket_dev_suspend,
357 .resume = pcmcia_socket_dev_resume,
358};
359
360/*--------------------------------------------------------------------------*/
361
362static int __init at91_cf_init(void)
363{
364 return driver_register(&at91_cf_driver);
365}
366module_init(at91_cf_init);
367
368static void __exit at91_cf_exit(void)
369{
370 driver_unregister(&at91_cf_driver);
371}
372module_exit(at91_cf_exit);
373
374MODULE_DESCRIPTION("AT91 Compact Flash Driver");
375MODULE_AUTHOR("David Brownell");
376MODULE_LICENSE("GPL");
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 120fa8da6392..912c03e5eb0a 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -12,7 +12,6 @@
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
18#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 613f2f1fbfdd..3162998579c1 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -16,7 +16,6 @@
16#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/config.h>
20#include <linux/string.h> 19#include <linux/string.h>
21#include <linux/major.h> 20#include <linux/major.h>
22#include <linux/errno.h> 21#include <linux/errno.h>
@@ -111,9 +110,9 @@ int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state)
111 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) { 110 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) {
112 if (socket->dev.dev != dev) 111 if (socket->dev.dev != dev)
113 continue; 112 continue;
114 down(&socket->skt_sem); 113 mutex_lock(&socket->skt_mutex);
115 socket_suspend(socket); 114 socket_suspend(socket);
116 up(&socket->skt_sem); 115 mutex_unlock(&socket->skt_mutex);
117 } 116 }
118 up_read(&pcmcia_socket_list_rwsem); 117 up_read(&pcmcia_socket_list_rwsem);
119 118
@@ -129,9 +128,9 @@ int pcmcia_socket_dev_resume(struct device *dev)
129 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) { 128 list_for_each_entry(socket, &pcmcia_socket_list, socket_list) {
130 if (socket->dev.dev != dev) 129 if (socket->dev.dev != dev)
131 continue; 130 continue;
132 down(&socket->skt_sem); 131 mutex_lock(&socket->skt_mutex);
133 socket_resume(socket); 132 socket_resume(socket);
134 up(&socket->skt_sem); 133 mutex_unlock(&socket->skt_mutex);
135 } 134 }
136 up_read(&pcmcia_socket_list_rwsem); 135 up_read(&pcmcia_socket_list_rwsem);
137 136
@@ -237,7 +236,7 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
237 init_completion(&socket->socket_released); 236 init_completion(&socket->socket_released);
238 init_completion(&socket->thread_done); 237 init_completion(&socket->thread_done);
239 init_waitqueue_head(&socket->thread_wait); 238 init_waitqueue_head(&socket->thread_wait);
240 init_MUTEX(&socket->skt_sem); 239 mutex_init(&socket->skt_mutex);
241 spin_lock_init(&socket->thread_lock); 240 spin_lock_init(&socket->thread_lock);
242 241
243 ret = kernel_thread(pccardd, socket, CLONE_KERNEL); 242 ret = kernel_thread(pccardd, socket, CLONE_KERNEL);
@@ -406,8 +405,6 @@ static void socket_shutdown(struct pcmcia_socket *s)
406 cb_free(s); 405 cb_free(s);
407#endif 406#endif
408 s->functions = 0; 407 s->functions = 0;
409 kfree(s->config);
410 s->config = NULL;
411 408
412 s->ops->get_status(s, &status); 409 s->ops->get_status(s, &status);
413 if (status & SS_POWERON) { 410 if (status & SS_POWERON) {
@@ -664,7 +661,7 @@ static int pccardd(void *__skt)
664 spin_unlock_irqrestore(&skt->thread_lock, flags); 661 spin_unlock_irqrestore(&skt->thread_lock, flags);
665 662
666 if (events) { 663 if (events) {
667 down(&skt->skt_sem); 664 mutex_lock(&skt->skt_mutex);
668 if (events & SS_DETECT) 665 if (events & SS_DETECT)
669 socket_detect_change(skt); 666 socket_detect_change(skt);
670 if (events & SS_BATDEAD) 667 if (events & SS_BATDEAD)
@@ -673,7 +670,7 @@ static int pccardd(void *__skt)
673 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW); 670 send_event(skt, CS_EVENT_BATTERY_LOW, CS_EVENT_PRI_LOW);
674 if (events & SS_READY) 671 if (events & SS_READY)
675 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW); 672 send_event(skt, CS_EVENT_READY_CHANGE, CS_EVENT_PRI_LOW);
676 up(&skt->skt_sem); 673 mutex_unlock(&skt->skt_mutex);
677 continue; 674 continue;
678 } 675 }
679 676
@@ -717,8 +714,8 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
717{ 714{
718 int ret = 0; 715 int ret = 0;
719 716
720 /* s->skt_sem also protects s->callback */ 717 /* s->skt_mutex also protects s->callback */
721 down(&s->skt_sem); 718 mutex_lock(&s->skt_mutex);
722 719
723 if (c) { 720 if (c) {
724 /* registration */ 721 /* registration */
@@ -734,7 +731,7 @@ int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c)
734 } else 731 } else
735 s->callback = NULL; 732 s->callback = NULL;
736 err: 733 err:
737 up(&s->skt_sem); 734 mutex_unlock(&s->skt_mutex);
738 735
739 return ret; 736 return ret;
740} 737}
@@ -752,7 +749,7 @@ int pccard_reset_card(struct pcmcia_socket *skt)
752 749
753 cs_dbg(skt, 1, "resetting socket\n"); 750 cs_dbg(skt, 1, "resetting socket\n");
754 751
755 down(&skt->skt_sem); 752 mutex_lock(&skt->skt_mutex);
756 do { 753 do {
757 if (!(skt->state & SOCKET_PRESENT)) { 754 if (!(skt->state & SOCKET_PRESENT)) {
758 ret = CS_NO_CARD; 755 ret = CS_NO_CARD;
@@ -781,7 +778,7 @@ int pccard_reset_card(struct pcmcia_socket *skt)
781 778
782 ret = CS_SUCCESS; 779 ret = CS_SUCCESS;
783 } while (0); 780 } while (0);
784 up(&skt->skt_sem); 781 mutex_unlock(&skt->skt_mutex);
785 782
786 return ret; 783 return ret;
787} /* reset_card */ 784} /* reset_card */
@@ -797,7 +794,7 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
797 794
798 cs_dbg(skt, 1, "suspending socket\n"); 795 cs_dbg(skt, 1, "suspending socket\n");
799 796
800 down(&skt->skt_sem); 797 mutex_lock(&skt->skt_mutex);
801 do { 798 do {
802 if (!(skt->state & SOCKET_PRESENT)) { 799 if (!(skt->state & SOCKET_PRESENT)) {
803 ret = CS_NO_CARD; 800 ret = CS_NO_CARD;
@@ -814,7 +811,7 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
814 } 811 }
815 ret = socket_suspend(skt); 812 ret = socket_suspend(skt);
816 } while (0); 813 } while (0);
817 up(&skt->skt_sem); 814 mutex_unlock(&skt->skt_mutex);
818 815
819 return ret; 816 return ret;
820} /* suspend_card */ 817} /* suspend_card */
@@ -827,7 +824,7 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
827 824
828 cs_dbg(skt, 1, "waking up socket\n"); 825 cs_dbg(skt, 1, "waking up socket\n");
829 826
830 down(&skt->skt_sem); 827 mutex_lock(&skt->skt_mutex);
831 do { 828 do {
832 if (!(skt->state & SOCKET_PRESENT)) { 829 if (!(skt->state & SOCKET_PRESENT)) {
833 ret = CS_NO_CARD; 830 ret = CS_NO_CARD;
@@ -841,7 +838,7 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
841 if (!ret && skt->callback) 838 if (!ret && skt->callback)
842 skt->callback->resume(skt); 839 skt->callback->resume(skt);
843 } while (0); 840 } while (0);
844 up(&skt->skt_sem); 841 mutex_unlock(&skt->skt_mutex);
845 842
846 return ret; 843 return ret;
847} /* resume_card */ 844} /* resume_card */
@@ -855,7 +852,7 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
855 852
856 cs_dbg(skt, 1, "user eject request\n"); 853 cs_dbg(skt, 1, "user eject request\n");
857 854
858 down(&skt->skt_sem); 855 mutex_lock(&skt->skt_mutex);
859 do { 856 do {
860 if (!(skt->state & SOCKET_PRESENT)) { 857 if (!(skt->state & SOCKET_PRESENT)) {
861 ret = -ENODEV; 858 ret = -ENODEV;
@@ -871,7 +868,7 @@ int pcmcia_eject_card(struct pcmcia_socket *skt)
871 socket_remove(skt); 868 socket_remove(skt);
872 ret = 0; 869 ret = 0;
873 } while (0); 870 } while (0);
874 up(&skt->skt_sem); 871 mutex_unlock(&skt->skt_mutex);
875 872
876 return ret; 873 return ret;
877} /* eject_card */ 874} /* eject_card */
@@ -884,7 +881,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
884 881
885 cs_dbg(skt, 1, "user insert request\n"); 882 cs_dbg(skt, 1, "user insert request\n");
886 883
887 down(&skt->skt_sem); 884 mutex_lock(&skt->skt_mutex);
888 do { 885 do {
889 if (skt->state & SOCKET_PRESENT) { 886 if (skt->state & SOCKET_PRESENT) {
890 ret = -EBUSY; 887 ret = -EBUSY;
@@ -896,7 +893,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
896 } 893 }
897 ret = 0; 894 ret = 0;
898 } while (0); 895 } while (0);
899 up(&skt->skt_sem); 896 mutex_unlock(&skt->skt_mutex);
900 897
901 return ret; 898 return ret;
902} /* insert_card */ 899} /* insert_card */
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 7b37eba35bf1..d6164cd583fd 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -15,7 +15,7 @@
15#ifndef _LINUX_CS_INTERNAL_H 15#ifndef _LINUX_CS_INTERNAL_H
16#define _LINUX_CS_INTERNAL_H 16#define _LINUX_CS_INTERNAL_H
17 17
18#include <linux/config.h> 18#include <linux/kref.h>
19 19
20/* Flags in client state */ 20/* Flags in client state */
21#define CLIENT_CONFIG_LOCKED 0x0001 21#define CLIENT_CONFIG_LOCKED 0x0001
@@ -23,7 +23,7 @@
23#define CLIENT_IO_REQ 0x0004 23#define CLIENT_IO_REQ 0x0004
24#define CLIENT_UNBOUND 0x0008 24#define CLIENT_UNBOUND 0x0008
25#define CLIENT_STALE 0x0010 25#define CLIENT_STALE 0x0010
26#define CLIENT_WIN_REQ(i) (0x20<<(i)) 26#define CLIENT_WIN_REQ(i) (0x1<<(i))
27#define CLIENT_CARDBUS 0x8000 27#define CLIENT_CARDBUS 0x8000
28 28
29#define REGION_MAGIC 0xE3C9 29#define REGION_MAGIC 0xE3C9
@@ -31,7 +31,7 @@ typedef struct region_t {
31 u_short region_magic; 31 u_short region_magic;
32 u_short state; 32 u_short state;
33 dev_info_t dev_info; 33 dev_info_t dev_info;
34 client_handle_t mtd; 34 struct pcmcia_device *mtd;
35 u_int MediaID; 35 u_int MediaID;
36 region_info_t info; 36 region_info_t info;
37} region_t; 37} region_t;
@@ -40,12 +40,12 @@ typedef struct region_t {
40 40
41/* Each card function gets one of these guys */ 41/* Each card function gets one of these guys */
42typedef struct config_t { 42typedef struct config_t {
43 struct kref ref;
43 u_int state; 44 u_int state;
44 u_int Attributes; 45 u_int Attributes;
45 u_int IntType; 46 u_int IntType;
46 u_int ConfigBase; 47 u_int ConfigBase;
47 u_char Status, Pin, Copy, Option, ExtStatus; 48 u_char Status, Pin, Copy, Option, ExtStatus;
48 u_int Present;
49 u_int CardValues; 49 u_int CardValues;
50 io_req_t io; 50 io_req_t io;
51 struct { 51 struct {
@@ -95,12 +95,6 @@ static inline void cs_socket_put(struct pcmcia_socket *skt)
95 } 95 }
96} 96}
97 97
98#define CHECK_SOCKET(s) \
99 (((s) >= sockets) || (socket_table[s]->ops == NULL))
100
101#define SOCKET(h) (h->socket)
102#define CONFIG(h) (&SOCKET(h)->config[(h)->func])
103
104/* In cardbus.c */ 98/* In cardbus.c */
105int cb_alloc(struct pcmcia_socket *s); 99int cb_alloc(struct pcmcia_socket *s);
106void cb_free(struct pcmcia_socket *s); 100void cb_free(struct pcmcia_socket *s);
@@ -133,10 +127,9 @@ extern struct class_interface pccard_sysfs_interface;
133extern struct rw_semaphore pcmcia_socket_list_rwsem; 127extern struct rw_semaphore pcmcia_socket_list_rwsem;
134extern struct list_head pcmcia_socket_list; 128extern struct list_head pcmcia_socket_list;
135int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req); 129int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
136int pccard_get_configuration_info(struct pcmcia_socket *s, unsigned int function, config_info_t *config); 130int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config);
137int pccard_reset_card(struct pcmcia_socket *skt); 131int pccard_reset_card(struct pcmcia_socket *skt);
138int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status); 132int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev, cs_status_t *status);
139int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int function, conf_reg_t *reg);
140 133
141 134
142struct pcmcia_callback{ 135struct pcmcia_callback{
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index bb96ce1db08c..ae10d1eed65e 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -10,10 +10,9 @@
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 * 11 *
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2005 Dominik Brodowski 13 * (C) 2003 - 2006 Dominik Brodowski
14 */ 14 */
15 15
16#include <linux/config.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/init.h> 18#include <linux/init.h>
@@ -23,6 +22,7 @@
23#include <linux/workqueue.h> 22#include <linux/workqueue.h>
24#include <linux/crc32.h> 23#include <linux/crc32.h>
25#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/kref.h>
26 26
27#define IN_CARD_SERVICES 27#define IN_CARD_SERVICES
28#include <pcmcia/cs_types.h> 28#include <pcmcia/cs_types.h>
@@ -343,12 +343,19 @@ void pcmcia_put_dev(struct pcmcia_device *p_dev)
343 put_device(&p_dev->dev); 343 put_device(&p_dev->dev);
344} 344}
345 345
346static void pcmcia_release_function(struct kref *ref)
347{
348 struct config_t *c = container_of(ref, struct config_t, ref);
349 kfree(c);
350}
351
346static void pcmcia_release_dev(struct device *dev) 352static void pcmcia_release_dev(struct device *dev)
347{ 353{
348 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 354 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
349 ds_dbg(1, "releasing dev %p\n", p_dev); 355 ds_dbg(1, "releasing dev %p\n", p_dev);
350 pcmcia_put_socket(p_dev->socket); 356 pcmcia_put_socket(p_dev->socket);
351 kfree(p_dev->devname); 357 kfree(p_dev->devname);
358 kref_put(&p_dev->function_config->ref, pcmcia_release_function);
352 kfree(p_dev); 359 kfree(p_dev);
353} 360}
354 361
@@ -377,29 +384,12 @@ static int pcmcia_device_probe(struct device * dev)
377 p_drv = to_pcmcia_drv(dev->driver); 384 p_drv = to_pcmcia_drv(dev->driver);
378 s = p_dev->socket; 385 s = p_dev->socket;
379 386
380 if ((!p_drv->probe) || (!try_module_get(p_drv->owner))) { 387 if ((!p_drv->probe) || (!p_dev->function_config) ||
388 (!try_module_get(p_drv->owner))) {
381 ret = -EINVAL; 389 ret = -EINVAL;
382 goto put_dev; 390 goto put_dev;
383 } 391 }
384 392
385 p_dev->state &= ~CLIENT_UNBOUND;
386
387 /* set up the device configuration, if it hasn't been done before */
388 if (!s->functions) {
389 cistpl_longlink_mfc_t mfc;
390 if (pccard_read_tuple(s, p_dev->func, CISTPL_LONGLINK_MFC,
391 &mfc) == CS_SUCCESS)
392 s->functions = mfc.nfn;
393 else
394 s->functions = 1;
395 s->config = kzalloc(sizeof(config_t) * s->functions,
396 GFP_KERNEL);
397 if (!s->config) {
398 ret = -ENOMEM;
399 goto put_module;
400 }
401 }
402
403 ret = p_drv->probe(p_dev); 393 ret = p_drv->probe(p_dev);
404 if (ret) 394 if (ret)
405 goto put_module; 395 goto put_module;
@@ -425,15 +415,61 @@ static int pcmcia_device_probe(struct device * dev)
425} 415}
426 416
427 417
418/*
419 * Removes a PCMCIA card from the device tree and socket list.
420 */
421static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *leftover)
422{
423 struct pcmcia_device *p_dev;
424 struct pcmcia_device *tmp;
425 unsigned long flags;
426
427 ds_dbg(2, "unbind_request(%d)\n", s->sock);
428
429
430 if (!leftover)
431 s->device_count = 0;
432 else
433 s->device_count = 1;
434
435 /* unregister all pcmcia_devices registered with this socket, except leftover */
436 list_for_each_entry_safe(p_dev, tmp, &s->devices_list, socket_device_list) {
437 if (p_dev == leftover)
438 continue;
439
440 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
441 list_del(&p_dev->socket_device_list);
442 p_dev->_removed=1;
443 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
444
445 device_unregister(&p_dev->dev);
446 }
447
448 return;
449}
450
451
428static int pcmcia_device_remove(struct device * dev) 452static int pcmcia_device_remove(struct device * dev)
429{ 453{
430 struct pcmcia_device *p_dev; 454 struct pcmcia_device *p_dev;
431 struct pcmcia_driver *p_drv; 455 struct pcmcia_driver *p_drv;
456 struct pcmcia_device_id *did;
432 int i; 457 int i;
433 458
434 /* detach the "instance" */
435 p_dev = to_pcmcia_dev(dev); 459 p_dev = to_pcmcia_dev(dev);
436 p_drv = to_pcmcia_drv(dev->driver); 460 p_drv = to_pcmcia_drv(dev->driver);
461
462 /* If we're removing the primary module driving a
463 * pseudo multi-function card, we need to unbind
464 * all devices
465 */
466 did = (struct pcmcia_device_id *) p_dev->dev.driver_data;
467 if (did && (did->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO) &&
468 (p_dev->socket->device_count != 0) &&
469 (p_dev->device_no == 0))
470 pcmcia_card_remove(p_dev->socket, p_dev);
471
472 /* detach the "instance" */
437 if (!p_drv) 473 if (!p_drv)
438 return 0; 474 return 0;
439 475
@@ -441,17 +477,16 @@ static int pcmcia_device_remove(struct device * dev)
441 p_drv->remove(p_dev); 477 p_drv->remove(p_dev);
442 478
443 /* check for proper unloading */ 479 /* check for proper unloading */
444 if (p_dev->state & (CLIENT_IRQ_REQ|CLIENT_IO_REQ|CLIENT_CONFIG_LOCKED)) 480 if (p_dev->_irq || p_dev->_io || p_dev->_locked)
445 printk(KERN_INFO "pcmcia: driver %s did not release config properly\n", 481 printk(KERN_INFO "pcmcia: driver %s did not release config properly\n",
446 p_drv->drv.name); 482 p_drv->drv.name);
447 483
448 for (i = 0; i < MAX_WIN; i++) 484 for (i = 0; i < MAX_WIN; i++)
449 if (p_dev->state & CLIENT_WIN_REQ(i)) 485 if (p_dev->_win & CLIENT_WIN_REQ(i))
450 printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", 486 printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n",
451 p_drv->drv.name); 487 p_drv->drv.name);
452 488
453 /* references from pcmcia_probe_device */ 489 /* references from pcmcia_probe_device */
454 p_dev->state = CLIENT_UNBOUND;
455 pcmcia_put_dev(p_dev); 490 pcmcia_put_dev(p_dev);
456 module_put(p_drv->owner); 491 module_put(p_drv->owner);
457 492
@@ -460,37 +495,6 @@ static int pcmcia_device_remove(struct device * dev)
460 495
461 496
462/* 497/*
463 * Removes a PCMCIA card from the device tree and socket list.
464 */
465static void pcmcia_card_remove(struct pcmcia_socket *s)
466{
467 struct pcmcia_device *p_dev;
468 unsigned long flags;
469
470 ds_dbg(2, "unbind_request(%d)\n", s->sock);
471
472 s->device_count = 0;
473
474 for (;;) {
475 /* unregister all pcmcia_devices registered with this socket*/
476 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
477 if (list_empty(&s->devices_list)) {
478 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
479 return;
480 }
481 p_dev = list_entry((&s->devices_list)->next, struct pcmcia_device, socket_device_list);
482 list_del(&p_dev->socket_device_list);
483 p_dev->state |= CLIENT_STALE;
484 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
485
486 device_unregister(&p_dev->dev);
487 }
488
489 return;
490} /* unbind_request */
491
492
493/*
494 * pcmcia_device_query -- determine information about a pcmcia device 498 * pcmcia_device_query -- determine information about a pcmcia device
495 */ 499 */
496static int pcmcia_device_query(struct pcmcia_device *p_dev) 500static int pcmcia_device_query(struct pcmcia_device *p_dev)
@@ -546,7 +550,7 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
546 tmp = vers1->str + vers1->ofs[i]; 550 tmp = vers1->str + vers1->ofs[i];
547 551
548 length = strlen(tmp) + 1; 552 length = strlen(tmp) + 1;
549 if ((length < 3) || (length > 255)) 553 if ((length < 2) || (length > 255))
550 continue; 554 continue;
551 555
552 p_dev->prod_id[i] = kmalloc(sizeof(char) * length, 556 p_dev->prod_id[i] = kmalloc(sizeof(char) * length,
@@ -571,11 +575,11 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
571 * won't work, this doesn't matter much at the moment: the driver core doesn't 575 * won't work, this doesn't matter much at the moment: the driver core doesn't
572 * support it either. 576 * support it either.
573 */ 577 */
574static DECLARE_MUTEX(device_add_lock); 578static DEFINE_MUTEX(device_add_lock);
575 579
576struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function) 580struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
577{ 581{
578 struct pcmcia_device *p_dev; 582 struct pcmcia_device *p_dev, *tmp_dev;
579 unsigned long flags; 583 unsigned long flags;
580 int bus_id_len; 584 int bus_id_len;
581 585
@@ -583,7 +587,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
583 if (!s) 587 if (!s)
584 return NULL; 588 return NULL;
585 589
586 down(&device_add_lock); 590 mutex_lock(&device_add_lock);
587 591
588 /* max of 2 devices per card */ 592 /* max of 2 devices per card */
589 if (s->device_count == 2) 593 if (s->device_count == 2)
@@ -596,6 +600,8 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
596 p_dev->socket = s; 600 p_dev->socket = s;
597 p_dev->device_no = (s->device_count++); 601 p_dev->device_no = (s->device_count++);
598 p_dev->func = function; 602 p_dev->func = function;
603 if (s->functions <= function)
604 s->functions = function + 1;
599 605
600 p_dev->dev.bus = &pcmcia_bus_type; 606 p_dev->dev.bus = &pcmcia_bus_type;
601 p_dev->dev.parent = s->dev.dev; 607 p_dev->dev.parent = s->dev.dev;
@@ -608,36 +614,55 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
608 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id); 614 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
609 615
610 /* compat */ 616 /* compat */
611 p_dev->state = CLIENT_UNBOUND; 617 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
618
619 /*
620 * p_dev->function_config must be the same for all card functions.
621 * Note that this is serialized by the device_add_lock, so that
622 * only one such struct will be created.
623 */
624 list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list)
625 if (p_dev->func == tmp_dev->func) {
626 p_dev->function_config = tmp_dev->function_config;
627 kref_get(&p_dev->function_config->ref);
628 }
612 629
613 /* Add to the list in pcmcia_bus_socket */ 630 /* Add to the list in pcmcia_bus_socket */
614 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
615 list_add_tail(&p_dev->socket_device_list, &s->devices_list); 631 list_add_tail(&p_dev->socket_device_list, &s->devices_list);
632
616 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 633 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
617 634
635 if (!p_dev->function_config) {
636 p_dev->function_config = kzalloc(sizeof(struct config_t),
637 GFP_KERNEL);
638 if (!p_dev->function_config)
639 goto err_unreg;
640 kref_init(&p_dev->function_config->ref);
641 }
642
618 printk(KERN_NOTICE "pcmcia: registering new device %s\n", 643 printk(KERN_NOTICE "pcmcia: registering new device %s\n",
619 p_dev->devname); 644 p_dev->devname);
620 645
621 pcmcia_device_query(p_dev); 646 pcmcia_device_query(p_dev);
622 647
623 if (device_register(&p_dev->dev)) { 648 if (device_register(&p_dev->dev))
624 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 649 goto err_unreg;
625 list_del(&p_dev->socket_device_list);
626 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
627
628 goto err_free;
629 }
630 650
631 up(&device_add_lock); 651 mutex_unlock(&device_add_lock);
632 652
633 return p_dev; 653 return p_dev;
634 654
655 err_unreg:
656 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
657 list_del(&p_dev->socket_device_list);
658 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
659
635 err_free: 660 err_free:
636 kfree(p_dev->devname); 661 kfree(p_dev->devname);
637 kfree(p_dev); 662 kfree(p_dev);
638 s->device_count--; 663 s->device_count--;
639 err_put: 664 err_put:
640 up(&device_add_lock); 665 mutex_unlock(&device_add_lock);
641 pcmcia_put_socket(s); 666 pcmcia_put_socket(s);
642 667
643 return NULL; 668 return NULL;
@@ -696,7 +721,7 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt)
696 int no_devices=0; 721 int no_devices=0;
697 unsigned long flags; 722 unsigned long flags;
698 723
699 /* must be called with skt_sem held */ 724 /* must be called with skt_mutex held */
700 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 725 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
701 if (list_empty(&skt->devices_list)) 726 if (list_empty(&skt->devices_list))
702 no_devices=1; 727 no_devices=1;
@@ -819,9 +844,11 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
819 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv); 844 struct pcmcia_driver * p_drv = to_pcmcia_drv(drv);
820 struct pcmcia_device_id *did = p_drv->id_table; 845 struct pcmcia_device_id *did = p_drv->id_table;
821 846
847#ifdef CONFIG_PCMCIA_IOCTL
822 /* matching by cardmgr */ 848 /* matching by cardmgr */
823 if (p_dev->cardmgr == p_drv) 849 if (p_dev->cardmgr == p_drv)
824 return 1; 850 return 1;
851#endif
825 852
826 while (did && did->match_flags) { 853 while (did && did->match_flags) {
827 if (pcmcia_devmatch(p_dev, did)) 854 if (pcmcia_devmatch(p_dev, did))
@@ -927,7 +954,7 @@ static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute
927{ 954{
928 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 955 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
929 956
930 if (p_dev->dev.power.power_state.event != PM_EVENT_ON) 957 if (p_dev->suspended)
931 return sprintf(buf, "off\n"); 958 return sprintf(buf, "off\n");
932 else 959 else
933 return sprintf(buf, "on\n"); 960 return sprintf(buf, "on\n");
@@ -942,11 +969,9 @@ static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute
942 if (!count) 969 if (!count)
943 return -EINVAL; 970 return -EINVAL;
944 971
945 if ((p_dev->dev.power.power_state.event == PM_EVENT_ON) && 972 if ((!p_dev->suspended) && !strncmp(buf, "off", 3))
946 (!strncmp(buf, "off", 3)))
947 ret = dpm_runtime_suspend(dev, PMSG_SUSPEND); 973 ret = dpm_runtime_suspend(dev, PMSG_SUSPEND);
948 else if ((p_dev->dev.power.power_state.event != PM_EVENT_ON) && 974 else if (p_dev->suspended && !strncmp(buf, "on", 2))
949 (!strncmp(buf, "on", 2)))
950 dpm_runtime_resume(dev); 975 dpm_runtime_resume(dev);
951 976
952 return ret ? ret : count; 977 return ret ? ret : count;
@@ -982,9 +1007,9 @@ static ssize_t pcmcia_store_allow_func_id_match(struct device *dev,
982 if (!count) 1007 if (!count)
983 return -EINVAL; 1008 return -EINVAL;
984 1009
985 down(&p_dev->socket->skt_sem); 1010 mutex_lock(&p_dev->socket->skt_mutex);
986 p_dev->allow_func_id_match = 1; 1011 p_dev->allow_func_id_match = 1;
987 up(&p_dev->socket->skt_sem); 1012 mutex_unlock(&p_dev->socket->skt_mutex);
988 1013
989 bus_rescan_devices(&pcmcia_bus_type); 1014 bus_rescan_devices(&pcmcia_bus_type);
990 1015
@@ -1012,14 +1037,27 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
1012{ 1037{
1013 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 1038 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
1014 struct pcmcia_driver *p_drv = NULL; 1039 struct pcmcia_driver *p_drv = NULL;
1040 int ret = 0;
1015 1041
1016 if (dev->driver) 1042 if (dev->driver)
1017 p_drv = to_pcmcia_drv(dev->driver); 1043 p_drv = to_pcmcia_drv(dev->driver);
1018 1044
1019 if (p_drv && p_drv->suspend) 1045 if (!p_drv)
1020 return p_drv->suspend(p_dev); 1046 goto out;
1021 1047
1022 return 0; 1048 if (p_drv->suspend) {
1049 ret = p_drv->suspend(p_dev);
1050 if (ret)
1051 goto out;
1052 }
1053
1054 if (p_dev->device_no == p_dev->func)
1055 pcmcia_release_configuration(p_dev);
1056
1057 out:
1058 if (!ret)
1059 p_dev->suspended = 1;
1060 return ret;
1023} 1061}
1024 1062
1025 1063
@@ -1027,14 +1065,27 @@ static int pcmcia_dev_resume(struct device * dev)
1027{ 1065{
1028 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 1066 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
1029 struct pcmcia_driver *p_drv = NULL; 1067 struct pcmcia_driver *p_drv = NULL;
1068 int ret = 0;
1030 1069
1031 if (dev->driver) 1070 if (dev->driver)
1032 p_drv = to_pcmcia_drv(dev->driver); 1071 p_drv = to_pcmcia_drv(dev->driver);
1033 1072
1034 if (p_drv && p_drv->resume) 1073 if (!p_drv)
1035 return p_drv->resume(p_dev); 1074 goto out;
1036 1075
1037 return 0; 1076 if (p_dev->device_no == p_dev->func) {
1077 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
1078 if (ret)
1079 goto out;
1080 }
1081
1082 if (p_drv->resume)
1083 ret = p_drv->resume(p_dev);
1084
1085 out:
1086 if (!ret)
1087 p_dev->suspended = 0;
1088 return ret;
1038} 1089}
1039 1090
1040 1091
@@ -1100,7 +1151,7 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1100 switch (event) { 1151 switch (event) {
1101 case CS_EVENT_CARD_REMOVAL: 1152 case CS_EVENT_CARD_REMOVAL:
1102 s->pcmcia_state.present = 0; 1153 s->pcmcia_state.present = 0;
1103 pcmcia_card_remove(skt); 1154 pcmcia_card_remove(skt, NULL);
1104 handle_event(skt, event); 1155 handle_event(skt, event);
1105 break; 1156 break;
1106 1157
@@ -1128,6 +1179,32 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1128} /* ds_event */ 1179} /* ds_event */
1129 1180
1130 1181
1182struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *_p_dev)
1183{
1184 struct pcmcia_device *p_dev;
1185 struct pcmcia_device *ret = NULL;
1186
1187 p_dev = pcmcia_get_dev(_p_dev);
1188 if (!p_dev)
1189 return NULL;
1190
1191 if (!p_dev->socket->pcmcia_state.present)
1192 goto out;
1193
1194 if (p_dev->_removed)
1195 goto out;
1196
1197 if (p_dev->suspended)
1198 goto out;
1199
1200 ret = p_dev;
1201 out:
1202 pcmcia_put_dev(p_dev);
1203 return ret;
1204}
1205EXPORT_SYMBOL(pcmcia_dev_present);
1206
1207
1131static struct pcmcia_callback pcmcia_bus_callback = { 1208static struct pcmcia_callback pcmcia_bus_callback = {
1132 .owner = THIS_MODULE, 1209 .owner = THIS_MODULE,
1133 .event = ds_event, 1210 .event = ds_event,
diff --git a/drivers/pcmcia/ds_internal.h b/drivers/pcmcia/ds_internal.h
index d359bd25a51c..3a2b25e6ed73 100644
--- a/drivers/pcmcia/ds_internal.h
+++ b/drivers/pcmcia/ds_internal.h
@@ -8,6 +8,8 @@ extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
8 8
9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function); 9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function);
10 10
11extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
12
11#ifdef CONFIG_PCMCIA_IOCTL 13#ifdef CONFIG_PCMCIA_IOCTL
12extern void __init pcmcia_setup_ioctl(void); 14extern void __init pcmcia_setup_ioctl(void);
13extern void __exit pcmcia_cleanup_ioctl(void); 15extern void __exit pcmcia_cleanup_ioctl(void);
@@ -15,7 +17,7 @@ extern void handle_event(struct pcmcia_socket *s, event_t event);
15extern int handle_request(struct pcmcia_socket *s, event_t event); 17extern int handle_request(struct pcmcia_socket *s, event_t event);
16#else 18#else
17static inline void __init pcmcia_setup_ioctl(void) { return; } 19static inline void __init pcmcia_setup_ioctl(void) { return; }
18static inline void __init pcmcia_cleanup_ioctl(void) { return; } 20static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
19static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; } 21static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; }
20static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; } 22static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; }
21#endif 23#endif
diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c
index 7979c85df3dc..d5f03a338c6c 100644
--- a/drivers/pcmcia/i82092.c
+++ b/drivers/pcmcia/i82092.c
@@ -10,7 +10,6 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/config.h>
14#include <linux/module.h> 13#include <linux/module.h>
15#include <linux/pci.h> 14#include <linux/pci.h>
16#include <linux/init.h> 15#include <linux/init.h>
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 35a92d1e4945..bd0308e89815 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -34,7 +34,6 @@
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/config.h>
38#include <linux/types.h> 37#include <linux/types.h>
39#include <linux/fcntl.h> 38#include <linux/fcntl.h>
40#include <linux/string.h> 39#include <linux/string.h>
diff --git a/drivers/pcmcia/pcmcia_compat.c b/drivers/pcmcia/pcmcia_compat.c
deleted file mode 100644
index ebb161c4f819..000000000000
--- a/drivers/pcmcia/pcmcia_compat.c
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 * PCMCIA 16-bit compatibility functions
3 *
4 * The initial developer of the original code is David A. Hinds
5 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
7 *
8 * Copyright (C) 2004 Dominik Brodowski
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 */
15
16#include <linux/config.h>
17#include <linux/module.h>
18#include <linux/init.h>
19
20#define IN_CARD_SERVICES
21#include <pcmcia/cs_types.h>
22#include <pcmcia/cs.h>
23#include <pcmcia/bulkmem.h>
24#include <pcmcia/cistpl.h>
25#include <pcmcia/ds.h>
26#include <pcmcia/ss.h>
27
28#include "cs_internal.h"
29
30int pcmcia_get_first_tuple(struct pcmcia_device *p_dev, tuple_t *tuple)
31{
32 return pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple);
33}
34EXPORT_SYMBOL(pcmcia_get_first_tuple);
35
36int pcmcia_get_next_tuple(struct pcmcia_device *p_dev, tuple_t *tuple)
37{
38 return pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple);
39}
40EXPORT_SYMBOL(pcmcia_get_next_tuple);
41
42int pcmcia_get_tuple_data(struct pcmcia_device *p_dev, tuple_t *tuple)
43{
44 return pccard_get_tuple_data(p_dev->socket, tuple);
45}
46EXPORT_SYMBOL(pcmcia_get_tuple_data);
47
48int pcmcia_parse_tuple(struct pcmcia_device *p_dev, tuple_t *tuple, cisparse_t *parse)
49{
50 return pccard_parse_tuple(tuple, parse);
51}
52EXPORT_SYMBOL(pcmcia_parse_tuple);
53
54int pcmcia_validate_cis(struct pcmcia_device *p_dev, cisinfo_t *info)
55{
56 return pccard_validate_cis(p_dev->socket, p_dev->func, info);
57}
58EXPORT_SYMBOL(pcmcia_validate_cis);
59
60
61int pcmcia_reset_card(struct pcmcia_device *p_dev, client_req_t *req)
62{
63 return pccard_reset_card(p_dev->socket);
64}
65EXPORT_SYMBOL(pcmcia_reset_card);
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index 80969f7e7a0b..c53db7ceda5e 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -18,7 +18,6 @@
18 */ 18 */
19 19
20 20
21#include <linux/config.h>
22#include <linux/kernel.h> 21#include <linux/kernel.h>
23#include <linux/module.h> 22#include <linux/module.h>
24#include <linux/init.h> 23#include <linux/init.h>
@@ -70,10 +69,26 @@ extern int ds_pc_debug;
70#define ds_dbg(lvl, fmt, arg...) do { } while (0) 69#define ds_dbg(lvl, fmt, arg...) do { } while (0)
71#endif 70#endif
72 71
72static struct pcmcia_device *get_pcmcia_device(struct pcmcia_socket *s,
73 unsigned int function)
74{
75 struct pcmcia_device *p_dev = NULL;
76 unsigned long flags;
77
78 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
79 list_for_each_entry(p_dev, &s->devices_list, socket_device_list) {
80 if (p_dev->func == function) {
81 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
82 return pcmcia_get_dev(p_dev);
83 }
84 }
85 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
86 return NULL;
87}
73 88
74/* backwards-compatible accessing of driver --- by name! */ 89/* backwards-compatible accessing of driver --- by name! */
75 90
76static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info) 91static struct pcmcia_driver *get_pcmcia_driver(dev_info_t *dev_info)
77{ 92{
78 struct device_driver *drv; 93 struct device_driver *drv;
79 struct pcmcia_driver *p_drv; 94 struct pcmcia_driver *p_drv;
@@ -214,7 +229,7 @@ static int bind_request(struct pcmcia_socket *s, bind_info_t *bind_info)
214 * by userspace before, we need to 229 * by userspace before, we need to
215 * return the "instance". */ 230 * return the "instance". */
216 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 231 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
217 bind_info->instance = p_dev->instance; 232 bind_info->instance = p_dev;
218 ret = -EBUSY; 233 ret = -EBUSY;
219 goto err_put_module; 234 goto err_put_module;
220 } else { 235 } else {
@@ -253,9 +268,9 @@ rescan:
253 /* 268 /*
254 * Prevent this racing with a card insertion. 269 * Prevent this racing with a card insertion.
255 */ 270 */
256 down(&s->skt_sem); 271 mutex_lock(&s->skt_mutex);
257 bus_rescan_devices(&pcmcia_bus_type); 272 bus_rescan_devices(&pcmcia_bus_type);
258 up(&s->skt_sem); 273 mutex_unlock(&s->skt_mutex);
259 274
260 /* check whether the driver indeed matched. I don't care if this 275 /* check whether the driver indeed matched. I don't care if this
261 * is racy or not, because it can only happen on cardmgr access 276 * is racy or not, because it can only happen on cardmgr access
@@ -289,6 +304,7 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
289{ 304{
290 dev_node_t *node; 305 dev_node_t *node;
291 struct pcmcia_device *p_dev; 306 struct pcmcia_device *p_dev;
307 struct pcmcia_driver *p_drv;
292 unsigned long flags; 308 unsigned long flags;
293 int ret = 0; 309 int ret = 0;
294 310
@@ -343,16 +359,16 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
343 found: 359 found:
344 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 360 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
345 361
346 if ((!p_dev->instance) || 362 p_drv = to_pcmcia_drv(p_dev->dev.driver);
347 (p_dev->instance->state & DEV_CONFIG_PENDING)) { 363 if (p_drv && !p_dev->_locked) {
348 ret = -EAGAIN; 364 ret = -EAGAIN;
349 goto err_put; 365 goto err_put;
350 } 366 }
351 367
352 if (first) 368 if (first)
353 node = p_dev->instance->dev; 369 node = p_dev->dev_node;
354 else 370 else
355 for (node = p_dev->instance->dev; node; node = node->next) 371 for (node = p_dev->dev_node; node; node = node->next)
356 if (node == bind_info->next) 372 if (node == bind_info->next)
357 break; 373 break;
358 if (!node) { 374 if (!node) {
@@ -583,14 +599,16 @@ static int ds_ioctl(struct inode * inode, struct file * file,
583 if (buf->config.Function && 599 if (buf->config.Function &&
584 (buf->config.Function >= s->functions)) 600 (buf->config.Function >= s->functions))
585 ret = CS_BAD_ARGS; 601 ret = CS_BAD_ARGS;
586 else 602 else {
587 ret = pccard_get_configuration_info(s, 603 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
588 buf->config.Function, &buf->config); 604 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
605 pcmcia_put_dev(p_dev);
606 }
589 break; 607 break;
590 case DS_GET_FIRST_TUPLE: 608 case DS_GET_FIRST_TUPLE:
591 down(&s->skt_sem); 609 mutex_lock(&s->skt_mutex);
592 pcmcia_validate_mem(s); 610 pcmcia_validate_mem(s);
593 up(&s->skt_sem); 611 mutex_unlock(&s->skt_mutex);
594 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple); 612 ret = pccard_get_first_tuple(s, BIND_FN_ALL, &buf->tuple);
595 break; 613 break;
596 case DS_GET_NEXT_TUPLE: 614 case DS_GET_NEXT_TUPLE:
@@ -609,16 +627,19 @@ static int ds_ioctl(struct inode * inode, struct file * file,
609 ret = pccard_reset_card(s); 627 ret = pccard_reset_card(s);
610 break; 628 break;
611 case DS_GET_STATUS: 629 case DS_GET_STATUS:
612 if (buf->status.Function && 630 if (buf->status.Function &&
613 (buf->status.Function >= s->functions)) 631 (buf->status.Function >= s->functions))
614 ret = CS_BAD_ARGS; 632 ret = CS_BAD_ARGS;
615 else 633 else {
616 ret = pccard_get_status(s, buf->status.Function, &buf->status); 634 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
617 break; 635 ret = pccard_get_status(s, p_dev, &buf->status);
636 pcmcia_put_dev(p_dev);
637 }
638 break;
618 case DS_VALIDATE_CIS: 639 case DS_VALIDATE_CIS:
619 down(&s->skt_sem); 640 mutex_lock(&s->skt_mutex);
620 pcmcia_validate_mem(s); 641 pcmcia_validate_mem(s);
621 up(&s->skt_sem); 642 mutex_unlock(&s->skt_mutex);
622 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo); 643 ret = pccard_validate_cis(s, BIND_FN_ALL, &buf->cisinfo);
623 break; 644 break;
624 case DS_SUSPEND_CARD: 645 case DS_SUSPEND_CARD:
@@ -638,12 +659,16 @@ static int ds_ioctl(struct inode * inode, struct file * file,
638 err = -EPERM; 659 err = -EPERM;
639 goto free_out; 660 goto free_out;
640 } 661 }
641 if (buf->conf_reg.Function && 662
642 (buf->conf_reg.Function >= s->functions)) 663 ret = CS_BAD_ARGS;
643 ret = CS_BAD_ARGS; 664
644 else 665 if (!(buf->conf_reg.Function &&
645 ret = pccard_access_configuration_register(s, 666 (buf->conf_reg.Function >= s->functions))) {
646 buf->conf_reg.Function, &buf->conf_reg); 667 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->conf_reg.Function);
668 if (p_dev)
669 ret = pcmcia_access_configuration_register(p_dev, &buf->conf_reg);
670 pcmcia_put_dev(p_dev);
671 }
647 break; 672 break;
648 case DS_GET_FIRST_REGION: 673 case DS_GET_FIRST_REGION:
649 case DS_GET_NEXT_REGION: 674 case DS_GET_NEXT_REGION:
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 89022ad5b520..45063b4e5b78 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -14,7 +14,6 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/config.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/interrupt.h> 19#include <linux/interrupt.h>
@@ -89,7 +88,7 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
89 } 88 }
90 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) { 89 if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
91 *base = s->io_offset | (*base & 0x0fff); 90 *base = s->io_offset | (*base & 0x0fff);
92 s->io[0].Attributes = attr; 91 s->io[0].res->flags = (s->io[0].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
93 return 0; 92 return 0;
94 } 93 }
95 /* Check for an already-allocated window that must conflict with 94 /* Check for an already-allocated window that must conflict with
@@ -97,38 +96,36 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr, ioaddr_t *base,
97 * potential conflicts, just the most obvious ones. 96 * potential conflicts, just the most obvious ones.
98 */ 97 */
99 for (i = 0; i < MAX_IO_WIN; i++) 98 for (i = 0; i < MAX_IO_WIN; i++)
100 if ((s->io[i].NumPorts != 0) && 99 if ((s->io[i].res) &&
101 ((s->io[i].BasePort & (align-1)) == *base)) 100 ((s->io[i].res->start & (align-1)) == *base))
102 return 1; 101 return 1;
103 for (i = 0; i < MAX_IO_WIN; i++) { 102 for (i = 0; i < MAX_IO_WIN; i++) {
104 if (s->io[i].NumPorts == 0) { 103 if (!s->io[i].res) {
105 s->io[i].res = pcmcia_find_io_region(*base, num, align, s); 104 s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
106 if (s->io[i].res) { 105 if (s->io[i].res) {
107 s->io[i].Attributes = attr; 106 *base = s->io[i].res->start;
108 s->io[i].BasePort = *base = s->io[i].res->start; 107 s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
109 s->io[i].NumPorts = s->io[i].InUse = num; 108 s->io[i].InUse = num;
110 break; 109 break;
111 } else 110 } else
112 return 1; 111 return 1;
113 } else if (s->io[i].Attributes != attr) 112 } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
114 continue; 113 continue;
115 /* Try to extend top of window */ 114 /* Try to extend top of window */
116 try = s->io[i].BasePort + s->io[i].NumPorts; 115 try = s->io[i].res->end + 1;
117 if ((*base == 0) || (*base == try)) 116 if ((*base == 0) || (*base == try))
118 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start, 117 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
119 s->io[i].res->end + num, s) == 0) { 118 s->io[i].res->end + num, s) == 0) {
120 *base = try; 119 *base = try;
121 s->io[i].NumPorts += num;
122 s->io[i].InUse += num; 120 s->io[i].InUse += num;
123 break; 121 break;
124 } 122 }
125 /* Try to extend bottom of window */ 123 /* Try to extend bottom of window */
126 try = s->io[i].BasePort - num; 124 try = s->io[i].res->start - num;
127 if ((*base == 0) || (*base == try)) 125 if ((*base == 0) || (*base == try))
128 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num, 126 if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
129 s->io[i].res->end, s) == 0) { 127 s->io[i].res->end, s) == 0) {
130 s->io[i].BasePort = *base = try; 128 *base = try;
131 s->io[i].NumPorts += num;
132 s->io[i].InUse += num; 129 s->io[i].InUse += num;
133 break; 130 break;
134 } 131 }
@@ -143,12 +140,13 @@ static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
143 int i; 140 int i;
144 141
145 for (i = 0; i < MAX_IO_WIN; i++) { 142 for (i = 0; i < MAX_IO_WIN; i++) {
146 if ((s->io[i].BasePort <= base) && 143 if (!s->io[i].res)
147 (s->io[i].BasePort+s->io[i].NumPorts >= base+num)) { 144 continue;
145 if ((s->io[i].res->start <= base) &&
146 (s->io[i].res->end >= base+num-1)) {
148 s->io[i].InUse -= num; 147 s->io[i].InUse -= num;
149 /* Free the window if no one else is using it */ 148 /* Free the window if no one else is using it */
150 if (s->io[i].InUse == 0) { 149 if (s->io[i].InUse == 0) {
151 s->io[i].NumPorts = 0;
152 release_resource(s->io[i].res); 150 release_resource(s->io[i].res);
153 kfree(s->io[i].res); 151 kfree(s->io[i].res);
154 s->io[i].res = NULL; 152 s->io[i].res = NULL;
@@ -165,21 +163,19 @@ static void release_io_space(struct pcmcia_socket *s, ioaddr_t base,
165 * this and the tuple reading services. 163 * this and the tuple reading services.
166 */ 164 */
167 165
168int pccard_access_configuration_register(struct pcmcia_socket *s, 166int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
169 unsigned int function,
170 conf_reg_t *reg) 167 conf_reg_t *reg)
171{ 168{
169 struct pcmcia_socket *s;
172 config_t *c; 170 config_t *c;
173 int addr; 171 int addr;
174 u_char val; 172 u_char val;
175 173
176 if (!s || !s->config) 174 if (!p_dev || !p_dev->function_config)
177 return CS_NO_CARD; 175 return CS_NO_CARD;
178 176
179 c = &s->config[function]; 177 s = p_dev->socket;
180 178 c = p_dev->function_config;
181 if (c == NULL)
182 return CS_NO_CARD;
183 179
184 if (!(c->state & CONFIG_LOCKED)) 180 if (!(c->state & CONFIG_LOCKED))
185 return CS_CONFIGURATION_LOCKED; 181 return CS_CONFIGURATION_LOCKED;
@@ -200,20 +196,12 @@ int pccard_access_configuration_register(struct pcmcia_socket *s,
200 break; 196 break;
201 } 197 }
202 return CS_SUCCESS; 198 return CS_SUCCESS;
203} /* pccard_access_configuration_register */ 199} /* pcmcia_access_configuration_register */
204
205int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
206 conf_reg_t *reg)
207{
208 return pccard_access_configuration_register(p_dev->socket,
209 p_dev->func, reg);
210}
211EXPORT_SYMBOL(pcmcia_access_configuration_register); 200EXPORT_SYMBOL(pcmcia_access_configuration_register);
212 201
213 202
214
215int pccard_get_configuration_info(struct pcmcia_socket *s, 203int pccard_get_configuration_info(struct pcmcia_socket *s,
216 unsigned int function, 204 struct pcmcia_device *p_dev,
217 config_info_t *config) 205 config_info_t *config)
218{ 206{
219 config_t *c; 207 config_t *c;
@@ -221,7 +209,7 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
221 if (!(s->state & SOCKET_PRESENT)) 209 if (!(s->state & SOCKET_PRESENT))
222 return CS_NO_CARD; 210 return CS_NO_CARD;
223 211
224 config->Function = function; 212 config->Function = p_dev->func;
225 213
226#ifdef CONFIG_CARDBUS 214#ifdef CONFIG_CARDBUS
227 if (s->state & SOCKET_CARDBUS) { 215 if (s->state & SOCKET_CARDBUS) {
@@ -235,14 +223,14 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
235 config->AssignedIRQ = s->irq.AssignedIRQ; 223 config->AssignedIRQ = s->irq.AssignedIRQ;
236 if (config->AssignedIRQ) 224 if (config->AssignedIRQ)
237 config->Attributes |= CONF_ENABLE_IRQ; 225 config->Attributes |= CONF_ENABLE_IRQ;
238 config->BasePort1 = s->io[0].BasePort; 226 config->BasePort1 = s->io[0].res->start;
239 config->NumPorts1 = s->io[0].NumPorts; 227 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
240 } 228 }
241 return CS_SUCCESS; 229 return CS_SUCCESS;
242 } 230 }
243#endif 231#endif
244 232
245 c = (s->config != NULL) ? &s->config[function] : NULL; 233 c = (p_dev) ? p_dev->function_config : NULL;
246 234
247 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { 235 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
248 config->Attributes = 0; 236 config->Attributes = 0;
@@ -271,7 +259,7 @@ int pccard_get_configuration_info(struct pcmcia_socket *s,
271int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, 259int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
272 config_info_t *config) 260 config_info_t *config)
273{ 261{
274 return pccard_get_configuration_info(p_dev->socket, p_dev->func, 262 return pccard_get_configuration_info(p_dev->socket, p_dev,
275 config); 263 config);
276} 264}
277EXPORT_SYMBOL(pcmcia_get_configuration_info); 265EXPORT_SYMBOL(pcmcia_get_configuration_info);
@@ -317,7 +305,7 @@ EXPORT_SYMBOL(pcmcia_get_window);
317 * SocketState yet: I haven't seen any point for it. 305 * SocketState yet: I haven't seen any point for it.
318 */ 306 */
319 307
320int pccard_get_status(struct pcmcia_socket *s, unsigned int function, 308int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev,
321 cs_status_t *status) 309 cs_status_t *status)
322{ 310{
323 config_t *c; 311 config_t *c;
@@ -334,11 +322,12 @@ int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
334 if (!(s->state & SOCKET_PRESENT)) 322 if (!(s->state & SOCKET_PRESENT))
335 return CS_NO_CARD; 323 return CS_NO_CARD;
336 324
337 c = (s->config != NULL) ? &s->config[function] : NULL; 325 c = (p_dev) ? p_dev->function_config : NULL;
326
338 if ((c != NULL) && (c->state & CONFIG_LOCKED) && 327 if ((c != NULL) && (c->state & CONFIG_LOCKED) &&
339 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) { 328 (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
340 u_char reg; 329 u_char reg;
341 if (c->Present & PRESENT_PIN_REPLACE) { 330 if (c->CardValues & PRESENT_PIN_REPLACE) {
342 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg); 331 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
343 status->CardState |= 332 status->CardState |=
344 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0; 333 (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
@@ -352,7 +341,7 @@ int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
352 /* No PRR? Then assume we're always ready */ 341 /* No PRR? Then assume we're always ready */
353 status->CardState |= CS_EVENT_READY_CHANGE; 342 status->CardState |= CS_EVENT_READY_CHANGE;
354 } 343 }
355 if (c->Present & PRESENT_EXT_STATUS) { 344 if (c->CardValues & PRESENT_EXT_STATUS) {
356 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg); 345 pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
357 status->CardState |= 346 status->CardState |=
358 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; 347 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
@@ -370,11 +359,9 @@ int pccard_get_status(struct pcmcia_socket *s, unsigned int function,
370 return CS_SUCCESS; 359 return CS_SUCCESS;
371} /* pccard_get_status */ 360} /* pccard_get_status */
372 361
373int pcmcia_get_status(client_handle_t handle, cs_status_t *status) 362int pcmcia_get_status(struct pcmcia_device *p_dev, cs_status_t *status)
374{ 363{
375 struct pcmcia_socket *s; 364 return pccard_get_status(p_dev->socket, p_dev, status);
376 s = SOCKET(handle);
377 return pccard_get_status(s, handle->func, status);
378} 365}
379EXPORT_SYMBOL(pcmcia_get_status); 366EXPORT_SYMBOL(pcmcia_get_status);
380 367
@@ -422,7 +409,8 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
422 config_t *c; 409 config_t *c;
423 410
424 s = p_dev->socket; 411 s = p_dev->socket;
425 c = CONFIG(p_dev); 412 c = p_dev->function_config;
413
426 if (!(s->state & SOCKET_PRESENT)) 414 if (!(s->state & SOCKET_PRESENT))
427 return CS_NO_CARD; 415 return CS_NO_CARD;
428 if (!(c->state & CONFIG_LOCKED)) 416 if (!(c->state & CONFIG_LOCKED))
@@ -454,6 +442,28 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
454 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) 442 (mod->Attributes & CONF_VPP2_CHANGE_VALID))
455 return CS_BAD_VPP; 443 return CS_BAD_VPP;
456 444
445 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
446 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
447 pccard_io_map io_on;
448 int i;
449
450 io_on.speed = io_speed;
451 for (i = 0; i < MAX_IO_WIN; i++) {
452 if (!s->io[i].res)
453 continue;
454 io_off.map = i;
455 io_on.map = i;
456
457 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
458 io_on.start = s->io[i].res->start;
459 io_on.stop = s->io[i].res->end;
460
461 s->ops->set_io_map(s, &io_off);
462 mdelay(40);
463 s->ops->set_io_map(s, &io_on);
464 }
465 }
466
457 return CS_SUCCESS; 467 return CS_SUCCESS;
458} /* modify_configuration */ 468} /* modify_configuration */
459EXPORT_SYMBOL(pcmcia_modify_configuration); 469EXPORT_SYMBOL(pcmcia_modify_configuration);
@@ -463,23 +473,23 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
463{ 473{
464 pccard_io_map io = { 0, 0, 0, 0, 1 }; 474 pccard_io_map io = { 0, 0, 0, 0, 1 };
465 struct pcmcia_socket *s = p_dev->socket; 475 struct pcmcia_socket *s = p_dev->socket;
476 config_t *c = p_dev->function_config;
466 int i; 477 int i;
467 478
468 if (!(p_dev->state & CLIENT_CONFIG_LOCKED)) 479 if (p_dev->_locked) {
469 return CS_BAD_HANDLE; 480 p_dev->_locked = 0;
470 p_dev->state &= ~CLIENT_CONFIG_LOCKED;
471
472 if (!(p_dev->state & CLIENT_STALE)) {
473 config_t *c = CONFIG(p_dev);
474 if (--(s->lock_count) == 0) { 481 if (--(s->lock_count) == 0) {
475 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ 482 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
476 s->socket.Vpp = 0; 483 s->socket.Vpp = 0;
477 s->socket.io_irq = 0; 484 s->socket.io_irq = 0;
478 s->ops->set_socket(s, &s->socket); 485 s->ops->set_socket(s, &s->socket);
479 } 486 }
487 }
488 if (c->state & CONFIG_LOCKED) {
489 c->state &= ~CONFIG_LOCKED;
480 if (c->state & CONFIG_IO_REQ) 490 if (c->state & CONFIG_IO_REQ)
481 for (i = 0; i < MAX_IO_WIN; i++) { 491 for (i = 0; i < MAX_IO_WIN; i++) {
482 if (s->io[i].NumPorts == 0) 492 if (!s->io[i].res)
483 continue; 493 continue;
484 s->io[i].Config--; 494 s->io[i].Config--;
485 if (s->io[i].Config != 0) 495 if (s->io[i].Config != 0)
@@ -487,12 +497,10 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
487 io.map = i; 497 io.map = i;
488 s->ops->set_io_map(s, &io); 498 s->ops->set_io_map(s, &io);
489 } 499 }
490 c->state &= ~CONFIG_LOCKED;
491 } 500 }
492 501
493 return CS_SUCCESS; 502 return CS_SUCCESS;
494} /* pcmcia_release_configuration */ 503} /* pcmcia_release_configuration */
495EXPORT_SYMBOL(pcmcia_release_configuration);
496 504
497 505
498/** pcmcia_release_io 506/** pcmcia_release_io
@@ -503,25 +511,23 @@ EXPORT_SYMBOL(pcmcia_release_configuration);
503 * don't bother checking the port ranges against the current socket 511 * don't bother checking the port ranges against the current socket
504 * values. 512 * values.
505 */ 513 */
506int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req) 514static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
507{ 515{
508 struct pcmcia_socket *s = p_dev->socket; 516 struct pcmcia_socket *s = p_dev->socket;
517 config_t *c = p_dev->function_config;
509 518
510 if (!(p_dev->state & CLIENT_IO_REQ)) 519 if (!p_dev->_io )
511 return CS_BAD_HANDLE; 520 return CS_BAD_HANDLE;
512 p_dev->state &= ~CLIENT_IO_REQ; 521
513 522 p_dev->_io = 0;
514 if (!(p_dev->state & CLIENT_STALE)) { 523
515 config_t *c = CONFIG(p_dev); 524 if ((c->io.BasePort1 != req->BasePort1) ||
516 if (c->state & CONFIG_LOCKED) 525 (c->io.NumPorts1 != req->NumPorts1) ||
517 return CS_CONFIGURATION_LOCKED; 526 (c->io.BasePort2 != req->BasePort2) ||
518 if ((c->io.BasePort1 != req->BasePort1) || 527 (c->io.NumPorts2 != req->NumPorts2))
519 (c->io.NumPorts1 != req->NumPorts1) || 528 return CS_BAD_ARGS;
520 (c->io.BasePort2 != req->BasePort2) || 529
521 (c->io.NumPorts2 != req->NumPorts2)) 530 c->state &= ~CONFIG_IO_REQ;
522 return CS_BAD_ARGS;
523 c->state &= ~CONFIG_IO_REQ;
524 }
525 531
526 release_io_space(s, req->BasePort1, req->NumPorts1); 532 release_io_space(s, req->BasePort1, req->NumPorts1);
527 if (req->NumPorts2) 533 if (req->NumPorts2)
@@ -529,28 +535,26 @@ int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
529 535
530 return CS_SUCCESS; 536 return CS_SUCCESS;
531} /* pcmcia_release_io */ 537} /* pcmcia_release_io */
532EXPORT_SYMBOL(pcmcia_release_io);
533 538
534 539
535int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req) 540static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
536{ 541{
537 struct pcmcia_socket *s = p_dev->socket; 542 struct pcmcia_socket *s = p_dev->socket;
538 if (!(p_dev->state & CLIENT_IRQ_REQ)) 543 config_t *c= p_dev->function_config;
544
545 if (!p_dev->_irq)
539 return CS_BAD_HANDLE; 546 return CS_BAD_HANDLE;
540 p_dev->state &= ~CLIENT_IRQ_REQ; 547 p_dev->_irq = 0;
541 548
542 if (!(p_dev->state & CLIENT_STALE)) { 549 if (c->state & CONFIG_LOCKED)
543 config_t *c = CONFIG(p_dev); 550 return CS_CONFIGURATION_LOCKED;
544 if (c->state & CONFIG_LOCKED) 551 if (c->irq.Attributes != req->Attributes)
545 return CS_CONFIGURATION_LOCKED; 552 return CS_BAD_ATTRIBUTE;
546 if (c->irq.Attributes != req->Attributes) 553 if (s->irq.AssignedIRQ != req->AssignedIRQ)
547 return CS_BAD_ATTRIBUTE; 554 return CS_BAD_IRQ;
548 if (s->irq.AssignedIRQ != req->AssignedIRQ) 555 if (--s->irq.Config == 0) {
549 return CS_BAD_IRQ; 556 c->state &= ~CONFIG_IRQ_REQ;
550 if (--s->irq.Config == 0) { 557 s->irq.AssignedIRQ = 0;
551 c->state &= ~CONFIG_IRQ_REQ;
552 s->irq.AssignedIRQ = 0;
553 }
554 } 558 }
555 559
556 if (req->Attributes & IRQ_HANDLE_PRESENT) { 560 if (req->Attributes & IRQ_HANDLE_PRESENT) {
@@ -563,7 +567,6 @@ int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
563 567
564 return CS_SUCCESS; 568 return CS_SUCCESS;
565} /* pcmcia_release_irq */ 569} /* pcmcia_release_irq */
566EXPORT_SYMBOL(pcmcia_release_irq);
567 570
568 571
569int pcmcia_release_window(window_handle_t win) 572int pcmcia_release_window(window_handle_t win)
@@ -573,7 +576,7 @@ int pcmcia_release_window(window_handle_t win)
573 if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 576 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
574 return CS_BAD_HANDLE; 577 return CS_BAD_HANDLE;
575 s = win->sock; 578 s = win->sock;
576 if (!(win->handle->state & CLIENT_WIN_REQ(win->index))) 579 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
577 return CS_BAD_HANDLE; 580 return CS_BAD_HANDLE;
578 581
579 /* Shut down memory window */ 582 /* Shut down memory window */
@@ -587,7 +590,7 @@ int pcmcia_release_window(window_handle_t win)
587 kfree(win->ctl.res); 590 kfree(win->ctl.res);
588 win->ctl.res = NULL; 591 win->ctl.res = NULL;
589 } 592 }
590 win->handle->state &= ~CLIENT_WIN_REQ(win->index); 593 win->handle->_win &= ~CLIENT_WIN_REQ(win->index);
591 594
592 win->magic = 0; 595 win->magic = 0;
593 596
@@ -610,16 +613,12 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
610 613
611 if (req->IntType & INT_CARDBUS) 614 if (req->IntType & INT_CARDBUS)
612 return CS_UNSUPPORTED_MODE; 615 return CS_UNSUPPORTED_MODE;
613 c = CONFIG(p_dev); 616 c = p_dev->function_config;
614 if (c->state & CONFIG_LOCKED) 617 if (c->state & CONFIG_LOCKED)
615 return CS_CONFIGURATION_LOCKED; 618 return CS_CONFIGURATION_LOCKED;
616 619
617 /* Do power control. We don't allow changes in Vcc. */ 620 /* Do power control. We don't allow changes in Vcc. */
618 if (s->socket.Vcc != req->Vcc) 621 s->socket.Vpp = req->Vpp;
619 return CS_BAD_VCC;
620 if (req->Vpp1 != req->Vpp2)
621 return CS_BAD_VPP;
622 s->socket.Vpp = req->Vpp1;
623 if (s->ops->set_socket(s, &s->socket)) 622 if (s->ops->set_socket(s, &s->socket))
624 return CS_BAD_VPP; 623 return CS_BAD_VPP;
625 624
@@ -643,7 +642,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
643 642
644 /* Set up CIS configuration registers */ 643 /* Set up CIS configuration registers */
645 base = c->ConfigBase = req->ConfigBase; 644 base = c->ConfigBase = req->ConfigBase;
646 c->Present = c->CardValues = req->Present; 645 c->CardValues = req->Present;
647 if (req->Present & PRESENT_COPY) { 646 if (req->Present & PRESENT_COPY) {
648 c->Copy = req->Copy; 647 c->Copy = req->Copy;
649 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); 648 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy);
@@ -690,10 +689,10 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
690 if (c->state & CONFIG_IO_REQ) { 689 if (c->state & CONFIG_IO_REQ) {
691 iomap.speed = io_speed; 690 iomap.speed = io_speed;
692 for (i = 0; i < MAX_IO_WIN; i++) 691 for (i = 0; i < MAX_IO_WIN; i++)
693 if (s->io[i].NumPorts != 0) { 692 if (s->io[i].res) {
694 iomap.map = i; 693 iomap.map = i;
695 iomap.flags = MAP_ACTIVE; 694 iomap.flags = MAP_ACTIVE;
696 switch (s->io[i].Attributes & IO_DATA_PATH_WIDTH) { 695 switch (s->io[i].res->flags & IO_DATA_PATH_WIDTH) {
697 case IO_DATA_PATH_WIDTH_16: 696 case IO_DATA_PATH_WIDTH_16:
698 iomap.flags |= MAP_16BIT; break; 697 iomap.flags |= MAP_16BIT; break;
699 case IO_DATA_PATH_WIDTH_AUTO: 698 case IO_DATA_PATH_WIDTH_AUTO:
@@ -701,15 +700,15 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
701 default: 700 default:
702 break; 701 break;
703 } 702 }
704 iomap.start = s->io[i].BasePort; 703 iomap.start = s->io[i].res->start;
705 iomap.stop = iomap.start + s->io[i].NumPorts - 1; 704 iomap.stop = s->io[i].res->end;
706 s->ops->set_io_map(s, &iomap); 705 s->ops->set_io_map(s, &iomap);
707 s->io[i].Config++; 706 s->io[i].Config++;
708 } 707 }
709 } 708 }
710 709
711 c->state |= CONFIG_LOCKED; 710 c->state |= CONFIG_LOCKED;
712 p_dev->state |= CLIENT_CONFIG_LOCKED; 711 p_dev->_locked = 1;
713 return CS_SUCCESS; 712 return CS_SUCCESS;
714} /* pcmcia_request_configuration */ 713} /* pcmcia_request_configuration */
715EXPORT_SYMBOL(pcmcia_request_configuration); 714EXPORT_SYMBOL(pcmcia_request_configuration);
@@ -730,7 +729,7 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
730 729
731 if (!req) 730 if (!req)
732 return CS_UNSUPPORTED_MODE; 731 return CS_UNSUPPORTED_MODE;
733 c = CONFIG(p_dev); 732 c = p_dev->function_config;
734 if (c->state & CONFIG_LOCKED) 733 if (c->state & CONFIG_LOCKED)
735 return CS_CONFIGURATION_LOCKED; 734 return CS_CONFIGURATION_LOCKED;
736 if (c->state & CONFIG_IO_REQ) 735 if (c->state & CONFIG_IO_REQ)
@@ -755,7 +754,7 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
755 754
756 c->io = *req; 755 c->io = *req;
757 c->state |= CONFIG_IO_REQ; 756 c->state |= CONFIG_IO_REQ;
758 p_dev->state |= CLIENT_IO_REQ; 757 p_dev->_io = 1;
759 return CS_SUCCESS; 758 return CS_SUCCESS;
760} /* pcmcia_request_io */ 759} /* pcmcia_request_io */
761EXPORT_SYMBOL(pcmcia_request_io); 760EXPORT_SYMBOL(pcmcia_request_io);
@@ -786,7 +785,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
786 785
787 if (!(s->state & SOCKET_PRESENT)) 786 if (!(s->state & SOCKET_PRESENT))
788 return CS_NO_CARD; 787 return CS_NO_CARD;
789 c = CONFIG(p_dev); 788 c = p_dev->function_config;
790 if (c->state & CONFIG_LOCKED) 789 if (c->state & CONFIG_LOCKED)
791 return CS_CONFIGURATION_LOCKED; 790 return CS_CONFIGURATION_LOCKED;
792 if (c->state & CONFIG_IRQ_REQ) 791 if (c->state & CONFIG_IRQ_REQ)
@@ -851,7 +850,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
851 s->irq.Config++; 850 s->irq.Config++;
852 851
853 c->state |= CONFIG_IRQ_REQ; 852 c->state |= CONFIG_IRQ_REQ;
854 p_dev->state |= CLIENT_IRQ_REQ; 853 p_dev->_irq = 1;
855 854
856#ifdef CONFIG_PCMCIA_PROBE 855#ifdef CONFIG_PCMCIA_PROBE
857 pcmcia_used_irq[irq]++; 856 pcmcia_used_irq[irq]++;
@@ -911,7 +910,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
911 if (!win->ctl.res) 910 if (!win->ctl.res)
912 return CS_IN_USE; 911 return CS_IN_USE;
913 } 912 }
914 (*p_dev)->state |= CLIENT_WIN_REQ(w); 913 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
915 914
916 /* Configure the socket controller */ 915 /* Configure the socket controller */
917 win->ctl.map = w+1; 916 win->ctl.map = w+1;
@@ -941,3 +940,14 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
941 return CS_SUCCESS; 940 return CS_SUCCESS;
942} /* pcmcia_request_window */ 941} /* pcmcia_request_window */
943EXPORT_SYMBOL(pcmcia_request_window); 942EXPORT_SYMBOL(pcmcia_request_window);
943
944void pcmcia_disable_device(struct pcmcia_device *p_dev) {
945 pcmcia_release_configuration(p_dev);
946 pcmcia_release_io(p_dev, &p_dev->io);
947 pcmcia_release_irq(p_dev, &p_dev->irq);
948 if (&p_dev->win)
949 pcmcia_release_window(p_dev->win);
950
951 p_dev->dev_node = NULL;
952}
953EXPORT_SYMBOL(pcmcia_disable_device);
diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c
index f2789afb22b2..16d1ea7b0a18 100644
--- a/drivers/pcmcia/pd6729.c
+++ b/drivers/pcmcia/pd6729.c
@@ -8,7 +8,6 @@
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/config.h>
12#include <linux/module.h> 11#include <linux/module.h>
13#include <linux/pci.h> 12#include <linux/pci.h>
14#include <linux/init.h> 13#include <linux/init.h>
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index 514609369836..81dfc2cac2b4 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -12,7 +12,6 @@
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18 17
@@ -22,6 +21,8 @@
22#include "cs_internal.h" 21#include "cs_internal.h"
23 22
24 23
24#ifdef CONFIG_PCMCIA_IOCTL
25
25#ifdef CONFIG_PCMCIA_PROBE 26#ifdef CONFIG_PCMCIA_PROBE
26 27
27static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) 28static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
@@ -98,6 +99,8 @@ int pcmcia_adjust_resource_info(adjust_t *adj)
98} 99}
99EXPORT_SYMBOL(pcmcia_adjust_resource_info); 100EXPORT_SYMBOL(pcmcia_adjust_resource_info);
100 101
102#endif
103
101int pcmcia_validate_mem(struct pcmcia_socket *s) 104int pcmcia_validate_mem(struct pcmcia_socket *s)
102{ 105{
103 if (s->resource_ops->validate_mem) 106 if (s->resource_ops->validate_mem)
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 5301ac60358f..0f8b157c9717 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -12,7 +12,6 @@
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/moduleparam.h> 16#include <linux/moduleparam.h>
18#include <linux/init.h> 17#include <linux/init.h>
@@ -61,7 +60,7 @@ struct socket_data {
61 unsigned int rsrc_mem_probe; 60 unsigned int rsrc_mem_probe;
62}; 61};
63 62
64static DECLARE_MUTEX(rsrc_sem); 63static DEFINE_MUTEX(rsrc_mutex);
65#define MEM_PROBE_LOW (1 << 0) 64#define MEM_PROBE_LOW (1 << 0)
66#define MEM_PROBE_HIGH (1 << 1) 65#define MEM_PROBE_HIGH (1 << 1)
67 66
@@ -484,7 +483,7 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
484 483
485 484
486/* 485/*
487 * Locking note: Must be called with skt_sem held! 486 * Locking note: Must be called with skt_mutex held!
488 */ 487 */
489static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s) 488static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
490{ 489{
@@ -495,7 +494,7 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
495 if (!probe_mem) 494 if (!probe_mem)
496 return 0; 495 return 0;
497 496
498 down(&rsrc_sem); 497 mutex_lock(&rsrc_mutex);
499 498
500 if (s->features & SS_CAP_PAGE_REGS) 499 if (s->features & SS_CAP_PAGE_REGS)
501 probe_mask = MEM_PROBE_HIGH; 500 probe_mask = MEM_PROBE_HIGH;
@@ -507,7 +506,7 @@ static int pcmcia_nonstatic_validate_mem(struct pcmcia_socket *s)
507 s_data->rsrc_mem_probe |= probe_mask; 506 s_data->rsrc_mem_probe |= probe_mask;
508 } 507 }
509 508
510 up(&rsrc_sem); 509 mutex_unlock(&rsrc_mutex);
511 510
512 return ret; 511 return ret;
513} 512}
@@ -585,7 +584,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
585 struct socket_data *s_data = s->resource_data; 584 struct socket_data *s_data = s->resource_data;
586 int ret = -ENOMEM; 585 int ret = -ENOMEM;
587 586
588 down(&rsrc_sem); 587 mutex_lock(&rsrc_mutex);
589 for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) { 588 for (m = s_data->io_db.next; m != &s_data->io_db; m = m->next) {
590 unsigned long start = m->base; 589 unsigned long start = m->base;
591 unsigned long end = m->base + m->num - 1; 590 unsigned long end = m->base + m->num - 1;
@@ -596,7 +595,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
596 ret = adjust_resource(res, r_start, r_end - r_start + 1); 595 ret = adjust_resource(res, r_start, r_end - r_start + 1);
597 break; 596 break;
598 } 597 }
599 up(&rsrc_sem); 598 mutex_unlock(&rsrc_mutex);
600 599
601 return ret; 600 return ret;
602} 601}
@@ -630,7 +629,7 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
630 data.offset = base & data.mask; 629 data.offset = base & data.mask;
631 data.map = &s_data->io_db; 630 data.map = &s_data->io_db;
632 631
633 down(&rsrc_sem); 632 mutex_lock(&rsrc_mutex);
634#ifdef CONFIG_PCI 633#ifdef CONFIG_PCI
635 if (s->cb_dev) { 634 if (s->cb_dev) {
636 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1, 635 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
@@ -639,7 +638,7 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
639#endif 638#endif
640 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL, 639 ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
641 1, pcmcia_align, &data); 640 1, pcmcia_align, &data);
642 up(&rsrc_sem); 641 mutex_unlock(&rsrc_mutex);
643 642
644 if (ret != 0) { 643 if (ret != 0) {
645 kfree(res); 644 kfree(res);
@@ -672,7 +671,7 @@ static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
672 min = 0x100000UL + base; 671 min = 0x100000UL + base;
673 } 672 }
674 673
675 down(&rsrc_sem); 674 mutex_lock(&rsrc_mutex);
676#ifdef CONFIG_PCI 675#ifdef CONFIG_PCI
677 if (s->cb_dev) { 676 if (s->cb_dev) {
678 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 677 ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num,
@@ -682,7 +681,7 @@ static struct resource * nonstatic_find_mem_region(u_long base, u_long num,
682#endif 681#endif
683 ret = allocate_resource(&iomem_resource, res, num, min, 682 ret = allocate_resource(&iomem_resource, res, num, min,
684 max, 1, pcmcia_align, &data); 683 max, 1, pcmcia_align, &data);
685 up(&rsrc_sem); 684 mutex_unlock(&rsrc_mutex);
686 if (ret == 0 || low) 685 if (ret == 0 || low)
687 break; 686 break;
688 low = 1; 687 low = 1;
@@ -705,7 +704,7 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned
705 if (end < start) 704 if (end < start)
706 return -EINVAL; 705 return -EINVAL;
707 706
708 down(&rsrc_sem); 707 mutex_lock(&rsrc_mutex);
709 switch (action) { 708 switch (action) {
710 case ADD_MANAGED_RESOURCE: 709 case ADD_MANAGED_RESOURCE:
711 ret = add_interval(&data->mem_db, start, size); 710 ret = add_interval(&data->mem_db, start, size);
@@ -723,7 +722,7 @@ static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned
723 default: 722 default:
724 ret = -EINVAL; 723 ret = -EINVAL;
725 } 724 }
726 up(&rsrc_sem); 725 mutex_unlock(&rsrc_mutex);
727 726
728 return ret; 727 return ret;
729} 728}
@@ -741,7 +740,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
741 if (end > IO_SPACE_LIMIT) 740 if (end > IO_SPACE_LIMIT)
742 return -EINVAL; 741 return -EINVAL;
743 742
744 down(&rsrc_sem); 743 mutex_lock(&rsrc_mutex);
745 switch (action) { 744 switch (action) {
746 case ADD_MANAGED_RESOURCE: 745 case ADD_MANAGED_RESOURCE:
747 if (add_interval(&data->io_db, start, size) != 0) { 746 if (add_interval(&data->io_db, start, size) != 0) {
@@ -760,7 +759,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long
760 ret = -EINVAL; 759 ret = -EINVAL;
761 break; 760 break;
762 } 761 }
763 up(&rsrc_sem); 762 mutex_unlock(&rsrc_mutex);
764 763
765 return ret; 764 return ret;
766} 765}
@@ -867,7 +866,7 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
867 struct socket_data *data = s->resource_data; 866 struct socket_data *data = s->resource_data;
868 struct resource_map *p, *q; 867 struct resource_map *p, *q;
869 868
870 down(&rsrc_sem); 869 mutex_lock(&rsrc_mutex);
871 for (p = data->mem_db.next; p != &data->mem_db; p = q) { 870 for (p = data->mem_db.next; p != &data->mem_db; p = q) {
872 q = p->next; 871 q = p->next;
873 kfree(p); 872 kfree(p);
@@ -876,7 +875,7 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
876 q = p->next; 875 q = p->next;
877 kfree(p); 876 kfree(p);
878 } 877 }
879 up(&rsrc_sem); 878 mutex_unlock(&rsrc_mutex);
880} 879}
881 880
882 881
@@ -901,7 +900,7 @@ static ssize_t show_io_db(struct class_device *class_dev, char *buf)
901 struct resource_map *p; 900 struct resource_map *p;
902 ssize_t ret = 0; 901 ssize_t ret = 0;
903 902
904 down(&rsrc_sem); 903 mutex_lock(&rsrc_mutex);
905 data = s->resource_data; 904 data = s->resource_data;
906 905
907 for (p = data->io_db.next; p != &data->io_db; p = p->next) { 906 for (p = data->io_db.next; p != &data->io_db; p = p->next) {
@@ -913,7 +912,7 @@ static ssize_t show_io_db(struct class_device *class_dev, char *buf)
913 ((unsigned long) p->base + p->num - 1)); 912 ((unsigned long) p->base + p->num - 1));
914 } 913 }
915 914
916 up(&rsrc_sem); 915 mutex_unlock(&rsrc_mutex);
917 return (ret); 916 return (ret);
918} 917}
919 918
@@ -953,7 +952,7 @@ static ssize_t show_mem_db(struct class_device *class_dev, char *buf)
953 struct resource_map *p; 952 struct resource_map *p;
954 ssize_t ret = 0; 953 ssize_t ret = 0;
955 954
956 down(&rsrc_sem); 955 mutex_lock(&rsrc_mutex);
957 data = s->resource_data; 956 data = s->resource_data;
958 957
959 for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { 958 for (p = data->mem_db.next; p != &data->mem_db; p = p->next) {
@@ -965,7 +964,7 @@ static ssize_t show_mem_db(struct class_device *class_dev, char *buf)
965 ((unsigned long) p->base + p->num - 1)); 964 ((unsigned long) p->base + p->num - 1));
966 } 965 }
967 966
968 up(&rsrc_sem); 967 mutex_unlock(&rsrc_mutex);
969 return (ret); 968 return (ret);
970} 969}
971 970
diff --git a/drivers/pcmcia/sa1100_cerf.c b/drivers/pcmcia/sa1100_cerf.c
index 2b3c2895b43d..eb89928f2338 100644
--- a/drivers/pcmcia/sa1100_cerf.c
+++ b/drivers/pcmcia/sa1100_cerf.c
@@ -5,7 +5,6 @@
5 * Based off the Assabet. 5 * Based off the Assabet.
6 * 6 *
7 */ 7 */
8#include <linux/config.h>
9#include <linux/module.h> 8#include <linux/module.h>
10#include <linux/kernel.h> 9#include <linux/kernel.h>
11#include <linux/sched.h> 10#include <linux/sched.h>
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 5ab1cdef7c48..c5d7476da471 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -12,7 +12,6 @@
12#include <linux/moduleparam.h> 12#include <linux/moduleparam.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/config.h>
16#include <linux/string.h> 15#include <linux/string.h>
17#include <linux/major.h> 16#include <linux/major.h>
18#include <linux/errno.h> 17#include <linux/errno.h>
@@ -25,6 +24,7 @@
25#include <linux/pm.h> 24#include <linux/pm.h>
26#include <linux/pci.h> 25#include <linux/pci.h>
27#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/mutex.h>
28#include <asm/system.h> 28#include <asm/system.h>
29#include <asm/irq.h> 29#include <asm/irq.h>
30 30
@@ -183,7 +183,7 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf,
183 s->resource_setup_done = 1; 183 s->resource_setup_done = 1;
184 spin_unlock_irqrestore(&s->lock, flags); 184 spin_unlock_irqrestore(&s->lock, flags);
185 185
186 down(&s->skt_sem); 186 mutex_lock(&s->skt_mutex);
187 if ((s->callback) && 187 if ((s->callback) &&
188 (s->state & SOCKET_PRESENT) && 188 (s->state & SOCKET_PRESENT) &&
189 !(s->state & SOCKET_CARDBUS)) { 189 !(s->state & SOCKET_CARDBUS)) {
@@ -192,7 +192,7 @@ static ssize_t pccard_store_resource(struct class_device *dev, const char *buf,
192 module_put(s->callback->owner); 192 module_put(s->callback->owner);
193 } 193 }
194 } 194 }
195 up(&s->skt_sem); 195 mutex_unlock(&s->skt_mutex);
196 196
197 return count; 197 return count;
198} 198}
@@ -322,7 +322,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
322 kfree(cis); 322 kfree(cis);
323 323
324 if (!ret) { 324 if (!ret) {
325 down(&s->skt_sem); 325 mutex_lock(&s->skt_mutex);
326 if ((s->callback) && (s->state & SOCKET_PRESENT) && 326 if ((s->callback) && (s->state & SOCKET_PRESENT) &&
327 !(s->state & SOCKET_CARDBUS)) { 327 !(s->state & SOCKET_CARDBUS)) {
328 if (try_module_get(s->callback->owner)) { 328 if (try_module_get(s->callback->owner)) {
@@ -330,7 +330,7 @@ static ssize_t pccard_store_cis(struct kobject *kobj, char *buf, loff_t off, siz
330 module_put(s->callback->owner); 330 module_put(s->callback->owner);
331 } 331 }
332 } 332 }
333 up(&s->skt_sem); 333 mutex_unlock(&s->skt_mutex);
334 } 334 }
335 335
336 336
diff --git a/drivers/pcmcia/ti113x.h b/drivers/pcmcia/ti113x.h
index d5b4ff74462e..7a3d1b8e16b9 100644
--- a/drivers/pcmcia/ti113x.h
+++ b/drivers/pcmcia/ti113x.h
@@ -30,7 +30,6 @@
30#ifndef _LINUX_TI113X_H 30#ifndef _LINUX_TI113X_H
31#define _LINUX_TI113X_H 31#define _LINUX_TI113X_H
32 32
33#include <linux/config.h>
34 33
35/* Register definitions for TI 113X PCI-to-CardBus bridges */ 34/* Register definitions for TI 113X PCI-to-CardBus bridges */
36 35
diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
index 0574efd7828a..459e6e1946fd 100644
--- a/drivers/pcmcia/vrc4171_card.c
+++ b/drivers/pcmcia/vrc4171_card.c
@@ -634,7 +634,7 @@ static void vrc4171_remove_sockets(void)
634static int __devinit vrc4171_card_setup(char *options) 634static int __devinit vrc4171_card_setup(char *options)
635{ 635{
636 if (options == NULL || *options == '\0') 636 if (options == NULL || *options == '\0')
637 return 0; 637 return 1;
638 638
639 if (strncmp(options, "irq:", 4) == 0) { 639 if (strncmp(options, "irq:", 4) == 0) {
640 int irq; 640 int irq;
@@ -644,7 +644,7 @@ static int __devinit vrc4171_card_setup(char *options)
644 vrc4171_irq = irq; 644 vrc4171_irq = irq;
645 645
646 if (*options != ',') 646 if (*options != ',')
647 return 0; 647 return 1;
648 options++; 648 options++;
649 } 649 }
650 650
@@ -663,10 +663,10 @@ static int __devinit vrc4171_card_setup(char *options)
663 } 663 }
664 664
665 if (*options != ',') 665 if (*options != ',')
666 return 0; 666 return 1;
667 options++; 667 options++;
668 } else 668 } else
669 return 0; 669 return 1;
670 670
671 } 671 }
672 672
@@ -688,7 +688,7 @@ static int __devinit vrc4171_card_setup(char *options)
688 } 688 }
689 689
690 if (*options != ',') 690 if (*options != ',')
691 return 0; 691 return 1;
692 options++; 692 options++;
693 693
694 if (strncmp(options, "memnoprobe", 10) == 0) 694 if (strncmp(options, "memnoprobe", 10) == 0)
@@ -700,7 +700,7 @@ static int __devinit vrc4171_card_setup(char *options)
700 } 700 }
701 } 701 }
702 702
703 return 0; 703 return 1;
704} 704}
705 705
706__setup("vrc4171_card=", vrc4171_card_setup); 706__setup("vrc4171_card=", vrc4171_card_setup);
diff --git a/drivers/pcmcia/vrc4173_cardu.c b/drivers/pcmcia/vrc4173_cardu.c
index 57f38dba0a48..6004196f7cc1 100644
--- a/drivers/pcmcia/vrc4173_cardu.c
+++ b/drivers/pcmcia/vrc4173_cardu.c
@@ -516,7 +516,7 @@ static int __devinit vrc4173_cardu_probe(struct pci_dev *dev,
516static int __devinit vrc4173_cardu_setup(char *options) 516static int __devinit vrc4173_cardu_setup(char *options)
517{ 517{
518 if (options == NULL || *options == '\0') 518 if (options == NULL || *options == '\0')
519 return 0; 519 return 1;
520 520
521 if (strncmp(options, "cardu1:", 7) == 0) { 521 if (strncmp(options, "cardu1:", 7) == 0) {
522 options += 7; 522 options += 7;
@@ -527,9 +527,9 @@ static int __devinit vrc4173_cardu_setup(char *options)
527 } 527 }
528 528
529 if (*options != ',') 529 if (*options != ',')
530 return 0; 530 return 1;
531 } else 531 } else
532 return 0; 532 return 1;
533 } 533 }
534 534
535 if (strncmp(options, "cardu2:", 7) == 0) { 535 if (strncmp(options, "cardu2:", 7) == 0) {
@@ -538,7 +538,7 @@ static int __devinit vrc4173_cardu_setup(char *options)
538 cardu_sockets[CARDU2].noprobe = 1; 538 cardu_sockets[CARDU2].noprobe = 1;
539 } 539 }
540 540
541 return 0; 541 return 1;
542} 542}
543 543
544__setup("vrc4173_cardu=", vrc4173_cardu_setup); 544__setup("vrc4173_cardu=", vrc4173_cardu_setup);
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 929dd8090578..65d090dbef46 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -147,6 +147,16 @@ config RTC_DRV_SA1100
147 To compile this driver as a module, choose M here: the 147 To compile this driver as a module, choose M here: the
148 module will be called rtc-sa1100. 148 module will be called rtc-sa1100.
149 149
150config RTC_DRV_VR41XX
151 tristate "NEC VR41XX"
152 depends on RTC_CLASS && CPU_VR41XX
153 help
154 If you say Y here you will get access to the real time clock
155 built into your NEC VR41XX CPU.
156
157 To compile this driver as a module, choose M here: the
158 module will be called rtc-vr41xx.
159
150config RTC_DRV_TEST 160config RTC_DRV_TEST
151 tristate "Test driver/device" 161 tristate "Test driver/device"
152 depends on RTC_CLASS 162 depends on RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 8d4c7fe88d58..a9ca0f171686 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_RTC_DRV_RS5C372) += rtc-rs5c372.o
19obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 19obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
20obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 20obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
21obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 21obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
22obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 8533936d50d8..413c7d54ea10 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -96,6 +96,8 @@ exit_idr:
96 idr_remove(&rtc_idr, id); 96 idr_remove(&rtc_idr, id);
97 97
98exit: 98exit:
99 dev_err(dev, "rtc core: unable to register %s, err = %d\n",
100 name, err);
99 return ERR_PTR(err); 101 return ERR_PTR(err);
100} 102}
101EXPORT_SYMBOL_GPL(rtc_device_register); 103EXPORT_SYMBOL_GPL(rtc_device_register);
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 358695a416f3..9be81fd4737c 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * An rtc/i2c driver for the Dallas DS1672 2 * An rtc/i2c driver for the Dallas DS1672
3 * Copyright 2005 Alessandro Zummo 3 * Copyright 2005-06 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
4 * 6 *
5 * 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
6 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -11,7 +13,7 @@
11#include <linux/i2c.h> 13#include <linux/i2c.h>
12#include <linux/rtc.h> 14#include <linux/rtc.h>
13 15
14#define DRV_VERSION "0.2" 16#define DRV_VERSION "0.3"
15 17
16/* Addresses to scan: none. This chip cannot be detected. */ 18/* Addresses to scan: none. This chip cannot be detected. */
17static unsigned short normal_i2c[] = { I2C_CLIENT_END }; 19static unsigned short normal_i2c[] = { I2C_CLIENT_END };
@@ -25,6 +27,7 @@ I2C_CLIENT_INSMOD;
25#define DS1672_REG_CONTROL 4 27#define DS1672_REG_CONTROL 4
26#define DS1672_REG_TRICKLE 5 28#define DS1672_REG_TRICKLE 5
27 29
30#define DS1672_REG_CONTROL_EOSC 0x80
28 31
29/* Prototypes */ 32/* Prototypes */
30static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind); 33static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind);
@@ -53,8 +56,7 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
53 56
54 dev_dbg(&client->dev, 57 dev_dbg(&client->dev,
55 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n" 58 "%s: raw read data - counters=%02x,%02x,%02x,%02x\n"
56 __FUNCTION__, 59 __FUNCTION__, buf[0], buf[1], buf[2], buf[3]);
57 buf[0], buf[1], buf[2], buf[3]);
58 60
59 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; 61 time = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
60 62
@@ -62,8 +64,7 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
62 64
63 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 65 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
64 "mday=%d, mon=%d, year=%d, wday=%d\n", 66 "mday=%d, mon=%d, year=%d, wday=%d\n",
65 __FUNCTION__, 67 __FUNCTION__, tm->tm_sec, tm->tm_min, tm->tm_hour,
66 tm->tm_sec, tm->tm_min, tm->tm_hour,
67 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 68 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
68 69
69 return 0; 70 return 0;
@@ -72,16 +73,17 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
72static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs) 73static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
73{ 74{
74 int xfer; 75 int xfer;
75 unsigned char buf[5]; 76 unsigned char buf[6];
76 77
77 buf[0] = DS1672_REG_CNT_BASE; 78 buf[0] = DS1672_REG_CNT_BASE;
78 buf[1] = secs & 0x000000FF; 79 buf[1] = secs & 0x000000FF;
79 buf[2] = (secs & 0x0000FF00) >> 8; 80 buf[2] = (secs & 0x0000FF00) >> 8;
80 buf[3] = (secs & 0x00FF0000) >> 16; 81 buf[3] = (secs & 0x00FF0000) >> 16;
81 buf[4] = (secs & 0xFF000000) >> 24; 82 buf[4] = (secs & 0xFF000000) >> 24;
83 buf[5] = 0; /* set control reg to enable counting */
82 84
83 xfer = i2c_master_send(client, buf, 5); 85 xfer = i2c_master_send(client, buf, 6);
84 if (xfer != 5) { 86 if (xfer != 6) {
85 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer); 87 dev_err(&client->dev, "%s: send: %d\n", __FUNCTION__, xfer);
86 return -EIO; 88 return -EIO;
87 } 89 }
@@ -120,6 +122,40 @@ static int ds1672_rtc_set_mmss(struct device *dev, unsigned long secs)
120 return ds1672_set_mmss(to_i2c_client(dev), secs); 122 return ds1672_set_mmss(to_i2c_client(dev), secs);
121} 123}
122 124
125static int ds1672_get_control(struct i2c_client *client, u8 *status)
126{
127 unsigned char addr = DS1672_REG_CONTROL;
128
129 struct i2c_msg msgs[] = {
130 { client->addr, 0, 1, &addr }, /* setup read ptr */
131 { client->addr, I2C_M_RD, 1, status }, /* read control */
132 };
133
134 /* read control register */
135 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
136 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
137 return -EIO;
138 }
139
140 return 0;
141}
142
143/* following are the sysfs callback functions */
144static ssize_t show_control(struct device *dev, struct device_attribute *attr, char *buf)
145{
146 struct i2c_client *client = to_i2c_client(dev);
147 u8 control;
148 int err;
149
150 err = ds1672_get_control(client, &control);
151 if (err)
152 return err;
153
154 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
155 ? "disabled" : "enabled");
156}
157static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
158
123static struct rtc_class_ops ds1672_rtc_ops = { 159static struct rtc_class_ops ds1672_rtc_ops = {
124 .read_time = ds1672_rtc_read_time, 160 .read_time = ds1672_rtc_read_time,
125 .set_time = ds1672_rtc_set_time, 161 .set_time = ds1672_rtc_set_time,
@@ -128,7 +164,6 @@ static struct rtc_class_ops ds1672_rtc_ops = {
128 164
129static int ds1672_attach(struct i2c_adapter *adapter) 165static int ds1672_attach(struct i2c_adapter *adapter)
130{ 166{
131 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
132 return i2c_probe(adapter, &addr_data, ds1672_probe); 167 return i2c_probe(adapter, &addr_data, ds1672_probe);
133} 168}
134 169
@@ -137,8 +172,6 @@ static int ds1672_detach(struct i2c_client *client)
137 int err; 172 int err;
138 struct rtc_device *rtc = i2c_get_clientdata(client); 173 struct rtc_device *rtc = i2c_get_clientdata(client);
139 174
140 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
141
142 if (rtc) 175 if (rtc)
143 rtc_device_unregister(rtc); 176 rtc_device_unregister(rtc);
144 177
@@ -162,6 +195,7 @@ static struct i2c_driver ds1672_driver = {
162static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind) 195static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
163{ 196{
164 int err = 0; 197 int err = 0;
198 u8 control;
165 struct i2c_client *client; 199 struct i2c_client *client;
166 struct rtc_device *rtc; 200 struct rtc_device *rtc;
167 201
@@ -195,13 +229,23 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
195 229
196 if (IS_ERR(rtc)) { 230 if (IS_ERR(rtc)) {
197 err = PTR_ERR(rtc); 231 err = PTR_ERR(rtc);
198 dev_err(&client->dev,
199 "unable to register the class device\n");
200 goto exit_detach; 232 goto exit_detach;
201 } 233 }
202 234
203 i2c_set_clientdata(client, rtc); 235 i2c_set_clientdata(client, rtc);
204 236
237 /* read control register */
238 err = ds1672_get_control(client, &control);
239 if (err)
240 goto exit_detach;
241
242 if (control & DS1672_REG_CONTROL_EOSC)
243 dev_warn(&client->dev, "Oscillator not enabled. "
244 "Set time to enable.\n");
245
246 /* Register sysfs hooks */
247 device_create_file(&client->dev, &dev_attr_control);
248
205 return 0; 249 return 0;
206 250
207exit_detach: 251exit_detach:
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 0dd80ea686a9..e1a1169e4664 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -67,7 +67,6 @@ static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
67 67
68 ep93xx_get_swcomp(dev, &preload, &delete); 68 ep93xx_get_swcomp(dev, &preload, &delete);
69 69
70 seq_printf(seq, "24hr\t\t: yes\n");
71 seq_printf(seq, "preload\t\t: %d\n", preload); 70 seq_printf(seq, "preload\t\t: %d\n", preload);
72 seq_printf(seq, "delete\t\t: %d\n", delete); 71 seq_printf(seq, "delete\t\t: %d\n", delete);
73 72
@@ -110,7 +109,6 @@ static int __devinit ep93xx_rtc_probe(struct platform_device *dev)
110 &dev->dev, &ep93xx_rtc_ops, THIS_MODULE); 109 &dev->dev, &ep93xx_rtc_ops, THIS_MODULE);
111 110
112 if (IS_ERR(rtc)) { 111 if (IS_ERR(rtc)) {
113 dev_err(&dev->dev, "unable to register\n");
114 return PTR_ERR(rtc); 112 return PTR_ERR(rtc);
115 } 113 }
116 114
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index db445c872b1b..f6e7ee04f3dc 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -23,7 +23,7 @@
23#define M48T86_REG_SECALRM 0x01 23#define M48T86_REG_SECALRM 0x01
24#define M48T86_REG_MIN 0x02 24#define M48T86_REG_MIN 0x02
25#define M48T86_REG_MINALRM 0x03 25#define M48T86_REG_MINALRM 0x03
26#define M48T86_REG_HOUR 0x04 26#define M48T86_REG_HOUR 0x04
27#define M48T86_REG_HOURALRM 0x05 27#define M48T86_REG_HOURALRM 0x05
28#define M48T86_REG_DOW 0x06 /* 1 = sunday */ 28#define M48T86_REG_DOW 0x06 /* 1 = sunday */
29#define M48T86_REG_DOM 0x07 29#define M48T86_REG_DOM 0x07
@@ -127,9 +127,6 @@ static int m48t86_rtc_proc(struct device *dev, struct seq_file *seq)
127 127
128 reg = ops->readb(M48T86_REG_B); 128 reg = ops->readb(M48T86_REG_B);
129 129
130 seq_printf(seq, "24hr\t\t: %s\n",
131 (reg & M48T86_REG_B_H24) ? "yes" : "no");
132
133 seq_printf(seq, "mode\t\t: %s\n", 130 seq_printf(seq, "mode\t\t: %s\n",
134 (reg & M48T86_REG_B_DM) ? "binary" : "bcd"); 131 (reg & M48T86_REG_B_DM) ? "binary" : "bcd");
135 132
@@ -154,10 +151,8 @@ static int __devinit m48t86_rtc_probe(struct platform_device *dev)
154 struct rtc_device *rtc = rtc_device_register("m48t86", 151 struct rtc_device *rtc = rtc_device_register("m48t86",
155 &dev->dev, &m48t86_rtc_ops, THIS_MODULE); 152 &dev->dev, &m48t86_rtc_ops, THIS_MODULE);
156 153
157 if (IS_ERR(rtc)) { 154 if (IS_ERR(rtc))
158 dev_err(&dev->dev, "unable to register\n");
159 return PTR_ERR(rtc); 155 return PTR_ERR(rtc);
160 }
161 156
162 platform_set_drvdata(dev, rtc); 157 platform_set_drvdata(dev, rtc);
163 158
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index d857d45bdbe8..ba9a583b7b68 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -227,14 +227,7 @@ static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
227 return pcf8563_set_datetime(to_i2c_client(dev), tm); 227 return pcf8563_set_datetime(to_i2c_client(dev), tm);
228} 228}
229 229
230static int pcf8563_rtc_proc(struct device *dev, struct seq_file *seq)
231{
232 seq_printf(seq, "24hr\t\t: yes\n");
233 return 0;
234}
235
236static struct rtc_class_ops pcf8563_rtc_ops = { 230static struct rtc_class_ops pcf8563_rtc_ops = {
237 .proc = pcf8563_rtc_proc,
238 .read_time = pcf8563_rtc_read_time, 231 .read_time = pcf8563_rtc_read_time,
239 .set_time = pcf8563_rtc_set_time, 232 .set_time = pcf8563_rtc_set_time,
240}; 233};
@@ -297,8 +290,6 @@ static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
297 290
298 if (IS_ERR(rtc)) { 291 if (IS_ERR(rtc)) {
299 err = PTR_ERR(rtc); 292 err = PTR_ERR(rtc);
300 dev_err(&client->dev,
301 "unable to register the class device\n");
302 goto exit_detach; 293 goto exit_detach;
303 } 294 }
304 295
@@ -321,8 +312,6 @@ static int pcf8563_detach(struct i2c_client *client)
321 int err; 312 int err;
322 struct rtc_device *rtc = i2c_get_clientdata(client); 313 struct rtc_device *rtc = i2c_get_clientdata(client);
323 314
324 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
325
326 if (rtc) 315 if (rtc)
327 rtc_device_unregister(rtc); 316 rtc_device_unregister(rtc);
328 317
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index 90b8a97a0919..cef5f5a3bbf9 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -71,6 +71,8 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
71 alrm.pending ? "yes" : "no"); 71 alrm.pending ? "yes" : "no");
72 } 72 }
73 73
74 seq_printf(seq, "24hr\t\t: yes\n");
75
74 if (ops->proc) 76 if (ops->proc)
75 ops->proc(class_dev->dev, seq); 77 ops->proc(class_dev->dev, seq);
76 78
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 396c8681f66c..7553d797603f 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -151,9 +151,8 @@ static int rs5c372_rtc_proc(struct device *dev, struct seq_file *seq)
151{ 151{
152 int err, osc, trim; 152 int err, osc, trim;
153 153
154 seq_printf(seq, "24hr\t\t: yes\n"); 154 err = rs5c372_get_trim(to_i2c_client(dev), &osc, &trim);
155 155 if (err == 0) {
156 if ((err = rs5c372_get_trim(to_i2c_client(dev), &osc, &trim)) == 0) {
157 seq_printf(seq, "%d.%03d KHz\n", osc / 1000, osc % 1000); 156 seq_printf(seq, "%d.%03d KHz\n", osc / 1000, osc % 1000);
158 seq_printf(seq, "trim\t: %d\n", trim); 157 seq_printf(seq, "trim\t: %d\n", trim);
159 } 158 }
@@ -170,30 +169,31 @@ static struct rtc_class_ops rs5c372_rtc_ops = {
170static ssize_t rs5c372_sysfs_show_trim(struct device *dev, 169static ssize_t rs5c372_sysfs_show_trim(struct device *dev,
171 struct device_attribute *attr, char *buf) 170 struct device_attribute *attr, char *buf)
172{ 171{
173 int trim; 172 int err, trim;
174 173
175 if (rs5c372_get_trim(to_i2c_client(dev), NULL, &trim) == 0) 174 err = rs5c372_get_trim(to_i2c_client(dev), NULL, &trim);
176 return sprintf(buf, "0x%2x\n", trim); 175 if (err)
176 return err;
177 177
178 return 0; 178 return sprintf(buf, "0x%2x\n", trim);
179} 179}
180static DEVICE_ATTR(trim, S_IRUGO, rs5c372_sysfs_show_trim, NULL); 180static DEVICE_ATTR(trim, S_IRUGO, rs5c372_sysfs_show_trim, NULL);
181 181
182static ssize_t rs5c372_sysfs_show_osc(struct device *dev, 182static ssize_t rs5c372_sysfs_show_osc(struct device *dev,
183 struct device_attribute *attr, char *buf) 183 struct device_attribute *attr, char *buf)
184{ 184{
185 int osc; 185 int err, osc;
186 186
187 if (rs5c372_get_trim(to_i2c_client(dev), &osc, NULL) == 0) 187 err = rs5c372_get_trim(to_i2c_client(dev), &osc, NULL);
188 return sprintf(buf, "%d.%03d KHz\n", osc / 1000, osc % 1000); 188 if (err)
189 return err;
189 190
190 return 0; 191 return sprintf(buf, "%d.%03d KHz\n", osc / 1000, osc % 1000);
191} 192}
192static DEVICE_ATTR(osc, S_IRUGO, rs5c372_sysfs_show_osc, NULL); 193static DEVICE_ATTR(osc, S_IRUGO, rs5c372_sysfs_show_osc, NULL);
193 194
194static int rs5c372_attach(struct i2c_adapter *adapter) 195static int rs5c372_attach(struct i2c_adapter *adapter)
195{ 196{
196 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
197 return i2c_probe(adapter, &addr_data, rs5c372_probe); 197 return i2c_probe(adapter, &addr_data, rs5c372_probe);
198} 198}
199 199
@@ -233,8 +233,6 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
233 233
234 if (IS_ERR(rtc)) { 234 if (IS_ERR(rtc)) {
235 err = PTR_ERR(rtc); 235 err = PTR_ERR(rtc);
236 dev_err(&client->dev,
237 "unable to register the class device\n");
238 goto exit_detach; 236 goto exit_detach;
239 } 237 }
240 238
@@ -260,8 +258,6 @@ static int rs5c372_detach(struct i2c_client *client)
260 int err; 258 int err;
261 struct rtc_device *rtc = i2c_get_clientdata(client); 259 struct rtc_device *rtc = i2c_get_clientdata(client);
262 260
263 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
264
265 if (rtc) 261 if (rtc)
266 rtc_device_unregister(rtc); 262 rtc_device_unregister(rtc);
267 263
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 83b2bb480a16..a23ec54989f6 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -160,19 +160,19 @@ static int sa1100_rtc_open(struct device *dev)
160 ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, SA_INTERRUPT, 160 ret = request_irq(IRQ_RTC1Hz, sa1100_rtc_interrupt, SA_INTERRUPT,
161 "rtc 1Hz", dev); 161 "rtc 1Hz", dev);
162 if (ret) { 162 if (ret) {
163 printk(KERN_ERR "rtc: IRQ%d already in use.\n", IRQ_RTC1Hz); 163 dev_err(dev, "IRQ %d already in use.\n", IRQ_RTC1Hz);
164 goto fail_ui; 164 goto fail_ui;
165 } 165 }
166 ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, SA_INTERRUPT, 166 ret = request_irq(IRQ_RTCAlrm, sa1100_rtc_interrupt, SA_INTERRUPT,
167 "rtc Alrm", dev); 167 "rtc Alrm", dev);
168 if (ret) { 168 if (ret) {
169 printk(KERN_ERR "rtc: IRQ%d already in use.\n", IRQ_RTCAlrm); 169 dev_err(dev, "IRQ %d already in use.\n", IRQ_RTCAlrm);
170 goto fail_ai; 170 goto fail_ai;
171 } 171 }
172 ret = request_irq(IRQ_OST1, timer1_interrupt, SA_INTERRUPT, 172 ret = request_irq(IRQ_OST1, timer1_interrupt, SA_INTERRUPT,
173 "rtc timer", dev); 173 "rtc timer", dev);
174 if (ret) { 174 if (ret) {
175 printk(KERN_ERR "rtc: IRQ%d already in use.\n", IRQ_OST1); 175 dev_err(dev, "IRQ %d already in use.\n", IRQ_OST1);
176 goto fail_pi; 176 goto fail_pi;
177 } 177 }
178 return 0; 178 return 0;
@@ -332,7 +332,7 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
332 */ 332 */
333 if (RTTR == 0) { 333 if (RTTR == 0) {
334 RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); 334 RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16);
335 printk(KERN_WARNING "rtc: warning: initializing default clock divider/trim value\n"); 335 dev_warn(&pdev->dev, "warning: initializing default clock divider/trim value\n");
336 /* The current RTC value probably doesn't make sense either */ 336 /* The current RTC value probably doesn't make sense either */
337 RCNR = 0; 337 RCNR = 0;
338 } 338 }
@@ -340,15 +340,11 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
340 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, 340 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops,
341 THIS_MODULE); 341 THIS_MODULE);
342 342
343 if (IS_ERR(rtc)) { 343 if (IS_ERR(rtc))
344 dev_err(&pdev->dev, "Unable to register the RTC device\n");
345 return PTR_ERR(rtc); 344 return PTR_ERR(rtc);
346 }
347 345
348 platform_set_drvdata(pdev, rtc); 346 platform_set_drvdata(pdev, rtc);
349 347
350 dev_info(&pdev->dev, "SA11xx/PXA2xx RTC Registered\n");
351
352 return 0; 348 return 0;
353} 349}
354 350
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index 43d107487820..e1f7e8e86daf 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -49,7 +49,6 @@ static int test_rtc_proc(struct device *dev, struct seq_file *seq)
49{ 49{
50 struct platform_device *plat_dev = to_platform_device(dev); 50 struct platform_device *plat_dev = to_platform_device(dev);
51 51
52 seq_printf(seq, "24hr\t\t: yes\n");
53 seq_printf(seq, "test\t\t: yes\n"); 52 seq_printf(seq, "test\t\t: yes\n");
54 seq_printf(seq, "id\t\t: %d\n", plat_dev->id); 53 seq_printf(seq, "id\t\t: %d\n", plat_dev->id);
55 54
@@ -120,8 +119,6 @@ static int test_probe(struct platform_device *plat_dev)
120 &test_rtc_ops, THIS_MODULE); 119 &test_rtc_ops, THIS_MODULE);
121 if (IS_ERR(rtc)) { 120 if (IS_ERR(rtc)) {
122 err = PTR_ERR(rtc); 121 err = PTR_ERR(rtc);
123 dev_err(&plat_dev->dev,
124 "unable to register the class device\n");
125 return err; 122 return err;
126 } 123 }
127 device_create_file(&plat_dev->dev, &dev_attr_irq); 124 device_create_file(&plat_dev->dev, &dev_attr_irq);
diff --git a/drivers/char/vr41xx_rtc.c b/drivers/rtc/rtc-vr41xx.c
index b109d9a502d6..4d49fd501198 100644
--- a/drivers/char/vr41xx_rtc.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for NEC VR4100 series Real Time Clock unit. 2 * Driver for NEC VR4100 series Real Time Clock unit.
3 * 3 *
4 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp> 4 * Copyright (C) 2003-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -17,23 +17,18 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20#include <linux/platform_device.h>
21#include <linux/fs.h> 20#include <linux/fs.h>
22#include <linux/init.h> 21#include <linux/init.h>
23#include <linux/ioport.h> 22#include <linux/ioport.h>
24#include <linux/irq.h> 23#include <linux/irq.h>
25#include <linux/mc146818rtc.h>
26#include <linux/miscdevice.h>
27#include <linux/module.h> 24#include <linux/module.h>
28#include <linux/poll.h> 25#include <linux/platform_device.h>
29#include <linux/rtc.h> 26#include <linux/rtc.h>
30#include <linux/spinlock.h> 27#include <linux/spinlock.h>
31#include <linux/types.h> 28#include <linux/types.h>
32#include <linux/wait.h>
33 29
34#include <asm/div64.h> 30#include <asm/div64.h>
35#include <asm/io.h> 31#include <asm/io.h>
36#include <asm/time.h>
37#include <asm/uaccess.h> 32#include <asm/uaccess.h>
38#include <asm/vr41xx/vr41xx.h> 33#include <asm/vr41xx/vr41xx.h>
39 34
@@ -99,27 +94,11 @@ static void __iomem *rtc2_base;
99 94
100static unsigned long epoch = 1970; /* Jan 1 1970 00:00:00 */ 95static unsigned long epoch = 1970; /* Jan 1 1970 00:00:00 */
101 96
102static spinlock_t rtc_task_lock; 97static spinlock_t rtc_lock = SPIN_LOCK_UNLOCKED;
103static wait_queue_head_t rtc_wait;
104static unsigned long rtc_irq_data;
105static struct fasync_struct *rtc_async_queue;
106static rtc_task_t *rtc_callback;
107static char rtc_name[] = "RTC"; 98static char rtc_name[] = "RTC";
108static unsigned long periodic_frequency; 99static unsigned long periodic_frequency;
109static unsigned long periodic_count; 100static unsigned long periodic_count;
110 101
111typedef enum {
112 RTC_RELEASE,
113 RTC_OPEN,
114} rtc_status_t;
115
116static rtc_status_t rtc_status;
117
118typedef enum {
119 FUNCTION_RTC_IOCTL,
120 FUNCTION_RTC_CONTROL,
121} rtc_callfrom_t;
122
123struct resource rtc_resource[2] = { 102struct resource rtc_resource[2] = {
124 { .name = rtc_name, 103 { .name = rtc_name,
125 .flags = IORESOURCE_MEM, }, 104 .flags = IORESOURCE_MEM, },
@@ -129,7 +108,9 @@ struct resource rtc_resource[2] = {
129 108
130static inline unsigned long read_elapsed_second(void) 109static inline unsigned long read_elapsed_second(void)
131{ 110{
111
132 unsigned long first_low, first_mid, first_high; 112 unsigned long first_low, first_mid, first_high;
113
133 unsigned long second_low, second_mid, second_high; 114 unsigned long second_low, second_mid, second_high;
134 115
135 do { 116 do {
@@ -156,50 +137,36 @@ static inline void write_elapsed_second(unsigned long sec)
156 spin_unlock_irq(&rtc_lock); 137 spin_unlock_irq(&rtc_lock);
157} 138}
158 139
159static void set_alarm(struct rtc_time *time) 140static void vr41xx_rtc_release(struct device *dev)
160{ 141{
161 unsigned long alarm_sec;
162
163 alarm_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
164 time->tm_hour, time->tm_min, time->tm_sec);
165
166 spin_lock_irq(&rtc_lock);
167
168 rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15));
169 rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1));
170 rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17));
171
172 spin_unlock_irq(&rtc_lock);
173}
174
175static void read_alarm(struct rtc_time *time)
176{
177 unsigned long low, mid, high;
178 142
179 spin_lock_irq(&rtc_lock); 143 spin_lock_irq(&rtc_lock);
180 144
181 low = rtc1_read(ECMPLREG); 145 rtc1_write(ECMPLREG, 0);
182 mid = rtc1_read(ECMPMREG); 146 rtc1_write(ECMPMREG, 0);
183 high = rtc1_read(ECMPHREG); 147 rtc1_write(ECMPHREG, 0);
148 rtc1_write(RTCL1LREG, 0);
149 rtc1_write(RTCL1HREG, 0);
184 150
185 spin_unlock_irq(&rtc_lock); 151 spin_unlock_irq(&rtc_lock);
186 152
187 to_tm((high << 17) | (mid << 1) | (low >> 15), time); 153 disable_irq(ELAPSEDTIME_IRQ);
188 time->tm_year -= 1900; 154 disable_irq(RTCLONG1_IRQ);
189} 155}
190 156
191static void read_time(struct rtc_time *time) 157static int vr41xx_rtc_read_time(struct device *dev, struct rtc_time *time)
192{ 158{
193 unsigned long epoch_sec, elapsed_sec; 159 unsigned long epoch_sec, elapsed_sec;
194 160
195 epoch_sec = mktime(epoch, 1, 1, 0, 0, 0); 161 epoch_sec = mktime(epoch, 1, 1, 0, 0, 0);
196 elapsed_sec = read_elapsed_second(); 162 elapsed_sec = read_elapsed_second();
197 163
198 to_tm(epoch_sec + elapsed_sec, time); 164 rtc_time_to_tm(epoch_sec + elapsed_sec, time);
199 time->tm_year -= 1900; 165
166 return 0;
200} 167}
201 168
202static void set_time(struct rtc_time *time) 169static int vr41xx_rtc_set_time(struct device *dev, struct rtc_time *time)
203{ 170{
204 unsigned long epoch_sec, current_sec; 171 unsigned long epoch_sec, current_sec;
205 172
@@ -208,73 +175,49 @@ static void set_time(struct rtc_time *time)
208 time->tm_hour, time->tm_min, time->tm_sec); 175 time->tm_hour, time->tm_min, time->tm_sec);
209 176
210 write_elapsed_second(current_sec - epoch_sec); 177 write_elapsed_second(current_sec - epoch_sec);
178
179 return 0;
211} 180}
212 181
213static ssize_t rtc_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 182static int vr41xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
214{ 183{
215 DECLARE_WAITQUEUE(wait, current); 184 unsigned long low, mid, high;
216 unsigned long irq_data; 185 struct rtc_time *time = &wkalrm->time;
217 int retval = 0;
218
219 if (count != sizeof(unsigned int) && count != sizeof(unsigned long))
220 return -EINVAL;
221
222 add_wait_queue(&rtc_wait, &wait);
223
224 do {
225 __set_current_state(TASK_INTERRUPTIBLE);
226 186
227 spin_lock_irq(&rtc_lock); 187 spin_lock_irq(&rtc_lock);
228 irq_data = rtc_irq_data;
229 rtc_irq_data = 0;
230 spin_unlock_irq(&rtc_lock);
231 188
232 if (irq_data != 0) 189 low = rtc1_read(ECMPLREG);
233 break; 190 mid = rtc1_read(ECMPMREG);
191 high = rtc1_read(ECMPHREG);
234 192
235 if (file->f_flags & O_NONBLOCK) { 193 spin_unlock_irq(&rtc_lock);
236 retval = -EAGAIN;
237 break;
238 }
239 194
240 if (signal_pending(current)) { 195 rtc_time_to_tm((high << 17) | (mid << 1) | (low >> 15), time);
241 retval = -ERESTARTSYS;
242 break;
243 }
244 } while (1);
245 196
246 if (retval == 0) { 197 return 0;
247 if (count == sizeof(unsigned int)) { 198}
248 retval = put_user(irq_data, (unsigned int __user *)buf);
249 if (retval == 0)
250 retval = sizeof(unsigned int);
251 } else {
252 retval = put_user(irq_data, (unsigned long __user *)buf);
253 if (retval == 0)
254 retval = sizeof(unsigned long);
255 }
256 199
257 } 200static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
201{
202 unsigned long alarm_sec;
203 struct rtc_time *time = &wkalrm->time;
258 204
259 __set_current_state(TASK_RUNNING); 205 alarm_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
260 remove_wait_queue(&rtc_wait, &wait); 206 time->tm_hour, time->tm_min, time->tm_sec);
261 207
262 return retval; 208 spin_lock_irq(&rtc_lock);
263}
264 209
265static unsigned int rtc_poll(struct file *file, struct poll_table_struct *table) 210 rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15));
266{ 211 rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1));
267 poll_wait(file, &rtc_wait, table); 212 rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17));
268 213
269 if (rtc_irq_data != 0) 214 spin_unlock_irq(&rtc_lock);
270 return POLLIN | POLLRDNORM;
271 215
272 return 0; 216 return 0;
273} 217}
274 218
275static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, rtc_callfrom_t from) 219static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
276{ 220{
277 struct rtc_time time;
278 unsigned long count; 221 unsigned long count;
279 222
280 switch (cmd) { 223 switch (cmd) {
@@ -290,33 +233,6 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, rtc_callfrom_t from
290 case RTC_PIE_OFF: 233 case RTC_PIE_OFF:
291 disable_irq(RTCLONG1_IRQ); 234 disable_irq(RTCLONG1_IRQ);
292 break; 235 break;
293 case RTC_ALM_SET:
294 if (copy_from_user(&time, (struct rtc_time __user *)arg,
295 sizeof(struct rtc_time)))
296 return -EFAULT;
297
298 set_alarm(&time);
299 break;
300 case RTC_ALM_READ:
301 memset(&time, 0, sizeof(struct rtc_time));
302 read_alarm(&time);
303 break;
304 case RTC_RD_TIME:
305 memset(&time, 0, sizeof(struct rtc_time));
306 read_time(&time);
307 if (copy_to_user((void __user *)arg, &time, sizeof(struct rtc_time)))
308 return -EFAULT;
309 break;
310 case RTC_SET_TIME:
311 if (capable(CAP_SYS_TIME) == 0)
312 return -EACCES;
313
314 if (copy_from_user(&time, (struct rtc_time __user *)arg,
315 sizeof(struct rtc_time)))
316 return -EFAULT;
317
318 set_time(&time);
319 break;
320 case RTC_IRQP_READ: 236 case RTC_IRQP_READ:
321 return put_user(periodic_frequency, (unsigned long __user *)arg); 237 return put_user(periodic_frequency, (unsigned long __user *)arg);
322 break; 238 break;
@@ -324,8 +240,7 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, rtc_callfrom_t from
324 if (arg > MAX_PERIODIC_RATE) 240 if (arg > MAX_PERIODIC_RATE)
325 return -EINVAL; 241 return -EINVAL;
326 242
327 if (from == FUNCTION_RTC_IOCTL && arg > MAX_USER_PERIODIC_RATE && 243 if (arg > MAX_USER_PERIODIC_RATE && capable(CAP_SYS_RESOURCE) == 0)
328 capable(CAP_SYS_RESOURCE) == 0)
329 return -EACCES; 244 return -EACCES;
330 245
331 periodic_frequency = arg; 246 periodic_frequency = arg;
@@ -361,205 +276,46 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, rtc_callfrom_t from
361 return 0; 276 return 0;
362} 277}
363 278
364static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
365 unsigned long arg)
366{
367 return rtc_do_ioctl(cmd, arg, FUNCTION_RTC_IOCTL);
368}
369
370static int rtc_open(struct inode *inode, struct file *file)
371{
372 spin_lock_irq(&rtc_lock);
373
374 if (rtc_status == RTC_OPEN) {
375 spin_unlock_irq(&rtc_lock);
376 return -EBUSY;
377 }
378
379 rtc_status = RTC_OPEN;
380 rtc_irq_data = 0;
381
382 spin_unlock_irq(&rtc_lock);
383
384 return 0;
385}
386
387static int rtc_release(struct inode *inode, struct file *file)
388{
389 if (file->f_flags & FASYNC)
390 (void)fasync_helper(-1, file, 0, &rtc_async_queue);
391
392 spin_lock_irq(&rtc_lock);
393
394 rtc1_write(ECMPLREG, 0);
395 rtc1_write(ECMPMREG, 0);
396 rtc1_write(ECMPHREG, 0);
397 rtc1_write(RTCL1LREG, 0);
398 rtc1_write(RTCL1HREG, 0);
399
400 rtc_status = RTC_RELEASE;
401
402 spin_unlock_irq(&rtc_lock);
403
404 disable_irq(ELAPSEDTIME_IRQ);
405 disable_irq(RTCLONG1_IRQ);
406
407 return 0;
408}
409
410static int rtc_fasync(int fd, struct file *file, int on)
411{
412 return fasync_helper(fd, file, on, &rtc_async_queue);
413}
414
415static struct file_operations rtc_fops = {
416 .owner = THIS_MODULE,
417 .llseek = no_llseek,
418 .read = rtc_read,
419 .poll = rtc_poll,
420 .ioctl = rtc_ioctl,
421 .open = rtc_open,
422 .release = rtc_release,
423 .fasync = rtc_fasync,
424};
425
426static irqreturn_t elapsedtime_interrupt(int irq, void *dev_id, struct pt_regs *regs) 279static irqreturn_t elapsedtime_interrupt(int irq, void *dev_id, struct pt_regs *regs)
427{ 280{
428 spin_lock(&rtc_lock); 281 struct platform_device *pdev = (struct platform_device *)dev_id;
429 rtc2_write(RTCINTREG, ELAPSEDTIME_INT); 282 struct rtc_device *rtc = platform_get_drvdata(pdev);
430
431 rtc_irq_data += 0x100;
432 rtc_irq_data &= ~0xff;
433 rtc_irq_data |= RTC_AF;
434 spin_unlock(&rtc_lock);
435 283
436 spin_lock(&rtc_lock); 284 rtc2_write(RTCINTREG, ELAPSEDTIME_INT);
437 if (rtc_callback)
438 rtc_callback->func(rtc_callback->private_data);
439 spin_unlock(&rtc_lock);
440
441 wake_up_interruptible(&rtc_wait);
442 285
443 kill_fasync(&rtc_async_queue, SIGIO, POLL_IN); 286 rtc_update_irq(&rtc->class_dev, 1, RTC_AF);
444 287
445 return IRQ_HANDLED; 288 return IRQ_HANDLED;
446} 289}
447 290
448static irqreturn_t rtclong1_interrupt(int irq, void *dev_id, struct pt_regs *regs) 291static irqreturn_t rtclong1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
449{ 292{
293 struct platform_device *pdev = (struct platform_device *)dev_id;
294 struct rtc_device *rtc = platform_get_drvdata(pdev);
450 unsigned long count = periodic_count; 295 unsigned long count = periodic_count;
451 296
452 spin_lock(&rtc_lock);
453 rtc2_write(RTCINTREG, RTCLONG1_INT); 297 rtc2_write(RTCINTREG, RTCLONG1_INT);
454 298
455 rtc1_write(RTCL1LREG, count); 299 rtc1_write(RTCL1LREG, count);
456 rtc1_write(RTCL1HREG, count >> 16); 300 rtc1_write(RTCL1HREG, count >> 16);
457 301
458 rtc_irq_data += 0x100; 302 rtc_update_irq(&rtc->class_dev, 1, RTC_PF);
459 rtc_irq_data &= ~0xff;
460 rtc_irq_data |= RTC_PF;
461 spin_unlock(&rtc_lock);
462
463 spin_lock(&rtc_task_lock);
464 if (rtc_callback)
465 rtc_callback->func(rtc_callback->private_data);
466 spin_unlock(&rtc_task_lock);
467
468 wake_up_interruptible(&rtc_wait);
469
470 kill_fasync(&rtc_async_queue, SIGIO, POLL_IN);
471 303
472 return IRQ_HANDLED; 304 return IRQ_HANDLED;
473} 305}
474 306
475int rtc_register(rtc_task_t *task) 307static struct rtc_class_ops vr41xx_rtc_ops = {
476{ 308 .release = vr41xx_rtc_release,
477 if (task == NULL || task->func == NULL) 309 .ioctl = vr41xx_rtc_ioctl,
478 return -EINVAL; 310 .read_time = vr41xx_rtc_read_time,
479 311 .set_time = vr41xx_rtc_set_time,
480 spin_lock_irq(&rtc_lock); 312 .read_alarm = vr41xx_rtc_read_alarm,
481 if (rtc_status == RTC_OPEN) { 313 .set_alarm = vr41xx_rtc_set_alarm,
482 spin_unlock_irq(&rtc_lock);
483 return -EBUSY;
484 }
485
486 spin_lock(&rtc_task_lock);
487 if (rtc_callback != NULL) {
488 spin_unlock(&rtc_task_lock);
489 spin_unlock_irq(&rtc_task_lock);
490 return -EBUSY;
491 }
492
493 rtc_callback = task;
494 spin_unlock(&rtc_task_lock);
495
496 rtc_status = RTC_OPEN;
497
498 spin_unlock_irq(&rtc_lock);
499
500 return 0;
501}
502
503EXPORT_SYMBOL_GPL(rtc_register);
504
505int rtc_unregister(rtc_task_t *task)
506{
507 spin_lock_irq(&rtc_task_lock);
508 if (task == NULL || rtc_callback != task) {
509 spin_unlock_irq(&rtc_task_lock);
510 return -ENXIO;
511 }
512
513 spin_lock(&rtc_lock);
514
515 rtc1_write(ECMPLREG, 0);
516 rtc1_write(ECMPMREG, 0);
517 rtc1_write(ECMPHREG, 0);
518 rtc1_write(RTCL1LREG, 0);
519 rtc1_write(RTCL1HREG, 0);
520
521 rtc_status = RTC_RELEASE;
522
523 spin_unlock(&rtc_lock);
524
525 rtc_callback = NULL;
526
527 spin_unlock_irq(&rtc_task_lock);
528
529 disable_irq(ELAPSEDTIME_IRQ);
530 disable_irq(RTCLONG1_IRQ);
531
532 return 0;
533}
534
535EXPORT_SYMBOL_GPL(rtc_unregister);
536
537int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg)
538{
539 int retval = 0;
540
541 spin_lock_irq(&rtc_task_lock);
542
543 if (rtc_callback != task)
544 retval = -ENXIO;
545 else
546 rtc_do_ioctl(cmd, arg, FUNCTION_RTC_CONTROL);
547
548 spin_unlock_irq(&rtc_task_lock);
549
550 return retval;
551}
552
553EXPORT_SYMBOL_GPL(rtc_control);
554
555static struct miscdevice rtc_miscdevice = {
556 .minor = RTC_MINOR,
557 .name = rtc_name,
558 .fops = &rtc_fops,
559}; 314};
560 315
561static int __devinit rtc_probe(struct platform_device *pdev) 316static int __devinit rtc_probe(struct platform_device *pdev)
562{ 317{
318 struct rtc_device *rtc;
563 unsigned int irq; 319 unsigned int irq;
564 int retval; 320 int retval;
565 321
@@ -577,13 +333,13 @@ static int __devinit rtc_probe(struct platform_device *pdev)
577 return -EBUSY; 333 return -EBUSY;
578 } 334 }
579 335
580 retval = misc_register(&rtc_miscdevice); 336 rtc = rtc_device_register(rtc_name, &pdev->dev, &vr41xx_rtc_ops, THIS_MODULE);
581 if (retval < 0) { 337 if (IS_ERR(rtc)) {
582 iounmap(rtc1_base); 338 iounmap(rtc1_base);
583 iounmap(rtc2_base); 339 iounmap(rtc2_base);
584 rtc1_base = NULL; 340 rtc1_base = NULL;
585 rtc2_base = NULL; 341 rtc2_base = NULL;
586 return retval; 342 return PTR_ERR(rtc);
587 } 343 }
588 344
589 spin_lock_irq(&rtc_lock); 345 spin_lock_irq(&rtc_lock);
@@ -594,24 +350,20 @@ static int __devinit rtc_probe(struct platform_device *pdev)
594 rtc1_write(RTCL1LREG, 0); 350 rtc1_write(RTCL1LREG, 0);
595 rtc1_write(RTCL1HREG, 0); 351 rtc1_write(RTCL1HREG, 0);
596 352
597 rtc_status = RTC_RELEASE;
598 rtc_irq_data = 0;
599
600 spin_unlock_irq(&rtc_lock); 353 spin_unlock_irq(&rtc_lock);
601 354
602 init_waitqueue_head(&rtc_wait);
603
604 irq = ELAPSEDTIME_IRQ; 355 irq = ELAPSEDTIME_IRQ;
605 retval = request_irq(irq, elapsedtime_interrupt, SA_INTERRUPT, 356 retval = request_irq(irq, elapsedtime_interrupt, SA_INTERRUPT,
606 "elapsed_time", NULL); 357 "elapsed_time", pdev);
607 if (retval == 0) { 358 if (retval == 0) {
608 irq = RTCLONG1_IRQ; 359 irq = RTCLONG1_IRQ;
609 retval = request_irq(irq, rtclong1_interrupt, SA_INTERRUPT, 360 retval = request_irq(irq, rtclong1_interrupt, SA_INTERRUPT,
610 "rtclong1", NULL); 361 "rtclong1", pdev);
611 } 362 }
612 363
613 if (retval < 0) { 364 if (retval < 0) {
614 printk(KERN_ERR "rtc: IRQ%d is busy\n", irq); 365 printk(KERN_ERR "rtc: IRQ%d is busy\n", irq);
366 rtc_device_unregister(rtc);
615 if (irq == RTCLONG1_IRQ) 367 if (irq == RTCLONG1_IRQ)
616 free_irq(ELAPSEDTIME_IRQ, NULL); 368 free_irq(ELAPSEDTIME_IRQ, NULL);
617 iounmap(rtc1_base); 369 iounmap(rtc1_base);
@@ -621,23 +373,25 @@ static int __devinit rtc_probe(struct platform_device *pdev)
621 return retval; 373 return retval;
622 } 374 }
623 375
376 platform_set_drvdata(pdev, rtc);
377
624 disable_irq(ELAPSEDTIME_IRQ); 378 disable_irq(ELAPSEDTIME_IRQ);
625 disable_irq(RTCLONG1_IRQ); 379 disable_irq(RTCLONG1_IRQ);
626 380
627 spin_lock_init(&rtc_task_lock);
628
629 printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n"); 381 printk(KERN_INFO "rtc: Real Time Clock of NEC VR4100 series\n");
630 382
631 return 0; 383 return 0;
632} 384}
633 385
634static int __devexit rtc_remove(struct platform_device *dev) 386static int __devexit rtc_remove(struct platform_device *pdev)
635{ 387{
636 int retval; 388 struct rtc_device *rtc;
637 389
638 retval = misc_deregister(&rtc_miscdevice); 390 rtc = platform_get_drvdata(pdev);
639 if (retval < 0) 391 if (rtc != NULL)
640 return retval; 392 rtc_device_unregister(rtc);
393
394 platform_set_drvdata(pdev, NULL);
641 395
642 free_irq(ELAPSEDTIME_IRQ, NULL); 396 free_irq(ELAPSEDTIME_IRQ, NULL);
643 free_irq(RTCLONG1_IRQ, NULL); 397 free_irq(RTCLONG1_IRQ, NULL);
@@ -651,7 +405,7 @@ static int __devexit rtc_remove(struct platform_device *dev)
651 405
652static struct platform_device *rtc_platform_device; 406static struct platform_device *rtc_platform_device;
653 407
654static struct platform_driver rtc_device_driver = { 408static struct platform_driver rtc_platform_driver = {
655 .probe = rtc_probe, 409 .probe = rtc_probe,
656 .remove = __devexit_p(rtc_remove), 410 .remove = __devexit_p(rtc_remove),
657 .driver = { 411 .driver = {
@@ -686,7 +440,7 @@ static int __init vr41xx_rtc_init(void)
686 } 440 }
687 441
688 rtc_platform_device = platform_device_alloc("RTC", -1); 442 rtc_platform_device = platform_device_alloc("RTC", -1);
689 if (!rtc_platform_device) 443 if (rtc_platform_device == NULL)
690 return -ENOMEM; 444 return -ENOMEM;
691 445
692 retval = platform_device_add_resources(rtc_platform_device, 446 retval = platform_device_add_resources(rtc_platform_device,
@@ -700,7 +454,7 @@ static int __init vr41xx_rtc_init(void)
700 return retval; 454 return retval;
701 } 455 }
702 456
703 retval = platform_driver_register(&rtc_device_driver); 457 retval = platform_driver_register(&rtc_platform_driver);
704 if (retval < 0) 458 if (retval < 0)
705 platform_device_unregister(rtc_platform_device); 459 platform_device_unregister(rtc_platform_device);
706 460
@@ -709,7 +463,7 @@ static int __init vr41xx_rtc_init(void)
709 463
710static void __exit vr41xx_rtc_exit(void) 464static void __exit vr41xx_rtc_exit(void)
711{ 465{
712 platform_driver_unregister(&rtc_device_driver); 466 platform_driver_unregister(&rtc_platform_driver);
713 platform_device_unregister(rtc_platform_device); 467 platform_device_unregister(rtc_platform_device);
714} 468}
715 469
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 621d17afc0d9..788b6d1f8f2f 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -19,7 +19,7 @@
19#include <linux/rtc.h> 19#include <linux/rtc.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21 21
22#define DRV_VERSION "1.0.6" 22#define DRV_VERSION "1.0.7"
23 23
24/* Addresses to scan: none. This chip is located at 24/* Addresses to scan: none. This chip is located at
25 * 0x6f and uses a two bytes register addressing. 25 * 0x6f and uses a two bytes register addressing.
@@ -451,8 +451,6 @@ static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)
451{ 451{
452 int err, dtrim, atrim; 452 int err, dtrim, atrim;
453 453
454 seq_printf(seq, "24hr\t\t: yes\n");
455
456 if ((err = x1205_get_dtrim(to_i2c_client(dev), &dtrim)) == 0) 454 if ((err = x1205_get_dtrim(to_i2c_client(dev), &dtrim)) == 0)
457 seq_printf(seq, "digital_trim\t: %d ppm\n", dtrim); 455 seq_printf(seq, "digital_trim\t: %d ppm\n", dtrim);
458 456
@@ -473,30 +471,31 @@ static struct rtc_class_ops x1205_rtc_ops = {
473static ssize_t x1205_sysfs_show_atrim(struct device *dev, 471static ssize_t x1205_sysfs_show_atrim(struct device *dev,
474 struct device_attribute *attr, char *buf) 472 struct device_attribute *attr, char *buf)
475{ 473{
476 int atrim; 474 int err, atrim;
477 475
478 if (x1205_get_atrim(to_i2c_client(dev), &atrim) == 0) 476 err = x1205_get_atrim(to_i2c_client(dev), &atrim);
479 return sprintf(buf, "%d.%02d pF\n", 477 if (err)
480 atrim / 1000, atrim % 1000); 478 return err;
481 return 0; 479
480 return sprintf(buf, "%d.%02d pF\n", atrim / 1000, atrim % 1000);
482} 481}
483static DEVICE_ATTR(atrim, S_IRUGO, x1205_sysfs_show_atrim, NULL); 482static DEVICE_ATTR(atrim, S_IRUGO, x1205_sysfs_show_atrim, NULL);
484 483
485static ssize_t x1205_sysfs_show_dtrim(struct device *dev, 484static ssize_t x1205_sysfs_show_dtrim(struct device *dev,
486 struct device_attribute *attr, char *buf) 485 struct device_attribute *attr, char *buf)
487{ 486{
488 int dtrim; 487 int err, dtrim;
489 488
490 if (x1205_get_dtrim(to_i2c_client(dev), &dtrim) == 0) 489 err = x1205_get_dtrim(to_i2c_client(dev), &dtrim);
491 return sprintf(buf, "%d ppm\n", dtrim); 490 if (err)
491 return err;
492 492
493 return 0; 493 return sprintf(buf, "%d ppm\n", dtrim);
494} 494}
495static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL); 495static DEVICE_ATTR(dtrim, S_IRUGO, x1205_sysfs_show_dtrim, NULL);
496 496
497static int x1205_attach(struct i2c_adapter *adapter) 497static int x1205_attach(struct i2c_adapter *adapter)
498{ 498{
499 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
500 return i2c_probe(adapter, &addr_data, x1205_probe); 499 return i2c_probe(adapter, &addr_data, x1205_probe);
501} 500}
502 501
@@ -545,8 +544,6 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
545 544
546 if (IS_ERR(rtc)) { 545 if (IS_ERR(rtc)) {
547 err = PTR_ERR(rtc); 546 err = PTR_ERR(rtc);
548 dev_err(&client->dev,
549 "unable to register the class device\n");
550 goto exit_detach; 547 goto exit_detach;
551 } 548 }
552 549
@@ -585,8 +582,6 @@ static int x1205_detach(struct i2c_client *client)
585 int err; 582 int err;
586 struct rtc_device *rtc = i2c_get_clientdata(client); 583 struct rtc_device *rtc = i2c_get_clientdata(client);
587 584
588 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
589
590 if (rtc) 585 if (rtc)
591 rtc_device_unregister(rtc); 586 rtc_device_unregister(rtc);
592 587
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 0a9f12c4e911..a3bfebcf31ef 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1257,25 +1257,28 @@ __dasd_start_head(struct dasd_device * device)
1257 if (list_empty(&device->ccw_queue)) 1257 if (list_empty(&device->ccw_queue))
1258 return; 1258 return;
1259 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list); 1259 cqr = list_entry(device->ccw_queue.next, struct dasd_ccw_req, list);
1260 /* check FAILFAST */ 1260 if (cqr->status != DASD_CQR_QUEUED)
1261 return;
1262 /* Non-temporary stop condition will trigger fail fast */
1261 if (device->stopped & ~DASD_STOPPED_PENDING && 1263 if (device->stopped & ~DASD_STOPPED_PENDING &&
1262 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) && 1264 test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
1263 (!dasd_eer_enabled(device))) { 1265 (!dasd_eer_enabled(device))) {
1264 cqr->status = DASD_CQR_FAILED; 1266 cqr->status = DASD_CQR_FAILED;
1265 dasd_schedule_bh(device); 1267 dasd_schedule_bh(device);
1268 return;
1266 } 1269 }
1267 if ((cqr->status == DASD_CQR_QUEUED) && 1270 /* Don't try to start requests if device is stopped */
1268 (!device->stopped)) { 1271 if (device->stopped)
1269 /* try to start the first I/O that can be started */ 1272 return;
1270 rc = device->discipline->start_IO(cqr); 1273
1271 if (rc == 0) 1274 rc = device->discipline->start_IO(cqr);
1272 dasd_set_timer(device, cqr->expires); 1275 if (rc == 0)
1273 else if (rc == -EACCES) { 1276 dasd_set_timer(device, cqr->expires);
1274 dasd_schedule_bh(device); 1277 else if (rc == -EACCES) {
1275 } else 1278 dasd_schedule_bh(device);
1276 /* Hmpf, try again in 1/2 sec */ 1279 } else
1277 dasd_set_timer(device, 50); 1280 /* Hmpf, try again in 1/2 sec */
1278 } 1281 dasd_set_timer(device, 50);
1279} 1282}
1280 1283
1281/* 1284/*
@@ -1968,7 +1971,7 @@ int
1968dasd_generic_set_offline (struct ccw_device *cdev) 1971dasd_generic_set_offline (struct ccw_device *cdev)
1969{ 1972{
1970 struct dasd_device *device; 1973 struct dasd_device *device;
1971 int max_count; 1974 int max_count, open_count;
1972 1975
1973 device = dasd_device_from_cdev(cdev); 1976 device = dasd_device_from_cdev(cdev);
1974 if (IS_ERR(device)) 1977 if (IS_ERR(device))
@@ -1985,10 +1988,16 @@ dasd_generic_set_offline (struct ccw_device *cdev)
1985 * in the other openers. 1988 * in the other openers.
1986 */ 1989 */
1987 max_count = device->bdev ? 0 : -1; 1990 max_count = device->bdev ? 0 : -1;
1988 if (atomic_read(&device->open_count) > max_count) { 1991 open_count = (int) atomic_read(&device->open_count);
1989 printk (KERN_WARNING "Can't offline dasd device with open" 1992 if (open_count > max_count) {
1990 " count = %i.\n", 1993 if (open_count > 0)
1991 atomic_read(&device->open_count)); 1994 printk (KERN_WARNING "Can't offline dasd device with "
1995 "open count = %i.\n",
1996 open_count);
1997 else
1998 printk (KERN_WARNING "%s",
1999 "Can't offline dasd device due to internal "
2000 "use\n");
1992 clear_bit(DASD_FLAG_OFFLINE, &device->flags); 2001 clear_bit(DASD_FLAG_OFFLINE, &device->flags);
1993 dasd_put_device(device); 2002 dasd_put_device(device);
1994 return -EBUSY; 2003 return -EBUSY;
diff --git a/drivers/s390/block/dasd_erp.c b/drivers/s390/block/dasd_erp.c
index 8fd71ab02ef0..b842377cb0c6 100644
--- a/drivers/s390/block/dasd_erp.c
+++ b/drivers/s390/block/dasd_erp.c
@@ -32,9 +32,8 @@ dasd_alloc_erp_request(char *magic, int cplength, int datasize,
32 int size; 32 int size;
33 33
34 /* Sanity checks */ 34 /* Sanity checks */
35 if ( magic == NULL || datasize > PAGE_SIZE || 35 BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
36 (cplength*sizeof(struct ccw1)) > PAGE_SIZE) 36 (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
37 BUG();
38 37
39 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L; 38 size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
40 if (cplength > 0) 39 if (cplength > 0)
@@ -125,8 +124,7 @@ dasd_default_erp_postaction(struct dasd_ccw_req * cqr)
125 struct dasd_device *device; 124 struct dasd_device *device;
126 int success; 125 int success;
127 126
128 if (cqr->refers == NULL || cqr->function == NULL) 127 BUG_ON(cqr->refers == NULL || cqr->function == NULL);
129 BUG();
130 128
131 device = cqr->device; 129 device = cqr->device;
132 success = cqr->status == DASD_CQR_DONE; 130 success = cqr->status == DASD_CQR_DONE;
diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c
index 1aa3c261718a..ad23aede356c 100644
--- a/drivers/s390/block/dasd_proc.c
+++ b/drivers/s390/block/dasd_proc.c
@@ -294,23 +294,40 @@ out_error:
294#endif /* CONFIG_DASD_PROFILE */ 294#endif /* CONFIG_DASD_PROFILE */
295} 295}
296 296
297/*
298 * Create dasd proc-fs entries.
299 * In case creation failed, cleanup and return -ENOENT.
300 */
297int 301int
298dasd_proc_init(void) 302dasd_proc_init(void)
299{ 303{
300 dasd_proc_root_entry = proc_mkdir("dasd", &proc_root); 304 dasd_proc_root_entry = proc_mkdir("dasd", &proc_root);
305 if (!dasd_proc_root_entry)
306 goto out_nodasd;
301 dasd_proc_root_entry->owner = THIS_MODULE; 307 dasd_proc_root_entry->owner = THIS_MODULE;
302 dasd_devices_entry = create_proc_entry("devices", 308 dasd_devices_entry = create_proc_entry("devices",
303 S_IFREG | S_IRUGO | S_IWUSR, 309 S_IFREG | S_IRUGO | S_IWUSR,
304 dasd_proc_root_entry); 310 dasd_proc_root_entry);
311 if (!dasd_devices_entry)
312 goto out_nodevices;
305 dasd_devices_entry->proc_fops = &dasd_devices_file_ops; 313 dasd_devices_entry->proc_fops = &dasd_devices_file_ops;
306 dasd_devices_entry->owner = THIS_MODULE; 314 dasd_devices_entry->owner = THIS_MODULE;
307 dasd_statistics_entry = create_proc_entry("statistics", 315 dasd_statistics_entry = create_proc_entry("statistics",
308 S_IFREG | S_IRUGO | S_IWUSR, 316 S_IFREG | S_IRUGO | S_IWUSR,
309 dasd_proc_root_entry); 317 dasd_proc_root_entry);
318 if (!dasd_statistics_entry)
319 goto out_nostatistics;
310 dasd_statistics_entry->read_proc = dasd_statistics_read; 320 dasd_statistics_entry->read_proc = dasd_statistics_read;
311 dasd_statistics_entry->write_proc = dasd_statistics_write; 321 dasd_statistics_entry->write_proc = dasd_statistics_write;
312 dasd_statistics_entry->owner = THIS_MODULE; 322 dasd_statistics_entry->owner = THIS_MODULE;
313 return 0; 323 return 0;
324
325 out_nostatistics:
326 remove_proc_entry("devices", dasd_proc_root_entry);
327 out_nodevices:
328 remove_proc_entry("dasd", &proc_root);
329 out_nodasd:
330 return -ENOENT;
314} 331}
315 332
316void 333void
diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c
index 6badd8403409..d4d2ff0a9da2 100644
--- a/drivers/s390/char/keyboard.c
+++ b/drivers/s390/char/keyboard.c
@@ -54,7 +54,7 @@ kbd_alloc(void) {
54 if (!kbd) 54 if (!kbd)
55 goto out; 55 goto out;
56 kbd->key_maps = kzalloc(sizeof(key_maps), GFP_KERNEL); 56 kbd->key_maps = kzalloc(sizeof(key_maps), GFP_KERNEL);
57 if (!key_maps) 57 if (!kbd->key_maps)
58 goto out_kbd; 58 goto out_kbd;
59 for (i = 0; i < ARRAY_SIZE(key_maps); i++) { 59 for (i = 0; i < ARRAY_SIZE(key_maps); i++) {
60 if (key_maps[i]) { 60 if (key_maps[i]) {
diff --git a/drivers/s390/char/sclp_rw.c b/drivers/s390/char/sclp_rw.c
index ac10dfb20a62..91e93c78f57a 100644
--- a/drivers/s390/char/sclp_rw.c
+++ b/drivers/s390/char/sclp_rw.c
@@ -24,7 +24,7 @@
24 24
25/* 25/*
26 * The room for the SCCB (only for writing) is not equal to a pages size 26 * The room for the SCCB (only for writing) is not equal to a pages size
27 * (as it is specified as the maximum size in the the SCLP ducumentation) 27 * (as it is specified as the maximum size in the the SCLP documentation)
28 * because of the additional data structure described above. 28 * because of the additional data structure described above.
29 */ 29 */
30#define MAX_SCCB_ROOM (PAGE_SIZE - sizeof(struct sclp_buffer)) 30#define MAX_SCCB_ROOM (PAGE_SIZE - sizeof(struct sclp_buffer))
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index 5ced2725d6c7..b70d92690242 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -198,9 +198,7 @@ tapeblock_request_fn(request_queue_t *queue)
198 198
199 device = (struct tape_device *) queue->queuedata; 199 device = (struct tape_device *) queue->queuedata;
200 DBF_LH(6, "tapeblock_request_fn(device=%p)\n", device); 200 DBF_LH(6, "tapeblock_request_fn(device=%p)\n", device);
201 if (device == NULL) 201 BUG_ON(device == NULL);
202 BUG();
203
204 tapeblock_trigger_requeue(device); 202 tapeblock_trigger_requeue(device);
205} 203}
206 204
@@ -307,8 +305,7 @@ tapeblock_revalidate_disk(struct gendisk *disk)
307 int rc; 305 int rc;
308 306
309 device = (struct tape_device *) disk->private_data; 307 device = (struct tape_device *) disk->private_data;
310 if (!device) 308 BUG_ON(!device);
311 BUG();
312 309
313 if (!device->blk_data.medium_changed) 310 if (!device->blk_data.medium_changed)
314 return 0; 311 return 0;
@@ -435,16 +432,14 @@ tapeblock_ioctl(
435) { 432) {
436 int rc; 433 int rc;
437 int minor; 434 int minor;
438 struct gendisk *disk = inode->i_bdev->bd_disk; 435 struct gendisk *disk;
439 struct tape_device *device = disk->private_data; 436 struct tape_device *device;
440 437
441 rc = 0; 438 rc = 0;
442 disk = inode->i_bdev->bd_disk; 439 disk = inode->i_bdev->bd_disk;
443 if (!disk) 440 BUG_ON(!disk);
444 BUG();
445 device = disk->private_data; 441 device = disk->private_data;
446 if (!device) 442 BUG_ON(!device);
447 BUG();
448 minor = iminor(inode); 443 minor = iminor(inode);
449 444
450 DBF_LH(6, "tapeblock_ioctl(0x%0x)\n", command); 445 DBF_LH(6, "tapeblock_ioctl(0x%0x)\n", command);
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 389ee2c0f443..e6e4086d3224 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -210,18 +210,14 @@ tape_state_set(struct tape_device *device, enum tape_state newstate)
210 return; 210 return;
211 } 211 }
212 DBF_EVENT(4, "ts. dev: %x\n", device->first_minor); 212 DBF_EVENT(4, "ts. dev: %x\n", device->first_minor);
213 if (device->tape_state < TO_SIZE && device->tape_state >= 0) 213 DBF_EVENT(4, "old ts:\t\n");
214 str = tape_state_verbose[device->tape_state]; 214 if (device->tape_state < TS_SIZE && device->tape_state >=0 )
215 else
216 str = "UNKNOWN TS";
217 DBF_EVENT(4, "old ts: %s\n", str);
218 if (device->tape_state < TO_SIZE && device->tape_state >=0 )
219 str = tape_state_verbose[device->tape_state]; 215 str = tape_state_verbose[device->tape_state];
220 else 216 else
221 str = "UNKNOWN TS"; 217 str = "UNKNOWN TS";
222 DBF_EVENT(4, "%s\n", str); 218 DBF_EVENT(4, "%s\n", str);
223 DBF_EVENT(4, "new ts:\t\n"); 219 DBF_EVENT(4, "new ts:\t\n");
224 if (newstate < TO_SIZE && newstate >= 0) 220 if (newstate < TS_SIZE && newstate >= 0)
225 str = tape_state_verbose[newstate]; 221 str = tape_state_verbose[newstate];
226 else 222 else
227 str = "UNKNOWN TS"; 223 str = "UNKNOWN TS";
diff --git a/drivers/s390/cio/blacklist.c b/drivers/s390/cio/blacklist.c
index cb8e2e672b68..0960bef7b199 100644
--- a/drivers/s390/cio/blacklist.c
+++ b/drivers/s390/cio/blacklist.c
@@ -414,11 +414,11 @@ cio_ignore_proc_init (void)
414 entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR, 414 entry = create_proc_entry ("cio_ignore", S_IFREG | S_IRUGO | S_IWUSR,
415 &proc_root); 415 &proc_root);
416 if (!entry) 416 if (!entry)
417 return 0; 417 return -ENOENT;
418 418
419 entry->proc_fops = &cio_ignore_proc_fops; 419 entry->proc_fops = &cio_ignore_proc_fops;
420 420
421 return 1; 421 return 0;
422} 422}
423 423
424__initcall (cio_ignore_proc_init); 424__initcall (cio_ignore_proc_init);
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index cbb86fa5f293..5b20d8c9c025 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -67,7 +67,7 @@ cio_debug_init (void)
67 goto out_unregister; 67 goto out_unregister;
68 debug_register_view (cio_debug_msg_id, &debug_sprintf_view); 68 debug_register_view (cio_debug_msg_id, &debug_sprintf_view);
69 debug_set_level (cio_debug_msg_id, 2); 69 debug_set_level (cio_debug_msg_id, 2);
70 cio_debug_trace_id = debug_register ("cio_trace", 16, 4, 8); 70 cio_debug_trace_id = debug_register ("cio_trace", 16, 4, 16);
71 if (!cio_debug_trace_id) 71 if (!cio_debug_trace_id)
72 goto out_unregister; 72 goto out_unregister;
73 debug_register_view (cio_debug_trace_id, &debug_hex_ascii_view); 73 debug_register_view (cio_debug_trace_id, &debug_hex_ascii_view);
diff --git a/drivers/s390/cio/cio_debug.h b/drivers/s390/cio/cio_debug.h
index 6af8b27d366b..f88844adae1b 100644
--- a/drivers/s390/cio/cio_debug.h
+++ b/drivers/s390/cio/cio_debug.h
@@ -3,6 +3,11 @@
3 3
4#include <asm/debug.h> 4#include <asm/debug.h>
5 5
6/* for use of debug feature */
7extern debug_info_t *cio_debug_msg_id;
8extern debug_info_t *cio_debug_trace_id;
9extern debug_info_t *cio_debug_crw_id;
10
6#define CIO_TRACE_EVENT(imp, txt) do { \ 11#define CIO_TRACE_EVENT(imp, txt) do { \
7 debug_text_event(cio_debug_trace_id, imp, txt); \ 12 debug_text_event(cio_debug_trace_id, imp, txt); \
8 } while (0) 13 } while (0)
@@ -15,18 +20,19 @@
15 debug_sprintf_event(cio_debug_crw_id, imp , ##args); \ 20 debug_sprintf_event(cio_debug_crw_id, imp , ##args); \
16 } while (0) 21 } while (0)
17 22
18#define CIO_HEX_EVENT(imp, args...) do { \ 23static inline void
19 debug_event(cio_debug_trace_id, imp, ##args); \ 24CIO_HEX_EVENT(int level, void *data, int length)
20 } while (0) 25{
26 while (length > 0) {
27 debug_event(cio_debug_trace_id, level, data, length);
28 length -= cio_debug_trace_id->buf_size;
29 data += cio_debug_trace_id->buf_size;
30 }
31}
21 32
22#define CIO_DEBUG(printk_level,event_level,msg...) ({ \ 33#define CIO_DEBUG(printk_level,event_level,msg...) ({ \
23 if (cio_show_msg) printk(printk_level msg); \ 34 if (cio_show_msg) printk(printk_level msg); \
24 CIO_MSG_EVENT (event_level, msg); \ 35 CIO_MSG_EVENT (event_level, msg); \
25}) 36})
26 37
27/* for use of debug feature */
28extern debug_info_t *cio_debug_msg_id;
29extern debug_info_t *cio_debug_trace_id;
30extern debug_info_t *cio_debug_crw_id;
31
32#endif 38#endif
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index edcf05d5d568..5d6b7a57b02f 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -675,9 +675,8 @@ lcs_ready_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
675 int index, rc; 675 int index, rc;
676 676
677 LCS_DBF_TEXT(5, trace, "rdybuff"); 677 LCS_DBF_TEXT(5, trace, "rdybuff");
678 if (buffer->state != BUF_STATE_LOCKED && 678 BUG_ON(buffer->state != BUF_STATE_LOCKED &&
679 buffer->state != BUF_STATE_PROCESSED) 679 buffer->state != BUF_STATE_PROCESSED);
680 BUG();
681 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 680 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
682 buffer->state = BUF_STATE_READY; 681 buffer->state = BUF_STATE_READY;
683 index = buffer - channel->iob; 682 index = buffer - channel->iob;
@@ -701,8 +700,7 @@ __lcs_processed_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
701 int index, prev, next; 700 int index, prev, next;
702 701
703 LCS_DBF_TEXT(5, trace, "prcsbuff"); 702 LCS_DBF_TEXT(5, trace, "prcsbuff");
704 if (buffer->state != BUF_STATE_READY) 703 BUG_ON(buffer->state != BUF_STATE_READY);
705 BUG();
706 buffer->state = BUF_STATE_PROCESSED; 704 buffer->state = BUF_STATE_PROCESSED;
707 index = buffer - channel->iob; 705 index = buffer - channel->iob;
708 prev = (index - 1) & (LCS_NUM_BUFFS - 1); 706 prev = (index - 1) & (LCS_NUM_BUFFS - 1);
@@ -734,9 +732,8 @@ lcs_release_buffer(struct lcs_channel *channel, struct lcs_buffer *buffer)
734 unsigned long flags; 732 unsigned long flags;
735 733
736 LCS_DBF_TEXT(5, trace, "relbuff"); 734 LCS_DBF_TEXT(5, trace, "relbuff");
737 if (buffer->state != BUF_STATE_LOCKED && 735 BUG_ON(buffer->state != BUF_STATE_LOCKED &&
738 buffer->state != BUF_STATE_PROCESSED) 736 buffer->state != BUF_STATE_PROCESSED);
739 BUG();
740 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags); 737 spin_lock_irqsave(get_ccwdev_lock(channel->ccwdev), flags);
741 buffer->state = BUF_STATE_EMPTY; 738 buffer->state = BUF_STATE_EMPTY;
742 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags); 739 spin_unlock_irqrestore(get_ccwdev_lock(channel->ccwdev), flags);
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 0d2b447c50ed..caeb6d246e57 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -65,6 +65,7 @@
65 2.26.02.005 - Fix use_sg == 0 mapping on systems with 4GB or higher. 65 2.26.02.005 - Fix use_sg == 0 mapping on systems with 4GB or higher.
66 2.26.02.006 - Fix 9550SX pchip reset timeout. 66 2.26.02.006 - Fix 9550SX pchip reset timeout.
67 Add big endian support. 67 Add big endian support.
68 2.26.02.007 - Disable local interrupts during kmap/unmap_atomic().
68*/ 69*/
69 70
70#include <linux/module.h> 71#include <linux/module.h>
@@ -88,7 +89,7 @@
88#include "3w-9xxx.h" 89#include "3w-9xxx.h"
89 90
90/* Globals */ 91/* Globals */
91#define TW_DRIVER_VERSION "2.26.02.006" 92#define TW_DRIVER_VERSION "2.26.02.007"
92static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; 93static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT];
93static unsigned int twa_device_extension_count; 94static unsigned int twa_device_extension_count;
94static int twa_major = -1; 95static int twa_major = -1;
@@ -1942,9 +1943,13 @@ static void twa_scsiop_execute_scsi_complete(TW_Device_Extension *tw_dev, int re
1942 } 1943 }
1943 if (tw_dev->srb[request_id]->use_sg == 1) { 1944 if (tw_dev->srb[request_id]->use_sg == 1) {
1944 struct scatterlist *sg = (struct scatterlist *)tw_dev->srb[request_id]->request_buffer; 1945 struct scatterlist *sg = (struct scatterlist *)tw_dev->srb[request_id]->request_buffer;
1945 char *buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1946 char *buf;
1947 unsigned long flags = 0;
1948 local_irq_save(flags);
1949 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1946 memcpy(buf, tw_dev->generic_buffer_virt[request_id], sg->length); 1950 memcpy(buf, tw_dev->generic_buffer_virt[request_id], sg->length);
1947 kunmap_atomic(buf - sg->offset, KM_IRQ0); 1951 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1952 local_irq_restore(flags);
1948 } 1953 }
1949 } 1954 }
1950} /* End twa_scsiop_execute_scsi_complete() */ 1955} /* End twa_scsiop_execute_scsi_complete() */
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 25f678d0780b..e8e41e6eb42a 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1508,10 +1508,12 @@ static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1508 struct scsi_cmnd *cmd = tw_dev->srb[request_id]; 1508 struct scsi_cmnd *cmd = tw_dev->srb[request_id];
1509 void *buf; 1509 void *buf;
1510 unsigned int transfer_len; 1510 unsigned int transfer_len;
1511 unsigned long flags = 0;
1511 1512
1512 if (cmd->use_sg) { 1513 if (cmd->use_sg) {
1513 struct scatterlist *sg = 1514 struct scatterlist *sg =
1514 (struct scatterlist *)cmd->request_buffer; 1515 (struct scatterlist *)cmd->request_buffer;
1516 local_irq_save(flags);
1515 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset; 1517 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1516 transfer_len = min(sg->length, len); 1518 transfer_len = min(sg->length, len);
1517 } else { 1519 } else {
@@ -1526,6 +1528,7 @@ static void tw_transfer_internal(TW_Device_Extension *tw_dev, int request_id,
1526 1528
1527 sg = (struct scatterlist *)cmd->request_buffer; 1529 sg = (struct scatterlist *)cmd->request_buffer;
1528 kunmap_atomic(buf - sg->offset, KM_IRQ0); 1530 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1531 local_irq_restore(flags);
1529 } 1532 }
1530} 1533}
1531 1534
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 4035920ce3d8..3e7302692dbe 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1079,7 +1079,7 @@ config SCSI_SYM53C8XX_DMA_ADDRESSING_MODE
1079 memory using PCI DAC cycles. 1079 memory using PCI DAC cycles.
1080 1080
1081config SCSI_SYM53C8XX_DEFAULT_TAGS 1081config SCSI_SYM53C8XX_DEFAULT_TAGS
1082 int "default tagged command queue depth" 1082 int "Default tagged command queue depth"
1083 depends on SCSI_SYM53C8XX_2 1083 depends on SCSI_SYM53C8XX_2
1084 default "16" 1084 default "16"
1085 help 1085 help
@@ -1090,7 +1090,7 @@ config SCSI_SYM53C8XX_DEFAULT_TAGS
1090 exceed CONFIG_SCSI_SYM53C8XX_MAX_TAGS. 1090 exceed CONFIG_SCSI_SYM53C8XX_MAX_TAGS.
1091 1091
1092config SCSI_SYM53C8XX_MAX_TAGS 1092config SCSI_SYM53C8XX_MAX_TAGS
1093 int "maximum number of queued commands" 1093 int "Maximum number of queued commands"
1094 depends on SCSI_SYM53C8XX_2 1094 depends on SCSI_SYM53C8XX_2
1095 default "64" 1095 default "64"
1096 help 1096 help
@@ -1099,13 +1099,14 @@ config SCSI_SYM53C8XX_MAX_TAGS
1099 possible. The driver supports up to 256 queued commands per device. 1099 possible. The driver supports up to 256 queued commands per device.
1100 This value is used as a compiled-in hard limit. 1100 This value is used as a compiled-in hard limit.
1101 1101
1102config SCSI_SYM53C8XX_IOMAPPED 1102config SCSI_SYM53C8XX_MMIO
1103 bool "use port IO" 1103 bool "Use memory mapped IO"
1104 depends on SCSI_SYM53C8XX_2 1104 depends on SCSI_SYM53C8XX_2
1105 default y
1105 help 1106 help
1106 If you say Y here, the driver will use port IO to access 1107 Memory mapped IO is faster than Port IO. Most people should
1107 the card. This is significantly slower then using memory 1108 answer Y here, but some machines may have problems. If you have
1108 mapped IO. Most people should answer N. 1109 to answer N here, please report the problem to the maintainer.
1109 1110
1110config SCSI_IPR 1111config SCSI_IPR
1111 tristate "IBM Power Linux RAID adapter support" 1112 tristate "IBM Power Linux RAID adapter support"
@@ -1309,15 +1310,6 @@ config SCSI_QLOGIC_FAS
1309 To compile this driver as a module, choose M here: the 1310 To compile this driver as a module, choose M here: the
1310 module will be called qlogicfas. 1311 module will be called qlogicfas.
1311 1312
1312config SCSI_QLOGIC_FC
1313 tristate "Qlogic ISP FC SCSI support"
1314 depends on PCI && SCSI
1315 help
1316 This is a driver for the QLogic ISP2100 SCSI-FCP host adapter.
1317
1318 To compile this driver as a module, choose M here: the
1319 module will be called qlogicfc.
1320
1321config SCSI_QLOGIC_FC_FIRMWARE 1313config SCSI_QLOGIC_FC_FIRMWARE
1322 bool "Include loadable firmware in driver" 1314 bool "Include loadable firmware in driver"
1323 depends on SCSI_QLOGIC_FC 1315 depends on SCSI_QLOGIC_FC
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index e513c3158ad9..81803a16f986 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -78,7 +78,6 @@ obj-$(CONFIG_SCSI_NCR_Q720) += NCR_Q720_mod.o
78obj-$(CONFIG_SCSI_SYM53C416) += sym53c416.o 78obj-$(CONFIG_SCSI_SYM53C416) += sym53c416.o
79obj-$(CONFIG_SCSI_QLOGIC_FAS) += qlogicfas408.o qlogicfas.o 79obj-$(CONFIG_SCSI_QLOGIC_FAS) += qlogicfas408.o qlogicfas.o
80obj-$(CONFIG_PCMCIA_QLOGIC) += qlogicfas408.o 80obj-$(CONFIG_PCMCIA_QLOGIC) += qlogicfas408.o
81obj-$(CONFIG_SCSI_QLOGIC_FC) += qlogicfc.o
82obj-$(CONFIG_SCSI_QLOGIC_1280) += qla1280.o 81obj-$(CONFIG_SCSI_QLOGIC_1280) += qla1280.o
83obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx/ 82obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx/
84obj-$(CONFIG_SCSI_LPFC) += lpfc/ 83obj-$(CONFIG_SCSI_LPFC) += lpfc/
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 8df4a0ea3761..642a3b4e5937 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -149,20 +149,20 @@ static int dacmode = -1;
149 149
150static int commit = -1; 150static int commit = -1;
151 151
152module_param(nondasd, int, 0); 152module_param(nondasd, int, S_IRUGO|S_IWUSR);
153MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on"); 153MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices. 0=off, 1=on");
154module_param(dacmode, int, 0); 154module_param(dacmode, int, S_IRUGO|S_IWUSR);
155MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on"); 155MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC. 0=off, 1=on");
156module_param(commit, int, 0); 156module_param(commit, int, S_IRUGO|S_IWUSR);
157MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on"); 157MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the adapter for foreign arrays.\nThis is typically needed in systems that do not have a BIOS. 0=off, 1=on");
158 158
159int numacb = -1; 159int numacb = -1;
160module_param(numacb, int, S_IRUGO|S_IWUSR); 160module_param(numacb, int, S_IRUGO|S_IWUSR);
161MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid\nvalues are 512 and down. Default is to use suggestion from Firmware."); 161MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control blocks (FIB) allocated. Valid values are 512 and down. Default is to use suggestion from Firmware.");
162 162
163int acbsize = -1; 163int acbsize = -1;
164module_param(acbsize, int, S_IRUGO|S_IWUSR); 164module_param(acbsize, int, S_IRUGO|S_IWUSR);
165MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512,\n2048, 4096 and 8192. Default is to use suggestion from Firmware."); 165MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
166/** 166/**
167 * aac_get_config_status - check the adapter configuration 167 * aac_get_config_status - check the adapter configuration
168 * @common: adapter to query 168 * @common: adapter to query
@@ -387,6 +387,7 @@ static void get_container_name_callback(void *context, struct fib * fibptr)
387 struct scsi_cmnd * scsicmd; 387 struct scsi_cmnd * scsicmd;
388 388
389 scsicmd = (struct scsi_cmnd *) context; 389 scsicmd = (struct scsi_cmnd *) context;
390 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
390 391
391 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies)); 392 dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
392 if (fibptr == NULL) 393 if (fibptr == NULL)
@@ -453,8 +454,10 @@ static int aac_get_container_name(struct scsi_cmnd * scsicmd, int cid)
453 /* 454 /*
454 * Check that the command queued to the controller 455 * Check that the command queued to the controller
455 */ 456 */
456 if (status == -EINPROGRESS) 457 if (status == -EINPROGRESS) {
458 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
457 return 0; 459 return 0;
460 }
458 461
459 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status); 462 printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
460 aac_fib_complete(cmd_fibcontext); 463 aac_fib_complete(cmd_fibcontext);
@@ -907,9 +910,10 @@ static void io_callback(void *context, struct fib * fibptr)
907 u32 cid; 910 u32 cid;
908 911
909 scsicmd = (struct scsi_cmnd *) context; 912 scsicmd = (struct scsi_cmnd *) context;
913 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
910 914
911 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 915 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
912 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun); 916 cid = scmd_id(scsicmd);
913 917
914 if (nblank(dprintk(x))) { 918 if (nblank(dprintk(x))) {
915 u64 lba; 919 u64 lba;
@@ -1151,8 +1155,10 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1151 /* 1155 /*
1152 * Check that the command queued to the controller 1156 * Check that the command queued to the controller
1153 */ 1157 */
1154 if (status == -EINPROGRESS) 1158 if (status == -EINPROGRESS) {
1159 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1155 return 0; 1160 return 0;
1161 }
1156 1162
1157 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status); 1163 printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
1158 /* 1164 /*
@@ -1318,8 +1324,8 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1318 /* 1324 /*
1319 * Check that the command queued to the controller 1325 * Check that the command queued to the controller
1320 */ 1326 */
1321 if (status == -EINPROGRESS) 1327 if (status == -EINPROGRESS) {
1322 { 1328 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1323 return 0; 1329 return 0;
1324 } 1330 }
1325 1331
@@ -1341,6 +1347,7 @@ static void synchronize_callback(void *context, struct fib *fibptr)
1341 struct scsi_cmnd *cmd; 1347 struct scsi_cmnd *cmd;
1342 1348
1343 cmd = context; 1349 cmd = context;
1350 cmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1344 1351
1345 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n", 1352 dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
1346 smp_processor_id(), jiffies)); 1353 smp_processor_id(), jiffies));
@@ -1354,7 +1361,7 @@ static void synchronize_callback(void *context, struct fib *fibptr)
1354 else { 1361 else {
1355 struct scsi_device *sdev = cmd->device; 1362 struct scsi_device *sdev = cmd->device;
1356 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata; 1363 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
1357 u32 cid = ID_LUN_TO_CONTAINER(sdev->id, sdev->lun); 1364 u32 cid = sdev_id(sdev);
1358 printk(KERN_WARNING 1365 printk(KERN_WARNING
1359 "synchronize_callback: synchronize failed, status = %d\n", 1366 "synchronize_callback: synchronize failed, status = %d\n",
1360 le32_to_cpu(synchronizereply->status)); 1367 le32_to_cpu(synchronizereply->status));
@@ -1386,12 +1393,12 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1386 unsigned long flags; 1393 unsigned long flags;
1387 1394
1388 /* 1395 /*
1389 * Wait for all commands to complete to this specific 1396 * Wait for all outstanding queued commands to complete to this
1390 * target (block). 1397 * specific target (block).
1391 */ 1398 */
1392 spin_lock_irqsave(&sdev->list_lock, flags); 1399 spin_lock_irqsave(&sdev->list_lock, flags);
1393 list_for_each_entry(cmd, &sdev->cmd_list, list) 1400 list_for_each_entry(cmd, &sdev->cmd_list, list)
1394 if (cmd != scsicmd && cmd->serial_number != 0) { 1401 if (cmd != scsicmd && cmd->SCp.phase == AAC_OWNER_FIRMWARE) {
1395 ++active; 1402 ++active;
1396 break; 1403 break;
1397 } 1404 }
@@ -1434,8 +1441,10 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd, int cid)
1434 /* 1441 /*
1435 * Check that the command queued to the controller 1442 * Check that the command queued to the controller
1436 */ 1443 */
1437 if (status == -EINPROGRESS) 1444 if (status == -EINPROGRESS) {
1445 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
1438 return 0; 1446 return 0;
1447 }
1439 1448
1440 printk(KERN_WARNING 1449 printk(KERN_WARNING
1441 "aac_synchronize: aac_fib_send failed with status: %d.\n", status); 1450 "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
@@ -1458,7 +1467,6 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1458 struct Scsi_Host *host = scsicmd->device->host; 1467 struct Scsi_Host *host = scsicmd->device->host;
1459 struct aac_dev *dev = (struct aac_dev *)host->hostdata; 1468 struct aac_dev *dev = (struct aac_dev *)host->hostdata;
1460 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev; 1469 struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
1461 int ret;
1462 1470
1463 /* 1471 /*
1464 * If the bus, id or lun is out of range, return fail 1472 * If the bus, id or lun is out of range, return fail
@@ -1466,13 +1474,14 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1466 * itself. 1474 * itself.
1467 */ 1475 */
1468 if (scmd_id(scsicmd) != host->this_id) { 1476 if (scmd_id(scsicmd) != host->this_id) {
1469 if ((scsicmd->device->channel == CONTAINER_CHANNEL)) { 1477 if ((scmd_channel(scsicmd) == CONTAINER_CHANNEL)) {
1470 if( (scsicmd->device->id >= dev->maximum_num_containers) || (scsicmd->device->lun != 0)){ 1478 if((scmd_id(scsicmd) >= dev->maximum_num_containers) ||
1479 (scsicmd->device->lun != 0)) {
1471 scsicmd->result = DID_NO_CONNECT << 16; 1480 scsicmd->result = DID_NO_CONNECT << 16;
1472 scsicmd->scsi_done(scsicmd); 1481 scsicmd->scsi_done(scsicmd);
1473 return 0; 1482 return 0;
1474 } 1483 }
1475 cid = ID_LUN_TO_CONTAINER(scsicmd->device->id, scsicmd->device->lun); 1484 cid = scmd_id(scsicmd);
1476 1485
1477 /* 1486 /*
1478 * If the target container doesn't exist, it may have 1487 * If the target container doesn't exist, it may have
@@ -1548,7 +1557,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1548 { 1557 {
1549 struct inquiry_data inq_data; 1558 struct inquiry_data inq_data;
1550 1559
1551 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scsicmd->device->id)); 1560 dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", scmd_id(scsicmd)));
1552 memset(&inq_data, 0, sizeof (struct inquiry_data)); 1561 memset(&inq_data, 0, sizeof (struct inquiry_data));
1553 1562
1554 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */ 1563 inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
@@ -1598,13 +1607,14 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1598 cp[11] = 0; 1607 cp[11] = 0;
1599 cp[12] = 0; 1608 cp[12] = 0;
1600 aac_internal_transfer(scsicmd, cp, 0, 1609 aac_internal_transfer(scsicmd, cp, 0,
1601 min((unsigned int)scsicmd->cmnd[13], sizeof(cp))); 1610 min_t(size_t, scsicmd->cmnd[13], sizeof(cp)));
1602 if (sizeof(cp) < scsicmd->cmnd[13]) { 1611 if (sizeof(cp) < scsicmd->cmnd[13]) {
1603 unsigned int len, offset = sizeof(cp); 1612 unsigned int len, offset = sizeof(cp);
1604 1613
1605 memset(cp, 0, offset); 1614 memset(cp, 0, offset);
1606 do { 1615 do {
1607 len = min(scsicmd->cmnd[13]-offset, sizeof(cp)); 1616 len = min_t(size_t, scsicmd->cmnd[13] - offset,
1617 sizeof(cp));
1608 aac_internal_transfer(scsicmd, cp, offset, len); 1618 aac_internal_transfer(scsicmd, cp, offset, len);
1609 } while ((offset += len) < scsicmd->cmnd[13]); 1619 } while ((offset += len) < scsicmd->cmnd[13]);
1610 } 1620 }
@@ -1728,24 +1738,19 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
1728 * containers to /dev/sd device names 1738 * containers to /dev/sd device names
1729 */ 1739 */
1730 1740
1731 spin_unlock_irq(host->host_lock);
1732 if (scsicmd->request->rq_disk) 1741 if (scsicmd->request->rq_disk)
1733 strlcpy(fsa_dev_ptr[cid].devname, 1742 strlcpy(fsa_dev_ptr[cid].devname,
1734 scsicmd->request->rq_disk->disk_name, 1743 scsicmd->request->rq_disk->disk_name,
1735 min(sizeof(fsa_dev_ptr[cid].devname), 1744 min(sizeof(fsa_dev_ptr[cid].devname),
1736 sizeof(scsicmd->request->rq_disk->disk_name) + 1)); 1745 sizeof(scsicmd->request->rq_disk->disk_name) + 1));
1737 ret = aac_read(scsicmd, cid); 1746
1738 spin_lock_irq(host->host_lock); 1747 return aac_read(scsicmd, cid);
1739 return ret;
1740 1748
1741 case WRITE_6: 1749 case WRITE_6:
1742 case WRITE_10: 1750 case WRITE_10:
1743 case WRITE_12: 1751 case WRITE_12:
1744 case WRITE_16: 1752 case WRITE_16:
1745 spin_unlock_irq(host->host_lock); 1753 return aac_write(scsicmd, cid);
1746 ret = aac_write(scsicmd, cid);
1747 spin_lock_irq(host->host_lock);
1748 return ret;
1749 1754
1750 case SYNCHRONIZE_CACHE: 1755 case SYNCHRONIZE_CACHE:
1751 /* Issue FIB to tell Firmware to flush it's cache */ 1756 /* Issue FIB to tell Firmware to flush it's cache */
@@ -1778,7 +1783,7 @@ static int query_disk(struct aac_dev *dev, void __user *arg)
1778 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk))) 1783 if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
1779 return -EFAULT; 1784 return -EFAULT;
1780 if (qd.cnum == -1) 1785 if (qd.cnum == -1)
1781 qd.cnum = ID_LUN_TO_CONTAINER(qd.id, qd.lun); 1786 qd.cnum = qd.id;
1782 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) 1787 else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1))
1783 { 1788 {
1784 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers) 1789 if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
@@ -1890,6 +1895,7 @@ static void aac_srb_callback(void *context, struct fib * fibptr)
1890 struct scsi_cmnd *scsicmd; 1895 struct scsi_cmnd *scsicmd;
1891 1896
1892 scsicmd = (struct scsi_cmnd *) context; 1897 scsicmd = (struct scsi_cmnd *) context;
1898 scsicmd->SCp.phase = AAC_OWNER_MIDLEVEL;
1893 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 1899 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
1894 1900
1895 if (fibptr == NULL) 1901 if (fibptr == NULL)
@@ -2068,14 +2074,13 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2068 u32 timeout; 2074 u32 timeout;
2069 2075
2070 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 2076 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2071 if (scsicmd->device->id >= dev->maximum_num_physicals || 2077 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
2072 scsicmd->device->lun > 7) { 2078 scsicmd->device->lun > 7) {
2073 scsicmd->result = DID_NO_CONNECT << 16; 2079 scsicmd->result = DID_NO_CONNECT << 16;
2074 scsicmd->scsi_done(scsicmd); 2080 scsicmd->scsi_done(scsicmd);
2075 return 0; 2081 return 0;
2076 } 2082 }
2077 2083
2078 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2079 switch(scsicmd->sc_data_direction){ 2084 switch(scsicmd->sc_data_direction){
2080 case DMA_TO_DEVICE: 2085 case DMA_TO_DEVICE:
2081 flag = SRB_DataOut; 2086 flag = SRB_DataOut;
@@ -2103,8 +2108,8 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2103 2108
2104 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext); 2109 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
2105 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi); 2110 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2106 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scsicmd->device->channel)); 2111 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(scsicmd)));
2107 srbcmd->id = cpu_to_le32(scsicmd->device->id); 2112 srbcmd->id = cpu_to_le32(scmd_id(scsicmd));
2108 srbcmd->lun = cpu_to_le32(scsicmd->device->lun); 2113 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
2109 srbcmd->flags = cpu_to_le32(flag); 2114 srbcmd->flags = cpu_to_le32(flag);
2110 timeout = scsicmd->timeout_per_command/HZ; 2115 timeout = scsicmd->timeout_per_command/HZ;
@@ -2161,7 +2166,8 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2161 /* 2166 /*
2162 * Check that the command queued to the controller 2167 * Check that the command queued to the controller
2163 */ 2168 */
2164 if (status == -EINPROGRESS){ 2169 if (status == -EINPROGRESS) {
2170 scsicmd->SCp.phase = AAC_OWNER_FIRMWARE;
2165 return 0; 2171 return 0;
2166 } 2172 }
2167 2173
@@ -2192,8 +2198,6 @@ static unsigned long aac_build_sg(struct scsi_cmnd* scsicmd, struct sgmap* psg)
2192 scsicmd->sc_data_direction); 2198 scsicmd->sc_data_direction);
2193 psg->count = cpu_to_le32(sg_count); 2199 psg->count = cpu_to_le32(sg_count);
2194 2200
2195 byte_count = 0;
2196
2197 for (i = 0; i < sg_count; i++) { 2201 for (i = 0; i < sg_count; i++) {
2198 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg)); 2202 psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
2199 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg)); 2203 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
@@ -2249,18 +2253,17 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
2249 2253
2250 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg, 2254 sg_count = pci_map_sg(dev->pdev, sg, scsicmd->use_sg,
2251 scsicmd->sc_data_direction); 2255 scsicmd->sc_data_direction);
2252 psg->count = cpu_to_le32(sg_count);
2253
2254 byte_count = 0;
2255 2256
2256 for (i = 0; i < sg_count; i++) { 2257 for (i = 0; i < sg_count; i++) {
2258 int count = sg_dma_len(sg);
2257 addr = sg_dma_address(sg); 2259 addr = sg_dma_address(sg);
2258 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff); 2260 psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
2259 psg->sg[i].addr[1] = cpu_to_le32(addr>>32); 2261 psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
2260 psg->sg[i].count = cpu_to_le32(sg_dma_len(sg)); 2262 psg->sg[i].count = cpu_to_le32(count);
2261 byte_count += sg_dma_len(sg); 2263 byte_count += count;
2262 sg++; 2264 sg++;
2263 } 2265 }
2266 psg->count = cpu_to_le32(sg_count);
2264 /* hba wants the size to be exact */ 2267 /* hba wants the size to be exact */
2265 if(byte_count > scsicmd->request_bufflen){ 2268 if(byte_count > scsicmd->request_bufflen){
2266 u32 temp = le32_to_cpu(psg->sg[i-1].count) - 2269 u32 temp = le32_to_cpu(psg->sg[i-1].count) -
@@ -2275,16 +2278,15 @@ static unsigned long aac_build_sg64(struct scsi_cmnd* scsicmd, struct sgmap64* p
2275 } 2278 }
2276 } 2279 }
2277 else if(scsicmd->request_bufflen) { 2280 else if(scsicmd->request_bufflen) {
2278 u64 addr; 2281 scsicmd->SCp.dma_handle = pci_map_single(dev->pdev,
2279 addr = pci_map_single(dev->pdev,
2280 scsicmd->request_buffer, 2282 scsicmd->request_buffer,
2281 scsicmd->request_bufflen, 2283 scsicmd->request_bufflen,
2282 scsicmd->sc_data_direction); 2284 scsicmd->sc_data_direction);
2285 addr = scsicmd->SCp.dma_handle;
2283 psg->count = cpu_to_le32(1); 2286 psg->count = cpu_to_le32(1);
2284 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff); 2287 psg->sg[0].addr[0] = cpu_to_le32(addr & 0xffffffff);
2285 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32); 2288 psg->sg[0].addr[1] = cpu_to_le32(addr >> 32);
2286 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen); 2289 psg->sg[0].count = cpu_to_le32(scsicmd->request_bufflen);
2287 scsicmd->SCp.dma_handle = addr;
2288 byte_count = scsicmd->request_bufflen; 2290 byte_count = scsicmd->request_bufflen;
2289 } 2291 }
2290 return byte_count; 2292 return byte_count;
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 9ce7002bd070..f773b0dcfc95 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -10,6 +10,10 @@
10 * D E F I N E S 10 * D E F I N E S
11 *----------------------------------------------------------------------------*/ 11 *----------------------------------------------------------------------------*/
12 12
13#ifndef AAC_DRIVER_BUILD
14# define AAC_DRIVER_BUILD 2409
15# define AAC_DRIVER_BRANCH "-mh1"
16#endif
13#define MAXIMUM_NUM_CONTAINERS 32 17#define MAXIMUM_NUM_CONTAINERS 32
14 18
15#define AAC_NUM_MGT_FIB 8 19#define AAC_NUM_MGT_FIB 8
@@ -25,7 +29,6 @@
25 * These macros convert from physical channels to virtual channels 29 * These macros convert from physical channels to virtual channels
26 */ 30 */
27#define CONTAINER_CHANNEL (0) 31#define CONTAINER_CHANNEL (0)
28#define ID_LUN_TO_CONTAINER(id, lun) (id)
29#define CONTAINER_TO_CHANNEL(cont) (CONTAINER_CHANNEL) 32#define CONTAINER_TO_CHANNEL(cont) (CONTAINER_CHANNEL)
30#define CONTAINER_TO_ID(cont) (cont) 33#define CONTAINER_TO_ID(cont) (cont)
31#define CONTAINER_TO_LUN(cont) (0) 34#define CONTAINER_TO_LUN(cont) (0)
@@ -789,6 +792,7 @@ struct fsa_dev_info {
789 u64 size; 792 u64 size;
790 u32 type; 793 u32 type;
791 u32 config_waiting_on; 794 u32 config_waiting_on;
795 unsigned long config_waiting_stamp;
792 u16 queue_depth; 796 u16 queue_depth;
793 u8 config_needed; 797 u8 config_needed;
794 u8 valid; 798 u8 valid;
@@ -1771,6 +1775,11 @@ static inline u32 cap_to_cyls(sector_t capacity, u32 divisor)
1771} 1775}
1772 1776
1773struct scsi_cmnd; 1777struct scsi_cmnd;
1778/* SCp.phase values */
1779#define AAC_OWNER_MIDLEVEL 0x101
1780#define AAC_OWNER_LOWLEVEL 0x102
1781#define AAC_OWNER_ERROR_HANDLER 0x103
1782#define AAC_OWNER_FIRMWARE 0x106
1774 1783
1775const char *aac_driverinfo(struct Scsi_Host *); 1784const char *aac_driverinfo(struct Scsi_Host *);
1776struct fib *aac_fib_alloc(struct aac_dev *dev); 1785struct fib *aac_fib_alloc(struct aac_dev *dev);
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index 47fefca72695..9f75144e5247 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -38,6 +38,8 @@
38#include <linux/completion.h> 38#include <linux/completion.h>
39#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
40#include <linux/blkdev.h> 40#include <linux/blkdev.h>
41#include <linux/delay.h>
42#include <linux/kthread.h>
41#include <asm/semaphore.h> 43#include <asm/semaphore.h>
42#include <asm/uaccess.h> 44#include <asm/uaccess.h>
43 45
@@ -293,6 +295,16 @@ return_fib:
293 status = 0; 295 status = 0;
294 } else { 296 } else {
295 spin_unlock_irqrestore(&dev->fib_lock, flags); 297 spin_unlock_irqrestore(&dev->fib_lock, flags);
298 /* If someone killed the AIF aacraid thread, restart it */
299 status = !dev->aif_thread;
300 if (status && dev->queues && dev->fsa_dev) {
301 /* Be paranoid, be very paranoid! */
302 kthread_stop(dev->thread);
303 ssleep(1);
304 dev->aif_thread = 0;
305 dev->thread = kthread_run(aac_command_thread, dev, dev->name);
306 ssleep(1);
307 }
296 if (f.wait) { 308 if (f.wait) {
297 if(down_interruptible(&fibctx->wait_sem) < 0) { 309 if(down_interruptible(&fibctx->wait_sem) < 0) {
298 status = -EINTR; 310 status = -EINTR;
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index c7f80ec7abde..9f9f4aae23c0 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -767,9 +767,9 @@ void aac_printf(struct aac_dev *dev, u32 val)
767 if (cp[length] != 0) 767 if (cp[length] != 0)
768 cp[length] = 0; 768 cp[length] = 0;
769 if (level == LOG_AAC_HIGH_ERROR) 769 if (level == LOG_AAC_HIGH_ERROR)
770 printk(KERN_WARNING "aacraid:%s", cp); 770 printk(KERN_WARNING "%s:%s", dev->name, cp);
771 else 771 else
772 printk(KERN_INFO "aacraid:%s", cp); 772 printk(KERN_INFO "%s:%s", dev->name, cp);
773 } 773 }
774 memset(cp, 0, 256); 774 memset(cp, 0, 256);
775} 775}
@@ -784,6 +784,7 @@ void aac_printf(struct aac_dev *dev, u32 val)
784 * dispatches it to the appropriate routine for handling. 784 * dispatches it to the appropriate routine for handling.
785 */ 785 */
786 786
787#define AIF_SNIFF_TIMEOUT (30*HZ)
787static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr) 788static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
788{ 789{
789 struct hw_fib * hw_fib = fibptr->hw_fib; 790 struct hw_fib * hw_fib = fibptr->hw_fib;
@@ -837,6 +838,7 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
837 if (device) { 838 if (device) {
838 dev->fsa_dev[container].config_needed = CHANGE; 839 dev->fsa_dev[container].config_needed = CHANGE;
839 dev->fsa_dev[container].config_waiting_on = AifEnConfigChange; 840 dev->fsa_dev[container].config_waiting_on = AifEnConfigChange;
841 dev->fsa_dev[container].config_waiting_stamp = jiffies;
840 scsi_device_put(device); 842 scsi_device_put(device);
841 } 843 }
842 } 844 }
@@ -849,13 +851,15 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
849 if (container != (u32)-1) { 851 if (container != (u32)-1) {
850 if (container >= dev->maximum_num_containers) 852 if (container >= dev->maximum_num_containers)
851 break; 853 break;
852 if (dev->fsa_dev[container].config_waiting_on == 854 if ((dev->fsa_dev[container].config_waiting_on ==
853 le32_to_cpu(*(u32 *)aifcmd->data)) 855 le32_to_cpu(*(u32 *)aifcmd->data)) &&
856 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
854 dev->fsa_dev[container].config_waiting_on = 0; 857 dev->fsa_dev[container].config_waiting_on = 0;
855 } else for (container = 0; 858 } else for (container = 0;
856 container < dev->maximum_num_containers; ++container) { 859 container < dev->maximum_num_containers; ++container) {
857 if (dev->fsa_dev[container].config_waiting_on == 860 if ((dev->fsa_dev[container].config_waiting_on ==
858 le32_to_cpu(*(u32 *)aifcmd->data)) 861 le32_to_cpu(*(u32 *)aifcmd->data)) &&
862 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
859 dev->fsa_dev[container].config_waiting_on = 0; 863 dev->fsa_dev[container].config_waiting_on = 0;
860 } 864 }
861 break; 865 break;
@@ -872,6 +876,7 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
872 dev->fsa_dev[container].config_needed = ADD; 876 dev->fsa_dev[container].config_needed = ADD;
873 dev->fsa_dev[container].config_waiting_on = 877 dev->fsa_dev[container].config_waiting_on =
874 AifEnConfigChange; 878 AifEnConfigChange;
879 dev->fsa_dev[container].config_waiting_stamp = jiffies;
875 break; 880 break;
876 881
877 /* 882 /*
@@ -884,6 +889,7 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
884 dev->fsa_dev[container].config_needed = DELETE; 889 dev->fsa_dev[container].config_needed = DELETE;
885 dev->fsa_dev[container].config_waiting_on = 890 dev->fsa_dev[container].config_waiting_on =
886 AifEnConfigChange; 891 AifEnConfigChange;
892 dev->fsa_dev[container].config_waiting_stamp = jiffies;
887 break; 893 break;
888 894
889 /* 895 /*
@@ -894,11 +900,13 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
894 container = le32_to_cpu(((u32 *)aifcmd->data)[1]); 900 container = le32_to_cpu(((u32 *)aifcmd->data)[1]);
895 if (container >= dev->maximum_num_containers) 901 if (container >= dev->maximum_num_containers)
896 break; 902 break;
897 if (dev->fsa_dev[container].config_waiting_on) 903 if (dev->fsa_dev[container].config_waiting_on &&
904 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
898 break; 905 break;
899 dev->fsa_dev[container].config_needed = CHANGE; 906 dev->fsa_dev[container].config_needed = CHANGE;
900 dev->fsa_dev[container].config_waiting_on = 907 dev->fsa_dev[container].config_waiting_on =
901 AifEnConfigChange; 908 AifEnConfigChange;
909 dev->fsa_dev[container].config_waiting_stamp = jiffies;
902 break; 910 break;
903 911
904 case AifEnConfigChange: 912 case AifEnConfigChange:
@@ -913,13 +921,15 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
913 if (container != (u32)-1) { 921 if (container != (u32)-1) {
914 if (container >= dev->maximum_num_containers) 922 if (container >= dev->maximum_num_containers)
915 break; 923 break;
916 if (dev->fsa_dev[container].config_waiting_on == 924 if ((dev->fsa_dev[container].config_waiting_on ==
917 le32_to_cpu(*(u32 *)aifcmd->data)) 925 le32_to_cpu(*(u32 *)aifcmd->data)) &&
926 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
918 dev->fsa_dev[container].config_waiting_on = 0; 927 dev->fsa_dev[container].config_waiting_on = 0;
919 } else for (container = 0; 928 } else for (container = 0;
920 container < dev->maximum_num_containers; ++container) { 929 container < dev->maximum_num_containers; ++container) {
921 if (dev->fsa_dev[container].config_waiting_on == 930 if ((dev->fsa_dev[container].config_waiting_on ==
922 le32_to_cpu(*(u32 *)aifcmd->data)) 931 le32_to_cpu(*(u32 *)aifcmd->data)) &&
932 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT))
923 dev->fsa_dev[container].config_waiting_on = 0; 933 dev->fsa_dev[container].config_waiting_on = 0;
924 } 934 }
925 break; 935 break;
@@ -946,6 +956,8 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
946 dev->fsa_dev[container].config_waiting_on = 956 dev->fsa_dev[container].config_waiting_on =
947 AifEnContainerChange; 957 AifEnContainerChange;
948 dev->fsa_dev[container].config_needed = ADD; 958 dev->fsa_dev[container].config_needed = ADD;
959 dev->fsa_dev[container].config_waiting_stamp =
960 jiffies;
949 } 961 }
950 } 962 }
951 if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero)) 963 if ((((u32 *)aifcmd->data)[1] == cpu_to_le32(AifJobCtrZero))
@@ -961,6 +973,8 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
961 dev->fsa_dev[container].config_waiting_on = 973 dev->fsa_dev[container].config_waiting_on =
962 AifEnContainerChange; 974 AifEnContainerChange;
963 dev->fsa_dev[container].config_needed = DELETE; 975 dev->fsa_dev[container].config_needed = DELETE;
976 dev->fsa_dev[container].config_waiting_stamp =
977 jiffies;
964 } 978 }
965 } 979 }
966 break; 980 break;
@@ -969,8 +983,9 @@ static void aac_handle_aif(struct aac_dev * dev, struct fib * fibptr)
969 device_config_needed = NOTHING; 983 device_config_needed = NOTHING;
970 for (container = 0; container < dev->maximum_num_containers; 984 for (container = 0; container < dev->maximum_num_containers;
971 ++container) { 985 ++container) {
972 if ((dev->fsa_dev[container].config_waiting_on == 0) 986 if ((dev->fsa_dev[container].config_waiting_on == 0) &&
973 && (dev->fsa_dev[container].config_needed != NOTHING)) { 987 (dev->fsa_dev[container].config_needed != NOTHING) &&
988 time_before(jiffies, dev->fsa_dev[container].config_waiting_stamp + AIF_SNIFF_TIMEOUT)) {
974 device_config_needed = 989 device_config_needed =
975 dev->fsa_dev[container].config_needed; 990 dev->fsa_dev[container].config_needed;
976 dev->fsa_dev[container].config_needed = NOTHING; 991 dev->fsa_dev[container].config_needed = NOTHING;
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 720330778648..6ef89c99dd12 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -27,12 +27,6 @@
27 * Abstract: Linux Driver entry module for Adaptec RAID Array Controller 27 * Abstract: Linux Driver entry module for Adaptec RAID Array Controller
28 */ 28 */
29 29
30#define AAC_DRIVER_VERSION "1.1-4"
31#ifndef AAC_DRIVER_BRANCH
32#define AAC_DRIVER_BRANCH ""
33#endif
34#define AAC_DRIVER_BUILD_DATE __DATE__ " " __TIME__
35#define AAC_DRIVERNAME "aacraid"
36 30
37#include <linux/compat.h> 31#include <linux/compat.h>
38#include <linux/blkdev.h> 32#include <linux/blkdev.h>
@@ -62,6 +56,13 @@
62 56
63#include "aacraid.h" 57#include "aacraid.h"
64 58
59#define AAC_DRIVER_VERSION "1.1-5"
60#ifndef AAC_DRIVER_BRANCH
61#define AAC_DRIVER_BRANCH ""
62#endif
63#define AAC_DRIVER_BUILD_DATE __DATE__ " " __TIME__
64#define AAC_DRIVERNAME "aacraid"
65
65#ifdef AAC_DRIVER_BUILD 66#ifdef AAC_DRIVER_BUILD
66#define _str(x) #x 67#define _str(x) #x
67#define str(x) _str(x) 68#define str(x) _str(x)
@@ -73,7 +74,7 @@
73MODULE_AUTHOR("Red Hat Inc and Adaptec"); 74MODULE_AUTHOR("Red Hat Inc and Adaptec");
74MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, " 75MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
75 "Adaptec Advanced Raid Products, " 76 "Adaptec Advanced Raid Products, "
76 "and HP NetRAID-4M SCSI driver"); 77 "HP NetRAID-4M, IBM ServeRAID & ICP SCSI driver");
77MODULE_LICENSE("GPL"); 78MODULE_LICENSE("GPL");
78MODULE_VERSION(AAC_DRIVER_FULL_VERSION); 79MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
79 80
@@ -243,6 +244,7 @@ static struct aac_driver_ident aac_drivers[] = {
243static int aac_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 244static int aac_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
244{ 245{
245 cmd->scsi_done = done; 246 cmd->scsi_done = done;
247 cmd->SCp.phase = AAC_OWNER_LOWLEVEL;
246 return (aac_scsi_cmd(cmd) ? FAILED : 0); 248 return (aac_scsi_cmd(cmd) ? FAILED : 0);
247} 249}
248 250
@@ -471,7 +473,8 @@ static int aac_eh_reset(struct scsi_cmnd* cmd)
471 __shost_for_each_device(dev, host) { 473 __shost_for_each_device(dev, host) {
472 spin_lock_irqsave(&dev->list_lock, flags); 474 spin_lock_irqsave(&dev->list_lock, flags);
473 list_for_each_entry(command, &dev->cmd_list, list) { 475 list_for_each_entry(command, &dev->cmd_list, list) {
474 if (command->serial_number) { 476 if ((command != cmd) &&
477 (command->SCp.phase == AAC_OWNER_FIRMWARE)) {
475 active++; 478 active++;
476 break; 479 break;
477 } 480 }
@@ -569,12 +572,12 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long
569 572
570 f = compat_alloc_user_space(sizeof(*f)); 573 f = compat_alloc_user_space(sizeof(*f));
571 ret = 0; 574 ret = 0;
572 if (clear_user(f, sizeof(*f) != sizeof(*f))) 575 if (clear_user(f, sizeof(*f)) != sizeof(*f))
573 ret = -EFAULT; 576 ret = -EFAULT;
574 if (copy_in_user(f, (void __user *)arg, sizeof(struct fib_ioctl) - sizeof(u32))) 577 if (copy_in_user(f, (void __user *)arg, sizeof(struct fib_ioctl) - sizeof(u32)))
575 ret = -EFAULT; 578 ret = -EFAULT;
576 if (!ret) 579 if (!ret)
577 ret = aac_do_ioctl(dev, cmd, (void __user *)arg); 580 ret = aac_do_ioctl(dev, cmd, f);
578 break; 581 break;
579 } 582 }
580 583
@@ -687,6 +690,18 @@ static ssize_t aac_show_serial_number(struct class_device *class_dev,
687 return len; 690 return len;
688} 691}
689 692
693static ssize_t aac_show_max_channel(struct class_device *class_dev, char *buf)
694{
695 return snprintf(buf, PAGE_SIZE, "%d\n",
696 class_to_shost(class_dev)->max_channel);
697}
698
699static ssize_t aac_show_max_id(struct class_device *class_dev, char *buf)
700{
701 return snprintf(buf, PAGE_SIZE, "%d\n",
702 class_to_shost(class_dev)->max_id);
703}
704
690 705
691static struct class_device_attribute aac_model = { 706static struct class_device_attribute aac_model = {
692 .attr = { 707 .attr = {
@@ -730,6 +745,20 @@ static struct class_device_attribute aac_serial_number = {
730 }, 745 },
731 .show = aac_show_serial_number, 746 .show = aac_show_serial_number,
732}; 747};
748static struct class_device_attribute aac_max_channel = {
749 .attr = {
750 .name = "max_channel",
751 .mode = S_IRUGO,
752 },
753 .show = aac_show_max_channel,
754};
755static struct class_device_attribute aac_max_id = {
756 .attr = {
757 .name = "max_id",
758 .mode = S_IRUGO,
759 },
760 .show = aac_show_max_id,
761};
733 762
734static struct class_device_attribute *aac_attrs[] = { 763static struct class_device_attribute *aac_attrs[] = {
735 &aac_model, 764 &aac_model,
@@ -738,6 +767,8 @@ static struct class_device_attribute *aac_attrs[] = {
738 &aac_monitor_version, 767 &aac_monitor_version,
739 &aac_bios_version, 768 &aac_bios_version,
740 &aac_serial_number, 769 &aac_serial_number,
770 &aac_max_channel,
771 &aac_max_id,
741 NULL 772 NULL
742}; 773};
743 774
@@ -775,6 +806,7 @@ static struct scsi_host_template aac_driver_template = {
775 .cmd_per_lun = AAC_NUM_IO_FIB, 806 .cmd_per_lun = AAC_NUM_IO_FIB,
776#endif 807#endif
777 .use_clustering = ENABLE_CLUSTERING, 808 .use_clustering = ENABLE_CLUSTERING,
809 .emulated = 1,
778}; 810};
779 811
780 812
@@ -798,10 +830,11 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
798 error = pci_enable_device(pdev); 830 error = pci_enable_device(pdev);
799 if (error) 831 if (error)
800 goto out; 832 goto out;
833 error = -ENODEV;
801 834
802 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) || 835 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) ||
803 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) 836 pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK))
804 goto out; 837 goto out_disable_pdev;
805 /* 838 /*
806 * If the quirk31 bit is set, the adapter needs adapter 839 * If the quirk31 bit is set, the adapter needs adapter
807 * to driver communication memory to be allocated below 2gig 840 * to driver communication memory to be allocated below 2gig
@@ -809,7 +842,7 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
809 if (aac_drivers[index].quirks & AAC_QUIRK_31BIT) 842 if (aac_drivers[index].quirks & AAC_QUIRK_31BIT)
810 if (pci_set_dma_mask(pdev, DMA_31BIT_MASK) || 843 if (pci_set_dma_mask(pdev, DMA_31BIT_MASK) ||
811 pci_set_consistent_dma_mask(pdev, DMA_31BIT_MASK)) 844 pci_set_consistent_dma_mask(pdev, DMA_31BIT_MASK))
812 goto out; 845 goto out_disable_pdev;
813 846
814 pci_set_master(pdev); 847 pci_set_master(pdev);
815 848
@@ -904,9 +937,9 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
904 * physical channels are address by their actual physical number+1 937 * physical channels are address by their actual physical number+1
905 */ 938 */
906 if (aac->nondasd_support == 1) 939 if (aac->nondasd_support == 1)
907 shost->max_channel = aac->maximum_num_channels + 1; 940 shost->max_channel = aac->maximum_num_channels;
908 else 941 else
909 shost->max_channel = 1; 942 shost->max_channel = 0;
910 943
911 aac_get_config_status(aac); 944 aac_get_config_status(aac);
912 aac_get_containers(aac); 945 aac_get_containers(aac);
@@ -1020,7 +1053,8 @@ static int __init aac_init(void)
1020 1053
1021static void __exit aac_exit(void) 1054static void __exit aac_exit(void)
1022{ 1055{
1023 unregister_chrdev(aac_cfg_major, "aac"); 1056 if (aac_cfg_major > -1)
1057 unregister_chrdev(aac_cfg_major, "aac");
1024 pci_unregister_driver(&aac_pci_driver); 1058 pci_unregister_driver(&aac_pci_driver);
1025} 1059}
1026 1060
diff --git a/drivers/scsi/aacraid/rkt.c b/drivers/scsi/aacraid/rkt.c
index e9b775d6bec9..7a23e027eb78 100644
--- a/drivers/scsi/aacraid/rkt.c
+++ b/drivers/scsi/aacraid/rkt.c
@@ -183,7 +183,7 @@ static int rkt_sync_cmd(struct aac_dev *dev, u32 command,
183 /* 183 /*
184 * Yield the processor in case we are slow 184 * Yield the processor in case we are slow
185 */ 185 */
186 schedule_timeout_uninterruptible(1); 186 msleep(1);
187 } 187 }
188 if (ok != 1) { 188 if (ok != 1) {
189 /* 189 /*
@@ -343,7 +343,7 @@ static int aac_rkt_check_health(struct aac_dev *dev)
343 NULL, NULL, NULL, NULL, NULL); 343 NULL, NULL, NULL, NULL, NULL);
344 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), 344 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
345 post, paddr); 345 post, paddr);
346 if ((buffer[0] == '0') && (buffer[1] == 'x')) { 346 if ((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X'))) {
347 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10); 347 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
348 ret <<= 4; 348 ret <<= 4;
349 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10); 349 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index 6998bc877dd6..729b9eb268c2 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -183,7 +183,7 @@ static int rx_sync_cmd(struct aac_dev *dev, u32 command,
183 /* 183 /*
184 * Yield the processor in case we are slow 184 * Yield the processor in case we are slow
185 */ 185 */
186 schedule_timeout_uninterruptible(1); 186 msleep(1);
187 } 187 }
188 if (ok != 1) { 188 if (ok != 1) {
189 /* 189 /*
@@ -342,7 +342,7 @@ static int aac_rx_check_health(struct aac_dev *dev)
342 NULL, NULL, NULL, NULL, NULL); 342 NULL, NULL, NULL, NULL, NULL);
343 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS), 343 pci_free_consistent(dev->pdev, sizeof(struct POSTSTATUS),
344 post, paddr); 344 post, paddr);
345 if ((buffer[0] == '0') && (buffer[1] == 'x')) { 345 if ((buffer[0] == '0') && ((buffer[1] == 'x') || (buffer[1] == 'X'))) {
346 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10); 346 ret = (buffer[2] <= '9') ? (buffer[2] - '0') : (buffer[2] - 'A' + 10);
347 ret <<= 4; 347 ret <<= 4;
348 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10); 348 ret += (buffer[3] <= '9') ? (buffer[3] - '0') : (buffer[3] - 'A' + 10);
diff --git a/drivers/scsi/aacraid/sa.c b/drivers/scsi/aacraid/sa.c
index 466f05cfbf0c..a53454908205 100644
--- a/drivers/scsi/aacraid/sa.c
+++ b/drivers/scsi/aacraid/sa.c
@@ -189,7 +189,7 @@ static int sa_sync_cmd(struct aac_dev *dev, u32 command,
189 ok = 1; 189 ok = 1;
190 break; 190 break;
191 } 191 }
192 schedule_timeout_uninterruptible(1); 192 msleep(1);
193 } 193 }
194 194
195 if (ok != 1) 195 if (ok != 1)
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index ffba65656a83..b4f8fb1d628b 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -207,7 +207,6 @@ static struct scsi_host_template ahci_sht = {
207 .name = DRV_NAME, 207 .name = DRV_NAME,
208 .ioctl = ata_scsi_ioctl, 208 .ioctl = ata_scsi_ioctl,
209 .queuecommand = ata_scsi_queuecmd, 209 .queuecommand = ata_scsi_queuecmd,
210 .eh_strategy_handler = ata_scsi_error,
211 .can_queue = ATA_DEF_QUEUE, 210 .can_queue = ATA_DEF_QUEUE,
212 .this_id = ATA_SHT_THIS_ID, 211 .this_id = ATA_SHT_THIS_ID,
213 .sg_tablesize = AHCI_MAX_SG, 212 .sg_tablesize = AHCI_MAX_SG,
@@ -293,6 +292,10 @@ static const struct pci_device_id ahci_pci_tbl[] = {
293 board_ahci }, /* JMicron JMB360 */ 292 board_ahci }, /* JMicron JMB360 */
294 { 0x197b, 0x2363, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 293 { 0x197b, 0x2363, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
295 board_ahci }, /* JMicron JMB363 */ 294 board_ahci }, /* JMicron JMB363 */
295 { PCI_VENDOR_ID_ATI, 0x4380, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
296 board_ahci }, /* ATI SB600 non-raid */
297 { PCI_VENDOR_ID_ATI, 0x4381, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
298 board_ahci }, /* ATI SB600 raid */
296 { } /* terminate list */ 299 { } /* terminate list */
297}; 300};
298 301
diff --git a/drivers/scsi/aic7xxx/Kconfig.aic7xxx b/drivers/scsi/aic7xxx/Kconfig.aic7xxx
index 6c2c395554ff..5517da5855f0 100644
--- a/drivers/scsi/aic7xxx/Kconfig.aic7xxx
+++ b/drivers/scsi/aic7xxx/Kconfig.aic7xxx
@@ -86,7 +86,7 @@ config AIC7XXX_DEBUG_MASK
86 default "0" 86 default "0"
87 help 87 help
88 Bit mask of debug options that is only valid if the 88 Bit mask of debug options that is only valid if the
89 CONFIG_AIC7XXX_DEBUG_ENBLE option is enabled. The bits in this mask 89 CONFIG_AIC7XXX_DEBUG_ENABLE option is enabled. The bits in this mask
90 are defined in the drivers/scsi/aic7xxx/aic7xxx.h - search for the 90 are defined in the drivers/scsi/aic7xxx/aic7xxx.h - search for the
91 variable ahc_debug in that file to find them. 91 variable ahc_debug in that file to find them.
92 92
diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index 1d11f7e77564..bb5166da4358 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -372,7 +372,7 @@ typedef enum {
372 AHD_CURRENT_SENSING = 0x40000, 372 AHD_CURRENT_SENSING = 0x40000,
373 AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */ 373 AHD_SCB_CONFIG_USED = 0x80000,/* No SEEPROM but SCB had info. */
374 AHD_HP_BOARD = 0x100000, 374 AHD_HP_BOARD = 0x100000,
375 AHD_RESET_POLL_ACTIVE = 0x200000, 375 AHD_BUS_RESET_ACTIVE = 0x200000,
376 AHD_UPDATE_PEND_CMDS = 0x400000, 376 AHD_UPDATE_PEND_CMDS = 0x400000,
377 AHD_RUNNING_QOUTFIFO = 0x800000, 377 AHD_RUNNING_QOUTFIFO = 0x800000,
378 AHD_HAD_FIRST_SEL = 0x1000000 378 AHD_HAD_FIRST_SEL = 0x1000000
@@ -589,7 +589,7 @@ typedef enum {
589 SCB_PACKETIZED = 0x00800, 589 SCB_PACKETIZED = 0x00800,
590 SCB_EXPECT_PPR_BUSFREE = 0x01000, 590 SCB_EXPECT_PPR_BUSFREE = 0x01000,
591 SCB_PKT_SENSE = 0x02000, 591 SCB_PKT_SENSE = 0x02000,
592 SCB_CMDPHASE_ABORT = 0x04000, 592 SCB_EXTERNAL_RESET = 0x04000,/* Device was reset externally */
593 SCB_ON_COL_LIST = 0x08000, 593 SCB_ON_COL_LIST = 0x08000,
594 SCB_SILENT = 0x10000 /* 594 SCB_SILENT = 0x10000 /*
595 * Be quiet about transmission type 595 * Be quiet about transmission type
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 326a62226235..08771f6f6859 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -207,7 +207,6 @@ static void ahd_add_scb_to_free_list(struct ahd_softc *ahd,
207static u_int ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid, 207static u_int ahd_rem_wscb(struct ahd_softc *ahd, u_int scbid,
208 u_int prev, u_int next, u_int tid); 208 u_int prev, u_int next, u_int tid);
209static void ahd_reset_current_bus(struct ahd_softc *ahd); 209static void ahd_reset_current_bus(struct ahd_softc *ahd);
210static ahd_callback_t ahd_reset_poll;
211static ahd_callback_t ahd_stat_timer; 210static ahd_callback_t ahd_stat_timer;
212#ifdef AHD_DUMP_SEQ 211#ifdef AHD_DUMP_SEQ
213static void ahd_dumpseq(struct ahd_softc *ahd); 212static void ahd_dumpseq(struct ahd_softc *ahd);
@@ -1054,12 +1053,10 @@ ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1054 * If a target takes us into the command phase 1053 * If a target takes us into the command phase
1055 * assume that it has been externally reset and 1054 * assume that it has been externally reset and
1056 * has thus lost our previous packetized negotiation 1055 * has thus lost our previous packetized negotiation
1057 * agreement. Since we have not sent an identify 1056 * agreement.
1058 * message and may not have fully qualified the 1057 * Revert to async/narrow transfers until we
1059 * connection, we change our command to TUR, assert 1058 * can renegotiate with the device and notify
1060 * ATN and ABORT the task when we go to message in 1059 * the OSM about the reset.
1061 * phase. The OSM will see the REQUEUE_REQUEST
1062 * status and retry the command.
1063 */ 1060 */
1064 scbid = ahd_get_scbptr(ahd); 1061 scbid = ahd_get_scbptr(ahd);
1065 scb = ahd_lookup_scb(ahd, scbid); 1062 scb = ahd_lookup_scb(ahd, scbid);
@@ -1086,31 +1083,15 @@ ahd_handle_seqint(struct ahd_softc *ahd, u_int intstat)
1086 ahd_set_syncrate(ahd, &devinfo, /*period*/0, 1083 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
1087 /*offset*/0, /*ppr_options*/0, 1084 /*offset*/0, /*ppr_options*/0,
1088 AHD_TRANS_ACTIVE, /*paused*/TRUE); 1085 AHD_TRANS_ACTIVE, /*paused*/TRUE);
1089 ahd_outb(ahd, SCB_CDB_STORE, 0); 1086 scb->flags |= SCB_EXTERNAL_RESET;
1090 ahd_outb(ahd, SCB_CDB_STORE+1, 0);
1091 ahd_outb(ahd, SCB_CDB_STORE+2, 0);
1092 ahd_outb(ahd, SCB_CDB_STORE+3, 0);
1093 ahd_outb(ahd, SCB_CDB_STORE+4, 0);
1094 ahd_outb(ahd, SCB_CDB_STORE+5, 0);
1095 ahd_outb(ahd, SCB_CDB_LEN, 6);
1096 scb->hscb->control &= ~(TAG_ENB|SCB_TAG_TYPE);
1097 scb->hscb->control |= MK_MESSAGE;
1098 ahd_outb(ahd, SCB_CONTROL, scb->hscb->control);
1099 ahd_outb(ahd, MSG_OUT, HOST_MSG);
1100 ahd_outb(ahd, SAVED_SCSIID, scb->hscb->scsiid);
1101 /*
1102 * The lun is 0, regardless of the SCB's lun
1103 * as we have not sent an identify message.
1104 */
1105 ahd_outb(ahd, SAVED_LUN, 0);
1106 ahd_outb(ahd, SEQ_FLAGS, 0);
1107 ahd_assert_atn(ahd);
1108 scb->flags &= ~SCB_PACKETIZED;
1109 scb->flags |= SCB_ABORT|SCB_CMDPHASE_ABORT;
1110 ahd_freeze_devq(ahd, scb); 1087 ahd_freeze_devq(ahd, scb);
1111 ahd_set_transaction_status(scb, CAM_REQUEUE_REQ); 1088 ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
1112 ahd_freeze_scb(scb); 1089 ahd_freeze_scb(scb);
1113 1090
1091 /* Notify XPT */
1092 ahd_send_async(ahd, devinfo.channel, devinfo.target,
1093 CAM_LUN_WILDCARD, AC_SENT_BDR, NULL);
1094
1114 /* 1095 /*
1115 * Allow the sequencer to continue with 1096 * Allow the sequencer to continue with
1116 * non-pack processing. 1097 * non-pack processing.
@@ -1534,6 +1515,18 @@ ahd_handle_scsiint(struct ahd_softc *ahd, u_int intstat)
1534 lqistat1 = ahd_inb(ahd, LQISTAT1); 1515 lqistat1 = ahd_inb(ahd, LQISTAT1);
1535 lqostat0 = ahd_inb(ahd, LQOSTAT0); 1516 lqostat0 = ahd_inb(ahd, LQOSTAT0);
1536 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME; 1517 busfreetime = ahd_inb(ahd, SSTAT2) & BUSFREETIME;
1518
1519 /*
1520 * Ignore external resets after a bus reset.
1521 */
1522 if (((status & SCSIRSTI) != 0) && (ahd->flags & AHD_BUS_RESET_ACTIVE))
1523 return;
1524
1525 /*
1526 * Clear bus reset flag
1527 */
1528 ahd->flags &= ~AHD_BUS_RESET_ACTIVE;
1529
1537 if ((status0 & (SELDI|SELDO)) != 0) { 1530 if ((status0 & (SELDI|SELDO)) != 0) {
1538 u_int simode0; 1531 u_int simode0;
1539 1532
@@ -2207,22 +2200,6 @@ ahd_handle_nonpkt_busfree(struct ahd_softc *ahd)
2207 if (sent_msg == MSG_ABORT_TAG) 2200 if (sent_msg == MSG_ABORT_TAG)
2208 tag = SCB_GET_TAG(scb); 2201 tag = SCB_GET_TAG(scb);
2209 2202
2210 if ((scb->flags & SCB_CMDPHASE_ABORT) != 0) {
2211 /*
2212 * This abort is in response to an
2213 * unexpected switch to command phase
2214 * for a packetized connection. Since
2215 * the identify message was never sent,
2216 * "saved lun" is 0. We really want to
2217 * abort only the SCB that encountered
2218 * this error, which could have a different
2219 * lun. The SCB will be retried so the OS
2220 * will see the UA after renegotiating to
2221 * packetized.
2222 */
2223 tag = SCB_GET_TAG(scb);
2224 saved_lun = scb->hscb->lun;
2225 }
2226 found = ahd_abort_scbs(ahd, target, 'A', saved_lun, 2203 found = ahd_abort_scbs(ahd, target, 'A', saved_lun,
2227 tag, ROLE_INITIATOR, 2204 tag, ROLE_INITIATOR,
2228 CAM_REQ_ABORTED); 2205 CAM_REQ_ABORTED);
@@ -7847,6 +7824,17 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7847 int found; 7824 int found;
7848 u_int fifo; 7825 u_int fifo;
7849 u_int next_fifo; 7826 u_int next_fifo;
7827 uint8_t scsiseq;
7828
7829 /*
7830 * Check if the last bus reset is cleared
7831 */
7832 if (ahd->flags & AHD_BUS_RESET_ACTIVE) {
7833 printf("%s: bus reset still active\n",
7834 ahd_name(ahd));
7835 return 0;
7836 }
7837 ahd->flags |= AHD_BUS_RESET_ACTIVE;
7850 7838
7851 ahd->pending_device = NULL; 7839 ahd->pending_device = NULL;
7852 7840
@@ -7860,6 +7848,12 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7860 /* Make sure the sequencer is in a safe location. */ 7848 /* Make sure the sequencer is in a safe location. */
7861 ahd_clear_critical_section(ahd); 7849 ahd_clear_critical_section(ahd);
7862 7850
7851 /*
7852 * Run our command complete fifos to ensure that we perform
7853 * completion processing on any commands that 'completed'
7854 * before the reset occurred.
7855 */
7856 ahd_run_qoutfifo(ahd);
7863#ifdef AHD_TARGET_MODE 7857#ifdef AHD_TARGET_MODE
7864 if ((ahd->flags & AHD_TARGETROLE) != 0) { 7858 if ((ahd->flags & AHD_TARGETROLE) != 0) {
7865 ahd_run_tqinfifo(ahd, /*paused*/TRUE); 7859 ahd_run_tqinfifo(ahd, /*paused*/TRUE);
@@ -7924,30 +7918,14 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7924 ahd_clear_fifo(ahd, 1); 7918 ahd_clear_fifo(ahd, 1);
7925 7919
7926 /* 7920 /*
7927 * Revert to async/narrow transfers until we renegotiate. 7921 * Reenable selections
7928 */ 7922 */
7929 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7; 7923 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST);
7930 for (target = 0; target <= max_scsiid; target++) { 7924 scsiseq = ahd_inb(ahd, SCSISEQ_TEMPLATE);
7931 7925 ahd_outb(ahd, SCSISEQ1, scsiseq & (ENSELI|ENRSELI|ENAUTOATNP));
7932 if (ahd->enabled_targets[target] == NULL)
7933 continue;
7934 for (initiator = 0; initiator <= max_scsiid; initiator++) {
7935 struct ahd_devinfo devinfo;
7936
7937 ahd_compile_devinfo(&devinfo, target, initiator,
7938 CAM_LUN_WILDCARD,
7939 'A', ROLE_UNKNOWN);
7940 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
7941 AHD_TRANS_CUR, /*paused*/TRUE);
7942 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
7943 /*offset*/0, /*ppr_options*/0,
7944 AHD_TRANS_CUR, /*paused*/TRUE);
7945 }
7946 }
7947 7926
7948#ifdef AHD_TARGET_MODE
7949 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7; 7927 max_scsiid = (ahd->features & AHD_WIDE) ? 15 : 7;
7950 7928#ifdef AHD_TARGET_MODE
7951 /* 7929 /*
7952 * Send an immediate notify ccb to all target more peripheral 7930 * Send an immediate notify ccb to all target more peripheral
7953 * drivers affected by this action. 7931 * drivers affected by this action.
@@ -7975,51 +7953,31 @@ ahd_reset_channel(struct ahd_softc *ahd, char channel, int initiate_reset)
7975 /* Notify the XPT that a bus reset occurred */ 7953 /* Notify the XPT that a bus reset occurred */
7976 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD, 7954 ahd_send_async(ahd, devinfo.channel, CAM_TARGET_WILDCARD,
7977 CAM_LUN_WILDCARD, AC_BUS_RESET, NULL); 7955 CAM_LUN_WILDCARD, AC_BUS_RESET, NULL);
7978 ahd_restart(ahd); 7956
7979 /* 7957 /*
7980 * Freeze the SIMQ until our poller can determine that 7958 * Revert to async/narrow transfers until we renegotiate.
7981 * the bus reset has really gone away. We set the initial
7982 * timer to 0 to have the check performed as soon as possible
7983 * from the timer context.
7984 */ 7959 */
7985 if ((ahd->flags & AHD_RESET_POLL_ACTIVE) == 0) { 7960 for (target = 0; target <= max_scsiid; target++) {
7986 ahd->flags |= AHD_RESET_POLL_ACTIVE;
7987 ahd_freeze_simq(ahd);
7988 ahd_timer_reset(&ahd->reset_timer, 0, ahd_reset_poll, ahd);
7989 }
7990 return (found);
7991}
7992 7961
7962 if (ahd->enabled_targets[target] == NULL)
7963 continue;
7964 for (initiator = 0; initiator <= max_scsiid; initiator++) {
7965 struct ahd_devinfo devinfo;
7993 7966
7994#define AHD_RESET_POLL_US 1000 7967 ahd_compile_devinfo(&devinfo, target, initiator,
7995static void 7968 CAM_LUN_WILDCARD,
7996ahd_reset_poll(void *arg) 7969 'A', ROLE_UNKNOWN);
7997{ 7970 ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
7998 struct ahd_softc *ahd = arg; 7971 AHD_TRANS_CUR, /*paused*/TRUE);
7999 u_int scsiseq1; 7972 ahd_set_syncrate(ahd, &devinfo, /*period*/0,
8000 u_long s; 7973 /*offset*/0, /*ppr_options*/0,
8001 7974 AHD_TRANS_CUR, /*paused*/TRUE);
8002 ahd_lock(ahd, &s); 7975 }
8003 ahd_pause(ahd);
8004 ahd_update_modes(ahd);
8005 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
8006 ahd_outb(ahd, CLRSINT1, CLRSCSIRSTI);
8007 if ((ahd_inb(ahd, SSTAT1) & SCSIRSTI) != 0) {
8008 ahd_timer_reset(&ahd->reset_timer, AHD_RESET_POLL_US,
8009 ahd_reset_poll, ahd);
8010 ahd_unpause(ahd);
8011 ahd_unlock(ahd, &s);
8012 return;
8013 } 7976 }
8014 7977
8015 /* Reset is now low. Complete chip reinitialization. */ 7978 ahd_restart(ahd);
8016 ahd_outb(ahd, SIMODE1, ahd_inb(ahd, SIMODE1) | ENSCSIRST); 7979
8017 scsiseq1 = ahd_inb(ahd, SCSISEQ_TEMPLATE); 7980 return (found);
8018 ahd_outb(ahd, SCSISEQ1, scsiseq1 & (ENSELI|ENRSELI|ENAUTOATNP));
8019 ahd_unpause(ahd);
8020 ahd->flags &= ~AHD_RESET_POLL_ACTIVE;
8021 ahd_unlock(ahd, &s);
8022 ahd_release_simq(ahd);
8023} 7981}
8024 7982
8025/**************************** Statistics Processing ***************************/ 7983/**************************** Statistics Processing ***************************/
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index bcced0a417e6..66e4a47bb9ee 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -782,6 +782,7 @@ ahd_linux_bus_reset(struct scsi_cmnd *cmd)
782{ 782{
783 struct ahd_softc *ahd; 783 struct ahd_softc *ahd;
784 int found; 784 int found;
785 unsigned long flags;
785 786
786 ahd = *(struct ahd_softc **)cmd->device->host->hostdata; 787 ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
787#ifdef AHD_DEBUG 788#ifdef AHD_DEBUG
@@ -789,8 +790,11 @@ ahd_linux_bus_reset(struct scsi_cmnd *cmd)
789 printf("%s: Bus reset called for cmd %p\n", 790 printf("%s: Bus reset called for cmd %p\n",
790 ahd_name(ahd), cmd); 791 ahd_name(ahd), cmd);
791#endif 792#endif
793 ahd_lock(ahd, &flags);
794
792 found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A', 795 found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
793 /*initiate reset*/TRUE); 796 /*initiate reset*/TRUE);
797 ahd_unlock(ahd, &flags);
794 798
795 if (bootverbose) 799 if (bootverbose)
796 printf("%s: SCSI bus reset delivered. " 800 printf("%s: SCSI bus reset delivered. "
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c
index 2d5be84d8bd4..6dc88149f9f1 100644
--- a/drivers/scsi/ata_piix.c
+++ b/drivers/scsi/ata_piix.c
@@ -209,7 +209,6 @@ static struct scsi_host_template piix_sht = {
209 .name = DRV_NAME, 209 .name = DRV_NAME,
210 .ioctl = ata_scsi_ioctl, 210 .ioctl = ata_scsi_ioctl,
211 .queuecommand = ata_scsi_queuecmd, 211 .queuecommand = ata_scsi_queuecmd,
212 .eh_strategy_handler = ata_scsi_error,
213 .can_queue = ATA_DEF_QUEUE, 212 .can_queue = ATA_DEF_QUEUE,
214 .this_id = ATA_SHT_THIS_ID, 213 .this_id = ATA_SHT_THIS_ID,
215 .sg_tablesize = LIBATA_MAX_PRD, 214 .sg_tablesize = LIBATA_MAX_PRD,
@@ -301,7 +300,7 @@ static struct piix_map_db ich6_map_db = {
301 .mask = 0x3, 300 .mask = 0x3,
302 .map = { 301 .map = {
303 /* PM PS SM SS MAP */ 302 /* PM PS SM SS MAP */
304 { P0, P1, P2, P3 }, /* 00b */ 303 { P0, P2, P1, P3 }, /* 00b */
305 { IDE, IDE, P1, P3 }, /* 01b */ 304 { IDE, IDE, P1, P3 }, /* 01b */
306 { P0, P2, IDE, IDE }, /* 10b */ 305 { P0, P2, IDE, IDE }, /* 10b */
307 { RV, RV, RV, RV }, 306 { RV, RV, RV, RV },
@@ -312,7 +311,7 @@ static struct piix_map_db ich6m_map_db = {
312 .mask = 0x3, 311 .mask = 0x3,
313 .map = { 312 .map = {
314 /* PM PS SM SS MAP */ 313 /* PM PS SM SS MAP */
315 { P0, P1, P2, P3 }, /* 00b */ 314 { P0, P2, RV, RV }, /* 00b */
316 { RV, RV, RV, RV }, 315 { RV, RV, RV, RV },
317 { P0, P2, IDE, IDE }, /* 10b */ 316 { P0, P2, IDE, IDE }, /* 10b */
318 { RV, RV, RV, RV }, 317 { RV, RV, RV, RV },
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index ef57f253031c..dfcb96f3e60c 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -294,18 +294,6 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
294 if (sht->unchecked_isa_dma && privsize) 294 if (sht->unchecked_isa_dma && privsize)
295 gfp_mask |= __GFP_DMA; 295 gfp_mask |= __GFP_DMA;
296 296
297 /* Check to see if this host has any error handling facilities */
298 if (!sht->eh_strategy_handler && !sht->eh_abort_handler &&
299 !sht->eh_device_reset_handler && !sht->eh_bus_reset_handler &&
300 !sht->eh_host_reset_handler) {
301 printk(KERN_ERR "ERROR: SCSI host `%s' has no error handling\n"
302 "ERROR: This is not a safe way to run your "
303 "SCSI host\n"
304 "ERROR: The error handling must be added to "
305 "this driver\n", sht->proc_name);
306 dump_stack();
307 }
308
309 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask); 297 shost = kzalloc(sizeof(struct Scsi_Host) + privsize, gfp_mask);
310 if (!shost) 298 if (!shost)
311 return NULL; 299 return NULL;
diff --git a/drivers/scsi/ibmmca.c b/drivers/scsi/ibmmca.c
index 3a8462e8d063..24eb59e143a9 100644
--- a/drivers/scsi/ibmmca.c
+++ b/drivers/scsi/ibmmca.c
@@ -2488,7 +2488,7 @@ static int option_setup(char *str)
2488 } 2488 }
2489 ints[0] = i - 1; 2489 ints[0] = i - 1;
2490 internal_ibmmca_scsi_setup(cur, ints); 2490 internal_ibmmca_scsi_setup(cur, ints);
2491 return 0; 2491 return 1;
2492} 2492}
2493 2493
2494__setup("ibmmcascsi=", option_setup); 2494__setup("ibmmcascsi=", option_setup);
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index eaefeddb2b4a..0a8ad37ae899 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -168,7 +168,7 @@ static void release_event_pool(struct event_pool *pool,
168 ++in_use; 168 ++in_use;
169 if (pool->events[i].ext_list) { 169 if (pool->events[i].ext_list) {
170 dma_free_coherent(hostdata->dev, 170 dma_free_coherent(hostdata->dev,
171 SG_ALL * sizeof(struct memory_descriptor), 171 SG_ALL * sizeof(struct srp_direct_buf),
172 pool->events[i].ext_list, 172 pool->events[i].ext_list,
173 pool->events[i].ext_list_token); 173 pool->events[i].ext_list_token);
174 } 174 }
@@ -284,40 +284,37 @@ static void set_srp_direction(struct scsi_cmnd *cmd,
284 struct srp_cmd *srp_cmd, 284 struct srp_cmd *srp_cmd,
285 int numbuf) 285 int numbuf)
286{ 286{
287 u8 fmt;
288
287 if (numbuf == 0) 289 if (numbuf == 0)
288 return; 290 return;
289 291
290 if (numbuf == 1) { 292 if (numbuf == 1)
293 fmt = SRP_DATA_DESC_DIRECT;
294 else {
295 fmt = SRP_DATA_DESC_INDIRECT;
296 numbuf = min(numbuf, MAX_INDIRECT_BUFS);
297
291 if (cmd->sc_data_direction == DMA_TO_DEVICE) 298 if (cmd->sc_data_direction == DMA_TO_DEVICE)
292 srp_cmd->data_out_format = SRP_DIRECT_BUFFER; 299 srp_cmd->data_out_desc_cnt = numbuf;
293 else 300 else
294 srp_cmd->data_in_format = SRP_DIRECT_BUFFER; 301 srp_cmd->data_in_desc_cnt = numbuf;
295 } else {
296 if (cmd->sc_data_direction == DMA_TO_DEVICE) {
297 srp_cmd->data_out_format = SRP_INDIRECT_BUFFER;
298 srp_cmd->data_out_count =
299 numbuf < MAX_INDIRECT_BUFS ?
300 numbuf: MAX_INDIRECT_BUFS;
301 } else {
302 srp_cmd->data_in_format = SRP_INDIRECT_BUFFER;
303 srp_cmd->data_in_count =
304 numbuf < MAX_INDIRECT_BUFS ?
305 numbuf: MAX_INDIRECT_BUFS;
306 }
307 } 302 }
303
304 if (cmd->sc_data_direction == DMA_TO_DEVICE)
305 srp_cmd->buf_fmt = fmt << 4;
306 else
307 srp_cmd->buf_fmt = fmt;
308} 308}
309 309
310static void unmap_sg_list(int num_entries, 310static void unmap_sg_list(int num_entries,
311 struct device *dev, 311 struct device *dev,
312 struct memory_descriptor *md) 312 struct srp_direct_buf *md)
313{ 313{
314 int i; 314 int i;
315 315
316 for (i = 0; i < num_entries; ++i) { 316 for (i = 0; i < num_entries; ++i)
317 dma_unmap_single(dev, 317 dma_unmap_single(dev, md[i].va, md[i].len, DMA_BIDIRECTIONAL);
318 md[i].virtual_address,
319 md[i].length, DMA_BIDIRECTIONAL);
320 }
321} 318}
322 319
323/** 320/**
@@ -330,23 +327,26 @@ static void unmap_cmd_data(struct srp_cmd *cmd,
330 struct srp_event_struct *evt_struct, 327 struct srp_event_struct *evt_struct,
331 struct device *dev) 328 struct device *dev)
332{ 329{
333 if ((cmd->data_out_format == SRP_NO_BUFFER) && 330 u8 out_fmt, in_fmt;
334 (cmd->data_in_format == SRP_NO_BUFFER)) 331
332 out_fmt = cmd->buf_fmt >> 4;
333 in_fmt = cmd->buf_fmt & ((1U << 4) - 1);
334
335 if (out_fmt == SRP_NO_DATA_DESC && in_fmt == SRP_NO_DATA_DESC)
335 return; 336 return;
336 else if ((cmd->data_out_format == SRP_DIRECT_BUFFER) || 337 else if (out_fmt == SRP_DATA_DESC_DIRECT ||
337 (cmd->data_in_format == SRP_DIRECT_BUFFER)) { 338 in_fmt == SRP_DATA_DESC_DIRECT) {
338 struct memory_descriptor *data = 339 struct srp_direct_buf *data =
339 (struct memory_descriptor *)cmd->additional_data; 340 (struct srp_direct_buf *) cmd->add_data;
340 dma_unmap_single(dev, data->virtual_address, data->length, 341 dma_unmap_single(dev, data->va, data->len, DMA_BIDIRECTIONAL);
341 DMA_BIDIRECTIONAL);
342 } else { 342 } else {
343 struct indirect_descriptor *indirect = 343 struct srp_indirect_buf *indirect =
344 (struct indirect_descriptor *)cmd->additional_data; 344 (struct srp_indirect_buf *) cmd->add_data;
345 int num_mapped = indirect->head.length / 345 int num_mapped = indirect->table_desc.len /
346 sizeof(indirect->list[0]); 346 sizeof(struct srp_direct_buf);
347 347
348 if (num_mapped <= MAX_INDIRECT_BUFS) { 348 if (num_mapped <= MAX_INDIRECT_BUFS) {
349 unmap_sg_list(num_mapped, dev, &indirect->list[0]); 349 unmap_sg_list(num_mapped, dev, &indirect->desc_list[0]);
350 return; 350 return;
351 } 351 }
352 352
@@ -356,17 +356,17 @@ static void unmap_cmd_data(struct srp_cmd *cmd,
356 356
357static int map_sg_list(int num_entries, 357static int map_sg_list(int num_entries,
358 struct scatterlist *sg, 358 struct scatterlist *sg,
359 struct memory_descriptor *md) 359 struct srp_direct_buf *md)
360{ 360{
361 int i; 361 int i;
362 u64 total_length = 0; 362 u64 total_length = 0;
363 363
364 for (i = 0; i < num_entries; ++i) { 364 for (i = 0; i < num_entries; ++i) {
365 struct memory_descriptor *descr = md + i; 365 struct srp_direct_buf *descr = md + i;
366 struct scatterlist *sg_entry = &sg[i]; 366 struct scatterlist *sg_entry = &sg[i];
367 descr->virtual_address = sg_dma_address(sg_entry); 367 descr->va = sg_dma_address(sg_entry);
368 descr->length = sg_dma_len(sg_entry); 368 descr->len = sg_dma_len(sg_entry);
369 descr->memory_handle = 0; 369 descr->key = 0;
370 total_length += sg_dma_len(sg_entry); 370 total_length += sg_dma_len(sg_entry);
371 } 371 }
372 return total_length; 372 return total_length;
@@ -389,10 +389,10 @@ static int map_sg_data(struct scsi_cmnd *cmd,
389 int sg_mapped; 389 int sg_mapped;
390 u64 total_length = 0; 390 u64 total_length = 0;
391 struct scatterlist *sg = cmd->request_buffer; 391 struct scatterlist *sg = cmd->request_buffer;
392 struct memory_descriptor *data = 392 struct srp_direct_buf *data =
393 (struct memory_descriptor *)srp_cmd->additional_data; 393 (struct srp_direct_buf *) srp_cmd->add_data;
394 struct indirect_descriptor *indirect = 394 struct srp_indirect_buf *indirect =
395 (struct indirect_descriptor *)data; 395 (struct srp_indirect_buf *) data;
396 396
397 sg_mapped = dma_map_sg(dev, sg, cmd->use_sg, DMA_BIDIRECTIONAL); 397 sg_mapped = dma_map_sg(dev, sg, cmd->use_sg, DMA_BIDIRECTIONAL);
398 398
@@ -403,9 +403,9 @@ static int map_sg_data(struct scsi_cmnd *cmd,
403 403
404 /* special case; we can use a single direct descriptor */ 404 /* special case; we can use a single direct descriptor */
405 if (sg_mapped == 1) { 405 if (sg_mapped == 1) {
406 data->virtual_address = sg_dma_address(&sg[0]); 406 data->va = sg_dma_address(&sg[0]);
407 data->length = sg_dma_len(&sg[0]); 407 data->len = sg_dma_len(&sg[0]);
408 data->memory_handle = 0; 408 data->key = 0;
409 return 1; 409 return 1;
410 } 410 }
411 411
@@ -416,25 +416,26 @@ static int map_sg_data(struct scsi_cmnd *cmd,
416 return 0; 416 return 0;
417 } 417 }
418 418
419 indirect->head.virtual_address = 0; 419 indirect->table_desc.va = 0;
420 indirect->head.length = sg_mapped * sizeof(indirect->list[0]); 420 indirect->table_desc.len = sg_mapped * sizeof(struct srp_direct_buf);
421 indirect->head.memory_handle = 0; 421 indirect->table_desc.key = 0;
422 422
423 if (sg_mapped <= MAX_INDIRECT_BUFS) { 423 if (sg_mapped <= MAX_INDIRECT_BUFS) {
424 total_length = map_sg_list(sg_mapped, sg, &indirect->list[0]); 424 total_length = map_sg_list(sg_mapped, sg,
425 indirect->total_length = total_length; 425 &indirect->desc_list[0]);
426 indirect->len = total_length;
426 return 1; 427 return 1;
427 } 428 }
428 429
429 /* get indirect table */ 430 /* get indirect table */
430 if (!evt_struct->ext_list) { 431 if (!evt_struct->ext_list) {
431 evt_struct->ext_list =(struct memory_descriptor*) 432 evt_struct->ext_list = (struct srp_direct_buf *)
432 dma_alloc_coherent(dev, 433 dma_alloc_coherent(dev,
433 SG_ALL * sizeof(struct memory_descriptor), 434 SG_ALL * sizeof(struct srp_direct_buf),
434 &evt_struct->ext_list_token, 0); 435 &evt_struct->ext_list_token, 0);
435 if (!evt_struct->ext_list) { 436 if (!evt_struct->ext_list) {
436 printk(KERN_ERR 437 printk(KERN_ERR
437 "ibmvscsi: Can't allocate memory for indirect table\n"); 438 "ibmvscsi: Can't allocate memory for indirect table\n");
438 return 0; 439 return 0;
439 440
440 } 441 }
@@ -442,11 +443,11 @@ static int map_sg_data(struct scsi_cmnd *cmd,
442 443
443 total_length = map_sg_list(sg_mapped, sg, evt_struct->ext_list); 444 total_length = map_sg_list(sg_mapped, sg, evt_struct->ext_list);
444 445
445 indirect->total_length = total_length; 446 indirect->len = total_length;
446 indirect->head.virtual_address = evt_struct->ext_list_token; 447 indirect->table_desc.va = evt_struct->ext_list_token;
447 indirect->head.length = sg_mapped * sizeof(indirect->list[0]); 448 indirect->table_desc.len = sg_mapped * sizeof(indirect->desc_list[0]);
448 memcpy(indirect->list, evt_struct->ext_list, 449 memcpy(indirect->desc_list, evt_struct->ext_list,
449 MAX_INDIRECT_BUFS * sizeof(struct memory_descriptor)); 450 MAX_INDIRECT_BUFS * sizeof(struct srp_direct_buf));
450 451
451 return 1; 452 return 1;
452} 453}
@@ -463,20 +464,20 @@ static int map_sg_data(struct scsi_cmnd *cmd,
463static int map_single_data(struct scsi_cmnd *cmd, 464static int map_single_data(struct scsi_cmnd *cmd,
464 struct srp_cmd *srp_cmd, struct device *dev) 465 struct srp_cmd *srp_cmd, struct device *dev)
465{ 466{
466 struct memory_descriptor *data = 467 struct srp_direct_buf *data =
467 (struct memory_descriptor *)srp_cmd->additional_data; 468 (struct srp_direct_buf *) srp_cmd->add_data;
468 469
469 data->virtual_address = 470 data->va =
470 dma_map_single(dev, cmd->request_buffer, 471 dma_map_single(dev, cmd->request_buffer,
471 cmd->request_bufflen, 472 cmd->request_bufflen,
472 DMA_BIDIRECTIONAL); 473 DMA_BIDIRECTIONAL);
473 if (dma_mapping_error(data->virtual_address)) { 474 if (dma_mapping_error(data->va)) {
474 printk(KERN_ERR 475 printk(KERN_ERR
475 "ibmvscsi: Unable to map request_buffer for command!\n"); 476 "ibmvscsi: Unable to map request_buffer for command!\n");
476 return 0; 477 return 0;
477 } 478 }
478 data->length = cmd->request_bufflen; 479 data->len = cmd->request_bufflen;
479 data->memory_handle = 0; 480 data->key = 0;
480 481
481 set_srp_direction(cmd, srp_cmd, 1); 482 set_srp_direction(cmd, srp_cmd, 1);
482 483
@@ -548,7 +549,7 @@ static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
548 549
549 /* Copy the IU into the transfer area */ 550 /* Copy the IU into the transfer area */
550 *evt_struct->xfer_iu = evt_struct->iu; 551 *evt_struct->xfer_iu = evt_struct->iu;
551 evt_struct->xfer_iu->srp.generic.tag = (u64)evt_struct; 552 evt_struct->xfer_iu->srp.rsp.tag = (u64)evt_struct;
552 553
553 /* Add this to the sent list. We need to do this 554 /* Add this to the sent list. We need to do this
554 * before we actually send 555 * before we actually send
@@ -586,27 +587,27 @@ static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
586 struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp; 587 struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp;
587 struct scsi_cmnd *cmnd = evt_struct->cmnd; 588 struct scsi_cmnd *cmnd = evt_struct->cmnd;
588 589
589 if (unlikely(rsp->type != SRP_RSP_TYPE)) { 590 if (unlikely(rsp->opcode != SRP_RSP)) {
590 if (printk_ratelimit()) 591 if (printk_ratelimit())
591 printk(KERN_WARNING 592 printk(KERN_WARNING
592 "ibmvscsi: bad SRP RSP type %d\n", 593 "ibmvscsi: bad SRP RSP type %d\n",
593 rsp->type); 594 rsp->opcode);
594 } 595 }
595 596
596 if (cmnd) { 597 if (cmnd) {
597 cmnd->result = rsp->status; 598 cmnd->result = rsp->status;
598 if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION) 599 if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
599 memcpy(cmnd->sense_buffer, 600 memcpy(cmnd->sense_buffer,
600 rsp->sense_and_response_data, 601 rsp->data,
601 rsp->sense_data_list_length); 602 rsp->sense_data_len);
602 unmap_cmd_data(&evt_struct->iu.srp.cmd, 603 unmap_cmd_data(&evt_struct->iu.srp.cmd,
603 evt_struct, 604 evt_struct,
604 evt_struct->hostdata->dev); 605 evt_struct->hostdata->dev);
605 606
606 if (rsp->doover) 607 if (rsp->flags & SRP_RSP_FLAG_DOOVER)
607 cmnd->resid = rsp->data_out_residual_count; 608 cmnd->resid = rsp->data_out_res_cnt;
608 else if (rsp->diover) 609 else if (rsp->flags & SRP_RSP_FLAG_DIOVER)
609 cmnd->resid = rsp->data_in_residual_count; 610 cmnd->resid = rsp->data_in_res_cnt;
610 } 611 }
611 612
612 if (evt_struct->cmnd_done) 613 if (evt_struct->cmnd_done)
@@ -633,10 +634,11 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
633{ 634{
634 struct srp_cmd *srp_cmd; 635 struct srp_cmd *srp_cmd;
635 struct srp_event_struct *evt_struct; 636 struct srp_event_struct *evt_struct;
636 struct indirect_descriptor *indirect; 637 struct srp_indirect_buf *indirect;
637 struct ibmvscsi_host_data *hostdata = 638 struct ibmvscsi_host_data *hostdata =
638 (struct ibmvscsi_host_data *)&cmnd->device->host->hostdata; 639 (struct ibmvscsi_host_data *)&cmnd->device->host->hostdata;
639 u16 lun = lun_from_dev(cmnd->device); 640 u16 lun = lun_from_dev(cmnd->device);
641 u8 out_fmt, in_fmt;
640 642
641 evt_struct = get_event_struct(&hostdata->pool); 643 evt_struct = get_event_struct(&hostdata->pool);
642 if (!evt_struct) 644 if (!evt_struct)
@@ -644,8 +646,8 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
644 646
645 /* Set up the actual SRP IU */ 647 /* Set up the actual SRP IU */
646 srp_cmd = &evt_struct->iu.srp.cmd; 648 srp_cmd = &evt_struct->iu.srp.cmd;
647 memset(srp_cmd, 0x00, sizeof(*srp_cmd)); 649 memset(srp_cmd, 0x00, SRP_MAX_IU_LEN);
648 srp_cmd->type = SRP_CMD_TYPE; 650 srp_cmd->opcode = SRP_CMD;
649 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(cmnd->cmnd)); 651 memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(cmnd->cmnd));
650 srp_cmd->lun = ((u64) lun) << 48; 652 srp_cmd->lun = ((u64) lun) << 48;
651 653
@@ -664,13 +666,15 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
664 evt_struct->cmnd_done = done; 666 evt_struct->cmnd_done = done;
665 667
666 /* Fix up dma address of the buffer itself */ 668 /* Fix up dma address of the buffer itself */
667 indirect = (struct indirect_descriptor *)srp_cmd->additional_data; 669 indirect = (struct srp_indirect_buf *) srp_cmd->add_data;
668 if (((srp_cmd->data_out_format == SRP_INDIRECT_BUFFER) || 670 out_fmt = srp_cmd->buf_fmt >> 4;
669 (srp_cmd->data_in_format == SRP_INDIRECT_BUFFER)) && 671 in_fmt = srp_cmd->buf_fmt & ((1U << 4) - 1);
670 (indirect->head.virtual_address == 0)) { 672 if ((in_fmt == SRP_DATA_DESC_INDIRECT ||
671 indirect->head.virtual_address = evt_struct->crq.IU_data_ptr + 673 out_fmt == SRP_DATA_DESC_INDIRECT) &&
672 offsetof(struct srp_cmd, additional_data) + 674 indirect->table_desc.va == 0) {
673 offsetof(struct indirect_descriptor, list); 675 indirect->table_desc.va = evt_struct->crq.IU_data_ptr +
676 offsetof(struct srp_cmd, add_data) +
677 offsetof(struct srp_indirect_buf, desc_list);
674 } 678 }
675 679
676 return ibmvscsi_send_srp_event(evt_struct, hostdata); 680 return ibmvscsi_send_srp_event(evt_struct, hostdata);
@@ -780,10 +784,10 @@ static void send_mad_adapter_info(struct ibmvscsi_host_data *hostdata)
780static void login_rsp(struct srp_event_struct *evt_struct) 784static void login_rsp(struct srp_event_struct *evt_struct)
781{ 785{
782 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata; 786 struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
783 switch (evt_struct->xfer_iu->srp.generic.type) { 787 switch (evt_struct->xfer_iu->srp.login_rsp.opcode) {
784 case SRP_LOGIN_RSP_TYPE: /* it worked! */ 788 case SRP_LOGIN_RSP: /* it worked! */
785 break; 789 break;
786 case SRP_LOGIN_REJ_TYPE: /* refused! */ 790 case SRP_LOGIN_REJ: /* refused! */
787 printk(KERN_INFO "ibmvscsi: SRP_LOGIN_REJ reason %u\n", 791 printk(KERN_INFO "ibmvscsi: SRP_LOGIN_REJ reason %u\n",
788 evt_struct->xfer_iu->srp.login_rej.reason); 792 evt_struct->xfer_iu->srp.login_rej.reason);
789 /* Login failed. */ 793 /* Login failed. */
@@ -792,7 +796,7 @@ static void login_rsp(struct srp_event_struct *evt_struct)
792 default: 796 default:
793 printk(KERN_ERR 797 printk(KERN_ERR
794 "ibmvscsi: Invalid login response typecode 0x%02x!\n", 798 "ibmvscsi: Invalid login response typecode 0x%02x!\n",
795 evt_struct->xfer_iu->srp.generic.type); 799 evt_struct->xfer_iu->srp.login_rsp.opcode);
796 /* Login failed. */ 800 /* Login failed. */
797 atomic_set(&hostdata->request_limit, -1); 801 atomic_set(&hostdata->request_limit, -1);
798 return; 802 return;
@@ -800,17 +804,17 @@ static void login_rsp(struct srp_event_struct *evt_struct)
800 804
801 printk(KERN_INFO "ibmvscsi: SRP_LOGIN succeeded\n"); 805 printk(KERN_INFO "ibmvscsi: SRP_LOGIN succeeded\n");
802 806
803 if (evt_struct->xfer_iu->srp.login_rsp.request_limit_delta > 807 if (evt_struct->xfer_iu->srp.login_rsp.req_lim_delta >
804 (max_requests - 2)) 808 (max_requests - 2))
805 evt_struct->xfer_iu->srp.login_rsp.request_limit_delta = 809 evt_struct->xfer_iu->srp.login_rsp.req_lim_delta =
806 max_requests - 2; 810 max_requests - 2;
807 811
808 /* Now we know what the real request-limit is */ 812 /* Now we know what the real request-limit is */
809 atomic_set(&hostdata->request_limit, 813 atomic_set(&hostdata->request_limit,
810 evt_struct->xfer_iu->srp.login_rsp.request_limit_delta); 814 evt_struct->xfer_iu->srp.login_rsp.req_lim_delta);
811 815
812 hostdata->host->can_queue = 816 hostdata->host->can_queue =
813 evt_struct->xfer_iu->srp.login_rsp.request_limit_delta - 2; 817 evt_struct->xfer_iu->srp.login_rsp.req_lim_delta - 2;
814 818
815 if (hostdata->host->can_queue < 1) { 819 if (hostdata->host->can_queue < 1) {
816 printk(KERN_ERR "ibmvscsi: Invalid request_limit_delta\n"); 820 printk(KERN_ERR "ibmvscsi: Invalid request_limit_delta\n");
@@ -849,18 +853,19 @@ static int send_srp_login(struct ibmvscsi_host_data *hostdata)
849 853
850 login = &evt_struct->iu.srp.login_req; 854 login = &evt_struct->iu.srp.login_req;
851 memset(login, 0x00, sizeof(struct srp_login_req)); 855 memset(login, 0x00, sizeof(struct srp_login_req));
852 login->type = SRP_LOGIN_REQ_TYPE; 856 login->opcode = SRP_LOGIN_REQ;
853 login->max_requested_initiator_to_target_iulen = sizeof(union srp_iu); 857 login->req_it_iu_len = sizeof(union srp_iu);
854 login->required_buffer_formats = 0x0006; 858 login->req_buf_fmt = SRP_BUF_FORMAT_DIRECT | SRP_BUF_FORMAT_INDIRECT;
855 859
860 spin_lock_irqsave(hostdata->host->host_lock, flags);
856 /* Start out with a request limit of 1, since this is negotiated in 861 /* Start out with a request limit of 1, since this is negotiated in
857 * the login request we are just sending 862 * the login request we are just sending
858 */ 863 */
859 atomic_set(&hostdata->request_limit, 1); 864 atomic_set(&hostdata->request_limit, 1);
860 865
861 spin_lock_irqsave(hostdata->host->host_lock, flags);
862 rc = ibmvscsi_send_srp_event(evt_struct, hostdata); 866 rc = ibmvscsi_send_srp_event(evt_struct, hostdata);
863 spin_unlock_irqrestore(hostdata->host->host_lock, flags); 867 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
868 printk("ibmvscsic: sent SRP login\n");
864 return rc; 869 return rc;
865}; 870};
866 871
@@ -928,13 +933,13 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
928 933
929 /* Set up an abort SRP command */ 934 /* Set up an abort SRP command */
930 memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt)); 935 memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt));
931 tsk_mgmt->type = SRP_TSK_MGMT_TYPE; 936 tsk_mgmt->opcode = SRP_TSK_MGMT;
932 tsk_mgmt->lun = ((u64) lun) << 48; 937 tsk_mgmt->lun = ((u64) lun) << 48;
933 tsk_mgmt->task_mgmt_flags = 0x01; /* ABORT TASK */ 938 tsk_mgmt->tsk_mgmt_func = SRP_TSK_ABORT_TASK;
934 tsk_mgmt->managed_task_tag = (u64) found_evt; 939 tsk_mgmt->task_tag = (u64) found_evt;
935 940
936 printk(KERN_INFO "ibmvscsi: aborting command. lun 0x%lx, tag 0x%lx\n", 941 printk(KERN_INFO "ibmvscsi: aborting command. lun 0x%lx, tag 0x%lx\n",
937 tsk_mgmt->lun, tsk_mgmt->managed_task_tag); 942 tsk_mgmt->lun, tsk_mgmt->task_tag);
938 943
939 evt->sync_srp = &srp_rsp; 944 evt->sync_srp = &srp_rsp;
940 init_completion(&evt->comp); 945 init_completion(&evt->comp);
@@ -948,25 +953,25 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
948 wait_for_completion(&evt->comp); 953 wait_for_completion(&evt->comp);
949 954
950 /* make sure we got a good response */ 955 /* make sure we got a good response */
951 if (unlikely(srp_rsp.srp.generic.type != SRP_RSP_TYPE)) { 956 if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) {
952 if (printk_ratelimit()) 957 if (printk_ratelimit())
953 printk(KERN_WARNING 958 printk(KERN_WARNING
954 "ibmvscsi: abort bad SRP RSP type %d\n", 959 "ibmvscsi: abort bad SRP RSP type %d\n",
955 srp_rsp.srp.generic.type); 960 srp_rsp.srp.rsp.opcode);
956 return FAILED; 961 return FAILED;
957 } 962 }
958 963
959 if (srp_rsp.srp.rsp.rspvalid) 964 if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID)
960 rsp_rc = *((int *)srp_rsp.srp.rsp.sense_and_response_data); 965 rsp_rc = *((int *)srp_rsp.srp.rsp.data);
961 else 966 else
962 rsp_rc = srp_rsp.srp.rsp.status; 967 rsp_rc = srp_rsp.srp.rsp.status;
963 968
964 if (rsp_rc) { 969 if (rsp_rc) {
965 if (printk_ratelimit()) 970 if (printk_ratelimit())
966 printk(KERN_WARNING 971 printk(KERN_WARNING
967 "ibmvscsi: abort code %d for task tag 0x%lx\n", 972 "ibmvscsi: abort code %d for task tag 0x%lx\n",
968 rsp_rc, 973 rsp_rc,
969 tsk_mgmt->managed_task_tag); 974 tsk_mgmt->task_tag);
970 return FAILED; 975 return FAILED;
971 } 976 }
972 977
@@ -987,13 +992,13 @@ static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
987 spin_unlock_irqrestore(hostdata->host->host_lock, flags); 992 spin_unlock_irqrestore(hostdata->host->host_lock, flags);
988 printk(KERN_INFO 993 printk(KERN_INFO
989 "ibmvscsi: aborted task tag 0x%lx completed\n", 994 "ibmvscsi: aborted task tag 0x%lx completed\n",
990 tsk_mgmt->managed_task_tag); 995 tsk_mgmt->task_tag);
991 return SUCCESS; 996 return SUCCESS;
992 } 997 }
993 998
994 printk(KERN_INFO 999 printk(KERN_INFO
995 "ibmvscsi: successfully aborted task tag 0x%lx\n", 1000 "ibmvscsi: successfully aborted task tag 0x%lx\n",
996 tsk_mgmt->managed_task_tag); 1001 tsk_mgmt->task_tag);
997 1002
998 cmd->result = (DID_ABORT << 16); 1003 cmd->result = (DID_ABORT << 16);
999 list_del(&found_evt->list); 1004 list_del(&found_evt->list);
@@ -1040,9 +1045,9 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
1040 1045
1041 /* Set up a lun reset SRP command */ 1046 /* Set up a lun reset SRP command */
1042 memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt)); 1047 memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt));
1043 tsk_mgmt->type = SRP_TSK_MGMT_TYPE; 1048 tsk_mgmt->opcode = SRP_TSK_MGMT;
1044 tsk_mgmt->lun = ((u64) lun) << 48; 1049 tsk_mgmt->lun = ((u64) lun) << 48;
1045 tsk_mgmt->task_mgmt_flags = 0x08; /* LUN RESET */ 1050 tsk_mgmt->tsk_mgmt_func = SRP_TSK_LUN_RESET;
1046 1051
1047 printk(KERN_INFO "ibmvscsi: resetting device. lun 0x%lx\n", 1052 printk(KERN_INFO "ibmvscsi: resetting device. lun 0x%lx\n",
1048 tsk_mgmt->lun); 1053 tsk_mgmt->lun);
@@ -1059,16 +1064,16 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
1059 wait_for_completion(&evt->comp); 1064 wait_for_completion(&evt->comp);
1060 1065
1061 /* make sure we got a good response */ 1066 /* make sure we got a good response */
1062 if (unlikely(srp_rsp.srp.generic.type != SRP_RSP_TYPE)) { 1067 if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) {
1063 if (printk_ratelimit()) 1068 if (printk_ratelimit())
1064 printk(KERN_WARNING 1069 printk(KERN_WARNING
1065 "ibmvscsi: reset bad SRP RSP type %d\n", 1070 "ibmvscsi: reset bad SRP RSP type %d\n",
1066 srp_rsp.srp.generic.type); 1071 srp_rsp.srp.rsp.opcode);
1067 return FAILED; 1072 return FAILED;
1068 } 1073 }
1069 1074
1070 if (srp_rsp.srp.rsp.rspvalid) 1075 if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID)
1071 rsp_rc = *((int *)srp_rsp.srp.rsp.sense_and_response_data); 1076 rsp_rc = *((int *)srp_rsp.srp.rsp.data);
1072 else 1077 else
1073 rsp_rc = srp_rsp.srp.rsp.status; 1078 rsp_rc = srp_rsp.srp.rsp.status;
1074 1079
@@ -1076,8 +1081,7 @@ static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
1076 if (printk_ratelimit()) 1081 if (printk_ratelimit())
1077 printk(KERN_WARNING 1082 printk(KERN_WARNING
1078 "ibmvscsi: reset code %d for task tag 0x%lx\n", 1083 "ibmvscsi: reset code %d for task tag 0x%lx\n",
1079 rsp_rc, 1084 rsp_rc, tsk_mgmt->task_tag);
1080 tsk_mgmt->managed_task_tag);
1081 return FAILED; 1085 return FAILED;
1082 } 1086 }
1083 1087
@@ -1179,6 +1183,7 @@ void ibmvscsi_handle_crq(struct viosrp_crq *crq,
1179 /* We need to re-setup the interpartition connection */ 1183 /* We need to re-setup the interpartition connection */
1180 printk(KERN_INFO 1184 printk(KERN_INFO
1181 "ibmvscsi: Re-enabling adapter!\n"); 1185 "ibmvscsi: Re-enabling adapter!\n");
1186 atomic_set(&hostdata->request_limit, -1);
1182 purge_requests(hostdata, DID_REQUEUE); 1187 purge_requests(hostdata, DID_REQUEUE);
1183 if (ibmvscsi_reenable_crq_queue(&hostdata->queue, 1188 if (ibmvscsi_reenable_crq_queue(&hostdata->queue,
1184 hostdata) == 0) 1189 hostdata) == 0)
@@ -1226,7 +1231,7 @@ void ibmvscsi_handle_crq(struct viosrp_crq *crq,
1226 } 1231 }
1227 1232
1228 if (crq->format == VIOSRP_SRP_FORMAT) 1233 if (crq->format == VIOSRP_SRP_FORMAT)
1229 atomic_add(evt_struct->xfer_iu->srp.rsp.request_limit_delta, 1234 atomic_add(evt_struct->xfer_iu->srp.rsp.req_lim_delta,
1230 &hostdata->request_limit); 1235 &hostdata->request_limit);
1231 1236
1232 if (evt_struct->done) 1237 if (evt_struct->done)
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.h b/drivers/scsi/ibmvscsi/ibmvscsi.h
index 4550d71e4744..5c6d93582929 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.h
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.h
@@ -68,7 +68,7 @@ struct srp_event_struct {
68 void (*cmnd_done) (struct scsi_cmnd *); 68 void (*cmnd_done) (struct scsi_cmnd *);
69 struct completion comp; 69 struct completion comp;
70 union viosrp_iu *sync_srp; 70 union viosrp_iu *sync_srp;
71 struct memory_descriptor *ext_list; 71 struct srp_direct_buf *ext_list;
72 dma_addr_t ext_list_token; 72 dma_addr_t ext_list_token;
73}; 73};
74 74
diff --git a/drivers/scsi/ibmvscsi/rpa_vscsi.c b/drivers/scsi/ibmvscsi/rpa_vscsi.c
index f47dd87c05e7..1a9992bdfef8 100644
--- a/drivers/scsi/ibmvscsi/rpa_vscsi.c
+++ b/drivers/scsi/ibmvscsi/rpa_vscsi.c
@@ -34,7 +34,6 @@
34#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include "ibmvscsi.h" 36#include "ibmvscsi.h"
37#include "srp.h"
38 37
39static char partition_name[97] = "UNKNOWN"; 38static char partition_name[97] = "UNKNOWN";
40static unsigned int partition_number = -1; 39static unsigned int partition_number = -1;
@@ -80,7 +79,7 @@ void ibmvscsi_release_crq_queue(struct crq_queue *queue,
80 tasklet_kill(&hostdata->srp_task); 79 tasklet_kill(&hostdata->srp_task);
81 do { 80 do {
82 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); 81 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
83 } while ((rc == H_Busy) || (H_isLongBusy(rc))); 82 } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
84 dma_unmap_single(hostdata->dev, 83 dma_unmap_single(hostdata->dev,
85 queue->msg_token, 84 queue->msg_token,
86 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL); 85 queue->size * sizeof(*queue->msgs), DMA_BIDIRECTIONAL);
@@ -230,7 +229,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
230 rc = plpar_hcall_norets(H_REG_CRQ, 229 rc = plpar_hcall_norets(H_REG_CRQ,
231 vdev->unit_address, 230 vdev->unit_address,
232 queue->msg_token, PAGE_SIZE); 231 queue->msg_token, PAGE_SIZE);
233 if (rc == H_Resource) 232 if (rc == H_RESOURCE)
234 /* maybe kexecing and resource is busy. try a reset */ 233 /* maybe kexecing and resource is busy. try a reset */
235 rc = ibmvscsi_reset_crq_queue(queue, 234 rc = ibmvscsi_reset_crq_queue(queue,
236 hostdata); 235 hostdata);
@@ -269,7 +268,7 @@ int ibmvscsi_init_crq_queue(struct crq_queue *queue,
269 req_irq_failed: 268 req_irq_failed:
270 do { 269 do {
271 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); 270 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
272 } while ((rc == H_Busy) || (H_isLongBusy(rc))); 271 } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
273 reg_crq_failed: 272 reg_crq_failed:
274 dma_unmap_single(hostdata->dev, 273 dma_unmap_single(hostdata->dev,
275 queue->msg_token, 274 queue->msg_token,
@@ -295,7 +294,7 @@ int ibmvscsi_reenable_crq_queue(struct crq_queue *queue,
295 /* Re-enable the CRQ */ 294 /* Re-enable the CRQ */
296 do { 295 do {
297 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address); 296 rc = plpar_hcall_norets(H_ENABLE_CRQ, vdev->unit_address);
298 } while ((rc == H_InProgress) || (rc == H_Busy) || (H_isLongBusy(rc))); 297 } while ((rc == H_IN_PROGRESS) || (rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
299 298
300 if (rc) 299 if (rc)
301 printk(KERN_ERR "ibmvscsi: Error %d enabling adapter\n", rc); 300 printk(KERN_ERR "ibmvscsi: Error %d enabling adapter\n", rc);
@@ -317,7 +316,7 @@ int ibmvscsi_reset_crq_queue(struct crq_queue *queue,
317 /* Close the CRQ */ 316 /* Close the CRQ */
318 do { 317 do {
319 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address); 318 rc = plpar_hcall_norets(H_FREE_CRQ, vdev->unit_address);
320 } while ((rc == H_Busy) || (H_isLongBusy(rc))); 319 } while ((rc == H_BUSY) || (H_IS_LONG_BUSY(rc)));
321 320
322 /* Clean out the queue */ 321 /* Clean out the queue */
323 memset(queue->msgs, 0x00, PAGE_SIZE); 322 memset(queue->msgs, 0x00, PAGE_SIZE);
diff --git a/drivers/scsi/ibmvscsi/srp.h b/drivers/scsi/ibmvscsi/srp.h
deleted file mode 100644
index 7d8e4c4accb9..000000000000
--- a/drivers/scsi/ibmvscsi/srp.h
+++ /dev/null
@@ -1,227 +0,0 @@
1/*****************************************************************************/
2/* srp.h -- SCSI RDMA Protocol definitions */
3/* */
4/* Written By: Colin Devilbis, IBM Corporation */
5/* */
6/* Copyright (C) 2003 IBM Corporation */
7/* */
8/* This program is free software; you can redistribute it and/or modify */
9/* it under the terms of the GNU General Public License as published by */
10/* the Free Software Foundation; either version 2 of the License, or */
11/* (at your option) any later version. */
12/* */
13/* This program is distributed in the hope that it will be useful, */
14/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16/* GNU General Public License for more details. */
17/* */
18/* You should have received a copy of the GNU General Public License */
19/* along with this program; if not, write to the Free Software */
20/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21/* */
22/* */
23/* This file contains structures and definitions for the SCSI RDMA Protocol */
24/* (SRP) as defined in the T10 standard available at www.t10.org. This */
25/* file was based on the 16a version of the standard */
26/* */
27/*****************************************************************************/
28#ifndef SRP_H
29#define SRP_H
30
31#define SRP_VERSION "16.a"
32
33#define PACKED __attribute__((packed))
34
35enum srp_types {
36 SRP_LOGIN_REQ_TYPE = 0x00,
37 SRP_LOGIN_RSP_TYPE = 0xC0,
38 SRP_LOGIN_REJ_TYPE = 0xC2,
39 SRP_I_LOGOUT_TYPE = 0x03,
40 SRP_T_LOGOUT_TYPE = 0x80,
41 SRP_TSK_MGMT_TYPE = 0x01,
42 SRP_CMD_TYPE = 0x02,
43 SRP_RSP_TYPE = 0xC1,
44 SRP_CRED_REQ_TYPE = 0x81,
45 SRP_CRED_RSP_TYPE = 0x41,
46 SRP_AER_REQ_TYPE = 0x82,
47 SRP_AER_RSP_TYPE = 0x42
48};
49
50enum srp_descriptor_formats {
51 SRP_NO_BUFFER = 0x00,
52 SRP_DIRECT_BUFFER = 0x01,
53 SRP_INDIRECT_BUFFER = 0x02
54};
55
56struct memory_descriptor {
57 u64 virtual_address;
58 u32 memory_handle;
59 u32 length;
60};
61
62struct indirect_descriptor {
63 struct memory_descriptor head;
64 u32 total_length;
65 struct memory_descriptor list[1] PACKED;
66};
67
68struct srp_generic {
69 u8 type;
70 u8 reserved1[7];
71 u64 tag;
72};
73
74struct srp_login_req {
75 u8 type;
76 u8 reserved1[7];
77 u64 tag;
78 u32 max_requested_initiator_to_target_iulen;
79 u32 reserved2;
80 u16 required_buffer_formats;
81 u8 reserved3:6;
82 u8 multi_channel_action:2;
83 u8 reserved4;
84 u32 reserved5;
85 u8 initiator_port_identifier[16];
86 u8 target_port_identifier[16];
87};
88
89struct srp_login_rsp {
90 u8 type;
91 u8 reserved1[3];
92 u32 request_limit_delta;
93 u64 tag;
94 u32 max_initiator_to_target_iulen;
95 u32 max_target_to_initiator_iulen;
96 u16 supported_buffer_formats;
97 u8 reserved2:6;
98 u8 multi_channel_result:2;
99 u8 reserved3;
100 u8 reserved4[24];
101};
102
103struct srp_login_rej {
104 u8 type;
105 u8 reserved1[3];
106 u32 reason;
107 u64 tag;
108 u64 reserved2;
109 u16 supported_buffer_formats;
110 u8 reserved3[6];
111};
112
113struct srp_i_logout {
114 u8 type;
115 u8 reserved1[7];
116 u64 tag;
117};
118
119struct srp_t_logout {
120 u8 type;
121 u8 reserved1[3];
122 u32 reason;
123 u64 tag;
124};
125
126struct srp_tsk_mgmt {
127 u8 type;
128 u8 reserved1[7];
129 u64 tag;
130 u32 reserved2;
131 u64 lun PACKED;
132 u8 reserved3;
133 u8 reserved4;
134 u8 task_mgmt_flags;
135 u8 reserved5;
136 u64 managed_task_tag;
137 u64 reserved6;
138};
139
140struct srp_cmd {
141 u8 type;
142 u32 reserved1 PACKED;
143 u8 data_out_format:4;
144 u8 data_in_format:4;
145 u8 data_out_count;
146 u8 data_in_count;
147 u64 tag;
148 u32 reserved2;
149 u64 lun PACKED;
150 u8 reserved3;
151 u8 reserved4:5;
152 u8 task_attribute:3;
153 u8 reserved5;
154 u8 additional_cdb_len;
155 u8 cdb[16];
156 u8 additional_data[0x100 - 0x30];
157};
158
159struct srp_rsp {
160 u8 type;
161 u8 reserved1[3];
162 u32 request_limit_delta;
163 u64 tag;
164 u16 reserved2;
165 u8 reserved3:2;
166 u8 diunder:1;
167 u8 diover:1;
168 u8 dounder:1;
169 u8 doover:1;
170 u8 snsvalid:1;
171 u8 rspvalid:1;
172 u8 status;
173 u32 data_in_residual_count;
174 u32 data_out_residual_count;
175 u32 sense_data_list_length;
176 u32 response_data_list_length;
177 u8 sense_and_response_data[18];
178};
179
180struct srp_cred_req {
181 u8 type;
182 u8 reserved1[3];
183 u32 request_limit_delta;
184 u64 tag;
185};
186
187struct srp_cred_rsp {
188 u8 type;
189 u8 reserved1[7];
190 u64 tag;
191};
192
193struct srp_aer_req {
194 u8 type;
195 u8 reserved1[3];
196 u32 request_limit_delta;
197 u64 tag;
198 u32 reserved2;
199 u64 lun;
200 u32 sense_data_list_length;
201 u32 reserved3;
202 u8 sense_data[20];
203};
204
205struct srp_aer_rsp {
206 u8 type;
207 u8 reserved1[7];
208 u64 tag;
209};
210
211union srp_iu {
212 struct srp_generic generic;
213 struct srp_login_req login_req;
214 struct srp_login_rsp login_rsp;
215 struct srp_login_rej login_rej;
216 struct srp_i_logout i_logout;
217 struct srp_t_logout t_logout;
218 struct srp_tsk_mgmt tsk_mgmt;
219 struct srp_cmd cmd;
220 struct srp_rsp rsp;
221 struct srp_cred_req cred_req;
222 struct srp_cred_rsp cred_rsp;
223 struct srp_aer_req aer_req;
224 struct srp_aer_rsp aer_rsp;
225};
226
227#endif
diff --git a/drivers/scsi/ibmvscsi/viosrp.h b/drivers/scsi/ibmvscsi/viosrp.h
index 6a6bba8a2f34..90f1a61283ad 100644
--- a/drivers/scsi/ibmvscsi/viosrp.h
+++ b/drivers/scsi/ibmvscsi/viosrp.h
@@ -33,7 +33,22 @@
33/*****************************************************************************/ 33/*****************************************************************************/
34#ifndef VIOSRP_H 34#ifndef VIOSRP_H
35#define VIOSRP_H 35#define VIOSRP_H
36#include "srp.h" 36#include <scsi/srp.h>
37
38#define SRP_VERSION "16.a"
39#define SRP_MAX_IU_LEN 256
40
41union srp_iu {
42 struct srp_login_req login_req;
43 struct srp_login_rsp login_rsp;
44 struct srp_login_rej login_rej;
45 struct srp_i_logout i_logout;
46 struct srp_t_logout t_logout;
47 struct srp_tsk_mgmt tsk_mgmt;
48 struct srp_cmd cmd;
49 struct srp_rsp rsp;
50 u8 reserved[SRP_MAX_IU_LEN];
51};
37 52
38enum viosrp_crq_formats { 53enum viosrp_crq_formats {
39 VIOSRP_SRP_FORMAT = 0x01, 54 VIOSRP_SRP_FORMAT = 0x01,
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 5890e5f92d82..8b80e59c8c52 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -164,29 +164,6 @@ MODULE_PARM_DESC(auto_create, "Auto-create single device RAID 0 arrays when init
164MODULE_LICENSE("GPL"); 164MODULE_LICENSE("GPL");
165MODULE_VERSION(IPR_DRIVER_VERSION); 165MODULE_VERSION(IPR_DRIVER_VERSION);
166 166
167static const char *ipr_gpdd_dev_end_states[] = {
168 "Command complete",
169 "Terminated by host",
170 "Terminated by device reset",
171 "Terminated by bus reset",
172 "Unknown",
173 "Command not started"
174};
175
176static const char *ipr_gpdd_dev_bus_phases[] = {
177 "Bus free",
178 "Arbitration",
179 "Selection",
180 "Message out",
181 "Command",
182 "Message in",
183 "Data out",
184 "Data in",
185 "Status",
186 "Reselection",
187 "Unknown"
188};
189
190/* A constant array of IOASCs/URCs/Error Messages */ 167/* A constant array of IOASCs/URCs/Error Messages */
191static const 168static const
192struct ipr_error_table_t ipr_error_table[] = { 169struct ipr_error_table_t ipr_error_table[] = {
@@ -869,8 +846,8 @@ static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
869 846
870 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) { 847 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
871 if (res->sdev) { 848 if (res->sdev) {
872 res->sdev->hostdata = NULL;
873 res->del_from_ml = 1; 849 res->del_from_ml = 1;
850 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
874 if (ioa_cfg->allow_ml_add_del) 851 if (ioa_cfg->allow_ml_add_del)
875 schedule_work(&ioa_cfg->work_q); 852 schedule_work(&ioa_cfg->work_q);
876 } else 853 } else
@@ -1356,8 +1333,8 @@ static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
1356 return; 1333 return;
1357 1334
1358 if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) { 1335 if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
1359 ipr_res_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr, 1336 ipr_ra_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
1360 "%s\n", ipr_error_table[error_index].error); 1337 "%s\n", ipr_error_table[error_index].error);
1361 } else { 1338 } else {
1362 dev_err(&ioa_cfg->pdev->dev, "%s\n", 1339 dev_err(&ioa_cfg->pdev->dev, "%s\n",
1363 ipr_error_table[error_index].error); 1340 ipr_error_table[error_index].error);
@@ -2107,7 +2084,6 @@ restart:
2107 did_work = 1; 2084 did_work = 1;
2108 sdev = res->sdev; 2085 sdev = res->sdev;
2109 if (!scsi_device_get(sdev)) { 2086 if (!scsi_device_get(sdev)) {
2110 res->sdev = NULL;
2111 list_move_tail(&res->queue, &ioa_cfg->free_res_q); 2087 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
2112 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 2088 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2113 scsi_remove_device(sdev); 2089 scsi_remove_device(sdev);
@@ -2124,6 +2100,7 @@ restart:
2124 bus = res->cfgte.res_addr.bus; 2100 bus = res->cfgte.res_addr.bus;
2125 target = res->cfgte.res_addr.target; 2101 target = res->cfgte.res_addr.target;
2126 lun = res->cfgte.res_addr.lun; 2102 lun = res->cfgte.res_addr.lun;
2103 res->add_to_ml = 0;
2127 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 2104 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2128 scsi_add_device(ioa_cfg->host, bus, target, lun); 2105 scsi_add_device(ioa_cfg->host, bus, target, lun);
2129 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 2106 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
@@ -3214,7 +3191,7 @@ static int ipr_slave_configure(struct scsi_device *sdev)
3214 sdev->timeout = IPR_VSET_RW_TIMEOUT; 3191 sdev->timeout = IPR_VSET_RW_TIMEOUT;
3215 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS); 3192 blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
3216 } 3193 }
3217 if (IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data)) 3194 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
3218 sdev->allow_restart = 1; 3195 sdev->allow_restart = 1;
3219 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 3196 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
3220 } 3197 }
@@ -3304,6 +3281,44 @@ static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
3304} 3281}
3305 3282
3306/** 3283/**
3284 * ipr_device_reset - Reset the device
3285 * @ioa_cfg: ioa config struct
3286 * @res: resource entry struct
3287 *
3288 * This function issues a device reset to the affected device.
3289 * If the device is a SCSI device, a LUN reset will be sent
3290 * to the device first. If that does not work, a target reset
3291 * will be sent.
3292 *
3293 * Return value:
3294 * 0 on success / non-zero on failure
3295 **/
3296static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
3297 struct ipr_resource_entry *res)
3298{
3299 struct ipr_cmnd *ipr_cmd;
3300 struct ipr_ioarcb *ioarcb;
3301 struct ipr_cmd_pkt *cmd_pkt;
3302 u32 ioasc;
3303
3304 ENTER;
3305 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3306 ioarcb = &ipr_cmd->ioarcb;
3307 cmd_pkt = &ioarcb->cmd_pkt;
3308
3309 ioarcb->res_handle = res->cfgte.res_handle;
3310 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3311 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3312
3313 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3314 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3315 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3316
3317 LEAVE;
3318 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
3319}
3320
3321/**
3307 * ipr_eh_dev_reset - Reset the device 3322 * ipr_eh_dev_reset - Reset the device
3308 * @scsi_cmd: scsi command struct 3323 * @scsi_cmd: scsi command struct
3309 * 3324 *
@@ -3319,8 +3334,7 @@ static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3319 struct ipr_cmnd *ipr_cmd; 3334 struct ipr_cmnd *ipr_cmd;
3320 struct ipr_ioa_cfg *ioa_cfg; 3335 struct ipr_ioa_cfg *ioa_cfg;
3321 struct ipr_resource_entry *res; 3336 struct ipr_resource_entry *res;
3322 struct ipr_cmd_pkt *cmd_pkt; 3337 int rc;
3323 u32 ioasc;
3324 3338
3325 ENTER; 3339 ENTER;
3326 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata; 3340 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
@@ -3347,25 +3361,12 @@ static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
3347 } 3361 }
3348 3362
3349 res->resetting_device = 1; 3363 res->resetting_device = 1;
3350 3364 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
3351 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg); 3365 rc = ipr_device_reset(ioa_cfg, res);
3352
3353 ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
3354 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
3355 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
3356 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
3357
3358 ipr_sdev_err(scsi_cmd->device, "Resetting device\n");
3359 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
3360
3361 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3362
3363 res->resetting_device = 0; 3366 res->resetting_device = 0;
3364 3367
3365 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
3366
3367 LEAVE; 3368 LEAVE;
3368 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS); 3369 return (rc ? FAILED : SUCCESS);
3369} 3370}
3370 3371
3371static int ipr_eh_dev_reset(struct scsi_cmnd * cmd) 3372static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
@@ -3440,7 +3441,7 @@ static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
3440 return; 3441 return;
3441 } 3442 }
3442 3443
3443 ipr_sdev_err(ipr_cmd->u.sdev, "Abort timed out. Resetting bus\n"); 3444 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
3444 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg); 3445 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
3445 ipr_cmd->sibling = reset_cmd; 3446 ipr_cmd->sibling = reset_cmd;
3446 reset_cmd->sibling = ipr_cmd; 3447 reset_cmd->sibling = ipr_cmd;
@@ -3504,7 +3505,8 @@ static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
3504 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS; 3505 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
3505 ipr_cmd->u.sdev = scsi_cmd->device; 3506 ipr_cmd->u.sdev = scsi_cmd->device;
3506 3507
3507 ipr_sdev_err(scsi_cmd->device, "Aborting command: %02X\n", scsi_cmd->cmnd[0]); 3508 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
3509 scsi_cmd->cmnd[0]);
3508 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT); 3510 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
3509 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc); 3511 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
3510 3512
@@ -3815,8 +3817,8 @@ static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
3815 3817
3816 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) { 3818 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
3817 scsi_cmd->result |= (DID_ERROR << 16); 3819 scsi_cmd->result |= (DID_ERROR << 16);
3818 ipr_sdev_err(scsi_cmd->device, 3820 scmd_printk(KERN_ERR, scsi_cmd,
3819 "Request Sense failed with IOASC: 0x%08X\n", ioasc); 3821 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
3820 } else { 3822 } else {
3821 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer, 3823 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
3822 SCSI_SENSE_BUFFERSIZE); 3824 SCSI_SENSE_BUFFERSIZE);
@@ -3938,6 +3940,7 @@ static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
3938 * ipr_dump_ioasa - Dump contents of IOASA 3940 * ipr_dump_ioasa - Dump contents of IOASA
3939 * @ioa_cfg: ioa config struct 3941 * @ioa_cfg: ioa config struct
3940 * @ipr_cmd: ipr command struct 3942 * @ipr_cmd: ipr command struct
3943 * @res: resource entry struct
3941 * 3944 *
3942 * This function is invoked by the interrupt handler when ops 3945 * This function is invoked by the interrupt handler when ops
3943 * fail. It will log the IOASA if appropriate. Only called 3946 * fail. It will log the IOASA if appropriate. Only called
@@ -3947,7 +3950,7 @@ static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
3947 * none 3950 * none
3948 **/ 3951 **/
3949static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg, 3952static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
3950 struct ipr_cmnd *ipr_cmd) 3953 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
3951{ 3954{
3952 int i; 3955 int i;
3953 u16 data_len; 3956 u16 data_len;
@@ -3975,16 +3978,7 @@ static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
3975 return; 3978 return;
3976 } 3979 }
3977 3980
3978 ipr_sdev_err(ipr_cmd->scsi_cmd->device, "%s\n", 3981 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
3979 ipr_error_table[error_index].error);
3980
3981 if ((ioasa->u.gpdd.end_state <= ARRAY_SIZE(ipr_gpdd_dev_end_states)) &&
3982 (ioasa->u.gpdd.bus_phase <= ARRAY_SIZE(ipr_gpdd_dev_bus_phases))) {
3983 ipr_sdev_err(ipr_cmd->scsi_cmd->device,
3984 "Device End state: %s Phase: %s\n",
3985 ipr_gpdd_dev_end_states[ioasa->u.gpdd.end_state],
3986 ipr_gpdd_dev_bus_phases[ioasa->u.gpdd.bus_phase]);
3987 }
3988 3982
3989 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len)) 3983 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
3990 data_len = sizeof(struct ipr_ioasa); 3984 data_len = sizeof(struct ipr_ioasa);
@@ -4141,7 +4135,7 @@ static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
4141 } 4135 }
4142 4136
4143 if (ipr_is_gscsi(res)) 4137 if (ipr_is_gscsi(res))
4144 ipr_dump_ioasa(ioa_cfg, ipr_cmd); 4138 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4145 else 4139 else
4146 ipr_gen_sense(ipr_cmd); 4140 ipr_gen_sense(ipr_cmd);
4147 4141
@@ -4540,7 +4534,7 @@ static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
4540 ipr_cmd->job_step = ipr_ioa_reset_done; 4534 ipr_cmd->job_step = ipr_ioa_reset_done;
4541 4535
4542 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) { 4536 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
4543 if (!IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data)) 4537 if (!ipr_is_scsi_disk(res))
4544 continue; 4538 continue;
4545 4539
4546 ipr_cmd->u.res = res; 4540 ipr_cmd->u.res = res;
@@ -4980,7 +4974,7 @@ static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
4980 list_for_each_entry_safe(res, temp, &old_res, queue) { 4974 list_for_each_entry_safe(res, temp, &old_res, queue) {
4981 if (res->sdev) { 4975 if (res->sdev) {
4982 res->del_from_ml = 1; 4976 res->del_from_ml = 1;
4983 res->sdev->hostdata = NULL; 4977 res->cfgte.res_handle = IPR_INVALID_RES_HANDLE;
4984 list_move_tail(&res->queue, &ioa_cfg->used_res_q); 4978 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
4985 } else { 4979 } else {
4986 list_move_tail(&res->queue, &ioa_cfg->free_res_q); 4980 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index fd360bfe56dd..1ad24df69d70 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -36,8 +36,8 @@
36/* 36/*
37 * Literals 37 * Literals
38 */ 38 */
39#define IPR_DRIVER_VERSION "2.1.2" 39#define IPR_DRIVER_VERSION "2.1.3"
40#define IPR_DRIVER_DATE "(February 8, 2006)" 40#define IPR_DRIVER_DATE "(March 29, 2006)"
41 41
42/* 42/*
43 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding 43 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding
@@ -133,6 +133,7 @@
133#define IPR_MAX_SCSI_RATE(width) ((320 * 10) / ((width) / 8)) 133#define IPR_MAX_SCSI_RATE(width) ((320 * 10) / ((width) / 8))
134 134
135#define IPR_IOA_RES_HANDLE 0xffffffff 135#define IPR_IOA_RES_HANDLE 0xffffffff
136#define IPR_INVALID_RES_HANDLE 0
136#define IPR_IOA_RES_ADDR 0x00ffffff 137#define IPR_IOA_RES_ADDR 0x00ffffff
137 138
138/* 139/*
@@ -1191,30 +1192,17 @@ struct ipr_ucode_image_header {
1191 */ 1192 */
1192#define ipr_err(...) printk(KERN_ERR IPR_NAME ": "__VA_ARGS__) 1193#define ipr_err(...) printk(KERN_ERR IPR_NAME ": "__VA_ARGS__)
1193#define ipr_info(...) printk(KERN_INFO IPR_NAME ": "__VA_ARGS__) 1194#define ipr_info(...) printk(KERN_INFO IPR_NAME ": "__VA_ARGS__)
1194#define ipr_crit(...) printk(KERN_CRIT IPR_NAME ": "__VA_ARGS__)
1195#define ipr_warn(...) printk(KERN_WARNING IPR_NAME": "__VA_ARGS__)
1196#define ipr_dbg(...) IPR_DBG_CMD(printk(KERN_INFO IPR_NAME ": "__VA_ARGS__)) 1195#define ipr_dbg(...) IPR_DBG_CMD(printk(KERN_INFO IPR_NAME ": "__VA_ARGS__))
1197 1196
1198#define ipr_sdev_printk(level, sdev, fmt, args...) \ 1197#define ipr_ra_printk(level, ioa_cfg, ra, fmt, ...) \
1199 sdev_printk(level, sdev, fmt, ## args) 1198 printk(level IPR_NAME ": %d:%d:%d:%d: " fmt, (ioa_cfg)->host->host_no, \
1199 (ra).bus, (ra).target, (ra).lun, ##__VA_ARGS__)
1200 1200
1201#define ipr_sdev_err(sdev, fmt, ...) \ 1201#define ipr_ra_err(ioa_cfg, ra, fmt, ...) \
1202 ipr_sdev_printk(KERN_ERR, sdev, fmt, ##__VA_ARGS__) 1202 ipr_ra_printk(KERN_ERR, ioa_cfg, ra, fmt, ##__VA_ARGS__)
1203
1204#define ipr_sdev_info(sdev, fmt, ...) \
1205 ipr_sdev_printk(KERN_INFO, sdev, fmt, ##__VA_ARGS__)
1206
1207#define ipr_sdev_dbg(sdev, fmt, ...) \
1208 IPR_DBG_CMD(ipr_sdev_printk(KERN_INFO, sdev, fmt, ##__VA_ARGS__))
1209
1210#define ipr_res_printk(level, ioa_cfg, res, fmt, ...) \
1211 printk(level IPR_NAME ": %d:%d:%d:%d: " fmt, ioa_cfg->host->host_no, \
1212 res.bus, res.target, res.lun, ##__VA_ARGS__)
1213 1203
1214#define ipr_res_err(ioa_cfg, res, fmt, ...) \ 1204#define ipr_res_err(ioa_cfg, res, fmt, ...) \
1215 ipr_res_printk(KERN_ERR, ioa_cfg, res, fmt, ##__VA_ARGS__) 1205 ipr_ra_err(ioa_cfg, (res)->cfgte.res_addr, fmt, ##__VA_ARGS__)
1216#define ipr_res_dbg(ioa_cfg, res, fmt, ...) \
1217 IPR_DBG_CMD(ipr_res_printk(KERN_INFO, ioa_cfg, res, fmt, ##__VA_ARGS__))
1218 1206
1219#define ipr_phys_res_err(ioa_cfg, res, fmt, ...) \ 1207#define ipr_phys_res_err(ioa_cfg, res, fmt, ...) \
1220{ \ 1208{ \
@@ -1304,6 +1292,22 @@ static inline int ipr_is_gscsi(struct ipr_resource_entry *res)
1304} 1292}
1305 1293
1306/** 1294/**
1295 * ipr_is_scsi_disk - Determine if a resource is a SCSI disk
1296 * @res: resource entry struct
1297 *
1298 * Return value:
1299 * 1 if SCSI disk / 0 if not SCSI disk
1300 **/
1301static inline int ipr_is_scsi_disk(struct ipr_resource_entry *res)
1302{
1303 if (ipr_is_af_dasd_device(res) ||
1304 (ipr_is_gscsi(res) && IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data)))
1305 return 1;
1306 else
1307 return 0;
1308}
1309
1310/**
1307 * ipr_is_naca_model - Determine if a resource is using NACA queueing model 1311 * ipr_is_naca_model - Determine if a resource is using NACA queueing model
1308 * @res: resource entry struct 1312 * @res: resource entry struct
1309 * 1313 *
diff --git a/drivers/scsi/lasi700.c b/drivers/scsi/lasi700.c
index 459a4daebece..eb7bd310cc82 100644
--- a/drivers/scsi/lasi700.c
+++ b/drivers/scsi/lasi700.c
@@ -112,7 +112,7 @@ lasi700_probe(struct parisc_device *dev)
112 112
113 hostdata->dev = &dev->dev; 113 hostdata->dev = &dev->dev;
114 dma_set_mask(&dev->dev, DMA_32BIT_MASK); 114 dma_set_mask(&dev->dev, DMA_32BIT_MASK);
115 hostdata->base = ioremap(base, 0x100); 115 hostdata->base = ioremap_nocache(base, 0x100);
116 hostdata->differential = 0; 116 hostdata->differential = 0;
117 117
118 if (dev->id.sversion == LASI_700_SVERSION) { 118 if (dev->id.sversion == LASI_700_SVERSION) {
diff --git a/drivers/scsi/libata-bmdma.c b/drivers/scsi/libata-bmdma.c
index 95d81d86d8b7..835dff0bafdc 100644
--- a/drivers/scsi/libata-bmdma.c
+++ b/drivers/scsi/libata-bmdma.c
@@ -703,6 +703,7 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
703 struct ata_probe_ent *probe_ent = 703 struct ata_probe_ent *probe_ent =
704 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 704 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
705 int p = 0; 705 int p = 0;
706 unsigned long bmdma;
706 707
707 if (!probe_ent) 708 if (!probe_ent)
708 return NULL; 709 return NULL;
@@ -716,7 +717,12 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
716 probe_ent->port[p].altstatus_addr = 717 probe_ent->port[p].altstatus_addr =
717 probe_ent->port[p].ctl_addr = 718 probe_ent->port[p].ctl_addr =
718 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; 719 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS;
719 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4); 720 bmdma = pci_resource_start(pdev, 4);
721 if (bmdma) {
722 if (inb(bmdma + 2) & 0x80)
723 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX;
724 probe_ent->port[p].bmdma_addr = bmdma;
725 }
720 ata_std_ports(&probe_ent->port[p]); 726 ata_std_ports(&probe_ent->port[p]);
721 p++; 727 p++;
722 } 728 }
@@ -726,7 +732,13 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
726 probe_ent->port[p].altstatus_addr = 732 probe_ent->port[p].altstatus_addr =
727 probe_ent->port[p].ctl_addr = 733 probe_ent->port[p].ctl_addr =
728 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS; 734 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS;
729 probe_ent->port[p].bmdma_addr = pci_resource_start(pdev, 4) + 8; 735 bmdma = pci_resource_start(pdev, 4);
736 if (bmdma) {
737 bmdma += 8;
738 if(inb(bmdma + 2) & 0x80)
739 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX;
740 probe_ent->port[p].bmdma_addr = bmdma;
741 }
730 ata_std_ports(&probe_ent->port[p]); 742 ata_std_ports(&probe_ent->port[p]);
731 p++; 743 p++;
732 } 744 }
@@ -740,6 +752,7 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
740 struct ata_port_info *port, int port_num) 752 struct ata_port_info *port, int port_num)
741{ 753{
742 struct ata_probe_ent *probe_ent; 754 struct ata_probe_ent *probe_ent;
755 unsigned long bmdma;
743 756
744 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port); 757 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port);
745 if (!probe_ent) 758 if (!probe_ent)
@@ -766,8 +779,13 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
766 break; 779 break;
767 } 780 }
768 781
769 probe_ent->port[0].bmdma_addr = 782 bmdma = pci_resource_start(pdev, 4);
770 pci_resource_start(pdev, 4) + 8 * port_num; 783 if (bmdma != 0) {
784 bmdma += 8 * port_num;
785 probe_ent->port[0].bmdma_addr = bmdma;
786 if (inb(bmdma + 2) & 0x80)
787 probe_ent->host_set_flags |= ATA_HOST_SIMPLEX;
788 }
771 ata_std_ports(&probe_ent->port[0]); 789 ata_std_ports(&probe_ent->port[0]);
772 790
773 return probe_ent; 791 return probe_ent;
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index d279666dcb38..bd147207f25d 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -62,7 +62,9 @@
62#include "libata.h" 62#include "libata.h"
63 63
64static unsigned int ata_dev_init_params(struct ata_port *ap, 64static unsigned int ata_dev_init_params(struct ata_port *ap,
65 struct ata_device *dev); 65 struct ata_device *dev,
66 u16 heads,
67 u16 sectors);
66static void ata_set_mode(struct ata_port *ap); 68static void ata_set_mode(struct ata_port *ap);
67static unsigned int ata_dev_set_xfermode(struct ata_port *ap, 69static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
68 struct ata_device *dev); 70 struct ata_device *dev);
@@ -276,7 +278,7 @@ static void ata_unpack_xfermask(unsigned int xfer_mask,
276} 278}
277 279
278static const struct ata_xfer_ent { 280static const struct ata_xfer_ent {
279 unsigned int shift, bits; 281 int shift, bits;
280 u8 base; 282 u8 base;
281} ata_xfer_tbl[] = { 283} ata_xfer_tbl[] = {
282 { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 }, 284 { ATA_SHIFT_PIO, ATA_BITS_PIO, XFER_PIO_0 },
@@ -987,9 +989,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
987 qc->private_data = &wait; 989 qc->private_data = &wait;
988 qc->complete_fn = ata_qc_complete_internal; 990 qc->complete_fn = ata_qc_complete_internal;
989 991
990 qc->err_mask = ata_qc_issue(qc); 992 ata_qc_issue(qc);
991 if (qc->err_mask)
992 ata_qc_complete(qc);
993 993
994 spin_unlock_irqrestore(&ap->host_set->lock, flags); 994 spin_unlock_irqrestore(&ap->host_set->lock, flags);
995 995
@@ -1081,9 +1081,8 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1081 * 1081 *
1082 * Read ID data from the specified device. ATA_CMD_ID_ATA is 1082 * Read ID data from the specified device. ATA_CMD_ID_ATA is
1083 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI 1083 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
1084 * devices. This function also takes care of EDD signature 1084 * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS
1085 * misreporting (to be removed once EDD support is gone) and 1085 * for pre-ATA4 drives.
1086 * issues ATA_CMD_INIT_DEV_PARAMS for pre-ATA4 drives.
1087 * 1086 *
1088 * LOCKING: 1087 * LOCKING:
1089 * Kernel thread context (may sleep) 1088 * Kernel thread context (may sleep)
@@ -1095,7 +1094,6 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1095 unsigned int *p_class, int post_reset, u16 **p_id) 1094 unsigned int *p_class, int post_reset, u16 **p_id)
1096{ 1095{
1097 unsigned int class = *p_class; 1096 unsigned int class = *p_class;
1098 unsigned int using_edd;
1099 struct ata_taskfile tf; 1097 struct ata_taskfile tf;
1100 unsigned int err_mask = 0; 1098 unsigned int err_mask = 0;
1101 u16 *id; 1099 u16 *id;
@@ -1104,12 +1102,6 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1104 1102
1105 DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno); 1103 DPRINTK("ENTER, host %u, dev %u\n", ap->id, dev->devno);
1106 1104
1107 if (ap->ops->probe_reset ||
1108 ap->flags & (ATA_FLAG_SRST | ATA_FLAG_SATA_RESET))
1109 using_edd = 0;
1110 else
1111 using_edd = 1;
1112
1113 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */ 1105 ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
1114 1106
1115 id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL); 1107 id = kmalloc(sizeof(id[0]) * ATA_ID_WORDS, GFP_KERNEL);
@@ -1139,39 +1131,16 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1139 1131
1140 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE, 1132 err_mask = ata_exec_internal(ap, dev, &tf, DMA_FROM_DEVICE,
1141 id, sizeof(id[0]) * ATA_ID_WORDS); 1133 id, sizeof(id[0]) * ATA_ID_WORDS);
1142
1143 if (err_mask) { 1134 if (err_mask) {
1144 rc = -EIO; 1135 rc = -EIO;
1145 reason = "I/O error"; 1136 reason = "I/O error";
1146
1147 if (err_mask & ~AC_ERR_DEV)
1148 goto err_out;
1149
1150 /*
1151 * arg! EDD works for all test cases, but seems to return
1152 * the ATA signature for some ATAPI devices. Until the
1153 * reason for this is found and fixed, we fix up the mess
1154 * here. If IDENTIFY DEVICE returns command aborted
1155 * (as ATAPI devices do), then we issue an
1156 * IDENTIFY PACKET DEVICE.
1157 *
1158 * ATA software reset (SRST, the default) does not appear
1159 * to have this problem.
1160 */
1161 if ((using_edd) && (class == ATA_DEV_ATA)) {
1162 u8 err = tf.feature;
1163 if (err & ATA_ABORTED) {
1164 class = ATA_DEV_ATAPI;
1165 goto retry;
1166 }
1167 }
1168 goto err_out; 1137 goto err_out;
1169 } 1138 }
1170 1139
1171 swap_buf_le16(id, ATA_ID_WORDS); 1140 swap_buf_le16(id, ATA_ID_WORDS);
1172 1141
1173 /* sanity check */ 1142 /* sanity check */
1174 if ((class == ATA_DEV_ATA) != ata_id_is_ata(id)) { 1143 if ((class == ATA_DEV_ATA) != (ata_id_is_ata(id) | ata_id_is_cfa(id))) {
1175 rc = -EINVAL; 1144 rc = -EINVAL;
1176 reason = "device reports illegal type"; 1145 reason = "device reports illegal type";
1177 goto err_out; 1146 goto err_out;
@@ -1187,7 +1156,7 @@ static int ata_dev_read_id(struct ata_port *ap, struct ata_device *dev,
1187 * Some drives were very specific about that exact sequence. 1156 * Some drives were very specific about that exact sequence.
1188 */ 1157 */
1189 if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) { 1158 if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) {
1190 err_mask = ata_dev_init_params(ap, dev); 1159 err_mask = ata_dev_init_params(ap, dev, id[3], id[6]);
1191 if (err_mask) { 1160 if (err_mask) {
1192 rc = -EIO; 1161 rc = -EIO;
1193 reason = "INIT_DEV_PARAMS failed"; 1162 reason = "INIT_DEV_PARAMS failed";
@@ -1440,7 +1409,11 @@ static int ata_bus_probe(struct ata_port *ap)
1440 if (!found) 1409 if (!found)
1441 goto err_out_disable; 1410 goto err_out_disable;
1442 1411
1443 ata_set_mode(ap); 1412 if (ap->ops->set_mode)
1413 ap->ops->set_mode(ap);
1414 else
1415 ata_set_mode(ap);
1416
1444 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1417 if (ap->flags & ATA_FLAG_PORT_DISABLED)
1445 goto err_out_disable; 1418 goto err_out_disable;
1446 1419
@@ -1845,7 +1818,7 @@ static void ata_host_set_dma(struct ata_port *ap)
1845 */ 1818 */
1846static void ata_set_mode(struct ata_port *ap) 1819static void ata_set_mode(struct ata_port *ap)
1847{ 1820{
1848 int i, rc; 1821 int i, rc, used_dma = 0;
1849 1822
1850 /* step 1: calculate xfer_mask */ 1823 /* step 1: calculate xfer_mask */
1851 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1824 for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -1863,6 +1836,9 @@ static void ata_set_mode(struct ata_port *ap)
1863 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask); 1836 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
1864 dev->pio_mode = ata_xfer_mask2mode(pio_mask); 1837 dev->pio_mode = ata_xfer_mask2mode(pio_mask);
1865 dev->dma_mode = ata_xfer_mask2mode(dma_mask); 1838 dev->dma_mode = ata_xfer_mask2mode(dma_mask);
1839
1840 if (dev->dma_mode)
1841 used_dma = 1;
1866 } 1842 }
1867 1843
1868 /* step 2: always set host PIO timings */ 1844 /* step 2: always set host PIO timings */
@@ -1884,6 +1860,17 @@ static void ata_set_mode(struct ata_port *ap)
1884 goto err_out; 1860 goto err_out;
1885 } 1861 }
1886 1862
1863 /*
1864 * Record simplex status. If we selected DMA then the other
1865 * host channels are not permitted to do so.
1866 */
1867
1868 if (used_dma && (ap->host_set->flags & ATA_HOST_SIMPLEX))
1869 ap->host_set->simplex_claimed = 1;
1870
1871 /*
1872 * Chip specific finalisation
1873 */
1887 if (ap->ops->post_set_mode) 1874 if (ap->ops->post_set_mode)
1888 ap->ops->post_set_mode(ap); 1875 ap->ops->post_set_mode(ap);
1889 1876
@@ -2005,45 +1992,6 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
2005 ap->ops->dev_select(ap, 0); 1992 ap->ops->dev_select(ap, 0);
2006} 1993}
2007 1994
2008/**
2009 * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command.
2010 * @ap: Port to reset and probe
2011 *
2012 * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and
2013 * probe the bus. Not often used these days.
2014 *
2015 * LOCKING:
2016 * PCI/etc. bus probe sem.
2017 * Obtains host_set lock.
2018 *
2019 */
2020
2021static unsigned int ata_bus_edd(struct ata_port *ap)
2022{
2023 struct ata_taskfile tf;
2024 unsigned long flags;
2025
2026 /* set up execute-device-diag (bus reset) taskfile */
2027 /* also, take interrupts to a known state (disabled) */
2028 DPRINTK("execute-device-diag\n");
2029 ata_tf_init(ap, &tf, 0);
2030 tf.ctl |= ATA_NIEN;
2031 tf.command = ATA_CMD_EDD;
2032 tf.protocol = ATA_PROT_NODATA;
2033
2034 /* do bus reset */
2035 spin_lock_irqsave(&ap->host_set->lock, flags);
2036 ata_tf_to_host(ap, &tf);
2037 spin_unlock_irqrestore(&ap->host_set->lock, flags);
2038
2039 /* spec says at least 2ms. but who knows with those
2040 * crazy ATAPI devices...
2041 */
2042 msleep(150);
2043
2044 return ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
2045}
2046
2047static unsigned int ata_bus_softreset(struct ata_port *ap, 1995static unsigned int ata_bus_softreset(struct ata_port *ap,
2048 unsigned int devmask) 1996 unsigned int devmask)
2049{ 1997{
@@ -2078,13 +2026,12 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2078 */ 2026 */
2079 msleep(150); 2027 msleep(150);
2080 2028
2081
2082 /* Before we perform post reset processing we want to see if 2029 /* Before we perform post reset processing we want to see if
2083 the bus shows 0xFF because the odd clown forgets the D7 pulldown 2030 * the bus shows 0xFF because the odd clown forgets the D7
2084 resistor */ 2031 * pulldown resistor.
2085 2032 */
2086 if (ata_check_status(ap) == 0xFF) 2033 if (ata_check_status(ap) == 0xFF)
2087 return 1; /* Positive is failure for some reason */ 2034 return AC_ERR_OTHER;
2088 2035
2089 ata_bus_post_reset(ap, devmask); 2036 ata_bus_post_reset(ap, devmask);
2090 2037
@@ -2116,7 +2063,7 @@ void ata_bus_reset(struct ata_port *ap)
2116 struct ata_ioports *ioaddr = &ap->ioaddr; 2063 struct ata_ioports *ioaddr = &ap->ioaddr;
2117 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 2064 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
2118 u8 err; 2065 u8 err;
2119 unsigned int dev0, dev1 = 0, rc = 0, devmask = 0; 2066 unsigned int dev0, dev1 = 0, devmask = 0;
2120 2067
2121 DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no); 2068 DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no);
2122 2069
@@ -2139,18 +2086,8 @@ void ata_bus_reset(struct ata_port *ap)
2139 2086
2140 /* issue bus reset */ 2087 /* issue bus reset */
2141 if (ap->flags & ATA_FLAG_SRST) 2088 if (ap->flags & ATA_FLAG_SRST)
2142 rc = ata_bus_softreset(ap, devmask); 2089 if (ata_bus_softreset(ap, devmask))
2143 else if ((ap->flags & ATA_FLAG_SATA_RESET) == 0) { 2090 goto err_out;
2144 /* set up device control */
2145 if (ap->flags & ATA_FLAG_MMIO)
2146 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
2147 else
2148 outb(ap->ctl, ioaddr->ctl_addr);
2149 rc = ata_bus_edd(ap);
2150 }
2151
2152 if (rc)
2153 goto err_out;
2154 2091
2155 /* 2092 /*
2156 * determine by signature whether we have ATA or ATAPI devices 2093 * determine by signature whether we have ATA or ATAPI devices
@@ -2223,9 +2160,9 @@ static int sata_phy_resume(struct ata_port *ap)
2223 * so makes reset sequence different from the original 2160 * so makes reset sequence different from the original
2224 * ->phy_reset implementation and Jeff nervous. :-P 2161 * ->phy_reset implementation and Jeff nervous. :-P
2225 */ 2162 */
2226extern void ata_std_probeinit(struct ata_port *ap) 2163void ata_std_probeinit(struct ata_port *ap)
2227{ 2164{
2228 if (ap->flags & ATA_FLAG_SATA && ap->ops->scr_read) { 2165 if ((ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read) {
2229 sata_phy_resume(ap); 2166 sata_phy_resume(ap);
2230 if (sata_dev_present(ap)) 2167 if (sata_dev_present(ap))
2231 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 2168 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
@@ -2714,18 +2651,23 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
2714 * known limits including host controller limits, device 2651 * known limits including host controller limits, device
2715 * blacklist, etc... 2652 * blacklist, etc...
2716 * 2653 *
2654 * FIXME: The current implementation limits all transfer modes to
2655 * the fastest of the lowested device on the port. This is not
2656 * required on most controllers.
2657 *
2717 * LOCKING: 2658 * LOCKING:
2718 * None. 2659 * None.
2719 */ 2660 */
2720static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev) 2661static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2721{ 2662{
2663 struct ata_host_set *hs = ap->host_set;
2722 unsigned long xfer_mask; 2664 unsigned long xfer_mask;
2723 int i; 2665 int i;
2724 2666
2725 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask, 2667 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
2726 ap->udma_mask); 2668 ap->udma_mask);
2727 2669
2728 /* use port-wide xfermask for now */ 2670 /* FIXME: Use port-wide xfermask for now */
2729 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2671 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2730 struct ata_device *d = &ap->device[i]; 2672 struct ata_device *d = &ap->device[i];
2731 if (!ata_dev_present(d)) 2673 if (!ata_dev_present(d))
@@ -2735,12 +2677,23 @@ static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2735 xfer_mask &= ata_id_xfermask(d->id); 2677 xfer_mask &= ata_id_xfermask(d->id);
2736 if (ata_dma_blacklisted(d)) 2678 if (ata_dma_blacklisted(d))
2737 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2679 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2680 /* Apply cable rule here. Don't apply it early because when
2681 we handle hot plug the cable type can itself change */
2682 if (ap->cbl == ATA_CBL_PATA40)
2683 xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
2738 } 2684 }
2739 2685
2740 if (ata_dma_blacklisted(dev)) 2686 if (ata_dma_blacklisted(dev))
2741 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, " 2687 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, "
2742 "disabling DMA\n", ap->id, dev->devno); 2688 "disabling DMA\n", ap->id, dev->devno);
2743 2689
2690 if (hs->flags & ATA_HOST_SIMPLEX) {
2691 if (hs->simplex_claimed)
2692 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2693 }
2694 if (ap->ops->mode_filter)
2695 xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask);
2696
2744 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask, 2697 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
2745 &dev->udma_mask); 2698 &dev->udma_mask);
2746} 2699}
@@ -2795,16 +2748,16 @@ static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
2795 */ 2748 */
2796 2749
2797static unsigned int ata_dev_init_params(struct ata_port *ap, 2750static unsigned int ata_dev_init_params(struct ata_port *ap,
2798 struct ata_device *dev) 2751 struct ata_device *dev,
2752 u16 heads,
2753 u16 sectors)
2799{ 2754{
2800 struct ata_taskfile tf; 2755 struct ata_taskfile tf;
2801 unsigned int err_mask; 2756 unsigned int err_mask;
2802 u16 sectors = dev->id[6];
2803 u16 heads = dev->id[3];
2804 2757
2805 /* Number of sectors per track 1-255. Number of heads 1-16 */ 2758 /* Number of sectors per track 1-255. Number of heads 1-16 */
2806 if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16) 2759 if (sectors < 1 || sectors > 255 || heads < 1 || heads > 16)
2807 return 0; 2760 return AC_ERR_INVALID;
2808 2761
2809 /* set up init dev params taskfile */ 2762 /* set up init dev params taskfile */
2810 DPRINTK("init dev params \n"); 2763 DPRINTK("init dev params \n");
@@ -4042,15 +3995,14 @@ static inline int ata_should_dma_map(struct ata_queued_cmd *qc)
4042 * 3995 *
4043 * LOCKING: 3996 * LOCKING:
4044 * spin_lock_irqsave(host_set lock) 3997 * spin_lock_irqsave(host_set lock)
4045 *
4046 * RETURNS:
4047 * Zero on success, AC_ERR_* mask on failure
4048 */ 3998 */
4049 3999void ata_qc_issue(struct ata_queued_cmd *qc)
4050unsigned int ata_qc_issue(struct ata_queued_cmd *qc)
4051{ 4000{
4052 struct ata_port *ap = qc->ap; 4001 struct ata_port *ap = qc->ap;
4053 4002
4003 qc->ap->active_tag = qc->tag;
4004 qc->flags |= ATA_QCFLAG_ACTIVE;
4005
4054 if (ata_should_dma_map(qc)) { 4006 if (ata_should_dma_map(qc)) {
4055 if (qc->flags & ATA_QCFLAG_SG) { 4007 if (qc->flags & ATA_QCFLAG_SG) {
4056 if (ata_sg_setup(qc)) 4008 if (ata_sg_setup(qc))
@@ -4065,17 +4017,18 @@ unsigned int ata_qc_issue(struct ata_queued_cmd *qc)
4065 4017
4066 ap->ops->qc_prep(qc); 4018 ap->ops->qc_prep(qc);
4067 4019
4068 qc->ap->active_tag = qc->tag; 4020 qc->err_mask |= ap->ops->qc_issue(qc);
4069 qc->flags |= ATA_QCFLAG_ACTIVE; 4021 if (unlikely(qc->err_mask))
4070 4022 goto err;
4071 return ap->ops->qc_issue(qc); 4023 return;
4072 4024
4073sg_err: 4025sg_err:
4074 qc->flags &= ~ATA_QCFLAG_DMAMAP; 4026 qc->flags &= ~ATA_QCFLAG_DMAMAP;
4075 return AC_ERR_SYSTEM; 4027 qc->err_mask |= AC_ERR_SYSTEM;
4028err:
4029 ata_qc_complete(qc);
4076} 4030}
4077 4031
4078
4079/** 4032/**
4080 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner 4033 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
4081 * @qc: command to issue to device 4034 * @qc: command to issue to device
@@ -4536,6 +4489,14 @@ static struct ata_port * ata_host_add(const struct ata_probe_ent *ent,
4536 int rc; 4489 int rc;
4537 4490
4538 DPRINTK("ENTER\n"); 4491 DPRINTK("ENTER\n");
4492
4493 if (!ent->port_ops->probe_reset &&
4494 !(ent->host_flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST))) {
4495 printk(KERN_ERR "ata%u: no reset mechanism available\n",
4496 port_no);
4497 return NULL;
4498 }
4499
4539 host = scsi_host_alloc(ent->sht, sizeof(struct ata_port)); 4500 host = scsi_host_alloc(ent->sht, sizeof(struct ata_port));
4540 if (!host) 4501 if (!host)
4541 return NULL; 4502 return NULL;
@@ -4596,6 +4557,7 @@ int ata_device_add(const struct ata_probe_ent *ent)
4596 host_set->mmio_base = ent->mmio_base; 4557 host_set->mmio_base = ent->mmio_base;
4597 host_set->private_data = ent->private_data; 4558 host_set->private_data = ent->private_data;
4598 host_set->ops = ent->port_ops; 4559 host_set->ops = ent->port_ops;
4560 host_set->flags = ent->host_set_flags;
4599 4561
4600 /* register each port bound to this device */ 4562 /* register each port bound to this device */
4601 for (i = 0; i < ent->n_ports; i++) { 4563 for (i = 0; i < ent->n_ports; i++) {
@@ -4976,7 +4938,6 @@ EXPORT_SYMBOL_GPL(ata_busy_sleep);
4976EXPORT_SYMBOL_GPL(ata_port_queue_task); 4938EXPORT_SYMBOL_GPL(ata_port_queue_task);
4977EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 4939EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
4978EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 4940EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
4979EXPORT_SYMBOL_GPL(ata_scsi_error);
4980EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 4941EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
4981EXPORT_SYMBOL_GPL(ata_scsi_release); 4942EXPORT_SYMBOL_GPL(ata_scsi_release);
4982EXPORT_SYMBOL_GPL(ata_host_intr); 4943EXPORT_SYMBOL_GPL(ata_host_intr);
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 628191bfd990..a0289ec3e283 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -53,6 +53,7 @@
53typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); 53typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd);
54static struct ata_device * 54static struct ata_device *
55ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); 55ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev);
56static void ata_scsi_error(struct Scsi_Host *host);
56enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); 57enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
57 58
58#define RW_RECOVERY_MPAGE 0x1 59#define RW_RECOVERY_MPAGE 0x1
@@ -99,6 +100,7 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
99 * It just needs the eh_timed_out hook. 100 * It just needs the eh_timed_out hook.
100 */ 101 */
101struct scsi_transport_template ata_scsi_transport_template = { 102struct scsi_transport_template ata_scsi_transport_template = {
103 .eh_strategy_handler = ata_scsi_error,
102 .eh_timed_out = ata_scsi_timed_out, 104 .eh_timed_out = ata_scsi_timed_out,
103}; 105};
104 106
@@ -772,12 +774,9 @@ enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
772 * 774 *
773 * LOCKING: 775 * LOCKING:
774 * Inherited from SCSI layer (none, can sleep) 776 * Inherited from SCSI layer (none, can sleep)
775 *
776 * RETURNS:
777 * Zero.
778 */ 777 */
779 778
780int ata_scsi_error(struct Scsi_Host *host) 779static void ata_scsi_error(struct Scsi_Host *host)
781{ 780{
782 struct ata_port *ap; 781 struct ata_port *ap;
783 unsigned long flags; 782 unsigned long flags;
@@ -805,7 +804,6 @@ int ata_scsi_error(struct Scsi_Host *host)
805 spin_unlock_irqrestore(&ap->host_set->lock, flags); 804 spin_unlock_irqrestore(&ap->host_set->lock, flags);
806 805
807 DPRINTK("EXIT\n"); 806 DPRINTK("EXIT\n");
808 return 0;
809} 807}
810 808
811static void ata_eh_scsidone(struct scsi_cmnd *scmd) 809static void ata_eh_scsidone(struct scsi_cmnd *scmd)
@@ -1431,9 +1429,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
1431 goto early_finish; 1429 goto early_finish;
1432 1430
1433 /* select device, send command to hardware */ 1431 /* select device, send command to hardware */
1434 qc->err_mask = ata_qc_issue(qc); 1432 ata_qc_issue(qc);
1435 if (qc->err_mask)
1436 ata_qc_complete(qc);
1437 1433
1438 VPRINTK("EXIT\n"); 1434 VPRINTK("EXIT\n");
1439 return; 1435 return;
@@ -2199,9 +2195,7 @@ static void atapi_request_sense(struct ata_queued_cmd *qc)
2199 2195
2200 qc->complete_fn = atapi_sense_complete; 2196 qc->complete_fn = atapi_sense_complete;
2201 2197
2202 qc->err_mask = ata_qc_issue(qc); 2198 ata_qc_issue(qc);
2203 if (qc->err_mask)
2204 ata_qc_complete(qc);
2205 2199
2206 DPRINTK("EXIT\n"); 2200 DPRINTK("EXIT\n");
2207} 2201}
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h
index 65f52beea884..bac8cbae06fe 100644
--- a/drivers/scsi/libata.h
+++ b/drivers/scsi/libata.h
@@ -47,7 +47,7 @@ extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,
47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); 47extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc);
48extern void ata_port_flush_task(struct ata_port *ap); 48extern void ata_port_flush_task(struct ata_port *ap);
49extern void ata_qc_free(struct ata_queued_cmd *qc); 49extern void ata_qc_free(struct ata_queued_cmd *qc);
50extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc); 50extern void ata_qc_issue(struct ata_queued_cmd *qc);
51extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); 51extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
52extern void ata_dev_select(struct ata_port *ap, unsigned int device, 52extern void ata_dev_select(struct ata_port *ap, unsigned int device,
53 unsigned int wait, unsigned int can_sleep); 53 unsigned int wait, unsigned int can_sleep);
@@ -60,7 +60,6 @@ extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
60extern struct scsi_transport_template ata_scsi_transport_template; 60extern struct scsi_transport_template ata_scsi_transport_template;
61 61
62extern void ata_scsi_scan_host(struct ata_port *ap); 62extern void ata_scsi_scan_host(struct ata_port *ap);
63extern int ata_scsi_error(struct Scsi_Host *host);
64extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 63extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
65 unsigned int buflen); 64 unsigned int buflen);
66 65
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index d6d2125f9044..f852421002ef 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1748,7 +1748,7 @@ static int mesh_host_reset(struct scsi_cmnd *cmd)
1748 1748
1749static void set_mesh_power(struct mesh_state *ms, int state) 1749static void set_mesh_power(struct mesh_state *ms, int state)
1750{ 1750{
1751 if (_machine != _MACH_Pmac) 1751 if (!machine_is(powermac))
1752 return; 1752 return;
1753 if (state) { 1753 if (state) {
1754 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1); 1754 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1);
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index 5609847e254a..ee449b29fc82 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -89,29 +89,29 @@ MODULE_LICENSE("Dual MPL/GPL");
89/*====================================================================*/ 89/*====================================================================*/
90 90
91typedef struct scsi_info_t { 91typedef struct scsi_info_t {
92 dev_link_t link; 92 struct pcmcia_device *p_dev;
93 dev_node_t node; 93 dev_node_t node;
94 struct Scsi_Host *host; 94 struct Scsi_Host *host;
95} scsi_info_t; 95} scsi_info_t;
96 96
97static void aha152x_release_cs(dev_link_t *link); 97static void aha152x_release_cs(struct pcmcia_device *link);
98static void aha152x_detach(struct pcmcia_device *p_dev); 98static void aha152x_detach(struct pcmcia_device *p_dev);
99static void aha152x_config_cs(dev_link_t *link); 99static int aha152x_config_cs(struct pcmcia_device *link);
100 100
101static dev_link_t *dev_list; 101static struct pcmcia_device *dev_list;
102 102
103static int aha152x_attach(struct pcmcia_device *p_dev) 103static int aha152x_probe(struct pcmcia_device *link)
104{ 104{
105 scsi_info_t *info; 105 scsi_info_t *info;
106 dev_link_t *link; 106
107
108 DEBUG(0, "aha152x_attach()\n"); 107 DEBUG(0, "aha152x_attach()\n");
109 108
110 /* Create new SCSI device */ 109 /* Create new SCSI device */
111 info = kmalloc(sizeof(*info), GFP_KERNEL); 110 info = kmalloc(sizeof(*info), GFP_KERNEL);
112 if (!info) return -ENOMEM; 111 if (!info) return -ENOMEM;
113 memset(info, 0, sizeof(*info)); 112 memset(info, 0, sizeof(*info));
114 link = &info->link; link->priv = info; 113 info->p_dev = link;
114 link->priv = info;
115 115
116 link->io.NumPorts1 = 0x20; 116 link->io.NumPorts1 = 0x20;
117 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 117 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -119,41 +119,22 @@ static int aha152x_attach(struct pcmcia_device *p_dev)
119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 119 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
120 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 120 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
121 link->conf.Attributes = CONF_ENABLE_IRQ; 121 link->conf.Attributes = CONF_ENABLE_IRQ;
122 link->conf.Vcc = 50;
123 link->conf.IntType = INT_MEMORY_AND_IO; 122 link->conf.IntType = INT_MEMORY_AND_IO;
124 link->conf.Present = PRESENT_OPTION; 123 link->conf.Present = PRESENT_OPTION;
125 124
126 link->handle = p_dev; 125 return aha152x_config_cs(link);
127 p_dev->instance = link;
128
129 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
130 aha152x_config_cs(link);
131
132 return 0;
133} /* aha152x_attach */ 126} /* aha152x_attach */
134 127
135/*====================================================================*/ 128/*====================================================================*/
136 129
137static void aha152x_detach(struct pcmcia_device *p_dev) 130static void aha152x_detach(struct pcmcia_device *link)
138{ 131{
139 dev_link_t *link = dev_to_instance(p_dev);
140 dev_link_t **linkp;
141
142 DEBUG(0, "aha152x_detach(0x%p)\n", link); 132 DEBUG(0, "aha152x_detach(0x%p)\n", link);
143
144 /* Locate device structure */
145 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
146 if (*linkp == link) break;
147 if (*linkp == NULL)
148 return;
149 133
150 if (link->state & DEV_CONFIG) 134 aha152x_release_cs(link);
151 aha152x_release_cs(link);
152 135
153 /* Unlink device structure, free bits */ 136 /* Unlink device structure, free bits */
154 *linkp = link->next;
155 kfree(link->priv); 137 kfree(link->priv);
156
157} /* aha152x_detach */ 138} /* aha152x_detach */
158 139
159/*====================================================================*/ 140/*====================================================================*/
@@ -161,9 +142,8 @@ static void aha152x_detach(struct pcmcia_device *p_dev)
161#define CS_CHECK(fn, ret) \ 142#define CS_CHECK(fn, ret) \
162do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 143do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
163 144
164static void aha152x_config_cs(dev_link_t *link) 145static int aha152x_config_cs(struct pcmcia_device *link)
165{ 146{
166 client_handle_t handle = link->handle;
167 scsi_info_t *info = link->priv; 147 scsi_info_t *info = link->priv;
168 struct aha152x_setup s; 148 struct aha152x_setup s;
169 tuple_t tuple; 149 tuple_t tuple;
@@ -178,19 +158,16 @@ static void aha152x_config_cs(dev_link_t *link)
178 tuple.TupleData = tuple_data; 158 tuple.TupleData = tuple_data;
179 tuple.TupleDataMax = 64; 159 tuple.TupleDataMax = 64;
180 tuple.TupleOffset = 0; 160 tuple.TupleOffset = 0;
181 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 161 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
182 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 162 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
183 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 163 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
184 link->conf.ConfigBase = parse.config.base; 164 link->conf.ConfigBase = parse.config.base;
185 165
186 /* Configure card */
187 link->state |= DEV_CONFIG;
188
189 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 166 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
190 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 167 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
191 while (1) { 168 while (1) {
192 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 169 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
193 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 170 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
194 goto next_entry; 171 goto next_entry;
195 /* For New Media T&J, look for a SCSI window */ 172 /* For New Media T&J, look for a SCSI window */
196 if (parse.cftable_entry.io.win[0].len >= 0x20) 173 if (parse.cftable_entry.io.win[0].len >= 0x20)
@@ -201,15 +178,15 @@ static void aha152x_config_cs(dev_link_t *link)
201 if ((parse.cftable_entry.io.nwin > 0) && 178 if ((parse.cftable_entry.io.nwin > 0) &&
202 (link->io.BasePort1 < 0xffff)) { 179 (link->io.BasePort1 < 0xffff)) {
203 link->conf.ConfigIndex = parse.cftable_entry.index; 180 link->conf.ConfigIndex = parse.cftable_entry.index;
204 i = pcmcia_request_io(handle, &link->io); 181 i = pcmcia_request_io(link, &link->io);
205 if (i == CS_SUCCESS) break; 182 if (i == CS_SUCCESS) break;
206 } 183 }
207 next_entry: 184 next_entry:
208 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 185 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
209 } 186 }
210 187
211 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 188 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
212 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 189 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
213 190
214 /* Set configuration options for the aha152x driver */ 191 /* Set configuration options for the aha152x driver */
215 memset(&s, 0, sizeof(s)); 192 memset(&s, 0, sizeof(s));
@@ -231,53 +208,30 @@ static void aha152x_config_cs(dev_link_t *link)
231 } 208 }
232 209
233 sprintf(info->node.dev_name, "scsi%d", host->host_no); 210 sprintf(info->node.dev_name, "scsi%d", host->host_no);
234 link->dev = &info->node; 211 link->dev_node = &info->node;
235 info->host = host; 212 info->host = host;
236 213
237 link->state &= ~DEV_CONFIG_PENDING; 214 return 0;
238 return; 215
239
240cs_failed: 216cs_failed:
241 cs_error(link->handle, last_fn, last_ret); 217 cs_error(link, last_fn, last_ret);
242 aha152x_release_cs(link); 218 aha152x_release_cs(link);
243 return; 219 return -ENODEV;
244} 220}
245 221
246static void aha152x_release_cs(dev_link_t *link) 222static void aha152x_release_cs(struct pcmcia_device *link)
247{ 223{
248 scsi_info_t *info = link->priv; 224 scsi_info_t *info = link->priv;
249 225
250 aha152x_release(info->host); 226 aha152x_release(info->host);
251 link->dev = NULL; 227 pcmcia_disable_device(link);
252
253 pcmcia_release_configuration(link->handle);
254 pcmcia_release_io(link->handle, &link->io);
255 pcmcia_release_irq(link->handle, &link->irq);
256
257 link->state &= ~DEV_CONFIG;
258} 228}
259 229
260static int aha152x_suspend(struct pcmcia_device *dev) 230static int aha152x_resume(struct pcmcia_device *link)
261{ 231{
262 dev_link_t *link = dev_to_instance(dev);
263
264 link->state |= DEV_SUSPEND;
265 if (link->state & DEV_CONFIG)
266 pcmcia_release_configuration(link->handle);
267
268 return 0;
269}
270
271static int aha152x_resume(struct pcmcia_device *dev)
272{
273 dev_link_t *link = dev_to_instance(dev);
274 scsi_info_t *info = link->priv; 232 scsi_info_t *info = link->priv;
275 233
276 link->state &= ~DEV_SUSPEND; 234 aha152x_host_reset_host(info->host);
277 if (link->state & DEV_CONFIG) {
278 pcmcia_request_configuration(link->handle, &link->conf);
279 aha152x_host_reset_host(info->host);
280 }
281 235
282 return 0; 236 return 0;
283} 237}
@@ -297,10 +251,9 @@ static struct pcmcia_driver aha152x_cs_driver = {
297 .drv = { 251 .drv = {
298 .name = "aha152x_cs", 252 .name = "aha152x_cs",
299 }, 253 },
300 .probe = aha152x_attach, 254 .probe = aha152x_probe,
301 .remove = aha152x_detach, 255 .remove = aha152x_detach,
302 .id_table = aha152x_ids, 256 .id_table = aha152x_ids,
303 .suspend = aha152x_suspend,
304 .resume = aha152x_resume, 257 .resume = aha152x_resume,
305}; 258};
306 259
@@ -317,4 +270,3 @@ static void __exit exit_aha152x_cs(void)
317 270
318module_init(init_aha152x_cs); 271module_init(init_aha152x_cs);
319module_exit(exit_aha152x_cs); 272module_exit(exit_aha152x_cs);
320
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index 788c58d805f3..85f7ffac19a0 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -73,57 +73,48 @@ static char *version =
73/*====================================================================*/ 73/*====================================================================*/
74 74
75typedef struct scsi_info_t { 75typedef struct scsi_info_t {
76 dev_link_t link; 76 struct pcmcia_device *p_dev;
77 dev_node_t node; 77 dev_node_t node;
78 struct Scsi_Host *host; 78 struct Scsi_Host *host;
79} scsi_info_t; 79} scsi_info_t;
80 80
81 81
82static void fdomain_release(dev_link_t *link); 82static void fdomain_release(struct pcmcia_device *link);
83static void fdomain_detach(struct pcmcia_device *p_dev); 83static void fdomain_detach(struct pcmcia_device *p_dev);
84static void fdomain_config(dev_link_t *link); 84static int fdomain_config(struct pcmcia_device *link);
85 85
86static int fdomain_attach(struct pcmcia_device *p_dev) 86static int fdomain_probe(struct pcmcia_device *link)
87{ 87{
88 scsi_info_t *info; 88 scsi_info_t *info;
89 dev_link_t *link; 89
90 90 DEBUG(0, "fdomain_attach()\n");
91 DEBUG(0, "fdomain_attach()\n"); 91
92 92 /* Create new SCSI device */
93 /* Create new SCSI device */ 93 info = kzalloc(sizeof(*info), GFP_KERNEL);
94 info = kmalloc(sizeof(*info), GFP_KERNEL); 94 if (!info)
95 if (!info) return -ENOMEM; 95 return -ENOMEM;
96 memset(info, 0, sizeof(*info)); 96
97 link = &info->link; link->priv = info; 97 info->p_dev = link;
98 link->io.NumPorts1 = 0x10; 98 link->priv = info;
99 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 99 link->io.NumPorts1 = 0x10;
100 link->io.IOAddrLines = 10; 100 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
101 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 101 link->io.IOAddrLines = 10;
102 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 102 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
103 link->conf.Attributes = CONF_ENABLE_IRQ; 103 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
104 link->conf.Vcc = 50; 104 link->conf.Attributes = CONF_ENABLE_IRQ;
105 link->conf.IntType = INT_MEMORY_AND_IO; 105 link->conf.IntType = INT_MEMORY_AND_IO;
106 link->conf.Present = PRESENT_OPTION; 106 link->conf.Present = PRESENT_OPTION;
107 107
108 link->handle = p_dev; 108 return fdomain_config(link);
109 p_dev->instance = link;
110
111 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
112 fdomain_config(link);
113
114 return 0;
115} /* fdomain_attach */ 109} /* fdomain_attach */
116 110
117/*====================================================================*/ 111/*====================================================================*/
118 112
119static void fdomain_detach(struct pcmcia_device *p_dev) 113static void fdomain_detach(struct pcmcia_device *link)
120{ 114{
121 dev_link_t *link = dev_to_instance(p_dev);
122
123 DEBUG(0, "fdomain_detach(0x%p)\n", link); 115 DEBUG(0, "fdomain_detach(0x%p)\n", link);
124 116
125 if (link->state & DEV_CONFIG) 117 fdomain_release(link);
126 fdomain_release(link);
127 118
128 kfree(link->priv); 119 kfree(link->priv);
129} /* fdomain_detach */ 120} /* fdomain_detach */
@@ -133,9 +124,8 @@ static void fdomain_detach(struct pcmcia_device *p_dev)
133#define CS_CHECK(fn, ret) \ 124#define CS_CHECK(fn, ret) \
134do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 125do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
135 126
136static void fdomain_config(dev_link_t *link) 127static int fdomain_config(struct pcmcia_device *link)
137{ 128{
138 client_handle_t handle = link->handle;
139 scsi_info_t *info = link->priv; 129 scsi_info_t *info = link->priv;
140 tuple_t tuple; 130 tuple_t tuple;
141 cisparse_t parse; 131 cisparse_t parse;
@@ -150,103 +140,75 @@ static void fdomain_config(dev_link_t *link)
150 tuple.TupleData = tuple_data; 140 tuple.TupleData = tuple_data;
151 tuple.TupleDataMax = 64; 141 tuple.TupleDataMax = 64;
152 tuple.TupleOffset = 0; 142 tuple.TupleOffset = 0;
153 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 143 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
154 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 144 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
155 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 145 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
156 link->conf.ConfigBase = parse.config.base; 146 link->conf.ConfigBase = parse.config.base;
157 147
158 /* Configure card */
159 link->state |= DEV_CONFIG;
160
161 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 148 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
162 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 149 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
163 while (1) { 150 while (1) {
164 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 151 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
165 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 152 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
166 goto next_entry; 153 goto next_entry;
167 link->conf.ConfigIndex = parse.cftable_entry.index; 154 link->conf.ConfigIndex = parse.cftable_entry.index;
168 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 155 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
169 i = pcmcia_request_io(handle, &link->io); 156 i = pcmcia_request_io(link, &link->io);
170 if (i == CS_SUCCESS) break; 157 if (i == CS_SUCCESS) break;
171 next_entry: 158 next_entry:
172 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 159 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
173 } 160 }
174 161
175 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 162 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
176 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 163 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
177 164
178 /* A bad hack... */ 165 /* A bad hack... */
179 release_region(link->io.BasePort1, link->io.NumPorts1); 166 release_region(link->io.BasePort1, link->io.NumPorts1);
180 167
181 /* Set configuration options for the fdomain driver */ 168 /* Set configuration options for the fdomain driver */
182 sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ); 169 sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ);
183 fdomain_setup(str); 170 fdomain_setup(str);
184 171
185 host = __fdomain_16x0_detect(&fdomain_driver_template); 172 host = __fdomain_16x0_detect(&fdomain_driver_template);
186 if (!host) { 173 if (!host) {
187 printk(KERN_INFO "fdomain_cs: no SCSI devices found\n"); 174 printk(KERN_INFO "fdomain_cs: no SCSI devices found\n");
188 goto cs_failed; 175 goto cs_failed;
189 } 176 }
190 177
191 scsi_add_host(host, NULL); /* XXX handle failure */ 178 if (scsi_add_host(host, NULL))
179 goto cs_failed;
192 scsi_scan_host(host); 180 scsi_scan_host(host);
193 181
194 sprintf(info->node.dev_name, "scsi%d", host->host_no); 182 sprintf(info->node.dev_name, "scsi%d", host->host_no);
195 link->dev = &info->node; 183 link->dev_node = &info->node;
196 info->host = host; 184 info->host = host;
197 185
198 link->state &= ~DEV_CONFIG_PENDING; 186 return 0;
199 return; 187
200
201cs_failed: 188cs_failed:
202 cs_error(link->handle, last_fn, last_ret); 189 cs_error(link, last_fn, last_ret);
203 fdomain_release(link); 190 fdomain_release(link);
204 return; 191 return -ENODEV;
205
206} /* fdomain_config */ 192} /* fdomain_config */
207 193
208/*====================================================================*/ 194/*====================================================================*/
209 195
210static void fdomain_release(dev_link_t *link) 196static void fdomain_release(struct pcmcia_device *link)
211{ 197{
212 scsi_info_t *info = link->priv; 198 scsi_info_t *info = link->priv;
213 199
214 DEBUG(0, "fdomain_release(0x%p)\n", link); 200 DEBUG(0, "fdomain_release(0x%p)\n", link);
215 201
216 scsi_remove_host(info->host); 202 scsi_remove_host(info->host);
217 link->dev = NULL; 203 pcmcia_disable_device(link);
218 204 scsi_unregister(info->host);
219 pcmcia_release_configuration(link->handle);
220 pcmcia_release_io(link->handle, &link->io);
221 pcmcia_release_irq(link->handle, &link->irq);
222
223 scsi_unregister(info->host);
224
225 link->state &= ~DEV_CONFIG;
226} 205}
227 206
228/*====================================================================*/ 207/*====================================================================*/
229 208
230static int fdomain_suspend(struct pcmcia_device *dev) 209static int fdomain_resume(struct pcmcia_device *link)
231{ 210{
232 dev_link_t *link = dev_to_instance(dev); 211 fdomain_16x0_bus_reset(NULL);
233
234 link->state |= DEV_SUSPEND;
235 if (link->state & DEV_CONFIG)
236 pcmcia_release_configuration(link->handle);
237
238 return 0;
239}
240
241static int fdomain_resume(struct pcmcia_device *dev)
242{
243 dev_link_t *link = dev_to_instance(dev);
244
245 link->state &= ~DEV_SUSPEND;
246 if (link->state & DEV_CONFIG) {
247 pcmcia_request_configuration(link->handle, &link->conf);
248 fdomain_16x0_bus_reset(NULL);
249 }
250 212
251 return 0; 213 return 0;
252} 214}
@@ -264,10 +226,9 @@ static struct pcmcia_driver fdomain_cs_driver = {
264 .drv = { 226 .drv = {
265 .name = "fdomain_cs", 227 .name = "fdomain_cs",
266 }, 228 },
267 .probe = fdomain_attach, 229 .probe = fdomain_probe,
268 .remove = fdomain_detach, 230 .remove = fdomain_detach,
269 .id_table = fdomain_ids, 231 .id_table = fdomain_ids,
270 .suspend = fdomain_suspend,
271 .resume = fdomain_resume, 232 .resume = fdomain_resume,
272}; 233};
273 234
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 9e3ab3fd5355..231f9c311c69 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1593,11 +1593,11 @@ static int nsp_eh_host_reset(Scsi_Cmnd *SCpnt)
1593 configure the card at this point -- we wait until we receive a 1593 configure the card at this point -- we wait until we receive a
1594 card insertion event. 1594 card insertion event.
1595======================================================================*/ 1595======================================================================*/
1596static int nsp_cs_attach(struct pcmcia_device *p_dev) 1596static int nsp_cs_probe(struct pcmcia_device *link)
1597{ 1597{
1598 scsi_info_t *info; 1598 scsi_info_t *info;
1599 dev_link_t *link;
1600 nsp_hw_data *data = &nsp_data_base; 1599 nsp_hw_data *data = &nsp_data_base;
1600 int ret;
1601 1601
1602 nsp_dbg(NSP_DEBUG_INIT, "in"); 1602 nsp_dbg(NSP_DEBUG_INIT, "in");
1603 1603
@@ -1605,7 +1605,7 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1605 info = kmalloc(sizeof(*info), GFP_KERNEL); 1605 info = kmalloc(sizeof(*info), GFP_KERNEL);
1606 if (info == NULL) { return -ENOMEM; } 1606 if (info == NULL) { return -ENOMEM; }
1607 memset(info, 0, sizeof(*info)); 1607 memset(info, 0, sizeof(*info));
1608 link = &info->link; 1608 info->p_dev = link;
1609 link->priv = info; 1609 link->priv = info;
1610 data->ScsiInfo = info; 1610 data->ScsiInfo = info;
1611 1611
@@ -1627,18 +1627,13 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1627 1627
1628 /* General socket configuration */ 1628 /* General socket configuration */
1629 link->conf.Attributes = CONF_ENABLE_IRQ; 1629 link->conf.Attributes = CONF_ENABLE_IRQ;
1630 link->conf.Vcc = 50;
1631 link->conf.IntType = INT_MEMORY_AND_IO; 1630 link->conf.IntType = INT_MEMORY_AND_IO;
1632 link->conf.Present = PRESENT_OPTION; 1631 link->conf.Present = PRESENT_OPTION;
1633 1632
1634 link->handle = p_dev; 1633 ret = nsp_cs_config(link);
1635 p_dev->instance = link;
1636
1637 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1638 nsp_cs_config(link);
1639 1634
1640 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link); 1635 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
1641 return 0; 1636 return ret;
1642} /* nsp_cs_attach */ 1637} /* nsp_cs_attach */
1643 1638
1644 1639
@@ -1648,16 +1643,12 @@ static int nsp_cs_attach(struct pcmcia_device *p_dev)
1648 structures are freed. Otherwise, the structures will be freed 1643 structures are freed. Otherwise, the structures will be freed
1649 when the device is released. 1644 when the device is released.
1650======================================================================*/ 1645======================================================================*/
1651static void nsp_cs_detach(struct pcmcia_device *p_dev) 1646static void nsp_cs_detach(struct pcmcia_device *link)
1652{ 1647{
1653 dev_link_t *link = dev_to_instance(p_dev);
1654
1655 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link); 1648 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link);
1656 1649
1657 if (link->state & DEV_CONFIG) { 1650 ((scsi_info_t *)link->priv)->stop = 1;
1658 ((scsi_info_t *)link->priv)->stop = 1; 1651 nsp_cs_release(link);
1659 nsp_cs_release(link);
1660 }
1661 1652
1662 kfree(link->priv); 1653 kfree(link->priv);
1663 link->priv = NULL; 1654 link->priv = NULL;
@@ -1672,9 +1663,9 @@ static void nsp_cs_detach(struct pcmcia_device *p_dev)
1672#define CS_CHECK(fn, ret) \ 1663#define CS_CHECK(fn, ret) \
1673do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 1664do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1674/*====================================================================*/ 1665/*====================================================================*/
1675static void nsp_cs_config(dev_link_t *link) 1666static int nsp_cs_config(struct pcmcia_device *link)
1676{ 1667{
1677 client_handle_t handle = link->handle; 1668 int ret;
1678 scsi_info_t *info = link->priv; 1669 scsi_info_t *info = link->priv;
1679 tuple_t tuple; 1670 tuple_t tuple;
1680 cisparse_t parse; 1671 cisparse_t parse;
@@ -1698,26 +1689,22 @@ static void nsp_cs_config(dev_link_t *link)
1698 tuple.TupleData = tuple_data; 1689 tuple.TupleData = tuple_data;
1699 tuple.TupleDataMax = sizeof(tuple_data); 1690 tuple.TupleDataMax = sizeof(tuple_data);
1700 tuple.TupleOffset = 0; 1691 tuple.TupleOffset = 0;
1701 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1692 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
1702 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 1693 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
1703 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 1694 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
1704 link->conf.ConfigBase = parse.config.base; 1695 link->conf.ConfigBase = parse.config.base;
1705 link->conf.Present = parse.config.rmask[0]; 1696 link->conf.Present = parse.config.rmask[0];
1706 1697
1707 /* Configure card */
1708 link->state |= DEV_CONFIG;
1709
1710 /* Look up the current Vcc */ 1698 /* Look up the current Vcc */
1711 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf)); 1699 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
1712 link->conf.Vcc = conf.Vcc;
1713 1700
1714 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 1701 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1715 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 1702 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
1716 while (1) { 1703 while (1) {
1717 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 1704 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
1718 1705
1719 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 1706 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
1720 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 1707 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
1721 goto next_entry; 1708 goto next_entry;
1722 1709
1723 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; } 1710 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; }
@@ -1743,10 +1730,10 @@ static void nsp_cs_config(dev_link_t *link)
1743 } 1730 }
1744 1731
1745 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1732 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1746 link->conf.Vpp1 = link->conf.Vpp2 = 1733 link->conf.Vpp =
1747 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 1734 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
1748 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1735 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1749 link->conf.Vpp1 = link->conf.Vpp2 = 1736 link->conf.Vpp =
1750 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 1737 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
1751 } 1738 }
1752 1739
@@ -1773,7 +1760,7 @@ static void nsp_cs_config(dev_link_t *link)
1773 link->io.NumPorts2 = io->win[1].len; 1760 link->io.NumPorts2 = io->win[1].len;
1774 } 1761 }
1775 /* This reserves IO space but doesn't actually enable it */ 1762 /* This reserves IO space but doesn't actually enable it */
1776 if (pcmcia_request_io(link->handle, &link->io) != 0) 1763 if (pcmcia_request_io(link, &link->io) != 0)
1777 goto next_entry; 1764 goto next_entry;
1778 } 1765 }
1779 1766
@@ -1788,7 +1775,7 @@ static void nsp_cs_config(dev_link_t *link)
1788 req.Size = 0x1000; 1775 req.Size = 0x1000;
1789 } 1776 }
1790 req.AccessSpeed = 0; 1777 req.AccessSpeed = 0;
1791 if (pcmcia_request_window(&link->handle, &req, &link->win) != 0) 1778 if (pcmcia_request_window(&link, &req, &link->win) != 0)
1792 goto next_entry; 1779 goto next_entry;
1793 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 1780 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
1794 if (pcmcia_map_mem_page(link->win, &map) != 0) 1781 if (pcmcia_map_mem_page(link->win, &map) != 0)
@@ -1802,17 +1789,14 @@ static void nsp_cs_config(dev_link_t *link)
1802 1789
1803 next_entry: 1790 next_entry:
1804 nsp_dbg(NSP_DEBUG_INIT, "next"); 1791 nsp_dbg(NSP_DEBUG_INIT, "next");
1805 1792 pcmcia_disable_device(link);
1806 if (link->io.NumPorts1) { 1793 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
1807 pcmcia_release_io(link->handle, &link->io);
1808 }
1809 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
1810 } 1794 }
1811 1795
1812 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1796 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1813 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq)); 1797 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
1814 } 1798 }
1815 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 1799 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
1816 1800
1817 if (free_ports) { 1801 if (free_ports) {
1818 if (link->io.BasePort1) { 1802 if (link->io.BasePort1) {
@@ -1854,16 +1838,19 @@ static void nsp_cs_config(dev_link_t *link)
1854 1838
1855 1839
1856#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) 1840#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
1857 scsi_add_host (host, NULL); 1841 ret = scsi_add_host (host, NULL);
1842 if (ret)
1843 goto cs_failed;
1844
1858 scsi_scan_host(host); 1845 scsi_scan_host(host);
1859 1846
1860 snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no); 1847 snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no);
1861 link->dev = &info->node; 1848 link->dev_node = &info->node;
1862 info->host = host; 1849 info->host = host;
1863 1850
1864#else 1851#else
1865 nsp_dbg(NSP_DEBUG_INIT, "GET_SCSI_INFO"); 1852 nsp_dbg(NSP_DEBUG_INIT, "GET_SCSI_INFO");
1866 tail = &link->dev; 1853 tail = &link->dev_node;
1867 info->ndev = 0; 1854 info->ndev = 0;
1868 1855
1869 nsp_dbg(NSP_DEBUG_INIT, "host=0x%p", host); 1856 nsp_dbg(NSP_DEBUG_INIT, "host=0x%p", host);
@@ -1908,11 +1895,10 @@ static void nsp_cs_config(dev_link_t *link)
1908#endif 1895#endif
1909 1896
1910 /* Finally, report what we've done */ 1897 /* Finally, report what we've done */
1911 printk(KERN_INFO "nsp_cs: index 0x%02x: Vcc %d.%d", 1898 printk(KERN_INFO "nsp_cs: index 0x%02x: ",
1912 link->conf.ConfigIndex, 1899 link->conf.ConfigIndex);
1913 link->conf.Vcc/10, link->conf.Vcc%10); 1900 if (link->conf.Vpp) {
1914 if (link->conf.Vpp1) { 1901 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
1915 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
1916 } 1902 }
1917 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1903 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1918 printk(", irq %d", link->irq.AssignedIRQ); 1904 printk(", irq %d", link->irq.AssignedIRQ);
@@ -1929,15 +1915,14 @@ static void nsp_cs_config(dev_link_t *link)
1929 req.Base+req.Size-1); 1915 req.Base+req.Size-1);
1930 printk("\n"); 1916 printk("\n");
1931 1917
1932 link->state &= ~DEV_CONFIG_PENDING; 1918 return 0;
1933 return;
1934 1919
1935 cs_failed: 1920 cs_failed:
1936 nsp_dbg(NSP_DEBUG_INIT, "config fail"); 1921 nsp_dbg(NSP_DEBUG_INIT, "config fail");
1937 cs_error(link->handle, last_fn, last_ret); 1922 cs_error(link, last_fn, last_ret);
1938 nsp_cs_release(link); 1923 nsp_cs_release(link);
1939 1924
1940 return; 1925 return -ENODEV;
1941} /* nsp_cs_config */ 1926} /* nsp_cs_config */
1942#undef CS_CHECK 1927#undef CS_CHECK
1943 1928
@@ -1947,7 +1932,7 @@ static void nsp_cs_config(dev_link_t *link)
1947 device, and release the PCMCIA configuration. If the device is 1932 device, and release the PCMCIA configuration. If the device is
1948 still open, this will be postponed until it is closed. 1933 still open, this will be postponed until it is closed.
1949======================================================================*/ 1934======================================================================*/
1950static void nsp_cs_release(dev_link_t *link) 1935static void nsp_cs_release(struct pcmcia_device *link)
1951{ 1936{
1952 scsi_info_t *info = link->priv; 1937 scsi_info_t *info = link->priv;
1953 nsp_hw_data *data = NULL; 1938 nsp_hw_data *data = NULL;
@@ -1968,22 +1953,15 @@ static void nsp_cs_release(dev_link_t *link)
1968#else 1953#else
1969 scsi_unregister_host(&nsp_driver_template); 1954 scsi_unregister_host(&nsp_driver_template);
1970#endif 1955#endif
1971 link->dev = NULL; 1956 link->dev_node = NULL;
1972 1957
1973 if (link->win) { 1958 if (link->win) {
1974 if (data != NULL) { 1959 if (data != NULL) {
1975 iounmap((void *)(data->MmioAddress)); 1960 iounmap((void *)(data->MmioAddress));
1976 } 1961 }
1977 pcmcia_release_window(link->win);
1978 }
1979 pcmcia_release_configuration(link->handle);
1980 if (link->io.NumPorts1) {
1981 pcmcia_release_io(link->handle, &link->io);
1982 } 1962 }
1983 if (link->irq.AssignedIRQ) { 1963 pcmcia_disable_device(link);
1984 pcmcia_release_irq(link->handle, &link->irq); 1964
1985 }
1986 link->state &= ~DEV_CONFIG;
1987#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)) 1965#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2))
1988 if (info->host != NULL) { 1966 if (info->host != NULL) {
1989 scsi_host_put(info->host); 1967 scsi_host_put(info->host);
@@ -1991,14 +1969,11 @@ static void nsp_cs_release(dev_link_t *link)
1991#endif 1969#endif
1992} /* nsp_cs_release */ 1970} /* nsp_cs_release */
1993 1971
1994static int nsp_cs_suspend(struct pcmcia_device *dev) 1972static int nsp_cs_suspend(struct pcmcia_device *link)
1995{ 1973{
1996 dev_link_t *link = dev_to_instance(dev);
1997 scsi_info_t *info = link->priv; 1974 scsi_info_t *info = link->priv;
1998 nsp_hw_data *data; 1975 nsp_hw_data *data;
1999 1976
2000 link->state |= DEV_SUSPEND;
2001
2002 nsp_dbg(NSP_DEBUG_INIT, "event: suspend"); 1977 nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
2003 1978
2004 if (info->host != NULL) { 1979 if (info->host != NULL) {
@@ -2011,25 +1986,16 @@ static int nsp_cs_suspend(struct pcmcia_device *dev)
2011 1986
2012 info->stop = 1; 1987 info->stop = 1;
2013 1988
2014 if (link->state & DEV_CONFIG)
2015 pcmcia_release_configuration(link->handle);
2016
2017 return 0; 1989 return 0;
2018} 1990}
2019 1991
2020static int nsp_cs_resume(struct pcmcia_device *dev) 1992static int nsp_cs_resume(struct pcmcia_device *link)
2021{ 1993{
2022 dev_link_t *link = dev_to_instance(dev);
2023 scsi_info_t *info = link->priv; 1994 scsi_info_t *info = link->priv;
2024 nsp_hw_data *data; 1995 nsp_hw_data *data;
2025 1996
2026 nsp_dbg(NSP_DEBUG_INIT, "event: resume"); 1997 nsp_dbg(NSP_DEBUG_INIT, "event: resume");
2027 1998
2028 link->state &= ~DEV_SUSPEND;
2029
2030 if (link->state & DEV_CONFIG)
2031 pcmcia_request_configuration(link->handle, &link->conf);
2032
2033 info->stop = 0; 1999 info->stop = 0;
2034 2000
2035 if (info->host != NULL) { 2001 if (info->host != NULL) {
@@ -2065,7 +2031,7 @@ static struct pcmcia_driver nsp_driver = {
2065 .drv = { 2031 .drv = {
2066 .name = "nsp_cs", 2032 .name = "nsp_cs",
2067 }, 2033 },
2068 .probe = nsp_cs_attach, 2034 .probe = nsp_cs_probe,
2069 .remove = nsp_cs_detach, 2035 .remove = nsp_cs_detach,
2070 .id_table = nsp_cs_ids, 2036 .id_table = nsp_cs_ids,
2071 .suspend = nsp_cs_suspend, 2037 .suspend = nsp_cs_suspend,
@@ -2098,19 +2064,7 @@ static int __init nsp_cs_init(void)
2098static void __exit nsp_cs_exit(void) 2064static void __exit nsp_cs_exit(void)
2099{ 2065{
2100 nsp_msg(KERN_INFO, "unloading..."); 2066 nsp_msg(KERN_INFO, "unloading...");
2101
2102#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68))
2103 pcmcia_unregister_driver(&nsp_driver); 2067 pcmcia_unregister_driver(&nsp_driver);
2104#else
2105 unregister_pcmcia_driver(&dev_info);
2106 /* XXX: this really needs to move into generic code.. */
2107 while (dev_list != NULL) {
2108 if (dev_list->state & DEV_CONFIG) {
2109 nsp_cs_release(dev_list);
2110 }
2111 nsp_cs_detach(dev_list);
2112 }
2113#endif
2114} 2068}
2115 2069
2116 2070
diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h
index b66b140a745e..8908b8e5b78a 100644
--- a/drivers/scsi/pcmcia/nsp_cs.h
+++ b/drivers/scsi/pcmcia/nsp_cs.h
@@ -225,7 +225,7 @@
225/*====================================================================*/ 225/*====================================================================*/
226 226
227typedef struct scsi_info_t { 227typedef struct scsi_info_t {
228 dev_link_t link; 228 struct pcmcia_device *p_dev;
229 struct Scsi_Host *host; 229 struct Scsi_Host *host;
230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) 230#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
231 dev_node_t node; 231 dev_node_t node;
@@ -297,8 +297,8 @@ typedef struct _nsp_hw_data {
297 297
298/* Card service functions */ 298/* Card service functions */
299static void nsp_cs_detach (struct pcmcia_device *p_dev); 299static void nsp_cs_detach (struct pcmcia_device *p_dev);
300static void nsp_cs_release(dev_link_t *link); 300static void nsp_cs_release(struct pcmcia_device *link);
301static void nsp_cs_config (dev_link_t *link); 301static int nsp_cs_config (struct pcmcia_device *link);
302 302
303/* Linux SCSI subsystem specific functions */ 303/* Linux SCSI subsystem specific functions */
304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); 304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht);
@@ -450,7 +450,7 @@ static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno)
450 return host; 450 return host;
451} 451}
452 452
453static void cs_error(client_handle_t handle, int func, int ret) 453static void cs_error(struct pcmcia_device *handle, int func, int ret)
454{ 454{
455 error_info_t err = { func, ret }; 455 error_info_t err = { func, ret };
456 pcmcia_report_error(handle, &err); 456 pcmcia_report_error(handle, &err);
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index dce7e687fd4a..86c2ac6ae623 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -91,18 +91,18 @@ static struct scsi_host_template qlogicfas_driver_template = {
91/*====================================================================*/ 91/*====================================================================*/
92 92
93typedef struct scsi_info_t { 93typedef struct scsi_info_t {
94 dev_link_t link; 94 struct pcmcia_device *p_dev;
95 dev_node_t node; 95 dev_node_t node;
96 struct Scsi_Host *host; 96 struct Scsi_Host *host;
97 unsigned short manf_id; 97 unsigned short manf_id;
98} scsi_info_t; 98} scsi_info_t;
99 99
100static void qlogic_release(dev_link_t *link); 100static void qlogic_release(struct pcmcia_device *link);
101static void qlogic_detach(struct pcmcia_device *p_dev); 101static void qlogic_detach(struct pcmcia_device *p_dev);
102static void qlogic_config(dev_link_t * link); 102static int qlogic_config(struct pcmcia_device * link);
103 103
104static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host, 104static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host,
105 dev_link_t *link, int qbase, int qlirq) 105 struct pcmcia_device *link, int qbase, int qlirq)
106{ 106{
107 int qltyp; /* type of chip */ 107 int qltyp; /* type of chip */
108 int qinitid; 108 int qinitid;
@@ -156,10 +156,9 @@ free_scsi_host:
156err: 156err:
157 return NULL; 157 return NULL;
158} 158}
159static int qlogic_attach(struct pcmcia_device *p_dev) 159static int qlogic_probe(struct pcmcia_device *link)
160{ 160{
161 scsi_info_t *info; 161 scsi_info_t *info;
162 dev_link_t *link;
163 162
164 DEBUG(0, "qlogic_attach()\n"); 163 DEBUG(0, "qlogic_attach()\n");
165 164
@@ -168,7 +167,7 @@ static int qlogic_attach(struct pcmcia_device *p_dev)
168 if (!info) 167 if (!info)
169 return -ENOMEM; 168 return -ENOMEM;
170 memset(info, 0, sizeof(*info)); 169 memset(info, 0, sizeof(*info));
171 link = &info->link; 170 info->p_dev = link;
172 link->priv = info; 171 link->priv = info;
173 link->io.NumPorts1 = 16; 172 link->io.NumPorts1 = 16;
174 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 173 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -176,30 +175,19 @@ static int qlogic_attach(struct pcmcia_device *p_dev)
176 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 175 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
177 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 176 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
178 link->conf.Attributes = CONF_ENABLE_IRQ; 177 link->conf.Attributes = CONF_ENABLE_IRQ;
179 link->conf.Vcc = 50;
180 link->conf.IntType = INT_MEMORY_AND_IO; 178 link->conf.IntType = INT_MEMORY_AND_IO;
181 link->conf.Present = PRESENT_OPTION; 179 link->conf.Present = PRESENT_OPTION;
182 180
183 link->handle = p_dev; 181 return qlogic_config(link);
184 p_dev->instance = link;
185
186 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
187 qlogic_config(link);
188
189 return 0;
190} /* qlogic_attach */ 182} /* qlogic_attach */
191 183
192/*====================================================================*/ 184/*====================================================================*/
193 185
194static void qlogic_detach(struct pcmcia_device *p_dev) 186static void qlogic_detach(struct pcmcia_device *link)
195{ 187{
196 dev_link_t *link = dev_to_instance(p_dev);
197
198 DEBUG(0, "qlogic_detach(0x%p)\n", link); 188 DEBUG(0, "qlogic_detach(0x%p)\n", link);
199 189
200 if (link->state & DEV_CONFIG) 190 qlogic_release(link);
201 qlogic_release(link);
202
203 kfree(link->priv); 191 kfree(link->priv);
204 192
205} /* qlogic_detach */ 193} /* qlogic_detach */
@@ -209,9 +197,8 @@ static void qlogic_detach(struct pcmcia_device *p_dev)
209#define CS_CHECK(fn, ret) \ 197#define CS_CHECK(fn, ret) \
210do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 198do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
211 199
212static void qlogic_config(dev_link_t * link) 200static int qlogic_config(struct pcmcia_device * link)
213{ 201{
214 client_handle_t handle = link->handle;
215 scsi_info_t *info = link->priv; 202 scsi_info_t *info = link->priv;
216 tuple_t tuple; 203 tuple_t tuple;
217 cisparse_t parse; 204 cisparse_t parse;
@@ -225,38 +212,35 @@ static void qlogic_config(dev_link_t * link)
225 tuple.TupleDataMax = 64; 212 tuple.TupleDataMax = 64;
226 tuple.TupleOffset = 0; 213 tuple.TupleOffset = 0;
227 tuple.DesiredTuple = CISTPL_CONFIG; 214 tuple.DesiredTuple = CISTPL_CONFIG;
228 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 215 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
229 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 216 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
230 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 217 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
231 link->conf.ConfigBase = parse.config.base; 218 link->conf.ConfigBase = parse.config.base;
232 219
233 tuple.DesiredTuple = CISTPL_MANFID; 220 tuple.DesiredTuple = CISTPL_MANFID;
234 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 221 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) && (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS))
235 info->manf_id = le16_to_cpu(tuple.TupleData[0]); 222 info->manf_id = le16_to_cpu(tuple.TupleData[0]);
236 223
237 /* Configure card */
238 link->state |= DEV_CONFIG;
239
240 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 224 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
241 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 225 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
242 while (1) { 226 while (1) {
243 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 227 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
244 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 228 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
245 goto next_entry; 229 goto next_entry;
246 link->conf.ConfigIndex = parse.cftable_entry.index; 230 link->conf.ConfigIndex = parse.cftable_entry.index;
247 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 231 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
248 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 232 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
249 if (link->io.BasePort1 != 0) { 233 if (link->io.BasePort1 != 0) {
250 i = pcmcia_request_io(handle, &link->io); 234 i = pcmcia_request_io(link, &link->io);
251 if (i == CS_SUCCESS) 235 if (i == CS_SUCCESS)
252 break; 236 break;
253 } 237 }
254 next_entry: 238 next_entry:
255 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 239 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
256 } 240 }
257 241
258 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 242 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
259 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 243 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
260 244
261 if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) { 245 if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) {
262 /* set ATAcmd */ 246 /* set ATAcmd */
@@ -275,82 +259,54 @@ static void qlogic_config(dev_link_t * link)
275 259
276 if (!host) { 260 if (!host) {
277 printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name); 261 printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name);
278 goto out; 262 goto cs_failed;
279 } 263 }
280 264
281 sprintf(info->node.dev_name, "scsi%d", host->host_no); 265 sprintf(info->node.dev_name, "scsi%d", host->host_no);
282 link->dev = &info->node; 266 link->dev_node = &info->node;
283 info->host = host; 267 info->host = host;
284 268
285out: 269 return 0;
286 link->state &= ~DEV_CONFIG_PENDING;
287 return;
288 270
289cs_failed: 271cs_failed:
290 cs_error(link->handle, last_fn, last_ret); 272 cs_error(link, last_fn, last_ret);
291 link->dev = NULL; 273 pcmcia_disable_device(link);
292 pcmcia_release_configuration(link->handle); 274 return -ENODEV;
293 pcmcia_release_io(link->handle, &link->io);
294 pcmcia_release_irq(link->handle, &link->irq);
295 link->state &= ~DEV_CONFIG;
296 return;
297 275
298} /* qlogic_config */ 276} /* qlogic_config */
299 277
300/*====================================================================*/ 278/*====================================================================*/
301 279
302static void qlogic_release(dev_link_t *link) 280static void qlogic_release(struct pcmcia_device *link)
303{ 281{
304 scsi_info_t *info = link->priv; 282 scsi_info_t *info = link->priv;
305 283
306 DEBUG(0, "qlogic_release(0x%p)\n", link); 284 DEBUG(0, "qlogic_release(0x%p)\n", link);
307 285
308 scsi_remove_host(info->host); 286 scsi_remove_host(info->host);
309 link->dev = NULL;
310 287
311 free_irq(link->irq.AssignedIRQ, info->host); 288 free_irq(link->irq.AssignedIRQ, info->host);
312 289 pcmcia_disable_device(link);
313 pcmcia_release_configuration(link->handle);
314 pcmcia_release_io(link->handle, &link->io);
315 pcmcia_release_irq(link->handle, &link->irq);
316 290
317 scsi_host_put(info->host); 291 scsi_host_put(info->host);
318
319 link->state &= ~DEV_CONFIG;
320} 292}
321 293
322/*====================================================================*/ 294/*====================================================================*/
323 295
324static int qlogic_suspend(struct pcmcia_device *dev) 296static int qlogic_resume(struct pcmcia_device *link)
325{ 297{
326 dev_link_t *link = dev_to_instance(dev); 298 scsi_info_t *info = link->priv;
327
328 link->state |= DEV_SUSPEND;
329 if (link->state & DEV_CONFIG)
330 pcmcia_release_configuration(link->handle);
331
332 return 0;
333}
334 299
335static int qlogic_resume(struct pcmcia_device *dev) 300 pcmcia_request_configuration(link, &link->conf);
336{ 301 if ((info->manf_id == MANFID_MACNICA) ||
337 dev_link_t *link = dev_to_instance(dev); 302 (info->manf_id == MANFID_PIONEER) ||
338 303 (info->manf_id == 0x0098)) {
339 link->state &= ~DEV_SUSPEND; 304 outb(0x80, link->io.BasePort1 + 0xd);
340 if (link->state & DEV_CONFIG) { 305 outb(0x24, link->io.BasePort1 + 0x9);
341 scsi_info_t *info = link->priv; 306 outb(0x04, link->io.BasePort1 + 0xd);
342
343 pcmcia_request_configuration(link->handle, &link->conf);
344 if ((info->manf_id == MANFID_MACNICA) ||
345 (info->manf_id == MANFID_PIONEER) ||
346 (info->manf_id == 0x0098)) {
347 outb(0x80, link->io.BasePort1 + 0xd);
348 outb(0x24, link->io.BasePort1 + 0x9);
349 outb(0x04, link->io.BasePort1 + 0xd);
350 }
351 /* Ugggglllyyyy!!! */
352 qlogicfas408_bus_reset(NULL);
353 } 307 }
308 /* Ugggglllyyyy!!! */
309 qlogicfas408_bus_reset(NULL);
354 310
355 return 0; 311 return 0;
356} 312}
@@ -382,10 +338,9 @@ static struct pcmcia_driver qlogic_cs_driver = {
382 .drv = { 338 .drv = {
383 .name = "qlogic_cs", 339 .name = "qlogic_cs",
384 }, 340 },
385 .probe = qlogic_attach, 341 .probe = qlogic_probe,
386 .remove = qlogic_detach, 342 .remove = qlogic_detach,
387 .id_table = qlogic_ids, 343 .id_table = qlogic_ids,
388 .suspend = qlogic_suspend,
389 .resume = qlogic_resume, 344 .resume = qlogic_resume,
390}; 345};
391 346
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 3a4dd6f5b81f..9f59827707f0 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -202,7 +202,7 @@ static char *version =
202/* ================================================================== */ 202/* ================================================================== */
203 203
204struct scsi_info_t { 204struct scsi_info_t {
205 dev_link_t link; 205 struct pcmcia_device *p_dev;
206 dev_node_t node; 206 dev_node_t node;
207 struct Scsi_Host *host; 207 struct Scsi_Host *host;
208 unsigned short manf_id; 208 unsigned short manf_id;
@@ -527,7 +527,7 @@ idle_out:
527} 527}
528 528
529static void 529static void
530SYM53C500_release(dev_link_t *link) 530SYM53C500_release(struct pcmcia_device *link)
531{ 531{
532 struct scsi_info_t *info = link->priv; 532 struct scsi_info_t *info = link->priv;
533 struct Scsi_Host *shost = info->host; 533 struct Scsi_Host *shost = info->host;
@@ -550,13 +550,7 @@ SYM53C500_release(dev_link_t *link)
550 if (shost->io_port && shost->n_io_port) 550 if (shost->io_port && shost->n_io_port)
551 release_region(shost->io_port, shost->n_io_port); 551 release_region(shost->io_port, shost->n_io_port);
552 552
553 link->dev = NULL; 553 pcmcia_disable_device(link);
554
555 pcmcia_release_configuration(link->handle);
556 pcmcia_release_io(link->handle, &link->io);
557 pcmcia_release_irq(link->handle, &link->irq);
558
559 link->state &= ~DEV_CONFIG;
560 554
561 scsi_host_put(shost); 555 scsi_host_put(shost);
562} /* SYM53C500_release */ 556} /* SYM53C500_release */
@@ -713,10 +707,9 @@ static struct scsi_host_template sym53c500_driver_template = {
713#define CS_CHECK(fn, ret) \ 707#define CS_CHECK(fn, ret) \
714do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 708do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
715 709
716static void 710static int
717SYM53C500_config(dev_link_t *link) 711SYM53C500_config(struct pcmcia_device *link)
718{ 712{
719 client_handle_t handle = link->handle;
720 struct scsi_info_t *info = link->priv; 713 struct scsi_info_t *info = link->priv;
721 tuple_t tuple; 714 tuple_t tuple;
722 cisparse_t parse; 715 cisparse_t parse;
@@ -733,40 +726,37 @@ SYM53C500_config(dev_link_t *link)
733 tuple.TupleDataMax = 64; 726 tuple.TupleDataMax = 64;
734 tuple.TupleOffset = 0; 727 tuple.TupleOffset = 0;
735 tuple.DesiredTuple = CISTPL_CONFIG; 728 tuple.DesiredTuple = CISTPL_CONFIG;
736 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 729 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
737 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 730 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
738 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 731 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
739 link->conf.ConfigBase = parse.config.base; 732 link->conf.ConfigBase = parse.config.base;
740 733
741 tuple.DesiredTuple = CISTPL_MANFID; 734 tuple.DesiredTuple = CISTPL_MANFID;
742 if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) && 735 if ((pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) &&
743 (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS)) 736 (pcmcia_get_tuple_data(link, &tuple) == CS_SUCCESS))
744 info->manf_id = le16_to_cpu(tuple.TupleData[0]); 737 info->manf_id = le16_to_cpu(tuple.TupleData[0]);
745 738
746 /* Configure card */
747 link->state |= DEV_CONFIG;
748
749 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 739 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
750 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 740 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
751 while (1) { 741 while (1) {
752 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 742 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
753 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 743 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
754 goto next_entry; 744 goto next_entry;
755 link->conf.ConfigIndex = parse.cftable_entry.index; 745 link->conf.ConfigIndex = parse.cftable_entry.index;
756 link->io.BasePort1 = parse.cftable_entry.io.win[0].base; 746 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
757 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len; 747 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
758 748
759 if (link->io.BasePort1 != 0) { 749 if (link->io.BasePort1 != 0) {
760 i = pcmcia_request_io(handle, &link->io); 750 i = pcmcia_request_io(link, &link->io);
761 if (i == CS_SUCCESS) 751 if (i == CS_SUCCESS)
762 break; 752 break;
763 } 753 }
764next_entry: 754next_entry:
765 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 755 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
766 } 756 }
767 757
768 CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); 758 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
769 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 759 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
770 760
771 /* 761 /*
772 * That's the trouble with copying liberally from another driver. 762 * That's the trouble with copying liberally from another driver.
@@ -835,7 +825,7 @@ next_entry:
835 data->fast_pio = USE_FAST_PIO; 825 data->fast_pio = USE_FAST_PIO;
836 826
837 sprintf(info->node.dev_name, "scsi%d", host->host_no); 827 sprintf(info->node.dev_name, "scsi%d", host->host_no);
838 link->dev = &info->node; 828 link->dev_node = &info->node;
839 info->host = host; 829 info->host = host;
840 830
841 if (scsi_add_host(host, NULL)) 831 if (scsi_add_host(host, NULL))
@@ -843,7 +833,7 @@ next_entry:
843 833
844 scsi_scan_host(host); 834 scsi_scan_host(host);
845 835
846 goto out; /* SUCCESS */ 836 return 0;
847 837
848err_free_irq: 838err_free_irq:
849 free_irq(irq_level, host); 839 free_irq(irq_level, host);
@@ -852,74 +842,50 @@ err_free_scsi:
852err_release: 842err_release:
853 release_region(port_base, 0x10); 843 release_region(port_base, 0x10);
854 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n"); 844 printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n");
855 845 return -ENODEV;
856out:
857 link->state &= ~DEV_CONFIG_PENDING;
858 return;
859 846
860cs_failed: 847cs_failed:
861 cs_error(link->handle, last_fn, last_ret); 848 cs_error(link, last_fn, last_ret);
862 SYM53C500_release(link); 849 SYM53C500_release(link);
863 return; 850 return -ENODEV;
864} /* SYM53C500_config */ 851} /* SYM53C500_config */
865 852
866static int sym53c500_suspend(struct pcmcia_device *dev) 853static int sym53c500_resume(struct pcmcia_device *link)
867{
868 dev_link_t *link = dev_to_instance(dev);
869
870 link->state |= DEV_SUSPEND;
871 if (link->state & DEV_CONFIG)
872 pcmcia_release_configuration(link->handle);
873
874 return 0;
875}
876
877static int sym53c500_resume(struct pcmcia_device *dev)
878{ 854{
879 dev_link_t *link = dev_to_instance(dev);
880 struct scsi_info_t *info = link->priv; 855 struct scsi_info_t *info = link->priv;
881 856
882 link->state &= ~DEV_SUSPEND; 857 /* See earlier comment about manufacturer IDs. */
883 if (link->state & DEV_CONFIG) { 858 if ((info->manf_id == MANFID_MACNICA) ||
884 pcmcia_request_configuration(link->handle, &link->conf); 859 (info->manf_id == MANFID_PIONEER) ||
885 860 (info->manf_id == 0x0098)) {
886 /* See earlier comment about manufacturer IDs. */ 861 outb(0x80, link->io.BasePort1 + 0xd);
887 if ((info->manf_id == MANFID_MACNICA) || 862 outb(0x24, link->io.BasePort1 + 0x9);
888 (info->manf_id == MANFID_PIONEER) || 863 outb(0x04, link->io.BasePort1 + 0xd);
889 (info->manf_id == 0x0098)) {
890 outb(0x80, link->io.BasePort1 + 0xd);
891 outb(0x24, link->io.BasePort1 + 0x9);
892 outb(0x04, link->io.BasePort1 + 0xd);
893 }
894 /*
895 * If things don't work after a "resume",
896 * this is a good place to start looking.
897 */
898 SYM53C500_int_host_reset(link->io.BasePort1);
899 } 864 }
865 /*
866 * If things don't work after a "resume",
867 * this is a good place to start looking.
868 */
869 SYM53C500_int_host_reset(link->io.BasePort1);
900 870
901 return 0; 871 return 0;
902} 872}
903 873
904static void 874static void
905SYM53C500_detach(struct pcmcia_device *p_dev) 875SYM53C500_detach(struct pcmcia_device *link)
906{ 876{
907 dev_link_t *link = dev_to_instance(p_dev);
908
909 DEBUG(0, "SYM53C500_detach(0x%p)\n", link); 877 DEBUG(0, "SYM53C500_detach(0x%p)\n", link);
910 878
911 if (link->state & DEV_CONFIG) 879 SYM53C500_release(link);
912 SYM53C500_release(link);
913 880
914 kfree(link->priv); 881 kfree(link->priv);
915 link->priv = NULL; 882 link->priv = NULL;
916} /* SYM53C500_detach */ 883} /* SYM53C500_detach */
917 884
918static int 885static int
919SYM53C500_attach(struct pcmcia_device *p_dev) 886SYM53C500_probe(struct pcmcia_device *link)
920{ 887{
921 struct scsi_info_t *info; 888 struct scsi_info_t *info;
922 dev_link_t *link;
923 889
924 DEBUG(0, "SYM53C500_attach()\n"); 890 DEBUG(0, "SYM53C500_attach()\n");
925 891
@@ -928,7 +894,7 @@ SYM53C500_attach(struct pcmcia_device *p_dev)
928 if (!info) 894 if (!info)
929 return -ENOMEM; 895 return -ENOMEM;
930 memset(info, 0, sizeof(*info)); 896 memset(info, 0, sizeof(*info));
931 link = &info->link; 897 info->p_dev = link;
932 link->priv = info; 898 link->priv = info;
933 link->io.NumPorts1 = 16; 899 link->io.NumPorts1 = 16;
934 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 900 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -936,17 +902,10 @@ SYM53C500_attach(struct pcmcia_device *p_dev)
936 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 902 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
937 link->irq.IRQInfo1 = IRQ_LEVEL_ID; 903 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
938 link->conf.Attributes = CONF_ENABLE_IRQ; 904 link->conf.Attributes = CONF_ENABLE_IRQ;
939 link->conf.Vcc = 50;
940 link->conf.IntType = INT_MEMORY_AND_IO; 905 link->conf.IntType = INT_MEMORY_AND_IO;
941 link->conf.Present = PRESENT_OPTION; 906 link->conf.Present = PRESENT_OPTION;
942 907
943 link->handle = p_dev; 908 return SYM53C500_config(link);
944 p_dev->instance = link;
945
946 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
947 SYM53C500_config(link);
948
949 return 0;
950} /* SYM53C500_attach */ 909} /* SYM53C500_attach */
951 910
952MODULE_AUTHOR("Bob Tracy <rct@frus.com>"); 911MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
@@ -966,10 +925,9 @@ static struct pcmcia_driver sym53c500_cs_driver = {
966 .drv = { 925 .drv = {
967 .name = "sym53c500_cs", 926 .name = "sym53c500_cs",
968 }, 927 },
969 .probe = SYM53C500_attach, 928 .probe = SYM53C500_probe,
970 .remove = SYM53C500_detach, 929 .remove = SYM53C500_detach,
971 .id_table = sym53c500_ids, 930 .id_table = sym53c500_ids,
972 .suspend = sym53c500_suspend,
973 .resume = sym53c500_resume, 931 .resume = sym53c500_resume,
974}; 932};
975 933
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c
index 3c85c4b66e19..5cda16cfacb0 100644
--- a/drivers/scsi/pdc_adma.c
+++ b/drivers/scsi/pdc_adma.c
@@ -143,7 +143,6 @@ static struct scsi_host_template adma_ata_sht = {
143 .name = DRV_NAME, 143 .name = DRV_NAME,
144 .ioctl = ata_scsi_ioctl, 144 .ioctl = ata_scsi_ioctl,
145 .queuecommand = ata_scsi_queuecmd, 145 .queuecommand = ata_scsi_queuecmd,
146 .eh_strategy_handler = ata_scsi_error,
147 .can_queue = ATA_DEF_QUEUE, 146 .can_queue = ATA_DEF_QUEUE,
148 .this_id = ATA_SHT_THIS_ID, 147 .this_id = ATA_SHT_THIS_ID,
149 .sg_tablesize = LIBATA_MAX_PRD, 148 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/qlogicfc.c b/drivers/scsi/qlogicfc.c
deleted file mode 100644
index 52b224a5d6fd..000000000000
--- a/drivers/scsi/qlogicfc.c
+++ /dev/null
@@ -1,2228 +0,0 @@
1/*
2 * QLogic ISP2x00 SCSI-FCP
3 * Written by Erik H. Moe, ehm@cris.com
4 * Copyright 1995, Erik H. Moe
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, or (at your option) any
9 * later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 */
16
17/* Renamed and updated to 1.3.x by Michael Griffith <grif@cs.ucr.edu> */
18
19/* This is a version of the isp1020 driver which was modified by
20 * Chris Loveland <cwl@iol.unh.edu> to support the isp2100 and isp2200
21 *
22 * Big endian support and dynamic DMA mapping added
23 * by Jakub Jelinek <jakub@redhat.com>.
24 *
25 * Conversion to final pci64 DMA interfaces
26 * by David S. Miller <davem@redhat.com>.
27 */
28
29/*
30 * $Date: 1995/09/22 02:23:15 $
31 * $Revision: 0.5 $
32 *
33 * $Log: isp1020.c,v $
34 * Revision 0.5 1995/09/22 02:23:15 root
35 * do auto request sense
36 *
37 * Revision 0.4 1995/08/07 04:44:33 root
38 * supply firmware with driver.
39 * numerous bug fixes/general cleanup of code.
40 *
41 * Revision 0.3 1995/07/16 16:15:39 root
42 * added reset/abort code.
43 *
44 * Revision 0.2 1995/06/29 03:14:19 root
45 * fixed biosparam.
46 * added queue protocol.
47 *
48 * Revision 0.1 1995/06/25 01:55:45 root
49 * Initial release.
50 *
51 */
52
53#include <linux/blkdev.h>
54#include <linux/kernel.h>
55#include <linux/string.h>
56#include <linux/ioport.h>
57#include <linux/sched.h>
58#include <linux/types.h>
59#include <linux/pci.h>
60#include <linux/delay.h>
61#include <linux/unistd.h>
62#include <linux/spinlock.h>
63#include <linux/interrupt.h>
64#include <linux/dma-mapping.h>
65#include <linux/jiffies.h>
66#include <asm/io.h>
67#include <asm/irq.h>
68#include "scsi.h"
69#include <scsi/scsi_host.h>
70
71#define pci64_dma_hi32(a) ((u32) (0xffffffff & (((u64)(a))>>32)))
72#define pci64_dma_lo32(a) ((u32) (0xffffffff & (((u64)(a)))))
73#define pci64_dma_build(hi,lo) \
74 ((dma_addr_t)(((u64)(lo))|(((u64)(hi))<<32)))
75
76/*
77 * With the qlogic interface, every queue slot can hold a SCSI
78 * command with up to 2 scatter/gather entries. If we need more
79 * than 2 entries, continuation entries can be used that hold
80 * another 5 entries each. Unlike for other drivers, this means
81 * that the maximum number of scatter/gather entries we can
82 * support at any given time is a function of the number of queue
83 * slots available. That is, host->can_queue and host->sg_tablesize
84 * are dynamic and _not_ independent. This all works fine because
85 * requests are queued serially and the scatter/gather limit is
86 * determined for each queue request anew.
87 */
88
89#define DATASEGS_PER_COMMAND 2
90#define DATASEGS_PER_CONT 5
91
92#define QLOGICFC_REQ_QUEUE_LEN 255 /* must be power of two - 1 */
93#define QLOGICFC_MAX_SG(ql) (DATASEGS_PER_COMMAND + (((ql) > 0) ? DATASEGS_PER_CONT*((ql) - 1) : 0))
94#define QLOGICFC_CMD_PER_LUN 8
95
96/* Configuration section **************************************************** */
97
98/* Set the following macro to 1 to reload the ISP2x00's firmware. This is
99 version 1.17.30 of the isp2100's firmware and version 2.00.40 of the
100 isp2200's firmware.
101*/
102
103#define USE_NVRAM_DEFAULTS 1
104
105#define ISP2x00_PORTDB 1
106
107/* Set the following to 1 to include fabric support, fabric support is
108 * currently not as well tested as the other aspects of the driver */
109
110#define ISP2x00_FABRIC 1
111
112/* Macros used for debugging */
113#define DEBUG_ISP2x00 0
114#define DEBUG_ISP2x00_INT 0
115#define DEBUG_ISP2x00_INTR 0
116#define DEBUG_ISP2x00_SETUP 0
117#define DEBUG_ISP2x00_FABRIC 0
118#define TRACE_ISP 0
119
120
121#define DEFAULT_LOOP_COUNT 1000000000
122
123#define ISP_TIMEOUT (2*HZ)
124/* End Configuration section ************************************************ */
125
126#include <linux/module.h>
127
128#if TRACE_ISP
129
130#define TRACE_BUF_LEN (32*1024)
131
132struct {
133 u_long next;
134 struct {
135 u_long time;
136 u_int index;
137 u_int addr;
138 u_char *name;
139 } buf[TRACE_BUF_LEN];
140} trace;
141
142#define TRACE(w, i, a) \
143{ \
144 unsigned long flags; \
145 \
146 save_flags(flags); \
147 cli(); \
148 trace.buf[trace.next].name = (w); \
149 trace.buf[trace.next].time = jiffies; \
150 trace.buf[trace.next].index = (i); \
151 trace.buf[trace.next].addr = (long) (a); \
152 trace.next = (trace.next + 1) & (TRACE_BUF_LEN - 1); \
153 restore_flags(flags); \
154}
155
156#else
157#define TRACE(w, i, a)
158#endif
159
160#if DEBUG_ISP2x00_FABRIC
161#define DEBUG_FABRIC(x) x
162#else
163#define DEBUG_FABRIC(x)
164#endif /* DEBUG_ISP2x00_FABRIC */
165
166
167#if DEBUG_ISP2x00
168#define ENTER(x) printk("isp2x00 : entering %s()\n", x);
169#define LEAVE(x) printk("isp2x00 : leaving %s()\n", x);
170#define DEBUG(x) x
171#else
172#define ENTER(x)
173#define LEAVE(x)
174#define DEBUG(x)
175#endif /* DEBUG_ISP2x00 */
176
177#if DEBUG_ISP2x00_INTR
178#define ENTER_INTR(x) printk("isp2x00 : entering %s()\n", x);
179#define LEAVE_INTR(x) printk("isp2x00 : leaving %s()\n", x);
180#define DEBUG_INTR(x) x
181#else
182#define ENTER_INTR(x)
183#define LEAVE_INTR(x)
184#define DEBUG_INTR(x)
185#endif /* DEBUG ISP2x00_INTR */
186
187
188#define ISP2100_REV_ID1 1
189#define ISP2100_REV_ID3 3
190#define ISP2200_REV_ID5 5
191
192/* host configuration and control registers */
193#define HOST_HCCR 0xc0 /* host command and control */
194
195/* pci bus interface registers */
196#define FLASH_BIOS_ADDR 0x00
197#define FLASH_BIOS_DATA 0x02
198#define ISP_CTRL_STATUS 0x06 /* configuration register #1 */
199#define PCI_INTER_CTL 0x08 /* pci interrupt control */
200#define PCI_INTER_STS 0x0a /* pci interrupt status */
201#define PCI_SEMAPHORE 0x0c /* pci semaphore */
202#define PCI_NVRAM 0x0e /* pci nvram interface */
203
204/* mailbox registers */
205#define MBOX0 0x10 /* mailbox 0 */
206#define MBOX1 0x12 /* mailbox 1 */
207#define MBOX2 0x14 /* mailbox 2 */
208#define MBOX3 0x16 /* mailbox 3 */
209#define MBOX4 0x18 /* mailbox 4 */
210#define MBOX5 0x1a /* mailbox 5 */
211#define MBOX6 0x1c /* mailbox 6 */
212#define MBOX7 0x1e /* mailbox 7 */
213
214/* mailbox command complete status codes */
215#define MBOX_COMMAND_COMPLETE 0x4000
216#define INVALID_COMMAND 0x4001
217#define HOST_INTERFACE_ERROR 0x4002
218#define TEST_FAILED 0x4003
219#define COMMAND_ERROR 0x4005
220#define COMMAND_PARAM_ERROR 0x4006
221#define PORT_ID_USED 0x4007
222#define LOOP_ID_USED 0x4008
223#define ALL_IDS_USED 0x4009
224
225/* async event status codes */
226#define RESET_DETECTED 0x8001
227#define SYSTEM_ERROR 0x8002
228#define REQUEST_TRANSFER_ERROR 0x8003
229#define RESPONSE_TRANSFER_ERROR 0x8004
230#define REQUEST_QUEUE_WAKEUP 0x8005
231#define LIP_OCCURRED 0x8010
232#define LOOP_UP 0x8011
233#define LOOP_DOWN 0x8012
234#define LIP_RECEIVED 0x8013
235#define PORT_DB_CHANGED 0x8014
236#define CHANGE_NOTIFICATION 0x8015
237#define SCSI_COMMAND_COMPLETE 0x8020
238#define POINT_TO_POINT_UP 0x8030
239#define CONNECTION_MODE 0x8036
240
241struct Entry_header {
242 u_char entry_type;
243 u_char entry_cnt;
244 u_char sys_def_1;
245 u_char flags;
246};
247
248/* entry header type commands */
249#define ENTRY_COMMAND 0x19
250#define ENTRY_CONTINUATION 0x0a
251
252#define ENTRY_STATUS 0x03
253#define ENTRY_MARKER 0x04
254
255
256/* entry header flag definitions */
257#define EFLAG_BUSY 2
258#define EFLAG_BAD_HEADER 4
259#define EFLAG_BAD_PAYLOAD 8
260
261struct dataseg {
262 u_int d_base;
263 u_int d_base_hi;
264 u_int d_count;
265};
266
267struct Command_Entry {
268 struct Entry_header hdr;
269 u_int handle;
270 u_char target_lun;
271 u_char target_id;
272 u_short expanded_lun;
273 u_short control_flags;
274 u_short rsvd2;
275 u_short time_out;
276 u_short segment_cnt;
277 u_char cdb[16];
278 u_int total_byte_cnt;
279 struct dataseg dataseg[DATASEGS_PER_COMMAND];
280};
281
282/* command entry control flag definitions */
283#define CFLAG_NODISC 0x01
284#define CFLAG_HEAD_TAG 0x02
285#define CFLAG_ORDERED_TAG 0x04
286#define CFLAG_SIMPLE_TAG 0x08
287#define CFLAG_TAR_RTN 0x10
288#define CFLAG_READ 0x20
289#define CFLAG_WRITE 0x40
290
291struct Continuation_Entry {
292 struct Entry_header hdr;
293 struct dataseg dataseg[DATASEGS_PER_CONT];
294};
295
296struct Marker_Entry {
297 struct Entry_header hdr;
298 u_int reserved;
299 u_char target_lun;
300 u_char target_id;
301 u_char modifier;
302 u_char expanded_lun;
303 u_char rsvds[52];
304};
305
306/* marker entry modifier definitions */
307#define SYNC_DEVICE 0
308#define SYNC_TARGET 1
309#define SYNC_ALL 2
310
311struct Status_Entry {
312 struct Entry_header hdr;
313 u_int handle;
314 u_short scsi_status;
315 u_short completion_status;
316 u_short state_flags;
317 u_short status_flags;
318 u_short res_info_len;
319 u_short req_sense_len;
320 u_int residual;
321 u_char res_info[8];
322 u_char req_sense_data[32];
323};
324
325/* status entry completion status definitions */
326#define CS_COMPLETE 0x0000
327#define CS_DMA_ERROR 0x0002
328#define CS_RESET_OCCURRED 0x0004
329#define CS_ABORTED 0x0005
330#define CS_TIMEOUT 0x0006
331#define CS_DATA_OVERRUN 0x0007
332#define CS_DATA_UNDERRUN 0x0015
333#define CS_QUEUE_FULL 0x001c
334#define CS_PORT_UNAVAILABLE 0x0028
335#define CS_PORT_LOGGED_OUT 0x0029
336#define CS_PORT_CONFIG_CHANGED 0x002a
337
338/* status entry state flag definitions */
339#define SF_SENT_CDB 0x0400
340#define SF_TRANSFERRED_DATA 0x0800
341#define SF_GOT_STATUS 0x1000
342
343/* status entry status flag definitions */
344#define STF_BUS_RESET 0x0008
345#define STF_DEVICE_RESET 0x0010
346#define STF_ABORTED 0x0020
347#define STF_TIMEOUT 0x0040
348
349/* interrupt control commands */
350#define ISP_EN_INT 0x8000
351#define ISP_EN_RISC 0x0008
352
353/* host control commands */
354#define HCCR_NOP 0x0000
355#define HCCR_RESET 0x1000
356#define HCCR_PAUSE 0x2000
357#define HCCR_RELEASE 0x3000
358#define HCCR_SINGLE_STEP 0x4000
359#define HCCR_SET_HOST_INTR 0x5000
360#define HCCR_CLEAR_HOST_INTR 0x6000
361#define HCCR_CLEAR_RISC_INTR 0x7000
362#define HCCR_BP_ENABLE 0x8000
363#define HCCR_BIOS_DISABLE 0x9000
364#define HCCR_TEST_MODE 0xf000
365
366#define RISC_BUSY 0x0004
367
368/* mailbox commands */
369#define MBOX_NO_OP 0x0000
370#define MBOX_LOAD_RAM 0x0001
371#define MBOX_EXEC_FIRMWARE 0x0002
372#define MBOX_DUMP_RAM 0x0003
373#define MBOX_WRITE_RAM_WORD 0x0004
374#define MBOX_READ_RAM_WORD 0x0005
375#define MBOX_MAILBOX_REG_TEST 0x0006
376#define MBOX_VERIFY_CHECKSUM 0x0007
377#define MBOX_ABOUT_FIRMWARE 0x0008
378#define MBOX_LOAD_RISC_RAM 0x0009
379#define MBOX_DUMP_RISC_RAM 0x000a
380#define MBOX_CHECK_FIRMWARE 0x000e
381#define MBOX_INIT_REQ_QUEUE 0x0010
382#define MBOX_INIT_RES_QUEUE 0x0011
383#define MBOX_EXECUTE_IOCB 0x0012
384#define MBOX_WAKE_UP 0x0013
385#define MBOX_STOP_FIRMWARE 0x0014
386#define MBOX_ABORT_IOCB 0x0015
387#define MBOX_ABORT_DEVICE 0x0016
388#define MBOX_ABORT_TARGET 0x0017
389#define MBOX_BUS_RESET 0x0018
390#define MBOX_STOP_QUEUE 0x0019
391#define MBOX_START_QUEUE 0x001a
392#define MBOX_SINGLE_STEP_QUEUE 0x001b
393#define MBOX_ABORT_QUEUE 0x001c
394#define MBOX_GET_DEV_QUEUE_STATUS 0x001d
395#define MBOX_GET_FIRMWARE_STATUS 0x001f
396#define MBOX_GET_INIT_SCSI_ID 0x0020
397#define MBOX_GET_RETRY_COUNT 0x0022
398#define MBOX_GET_TARGET_PARAMS 0x0028
399#define MBOX_GET_DEV_QUEUE_PARAMS 0x0029
400#define MBOX_SET_RETRY_COUNT 0x0032
401#define MBOX_SET_TARGET_PARAMS 0x0038
402#define MBOX_SET_DEV_QUEUE_PARAMS 0x0039
403#define MBOX_EXECUTE_IOCB64 0x0054
404#define MBOX_INIT_FIRMWARE 0x0060
405#define MBOX_GET_INIT_CB 0x0061
406#define MBOX_INIT_LIP 0x0062
407#define MBOX_GET_POS_MAP 0x0063
408#define MBOX_GET_PORT_DB 0x0064
409#define MBOX_CLEAR_ACA 0x0065
410#define MBOX_TARGET_RESET 0x0066
411#define MBOX_CLEAR_TASK_SET 0x0067
412#define MBOX_ABORT_TASK_SET 0x0068
413#define MBOX_GET_FIRMWARE_STATE 0x0069
414#define MBOX_GET_PORT_NAME 0x006a
415#define MBOX_SEND_SNS 0x006e
416#define MBOX_PORT_LOGIN 0x006f
417#define MBOX_SEND_CHANGE_REQUEST 0x0070
418#define MBOX_PORT_LOGOUT 0x0071
419
420/*
421 * Firmware if needed (note this is a hack, it belongs in a separate
422 * module.
423 */
424
425#ifdef CONFIG_SCSI_QLOGIC_FC_FIRMWARE
426#include "qlogicfc_asm.c"
427#else
428static unsigned short risc_code_addr01 = 0x1000 ;
429#endif
430
431/* Each element in mbox_param is an 8 bit bitmap where each bit indicates
432 if that mbox should be copied as input. For example 0x2 would mean
433 only copy mbox1. */
434
435static const u_char mbox_param[] =
436{
437 0x01, /* MBOX_NO_OP */
438 0x1f, /* MBOX_LOAD_RAM */
439 0x03, /* MBOX_EXEC_FIRMWARE */
440 0x1f, /* MBOX_DUMP_RAM */
441 0x07, /* MBOX_WRITE_RAM_WORD */
442 0x03, /* MBOX_READ_RAM_WORD */
443 0xff, /* MBOX_MAILBOX_REG_TEST */
444 0x03, /* MBOX_VERIFY_CHECKSUM */
445 0x01, /* MBOX_ABOUT_FIRMWARE */
446 0xff, /* MBOX_LOAD_RISC_RAM */
447 0xff, /* MBOX_DUMP_RISC_RAM */
448 0x00, /* 0x000b */
449 0x00, /* 0x000c */
450 0x00, /* 0x000d */
451 0x01, /* MBOX_CHECK_FIRMWARE */
452 0x00, /* 0x000f */
453 0x1f, /* MBOX_INIT_REQ_QUEUE */
454 0x2f, /* MBOX_INIT_RES_QUEUE */
455 0x0f, /* MBOX_EXECUTE_IOCB */
456 0x03, /* MBOX_WAKE_UP */
457 0x01, /* MBOX_STOP_FIRMWARE */
458 0x0f, /* MBOX_ABORT_IOCB */
459 0x03, /* MBOX_ABORT_DEVICE */
460 0x07, /* MBOX_ABORT_TARGET */
461 0x03, /* MBOX_BUS_RESET */
462 0x03, /* MBOX_STOP_QUEUE */
463 0x03, /* MBOX_START_QUEUE */
464 0x03, /* MBOX_SINGLE_STEP_QUEUE */
465 0x03, /* MBOX_ABORT_QUEUE */
466 0x03, /* MBOX_GET_DEV_QUEUE_STATUS */
467 0x00, /* 0x001e */
468 0x01, /* MBOX_GET_FIRMWARE_STATUS */
469 0x01, /* MBOX_GET_INIT_SCSI_ID */
470 0x00, /* 0x0021 */
471 0x01, /* MBOX_GET_RETRY_COUNT */
472 0x00, /* 0x0023 */
473 0x00, /* 0x0024 */
474 0x00, /* 0x0025 */
475 0x00, /* 0x0026 */
476 0x00, /* 0x0027 */
477 0x03, /* MBOX_GET_TARGET_PARAMS */
478 0x03, /* MBOX_GET_DEV_QUEUE_PARAMS */
479 0x00, /* 0x002a */
480 0x00, /* 0x002b */
481 0x00, /* 0x002c */
482 0x00, /* 0x002d */
483 0x00, /* 0x002e */
484 0x00, /* 0x002f */
485 0x00, /* 0x0030 */
486 0x00, /* 0x0031 */
487 0x07, /* MBOX_SET_RETRY_COUNT */
488 0x00, /* 0x0033 */
489 0x00, /* 0x0034 */
490 0x00, /* 0x0035 */
491 0x00, /* 0x0036 */
492 0x00, /* 0x0037 */
493 0x0f, /* MBOX_SET_TARGET_PARAMS */
494 0x0f, /* MBOX_SET_DEV_QUEUE_PARAMS */
495 0x00, /* 0x003a */
496 0x00, /* 0x003b */
497 0x00, /* 0x003c */
498 0x00, /* 0x003d */
499 0x00, /* 0x003e */
500 0x00, /* 0x003f */
501 0x00, /* 0x0040 */
502 0x00, /* 0x0041 */
503 0x00, /* 0x0042 */
504 0x00, /* 0x0043 */
505 0x00, /* 0x0044 */
506 0x00, /* 0x0045 */
507 0x00, /* 0x0046 */
508 0x00, /* 0x0047 */
509 0x00, /* 0x0048 */
510 0x00, /* 0x0049 */
511 0x00, /* 0x004a */
512 0x00, /* 0x004b */
513 0x00, /* 0x004c */
514 0x00, /* 0x004d */
515 0x00, /* 0x004e */
516 0x00, /* 0x004f */
517 0x00, /* 0x0050 */
518 0x00, /* 0x0051 */
519 0x00, /* 0x0052 */
520 0x00, /* 0x0053 */
521 0xcf, /* MBOX_EXECUTE_IOCB64 */
522 0x00, /* 0x0055 */
523 0x00, /* 0x0056 */
524 0x00, /* 0x0057 */
525 0x00, /* 0x0058 */
526 0x00, /* 0x0059 */
527 0x00, /* 0x005a */
528 0x00, /* 0x005b */
529 0x00, /* 0x005c */
530 0x00, /* 0x005d */
531 0x00, /* 0x005e */
532 0x00, /* 0x005f */
533 0xff, /* MBOX_INIT_FIRMWARE */
534 0xcd, /* MBOX_GET_INIT_CB */
535 0x01, /* MBOX_INIT_LIP */
536 0xcd, /* MBOX_GET_POS_MAP */
537 0xcf, /* MBOX_GET_PORT_DB */
538 0x03, /* MBOX_CLEAR_ACA */
539 0x03, /* MBOX_TARGET_RESET */
540 0x03, /* MBOX_CLEAR_TASK_SET */
541 0x03, /* MBOX_ABORT_TASK_SET */
542 0x01, /* MBOX_GET_FIRMWARE_STATE */
543 0x03, /* MBOX_GET_PORT_NAME */
544 0x00, /* 0x006b */
545 0x00, /* 0x006c */
546 0x00, /* 0x006d */
547 0xcf, /* MBOX_SEND_SNS */
548 0x0f, /* MBOX_PORT_LOGIN */
549 0x03, /* MBOX_SEND_CHANGE_REQUEST */
550 0x03, /* MBOX_PORT_LOGOUT */
551};
552
553#define MAX_MBOX_COMMAND (sizeof(mbox_param)/sizeof(u_short))
554
555
556struct id_name_map {
557 u64 wwn;
558 u_char loop_id;
559};
560
561struct sns_cb {
562 u_short len;
563 u_short res1;
564 u_int response_low;
565 u_int response_high;
566 u_short sub_len;
567 u_short res2;
568 u_char data[44];
569};
570
571/* address of instance of this struct is passed to adapter to initialize things
572 */
573struct init_cb {
574 u_char version;
575 u_char reseverd1[1];
576 u_short firm_opts;
577 u_short max_frame_len;
578 u_short max_iocb;
579 u_short exec_throttle;
580 u_char retry_cnt;
581 u_char retry_delay;
582 u_short node_name[4];
583 u_short hard_addr;
584 u_char reserved2[10];
585 u_short req_queue_out;
586 u_short res_queue_in;
587 u_short req_queue_len;
588 u_short res_queue_len;
589 u_int req_queue_addr_lo;
590 u_int req_queue_addr_high;
591 u_int res_queue_addr_lo;
592 u_int res_queue_addr_high;
593 /* the rest of this structure only applies to the isp2200 */
594 u_short lun_enables;
595 u_char cmd_resource_cnt;
596 u_char notify_resource_cnt;
597 u_short timeout;
598 u_short reserved3;
599 u_short add_firm_opts;
600 u_char res_accum_timer;
601 u_char irq_delay_timer;
602 u_short special_options;
603 u_short reserved4[13];
604};
605
606/*
607 * The result queue can be quite a bit smaller since continuation entries
608 * do not show up there:
609 */
610#define RES_QUEUE_LEN ((QLOGICFC_REQ_QUEUE_LEN + 1) / 8 - 1)
611#define QUEUE_ENTRY_LEN 64
612
613#if ISP2x00_FABRIC
614#define QLOGICFC_MAX_ID 0xff
615#else
616#define QLOGICFC_MAX_ID 0x7d
617#endif
618
619#define QLOGICFC_MAX_LUN 128
620#define QLOGICFC_MAX_LOOP_ID 0x7d
621
622/* the following connection options only apply to the 2200. i have only
623 * had success with LOOP_ONLY and P2P_ONLY.
624 */
625
626#define LOOP_ONLY 0
627#define P2P_ONLY 1
628#define LOOP_PREFERED 2
629#define P2P_PREFERED 3
630
631#define CONNECTION_PREFERENCE LOOP_ONLY
632
633/* adapter_state values */
634#define AS_FIRMWARE_DEAD -1
635#define AS_LOOP_DOWN 0
636#define AS_LOOP_GOOD 1
637#define AS_REDO_FABRIC_PORTDB 2
638#define AS_REDO_LOOP_PORTDB 4
639
640#define RES_SIZE ((RES_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN)
641#define REQ_SIZE ((QLOGICFC_REQ_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN)
642
643struct isp2x00_hostdata {
644 u_char revision;
645 struct pci_dev *pci_dev;
646 /* result and request queues (shared with isp2x00): */
647 u_int req_in_ptr; /* index of next request slot */
648 u_int res_out_ptr; /* index of next result slot */
649
650 /* this is here so the queues are nicely aligned */
651 long send_marker; /* do we need to send a marker? */
652
653 char * res;
654 char * req;
655 struct init_cb control_block;
656 int adapter_state;
657 unsigned long int tag_ages[QLOGICFC_MAX_ID + 1];
658 Scsi_Cmnd *handle_ptrs[QLOGICFC_REQ_QUEUE_LEN + 1];
659 unsigned long handle_serials[QLOGICFC_REQ_QUEUE_LEN + 1];
660 struct id_name_map port_db[QLOGICFC_MAX_ID + 1];
661 u_char mbox_done;
662 u64 wwn;
663 u_int port_id;
664 u_char queued;
665 u_char host_id;
666 struct timer_list explore_timer;
667 struct id_name_map tempmap[QLOGICFC_MAX_ID + 1];
668};
669
670
671/* queue length's _must_ be power of two: */
672#define QUEUE_DEPTH(in, out, ql) ((in - out) & (ql))
673#define REQ_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, \
674 QLOGICFC_REQ_QUEUE_LEN)
675#define RES_QUEUE_DEPTH(in, out) QUEUE_DEPTH(in, out, RES_QUEUE_LEN)
676
677static void isp2x00_enable_irqs(struct Scsi_Host *);
678static void isp2x00_disable_irqs(struct Scsi_Host *);
679static int isp2x00_init(struct Scsi_Host *);
680static int isp2x00_reset_hardware(struct Scsi_Host *);
681static int isp2x00_mbox_command(struct Scsi_Host *, u_short[]);
682static int isp2x00_return_status(Scsi_Cmnd *, struct Status_Entry *);
683static void isp2x00_intr_handler(int, void *, struct pt_regs *);
684static irqreturn_t do_isp2x00_intr_handler(int, void *, struct pt_regs *);
685static int isp2x00_make_portdb(struct Scsi_Host *);
686
687#if ISP2x00_FABRIC
688static int isp2x00_init_fabric(struct Scsi_Host *, struct id_name_map *, int);
689#endif
690
691#if USE_NVRAM_DEFAULTS
692static int isp2x00_get_nvram_defaults(struct Scsi_Host *, struct init_cb *);
693static u_short isp2x00_read_nvram_word(struct Scsi_Host *, u_short);
694#endif
695
696#if DEBUG_ISP2x00
697static void isp2x00_print_scsi_cmd(Scsi_Cmnd *);
698#endif
699
700#if DEBUG_ISP2x00_INTR
701static void isp2x00_print_status_entry(struct Status_Entry *);
702#endif
703
704static inline void isp2x00_enable_irqs(struct Scsi_Host *host)
705{
706 outw(ISP_EN_INT | ISP_EN_RISC, host->io_port + PCI_INTER_CTL);
707}
708
709
710static inline void isp2x00_disable_irqs(struct Scsi_Host *host)
711{
712 outw(0x0, host->io_port + PCI_INTER_CTL);
713}
714
715
716static int isp2x00_detect(struct scsi_host_template * tmpt)
717{
718 int hosts = 0;
719 unsigned long wait_time;
720 struct Scsi_Host *host = NULL;
721 struct isp2x00_hostdata *hostdata;
722 struct pci_dev *pdev;
723 unsigned short device_ids[2];
724 dma_addr_t busaddr;
725 int i;
726
727
728 ENTER("isp2x00_detect");
729
730 device_ids[0] = PCI_DEVICE_ID_QLOGIC_ISP2100;
731 device_ids[1] = PCI_DEVICE_ID_QLOGIC_ISP2200;
732
733 tmpt->proc_name = "isp2x00";
734
735 for (i=0; i<2; i++){
736 pdev = NULL;
737 while ((pdev = pci_find_device(PCI_VENDOR_ID_QLOGIC, device_ids[i], pdev))) {
738 if (pci_enable_device(pdev))
739 continue;
740
741 /* Try to configure DMA attributes. */
742 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
743 pci_set_dma_mask(pdev, DMA_32BIT_MASK))
744 continue;
745
746 host = scsi_register(tmpt, sizeof(struct isp2x00_hostdata));
747 if (!host) {
748 printk("qlogicfc%d : could not register host.\n", hosts);
749 continue;
750 }
751 host->max_id = QLOGICFC_MAX_ID + 1;
752 host->max_lun = QLOGICFC_MAX_LUN;
753 hostdata = (struct isp2x00_hostdata *) host->hostdata;
754
755 memset(hostdata, 0, sizeof(struct isp2x00_hostdata));
756 hostdata->pci_dev = pdev;
757 hostdata->res = pci_alloc_consistent(pdev, RES_SIZE + REQ_SIZE, &busaddr);
758
759 if (!hostdata->res){
760 printk("qlogicfc%d : could not allocate memory for request and response queue.\n", hosts);
761 scsi_unregister(host);
762 continue;
763 }
764 hostdata->req = hostdata->res + (RES_QUEUE_LEN + 1)*QUEUE_ENTRY_LEN;
765 hostdata->queued = 0;
766 /* set up the control block */
767 hostdata->control_block.version = 0x1;
768 hostdata->control_block.firm_opts = cpu_to_le16(0x800e);
769 hostdata->control_block.max_frame_len = cpu_to_le16(2048);
770 hostdata->control_block.max_iocb = cpu_to_le16(QLOGICFC_REQ_QUEUE_LEN);
771 hostdata->control_block.exec_throttle = cpu_to_le16(QLOGICFC_CMD_PER_LUN);
772 hostdata->control_block.retry_delay = 5;
773 hostdata->control_block.retry_cnt = 1;
774 hostdata->control_block.node_name[0] = cpu_to_le16(0x0020);
775 hostdata->control_block.node_name[1] = cpu_to_le16(0xE000);
776 hostdata->control_block.node_name[2] = cpu_to_le16(0x008B);
777 hostdata->control_block.node_name[3] = cpu_to_le16(0x0000);
778 hostdata->control_block.hard_addr = cpu_to_le16(0x0003);
779 hostdata->control_block.req_queue_len = cpu_to_le16(QLOGICFC_REQ_QUEUE_LEN + 1);
780 hostdata->control_block.res_queue_len = cpu_to_le16(RES_QUEUE_LEN + 1);
781 hostdata->control_block.res_queue_addr_lo = cpu_to_le32(pci64_dma_lo32(busaddr));
782 hostdata->control_block.res_queue_addr_high = cpu_to_le32(pci64_dma_hi32(busaddr));
783 hostdata->control_block.req_queue_addr_lo = cpu_to_le32(pci64_dma_lo32(busaddr + RES_SIZE));
784 hostdata->control_block.req_queue_addr_high = cpu_to_le32(pci64_dma_hi32(busaddr + RES_SIZE));
785
786
787 hostdata->control_block.add_firm_opts |= cpu_to_le16(CONNECTION_PREFERENCE<<4);
788 hostdata->adapter_state = AS_LOOP_DOWN;
789 hostdata->explore_timer.data = 1;
790 hostdata->host_id = hosts;
791
792 if (isp2x00_init(host) || isp2x00_reset_hardware(host)) {
793 pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
794 scsi_unregister(host);
795 continue;
796 }
797 host->this_id = 0;
798
799 if (request_irq(host->irq, do_isp2x00_intr_handler, SA_INTERRUPT | SA_SHIRQ, "qlogicfc", host)) {
800 printk("qlogicfc%d : interrupt %d already in use\n",
801 hostdata->host_id, host->irq);
802 pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
803 scsi_unregister(host);
804 continue;
805 }
806 if (!request_region(host->io_port, 0xff, "qlogicfc")) {
807 printk("qlogicfc%d : i/o region 0x%lx-0x%lx already "
808 "in use\n",
809 hostdata->host_id, host->io_port, host->io_port + 0xff);
810 free_irq(host->irq, host);
811 pci_free_consistent (pdev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
812 scsi_unregister(host);
813 continue;
814 }
815
816 outw(0x0, host->io_port + PCI_SEMAPHORE);
817 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
818 isp2x00_enable_irqs(host);
819 /* wait for the loop to come up */
820 for (wait_time = jiffies + 10 * HZ; time_before(jiffies, wait_time) && hostdata->adapter_state == AS_LOOP_DOWN;) {
821 barrier();
822 cpu_relax();
823 }
824 if (hostdata->adapter_state == AS_LOOP_DOWN) {
825 printk("qlogicfc%d : link is not up\n", hostdata->host_id);
826 }
827 hosts++;
828 hostdata->explore_timer.data = 0;
829 }
830 }
831
832
833 /* this busy loop should not be needed but the isp2x00 seems to need
834 some time before recognizing it is attached to a fabric */
835
836#if ISP2x00_FABRIC
837 if (hosts) {
838 for (wait_time = jiffies + 5 * HZ; time_before(jiffies, wait_time);) {
839 barrier();
840 cpu_relax();
841 }
842 }
843#endif
844
845 LEAVE("isp2x00_detect");
846
847 return hosts;
848}
849
850
851static int isp2x00_make_portdb(struct Scsi_Host *host)
852{
853
854 short param[8];
855 int i, j;
856 struct isp2x00_hostdata *hostdata;
857
858 isp2x00_disable_irqs(host);
859
860 hostdata = (struct isp2x00_hostdata *) host->hostdata;
861 memset(hostdata->tempmap, 0, sizeof(hostdata->tempmap));
862
863#if ISP2x00_FABRIC
864 for (i = 0x81; i < QLOGICFC_MAX_ID; i++) {
865 param[0] = MBOX_PORT_LOGOUT;
866 param[1] = i << 8;
867 param[2] = 0;
868 param[3] = 0;
869
870 isp2x00_mbox_command(host, param);
871
872 if (param[0] != MBOX_COMMAND_COMPLETE) {
873
874 DEBUG_FABRIC(printk("qlogicfc%d : logout failed %x %x\n", hostdata->host_id, i, param[0]));
875 }
876 }
877#endif
878
879
880 param[0] = MBOX_GET_INIT_SCSI_ID;
881
882 isp2x00_mbox_command(host, param);
883
884 if (param[0] == MBOX_COMMAND_COMPLETE) {
885 hostdata->port_id = ((u_int) param[3]) << 16;
886 hostdata->port_id |= param[2];
887 hostdata->tempmap[0].loop_id = param[1];
888 hostdata->tempmap[0].wwn = hostdata->wwn;
889 }
890 else {
891 printk("qlogicfc%d : error getting scsi id.\n", hostdata->host_id);
892 }
893
894 for (i = 0; i <=QLOGICFC_MAX_ID; i++)
895 hostdata->tempmap[i].loop_id = hostdata->tempmap[0].loop_id;
896
897 for (i = 0, j = 1; i <= QLOGICFC_MAX_LOOP_ID; i++) {
898 param[0] = MBOX_GET_PORT_NAME;
899 param[1] = (i << 8) & 0xff00;
900
901 isp2x00_mbox_command(host, param);
902
903 if (param[0] == MBOX_COMMAND_COMPLETE) {
904 hostdata->tempmap[j].loop_id = i;
905 hostdata->tempmap[j].wwn = ((u64) (param[2] & 0xff)) << 56;
906 hostdata->tempmap[j].wwn |= ((u64) ((param[2] >> 8) & 0xff)) << 48;
907 hostdata->tempmap[j].wwn |= ((u64) (param[3] & 0xff)) << 40;
908 hostdata->tempmap[j].wwn |= ((u64) ((param[3] >> 8) & 0xff)) << 32;
909 hostdata->tempmap[j].wwn |= ((u64) (param[6] & 0xff)) << 24;
910 hostdata->tempmap[j].wwn |= ((u64) ((param[6] >> 8) & 0xff)) << 16;
911 hostdata->tempmap[j].wwn |= ((u64) (param[7] & 0xff)) << 8;
912 hostdata->tempmap[j].wwn |= ((u64) ((param[7] >> 8) & 0xff));
913
914 j++;
915
916 }
917 }
918
919
920#if ISP2x00_FABRIC
921 isp2x00_init_fabric(host, hostdata->tempmap, j);
922#endif
923
924 for (i = 0; i <= QLOGICFC_MAX_ID; i++) {
925 if (hostdata->tempmap[i].wwn != hostdata->port_db[i].wwn) {
926 for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
927 if (hostdata->tempmap[j].wwn == hostdata->port_db[i].wwn) {
928 hostdata->port_db[i].loop_id = hostdata->tempmap[j].loop_id;
929 break;
930 }
931 }
932 if (j == QLOGICFC_MAX_ID + 1)
933 hostdata->port_db[i].loop_id = hostdata->tempmap[0].loop_id;
934
935 for (j = 0; j <= QLOGICFC_MAX_ID; j++) {
936 if (hostdata->port_db[j].wwn == hostdata->tempmap[i].wwn || !hostdata->port_db[j].wwn) {
937 break;
938 }
939 }
940 if (j == QLOGICFC_MAX_ID + 1)
941 printk("qlogicfc%d : Too many scsi devices, no more room in port map.\n", hostdata->host_id);
942 if (!hostdata->port_db[j].wwn) {
943 hostdata->port_db[j].loop_id = hostdata->tempmap[i].loop_id;
944 hostdata->port_db[j].wwn = hostdata->tempmap[i].wwn;
945 }
946 } else
947 hostdata->port_db[i].loop_id = hostdata->tempmap[i].loop_id;
948
949 }
950
951 isp2x00_enable_irqs(host);
952
953 return 0;
954}
955
956
957#if ISP2x00_FABRIC
958
959#define FABRIC_PORT 0x7e
960#define FABRIC_CONTROLLER 0x7f
961#define FABRIC_SNS 0x80
962
963int isp2x00_init_fabric(struct Scsi_Host *host, struct id_name_map *port_db, int cur_scsi_id)
964{
965
966 u_short param[8];
967 u64 wwn;
968 int done = 0;
969 u_short loop_id = 0x81;
970 u_short scsi_id = cur_scsi_id;
971 u_int port_id;
972 struct sns_cb *req;
973 u_char *sns_response;
974 dma_addr_t busaddr;
975 struct isp2x00_hostdata *hostdata;
976
977 hostdata = (struct isp2x00_hostdata *) host->hostdata;
978
979 DEBUG_FABRIC(printk("qlogicfc%d : Checking for a fabric.\n", hostdata->host_id));
980 param[0] = MBOX_GET_PORT_NAME;
981 param[1] = (u16)FABRIC_PORT << 8;
982
983 isp2x00_mbox_command(host, param);
984
985 if (param[0] != MBOX_COMMAND_COMPLETE) {
986 DEBUG_FABRIC(printk("qlogicfc%d : fabric check result %x\n", hostdata->host_id, param[0]));
987 return 0;
988 }
989 printk("qlogicfc%d : Fabric found.\n", hostdata->host_id);
990
991 req = (struct sns_cb *)pci_alloc_consistent(hostdata->pci_dev, sizeof(*req) + 608, &busaddr);
992
993 if (!req){
994 printk("qlogicfc%d : Could not allocate DMA resources for fabric initialization\n", hostdata->host_id);
995 return 0;
996 }
997 sns_response = (u_char *)(req + 1);
998
999 if (hostdata->adapter_state & AS_REDO_LOOP_PORTDB){
1000 memset(req, 0, sizeof(*req));
1001
1002 req->len = cpu_to_le16(8);
1003 req->response_low = cpu_to_le32(pci64_dma_lo32(busaddr + sizeof(*req)));
1004 req->response_high = cpu_to_le32(pci64_dma_hi32(busaddr + sizeof(*req)));
1005 req->sub_len = cpu_to_le16(22);
1006 req->data[0] = 0x17;
1007 req->data[1] = 0x02;
1008 req->data[8] = (u_char) (hostdata->port_id & 0xff);
1009 req->data[9] = (u_char) (hostdata->port_id >> 8 & 0xff);
1010 req->data[10] = (u_char) (hostdata->port_id >> 16 & 0xff);
1011 req->data[13] = 0x01;
1012 param[0] = MBOX_SEND_SNS;
1013 param[1] = 30;
1014 param[2] = pci64_dma_lo32(busaddr) >> 16;
1015 param[3] = pci64_dma_lo32(busaddr);
1016 param[6] = pci64_dma_hi32(busaddr) >> 16;
1017 param[7] = pci64_dma_hi32(busaddr);
1018
1019 isp2x00_mbox_command(host, param);
1020
1021 if (param[0] != MBOX_COMMAND_COMPLETE)
1022 printk("qlogicfc%d : error sending RFC-4\n", hostdata->host_id);
1023 }
1024
1025 port_id = hostdata->port_id;
1026 while (!done) {
1027 memset(req, 0, sizeof(*req));
1028
1029 req->len = cpu_to_le16(304);
1030 req->response_low = cpu_to_le32(pci64_dma_lo32(busaddr + sizeof(*req)));
1031 req->response_high = cpu_to_le32(pci64_dma_hi32(busaddr + sizeof(*req)));
1032 req->sub_len = cpu_to_le16(6);
1033 req->data[0] = 0x00;
1034 req->data[1] = 0x01;
1035 req->data[8] = (u_char) (port_id & 0xff);
1036 req->data[9] = (u_char) (port_id >> 8 & 0xff);
1037 req->data[10] = (u_char) (port_id >> 16 & 0xff);
1038
1039 param[0] = MBOX_SEND_SNS;
1040 param[1] = 14;
1041 param[2] = pci64_dma_lo32(busaddr) >> 16;
1042 param[3] = pci64_dma_lo32(busaddr);
1043 param[6] = pci64_dma_hi32(busaddr) >> 16;
1044 param[7] = pci64_dma_hi32(busaddr);
1045
1046 isp2x00_mbox_command(host, param);
1047
1048 if (param[0] == MBOX_COMMAND_COMPLETE) {
1049 DEBUG_FABRIC(printk("qlogicfc%d : found node %02x%02x%02x%02x%02x%02x%02x%02x ", hostdata->host_id, sns_response[20], sns_response[21], sns_response[22], sns_response[23], sns_response[24], sns_response[25], sns_response[26], sns_response[27]));
1050 DEBUG_FABRIC(printk(" port id: %02x%02x%02x\n", sns_response[17], sns_response[18], sns_response[19]));
1051 port_id = ((u_int) sns_response[17]) << 16;
1052 port_id |= ((u_int) sns_response[18]) << 8;
1053 port_id |= ((u_int) sns_response[19]);
1054 wwn = ((u64) sns_response[20]) << 56;
1055 wwn |= ((u64) sns_response[21]) << 48;
1056 wwn |= ((u64) sns_response[22]) << 40;
1057 wwn |= ((u64) sns_response[23]) << 32;
1058 wwn |= ((u64) sns_response[24]) << 24;
1059 wwn |= ((u64) sns_response[25]) << 16;
1060 wwn |= ((u64) sns_response[26]) << 8;
1061 wwn |= ((u64) sns_response[27]);
1062 if (hostdata->port_id >> 8 != port_id >> 8) {
1063 DEBUG_FABRIC(printk("qlogicfc%d : adding a fabric port: %x\n", hostdata->host_id, port_id));
1064 param[0] = MBOX_PORT_LOGIN;
1065 param[1] = loop_id << 8;
1066 param[2] = (u_short) (port_id >> 16);
1067 param[3] = (u_short) (port_id);
1068
1069 isp2x00_mbox_command(host, param);
1070
1071 if (param[0] == MBOX_COMMAND_COMPLETE) {
1072 port_db[scsi_id].wwn = wwn;
1073 port_db[scsi_id].loop_id = loop_id;
1074 loop_id++;
1075 scsi_id++;
1076 } else {
1077 printk("qlogicfc%d : Error performing port login %x\n", hostdata->host_id, param[0]);
1078 DEBUG_FABRIC(printk("qlogicfc%d : loop_id: %x\n", hostdata->host_id, loop_id));
1079 param[0] = MBOX_PORT_LOGOUT;
1080 param[1] = loop_id << 8;
1081 param[2] = 0;
1082 param[3] = 0;
1083
1084 isp2x00_mbox_command(host, param);
1085
1086 }
1087
1088 }
1089 if (hostdata->port_id == port_id)
1090 done = 1;
1091 } else {
1092 printk("qlogicfc%d : Get All Next failed %x.\n", hostdata->host_id, param[0]);
1093 pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
1094 return 0;
1095 }
1096 }
1097
1098 pci_free_consistent(hostdata->pci_dev, sizeof(*req) + 608, req, busaddr);
1099 return 1;
1100}
1101
1102#endif /* ISP2x00_FABRIC */
1103
1104
1105static int isp2x00_release(struct Scsi_Host *host)
1106{
1107 struct isp2x00_hostdata *hostdata;
1108 dma_addr_t busaddr;
1109
1110 ENTER("isp2x00_release");
1111
1112 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1113
1114 outw(0x0, host->io_port + PCI_INTER_CTL);
1115 free_irq(host->irq, host);
1116
1117 release_region(host->io_port, 0xff);
1118
1119 busaddr = pci64_dma_build(le32_to_cpu(hostdata->control_block.res_queue_addr_high),
1120 le32_to_cpu(hostdata->control_block.res_queue_addr_lo));
1121 pci_free_consistent(hostdata->pci_dev, RES_SIZE + REQ_SIZE, hostdata->res, busaddr);
1122
1123 LEAVE("isp2x00_release");
1124
1125 return 0;
1126}
1127
1128
1129static const char *isp2x00_info(struct Scsi_Host *host)
1130{
1131 static char buf[80];
1132 struct isp2x00_hostdata *hostdata;
1133 ENTER("isp2x00_info");
1134
1135 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1136 sprintf(buf,
1137 "QLogic ISP%04x SCSI on PCI bus %02x device %02x irq %d base 0x%lx",
1138 hostdata->pci_dev->device, hostdata->pci_dev->bus->number, hostdata->pci_dev->devfn, host->irq,
1139 host->io_port);
1140
1141
1142 LEAVE("isp2x00_info");
1143
1144 return buf;
1145}
1146
1147
1148/*
1149 * The middle SCSI layer ensures that queuecommand never gets invoked
1150 * concurrently with itself or the interrupt handler (though the
1151 * interrupt handler may call this routine as part of
1152 * request-completion handling).
1153 */
1154static int isp2x00_queuecommand(Scsi_Cmnd * Cmnd, void (*done) (Scsi_Cmnd *))
1155{
1156 int i, sg_count, n, num_free;
1157 u_int in_ptr, out_ptr;
1158 struct dataseg *ds;
1159 struct scatterlist *sg;
1160 struct Command_Entry *cmd;
1161 struct Continuation_Entry *cont;
1162 struct Scsi_Host *host;
1163 struct isp2x00_hostdata *hostdata;
1164
1165 ENTER("isp2x00_queuecommand");
1166
1167 host = Cmnd->device->host;
1168 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1169 Cmnd->scsi_done = done;
1170
1171 DEBUG(isp2x00_print_scsi_cmd(Cmnd));
1172
1173 if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
1174 isp2x00_make_portdb(host);
1175 hostdata->adapter_state = AS_LOOP_GOOD;
1176 printk("qlogicfc%d : Port Database\n", hostdata->host_id);
1177 for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
1178 printk("wwn: %08x%08x scsi_id: %x loop_id: ", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i);
1179 if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)
1180 printk("%x", hostdata->port_db[i].loop_id);
1181 else
1182 printk("Not Available");
1183 printk("\n");
1184 }
1185 }
1186 if (hostdata->adapter_state == AS_FIRMWARE_DEAD) {
1187 printk("qlogicfc%d : The firmware is dead, just return.\n", hostdata->host_id);
1188 host->max_id = 0;
1189 return 0;
1190 }
1191
1192 out_ptr = inw(host->io_port + MBOX4);
1193 in_ptr = hostdata->req_in_ptr;
1194
1195 DEBUG(printk("qlogicfc%d : request queue depth %d\n", hostdata->host_id,
1196 REQ_QUEUE_DEPTH(in_ptr, out_ptr)));
1197
1198 cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
1199 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1200 if (in_ptr == out_ptr) {
1201 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));
1202 return 1;
1203 }
1204 if (hostdata->send_marker) {
1205 struct Marker_Entry *marker;
1206
1207 TRACE("queue marker", in_ptr, 0);
1208
1209 DEBUG(printk("qlogicfc%d : adding marker entry\n", hostdata->host_id));
1210 marker = (struct Marker_Entry *) cmd;
1211 memset(marker, 0, sizeof(struct Marker_Entry));
1212
1213 marker->hdr.entry_type = ENTRY_MARKER;
1214 marker->hdr.entry_cnt = 1;
1215 marker->modifier = SYNC_ALL;
1216
1217 hostdata->send_marker = 0;
1218
1219 if (((in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN) == out_ptr) {
1220 outw(in_ptr, host->io_port + MBOX4);
1221 hostdata->req_in_ptr = in_ptr;
1222 DEBUG(printk("qlogicfc%d : request queue overflow\n", hostdata->host_id));
1223 return 1;
1224 }
1225 cmd = (struct Command_Entry *) &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
1226 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1227 }
1228 TRACE("queue command", in_ptr, Cmnd);
1229
1230 memset(cmd, 0, sizeof(struct Command_Entry));
1231
1232 /* find a free handle mapping slot */
1233 for (i = in_ptr; i != (in_ptr - 1) && hostdata->handle_ptrs[i]; i = ((i + 1) % (QLOGICFC_REQ_QUEUE_LEN + 1)));
1234
1235 if (!hostdata->handle_ptrs[i]) {
1236 cmd->handle = cpu_to_le32(i);
1237 hostdata->handle_ptrs[i] = Cmnd;
1238 hostdata->handle_serials[i] = Cmnd->serial_number;
1239 } else {
1240 printk("qlogicfc%d : no handle slots, this should not happen.\n", hostdata->host_id);
1241 printk("hostdata->queued is %x, in_ptr: %x\n", hostdata->queued, in_ptr);
1242 for (i = 0; i <= QLOGICFC_REQ_QUEUE_LEN; i++){
1243 if (!hostdata->handle_ptrs[i]){
1244 printk("slot %d has %p\n", i, hostdata->handle_ptrs[i]);
1245 }
1246 }
1247 return 1;
1248 }
1249
1250 cmd->hdr.entry_type = ENTRY_COMMAND;
1251 cmd->hdr.entry_cnt = 1;
1252 cmd->target_lun = Cmnd->device->lun;
1253 cmd->expanded_lun = cpu_to_le16(Cmnd->device->lun);
1254#if ISP2x00_PORTDB
1255 cmd->target_id = hostdata->port_db[Cmnd->device->id].loop_id;
1256#else
1257 cmd->target_id = Cmnd->target;
1258#endif
1259 cmd->total_byte_cnt = cpu_to_le32(Cmnd->request_bufflen);
1260 cmd->time_out = 0;
1261 memcpy(cmd->cdb, Cmnd->cmnd, Cmnd->cmd_len);
1262
1263 if (Cmnd->use_sg) {
1264 sg = (struct scatterlist *) Cmnd->request_buffer;
1265 sg_count = pci_map_sg(hostdata->pci_dev, sg, Cmnd->use_sg, Cmnd->sc_data_direction);
1266 cmd->segment_cnt = cpu_to_le16(sg_count);
1267 ds = cmd->dataseg;
1268 /* fill in first two sg entries: */
1269 n = sg_count;
1270 if (n > DATASEGS_PER_COMMAND)
1271 n = DATASEGS_PER_COMMAND;
1272
1273 for (i = 0; i < n; i++) {
1274 ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
1275 ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
1276 ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
1277 ++sg;
1278 }
1279 sg_count -= DATASEGS_PER_COMMAND;
1280
1281 while (sg_count > 0) {
1282 ++cmd->hdr.entry_cnt;
1283 cont = (struct Continuation_Entry *)
1284 &hostdata->req[in_ptr*QUEUE_ENTRY_LEN];
1285 memset(cont, 0, sizeof(struct Continuation_Entry));
1286 in_ptr = (in_ptr + 1) & QLOGICFC_REQ_QUEUE_LEN;
1287 if (in_ptr == out_ptr) {
1288 DEBUG(printk("qlogicfc%d : unexpected request queue overflow\n", hostdata->host_id));
1289 return 1;
1290 }
1291 TRACE("queue continuation", in_ptr, 0);
1292 cont->hdr.entry_type = ENTRY_CONTINUATION;
1293 ds = cont->dataseg;
1294 n = sg_count;
1295 if (n > DATASEGS_PER_CONT)
1296 n = DATASEGS_PER_CONT;
1297 for (i = 0; i < n; ++i) {
1298 ds[i].d_base = cpu_to_le32(pci64_dma_lo32(sg_dma_address(sg)));
1299 ds[i].d_base_hi = cpu_to_le32(pci64_dma_hi32(sg_dma_address(sg)));
1300 ds[i].d_count = cpu_to_le32(sg_dma_len(sg));
1301 ++sg;
1302 }
1303 sg_count -= n;
1304 }
1305 } else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE) {
1306 struct page *page = virt_to_page(Cmnd->request_buffer);
1307 unsigned long offset = offset_in_page(Cmnd->request_buffer);
1308 dma_addr_t busaddr = pci_map_page(hostdata->pci_dev,
1309 page, offset,
1310 Cmnd->request_bufflen,
1311 Cmnd->sc_data_direction);
1312 Cmnd->SCp.dma_handle = busaddr;
1313
1314 cmd->dataseg[0].d_base = cpu_to_le32(pci64_dma_lo32(busaddr));
1315 cmd->dataseg[0].d_base_hi = cpu_to_le32(pci64_dma_hi32(busaddr));
1316 cmd->dataseg[0].d_count = cpu_to_le32(Cmnd->request_bufflen);
1317 cmd->segment_cnt = cpu_to_le16(1);
1318 } else {
1319 cmd->dataseg[0].d_base = 0;
1320 cmd->dataseg[0].d_base_hi = 0;
1321 cmd->segment_cnt = cpu_to_le16(1); /* Shouldn't this be 0? */
1322 }
1323
1324 if (Cmnd->sc_data_direction == DMA_TO_DEVICE)
1325 cmd->control_flags = cpu_to_le16(CFLAG_WRITE);
1326 else
1327 cmd->control_flags = cpu_to_le16(CFLAG_READ);
1328
1329 if (Cmnd->device->tagged_supported) {
1330 if (time_after(jiffies, hostdata->tag_ages[Cmnd->device->id] + (2 * ISP_TIMEOUT))) {
1331 cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
1332 hostdata->tag_ages[Cmnd->device->id] = jiffies;
1333 } else
1334 switch (Cmnd->tag) {
1335 case HEAD_OF_QUEUE_TAG:
1336 cmd->control_flags |= cpu_to_le16(CFLAG_HEAD_TAG);
1337 break;
1338 case ORDERED_QUEUE_TAG:
1339 cmd->control_flags |= cpu_to_le16(CFLAG_ORDERED_TAG);
1340 break;
1341 default:
1342 cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);
1343 break;
1344 }
1345 }
1346 /*
1347 * TEST_UNIT_READY commands from scsi_scan will fail due to "overlapped
1348 * commands attempted" unless we setup at least a simple queue (midlayer
1349 * will embelish this once it can do an INQUIRY command to the device)
1350 */
1351 else
1352 cmd->control_flags |= cpu_to_le16(CFLAG_SIMPLE_TAG);
1353 outw(in_ptr, host->io_port + MBOX4);
1354 hostdata->req_in_ptr = in_ptr;
1355
1356 hostdata->queued++;
1357
1358 num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
1359 num_free = (num_free > 2) ? num_free - 2 : 0;
1360 host->can_queue = host->host_busy + num_free;
1361 if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
1362 host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
1363 host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
1364
1365 LEAVE("isp2x00_queuecommand");
1366
1367 return 0;
1368}
1369
1370
1371/* we have received an event, such as a lip or an RSCN, which may mean that
1372 * our port database is incorrect so the port database must be recreated.
1373 */
1374static void redo_port_db(unsigned long arg)
1375{
1376
1377 struct Scsi_Host * host = (struct Scsi_Host *) arg;
1378 struct isp2x00_hostdata * hostdata;
1379 unsigned long flags;
1380 int i;
1381
1382 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1383 hostdata->explore_timer.data = 0;
1384 del_timer(&hostdata->explore_timer);
1385
1386 spin_lock_irqsave(host->host_lock, flags);
1387
1388 if (hostdata->adapter_state & AS_REDO_FABRIC_PORTDB || hostdata->adapter_state & AS_REDO_LOOP_PORTDB) {
1389 isp2x00_make_portdb(host);
1390 printk("qlogicfc%d : Port Database\n", hostdata->host_id);
1391 for (i = 0; hostdata->port_db[i].wwn != 0; i++) {
1392 printk("wwn: %08x%08x scsi_id: %x loop_id: ", (u_int) (hostdata->port_db[i].wwn >> 32), (u_int) hostdata->port_db[i].wwn, i);
1393 if (hostdata->port_db[i].loop_id != hostdata->port_db[0].loop_id || i == 0)
1394 printk("%x", hostdata->port_db[i].loop_id);
1395 else
1396 printk("Not Available");
1397 printk("\n");
1398 }
1399
1400 for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++){
1401 if (hostdata->handle_ptrs[i] && (hostdata->port_db[hostdata->handle_ptrs[i]->device->id].loop_id > QLOGICFC_MAX_LOOP_ID || hostdata->adapter_state & AS_REDO_LOOP_PORTDB)){
1402 if (hostdata->port_db[hostdata->handle_ptrs[i]->device->id].loop_id != hostdata->port_db[0].loop_id){
1403 Scsi_Cmnd *Cmnd = hostdata->handle_ptrs[i];
1404
1405 if (Cmnd->use_sg)
1406 pci_unmap_sg(hostdata->pci_dev,
1407 (struct scatterlist *)Cmnd->buffer,
1408 Cmnd->use_sg,
1409 Cmnd->sc_data_direction);
1410 else if (Cmnd->request_bufflen &&
1411 Cmnd->sc_data_direction != PCI_DMA_NONE) {
1412 pci_unmap_page(hostdata->pci_dev,
1413 Cmnd->SCp.dma_handle,
1414 Cmnd->request_bufflen,
1415 Cmnd->sc_data_direction);
1416 }
1417
1418 hostdata->handle_ptrs[i]->result = DID_SOFT_ERROR << 16;
1419
1420 if (hostdata->handle_ptrs[i]->scsi_done){
1421 (*hostdata->handle_ptrs[i]->scsi_done) (hostdata->handle_ptrs[i]);
1422 }
1423 else printk("qlogicfc%d : done is null?\n", hostdata->host_id);
1424 hostdata->handle_ptrs[i] = NULL;
1425 hostdata->handle_serials[i] = 0;
1426 }
1427 }
1428 }
1429
1430 hostdata->adapter_state = AS_LOOP_GOOD;
1431 }
1432
1433 spin_unlock_irqrestore(host->host_lock, flags);
1434
1435}
1436
1437#define ASYNC_EVENT_INTERRUPT 0x01
1438
1439irqreturn_t do_isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1440{
1441 struct Scsi_Host *host = dev_id;
1442 unsigned long flags;
1443
1444 spin_lock_irqsave(host->host_lock, flags);
1445 isp2x00_intr_handler(irq, dev_id, regs);
1446 spin_unlock_irqrestore(host->host_lock, flags);
1447
1448 return IRQ_HANDLED;
1449}
1450
1451void isp2x00_intr_handler(int irq, void *dev_id, struct pt_regs *regs)
1452{
1453 Scsi_Cmnd *Cmnd;
1454 struct Status_Entry *sts;
1455 struct Scsi_Host *host = dev_id;
1456 struct isp2x00_hostdata *hostdata;
1457 u_int in_ptr, out_ptr, handle, num_free;
1458 u_short status;
1459
1460 ENTER_INTR("isp2x00_intr_handler");
1461
1462 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1463
1464 DEBUG_INTR(printk("qlogicfc%d : interrupt on line %d\n", hostdata->host_id, irq));
1465
1466 if (!(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
1467 /* spurious interrupts can happen legally */
1468 DEBUG_INTR(printk("qlogicfc%d : got spurious interrupt\n", hostdata->host_id));
1469 return;
1470 }
1471 in_ptr = inw(host->io_port + MBOX5);
1472 out_ptr = hostdata->res_out_ptr;
1473
1474 if ((inw(host->io_port + PCI_SEMAPHORE) & ASYNC_EVENT_INTERRUPT)) {
1475 status = inw(host->io_port + MBOX0);
1476
1477 DEBUG_INTR(printk("qlogicfc%d : mbox completion status: %x\n",
1478 hostdata->host_id, status));
1479
1480 switch (status) {
1481 case LOOP_UP:
1482 case POINT_TO_POINT_UP:
1483 printk("qlogicfc%d : Link is Up\n", hostdata->host_id);
1484 hostdata->adapter_state = AS_REDO_FABRIC_PORTDB | AS_REDO_LOOP_PORTDB;
1485 break;
1486 case LOOP_DOWN:
1487 printk("qlogicfc%d : Link is Down\n", hostdata->host_id);
1488 hostdata->adapter_state = AS_LOOP_DOWN;
1489 break;
1490 case CONNECTION_MODE:
1491 printk("received CONNECTION_MODE irq %x\n", inw(host->io_port + MBOX1));
1492 break;
1493 case CHANGE_NOTIFICATION:
1494 printk("qlogicfc%d : RSCN Received\n", hostdata->host_id);
1495 if (hostdata->adapter_state == AS_LOOP_GOOD)
1496 hostdata->adapter_state = AS_REDO_FABRIC_PORTDB;
1497 break;
1498 case LIP_OCCURRED:
1499 case LIP_RECEIVED:
1500 printk("qlogicfc%d : Loop Reinitialized\n", hostdata->host_id);
1501 if (hostdata->adapter_state == AS_LOOP_GOOD)
1502 hostdata->adapter_state = AS_REDO_LOOP_PORTDB;
1503 break;
1504 case SYSTEM_ERROR:
1505 printk("qlogicfc%d : The firmware just choked.\n", hostdata->host_id);
1506 hostdata->adapter_state = AS_FIRMWARE_DEAD;
1507 break;
1508 case SCSI_COMMAND_COMPLETE:
1509 handle = inw(host->io_port + MBOX1) | (inw(host->io_port + MBOX2) << 16);
1510 Cmnd = hostdata->handle_ptrs[handle];
1511 hostdata->handle_ptrs[handle] = NULL;
1512 hostdata->handle_serials[handle] = 0;
1513 hostdata->queued--;
1514 if (Cmnd != NULL) {
1515 if (Cmnd->use_sg)
1516 pci_unmap_sg(hostdata->pci_dev,
1517 (struct scatterlist *)Cmnd->buffer,
1518 Cmnd->use_sg,
1519 Cmnd->sc_data_direction);
1520 else if (Cmnd->request_bufflen &&
1521 Cmnd->sc_data_direction != PCI_DMA_NONE)
1522 pci_unmap_page(hostdata->pci_dev,
1523 Cmnd->SCp.dma_handle,
1524 Cmnd->request_bufflen,
1525 Cmnd->sc_data_direction);
1526 Cmnd->result = 0x0;
1527 (*Cmnd->scsi_done) (Cmnd);
1528 } else
1529 printk("qlogicfc%d.c : got a null value out of handle_ptrs, this sucks\n", hostdata->host_id);
1530 break;
1531 case MBOX_COMMAND_COMPLETE:
1532 case INVALID_COMMAND:
1533 case HOST_INTERFACE_ERROR:
1534 case TEST_FAILED:
1535 case COMMAND_ERROR:
1536 case COMMAND_PARAM_ERROR:
1537 case PORT_ID_USED:
1538 case LOOP_ID_USED:
1539 case ALL_IDS_USED:
1540 hostdata->mbox_done = 1;
1541 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
1542 return;
1543 default:
1544 printk("qlogicfc%d : got an unknown status? %x\n", hostdata->host_id, status);
1545 }
1546 if ((hostdata->adapter_state & AS_REDO_LOOP_PORTDB || hostdata->adapter_state & AS_REDO_FABRIC_PORTDB) && hostdata->explore_timer.data == 0){
1547 hostdata->explore_timer.function = redo_port_db;
1548 hostdata->explore_timer.data = (unsigned long)host;
1549 hostdata->explore_timer.expires = jiffies + (HZ/4);
1550 init_timer(&hostdata->explore_timer);
1551 add_timer(&hostdata->explore_timer);
1552 }
1553 outw(0x0, host->io_port + PCI_SEMAPHORE);
1554 } else {
1555 DEBUG_INTR(printk("qlogicfc%d : response queue update\n", hostdata->host_id));
1556 DEBUG_INTR(printk("qlogicfc%d : response queue depth %d\n", hostdata->host_id, RES_QUEUE_DEPTH(in_ptr, out_ptr)));
1557
1558 while (out_ptr != in_ptr) {
1559 unsigned le_hand;
1560 sts = (struct Status_Entry *) &hostdata->res[out_ptr*QUEUE_ENTRY_LEN];
1561 out_ptr = (out_ptr + 1) & RES_QUEUE_LEN;
1562
1563 TRACE("done", out_ptr, Cmnd);
1564 DEBUG_INTR(isp2x00_print_status_entry(sts));
1565 le_hand = le32_to_cpu(sts->handle);
1566 if (sts->hdr.entry_type == ENTRY_STATUS && (Cmnd = hostdata->handle_ptrs[le_hand])) {
1567 Cmnd->result = isp2x00_return_status(Cmnd, sts);
1568 hostdata->queued--;
1569
1570 if (Cmnd->use_sg)
1571 pci_unmap_sg(hostdata->pci_dev,
1572 (struct scatterlist *)Cmnd->buffer, Cmnd->use_sg,
1573 Cmnd->sc_data_direction);
1574 else if (Cmnd->request_bufflen && Cmnd->sc_data_direction != PCI_DMA_NONE)
1575 pci_unmap_page(hostdata->pci_dev,
1576 Cmnd->SCp.dma_handle,
1577 Cmnd->request_bufflen,
1578 Cmnd->sc_data_direction);
1579
1580 /*
1581 * if any of the following are true we do not
1582 * call scsi_done. if the status is CS_ABORTED
1583 * we don't have to call done because the upper
1584 * level should already know its aborted.
1585 */
1586 if (hostdata->handle_serials[le_hand] != Cmnd->serial_number
1587 || le16_to_cpu(sts->completion_status) == CS_ABORTED){
1588 hostdata->handle_serials[le_hand] = 0;
1589 hostdata->handle_ptrs[le_hand] = NULL;
1590 outw(out_ptr, host->io_port + MBOX5);
1591 continue;
1592 }
1593 /*
1594 * if we get back an error indicating the port
1595 * is not there or if the link is down and
1596 * this is a device that used to be there
1597 * allow the command to timeout.
1598 * the device may well be back in a couple of
1599 * seconds.
1600 */
1601 if ((hostdata->adapter_state == AS_LOOP_DOWN || sts->completion_status == cpu_to_le16(CS_PORT_UNAVAILABLE) || sts->completion_status == cpu_to_le16(CS_PORT_LOGGED_OUT) || sts->completion_status == cpu_to_le16(CS_PORT_CONFIG_CHANGED)) && hostdata->port_db[Cmnd->device->id].wwn){
1602 outw(out_ptr, host->io_port + MBOX5);
1603 continue;
1604 }
1605 } else {
1606 outw(out_ptr, host->io_port + MBOX5);
1607 continue;
1608 }
1609
1610 hostdata->handle_ptrs[le_hand] = NULL;
1611
1612 if (sts->completion_status == cpu_to_le16(CS_RESET_OCCURRED)
1613 || (sts->status_flags & cpu_to_le16(STF_BUS_RESET)))
1614 hostdata->send_marker = 1;
1615
1616 if (le16_to_cpu(sts->scsi_status) & 0x0200)
1617 memcpy(Cmnd->sense_buffer, sts->req_sense_data,
1618 sizeof(Cmnd->sense_buffer));
1619
1620 outw(out_ptr, host->io_port + MBOX5);
1621
1622 if (Cmnd->scsi_done != NULL) {
1623 (*Cmnd->scsi_done) (Cmnd);
1624 } else
1625 printk("qlogicfc%d : Ouch, scsi done is NULL\n", hostdata->host_id);
1626 }
1627 hostdata->res_out_ptr = out_ptr;
1628 }
1629
1630
1631 out_ptr = inw(host->io_port + MBOX4);
1632 in_ptr = hostdata->req_in_ptr;
1633
1634 num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
1635 num_free = (num_free > 2) ? num_free - 2 : 0;
1636 host->can_queue = host->host_busy + num_free;
1637 if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
1638 host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
1639 host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
1640
1641 outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
1642 LEAVE_INTR("isp2x00_intr_handler");
1643}
1644
1645
1646static int isp2x00_return_status(Scsi_Cmnd *Cmnd, struct Status_Entry *sts)
1647{
1648 int host_status = DID_ERROR;
1649#if DEBUG_ISP2x00_INTR
1650 static char *reason[] =
1651 {
1652 "DID_OK",
1653 "DID_NO_CONNECT",
1654 "DID_BUS_BUSY",
1655 "DID_TIME_OUT",
1656 "DID_BAD_TARGET",
1657 "DID_ABORT",
1658 "DID_PARITY",
1659 "DID_ERROR",
1660 "DID_RESET",
1661 "DID_BAD_INTR"
1662 };
1663#endif /* DEBUG_ISP2x00_INTR */
1664
1665 ENTER("isp2x00_return_status");
1666
1667 DEBUG(printk("qlogicfc : completion status = 0x%04x\n",
1668 le16_to_cpu(sts->completion_status)));
1669
1670 switch (le16_to_cpu(sts->completion_status)) {
1671 case CS_COMPLETE:
1672 host_status = DID_OK;
1673 break;
1674 case CS_DMA_ERROR:
1675 host_status = DID_ERROR;
1676 break;
1677 case CS_RESET_OCCURRED:
1678 host_status = DID_RESET;
1679 break;
1680 case CS_ABORTED:
1681 host_status = DID_ABORT;
1682 break;
1683 case CS_TIMEOUT:
1684 host_status = DID_TIME_OUT;
1685 break;
1686 case CS_DATA_OVERRUN:
1687 host_status = DID_ERROR;
1688 break;
1689 case CS_DATA_UNDERRUN:
1690 if (Cmnd->underflow <= (Cmnd->request_bufflen - le32_to_cpu(sts->residual)))
1691 host_status = DID_OK;
1692 else
1693 host_status = DID_ERROR;
1694 break;
1695 case CS_PORT_UNAVAILABLE:
1696 case CS_PORT_LOGGED_OUT:
1697 case CS_PORT_CONFIG_CHANGED:
1698 host_status = DID_BAD_TARGET;
1699 break;
1700 case CS_QUEUE_FULL:
1701 host_status = DID_ERROR;
1702 break;
1703 default:
1704 printk("qlogicfc : unknown completion status 0x%04x\n",
1705 le16_to_cpu(sts->completion_status));
1706 host_status = DID_ERROR;
1707 break;
1708 }
1709
1710 DEBUG_INTR(printk("qlogicfc : host status (%s) scsi status %x\n",
1711 reason[host_status], le16_to_cpu(sts->scsi_status)));
1712
1713 LEAVE("isp2x00_return_status");
1714
1715 return (le16_to_cpu(sts->scsi_status) & STATUS_MASK) | (host_status << 16);
1716}
1717
1718
1719static int isp2x00_abort(Scsi_Cmnd * Cmnd)
1720{
1721 u_short param[8];
1722 int i;
1723 struct Scsi_Host *host;
1724 struct isp2x00_hostdata *hostdata;
1725 int return_status = SUCCESS;
1726
1727 ENTER("isp2x00_abort");
1728
1729 host = Cmnd->device->host;
1730 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1731
1732 for (i = 0; i < QLOGICFC_REQ_QUEUE_LEN; i++)
1733 if (hostdata->handle_ptrs[i] == Cmnd)
1734 break;
1735
1736 if (i == QLOGICFC_REQ_QUEUE_LEN){
1737 return SUCCESS;
1738 }
1739
1740 isp2x00_disable_irqs(host);
1741
1742 param[0] = MBOX_ABORT_IOCB;
1743#if ISP2x00_PORTDB
1744 param[1] = (((u_short) hostdata->port_db[Cmnd->device->id].loop_id) << 8) | Cmnd->device->lun;
1745#else
1746 param[1] = (((u_short) Cmnd->target) << 8) | Cmnd->lun;
1747#endif
1748 param[2] = i & 0xffff;
1749 param[3] = i >> 16;
1750
1751 isp2x00_mbox_command(host, param);
1752
1753 if (param[0] != MBOX_COMMAND_COMPLETE) {
1754 printk("qlogicfc%d : scsi abort failure: %x\n", hostdata->host_id, param[0]);
1755 if (param[0] == 0x4005)
1756 Cmnd->result = DID_ERROR << 16;
1757 if (param[0] == 0x4006)
1758 Cmnd->result = DID_BAD_TARGET << 16;
1759 return_status = FAILED;
1760 }
1761
1762 if (return_status != SUCCESS){
1763 param[0] = MBOX_GET_FIRMWARE_STATE;
1764 isp2x00_mbox_command(host, param);
1765 printk("qlogicfc%d : abort failed\n", hostdata->host_id);
1766 printk("qlogicfc%d : firmware status is %x %x\n", hostdata->host_id, param[0], param[1]);
1767 }
1768
1769 isp2x00_enable_irqs(host);
1770
1771 LEAVE("isp2x00_abort");
1772
1773 return return_status;
1774}
1775
1776
1777static int isp2x00_biosparam(struct scsi_device *sdev, struct block_device *n,
1778 sector_t capacity, int ip[])
1779{
1780 int size = capacity;
1781
1782 ENTER("isp2x00_biosparam");
1783
1784 ip[0] = 64;
1785 ip[1] = 32;
1786 ip[2] = size >> 11;
1787 if (ip[2] > 1024) {
1788 ip[0] = 255;
1789 ip[1] = 63;
1790 ip[2] = size / (ip[0] * ip[1]);
1791 }
1792 LEAVE("isp2x00_biosparam");
1793
1794 return 0;
1795}
1796
1797static int isp2x00_reset_hardware(struct Scsi_Host *host)
1798{
1799 u_short param[8];
1800 struct isp2x00_hostdata *hostdata;
1801 int loop_count;
1802 dma_addr_t busaddr;
1803
1804 ENTER("isp2x00_reset_hardware");
1805
1806 hostdata = (struct isp2x00_hostdata *) host->hostdata;
1807
1808 /*
1809 * This cannot be right - PCI writes are posted
1810 * (apparently this is hardware design flaw not software ?)
1811 */
1812
1813 outw(0x01, host->io_port + ISP_CTRL_STATUS);
1814 udelay(100);
1815 outw(HCCR_RESET, host->io_port + HOST_HCCR);
1816 udelay(100);
1817 outw(HCCR_RELEASE, host->io_port + HOST_HCCR);
1818 outw(HCCR_BIOS_DISABLE, host->io_port + HOST_HCCR);
1819
1820 loop_count = DEFAULT_LOOP_COUNT;
1821 while (--loop_count && inw(host->io_port + HOST_HCCR) == RISC_BUSY) {
1822 barrier();
1823 cpu_relax();
1824 }
1825 if (!loop_count)
1826 printk("qlogicfc%d : reset_hardware loop timeout\n", hostdata->host_id);
1827
1828
1829
1830#if DEBUG_ISP2x00
1831 printk("qlogicfc%d : mbox 0 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX0));
1832 printk("qlogicfc%d : mbox 1 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX1));
1833 printk("qlogicfc%d : mbox 2 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX2));
1834 printk("qlogicfc%d : mbox 3 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX3));
1835 printk("qlogicfc%d : mbox 4 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX4));
1836 printk("qlogicfc%d : mbox 5 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX5));
1837 printk("qlogicfc%d : mbox 6 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX6));
1838 printk("qlogicfc%d : mbox 7 0x%04x \n", hostdata->host_id, inw(host->io_port + MBOX7));
1839#endif /* DEBUG_ISP2x00 */
1840
1841 DEBUG(printk("qlogicfc%d : verifying checksum\n", hostdata->host_id));
1842
1843#if defined(CONFIG_SCSI_QLOGIC_FC_FIRMWARE)
1844 {
1845 int i;
1846 unsigned short * risc_code = NULL;
1847 unsigned short risc_code_len = 0;
1848 if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2100){
1849 risc_code = risc_code2100;
1850 risc_code_len = risc_code_length2100;
1851 }
1852 else if (hostdata->pci_dev->device == PCI_DEVICE_ID_QLOGIC_ISP2200){
1853 risc_code = risc_code2200;
1854 risc_code_len = risc_code_length2200;
1855 }
1856
1857 for (i = 0; i < risc_code_len; i++) {
1858 param[0] = MBOX_WRITE_RAM_WORD;
1859 param[1] = risc_code_addr01 + i;
1860 param[2] = risc_code[i];
1861
1862 isp2x00_mbox_command(host, param);
1863
1864 if (param[0] != MBOX_COMMAND_COMPLETE) {
1865 printk("qlogicfc%d : firmware load failure\n", hostdata->host_id);
1866 return 1;
1867 }
1868 }
1869 }
1870#endif /* RELOAD_FIRMWARE */
1871
1872 param[0] = MBOX_VERIFY_CHECKSUM;
1873 param[1] = risc_code_addr01;
1874
1875 isp2x00_mbox_command(host, param);
1876
1877 if (param[0] != MBOX_COMMAND_COMPLETE) {
1878 printk("qlogicfc%d : ram checksum failure\n", hostdata->host_id);
1879 return 1;
1880 }
1881 DEBUG(printk("qlogicfc%d : executing firmware\n", hostdata->host_id));
1882
1883 param[0] = MBOX_EXEC_FIRMWARE;
1884 param[1] = risc_code_addr01;
1885
1886 isp2x00_mbox_command(host, param);
1887
1888 param[0] = MBOX_ABOUT_FIRMWARE;
1889
1890 isp2x00_mbox_command(host, param);
1891
1892 if (param[0] != MBOX_COMMAND_COMPLETE) {
1893 printk("qlogicfc%d : about firmware failure\n", hostdata->host_id);
1894 return 1;
1895 }
1896 DEBUG(printk("qlogicfc%d : firmware major revision %d\n", hostdata->host_id, param[1]));
1897 DEBUG(printk("qlogicfc%d : firmware minor revision %d\n", hostdata->host_id, param[2]));
1898
1899#ifdef USE_NVRAM_DEFAULTS
1900
1901 if (isp2x00_get_nvram_defaults(host, &hostdata->control_block) != 0) {
1902 printk("qlogicfc%d : Could not read from NVRAM\n", hostdata->host_id);
1903 }
1904#endif
1905
1906 hostdata->wwn = (u64) (cpu_to_le16(hostdata->control_block.node_name[0])) << 56;
1907 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[0]) & 0xff00) << 48;
1908 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[1]) & 0xff00) << 24;
1909 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[1]) & 0x00ff) << 48;
1910 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[2]) & 0x00ff) << 24;
1911 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[2]) & 0xff00) << 8;
1912 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0x00ff) << 8;
1913 hostdata->wwn |= (u64) (cpu_to_le16(hostdata->control_block.node_name[3]) & 0xff00) >> 8;
1914
1915 /* FIXME: If the DMA transfer goes one way only, this should use
1916 * PCI_DMA_TODEVICE and below as well.
1917 */
1918 busaddr = pci_map_page(hostdata->pci_dev,
1919 virt_to_page(&hostdata->control_block),
1920 offset_in_page(&hostdata->control_block),
1921 sizeof(hostdata->control_block),
1922 PCI_DMA_BIDIRECTIONAL);
1923
1924 param[0] = MBOX_INIT_FIRMWARE;
1925 param[2] = (u_short) (pci64_dma_lo32(busaddr) >> 16);
1926 param[3] = (u_short) (pci64_dma_lo32(busaddr) & 0xffff);
1927 param[4] = 0;
1928 param[5] = 0;
1929 param[6] = (u_short) (pci64_dma_hi32(busaddr) >> 16);
1930 param[7] = (u_short) (pci64_dma_hi32(busaddr) & 0xffff);
1931 isp2x00_mbox_command(host, param);
1932 if (param[0] != MBOX_COMMAND_COMPLETE) {
1933 printk("qlogicfc%d.c: Ouch 0x%04x\n", hostdata->host_id, param[0]);
1934 pci_unmap_page(hostdata->pci_dev, busaddr,
1935 sizeof(hostdata->control_block),
1936 PCI_DMA_BIDIRECTIONAL);
1937 return 1;
1938 }
1939 param[0] = MBOX_GET_FIRMWARE_STATE;
1940 isp2x00_mbox_command(host, param);
1941 if (param[0] != MBOX_COMMAND_COMPLETE) {
1942 printk("qlogicfc%d.c: 0x%04x\n", hostdata->host_id, param[0]);
1943 pci_unmap_page(hostdata->pci_dev, busaddr,
1944 sizeof(hostdata->control_block),
1945 PCI_DMA_BIDIRECTIONAL);
1946 return 1;
1947 }
1948
1949 pci_unmap_page(hostdata->pci_dev, busaddr,
1950 sizeof(hostdata->control_block),
1951 PCI_DMA_BIDIRECTIONAL);
1952 LEAVE("isp2x00_reset_hardware");
1953
1954 return 0;
1955}
1956
1957#ifdef USE_NVRAM_DEFAULTS
1958
1959static int isp2x00_get_nvram_defaults(struct Scsi_Host *host, struct init_cb *control_block)
1960{
1961
1962 u_short value;
1963 if (isp2x00_read_nvram_word(host, 0) != 0x5349)
1964 return 1;
1965
1966 value = isp2x00_read_nvram_word(host, 8);
1967 control_block->node_name[0] = cpu_to_le16(isp2x00_read_nvram_word(host, 9));
1968 control_block->node_name[1] = cpu_to_le16(isp2x00_read_nvram_word(host, 10));
1969 control_block->node_name[2] = cpu_to_le16(isp2x00_read_nvram_word(host, 11));
1970 control_block->node_name[3] = cpu_to_le16(isp2x00_read_nvram_word(host, 12));
1971 control_block->hard_addr = cpu_to_le16(isp2x00_read_nvram_word(host, 13));
1972
1973 return 0;
1974
1975}
1976
1977#endif
1978
1979static int isp2x00_init(struct Scsi_Host *sh)
1980{
1981 u_long io_base;
1982 struct isp2x00_hostdata *hostdata;
1983 u_char revision;
1984 u_int irq;
1985 u_short command;
1986 struct pci_dev *pdev;
1987
1988
1989 ENTER("isp2x00_init");
1990
1991 hostdata = (struct isp2x00_hostdata *) sh->hostdata;
1992 pdev = hostdata->pci_dev;
1993
1994 if (pci_read_config_word(pdev, PCI_COMMAND, &command)
1995 || pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision)) {
1996 printk("qlogicfc%d : error reading PCI configuration\n", hostdata->host_id);
1997 return 1;
1998 }
1999 io_base = pci_resource_start(pdev, 0);
2000 irq = pdev->irq;
2001
2002
2003 if (pdev->vendor != PCI_VENDOR_ID_QLOGIC) {
2004 printk("qlogicfc%d : 0x%04x is not QLogic vendor ID\n", hostdata->host_id,
2005 pdev->vendor);
2006 return 1;
2007 }
2008 if (pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2100 && pdev->device != PCI_DEVICE_ID_QLOGIC_ISP2200) {
2009 printk("qlogicfc%d : 0x%04x does not match ISP2100 or ISP2200 device id\n", hostdata->host_id,
2010 pdev->device);
2011 return 1;
2012 }
2013 if (!(command & PCI_COMMAND_IO) ||
2014 !(pdev->resource[0].flags & IORESOURCE_IO)) {
2015 printk("qlogicfc%d : i/o mapping is disabled\n", hostdata->host_id);
2016 return 1;
2017 }
2018
2019 pci_set_master(pdev);
2020 if (revision != ISP2100_REV_ID1 && revision != ISP2100_REV_ID3 && revision != ISP2200_REV_ID5)
2021 printk("qlogicfc%d : new isp2x00 revision ID (%d)\n", hostdata->host_id, revision);
2022
2023
2024 hostdata->revision = revision;
2025
2026 sh->irq = irq;
2027 sh->io_port = io_base;
2028
2029 LEAVE("isp2x00_init");
2030
2031 return 0;
2032}
2033
2034#if USE_NVRAM_DEFAULTS
2035
2036#define NVRAM_DELAY() udelay(10) /* 10 microsecond delay */
2037
2038
2039u_short isp2x00_read_nvram_word(struct Scsi_Host * host, u_short byte)
2040{
2041 int i;
2042 u_short value, output, input;
2043
2044 outw(0x2, host->io_port + PCI_NVRAM);
2045 NVRAM_DELAY();
2046 outw(0x3, host->io_port + PCI_NVRAM);
2047 NVRAM_DELAY();
2048
2049 byte &= 0xff;
2050 byte |= 0x0600;
2051 for (i = 10; i >= 0; i--) {
2052 output = ((byte >> i) & 0x1) ? 0x4 : 0x0;
2053 outw(output | 0x2, host->io_port + PCI_NVRAM);
2054 NVRAM_DELAY();
2055 outw(output | 0x3, host->io_port + PCI_NVRAM);
2056 NVRAM_DELAY();
2057 outw(output | 0x2, host->io_port + PCI_NVRAM);
2058 NVRAM_DELAY();
2059 }
2060
2061 for (i = 0xf, value = 0; i >= 0; i--) {
2062 value <<= 1;
2063 outw(0x3, host->io_port + PCI_NVRAM);
2064 NVRAM_DELAY();
2065 input = inw(host->io_port + PCI_NVRAM);
2066 NVRAM_DELAY();
2067 outw(0x2, host->io_port + PCI_NVRAM);
2068 NVRAM_DELAY();
2069 if (input & 0x8)
2070 value |= 1;
2071 }
2072
2073 outw(0x0, host->io_port + PCI_NVRAM);
2074 NVRAM_DELAY();
2075
2076 return value;
2077}
2078
2079
2080#endif /* USE_NVRAM_DEFAULTS */
2081
2082
2083
2084/*
2085 * currently, this is only called during initialization or abort/reset,
2086 * at which times interrupts are disabled, so polling is OK, I guess...
2087 */
2088static int isp2x00_mbox_command(struct Scsi_Host *host, u_short param[])
2089{
2090 int loop_count;
2091 struct isp2x00_hostdata *hostdata = (struct isp2x00_hostdata *) host->hostdata;
2092
2093 if (mbox_param[param[0]] == 0 || hostdata->adapter_state == AS_FIRMWARE_DEAD)
2094 return 1;
2095
2096 loop_count = DEFAULT_LOOP_COUNT;
2097 while (--loop_count && inw(host->io_port + HOST_HCCR) & 0x0080) {
2098 barrier();
2099 cpu_relax();
2100 }
2101 if (!loop_count) {
2102 printk("qlogicfc%d : mbox_command loop timeout #1\n", hostdata->host_id);
2103 param[0] = 0x4006;
2104 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2105 return 1;
2106 }
2107 hostdata->mbox_done = 0;
2108
2109 if (mbox_param[param[0]] == 0)
2110 printk("qlogicfc%d : invalid mbox command\n", hostdata->host_id);
2111
2112 if (mbox_param[param[0]] & 0x80)
2113 outw(param[7], host->io_port + MBOX7);
2114 if (mbox_param[param[0]] & 0x40)
2115 outw(param[6], host->io_port + MBOX6);
2116 if (mbox_param[param[0]] & 0x20)
2117 outw(param[5], host->io_port + MBOX5);
2118 if (mbox_param[param[0]] & 0x10)
2119 outw(param[4], host->io_port + MBOX4);
2120 if (mbox_param[param[0]] & 0x08)
2121 outw(param[3], host->io_port + MBOX3);
2122 if (mbox_param[param[0]] & 0x04)
2123 outw(param[2], host->io_port + MBOX2);
2124 if (mbox_param[param[0]] & 0x02)
2125 outw(param[1], host->io_port + MBOX1);
2126 if (mbox_param[param[0]] & 0x01)
2127 outw(param[0], host->io_port + MBOX0);
2128
2129
2130 outw(HCCR_SET_HOST_INTR, host->io_port + HOST_HCCR);
2131
2132 while (1) {
2133 loop_count = DEFAULT_LOOP_COUNT;
2134 while (--loop_count && !(inw(host->io_port + PCI_INTER_STS) & 0x08)) {
2135 barrier();
2136 cpu_relax();
2137 }
2138
2139 if (!loop_count) {
2140 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2141 printk("qlogicfc%d : mbox_command loop timeout #2\n", hostdata->host_id);
2142 break;
2143 }
2144 isp2x00_intr_handler(host->irq, host, NULL);
2145
2146 if (hostdata->mbox_done == 1)
2147 break;
2148
2149 }
2150
2151 loop_count = DEFAULT_LOOP_COUNT;
2152 while (--loop_count && inw(host->io_port + MBOX0) == 0x04) {
2153 barrier();
2154 cpu_relax();
2155 }
2156 if (!loop_count)
2157 printk("qlogicfc%d : mbox_command loop timeout #3\n", hostdata->host_id);
2158
2159 param[7] = inw(host->io_port + MBOX7);
2160 param[6] = inw(host->io_port + MBOX6);
2161 param[5] = inw(host->io_port + MBOX5);
2162 param[4] = inw(host->io_port + MBOX4);
2163 param[3] = inw(host->io_port + MBOX3);
2164 param[2] = inw(host->io_port + MBOX2);
2165 param[1] = inw(host->io_port + MBOX1);
2166 param[0] = inw(host->io_port + MBOX0);
2167
2168
2169 outw(0x0, host->io_port + PCI_SEMAPHORE);
2170
2171 if (inw(host->io_port + HOST_HCCR) & 0x0080) {
2172 hostdata->adapter_state = AS_FIRMWARE_DEAD;
2173 printk("qlogicfc%d : mbox op is still pending\n", hostdata->host_id);
2174 }
2175 return 0;
2176}
2177
2178#if DEBUG_ISP2x00_INTR
2179
2180void isp2x00_print_status_entry(struct Status_Entry *status)
2181{
2182 printk("qlogicfc : entry count = 0x%02x, type = 0x%02x, flags = 0x%02x\n",
2183 status->hdr.entry_cnt, status->hdr.entry_type, status->hdr.flags);
2184 printk("qlogicfc : scsi status = 0x%04x, completion status = 0x%04x\n",
2185 le16_to_cpu(status->scsi_status), le16_to_cpu(status->completion_status));
2186 printk("qlogicfc : state flags = 0x%04x, status flags = 0x%04x\n",
2187 le16_to_cpu(status->state_flags), le16_to_cpu(status->status_flags));
2188 printk("qlogicfc : response info length = 0x%04x, request sense length = 0x%04x\n",
2189 le16_to_cpu(status->res_info_len), le16_to_cpu(status->req_sense_len));
2190 printk("qlogicfc : residual transfer length = 0x%08x, response = 0x%02x\n", le32_to_cpu(status->residual), status->res_info[3]);
2191
2192}
2193
2194#endif /* DEBUG_ISP2x00_INTR */
2195
2196
2197#if DEBUG_ISP2x00
2198
2199void isp2x00_print_scsi_cmd(Scsi_Cmnd * cmd)
2200{
2201 int i;
2202
2203 printk("qlogicfc : target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
2204 cmd->target, cmd->lun, cmd->cmd_len);
2205 printk("qlogicfc : command = ");
2206 for (i = 0; i < cmd->cmd_len; i++)
2207 printk("0x%02x ", cmd->cmnd[i]);
2208 printk("\n");
2209}
2210
2211#endif /* DEBUG_ISP2x00 */
2212
2213MODULE_LICENSE("GPL");
2214
2215static struct scsi_host_template driver_template = {
2216 .detect = isp2x00_detect,
2217 .release = isp2x00_release,
2218 .info = isp2x00_info,
2219 .queuecommand = isp2x00_queuecommand,
2220 .eh_abort_handler = isp2x00_abort,
2221 .bios_param = isp2x00_biosparam,
2222 .can_queue = QLOGICFC_REQ_QUEUE_LEN,
2223 .this_id = -1,
2224 .sg_tablesize = QLOGICFC_MAX_SG(QLOGICFC_REQ_QUEUE_LEN),
2225 .cmd_per_lun = QLOGICFC_CMD_PER_LUN,
2226 .use_clustering = ENABLE_CLUSTERING,
2227};
2228#include "scsi_module.c"
diff --git a/drivers/scsi/qlogicfc_asm.c b/drivers/scsi/qlogicfc_asm.c
deleted file mode 100644
index b1d45102d388..000000000000
--- a/drivers/scsi/qlogicfc_asm.c
+++ /dev/null
@@ -1,9751 +0,0 @@
1/************************************************************************
2 * *
3 * --- ISP2100 Fabric Initiator/Target Firmware --- *
4 * with expanded LUN addressing *
5 * and FcTape (FCP-2) support *
6 * *
7 * *
8 ************************************************************************
9 Copyright (C) 2000 and 2001 Qlogic Corporation
10 (www.qlogic.com)
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16************************************************************************/
17
18/*
19 * Firmware Version 1.19.16 (10:36 Nov 02, 2000)
20 */
21
22static unsigned short risc_code_addr01 = 0x1000 ;
23
24static unsigned short risc_code_length2100 = 0x9260;
25static unsigned short risc_code2100[] = {
26 0x0078, 0x102d, 0x0000, 0x9260, 0x0000, 0x0001, 0x0013, 0x0010,
27 0x0017, 0x2043, 0x4f50, 0x5952, 0x4947, 0x4854, 0x2031, 0x3939,
28 0x3920, 0x514c, 0x4f47, 0x4943, 0x2043, 0x4f52, 0x504f, 0x5241,
29 0x5449, 0x4f4e, 0x2049, 0x5350, 0x3231, 0x3030, 0x2046, 0x6972,
30 0x6d77, 0x6172, 0x6520, 0x2056, 0x6572, 0x7369, 0x6f6e, 0x2030,
31 0x312e, 0x3139, 0x2020, 0x2020, 0x2400, 0x2091, 0x2000, 0x20c1,
32 0x0021, 0x2039, 0xffff, 0x2019, 0xaaaa, 0x2760, 0x2069, 0x7fff,
33 0x20c1, 0x0020, 0x2c2c, 0x2d34, 0x2762, 0x236a, 0x2c24, 0x2d04,
34 0x266a, 0x2562, 0xa406, 0x00c0, 0x1052, 0x20c1, 0x0021, 0x2c2c,
35 0x2362, 0x2c04, 0x2562, 0xa306, 0x0040, 0x1052, 0x20c1, 0x0020,
36 0x2039, 0x8fff, 0x20a1, 0xaa00, 0x2708, 0x810d, 0x810d, 0x810d,
37 0x810d, 0xa18c, 0x000f, 0x2001, 0x000a, 0xa112, 0xa00e, 0x21a8,
38 0x41a4, 0x3400, 0x8211, 0x00c0, 0x105f, 0x2708, 0x3400, 0xa102,
39 0x0040, 0x106f, 0x0048, 0x106f, 0x20a8, 0xa00e, 0x41a4, 0x20a1,
40 0xa260, 0x2009, 0x0000, 0x20a9, 0x07a0, 0x41a4, 0x3400, 0x20c9,
41 0xa7ff, 0x2059, 0x0000, 0x2b78, 0x7823, 0x0004, 0x2089, 0x255d,
42 0x2051, 0xa300, 0x2a70, 0x775e, 0xa786, 0x8fff, 0x0040, 0x1092,
43 0x705b, 0xca00, 0x7057, 0xc9f1, 0x7063, 0x0200, 0x7067, 0x0200,
44 0x0078, 0x109a, 0x7057, 0xba01, 0x7063, 0x0100, 0x7067, 0x0100,
45 0x705b, 0xba00, 0x1078, 0x12df, 0x1078, 0x13c0, 0x1078, 0x1569,
46 0x1078, 0x1ca4, 0x1078, 0x4229, 0x1078, 0x74cf, 0x1078, 0x134b,
47 0x1078, 0x2a3f, 0x1078, 0x4da2, 0x1078, 0x48b2, 0x1078, 0x57df,
48 0x1078, 0x21f7, 0x1078, 0x5abf, 0x1078, 0x5369, 0x1078, 0x210d,
49 0x1078, 0x21d4, 0x2091, 0x3009, 0x7823, 0x0000, 0x0090, 0x10cf,
50 0x7820, 0xa086, 0x0002, 0x00c0, 0x10cf, 0x7823, 0x4000, 0x0068,
51 0x10c7, 0x781b, 0x0001, 0x2091, 0x5000, 0x2091, 0x4080, 0x2a70,
52 0x7003, 0x0000, 0x2001, 0x017f, 0x2003, 0x0000, 0x2a70, 0x7000,
53 0xa08e, 0x0003, 0x00c0, 0x10ef, 0x1078, 0x35bc, 0x1078, 0x2a67,
54 0x1078, 0x4df2, 0x1078, 0x4a75, 0x2009, 0x0100, 0x2104, 0xa082,
55 0x0002, 0x0048, 0x10f3, 0x1078, 0x57fb, 0x0078, 0x10d6, 0x1079,
56 0x10f7, 0x0078, 0x10dc, 0x1078, 0x6fa9, 0x0078, 0x10eb, 0x1101,
57 0x1102, 0x11be, 0x10ff, 0x1246, 0x12dc, 0x12dd, 0x12de, 0x1078,
58 0x1328, 0x007c, 0x127e, 0x0f7e, 0x2091, 0x8000, 0x7000, 0xa086,
59 0x0001, 0x00c0, 0x1198, 0x1078, 0x3a43, 0x2079, 0x0100, 0x7844,
60 0xa005, 0x00c0, 0x1198, 0x2011, 0x4129, 0x1078, 0x58d4, 0x1078,
61 0x1ab1, 0x780f, 0x00ff, 0x7840, 0xa084, 0xfffb, 0x7842, 0x2011,
62 0x8010, 0x73c0, 0x1078, 0x3579, 0x2001, 0xffff, 0x1078, 0x5975,
63 0x7238, 0xc284, 0x723a, 0x2001, 0xa30c, 0x2014, 0xc2ac, 0x2202,
64 0x1078, 0x6db5, 0x2011, 0x0004, 0x1078, 0x8a59, 0x1078, 0x47ce,
65 0x1078, 0x4211, 0x0040, 0x1144, 0x7083, 0x0001, 0x70bb, 0x0000,
66 0x1078, 0x3bf5, 0x0078, 0x1198, 0x1078, 0x4897, 0x0040, 0x114d,
67 0x7a0c, 0xc2b4, 0x7a0e, 0x0078, 0x1159, 0x1078, 0x8ddf, 0x70c8,
68 0xd09c, 0x00c0, 0x1159, 0x7094, 0xa005, 0x0040, 0x1159, 0x1078,
69 0x41f5, 0x70d3, 0x0000, 0x70cf, 0x0000, 0x72c8, 0x2079, 0xa351,
70 0x7804, 0xd0ac, 0x0040, 0x1165, 0xc295, 0x72ca, 0xa296, 0x0004,
71 0x0040, 0x1186, 0x2011, 0x0001, 0x1078, 0x8a59, 0x708f, 0x0000,
72 0x7093, 0xffff, 0x7003, 0x0002, 0x0f7f, 0x1078, 0x260d, 0x2011,
73 0x0005, 0x1078, 0x6ef2, 0x1078, 0x6109, 0x0c7e, 0x2061, 0x0100,
74 0x60e3, 0x0008, 0x0c7f, 0x127f, 0x0078, 0x119a, 0x708f, 0x0000,
75 0x7093, 0xffff, 0x7003, 0x0002, 0x2011, 0x0005, 0x1078, 0x6ef2,
76 0x1078, 0x6109, 0x0c7e, 0x2061, 0x0100, 0x60e3, 0x0008, 0x0c7f,
77 0x0f7f, 0x127f, 0x007c, 0x0c7e, 0x20a9, 0x0082, 0x2009, 0x007e,
78 0x017e, 0x027e, 0x037e, 0x2110, 0x027e, 0x2019, 0x0029, 0x1078,
79 0x71e0, 0x027f, 0x1078, 0xa190, 0x037f, 0x027f, 0x017f, 0x1078,
80 0x2921, 0x8108, 0x00f0, 0x11a0, 0x0c7f, 0x706b, 0x0000, 0x706c,
81 0xa084, 0x00ff, 0x706e, 0x7097, 0x0000, 0x007c, 0x127e, 0x2091,
82 0x8000, 0x7000, 0xa086, 0x0002, 0x00c0, 0x1244, 0x7090, 0xa086,
83 0xffff, 0x0040, 0x11d1, 0x1078, 0x260d, 0x1078, 0x6109, 0x0078,
84 0x1244, 0x70c8, 0xd09c, 0x0040, 0x11fd, 0xd084, 0x0040, 0x11fd,
85 0x0f7e, 0x2079, 0x0100, 0x790c, 0xc1b5, 0x790e, 0x0f7f, 0xd08c,
86 0x0040, 0x11fd, 0x70cc, 0xa086, 0xffff, 0x0040, 0x11f9, 0x1078,
87 0x278a, 0x1078, 0x6109, 0x70c8, 0xd094, 0x00c0, 0x1244, 0x2011,
88 0x0001, 0x2019, 0x0000, 0x1078, 0x27c2, 0x1078, 0x6109, 0x0078,
89 0x1244, 0x70d0, 0xa005, 0x00c0, 0x1244, 0x708c, 0xa005, 0x00c0,
90 0x1244, 0x1078, 0x4897, 0x00c0, 0x1244, 0x2001, 0xa352, 0x2004,
91 0xd0ac, 0x0040, 0x1227, 0x157e, 0x0c7e, 0x20a9, 0x007f, 0x2009,
92 0x0000, 0x017e, 0x1078, 0x4501, 0x00c0, 0x121a, 0x6000, 0xd0ec,
93 0x00c0, 0x1222, 0x017f, 0x8108, 0x00f0, 0x1211, 0x0c7f, 0x157f,
94 0x0078, 0x1227, 0x017f, 0x0c7f, 0x157f, 0x0078, 0x1244, 0x7003,
95 0x0003, 0x7093, 0xffff, 0x2001, 0x0000, 0x1078, 0x2480, 0x1078,
96 0x35f7, 0x2001, 0xa5ac, 0x2004, 0xa086, 0x0005, 0x00c0, 0x123c,
97 0x2011, 0x0000, 0x1078, 0x6ef2, 0x2011, 0x0000, 0x1078, 0x6efc,
98 0x1078, 0x6109, 0x1078, 0x61d3, 0x127f, 0x007c, 0x017e, 0x0f7e,
99 0x127e, 0x2091, 0x8000, 0x2079, 0x0100, 0x2009, 0x00f7, 0x1078,
100 0x41de, 0x7940, 0xa18c, 0x0010, 0x7942, 0x7924, 0xd1b4, 0x0040,
101 0x125b, 0x7827, 0x0040, 0xd19c, 0x0040, 0x1260, 0x7827, 0x0008,
102 0x007e, 0x037e, 0x157e, 0xa006, 0x1078, 0x5975, 0x7900, 0xa18a,
103 0x0003, 0x0050, 0x1289, 0x7954, 0xd1ac, 0x00c0, 0x1289, 0x2009,
104 0x00f8, 0x1078, 0x41de, 0x7843, 0x0090, 0x7843, 0x0010, 0x20a9,
105 0x09c4, 0x7820, 0xd09c, 0x00c0, 0x1281, 0x7824, 0xd0ac, 0x00c0,
106 0x12ca, 0x00f0, 0x1279, 0x2001, 0x0001, 0x1078, 0x2480, 0x0078,
107 0x12d5, 0x7853, 0x0000, 0x782f, 0x0020, 0x20a9, 0x0050, 0x00e0,
108 0x128f, 0x2091, 0x6000, 0x00f0, 0x128f, 0x7853, 0x0400, 0x782f,
109 0x0000, 0x2009, 0x00f8, 0x1078, 0x41de, 0x20a9, 0x000e, 0x0005,
110 0x00f0, 0x129f, 0x7853, 0x1400, 0x7843, 0x0090, 0x7843, 0x0010,
111 0x2019, 0x61a8, 0x7854, 0x0005, 0x0005, 0xd08c, 0x0040, 0x12b4,
112 0x7824, 0xd0ac, 0x00c0, 0x12ca, 0x8319, 0x00c0, 0x12aa, 0x2009,
113 0xa331, 0x2104, 0x8000, 0x200a, 0xa084, 0xfff0, 0x0040, 0x12c4,
114 0x200b, 0x0000, 0x1078, 0x251e, 0x2001, 0x0001, 0x1078, 0x2480,
115 0x0078, 0x12d3, 0x2001, 0xa331, 0x2003, 0x0000, 0x7828, 0xc09d,
116 0x782a, 0x7827, 0x0048, 0x7853, 0x0400, 0x157f, 0x037f, 0x007f,
117 0x127f, 0x0f7f, 0x017f, 0x007c, 0x007c, 0x007c, 0x007c, 0x2a70,
118 0x2009, 0x0100, 0x2104, 0xa082, 0x0002, 0x0048, 0x12eb, 0x704f,
119 0xffff, 0x0078, 0x12ed, 0x704f, 0x0000, 0x7053, 0xffff, 0x706b,
120 0x0000, 0x706f, 0x0000, 0x1078, 0x8ddf, 0x2061, 0xa58c, 0x6003,
121 0x0909, 0x6007, 0x0000, 0x600b, 0x8800, 0x600f, 0x0200, 0x6013,
122 0x00ff, 0x6017, 0x0003, 0x601b, 0x0000, 0x601f, 0x07d0, 0x2061,
123 0xa594, 0x6003, 0x8000, 0x6007, 0x0000, 0x600b, 0x0000, 0x600f,
124 0x0200, 0x6013, 0x00ff, 0x6017, 0x0000, 0x601b, 0x0001, 0x601f,
125 0x0000, 0x2061, 0xa5a3, 0x6003, 0x514c, 0x6007, 0x4f47, 0x600b,
126 0x4943, 0x600f, 0x2020, 0x2001, 0xa325, 0x2003, 0x0000, 0x007c,
127 0x2091, 0x8000, 0x0068, 0x132a, 0x007e, 0x017e, 0x2079, 0x0000,
128 0x7818, 0xd084, 0x00c0, 0x1330, 0x017f, 0x792e, 0x007f, 0x782a,
129 0x007f, 0x7826, 0x3900, 0x783a, 0x7823, 0x8002, 0x781b, 0x0001,
130 0x2091, 0x5000, 0x2091, 0x4080, 0x2079, 0xa300, 0x7803, 0x0005,
131 0x0078, 0x1348, 0x007c, 0x2071, 0xa300, 0x7158, 0x712e, 0x2021,
132 0x0001, 0xa190, 0x002d, 0xa298, 0x002d, 0x0048, 0x1361, 0x705c,
133 0xa302, 0x00c8, 0x1361, 0x220a, 0x2208, 0x2310, 0x8420, 0x0078,
134 0x1353, 0x200b, 0x0000, 0x74a6, 0x74aa, 0x007c, 0x0e7e, 0x127e,
135 0x2091, 0x8000, 0x2071, 0xa300, 0x70a8, 0xa0ea, 0x0010, 0x00c8,
136 0x1374, 0xa06e, 0x0078, 0x137e, 0x8001, 0x70aa, 0x702c, 0x2068,
137 0x2d04, 0x702e, 0x206b, 0x0000, 0x6807, 0x0000, 0x127f, 0x0e7f,
138 0x007c, 0x0e7e, 0x2071, 0xa300, 0x127e, 0x2091, 0x8000, 0x70a8,
139 0x8001, 0x00c8, 0x138e, 0xa06e, 0x0078, 0x1397, 0x70aa, 0x702c,
140 0x2068, 0x2d04, 0x702e, 0x206b, 0x0000, 0x6807, 0x0000, 0x127f,
141 0x0e7f, 0x007c, 0x0e7e, 0x127e, 0x2091, 0x8000, 0x2071, 0xa300,
142 0x702c, 0x206a, 0x2d00, 0x702e, 0x70a8, 0x8000, 0x70aa, 0x127f,
143 0x0e7f, 0x007c, 0x8dff, 0x0040, 0x13b6, 0x6804, 0x6807, 0x0000,
144 0x007e, 0x1078, 0x139a, 0x0d7f, 0x0078, 0x13aa, 0x007c, 0x0e7e,
145 0x2071, 0xa300, 0x70a8, 0xa08a, 0x0010, 0xa00d, 0x0e7f, 0x007c,
146 0x0e7e, 0x2071, 0xa5d0, 0x7007, 0x0000, 0x701b, 0x0000, 0x701f,
147 0x0000, 0x2071, 0x0000, 0x7010, 0xa085, 0x8004, 0x7012, 0x0e7f,
148 0x007c, 0x0e7e, 0x2270, 0x700b, 0x0000, 0x2071, 0xa5d0, 0x7018,
149 0xa088, 0xa5d9, 0x220a, 0x8000, 0xa084, 0x0007, 0x701a, 0x7004,
150 0xa005, 0x00c0, 0x13e9, 0x0f7e, 0x2079, 0x0010, 0x1078, 0x13fa,
151 0x0f7f, 0x0e7f, 0x007c, 0x0e7e, 0x2071, 0xa5d0, 0x7004, 0xa005,
152 0x00c0, 0x13f8, 0x0f7e, 0x2079, 0x0010, 0x1078, 0x13fa, 0x0f7f,
153 0x0e7f, 0x007c, 0x7000, 0x0079, 0x13fd, 0x1401, 0x146b, 0x1488,
154 0x1488, 0x7018, 0x711c, 0xa106, 0x00c0, 0x1409, 0x7007, 0x0000,
155 0x007c, 0x0d7e, 0xa180, 0xa5d9, 0x2004, 0x700a, 0x2068, 0x8108,
156 0xa18c, 0x0007, 0x711e, 0x7803, 0x0026, 0x6824, 0x7832, 0x6828,
157 0x7836, 0x682c, 0x783a, 0x6830, 0x783e, 0x6810, 0x700e, 0x680c,
158 0x7016, 0x6804, 0x0d7f, 0xd084, 0x0040, 0x142b, 0x7007, 0x0001,
159 0x1078, 0x1430, 0x007c, 0x7007, 0x0002, 0x1078, 0x1446, 0x007c,
160 0x017e, 0x027e, 0x710c, 0x2011, 0x0040, 0xa182, 0x0040, 0x00c8,
161 0x143b, 0x2110, 0xa006, 0x700e, 0x7212, 0x8203, 0x7822, 0x7803,
162 0x0020, 0x7803, 0x0041, 0x027f, 0x017f, 0x007c, 0x017e, 0x027e,
163 0x137e, 0x147e, 0x157e, 0x7014, 0x2098, 0x20a1, 0x0014, 0x7803,
164 0x0026, 0x710c, 0x2011, 0x0040, 0xa182, 0x0040, 0x00c8, 0x145a,
165 0x2110, 0xa006, 0x700e, 0x22a8, 0x53a6, 0x8203, 0x7822, 0x7803,
166 0x0020, 0x3300, 0x7016, 0x7803, 0x0001, 0x157f, 0x147f, 0x137f,
167 0x027f, 0x017f, 0x007c, 0x137e, 0x147e, 0x157e, 0x2099, 0xa3f9,
168 0x20a1, 0x0018, 0x20a9, 0x0008, 0x53a3, 0x7803, 0x0020, 0x127e,
169 0x2091, 0x8000, 0x7803, 0x0041, 0x7007, 0x0003, 0x7000, 0xc084,
170 0x7002, 0x700b, 0xa3f4, 0x127f, 0x157f, 0x147f, 0x137f, 0x007c,
171 0x137e, 0x147e, 0x157e, 0x2001, 0xa428, 0x209c, 0x20a1, 0x0014,
172 0x7803, 0x0026, 0x2001, 0xa429, 0x20ac, 0x53a6, 0x2099, 0xa42a,
173 0x20a1, 0x0018, 0x20a9, 0x0008, 0x53a3, 0x7803, 0x0020, 0x127e,
174 0x2091, 0x8000, 0x7803, 0x0001, 0x7007, 0x0004, 0x7000, 0xc08c,
175 0x7002, 0x700b, 0xa425, 0x127f, 0x157f, 0x147f, 0x137f, 0x007c,
176 0x017e, 0x0e7e, 0x2071, 0xa5d0, 0x0f7e, 0x2079, 0x0010, 0x7904,
177 0x7803, 0x0002, 0xd1fc, 0x0040, 0x14c2, 0xa18c, 0x0700, 0x7004,
178 0x1079, 0x14c6, 0x0f7f, 0x0e7f, 0x017f, 0x007c, 0x13fa, 0x14ce,
179 0x14fb, 0x1523, 0x1556, 0x14cc, 0x0078, 0x14cc, 0xa18c, 0x0700,
180 0x00c0, 0x14f4, 0x137e, 0x147e, 0x157e, 0x7014, 0x20a0, 0x2099,
181 0x0014, 0x7803, 0x0040, 0x7010, 0x20a8, 0x53a5, 0x3400, 0x7016,
182 0x157f, 0x147f, 0x137f, 0x700c, 0xa005, 0x0040, 0x1510, 0x1078,
183 0x1430, 0x007c, 0x7008, 0xa080, 0x0002, 0x2003, 0x0100, 0x7007,
184 0x0000, 0x1078, 0x13fa, 0x007c, 0x7008, 0xa080, 0x0002, 0x2003,
185 0x0200, 0x0078, 0x14ef, 0xa18c, 0x0700, 0x00c0, 0x1506, 0x700c,
186 0xa005, 0x0040, 0x1510, 0x1078, 0x1446, 0x007c, 0x7008, 0xa080,
187 0x0002, 0x2003, 0x0200, 0x7007, 0x0000, 0x1078, 0x13fa, 0x007c,
188 0x0d7e, 0x7008, 0x2068, 0x7830, 0x6826, 0x7834, 0x682a, 0x7838,
189 0x682e, 0x783c, 0x6832, 0x680b, 0x0100, 0x0d7f, 0x7007, 0x0000,
190 0x1078, 0x13fa, 0x007c, 0xa18c, 0x0700, 0x00c0, 0x1550, 0x137e,
191 0x147e, 0x157e, 0x2001, 0xa3f7, 0x2004, 0xa080, 0x000d, 0x20a0,
192 0x2099, 0x0014, 0x7803, 0x0040, 0x20a9, 0x0020, 0x53a5, 0x2001,
193 0xa3f9, 0x2004, 0xd0bc, 0x0040, 0x1546, 0x2001, 0xa402, 0x2004,
194 0xa080, 0x000d, 0x20a0, 0x20a9, 0x0020, 0x53a5, 0x157f, 0x147f,
195 0x137f, 0x7007, 0x0000, 0x1078, 0x4e9b, 0x1078, 0x13fa, 0x007c,
196 0x2011, 0x8003, 0x1078, 0x3579, 0x0078, 0x1554, 0xa18c, 0x0700,
197 0x00c0, 0x1563, 0x2001, 0xa427, 0x2003, 0x0100, 0x7007, 0x0000,
198 0x1078, 0x13fa, 0x007c, 0x2011, 0x8004, 0x1078, 0x3579, 0x0078,
199 0x1567, 0x127e, 0x2091, 0x2100, 0x2079, 0x0030, 0x2071, 0xa5e1,
200 0x7803, 0x0004, 0x7003, 0x0000, 0x700f, 0xa5e7, 0x7013, 0xa5e7,
201 0x780f, 0x0076, 0x7803, 0x0004, 0x127f, 0x007c, 0x6934, 0xa184,
202 0x0007, 0x0079, 0x1583, 0x158b, 0x15d1, 0x158b, 0x158b, 0x158b,
203 0x15b6, 0x159a, 0x158f, 0xa085, 0x0001, 0x0078, 0x15eb, 0x684c,
204 0xd0bc, 0x0040, 0x158b, 0x6860, 0x682e, 0x685c, 0x682a, 0x6858,
205 0x0078, 0x15d9, 0xa18c, 0x00ff, 0xa186, 0x001e, 0x00c0, 0x158b,
206 0x684c, 0xd0bc, 0x0040, 0x158b, 0x6860, 0x682e, 0x685c, 0x682a,
207 0x6804, 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f, 0xa080,
208 0x2015, 0x2004, 0x6832, 0x6858, 0x0078, 0x15e1, 0xa18c, 0x00ff,
209 0xa186, 0x0015, 0x00c0, 0x158b, 0x684c, 0xd0ac, 0x0040, 0x158b,
210 0x6804, 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f, 0xa080,
211 0x2015, 0x2004, 0x6832, 0xa006, 0x682e, 0x682a, 0x6858, 0x0078,
212 0x15e1, 0x684c, 0xd0ac, 0x0040, 0x158b, 0xa006, 0x682e, 0x682a,
213 0x6858, 0xa18c, 0x000f, 0xa188, 0x2015, 0x210c, 0x6932, 0x2d08,
214 0x691a, 0x6826, 0x684c, 0xc0dd, 0x684e, 0xa006, 0x680a, 0x697c,
215 0x6912, 0x6980, 0x6916, 0x007c, 0x20e1, 0x0007, 0x20e1, 0x2000,
216 0x2001, 0x020a, 0x2004, 0x82ff, 0x0040, 0x160e, 0xa280, 0x0004,
217 0x0d7e, 0x206c, 0x684c, 0xd0dc, 0x00c0, 0x160a, 0x1078, 0x157e,
218 0x0040, 0x160a, 0x0d7f, 0xa280, 0x0000, 0x2003, 0x0002, 0xa016,
219 0x0078, 0x160e, 0x6808, 0x8000, 0x680a, 0x0d7f, 0x127e, 0x047e,
220 0x037e, 0x027e, 0x2091, 0x2100, 0x027f, 0x037f, 0x047f, 0x7000,
221 0xa005, 0x00c0, 0x1622, 0x7206, 0x2001, 0x1643, 0x007e, 0x2260,
222 0x0078, 0x17be, 0x710c, 0x220a, 0x8108, 0x230a, 0x8108, 0x240a,
223 0x8108, 0xa182, 0xa602, 0x0048, 0x162f, 0x2009, 0xa5e7, 0x710e,
224 0x7010, 0xa102, 0xa082, 0x0009, 0x0040, 0x163a, 0xa080, 0x001b,
225 0x00c0, 0x163d, 0x2009, 0x0138, 0x200a, 0x7000, 0xa005, 0x00c0,
226 0x1643, 0x1078, 0x179f, 0x127f, 0x007c, 0x127e, 0x027e, 0x037e,
227 0x0c7e, 0x007e, 0x2091, 0x2100, 0x007f, 0x047f, 0x037f, 0x027f,
228 0x0d7e, 0x0c7e, 0x2460, 0x6110, 0x2168, 0x6a62, 0x6b5e, 0xa005,
229 0x0040, 0x16cf, 0x6808, 0xa005, 0x0040, 0x173c, 0x7000, 0xa005,
230 0x00c0, 0x1664, 0x0078, 0x16c4, 0x700c, 0x7110, 0xa106, 0x00c0,
231 0x1745, 0x7004, 0xa406, 0x00c0, 0x16c4, 0x2001, 0x0005, 0x2004,
232 0xd08c, 0x0040, 0x1681, 0x047e, 0x1078, 0x18e2, 0x047f, 0x2460,
233 0x6010, 0xa080, 0x0002, 0x2004, 0xa005, 0x0040, 0x173c, 0x0078,
234 0x165e, 0x2001, 0x0207, 0x2004, 0xd09c, 0x00c0, 0x166d, 0x7804,
235 0xa084, 0x6000, 0x0040, 0x1692, 0xa086, 0x6000, 0x0040, 0x1692,
236 0x0078, 0x166d, 0x7100, 0xa186, 0x0002, 0x00c0, 0x16b2, 0x0e7e,
237 0x2b68, 0x6818, 0x2060, 0x1078, 0x1fea, 0x2804, 0xac70, 0x6034,
238 0xd09c, 0x00c0, 0x16a7, 0x7108, 0x720c, 0x0078, 0x16a9, 0x7110,
239 0x7214, 0x6810, 0xa100, 0x6812, 0x6814, 0xa201, 0x6816, 0x0e7f,
240 0x0078, 0x16b6, 0xa186, 0x0001, 0x00c0, 0x16be, 0x7820, 0x6910,
241 0xa100, 0x6812, 0x7824, 0x6914, 0xa101, 0x6816, 0x7803, 0x0004,
242 0x7003, 0x0000, 0x7004, 0x2060, 0x6100, 0xa18e, 0x0004, 0x00c0,
243 0x1745, 0x2009, 0x0048, 0x1078, 0x756c, 0x0078, 0x1745, 0x6808,
244 0xa005, 0x0040, 0x173c, 0x7000, 0xa005, 0x00c0, 0x16d9, 0x0078,
245 0x173c, 0x700c, 0x7110, 0xa106, 0x00c0, 0x16e2, 0x7004, 0xa406,
246 0x00c0, 0x173c, 0x2001, 0x0005, 0x2004, 0xd08c, 0x0040, 0x16f6,
247 0x047e, 0x1078, 0x18e2, 0x047f, 0x2460, 0x6010, 0xa080, 0x0002,
248 0x2004, 0xa005, 0x0040, 0x173c, 0x0078, 0x16d3, 0x2001, 0x0207,
249 0x2004, 0xd09c, 0x00c0, 0x16e2, 0x2001, 0x0005, 0x2004, 0xd08c,
250 0x00c0, 0x16e8, 0x7804, 0xa084, 0x6000, 0x0040, 0x170d, 0xa086,
251 0x6000, 0x0040, 0x170d, 0x0078, 0x16e2, 0x7007, 0x0000, 0xa016,
252 0x2218, 0x7000, 0xa08e, 0x0001, 0x0040, 0x172e, 0xa08e, 0x0002,
253 0x00c0, 0x173c, 0x0c7e, 0x0e7e, 0x6818, 0x2060, 0x1078, 0x1fea,
254 0x2804, 0xac70, 0x6034, 0xd09c, 0x00c0, 0x172a, 0x7308, 0x720c,
255 0x0078, 0x172c, 0x7310, 0x7214, 0x0e7f, 0x0c7f, 0x7820, 0xa318,
256 0x7824, 0xa211, 0x6810, 0xa300, 0x6812, 0x6814, 0xa201, 0x6816,
257 0x7803, 0x0004, 0x7003, 0x0000, 0x6100, 0xa18e, 0x0004, 0x00c0,
258 0x1745, 0x2009, 0x0048, 0x1078, 0x756c, 0x0c7f, 0x0d7f, 0x127f,
259 0x007c, 0x0f7e, 0x0e7e, 0x027e, 0x037e, 0x047e, 0x1078, 0x1af7,
260 0x027e, 0x2071, 0xa5e1, 0x7000, 0xa086, 0x0000, 0x0040, 0x1790,
261 0x7004, 0xac06, 0x00c0, 0x1781, 0x2079, 0x0030, 0x7000, 0xa086,
262 0x0003, 0x0040, 0x1781, 0x7804, 0xd0fc, 0x00c0, 0x177d, 0x2001,
263 0x0207, 0x2004, 0xd09c, 0x00c0, 0x1763, 0x7803, 0x0004, 0x7804,
264 0xd0ac, 0x00c0, 0x176f, 0x7803, 0x0002, 0x7803, 0x0009, 0x7003,
265 0x0003, 0x7007, 0x0000, 0x0078, 0x1781, 0x1078, 0x18e2, 0x0078,
266 0x1753, 0x157e, 0x20a9, 0x0009, 0x2009, 0xa5e7, 0x2104, 0xac06,
267 0x00c0, 0x178b, 0x200a, 0xa188, 0x0003, 0x00f0, 0x1786, 0x157f,
268 0x027f, 0x2001, 0x015d, 0x201c, 0x831a, 0x2302, 0x2001, 0x0138,
269 0x2202, 0x047f, 0x037f, 0x027f, 0x0e7f, 0x0f7f, 0x007c, 0x700c,
270 0x7110, 0xa106, 0x00c0, 0x17a7, 0x7003, 0x0000, 0x007c, 0x2104,
271 0x7006, 0x2060, 0x8108, 0x211c, 0x8108, 0x2124, 0x8108, 0xa182,
272 0xa602, 0x0048, 0x17b5, 0x2009, 0xa5e7, 0x7112, 0x700c, 0xa106,
273 0x00c0, 0x17be, 0x2001, 0x0138, 0x2003, 0x0008, 0x8cff, 0x00c0,
274 0x17c5, 0x1078, 0x1b22, 0x0078, 0x1823, 0x6010, 0x2068, 0x2d58,
275 0x6828, 0xa406, 0x00c0, 0x17d0, 0x682c, 0xa306, 0x0040, 0x17fe,
276 0x601c, 0xa086, 0x0008, 0x0040, 0x17fe, 0x6024, 0xd0f4, 0x00c0,
277 0x17fa, 0xd0d4, 0x0040, 0x17f6, 0x6038, 0xa402, 0x6034, 0xa303,
278 0x0040, 0x17e4, 0x00c8, 0x17f6, 0x643a, 0x6336, 0x6c2a, 0x6b2e,
279 0x047e, 0x037e, 0x2400, 0x6c7c, 0xa402, 0x6812, 0x2300, 0x6b80,
280 0xa303, 0x6816, 0x037f, 0x047f, 0x0078, 0x17fa, 0x1078, 0x8d8e,
281 0x0040, 0x17c1, 0x1078, 0x2035, 0x00c0, 0x17c1, 0x0c7e, 0x7004,
282 0x2060, 0x6024, 0xc0d4, 0x6026, 0x0c7f, 0x684c, 0xd0f4, 0x0040,
283 0x180f, 0x6817, 0xffff, 0x6813, 0xffff, 0x0078, 0x17c1, 0x6824,
284 0x2050, 0x6818, 0x2060, 0x6830, 0x2040, 0x6034, 0xa0cc, 0x000f,
285 0x2009, 0x0011, 0x1078, 0x1824, 0x0040, 0x1822, 0x2009, 0x0001,
286 0x1078, 0x1824, 0x2d58, 0x007c, 0x8aff, 0x0040, 0x18bb, 0xa03e,
287 0x2730, 0x6850, 0xd0fc, 0x00c0, 0x1846, 0xd0f4, 0x00c0, 0x1856,
288 0x0d7e, 0x2804, 0xac68, 0x2900, 0x0079, 0x1836, 0x189d, 0x185d,
289 0x185d, 0x189d, 0x189d, 0x1895, 0x189d, 0x185d, 0x189d, 0x1863,
290 0x1863, 0x189d, 0x189d, 0x189d, 0x188c, 0x1863, 0xc0fc, 0x6852,
291 0x6b6c, 0x6a70, 0x6d1c, 0x6c20, 0x0d7e, 0xd99c, 0x0040, 0x18a0,
292 0x2804, 0xac68, 0x6f08, 0x6e0c, 0x0078, 0x18a0, 0xc0f4, 0x6852,
293 0x6b6c, 0x6a70, 0x0d7e, 0x0078, 0x18a7, 0x6b08, 0x6a0c, 0x6d00,
294 0x6c04, 0x0078, 0x18a0, 0x7b0c, 0xd3bc, 0x0040, 0x1884, 0x7004,
295 0x0e7e, 0x2070, 0x701c, 0x0e7f, 0xa086, 0x0008, 0x00c0, 0x1884,
296 0x7b08, 0xa39c, 0x0fff, 0x2d20, 0x0d7f, 0x0d7e, 0x6a14, 0x82ff,
297 0x00c0, 0x187f, 0x6810, 0xa302, 0x0048, 0x187f, 0x6b10, 0x2011,
298 0x0000, 0x2468, 0x0078, 0x1886, 0x6b10, 0x6a14, 0x6d00, 0x6c04,
299 0x6f08, 0x6e0c, 0x0078, 0x18a0, 0x0d7f, 0x0d7e, 0x6834, 0xa084,
300 0x00ff, 0xa086, 0x001e, 0x00c0, 0x189d, 0x0d7f, 0x1078, 0x1fd1,
301 0x00c0, 0x1824, 0xa00e, 0x0078, 0x18bb, 0x0d7f, 0x1078, 0x1328,
302 0x7b22, 0x7a26, 0x7d32, 0x7c36, 0x7f3a, 0x7e3e, 0x7902, 0x7000,
303 0x8000, 0x7002, 0x0d7f, 0x6828, 0xa300, 0x682a, 0x682c, 0xa201,
304 0x682e, 0x2300, 0x6b10, 0xa302, 0x6812, 0x2200, 0x6a14, 0xa203,
305 0x6816, 0x1078, 0x1fd1, 0x007c, 0x1078, 0x1328, 0x1078, 0x1c52,
306 0x7004, 0x2060, 0x0d7e, 0x6010, 0x2068, 0x7003, 0x0000, 0x1078,
307 0x1ac6, 0x1078, 0x8a44, 0x0040, 0x18db, 0x6808, 0x8001, 0x680a,
308 0x697c, 0x6912, 0x6980, 0x6916, 0x682b, 0xffff, 0x682f, 0xffff,
309 0x6850, 0xc0bd, 0x6852, 0x0d7f, 0x1078, 0x8758, 0x0078, 0x1aad,
310 0x1078, 0x1328, 0x127e, 0x2091, 0x2100, 0x007e, 0x017e, 0x2b68,
311 0x6818, 0x2060, 0x7904, 0x7803, 0x0002, 0xa184, 0x0700, 0x00c0,
312 0x18be, 0xa184, 0x0003, 0xa086, 0x0003, 0x0040, 0x18e0, 0x7000,
313 0x0079, 0x18fa, 0x1902, 0x1904, 0x1a06, 0x1a84, 0x1a9b, 0x1902,
314 0x1902, 0x1902, 0x1078, 0x1328, 0x8001, 0x7002, 0xa184, 0x0880,
315 0x00c0, 0x1919, 0x8aff, 0x0040, 0x199b, 0x2009, 0x0001, 0x1078,
316 0x1824, 0x0040, 0x1aad, 0x2009, 0x0001, 0x1078, 0x1824, 0x0078,
317 0x1aad, 0x7803, 0x0004, 0x7003, 0x0000, 0xd1bc, 0x00c0, 0x1979,
318 0x027e, 0x037e, 0x7808, 0xd0ec, 0x00c0, 0x1930, 0x7c20, 0x7d24,
319 0x7e30, 0x7f34, 0x7803, 0x0009, 0x7003, 0x0004, 0x0078, 0x1932,
320 0x1078, 0x1b9f, 0x6b28, 0x6a2c, 0x2400, 0x686e, 0xa31a, 0x2500,
321 0x6872, 0xa213, 0x6b2a, 0x6a2e, 0x0c7e, 0x7004, 0x2060, 0x6024,
322 0xd0f4, 0x00c0, 0x1945, 0x633a, 0x6236, 0x0c7f, 0x2400, 0x6910,
323 0xa100, 0x6812, 0x2500, 0x6914, 0xa101, 0x6816, 0x037f, 0x027f,
324 0x2600, 0x681e, 0x2700, 0x6822, 0x1078, 0x1fea, 0x2a00, 0x6826,
325 0x2c00, 0x681a, 0x2800, 0x6832, 0x6850, 0xc0fd, 0x6852, 0x6808,
326 0x8001, 0x680a, 0x00c0, 0x196e, 0x684c, 0xd0e4, 0x0040, 0x196e,
327 0x7004, 0x2060, 0x2009, 0x0048, 0x1078, 0x756c, 0x7000, 0xa086,
328 0x0004, 0x0040, 0x1aad, 0x7003, 0x0000, 0x1078, 0x179f, 0x0078,
329 0x1aad, 0x057e, 0x7d0c, 0xd5bc, 0x00c0, 0x1980, 0x1078, 0xa20c,
330 0x057f, 0x1078, 0x1ac6, 0x0f7e, 0x7004, 0x2078, 0x1078, 0x4893,
331 0x0040, 0x198d, 0x7824, 0xc0f5, 0x7826, 0x0f7f, 0x682b, 0xffff,
332 0x682f, 0xffff, 0x6808, 0x8001, 0x680a, 0x697c, 0x6912, 0x6980,
333 0x6916, 0x0078, 0x1aad, 0x7004, 0x0c7e, 0x2060, 0x6024, 0x0c7f,
334 0xd0f4, 0x0040, 0x19a8, 0x6808, 0x8001, 0x680a, 0x0078, 0x1aad,
335 0x684c, 0xc0f5, 0x684e, 0x7814, 0xa005, 0x00c0, 0x19c0, 0x7003,
336 0x0000, 0x6808, 0x8001, 0x680a, 0x00c0, 0x19bc, 0x7004, 0x2060,
337 0x2009, 0x0048, 0x1078, 0x756c, 0x1078, 0x179f, 0x0078, 0x1aad,
338 0x7814, 0x6910, 0xa102, 0x6812, 0x6914, 0xa183, 0x0000, 0x6816,
339 0x7814, 0x7908, 0xa18c, 0x0fff, 0xa188, 0x0007, 0x8114, 0x8214,
340 0x8214, 0xa10a, 0x8104, 0x8004, 0x8004, 0xa20a, 0x810b, 0x810b,
341 0x810b, 0x1078, 0x1b4d, 0x7803, 0x0004, 0x780f, 0xffff, 0x7803,
342 0x0001, 0x7804, 0xd0fc, 0x0040, 0x19e1, 0x7803, 0x0002, 0x7803,
343 0x0004, 0x780f, 0x0076, 0x7004, 0x7007, 0x0000, 0x2060, 0x2009,
344 0x0048, 0x1078, 0x756c, 0x1078, 0x1b81, 0x0040, 0x19bc, 0x7908,
345 0xd1ec, 0x00c0, 0x19ff, 0x2009, 0x0009, 0x0078, 0x1a01, 0x2009,
346 0x0019, 0x7902, 0x7003, 0x0003, 0x0078, 0x1aad, 0x8001, 0x7002,
347 0xd194, 0x0040, 0x1a18, 0x7804, 0xd0fc, 0x00c0, 0x18ea, 0x8aff,
348 0x0040, 0x1aad, 0x2009, 0x0001, 0x1078, 0x1824, 0x0078, 0x1aad,
349 0xa184, 0x0880, 0x00c0, 0x1a25, 0x8aff, 0x0040, 0x1aad, 0x2009,
350 0x0001, 0x1078, 0x1824, 0x0078, 0x1aad, 0x7803, 0x0004, 0x7003,
351 0x0000, 0xd1bc, 0x00c0, 0x1a65, 0x027e, 0x037e, 0x7808, 0xd0ec,
352 0x00c0, 0x1a38, 0x7803, 0x0009, 0x7003, 0x0004, 0x0078, 0x1a3a,
353 0x1078, 0x1b9f, 0x6b28, 0x6a2c, 0x1078, 0x1fea, 0x0d7e, 0x0f7e,
354 0x2d78, 0x2804, 0xac68, 0x6034, 0xd09c, 0x00c0, 0x1a55, 0x6808,
355 0x2008, 0xa31a, 0x680c, 0xa213, 0x7810, 0xa100, 0x7812, 0x690c,
356 0x7814, 0xa101, 0x7816, 0x0078, 0x1a61, 0x6810, 0x2008, 0xa31a,
357 0x6814, 0xa213, 0x7810, 0xa100, 0x7812, 0x6914, 0x7814, 0xa101,
358 0x7816, 0x0f7f, 0x0d7f, 0x0078, 0x1934, 0x057e, 0x7d0c, 0x1078,
359 0xa20c, 0x057f, 0x1078, 0x1ac6, 0x0f7e, 0x7004, 0x2078, 0x1078,
360 0x4893, 0x0040, 0x1a76, 0x7824, 0xc0f5, 0x7826, 0x0f7f, 0x682b,
361 0xffff, 0x682f, 0xffff, 0x6808, 0x8001, 0x680a, 0x697c, 0x6912,
362 0x6980, 0x6916, 0x0078, 0x1aad, 0x7803, 0x0004, 0x7003, 0x0000,
363 0x7004, 0xa00d, 0x0040, 0x1a97, 0x6808, 0x8001, 0x680a, 0x00c0,
364 0x1a97, 0x7004, 0x2060, 0x2009, 0x0048, 0x1078, 0x756c, 0x1078,
365 0x179f, 0x0078, 0x1aad, 0x7803, 0x0004, 0x7003, 0x0000, 0x7004,
366 0x2060, 0x6010, 0xa005, 0x0040, 0x1a97, 0x2068, 0x6808, 0x8000,
367 0x680a, 0x6c28, 0x6b2c, 0x1078, 0x17be, 0x017f, 0x007f, 0x127f,
368 0x007c, 0x127e, 0x2091, 0x2100, 0x7000, 0xa086, 0x0003, 0x00c0,
369 0x1ac4, 0x700c, 0x7110, 0xa106, 0x0040, 0x1ac4, 0x20e1, 0x9028,
370 0x700f, 0xa5e7, 0x7013, 0xa5e7, 0x127f, 0x007c, 0x0c7e, 0x1078,
371 0x1af7, 0x20e1, 0x9028, 0x700c, 0x7110, 0xa106, 0x0040, 0x1aed,
372 0x2104, 0xa005, 0x0040, 0x1ada, 0x2060, 0x6010, 0x2060, 0x6008,
373 0x8001, 0x600a, 0xa188, 0x0003, 0xa182, 0xa602, 0x0048, 0x1ae2,
374 0x2009, 0xa5e7, 0x7112, 0x700c, 0xa106, 0x00c0, 0x1acb, 0x2001,
375 0x0138, 0x2003, 0x0008, 0x0078, 0x1acb, 0x2001, 0x015d, 0x200c,
376 0x810a, 0x2102, 0x2001, 0x0138, 0x2202, 0x0c7f, 0x007c, 0x2001,
377 0x0138, 0x2014, 0x2003, 0x0000, 0x2021, 0xb015, 0x2001, 0x0141,
378 0x201c, 0xd3dc, 0x00c0, 0x1b14, 0x2001, 0x0109, 0x201c, 0xa39c,
379 0x0048, 0x00c0, 0x1b14, 0x2001, 0x0111, 0x201c, 0x83ff, 0x00c0,
380 0x1b14, 0x8421, 0x00c0, 0x1afe, 0x007c, 0x2011, 0x0201, 0x2009,
381 0x003c, 0x2204, 0xa005, 0x00c0, 0x1b21, 0x8109, 0x00c0, 0x1b19,
382 0x007c, 0x007c, 0x1078, 0x1b15, 0x0040, 0x1b4a, 0x7908, 0xd1ec,
383 0x00c0, 0x1b3a, 0x1078, 0x1b81, 0x0040, 0x1b3a, 0x7803, 0x0009,
384 0x7904, 0xd1fc, 0x0040, 0x1b30, 0x7803, 0x0006, 0x1078, 0x1b15,
385 0x0040, 0x1b4a, 0x780c, 0xd0a4, 0x00c0, 0x1b4a, 0x7007, 0x0000,
386 0x1078, 0x1b81, 0x0040, 0x1b4c, 0x7803, 0x0019, 0x7003, 0x0003,
387 0x0078, 0x1b4c, 0x1078, 0x1ac6, 0x007c, 0x0e7e, 0x2071, 0x0200,
388 0x7808, 0xa084, 0xf000, 0xa10d, 0x1078, 0x1af7, 0x2019, 0x5000,
389 0x8319, 0x0040, 0x1b6b, 0x2001, 0xa602, 0x2004, 0xa086, 0x0000,
390 0x0040, 0x1b6b, 0x2001, 0x0021, 0xd0fc, 0x0040, 0x1b58, 0x1078,
391 0x1e5d, 0x0078, 0x1b56, 0x20e1, 0x7000, 0x7324, 0x7420, 0x7028,
392 0x7028, 0x7426, 0x7037, 0x0001, 0x810f, 0x712e, 0x702f, 0x0100,
393 0x7037, 0x0008, 0x7326, 0x7422, 0x2001, 0x0138, 0x2202, 0x0e7f,
394 0x007c, 0x7908, 0xa18c, 0x0fff, 0xa182, 0x0009, 0x0048, 0x1b8c,
395 0xa085, 0x0001, 0x0078, 0x1b9e, 0x2001, 0x020a, 0x81ff, 0x0040,
396 0x1b97, 0x20e1, 0x6000, 0x200c, 0x200c, 0x200c, 0x200c, 0x20e1,
397 0x7000, 0x200c, 0x200c, 0x7003, 0x0000, 0xa006, 0x007c, 0x7c20,
398 0x7d24, 0x7e30, 0x7f34, 0x700c, 0x7110, 0xa106, 0x0040, 0x1c24,
399 0x7004, 0x017e, 0x210c, 0xa106, 0x017f, 0x0040, 0x1c24, 0x0d7e,
400 0x0c7e, 0x216c, 0x2d00, 0xa005, 0x0040, 0x1c22, 0x6824, 0xd0d4,
401 0x00c0, 0x1c22, 0x6810, 0x2068, 0x6850, 0xd0fc, 0x0040, 0x1bec,
402 0x8108, 0x2104, 0x6b2c, 0xa306, 0x00c0, 0x1c22, 0x8108, 0x2104,
403 0x6a28, 0xa206, 0x00c0, 0x1c22, 0x6850, 0xc0fc, 0xc0f5, 0x6852,
404 0x686c, 0x7822, 0x6870, 0x7826, 0x681c, 0x7832, 0x6820, 0x7836,
405 0x6818, 0x2060, 0x6034, 0xd09c, 0x0040, 0x1be7, 0x6830, 0x2004,
406 0xac68, 0x6808, 0x783a, 0x680c, 0x783e, 0x0078, 0x1c20, 0xa006,
407 0x783a, 0x783e, 0x0078, 0x1c20, 0x8108, 0x2104, 0xa005, 0x00c0,
408 0x1c22, 0x8108, 0x2104, 0xa005, 0x00c0, 0x1c22, 0x6850, 0xc0f5,
409 0x6852, 0x6830, 0x2004, 0x6918, 0xa160, 0xa180, 0x000d, 0x2004,
410 0xd09c, 0x00c0, 0x1c12, 0x6008, 0x7822, 0x686e, 0x600c, 0x7826,
411 0x6872, 0x6000, 0x7832, 0x6004, 0x7836, 0xa006, 0x783a, 0x783e,
412 0x0078, 0x1c20, 0x6010, 0x7822, 0x686e, 0x6014, 0x7826, 0x6872,
413 0x6000, 0x7832, 0x6004, 0x7836, 0x6008, 0x783a, 0x600c, 0x783e,
414 0x7803, 0x0011, 0x0c7f, 0x0d7f, 0x007c, 0x0f7e, 0x0e7e, 0x017e,
415 0x027e, 0x2071, 0xa5e1, 0x2079, 0x0030, 0x2011, 0x0050, 0x7000,
416 0xa086, 0x0000, 0x0040, 0x1c4d, 0x8211, 0x0040, 0x1c4b, 0x2001,
417 0x0005, 0x2004, 0xd08c, 0x0040, 0x1c34, 0x7904, 0xa18c, 0x0780,
418 0x017e, 0x1078, 0x18e2, 0x017f, 0x81ff, 0x00c0, 0x1c4b, 0x2011,
419 0x0050, 0x0078, 0x1c2f, 0xa085, 0x0001, 0x027f, 0x017f, 0x0e7f,
420 0x0f7f, 0x007c, 0x7803, 0x0004, 0x2009, 0x0064, 0x7804, 0xd0ac,
421 0x0040, 0x1ca3, 0x8109, 0x00c0, 0x1c56, 0x2009, 0x0100, 0x210c,
422 0xa18a, 0x0003, 0x1048, 0x1328, 0x1078, 0x1f75, 0x0e7e, 0x0f7e,
423 0x2071, 0xa5d0, 0x2079, 0x0010, 0x7004, 0xa086, 0x0000, 0x0040,
424 0x1c9b, 0x7800, 0x007e, 0x7820, 0x007e, 0x7830, 0x007e, 0x7834,
425 0x007e, 0x7838, 0x007e, 0x783c, 0x007e, 0x7803, 0x0004, 0x7823,
426 0x0000, 0x0005, 0x0005, 0x2079, 0x0030, 0x7804, 0xd0ac, 0x10c0,
427 0x1328, 0x2079, 0x0010, 0x007f, 0x783e, 0x007f, 0x783a, 0x007f,
428 0x7836, 0x007f, 0x7832, 0x007f, 0x7822, 0x007f, 0x7802, 0x0f7f,
429 0x0e7f, 0x0078, 0x1ca1, 0x0f7f, 0x0e7f, 0x7804, 0xd0ac, 0x10c0,
430 0x1328, 0x1078, 0x61d3, 0x007c, 0x0e7e, 0x2071, 0xa602, 0x7003,
431 0x0000, 0x0e7f, 0x007c, 0x0d7e, 0xa280, 0x0004, 0x206c, 0x694c,
432 0xd1dc, 0x00c0, 0x1d26, 0x6934, 0xa184, 0x0007, 0x0079, 0x1cb8,
433 0x1cc0, 0x1d11, 0x1cc0, 0x1cc0, 0x1cc0, 0x1cf6, 0x1cd3, 0x1cc2,
434 0x1078, 0x1328, 0x684c, 0xd0b4, 0x0040, 0x1e34, 0x6860, 0x682e,
435 0x6816, 0x685c, 0x682a, 0x6812, 0x687c, 0x680a, 0x6880, 0x680e,
436 0x6958, 0x0078, 0x1d19, 0x6834, 0xa084, 0x00ff, 0xa086, 0x001e,
437 0x00c0, 0x1cc0, 0x684c, 0xd0b4, 0x0040, 0x1e34, 0x6860, 0x682e,
438 0x6816, 0x685c, 0x682a, 0x6812, 0x687c, 0x680a, 0x6880, 0x680e,
439 0x6804, 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f, 0xa080,
440 0x2015, 0x2004, 0x6832, 0x6958, 0x0078, 0x1d22, 0xa18c, 0x00ff,
441 0xa186, 0x0015, 0x00c0, 0x1d26, 0x684c, 0xd0b4, 0x0040, 0x1e34,
442 0x6804, 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f, 0xa080,
443 0x2015, 0x2004, 0x6832, 0x6958, 0xa006, 0x682e, 0x682a, 0x0078,
444 0x1d22, 0x684c, 0xd0b4, 0x0040, 0x18bc, 0x6958, 0xa006, 0x682e,
445 0x682a, 0x2d00, 0x681a, 0x6834, 0xa084, 0x000f, 0xa080, 0x2015,
446 0x2004, 0x6832, 0x6926, 0x684c, 0xc0dd, 0x684e, 0x0d7f, 0x007c,
447 0x0f7e, 0x2079, 0x0020, 0x7804, 0xd0fc, 0x10c0, 0x1e5d, 0x0e7e,
448 0x0d7e, 0x2071, 0xa602, 0x7000, 0xa005, 0x00c0, 0x1dab, 0x0c7e,
449 0x7206, 0xa280, 0x0004, 0x205c, 0x7004, 0x2068, 0x7803, 0x0004,
450 0x6818, 0x0d7e, 0x2068, 0x686c, 0x7812, 0x6890, 0x0f7e, 0x20e1,
451 0x9040, 0x2079, 0x0200, 0x781a, 0x2079, 0x0100, 0x8004, 0x78d6,
452 0x0f7f, 0x0d7f, 0x2b68, 0x6824, 0x2050, 0x6818, 0x2060, 0x6830,
453 0x2040, 0x6034, 0xa0cc, 0x000f, 0x6908, 0x2001, 0x04fd, 0x2004,
454 0xa086, 0x0007, 0x0040, 0x1d6d, 0xa184, 0x0007, 0x0040, 0x1d6d,
455 0x017e, 0x2009, 0x0008, 0xa102, 0x017f, 0xa108, 0x791a, 0x7116,
456 0x701e, 0x680c, 0xa081, 0x0000, 0x781e, 0x701a, 0xa006, 0x700e,
457 0x7012, 0x7004, 0x692c, 0x6814, 0xa106, 0x00c0, 0x1d84, 0x6928,
458 0x6810, 0xa106, 0x0040, 0x1d91, 0x037e, 0x047e, 0x6b14, 0x6c10,
459 0x1078, 0x2035, 0x047f, 0x037f, 0x0040, 0x1d91, 0x0c7f, 0x0078,
460 0x1dab, 0x8aff, 0x00c0, 0x1d99, 0x0c7f, 0xa085, 0x0001, 0x0078,
461 0x1dab, 0x127e, 0x2091, 0x8000, 0x2079, 0x0020, 0x2009, 0x0001,
462 0x1078, 0x1daf, 0x0040, 0x1da8, 0x2009, 0x0001, 0x1078, 0x1daf,
463 0x127f, 0x0c7f, 0xa006, 0x0d7f, 0x0e7f, 0x0f7f, 0x007c, 0x077e,
464 0x067e, 0x057e, 0x047e, 0x037e, 0x027e, 0x8aff, 0x0040, 0x1e2d,
465 0x700c, 0x7214, 0xa23a, 0x7010, 0x7218, 0xa203, 0x0048, 0x1e2c,
466 0xa705, 0x0040, 0x1e2c, 0xa03e, 0x2730, 0x6850, 0xd0fc, 0x00c0,
467 0x1ddf, 0x0d7e, 0x2804, 0xac68, 0x2900, 0x0079, 0x1dcf, 0x1e0e,
468 0x1def, 0x1def, 0x1e0e, 0x1e0e, 0x1e06, 0x1e0e, 0x1def, 0x1e0e,
469 0x1df5, 0x1df5, 0x1e0e, 0x1e0e, 0x1e0e, 0x1dfd, 0x1df5, 0xc0fc,
470 0x6852, 0x6b6c, 0x6a70, 0x6d1c, 0x6c20, 0xd99c, 0x0040, 0x1e12,
471 0x0d7e, 0x2804, 0xac68, 0x6f08, 0x6e0c, 0x0078, 0x1e11, 0x6b08,
472 0x6a0c, 0x6d00, 0x6c04, 0x0078, 0x1e11, 0x6b10, 0x6a14, 0x6d00,
473 0x6c04, 0x6f08, 0x6e0c, 0x0078, 0x1e11, 0x0d7f, 0x0d7e, 0x6834,
474 0xa084, 0x00ff, 0xa086, 0x001e, 0x00c0, 0x1e0e, 0x0d7f, 0x1078,
475 0x1fd1, 0x00c0, 0x1db5, 0xa00e, 0x0078, 0x1e2d, 0x0d7f, 0x1078,
476 0x1328, 0x0d7f, 0x7b22, 0x7a26, 0x7d32, 0x7c36, 0x7f3a, 0x7e3e,
477 0x7902, 0x7000, 0x8000, 0x7002, 0x6828, 0xa300, 0x682a, 0x682c,
478 0xa201, 0x682e, 0x700c, 0xa300, 0x700e, 0x7010, 0xa201, 0x7012,
479 0x1078, 0x1fd1, 0x0078, 0x1e2d, 0xa006, 0x027f, 0x037f, 0x047f,
480 0x057f, 0x067f, 0x077f, 0x007c, 0x1078, 0x1328, 0x027e, 0x2001,
481 0x0105, 0x2003, 0x0010, 0x20e1, 0x9040, 0x7803, 0x0004, 0x7003,
482 0x0000, 0x7004, 0x2060, 0x0d7e, 0x6010, 0x2068, 0x1078, 0x8a44,
483 0x0040, 0x1e4d, 0x6850, 0xc0bd, 0x6852, 0x0d7f, 0x1078, 0x8758,
484 0x20e1, 0x9040, 0x1078, 0x719a, 0x2011, 0x0000, 0x1078, 0x6efc,
485 0x1078, 0x61d3, 0x027f, 0x0078, 0x1f29, 0x127e, 0x2091, 0x2200,
486 0x007e, 0x017e, 0x0f7e, 0x0e7e, 0x0d7e, 0x0c7e, 0x2079, 0x0020,
487 0x2071, 0xa602, 0x2b68, 0x6818, 0x2060, 0x7904, 0x7803, 0x0002,
488 0xa184, 0x0700, 0x00c0, 0x1e36, 0x7000, 0x0079, 0x1e77, 0x1f29,
489 0x1e7b, 0x1ef6, 0x1f27, 0x8001, 0x7002, 0xd19c, 0x00c0, 0x1e8f,
490 0x8aff, 0x0040, 0x1eae, 0x2009, 0x0001, 0x1078, 0x1daf, 0x0040,
491 0x1f29, 0x2009, 0x0001, 0x1078, 0x1daf, 0x0078, 0x1f29, 0x7803,
492 0x0004, 0xd194, 0x0040, 0x1e9f, 0x6850, 0xc0fc, 0x6852, 0x8aff,
493 0x00c0, 0x1ea4, 0x684c, 0xc0f5, 0x684e, 0x0078, 0x1ea4, 0x1078,
494 0x1fea, 0x6850, 0xc0fd, 0x6852, 0x2a00, 0x6826, 0x2c00, 0x681a,
495 0x2800, 0x6832, 0x7003, 0x0000, 0x0078, 0x1f29, 0x711c, 0x81ff,
496 0x0040, 0x1ec4, 0x7918, 0x7922, 0x7827, 0x0000, 0x7803, 0x0001,
497 0x7000, 0x8000, 0x7002, 0x700c, 0xa100, 0x700e, 0x7010, 0xa081,
498 0x0000, 0x7012, 0x0078, 0x1f29, 0x0f7e, 0x027e, 0x781c, 0x007e,
499 0x7818, 0x007e, 0x2079, 0x0100, 0x7a14, 0xa284, 0x0004, 0xa085,
500 0x0012, 0x7816, 0x037e, 0x2019, 0x1000, 0x8319, 0x1040, 0x1328,
501 0x7820, 0xd0bc, 0x00c0, 0x1ed5, 0x037f, 0x79c8, 0x007f, 0xa102,
502 0x017f, 0x007e, 0x017e, 0x79c4, 0x007f, 0xa103, 0x78c6, 0x007f,
503 0x78ca, 0xa284, 0x0004, 0xa085, 0x0012, 0x7816, 0x027f, 0x0f7f,
504 0x7803, 0x0008, 0x7003, 0x0000, 0x0078, 0x1f29, 0x8001, 0x7002,
505 0xd194, 0x0040, 0x1f0b, 0x7804, 0xd0fc, 0x00c0, 0x1e6d, 0xd19c,
506 0x00c0, 0x1f25, 0x8aff, 0x0040, 0x1f29, 0x2009, 0x0001, 0x1078,
507 0x1daf, 0x0078, 0x1f29, 0x027e, 0x037e, 0x6b28, 0x6a2c, 0x1078,
508 0x1fea, 0x0d7e, 0x2804, 0xac68, 0x6034, 0xd09c, 0x00c0, 0x1f1e,
509 0x6808, 0xa31a, 0x680c, 0xa213, 0x0078, 0x1f22, 0x6810, 0xa31a,
510 0x6814, 0xa213, 0x0d7f, 0x0078, 0x1e9f, 0x0078, 0x1e9f, 0x1078,
511 0x1328, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f, 0x017f, 0x007f, 0x127f,
512 0x007c, 0x0f7e, 0x0e7e, 0x2071, 0xa602, 0x7000, 0xa086, 0x0000,
513 0x0040, 0x1f72, 0x2079, 0x0020, 0x017e, 0x2009, 0x0207, 0x210c,
514 0xd194, 0x0040, 0x1f4f, 0x2009, 0x020c, 0x210c, 0xa184, 0x0003,
515 0x0040, 0x1f4f, 0x20e1, 0x9040, 0x2001, 0x020c, 0x2102, 0x2009,
516 0x0206, 0x2104, 0x2009, 0x0203, 0x210c, 0xa106, 0x00c0, 0x1f5a,
517 0x20e1, 0x9040, 0x7804, 0xd0fc, 0x0040, 0x1f3d, 0x1078, 0x1e5d,
518 0x7000, 0xa086, 0x0000, 0x00c0, 0x1f3d, 0x017f, 0x7803, 0x0004,
519 0x7804, 0xd0ac, 0x00c0, 0x1f68, 0x20e1, 0x9040, 0x7803, 0x0002,
520 0x7003, 0x0000, 0x0e7f, 0x0f7f, 0x007c, 0x027e, 0x0c7e, 0x0d7e,
521 0x0e7e, 0x0f7e, 0x2071, 0xa602, 0x2079, 0x0020, 0x7000, 0xa086,
522 0x0000, 0x0040, 0x1fae, 0x7004, 0x2060, 0x6010, 0x2068, 0x1078,
523 0x8a44, 0x0040, 0x1f98, 0x6850, 0xc0b5, 0x6852, 0x680c, 0x7a1c,
524 0xa206, 0x00c0, 0x1f98, 0x6808, 0x7a18, 0xa206, 0x0040, 0x1fb4,
525 0x2001, 0x0105, 0x2003, 0x0010, 0x20e1, 0x9040, 0x7803, 0x0004,
526 0x7003, 0x0000, 0x7004, 0x2060, 0x1078, 0x8758, 0x20e1, 0x9040,
527 0x1078, 0x719a, 0x2011, 0x0000, 0x1078, 0x6efc, 0x0f7f, 0x0e7f,
528 0x0d7f, 0x0c7f, 0x027f, 0x007c, 0x6810, 0x6a14, 0xa205, 0x00c0,
529 0x1f98, 0x684c, 0xc0dc, 0x684e, 0x2c10, 0x1078, 0x1cab, 0x2001,
530 0x0105, 0x2003, 0x0010, 0x20e1, 0x9040, 0x7803, 0x0004, 0x7003,
531 0x0000, 0x2069, 0xa5ab, 0x6833, 0x0000, 0x683f, 0x0000, 0x0078,
532 0x1fae, 0x8840, 0x2804, 0xa005, 0x00c0, 0x1fe5, 0x6004, 0xa005,
533 0x0040, 0x1fe7, 0x681a, 0x2060, 0x6034, 0xa084, 0x000f, 0xa080,
534 0x2015, 0x2044, 0x88ff, 0x1040, 0x1328, 0x8a51, 0x007c, 0x2051,
535 0x0000, 0x007c, 0x8a50, 0x8841, 0x2804, 0xa005, 0x00c0, 0x2004,
536 0x2c00, 0xad06, 0x0040, 0x1ff9, 0x6000, 0xa005, 0x00c0, 0x1ff9,
537 0x2d00, 0x2060, 0x681a, 0x6034, 0xa084, 0x000f, 0xa080, 0x2025,
538 0x2044, 0x88ff, 0x1040, 0x1328, 0x007c, 0x0000, 0x0011, 0x0015,
539 0x0019, 0x001d, 0x0021, 0x0025, 0x0029, 0x0000, 0x000f, 0x0015,
540 0x001b, 0x0021, 0x0027, 0x0000, 0x0000, 0x0000, 0x200a, 0x2006,
541 0x0000, 0x0000, 0x2014, 0x0000, 0x200a, 0x0000, 0x2011, 0x200e,
542 0x0000, 0x0000, 0x0000, 0x2014, 0x2011, 0x0000, 0x200c, 0x200c,
543 0x0000, 0x0000, 0x2014, 0x0000, 0x200c, 0x0000, 0x2012, 0x2012,
544 0x0000, 0x0000, 0x0000, 0x2014, 0x2012, 0x0a7e, 0x097e, 0x087e,
545 0x6b2e, 0x6c2a, 0x6858, 0xa055, 0x0040, 0x20d8, 0x2d60, 0x6034,
546 0xa0cc, 0x000f, 0xa9c0, 0x2015, 0xa986, 0x0007, 0x0040, 0x2050,
547 0xa986, 0x000e, 0x0040, 0x2050, 0xa986, 0x000f, 0x00c0, 0x2054,
548 0x605c, 0xa422, 0x6060, 0xa31a, 0x2804, 0xa045, 0x00c0, 0x2062,
549 0x0050, 0x205c, 0x0078, 0x20d8, 0x6004, 0xa065, 0x0040, 0x20d8,
550 0x0078, 0x203f, 0x2804, 0xa005, 0x0040, 0x2080, 0xac68, 0xd99c,
551 0x00c0, 0x2070, 0x6808, 0xa422, 0x680c, 0xa31b, 0x0078, 0x2074,
552 0x6810, 0xa422, 0x6814, 0xa31b, 0x0048, 0x209f, 0x2300, 0xa405,
553 0x0040, 0x2086, 0x8a51, 0x0040, 0x20d8, 0x8840, 0x0078, 0x2062,
554 0x6004, 0xa065, 0x0040, 0x20d8, 0x0078, 0x203f, 0x8a51, 0x0040,
555 0x20d8, 0x8840, 0x2804, 0xa005, 0x00c0, 0x2099, 0x6004, 0xa065,
556 0x0040, 0x20d8, 0x6034, 0xa0cc, 0x000f, 0xa9c0, 0x2015, 0x2804,
557 0x2040, 0x2b68, 0x6850, 0xc0fc, 0x6852, 0x0078, 0x20cc, 0x8422,
558 0x8420, 0x831a, 0xa399, 0x0000, 0x0d7e, 0x2b68, 0x6c6e, 0x6b72,
559 0x0d7f, 0xd99c, 0x00c0, 0x20ba, 0x6908, 0x2400, 0xa122, 0x690c,
560 0x2300, 0xa11b, 0x1048, 0x1328, 0x6800, 0xa420, 0x6804, 0xa319,
561 0x0078, 0x20c6, 0x6910, 0x2400, 0xa122, 0x6914, 0x2300, 0xa11b,
562 0x1048, 0x1328, 0x6800, 0xa420, 0x6804, 0xa319, 0x2b68, 0x6c1e,
563 0x6b22, 0x6850, 0xc0fd, 0x6852, 0x2c00, 0x681a, 0x2800, 0x6832,
564 0x2a00, 0x6826, 0x007f, 0x007f, 0x007f, 0xa006, 0x0078, 0x20dd,
565 0x087f, 0x097f, 0x0a7f, 0xa085, 0x0001, 0x007c, 0x2001, 0x0005,
566 0x2004, 0xa084, 0x0007, 0x0079, 0x20e5, 0x20ed, 0x20ee, 0x20f1,
567 0x20f4, 0x20f9, 0x20fc, 0x2101, 0x2106, 0x007c, 0x1078, 0x1e5d,
568 0x007c, 0x1078, 0x18e2, 0x007c, 0x1078, 0x18e2, 0x1078, 0x1e5d,
569 0x007c, 0x1078, 0x14b0, 0x007c, 0x1078, 0x1e5d, 0x1078, 0x14b0,
570 0x007c, 0x1078, 0x18e2, 0x1078, 0x14b0, 0x007c, 0x1078, 0x18e2,
571 0x1078, 0x1e5d, 0x1078, 0x14b0, 0x007c, 0x127e, 0x2091, 0x2300,
572 0x2079, 0x0200, 0x2071, 0xa880, 0x2069, 0xa300, 0x2009, 0x0004,
573 0x7912, 0x7817, 0x0004, 0x1078, 0x24b5, 0x781b, 0x0002, 0x20e1,
574 0x8700, 0x127f, 0x007c, 0x127e, 0x2091, 0x2300, 0x781c, 0xa084,
575 0x0007, 0x0079, 0x212b, 0x214f, 0x2133, 0x2137, 0x213b, 0x2141,
576 0x2145, 0x2149, 0x214d, 0x1078, 0x5372, 0x0078, 0x214f, 0x1078,
577 0x53b3, 0x0078, 0x214f, 0x1078, 0x5372, 0x1078, 0x53b3, 0x0078,
578 0x214f, 0x1078, 0x2151, 0x0078, 0x214f, 0x1078, 0x2151, 0x0078,
579 0x214f, 0x1078, 0x2151, 0x0078, 0x214f, 0x1078, 0x2151, 0x127f,
580 0x007c, 0x007e, 0x017e, 0x027e, 0x7930, 0xa184, 0x0003, 0x0040,
581 0x215d, 0x20e1, 0x9040, 0x0078, 0x2186, 0xa184, 0x0030, 0x0040,
582 0x216e, 0x6a00, 0xa286, 0x0003, 0x00c0, 0x2168, 0x0078, 0x216a,
583 0x1078, 0x4171, 0x20e1, 0x9010, 0x0078, 0x2186, 0xa184, 0x00c0,
584 0x0040, 0x2180, 0x0e7e, 0x037e, 0x047e, 0x057e, 0x2071, 0xa5e1,
585 0x1078, 0x1ac6, 0x057f, 0x047f, 0x037f, 0x0e7f, 0x0078, 0x2186,
586 0xa184, 0x0300, 0x0040, 0x2186, 0x20e1, 0x9020, 0x7932, 0x027f,
587 0x017f, 0x007f, 0x007c, 0x017e, 0x0e7e, 0x0f7e, 0x2071, 0xa300,
588 0x7128, 0x2001, 0xa58f, 0x2102, 0x2001, 0xa597, 0x2102, 0xa182,
589 0x0211, 0x00c8, 0x219f, 0x2009, 0x0008, 0x0078, 0x21c9, 0xa182,
590 0x0259, 0x00c8, 0x21a7, 0x2009, 0x0007, 0x0078, 0x21c9, 0xa182,
591 0x02c1, 0x00c8, 0x21af, 0x2009, 0x0006, 0x0078, 0x21c9, 0xa182,
592 0x0349, 0x00c8, 0x21b7, 0x2009, 0x0005, 0x0078, 0x21c9, 0xa182,
593 0x0421, 0x00c8, 0x21bf, 0x2009, 0x0004, 0x0078, 0x21c9, 0xa182,
594 0x0581, 0x00c8, 0x21c7, 0x2009, 0x0003, 0x0078, 0x21c9, 0x2009,
595 0x0002, 0x2079, 0x0200, 0x7912, 0x7817, 0x0004, 0x1078, 0x24b5,
596 0x0f7f, 0x0e7f, 0x017f, 0x007c, 0x127e, 0x2091, 0x2200, 0x2061,
597 0x0100, 0x2071, 0xa300, 0x6024, 0x6026, 0x6053, 0x0030, 0x6033,
598 0x00ef, 0x60e7, 0x0000, 0x60eb, 0x00ef, 0x60e3, 0x0008, 0x604b,
599 0xf7f7, 0x6043, 0x0000, 0x602f, 0x0080, 0x602f, 0x0000, 0x6007,
600 0x0eaf, 0x600f, 0x00ff, 0x602b, 0x002f, 0x127f, 0x007c, 0x2001,
601 0xa32f, 0x2003, 0x0000, 0x2001, 0xa32e, 0x2003, 0x0001, 0x007c,
602 0x127e, 0x2091, 0x2200, 0x007e, 0x017e, 0x027e, 0x6124, 0xa184,
603 0x002c, 0x00c0, 0x220f, 0xa184, 0x0007, 0x0079, 0x2215, 0xa195,
604 0x0004, 0xa284, 0x0007, 0x0079, 0x2215, 0x2241, 0x221d, 0x2221,
605 0x2225, 0x222b, 0x222f, 0x2235, 0x223b, 0x1078, 0x5ad2, 0x0078,
606 0x2241, 0x1078, 0x5bc1, 0x0078, 0x2241, 0x1078, 0x5bc1, 0x1078,
607 0x5ad2, 0x0078, 0x2241, 0x1078, 0x2246, 0x0078, 0x2241, 0x1078,
608 0x5ad2, 0x1078, 0x2246, 0x0078, 0x2241, 0x1078, 0x5bc1, 0x1078,
609 0x2246, 0x0078, 0x2241, 0x1078, 0x5bc1, 0x1078, 0x5ad2, 0x1078,
610 0x2246, 0x027f, 0x017f, 0x007f, 0x127f, 0x007c, 0x6124, 0xd1ac,
611 0x0040, 0x2342, 0x017e, 0x047e, 0x0c7e, 0x644c, 0xa486, 0xf0f0,
612 0x00c0, 0x2259, 0x2061, 0x0100, 0x644a, 0x6043, 0x0090, 0x6043,
613 0x0010, 0x74c2, 0xa48c, 0xff00, 0x7034, 0xd084, 0x0040, 0x2271,
614 0xa186, 0xf800, 0x00c0, 0x2271, 0x7038, 0xd084, 0x00c0, 0x2271,
615 0xc085, 0x703a, 0x037e, 0x2418, 0x2011, 0x8016, 0x1078, 0x3579,
616 0x037f, 0xa196, 0xff00, 0x0040, 0x22b3, 0x6030, 0xa084, 0x00ff,
617 0x810f, 0xa116, 0x0040, 0x22b3, 0x7130, 0xd184, 0x00c0, 0x22b3,
618 0x2011, 0xa352, 0x2214, 0xd2ec, 0x0040, 0x228e, 0xc18d, 0x7132,
619 0x2011, 0xa352, 0x2214, 0xd2ac, 0x00c0, 0x22b3, 0x6240, 0xa294,
620 0x0010, 0x0040, 0x229a, 0x6248, 0xa294, 0xff00, 0xa296, 0xff00,
621 0x0040, 0x22b3, 0x7030, 0xd08c, 0x0040, 0x2305, 0x7034, 0xd08c,
622 0x00c0, 0x22aa, 0x2001, 0xa30c, 0x200c, 0xd1ac, 0x00c0, 0x2305,
623 0xc1ad, 0x2102, 0x037e, 0x73c0, 0x2011, 0x8013, 0x1078, 0x3579,
624 0x037f, 0x0078, 0x2305, 0x7034, 0xd08c, 0x00c0, 0x22bf, 0x2001,
625 0xa30c, 0x200c, 0xd1ac, 0x00c0, 0x2305, 0xc1ad, 0x2102, 0x037e,
626 0x73c0, 0x2011, 0x8013, 0x1078, 0x3579, 0x037f, 0x7130, 0xc185,
627 0x7132, 0x2011, 0xa352, 0x220c, 0xd1a4, 0x0040, 0x22e9, 0x017e,
628 0x2009, 0x0001, 0x2011, 0x0100, 0x1078, 0x5a6d, 0x2019, 0x000e,
629 0x1078, 0x9e3b, 0xa484, 0x00ff, 0xa080, 0x293f, 0x200c, 0xa18c,
630 0xff00, 0x810f, 0x8127, 0xa006, 0x2009, 0x000e, 0x1078, 0x9ec0,
631 0x017f, 0xd1ac, 0x00c0, 0x22f6, 0x017e, 0x2009, 0x0000, 0x2019,
632 0x0004, 0x1078, 0x27e2, 0x017f, 0x0078, 0x2305, 0x157e, 0x20a9,
633 0x007f, 0x2009, 0x0000, 0x1078, 0x4501, 0x00c0, 0x2301, 0x1078,
634 0x4235, 0x8108, 0x00f0, 0x22fb, 0x157f, 0x0c7f, 0x047f, 0x0f7e,
635 0x2079, 0xa5be, 0x783c, 0xa086, 0x0000, 0x0040, 0x2317, 0x6027,
636 0x0004, 0x783f, 0x0000, 0x2079, 0x0140, 0x7803, 0x0000, 0x0f7f,
637 0x2011, 0x0003, 0x1078, 0x6ef2, 0x2011, 0x0002, 0x1078, 0x6efc,
638 0x1078, 0x6dda, 0x1078, 0x595a, 0x037e, 0x2019, 0x0000, 0x1078,
639 0x6e6c, 0x037f, 0x60e3, 0x0000, 0x017f, 0x2001, 0xa300, 0x2014,
640 0xa296, 0x0004, 0x00c0, 0x233a, 0xd19c, 0x00c0, 0x233a, 0x6228,
641 0xc29d, 0x622a, 0x2003, 0x0001, 0x2001, 0xa321, 0x2003, 0x0000,
642 0x6027, 0x0020, 0xd194, 0x0040, 0x2426, 0x0f7e, 0x2079, 0xa5be,
643 0x783c, 0xa086, 0x0001, 0x00c0, 0x2366, 0x017e, 0x6027, 0x0004,
644 0x783f, 0x0000, 0x2079, 0x0140, 0x7803, 0x1000, 0x7803, 0x0000,
645 0x2079, 0xa5ab, 0x7807, 0x0000, 0x7833, 0x0000, 0x1078, 0x6109,
646 0x1078, 0x61d3, 0x017f, 0x0f7f, 0x0078, 0x2426, 0x0f7f, 0x017e,
647 0x3900, 0xa082, 0xa6cd, 0x00c8, 0x2371, 0x017e, 0x1078, 0x728a,
648 0x017f, 0x6220, 0xd2b4, 0x0040, 0x23dc, 0x1078, 0x595a, 0x1078,
649 0x6c41, 0x6027, 0x0004, 0x0f7e, 0x2019, 0xa5b4, 0x2304, 0xa07d,
650 0x0040, 0x23b2, 0x7804, 0xa086, 0x0032, 0x00c0, 0x23b2, 0x0d7e,
651 0x0c7e, 0x0e7e, 0x2069, 0x0140, 0x618c, 0x6288, 0x7818, 0x608e,
652 0x7808, 0x608a, 0x6043, 0x0002, 0x2001, 0x0003, 0x8001, 0x00c0,
653 0x2396, 0x6043, 0x0000, 0x6803, 0x1000, 0x6803, 0x0000, 0x618e,
654 0x628a, 0x1078, 0x6010, 0x1078, 0x6109, 0x7810, 0x2070, 0x7037,
655 0x0103, 0x2f60, 0x1078, 0x753d, 0x0e7f, 0x0c7f, 0x0d7f, 0x0f7f,
656 0x017f, 0x007c, 0x0f7f, 0x0d7e, 0x2069, 0x0140, 0x6804, 0xa084,
657 0x4000, 0x0040, 0x23bf, 0x6803, 0x1000, 0x6803, 0x0000, 0x0d7f,
658 0x0c7e, 0x2061, 0xa5ab, 0x6028, 0xa09a, 0x00c8, 0x00c8, 0x23cf,
659 0x8000, 0x602a, 0x0c7f, 0x1078, 0x6c33, 0x0078, 0x2425, 0x2019,
660 0xa5b4, 0x2304, 0xa065, 0x0040, 0x23d9, 0x2009, 0x0027, 0x1078,
661 0x756c, 0x0c7f, 0x0078, 0x2425, 0xd2bc, 0x0040, 0x2425, 0x1078,
662 0x5967, 0x6017, 0x0010, 0x6027, 0x0004, 0x0d7e, 0x2069, 0x0140,
663 0x6804, 0xa084, 0x4000, 0x0040, 0x23f1, 0x6803, 0x1000, 0x6803,
664 0x0000, 0x0d7f, 0x0c7e, 0x2061, 0xa5ab, 0x6044, 0xa09a, 0x00c8,
665 0x00c8, 0x2414, 0x8000, 0x6046, 0x603c, 0x0c7f, 0xa005, 0x0040,
666 0x2425, 0x2009, 0x07d0, 0x1078, 0x595f, 0xa080, 0x0007, 0x2004,
667 0xa086, 0x0006, 0x00c0, 0x2410, 0x6017, 0x0012, 0x0078, 0x2425,
668 0x6017, 0x0016, 0x0078, 0x2425, 0x037e, 0x2019, 0x0001, 0x1078,
669 0x6e6c, 0x037f, 0x2019, 0xa5ba, 0x2304, 0xa065, 0x0040, 0x2424,
670 0x2009, 0x004f, 0x1078, 0x756c, 0x0c7f, 0x017f, 0xd19c, 0x0040,
671 0x247c, 0x7034, 0xd0ac, 0x00c0, 0x2457, 0x017e, 0x157e, 0x6027,
672 0x0008, 0x602f, 0x0020, 0x20a9, 0x000a, 0x00f0, 0x2435, 0x602f,
673 0x0000, 0x6150, 0xa185, 0x1400, 0x6052, 0x20a9, 0x0320, 0x00e0,
674 0x243f, 0x2091, 0x6000, 0x6020, 0xd09c, 0x00c0, 0x244e, 0x157f,
675 0x6152, 0x017f, 0x6027, 0x0008, 0x0078, 0x247c, 0x1078, 0x250d,
676 0x00f0, 0x243f, 0x157f, 0x6152, 0x017f, 0x6027, 0x0008, 0x017e,
677 0x6028, 0xc09c, 0x602a, 0x2011, 0x0003, 0x1078, 0x6ef2, 0x2011,
678 0x0002, 0x1078, 0x6efc, 0x1078, 0x6dda, 0x1078, 0x595a, 0x037e,
679 0x2019, 0x0000, 0x1078, 0x6e6c, 0x037f, 0x60e3, 0x0000, 0x1078,
680 0xa22a, 0x1078, 0xa248, 0x2001, 0xa300, 0x2003, 0x0004, 0x6027,
681 0x0008, 0x1078, 0x1246, 0x017f, 0xa18c, 0xffd0, 0x6126, 0x007c,
682 0x007e, 0x017e, 0x027e, 0x0e7e, 0x0f7e, 0x127e, 0x2091, 0x8000,
683 0x2071, 0xa300, 0x71b8, 0x70ba, 0xa116, 0x0040, 0x24ae, 0x81ff,
684 0x0040, 0x2498, 0x2011, 0x8011, 0x1078, 0x3579, 0x0078, 0x24ae,
685 0x2011, 0x8012, 0x1078, 0x3579, 0x2001, 0xa371, 0x2004, 0xd0fc,
686 0x00c0, 0x24ae, 0x037e, 0x0c7e, 0x2061, 0x0100, 0x2019, 0x0028,
687 0x2009, 0x0000, 0x1078, 0x27e2, 0x0c7f, 0x037f, 0x127f, 0x0f7f,
688 0x0e7f, 0x027f, 0x017f, 0x007f, 0x007c, 0x0c7e, 0x0f7e, 0x007e,
689 0x027e, 0x2061, 0x0100, 0xa190, 0x24d1, 0x2204, 0x60f2, 0x2011,
690 0x24de, 0x6000, 0xa082, 0x0003, 0x00c8, 0x24ca, 0x2001, 0x00ff,
691 0x0078, 0x24cb, 0x2204, 0x60ee, 0x027f, 0x007f, 0x0f7f, 0x0c7f,
692 0x007c, 0x0840, 0x0840, 0x0840, 0x0580, 0x0420, 0x0348, 0x02c0,
693 0x0258, 0x0210, 0x01a8, 0x01a8, 0x01a8, 0x01a8, 0x0140, 0x00f8,
694 0x00d0, 0x00b0, 0x00a0, 0x2028, 0xa18c, 0x00ff, 0x2130, 0xa094,
695 0xff00, 0x00c0, 0x24ee, 0x81ff, 0x0040, 0x24f2, 0x1078, 0x5623,
696 0x0078, 0x24f9, 0xa080, 0x293f, 0x200c, 0xa18c, 0xff00, 0x810f,
697 0xa006, 0x007c, 0xa080, 0x293f, 0x200c, 0xa18c, 0x00ff, 0x007c,
698 0x0c7e, 0x2061, 0xa300, 0x6030, 0x0040, 0x2509, 0xc09d, 0x0078,
699 0x250a, 0xc09c, 0x6032, 0x0c7f, 0x007c, 0x007e, 0x157e, 0x0f7e,
700 0x2079, 0x0100, 0x20a9, 0x000a, 0x7854, 0xd08c, 0x00c0, 0x251a,
701 0x00f0, 0x2514, 0x0f7f, 0x157f, 0x007f, 0x007c, 0x0c7e, 0x007e,
702 0x2061, 0x0100, 0x6030, 0x007e, 0x6048, 0x007e, 0x60e4, 0x007e,
703 0x60e8, 0x007e, 0x6050, 0x007e, 0x60f0, 0x007e, 0x60ec, 0x007e,
704 0x600c, 0x007e, 0x6004, 0x007e, 0x6028, 0x007e, 0x60e0, 0x007e,
705 0x602f, 0x0100, 0x602f, 0x0000, 0x0005, 0x0005, 0x0005, 0x0005,
706 0x602f, 0x0040, 0x602f, 0x0000, 0x007f, 0x60e2, 0x007f, 0x602a,
707 0x007f, 0x6006, 0x007f, 0x600e, 0x007f, 0x60ee, 0x007f, 0x60f2,
708 0x007f, 0x6052, 0x007f, 0x60ea, 0x007f, 0x60e6, 0x007f, 0x604a,
709 0x007f, 0x6032, 0x007f, 0x0c7f, 0x007c, 0x257d, 0x2581, 0x2585,
710 0x258b, 0x2591, 0x2597, 0x259d, 0x25a5, 0x25ad, 0x25b3, 0x25b9,
711 0x25c1, 0x25c9, 0x25d1, 0x25d9, 0x25e3, 0x25ed, 0x25ed, 0x25ed,
712 0x25ed, 0x25ed, 0x25ed, 0x25ed, 0x25ed, 0x25ed, 0x25ed, 0x25ed,
713 0x25ed, 0x25ed, 0x25ed, 0x25ed, 0x25ed, 0x107e, 0x007e, 0x0078,
714 0x2606, 0x107e, 0x007e, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078,
715 0x2200, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078, 0x2200, 0x0078,
716 0x2606, 0x107e, 0x007e, 0x1078, 0x20de, 0x0078, 0x2606, 0x107e,
717 0x007e, 0x1078, 0x20de, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078,
718 0x2200, 0x1078, 0x20de, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078,
719 0x2200, 0x1078, 0x20de, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078,
720 0x2123, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078, 0x2123, 0x0078,
721 0x2606, 0x107e, 0x007e, 0x1078, 0x2200, 0x1078, 0x2123, 0x0078,
722 0x2606, 0x107e, 0x007e, 0x1078, 0x2200, 0x1078, 0x2123, 0x0078,
723 0x2606, 0x107e, 0x007e, 0x1078, 0x20de, 0x1078, 0x2123, 0x0078,
724 0x2606, 0x107e, 0x007e, 0x1078, 0x20de, 0x1078, 0x2123, 0x0078,
725 0x2606, 0x107e, 0x007e, 0x1078, 0x2200, 0x1078, 0x20de, 0x1078,
726 0x2123, 0x0078, 0x2606, 0x107e, 0x007e, 0x1078, 0x2200, 0x1078,
727 0x20de, 0x1078, 0x2123, 0x0078, 0x2606, 0x0005, 0x0078, 0x25ed,
728 0xb084, 0x003c, 0x8004, 0x8004, 0x0079, 0x25f6, 0x2606, 0x2583,
729 0x2587, 0x258d, 0x2593, 0x2599, 0x259f, 0x25a7, 0x25af, 0x25b5,
730 0x25bb, 0x25c3, 0x25cb, 0x25d3, 0x25db, 0x25e5, 0x0008, 0x25f0,
731 0x007f, 0x107f, 0x2091, 0x8001, 0x007c, 0x0c7e, 0x027e, 0x047e,
732 0x2021, 0x0000, 0x1078, 0x4897, 0x00c0, 0x2705, 0x70c8, 0xd09c,
733 0x0040, 0x2624, 0xd084, 0x00c0, 0x2624, 0xd0bc, 0x00c0, 0x2705,
734 0x1078, 0x2709, 0x0078, 0x2705, 0xd094, 0x0040, 0x262b, 0x7093,
735 0xffff, 0x0078, 0x2705, 0x2001, 0x010c, 0x203c, 0x7280, 0xd284,
736 0x0040, 0x2694, 0xd28c, 0x00c0, 0x2694, 0x037e, 0x7390, 0xa38e,
737 0xffff, 0x0040, 0x263e, 0x83ff, 0x00c0, 0x2640, 0x2019, 0x0001,
738 0x8314, 0xa2e0, 0xa9c0, 0x2c04, 0xa38c, 0x0001, 0x0040, 0x264d,
739 0xa084, 0xff00, 0x8007, 0x0078, 0x264f, 0xa084, 0x00ff, 0xa70e,
740 0x0040, 0x2689, 0xa08e, 0x0000, 0x0040, 0x2689, 0xa08e, 0x00ff,
741 0x00c0, 0x2666, 0x7230, 0xd284, 0x00c0, 0x268f, 0x7280, 0xc28d,
742 0x7282, 0x7093, 0xffff, 0x037f, 0x0078, 0x2694, 0x2009, 0x0000,
743 0x1078, 0x24e3, 0x1078, 0x4499, 0x00c0, 0x268c, 0x6004, 0xa084,
744 0x00ff, 0xa086, 0x0006, 0x00c0, 0x2683, 0x7030, 0xd08c, 0x0040,
745 0x267d, 0x6000, 0xd0bc, 0x0040, 0x2683, 0x1078, 0x271f, 0x0040,
746 0x268c, 0x0078, 0x2689, 0x1078, 0x2857, 0x1078, 0x274c, 0x0040,
747 0x268c, 0x8318, 0x0078, 0x2640, 0x7392, 0x0078, 0x2691, 0x7093,
748 0xffff, 0x037f, 0x0078, 0x2705, 0xa780, 0x293f, 0x203c, 0xa7bc,
749 0xff00, 0x873f, 0x2041, 0x007e, 0x7090, 0xa096, 0xffff, 0x00c0,
750 0x26a6, 0x2009, 0x0000, 0x28a8, 0x0078, 0x26b2, 0xa812, 0x0048,
751 0x26ae, 0x2008, 0xa802, 0x20a8, 0x0078, 0x26b2, 0x7093, 0xffff,
752 0x0078, 0x2705, 0x2700, 0x157e, 0x017e, 0xa106, 0x0040, 0x26f9,
753 0xc484, 0x1078, 0x4501, 0x0040, 0x26c3, 0x1078, 0x4499, 0x00c0,
754 0x2702, 0x0078, 0x26c4, 0xc485, 0x6004, 0xa084, 0x00ff, 0xa086,
755 0x0006, 0x00c0, 0x26d3, 0x7030, 0xd08c, 0x0040, 0x26f1, 0x6000,
756 0xd0bc, 0x00c0, 0x26f1, 0x7280, 0xd28c, 0x0040, 0x26e9, 0x6004,
757 0xa084, 0x00ff, 0xa082, 0x0006, 0x0048, 0x26f9, 0xd484, 0x00c0,
758 0x26e5, 0x1078, 0x44bc, 0x0078, 0x26e7, 0x1078, 0x2921, 0x0078,
759 0x26f9, 0x1078, 0x2857, 0x1078, 0x274c, 0x0040, 0x2702, 0x0078,
760 0x26f9, 0x1078, 0x28ec, 0x0040, 0x26f9, 0x1078, 0x271f, 0x0040,
761 0x2702, 0x017f, 0x8108, 0x157f, 0x00f0, 0x26b2, 0x7093, 0xffff,
762 0x0078, 0x2705, 0x017f, 0x157f, 0x7192, 0x047f, 0x027f, 0x0c7f,
763 0x007c, 0x0c7e, 0x017e, 0x7093, 0x0000, 0x2009, 0x007e, 0x1078,
764 0x4499, 0x00c0, 0x271c, 0x1078, 0x2857, 0x1078, 0x274c, 0x0040,
765 0x271c, 0x70c8, 0xc0bd, 0x70ca, 0x017f, 0x0c7f, 0x007c, 0x017e,
766 0x077e, 0x0d7e, 0x0c7e, 0x2c68, 0x2001, 0xa356, 0x2004, 0xa084,
767 0x00ff, 0x6842, 0x1078, 0x74d7, 0x0040, 0x2747, 0x2d00, 0x601a,
768 0x601f, 0x0001, 0x2001, 0x0000, 0x1078, 0x442b, 0x2001, 0x0000,
769 0x1078, 0x443f, 0x127e, 0x2091, 0x8000, 0x708c, 0x8000, 0x708e,
770 0x127f, 0x2009, 0x0004, 0x1078, 0x756c, 0xa085, 0x0001, 0x0c7f,
771 0x0d7f, 0x077f, 0x017f, 0x007c, 0x017e, 0x077e, 0x0d7e, 0x0c7e,
772 0x2c68, 0x2001, 0xa356, 0x2004, 0xa084, 0x00ff, 0x6842, 0x1078,
773 0x74d7, 0x0040, 0x2785, 0x2d00, 0x601a, 0x6800, 0xc0c4, 0x6802,
774 0x68a0, 0xa086, 0x007e, 0x0040, 0x276e, 0x6804, 0xa084, 0x00ff,
775 0xa086, 0x0006, 0x00c0, 0x276e, 0x1078, 0x2813, 0x601f, 0x0001,
776 0x2001, 0x0000, 0x1078, 0x442b, 0x2001, 0x0002, 0x1078, 0x443f,
777 0x127e, 0x2091, 0x8000, 0x708c, 0x8000, 0x708e, 0x127f, 0x2009,
778 0x0002, 0x1078, 0x756c, 0xa085, 0x0001, 0x0c7f, 0x0d7f, 0x077f,
779 0x017f, 0x007c, 0x0c7e, 0x027e, 0x2009, 0x0080, 0x1078, 0x4499,
780 0x00c0, 0x2798, 0x1078, 0x279b, 0x0040, 0x2798, 0x70cf, 0xffff,
781 0x027f, 0x0c7f, 0x007c, 0x017e, 0x077e, 0x0d7e, 0x0c7e, 0x2c68,
782 0x1078, 0x74d7, 0x0040, 0x27bd, 0x2d00, 0x601a, 0x601f, 0x0001,
783 0x2001, 0x0000, 0x1078, 0x442b, 0x2001, 0x0002, 0x1078, 0x443f,
784 0x127e, 0x2091, 0x8000, 0x70d0, 0x8000, 0x70d2, 0x127f, 0x2009,
785 0x0002, 0x1078, 0x756c, 0xa085, 0x0001, 0x0c7f, 0x0d7f, 0x077f,
786 0x017f, 0x007c, 0x0c7e, 0x0d7e, 0x127e, 0x2091, 0x8000, 0x2009,
787 0x007f, 0x1078, 0x4499, 0x00c0, 0x27de, 0x2c68, 0x1078, 0x74d7,
788 0x0040, 0x27de, 0x2d00, 0x601a, 0x6312, 0x601f, 0x0001, 0x620a,
789 0x2009, 0x0022, 0x1078, 0x756c, 0xa085, 0x0001, 0x127f, 0x0d7f,
790 0x0c7f, 0x007c, 0x0e7e, 0x0c7e, 0x067e, 0x037e, 0x027e, 0x1078,
791 0x5d60, 0x1078, 0x5d02, 0x1078, 0x7ddf, 0x2130, 0x81ff, 0x0040,
792 0x27f7, 0x20a9, 0x007e, 0x2009, 0x0000, 0x0078, 0x27fb, 0x20a9,
793 0x007f, 0x2009, 0x0000, 0x017e, 0x1078, 0x4501, 0x00c0, 0x2804,
794 0x1078, 0x471b, 0x1078, 0x4235, 0x017f, 0x8108, 0x00f0, 0x27fb,
795 0x86ff, 0x00c0, 0x280d, 0x1078, 0x119b, 0x027f, 0x037f, 0x067f,
796 0x0c7f, 0x0e7f, 0x007c, 0x0e7e, 0x0c7e, 0x037e, 0x027e, 0x017e,
797 0x6218, 0x2270, 0x72a0, 0x027e, 0x2019, 0x0029, 0x1078, 0x5d53,
798 0x077e, 0x2039, 0x0000, 0x1078, 0x5c78, 0x2c08, 0x1078, 0x9c38,
799 0x077f, 0x017f, 0x2e60, 0x1078, 0x471b, 0x6210, 0x6314, 0x1078,
800 0x4235, 0x6212, 0x6316, 0x017f, 0x027f, 0x037f, 0x0c7f, 0x0e7f,
801 0x007c, 0x0e7e, 0x007e, 0x6018, 0xa080, 0x0028, 0x2004, 0xd0bc,
802 0x00c0, 0x284d, 0x2071, 0xa300, 0x708c, 0xa005, 0x0040, 0x284a,
803 0x8001, 0x708e, 0x007f, 0x0e7f, 0x007c, 0x2071, 0xa300, 0x70d0,
804 0xa005, 0x0040, 0x284a, 0x8001, 0x70d2, 0x0078, 0x284a, 0x6000,
805 0xc08c, 0x6002, 0x007c, 0x0f7e, 0x0e7e, 0x0c7e, 0x037e, 0x027e,
806 0x017e, 0x157e, 0x2178, 0x81ff, 0x00c0, 0x286a, 0x20a9, 0x0001,
807 0x0078, 0x2885, 0x2001, 0xa352, 0x2004, 0xd0c4, 0x0040, 0x2881,
808 0xd0a4, 0x0040, 0x2881, 0x047e, 0x6018, 0xa080, 0x0028, 0x2024,
809 0xa4a4, 0x00ff, 0x8427, 0xa006, 0x2009, 0x002d, 0x1078, 0x9ec0,
810 0x047f, 0x20a9, 0x00ff, 0x2011, 0x0000, 0x027e, 0xa28e, 0x007e,
811 0x0040, 0x28c9, 0xa28e, 0x007f, 0x0040, 0x28c9, 0xa28e, 0x0080,
812 0x0040, 0x28c9, 0xa288, 0xa434, 0x210c, 0x81ff, 0x0040, 0x28c9,
813 0x8fff, 0x1040, 0x28d5, 0x0c7e, 0x2160, 0x2001, 0x0001, 0x1078,
814 0x48a2, 0x0c7f, 0x2019, 0x0029, 0x1078, 0x5d53, 0x077e, 0x2039,
815 0x0000, 0x1078, 0x5c78, 0x0c7e, 0x027e, 0x2160, 0x6204, 0xa294,
816 0x00ff, 0xa286, 0x0006, 0x00c0, 0x28b9, 0x6007, 0x0404, 0x0078,
817 0x28be, 0x2001, 0x0004, 0x8007, 0xa215, 0x6206, 0x027f, 0x0c7f,
818 0x017e, 0x2c08, 0x1078, 0x9c38, 0x017f, 0x077f, 0x2160, 0x1078,
819 0x471b, 0x027f, 0x8210, 0x00f0, 0x2885, 0x157f, 0x017f, 0x027f,
820 0x037f, 0x0c7f, 0x0e7f, 0x0f7f, 0x007c, 0x047e, 0x027e, 0x017e,
821 0x2001, 0xa352, 0x2004, 0xd0c4, 0x0040, 0x28e8, 0xd0a4, 0x0040,
822 0x28e8, 0xa006, 0x2220, 0x8427, 0x2009, 0x0029, 0x1078, 0x9ec0,
823 0x017f, 0x027f, 0x047f, 0x007c, 0x017e, 0x027e, 0x037e, 0x0c7e,
824 0x7280, 0x82ff, 0x0040, 0x291a, 0xa290, 0xa352, 0x2214, 0xd2ac,
825 0x00c0, 0x291a, 0x2100, 0x1078, 0x24fa, 0x81ff, 0x0040, 0x291c,
826 0x2019, 0x0001, 0x8314, 0xa2e0, 0xa9c0, 0x2c04, 0xd384, 0x0040,
827 0x290e, 0xa084, 0xff00, 0x8007, 0x0078, 0x2910, 0xa084, 0x00ff,
828 0xa116, 0x0040, 0x291c, 0xa096, 0x00ff, 0x0040, 0x291a, 0x8318,
829 0x0078, 0x2902, 0xa085, 0x0001, 0x0c7f, 0x037f, 0x027f, 0x017f,
830 0x007c, 0x017e, 0x0c7e, 0x127e, 0x2091, 0x8000, 0xa180, 0xa434,
831 0x2004, 0xa065, 0x0040, 0x293b, 0x017e, 0x0c7e, 0x1078, 0x8ec0,
832 0x017f, 0x1040, 0x1328, 0x611a, 0x1078, 0x2813, 0x1078, 0x753d,
833 0x017f, 0x1078, 0x44bc, 0x127f, 0x0c7f, 0x017f, 0x007c, 0x7eef,
834 0x7de8, 0x7ce4, 0x80e2, 0x7be1, 0x80e0, 0x80dc, 0x80da, 0x7ad9,
835 0x80d6, 0x80d5, 0x80d4, 0x80d3, 0x80d2, 0x80d1, 0x79ce, 0x78cd,
836 0x80cc, 0x80cb, 0x80ca, 0x80c9, 0x80c7, 0x80c6, 0x77c5, 0x76c3,
837 0x80bc, 0x80ba, 0x75b9, 0x80b6, 0x74b5, 0x73b4, 0x72b3, 0x80b2,
838 0x80b1, 0x80ae, 0x71ad, 0x80ac, 0x70ab, 0x6faa, 0x6ea9, 0x80a7,
839 0x6da6, 0x6ca5, 0x6ba3, 0x6a9f, 0x699e, 0x689d, 0x809b, 0x8098,
840 0x6797, 0x6690, 0x658f, 0x6488, 0x6384, 0x6282, 0x8081, 0x8080,
841 0x617c, 0x607a, 0x8079, 0x5f76, 0x8075, 0x8074, 0x8073, 0x8072,
842 0x8071, 0x806e, 0x5e6d, 0x806c, 0x5d6b, 0x5c6a, 0x5b69, 0x8067,
843 0x5a66, 0x5965, 0x5863, 0x575c, 0x565a, 0x5559, 0x8056, 0x8055,
844 0x5454, 0x5353, 0x5252, 0x5151, 0x504e, 0x4f4d, 0x804c, 0x804b,
845 0x4e4a, 0x4d49, 0x8047, 0x4c46, 0x8045, 0x8043, 0x803c, 0x803a,
846 0x8039, 0x8036, 0x4b35, 0x8034, 0x4a33, 0x4932, 0x4831, 0x802e,
847 0x472d, 0x462c, 0x452b, 0x442a, 0x4329, 0x4227, 0x8026, 0x8025,
848 0x4123, 0x401f, 0x3f1e, 0x3e1d, 0x3d1b, 0x3c18, 0x8017, 0x8010,
849 0x3b0f, 0x3a08, 0x8004, 0x3902, 0x8001, 0x8000, 0x8000, 0x3800,
850 0x3700, 0x3600, 0x8000, 0x3500, 0x8000, 0x8000, 0x8000, 0x3400,
851 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x3300, 0x3200,
852 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x3100, 0x3000,
853 0x8000, 0x8000, 0x2f00, 0x8000, 0x2e00, 0x2d00, 0x2c00, 0x8000,
854 0x8000, 0x8000, 0x2b00, 0x8000, 0x2a00, 0x2900, 0x2800, 0x8000,
855 0x2700, 0x2600, 0x2500, 0x2400, 0x2300, 0x2200, 0x8000, 0x8000,
856 0x2100, 0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x8000, 0x8000,
857 0x1b00, 0x1a00, 0x8000, 0x1900, 0x8000, 0x8000, 0x8000, 0x8000,
858 0x8000, 0x8000, 0x1800, 0x8000, 0x1700, 0x1600, 0x1500, 0x8000,
859 0x1400, 0x1300, 0x1200, 0x1100, 0x1000, 0x0f00, 0x8000, 0x8000,
860 0x0e00, 0x0d00, 0x0c00, 0x0b00, 0x0a00, 0x0900, 0x8000, 0x8000,
861 0x0800, 0x0700, 0x8000, 0x0600, 0x8000, 0x8000, 0x8000, 0x0500,
862 0x0400, 0x0300, 0x8000, 0x0200, 0x8000, 0x8000, 0x8000, 0x0100,
863 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x8000,
864 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
865 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x2071,
866 0xa381, 0x7003, 0x0002, 0xa006, 0x7012, 0x7016, 0x703a, 0x703e,
867 0x7033, 0xa391, 0x7037, 0xa391, 0x7007, 0x0001, 0x2061, 0xa3d1,
868 0x6003, 0x0002, 0x007c, 0x0090, 0x2a66, 0x0068, 0x2a66, 0x2071,
869 0xa381, 0x2b78, 0x7818, 0xd084, 0x00c0, 0x2a66, 0x2a60, 0x7820,
870 0xa08e, 0x0069, 0x00c0, 0x2b56, 0x0079, 0x2aea, 0x007c, 0x2071,
871 0xa381, 0x7004, 0x0079, 0x2a6c, 0x2a70, 0x2a71, 0x2a7b, 0x2a8d,
872 0x007c, 0x0090, 0x2a7a, 0x0068, 0x2a7a, 0x2b78, 0x7818, 0xd084,
873 0x0040, 0x2a99, 0x007c, 0x2b78, 0x2061, 0xa3d1, 0x6008, 0xa08e,
874 0x0100, 0x0040, 0x2a88, 0xa086, 0x0200, 0x0040, 0x2b4e, 0x007c,
875 0x7014, 0x2068, 0x2a60, 0x7018, 0x007a, 0x7010, 0x2068, 0x6834,
876 0xa086, 0x0103, 0x0040, 0x2a95, 0x007c, 0x2a60, 0x2b78, 0x7018,
877 0x007a, 0x2a60, 0x7820, 0xa08a, 0x0040, 0x00c8, 0x2aa2, 0x61b8,
878 0x0079, 0x2aaa, 0x2100, 0xa08a, 0x003f, 0x00c8, 0x2b4a, 0x61b8,
879 0x0079, 0x2aea, 0x2b2c, 0x2b5e, 0x2b66, 0x2b6a, 0x2b72, 0x2b78,
880 0x2b7c, 0x2b88, 0x2b8c, 0x2b96, 0x2b9a, 0x2b4a, 0x2b4a, 0x2b4a,
881 0x2b9e, 0x2b4a, 0x2bae, 0x2bc5, 0x2bdc, 0x2c58, 0x2c5d, 0x2c8a,
882 0x2ce4, 0x2cf5, 0x2d13, 0x2d54, 0x2d5e, 0x2d6b, 0x2d7e, 0x2d9d,
883 0x2da6, 0x2de3, 0x2de9, 0x2b4a, 0x2e05, 0x2b4a, 0x2b4a, 0x2b4a,
884 0x2b4a, 0x2b4a, 0x2e0c, 0x2e16, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a,
885 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2e1e, 0x2b4a, 0x2b4a, 0x2b4a,
886 0x2b4a, 0x2b4a, 0x2e30, 0x2e47, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a,
887 0x2b4a, 0x2b4a, 0x2e59, 0x2eb0, 0x2f0e, 0x2f1f, 0x2b4a, 0x2b4a,
888 0x2b4a, 0x38f1, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a,
889 0x2b4a, 0x2b4a, 0x2b96, 0x2b9a, 0x2f36, 0x2b4a, 0x2f43, 0x397d,
890 0x39da, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a,
891 0x2b4a, 0x2b4a, 0x2f90, 0x30c5, 0x30e1, 0x30ed, 0x3150, 0x31a9,
892 0x31b4, 0x31f3, 0x3202, 0x3211, 0x3214, 0x2f47, 0x3238, 0x3284,
893 0x3291, 0x33a2, 0x34cd, 0x34f7, 0x3604, 0x3614, 0x3621, 0x365b,
894 0x372a, 0x2b4a, 0x2b4a, 0x2b4a, 0x2b4a, 0x3792, 0x37ae, 0x3828,
895 0x38e2, 0x713c, 0x0078, 0x2b2c, 0x2021, 0x4000, 0x1078, 0x3553,
896 0x127e, 0x2091, 0x8000, 0x0068, 0x2b39, 0x7818, 0xd084, 0x0040,
897 0x2b3c, 0x127f, 0x0078, 0x2b30, 0x7c22, 0x7926, 0x7a2a, 0x7b2e,
898 0x781b, 0x0001, 0x2091, 0x4080, 0x7007, 0x0001, 0x2091, 0x5000,
899 0x127f, 0x007c, 0x2021, 0x4001, 0x0078, 0x2b2e, 0x2021, 0x4002,
900 0x0078, 0x2b2e, 0x2021, 0x4003, 0x0078, 0x2b2e, 0x2021, 0x4005,
901 0x0078, 0x2b2e, 0x2021, 0x4006, 0x0078, 0x2b2e, 0xa02e, 0x2520,
902 0x7b28, 0x7a2c, 0x7824, 0x7930, 0x0078, 0x3562, 0x7823, 0x0004,
903 0x7824, 0x007a, 0xa02e, 0x2520, 0x7b28, 0x7a2c, 0x7824, 0x7930,
904 0x0078, 0x3566, 0x7924, 0x7828, 0x2114, 0x200a, 0x0078, 0x2b2c,
905 0x7924, 0x2114, 0x0078, 0x2b2c, 0x2099, 0x0009, 0x20a1, 0x0009,
906 0x20a9, 0x0007, 0x53a3, 0x7924, 0x7a28, 0x7b2c, 0x0078, 0x2b2c,
907 0x7824, 0x2060, 0x0078, 0x2ba0, 0x2009, 0x0001, 0x2011, 0x0013,
908 0x2019, 0x0010, 0x783b, 0x0017, 0x0078, 0x2b2c, 0x7d38, 0x7c3c,
909 0x0078, 0x2b60, 0x7d38, 0x7c3c, 0x0078, 0x2b6c, 0x2061, 0x1000,
910 0x610c, 0xa006, 0x2c14, 0xa200, 0x8c60, 0x8109, 0x00c0, 0x2ba2,
911 0x2010, 0xa005, 0x0040, 0x2b2c, 0x0078, 0x2b52, 0x2069, 0xa351,
912 0x7824, 0x7930, 0xa11a, 0x00c8, 0x2b5a, 0x8019, 0x0040, 0x2b5a,
913 0x684a, 0x6942, 0x782c, 0x6852, 0x7828, 0x6856, 0xa006, 0x685a,
914 0x685e, 0x1078, 0x4dbd, 0x0078, 0x2b2c, 0x2069, 0xa351, 0x7824,
915 0x7934, 0xa11a, 0x00c8, 0x2b5a, 0x8019, 0x0040, 0x2b5a, 0x684e,
916 0x6946, 0x782c, 0x6862, 0x7828, 0x6866, 0xa006, 0x686a, 0x686e,
917 0x1078, 0x494d, 0x0078, 0x2b2c, 0xa02e, 0x2520, 0x81ff, 0x00c0,
918 0x2b56, 0x7924, 0x7b28, 0x7a2c, 0x20a9, 0x0005, 0x20a1, 0xa388,
919 0x41a1, 0x1078, 0x3518, 0x0040, 0x2b56, 0x2009, 0x0020, 0x1078,
920 0x3562, 0x701b, 0x2bf4, 0x007c, 0x6834, 0x2008, 0xa084, 0x00ff,
921 0xa096, 0x0011, 0x0040, 0x2c00, 0xa096, 0x0019, 0x00c0, 0x2b56,
922 0x810f, 0xa18c, 0x00ff, 0x0040, 0x2b56, 0x710e, 0x700c, 0x8001,
923 0x0040, 0x2c31, 0x700e, 0x1078, 0x3518, 0x0040, 0x2b56, 0x2009,
924 0x0020, 0x2061, 0xa3d1, 0x6224, 0x6328, 0x642c, 0x6530, 0xa290,
925 0x0040, 0xa399, 0x0000, 0xa4a1, 0x0000, 0xa5a9, 0x0000, 0x1078,
926 0x3562, 0x701b, 0x2c24, 0x007c, 0x6834, 0xa084, 0x00ff, 0xa096,
927 0x0002, 0x0040, 0x2c2f, 0xa096, 0x000a, 0x00c0, 0x2b56, 0x0078,
928 0x2c06, 0x7010, 0x2068, 0x6838, 0xc0fd, 0x683a, 0x1078, 0x436e,
929 0x00c0, 0x2c3f, 0x7007, 0x0003, 0x701b, 0x2c41, 0x007c, 0x1078,
930 0x4a60, 0x127e, 0x2091, 0x8000, 0x20a9, 0x0005, 0x2099, 0xa388,
931 0x530a, 0x2100, 0xa210, 0xa399, 0x0000, 0xa4a1, 0x0000, 0xa5a9,
932 0x0000, 0xad80, 0x000d, 0x2009, 0x0020, 0x127f, 0x0078, 0x3566,
933 0x61a0, 0x7824, 0x60a2, 0x0078, 0x2b2c, 0x2091, 0x8000, 0x7823,
934 0x4000, 0x7827, 0x4953, 0x782b, 0x5020, 0x782f, 0x2020, 0x2009,
935 0x017f, 0x2104, 0x7832, 0x3f00, 0x7836, 0x2061, 0x0100, 0x6200,
936 0x2061, 0x0200, 0x603c, 0x8007, 0xa205, 0x783a, 0x2009, 0x04fd,
937 0x2104, 0x783e, 0x781b, 0x0001, 0x2091, 0x5000, 0x2091, 0x4080,
938 0x2071, 0x0010, 0x20c1, 0x00f0, 0xa08a, 0x0003, 0x00c8, 0x0427,
939 0x0078, 0x0423, 0x81ff, 0x00c0, 0x2b56, 0x7924, 0x810f, 0xa18c,
940 0x00ff, 0x1078, 0x4501, 0x00c0, 0x2b5a, 0x7e38, 0xa684, 0x3fff,
941 0xa082, 0x4000, 0x0048, 0x2c9e, 0x0078, 0x2b5a, 0x7c28, 0x7d2c,
942 0x1078, 0x46d6, 0xd28c, 0x00c0, 0x2ca9, 0x1078, 0x466a, 0x0078,
943 0x2cab, 0x1078, 0x46a4, 0x00c0, 0x2cd5, 0x2061, 0xaa00, 0x127e,
944 0x2091, 0x8000, 0x6000, 0xa086, 0x0000, 0x0040, 0x2cc3, 0x6010,
945 0xa06d, 0x0040, 0x2cc3, 0x683c, 0xa406, 0x00c0, 0x2cc3, 0x6840,
946 0xa506, 0x0040, 0x2cce, 0x127f, 0xace0, 0x0010, 0x2001, 0xa315,
947 0x2004, 0xac02, 0x00c8, 0x2b56, 0x0078, 0x2caf, 0x1078, 0x8758,
948 0x127f, 0x0040, 0x2b56, 0x0078, 0x2b2c, 0xa00e, 0x2001, 0x0005,
949 0x1078, 0x4a60, 0x127e, 0x2091, 0x8000, 0x1078, 0x8cc0, 0x1078,
950 0x4982, 0x127f, 0x0078, 0x2b2c, 0x81ff, 0x00c0, 0x2b56, 0x1078,
951 0x3530, 0x0040, 0x2b5a, 0x1078, 0x45a7, 0x0040, 0x2b56, 0x1078,
952 0x46e4, 0x0040, 0x2b56, 0x0078, 0x2b2c, 0x81ff, 0x00c0, 0x2b56,
953 0x1078, 0x3542, 0x0040, 0x2b5a, 0x1078, 0x475f, 0x0040, 0x2b56,
954 0x2019, 0x0005, 0x1078, 0x4705, 0x0040, 0x2b56, 0x7828, 0xa08a,
955 0x1000, 0x00c8, 0x2b5a, 0x8003, 0x800b, 0x810b, 0xa108, 0x1078,
956 0x58e1, 0x0078, 0x2b2c, 0x127e, 0x2091, 0x8000, 0x81ff, 0x0040,
957 0x2d1d, 0x2009, 0x0001, 0x0078, 0x2d4e, 0x2029, 0x00ff, 0x644c,
958 0x2400, 0xa506, 0x0040, 0x2d48, 0x2508, 0x1078, 0x4501, 0x00c0,
959 0x2d48, 0x1078, 0x475f, 0x00c0, 0x2d33, 0x2009, 0x0002, 0x62a8,
960 0x2518, 0x0078, 0x2d4e, 0x2019, 0x0004, 0x1078, 0x4705, 0x00c0,
961 0x2d3d, 0x2009, 0x0006, 0x0078, 0x2d4e, 0x7824, 0xa08a, 0x1000,
962 0x00c8, 0x2d51, 0x8003, 0x800b, 0x810b, 0xa108, 0x1078, 0x58e1,
963 0x8529, 0x00c8, 0x2d20, 0x127f, 0x0078, 0x2b2c, 0x127f, 0x0078,
964 0x2b56, 0x127f, 0x0078, 0x2b5a, 0x1078, 0x3530, 0x0040, 0x2b5a,
965 0x1078, 0x461b, 0x1078, 0x46d6, 0x0078, 0x2b2c, 0x81ff, 0x00c0,
966 0x2b56, 0x1078, 0x3530, 0x0040, 0x2b5a, 0x1078, 0x460a, 0x1078,
967 0x46d6, 0x0078, 0x2b2c, 0x81ff, 0x00c0, 0x2b56, 0x1078, 0x3530,
968 0x0040, 0x2b5a, 0x1078, 0x46a7, 0x0040, 0x2b56, 0x1078, 0x43c1,
969 0x1078, 0x4663, 0x1078, 0x46d6, 0x0078, 0x2b2c, 0x1078, 0x3530,
970 0x0040, 0x2b5a, 0x1078, 0x45a7, 0x0040, 0x2b56, 0x62a0, 0x2019,
971 0x0005, 0x0c7e, 0x1078, 0x471b, 0x0c7f, 0x1078, 0x5d53, 0x077e,
972 0x2039, 0x0000, 0x1078, 0x5c78, 0x2009, 0x0000, 0x1078, 0x9c38,
973 0x077f, 0x1078, 0x46d6, 0x0078, 0x2b2c, 0x1078, 0x3530, 0x0040,
974 0x2b5a, 0x1078, 0x46d6, 0x2208, 0x0078, 0x2b2c, 0x157e, 0x0d7e,
975 0x0e7e, 0x2069, 0xa413, 0x6810, 0x6914, 0xa10a, 0x00c8, 0x2db2,
976 0x2009, 0x0000, 0x6816, 0x2011, 0x0000, 0x2019, 0x0000, 0x20a9,
977 0x00ff, 0x2069, 0xa434, 0x2d04, 0xa075, 0x0040, 0x2dc7, 0x704c,
978 0x1078, 0x2dd1, 0xa210, 0x7080, 0x1078, 0x2dd1, 0xa318, 0x8d68,
979 0x00f0, 0x2dbb, 0x2300, 0xa218, 0x0e7f, 0x0d7f, 0x157f, 0x0078,
980 0x2b2c, 0x0f7e, 0x017e, 0xa07d, 0x0040, 0x2de0, 0x2001, 0x0000,
981 0x8000, 0x2f0c, 0x81ff, 0x0040, 0x2de0, 0x2178, 0x0078, 0x2dd8,
982 0x017f, 0x0f7f, 0x007c, 0x2069, 0xa413, 0x6910, 0x62a4, 0x0078,
983 0x2b2c, 0x81ff, 0x00c0, 0x2b56, 0x614c, 0xa190, 0x293f, 0x2214,
984 0xa294, 0x00ff, 0x606c, 0xa084, 0xff00, 0xa215, 0x6368, 0x67c8,
985 0xd79c, 0x0040, 0x2dff, 0x2031, 0x0001, 0x0078, 0x2e01, 0x2031,
986 0x0000, 0x7e3a, 0x7f3e, 0x0078, 0x2b2c, 0x613c, 0x6240, 0x2019,
987 0xa5a0, 0x231c, 0x0078, 0x2b2c, 0x127e, 0x2091, 0x8000, 0x6134,
988 0xa006, 0x2010, 0x2018, 0x127f, 0x0078, 0x2b2c, 0x1078, 0x3542,
989 0x0040, 0x2b5a, 0x6244, 0x6338, 0x0078, 0x2b2c, 0x613c, 0x6240,
990 0x7824, 0x603e, 0x7b28, 0x6342, 0x2069, 0xa351, 0x831f, 0xa305,
991 0x6816, 0x782c, 0x2069, 0xa5a0, 0x2d1c, 0x206a, 0x0078, 0x2b2c,
992 0x017e, 0x127e, 0x2091, 0x8000, 0x7824, 0x6036, 0xd094, 0x0040,
993 0x2e43, 0x7828, 0xa085, 0x0001, 0x2009, 0xa5a9, 0x200a, 0x2001,
994 0xffff, 0x1078, 0x5975, 0x127f, 0x017f, 0x0078, 0x2b2c, 0x1078,
995 0x3542, 0x0040, 0x2b5a, 0x7828, 0xa00d, 0x0040, 0x2b5a, 0x782c,
996 0xa005, 0x0040, 0x2b5a, 0x6244, 0x6146, 0x6338, 0x603a, 0x0078,
997 0x2b2c, 0x2001, 0xa300, 0x2004, 0xa086, 0x0003, 0x00c0, 0x2b56,
998 0x0c7e, 0x2061, 0x0100, 0x7924, 0x810f, 0xa18c, 0x00ff, 0xa196,
999 0x00ff, 0x00c0, 0x2e70, 0x6030, 0xa085, 0xff00, 0x0078, 0x2e7f,
1000 0xa182, 0x007f, 0x00c8, 0x2ea9, 0xa188, 0x293f, 0x210c, 0xa18c,
1001 0x00ff, 0x6030, 0xa116, 0x0040, 0x2ea9, 0x810f, 0xa105, 0x127e,
1002 0x2091, 0x8000, 0x007e, 0x1078, 0x74d7, 0x007f, 0x0040, 0x2ea5,
1003 0x601a, 0x600b, 0xbc09, 0x601f, 0x0001, 0x1078, 0x3518, 0x0040,
1004 0x2eac, 0x6837, 0x0000, 0x7007, 0x0003, 0x6833, 0x0000, 0x6838,
1005 0xc0fd, 0x683a, 0x701b, 0x2f07, 0x2d00, 0x6012, 0x2009, 0x0032,
1006 0x1078, 0x756c, 0x127f, 0x0c7f, 0x007c, 0x127f, 0x0c7f, 0x0078,
1007 0x2b56, 0x0c7f, 0x0078, 0x2b5a, 0x1078, 0x753d, 0x0078, 0x2ea5,
1008 0x2001, 0xa300, 0x2004, 0xa086, 0x0003, 0x00c0, 0x2b56, 0x0c7e,
1009 0x2061, 0x0100, 0x7924, 0x810f, 0xa18c, 0x00ff, 0xa196, 0x00ff,
1010 0x00c0, 0x2ec7, 0x6030, 0xa085, 0xff00, 0x0078, 0x2ed6, 0xa182,
1011 0x007f, 0x00c8, 0x2f00, 0xa188, 0x293f, 0x210c, 0xa18c, 0x00ff,
1012 0x6030, 0xa116, 0x0040, 0x2f00, 0x810f, 0xa105, 0x127e, 0x2091,
1013 0x8000, 0x007e, 0x1078, 0x74d7, 0x007f, 0x0040, 0x2efc, 0x601a,
1014 0x600b, 0xbc05, 0x601f, 0x0001, 0x1078, 0x3518, 0x0040, 0x2f03,
1015 0x6837, 0x0000, 0x7007, 0x0003, 0x6833, 0x0000, 0x6838, 0xc0fd,
1016 0x683a, 0x701b, 0x2f07, 0x2d00, 0x6012, 0x2009, 0x0032, 0x1078,
1017 0x756c, 0x127f, 0x0c7f, 0x007c, 0x127f, 0x0c7f, 0x0078, 0x2b56,
1018 0x0c7f, 0x0078, 0x2b5a, 0x1078, 0x753d, 0x0078, 0x2efc, 0x6830,
1019 0xa086, 0x0100, 0x0040, 0x2b56, 0x0078, 0x2b2c, 0x2061, 0xa62d,
1020 0x127e, 0x2091, 0x8000, 0x6000, 0xd084, 0x0040, 0x2f1c, 0x6104,
1021 0x6208, 0x127f, 0x0078, 0x2b2c, 0x127f, 0x0078, 0x2b5a, 0x81ff,
1022 0x00c0, 0x2b56, 0x127e, 0x2091, 0x8000, 0x6244, 0x6060, 0xa202,
1023 0x0048, 0x2f33, 0xa085, 0x0001, 0x1078, 0x2500, 0x1078, 0x3bf5,
1024 0x127f, 0x0078, 0x2b2c, 0x127f, 0x0078, 0x2b5a, 0x127e, 0x2091,
1025 0x8000, 0x20a9, 0x0011, 0x2001, 0xa340, 0x20a0, 0xa006, 0x40a4,
1026 0x127f, 0x0078, 0x2b2c, 0x7d38, 0x7c3c, 0x0078, 0x2bde, 0x7824,
1027 0xa09c, 0x00ff, 0xa39a, 0x0003, 0x00c8, 0x2b56, 0x624c, 0xa084,
1028 0xff00, 0x8007, 0xa206, 0x00c0, 0x2f5f, 0x2001, 0xa340, 0x2009,
1029 0x000c, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0078, 0x3566, 0x81ff,
1030 0x00c0, 0x2b56, 0x1078, 0x3542, 0x0040, 0x2b5a, 0x6004, 0xa084,
1031 0x00ff, 0xa086, 0x0006, 0x00c0, 0x2b56, 0x0c7e, 0x1078, 0x3518,
1032 0x0c7f, 0x0040, 0x2b56, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a,
1033 0x1078, 0x8b85, 0x0040, 0x2b56, 0x7007, 0x0003, 0x701b, 0x2f81,
1034 0x007c, 0x6830, 0xa086, 0x0100, 0x0040, 0x2b56, 0xad80, 0x000e,
1035 0x2009, 0x000c, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0078, 0x3566,
1036 0x1078, 0x3518, 0x0040, 0x2b56, 0x1078, 0x421a, 0x2009, 0x001c,
1037 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x1078, 0x3562, 0x701b, 0x2fa1,
1038 0x007c, 0xade8, 0x000d, 0x6800, 0xa005, 0x0040, 0x2b5a, 0x6804,
1039 0xd0ac, 0x0040, 0x2fae, 0xd0a4, 0x0040, 0x2b5a, 0xd094, 0x0040,
1040 0x2fb9, 0x0c7e, 0x2061, 0x0100, 0x6104, 0xa18c, 0xffdf, 0x6106,
1041 0x0c7f, 0xd08c, 0x0040, 0x2fc4, 0x0c7e, 0x2061, 0x0100, 0x6104,
1042 0xa18d, 0x0010, 0x6106, 0x0c7f, 0x2009, 0x0100, 0x210c, 0xa18a,
1043 0x0002, 0x0048, 0x2fd9, 0xd084, 0x0040, 0x2fd9, 0x6a28, 0xa28a,
1044 0x007f, 0x00c8, 0x2b5a, 0xa288, 0x293f, 0x210c, 0xa18c, 0x00ff,
1045 0x6152, 0xd0dc, 0x0040, 0x2fe2, 0x6828, 0xa08a, 0x007f, 0x00c8,
1046 0x2b5a, 0x604e, 0x6808, 0xa08a, 0x0100, 0x0048, 0x2b5a, 0xa08a,
1047 0x0841, 0x00c8, 0x2b5a, 0xa084, 0x0007, 0x00c0, 0x2b5a, 0x680c,
1048 0xa005, 0x0040, 0x2b5a, 0x6810, 0xa005, 0x0040, 0x2b5a, 0x6848,
1049 0x6940, 0xa10a, 0x00c8, 0x2b5a, 0x8001, 0x0040, 0x2b5a, 0x684c,
1050 0x6944, 0xa10a, 0x00c8, 0x2b5a, 0x8001, 0x0040, 0x2b5a, 0x6804,
1051 0xd0fc, 0x0040, 0x3038, 0x1078, 0x3518, 0x0040, 0x2b56, 0x2009,
1052 0x0014, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0xa290, 0x0038, 0xa399,
1053 0x0000, 0x1078, 0x3562, 0x701b, 0x301e, 0x007c, 0xade8, 0x000d,
1054 0x20a9, 0x0014, 0x2d98, 0x2069, 0xa36d, 0x2da0, 0x53a3, 0x7010,
1055 0xa0e8, 0x000d, 0x2001, 0xa371, 0x200c, 0xd1e4, 0x0040, 0x3038,
1056 0x0c7e, 0x2061, 0x0100, 0x6004, 0xa085, 0x0b00, 0x6006, 0x0c7f,
1057 0x20a9, 0x001c, 0x2d98, 0x2069, 0xa351, 0x2da0, 0x53a3, 0x6814,
1058 0xa08c, 0x00ff, 0x613e, 0x8007, 0xa084, 0x00ff, 0x6042, 0x1078,
1059 0x4dbd, 0x1078, 0x48dd, 0x1078, 0x494d, 0x6000, 0xa086, 0x0000,
1060 0x00c0, 0x30c3, 0x6808, 0x602a, 0x1078, 0x218b, 0x6818, 0x691c,
1061 0x6a20, 0x6b24, 0x8007, 0x810f, 0x8217, 0x831f, 0x6016, 0x611a,
1062 0x621e, 0x6322, 0x6c04, 0xd4f4, 0x0040, 0x3070, 0x6830, 0x6934,
1063 0x6a38, 0x6b3c, 0x8007, 0x810f, 0x8217, 0x831f, 0x0078, 0x3072,
1064 0xa084, 0xf0ff, 0x6006, 0x610a, 0x620e, 0x6312, 0x1078, 0x59a8,
1065 0x6904, 0xd1fc, 0x0040, 0x30a5, 0x0c7e, 0x2009, 0x0000, 0x20a9,
1066 0x0001, 0x6b70, 0xd384, 0x0040, 0x30a2, 0x0078, 0x308c, 0x839d,
1067 0x00c8, 0x30a2, 0x3508, 0x8109, 0x1078, 0x5364, 0x6878, 0x6016,
1068 0x6874, 0x2008, 0xa084, 0xff00, 0x8007, 0x600a, 0xa184, 0x00ff,
1069 0x6006, 0x8108, 0x00c0, 0x30a0, 0x6003, 0x0003, 0x0078, 0x30a2,
1070 0x6003, 0x0001, 0x00f0, 0x3087, 0x0c7f, 0x0c7e, 0x2061, 0x0100,
1071 0x602f, 0x0040, 0x602f, 0x0000, 0x0c7f, 0x1078, 0x3784, 0x0040,
1072 0x30b3, 0x1078, 0x2500, 0x60bc, 0xa005, 0x0040, 0x30bf, 0x6003,
1073 0x0001, 0x2091, 0x301d, 0x1078, 0x4171, 0x0078, 0x30c3, 0x6003,
1074 0x0004, 0x2091, 0x301d, 0x0078, 0x2b2c, 0x6000, 0xa086, 0x0000,
1075 0x0040, 0x2b56, 0x2069, 0xa351, 0x7830, 0x6842, 0x7834, 0x6846,
1076 0x6804, 0xd0fc, 0x0040, 0x30d8, 0x2009, 0x0030, 0x0078, 0x30da,
1077 0x2009, 0x001c, 0x2d00, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0078,
1078 0x3566, 0xa006, 0x1078, 0x2500, 0x81ff, 0x00c0, 0x2b56, 0x1078,
1079 0x421a, 0x1078, 0x4171, 0x0078, 0x2b2c, 0x81ff, 0x00c0, 0x2b56,
1080 0x6180, 0x81ff, 0x0040, 0x3107, 0x703f, 0x0000, 0x2001, 0xa9c0,
1081 0x2009, 0x0040, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x127e, 0x2091,
1082 0x8000, 0x1078, 0x3566, 0x701b, 0x2b29, 0x127f, 0x007c, 0x703f,
1083 0x0001, 0x0d7e, 0x2069, 0xa9c0, 0x20a9, 0x0040, 0x20a1, 0xa9c0,
1084 0x2019, 0xffff, 0x43a4, 0x654c, 0xa588, 0x293f, 0x210c, 0xa18c,
1085 0x00ff, 0x216a, 0xa00e, 0x2011, 0x0002, 0x2100, 0xa506, 0x0040,
1086 0x3139, 0x1078, 0x4501, 0x00c0, 0x3139, 0x6014, 0x821c, 0x0048,
1087 0x3131, 0xa398, 0xa9c0, 0xa085, 0xff00, 0x8007, 0x201a, 0x0078,
1088 0x3138, 0xa398, 0xa9c0, 0x2324, 0xa4a4, 0xff00, 0xa405, 0x201a,
1089 0x8210, 0x8108, 0xa182, 0x0080, 0x00c8, 0x3140, 0x0078, 0x311d,
1090 0x8201, 0x8007, 0x2d0c, 0xa105, 0x206a, 0x0d7f, 0x20a9, 0x0040,
1091 0x20a1, 0xa9c0, 0x2099, 0xa9c0, 0x1078, 0x41be, 0x0078, 0x30f6,
1092 0x1078, 0x3542, 0x0040, 0x2b5a, 0x0c7e, 0x1078, 0x3518, 0x0c7f,
1093 0x00c0, 0x315e, 0x2009, 0x0002, 0x0078, 0x2b56, 0x2001, 0xa352,
1094 0x2004, 0xd0b4, 0x0040, 0x3185, 0x6000, 0xd08c, 0x00c0, 0x3185,
1095 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x00c0, 0x3185, 0x6837,
1096 0x0000, 0x6838, 0xc0fd, 0x683a, 0x1078, 0x8bd9, 0x00c0, 0x317c,
1097 0x2009, 0x0003, 0x0078, 0x2b56, 0x7007, 0x0003, 0x701b, 0x3181,
1098 0x007c, 0x1078, 0x3542, 0x0040, 0x2b5a, 0x20a9, 0x002b, 0x2c98,
1099 0xade8, 0x0002, 0x2da0, 0x53a3, 0x20a9, 0x0004, 0xac80, 0x0006,
1100 0x2098, 0xad80, 0x0006, 0x20a0, 0x1078, 0x41be, 0x20a9, 0x0004,
1101 0xac80, 0x000a, 0x2098, 0xad80, 0x000a, 0x20a0, 0x1078, 0x41be,
1102 0x2d00, 0x2009, 0x002b, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0078,
1103 0x3566, 0x81ff, 0x00c0, 0x2b56, 0x1078, 0x3530, 0x0040, 0x2b5a,
1104 0x1078, 0x46ef, 0x0078, 0x2b2c, 0x81ff, 0x00c0, 0x2b56, 0x7828,
1105 0xa08a, 0x1000, 0x00c8, 0x2b5a, 0x1078, 0x3542, 0x0040, 0x2b5a,
1106 0x1078, 0x475f, 0x0040, 0x2b56, 0x2019, 0x0004, 0x1078, 0x4705,
1107 0x7924, 0x810f, 0x7a28, 0x1078, 0x31cf, 0x0078, 0x2b2c, 0xa186,
1108 0x00ff, 0x0040, 0x31d7, 0x1078, 0x31e7, 0x0078, 0x31e6, 0x2029,
1109 0x007e, 0x2061, 0xa300, 0x644c, 0x2400, 0xa506, 0x0040, 0x31e3,
1110 0x2508, 0x1078, 0x31e7, 0x8529, 0x00c8, 0x31dc, 0x007c, 0x1078,
1111 0x4501, 0x00c0, 0x31f2, 0x2200, 0x8003, 0x800b, 0x810b, 0xa108,
1112 0x1078, 0x58e1, 0x007c, 0x81ff, 0x00c0, 0x2b56, 0x1078, 0x3530,
1113 0x0040, 0x2b5a, 0x1078, 0x45a7, 0x0040, 0x2b56, 0x1078, 0x46fa,
1114 0x0078, 0x2b2c, 0x81ff, 0x00c0, 0x2b56, 0x1078, 0x3530, 0x0040,
1115 0x2b5a, 0x1078, 0x45a7, 0x0040, 0x2b56, 0x1078, 0x46e4, 0x0078,
1116 0x2b2c, 0x6100, 0x0078, 0x2b2c, 0x1078, 0x3542, 0x0040, 0x2b5a,
1117 0x2001, 0xa300, 0x2004, 0xa086, 0x0003, 0x00c0, 0x2b56, 0x0d7e,
1118 0xace8, 0x000a, 0x7924, 0xd184, 0x0040, 0x3228, 0xace8, 0x0006,
1119 0x680c, 0x8007, 0x783e, 0x6808, 0x8007, 0x783a, 0x6b04, 0x831f,
1120 0x6a00, 0x8217, 0x0d7f, 0x6100, 0xa18c, 0x0200, 0x0078, 0x2b2c,
1121 0xa006, 0x1078, 0x2500, 0x7824, 0xa084, 0x00ff, 0xa086, 0x00ff,
1122 0x0040, 0x3245, 0x81ff, 0x00c0, 0x2b56, 0x1078, 0x421a, 0x7828,
1123 0xa08a, 0x1000, 0x00c8, 0x2b5a, 0x7924, 0xa18c, 0xff00, 0x810f,
1124 0xa186, 0x00ff, 0x0040, 0x325b, 0xa182, 0x007f, 0x00c8, 0x2b5a,
1125 0x2100, 0x1078, 0x24fa, 0x027e, 0x0c7e, 0x127e, 0x2091, 0x8000,
1126 0x2061, 0xa5be, 0x601b, 0x0000, 0x601f, 0x0000, 0x2061, 0x0100,
1127 0x6030, 0xa084, 0x00ff, 0x810f, 0xa105, 0x604a, 0x6043, 0x0090,
1128 0x6043, 0x0010, 0x2009, 0x002d, 0x2011, 0x4196, 0x1078, 0x596c,
1129 0x7924, 0xa18c, 0xff00, 0x810f, 0x7a28, 0x1078, 0x31cf, 0x127f,
1130 0x0c7f, 0x027f, 0x0078, 0x2b2c, 0x7924, 0xa18c, 0xff00, 0x810f,
1131 0x0c7e, 0x1078, 0x4499, 0x2c08, 0x0c7f, 0x00c0, 0x2b5a, 0x0078,
1132 0x2b2c, 0x81ff, 0x0040, 0x3298, 0x2009, 0x0001, 0x0078, 0x2b56,
1133 0x60c8, 0xd09c, 0x00c0, 0x32a0, 0x2009, 0x0005, 0x0078, 0x2b56,
1134 0x1078, 0x3518, 0x00c0, 0x32a8, 0x2009, 0x0002, 0x0078, 0x2b56,
1135 0x7924, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x1078, 0x3562, 0x701b,
1136 0x32b2, 0x007c, 0x2009, 0x0080, 0x1078, 0x4501, 0x00c0, 0x32bf,
1137 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x0040, 0x32c3, 0x2021,
1138 0x400a, 0x0078, 0x2b2e, 0x0d7e, 0xade8, 0x000d, 0x6900, 0x6a08,
1139 0x6b0c, 0x6c10, 0x6d14, 0x6e18, 0x6820, 0xa0be, 0x0100, 0x0040,
1140 0x3336, 0xa0be, 0x0112, 0x0040, 0x3336, 0xa0be, 0x0113, 0x0040,
1141 0x3336, 0xa0be, 0x0114, 0x0040, 0x3336, 0xa0be, 0x0117, 0x0040,
1142 0x3336, 0xa0be, 0x011a, 0x0040, 0x3336, 0xa0be, 0x0121, 0x0040,
1143 0x332c, 0xa0be, 0x0131, 0x0040, 0x332c, 0xa0be, 0x0171, 0x0040,
1144 0x3336, 0xa0be, 0x0173, 0x0040, 0x3336, 0xa0be, 0x01a1, 0x00c0,
1145 0x32fe, 0x6830, 0x8007, 0x6832, 0x0078, 0x333c, 0xa0be, 0x0212,
1146 0x0040, 0x3332, 0xa0be, 0x0213, 0x0040, 0x3332, 0xa0be, 0x0214,
1147 0x0040, 0x3324, 0xa0be, 0x0217, 0x0040, 0x331e, 0xa0be, 0x021a,
1148 0x00c0, 0x3317, 0x6838, 0x8007, 0x683a, 0x0078, 0x3336, 0xa0be,
1149 0x0300, 0x0040, 0x3336, 0x0d7f, 0x0078, 0x2b5a, 0xad80, 0x0010,
1150 0x20a9, 0x0007, 0x1078, 0x337e, 0xad80, 0x000e, 0x20a9, 0x0001,
1151 0x1078, 0x337e, 0x0078, 0x3336, 0xad80, 0x000c, 0x1078, 0x338c,
1152 0x0078, 0x333c, 0xad80, 0x000e, 0x1078, 0x338c, 0xad80, 0x000c,
1153 0x20a9, 0x0001, 0x1078, 0x337e, 0x0c7e, 0x1078, 0x3518, 0x0040,
1154 0x336f, 0x6838, 0xc0fd, 0x683a, 0x6837, 0x0119, 0x6853, 0x0000,
1155 0x684f, 0x0020, 0x685b, 0x0001, 0x810b, 0x697e, 0x6883, 0x0000,
1156 0x6a86, 0x6b8a, 0x6c8e, 0x6d92, 0x6996, 0x689b, 0x0000, 0x0c7f,
1157 0x0d7f, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x6823, 0x0000,
1158 0x6804, 0x2068, 0x1078, 0x8ba1, 0x00c0, 0x336a, 0x2009, 0x0003,
1159 0x0078, 0x2b56, 0x7007, 0x0003, 0x701b, 0x3375, 0x007c, 0x0c7f,
1160 0x0d7f, 0x2009, 0x0002, 0x0078, 0x2b56, 0x6820, 0xa086, 0x8001,
1161 0x00c0, 0x2b2c, 0x2009, 0x0004, 0x0078, 0x2b56, 0x017e, 0x2008,
1162 0x2044, 0x8000, 0x204c, 0x8000, 0x290a, 0x8108, 0x280a, 0x8108,
1163 0x00f0, 0x3380, 0x017f, 0x007c, 0x017e, 0x0a7e, 0x0b7e, 0x2008,
1164 0x2044, 0x8000, 0x204c, 0x8000, 0x2054, 0x8000, 0x205c, 0x2b0a,
1165 0x8108, 0x2a0a, 0x8108, 0x290a, 0x8108, 0x280a, 0x0b7f, 0x0a7f,
1166 0x017f, 0x007c, 0x81ff, 0x0040, 0x33a9, 0x2009, 0x0001, 0x0078,
1167 0x2b56, 0x7924, 0x2140, 0xa18c, 0xff00, 0x810f, 0xa182, 0x0080,
1168 0x0048, 0x2b5a, 0xa182, 0x00ff, 0x00c8, 0x2b5a, 0x7a2c, 0x7b28,
1169 0x6068, 0xa306, 0x00c0, 0x33c4, 0x606c, 0xa24e, 0x0040, 0x2b5a,
1170 0xa9cc, 0xff00, 0x0040, 0x2b5a, 0x0c7e, 0x1078, 0x346d, 0x2c68,
1171 0x0c7f, 0x0040, 0x33fc, 0xa0c6, 0x4000, 0x00c0, 0x33e2, 0x0c7e,
1172 0x007e, 0x2d60, 0x2009, 0x0000, 0x1078, 0x47cb, 0x00c0, 0x33d9,
1173 0xc185, 0x6000, 0xd0bc, 0x0040, 0x33de, 0xc18d, 0x007f, 0x0c7f,
1174 0x0078, 0x33f9, 0xa0c6, 0x4007, 0x00c0, 0x33e9, 0x2408, 0x0078,
1175 0x33f9, 0xa0c6, 0x4008, 0x00c0, 0x33f1, 0x2708, 0x2610, 0x0078,
1176 0x33f9, 0xa0c6, 0x4009, 0x00c0, 0x33f7, 0x0078, 0x33f9, 0x2001,
1177 0x4006, 0x2020, 0x0078, 0x2b2e, 0x2d00, 0x7022, 0x017e, 0x0b7e,
1178 0x0c7e, 0x0e7e, 0x2c70, 0x1078, 0x74d7, 0x0040, 0x3442, 0x2d00,
1179 0x601a, 0x2001, 0xa356, 0x2004, 0xa084, 0x00ff, 0x6842, 0x2e58,
1180 0x0e7f, 0x0e7e, 0x0c7e, 0x1078, 0x3518, 0x0c7f, 0x2b70, 0x00c0,
1181 0x3423, 0x1078, 0x753d, 0x0e7f, 0x0c7f, 0x0b7f, 0x017f, 0x2009,
1182 0x0002, 0x0078, 0x2b56, 0x6837, 0x0000, 0x2d00, 0x6012, 0x6833,
1183 0x0000, 0x6838, 0xc0fd, 0x683a, 0x127e, 0x2091, 0x8000, 0x1078,
1184 0x2813, 0x127f, 0x601f, 0x0001, 0x2001, 0x0000, 0x1078, 0x442b,
1185 0x2001, 0x0002, 0x1078, 0x443f, 0x2009, 0x0002, 0x1078, 0x756c,
1186 0xa085, 0x0001, 0x0e7f, 0x0c7f, 0x0b7f, 0x017f, 0x00c0, 0x344c,
1187 0x2009, 0x0003, 0x0078, 0x2b56, 0x7007, 0x0003, 0x701b, 0x3451,
1188 0x007c, 0x6830, 0xa086, 0x0100, 0x7020, 0x2060, 0x00c0, 0x345f,
1189 0x2009, 0x0004, 0x6204, 0xa294, 0x00ff, 0x0078, 0x2b56, 0x2009,
1190 0x0000, 0x1078, 0x47cb, 0x00c0, 0x3466, 0xc185, 0x6000, 0xd0bc,
1191 0x0040, 0x346b, 0xc18d, 0x0078, 0x2b2c, 0x0e7e, 0x0d7e, 0x2029,
1192 0x0000, 0x2021, 0x0080, 0x20a9, 0x007f, 0x2071, 0xa4b4, 0x2e04,
1193 0xa005, 0x00c0, 0x3482, 0x2100, 0xa406, 0x00c0, 0x34b3, 0x2428,
1194 0x0078, 0x34b3, 0x2068, 0x6f10, 0x2700, 0xa306, 0x00c0, 0x34a4,
1195 0x6e14, 0x2600, 0xa206, 0x00c0, 0x34a4, 0x2400, 0xa106, 0x00c0,
1196 0x34a0, 0x2d60, 0xd884, 0x0040, 0x34c8, 0x6004, 0xa084, 0x00ff,
1197 0xa086, 0x0006, 0x00c0, 0x34c8, 0x2001, 0x4000, 0x0078, 0x34c9,
1198 0x2001, 0x4007, 0x0078, 0x34c9, 0x2400, 0xa106, 0x00c0, 0x34b3,
1199 0x6e14, 0x87ff, 0x00c0, 0x34af, 0x86ff, 0x0040, 0x347f, 0x2001,
1200 0x4008, 0x0078, 0x34c9, 0x8420, 0x8e70, 0x00f0, 0x3477, 0x85ff,
1201 0x00c0, 0x34c2, 0x2001, 0x4009, 0x0078, 0x34c9, 0x2001, 0x0001,
1202 0x0078, 0x34c9, 0x1078, 0x4499, 0x00c0, 0x34be, 0x6312, 0x6216,
1203 0xa006, 0xa005, 0x0d7f, 0x0e7f, 0x007c, 0x81ff, 0x00c0, 0x2b56,
1204 0x1078, 0x3518, 0x0040, 0x2b56, 0x6837, 0x0000, 0x6838, 0xc0fd,
1205 0x683a, 0x7824, 0xa005, 0x0040, 0x2b5a, 0xa096, 0x00ff, 0x0040,
1206 0x34e5, 0xa092, 0x0004, 0x00c8, 0x2b5a, 0x2010, 0x2d18, 0x1078,
1207 0x27c2, 0x0040, 0x2b56, 0x7007, 0x0003, 0x701b, 0x34f0, 0x007c,
1208 0x6830, 0xa086, 0x0100, 0x0040, 0x2b56, 0x0078, 0x2b2c, 0x7924,
1209 0xa18c, 0xff00, 0x810f, 0xa182, 0x0080, 0x0048, 0x2b5a, 0xa182,
1210 0x00ff, 0x00c8, 0x2b5a, 0x127e, 0x2091, 0x8000, 0x1078, 0x8a89,
1211 0x00c0, 0x3515, 0xa190, 0xa434, 0x2204, 0xa065, 0x0040, 0x3515,
1212 0x1078, 0x4235, 0x127f, 0x0078, 0x2b2c, 0x127f, 0x0078, 0x2b56,
1213 0x1078, 0x1381, 0x0040, 0x352f, 0xa006, 0x6802, 0x7010, 0xa005,
1214 0x00c0, 0x3527, 0x2d00, 0x7012, 0x7016, 0x0078, 0x352d, 0x7014,
1215 0x6802, 0x2060, 0x2d00, 0x6006, 0x7016, 0xad80, 0x000d, 0x007c,
1216 0x7924, 0x810f, 0xa18c, 0x00ff, 0x1078, 0x4501, 0x00c0, 0x353f,
1217 0x7e28, 0xa684, 0x3fff, 0xa082, 0x4000, 0x0048, 0x3540, 0xa066,
1218 0x8cff, 0x007c, 0x7e24, 0x860f, 0xa18c, 0x00ff, 0x1078, 0x4501,
1219 0x00c0, 0x3550, 0xa6b4, 0x00ff, 0xa682, 0x4000, 0x0048, 0x3551,
1220 0xa066, 0x8cff, 0x007c, 0x017e, 0x7110, 0x81ff, 0x0040, 0x355e,
1221 0x2168, 0x6904, 0x1078, 0x139a, 0x0078, 0x3555, 0x7112, 0x7116,
1222 0x017f, 0x007c, 0x2031, 0x0001, 0x0078, 0x3568, 0x2031, 0x0000,
1223 0x2061, 0xa3d1, 0x6606, 0x6112, 0x600e, 0x6226, 0x632a, 0x642e,
1224 0x6532, 0x2c10, 0x1078, 0x13d1, 0x7007, 0x0002, 0x701b, 0x2b2c,
1225 0x007c, 0x0f7e, 0x127e, 0x2091, 0x8000, 0x2079, 0x0000, 0x2001,
1226 0xa38f, 0x2004, 0xa005, 0x00c0, 0x3594, 0x0068, 0x3594, 0x7818,
1227 0xd084, 0x00c0, 0x3594, 0x7a22, 0x7b26, 0x7c2a, 0x781b, 0x0001,
1228 0x2091, 0x4080, 0x0078, 0x35b9, 0x017e, 0x0c7e, 0x0e7e, 0x2071,
1229 0xa381, 0x7138, 0xa182, 0x0008, 0x0048, 0x35a2, 0x7030, 0x2060,
1230 0x0078, 0x35b3, 0x7030, 0xa0e0, 0x0008, 0xac82, 0xa3d1, 0x0048,
1231 0x35ab, 0x2061, 0xa391, 0x2c00, 0x7032, 0x81ff, 0x00c0, 0x35b1,
1232 0x7036, 0x8108, 0x713a, 0x2262, 0x6306, 0x640a, 0x0e7f, 0x0c7f,
1233 0x017f, 0x127f, 0x0f7f, 0x007c, 0x0e7e, 0x2071, 0xa381, 0x7038,
1234 0xa005, 0x0040, 0x35f5, 0x127e, 0x2091, 0x8000, 0x0068, 0x35f4,
1235 0x0f7e, 0x2079, 0x0000, 0x7818, 0xd084, 0x00c0, 0x35f3, 0x0c7e,
1236 0x7034, 0x2060, 0x2c04, 0x7822, 0x6004, 0x7826, 0x6008, 0x782a,
1237 0x781b, 0x0001, 0x2091, 0x4080, 0x7038, 0x8001, 0x703a, 0xa005,
1238 0x00c0, 0x35e9, 0x7033, 0xa391, 0x7037, 0xa391, 0x0c7f, 0x0078,
1239 0x35f3, 0xac80, 0x0008, 0xa0fa, 0xa3d1, 0x0048, 0x35f1, 0x2001,
1240 0xa391, 0x7036, 0x0c7f, 0x0f7f, 0x127f, 0x0e7f, 0x007c, 0x027e,
1241 0x2001, 0xa352, 0x2004, 0xd0c4, 0x0040, 0x3602, 0x2011, 0x8014,
1242 0x1078, 0x3579, 0x027f, 0x007c, 0x81ff, 0x00c0, 0x2b56, 0x127e,
1243 0x2091, 0x8000, 0x6030, 0xc08d, 0xc085, 0xc0ac, 0x6032, 0x1078,
1244 0x4171, 0x127f, 0x0078, 0x2b2c, 0x7824, 0x2008, 0xa18c, 0xfffd,
1245 0x00c0, 0x361f, 0x61d4, 0xa10d, 0x61d6, 0x0078, 0x2b2c, 0x0078,
1246 0x2b5a, 0x81ff, 0x00c0, 0x2b56, 0x6000, 0xa086, 0x0003, 0x00c0,
1247 0x2b56, 0x2001, 0xa352, 0x2004, 0xd0ac, 0x00c0, 0x2b56, 0x1078,
1248 0x3542, 0x0040, 0x2b5a, 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006,
1249 0x00c0, 0x363e, 0x7828, 0xa005, 0x0040, 0x2b2c, 0x0c7e, 0x1078,
1250 0x3518, 0x0c7f, 0x0040, 0x2b56, 0x6837, 0x0000, 0x6833, 0x0000,
1251 0x6838, 0xc0fd, 0x683a, 0x1078, 0x8c4d, 0x0040, 0x2b56, 0x7007,
1252 0x0003, 0x701b, 0x3654, 0x007c, 0x6830, 0xa086, 0x0100, 0x0040,
1253 0x2b56, 0x0078, 0x2b2c, 0x2001, 0xa300, 0x2004, 0xa086, 0x0003,
1254 0x00c0, 0x2b56, 0x7f24, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x1078,
1255 0x3518, 0x0040, 0x2b56, 0x2009, 0x0000, 0x2031, 0x0000, 0x7023,
1256 0x0000, 0x702f, 0x0000, 0xad80, 0x0005, 0x7026, 0x20a0, 0x1078,
1257 0x4501, 0x00c0, 0x36d8, 0x6004, 0xa0c4, 0x00ff, 0xa8c6, 0x0006,
1258 0x0040, 0x3688, 0xa0c4, 0xff00, 0xa8c6, 0x0600, 0x00c0, 0x36d8,
1259 0x2001, 0xa352, 0x2004, 0xd0ac, 0x00c0, 0x3695, 0x1078, 0x47cb,
1260 0x00c0, 0x3695, 0xd79c, 0x0040, 0x36d8, 0xd794, 0x00c0, 0x369b,
1261 0xd784, 0x0040, 0x36a7, 0xac80, 0x0006, 0x2098, 0x3400, 0x20a9,
1262 0x0004, 0x53a3, 0x1078, 0x338c, 0xd794, 0x0040, 0x36b0, 0xac80,
1263 0x000a, 0x2098, 0x3400, 0x20a9, 0x0004, 0x53a3, 0x1078, 0x338c,
1264 0x21a2, 0xd794, 0x0040, 0x36d0, 0xac80, 0x0000, 0x2098, 0x94a0,
1265 0x20a9, 0x0002, 0x53a3, 0xac80, 0x0003, 0x20a6, 0x94a0, 0xac80,
1266 0x0004, 0x2098, 0x3400, 0x20a9, 0x0002, 0x53a3, 0x1078, 0x337e,
1267 0xac80, 0x0026, 0x2098, 0x20a9, 0x0002, 0x53a3, 0x0078, 0x36d1,
1268 0x94a0, 0xd794, 0x0040, 0x36d6, 0xa6b0, 0x000b, 0xa6b0, 0x0005,
1269 0x8108, 0xd78c, 0x0040, 0x36e2, 0xa186, 0x0100, 0x0040, 0x36f3,
1270 0x0078, 0x36e6, 0xa186, 0x007e, 0x0040, 0x36f3, 0xd794, 0x0040,
1271 0x36ed, 0xa686, 0x0020, 0x0078, 0x36ef, 0xa686, 0x0028, 0x0040,
1272 0x36fc, 0x0078, 0x3677, 0x86ff, 0x00c0, 0x36fa, 0x7120, 0x810b,
1273 0x0078, 0x2b2c, 0x702f, 0x0001, 0x711e, 0x7020, 0xa600, 0x7022,
1274 0x772a, 0x2061, 0xa3d1, 0x6007, 0x0000, 0x6612, 0x7024, 0x600e,
1275 0x6226, 0x632a, 0x642e, 0x6532, 0x2c10, 0x1078, 0x13d1, 0x7007,
1276 0x0002, 0x701b, 0x3714, 0x007c, 0x702c, 0xa005, 0x00c0, 0x3726,
1277 0x711c, 0x7024, 0x20a0, 0x7728, 0x2031, 0x0000, 0x2061, 0xa3d1,
1278 0x6224, 0x6328, 0x642c, 0x6530, 0x0078, 0x3677, 0x7120, 0x810b,
1279 0x0078, 0x2b2c, 0x2029, 0x007e, 0x7924, 0x7a28, 0x7b2c, 0x7c38,
1280 0xa184, 0xff00, 0x8007, 0xa0e2, 0x0020, 0x0048, 0x2b5a, 0xa502,
1281 0x0048, 0x2b5a, 0xa184, 0x00ff, 0xa0e2, 0x0020, 0x0048, 0x2b5a,
1282 0xa502, 0x0048, 0x2b5a, 0xa284, 0xff00, 0x8007, 0xa0e2, 0x0020,
1283 0x0048, 0x2b5a, 0xa502, 0x0048, 0x2b5a, 0xa284, 0x00ff, 0xa0e2,
1284 0x0020, 0x0048, 0x2b5a, 0xa502, 0x0048, 0x2b5a, 0xa384, 0xff00,
1285 0x8007, 0xa0e2, 0x0020, 0x0048, 0x2b5a, 0xa502, 0x0048, 0x2b5a,
1286 0xa384, 0x00ff, 0xa0e2, 0x0020, 0x0048, 0x2b5a, 0xa502, 0x0048,
1287 0x2b5a, 0xa484, 0xff00, 0x8007, 0xa0e2, 0x0020, 0x0048, 0x2b5a,
1288 0xa502, 0x0048, 0x2b5a, 0xa484, 0x00ff, 0xa0e2, 0x0020, 0x0048,
1289 0x2b5a, 0xa502, 0x0048, 0x2b5a, 0x2061, 0xa5a3, 0x6102, 0x6206,
1290 0x630a, 0x640e, 0x0078, 0x2b2c, 0x007e, 0x2001, 0xa352, 0x2004,
1291 0xd0cc, 0x007f, 0x007c, 0x007e, 0x2001, 0xa371, 0x2004, 0xd0bc,
1292 0x007f, 0x007c, 0x6160, 0x7a24, 0x6300, 0x82ff, 0x00c0, 0x379b,
1293 0x7926, 0x0078, 0x2b2c, 0x83ff, 0x00c0, 0x2b5a, 0x2001, 0xfff0,
1294 0xa200, 0x00c8, 0x2b5a, 0x2019, 0xffff, 0x6064, 0xa302, 0xa200,
1295 0x0048, 0x2b5a, 0x7926, 0x6262, 0x0078, 0x2b2c, 0x2001, 0xa300,
1296 0x2004, 0xa086, 0x0003, 0x00c0, 0x2b56, 0x7c28, 0x7d24, 0x7e38,
1297 0x7f2c, 0x1078, 0x3518, 0x0040, 0x2b56, 0x2009, 0x0000, 0x2019,
1298 0x0000, 0x7023, 0x0000, 0x702f, 0x0000, 0xad80, 0x0003, 0x7026,
1299 0x20a0, 0xa1e0, 0xa434, 0x2c64, 0x8cff, 0x0040, 0x37e8, 0x6004,
1300 0xa084, 0x00ff, 0xa086, 0x0006, 0x0040, 0x37dd, 0x6004, 0xa084,
1301 0xff00, 0xa086, 0x0600, 0x00c0, 0x37e8, 0x6014, 0x20a2, 0x94a0,
1302 0x6010, 0x8007, 0xa105, 0x8007, 0x20a2, 0x94a0, 0xa398, 0x0002,
1303 0x8108, 0xa182, 0x00ff, 0x0040, 0x37f3, 0xa386, 0x002a, 0x0040,
1304 0x37fc, 0x0078, 0x37c9, 0x83ff, 0x00c0, 0x37fa, 0x7120, 0x810c,
1305 0x0078, 0x2b2c, 0x702f, 0x0001, 0x711e, 0x7020, 0xa300, 0x7022,
1306 0x2061, 0xa3d1, 0x6007, 0x0000, 0x6312, 0x7024, 0x600e, 0x6426,
1307 0x652a, 0x662e, 0x6732, 0x2c10, 0x1078, 0x13d1, 0x7007, 0x0002,
1308 0x701b, 0x3813, 0x007c, 0x702c, 0xa005, 0x00c0, 0x3824, 0x711c,
1309 0x7024, 0x20a0, 0x2019, 0x0000, 0x2061, 0xa3d1, 0x6424, 0x6528,
1310 0x662c, 0x6730, 0x0078, 0x37c9, 0x7120, 0x810c, 0x0078, 0x2b2c,
1311 0x81ff, 0x00c0, 0x2b56, 0x60c8, 0xd09c, 0x0040, 0x2b56, 0x1078,
1312 0x3518, 0x0040, 0x2b56, 0x7924, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38,
1313 0x1078, 0x3562, 0x701b, 0x383d, 0x007c, 0x0d7e, 0xade8, 0x000d,
1314 0x6828, 0xa0be, 0x7000, 0x0040, 0x3850, 0xa0be, 0x7100, 0x0040,
1315 0x3850, 0xa0be, 0x7200, 0x0040, 0x3850, 0x0d7f, 0x0078, 0x2b5a,
1316 0x6820, 0x6924, 0x1078, 0x24e3, 0x00c0, 0x387b, 0x1078, 0x4499,
1317 0x00c0, 0x387b, 0x7122, 0x6612, 0x6516, 0x6e18, 0x0c7e, 0x1078,
1318 0x3518, 0x0040, 0x387b, 0x1078, 0x3518, 0x0040, 0x387b, 0x0c7f,
1319 0x0d7f, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x6823, 0x0000,
1320 0x6804, 0x2068, 0x1078, 0x8bbd, 0x0040, 0x2b56, 0x7007, 0x0003,
1321 0x701b, 0x387e, 0x007c, 0x0d7f, 0x0078, 0x2b56, 0x7120, 0x1078,
1322 0x2921, 0x6820, 0xa086, 0x8001, 0x0040, 0x2b56, 0x2d00, 0x701e,
1323 0x6804, 0xa080, 0x0002, 0x007e, 0x20a9, 0x002a, 0x2098, 0x20a0,
1324 0x1078, 0x41be, 0x007f, 0xade8, 0x000d, 0x6a08, 0x6b0c, 0x6c10,
1325 0x6d14, 0x2061, 0xa3d1, 0x6007, 0x0000, 0x6e00, 0x6f28, 0xa7c6,
1326 0x7000, 0x00c0, 0x38a5, 0x0078, 0x38a9, 0xa7c6, 0x7100, 0x00c0,
1327 0x38b1, 0xa6c2, 0x0004, 0x0048, 0x2b5a, 0x2009, 0x0004, 0x0078,
1328 0x3566, 0xa7c6, 0x7200, 0x00c0, 0x2b5a, 0xa6c2, 0x0054, 0x0048,
1329 0x2b5a, 0x600e, 0x6013, 0x002a, 0x6226, 0x632a, 0x642e, 0x6532,
1330 0x2c10, 0x1078, 0x13d1, 0x7007, 0x0002, 0x701b, 0x38c8, 0x007c,
1331 0x701c, 0x2068, 0x6804, 0xa080, 0x0001, 0x2004, 0xa080, 0x0002,
1332 0x007e, 0x20a9, 0x002a, 0x2098, 0x20a0, 0x1078, 0x41be, 0x007f,
1333 0x2009, 0x002a, 0x2061, 0xa3d1, 0x6224, 0x6328, 0x642c, 0x6530,
1334 0x0078, 0x3566, 0x81ff, 0x00c0, 0x2b56, 0x1078, 0x3530, 0x0040,
1335 0x2b5a, 0x1078, 0x45a7, 0x0040, 0x2b56, 0x1078, 0x4710, 0x0078,
1336 0x2b2c, 0x7824, 0xd084, 0x0040, 0x3150, 0x1078, 0x3542, 0x0040,
1337 0x2b5a, 0x0c7e, 0x1078, 0x3518, 0x0c7f, 0x00c0, 0x3903, 0x2009,
1338 0x0002, 0x0078, 0x2b56, 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006,
1339 0x0040, 0x3910, 0xa08e, 0x0004, 0x0040, 0x3910, 0xa08e, 0x0005,
1340 0x00c0, 0x3934, 0x2001, 0xa352, 0x2004, 0xd0b4, 0x0040, 0x3185,
1341 0x6000, 0xd08c, 0x00c0, 0x3185, 0x6837, 0x0000, 0x6838, 0xc0fd,
1342 0x683a, 0x1078, 0x8bd9, 0x00c0, 0x3929, 0x2009, 0x0003, 0x0078,
1343 0x2b56, 0x7007, 0x0003, 0x701b, 0x392e, 0x007c, 0x1078, 0x3542,
1344 0x0040, 0x2b5a, 0x0078, 0x3185, 0x2009, 0xa32e, 0x210c, 0x81ff,
1345 0x0040, 0x393e, 0x2009, 0x0001, 0x0078, 0x2b56, 0x2001, 0xa300,
1346 0x2004, 0xa086, 0x0003, 0x0040, 0x3949, 0x2009, 0x0007, 0x0078,
1347 0x2b56, 0x2001, 0xa352, 0x2004, 0xd0ac, 0x0040, 0x3953, 0x2009,
1348 0x0008, 0x0078, 0x2b56, 0x609c, 0xd0a4, 0x00c0, 0x395a, 0xd0ac,
1349 0x00c0, 0x3185, 0x6837, 0x0000, 0x6833, 0x0000, 0x6838, 0xc0fd,
1350 0x683a, 0x1078, 0x8c4d, 0x00c0, 0x3969, 0x2009, 0x0003, 0x0078,
1351 0x2b56, 0x7007, 0x0003, 0x701b, 0x396e, 0x007c, 0x6830, 0xa086,
1352 0x0100, 0x00c0, 0x3977, 0x2009, 0x0004, 0x0078, 0x2b56, 0x1078,
1353 0x3542, 0x0040, 0x2b5a, 0x0078, 0x3912, 0x81ff, 0x2009, 0x0001,
1354 0x00c0, 0x2b56, 0x6000, 0xa086, 0x0003, 0x2009, 0x0007, 0x00c0,
1355 0x2b56, 0x2001, 0xa352, 0x2004, 0xd0ac, 0x2009, 0x0008, 0x00c0,
1356 0x2b56, 0x1078, 0x3542, 0x0040, 0x2b5a, 0x6004, 0xa084, 0x00ff,
1357 0xa086, 0x0006, 0x2009, 0x0009, 0x00c0, 0x2b56, 0x0c7e, 0x1078,
1358 0x3518, 0x0c7f, 0x2009, 0x0002, 0x0040, 0x2b56, 0x6837, 0x0000,
1359 0x6833, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x7928, 0xa194, 0xff00,
1360 0xa18c, 0x00ff, 0xa006, 0x82ff, 0x00c0, 0x39bc, 0xc0ed, 0x6952,
1361 0x792c, 0x6956, 0x0078, 0x39c5, 0xa28e, 0x0100, 0x00c0, 0x2b5a,
1362 0xc0e5, 0x6853, 0x0000, 0x6857, 0x0000, 0x683e, 0x1078, 0x8df6,
1363 0x2009, 0x0003, 0x0040, 0x2b56, 0x7007, 0x0003, 0x701b, 0x39d1,
1364 0x007c, 0x6830, 0xa086, 0x0100, 0x2009, 0x0004, 0x0040, 0x2b56,
1365 0x0078, 0x2b2c, 0x81ff, 0x2009, 0x0001, 0x00c0, 0x2b56, 0x6000,
1366 0xa086, 0x0003, 0x2009, 0x0007, 0x00c0, 0x2b56, 0x1078, 0x3542,
1367 0x0040, 0x2b5a, 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x2009,
1368 0x0009, 0x00c0, 0x2b56, 0x0c7e, 0x1078, 0x3518, 0x0c7f, 0x2009,
1369 0x0002, 0x0040, 0x2b56, 0xad80, 0x000f, 0x2009, 0x0008, 0x7a2c,
1370 0x7b28, 0x7c3c, 0x7d38, 0x1078, 0x3562, 0x701b, 0x3a08, 0x007c,
1371 0x0d7e, 0xade8, 0x000f, 0x6800, 0xa086, 0x0500, 0x00c0, 0x3a1b,
1372 0x6804, 0xa005, 0x00c0, 0x3a1b, 0x6808, 0xa084, 0xff00, 0x00c0,
1373 0x3a1b, 0x0078, 0x3a1e, 0x0d7f, 0x00c0, 0x2b5a, 0x0d7f, 0x6837,
1374 0x0000, 0x6833, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x0c7e, 0x1078,
1375 0x3542, 0x00c0, 0x3a2e, 0x0c7f, 0x0078, 0x2b5a, 0x1078, 0x8e52,
1376 0x2009, 0x0003, 0x0c7f, 0x0040, 0x2b56, 0x7007, 0x0003, 0x701b,
1377 0x3a3a, 0x007c, 0x6830, 0xa086, 0x0100, 0x2009, 0x0004, 0x0040,
1378 0x2b56, 0x0078, 0x2b2c, 0x127e, 0x0c7e, 0x0e7e, 0x2061, 0x0100,
1379 0x2071, 0xa300, 0x6044, 0xd0a4, 0x00c0, 0x3a6c, 0xd084, 0x0040,
1380 0x3a55, 0x1078, 0x3bcc, 0x0078, 0x3a68, 0xd08c, 0x0040, 0x3a5c,
1381 0x1078, 0x3ae3, 0x0078, 0x3a68, 0xd094, 0x0040, 0x3a63, 0x1078,
1382 0x3ab7, 0x0078, 0x3a68, 0xd09c, 0x0040, 0x3a68, 0x1078, 0x3a76,
1383 0x0e7f, 0x0c7f, 0x127f, 0x007c, 0x017e, 0x6128, 0xd19c, 0x00c0,
1384 0x3a73, 0xc19d, 0x612a, 0x017f, 0x0078, 0x3a68, 0x624c, 0xa286,
1385 0xf0f0, 0x00c0, 0x3a87, 0x6048, 0xa086, 0xf0f0, 0x0040, 0x3a87,
1386 0x624a, 0x6043, 0x0090, 0x6043, 0x0010, 0x0078, 0x3ab6, 0xa294,
1387 0xff00, 0xa296, 0xf700, 0x0040, 0x3a9c, 0x7134, 0xd1a4, 0x00c0,
1388 0x3a9c, 0x6240, 0xa294, 0x0010, 0x0040, 0x3a9c, 0x2009, 0x00f7,
1389 0x1078, 0x41de, 0x0078, 0x3ab6, 0x6043, 0x0040, 0x6043, 0x0000,
1390 0x7073, 0x0000, 0x708b, 0x0001, 0x70af, 0x0000, 0x70cb, 0x0000,
1391 0x2009, 0xa9c0, 0x200b, 0x0000, 0x7083, 0x0000, 0x7077, 0x000f,
1392 0x2009, 0x000f, 0x2011, 0x4122, 0x1078, 0x596c, 0x007c, 0x157e,
1393 0x7074, 0xa005, 0x00c0, 0x3ae1, 0x2011, 0x4122, 0x1078, 0x58d4,
1394 0x6040, 0xa094, 0x0010, 0xa285, 0x0020, 0x6042, 0x20a9, 0x00c8,
1395 0x6044, 0xd08c, 0x00c0, 0x3ada, 0x00f0, 0x3ac8, 0x6242, 0x7087,
1396 0x0000, 0x6040, 0xa094, 0x0010, 0xa285, 0x0080, 0x6042, 0x6242,
1397 0x0078, 0x3ae1, 0x6242, 0x7087, 0x0000, 0x707b, 0x0000, 0x0078,
1398 0x3ae1, 0x157f, 0x007c, 0x7078, 0xa08a, 0x0003, 0x00c8, 0x3aec,
1399 0x1079, 0x3aef, 0x0078, 0x3aee, 0x1078, 0x1328, 0x007c, 0x3af2,
1400 0x3b41, 0x3bcb, 0x0f7e, 0x707b, 0x0001, 0x20e1, 0xa000, 0x20e1,
1401 0x8700, 0x1078, 0x218b, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2079,
1402 0xa800, 0x207b, 0x2200, 0x7807, 0x00ef, 0x780b, 0x0000, 0x780f,
1403 0x00ef, 0x7813, 0x0138, 0x7817, 0x0000, 0x781b, 0x0000, 0x781f,
1404 0x0000, 0x7823, 0xffff, 0x7827, 0xffff, 0x782b, 0x0000, 0x782f,
1405 0x0000, 0x2079, 0xa80c, 0x207b, 0x1101, 0x7807, 0x0000, 0x2099,
1406 0xa305, 0x20a1, 0xa80e, 0x20a9, 0x0004, 0x53a3, 0x2079, 0xa812,
1407 0x207b, 0x0000, 0x7807, 0x0000, 0x2099, 0xa800, 0x20a1, 0x020b,
1408 0x20a9, 0x0014, 0x53a6, 0x60c3, 0x000c, 0x600f, 0x0000, 0x1078,
1409 0x4158, 0x0f7f, 0x707f, 0x0000, 0x6043, 0x0008, 0x6043, 0x0000,
1410 0x007c, 0x0d7e, 0x707c, 0x707f, 0x0000, 0xa025, 0x0040, 0x3bb5,
1411 0x6020, 0xd0b4, 0x00c0, 0x3bb3, 0x7188, 0x81ff, 0x0040, 0x3ba2,
1412 0xa486, 0x000c, 0x00c0, 0x3bad, 0xa480, 0x0018, 0x8004, 0x20a8,
1413 0x2011, 0xa880, 0x2019, 0xa800, 0x220c, 0x2304, 0xa106, 0x00c0,
1414 0x3b79, 0x8210, 0x8318, 0x00f0, 0x3b5c, 0x6043, 0x0004, 0x608b,
1415 0xbc94, 0x608f, 0xf0f0, 0x6043, 0x0006, 0x707b, 0x0002, 0x7087,
1416 0x0002, 0x2009, 0x07d0, 0x2011, 0x4129, 0x1078, 0x596c, 0x0078,
1417 0x3bb3, 0x2069, 0xa880, 0x6930, 0xa18e, 0x1101, 0x00c0, 0x3bad,
1418 0x6834, 0xa005, 0x00c0, 0x3bad, 0x6900, 0xa18c, 0x00ff, 0x00c0,
1419 0x3b8d, 0x6804, 0xa005, 0x0040, 0x3ba2, 0x2011, 0xa88e, 0x2019,
1420 0xa305, 0x20a9, 0x0004, 0x220c, 0x2304, 0xa102, 0x0048, 0x3ba0,
1421 0x00c0, 0x3bad, 0x8210, 0x8318, 0x00f0, 0x3b93, 0x0078, 0x3bad,
1422 0x708b, 0x0000, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2099, 0xa880,
1423 0x20a1, 0x020b, 0x20a9, 0x0014, 0x53a6, 0x6043, 0x0008, 0x6043,
1424 0x0000, 0x0078, 0x3bb5, 0x0d7f, 0x007c, 0x6020, 0xd0b4, 0x00c0,
1425 0x3bb3, 0x60c3, 0x000c, 0x2011, 0xa5b5, 0x2013, 0x0000, 0x707f,
1426 0x0000, 0x20e1, 0x9080, 0x60a3, 0x0056, 0x60a7, 0x9575, 0x1078,
1427 0x6c38, 0x0078, 0x3bb3, 0x007c, 0x7084, 0xa08a, 0x001d, 0x00c8,
1428 0x3bd5, 0x1079, 0x3bd8, 0x0078, 0x3bd7, 0x1078, 0x1328, 0x007c,
1429 0x3c02, 0x3c11, 0x3c40, 0x3c59, 0x3c85, 0x3cb1, 0x3cdd, 0x3d13,
1430 0x3d3f, 0x3d67, 0x3daa, 0x3dd4, 0x3df6, 0x3e0c, 0x3e32, 0x3e45,
1431 0x3e4e, 0x3e7e, 0x3eaa, 0x3ed6, 0x3f02, 0x3f38, 0x3f7d, 0x3fac,
1432 0x3fce, 0x4010, 0x4036, 0x404f, 0x4050, 0x0c7e, 0x2061, 0xa300,
1433 0x6003, 0x0007, 0x2061, 0x0100, 0x6004, 0xa084, 0xfff9, 0x6006,
1434 0x0c7f, 0x007c, 0x608b, 0xbc94, 0x608f, 0xf0f0, 0x6043, 0x0002,
1435 0x7087, 0x0001, 0x2009, 0x07d0, 0x2011, 0x4129, 0x1078, 0x596c,
1436 0x007c, 0x0f7e, 0x707c, 0xa086, 0x0014, 0x00c0, 0x3c3e, 0x6043,
1437 0x0000, 0x6020, 0xd0b4, 0x00c0, 0x3c3e, 0x2079, 0xa880, 0x7a30,
1438 0xa296, 0x1102, 0x00c0, 0x3c3c, 0x7834, 0xa005, 0x00c0, 0x3c3c,
1439 0x7a38, 0xd2fc, 0x0040, 0x3c32, 0x70ac, 0xa005, 0x00c0, 0x3c32,
1440 0x70af, 0x0001, 0x2011, 0x4129, 0x1078, 0x58d4, 0x7087, 0x0010,
1441 0x1078, 0x3e4e, 0x0078, 0x3c3e, 0x1078, 0x4171, 0x0f7f, 0x007c,
1442 0x7087, 0x0003, 0x6043, 0x0004, 0x2011, 0x4129, 0x1078, 0x58d4,
1443 0x1078, 0x41c6, 0x20a3, 0x1102, 0x20a3, 0x0000, 0x20a9, 0x000a,
1444 0x20a3, 0x0000, 0x00f0, 0x3c50, 0x60c3, 0x0014, 0x1078, 0x4158,
1445 0x007c, 0x0f7e, 0x707c, 0xa005, 0x0040, 0x3c83, 0x2011, 0x4129,
1446 0x1078, 0x58d4, 0xa086, 0x0014, 0x00c0, 0x3c81, 0x2079, 0xa880,
1447 0x7a30, 0xa296, 0x1102, 0x00c0, 0x3c81, 0x7834, 0xa005, 0x00c0,
1448 0x3c81, 0x7a38, 0xd2fc, 0x0040, 0x3c7b, 0x70ac, 0xa005, 0x00c0,
1449 0x3c7b, 0x70af, 0x0001, 0x7087, 0x0004, 0x1078, 0x3c85, 0x0078,
1450 0x3c83, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x7087, 0x0005, 0x1078,
1451 0x41c6, 0x20a3, 0x1103, 0x20a3, 0x0000, 0x3430, 0x2011, 0xa88e,
1452 0x1078, 0x4211, 0x00c0, 0x3ca3, 0x7070, 0xa005, 0x00c0, 0x3ca3,
1453 0x714c, 0xa186, 0xffff, 0x0040, 0x3ca3, 0x1078, 0x40ea, 0x0040,
1454 0x3ca3, 0x1078, 0x41f5, 0x20a9, 0x0008, 0x2298, 0x26a0, 0x53a6,
1455 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014, 0x1078, 0x4158,
1456 0x007c, 0x0f7e, 0x707c, 0xa005, 0x0040, 0x3cdb, 0x2011, 0x4129,
1457 0x1078, 0x58d4, 0xa086, 0x0014, 0x00c0, 0x3cd9, 0x2079, 0xa880,
1458 0x7a30, 0xa296, 0x1103, 0x00c0, 0x3cd9, 0x7834, 0xa005, 0x00c0,
1459 0x3cd9, 0x7a38, 0xd2fc, 0x0040, 0x3cd3, 0x70ac, 0xa005, 0x00c0,
1460 0x3cd3, 0x70af, 0x0001, 0x7087, 0x0006, 0x1078, 0x3cdd, 0x0078,
1461 0x3cdb, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x7087, 0x0007, 0x1078,
1462 0x41c6, 0x20a3, 0x1104, 0x20a3, 0x0000, 0x3430, 0x2011, 0xa88e,
1463 0x1078, 0x4211, 0x00c0, 0x3d05, 0x7070, 0xa005, 0x00c0, 0x3d05,
1464 0x7150, 0xa186, 0xffff, 0x0040, 0x3d05, 0xa180, 0x293f, 0x200c,
1465 0xa18c, 0xff00, 0x810f, 0x1078, 0x40ea, 0x0040, 0x3d05, 0x1078,
1466 0x378b, 0x0040, 0x3d05, 0x1078, 0x2500, 0x20a9, 0x0008, 0x2298,
1467 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014,
1468 0x1078, 0x4158, 0x007c, 0x0f7e, 0x707c, 0xa005, 0x0040, 0x3d3d,
1469 0x2011, 0x4129, 0x1078, 0x58d4, 0xa086, 0x0014, 0x00c0, 0x3d3b,
1470 0x2079, 0xa880, 0x7a30, 0xa296, 0x1104, 0x00c0, 0x3d3b, 0x7834,
1471 0xa005, 0x00c0, 0x3d3b, 0x7a38, 0xd2fc, 0x0040, 0x3d35, 0x70ac,
1472 0xa005, 0x00c0, 0x3d35, 0x70af, 0x0001, 0x7087, 0x0008, 0x1078,
1473 0x3d3f, 0x0078, 0x3d3d, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x7087,
1474 0x0009, 0x1078, 0x41c6, 0x20a3, 0x1105, 0x20a3, 0x0100, 0x3430,
1475 0x1078, 0x4211, 0x00c0, 0x3d58, 0x7070, 0xa005, 0x00c0, 0x3d58,
1476 0x1078, 0x4051, 0x00c0, 0x3d62, 0xa085, 0x0001, 0x1078, 0x2500,
1477 0x20a9, 0x0008, 0x2099, 0xa88e, 0x26a0, 0x53a6, 0x20a3, 0x0000,
1478 0x20a3, 0x0000, 0x60c3, 0x0014, 0x1078, 0x4158, 0x007c, 0x0f7e,
1479 0x707c, 0xa005, 0x0040, 0x3da8, 0x2011, 0x4129, 0x1078, 0x58d4,
1480 0xa086, 0x0014, 0x00c0, 0x3da6, 0x2079, 0xa880, 0x7a30, 0xa296,
1481 0x1105, 0x00c0, 0x3da6, 0x7834, 0x2011, 0x0100, 0xa21e, 0x00c0,
1482 0x3d91, 0x7a38, 0xd2fc, 0x0040, 0x3d8b, 0x70ac, 0xa005, 0x00c0,
1483 0x3d8b, 0x70af, 0x0001, 0x7087, 0x000a, 0x1078, 0x3daa, 0x0078,
1484 0x3da8, 0xa005, 0x00c0, 0x3da6, 0x7a38, 0xd2fc, 0x0040, 0x3d9e,
1485 0x70ac, 0xa005, 0x00c0, 0x3d9e, 0x70af, 0x0001, 0x7083, 0x0000,
1486 0x7087, 0x000e, 0x1078, 0x3e32, 0x0078, 0x3da8, 0x1078, 0x4171,
1487 0x0f7f, 0x007c, 0x7087, 0x000b, 0x2011, 0xa80e, 0x22a0, 0x20a9,
1488 0x0040, 0x2019, 0xffff, 0x43a4, 0x20a9, 0x0002, 0x2009, 0x0000,
1489 0x41a4, 0x1078, 0x41c6, 0x20a3, 0x1106, 0x20a3, 0x0000, 0x1078,
1490 0x4211, 0x0040, 0x3dc7, 0x2013, 0x0000, 0x0078, 0x3dcb, 0x6030,
1491 0xa085, 0x0100, 0x2012, 0x2298, 0x20a9, 0x0042, 0x53a6, 0x60c3,
1492 0x0084, 0x1078, 0x4158, 0x007c, 0x0f7e, 0x707c, 0xa005, 0x0040,
1493 0x3df4, 0x2011, 0x4129, 0x1078, 0x58d4, 0xa086, 0x0084, 0x00c0,
1494 0x3df2, 0x2079, 0xa880, 0x7a30, 0xa296, 0x1106, 0x00c0, 0x3df2,
1495 0x7834, 0xa005, 0x00c0, 0x3df2, 0x7087, 0x000c, 0x1078, 0x3df6,
1496 0x0078, 0x3df4, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x7087, 0x000d,
1497 0x1078, 0x41c6, 0x20a3, 0x1107, 0x20a3, 0x0000, 0x2099, 0xa88e,
1498 0x20a9, 0x0040, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3,
1499 0x0084, 0x1078, 0x4158, 0x007c, 0x0f7e, 0x707c, 0xa005, 0x0040,
1500 0x3e30, 0x2011, 0x4129, 0x1078, 0x58d4, 0xa086, 0x0084, 0x00c0,
1501 0x3e2e, 0x2079, 0xa880, 0x7a30, 0xa296, 0x1107, 0x00c0, 0x3e2e,
1502 0x7834, 0xa005, 0x00c0, 0x3e2e, 0x7083, 0x0001, 0x1078, 0x41b8,
1503 0x7087, 0x000e, 0x1078, 0x3e32, 0x0078, 0x3e30, 0x1078, 0x4171,
1504 0x0f7f, 0x007c, 0x7087, 0x000f, 0x707f, 0x0000, 0x608b, 0xbc85,
1505 0x608f, 0xb5b5, 0x6043, 0x0005, 0x6043, 0x0004, 0x2009, 0x07d0,
1506 0x2011, 0x4129, 0x1078, 0x58c7, 0x007c, 0x707c, 0xa005, 0x0040,
1507 0x3e4d, 0x2011, 0x4129, 0x1078, 0x58d4, 0x007c, 0x7087, 0x0011,
1508 0x1078, 0x4211, 0x00c0, 0x3e67, 0x7168, 0x81ff, 0x0040, 0x3e67,
1509 0x2009, 0x0000, 0x706c, 0xa084, 0x00ff, 0x1078, 0x24e3, 0xa186,
1510 0x0080, 0x0040, 0x3e67, 0x2011, 0xa88e, 0x1078, 0x40ea, 0x20e1,
1511 0x9080, 0x20e1, 0x4000, 0x2099, 0xa880, 0x20a1, 0x020b, 0x747c,
1512 0xa480, 0x0018, 0xa080, 0x0007, 0xa084, 0x03f8, 0x8004, 0x20a8,
1513 0x53a6, 0x60c3, 0x0014, 0x1078, 0x4158, 0x007c, 0x0f7e, 0x707c,
1514 0xa005, 0x0040, 0x3ea8, 0x2011, 0x4129, 0x1078, 0x58d4, 0xa086,
1515 0x0014, 0x00c0, 0x3ea6, 0x2079, 0xa880, 0x7a30, 0xa296, 0x1103,
1516 0x00c0, 0x3ea6, 0x7834, 0xa005, 0x00c0, 0x3ea6, 0x7a38, 0xd2fc,
1517 0x0040, 0x3ea0, 0x70ac, 0xa005, 0x00c0, 0x3ea0, 0x70af, 0x0001,
1518 0x7087, 0x0012, 0x1078, 0x3eaa, 0x0078, 0x3ea8, 0x1078, 0x4171,
1519 0x0f7f, 0x007c, 0x7087, 0x0013, 0x1078, 0x41d2, 0x20a3, 0x1103,
1520 0x20a3, 0x0000, 0x3430, 0x2011, 0xa88e, 0x1078, 0x4211, 0x00c0,
1521 0x3ec8, 0x7070, 0xa005, 0x00c0, 0x3ec8, 0x714c, 0xa186, 0xffff,
1522 0x0040, 0x3ec8, 0x1078, 0x40ea, 0x0040, 0x3ec8, 0x1078, 0x41f5,
1523 0x20a9, 0x0008, 0x2298, 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3,
1524 0x0000, 0x60c3, 0x0014, 0x1078, 0x4158, 0x007c, 0x0f7e, 0x707c,
1525 0xa005, 0x0040, 0x3f00, 0x2011, 0x4129, 0x1078, 0x58d4, 0xa086,
1526 0x0014, 0x00c0, 0x3efe, 0x2079, 0xa880, 0x7a30, 0xa296, 0x1104,
1527 0x00c0, 0x3efe, 0x7834, 0xa005, 0x00c0, 0x3efe, 0x7a38, 0xd2fc,
1528 0x0040, 0x3ef8, 0x70ac, 0xa005, 0x00c0, 0x3ef8, 0x70af, 0x0001,
1529 0x7087, 0x0014, 0x1078, 0x3f02, 0x0078, 0x3f00, 0x1078, 0x4171,
1530 0x0f7f, 0x007c, 0x7087, 0x0015, 0x1078, 0x41d2, 0x20a3, 0x1104,
1531 0x20a3, 0x0000, 0x3430, 0x2011, 0xa88e, 0x1078, 0x4211, 0x00c0,
1532 0x3f2a, 0x7070, 0xa005, 0x00c0, 0x3f2a, 0x7150, 0xa186, 0xffff,
1533 0x0040, 0x3f2a, 0xa180, 0x293f, 0x200c, 0xa18c, 0xff00, 0x810f,
1534 0x1078, 0x40ea, 0x0040, 0x3f2a, 0x1078, 0x378b, 0x0040, 0x3f2a,
1535 0x1078, 0x2500, 0x20a9, 0x0008, 0x2298, 0x26a0, 0x53a6, 0x20a3,
1536 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014, 0x1078, 0x4158, 0x007c,
1537 0x0f7e, 0x707c, 0xa005, 0x0040, 0x3f7b, 0x2011, 0x4129, 0x1078,
1538 0x58d4, 0xa086, 0x0014, 0x00c0, 0x3f79, 0x2079, 0xa880, 0x7a30,
1539 0xa296, 0x1105, 0x00c0, 0x3f79, 0x7834, 0x2011, 0x0100, 0xa21e,
1540 0x00c0, 0x3f5e, 0x7a38, 0xd2fc, 0x0040, 0x3f5c, 0x70ac, 0xa005,
1541 0x00c0, 0x3f5c, 0x70af, 0x0001, 0x0078, 0x3f6d, 0xa005, 0x00c0,
1542 0x3f79, 0x7a38, 0xd2fc, 0x0040, 0x3f6b, 0x70ac, 0xa005, 0x00c0,
1543 0x3f6b, 0x70af, 0x0001, 0x7083, 0x0000, 0x7a38, 0xd2f4, 0x0040,
1544 0x3f73, 0x70cb, 0x0008, 0x7087, 0x0016, 0x1078, 0x3f7d, 0x0078,
1545 0x3f7b, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x20e1, 0x9080, 0x20e1,
1546 0x4000, 0x2099, 0xa880, 0x20a1, 0x020b, 0x20a9, 0x000e, 0x53a6,
1547 0x3430, 0x2011, 0xa88e, 0x7087, 0x0017, 0x1078, 0x4211, 0x00c0,
1548 0x3f9d, 0x7070, 0xa005, 0x00c0, 0x3f9d, 0x1078, 0x4051, 0x00c0,
1549 0x3fa7, 0xa085, 0x0001, 0x1078, 0x2500, 0x20a9, 0x0008, 0x2099,
1550 0xa88e, 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3,
1551 0x0014, 0x1078, 0x4158, 0x007c, 0x0f7e, 0x707c, 0xa005, 0x0040,
1552 0x3fcc, 0x2011, 0x4129, 0x1078, 0x58d4, 0xa086, 0x0084, 0x00c0,
1553 0x3fca, 0x2079, 0xa880, 0x7a30, 0xa296, 0x1106, 0x00c0, 0x3fca,
1554 0x7834, 0xa005, 0x00c0, 0x3fca, 0x7087, 0x0018, 0x1078, 0x3fce,
1555 0x0078, 0x3fcc, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x7087, 0x0019,
1556 0x1078, 0x41d2, 0x20a3, 0x1106, 0x20a3, 0x0000, 0x3430, 0x2099,
1557 0xa88e, 0x2039, 0xa80e, 0x27a0, 0x20a9, 0x0040, 0x53a3, 0x1078,
1558 0x4211, 0x00c0, 0x4002, 0x2728, 0x2514, 0x8207, 0xa084, 0x00ff,
1559 0x8000, 0x2018, 0xa294, 0x00ff, 0x8007, 0xa205, 0x202a, 0x6030,
1560 0x2310, 0x8214, 0xa2a0, 0xa80e, 0x2414, 0xa38c, 0x0001, 0x0040,
1561 0x3ffd, 0xa294, 0xff00, 0x0078, 0x4000, 0xa294, 0x00ff, 0x8007,
1562 0xa215, 0x2222, 0x2798, 0x26a0, 0x20a9, 0x0040, 0x53a6, 0x20a3,
1563 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0084, 0x1078, 0x4158, 0x007c,
1564 0x0f7e, 0x707c, 0xa005, 0x0040, 0x4034, 0x2011, 0x4129, 0x1078,
1565 0x58d4, 0xa086, 0x0084, 0x00c0, 0x4032, 0x2079, 0xa880, 0x7a30,
1566 0xa296, 0x1107, 0x00c0, 0x4032, 0x7834, 0xa005, 0x00c0, 0x4032,
1567 0x7083, 0x0001, 0x1078, 0x41b8, 0x7087, 0x001a, 0x1078, 0x4036,
1568 0x0078, 0x4034, 0x1078, 0x4171, 0x0f7f, 0x007c, 0x7087, 0x001b,
1569 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2099, 0xa880, 0x20a1, 0x020b,
1570 0x747c, 0xa480, 0x0018, 0xa080, 0x0007, 0xa084, 0x03f8, 0x8004,
1571 0x20a8, 0x53a6, 0x60c3, 0x0084, 0x1078, 0x4158, 0x007c, 0x007c,
1572 0x007c, 0x087e, 0x097e, 0x2029, 0xa352, 0x252c, 0x20a9, 0x0008,
1573 0x2041, 0xa80e, 0x28a0, 0x2099, 0xa88e, 0x53a3, 0x20a9, 0x0008,
1574 0x2011, 0x0007, 0xd5d4, 0x0040, 0x4067, 0x2011, 0x0000, 0x2800,
1575 0xa200, 0x200c, 0xa1a6, 0xffff, 0x00c0, 0x4079, 0xd5d4, 0x0040,
1576 0x4074, 0x8210, 0x0078, 0x4075, 0x8211, 0x00f0, 0x4067, 0x0078,
1577 0x40e1, 0x82ff, 0x00c0, 0x408b, 0xd5d4, 0x0040, 0x4085, 0xa1a6,
1578 0x3fff, 0x0040, 0x4071, 0x0078, 0x4089, 0xa1a6, 0x3fff, 0x0040,
1579 0x40e1, 0xa18d, 0xc000, 0x20a9, 0x0010, 0x2019, 0x0001, 0xd5d4,
1580 0x0040, 0x4094, 0x2019, 0x0010, 0x2120, 0xd5d4, 0x0040, 0x409b,
1581 0x8423, 0x0078, 0x409c, 0x8424, 0x00c8, 0x40a9, 0xd5d4, 0x0040,
1582 0x40a4, 0x8319, 0x0078, 0x40a5, 0x8318, 0x00f0, 0x4095, 0x0078,
1583 0x40e1, 0x23a8, 0x2021, 0x0001, 0x8426, 0x8425, 0x00f0, 0x40ad,
1584 0x2328, 0x8529, 0xa2be, 0x0007, 0x0040, 0x40c1, 0x007e, 0x2039,
1585 0x0007, 0x2200, 0xa73a, 0x007f, 0x27a8, 0xa5a8, 0x0010, 0x00f0,
1586 0x40bd, 0x754e, 0xa5c8, 0x293f, 0x292c, 0xa5ac, 0x00ff, 0x6532,
1587 0x60e7, 0x0000, 0x65ea, 0x706b, 0x0000, 0x756e, 0x2018, 0x2304,
1588 0xa405, 0x201a, 0x7073, 0x0001, 0x26a0, 0x2898, 0x20a9, 0x0008,
1589 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0xa085, 0x0001, 0x0078,
1590 0x40e7, 0xa006, 0x0078, 0x40e7, 0xa006, 0x1078, 0x1328, 0x097f,
1591 0x087f, 0x007c, 0x2118, 0x2021, 0x0000, 0x2001, 0x0007, 0xa39a,
1592 0x0010, 0x0048, 0x40f7, 0x8420, 0x8001, 0x0078, 0x40ef, 0x2118,
1593 0x84ff, 0x0040, 0x4100, 0xa39a, 0x0010, 0x8421, 0x00c0, 0x40fb,
1594 0x2021, 0x0001, 0x83ff, 0x0040, 0x4109, 0x8423, 0x8319, 0x00c0,
1595 0x4105, 0xa238, 0x2704, 0xa42c, 0x00c0, 0x4121, 0xa405, 0x203a,
1596 0x714e, 0xa1a0, 0x293f, 0x242c, 0xa5ac, 0x00ff, 0x6532, 0x60e7,
1597 0x0000, 0x65ea, 0x706b, 0x0000, 0x756e, 0x7073, 0x0001, 0xa084,
1598 0x0000, 0x007c, 0x0e7e, 0x2071, 0xa300, 0x7077, 0x0000, 0x0e7f,
1599 0x007c, 0x0e7e, 0x0f7e, 0x2001, 0x0002, 0x1078, 0x5975, 0x2079,
1600 0x0100, 0x2071, 0x0140, 0x1078, 0x6c41, 0x7004, 0xa084, 0x4000,
1601 0x0040, 0x413e, 0x7003, 0x1000, 0x7003, 0x0000, 0x127e, 0x2091,
1602 0x8000, 0x2071, 0xa321, 0x2073, 0x0000, 0x7840, 0x027e, 0x017e,
1603 0x2009, 0x00f7, 0x1078, 0x41de, 0x017f, 0xa094, 0x0010, 0xa285,
1604 0x0080, 0x7842, 0x7a42, 0x027f, 0x127f, 0x0f7f, 0x0e7f, 0x007c,
1605 0x127e, 0x2091, 0x8000, 0x2011, 0xa5b5, 0x2013, 0x0000, 0x707f,
1606 0x0000, 0x127f, 0x20e1, 0x9080, 0x60a3, 0x0056, 0x60a7, 0x9575,
1607 0x1078, 0x6c38, 0x2009, 0x07d0, 0x2011, 0x4129, 0x1078, 0x596c,
1608 0x007c, 0x017e, 0x027e, 0x0c7e, 0x127e, 0x2091, 0x8000, 0x2009,
1609 0x00f7, 0x1078, 0x41de, 0x2061, 0xa5be, 0x601b, 0x0000, 0x601f,
1610 0x0000, 0x2061, 0xa300, 0x6003, 0x0001, 0x2061, 0x0100, 0x6043,
1611 0x0090, 0x6043, 0x0010, 0x2009, 0x002d, 0x2011, 0x4196, 0x1078,
1612 0x58c7, 0x127f, 0x0c7f, 0x027f, 0x017f, 0x007c, 0x0e7e, 0x007e,
1613 0x127e, 0x2091, 0x8000, 0x2001, 0x0001, 0x1078, 0x5975, 0x2071,
1614 0x0100, 0x1078, 0x6c41, 0x2071, 0x0140, 0x7004, 0xa084, 0x4000,
1615 0x0040, 0x41ae, 0x7003, 0x1000, 0x7003, 0x0000, 0x2001, 0x0001,
1616 0x1078, 0x2480, 0x1078, 0x4171, 0x127f, 0x007f, 0x0e7f, 0x007c,
1617 0x20a9, 0x0040, 0x20a1, 0xa9c0, 0x2099, 0xa88e, 0x3304, 0x8007,
1618 0x20a2, 0x9398, 0x94a0, 0x00f0, 0x41be, 0x007c, 0x20e1, 0x9080,
1619 0x20e1, 0x4000, 0x2099, 0xa800, 0x20a1, 0x020b, 0x20a9, 0x000c,
1620 0x53a6, 0x007c, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2099, 0xa880,
1621 0x20a1, 0x020b, 0x20a9, 0x000c, 0x53a6, 0x007c, 0x0c7e, 0x007e,
1622 0x2061, 0x0100, 0x810f, 0x2001, 0xa32e, 0x2004, 0xa005, 0x00c0,
1623 0x41ef, 0x6030, 0xa084, 0x00ff, 0xa105, 0x0078, 0x41f1, 0xa185,
1624 0x00f7, 0x604a, 0x007f, 0x0c7f, 0x007c, 0x017e, 0x047e, 0x2001,
1625 0xa352, 0x2004, 0xd0a4, 0x0040, 0x4208, 0xa006, 0x2020, 0x2009,
1626 0x002a, 0x1078, 0x9ec0, 0x2001, 0xa30c, 0x200c, 0xc195, 0x2102,
1627 0x2019, 0x002a, 0x2009, 0x0000, 0x1078, 0x27e2, 0x047f, 0x017f,
1628 0x007c, 0x007e, 0x2001, 0xa30c, 0x2004, 0xd09c, 0x0040, 0x4218,
1629 0x007f, 0x007c, 0x007e, 0x017e, 0x127e, 0x2091, 0x8000, 0x2001,
1630 0x0101, 0x200c, 0xa18d, 0x0006, 0x2102, 0x127f, 0x017f, 0x007f,
1631 0x007c, 0x157e, 0x20a9, 0x00ff, 0x2009, 0xa434, 0xa006, 0x200a,
1632 0x8108, 0x00f0, 0x422f, 0x157f, 0x007c, 0x0d7e, 0x037e, 0x157e,
1633 0x137e, 0x147e, 0x2069, 0xa351, 0xa006, 0x6002, 0x6007, 0x0707,
1634 0x600a, 0x600e, 0x6012, 0xa198, 0x293f, 0x231c, 0xa39c, 0x00ff,
1635 0x6316, 0x20a9, 0x0004, 0xac98, 0x0006, 0x23a0, 0x40a4, 0x20a9,
1636 0x0004, 0xac98, 0x000a, 0x23a0, 0x40a4, 0x603e, 0x6042, 0x604e,
1637 0x6052, 0x6056, 0x605a, 0x605e, 0x6062, 0x6066, 0x606a, 0x606e,
1638 0x6072, 0x6076, 0x607a, 0x607e, 0x6082, 0x6086, 0x608a, 0x608e,
1639 0x6092, 0x6096, 0x609a, 0x609e, 0x60ae, 0x61a2, 0x0d7e, 0x60a4,
1640 0xa06d, 0x0040, 0x4275, 0x1078, 0x139a, 0x60a7, 0x0000, 0x60a8,
1641 0xa06d, 0x0040, 0x427d, 0x1078, 0x139a, 0x60ab, 0x0000, 0x0d7f,
1642 0xa006, 0x604a, 0x6810, 0x603a, 0x680c, 0x6046, 0x6814, 0xa084,
1643 0x00ff, 0x6042, 0x147f, 0x137f, 0x157f, 0x037f, 0x0d7f, 0x007c,
1644 0x127e, 0x2091, 0x8000, 0x6944, 0x6e48, 0xa684, 0x3fff, 0xa082,
1645 0x4000, 0x00c8, 0x4361, 0xa18c, 0xff00, 0x810f, 0xa182, 0x00ff,
1646 0x00c8, 0x4367, 0x2001, 0xa30c, 0x2004, 0xa084, 0x0003, 0x0040,
1647 0x42c2, 0x2001, 0xa30c, 0x2004, 0xd084, 0x00c0, 0x4342, 0xa188,
1648 0xa434, 0x2104, 0xa065, 0x0040, 0x4342, 0x6004, 0xa084, 0x00ff,
1649 0xa08e, 0x0006, 0x00c0, 0x4342, 0x6000, 0xd0c4, 0x0040, 0x4342,
1650 0x0078, 0x42cf, 0xa188, 0xa434, 0x2104, 0xa065, 0x0040, 0x4326,
1651 0x6004, 0xa084, 0x00ff, 0xa08e, 0x0006, 0x00c0, 0x432c, 0x60a4,
1652 0xa00d, 0x0040, 0x42d7, 0x1078, 0x4749, 0x0040, 0x4320, 0x60a8,
1653 0xa00d, 0x0040, 0x42f1, 0x1078, 0x479a, 0x00c0, 0x42f1, 0x694c,
1654 0xd1fc, 0x00c0, 0x42e7, 0x1078, 0x441c, 0x0078, 0x431b, 0x1078,
1655 0x43d6, 0x694c, 0xd1ec, 0x00c0, 0x431b, 0x1078, 0x460a, 0x0078,
1656 0x431b, 0x694c, 0xa184, 0xa000, 0x0040, 0x430b, 0xd1ec, 0x0040,
1657 0x4304, 0xd1fc, 0x0040, 0x4300, 0x1078, 0x461b, 0x0078, 0x4307,
1658 0x1078, 0x461b, 0x0078, 0x430b, 0xd1fc, 0x0040, 0x430b, 0x1078,
1659 0x43d6, 0x0078, 0x431b, 0x6050, 0xa00d, 0x0040, 0x4316, 0x2d00,
1660 0x200a, 0x6803, 0x0000, 0x6052, 0x0078, 0x431b, 0x2d00, 0x6052,
1661 0x604e, 0x6803, 0x0000, 0x1078, 0x5c17, 0xa006, 0x127f, 0x007c,
1662 0x2001, 0x0005, 0x2009, 0x0000, 0x0078, 0x436b, 0x2001, 0x0028,
1663 0x2009, 0x0000, 0x0078, 0x436b, 0xa082, 0x0006, 0x00c8, 0x4342,
1664 0x60a0, 0xd0bc, 0x00c0, 0x433e, 0x6100, 0xd1fc, 0x0040, 0x42cf,
1665 0x2001, 0x0029, 0x2009, 0x1000, 0x0078, 0x436b, 0x2001, 0x0028,
1666 0x0078, 0x435d, 0x2009, 0xa30c, 0x210c, 0xd18c, 0x0040, 0x434c,
1667 0x2001, 0x0004, 0x0078, 0x435d, 0xd184, 0x0040, 0x4353, 0x2001,
1668 0x0004, 0x0078, 0x435d, 0x2001, 0x0029, 0x6100, 0xd1fc, 0x0040,
1669 0x435d, 0x2009, 0x1000, 0x0078, 0x436b, 0x2009, 0x0000, 0x0078,
1670 0x436b, 0x2001, 0x0029, 0x2009, 0x0000, 0x0078, 0x436b, 0x2001,
1671 0x0029, 0x2009, 0x0000, 0xa005, 0x127f, 0x007c, 0x6944, 0x6e48,
1672 0xa684, 0x3fff, 0xa082, 0x4000, 0x00c8, 0x43bb, 0xa18c, 0xff00,
1673 0x810f, 0xa182, 0x00ff, 0x00c8, 0x43a1, 0xa188, 0xa434, 0x2104,
1674 0xa065, 0x0040, 0x43a1, 0x6004, 0xa084, 0x00ff, 0xa08e, 0x0006,
1675 0x00c0, 0x43a7, 0x684c, 0xd0ec, 0x0040, 0x4394, 0x1078, 0x461b,
1676 0x1078, 0x43d6, 0x0078, 0x439c, 0x1078, 0x43d6, 0x684c, 0xd0fc,
1677 0x0040, 0x439c, 0x1078, 0x460a, 0x1078, 0x4663, 0xa006, 0x0078,
1678 0x43bf, 0x2001, 0x0028, 0x2009, 0x0000, 0x0078, 0x43bf, 0xa082,
1679 0x0006, 0x00c8, 0x43b5, 0x6100, 0xd1fc, 0x0040, 0x438a, 0x2001,
1680 0x0029, 0x2009, 0x1000, 0x0078, 0x43bf, 0x2001, 0x0029, 0x2009,
1681 0x0000, 0x0078, 0x43bf, 0x2001, 0x0029, 0x2009, 0x0000, 0xa005,
1682 0x007c, 0x127e, 0x2091, 0x8000, 0x6050, 0xa00d, 0x0040, 0x43cf,
1683 0x2d00, 0x200a, 0x6803, 0x0000, 0x6052, 0x127f, 0x007c, 0x2d00,
1684 0x6052, 0x604e, 0x6803, 0x0000, 0x0078, 0x43cd, 0x127e, 0x2091,
1685 0x8000, 0x604c, 0xa005, 0x0040, 0x43ec, 0x0e7e, 0x2071, 0xa5ab,
1686 0x7004, 0xa086, 0x0002, 0x0040, 0x43f3, 0x0e7f, 0x604c, 0x6802,
1687 0x2d00, 0x604e, 0x127f, 0x007c, 0x2d00, 0x6052, 0x604e, 0x6803,
1688 0x0000, 0x0078, 0x43ea, 0x701c, 0xac06, 0x00c0, 0x43e5, 0x604c,
1689 0x2070, 0x7000, 0x6802, 0x2d00, 0x7002, 0x0e7f, 0x127f, 0x007c,
1690 0x127e, 0x2091, 0x8000, 0x604c, 0xa06d, 0x0040, 0x440e, 0x6800,
1691 0xa005, 0x00c0, 0x440c, 0x6052, 0x604e, 0xad05, 0x127f, 0x007c,
1692 0x604c, 0xa06d, 0x0040, 0x441b, 0x6800, 0xa005, 0x00c0, 0x4419,
1693 0x6052, 0x604e, 0xad05, 0x007c, 0x6803, 0x0000, 0x6084, 0xa00d,
1694 0x0040, 0x4426, 0x2d00, 0x200a, 0x6086, 0x007c, 0x2d00, 0x6086,
1695 0x6082, 0x0078, 0x4425, 0x127e, 0x0c7e, 0x027e, 0x2091, 0x8000,
1696 0x6218, 0x2260, 0x6200, 0xa005, 0x0040, 0x4439, 0xc285, 0x0078,
1697 0x443a, 0xc284, 0x6202, 0x027f, 0x0c7f, 0x127f, 0x007c, 0x127e,
1698 0x0c7e, 0x2091, 0x8000, 0x6218, 0x2260, 0x6204, 0x007e, 0xa086,
1699 0x0006, 0x00c0, 0x445e, 0x609c, 0xd0ac, 0x0040, 0x445e, 0x2001,
1700 0xa352, 0x2004, 0xd0a4, 0x0040, 0x445e, 0xa284, 0xff00, 0x8007,
1701 0xa086, 0x0007, 0x00c0, 0x445e, 0x2011, 0x0600, 0x007f, 0xa294,
1702 0xff00, 0xa215, 0x6206, 0x007e, 0xa086, 0x0006, 0x00c0, 0x446e,
1703 0x6290, 0x82ff, 0x00c0, 0x446e, 0x1078, 0x1328, 0x007f, 0x0c7f,
1704 0x127f, 0x007c, 0x127e, 0x0c7e, 0x2091, 0x8000, 0x6218, 0x2260,
1705 0x6204, 0x007e, 0xa086, 0x0006, 0x00c0, 0x4490, 0x609c, 0xd0a4,
1706 0x0040, 0x4490, 0x2001, 0xa352, 0x2004, 0xd0ac, 0x00c0, 0x4490,
1707 0xa284, 0x00ff, 0xa086, 0x0007, 0x00c0, 0x4490, 0x2011, 0x0006,
1708 0x007f, 0xa294, 0x00ff, 0x8007, 0xa215, 0x6206, 0x0c7f, 0x127f,
1709 0x007c, 0x027e, 0xa182, 0x00ff, 0x0048, 0x44a2, 0xa085, 0x0001,
1710 0x0078, 0x44ba, 0xa190, 0xa434, 0x2204, 0xa065, 0x00c0, 0x44b9,
1711 0x017e, 0x0d7e, 0x1078, 0x1366, 0x2d60, 0x0d7f, 0x017f, 0x0040,
1712 0x449e, 0x2c00, 0x2012, 0x60a7, 0x0000, 0x60ab, 0x0000, 0x1078,
1713 0x4235, 0xa006, 0x027f, 0x007c, 0x127e, 0x2091, 0x8000, 0x027e,
1714 0xa182, 0x00ff, 0x0048, 0x44c8, 0xa085, 0x0001, 0x0078, 0x44fe,
1715 0x0d7e, 0xa190, 0xa434, 0x2204, 0xa06d, 0x0040, 0x44fc, 0x2013,
1716 0x0000, 0x0d7e, 0x0c7e, 0x2d60, 0x60a4, 0xa06d, 0x0040, 0x44da,
1717 0x1078, 0x139a, 0x60a8, 0xa06d, 0x0040, 0x44e0, 0x1078, 0x139a,
1718 0x0c7f, 0x0d7f, 0x0d7e, 0x0c7e, 0x68ac, 0x2060, 0x8cff, 0x0040,
1719 0x44f8, 0x600c, 0x007e, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040,
1720 0x44f3, 0x1078, 0x13aa, 0x1078, 0x753d, 0x0c7f, 0x0078, 0x44e6,
1721 0x0c7f, 0x0d7f, 0x1078, 0x139a, 0x0d7f, 0xa006, 0x027f, 0x127f,
1722 0x007c, 0x017e, 0xa182, 0x00ff, 0x0048, 0x450a, 0xa085, 0x0001,
1723 0x0078, 0x4511, 0xa188, 0xa434, 0x2104, 0xa065, 0x0040, 0x4506,
1724 0xa006, 0x017f, 0x007c, 0x0d7e, 0x157e, 0x137e, 0x147e, 0x600b,
1725 0x0000, 0x600f, 0x0000, 0x6000, 0xc08c, 0x6002, 0x2069, 0xa88e,
1726 0x6808, 0x605e, 0x6810, 0x6062, 0x6138, 0xa10a, 0x0048, 0x4529,
1727 0x603a, 0x6814, 0x6066, 0x2099, 0xa896, 0xac88, 0x000a, 0x21a0,
1728 0x20a9, 0x0004, 0x53a3, 0x2099, 0xa89a, 0xac88, 0x0006, 0x21a0,
1729 0x20a9, 0x0004, 0x53a3, 0x2069, 0xa8ae, 0x6808, 0x606a, 0x690c,
1730 0x616e, 0x6810, 0x6072, 0x6818, 0x6076, 0xa182, 0x0211, 0x00c8,
1731 0x454d, 0x2009, 0x0008, 0x0078, 0x4577, 0xa182, 0x0259, 0x00c8,
1732 0x4555, 0x2009, 0x0007, 0x0078, 0x4577, 0xa182, 0x02c1, 0x00c8,
1733 0x455d, 0x2009, 0x0006, 0x0078, 0x4577, 0xa182, 0x0349, 0x00c8,
1734 0x4565, 0x2009, 0x0005, 0x0078, 0x4577, 0xa182, 0x0421, 0x00c8,
1735 0x456d, 0x2009, 0x0004, 0x0078, 0x4577, 0xa182, 0x0581, 0x00c8,
1736 0x4575, 0x2009, 0x0003, 0x0078, 0x4577, 0x2009, 0x0002, 0x6192,
1737 0x147f, 0x137f, 0x157f, 0x0d7f, 0x007c, 0x017e, 0x027e, 0x0e7e,
1738 0x2071, 0xa88d, 0x2e04, 0x6896, 0x2071, 0xa88e, 0x7004, 0x689a,
1739 0x701c, 0x689e, 0x6a00, 0x2009, 0xa371, 0x210c, 0xd0bc, 0x0040,
1740 0x4597, 0xd1ec, 0x0040, 0x4597, 0xc2ad, 0x0078, 0x4598, 0xc2ac,
1741 0xd0c4, 0x0040, 0x45a1, 0xd1e4, 0x0040, 0x45a1, 0xc2bd, 0x0078,
1742 0x45a2, 0xc2bc, 0x6a02, 0x0e7f, 0x027f, 0x017f, 0x007c, 0x0d7e,
1743 0x127e, 0x2091, 0x8000, 0x60a4, 0xa06d, 0x0040, 0x45cb, 0x6900,
1744 0x81ff, 0x00c0, 0x45df, 0x6a04, 0xa282, 0x0010, 0x00c8, 0x45e4,
1745 0xad88, 0x0004, 0x20a9, 0x0010, 0x2104, 0xa086, 0xffff, 0x0040,
1746 0x45c6, 0x8108, 0x00f0, 0x45bc, 0x1078, 0x1328, 0x260a, 0x8210,
1747 0x6a06, 0x0078, 0x45df, 0x1078, 0x1381, 0x0040, 0x45e4, 0x2d00,
1748 0x60a6, 0x6803, 0x0000, 0xad88, 0x0004, 0x20a9, 0x0010, 0x200b,
1749 0xffff, 0x8108, 0x00f0, 0x45d7, 0x6807, 0x0001, 0x6e12, 0xa085,
1750 0x0001, 0x127f, 0x0d7f, 0x007c, 0xa006, 0x0078, 0x45e1, 0x127e,
1751 0x2091, 0x8000, 0x0d7e, 0x60a4, 0xa00d, 0x0040, 0x4607, 0x2168,
1752 0x6800, 0xa005, 0x00c0, 0x4603, 0x1078, 0x4749, 0x00c0, 0x4607,
1753 0x200b, 0xffff, 0x6804, 0xa08a, 0x0002, 0x0048, 0x4603, 0x8001,
1754 0x6806, 0x0078, 0x4607, 0x1078, 0x139a, 0x60a7, 0x0000, 0x0d7f,
1755 0x127f, 0x007c, 0x127e, 0x2091, 0x8000, 0x1078, 0x47af, 0x0078,
1756 0x4613, 0x1078, 0x43c1, 0x1078, 0x46a7, 0x00c0, 0x4611, 0x1078,
1757 0x4663, 0x127f, 0x007c, 0x0d7e, 0x127e, 0x2091, 0x8000, 0x60a8,
1758 0xa06d, 0x0040, 0x463f, 0x6950, 0x81ff, 0x00c0, 0x4653, 0x6a54,
1759 0xa282, 0x0010, 0x00c8, 0x4660, 0xad88, 0x0018, 0x20a9, 0x0010,
1760 0x2104, 0xa086, 0xffff, 0x0040, 0x463a, 0x8108, 0x00f0, 0x4630,
1761 0x1078, 0x1328, 0x260a, 0x8210, 0x6a56, 0x0078, 0x4653, 0x1078,
1762 0x1381, 0x0040, 0x4660, 0x2d00, 0x60aa, 0x6853, 0x0000, 0xad88,
1763 0x0018, 0x20a9, 0x0010, 0x200b, 0xffff, 0x8108, 0x00f0, 0x464b,
1764 0x6857, 0x0001, 0x6e62, 0x0078, 0x4657, 0x1078, 0x441c, 0x1078,
1765 0x466d, 0x00c0, 0x4655, 0xa085, 0x0001, 0x127f, 0x0d7f, 0x007c,
1766 0xa006, 0x0078, 0x465d, 0x127e, 0x2091, 0x8000, 0x1078, 0x5c17,
1767 0x127f, 0x007c, 0xa01e, 0x0078, 0x466f, 0x2019, 0x0001, 0xa00e,
1768 0x127e, 0x2091, 0x8000, 0x604c, 0x2068, 0x6000, 0xd0dc, 0x00c0,
1769 0x468d, 0x8dff, 0x0040, 0x46a2, 0x83ff, 0x0040, 0x4685, 0x6848,
1770 0xa606, 0x0040, 0x4692, 0x0078, 0x468d, 0x683c, 0xa406, 0x00c0,
1771 0x468d, 0x6840, 0xa506, 0x0040, 0x4692, 0x2d08, 0x6800, 0x2068,
1772 0x0078, 0x4679, 0x6a00, 0x604c, 0xad06, 0x00c0, 0x469a, 0x624e,
1773 0x0078, 0x469d, 0xa180, 0x0000, 0x2202, 0x82ff, 0x00c0, 0x46a2,
1774 0x6152, 0x8dff, 0x127f, 0x007c, 0xa01e, 0x0078, 0x46a9, 0x2019,
1775 0x0001, 0xa00e, 0x6080, 0x2068, 0x8dff, 0x0040, 0x46d5, 0x83ff,
1776 0x0040, 0x46b8, 0x6848, 0xa606, 0x0040, 0x46c5, 0x0078, 0x46c0,
1777 0x683c, 0xa406, 0x00c0, 0x46c0, 0x6840, 0xa506, 0x0040, 0x46c5,
1778 0x2d08, 0x6800, 0x2068, 0x0078, 0x46ac, 0x6a00, 0x6080, 0xad06,
1779 0x00c0, 0x46cd, 0x6282, 0x0078, 0x46d0, 0xa180, 0x0000, 0x2202,
1780 0x82ff, 0x00c0, 0x46d5, 0x6186, 0x8dff, 0x007c, 0xa016, 0x1078,
1781 0x4742, 0x00c0, 0x46dd, 0x2011, 0x0001, 0x1078, 0x4793, 0x00c0,
1782 0x46e3, 0xa295, 0x0002, 0x007c, 0x1078, 0x47cb, 0x0040, 0x46ec,
1783 0x1078, 0x8b12, 0x0078, 0x46ee, 0xa085, 0x0001, 0x007c, 0x1078,
1784 0x47cb, 0x0040, 0x46f7, 0x1078, 0x8aaa, 0x0078, 0x46f9, 0xa085,
1785 0x0001, 0x007c, 0x1078, 0x47cb, 0x0040, 0x4702, 0x1078, 0x8af4,
1786 0x0078, 0x4704, 0xa085, 0x0001, 0x007c, 0x1078, 0x47cb, 0x0040,
1787 0x470d, 0x1078, 0x8ac6, 0x0078, 0x470f, 0xa085, 0x0001, 0x007c,
1788 0x1078, 0x47cb, 0x0040, 0x4718, 0x1078, 0x8b30, 0x0078, 0x471a,
1789 0xa085, 0x0001, 0x007c, 0x127e, 0x007e, 0x0d7e, 0x2091, 0x8000,
1790 0x6080, 0xa06d, 0x0040, 0x473a, 0x6800, 0x007e, 0x6837, 0x0103,
1791 0x6b4a, 0x6847, 0x0000, 0x1078, 0x8cb8, 0x007e, 0x6000, 0xd0fc,
1792 0x0040, 0x4734, 0x1078, 0xa18c, 0x007f, 0x1078, 0x4982, 0x007f,
1793 0x0078, 0x4721, 0x6083, 0x0000, 0x6087, 0x0000, 0x0d7f, 0x007f,
1794 0x127f, 0x007c, 0x60a4, 0xa00d, 0x00c0, 0x4749, 0xa085, 0x0001,
1795 0x007c, 0x0e7e, 0x2170, 0x7000, 0xa005, 0x00c0, 0x475c, 0x20a9,
1796 0x0010, 0xae88, 0x0004, 0x2104, 0xa606, 0x0040, 0x475c, 0x8108,
1797 0x00f0, 0x4753, 0xa085, 0x0001, 0xa006, 0x0e7f, 0x007c, 0x0d7e,
1798 0x127e, 0x2091, 0x8000, 0x60a4, 0xa06d, 0x00c0, 0x476d, 0x1078,
1799 0x1381, 0x0040, 0x477f, 0x2d00, 0x60a6, 0x6803, 0x0001, 0x6807,
1800 0x0000, 0xad88, 0x0004, 0x20a9, 0x0010, 0x200b, 0xffff, 0x8108,
1801 0x00f0, 0x4775, 0xa085, 0x0001, 0x127f, 0x0d7f, 0x007c, 0xa006,
1802 0x0078, 0x477c, 0x0d7e, 0x127e, 0x2091, 0x8000, 0x60a4, 0xa06d,
1803 0x0040, 0x4790, 0x60a7, 0x0000, 0x1078, 0x139a, 0xa085, 0x0001,
1804 0x127f, 0x0d7f, 0x007c, 0x60a8, 0xa00d, 0x00c0, 0x479a, 0xa085,
1805 0x0001, 0x007c, 0x0e7e, 0x2170, 0x7050, 0xa005, 0x00c0, 0x47ad,
1806 0x20a9, 0x0010, 0xae88, 0x0018, 0x2104, 0xa606, 0x0040, 0x47ad,
1807 0x8108, 0x00f0, 0x47a4, 0xa085, 0x0001, 0x0e7f, 0x007c, 0x127e,
1808 0x2091, 0x8000, 0x1078, 0x4793, 0x00c0, 0x47c9, 0x200b, 0xffff,
1809 0x0d7e, 0x60a8, 0x2068, 0x6854, 0xa08a, 0x0002, 0x0048, 0x47c4,
1810 0x8001, 0x6856, 0x0078, 0x47c8, 0x1078, 0x139a, 0x60ab, 0x0000,
1811 0x0d7f, 0x127f, 0x007c, 0x609c, 0xd0a4, 0x007c, 0x0f7e, 0x71ac,
1812 0x81ff, 0x00c0, 0x47e9, 0x71c8, 0xd19c, 0x0040, 0x47e9, 0x2001,
1813 0x007e, 0xa080, 0xa434, 0x2004, 0xa07d, 0x0040, 0x47e9, 0x7804,
1814 0xa084, 0x00ff, 0xa086, 0x0006, 0x00c0, 0x47e9, 0x7800, 0xc0ed,
1815 0x7802, 0x2079, 0xa351, 0x7804, 0xd0a4, 0x0040, 0x480f, 0x157e,
1816 0x0c7e, 0x20a9, 0x007f, 0x2009, 0x0000, 0x017e, 0x1078, 0x4501,
1817 0x00c0, 0x4809, 0x6004, 0xa084, 0xff00, 0x8007, 0xa096, 0x0004,
1818 0x0040, 0x4806, 0xa086, 0x0006, 0x00c0, 0x4809, 0x6000, 0xc0ed,
1819 0x6002, 0x017f, 0x8108, 0x00f0, 0x47f5, 0x0c7f, 0x157f, 0x1078,
1820 0x4897, 0x0040, 0x4818, 0x2001, 0xa59f, 0x200c, 0x0078, 0x4820,
1821 0x2079, 0xa351, 0x7804, 0xd0a4, 0x0040, 0x4824, 0x2009, 0x07d0,
1822 0x2011, 0x4826, 0x1078, 0x596c, 0x0f7f, 0x007c, 0x2011, 0x4826,
1823 0x1078, 0x58d4, 0x1078, 0x4897, 0x0040, 0x484e, 0x2001, 0xa4b2,
1824 0x2004, 0xa080, 0x0000, 0x200c, 0xc1ec, 0x2102, 0x2001, 0xa352,
1825 0x2004, 0xd0a4, 0x0040, 0x4842, 0x2009, 0x07d0, 0x2011, 0x4826,
1826 0x1078, 0x596c, 0x0e7e, 0x2071, 0xa300, 0x706b, 0x0000, 0x706f,
1827 0x0000, 0x1078, 0x260d, 0x0e7f, 0x0078, 0x4886, 0x157e, 0x0c7e,
1828 0x20a9, 0x007f, 0x2009, 0x0000, 0x017e, 0x1078, 0x4501, 0x00c0,
1829 0x4880, 0x6000, 0xd0ec, 0x0040, 0x4880, 0x047e, 0x62a0, 0xa294,
1830 0x00ff, 0x8227, 0xa006, 0x2009, 0x0029, 0x1078, 0x9ec0, 0x6000,
1831 0xc0e5, 0xc0ec, 0x6002, 0x6004, 0xa084, 0x00ff, 0xa085, 0x0700,
1832 0x6006, 0x2019, 0x0029, 0x1078, 0x5d53, 0x077e, 0x2039, 0x0000,
1833 0x1078, 0x5c78, 0x2009, 0x0000, 0x1078, 0x9c38, 0x077f, 0x047f,
1834 0x017f, 0x8108, 0x00f0, 0x4854, 0x0c7f, 0x157f, 0x007c, 0x0c7e,
1835 0x6018, 0x2060, 0x6000, 0xc0ec, 0x6002, 0x0c7f, 0x007c, 0x7818,
1836 0x2004, 0xd0ac, 0x007c, 0x7818, 0x2004, 0xd0bc, 0x007c, 0x0f7e,
1837 0x2001, 0xa4b2, 0x2004, 0xa07d, 0x0040, 0x48a0, 0x7800, 0xd0ec,
1838 0x0f7f, 0x007c, 0x127e, 0x027e, 0x2091, 0x8000, 0x6200, 0xa005,
1839 0x0040, 0x48ad, 0xc2fd, 0x0078, 0x48ae, 0xc2fc, 0x6202, 0x027f,
1840 0x127f, 0x007c, 0x2071, 0xa413, 0x7003, 0x0001, 0x7007, 0x0000,
1841 0x7013, 0x0000, 0x7017, 0x0000, 0x701b, 0x0000, 0x701f, 0x0000,
1842 0x700b, 0x0000, 0x704b, 0x0001, 0x704f, 0x0000, 0x705b, 0x0020,
1843 0x705f, 0x0040, 0x707f, 0x0000, 0x2071, 0xa57c, 0x7003, 0xa413,
1844 0x7007, 0x0000, 0x700b, 0x0000, 0x700f, 0xa55c, 0x7013, 0x0020,
1845 0x7017, 0x0040, 0x7037, 0x0000, 0x007c, 0x017e, 0x0e7e, 0x2071,
1846 0xa534, 0xa00e, 0x7186, 0x718a, 0x7097, 0x0001, 0x2001, 0xa352,
1847 0x2004, 0xd0fc, 0x00c0, 0x48f7, 0x2001, 0xa352, 0x2004, 0xa00e,
1848 0xd09c, 0x0040, 0x48f4, 0x8108, 0x7102, 0x0078, 0x494a, 0x2001,
1849 0xa371, 0x200c, 0xa184, 0x000f, 0x2009, 0xa372, 0x210c, 0x0079,
1850 0x4901, 0x48ec, 0x4922, 0x492a, 0x4935, 0x493b, 0x48ec, 0x48ec,
1851 0x48ec, 0x4911, 0x48ec, 0x48ec, 0x48ec, 0x48ec, 0x48ec, 0x48ec,
1852 0x48ec, 0x7003, 0x0004, 0x137e, 0x147e, 0x157e, 0x2099, 0xa375,
1853 0x20a1, 0xa585, 0x20a9, 0x0004, 0x53a3, 0x157f, 0x147f, 0x137f,
1854 0x0078, 0x494a, 0x708f, 0x0005, 0x7007, 0x0122, 0x2001, 0x0002,
1855 0x0078, 0x4930, 0x708f, 0x0002, 0x7007, 0x0121, 0x2001, 0x0003,
1856 0x7002, 0x7097, 0x0001, 0x0078, 0x4947, 0x7007, 0x0122, 0x2001,
1857 0x0002, 0x0078, 0x493f, 0x7007, 0x0121, 0x2001, 0x0003, 0x7002,
1858 0xa006, 0x7096, 0x708e, 0xa184, 0xff00, 0x8007, 0x709a, 0xa184,
1859 0x00ff, 0x7092, 0x0e7f, 0x017f, 0x007c, 0x0e7e, 0x2071, 0xa413,
1860 0x684c, 0xa005, 0x00c0, 0x495b, 0x7028, 0xc085, 0x702a, 0xa085,
1861 0x0001, 0x0078, 0x4980, 0x6a60, 0x7236, 0x6b64, 0x733a, 0x6868,
1862 0x703e, 0x7076, 0x686c, 0x7042, 0x707a, 0x684c, 0x702e, 0x6844,
1863 0x7032, 0x2009, 0x000d, 0x200a, 0x700b, 0x0000, 0x8007, 0x8006,
1864 0x8006, 0xa08c, 0x003f, 0xa084, 0xffc0, 0xa210, 0x2100, 0xa319,
1865 0x726e, 0x7372, 0x7028, 0xc084, 0x702a, 0x7007, 0x0001, 0xa006,
1866 0x0e7f, 0x007c, 0x0e7e, 0x027e, 0x6838, 0xd0fc, 0x00c0, 0x49d8,
1867 0x6804, 0xa00d, 0x0040, 0x499e, 0x0d7e, 0x2071, 0xa300, 0xa016,
1868 0x702c, 0x2168, 0x6904, 0x206a, 0x8210, 0x2d00, 0x81ff, 0x00c0,
1869 0x4991, 0x702e, 0x70a8, 0xa200, 0x70aa, 0x0d7f, 0x2071, 0xa413,
1870 0x701c, 0xa005, 0x00c0, 0x49ea, 0x0068, 0x49e8, 0x2071, 0xa534,
1871 0x7200, 0x82ff, 0x0040, 0x49e8, 0x6934, 0xa186, 0x0103, 0x00c0,
1872 0x49fb, 0x6948, 0x6844, 0xa105, 0x00c0, 0x49db, 0x2009, 0x8020,
1873 0x2200, 0x0079, 0x49bb, 0x49e8, 0x49c0, 0x4a18, 0x4a26, 0x49e8,
1874 0x2071, 0x0000, 0x7018, 0xd084, 0x00c0, 0x49e8, 0x7122, 0x683c,
1875 0x7026, 0x6840, 0x702a, 0x701b, 0x0001, 0x2091, 0x4080, 0x2071,
1876 0xa300, 0x702c, 0x206a, 0x2d00, 0x702e, 0x70a8, 0x8000, 0x70aa,
1877 0x027f, 0x0e7f, 0x007c, 0x6844, 0xa086, 0x0100, 0x00c0, 0x49e8,
1878 0x6868, 0xa005, 0x00c0, 0x49e8, 0x2009, 0x8020, 0x0078, 0x49b8,
1879 0x2071, 0xa413, 0x2d08, 0x206b, 0x0000, 0x7010, 0x8000, 0x7012,
1880 0x7018, 0xa06d, 0x711a, 0x0040, 0x49f8, 0x6902, 0x0078, 0x49f9,
1881 0x711e, 0x0078, 0x49d8, 0xa18c, 0x00ff, 0xa186, 0x0017, 0x0040,
1882 0x4a09, 0xa186, 0x001e, 0x0040, 0x4a09, 0xa18e, 0x001f, 0x00c0,
1883 0x49e8, 0x684c, 0xd0cc, 0x0040, 0x49e8, 0x6850, 0xa084, 0x00ff,
1884 0xa086, 0x0001, 0x00c0, 0x49e8, 0x2009, 0x8021, 0x0078, 0x49b8,
1885 0x7084, 0x8008, 0xa092, 0x001e, 0x00c8, 0x49e8, 0x7186, 0xae90,
1886 0x0003, 0xa210, 0x683c, 0x2012, 0x0078, 0x4a36, 0x7084, 0x8008,
1887 0xa092, 0x000f, 0x00c8, 0x49e8, 0x7186, 0xae90, 0x0003, 0x8003,
1888 0xa210, 0x683c, 0x2012, 0x8210, 0x6840, 0x2012, 0x7088, 0xa10a,
1889 0x0048, 0x49cf, 0x718c, 0x7084, 0xa10a, 0x0048, 0x49cf, 0x2071,
1890 0x0000, 0x7018, 0xd084, 0x00c0, 0x49cf, 0x2071, 0xa534, 0x7000,
1891 0xa086, 0x0002, 0x00c0, 0x4a56, 0x1078, 0x4cd2, 0x2071, 0x0000,
1892 0x701b, 0x0001, 0x2091, 0x4080, 0x0078, 0x49cf, 0x1078, 0x4cfd,
1893 0x2071, 0x0000, 0x701b, 0x0001, 0x2091, 0x4080, 0x0078, 0x49cf,
1894 0x007e, 0x684c, 0x007e, 0x6837, 0x0103, 0x20a9, 0x001c, 0xad80,
1895 0x0011, 0x20a0, 0x2001, 0x0000, 0x40a4, 0x007f, 0xa084, 0x00ff,
1896 0x684e, 0x007f, 0x684a, 0x6952, 0x007c, 0x2071, 0xa413, 0x7004,
1897 0x0079, 0x4a7a, 0x4a84, 0x4a95, 0x4ca3, 0x4ca4, 0x4ccb, 0x4cd1,
1898 0x4a85, 0x4c91, 0x4c32, 0x4cb4, 0x007c, 0x127e, 0x2091, 0x8000,
1899 0x0068, 0x4a94, 0x2009, 0x000d, 0x7030, 0x200a, 0x2091, 0x4080,
1900 0x7007, 0x0001, 0x700b, 0x0000, 0x127f, 0x2069, 0xa5be, 0x6844,
1901 0xa005, 0x0050, 0x4abd, 0x00c0, 0x4abd, 0x127e, 0x2091, 0x8000,
1902 0x2069, 0x0000, 0x6934, 0x2001, 0xa41f, 0x2004, 0xa10a, 0x0040,
1903 0x4ab8, 0x0068, 0x4abc, 0x2069, 0x0000, 0x6818, 0xd084, 0x00c0,
1904 0x4abc, 0x2009, 0x8040, 0x6922, 0x681b, 0x0001, 0x2091, 0x4080,
1905 0x2069, 0xa5be, 0x6847, 0xffff, 0x127f, 0x2069, 0xa300, 0x6844,
1906 0x6960, 0xa102, 0x2069, 0xa534, 0x688a, 0x6984, 0x701c, 0xa06d,
1907 0x0040, 0x4acf, 0x81ff, 0x0040, 0x4b17, 0x0078, 0x4ae5, 0x81ff,
1908 0x0040, 0x4be9, 0x2071, 0xa534, 0x7184, 0x7088, 0xa10a, 0x00c8,
1909 0x4ae5, 0x7190, 0x2071, 0xa5be, 0x7040, 0xa005, 0x0040, 0x4ae5,
1910 0x00d0, 0x4be9, 0x7142, 0x0078, 0x4be9, 0x2071, 0xa534, 0x718c,
1911 0x127e, 0x2091, 0x8000, 0x7084, 0xa10a, 0x0048, 0x4c06, 0x0068,
1912 0x4b9b, 0x2071, 0x0000, 0x7018, 0xd084, 0x00c0, 0x4b9b, 0x2001,
1913 0xffff, 0x2071, 0xa5be, 0x7042, 0x2071, 0xa534, 0x7000, 0xa086,
1914 0x0002, 0x00c0, 0x4b0d, 0x1078, 0x4cd2, 0x2071, 0x0000, 0x701b,
1915 0x0001, 0x2091, 0x4080, 0x0078, 0x4b9b, 0x1078, 0x4cfd, 0x2071,
1916 0x0000, 0x701b, 0x0001, 0x2091, 0x4080, 0x0078, 0x4b9b, 0x2071,
1917 0xa534, 0x7000, 0xa005, 0x0040, 0x4bc8, 0x6934, 0xa186, 0x0103,
1918 0x00c0, 0x4b9e, 0x684c, 0xd0bc, 0x00c0, 0x4bc8, 0x6948, 0x6844,
1919 0xa105, 0x00c0, 0x4bbb, 0x2009, 0x8020, 0x2071, 0xa534, 0x7000,
1920 0x0079, 0x4b32, 0x4bc8, 0x4b80, 0x4b58, 0x4b6a, 0x4b37, 0x137e,
1921 0x147e, 0x157e, 0x2099, 0xa375, 0x20a1, 0xa585, 0x20a9, 0x0004,
1922 0x53a3, 0x157f, 0x147f, 0x137f, 0x2071, 0xa57c, 0xad80, 0x000f,
1923 0x700e, 0x7013, 0x0002, 0x7007, 0x0002, 0x700b, 0x0000, 0x2e10,
1924 0x1078, 0x13d1, 0x2071, 0xa413, 0x7007, 0x0009, 0x0078, 0x4be9,
1925 0x7084, 0x8008, 0xa092, 0x001e, 0x00c8, 0x4be9, 0xae90, 0x0003,
1926 0xa210, 0x683c, 0x2012, 0x7186, 0x2071, 0xa413, 0x1078, 0x4d5b,
1927 0x0078, 0x4be9, 0x7084, 0x8008, 0xa092, 0x000f, 0x00c8, 0x4be9,
1928 0xae90, 0x0003, 0x8003, 0xa210, 0x683c, 0x2012, 0x8210, 0x6840,
1929 0x2012, 0x7186, 0x2071, 0xa413, 0x1078, 0x4d5b, 0x0078, 0x4be9,
1930 0x127e, 0x2091, 0x8000, 0x0068, 0x4b9b, 0x2071, 0x0000, 0x7018,
1931 0xd084, 0x00c0, 0x4b9b, 0x7122, 0x683c, 0x7026, 0x6840, 0x702a,
1932 0x701b, 0x0001, 0x2091, 0x4080, 0x127f, 0x2071, 0xa413, 0x1078,
1933 0x4d5b, 0x0078, 0x4be9, 0x127f, 0x0078, 0x4be9, 0xa18c, 0x00ff,
1934 0xa186, 0x0017, 0x0040, 0x4bac, 0xa186, 0x001e, 0x0040, 0x4bac,
1935 0xa18e, 0x001f, 0x00c0, 0x4bc8, 0x684c, 0xd0cc, 0x0040, 0x4bc8,
1936 0x6850, 0xa084, 0x00ff, 0xa086, 0x0001, 0x00c0, 0x4bc8, 0x2009,
1937 0x8021, 0x0078, 0x4b2d, 0x6844, 0xa086, 0x0100, 0x00c0, 0x4bc8,
1938 0x6868, 0xa005, 0x00c0, 0x4bc8, 0x2009, 0x8020, 0x0078, 0x4b2d,
1939 0x2071, 0xa413, 0x1078, 0x4d6f, 0x0040, 0x4be9, 0x2071, 0xa413,
1940 0x700f, 0x0001, 0x6934, 0xa184, 0x00ff, 0xa086, 0x0003, 0x00c0,
1941 0x4be0, 0x810f, 0xa18c, 0x00ff, 0x8101, 0x0040, 0x4be0, 0x710e,
1942 0x7007, 0x0003, 0x1078, 0x4d8f, 0x7050, 0xa086, 0x0100, 0x0040,
1943 0x4ca4, 0x127e, 0x2091, 0x8000, 0x2071, 0xa413, 0x7008, 0xa086,
1944 0x0001, 0x00c0, 0x4c04, 0x0068, 0x4c04, 0x2009, 0x000d, 0x7030,
1945 0x200a, 0x2091, 0x4080, 0x700b, 0x0000, 0x7004, 0xa086, 0x0006,
1946 0x00c0, 0x4c04, 0x7007, 0x0001, 0x127f, 0x007c, 0x2071, 0xa413,
1947 0x1078, 0x4d6f, 0x0040, 0x4c2f, 0x2071, 0xa534, 0x7084, 0x700a,
1948 0x20a9, 0x0020, 0x2099, 0xa535, 0x20a1, 0xa55c, 0x53a3, 0x7087,
1949 0x0000, 0x2071, 0xa413, 0x2069, 0xa57c, 0x706c, 0x6826, 0x7070,
1950 0x682a, 0x7074, 0x682e, 0x7078, 0x6832, 0x2d10, 0x1078, 0x13d1,
1951 0x7007, 0x0008, 0x2001, 0xffff, 0x2071, 0xa5be, 0x7042, 0x127f,
1952 0x0078, 0x4be9, 0x2069, 0xa57c, 0x6808, 0xa08e, 0x0000, 0x0040,
1953 0x4c90, 0xa08e, 0x0200, 0x0040, 0x4c8e, 0xa08e, 0x0100, 0x00c0,
1954 0x4c90, 0x127e, 0x2091, 0x8000, 0x0068, 0x4c8b, 0x2069, 0x0000,
1955 0x6818, 0xd084, 0x00c0, 0x4c8b, 0x702c, 0x7130, 0x8108, 0xa102,
1956 0x0048, 0x4c59, 0xa00e, 0x7034, 0x706e, 0x7038, 0x7072, 0x0078,
1957 0x4c63, 0x706c, 0xa080, 0x0040, 0x706e, 0x00c8, 0x4c63, 0x7070,
1958 0xa081, 0x0000, 0x7072, 0x7132, 0x6936, 0x700b, 0x0000, 0x2001,
1959 0xa559, 0x2004, 0xa005, 0x00c0, 0x4c82, 0x6934, 0x2069, 0xa534,
1960 0x689c, 0x699e, 0x2069, 0xa5be, 0xa102, 0x00c0, 0x4c7b, 0x6844,
1961 0xa005, 0x00d0, 0x4c89, 0x2001, 0xa55a, 0x200c, 0x810d, 0x6946,
1962 0x0078, 0x4c89, 0x2009, 0x8040, 0x6922, 0x681b, 0x0001, 0x2091,
1963 0x4080, 0x7007, 0x0001, 0x127f, 0x0078, 0x4c90, 0x7007, 0x0005,
1964 0x007c, 0x701c, 0xa06d, 0x0040, 0x4ca2, 0x1078, 0x4d6f, 0x0040,
1965 0x4ca2, 0x7007, 0x0003, 0x1078, 0x4d8f, 0x7050, 0xa086, 0x0100,
1966 0x0040, 0x4ca4, 0x007c, 0x007c, 0x7050, 0xa09e, 0x0100, 0x00c0,
1967 0x4cad, 0x7007, 0x0004, 0x0078, 0x4ccb, 0xa086, 0x0200, 0x00c0,
1968 0x4cb3, 0x7007, 0x0005, 0x007c, 0x2001, 0xa57e, 0x2004, 0xa08e,
1969 0x0100, 0x00c0, 0x4cc0, 0x7007, 0x0001, 0x1078, 0x4d5b, 0x007c,
1970 0xa08e, 0x0000, 0x0040, 0x4cbf, 0xa08e, 0x0200, 0x00c0, 0x4cbf,
1971 0x7007, 0x0005, 0x007c, 0x1078, 0x4d25, 0x7006, 0x1078, 0x4d5b,
1972 0x007c, 0x007c, 0x0e7e, 0x157e, 0x2071, 0xa534, 0x7184, 0x81ff,
1973 0x0040, 0x4cfa, 0xa006, 0x7086, 0xae80, 0x0003, 0x2071, 0x0000,
1974 0x21a8, 0x2014, 0x7226, 0x8000, 0x0070, 0x4cf7, 0x2014, 0x722a,
1975 0x8000, 0x0070, 0x4cf7, 0x2014, 0x722e, 0x8000, 0x0070, 0x4cf7,
1976 0x2014, 0x723a, 0x8000, 0x0070, 0x4cf7, 0x2014, 0x723e, 0xa180,
1977 0x8030, 0x7022, 0x157f, 0x0e7f, 0x007c, 0x0e7e, 0x157e, 0x2071,
1978 0xa534, 0x7184, 0x81ff, 0x0040, 0x4d22, 0xa006, 0x7086, 0xae80,
1979 0x0003, 0x2071, 0x0000, 0x21a8, 0x2014, 0x7226, 0x8000, 0x2014,
1980 0x722a, 0x8000, 0x0070, 0x4d1b, 0x2014, 0x723a, 0x8000, 0x2014,
1981 0x723e, 0x0078, 0x4d1f, 0x2001, 0x8020, 0x0078, 0x4d21, 0x2001,
1982 0x8042, 0x7022, 0x157f, 0x0e7f, 0x007c, 0x702c, 0x7130, 0x8108,
1983 0xa102, 0x0048, 0x4d32, 0xa00e, 0x7034, 0x706e, 0x7038, 0x7072,
1984 0x0078, 0x4d3c, 0x706c, 0xa080, 0x0040, 0x706e, 0x00c8, 0x4d3c,
1985 0x7070, 0xa081, 0x0000, 0x7072, 0x7132, 0x700c, 0x8001, 0x700e,
1986 0x00c0, 0x4d52, 0x127e, 0x2091, 0x8000, 0x0068, 0x4d55, 0x2001,
1987 0x000d, 0x2102, 0x2091, 0x4080, 0x2001, 0x0001, 0x700b, 0x0000,
1988 0x127f, 0x007c, 0x2001, 0x0007, 0x007c, 0x2001, 0x0006, 0x700b,
1989 0x0001, 0x127f, 0x007c, 0x701c, 0xa06d, 0x0040, 0x4d6e, 0x127e,
1990 0x2091, 0x8000, 0x7010, 0x8001, 0x7012, 0x2d04, 0x701e, 0xa005,
1991 0x00c0, 0x4d6b, 0x701a, 0x127f, 0x1078, 0x139a, 0x007c, 0x2019,
1992 0x000d, 0x2304, 0x230c, 0xa10e, 0x0040, 0x4d7e, 0x2304, 0x230c,
1993 0xa10e, 0x0040, 0x4d7e, 0xa006, 0x0078, 0x4d8e, 0x732c, 0x8319,
1994 0x7130, 0xa102, 0x00c0, 0x4d88, 0x2300, 0xa005, 0x0078, 0x4d8e,
1995 0x0048, 0x4d8d, 0xa302, 0x0078, 0x4d8e, 0x8002, 0x007c, 0x2d00,
1996 0x7026, 0xa080, 0x000d, 0x7056, 0x7053, 0x0000, 0x127e, 0x2091,
1997 0x8000, 0x2009, 0xa5d0, 0x2104, 0xc08d, 0x200a, 0x127f, 0x1078,
1998 0x13eb, 0x007c, 0x2071, 0xa3e1, 0x7003, 0x0000, 0x7007, 0x0000,
1999 0x700f, 0x0000, 0x702b, 0x0001, 0x704f, 0x0000, 0x7053, 0x0001,
2000 0x705f, 0x0020, 0x7063, 0x0040, 0x7083, 0x0000, 0x708b, 0x0000,
2001 0x708f, 0x0001, 0x70bf, 0x0000, 0x007c, 0x0e7e, 0x2071, 0xa3e1,
2002 0x6848, 0xa005, 0x00c0, 0x4dcb, 0x7028, 0xc085, 0x702a, 0xa085,
2003 0x0001, 0x0078, 0x4df0, 0x6a50, 0x7236, 0x6b54, 0x733a, 0x6858,
2004 0x703e, 0x707a, 0x685c, 0x7042, 0x707e, 0x6848, 0x702e, 0x6840,
2005 0x7032, 0x2009, 0x000c, 0x200a, 0x8007, 0x8006, 0x8006, 0xa08c,
2006 0x003f, 0xa084, 0xffc0, 0xa210, 0x2100, 0xa319, 0x7272, 0x7376,
2007 0x7028, 0xc084, 0x702a, 0x7007, 0x0001, 0x700f, 0x0000, 0xa006,
2008 0x0e7f, 0x007c, 0x2b78, 0x2071, 0xa3e1, 0x7004, 0x1079, 0x4e50,
2009 0x700c, 0x0079, 0x4dfb, 0x4e00, 0x4df5, 0x4df5, 0x4df5, 0x4df5,
2010 0x007c, 0x700c, 0x0079, 0x4e04, 0x4e09, 0x4e4e, 0x4e4e, 0x4e4f,
2011 0x4e4f, 0x7830, 0x7930, 0xa106, 0x0040, 0x4e13, 0x7830, 0x7930,
2012 0xa106, 0x00c0, 0x4e39, 0x7030, 0xa10a, 0x0040, 0x4e39, 0x00c8,
2013 0x4e1b, 0x712c, 0xa10a, 0xa18a, 0x0002, 0x00c8, 0x4e3a, 0x1078,
2014 0x1366, 0x0040, 0x4e39, 0x2d00, 0x705a, 0x7063, 0x0040, 0x2001,
2015 0x0003, 0x7057, 0x0000, 0x127e, 0x007e, 0x2091, 0x8000, 0x2009,
2016 0xa5d0, 0x2104, 0xc085, 0x200a, 0x007f, 0x700e, 0x127f, 0x1078,
2017 0x13eb, 0x007c, 0x1078, 0x1366, 0x0040, 0x4e39, 0x2d00, 0x705a,
2018 0x1078, 0x1366, 0x00c0, 0x4e46, 0x0078, 0x4e25, 0x2d00, 0x7086,
2019 0x7063, 0x0080, 0x2001, 0x0004, 0x0078, 0x4e29, 0x007c, 0x007c,
2020 0x4e61, 0x4e62, 0x4e99, 0x4e9a, 0x4e4e, 0x4ed0, 0x4ed5, 0x4f0c,
2021 0x4f0d, 0x4f28, 0x4f29, 0x4f2a, 0x4f2b, 0x4f2c, 0x4f2d, 0x4fad,
2022 0x4fd7, 0x007c, 0x700c, 0x0079, 0x4e65, 0x4e6a, 0x4e6d, 0x4e7d,
2023 0x4e98, 0x4e98, 0x1078, 0x4e01, 0x007c, 0x127e, 0x8001, 0x700e,
2024 0x7058, 0x007e, 0x1078, 0x5348, 0x0040, 0x4e7a, 0x2091, 0x8000,
2025 0x1078, 0x4e01, 0x0d7f, 0x0078, 0x4e86, 0x127e, 0x8001, 0x700e,
2026 0x1078, 0x5348, 0x7058, 0x2068, 0x7084, 0x705a, 0x6803, 0x0000,
2027 0x6807, 0x0000, 0x6834, 0xa084, 0x00ff, 0xa08a, 0x0020, 0x00c8,
2028 0x4e95, 0x1079, 0x4eb0, 0x127f, 0x007c, 0x127f, 0x1078, 0x4f2e,
2029 0x007c, 0x007c, 0x007c, 0x0e7e, 0x2071, 0xa3e1, 0x700c, 0x0079,
2030 0x4ea1, 0x4ea6, 0x4ea6, 0x4ea6, 0x4ea8, 0x4eac, 0x0e7f, 0x007c,
2031 0x700f, 0x0001, 0x0078, 0x4eae, 0x700f, 0x0002, 0x0e7f, 0x007c,
2032 0x4f2e, 0x4f2e, 0x4f4a, 0x4f2e, 0x5080, 0x4f2e, 0x4f2e, 0x4f2e,
2033 0x4f2e, 0x4f2e, 0x4f4a, 0x50ca, 0x5117, 0x5170, 0x5186, 0x4f2e,
2034 0x4f2e, 0x4f66, 0x4f4a, 0x4f2e, 0x4f2e, 0x4f87, 0x5245, 0x5263,
2035 0x4f2e, 0x4f66, 0x4f2e, 0x4f2e, 0x4f2e, 0x4f2e, 0x4f7c, 0x5263,
2036 0x7020, 0x2068, 0x1078, 0x139a, 0x007c, 0x700c, 0x0079, 0x4ed8,
2037 0x4edd, 0x4ee0, 0x4ef0, 0x4f0b, 0x4f0b, 0x1078, 0x4e01, 0x007c,
2038 0x127e, 0x8001, 0x700e, 0x7058, 0x007e, 0x1078, 0x5348, 0x0040,
2039 0x4eed, 0x2091, 0x8000, 0x1078, 0x4e01, 0x0d7f, 0x0078, 0x4ef9,
2040 0x127e, 0x8001, 0x700e, 0x1078, 0x5348, 0x7058, 0x2068, 0x7084,
2041 0x705a, 0x6803, 0x0000, 0x6807, 0x0000, 0x6834, 0xa084, 0x00ff,
2042 0xa08a, 0x001a, 0x00c8, 0x4f08, 0x1079, 0x4f0e, 0x127f, 0x007c,
2043 0x127f, 0x1078, 0x4f2e, 0x007c, 0x007c, 0x007c, 0x4f2e, 0x4f4a,
2044 0x506a, 0x4f2e, 0x4f4a, 0x4f2e, 0x4f4a, 0x4f4a, 0x4f2e, 0x4f4a,
2045 0x506a, 0x4f4a, 0x4f4a, 0x4f4a, 0x4f4a, 0x4f4a, 0x4f2e, 0x4f4a,
2046 0x506a, 0x4f2e, 0x4f2e, 0x4f4a, 0x4f2e, 0x4f2e, 0x4f2e, 0x4f4a,
2047 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x007c, 0x7007, 0x0001,
2048 0x6838, 0xa084, 0x00ff, 0xc0d5, 0x683a, 0x127e, 0x2091, 0x8000,
2049 0x1078, 0x4982, 0x127f, 0x007c, 0x7007, 0x0001, 0x6838, 0xa084,
2050 0x00ff, 0xc0e5, 0x683a, 0x127e, 0x2091, 0x8000, 0x1078, 0x4982,
2051 0x127f, 0x007c, 0x7007, 0x0001, 0x6838, 0xa084, 0x00ff, 0xc0ed,
2052 0x683a, 0x127e, 0x2091, 0x8000, 0x1078, 0x4982, 0x127f, 0x007c,
2053 0x7007, 0x0001, 0x6838, 0xa084, 0x00ff, 0xc0dd, 0x683a, 0x127e,
2054 0x2091, 0x8000, 0x1078, 0x4982, 0x127f, 0x007c, 0x6834, 0x8007,
2055 0xa084, 0x00ff, 0x0040, 0x4f3c, 0x8001, 0x00c0, 0x4f73, 0x7007,
2056 0x0001, 0x0078, 0x5049, 0x7007, 0x0006, 0x7012, 0x2d00, 0x7016,
2057 0x701a, 0x704b, 0x5049, 0x007c, 0x684c, 0xa084, 0x00c0, 0xa086,
2058 0x00c0, 0x00c0, 0x4f87, 0x7007, 0x0001, 0x0078, 0x5280, 0x2d00,
2059 0x7016, 0x701a, 0x20a9, 0x0004, 0xa080, 0x0024, 0x2098, 0x20a1,
2060 0xa40c, 0x53a3, 0x6858, 0x7012, 0xa082, 0x0401, 0x00c8, 0x4f58,
2061 0x6884, 0xa08a, 0x0002, 0x00c8, 0x4f58, 0x82ff, 0x00c0, 0x4fa9,
2062 0x6888, 0x698c, 0xa105, 0x0040, 0x4fa9, 0x2001, 0x5019, 0x0078,
2063 0x4fac, 0xa280, 0x500f, 0x2004, 0x70c6, 0x7010, 0xa015, 0x0040,
2064 0x4ff7, 0x1078, 0x1366, 0x00c0, 0x4fb8, 0x7007, 0x000f, 0x007c,
2065 0x2d00, 0x7022, 0x70c4, 0x2060, 0x6000, 0x6836, 0x6004, 0xad00,
2066 0x7096, 0x6008, 0xa20a, 0x00c8, 0x4fc7, 0xa00e, 0x2200, 0x7112,
2067 0x620c, 0x8003, 0x800b, 0xa296, 0x0004, 0x0040, 0x4fd0, 0xa108,
2068 0x719a, 0x810b, 0x719e, 0xae90, 0x0022, 0x1078, 0x13d1, 0x7090,
2069 0xa08e, 0x0100, 0x0040, 0x4feb, 0xa086, 0x0200, 0x0040, 0x4fe3,
2070 0x7007, 0x0010, 0x007c, 0x7020, 0x2068, 0x1078, 0x139a, 0x7014,
2071 0x2068, 0x0078, 0x4f58, 0x7020, 0x2068, 0x7018, 0x6802, 0x6807,
2072 0x0000, 0x2d08, 0x2068, 0x6906, 0x711a, 0x0078, 0x4fad, 0x7014,
2073 0x2068, 0x7007, 0x0001, 0x6884, 0xa005, 0x00c0, 0x5006, 0x6888,
2074 0x698c, 0xa105, 0x0040, 0x5006, 0x1078, 0x501d, 0x6834, 0xa084,
2075 0x00ff, 0xa086, 0x001e, 0x0040, 0x5280, 0x0078, 0x5049, 0x5011,
2076 0x5015, 0x0002, 0x0011, 0x0007, 0x0004, 0x000a, 0x000f, 0x0005,
2077 0x0006, 0x000a, 0x0011, 0x0005, 0x0004, 0x0f7e, 0x0e7e, 0x0c7e,
2078 0x077e, 0x067e, 0x6f88, 0x6e8c, 0x6804, 0x2060, 0xacf0, 0x0021,
2079 0xacf8, 0x0027, 0x2009, 0x0005, 0x700c, 0x7816, 0x7008, 0x7812,
2080 0x7004, 0x7806, 0x7000, 0x7802, 0x7e0e, 0x7f0a, 0x8109, 0x0040,
2081 0x503f, 0xaef2, 0x0004, 0xaffa, 0x0006, 0x0078, 0x502c, 0x6004,
2082 0xa065, 0x00c0, 0x5026, 0x067f, 0x077f, 0x0c7f, 0x0e7f, 0x0f7f,
2083 0x007c, 0x2009, 0xa32e, 0x210c, 0x81ff, 0x00c0, 0x5064, 0x6838,
2084 0xa084, 0x00ff, 0x683a, 0x1078, 0x4290, 0x00c0, 0x5058, 0x007c,
2085 0x1078, 0x4a60, 0x127e, 0x2091, 0x8000, 0x1078, 0x8cb8, 0x1078,
2086 0x4982, 0x127f, 0x0078, 0x5057, 0x2001, 0x0028, 0x2009, 0x0000,
2087 0x0078, 0x5058, 0x7018, 0x6802, 0x2d08, 0x2068, 0x6906, 0x711a,
2088 0x7010, 0x8001, 0x7012, 0x0040, 0x5079, 0x7007, 0x0006, 0x0078,
2089 0x507f, 0x7014, 0x2068, 0x7007, 0x0001, 0x7048, 0x107a, 0x007c,
2090 0x7007, 0x0001, 0x6944, 0x810f, 0xa18c, 0x00ff, 0x6848, 0xa084,
2091 0x00ff, 0x20a9, 0x0001, 0xa096, 0x0001, 0x0040, 0x50a9, 0x2009,
2092 0x0000, 0x20a9, 0x00ff, 0xa096, 0x0002, 0x0040, 0x50a9, 0xa005,
2093 0x00c0, 0x50bc, 0x6944, 0x810f, 0xa18c, 0x00ff, 0x1078, 0x4501,
2094 0x00c0, 0x50bc, 0x067e, 0x6e50, 0x1078, 0x45e7, 0x067f, 0x0078,
2095 0x50bc, 0x047e, 0x2011, 0xa30c, 0x2224, 0xc484, 0xc48c, 0x2412,
2096 0x047f, 0x0c7e, 0x1078, 0x4501, 0x00c0, 0x50b8, 0x1078, 0x4782,
2097 0x8108, 0x00f0, 0x50b2, 0x0c7f, 0x684c, 0xd084, 0x00c0, 0x50c3,
2098 0x1078, 0x139a, 0x007c, 0x127e, 0x2091, 0x8000, 0x1078, 0x4982,
2099 0x127f, 0x007c, 0x127e, 0x2091, 0x8000, 0x7007, 0x0001, 0x2001,
2100 0xa352, 0x2004, 0xd0a4, 0x0040, 0x510e, 0x2061, 0xa62d, 0x6100,
2101 0xd184, 0x0040, 0x50ee, 0x6858, 0xa084, 0x00ff, 0x00c0, 0x5111,
2102 0x6000, 0xd084, 0x0040, 0x510e, 0x6004, 0xa005, 0x00c0, 0x5114,
2103 0x6003, 0x0000, 0x600b, 0x0000, 0x0078, 0x510b, 0x2011, 0x0001,
2104 0x6860, 0xa005, 0x00c0, 0x50f6, 0x2001, 0x001e, 0x8000, 0x6016,
2105 0x6858, 0xa084, 0x00ff, 0x0040, 0x510e, 0x6006, 0x6858, 0x8007,
2106 0xa084, 0x00ff, 0x0040, 0x510e, 0x600a, 0x6858, 0x8000, 0x00c0,
2107 0x510a, 0xc28d, 0x6202, 0x127f, 0x0078, 0x5337, 0x127f, 0x0078,
2108 0x532f, 0x127f, 0x0078, 0x5327, 0x127f, 0x0078, 0x532b, 0x127e,
2109 0x2091, 0x8000, 0x7007, 0x0001, 0x2001, 0xa352, 0x2004, 0xd0a4,
2110 0x0040, 0x516d, 0x2061, 0xa62d, 0x6000, 0xd084, 0x0040, 0x516d,
2111 0x6204, 0x6308, 0xd08c, 0x00c0, 0x515f, 0x6c48, 0xa484, 0x0003,
2112 0x0040, 0x5145, 0x6958, 0xa18c, 0x00ff, 0x8001, 0x00c0, 0x513e,
2113 0x2100, 0xa210, 0x0048, 0x516a, 0x0078, 0x5145, 0x8001, 0x00c0,
2114 0x516a, 0x2100, 0xa212, 0x0048, 0x516a, 0xa484, 0x000c, 0x0040,
2115 0x515f, 0x6958, 0x810f, 0xa18c, 0x00ff, 0xa082, 0x0004, 0x00c0,
2116 0x5157, 0x2100, 0xa318, 0x0048, 0x516a, 0x0078, 0x515f, 0xa082,
2117 0x0004, 0x00c0, 0x516a, 0x2100, 0xa31a, 0x0048, 0x516a, 0x6860,
2118 0xa005, 0x0040, 0x5165, 0x8000, 0x6016, 0x6206, 0x630a, 0x127f,
2119 0x0078, 0x5337, 0x127f, 0x0078, 0x5333, 0x127f, 0x0078, 0x532f,
2120 0x127e, 0x2091, 0x8000, 0x7007, 0x0001, 0x2061, 0xa62d, 0x6300,
2121 0xd38c, 0x00c0, 0x5180, 0x6308, 0x8318, 0x0048, 0x5183, 0x630a,
2122 0x127f, 0x0078, 0x5345, 0x127f, 0x0078, 0x5333, 0x127e, 0x0c7e,
2123 0x2091, 0x8000, 0x7007, 0x0001, 0x684c, 0xd0ac, 0x0040, 0x519a,
2124 0x0c7e, 0x2061, 0xa62d, 0x6000, 0xa084, 0xfcff, 0x6002, 0x0c7f,
2125 0x0078, 0x51c9, 0x6858, 0xa005, 0x0040, 0x51e0, 0x685c, 0xa065,
2126 0x0040, 0x51dc, 0x2001, 0xa32e, 0x2004, 0xa005, 0x0040, 0x51ac,
2127 0x1078, 0x8c01, 0x0078, 0x51ba, 0x6013, 0x0400, 0x6037, 0x0000,
2128 0x694c, 0xd1a4, 0x0040, 0x51b6, 0x6950, 0x6136, 0x2009, 0x0041,
2129 0x1078, 0x756c, 0x6958, 0xa18c, 0xff00, 0xa186, 0x2000, 0x00c0,
2130 0x51c9, 0x027e, 0x2009, 0x0000, 0x2011, 0xfdff, 0x1078, 0x5a6d,
2131 0x027f, 0x684c, 0xd0c4, 0x0040, 0x51d8, 0x2061, 0xa62d, 0x6000,
2132 0xd08c, 0x00c0, 0x51d8, 0x6008, 0x8000, 0x0048, 0x51dc, 0x600a,
2133 0x0c7f, 0x127f, 0x0078, 0x5337, 0x0c7f, 0x127f, 0x0078, 0x532f,
2134 0x6954, 0xa186, 0x0045, 0x0040, 0x5213, 0xa186, 0x002a, 0x00c0,
2135 0x51f0, 0x2001, 0xa30c, 0x200c, 0xc194, 0x2102, 0x0078, 0x51c9,
2136 0xa186, 0x0020, 0x0040, 0x5209, 0xa186, 0x0029, 0x0040, 0x51fc,
2137 0xa186, 0x002d, 0x00c0, 0x51dc, 0x6944, 0xa18c, 0xff00, 0x810f,
2138 0x1078, 0x4501, 0x00c0, 0x51c9, 0x6000, 0xc0e4, 0x6002, 0x0078,
2139 0x51c9, 0x685c, 0xa065, 0x0040, 0x51dc, 0x2001, 0xa5a1, 0x2004,
2140 0x6016, 0x0078, 0x51c9, 0x685c, 0xa065, 0x0040, 0x51dc, 0x0e7e,
2141 0x6860, 0xa075, 0x2001, 0xa32e, 0x2004, 0xa005, 0x0040, 0x522b,
2142 0x1078, 0x8c01, 0x8eff, 0x0040, 0x5228, 0x2e60, 0x1078, 0x8c01,
2143 0x0e7f, 0x0078, 0x51c9, 0x6024, 0xc0dc, 0xc0d5, 0x6026, 0x2e60,
2144 0x6007, 0x003a, 0x6870, 0xa005, 0x0040, 0x523c, 0x6007, 0x003b,
2145 0x6874, 0x602a, 0x6878, 0x6012, 0x6003, 0x0001, 0x1078, 0x5bf8,
2146 0x1078, 0x6109, 0x0e7f, 0x0078, 0x51c9, 0x2061, 0xa62d, 0x6000,
2147 0xd084, 0x0040, 0x525f, 0xd08c, 0x00c0, 0x5345, 0x2091, 0x8000,
2148 0x6204, 0x8210, 0x0048, 0x5259, 0x6206, 0x2091, 0x8001, 0x0078,
2149 0x5345, 0x2091, 0x8001, 0x6853, 0x0016, 0x0078, 0x533e, 0x6853,
2150 0x0007, 0x0078, 0x533e, 0x6834, 0x8007, 0xa084, 0x00ff, 0x00c0,
2151 0x526d, 0x1078, 0x4f3c, 0x0078, 0x527f, 0x2030, 0x8001, 0x00c0,
2152 0x5277, 0x7007, 0x0001, 0x1078, 0x5280, 0x0078, 0x527f, 0x7007,
2153 0x0006, 0x7012, 0x2d00, 0x7016, 0x701a, 0x704b, 0x5280, 0x007c,
2154 0x0e7e, 0x127e, 0x2091, 0x8000, 0x2009, 0xa32e, 0x210c, 0x81ff,
2155 0x00c0, 0x530b, 0x2009, 0xa30c, 0x210c, 0xd194, 0x00c0, 0x5315,
2156 0x6848, 0x2070, 0xae82, 0xaa00, 0x0048, 0x52fb, 0x2001, 0xa315,
2157 0x2004, 0xae02, 0x00c8, 0x52fb, 0x2061, 0xa62d, 0x6100, 0xa184,
2158 0x0301, 0xa086, 0x0001, 0x00c0, 0x52de, 0x711c, 0xa186, 0x0006,
2159 0x00c0, 0x52e6, 0x7018, 0xa005, 0x0040, 0x530b, 0x2004, 0xd0e4,
2160 0x00c0, 0x530f, 0x7024, 0xd0dc, 0x00c0, 0x5319, 0x6853, 0x0000,
2161 0x6803, 0x0000, 0x2d08, 0x7010, 0xa005, 0x00c0, 0x52ca, 0x7112,
2162 0x684c, 0xd0f4, 0x00c0, 0x531d, 0x2e60, 0x1078, 0x59b6, 0x127f,
2163 0x0e7f, 0x007c, 0x2068, 0x6800, 0xa005, 0x00c0, 0x52ca, 0x6902,
2164 0x2168, 0x684c, 0xd0f4, 0x00c0, 0x531d, 0x127f, 0x0e7f, 0x007c,
2165 0x127f, 0x0e7f, 0x6853, 0x0006, 0x0078, 0x533e, 0xd184, 0x0040,
2166 0x52d8, 0xd1c4, 0x00c0, 0x52ff, 0x0078, 0x5303, 0x6944, 0xa18c,
2167 0xff00, 0x810f, 0x1078, 0x4501, 0x00c0, 0x530f, 0x6000, 0xd0e4,
2168 0x00c0, 0x530f, 0x711c, 0xa186, 0x0007, 0x00c0, 0x52fb, 0x6853,
2169 0x0002, 0x0078, 0x5311, 0x6853, 0x0008, 0x0078, 0x5311, 0x6853,
2170 0x000e, 0x0078, 0x5311, 0x6853, 0x0017, 0x0078, 0x5311, 0x6853,
2171 0x0035, 0x0078, 0x5311, 0x6853, 0x0028, 0x0078, 0x5311, 0x6853,
2172 0x0029, 0x127f, 0x0e7f, 0x0078, 0x533e, 0x6853, 0x002a, 0x0078,
2173 0x5311, 0x6853, 0x0045, 0x0078, 0x5311, 0x2e60, 0x2019, 0x0002,
2174 0x6017, 0x0014, 0x1078, 0x9a6a, 0x127f, 0x0e7f, 0x007c, 0x2009,
2175 0x003e, 0x0078, 0x5339, 0x2009, 0x0004, 0x0078, 0x5339, 0x2009,
2176 0x0006, 0x0078, 0x5339, 0x2009, 0x0016, 0x0078, 0x5339, 0x2009,
2177 0x0001, 0x6854, 0xa084, 0xff00, 0xa105, 0x6856, 0x2091, 0x8000,
2178 0x1078, 0x4982, 0x2091, 0x8001, 0x007c, 0x1078, 0x139a, 0x007c,
2179 0x702c, 0x7130, 0x8108, 0xa102, 0x0048, 0x5355, 0xa00e, 0x7034,
2180 0x7072, 0x7038, 0x7076, 0x0078, 0x5361, 0x7070, 0xa080, 0x0040,
2181 0x7072, 0x00c8, 0x5361, 0x7074, 0xa081, 0x0000, 0x7076, 0xa085,
2182 0x0001, 0x7932, 0x7132, 0x007c, 0x0d7e, 0x1078, 0x59ad, 0x0d7f,
2183 0x007c, 0x0d7e, 0x2011, 0x0004, 0x2204, 0xa085, 0x8002, 0x2012,
2184 0x0d7f, 0x007c, 0x20e1, 0x0002, 0x3d08, 0x20e1, 0x2000, 0x3d00,
2185 0xa084, 0x7000, 0x0040, 0x5380, 0xa086, 0x1000, 0x00c0, 0x53ac,
2186 0x20e1, 0x0000, 0x3d00, 0xa094, 0xff00, 0x8217, 0xa084, 0xf000,
2187 0xa086, 0x3000, 0x00c0, 0x5390, 0x1078, 0x5570, 0x0078, 0x53a7,
2188 0x20e1, 0x0004, 0x3d60, 0xd1bc, 0x00c0, 0x5397, 0x3e60, 0xac84,
2189 0x000f, 0x00c0, 0x53ac, 0xac82, 0xaa00, 0x0048, 0x53ac, 0x6854,
2190 0xac02, 0x00c8, 0x53ac, 0x2009, 0x0047, 0x1078, 0x756c, 0x7a1c,
2191 0xd284, 0x00c0, 0x5372, 0x007c, 0xa016, 0x1078, 0x15ec, 0x0078,
2192 0x53a7, 0x0078, 0x53ac, 0x781c, 0xd08c, 0x0040, 0x53db, 0x157e,
2193 0x137e, 0x147e, 0x20e1, 0x3000, 0x3d20, 0x3e28, 0xa584, 0x0076,
2194 0x00c0, 0x53f1, 0xa484, 0x7000, 0xa086, 0x1000, 0x00c0, 0x53e0,
2195 0x1078, 0x540c, 0x0040, 0x53f1, 0x20e1, 0x3000, 0x7828, 0x7828,
2196 0x1078, 0x542a, 0x147f, 0x137f, 0x157f, 0x2009, 0xa5b3, 0x2104,
2197 0xa005, 0x00c0, 0x53dc, 0x007c, 0x1078, 0x6109, 0x0078, 0x53db,
2198 0xa484, 0x7000, 0x00c0, 0x53f1, 0x1078, 0x540c, 0x0040, 0x5403,
2199 0x7000, 0xa084, 0xff00, 0xa086, 0x8100, 0x0040, 0x53cc, 0x0078,
2200 0x5403, 0x1078, 0xa1ee, 0xd5a4, 0x0040, 0x53ff, 0x1078, 0x1af7,
2201 0x20e1, 0x9010, 0x2001, 0x0138, 0x2202, 0x0078, 0x5407, 0x1078,
2202 0x540c, 0x687f, 0x0000, 0x20e1, 0x3000, 0x7828, 0x7828, 0x147f,
2203 0x137f, 0x157f, 0x0078, 0x53db, 0xa484, 0x01ff, 0x687e, 0xa005,
2204 0x0040, 0x541e, 0xa080, 0x001f, 0xa084, 0x03f8, 0x80ac, 0x20e1,
2205 0x1000, 0x2ea0, 0x2099, 0x020a, 0x53a5, 0x007c, 0x20a9, 0x000c,
2206 0x20e1, 0x1000, 0x2ea0, 0x2099, 0x020a, 0x53a5, 0xa085, 0x0001,
2207 0x0078, 0x541d, 0x7000, 0xa084, 0xff00, 0xa08c, 0xf000, 0x8007,
2208 0xa196, 0x0000, 0x00c0, 0x5437, 0x0078, 0x567c, 0x007c, 0xa196,
2209 0x2000, 0x00c0, 0x5448, 0x6900, 0xa18e, 0x0001, 0x00c0, 0x5444,
2210 0x1078, 0x3a43, 0x0078, 0x5436, 0x1078, 0x5450, 0x0078, 0x5436,
2211 0xa196, 0x8000, 0x00c0, 0x5436, 0x1078, 0x570c, 0x0078, 0x5436,
2212 0x0c7e, 0x7110, 0xa18c, 0xff00, 0x810f, 0xa196, 0x0001, 0x0040,
2213 0x545d, 0xa196, 0x0023, 0x00c0, 0x5568, 0xa08e, 0x0023, 0x00c0,
2214 0x5492, 0x1078, 0x57b2, 0x0040, 0x5568, 0x7124, 0x610a, 0x7030,
2215 0xa08e, 0x0200, 0x00c0, 0x5476, 0x7034, 0xa005, 0x00c0, 0x5568,
2216 0x2009, 0x0015, 0x1078, 0x756c, 0x0078, 0x5568, 0xa08e, 0x0214,
2217 0x0040, 0x547e, 0xa08e, 0x0210, 0x00c0, 0x5484, 0x2009, 0x0015,
2218 0x1078, 0x756c, 0x0078, 0x5568, 0xa08e, 0x0100, 0x00c0, 0x5568,
2219 0x7034, 0xa005, 0x00c0, 0x5568, 0x2009, 0x0016, 0x1078, 0x756c,
2220 0x0078, 0x5568, 0xa08e, 0x0022, 0x00c0, 0x5568, 0x7030, 0xa08e,
2221 0x0300, 0x00c0, 0x54a3, 0x7034, 0xa005, 0x00c0, 0x5568, 0x2009,
2222 0x0017, 0x0078, 0x5534, 0xa08e, 0x0500, 0x00c0, 0x54af, 0x7034,
2223 0xa005, 0x00c0, 0x5568, 0x2009, 0x0018, 0x0078, 0x5534, 0xa08e,
2224 0x2010, 0x00c0, 0x54b7, 0x2009, 0x0019, 0x0078, 0x5534, 0xa08e,
2225 0x2110, 0x00c0, 0x54bf, 0x2009, 0x001a, 0x0078, 0x5534, 0xa08e,
2226 0x5200, 0x00c0, 0x54cb, 0x7034, 0xa005, 0x00c0, 0x5568, 0x2009,
2227 0x001b, 0x0078, 0x5534, 0xa08e, 0x5000, 0x00c0, 0x54d7, 0x7034,
2228 0xa005, 0x00c0, 0x5568, 0x2009, 0x001c, 0x0078, 0x5534, 0xa08e,
2229 0x1300, 0x00c0, 0x54df, 0x2009, 0x0034, 0x0078, 0x5534, 0xa08e,
2230 0x1200, 0x00c0, 0x54eb, 0x7034, 0xa005, 0x00c0, 0x5568, 0x2009,
2231 0x0024, 0x0078, 0x5534, 0xa08c, 0xff00, 0xa18e, 0x2400, 0x00c0,
2232 0x54f5, 0x2009, 0x002d, 0x0078, 0x5534, 0xa08c, 0xff00, 0xa18e,
2233 0x5300, 0x00c0, 0x54ff, 0x2009, 0x002a, 0x0078, 0x5534, 0xa08e,
2234 0x0f00, 0x00c0, 0x5507, 0x2009, 0x0020, 0x0078, 0x5534, 0xa08e,
2235 0x5300, 0x00c0, 0x550d, 0x0078, 0x552a, 0xa08e, 0x6104, 0x00c0,
2236 0x552a, 0x2011, 0xa88d, 0x8208, 0x2204, 0xa082, 0x0004, 0x20a8,
2237 0x95ac, 0x95ac, 0x2011, 0x8015, 0x211c, 0x8108, 0x047e, 0x2124,
2238 0x1078, 0x3579, 0x047f, 0x8108, 0x00f0, 0x551a, 0x2009, 0x0023,
2239 0x0078, 0x5534, 0xa08e, 0x6000, 0x00c0, 0x5532, 0x2009, 0x003f,
2240 0x0078, 0x5534, 0x2009, 0x001d, 0x017e, 0x2011, 0xa883, 0x2204,
2241 0x8211, 0x220c, 0x1078, 0x24e3, 0x00c0, 0x556a, 0x1078, 0x4499,
2242 0x00c0, 0x556a, 0x6612, 0x6516, 0x86ff, 0x0040, 0x555a, 0x017f,
2243 0x017e, 0xa186, 0x0017, 0x00c0, 0x555a, 0x6868, 0xa606, 0x00c0,
2244 0x555a, 0x686c, 0xa506, 0xa084, 0xff00, 0x00c0, 0x555a, 0x6000,
2245 0xc0f5, 0x6002, 0x0c7e, 0x1078, 0x74d7, 0x0040, 0x556d, 0x017f,
2246 0x611a, 0x601f, 0x0004, 0x7120, 0x610a, 0x017f, 0x1078, 0x756c,
2247 0x0c7f, 0x007c, 0x017f, 0x0078, 0x5568, 0x0c7f, 0x0078, 0x556a,
2248 0x0c7e, 0x1078, 0x55d4, 0x00c0, 0x55d2, 0xa184, 0xff00, 0x8007,
2249 0xa086, 0x0008, 0x00c0, 0x55d2, 0xa28e, 0x0033, 0x00c0, 0x55a3,
2250 0x1078, 0x57b2, 0x0040, 0x55d2, 0x7124, 0x610a, 0x7030, 0xa08e,
2251 0x0200, 0x00c0, 0x5595, 0x7034, 0xa005, 0x00c0, 0x55d2, 0x2009,
2252 0x0015, 0x1078, 0x756c, 0x0078, 0x55d2, 0xa08e, 0x0100, 0x00c0,
2253 0x55d2, 0x7034, 0xa005, 0x00c0, 0x55d2, 0x2009, 0x0016, 0x1078,
2254 0x756c, 0x0078, 0x55d2, 0xa28e, 0x0032, 0x00c0, 0x55d2, 0x7030,
2255 0xa08e, 0x1400, 0x00c0, 0x55d2, 0x2009, 0x0038, 0x017e, 0x2011,
2256 0xa883, 0x2204, 0x8211, 0x220c, 0x1078, 0x24e3, 0x00c0, 0x55d1,
2257 0x1078, 0x4499, 0x00c0, 0x55d1, 0x6612, 0x6516, 0x0c7e, 0x1078,
2258 0x74d7, 0x0040, 0x55d0, 0x017f, 0x611a, 0x601f, 0x0004, 0x7120,
2259 0x610a, 0x017f, 0x1078, 0x756c, 0x1078, 0x6109, 0x0078, 0x55d2,
2260 0x0c7f, 0x017f, 0x0c7f, 0x007c, 0x0f7e, 0x0d7e, 0x027e, 0x017e,
2261 0x137e, 0x147e, 0x157e, 0x3c00, 0x007e, 0x2079, 0x0030, 0x2069,
2262 0x0200, 0x1078, 0x1c25, 0x00c0, 0x5615, 0x1078, 0x1b15, 0x0040,
2263 0x561f, 0x7908, 0xa18c, 0x1fff, 0xa182, 0x0011, 0x00c8, 0x561f,
2264 0x20a9, 0x000c, 0x20e1, 0x0000, 0x2ea0, 0x2099, 0x020a, 0x53a5,
2265 0x20e1, 0x2000, 0x2001, 0x020a, 0x2004, 0x7a0c, 0x7808, 0xa080,
2266 0x0007, 0xa084, 0x1ff8, 0xa08a, 0x0140, 0x10c8, 0x1328, 0x80ac,
2267 0x20e1, 0x6000, 0x2099, 0x020a, 0x53a5, 0x20e1, 0x7000, 0x6828,
2268 0x6828, 0x7803, 0x0004, 0xa294, 0x0070, 0x007f, 0x20e0, 0x157f,
2269 0x147f, 0x137f, 0x017f, 0x027f, 0x0d7f, 0x0f7f, 0x007c, 0xa085,
2270 0x0001, 0x0078, 0x5615, 0x047e, 0x0e7e, 0x0d7e, 0x2028, 0x2130,
2271 0xa696, 0x00ff, 0x00c0, 0x5644, 0xa596, 0xfffd, 0x00c0, 0x5634,
2272 0x2009, 0x007f, 0x0078, 0x5677, 0xa596, 0xfffe, 0x00c0, 0x563c,
2273 0x2009, 0x007e, 0x0078, 0x5677, 0xa596, 0xfffc, 0x00c0, 0x5644,
2274 0x2009, 0x0080, 0x0078, 0x5677, 0x2011, 0x0000, 0x2021, 0x0081,
2275 0x20a9, 0x007e, 0x2071, 0xa4b5, 0x2e1c, 0x83ff, 0x00c0, 0x5656,
2276 0x82ff, 0x00c0, 0x566b, 0x2410, 0x0078, 0x566b, 0x2368, 0x6f10,
2277 0x007e, 0x2100, 0xa706, 0x007f, 0x6b14, 0x00c0, 0x5665, 0xa346,
2278 0x00c0, 0x5665, 0x2408, 0x0078, 0x5677, 0x87ff, 0x00c0, 0x566b,
2279 0x83ff, 0x0040, 0x5650, 0x8420, 0x8e70, 0x00f0, 0x564c, 0x82ff,
2280 0x00c0, 0x5676, 0xa085, 0x0001, 0x0078, 0x5678, 0x2208, 0xa006,
2281 0x0d7f, 0x0e7f, 0x047f, 0x007c, 0xa084, 0x0007, 0x0079, 0x5681,
2282 0x007c, 0x5689, 0x5689, 0x5689, 0x57c8, 0x5689, 0x568a, 0x56a3,
2283 0x56f3, 0x007c, 0x7110, 0xd1bc, 0x0040, 0x56a2, 0x7120, 0x2160,
2284 0xac8c, 0x000f, 0x00c0, 0x56a2, 0xac8a, 0xaa00, 0x0048, 0x56a2,
2285 0x6854, 0xac02, 0x00c8, 0x56a2, 0x7124, 0x610a, 0x2009, 0x0046,
2286 0x1078, 0x756c, 0x007c, 0x0c7e, 0x7110, 0xd1bc, 0x00c0, 0x56f1,
2287 0x2011, 0xa883, 0x2204, 0x8211, 0x220c, 0x1078, 0x24e3, 0x00c0,
2288 0x56f1, 0x1078, 0x4499, 0x00c0, 0x56f1, 0x6612, 0x6516, 0x6000,
2289 0xd0ec, 0x00c0, 0x56f1, 0x6204, 0xa294, 0xff00, 0x8217, 0xa286,
2290 0x0006, 0x00c0, 0x56d6, 0x0c7e, 0x1078, 0x74d7, 0x017f, 0x0040,
2291 0x56f1, 0x611a, 0x601f, 0x0006, 0x7120, 0x610a, 0x7130, 0x6122,
2292 0x2009, 0x0044, 0x1078, 0x756c, 0x0078, 0x56f1, 0x0c7e, 0x1078,
2293 0x74d7, 0x017f, 0x0040, 0x56f1, 0x611a, 0x601f, 0x0004, 0x7120,
2294 0x610a, 0xa286, 0x0004, 0x00c0, 0x56e9, 0x6007, 0x0005, 0x0078,
2295 0x56eb, 0x6007, 0x0001, 0x6003, 0x0001, 0x1078, 0x5c45, 0x1078,
2296 0x6109, 0x0c7f, 0x007c, 0x7110, 0xd1bc, 0x0040, 0x570b, 0x7020,
2297 0x2060, 0xac84, 0x000f, 0x00c0, 0x570b, 0xac82, 0xaa00, 0x0048,
2298 0x570b, 0x6854, 0xac02, 0x00c8, 0x570b, 0x7124, 0x610a, 0x2009,
2299 0x0045, 0x1078, 0x756c, 0x007c, 0x7110, 0xa18c, 0xff00, 0x810f,
2300 0xa18e, 0x0000, 0x00c0, 0x571c, 0xa084, 0x000f, 0xa08a, 0x0006,
2301 0x00c8, 0x571c, 0x1079, 0x571d, 0x007c, 0x5723, 0x5724, 0x5723,
2302 0x5723, 0x5794, 0x57a3, 0x007c, 0x7110, 0xd1bc, 0x0040, 0x572c,
2303 0x702c, 0xd084, 0x0040, 0x5793, 0x700c, 0x7108, 0x1078, 0x24e3,
2304 0x00c0, 0x5793, 0x1078, 0x4499, 0x00c0, 0x5793, 0x6612, 0x6516,
2305 0x6204, 0x7110, 0xd1bc, 0x0040, 0x575e, 0xa28c, 0x00ff, 0xa186,
2306 0x0004, 0x0040, 0x5747, 0xa186, 0x0006, 0x00c0, 0x5784, 0x0c7e,
2307 0x1078, 0x57b2, 0x0c7f, 0x0040, 0x5793, 0x0c7e, 0x1078, 0x74d7,
2308 0x017f, 0x0040, 0x5793, 0x611a, 0x601f, 0x0002, 0x7120, 0x610a,
2309 0x2009, 0x0088, 0x1078, 0x756c, 0x0078, 0x5793, 0xa28c, 0x00ff,
2310 0xa186, 0x0006, 0x0040, 0x5773, 0xa186, 0x0004, 0x0040, 0x5773,
2311 0xa294, 0xff00, 0x8217, 0xa286, 0x0004, 0x0040, 0x5773, 0xa286,
2312 0x0006, 0x00c0, 0x5784, 0x0c7e, 0x1078, 0x74d7, 0x017f, 0x0040,
2313 0x5793, 0x611a, 0x601f, 0x0005, 0x7120, 0x610a, 0x2009, 0x0088,
2314 0x1078, 0x756c, 0x0078, 0x5793, 0x0c7e, 0x1078, 0x74d7, 0x017f,
2315 0x0040, 0x5793, 0x611a, 0x601f, 0x0004, 0x7120, 0x610a, 0x2009,
2316 0x0001, 0x1078, 0x756c, 0x007c, 0x7110, 0xd1bc, 0x0040, 0x57a2,
2317 0x1078, 0x57b2, 0x0040, 0x57a2, 0x7124, 0x610a, 0x2009, 0x0089,
2318 0x1078, 0x756c, 0x007c, 0x7110, 0xd1bc, 0x0040, 0x57b1, 0x1078,
2319 0x57b2, 0x0040, 0x57b1, 0x7124, 0x610a, 0x2009, 0x008a, 0x1078,
2320 0x756c, 0x007c, 0x7020, 0x2060, 0xac84, 0x000f, 0x00c0, 0x57c5,
2321 0xac82, 0xaa00, 0x0048, 0x57c5, 0x2001, 0xa315, 0x2004, 0xac02,
2322 0x00c8, 0x57c5, 0xa085, 0x0001, 0x007c, 0xa006, 0x0078, 0x57c4,
2323 0x7110, 0xd1bc, 0x00c0, 0x57de, 0x7024, 0x2060, 0xac84, 0x000f,
2324 0x00c0, 0x57de, 0xac82, 0xaa00, 0x0048, 0x57de, 0x6854, 0xac02,
2325 0x00c8, 0x57de, 0x2009, 0x0051, 0x1078, 0x756c, 0x007c, 0x2071,
2326 0xa5be, 0x7003, 0x0003, 0x700f, 0x0361, 0xa006, 0x701a, 0x7012,
2327 0x7017, 0xaa00, 0x7007, 0x0000, 0x7026, 0x702b, 0x6c4e, 0x7032,
2328 0x7037, 0x6ca0, 0x703b, 0x0002, 0x703f, 0x0000, 0x7043, 0xffff,
2329 0x7047, 0xffff, 0x007c, 0x2071, 0xa5be, 0x00e0, 0x58c1, 0x2091,
2330 0x6000, 0x700c, 0x8001, 0x700e, 0x00c0, 0x5873, 0x700f, 0x0361,
2331 0x7007, 0x0001, 0x127e, 0x2091, 0x8000, 0x7138, 0x8109, 0x713a,
2332 0x00c0, 0x5871, 0x703b, 0x0002, 0x2009, 0x0100, 0x2104, 0xa082,
2333 0x0003, 0x00c8, 0x5871, 0x703c, 0xa086, 0x0001, 0x00c0, 0x584e,
2334 0x0d7e, 0x2069, 0x0140, 0x6804, 0xa084, 0x4000, 0x0040, 0x582c,
2335 0x6803, 0x1000, 0x0078, 0x5833, 0x6804, 0xa084, 0x1000, 0x0040,
2336 0x5833, 0x6803, 0x0100, 0x6803, 0x0000, 0x703f, 0x0000, 0x2069,
2337 0xa5ab, 0x6804, 0xa082, 0x0006, 0x00c0, 0x5840, 0x6807, 0x0000,
2338 0x6830, 0xa082, 0x0003, 0x00c0, 0x5847, 0x6833, 0x0000, 0x1078,
2339 0x6109, 0x1078, 0x61d3, 0x0d7f, 0x0078, 0x5871, 0x0d7e, 0x2069,
2340 0xa300, 0x6944, 0x6860, 0xa102, 0x00c8, 0x5870, 0x2069, 0xa5ab,
2341 0x6804, 0xa086, 0x0000, 0x00c0, 0x5870, 0x6830, 0xa086, 0x0000,
2342 0x00c0, 0x5870, 0x703f, 0x0001, 0x6807, 0x0006, 0x6833, 0x0003,
2343 0x2069, 0x0100, 0x6830, 0x689e, 0x2069, 0x0140, 0x6803, 0x0600,
2344 0x0d7f, 0x0078, 0x5876, 0x127e, 0x2091, 0x8000, 0x7024, 0xa00d,
2345 0x0040, 0x588e, 0x7020, 0x8001, 0x7022, 0x00c0, 0x588e, 0x7023,
2346 0x0009, 0x8109, 0x7126, 0xa186, 0x03e8, 0x00c0, 0x5889, 0x7028,
2347 0x107a, 0x81ff, 0x00c0, 0x588e, 0x7028, 0x107a, 0x7030, 0xa00d,
2348 0x0040, 0x589f, 0x702c, 0x8001, 0x702e, 0x00c0, 0x589f, 0x702f,
2349 0x0009, 0x8109, 0x7132, 0x00c0, 0x589f, 0x7034, 0x107a, 0x7040,
2350 0xa005, 0x0040, 0x58a7, 0x0050, 0x58a7, 0x8001, 0x7042, 0x7044,
2351 0xa005, 0x0040, 0x58af, 0x0050, 0x58af, 0x8001, 0x7046, 0x7018,
2352 0xa00d, 0x0040, 0x58c0, 0x7008, 0x8001, 0x700a, 0x00c0, 0x58c0,
2353 0x700b, 0x0009, 0x8109, 0x711a, 0x00c0, 0x58c0, 0x701c, 0x107a,
2354 0x127f, 0x7004, 0x0079, 0x58c4, 0x58eb, 0x58ec, 0x5908, 0x0e7e,
2355 0x2071, 0xa5be, 0x7018, 0xa005, 0x00c0, 0x58d2, 0x711a, 0x721e,
2356 0x700b, 0x0009, 0x0e7f, 0x007c, 0x0e7e, 0x007e, 0x2071, 0xa5be,
2357 0x701c, 0xa206, 0x00c0, 0x58de, 0x701a, 0x701e, 0x007f, 0x0e7f,
2358 0x007c, 0x0e7e, 0x2071, 0xa5be, 0x6088, 0xa102, 0x0048, 0x58e9,
2359 0x618a, 0x0e7f, 0x007c, 0x007c, 0x7110, 0x1078, 0x4501, 0x00c0,
2360 0x58fe, 0x6088, 0x8001, 0x0048, 0x58fe, 0x608a, 0x00c0, 0x58fe,
2361 0x127e, 0x2091, 0x8000, 0x1078, 0x6109, 0x127f, 0x8108, 0xa182,
2362 0x00ff, 0x0048, 0x5906, 0xa00e, 0x7007, 0x0002, 0x7112, 0x007c,
2363 0x7014, 0x2060, 0x127e, 0x2091, 0x8000, 0x603c, 0xa005, 0x0040,
2364 0x5917, 0x8001, 0x603e, 0x00c0, 0x5917, 0x1078, 0x8cd7, 0x6014,
2365 0xa005, 0x0040, 0x5941, 0x8001, 0x6016, 0x00c0, 0x5941, 0x611c,
2366 0xa186, 0x0003, 0x0040, 0x5928, 0xa186, 0x0006, 0x00c0, 0x593f,
2367 0x6010, 0x2068, 0x6854, 0xa08a, 0x199a, 0x0048, 0x593f, 0xa082,
2368 0x1999, 0x6856, 0xa08a, 0x199a, 0x0048, 0x5938, 0x2001, 0x1999,
2369 0x8003, 0x800b, 0x810b, 0xa108, 0x6116, 0x0078, 0x5941, 0x1078,
2370 0x8810, 0x127f, 0xac88, 0x0010, 0x7116, 0x2001, 0xca00, 0xa102,
2371 0x0048, 0x594e, 0x7017, 0xaa00, 0x7007, 0x0000, 0x007c, 0x0e7e,
2372 0x2071, 0xa5be, 0x7027, 0x07d0, 0x7023, 0x0009, 0x703b, 0x0002,
2373 0x0e7f, 0x007c, 0x2001, 0xa5c7, 0x2003, 0x0000, 0x007c, 0x0e7e,
2374 0x2071, 0xa5be, 0x7132, 0x702f, 0x0009, 0x0e7f, 0x007c, 0x2011,
2375 0xa5ca, 0x2013, 0x0000, 0x007c, 0x0e7e, 0x2071, 0xa5be, 0x711a,
2376 0x721e, 0x700b, 0x0009, 0x0e7f, 0x007c, 0x027e, 0x0e7e, 0x0f7e,
2377 0x2079, 0xa300, 0x7a34, 0xd294, 0x0040, 0x59a4, 0x2071, 0xa5aa,
2378 0x2e14, 0xa0fe, 0x0000, 0x0040, 0x5991, 0xa0fe, 0x0001, 0x0040,
2379 0x5995, 0xa0fe, 0x0002, 0x00c0, 0x59a0, 0xa292, 0x0085, 0x0078,
2380 0x5997, 0xa292, 0x0005, 0x0078, 0x5997, 0xa292, 0x0002, 0x2272,
2381 0x0040, 0x599c, 0x00c8, 0x59a4, 0x2011, 0x8037, 0x1078, 0x3579,
2382 0x2011, 0xa5a9, 0x2204, 0x2072, 0x0f7f, 0x0e7f, 0x027f, 0x007c,
2383 0x0c7e, 0x2061, 0xa62d, 0x0c7f, 0x007c, 0xa184, 0x000f, 0x8003,
2384 0x8003, 0x8003, 0xa080, 0xa62d, 0x2060, 0x007c, 0x6854, 0xa08a,
2385 0x199a, 0x0048, 0x59bd, 0x2001, 0x1999, 0xa005, 0x00c0, 0x59cc,
2386 0x0c7e, 0x2061, 0xa62d, 0x6014, 0x0c7f, 0xa005, 0x00c0, 0x59d1,
2387 0x2001, 0x001e, 0x0078, 0x59d1, 0xa08e, 0xffff, 0x00c0, 0x59d1,
2388 0xa006, 0x8003, 0x800b, 0x810b, 0xa108, 0x6116, 0x684c, 0xa08c,
2389 0x00c0, 0xa18e, 0x00c0, 0x0040, 0x5a24, 0xd0b4, 0x00c0, 0x59e8,
2390 0xd0bc, 0x00c0, 0x5a14, 0x2009, 0x0006, 0x1078, 0x5a43, 0x007c,
2391 0xd0fc, 0x0040, 0x59f3, 0xa084, 0x0003, 0x0040, 0x59f3, 0xa086,
2392 0x0003, 0x00c0, 0x5a3c, 0x6024, 0xd0d4, 0x0040, 0x59fd, 0xc0d4,
2393 0x6026, 0x6860, 0x602a, 0x685c, 0x602e, 0x2009, 0xa373, 0x2104,
2394 0xd084, 0x0040, 0x5a0f, 0x6118, 0xa188, 0x0027, 0x2104, 0xd08c,
2395 0x00c0, 0x5a0f, 0x2009, 0x0042, 0x1078, 0x756c, 0x007c, 0x2009,
2396 0x0043, 0x1078, 0x756c, 0x007c, 0xd0fc, 0x0040, 0x5a1f, 0xa084,
2397 0x0003, 0x0040, 0x5a1f, 0xa086, 0x0003, 0x00c0, 0x5a3c, 0x2009,
2398 0x0042, 0x1078, 0x756c, 0x007c, 0xd0fc, 0x0040, 0x5a32, 0xa084,
2399 0x0003, 0xa08e, 0x0002, 0x0040, 0x5a36, 0x2009, 0x0041, 0x1078,
2400 0x756c, 0x007c, 0x1078, 0x5a41, 0x0078, 0x5a31, 0x2009, 0x0043,
2401 0x1078, 0x756c, 0x0078, 0x5a31, 0x2009, 0x0004, 0x1078, 0x5a43,
2402 0x007c, 0x2009, 0x0001, 0x0d7e, 0x6010, 0xa0ec, 0xf000, 0x0040,
2403 0x5a6b, 0x2068, 0x6952, 0x6800, 0x6012, 0xa186, 0x0001, 0x00c0,
2404 0x5a65, 0x694c, 0xa18c, 0x8100, 0xa18e, 0x8100, 0x00c0, 0x5a65,
2405 0x0c7e, 0x2061, 0xa62d, 0x6200, 0xd28c, 0x00c0, 0x5a64, 0x6204,
2406 0x8210, 0x0048, 0x5a64, 0x6206, 0x0c7f, 0x1078, 0x4982, 0x6010,
2407 0xa06d, 0x10c0, 0x59b6, 0x0d7f, 0x007c, 0x157e, 0x0c7e, 0x2061,
2408 0xa62d, 0x6000, 0x81ff, 0x0040, 0x5a78, 0xa205, 0x0078, 0x5a79,
2409 0xa204, 0x6002, 0x0c7f, 0x157f, 0x007c, 0x6800, 0xd08c, 0x00c0,
2410 0x5a89, 0x6808, 0xa005, 0x0040, 0x5a89, 0x8001, 0x680a, 0xa085,
2411 0x0001, 0x007c, 0x20a9, 0x0010, 0xa006, 0x8004, 0x8086, 0x818e,
2412 0x00c8, 0x5a93, 0xa200, 0x00f0, 0x5a8e, 0x8086, 0x818e, 0x007c,
2413 0x157e, 0x20a9, 0x0010, 0xa005, 0x0040, 0x5ab9, 0xa11a, 0x00c8,
2414 0x5ab9, 0x8213, 0x818d, 0x0048, 0x5aac, 0xa11a, 0x00c8, 0x5aad,
2415 0x00f0, 0x5aa1, 0x0078, 0x5ab1, 0xa11a, 0x2308, 0x8210, 0x00f0,
2416 0x5aa1, 0x007e, 0x3200, 0xa084, 0xf7ff, 0x2080, 0x007f, 0x157f,
2417 0x007c, 0x007e, 0x3200, 0xa085, 0x0800, 0x0078, 0x5ab5, 0x127e,
2418 0x2091, 0x2200, 0x2079, 0xa5ab, 0x127f, 0x0d7e, 0x2069, 0xa5ab,
2419 0x6803, 0x0005, 0x2069, 0x0004, 0x2d04, 0xa085, 0x8001, 0x206a,
2420 0x0d7f, 0x007c, 0x0c7e, 0x6027, 0x0001, 0x7804, 0xa084, 0x0007,
2421 0x0079, 0x5ada, 0x5ae4, 0x5b09, 0x5b64, 0x5aea, 0x5b09, 0x5ae4,
2422 0x5ae2, 0x5ae2, 0x1078, 0x1328, 0x1078, 0x595a, 0x1078, 0x6109,
2423 0x0c7f, 0x007c, 0x62c0, 0x82ff, 0x00c0, 0x5af0, 0x0c7f, 0x007c,
2424 0x2011, 0x4129, 0x1078, 0x58d4, 0x7828, 0xa092, 0x00c8, 0x00c8,
2425 0x5aff, 0x8000, 0x782a, 0x1078, 0x4168, 0x0078, 0x5aee, 0x1078,
2426 0x4129, 0x7807, 0x0003, 0x7827, 0x0000, 0x782b, 0x0000, 0x0078,
2427 0x5aee, 0x1078, 0x595a, 0x3c00, 0x007e, 0x2011, 0x0209, 0x20e1,
2428 0x4000, 0x2214, 0x007f, 0x20e0, 0x82ff, 0x0040, 0x5b27, 0x62c0,
2429 0x82ff, 0x00c0, 0x5b27, 0x782b, 0x0000, 0x7824, 0xa065, 0x1040,
2430 0x1328, 0x2009, 0x0013, 0x1078, 0x756c, 0x0c7f, 0x007c, 0x3900,
2431 0xa082, 0xa6cd, 0x00c8, 0x5b2e, 0x1078, 0x728a, 0x0c7e, 0x7824,
2432 0xa065, 0x1040, 0x1328, 0x7804, 0xa086, 0x0004, 0x0040, 0x5ba9,
2433 0x7828, 0xa092, 0x2710, 0x00c8, 0x5b44, 0x8000, 0x782a, 0x0c7f,
2434 0x1078, 0x6c33, 0x0078, 0x5b25, 0x6104, 0xa186, 0x0003, 0x00c0,
2435 0x5b5b, 0x0e7e, 0x2071, 0xa300, 0x70d4, 0x0e7f, 0xd08c, 0x0040,
2436 0x5b5b, 0x0c7e, 0x0e7e, 0x2061, 0x0100, 0x2071, 0xa300, 0x1078,
2437 0x4171, 0x0e7f, 0x0c7f, 0x1078, 0xa241, 0x2009, 0x0014, 0x1078,
2438 0x756c, 0x0c7f, 0x0078, 0x5b25, 0x2001, 0xa5c7, 0x2003, 0x0000,
2439 0x62c0, 0x82ff, 0x00c0, 0x5b78, 0x782b, 0x0000, 0x7824, 0xa065,
2440 0x1040, 0x1328, 0x2009, 0x0013, 0x1078, 0x75c3, 0x0c7f, 0x007c,
2441 0x0c7e, 0x0d7e, 0x3900, 0xa082, 0xa6cd, 0x00c8, 0x5b81, 0x1078,
2442 0x728a, 0x7824, 0xa005, 0x1040, 0x1328, 0x781c, 0xa06d, 0x1040,
2443 0x1328, 0x6800, 0xc0dc, 0x6802, 0x7924, 0x2160, 0x1078, 0x753d,
2444 0x693c, 0x81ff, 0x1040, 0x1328, 0x8109, 0x693e, 0x6854, 0xa015,
2445 0x0040, 0x5b9d, 0x7a1e, 0x0078, 0x5b9f, 0x7918, 0x791e, 0x7807,
2446 0x0000, 0x7827, 0x0000, 0x0d7f, 0x0c7f, 0x1078, 0x6109, 0x0078,
2447 0x5b76, 0x6104, 0xa186, 0x0002, 0x0040, 0x5bb4, 0xa186, 0x0004,
2448 0x0040, 0x5bb4, 0x0078, 0x5b38, 0x7808, 0xac06, 0x0040, 0x5b38,
2449 0x1078, 0x6010, 0x1078, 0x5c45, 0x0c7f, 0x1078, 0x6109, 0x0078,
2450 0x5b25, 0x0c7e, 0x6027, 0x0002, 0x62c8, 0x82ff, 0x00c0, 0x5bdb,
2451 0x62c4, 0x82ff, 0x00c0, 0x5bdb, 0x793c, 0xa1e5, 0x0000, 0x0040,
2452 0x5bd5, 0x2009, 0x0049, 0x1078, 0x756c, 0x2011, 0xa5ca, 0x2013,
2453 0x0000, 0x0c7f, 0x007c, 0x3908, 0xa192, 0xa6cd, 0x00c8, 0x5be2,
2454 0x1078, 0x728a, 0x6017, 0x0010, 0x793c, 0x81ff, 0x0040, 0x5bd5,
2455 0x793c, 0xa188, 0x0007, 0x210c, 0xa18e, 0x0006, 0x00c0, 0x5bf4,
2456 0x6017, 0x0012, 0x0078, 0x5bd9, 0x6017, 0x0016, 0x0078, 0x5bd9,
2457 0x007e, 0x017e, 0x0c7e, 0x127e, 0x2091, 0x8000, 0x600f, 0x0000,
2458 0x2c08, 0x2061, 0xa5ab, 0x6020, 0x8000, 0x6022, 0x6010, 0xa005,
2459 0x0040, 0x5c13, 0xa080, 0x0003, 0x2102, 0x6112, 0x127f, 0x0c7f,
2460 0x017f, 0x007f, 0x007c, 0x6116, 0x6112, 0x0078, 0x5c0e, 0x0d7e,
2461 0x2069, 0xa5ab, 0x6000, 0xd0d4, 0x0040, 0x5c2c, 0x6820, 0x8000,
2462 0x6822, 0xa086, 0x0001, 0x00c0, 0x5c27, 0x2c00, 0x681e, 0x6804,
2463 0xa084, 0x0007, 0x0079, 0x6111, 0xc0d5, 0x6002, 0x6818, 0xa005,
2464 0x0040, 0x5c3e, 0x6056, 0x605b, 0x0000, 0x007e, 0x2c00, 0x681a,
2465 0x0d7f, 0x685a, 0x2069, 0xa5ab, 0x0078, 0x5c1e, 0x6056, 0x605a,
2466 0x2c00, 0x681a, 0x681e, 0x0078, 0x5c1e, 0x007e, 0x017e, 0x0c7e,
2467 0x127e, 0x2091, 0x8000, 0x600f, 0x0000, 0x2c08, 0x2061, 0xa5ab,
2468 0x6020, 0x8000, 0x6022, 0x6008, 0xa005, 0x0040, 0x5c60, 0xa080,
2469 0x0003, 0x2102, 0x610a, 0x127f, 0x0c7f, 0x017f, 0x007f, 0x007c,
2470 0x610e, 0x610a, 0x0078, 0x5c5b, 0x0c7e, 0x600f, 0x0000, 0x2c08,
2471 0x2061, 0xa5ab, 0x6034, 0xa005, 0x0040, 0x5c74, 0xa080, 0x0003,
2472 0x2102, 0x6136, 0x0c7f, 0x007c, 0x613a, 0x6136, 0x0078, 0x5c72,
2473 0x0f7e, 0x0e7e, 0x0d7e, 0x0c7e, 0x067e, 0x027e, 0x017e, 0x007e,
2474 0x127e, 0x2071, 0xa5ab, 0x7638, 0x2660, 0x2678, 0x2091, 0x8000,
2475 0x8cff, 0x0040, 0x5ced, 0x6018, 0xa080, 0x0028, 0x2004, 0xa206,
2476 0x00c0, 0x5ce8, 0x87ff, 0x0040, 0x5c99, 0x6020, 0xa106, 0x00c0,
2477 0x5ce8, 0x703c, 0xac06, 0x00c0, 0x5cab, 0x037e, 0x2019, 0x0001,
2478 0x1078, 0x6e6c, 0x7033, 0x0000, 0x703f, 0x0000, 0x7043, 0x0000,
2479 0x7047, 0x0000, 0x037f, 0x7038, 0xac36, 0x00c0, 0x5cb1, 0x660c,
2480 0x763a, 0x7034, 0xac36, 0x00c0, 0x5cbf, 0x2c00, 0xaf36, 0x0040,
2481 0x5cbd, 0x2f00, 0x7036, 0x0078, 0x5cbf, 0x7037, 0x0000, 0x660c,
2482 0x067e, 0x2c00, 0xaf06, 0x0040, 0x5cc8, 0x7e0e, 0x0078, 0x5cc9,
2483 0x2678, 0x600f, 0x0000, 0x1078, 0x8a44, 0x0040, 0x5ce3, 0x6010,
2484 0x2068, 0x601c, 0xa086, 0x0003, 0x00c0, 0x5cf7, 0x6837, 0x0103,
2485 0x6b4a, 0x6847, 0x0000, 0x1078, 0x8cb8, 0x1078, 0xa181, 0x1078,
2486 0x4982, 0x1078, 0x8bf4, 0x1078, 0x8c01, 0x0c7f, 0x0078, 0x5c88,
2487 0x2c78, 0x600c, 0x2060, 0x0078, 0x5c88, 0x127f, 0x007f, 0x017f,
2488 0x027f, 0x067f, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f, 0x007c, 0x601c,
2489 0xa086, 0x0006, 0x00c0, 0x5cd6, 0x1078, 0xa181, 0x1078, 0x9e70,
2490 0x0078, 0x5ce3, 0x007e, 0x067e, 0x0c7e, 0x0d7e, 0x0f7e, 0x2031,
2491 0x0000, 0x127e, 0x2091, 0x8000, 0x2079, 0xa5ab, 0x7838, 0xa065,
2492 0x0040, 0x5d41, 0x600c, 0x007e, 0x600f, 0x0000, 0x783c, 0xac06,
2493 0x00c0, 0x5d28, 0x037e, 0x2019, 0x0001, 0x1078, 0x6e6c, 0x7833,
2494 0x0000, 0x783f, 0x0000, 0x7843, 0x0000, 0x7847, 0x0000, 0x037f,
2495 0x1078, 0x8a44, 0x0040, 0x5d3c, 0x6010, 0x2068, 0x601c, 0xa086,
2496 0x0003, 0x00c0, 0x5d4a, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000,
2497 0x1078, 0x4982, 0x1078, 0x8bf4, 0x1078, 0x8c01, 0x007f, 0x0078,
2498 0x5d0f, 0x7e3a, 0x7e36, 0x127f, 0x0f7f, 0x0d7f, 0x0c7f, 0x067f,
2499 0x007f, 0x007c, 0x601c, 0xa086, 0x0006, 0x00c0, 0x5d33, 0x1078,
2500 0x9e70, 0x0078, 0x5d3c, 0x017e, 0x027e, 0x087e, 0x2041, 0x0000,
2501 0x1078, 0x5d6d, 0x1078, 0x5e21, 0x087f, 0x027f, 0x017f, 0x007c,
2502 0x0f7e, 0x127e, 0x2079, 0xa5ab, 0x2091, 0x8000, 0x1078, 0x5ebc,
2503 0x1078, 0x5f32, 0x127f, 0x0f7f, 0x007c, 0x0f7e, 0x0e7e, 0x0d7e,
2504 0x0c7e, 0x067e, 0x017e, 0x007e, 0x127e, 0x2091, 0x8000, 0x2071,
2505 0xa5ab, 0x7614, 0x2660, 0x2678, 0x8cff, 0x0040, 0x5e01, 0x6018,
2506 0xa080, 0x0028, 0x2004, 0xa206, 0x00c0, 0x5dfc, 0x88ff, 0x0040,
2507 0x5d8d, 0x6020, 0xa106, 0x00c0, 0x5dfc, 0x7024, 0xac06, 0x00c0,
2508 0x5dbd, 0x2069, 0x0100, 0x68c0, 0xa005, 0x0040, 0x5db8, 0x1078,
2509 0x595a, 0x1078, 0x6c41, 0x68c3, 0x0000, 0x1078, 0x7188, 0x7027,
2510 0x0000, 0x037e, 0x2069, 0x0140, 0x6b04, 0xa384, 0x1000, 0x0040,
2511 0x5dad, 0x6803, 0x0100, 0x6803, 0x0000, 0x2069, 0x0100, 0x6824,
2512 0xd084, 0x0040, 0x5db5, 0x6827, 0x0001, 0x037f, 0x0078, 0x5dbd,
2513 0x6003, 0x0009, 0x630a, 0x0078, 0x5dfc, 0x7014, 0xac36, 0x00c0,
2514 0x5dc3, 0x660c, 0x7616, 0x7010, 0xac36, 0x00c0, 0x5dd1, 0x2c00,
2515 0xaf36, 0x0040, 0x5dcf, 0x2f00, 0x7012, 0x0078, 0x5dd1, 0x7013,
2516 0x0000, 0x660c, 0x067e, 0x2c00, 0xaf06, 0x0040, 0x5dda, 0x7e0e,
2517 0x0078, 0x5ddb, 0x2678, 0x600f, 0x0000, 0x6010, 0x2068, 0x1078,
2518 0x8a44, 0x0040, 0x5df5, 0x601c, 0xa086, 0x0003, 0x00c0, 0x5e0a,
2519 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x1078, 0x8cb8, 0x1078,
2520 0xa181, 0x1078, 0x4982, 0x1078, 0x8bf4, 0x1078, 0x8c01, 0x1078,
2521 0x7045, 0x0c7f, 0x0078, 0x5d7c, 0x2c78, 0x600c, 0x2060, 0x0078,
2522 0x5d7c, 0x127f, 0x007f, 0x017f, 0x067f, 0x0c7f, 0x0d7f, 0x0e7f,
2523 0x0f7f, 0x007c, 0x601c, 0xa086, 0x0006, 0x00c0, 0x5e15, 0x1078,
2524 0xa181, 0x1078, 0x9e70, 0x0078, 0x5df5, 0x601c, 0xa086, 0x0002,
2525 0x00c0, 0x5df5, 0x6004, 0xa086, 0x0085, 0x0040, 0x5de8, 0x0078,
2526 0x5df5, 0x0c7e, 0x007e, 0x127e, 0x2091, 0x8000, 0xa280, 0xa434,
2527 0x2004, 0xa065, 0x0040, 0x5eb8, 0x0f7e, 0x0e7e, 0x0d7e, 0x067e,
2528 0x2071, 0xa5ab, 0x6654, 0x7018, 0xac06, 0x00c0, 0x5e38, 0x761a,
2529 0x701c, 0xac06, 0x00c0, 0x5e44, 0x86ff, 0x00c0, 0x5e43, 0x7018,
2530 0x701e, 0x0078, 0x5e44, 0x761e, 0x6058, 0xa07d, 0x0040, 0x5e49,
2531 0x7e56, 0xa6ed, 0x0000, 0x0040, 0x5e4f, 0x2f00, 0x685a, 0x6057,
2532 0x0000, 0x605b, 0x0000, 0x6000, 0xc0d4, 0xc0dc, 0x6002, 0x1078,
2533 0x4410, 0x0040, 0x5eb4, 0x7624, 0x86ff, 0x0040, 0x5ea2, 0xa680,
2534 0x0004, 0x2004, 0xad06, 0x00c0, 0x5ea2, 0x0d7e, 0x2069, 0x0100,
2535 0x68c0, 0xa005, 0x0040, 0x5e99, 0x1078, 0x595a, 0x1078, 0x6c41,
2536 0x68c3, 0x0000, 0x1078, 0x7188, 0x7027, 0x0000, 0x037e, 0x2069,
2537 0x0140, 0x6b04, 0xa384, 0x1000, 0x0040, 0x5e82, 0x6803, 0x0100,
2538 0x6803, 0x0000, 0x2069, 0x0100, 0x6824, 0xd084, 0x0040, 0x5e8a,
2539 0x6827, 0x0001, 0x037f, 0x0d7f, 0x0c7e, 0x603c, 0xa005, 0x0040,
2540 0x5e93, 0x8001, 0x603e, 0x2660, 0x1078, 0x8c01, 0x0c7f, 0x0078,
2541 0x5ea2, 0x0d7f, 0x0c7e, 0x2660, 0x6003, 0x0009, 0x630a, 0x0c7f,
2542 0x0078, 0x5e57, 0x8dff, 0x0040, 0x5eb0, 0x6837, 0x0103, 0x6b4a,
2543 0x6847, 0x0000, 0x1078, 0x8cb8, 0x1078, 0xa181, 0x1078, 0x4982,
2544 0x1078, 0x7045, 0x0078, 0x5e57, 0x067f, 0x0d7f, 0x0e7f, 0x0f7f,
2545 0x127f, 0x007f, 0x0c7f, 0x007c, 0x007e, 0x067e, 0x0c7e, 0x0d7e,
2546 0x2031, 0x0000, 0x7814, 0xa065, 0x0040, 0x5f16, 0x600c, 0x007e,
2547 0x600f, 0x0000, 0x7824, 0xac06, 0x00c0, 0x5efb, 0x2069, 0x0100,
2548 0x68c0, 0xa005, 0x0040, 0x5ef5, 0x1078, 0x595a, 0x1078, 0x6c41,
2549 0x68c3, 0x0000, 0x1078, 0x7188, 0x7827, 0x0000, 0x037e, 0x2069,
2550 0x0140, 0x6b04, 0xa384, 0x1000, 0x0040, 0x5eea, 0x6803, 0x0100,
2551 0x6803, 0x0000, 0x2069, 0x0100, 0x6824, 0xd084, 0x0040, 0x5ef2,
2552 0x6827, 0x0001, 0x037f, 0x0078, 0x5efb, 0x6003, 0x0009, 0x630a,
2553 0x2c30, 0x0078, 0x5f13, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040,
2554 0x5f0f, 0x601c, 0xa086, 0x0003, 0x00c0, 0x5f1d, 0x6837, 0x0103,
2555 0x6b4a, 0x6847, 0x0000, 0x1078, 0x4982, 0x1078, 0x8bf4, 0x1078,
2556 0x8c01, 0x1078, 0x7045, 0x007f, 0x0078, 0x5ec3, 0x7e16, 0x7e12,
2557 0x0d7f, 0x0c7f, 0x067f, 0x007f, 0x007c, 0x601c, 0xa086, 0x0006,
2558 0x00c0, 0x5f26, 0x1078, 0x9e70, 0x0078, 0x5f0f, 0x601c, 0xa086,
2559 0x0002, 0x00c0, 0x5f0f, 0x6004, 0xa086, 0x0085, 0x0040, 0x5f06,
2560 0x0078, 0x5f0f, 0x007e, 0x067e, 0x0c7e, 0x0d7e, 0x7818, 0xa065,
2561 0x0040, 0x5fa0, 0x6054, 0x007e, 0x6057, 0x0000, 0x605b, 0x0000,
2562 0x6000, 0xc0d4, 0xc0dc, 0x6002, 0x1078, 0x4410, 0x0040, 0x5f9d,
2563 0x7e24, 0x86ff, 0x0040, 0x5f8f, 0xa680, 0x0004, 0x2004, 0xad06,
2564 0x00c0, 0x5f8f, 0x0d7e, 0x2069, 0x0100, 0x68c0, 0xa005, 0x0040,
2565 0x5f86, 0x1078, 0x595a, 0x1078, 0x6c41, 0x68c3, 0x0000, 0x1078,
2566 0x7188, 0x7827, 0x0000, 0x037e, 0x2069, 0x0140, 0x6b04, 0xa384,
2567 0x1000, 0x0040, 0x5f6f, 0x6803, 0x0100, 0x6803, 0x0000, 0x2069,
2568 0x0100, 0x6824, 0xd084, 0x0040, 0x5f77, 0x6827, 0x0001, 0x037f,
2569 0x0d7f, 0x0c7e, 0x603c, 0xa005, 0x0040, 0x5f80, 0x8001, 0x603e,
2570 0x2660, 0x1078, 0x8c01, 0x0c7f, 0x0078, 0x5f8f, 0x0d7f, 0x0c7e,
2571 0x2660, 0x6003, 0x0009, 0x630a, 0x0c7f, 0x0078, 0x5f44, 0x8dff,
2572 0x0040, 0x5f99, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x1078,
2573 0x4982, 0x1078, 0x7045, 0x0078, 0x5f44, 0x007f, 0x0078, 0x5f37,
2574 0x781e, 0x781a, 0x0d7f, 0x0c7f, 0x067f, 0x007f, 0x007c, 0x0e7e,
2575 0x0d7e, 0x067e, 0x6000, 0xd0dc, 0x0040, 0x5fc4, 0x604c, 0xa06d,
2576 0x0040, 0x5fc4, 0x6848, 0xa606, 0x00c0, 0x5fc4, 0x2071, 0xa5ab,
2577 0x7024, 0xa035, 0x0040, 0x5fc4, 0xa080, 0x0004, 0x2004, 0xad06,
2578 0x00c0, 0x5fc4, 0x1078, 0x5fc8, 0x067f, 0x0d7f, 0x0e7f, 0x007c,
2579 0x0f7e, 0x2079, 0x0100, 0x78c0, 0xa005, 0x00c0, 0x5fd7, 0x0c7e,
2580 0x2660, 0x6003, 0x0009, 0x630a, 0x0c7f, 0x0078, 0x600e, 0x1078,
2581 0x6c41, 0x78c3, 0x0000, 0x1078, 0x7188, 0x7027, 0x0000, 0x037e,
2582 0x2079, 0x0140, 0x7b04, 0xa384, 0x1000, 0x0040, 0x5feb, 0x7803,
2583 0x0100, 0x7803, 0x0000, 0x2079, 0x0100, 0x7824, 0xd084, 0x0040,
2584 0x5ff3, 0x7827, 0x0001, 0x1078, 0x7188, 0x037f, 0x1078, 0x4410,
2585 0x0c7e, 0x603c, 0xa005, 0x0040, 0x5fff, 0x8001, 0x603e, 0x2660,
2586 0x1078, 0x753d, 0x0c7f, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000,
2587 0x1078, 0x8cb8, 0x1078, 0x4982, 0x1078, 0x7045, 0x0f7f, 0x007c,
2588 0x0e7e, 0x0c7e, 0x2071, 0xa5ab, 0x7004, 0xa084, 0x0007, 0x0079,
2589 0x6019, 0x6023, 0x6026, 0x603f, 0x605b, 0x60a0, 0x6023, 0x6023,
2590 0x6021, 0x1078, 0x1328, 0x0c7f, 0x0e7f, 0x007c, 0x7024, 0xa065,
2591 0x0040, 0x6034, 0x7020, 0x8001, 0x7022, 0x600c, 0xa015, 0x0040,
2592 0x603b, 0x7216, 0x600f, 0x0000, 0x7007, 0x0000, 0x7027, 0x0000,
2593 0x0c7f, 0x0e7f, 0x007c, 0x7216, 0x7212, 0x0078, 0x6034, 0x6018,
2594 0x2060, 0x1078, 0x4410, 0x6000, 0xc0dc, 0x6002, 0x7020, 0x8001,
2595 0x7022, 0x0040, 0x6050, 0x6054, 0xa015, 0x0040, 0x6057, 0x721e,
2596 0x7007, 0x0000, 0x7027, 0x0000, 0x0c7f, 0x0e7f, 0x007c, 0x7218,
2597 0x721e, 0x0078, 0x6050, 0x7024, 0xa065, 0x0040, 0x609d, 0x700c,
2598 0xac06, 0x00c0, 0x6072, 0x1078, 0x7045, 0x600c, 0xa015, 0x0040,
2599 0x606e, 0x720e, 0x600f, 0x0000, 0x0078, 0x609b, 0x720e, 0x720a,
2600 0x0078, 0x609b, 0x7014, 0xac06, 0x00c0, 0x6085, 0x1078, 0x7045,
2601 0x600c, 0xa015, 0x0040, 0x6081, 0x7216, 0x600f, 0x0000, 0x0078,
2602 0x609b, 0x7216, 0x7212, 0x0078, 0x609b, 0x6018, 0x2060, 0x1078,
2603 0x4410, 0x6000, 0xc0dc, 0x6002, 0x1078, 0x7045, 0x701c, 0xa065,
2604 0x0040, 0x609b, 0x6054, 0xa015, 0x0040, 0x6099, 0x721e, 0x0078,
2605 0x609b, 0x7218, 0x721e, 0x7027, 0x0000, 0x0c7f, 0x0e7f, 0x007c,
2606 0x7024, 0xa065, 0x0040, 0x60ad, 0x1078, 0x7045, 0x600c, 0xa015,
2607 0x0040, 0x60b4, 0x720e, 0x600f, 0x0000, 0x1078, 0x7188, 0x7027,
2608 0x0000, 0x0c7f, 0x0e7f, 0x007c, 0x720e, 0x720a, 0x0078, 0x60ad,
2609 0x0d7e, 0x2069, 0xa5ab, 0x6830, 0xa084, 0x0003, 0x0079, 0x60c0,
2610 0x60c6, 0x60c8, 0x60ee, 0x60c6, 0x1078, 0x1328, 0x0d7f, 0x007c,
2611 0x0c7e, 0x6840, 0xa086, 0x0001, 0x0040, 0x60e4, 0x683c, 0xa065,
2612 0x0040, 0x60d9, 0x600c, 0xa015, 0x0040, 0x60e0, 0x6a3a, 0x600f,
2613 0x0000, 0x6833, 0x0000, 0x683f, 0x0000, 0x0c7f, 0x0d7f, 0x007c,
2614 0x683a, 0x6836, 0x0078, 0x60d9, 0x6843, 0x0000, 0x6838, 0xa065,
2615 0x0040, 0x60d9, 0x6003, 0x0003, 0x0078, 0x60d9, 0x0c7e, 0x6843,
2616 0x0000, 0x6847, 0x0000, 0x683c, 0xa065, 0x0040, 0x6106, 0x600c,
2617 0xa015, 0x0040, 0x6102, 0x6a3a, 0x600f, 0x0000, 0x683f, 0x0000,
2618 0x0078, 0x6106, 0x683f, 0x0000, 0x683a, 0x6836, 0x0c7f, 0x0d7f,
2619 0x007c, 0x0d7e, 0x2069, 0xa5ab, 0x6804, 0xa084, 0x0007, 0x0079,
2620 0x6111, 0x611b, 0x61c2, 0x61c2, 0x61c2, 0x61c2, 0x61c4, 0x61c2,
2621 0x6119, 0x1078, 0x1328, 0x6820, 0xa005, 0x00c0, 0x6121, 0x0d7f,
2622 0x007c, 0x0c7e, 0x680c, 0xa065, 0x0040, 0x6130, 0x6807, 0x0004,
2623 0x6826, 0x682b, 0x0000, 0x1078, 0x620a, 0x0c7f, 0x0d7f, 0x007c,
2624 0x6814, 0xa065, 0x0040, 0x613e, 0x6807, 0x0001, 0x6826, 0x682b,
2625 0x0000, 0x1078, 0x620a, 0x0c7f, 0x0d7f, 0x007c, 0x0e7e, 0x037e,
2626 0x6a1c, 0xa2f5, 0x0000, 0x0040, 0x61bd, 0x704c, 0xa00d, 0x0040,
2627 0x614d, 0x7088, 0xa005, 0x0040, 0x6165, 0x7054, 0xa075, 0x0040,
2628 0x6156, 0xa20e, 0x0040, 0x61bd, 0x0078, 0x615b, 0x6818, 0xa20e,
2629 0x0040, 0x61bd, 0x2070, 0x704c, 0xa00d, 0x0040, 0x614d, 0x7088,
2630 0xa005, 0x00c0, 0x614d, 0x2e00, 0x681e, 0x733c, 0x7038, 0xa302,
2631 0x00c8, 0x614d, 0x1078, 0x750c, 0x0040, 0x61bd, 0x8318, 0x733e,
2632 0x6112, 0x2e10, 0x621a, 0xa180, 0x0014, 0x2004, 0xa084, 0x00ff,
2633 0x6032, 0xa180, 0x0014, 0x2003, 0x0000, 0xa180, 0x0015, 0x2004,
2634 0xa08a, 0x199a, 0x0048, 0x6186, 0x2001, 0x1999, 0x8003, 0x801b,
2635 0x831b, 0xa318, 0x6316, 0x037f, 0x0f7e, 0x2c78, 0x71a0, 0xd1bc,
2636 0x0040, 0x619f, 0x7100, 0xd1f4, 0x0040, 0x619b, 0x7114, 0xa18c,
2637 0x00ff, 0x0078, 0x61a4, 0x2009, 0x0000, 0x0078, 0x61a4, 0xa1e0,
2638 0x293f, 0x2c0c, 0xa18c, 0x00ff, 0x2061, 0x0100, 0x619a, 0x1078,
2639 0x679b, 0x7300, 0xc3dd, 0x7302, 0x6807, 0x0002, 0x2f18, 0x6b26,
2640 0x682b, 0x0000, 0x781f, 0x0003, 0x7803, 0x0001, 0x7807, 0x0040,
2641 0x0f7f, 0x0e7f, 0x0c7f, 0x0d7f, 0x007c, 0x037f, 0x0e7f, 0x0c7f,
2642 0x0078, 0x61bb, 0x0d7f, 0x007c, 0x0c7e, 0x680c, 0xa065, 0x0040,
2643 0x61d0, 0x6807, 0x0004, 0x6826, 0x682b, 0x0000, 0x1078, 0x620a,
2644 0x0c7f, 0x0d7f, 0x007c, 0x0f7e, 0x0d7e, 0x2069, 0xa5ab, 0x6830,
2645 0xa086, 0x0000, 0x00c0, 0x61f1, 0x6838, 0xa07d, 0x0040, 0x61f1,
2646 0x6833, 0x0001, 0x683e, 0x6847, 0x0000, 0x127e, 0x0f7e, 0x2091,
2647 0x2200, 0x027f, 0x1078, 0x1d28, 0x00c0, 0x61f4, 0x127f, 0x1078,
2648 0x6ae5, 0x0d7f, 0x0f7f, 0x007c, 0x127f, 0x6843, 0x0000, 0x7803,
2649 0x0002, 0x780c, 0xa015, 0x0040, 0x6206, 0x6a3a, 0x780f, 0x0000,
2650 0x6833, 0x0000, 0x683f, 0x0000, 0x0078, 0x61f1, 0x683a, 0x6836,
2651 0x0078, 0x6200, 0x601c, 0xa084, 0x000f, 0x1079, 0x6210, 0x007c,
2652 0x6219, 0x621e, 0x663f, 0x6758, 0x621e, 0x663f, 0x6758, 0x6219,
2653 0x621e, 0x1078, 0x6010, 0x1078, 0x6109, 0x007c, 0x157e, 0x137e,
2654 0x147e, 0x0c7e, 0x0f7e, 0x6004, 0xa08a, 0x0044, 0x10c8, 0x1328,
2655 0x6118, 0x2178, 0x79a0, 0xd1bc, 0x0040, 0x623b, 0x7900, 0xd1f4,
2656 0x0040, 0x6237, 0x7914, 0xa18c, 0x00ff, 0x0078, 0x6240, 0x2009,
2657 0x0000, 0x0078, 0x6240, 0xa1f8, 0x293f, 0x2f0c, 0xa18c, 0x00ff,
2658 0x2c78, 0x2061, 0x0100, 0x619a, 0xa08a, 0x0040, 0x00c8, 0x6292,
2659 0x1079, 0x6250, 0x0f7f, 0x0c7f, 0x147f, 0x137f, 0x157f, 0x007c,
2660 0x62f8, 0x6340, 0x6368, 0x6403, 0x6433, 0x643b, 0x6462, 0x6473,
2661 0x6484, 0x648c, 0x64a4, 0x648c, 0x650f, 0x6473, 0x6530, 0x6538,
2662 0x6484, 0x6538, 0x6549, 0x6290, 0x6290, 0x6290, 0x6290, 0x6290,
2663 0x6290, 0x6290, 0x6290, 0x6290, 0x6290, 0x6290, 0x6d05, 0x6d2a,
2664 0x6d3f, 0x6d62, 0x6d83, 0x6462, 0x6290, 0x6462, 0x648c, 0x6290,
2665 0x6368, 0x6403, 0x6290, 0x72ac, 0x648c, 0x6290, 0x72cc, 0x648c,
2666 0x6290, 0x6290, 0x62f3, 0x62a1, 0x6290, 0x72f1, 0x7368, 0x7450,
2667 0x6290, 0x7461, 0x645c, 0x747d, 0x6290, 0x6d98, 0x6290, 0x6290,
2668 0x1078, 0x1328, 0x2100, 0x1079, 0x629b, 0x0f7f, 0x0c7f, 0x147f,
2669 0x137f, 0x157f, 0x007c, 0x629f, 0x629f, 0x629f, 0x62d5, 0x1078,
2670 0x1328, 0x0d7e, 0x20a1, 0x020b, 0x1078, 0x6567, 0x7810, 0x2068,
2671 0x20a3, 0x2414, 0x20a3, 0x0018, 0x20a3, 0x0800, 0x683c, 0x20a2,
2672 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000,
2673 0x6850, 0x20a2, 0x6854, 0x20a2, 0x20a3, 0x0000, 0x20a3, 0x0000,
2674 0x60c3, 0x0018, 0x1078, 0x6c2d, 0x0d7f, 0x007c, 0x0d7e, 0x7818,
2675 0x2068, 0x68a0, 0xa082, 0x007e, 0x0048, 0x62d2, 0xa085, 0x0001,
2676 0x0d7f, 0x007c, 0xa006, 0x0078, 0x62d0, 0x0d7e, 0x20a1, 0x020b,
2677 0x1078, 0x6567, 0x20a3, 0x0500, 0x20a3, 0x0000, 0x7810, 0xa0e8,
2678 0x000f, 0x6808, 0x20a2, 0x680c, 0x20a2, 0x6810, 0x20a2, 0x6814,
2679 0x20a2, 0x6818, 0x20a2, 0x681c, 0x20a2, 0x60c3, 0x0010, 0x1078,
2680 0x6c2d, 0x0d7f, 0x007c, 0x6030, 0x609a, 0x1078, 0x6c2d, 0x007c,
2681 0x20a1, 0x020b, 0x1078, 0x6567, 0x20a3, 0x5200, 0x20a3, 0x0000,
2682 0x0d7e, 0x2069, 0xa351, 0x6804, 0xd084, 0x0040, 0x6312, 0x6828,
2683 0x20a3, 0x0000, 0x017e, 0x1078, 0x24fa, 0x21a2, 0x017f, 0x0d7f,
2684 0x0078, 0x6317, 0x0d7f, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a9,
2685 0x0004, 0x2099, 0xa305, 0x53a6, 0x20a9, 0x0004, 0x2099, 0xa301,
2686 0x53a6, 0x7818, 0xa080, 0x0028, 0x2004, 0xa082, 0x007f, 0x0048,
2687 0x6331, 0x2001, 0xa31a, 0x20a6, 0x2001, 0xa31b, 0x20a6, 0x0078,
2688 0x6337, 0x20a3, 0x0000, 0x6030, 0xa084, 0x00ff, 0x20a2, 0x20a3,
2689 0x0000, 0x20a3, 0x0000, 0x60c3, 0x001c, 0x1078, 0x6c2d, 0x007c,
2690 0x20a1, 0x020b, 0x1078, 0x6567, 0x20a3, 0x0500, 0x20a3, 0x0000,
2691 0x7818, 0xa080, 0x0028, 0x2004, 0xa082, 0x007f, 0x0048, 0x6358,
2692 0x2001, 0xa31a, 0x20a6, 0x2001, 0xa31b, 0x20a6, 0x0078, 0x635e,
2693 0x20a3, 0x0000, 0x6030, 0xa084, 0x00ff, 0x20a2, 0x20a9, 0x0004,
2694 0x2099, 0xa305, 0x53a6, 0x60c3, 0x0010, 0x1078, 0x6c2d, 0x007c,
2695 0x20a1, 0x020b, 0x1078, 0x6567, 0x0c7e, 0x7818, 0x2060, 0x2001,
2696 0x0000, 0x1078, 0x48a2, 0x0c7f, 0x7818, 0xa080, 0x0028, 0x2004,
2697 0xa086, 0x007e, 0x00c0, 0x6383, 0x20a3, 0x0400, 0x620c, 0xc2b4,
2698 0x620e, 0x0078, 0x6385, 0x20a3, 0x0300, 0x20a3, 0x0000, 0x7818,
2699 0xa080, 0x0028, 0x2004, 0xa086, 0x007e, 0x00c0, 0x63d2, 0x2099,
2700 0xa58c, 0x33a6, 0x9398, 0x33a6, 0x9398, 0x3304, 0xa084, 0x3fff,
2701 0x20a2, 0x9398, 0x33a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
2702 0x0000, 0x20a3, 0x0000, 0x20a9, 0x0004, 0x2099, 0xa305, 0x53a6,
2703 0x20a9, 0x0004, 0x2099, 0xa301, 0x53a6, 0x20a9, 0x0010, 0x20a3,
2704 0x0000, 0x00f0, 0x63af, 0x2099, 0xa594, 0x3304, 0xc0dd, 0x20a2,
2705 0x2001, 0xa371, 0x2004, 0xd0e4, 0x0040, 0x63ca, 0x20a3, 0x0000,
2706 0x20a3, 0x0000, 0x9398, 0x9398, 0x9398, 0x33a6, 0x20a9, 0x0004,
2707 0x0078, 0x63cc, 0x20a9, 0x0007, 0x20a3, 0x0000, 0x00f0, 0x63cc,
2708 0x0078, 0x63f2, 0x2099, 0xa58c, 0x20a9, 0x0008, 0x53a6, 0x20a9,
2709 0x0004, 0x2099, 0xa305, 0x53a6, 0x20a9, 0x0004, 0x2099, 0xa301,
2710 0x53a6, 0x20a9, 0x0008, 0x20a3, 0x0000, 0x00f0, 0x63e3, 0x20a9,
2711 0x0008, 0x20a3, 0x0000, 0x00f0, 0x63e9, 0x2099, 0xa594, 0x20a9,
2712 0x0008, 0x53a6, 0x20a9, 0x0008, 0x20a3, 0x0000, 0x00f0, 0x63f4,
2713 0x20a9, 0x000a, 0x20a3, 0x0000, 0x00f0, 0x63fa, 0x60c3, 0x0074,
2714 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x1078, 0x6567, 0x20a3,
2715 0x2010, 0x20a3, 0x0014, 0x20a3, 0x0800, 0x20a3, 0x2000, 0xa006,
2716 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x0f7e, 0x2079, 0xa351,
2717 0x7904, 0x0f7f, 0xd1ac, 0x00c0, 0x641f, 0xa085, 0x0020, 0xd1a4,
2718 0x0040, 0x6424, 0xa085, 0x0010, 0xa085, 0x0002, 0x0d7e, 0x0078,
2719 0x64ed, 0x20a2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014,
2720 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x1078, 0x6567, 0x20a3,
2721 0x5000, 0x0078, 0x6385, 0x20a1, 0x020b, 0x1078, 0x6567, 0x20a3,
2722 0x2110, 0x20a3, 0x0014, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
2723 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
2724 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3,
2725 0x0014, 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x1078, 0x65ef,
2726 0x0078, 0x6466, 0x20a1, 0x020b, 0x1078, 0x65f8, 0x20a3, 0x0200,
2727 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0004,
2728 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x1078, 0x65f8, 0x20a3,
2729 0x0100, 0x20a3, 0x0000, 0x20a3, 0x0003, 0x20a3, 0x2a00, 0x60c3,
2730 0x0008, 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x1078, 0x65f8,
2731 0x20a3, 0x0200, 0x0078, 0x6385, 0x20a1, 0x020b, 0x1078, 0x65f8,
2732 0x20a3, 0x0100, 0x20a3, 0x0000, 0x7828, 0xa005, 0x0040, 0x649b,
2733 0x20a2, 0x0078, 0x649d, 0x20a3, 0x0003, 0x7810, 0x20a2, 0x60c3,
2734 0x0008, 0x1078, 0x6c2d, 0x007c, 0x0d7e, 0x20a1, 0x020b, 0x1078,
2735 0x65f8, 0x20a3, 0x0210, 0x20a3, 0x0014, 0x20a3, 0x0800, 0x7818,
2736 0x2068, 0x6894, 0xa086, 0x0014, 0x00c0, 0x64ca, 0x6998, 0xa184,
2737 0xc000, 0x00c0, 0x64c6, 0xd1ec, 0x0040, 0x64c2, 0x20a3, 0x2100,
2738 0x0078, 0x64cc, 0x20a3, 0x0100, 0x0078, 0x64cc, 0x20a3, 0x0400,
2739 0x0078, 0x64cc, 0x20a3, 0x0700, 0xa006, 0x20a2, 0x20a2, 0x20a2,
2740 0x20a2, 0x20a2, 0x0f7e, 0x2079, 0xa351, 0x7904, 0x0f7f, 0xd1ac,
2741 0x00c0, 0x64dc, 0xa085, 0x0020, 0xd1a4, 0x0040, 0x64e1, 0xa085,
2742 0x0010, 0x2009, 0xa373, 0x210c, 0xd184, 0x0040, 0x64eb, 0x699c,
2743 0xd18c, 0x0040, 0x64ed, 0xa085, 0x0002, 0x027e, 0x2009, 0xa371,
2744 0x210c, 0xd1e4, 0x0040, 0x64fb, 0xc0c5, 0xa094, 0x0030, 0xa296,
2745 0x0010, 0x0040, 0x6505, 0xd1ec, 0x0040, 0x6505, 0xa094, 0x0030,
2746 0xa296, 0x0010, 0x0040, 0x6505, 0xc0bd, 0x027f, 0x20a2, 0x20a2,
2747 0x20a2, 0x60c3, 0x0014, 0x1078, 0x6c2d, 0x0d7f, 0x007c, 0x20a1,
2748 0x020b, 0x1078, 0x65f8, 0x20a3, 0x0210, 0x20a3, 0x0014, 0x20a3,
2749 0x0000, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
2750 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
2751 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014, 0x1078, 0x6c2d, 0x007c,
2752 0x20a1, 0x020b, 0x1078, 0x65f8, 0x20a3, 0x0200, 0x0078, 0x62fe,
2753 0x20a1, 0x020b, 0x1078, 0x65f8, 0x20a3, 0x0100, 0x20a3, 0x0000,
2754 0x20a3, 0x0003, 0x20a3, 0x2a00, 0x60c3, 0x0008, 0x1078, 0x6c2d,
2755 0x007c, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x20a1, 0x020b, 0x1078,
2756 0x65f8, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x20a3, 0x000b, 0x20a3,
2757 0x0000, 0x60c3, 0x0008, 0x1078, 0x6c2d, 0x007c, 0x027e, 0x037e,
2758 0x047e, 0x2019, 0x3200, 0x2021, 0x0800, 0x0078, 0x656e, 0x027e,
2759 0x037e, 0x047e, 0x2019, 0x2200, 0x2021, 0x0100, 0x20e1, 0x9080,
2760 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028, 0x2014, 0xa286, 0x007e,
2761 0x00c0, 0x6581, 0xa385, 0x00ff, 0x20a2, 0x20a3, 0xfffe, 0x0078,
2762 0x65b6, 0xa286, 0x007f, 0x00c0, 0x658d, 0x0d7e, 0xa385, 0x00ff,
2763 0x20a2, 0x20a3, 0xfffd, 0x0078, 0x65a4, 0xd2bc, 0x0040, 0x65ac,
2764 0xa286, 0x0080, 0x0d7e, 0x00c0, 0x659c, 0xa385, 0x00ff, 0x20a2,
2765 0x20a3, 0xfffc, 0x0078, 0x65a4, 0xa2e8, 0xa434, 0x2d6c, 0x6810,
2766 0xa305, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a, 0x2da6, 0x8d68,
2767 0x2da6, 0x0d7f, 0x0078, 0x65ba, 0x0d7e, 0xa2e8, 0xa434, 0x2d6c,
2768 0x6810, 0xa305, 0x20a2, 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000,
2769 0x6230, 0x22a2, 0xa485, 0x0029, 0x20a2, 0x047f, 0x037f, 0x20a3,
2770 0x0000, 0x1078, 0x6c1c, 0x22a2, 0x20a3, 0x0000, 0x2fa2, 0x20a3,
2771 0xffff, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x027f, 0x007c, 0x027e,
2772 0x20e1, 0x9080, 0x20e1, 0x4000, 0x20a3, 0x02ff, 0x2011, 0xfffc,
2773 0x22a2, 0x0d7e, 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6, 0x0d7f,
2774 0x20a3, 0x2029, 0x20a3, 0x0000, 0x0078, 0x65c1, 0x20a3, 0x0100,
2775 0x20a3, 0x0000, 0x20a3, 0xfc02, 0x20a3, 0x0000, 0x007c, 0x027e,
2776 0x037e, 0x047e, 0x2019, 0x3300, 0x2021, 0x0800, 0x0078, 0x65ff,
2777 0x027e, 0x037e, 0x047e, 0x2019, 0x2300, 0x2021, 0x0100, 0x20e1,
2778 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028, 0x2004, 0xa092,
2779 0x007e, 0x0048, 0x661c, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810,
2780 0xa305, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a, 0x2da6, 0x8d68,
2781 0x2da6, 0x0d7f, 0x0078, 0x662a, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c,
2782 0x6810, 0xa305, 0x20a2, 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000,
2783 0x6230, 0x22a2, 0xa485, 0x0098, 0x20a2, 0x20a3, 0x0000, 0x047f,
2784 0x037f, 0x1078, 0x6c1c, 0x22a2, 0x20a3, 0x0000, 0x7a08, 0x22a2,
2785 0x2fa2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x027f, 0x007c, 0x0c7e,
2786 0x0f7e, 0x6004, 0xa08a, 0x0085, 0x1048, 0x1328, 0xa08a, 0x008c,
2787 0x10c8, 0x1328, 0x6118, 0x2178, 0x79a0, 0xd1bc, 0x0040, 0x665d,
2788 0x7900, 0xd1f4, 0x0040, 0x6659, 0x7914, 0xa18c, 0x00ff, 0x0078,
2789 0x6662, 0x2009, 0x0000, 0x0078, 0x6662, 0xa1f8, 0x293f, 0x2f0c,
2790 0xa18c, 0x00ff, 0x2c78, 0x2061, 0x0100, 0x619a, 0xa082, 0x0085,
2791 0x1079, 0x666d, 0x0f7f, 0x0c7f, 0x007c, 0x6676, 0x6681, 0x669c,
2792 0x6674, 0x6674, 0x6674, 0x6676, 0x1078, 0x1328, 0x147e, 0x20a1,
2793 0x020b, 0x1078, 0x66af, 0x60c3, 0x0000, 0x1078, 0x6c2d, 0x147f,
2794 0x007c, 0x147e, 0x20a1, 0x020b, 0x1078, 0x66e3, 0x20a3, 0x0000,
2795 0x20a3, 0x0000, 0x7808, 0x20a2, 0x7810, 0x20a2, 0x20a3, 0x0000,
2796 0x20a3, 0xffff, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x000c,
2797 0x1078, 0x6c2d, 0x147f, 0x007c, 0x147e, 0x20a1, 0x020b, 0x1078,
2798 0x6724, 0x20a3, 0x0003, 0x20a3, 0x0300, 0x20a3, 0x0000, 0x20a3,
2799 0x0000, 0x60c3, 0x0004, 0x1078, 0x6c2d, 0x147f, 0x007c, 0x027e,
2800 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028, 0x2004,
2801 0xa092, 0x007e, 0x0048, 0x66ce, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c,
2802 0x6810, 0xa085, 0x8100, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a,
2803 0x2da6, 0x8d68, 0x2da6, 0x0d7f, 0x0078, 0x66dd, 0x0d7e, 0xa0e8,
2804 0xa434, 0x2d6c, 0x6810, 0xa085, 0x8100, 0x20a2, 0x6814, 0x20a2,
2805 0x0d7f, 0x20a3, 0x0000, 0x6230, 0x22a2, 0x20a3, 0x0009, 0x20a3,
2806 0x0000, 0x0078, 0x65c1, 0x027e, 0x20e1, 0x9080, 0x20e1, 0x4000,
2807 0x7818, 0xa080, 0x0028, 0x2004, 0xa092, 0x007e, 0x0048, 0x6702,
2808 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085, 0x8400, 0x20a2,
2809 0x6814, 0x20a2, 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6, 0x0d7f,
2810 0x0078, 0x6711, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085,
2811 0x8400, 0x20a2, 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000, 0x6230,
2812 0x22a2, 0x20a3, 0x0099, 0x20a3, 0x0000, 0x1078, 0x6c1c, 0x22a2,
2813 0x20a3, 0x0000, 0x7a08, 0x22a2, 0x7a10, 0x22a2, 0x20a3, 0x0000,
2814 0x20a3, 0x0000, 0x027f, 0x007c, 0x027e, 0x20e1, 0x9080, 0x20e1,
2815 0x4000, 0x7818, 0xa080, 0x0028, 0x2004, 0xa092, 0x007e, 0x0048,
2816 0x6743, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085, 0x8500,
2817 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6,
2818 0x0d7f, 0x0078, 0x6752, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810,
2819 0xa085, 0x8500, 0x20a2, 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000,
2820 0x6230, 0x22a2, 0x20a3, 0x0099, 0x20a3, 0x0000, 0x0078, 0x6715,
2821 0x0c7e, 0x0f7e, 0x2c78, 0x7804, 0xa08a, 0x0040, 0x1048, 0x1328,
2822 0xa08a, 0x0053, 0x10c8, 0x1328, 0x7918, 0x2160, 0x61a0, 0xd1bc,
2823 0x0040, 0x6777, 0x6100, 0xd1f4, 0x0040, 0x6773, 0x6114, 0xa18c,
2824 0x00ff, 0x0078, 0x677c, 0x2009, 0x0000, 0x0078, 0x677c, 0xa1e0,
2825 0x293f, 0x2c0c, 0xa18c, 0x00ff, 0x2061, 0x0100, 0x619a, 0xa082,
2826 0x0040, 0x1079, 0x6786, 0x0f7f, 0x0c7f, 0x007c, 0x679b, 0x68a9,
2827 0x684a, 0x6a59, 0x6799, 0x6799, 0x6799, 0x6799, 0x6799, 0x6799,
2828 0x6799, 0x6f5e, 0x6f6f, 0x6f80, 0x6f91, 0x6799, 0x748e, 0x6799,
2829 0x6f4d, 0x1078, 0x1328, 0x0d7e, 0x157e, 0x147e, 0x780b, 0xffff,
2830 0x20a1, 0x020b, 0x1078, 0x6806, 0x7910, 0x2168, 0x6948, 0x7922,
2831 0x21a2, 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x694c, 0xa184, 0x000f,
2832 0x00c0, 0x67b6, 0x2001, 0x0005, 0x0078, 0x67c0, 0xd184, 0x0040,
2833 0x67bd, 0x2001, 0x0004, 0x0078, 0x67c0, 0xa084, 0x0006, 0x8004,
2834 0x017e, 0x2008, 0x7830, 0xa084, 0x00ff, 0x8007, 0xa105, 0x017f,
2835 0x20a2, 0xd1ac, 0x0040, 0x67d0, 0x20a3, 0x0002, 0x0078, 0x67dc,
2836 0xd1b4, 0x0040, 0x67d7, 0x20a3, 0x0001, 0x0078, 0x67dc, 0x20a3,
2837 0x0000, 0x2230, 0x0078, 0x67de, 0x6a80, 0x6e7c, 0x20a9, 0x0008,
2838 0xad80, 0x0017, 0x200c, 0x810f, 0x21a2, 0x8000, 0x00f0, 0x67e2,
2839 0x22a2, 0x26a2, 0x60c3, 0x0020, 0x20e1, 0x9080, 0x6014, 0xa084,
2840 0x0004, 0xa085, 0x0009, 0x6016, 0x2001, 0xa5c7, 0x2003, 0x07d0,
2841 0x2001, 0xa5c6, 0x2003, 0x0009, 0x2001, 0xa5cc, 0x2003, 0x0002,
2842 0x1078, 0x157e, 0x147f, 0x157f, 0x0d7f, 0x007c, 0x20e1, 0x9080,
2843 0x20e1, 0x4000, 0x7a18, 0xa280, 0x0023, 0x2014, 0x8210, 0xa294,
2844 0x00ff, 0x2202, 0x8217, 0x7818, 0xa080, 0x0028, 0x2004, 0xd0bc,
2845 0x0040, 0x682c, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085,
2846 0x0600, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a, 0x2da6, 0x8d68,
2847 0x2da6, 0x0d7f, 0x0078, 0x683b, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c,
2848 0x6810, 0xa085, 0x0600, 0x20a2, 0x6814, 0x20a2, 0x0d7f, 0x20a3,
2849 0x0000, 0x6130, 0x21a2, 0x20a3, 0x0829, 0x20a3, 0x0000, 0x22a2,
2850 0x20a3, 0x0000, 0x2fa2, 0x20a3, 0xffff, 0x20a3, 0x0000, 0x20a3,
2851 0x0000, 0x007c, 0x0d7e, 0x157e, 0x137e, 0x147e, 0x20a1, 0x020b,
2852 0x1078, 0x686a, 0x7810, 0x2068, 0x6860, 0x20a2, 0x685c, 0x20a2,
2853 0x6880, 0x20a2, 0x687c, 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2,
2854 0x20a2, 0x60c3, 0x000c, 0x1078, 0x6c2d, 0x147f, 0x137f, 0x157f,
2855 0x0d7f, 0x007c, 0x027e, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818,
2856 0xa080, 0x0028, 0x2004, 0xd0bc, 0x0040, 0x6888, 0x0d7e, 0xa0e8,
2857 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0500, 0x20a2, 0x6814, 0x20a2,
2858 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6, 0x0d7f, 0x0078, 0x6897,
2859 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0500, 0x20a2,
2860 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000, 0x6230, 0x22a2, 0x20a3,
2861 0x0889, 0x20a3, 0x0000, 0x1078, 0x6c1c, 0x22a2, 0x20a3, 0x0000,
2862 0x7a08, 0x22a2, 0x2fa2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x027f,
2863 0x007c, 0x0d7e, 0x157e, 0x137e, 0x147e, 0x7810, 0xa06d, 0x1078,
2864 0x488f, 0x0040, 0x68bd, 0x684c, 0xa084, 0x2020, 0xa086, 0x2020,
2865 0x00c0, 0x68bd, 0x7824, 0xc0cd, 0x7826, 0x20a1, 0x020b, 0x1078,
2866 0x6a12, 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x7810,
2867 0xa084, 0xf000, 0x00c0, 0x68d4, 0x7810, 0xa084, 0x0700, 0x8007,
2868 0x1079, 0x68dc, 0x0078, 0x68d7, 0xa006, 0x1079, 0x68dc, 0x147f,
2869 0x137f, 0x157f, 0x0d7f, 0x007c, 0x68e6, 0x697e, 0x6989, 0x69b3,
2870 0x69c7, 0x69e3, 0x69ee, 0x68e4, 0x1078, 0x1328, 0x017e, 0x037e,
2871 0x694c, 0xa18c, 0x0003, 0x0040, 0x68f1, 0xa186, 0x0003, 0x00c0,
2872 0x6900, 0x6b78, 0x7824, 0xd0cc, 0x0040, 0x68f7, 0xc3e5, 0x23a2,
2873 0x6868, 0x20a2, 0x6864, 0x20a2, 0x037f, 0x017f, 0x0078, 0x69be,
2874 0xa186, 0x0001, 0x10c0, 0x1328, 0x6b78, 0x7824, 0xd0cc, 0x0040,
2875 0x690a, 0xc3e5, 0x23a2, 0x6868, 0x20a2, 0x6864, 0x20a2, 0x22a2,
2876 0x6874, 0x20a2, 0x22a2, 0x687c, 0x20a2, 0x2009, 0x0018, 0xa384,
2877 0x0300, 0x0040, 0x6978, 0xd3c4, 0x0040, 0x6920, 0x687c, 0xa108,
2878 0xd3cc, 0x0040, 0x6925, 0x6874, 0xa108, 0x157e, 0x20a9, 0x000d,
2879 0xad80, 0x0020, 0x201c, 0x831f, 0x23a2, 0x8000, 0x00f0, 0x692a,
2880 0x157f, 0x22a2, 0x22a2, 0x22a2, 0xa184, 0x0003, 0x0040, 0x6978,
2881 0x20a1, 0x020b, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x007e, 0x7818,
2882 0xa080, 0x0028, 0x2004, 0xd0bc, 0x0040, 0x6958, 0x0d7e, 0xa0e8,
2883 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0700, 0x20a2, 0x6814, 0x20a2,
2884 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6, 0x0d7f, 0x0078, 0x6967,
2885 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0700, 0x20a2,
2886 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000, 0x6230, 0x22a2, 0x007f,
2887 0x7b24, 0xd3cc, 0x0040, 0x6970, 0x20a3, 0x0889, 0x0078, 0x6972,
2888 0x20a3, 0x0898, 0x20a2, 0x1078, 0x6c1c, 0x22a2, 0x20a3, 0x0000,
2889 0x61c2, 0x037f, 0x017f, 0x1078, 0x6c2d, 0x007c, 0x2011, 0x0008,
2890 0x7824, 0xd0cc, 0x0040, 0x6985, 0xc2e5, 0x22a2, 0xa016, 0x0078,
2891 0x69bc, 0x2011, 0x0302, 0x7824, 0xd0cc, 0x0040, 0x6990, 0xc2e5,
2892 0x22a2, 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x20a3, 0x0012, 0x22a2,
2893 0x20a3, 0x0008, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x20a3, 0x7000,
2894 0x20a3, 0x0500, 0x22a2, 0x20a3, 0x000a, 0x22a2, 0x22a2, 0x20a3,
2895 0x2500, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x60c3, 0x0032,
2896 0x1078, 0x6c2d, 0x007c, 0x2011, 0x0028, 0x7824, 0xd0cc, 0x0040,
2897 0x69ba, 0xc2e5, 0x22a2, 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x22a2,
2898 0x22a2, 0x22a2, 0x60c3, 0x0018, 0x1078, 0x6c2d, 0x007c, 0x2011,
2899 0x0100, 0x7824, 0xd0cc, 0x0040, 0x69ce, 0xc2e5, 0x22a2, 0xa016,
2900 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x20a3, 0x0008, 0x22a2,
2901 0x7834, 0xa084, 0x00ff, 0x20a2, 0x22a2, 0x22a2, 0x60c3, 0x0020,
2902 0x1078, 0x6c2d, 0x007c, 0x2011, 0x0008, 0x7824, 0xd0cc, 0x0040,
2903 0x69ea, 0xc2e5, 0x22a2, 0xa016, 0x0078, 0x69bc, 0x037e, 0x7b10,
2904 0xa384, 0xff00, 0x7812, 0xa384, 0x00ff, 0x8001, 0x00c0, 0x6a01,
2905 0x7824, 0xd0cc, 0x0040, 0x69fd, 0xc2e5, 0x22a2, 0x037f, 0x0078,
2906 0x69bc, 0x047e, 0x2021, 0x0800, 0x007e, 0x7824, 0xd0cc, 0x007f,
2907 0x0040, 0x6a0b, 0xc4e5, 0x24a2, 0x047f, 0x22a2, 0x20a2, 0x037f,
2908 0x0078, 0x69be, 0x027e, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818,
2909 0xa080, 0x0028, 0x2004, 0xd0bc, 0x0040, 0x6a30, 0x0d7e, 0xa0e8,
2910 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0700, 0x20a2, 0x6814, 0x20a2,
2911 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6, 0x0d7f, 0x0078, 0x6a3f,
2912 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0700, 0x20a2,
2913 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000, 0x6230, 0x22a2, 0x7824,
2914 0xd0cc, 0x0040, 0x6a47, 0x20a3, 0x0889, 0x0078, 0x6a49, 0x20a3,
2915 0x0898, 0x20a3, 0x0000, 0x1078, 0x6c1c, 0x22a2, 0x20a3, 0x0000,
2916 0x7a08, 0x22a2, 0x2fa2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x027f,
2917 0x007c, 0x0d7e, 0x157e, 0x137e, 0x147e, 0x017e, 0x037e, 0x7810,
2918 0xa084, 0x0700, 0x8007, 0x1079, 0x6a6c, 0x037f, 0x017f, 0x147f,
2919 0x137f, 0x157f, 0x0d7f, 0x007c, 0x6a74, 0x6a74, 0x6a76, 0x6a74,
2920 0x6a74, 0x6a74, 0x6a9b, 0x6a74, 0x1078, 0x1328, 0x7910, 0xa18c,
2921 0xf8ff, 0xa18d, 0x0600, 0x7912, 0x20a1, 0x020b, 0x2009, 0x0003,
2922 0x1078, 0x6aa5, 0x0d7e, 0x2069, 0xa351, 0x6804, 0xd0bc, 0x0040,
2923 0x6a90, 0x682c, 0xa084, 0x00ff, 0x8007, 0x20a2, 0x0078, 0x6a92,
2924 0x20a3, 0x3f00, 0x0d7f, 0x22a2, 0x22a2, 0x22a2, 0x60c3, 0x0001,
2925 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x2009, 0x0003, 0x1078,
2926 0x6aa5, 0x20a3, 0x7f00, 0x0078, 0x6a93, 0x027e, 0x20e1, 0x9080,
2927 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028, 0x2004, 0xd0bc, 0x0040,
2928 0x6ac3, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810, 0xa085, 0x0100,
2929 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a, 0x2da6, 0x8d68, 0x2da6,
2930 0x0d7f, 0x0078, 0x6ad2, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c, 0x6810,
2931 0xa085, 0x0100, 0x20a2, 0x6814, 0x20a2, 0x0d7f, 0x20a3, 0x0000,
2932 0x6230, 0x22a2, 0x20a3, 0x0888, 0xa18d, 0x0008, 0x21a2, 0x1078,
2933 0x6c1c, 0x22a2, 0x20a3, 0x0000, 0x7a08, 0x22a2, 0x2fa2, 0x20a3,
2934 0x0000, 0x20a3, 0x0000, 0x027f, 0x007c, 0x0e7e, 0x0d7e, 0x0c7e,
2935 0x057e, 0x047e, 0x037e, 0x2061, 0x0100, 0x2071, 0xa300, 0x6130,
2936 0x7818, 0x2068, 0x68a0, 0x2028, 0xd0bc, 0x00c0, 0x6afc, 0x6910,
2937 0x6a14, 0x6430, 0x0078, 0x6b00, 0x6910, 0x6a14, 0x7368, 0x746c,
2938 0x781c, 0xa086, 0x0006, 0x0040, 0x6b5f, 0xd5bc, 0x0040, 0x6b10,
2939 0xa185, 0x0100, 0x6062, 0x6266, 0x636a, 0x646e, 0x0078, 0x6b17,
2940 0xa185, 0x0100, 0x6062, 0x6266, 0x606b, 0x0000, 0x646e, 0x6073,
2941 0x0809, 0x6077, 0x0008, 0x688c, 0x8000, 0xa084, 0x00ff, 0x688e,
2942 0x8007, 0x607a, 0x607f, 0x0000, 0x2f00, 0x6082, 0x7808, 0x6086,
2943 0x7810, 0x2070, 0x7014, 0x608a, 0x7010, 0x608e, 0x700c, 0x60c6,
2944 0x7008, 0x60ca, 0x686c, 0x60ce, 0x60ab, 0x0036, 0x60af, 0x95d5,
2945 0x60d7, 0x0000, 0xa582, 0x0080, 0x0048, 0x6b49, 0x6a00, 0xd2f4,
2946 0x0040, 0x6b47, 0x6a14, 0xa294, 0x00ff, 0x0078, 0x6b49, 0x2011,
2947 0x0000, 0x629e, 0x6017, 0x0016, 0x2009, 0x07d0, 0x60c4, 0xa084,
2948 0xfff0, 0xa005, 0x0040, 0x6b56, 0x2009, 0x1b58, 0x1078, 0x595f,
2949 0x037f, 0x047f, 0x057f, 0x0c7f, 0x0d7f, 0x0e7f, 0x007c, 0x7810,
2950 0x2070, 0x704c, 0xa084, 0x0003, 0xa086, 0x0002, 0x0040, 0x6bb7,
2951 0xd5bc, 0x0040, 0x6b73, 0xa185, 0x0100, 0x6062, 0x6266, 0x636a,
2952 0x646e, 0x0078, 0x6b7a, 0xa185, 0x0100, 0x6062, 0x6266, 0x606b,
2953 0x0000, 0x646e, 0x6073, 0x0880, 0x6077, 0x0008, 0x688c, 0x8000,
2954 0xa084, 0x00ff, 0x688e, 0x8007, 0x607a, 0x607f, 0x0000, 0x2f00,
2955 0x6086, 0x7808, 0x6082, 0x7060, 0x608a, 0x705c, 0x608e, 0x7080,
2956 0x60c6, 0x707c, 0x60ca, 0x707c, 0x792c, 0xa108, 0x792e, 0x7080,
2957 0x7928, 0xa109, 0x792a, 0x686c, 0x60ce, 0x60ab, 0x0036, 0x60af,
2958 0x95d5, 0x60d7, 0x0000, 0xa582, 0x0080, 0x0048, 0x6bb2, 0x6a00,
2959 0xd2f4, 0x0040, 0x6bb0, 0x6a14, 0xa294, 0x00ff, 0x0078, 0x6bb2,
2960 0x2011, 0x0000, 0x629e, 0x6017, 0x0012, 0x0078, 0x6b4c, 0xd5bc,
2961 0x0040, 0x6bc2, 0xa185, 0x0700, 0x6062, 0x6266, 0x636a, 0x646e,
2962 0x0078, 0x6bc9, 0xa185, 0x0700, 0x6062, 0x6266, 0x606b, 0x0000,
2963 0x646e, 0x1078, 0x488f, 0x0040, 0x6bdf, 0x0d7e, 0x7810, 0xa06d,
2964 0x684c, 0x0d7f, 0xa084, 0x2020, 0xa086, 0x2020, 0x00c0, 0x6bdf,
2965 0x7824, 0xc0cd, 0x7826, 0x6073, 0x0889, 0x0078, 0x6be1, 0x6073,
2966 0x0898, 0x6077, 0x0000, 0x688c, 0x8000, 0xa084, 0x00ff, 0x688e,
2967 0x8007, 0x607a, 0x607f, 0x0000, 0x2f00, 0x6086, 0x7808, 0x6082,
2968 0x7014, 0x608a, 0x7010, 0x608e, 0x700c, 0x60c6, 0x7008, 0x60ca,
2969 0x686c, 0x60ce, 0x60ab, 0x0036, 0x60af, 0x95d5, 0x60d7, 0x0000,
2970 0xa582, 0x0080, 0x0048, 0x6c0f, 0x6a00, 0xd2f4, 0x0040, 0x6c0d,
2971 0x6a14, 0xa294, 0x00ff, 0x0078, 0x6c0f, 0x2011, 0x0000, 0x629e,
2972 0x7824, 0xd0cc, 0x0040, 0x6c18, 0x6017, 0x0016, 0x0078, 0x6b4c,
2973 0x6017, 0x0012, 0x0078, 0x6b4c, 0x7a18, 0xa280, 0x0023, 0x2014,
2974 0x8210, 0xa294, 0x00ff, 0x2202, 0x8217, 0x007c, 0x0d7e, 0x2069,
2975 0xa5ab, 0x6843, 0x0001, 0x0d7f, 0x007c, 0x20e1, 0x9080, 0x60a3,
2976 0x0056, 0x60a7, 0x9575, 0x1078, 0x6c38, 0x1078, 0x594f, 0x007c,
2977 0x007e, 0x6014, 0xa084, 0x0004, 0xa085, 0x0009, 0x6016, 0x007f,
2978 0x007c, 0x007e, 0x0c7e, 0x2061, 0x0100, 0x6014, 0xa084, 0x0004,
2979 0xa085, 0x0008, 0x6016, 0x0c7f, 0x007f, 0x007c, 0x0c7e, 0x0d7e,
2980 0x017e, 0x027e, 0x2061, 0x0100, 0x2069, 0x0140, 0x6904, 0xa194,
2981 0x4000, 0x0040, 0x6c89, 0x1078, 0x6c41, 0x6803, 0x1000, 0x6803,
2982 0x0000, 0x0c7e, 0x2061, 0xa5ab, 0x6128, 0xa192, 0x00c8, 0x00c8,
2983 0x6c76, 0x8108, 0x612a, 0x6124, 0x0c7f, 0x81ff, 0x0040, 0x6c84,
2984 0x1078, 0x594f, 0x1078, 0x6c38, 0x0078, 0x6c84, 0x6124, 0xa1e5,
2985 0x0000, 0x0040, 0x6c81, 0x1078, 0xa241, 0x2009, 0x0014, 0x1078,
2986 0x756c, 0x0c7f, 0x0078, 0x6c84, 0x027f, 0x017f, 0x0d7f, 0x0c7f,
2987 0x007c, 0x2001, 0xa5c7, 0x2004, 0xa005, 0x00c0, 0x6c84, 0x0c7e,
2988 0x2061, 0xa5ab, 0x6128, 0xa192, 0x0003, 0x00c8, 0x6c76, 0x8108,
2989 0x612a, 0x0c7f, 0x1078, 0x594f, 0x1078, 0x4171, 0x0078, 0x6c84,
2990 0x0c7e, 0x0d7e, 0x0e7e, 0x017e, 0x027e, 0x1078, 0x5967, 0x2071,
2991 0xa5ab, 0x713c, 0x81ff, 0x0040, 0x6cca, 0x2061, 0x0100, 0x2069,
2992 0x0140, 0x6904, 0xa194, 0x4000, 0x0040, 0x6cd0, 0x6803, 0x1000,
2993 0x6803, 0x0000, 0x037e, 0x2019, 0x0001, 0x1078, 0x6e6c, 0x037f,
2994 0x713c, 0x2160, 0x1078, 0xa241, 0x2009, 0x004a, 0x1078, 0x756c,
2995 0x0078, 0x6cca, 0x027f, 0x017f, 0x0e7f, 0x0d7f, 0x0c7f, 0x007c,
2996 0x0078, 0x6cba, 0x0e7e, 0x0d7e, 0x0c7e, 0x067e, 0x057e, 0x047e,
2997 0x007e, 0x127e, 0x2091, 0x8000, 0x6018, 0x2068, 0x6ca0, 0x2071,
2998 0xa5ab, 0x7018, 0x2068, 0x8dff, 0x0040, 0x6cfc, 0x68a0, 0xa406,
2999 0x0040, 0x6cee, 0x6854, 0x2068, 0x0078, 0x6ce3, 0x6010, 0x2060,
3000 0x643c, 0x6540, 0x6e48, 0x2d60, 0x1078, 0x466a, 0x0040, 0x6cfc,
3001 0x1078, 0x7045, 0xa085, 0x0001, 0x127f, 0x007f, 0x047f, 0x057f,
3002 0x067f, 0x0c7f, 0x0d7f, 0x0e7f, 0x007c, 0x20a1, 0x020b, 0x1078,
3003 0x6567, 0x20a3, 0x1200, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x781c,
3004 0xa086, 0x0004, 0x00c0, 0x6d17, 0x6098, 0x0078, 0x6d18, 0x6030,
3005 0x20a2, 0x7834, 0x20a2, 0x7838, 0x20a2, 0x20a9, 0x0010, 0xa006,
3006 0x20a2, 0x00f0, 0x6d20, 0x20a2, 0x20a2, 0x60c3, 0x002c, 0x1078,
3007 0x6c2d, 0x007c, 0x157e, 0x147e, 0x20a1, 0x020b, 0x1078, 0x6567,
3008 0x20a3, 0x0f00, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x7808, 0x20a2,
3009 0x60c3, 0x0008, 0x1078, 0x6c2d, 0x147f, 0x157f, 0x007c, 0x157e,
3010 0x147e, 0x20a1, 0x020b, 0x1078, 0x65f8, 0x20a3, 0x0200, 0x20a3,
3011 0x0000, 0x20a9, 0x0006, 0x2011, 0xa340, 0x2019, 0xa341, 0x23a6,
3012 0x22a6, 0xa398, 0x0002, 0xa290, 0x0002, 0x00f0, 0x6d4f, 0x20a3,
3013 0x0000, 0x20a3, 0x0000, 0x60c3, 0x001c, 0x1078, 0x6c2d, 0x147f,
3014 0x157f, 0x007c, 0x157e, 0x147e, 0x017e, 0x027e, 0x20a1, 0x020b,
3015 0x1078, 0x65cf, 0x1078, 0x65e6, 0x7810, 0xa080, 0x0000, 0x2004,
3016 0xa080, 0x0015, 0x2098, 0x7808, 0xa088, 0x0002, 0x21a8, 0x53a6,
3017 0xa080, 0x0004, 0x8003, 0x60c2, 0x1078, 0x6c2d, 0x027f, 0x017f,
3018 0x147f, 0x157f, 0x007c, 0x157e, 0x147e, 0x20a1, 0x020b, 0x1078,
3019 0x6567, 0x20a3, 0x6200, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x7808,
3020 0x20a2, 0x60c3, 0x0008, 0x1078, 0x6c2d, 0x147f, 0x157f, 0x007c,
3021 0x157e, 0x147e, 0x017e, 0x027e, 0x20a1, 0x020b, 0x1078, 0x6567,
3022 0x7810, 0xa080, 0x0000, 0x2004, 0xa080, 0x0017, 0x2098, 0x7808,
3023 0xa088, 0x0002, 0x21a8, 0x53a6, 0x8003, 0x60c2, 0x1078, 0x6c2d,
3024 0x027f, 0x017f, 0x147f, 0x157f, 0x007c, 0x0e7e, 0x0c7e, 0x007e,
3025 0x127e, 0x2091, 0x8000, 0x2071, 0xa5ab, 0x700c, 0x2060, 0x8cff,
3026 0x0040, 0x6dd1, 0x1078, 0x8c3b, 0x00c0, 0x6dc8, 0x1078, 0x7a05,
3027 0x600c, 0x007e, 0x1078, 0x753d, 0x1078, 0x7045, 0x0c7f, 0x0078,
3028 0x6dbf, 0x700f, 0x0000, 0x700b, 0x0000, 0x127f, 0x007f, 0x0c7f,
3029 0x0e7f, 0x007c, 0x127e, 0x157e, 0x0f7e, 0x0e7e, 0x0d7e, 0x0c7e,
3030 0x027e, 0x017e, 0x007e, 0x2091, 0x8000, 0x2069, 0x0100, 0x2079,
3031 0x0140, 0x2071, 0xa5ab, 0x7024, 0x2060, 0x8cff, 0x0040, 0x6e2a,
3032 0x1078, 0x6c41, 0x68c3, 0x0000, 0x1078, 0x595a, 0x2009, 0x0013,
3033 0x1078, 0x756c, 0x20a9, 0x01f4, 0x6824, 0xd094, 0x0040, 0x6e0d,
3034 0x6827, 0x0004, 0x7804, 0xa084, 0x4000, 0x0040, 0x6e1f, 0x7803,
3035 0x1000, 0x7803, 0x0000, 0x0078, 0x6e1f, 0xd084, 0x0040, 0x6e14,
3036 0x6827, 0x0001, 0x0078, 0x6e16, 0x00f0, 0x6dfc, 0x7804, 0xa084,
3037 0x1000, 0x0040, 0x6e1f, 0x7803, 0x0100, 0x7803, 0x0000, 0x6824,
3038 0x007f, 0x017f, 0x027f, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f, 0x157f,
3039 0x127f, 0x007c, 0x2001, 0xa300, 0x2004, 0xa096, 0x0001, 0x0040,
3040 0x6e62, 0xa096, 0x0004, 0x0040, 0x6e62, 0x6817, 0x0008, 0x68c3,
3041 0x0000, 0x2011, 0x4129, 0x1078, 0x58d4, 0x20a9, 0x01f4, 0x6824,
3042 0xd094, 0x0040, 0x6e50, 0x6827, 0x0004, 0x7804, 0xa084, 0x4000,
3043 0x0040, 0x6e62, 0x7803, 0x1000, 0x7803, 0x0000, 0x0078, 0x6e62,
3044 0xd084, 0x0040, 0x6e57, 0x6827, 0x0001, 0x0078, 0x6e59, 0x00f0,
3045 0x6e3f, 0x7804, 0xa084, 0x1000, 0x0040, 0x6e62, 0x7803, 0x0100,
3046 0x7803, 0x0000, 0x007f, 0x017f, 0x027f, 0x0c7f, 0x0d7f, 0x0e7f,
3047 0x0f7f, 0x157f, 0x127f, 0x007c, 0x127e, 0x157e, 0x0f7e, 0x0e7e,
3048 0x0d7e, 0x0c7e, 0x027e, 0x017e, 0x007e, 0x2091, 0x8000, 0x2069,
3049 0x0100, 0x2079, 0x0140, 0x2071, 0xa5ab, 0x703c, 0x2060, 0x8cff,
3050 0x0040, 0x6ee8, 0x6817, 0x0010, 0x2009, 0x00fa, 0x8109, 0x00c0,
3051 0x6e86, 0x68c7, 0x0000, 0x68cb, 0x0008, 0x1078, 0x5967, 0x1078,
3052 0x1f31, 0x047e, 0x057e, 0x2009, 0x017f, 0x212c, 0x200b, 0x00a5,
3053 0x2021, 0x0169, 0x2404, 0xa084, 0x000f, 0xa086, 0x0004, 0x00c0,
3054 0x6eb7, 0x68c7, 0x0000, 0x68cb, 0x0008, 0x0e7e, 0x0f7e, 0x2079,
3055 0x0020, 0x2071, 0xa602, 0x6814, 0xa084, 0x0004, 0xa085, 0x0012,
3056 0x6816, 0x7803, 0x0008, 0x7003, 0x0000, 0x0f7f, 0x0e7f, 0x250a,
3057 0x057f, 0x047f, 0xa39d, 0x0000, 0x00c0, 0x6ec2, 0x2009, 0x0049,
3058 0x1078, 0x756c, 0x20a9, 0x03e8, 0x6824, 0xd094, 0x0040, 0x6ed5,
3059 0x6827, 0x0004, 0x7804, 0xa084, 0x4000, 0x0040, 0x6ee7, 0x7803,
3060 0x1000, 0x7803, 0x0000, 0x0078, 0x6ee7, 0xd08c, 0x0040, 0x6edc,
3061 0x6827, 0x0002, 0x0078, 0x6ede, 0x00f0, 0x6ec4, 0x7804, 0xa084,
3062 0x1000, 0x0040, 0x6ee7, 0x7803, 0x0100, 0x7803, 0x0000, 0x6824,
3063 0x007f, 0x017f, 0x027f, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f, 0x157f,
3064 0x127f, 0x007c, 0x0d7e, 0x127e, 0x2091, 0x8000, 0x2069, 0xa5ab,
3065 0x6a06, 0x127f, 0x0d7f, 0x007c, 0x0d7e, 0x127e, 0x2091, 0x8000,
3066 0x2069, 0xa5ab, 0x6a32, 0x127f, 0x0d7f, 0x007c, 0x0f7e, 0x0e7e,
3067 0x0c7e, 0x067e, 0x007e, 0x127e, 0x2071, 0xa5ab, 0x7614, 0x2660,
3068 0x2678, 0x2091, 0x8000, 0x8cff, 0x0040, 0x6f46, 0x601c, 0xa206,
3069 0x00c0, 0x6f41, 0x7014, 0xac36, 0x00c0, 0x6f20, 0x660c, 0x7616,
3070 0x7010, 0xac36, 0x00c0, 0x6f2e, 0x2c00, 0xaf36, 0x0040, 0x6f2c,
3071 0x2f00, 0x7012, 0x0078, 0x6f2e, 0x7013, 0x0000, 0x660c, 0x067e,
3072 0x2c00, 0xaf06, 0x0040, 0x6f37, 0x7e0e, 0x0078, 0x6f38, 0x2678,
3073 0x600f, 0x0000, 0x1078, 0x8c01, 0x1078, 0x7045, 0x0c7f, 0x0078,
3074 0x6f13, 0x2c78, 0x600c, 0x2060, 0x0078, 0x6f13, 0x127f, 0x007f,
3075 0x067f, 0x0c7f, 0x0e7f, 0x0f7f, 0x007c, 0x157e, 0x147e, 0x20a1,
3076 0x020b, 0x1078, 0x6806, 0x7810, 0x20a2, 0xa006, 0x20a2, 0x20a2,
3077 0x20a2, 0x20a2, 0x20a3, 0x1000, 0x0078, 0x6fa0, 0x157e, 0x147e,
3078 0x20a1, 0x020b, 0x1078, 0x6806, 0x7810, 0x20a2, 0xa006, 0x20a2,
3079 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x4000, 0x0078, 0x6fa0, 0x157e,
3080 0x147e, 0x20a1, 0x020b, 0x1078, 0x6806, 0x7810, 0x20a2, 0xa006,
3081 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x2000, 0x0078, 0x6fa0,
3082 0x157e, 0x147e, 0x20a1, 0x020b, 0x1078, 0x6806, 0x7810, 0x20a2,
3083 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x0400, 0x0078,
3084 0x6fa0, 0x157e, 0x147e, 0x20a1, 0x020b, 0x1078, 0x6806, 0x7810,
3085 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x0200,
3086 0x1078, 0x7050, 0x60c3, 0x0020, 0x1078, 0x6c2d, 0x147f, 0x157f,
3087 0x007c, 0x127e, 0x0c7e, 0x2091, 0x8000, 0x2061, 0x0100, 0x6120,
3088 0xd1b4, 0x00c0, 0x6fb8, 0xd1bc, 0x00c0, 0x7002, 0x0078, 0x7042,
3089 0x2009, 0x017f, 0x200b, 0x00a1, 0x157e, 0x007e, 0x0d7e, 0x2069,
3090 0x0140, 0x20a9, 0x001e, 0x2009, 0x0169, 0x6804, 0xa084, 0x4000,
3091 0x0040, 0x6ff9, 0x6020, 0xd0b4, 0x0040, 0x6ff9, 0x6024, 0xd094,
3092 0x00c0, 0x6ff9, 0x2104, 0xa084, 0x000f, 0xa086, 0x0004, 0x00c0,
3093 0x6ff9, 0x00f0, 0x6fc5, 0x027e, 0x6198, 0xa18c, 0x00ff, 0x8107,
3094 0x6130, 0xa18c, 0x00ff, 0xa10d, 0x6088, 0x628c, 0x618e, 0x608b,
3095 0xbc91, 0x6043, 0x0001, 0x6043, 0x0000, 0x608a, 0x628e, 0x6024,
3096 0xd094, 0x00c0, 0x6ff8, 0x6a04, 0xa294, 0x4000, 0x00c0, 0x6fef,
3097 0x027f, 0x0d7f, 0x007f, 0x157f, 0x2009, 0x017f, 0x200b, 0x0000,
3098 0x0078, 0x7042, 0x2009, 0x017f, 0x200b, 0x00a1, 0x157e, 0x007e,
3099 0x0d7e, 0x2069, 0x0140, 0x20a9, 0x001e, 0x2009, 0x0169, 0x6804,
3100 0xa084, 0x4000, 0x0040, 0x703b, 0x6020, 0xd0bc, 0x0040, 0x703b,
3101 0x2104, 0xa084, 0x000f, 0xa086, 0x0004, 0x00c0, 0x703b, 0x00f0,
3102 0x700f, 0x027e, 0x6164, 0xa18c, 0x00ff, 0x8107, 0x6130, 0xa18c,
3103 0x00ff, 0xa10d, 0x6088, 0x628c, 0x608b, 0xbc91, 0x618e, 0x6043,
3104 0x0001, 0x6043, 0x0000, 0x608a, 0x628e, 0x6a04, 0xa294, 0x4000,
3105 0x00c0, 0x7035, 0x027f, 0x0d7f, 0x007f, 0x157f, 0x2009, 0x017f,
3106 0x200b, 0x0000, 0x0c7f, 0x127f, 0x007c, 0x0e7e, 0x2071, 0xa5ab,
3107 0x7020, 0xa005, 0x0040, 0x704e, 0x8001, 0x7022, 0x0e7f, 0x007c,
3108 0x20a9, 0x0008, 0x20a2, 0x00f0, 0x7052, 0x20a2, 0x20a2, 0x007c,
3109 0x0f7e, 0x0e7e, 0x0d7e, 0x0c7e, 0x077e, 0x067e, 0x007e, 0x127e,
3110 0x2091, 0x8000, 0x2071, 0xa5ab, 0x7614, 0x2660, 0x2678, 0x2039,
3111 0x0001, 0x87ff, 0x0040, 0x70f4, 0x8cff, 0x0040, 0x70f4, 0x601c,
3112 0xa086, 0x0006, 0x00c0, 0x70ef, 0x88ff, 0x0040, 0x707f, 0x2800,
3113 0xac06, 0x00c0, 0x70ef, 0x2039, 0x0000, 0x0078, 0x708a, 0x6018,
3114 0xa206, 0x00c0, 0x70ef, 0x85ff, 0x0040, 0x708a, 0x6020, 0xa106,
3115 0x00c0, 0x70ef, 0x7024, 0xac06, 0x00c0, 0x70ba, 0x2069, 0x0100,
3116 0x68c0, 0xa005, 0x0040, 0x70b5, 0x1078, 0x595a, 0x6817, 0x0008,
3117 0x68c3, 0x0000, 0x1078, 0x7188, 0x7027, 0x0000, 0x037e, 0x2069,
3118 0x0140, 0x6b04, 0xa384, 0x1000, 0x0040, 0x70aa, 0x6803, 0x0100,
3119 0x6803, 0x0000, 0x2069, 0x0100, 0x6824, 0xd084, 0x0040, 0x70b2,
3120 0x6827, 0x0001, 0x037f, 0x0078, 0x70ba, 0x6003, 0x0009, 0x630a,
3121 0x0078, 0x70ef, 0x7014, 0xac36, 0x00c0, 0x70c0, 0x660c, 0x7616,
3122 0x7010, 0xac36, 0x00c0, 0x70ce, 0x2c00, 0xaf36, 0x0040, 0x70cc,
3123 0x2f00, 0x7012, 0x0078, 0x70ce, 0x7013, 0x0000, 0x660c, 0x067e,
3124 0x2c00, 0xaf06, 0x0040, 0x70d7, 0x7e0e, 0x0078, 0x70d8, 0x2678,
3125 0x89ff, 0x00c0, 0x70e7, 0x600f, 0x0000, 0x6010, 0x2068, 0x1078,
3126 0x8a44, 0x0040, 0x70e5, 0x1078, 0x9e70, 0x1078, 0x8c01, 0x1078,
3127 0x7045, 0x88ff, 0x00c0, 0x70fe, 0x0c7f, 0x0078, 0x7069, 0x2c78,
3128 0x600c, 0x2060, 0x0078, 0x7069, 0xa006, 0x127f, 0x007f, 0x067f,
3129 0x077f, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f, 0x007c, 0x6017, 0x0000,
3130 0x0c7f, 0xa8c5, 0x0001, 0x0078, 0x70f5, 0x0f7e, 0x0e7e, 0x0d7e,
3131 0x0c7e, 0x067e, 0x027e, 0x007e, 0x127e, 0x2091, 0x8000, 0x2071,
3132 0xa5ab, 0x7638, 0x2660, 0x2678, 0x8cff, 0x0040, 0x7177, 0x601c,
3133 0xa086, 0x0006, 0x00c0, 0x7172, 0x87ff, 0x0040, 0x7125, 0x2700,
3134 0xac06, 0x00c0, 0x7172, 0x0078, 0x7130, 0x6018, 0xa206, 0x00c0,
3135 0x7172, 0x85ff, 0x0040, 0x7130, 0x6020, 0xa106, 0x00c0, 0x7172,
3136 0x703c, 0xac06, 0x00c0, 0x7142, 0x037e, 0x2019, 0x0001, 0x1078,
3137 0x6e6c, 0x7033, 0x0000, 0x703f, 0x0000, 0x7043, 0x0000, 0x7047,
3138 0x0000, 0x037f, 0x7038, 0xac36, 0x00c0, 0x7148, 0x660c, 0x763a,
3139 0x7034, 0xac36, 0x00c0, 0x7156, 0x2c00, 0xaf36, 0x0040, 0x7154,
3140 0x2f00, 0x7036, 0x0078, 0x7156, 0x7037, 0x0000, 0x660c, 0x067e,
3141 0x2c00, 0xaf06, 0x0040, 0x715f, 0x7e0e, 0x0078, 0x7160, 0x2678,
3142 0x600f, 0x0000, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x716a,
3143 0x1078, 0x9e70, 0x1078, 0x8c01, 0x87ff, 0x00c0, 0x7181, 0x0c7f,
3144 0x0078, 0x7114, 0x2c78, 0x600c, 0x2060, 0x0078, 0x7114, 0xa006,
3145 0x127f, 0x007f, 0x027f, 0x067f, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f,
3146 0x007c, 0x6017, 0x0000, 0x0c7f, 0xa7bd, 0x0001, 0x0078, 0x7178,
3147 0x0e7e, 0x2071, 0xa5ab, 0x2001, 0xa300, 0x2004, 0xa086, 0x0002,
3148 0x00c0, 0x7196, 0x7007, 0x0005, 0x0078, 0x7198, 0x7007, 0x0000,
3149 0x0e7f, 0x007c, 0x0f7e, 0x0e7e, 0x0c7e, 0x067e, 0x027e, 0x007e,
3150 0x127e, 0x2091, 0x8000, 0x2071, 0xa5ab, 0x2c10, 0x7638, 0x2660,
3151 0x2678, 0x8cff, 0x0040, 0x71d8, 0x2200, 0xac06, 0x00c0, 0x71d3,
3152 0x7038, 0xac36, 0x00c0, 0x71b6, 0x660c, 0x763a, 0x7034, 0xac36,
3153 0x00c0, 0x71c4, 0x2c00, 0xaf36, 0x0040, 0x71c2, 0x2f00, 0x7036,
3154 0x0078, 0x71c4, 0x7037, 0x0000, 0x660c, 0x2c00, 0xaf06, 0x0040,
3155 0x71cc, 0x7e0e, 0x0078, 0x71cd, 0x2678, 0x600f, 0x0000, 0xa085,
3156 0x0001, 0x0078, 0x71d8, 0x2c78, 0x600c, 0x2060, 0x0078, 0x71a9,
3157 0x127f, 0x007f, 0x027f, 0x067f, 0x0c7f, 0x0e7f, 0x0f7f, 0x007c,
3158 0x0f7e, 0x0e7e, 0x0d7e, 0x0c7e, 0x067e, 0x007e, 0x127e, 0x2091,
3159 0x8000, 0x2071, 0xa5ab, 0x760c, 0x2660, 0x2678, 0x8cff, 0x0040,
3160 0x7279, 0x6018, 0xa080, 0x0028, 0x2004, 0xa206, 0x00c0, 0x7274,
3161 0x7024, 0xac06, 0x00c0, 0x721f, 0x2069, 0x0100, 0x68c0, 0xa005,
3162 0x0040, 0x724d, 0x1078, 0x6c41, 0x68c3, 0x0000, 0x1078, 0x7188,
3163 0x7027, 0x0000, 0x037e, 0x2069, 0x0140, 0x6b04, 0xa384, 0x1000,
3164 0x0040, 0x7216, 0x6803, 0x0100, 0x6803, 0x0000, 0x2069, 0x0100,
3165 0x6824, 0xd084, 0x0040, 0x721e, 0x6827, 0x0001, 0x037f, 0x700c,
3166 0xac36, 0x00c0, 0x7225, 0x660c, 0x760e, 0x7008, 0xac36, 0x00c0,
3167 0x7233, 0x2c00, 0xaf36, 0x0040, 0x7231, 0x2f00, 0x700a, 0x0078,
3168 0x7233, 0x700b, 0x0000, 0x660c, 0x067e, 0x2c00, 0xaf06, 0x0040,
3169 0x723c, 0x7e0e, 0x0078, 0x723d, 0x2678, 0x600f, 0x0000, 0x1078,
3170 0x8c27, 0x00c0, 0x7251, 0x1078, 0x2839, 0x1078, 0x8c3b, 0x00c0,
3171 0x726d, 0x1078, 0x7a05, 0x0078, 0x726d, 0x1078, 0x7188, 0x0078,
3172 0x721f, 0x1078, 0x8c3b, 0x00c0, 0x7259, 0x1078, 0x7a05, 0x0078,
3173 0x726d, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x726d, 0x601c,
3174 0xa086, 0x0003, 0x00c0, 0x7281, 0x6837, 0x0103, 0x6b4a, 0x6847,
3175 0x0000, 0x1078, 0x4982, 0x1078, 0x8bf4, 0x1078, 0x8c01, 0x1078,
3176 0x7045, 0x0c7f, 0x0078, 0x71ee, 0x2c78, 0x600c, 0x2060, 0x0078,
3177 0x71ee, 0x127f, 0x007f, 0x067f, 0x0c7f, 0x0d7f, 0x0e7f, 0x0f7f,
3178 0x007c, 0x601c, 0xa086, 0x0006, 0x00c0, 0x726d, 0x1078, 0x9e70,
3179 0x0078, 0x726d, 0x037e, 0x157e, 0x137e, 0x147e, 0x3908, 0xa006,
3180 0xa190, 0x0020, 0x221c, 0xa39e, 0x260c, 0x00c0, 0x729b, 0x8210,
3181 0x8000, 0x0078, 0x7292, 0xa005, 0x0040, 0x72a7, 0x20a9, 0x0020,
3182 0x2198, 0x8211, 0xa282, 0x0020, 0x20c8, 0x20a0, 0x53a3, 0x147f,
3183 0x137f, 0x157f, 0x037f, 0x007c, 0x0d7e, 0x20a1, 0x020b, 0x1078,
3184 0x65f8, 0x20a3, 0x0200, 0x20a3, 0x0014, 0x60c3, 0x0014, 0x20a3,
3185 0x0000, 0x20a3, 0x0000, 0x2099, 0xa5a3, 0x20a9, 0x0004, 0x53a6,
3186 0x20a3, 0x0004, 0x20a3, 0x7878, 0x20a3, 0x0000, 0x20a3, 0x0000,
3187 0x1078, 0x6c2d, 0x0d7f, 0x007c, 0x20a1, 0x020b, 0x1078, 0x65f8,
3188 0x20a3, 0x0214, 0x20a3, 0x0018, 0x20a3, 0x0800, 0x7810, 0xa084,
3189 0xff00, 0x20a2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000,
3190 0x20a3, 0x0000, 0x7810, 0xa084, 0x00ff, 0x20a2, 0x7828, 0x20a2,
3191 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0018, 0x1078, 0x6c2d,
3192 0x007c, 0x0d7e, 0x017e, 0x2f68, 0x2009, 0x0035, 0x1078, 0x8ef5,
3193 0x00c0, 0x7361, 0x20a1, 0x020b, 0x1078, 0x6567, 0x20a3, 0x1300,
3194 0x20a3, 0x0000, 0x7828, 0x2068, 0x681c, 0xa086, 0x0003, 0x0040,
3195 0x733d, 0x7818, 0xa080, 0x0028, 0x2014, 0xa286, 0x007e, 0x00c0,
3196 0x7317, 0x20a3, 0x00ff, 0x20a3, 0xfffe, 0x0078, 0x7352, 0xa286,
3197 0x007f, 0x00c0, 0x7321, 0x20a3, 0x00ff, 0x20a3, 0xfffd, 0x0078,
3198 0x7352, 0xd2bc, 0x0040, 0x7337, 0xa286, 0x0080, 0x00c0, 0x732e,
3199 0x20a3, 0x00ff, 0x20a3, 0xfffc, 0x0078, 0x7352, 0xa2e8, 0xa434,
3200 0x2d6c, 0x6810, 0x20a2, 0x6814, 0x20a2, 0x0078, 0x7352, 0x20a3,
3201 0x0000, 0x6098, 0x20a2, 0x0078, 0x7352, 0x7818, 0xa080, 0x0028,
3202 0x2004, 0xa082, 0x007e, 0x0048, 0x734e, 0x0d7e, 0x2069, 0xa31a,
3203 0x2da6, 0x8d68, 0x2da6, 0x0d7f, 0x0078, 0x7352, 0x20a3, 0x0000,
3204 0x6030, 0x20a2, 0x7834, 0x20a2, 0x7838, 0x20a2, 0x20a3, 0x0000,
3205 0x20a3, 0x0000, 0x60c3, 0x000c, 0x1078, 0x6c2d, 0x017f, 0x0d7f,
3206 0x007c, 0x7817, 0x0001, 0x7803, 0x0006, 0x017f, 0x0d7f, 0x007c,
3207 0x0d7e, 0x027e, 0x7928, 0x2168, 0x691c, 0xa186, 0x0006, 0x0040,
3208 0x738a, 0xa186, 0x0003, 0x0040, 0x73e5, 0xa186, 0x0005, 0x0040,
3209 0x73c8, 0xa186, 0x0004, 0x0040, 0x73b8, 0xa186, 0x0008, 0x0040,
3210 0x73d2, 0x7807, 0x0037, 0x7813, 0x1700, 0x1078, 0x7450, 0x027f,
3211 0x0d7f, 0x007c, 0x1078, 0x740d, 0x2009, 0x4000, 0x6800, 0x0079,
3212 0x7391, 0x73a4, 0x73b2, 0x73a6, 0x73b2, 0x73ad, 0x73a4, 0x73a4,
3213 0x73b2, 0x73b2, 0x73b2, 0x73b2, 0x73a4, 0x73a4, 0x73a4, 0x73a4,
3214 0x73a4, 0x73b2, 0x73a4, 0x73b2, 0x1078, 0x1328, 0x6824, 0xd0e4,
3215 0x0040, 0x73ad, 0xd0cc, 0x0040, 0x73b0, 0xa00e, 0x0078, 0x73b2,
3216 0x2009, 0x2000, 0x6828, 0x20a2, 0x682c, 0x20a2, 0x0078, 0x7403,
3217 0x1078, 0x740d, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x2009, 0x4000,
3218 0x6a00, 0xa286, 0x0002, 0x00c0, 0x73c6, 0xa00e, 0x0078, 0x7403,
3219 0x1078, 0x740d, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x2009, 0x4000,
3220 0x0078, 0x7403, 0x1078, 0x740d, 0x20a3, 0x0000, 0x20a3, 0x0000,
3221 0x2009, 0x4000, 0xa286, 0x0005, 0x0040, 0x73e2, 0xa286, 0x0002,
3222 0x00c0, 0x73e3, 0xa00e, 0x0078, 0x7403, 0x1078, 0x740d, 0x6810,
3223 0x2068, 0x697c, 0x6810, 0xa112, 0x6980, 0x6814, 0xa103, 0x20a2,
3224 0x22a2, 0x7928, 0xa180, 0x0000, 0x2004, 0xa08e, 0x0002, 0x0040,
3225 0x7401, 0xa08e, 0x0004, 0x0040, 0x7401, 0x2009, 0x4000, 0x0078,
3226 0x7403, 0x2009, 0x0000, 0x21a2, 0x20a3, 0x0000, 0x60c3, 0x0018,
3227 0x1078, 0x6c2d, 0x027f, 0x0d7f, 0x007c, 0x037e, 0x047e, 0x057e,
3228 0x067e, 0x20a1, 0x020b, 0x1078, 0x65f8, 0xa006, 0x20a3, 0x0200,
3229 0x20a2, 0x7934, 0x21a2, 0x7938, 0x21a2, 0x7818, 0xa080, 0x0028,
3230 0x2004, 0xa092, 0x007e, 0x0048, 0x7433, 0x0d7e, 0x2069, 0xa31a,
3231 0x2d2c, 0x8d68, 0x2d34, 0xa0e8, 0xa434, 0x2d6c, 0x6b10, 0x6c14,
3232 0x0d7f, 0x0078, 0x7439, 0x2019, 0x0000, 0x6498, 0x2029, 0x0000,
3233 0x6630, 0x7828, 0xa080, 0x0007, 0x2004, 0xa086, 0x0003, 0x00c0,
3234 0x7447, 0x25a2, 0x26a2, 0x23a2, 0x24a2, 0x0078, 0x744b, 0x23a2,
3235 0x24a2, 0x25a2, 0x26a2, 0x067f, 0x057f, 0x047f, 0x037f, 0x007c,
3236 0x20a1, 0x020b, 0x1078, 0x65f8, 0x20a3, 0x0100, 0x20a3, 0x0000,
3237 0x20a3, 0x0009, 0x7810, 0x20a2, 0x60c3, 0x0008, 0x1078, 0x6c2d,
3238 0x007c, 0x20a1, 0x020b, 0x1078, 0x655e, 0x20a3, 0x1400, 0x20a3,
3239 0x0000, 0x7834, 0x20a2, 0x7838, 0x20a2, 0x7828, 0x20a2, 0x782c,
3240 0x20a2, 0x7830, 0xa084, 0x00ff, 0x8007, 0x20a2, 0x20a3, 0x0000,
3241 0x60c3, 0x0010, 0x1078, 0x6c2d, 0x007c, 0x20a1, 0x020b, 0x1078,
3242 0x65ef, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x7828, 0x20a2, 0x7810,
3243 0x20a2, 0x60c3, 0x0008, 0x1078, 0x6c2d, 0x007c, 0x147e, 0x20a1,
3244 0x020b, 0x1078, 0x7499, 0x60c3, 0x0000, 0x1078, 0x6c2d, 0x147f,
3245 0x007c, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028,
3246 0x2004, 0xd0bc, 0x0040, 0x74b6, 0x0d7e, 0xa0e8, 0xa434, 0x2d6c,
3247 0x6810, 0xa085, 0x0300, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xa31a,
3248 0x2da6, 0x8d68, 0x2da6, 0x0d7f, 0x0078, 0x74be, 0x20a3, 0x0300,
3249 0x6298, 0x22a2, 0x20a3, 0x0000, 0x6230, 0x22a2, 0x20a3, 0x0819,
3250 0x20a3, 0x0000, 0x1078, 0x6c1c, 0x22a2, 0x20a3, 0x0000, 0x2fa2,
3251 0x7a08, 0x22a2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x007c, 0x2061,
3252 0xaa00, 0x2a70, 0x7060, 0x7046, 0x704b, 0xaa00, 0x007c, 0x0e7e,
3253 0x127e, 0x2071, 0xa300, 0x2091, 0x8000, 0x7544, 0xa582, 0x0010,
3254 0x0048, 0x7509, 0x7048, 0x2060, 0x6000, 0xa086, 0x0000, 0x0040,
3255 0x74f5, 0xace0, 0x0010, 0x7054, 0xac02, 0x00c8, 0x74f1, 0x0078,
3256 0x74e4, 0x2061, 0xaa00, 0x0078, 0x74e4, 0x6003, 0x0008, 0x8529,
3257 0x7546, 0xaca8, 0x0010, 0x7054, 0xa502, 0x00c8, 0x7505, 0x754a,
3258 0xa085, 0x0001, 0x127f, 0x0e7f, 0x007c, 0x704b, 0xaa00, 0x0078,
3259 0x7500, 0xa006, 0x0078, 0x7502, 0x0e7e, 0x2071, 0xa300, 0x7544,
3260 0xa582, 0x0010, 0x0048, 0x753a, 0x7048, 0x2060, 0x6000, 0xa086,
3261 0x0000, 0x0040, 0x7527, 0xace0, 0x0010, 0x7054, 0xac02, 0x00c8,
3262 0x7523, 0x0078, 0x7516, 0x2061, 0xaa00, 0x0078, 0x7516, 0x6003,
3263 0x0008, 0x8529, 0x7546, 0xaca8, 0x0010, 0x7054, 0xa502, 0x00c8,
3264 0x7536, 0x754a, 0xa085, 0x0001, 0x0e7f, 0x007c, 0x704b, 0xaa00,
3265 0x0078, 0x7532, 0xa006, 0x0078, 0x7534, 0xac82, 0xaa00, 0x1048,
3266 0x1328, 0x2001, 0xa315, 0x2004, 0xac02, 0x10c8, 0x1328, 0xa006,
3267 0x6006, 0x600a, 0x600e, 0x6012, 0x6016, 0x601a, 0x601f, 0x0000,
3268 0x6003, 0x0000, 0x6022, 0x6026, 0x602a, 0x602e, 0x6032, 0x6036,
3269 0x603a, 0x603e, 0x2061, 0xa300, 0x6044, 0x8000, 0x6046, 0xa086,
3270 0x0001, 0x0040, 0x7564, 0x007c, 0x127e, 0x2091, 0x8000, 0x1078,
3271 0x6109, 0x127f, 0x0078, 0x7563, 0x601c, 0xa084, 0x000f, 0x0079,
3272 0x7571, 0x757a, 0x758b, 0x75a7, 0x75c3, 0x8f2d, 0x8f49, 0x8f65,
3273 0x757a, 0x758b, 0xa186, 0x0013, 0x00c0, 0x7583, 0x1078, 0x6010,
3274 0x1078, 0x6109, 0x007c, 0xa18e, 0x0047, 0x00c0, 0x758a, 0xa016,
3275 0x1078, 0x15ec, 0x007c, 0x067e, 0x6000, 0xa0b2, 0x0010, 0x10c8,
3276 0x1328, 0x1079, 0x7595, 0x067f, 0x007c, 0x75a5, 0x7891, 0x7a34,
3277 0x75a5, 0x7ab8, 0x75df, 0x75a5, 0x75a5, 0x7823, 0x7e6d, 0x75a5,
3278 0x75a5, 0x75a5, 0x75a5, 0x75a5, 0x75a5, 0x1078, 0x1328, 0x067e,
3279 0x6000, 0xa0b2, 0x0010, 0x10c8, 0x1328, 0x1079, 0x75b1, 0x067f,
3280 0x007c, 0x75c1, 0x8522, 0x75c1, 0x75c1, 0x75c1, 0x75c1, 0x75c1,
3281 0x75c1, 0x84c5, 0x86a8, 0x75c1, 0x8552, 0x85d8, 0x8552, 0x85d8,
3282 0x75c1, 0x1078, 0x1328, 0x067e, 0x6000, 0xa0b2, 0x0010, 0x10c8,
3283 0x1328, 0x1079, 0x75cd, 0x067f, 0x007c, 0x75dd, 0x7eb4, 0x7f81,
3284 0x80c6, 0x8242, 0x75dd, 0x75dd, 0x75dd, 0x7e8d, 0x846d, 0x8471,
3285 0x75dd, 0x75dd, 0x75dd, 0x75dd, 0x84a1, 0x1078, 0x1328, 0xa1b6,
3286 0x0015, 0x00c0, 0x75e7, 0x1078, 0x753d, 0x0078, 0x75ed, 0xa1b6,
3287 0x0016, 0x10c0, 0x1328, 0x1078, 0x753d, 0x007c, 0x20a9, 0x000e,
3288 0x2e98, 0x6010, 0x20a0, 0x53a3, 0x20a9, 0x0006, 0x3310, 0x3420,
3289 0x9398, 0x94a0, 0x3318, 0x3428, 0x222e, 0x2326, 0xa290, 0x0002,
3290 0xa5a8, 0x0002, 0xa398, 0x0002, 0xa4a0, 0x0002, 0x00f0, 0x75fc,
3291 0x0e7e, 0x1078, 0x8a44, 0x0040, 0x7613, 0x6010, 0x2070, 0x7007,
3292 0x0000, 0x7037, 0x0103, 0x0e7f, 0x1078, 0x753d, 0x007c, 0x0d7e,
3293 0x037e, 0x7330, 0xa386, 0x0200, 0x00c0, 0x7624, 0x6018, 0x2068,
3294 0x6813, 0x00ff, 0x6817, 0xfffd, 0x6010, 0xa005, 0x0040, 0x762e,
3295 0x2068, 0x6807, 0x0000, 0x6837, 0x0103, 0x6b32, 0x1078, 0x753d,
3296 0x037f, 0x0d7f, 0x007c, 0x017e, 0x20a9, 0x002a, 0xae80, 0x000c,
3297 0x2098, 0x6010, 0xa080, 0x0002, 0x20a0, 0x53a3, 0x20a9, 0x002a,
3298 0x6010, 0xa080, 0x0001, 0x2004, 0xa080, 0x0002, 0x20a0, 0x53a3,
3299 0x0e7e, 0x6010, 0x2004, 0x2070, 0x7037, 0x0103, 0x0e7f, 0x1078,
3300 0x753d, 0x017f, 0x007c, 0x0e7e, 0x0d7e, 0x603f, 0x0000, 0x2c68,
3301 0x017e, 0x2009, 0x0035, 0x1078, 0x8ef5, 0x017f, 0x00c0, 0x766f,
3302 0x027e, 0x6228, 0x2268, 0x027f, 0x2071, 0xa88c, 0x6b1c, 0xa386,
3303 0x0003, 0x0040, 0x7673, 0xa386, 0x0006, 0x0040, 0x7677, 0x1078,
3304 0x753d, 0x0078, 0x7679, 0x1078, 0x767c, 0x0078, 0x7679, 0x1078,
3305 0x771e, 0x0d7f, 0x0e7f, 0x007c, 0x0f7e, 0x6810, 0x2078, 0xa186,
3306 0x0015, 0x0040, 0x7705, 0xa18e, 0x0016, 0x00c0, 0x771c, 0x700c,
3307 0xa084, 0xff00, 0xa086, 0x1700, 0x00c0, 0x76e0, 0x8fff, 0x0040,
3308 0x771a, 0x6808, 0xa086, 0xffff, 0x00c0, 0x7709, 0x784c, 0xa084,
3309 0x0060, 0xa086, 0x0020, 0x00c0, 0x76a7, 0x797c, 0x7810, 0xa106,
3310 0x00c0, 0x7709, 0x7980, 0x7814, 0xa106, 0x00c0, 0x7709, 0x1078,
3311 0x8bf4, 0x6830, 0x7852, 0x784c, 0xc0dc, 0xc0f4, 0xc0d4, 0x784e,
3312 0x027e, 0xa00e, 0x6a14, 0x2001, 0x000a, 0x1078, 0x5a98, 0x7854,
3313 0xa20a, 0x0048, 0x76bc, 0x8011, 0x7a56, 0x82ff, 0x027f, 0x00c0,
3314 0x76c8, 0x0c7e, 0x2d60, 0x1078, 0x8832, 0x0c7f, 0x0078, 0x771a,
3315 0x0c7e, 0x0d7e, 0x2f68, 0x6838, 0xd0fc, 0x00c0, 0x76d3, 0x1078,
3316 0x4290, 0x0078, 0x76d5, 0x1078, 0x436e, 0x0d7f, 0x0c7f, 0x00c0,
3317 0x7709, 0x0c7e, 0x2d60, 0x1078, 0x753d, 0x0c7f, 0x0078, 0x771a,
3318 0x7008, 0xa086, 0x000b, 0x00c0, 0x76fa, 0x6018, 0x200c, 0xc1bc,
3319 0x2102, 0x0c7e, 0x2d60, 0x7853, 0x0003, 0x6007, 0x0085, 0x6003,
3320 0x000b, 0x601f, 0x0002, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0c7f,
3321 0x0078, 0x771a, 0x700c, 0xa086, 0x2a00, 0x00c0, 0x7709, 0x2001,
3322 0xa5a2, 0x2004, 0x683e, 0x0078, 0x771a, 0x1078, 0x7739, 0x0078,
3323 0x771c, 0x8fff, 0x1040, 0x1328, 0x0c7e, 0x0d7e, 0x2d60, 0x2f68,
3324 0x684b, 0x0003, 0x1078, 0x8726, 0x1078, 0x8bf4, 0x1078, 0x8c01,
3325 0x0d7f, 0x0c7f, 0x1078, 0x753d, 0x0f7f, 0x007c, 0xa186, 0x0015,
3326 0x00c0, 0x7728, 0x2001, 0xa5a2, 0x2004, 0x683e, 0x0078, 0x7736,
3327 0xa18e, 0x0016, 0x00c0, 0x7738, 0x0c7e, 0x2d00, 0x2060, 0x1078,
3328 0xa134, 0x1078, 0x5a41, 0x1078, 0x753d, 0x0c7f, 0x1078, 0x753d,
3329 0x007c, 0x027e, 0x037e, 0x047e, 0x7228, 0x7c80, 0x7b7c, 0xd2f4,
3330 0x0040, 0x7748, 0x2001, 0xa5a2, 0x2004, 0x683e, 0x0078, 0x77ac,
3331 0x0c7e, 0x2d60, 0x1078, 0x874a, 0x0c7f, 0x6804, 0xa086, 0x0050,
3332 0x00c0, 0x7760, 0x0c7e, 0x2d00, 0x2060, 0x6003, 0x0001, 0x6007,
3333 0x0050, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0c7f, 0x0078, 0x77ac,
3334 0x6800, 0xa086, 0x000f, 0x0040, 0x7782, 0x8fff, 0x1040, 0x1328,
3335 0x6824, 0xd0dc, 0x00c0, 0x7782, 0x6800, 0xa086, 0x0004, 0x00c0,
3336 0x7787, 0x784c, 0xd0ac, 0x0040, 0x7787, 0x784c, 0xc0dc, 0xc0f4,
3337 0x784e, 0x7850, 0xc0f4, 0xc0fc, 0x7852, 0x2001, 0x0001, 0x682e,
3338 0x0078, 0x77a6, 0x2001, 0x0007, 0x682e, 0x0078, 0x77a6, 0x784c,
3339 0xd0b4, 0x00c0, 0x7794, 0xd0ac, 0x0040, 0x7782, 0x784c, 0xd0f4,
3340 0x00c0, 0x7782, 0x0078, 0x7775, 0xd2ec, 0x00c0, 0x7782, 0x7024,
3341 0xa306, 0x00c0, 0x779f, 0x7020, 0xa406, 0x0040, 0x7782, 0x7020,
3342 0x6836, 0x7024, 0x683a, 0x2001, 0x0005, 0x682e, 0x1078, 0x8d2b,
3343 0x1078, 0x6109, 0x0078, 0x77ae, 0x1078, 0x753d, 0x047f, 0x037f,
3344 0x027f, 0x007c, 0x0e7e, 0x0d7e, 0x027e, 0x6034, 0x2068, 0x6a1c,
3345 0xa286, 0x0007, 0x0040, 0x7806, 0xa286, 0x0002, 0x0040, 0x7806,
3346 0xa286, 0x0000, 0x0040, 0x7806, 0x6808, 0x6338, 0xa306, 0x00c0,
3347 0x7806, 0x2071, 0xa88c, 0xa186, 0x0015, 0x0040, 0x7800, 0xa18e,
3348 0x0016, 0x00c0, 0x77e8, 0x6030, 0xa084, 0x00ff, 0xa086, 0x0001,
3349 0x00c0, 0x77e8, 0x700c, 0xa086, 0x2a00, 0x00c0, 0x77e8, 0x6034,
3350 0xa080, 0x0009, 0x200c, 0xc1dd, 0xc1f5, 0x2102, 0x0078, 0x7800,
3351 0x0c7e, 0x6034, 0x2060, 0x6010, 0x2068, 0x1078, 0x8a44, 0x1040,
3352 0x1328, 0x6853, 0x0003, 0x6007, 0x0085, 0x6003, 0x000b, 0x601f,
3353 0x0002, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0c7f, 0x0078, 0x7806,
3354 0x6034, 0x2068, 0x2001, 0xa5a2, 0x2004, 0x683e, 0x1078, 0x753d,
3355 0x027f, 0x0d7f, 0x0e7f, 0x007c, 0x0d7e, 0x20a9, 0x000e, 0x2e98,
3356 0x6010, 0x20a0, 0x53a3, 0xa1b6, 0x0015, 0x00c0, 0x7820, 0x6018,
3357 0x2068, 0x7038, 0x680a, 0x703c, 0x680e, 0x6800, 0xc08d, 0x6802,
3358 0x0d7f, 0x0078, 0x7608, 0x2100, 0xa1b2, 0x0044, 0x10c8, 0x1328,
3359 0xa1b2, 0x0040, 0x00c8, 0x7888, 0x0079, 0x782e, 0x787c, 0x7870,
3360 0x787c, 0x787c, 0x787c, 0x787c, 0x786e, 0x786e, 0x786e, 0x786e,
3361 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e,
3362 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e,
3363 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x787c, 0x786e, 0x787c,
3364 0x787c, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x787c, 0x786e,
3365 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e,
3366 0x787c, 0x787c, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e, 0x786e,
3367 0x786e, 0x786e, 0x786e, 0x787c, 0x786e, 0x786e, 0x1078, 0x1328,
3368 0x6003, 0x0001, 0x6106, 0x1078, 0x5c45, 0x127e, 0x2091, 0x8000,
3369 0x1078, 0x6109, 0x127f, 0x007c, 0x6003, 0x0001, 0x6106, 0x1078,
3370 0x5c45, 0x127e, 0x2091, 0x8000, 0x1078, 0x6109, 0x127f, 0x007c,
3371 0x2600, 0x0079, 0x788b, 0x788f, 0x788f, 0x788f, 0x787c, 0x1078,
3372 0x1328, 0x6004, 0xa0b2, 0x0044, 0x10c8, 0x1328, 0xa1b6, 0x0013,
3373 0x00c0, 0x78a1, 0xa0b2, 0x0040, 0x00c8, 0x79fb, 0x2008, 0x0079,
3374 0x7941, 0xa1b6, 0x0027, 0x00c0, 0x78fe, 0x1078, 0x6010, 0x6004,
3375 0x1078, 0x8c27, 0x0040, 0x78be, 0x1078, 0x8c3b, 0x0040, 0x78f6,
3376 0xa08e, 0x0021, 0x0040, 0x78fa, 0xa08e, 0x0022, 0x0040, 0x78f6,
3377 0xa08e, 0x003d, 0x0040, 0x78fa, 0x0078, 0x78f1, 0x1078, 0x2839,
3378 0x2001, 0x0007, 0x1078, 0x443f, 0x6018, 0xa080, 0x0028, 0x200c,
3379 0x1078, 0x7a05, 0xa186, 0x007e, 0x00c0, 0x78d3, 0x2001, 0xa332,
3380 0x2014, 0xc285, 0x2202, 0x017e, 0x027e, 0x037e, 0x2110, 0x2019,
3381 0x0028, 0x1078, 0x5d53, 0x077e, 0x2039, 0x0000, 0x1078, 0x5c78,
3382 0x0c7e, 0x6018, 0xa065, 0x0040, 0x78e7, 0x1078, 0x471b, 0x0c7f,
3383 0x2c08, 0x1078, 0x9c38, 0x077f, 0x037f, 0x027f, 0x017f, 0x1078,
3384 0x44bc, 0x1078, 0x753d, 0x1078, 0x6109, 0x007c, 0x1078, 0x7a05,
3385 0x0078, 0x78f1, 0x1078, 0x7a28, 0x0078, 0x78f1, 0xa186, 0x0014,
3386 0x00c0, 0x78f5, 0x1078, 0x6010, 0x1078, 0x2813, 0x1078, 0x8c27,
3387 0x00c0, 0x791d, 0x1078, 0x2839, 0x6018, 0xa080, 0x0028, 0x200c,
3388 0x1078, 0x7a05, 0xa186, 0x007e, 0x00c0, 0x791b, 0x2001, 0xa332,
3389 0x200c, 0xc185, 0x2102, 0x0078, 0x78f1, 0x1078, 0x8c3b, 0x00c0,
3390 0x7925, 0x1078, 0x7a05, 0x0078, 0x78f1, 0x6004, 0xa08e, 0x0032,
3391 0x00c0, 0x7936, 0x0e7e, 0x0f7e, 0x2071, 0xa381, 0x2079, 0x0000,
3392 0x1078, 0x2b56, 0x0f7f, 0x0e7f, 0x0078, 0x78f1, 0x6004, 0xa08e,
3393 0x0021, 0x0040, 0x7921, 0xa08e, 0x0022, 0x1040, 0x7a05, 0x0078,
3394 0x78f1, 0x7983, 0x7985, 0x7989, 0x798d, 0x7991, 0x7995, 0x7981,
3395 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981,
3396 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981,
3397 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981, 0x7999,
3398 0x79ab, 0x7981, 0x79ad, 0x79ab, 0x7981, 0x7981, 0x7981, 0x7981,
3399 0x7981, 0x79ab, 0x79ab, 0x7981, 0x7981, 0x7981, 0x7981, 0x7981,
3400 0x7981, 0x7981, 0x7981, 0x79de, 0x79ab, 0x7981, 0x79a5, 0x7981,
3401 0x7981, 0x7981, 0x79a7, 0x7981, 0x7981, 0x7981, 0x79ab, 0x7981,
3402 0x7981, 0x1078, 0x1328, 0x0078, 0x79ab, 0x2001, 0x000b, 0x0078,
3403 0x79b8, 0x2001, 0x0003, 0x0078, 0x79b8, 0x2001, 0x0005, 0x0078,
3404 0x79b8, 0x2001, 0x0001, 0x0078, 0x79b8, 0x2001, 0x0009, 0x0078,
3405 0x79b8, 0x1078, 0x6010, 0x6003, 0x0005, 0x2001, 0xa5a2, 0x2004,
3406 0x603e, 0x1078, 0x6109, 0x0078, 0x79b7, 0x0078, 0x79ab, 0x0078,
3407 0x79ab, 0x1078, 0x443f, 0x0078, 0x79f0, 0x1078, 0x6010, 0x6003,
3408 0x0004, 0x2001, 0xa5a0, 0x2004, 0x6016, 0x1078, 0x6109, 0x007c,
3409 0x1078, 0x443f, 0x1078, 0x6010, 0x2001, 0xa5a2, 0x2004, 0x603e,
3410 0x6003, 0x0002, 0x037e, 0x2019, 0xa35c, 0x2304, 0xa084, 0xff00,
3411 0x00c0, 0x79cf, 0x2019, 0xa5a0, 0x231c, 0x0078, 0x79d8, 0x8007,
3412 0xa09a, 0x0004, 0x0048, 0x79ca, 0x8003, 0x801b, 0x831b, 0xa318,
3413 0x6316, 0x037f, 0x1078, 0x6109, 0x0078, 0x79b7, 0x0e7e, 0x0f7e,
3414 0x2071, 0xa381, 0x2079, 0x0000, 0x1078, 0x2b56, 0x0f7f, 0x0e7f,
3415 0x1078, 0x6010, 0x1078, 0x753d, 0x1078, 0x6109, 0x0078, 0x79b7,
3416 0x1078, 0x6010, 0x6003, 0x0002, 0x2001, 0xa5a0, 0x2004, 0x6016,
3417 0x1078, 0x6109, 0x007c, 0x2600, 0x2008, 0x0079, 0x79ff, 0x7a03,
3418 0x7a03, 0x7a03, 0x79f0, 0x1078, 0x1328, 0x0e7e, 0x1078, 0x8a44,
3419 0x0040, 0x7a21, 0x6010, 0x2070, 0x7038, 0xd0fc, 0x0040, 0x7a21,
3420 0x7007, 0x0000, 0x017e, 0x6004, 0xa08e, 0x0021, 0x0040, 0x7a23,
3421 0xa08e, 0x003d, 0x0040, 0x7a23, 0x017f, 0x7037, 0x0103, 0x7033,
3422 0x0100, 0x0e7f, 0x007c, 0x017f, 0x1078, 0x7a28, 0x0078, 0x7a21,
3423 0x0e7e, 0xacf0, 0x0004, 0x2e74, 0x7000, 0x2070, 0x7037, 0x0103,
3424 0x7023, 0x8001, 0x0e7f, 0x007c, 0x0d7e, 0x6618, 0x2668, 0x6804,
3425 0xa084, 0x00ff, 0x0d7f, 0xa0b2, 0x000c, 0x10c8, 0x1328, 0x6604,
3426 0xa6b6, 0x0043, 0x00c0, 0x7a48, 0x1078, 0x8e6d, 0x0078, 0x7aa7,
3427 0x6604, 0xa6b6, 0x0033, 0x00c0, 0x7a51, 0x1078, 0x8e11, 0x0078,
3428 0x7aa7, 0x6604, 0xa6b6, 0x0028, 0x00c0, 0x7a5a, 0x1078, 0x8c6a,
3429 0x0078, 0x7aa7, 0x6604, 0xa6b6, 0x0029, 0x00c0, 0x7a63, 0x1078,
3430 0x8c84, 0x0078, 0x7aa7, 0x6604, 0xa6b6, 0x001f, 0x00c0, 0x7a6c,
3431 0x1078, 0x75ee, 0x0078, 0x7aa7, 0x6604, 0xa6b6, 0x0000, 0x00c0,
3432 0x7a75, 0x1078, 0x780c, 0x0078, 0x7aa7, 0x6604, 0xa6b6, 0x0022,
3433 0x00c0, 0x7a7e, 0x1078, 0x7617, 0x0078, 0x7aa7, 0x6604, 0xa6b6,
3434 0x0035, 0x00c0, 0x7a87, 0x1078, 0x7653, 0x0078, 0x7aa7, 0x6604,
3435 0xa6b6, 0x0039, 0x00c0, 0x7a90, 0x1078, 0x77b2, 0x0078, 0x7aa7,
3436 0x6604, 0xa6b6, 0x003d, 0x00c0, 0x7a99, 0x1078, 0x7633, 0x0078,
3437 0x7aa7, 0xa1b6, 0x0015, 0x00c0, 0x7aa1, 0x1079, 0x7aac, 0x0078,
3438 0x7aa7, 0xa1b6, 0x0016, 0x00c0, 0x7aa8, 0x1079, 0x7bfd, 0x007c,
3439 0x1078, 0x7583, 0x0078, 0x7aa7, 0x7ad0, 0x7ad3, 0x7ad0, 0x7b1e,
3440 0x7ad0, 0x7b91, 0x7c09, 0x7ad0, 0x7ad0, 0x7bd5, 0x7ad0, 0x7beb,
3441 0xa1b6, 0x0048, 0x0040, 0x7ac4, 0x20e1, 0x0005, 0x3d18, 0x3e20,
3442 0x2c10, 0x1078, 0x15ec, 0x007c, 0x0e7e, 0xacf0, 0x0004, 0x2e74,
3443 0x7000, 0x2070, 0x7037, 0x0103, 0x0e7f, 0x1078, 0x753d, 0x007c,
3444 0x0005, 0x0005, 0x007c, 0x0e7e, 0x2071, 0xa300, 0x707c, 0xa086,
3445 0x0074, 0x00c0, 0x7b07, 0x1078, 0x9c0c, 0x00c0, 0x7af9, 0x0d7e,
3446 0x6018, 0x2068, 0x7030, 0xd08c, 0x0040, 0x7aec, 0x6800, 0xd0bc,
3447 0x0040, 0x7aec, 0xc0c5, 0x6802, 0x1078, 0x7b0b, 0x0d7f, 0x2001,
3448 0x0006, 0x1078, 0x443f, 0x1078, 0x2839, 0x1078, 0x753d, 0x0078,
3449 0x7b09, 0x2001, 0x000a, 0x1078, 0x443f, 0x1078, 0x2839, 0x6003,
3450 0x0001, 0x6007, 0x0001, 0x1078, 0x5c45, 0x0078, 0x7b09, 0x1078,
3451 0x7b81, 0x0e7f, 0x007c, 0x6800, 0xd084, 0x0040, 0x7b1d, 0x2001,
3452 0x0000, 0x1078, 0x442b, 0x2069, 0xa351, 0x6804, 0xd0a4, 0x0040,
3453 0x7b1d, 0x2001, 0x0006, 0x1078, 0x4472, 0x007c, 0x0d7e, 0x2011,
3454 0xa31f, 0x2204, 0xa086, 0x0074, 0x00c0, 0x7b7d, 0x6018, 0x2068,
3455 0x6aa0, 0xa286, 0x007e, 0x00c0, 0x7b31, 0x1078, 0x7d17, 0x0078,
3456 0x7b7f, 0x1078, 0x7d0d, 0x6018, 0x2068, 0xa080, 0x0028, 0x2014,
3457 0xa286, 0x0080, 0x00c0, 0x7b55, 0x6813, 0x00ff, 0x6817, 0xfffc,
3458 0x6010, 0xa005, 0x0040, 0x7b4b, 0x2068, 0x6807, 0x0000, 0x6837,
3459 0x0103, 0x6833, 0x0200, 0x2001, 0x0006, 0x1078, 0x443f, 0x1078,
3460 0x2839, 0x1078, 0x753d, 0x0078, 0x7b7f, 0x0e7e, 0x2071, 0xa332,
3461 0x2e04, 0xd09c, 0x0040, 0x7b70, 0x2071, 0xa880, 0x7108, 0x720c,
3462 0xa18c, 0x00ff, 0x00c0, 0x7b68, 0xa284, 0xff00, 0x0040, 0x7b70,
3463 0x6018, 0x2070, 0x70a0, 0xd0bc, 0x00c0, 0x7b70, 0x7112, 0x7216,
3464 0x0e7f, 0x2001, 0x0004, 0x1078, 0x443f, 0x6003, 0x0001, 0x6007,
3465 0x0003, 0x1078, 0x5c45, 0x0078, 0x7b7f, 0x1078, 0x7b81, 0x0d7f,
3466 0x007c, 0x2001, 0xa300, 0x2004, 0xa086, 0x0003, 0x0040, 0x7b8c,
3467 0x2001, 0x0007, 0x1078, 0x443f, 0x1078, 0x2839, 0x1078, 0x753d,
3468 0x007c, 0x0e7e, 0x2071, 0xa300, 0x707c, 0xa086, 0x0014, 0x00c0,
3469 0x7bcf, 0x7000, 0xa086, 0x0003, 0x00c0, 0x7ba4, 0x6010, 0xa005,
3470 0x00c0, 0x7ba4, 0x1078, 0x35f7, 0x0d7e, 0x6018, 0x2068, 0x1078,
3471 0x457d, 0x1078, 0x7b0b, 0x0d7f, 0x1078, 0x7dba, 0x00c0, 0x7bcf,
3472 0x0d7e, 0x6018, 0x2068, 0x6890, 0x0d7f, 0xa005, 0x0040, 0x7bcf,
3473 0x2001, 0x0006, 0x1078, 0x443f, 0x0e7e, 0x6010, 0xa005, 0x0040,
3474 0x7bc8, 0x2070, 0x7007, 0x0000, 0x7037, 0x0103, 0x7033, 0x0200,
3475 0x0e7f, 0x1078, 0x2839, 0x1078, 0x753d, 0x0078, 0x7bd3, 0x1078,
3476 0x7a05, 0x1078, 0x7b81, 0x0e7f, 0x007c, 0x2011, 0xa31f, 0x2204,
3477 0xa086, 0x0014, 0x00c0, 0x7be8, 0x2001, 0x0002, 0x1078, 0x443f,
3478 0x6003, 0x0001, 0x6007, 0x0001, 0x1078, 0x5c45, 0x0078, 0x7bea,
3479 0x1078, 0x7b81, 0x007c, 0x2011, 0xa31f, 0x2204, 0xa086, 0x0004,
3480 0x00c0, 0x7bfa, 0x2001, 0x0007, 0x1078, 0x443f, 0x1078, 0x753d,
3481 0x0078, 0x7bfc, 0x1078, 0x7b81, 0x007c, 0x7ad0, 0x7c11, 0x7ad0,
3482 0x7c4e, 0x7ad0, 0x7cc0, 0x7c09, 0x7ad0, 0x7ad0, 0x7cd5, 0x7ad0,
3483 0x7ce8, 0x6604, 0xa6b6, 0x001e, 0x00c0, 0x7c10, 0x1078, 0x753d,
3484 0x007c, 0x0d7e, 0x0c7e, 0x1078, 0x7cfb, 0x00c0, 0x7c27, 0x2001,
3485 0x0000, 0x1078, 0x442b, 0x2001, 0x0002, 0x1078, 0x443f, 0x6003,
3486 0x0001, 0x6007, 0x0002, 0x1078, 0x5c45, 0x0078, 0x7c4b, 0x2009,
3487 0xa88e, 0x2104, 0xa086, 0x0009, 0x00c0, 0x7c3c, 0x6018, 0x2068,
3488 0x6840, 0xa084, 0x00ff, 0xa005, 0x0040, 0x7c49, 0x8001, 0x6842,
3489 0x6017, 0x000a, 0x0078, 0x7c4b, 0x2009, 0xa88f, 0x2104, 0xa084,
3490 0xff00, 0xa086, 0x1900, 0x00c0, 0x7c49, 0x1078, 0x753d, 0x0078,
3491 0x7c4b, 0x1078, 0x7b81, 0x0c7f, 0x0d7f, 0x007c, 0x1078, 0x7d0a,
3492 0x00c0, 0x7c62, 0x2001, 0x0000, 0x1078, 0x442b, 0x2001, 0x0002,
3493 0x1078, 0x443f, 0x6003, 0x0001, 0x6007, 0x0002, 0x1078, 0x5c45,
3494 0x0078, 0x7c8e, 0x1078, 0x7a05, 0x2009, 0xa88e, 0x2134, 0xa6b4,
3495 0x00ff, 0xa686, 0x0005, 0x0040, 0x7c8f, 0xa686, 0x000b, 0x0040,
3496 0x7c8c, 0x2009, 0xa88f, 0x2104, 0xa084, 0xff00, 0x00c0, 0x7c7c,
3497 0xa686, 0x0009, 0x0040, 0x7c8f, 0xa086, 0x1900, 0x00c0, 0x7c8c,
3498 0xa686, 0x0009, 0x0040, 0x7c8f, 0x2001, 0x0004, 0x1078, 0x443f,
3499 0x1078, 0x753d, 0x0078, 0x7c8e, 0x1078, 0x7b81, 0x007c, 0x0d7e,
3500 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x7c9d, 0x6838, 0xd0fc,
3501 0x0040, 0x7c9d, 0x0d7f, 0x0078, 0x7c8c, 0x6018, 0x2068, 0x6840,
3502 0xa084, 0x00ff, 0xa005, 0x0040, 0x7cae, 0x8001, 0x6842, 0x6017,
3503 0x000a, 0x6007, 0x0016, 0x0d7f, 0x0078, 0x7c8e, 0x68a0, 0xa086,
3504 0x007e, 0x00c0, 0x7cbb, 0x0e7e, 0x2071, 0xa300, 0x1078, 0x41f5,
3505 0x0e7f, 0x0078, 0x7cbd, 0x1078, 0x2813, 0x0d7f, 0x0078, 0x7c8c,
3506 0x1078, 0x7d0a, 0x00c0, 0x7cd0, 0x2001, 0x0004, 0x1078, 0x443f,
3507 0x6003, 0x0001, 0x6007, 0x0003, 0x1078, 0x5c45, 0x0078, 0x7cd4,
3508 0x1078, 0x7a05, 0x1078, 0x7b81, 0x007c, 0x1078, 0x7d0a, 0x00c0,
3509 0x7ce5, 0x2001, 0x0008, 0x1078, 0x443f, 0x6003, 0x0001, 0x6007,
3510 0x0005, 0x1078, 0x5c45, 0x0078, 0x7ce7, 0x1078, 0x7b81, 0x007c,
3511 0x1078, 0x7d0a, 0x00c0, 0x7cf8, 0x2001, 0x000a, 0x1078, 0x443f,
3512 0x6003, 0x0001, 0x6007, 0x0001, 0x1078, 0x5c45, 0x0078, 0x7cfa,
3513 0x1078, 0x7b81, 0x007c, 0x2009, 0xa88e, 0x2104, 0xa086, 0x0003,
3514 0x00c0, 0x7d09, 0x2009, 0xa88f, 0x2104, 0xa084, 0xff00, 0xa086,
3515 0x2a00, 0x007c, 0xa085, 0x0001, 0x007c, 0x0c7e, 0x017e, 0xac88,
3516 0x0006, 0x2164, 0x1078, 0x4513, 0x017f, 0x0c7f, 0x007c, 0x0f7e,
3517 0x0e7e, 0x0d7e, 0x037e, 0x017e, 0x6018, 0x2068, 0x2071, 0xa332,
3518 0x2e04, 0xa085, 0x0003, 0x2072, 0x1078, 0x7d8b, 0x0040, 0x7d50,
3519 0x2001, 0xa352, 0x2004, 0xd0a4, 0x0040, 0x7d39, 0xa006, 0x2020,
3520 0x2009, 0x002a, 0x1078, 0x9ec0, 0x2001, 0xa30c, 0x200c, 0xc195,
3521 0x2102, 0x2019, 0x002a, 0x2009, 0x0001, 0x1078, 0x27e2, 0x2071,
3522 0xa300, 0x1078, 0x260d, 0x0c7e, 0x157e, 0x20a9, 0x0081, 0x2009,
3523 0x007f, 0x1078, 0x2921, 0x8108, 0x00f0, 0x7d49, 0x157f, 0x0c7f,
3524 0x1078, 0x7d0d, 0x6813, 0x00ff, 0x6817, 0xfffe, 0x2071, 0xa880,
3525 0x2079, 0x0100, 0x2e04, 0xa084, 0x00ff, 0x2069, 0xa31a, 0x206a,
3526 0x78e6, 0x007e, 0x8e70, 0x2e04, 0x2069, 0xa31b, 0x206a, 0x78ea,
3527 0xa084, 0xff00, 0x017f, 0xa105, 0x2009, 0xa325, 0x200a, 0x2069,
3528 0xa88e, 0x2071, 0xa59c, 0x6810, 0x2072, 0x6814, 0x7006, 0x6818,
3529 0x700a, 0x681c, 0x700e, 0x1078, 0x8da9, 0x2001, 0x0006, 0x1078,
3530 0x443f, 0x1078, 0x2839, 0x1078, 0x753d, 0x017f, 0x037f, 0x0d7f,
3531 0x0e7f, 0x0f7f, 0x007c, 0x027e, 0x037e, 0x0e7e, 0x157e, 0x2019,
3532 0xa325, 0x231c, 0x83ff, 0x0040, 0x7db5, 0x2071, 0xa880, 0x2e14,
3533 0xa294, 0x00ff, 0x7004, 0xa084, 0xff00, 0xa205, 0xa306, 0x00c0,
3534 0x7db5, 0x2011, 0xa896, 0xad98, 0x000a, 0x20a9, 0x0004, 0x1078,
3535 0x7e55, 0x00c0, 0x7db5, 0x2011, 0xa89a, 0xad98, 0x0006, 0x20a9,
3536 0x0004, 0x1078, 0x7e55, 0x00c0, 0x7db5, 0x157f, 0x0e7f, 0x037f,
3537 0x027f, 0x007c, 0x0e7e, 0x2071, 0xa88c, 0x7004, 0xa086, 0x0014,
3538 0x00c0, 0x7ddd, 0x7008, 0xa086, 0x0800, 0x00c0, 0x7ddd, 0x700c,
3539 0xd0ec, 0x0040, 0x7ddb, 0xa084, 0x0f00, 0xa086, 0x0100, 0x00c0,
3540 0x7ddb, 0x7024, 0xd0a4, 0x00c0, 0x7dd8, 0xd0ac, 0x0040, 0x7ddb,
3541 0xa006, 0x0078, 0x7ddd, 0xa085, 0x0001, 0x0e7f, 0x007c, 0x0e7e,
3542 0x0d7e, 0x0c7e, 0x077e, 0x057e, 0x047e, 0x027e, 0x007e, 0x127e,
3543 0x2091, 0x8000, 0x2029, 0xa5b4, 0x252c, 0x2021, 0xa5ba, 0x2424,
3544 0x2061, 0xaa00, 0x2071, 0xa300, 0x7244, 0x7060, 0xa202, 0x00c8,
3545 0x7e43, 0x1078, 0x9ee5, 0x0040, 0x7e3b, 0x671c, 0xa786, 0x0001,
3546 0x0040, 0x7e3b, 0xa786, 0x0007, 0x0040, 0x7e3b, 0x2500, 0xac06,
3547 0x0040, 0x7e3b, 0x2400, 0xac06, 0x0040, 0x7e3b, 0x0c7e, 0x6000,
3548 0xa086, 0x0004, 0x00c0, 0x7e16, 0x1078, 0x1749, 0xa786, 0x0008,
3549 0x00c0, 0x7e25, 0x1078, 0x8c3b, 0x00c0, 0x7e25, 0x0c7f, 0x1078,
3550 0x7a05, 0x1078, 0x8c01, 0x0078, 0x7e3b, 0x6010, 0x2068, 0x1078,
3551 0x8a44, 0x0040, 0x7e38, 0xa786, 0x0003, 0x00c0, 0x7e4d, 0x6837,
3552 0x0103, 0x6b4a, 0x6847, 0x0000, 0x1078, 0x4982, 0x1078, 0x8bf4,
3553 0x1078, 0x8c01, 0x0c7f, 0xace0, 0x0010, 0x7054, 0xac02, 0x00c8,
3554 0x7e43, 0x0078, 0x7df4, 0x127f, 0x007f, 0x027f, 0x047f, 0x057f,
3555 0x077f, 0x0c7f, 0x0d7f, 0x0e7f, 0x007c, 0xa786, 0x0006, 0x00c0,
3556 0x7e2f, 0x1078, 0x9e70, 0x0078, 0x7e38, 0x220c, 0x2304, 0xa106,
3557 0x00c0, 0x7e60, 0x8210, 0x8318, 0x00f0, 0x7e55, 0xa006, 0x007c,
3558 0x2304, 0xa102, 0x0048, 0x7e68, 0x2001, 0x0001, 0x0078, 0x7e6a,
3559 0x2001, 0x0000, 0xa18d, 0x0001, 0x007c, 0x6004, 0xa08a, 0x0044,
3560 0x10c8, 0x1328, 0x1078, 0x8c27, 0x0040, 0x7e7c, 0x1078, 0x8c3b,
3561 0x0040, 0x7e89, 0x0078, 0x7e82, 0x1078, 0x2839, 0x1078, 0x8c3b,
3562 0x0040, 0x7e89, 0x1078, 0x6010, 0x1078, 0x753d, 0x1078, 0x6109,
3563 0x007c, 0x1078, 0x7a05, 0x0078, 0x7e82, 0xa182, 0x0040, 0x0079,
3564 0x7e91, 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea4,
3565 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea6, 0x7ea6, 0x7ea6, 0x7ea6,
3566 0x7ea4, 0x7ea4, 0x7ea4, 0x7ea6, 0x1078, 0x1328, 0x600b, 0xffff,
3567 0x6003, 0x0001, 0x6106, 0x1078, 0x5bf8, 0x127e, 0x2091, 0x8000,
3568 0x1078, 0x6109, 0x127f, 0x007c, 0xa186, 0x0013, 0x00c0, 0x7ebd,
3569 0x6004, 0xa082, 0x0040, 0x0079, 0x7f48, 0xa186, 0x0027, 0x00c0,
3570 0x7edf, 0x1078, 0x6010, 0x1078, 0x2813, 0x0d7e, 0x6110, 0x2168,
3571 0x1078, 0x8a44, 0x0040, 0x7ed9, 0x6837, 0x0103, 0x684b, 0x0029,
3572 0x6847, 0x0000, 0x694c, 0xc1c5, 0x694e, 0x1078, 0x4982, 0x1078,
3573 0x8bf4, 0x0d7f, 0x1078, 0x753d, 0x1078, 0x6109, 0x007c, 0xa186,
3574 0x0014, 0x00c0, 0x7ee8, 0x6004, 0xa082, 0x0040, 0x0079, 0x7f10,
3575 0xa186, 0x0046, 0x0040, 0x7ef4, 0xa186, 0x0045, 0x0040, 0x7ef4,
3576 0xa186, 0x0047, 0x10c0, 0x1328, 0x2001, 0x0109, 0x2004, 0xd084,
3577 0x0040, 0x7f0d, 0x127e, 0x2091, 0x2200, 0x007e, 0x017e, 0x027e,
3578 0x1078, 0x5ad2, 0x027f, 0x017f, 0x007f, 0x127f, 0x6000, 0xa086,
3579 0x0002, 0x00c0, 0x7f0d, 0x0078, 0x7f81, 0x1078, 0x7583, 0x007c,
3580 0x7f25, 0x7f23, 0x7f23, 0x7f23, 0x7f23, 0x7f23, 0x7f23, 0x7f23,
3581 0x7f23, 0x7f23, 0x7f23, 0x7f41, 0x7f41, 0x7f41, 0x7f41, 0x7f23,
3582 0x7f41, 0x7f23, 0x7f41, 0x1078, 0x1328, 0x1078, 0x6010, 0x0d7e,
3583 0x6110, 0x2168, 0x1078, 0x8a44, 0x0040, 0x7f3b, 0x6837, 0x0103,
3584 0x684b, 0x0006, 0x6847, 0x0000, 0x6850, 0xc0ec, 0x6852, 0x1078,
3585 0x4982, 0x1078, 0x8bf4, 0x0d7f, 0x1078, 0x753d, 0x1078, 0x6109,
3586 0x007c, 0x1078, 0x6010, 0x1078, 0x753d, 0x1078, 0x6109, 0x007c,
3587 0x7f5d, 0x7f5b, 0x7f5b, 0x7f5b, 0x7f5b, 0x7f5b, 0x7f5b, 0x7f5b,
3588 0x7f5b, 0x7f5b, 0x7f5b, 0x7f6f, 0x7f6f, 0x7f6f, 0x7f6f, 0x7f5b,
3589 0x7f7a, 0x7f5b, 0x7f6f, 0x1078, 0x1328, 0x1078, 0x6010, 0x2001,
3590 0xa5a2, 0x2004, 0x603e, 0x6003, 0x0002, 0x1078, 0x6109, 0x6010,
3591 0xa088, 0x0013, 0x2104, 0xa085, 0x0400, 0x200a, 0x007c, 0x1078,
3592 0x6010, 0x2001, 0xa5a2, 0x2004, 0x603e, 0x6003, 0x000f, 0x1078,
3593 0x6109, 0x007c, 0x1078, 0x6010, 0x1078, 0x753d, 0x1078, 0x6109,
3594 0x007c, 0xa182, 0x0040, 0x0079, 0x7f85, 0x7f98, 0x7f98, 0x7f98,
3595 0x7f98, 0x7f98, 0x7f9a, 0x8095, 0x80b7, 0x7f98, 0x7f98, 0x7f98,
3596 0x7f98, 0x7f98, 0x7f98, 0x7f98, 0x7f98, 0x7f98, 0x7f98, 0x7f98,
3597 0x1078, 0x1328, 0x0e7e, 0x0d7e, 0x603f, 0x0000, 0x2071, 0xa880,
3598 0x7124, 0x610a, 0x2071, 0xa88c, 0x6110, 0x2168, 0x7614, 0xa6b4,
3599 0x0fff, 0x86ff, 0x0040, 0x8058, 0xa68c, 0x0c00, 0x0040, 0x7fd1,
3600 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0f7f, 0x0040, 0x7fcd, 0x684c,
3601 0xd0ac, 0x0040, 0x7fcd, 0x6024, 0xd0dc, 0x00c0, 0x7fcd, 0x6850,
3602 0xd0bc, 0x00c0, 0x7fcd, 0x7318, 0x6814, 0xa306, 0x00c0, 0x806f,
3603 0x731c, 0x6810, 0xa306, 0x00c0, 0x806f, 0x7318, 0x6b62, 0x731c,
3604 0x6b5e, 0xa68c, 0x00ff, 0xa186, 0x0002, 0x0040, 0x8004, 0xa186,
3605 0x0028, 0x00c0, 0x7fe1, 0x1078, 0x8c15, 0x684b, 0x001c, 0x0078,
3606 0x8006, 0xd6dc, 0x0040, 0x7ffd, 0x684b, 0x0015, 0x684c, 0xd0ac,
3607 0x0040, 0x7ffb, 0x6914, 0x6a10, 0x2100, 0xa205, 0x0040, 0x7ffb,
3608 0x7018, 0xa106, 0x00c0, 0x7ff8, 0x701c, 0xa206, 0x0040, 0x7ffb,
3609 0x6962, 0x6a5e, 0xc6dc, 0x0078, 0x8006, 0xd6d4, 0x0040, 0x8004,
3610 0x684b, 0x0007, 0x0078, 0x8006, 0x684b, 0x0000, 0x6837, 0x0103,
3611 0x6e46, 0xa01e, 0xd6c4, 0x0040, 0x802f, 0xa686, 0x0100, 0x00c0,
3612 0x801a, 0x2001, 0xa899, 0x2004, 0xa005, 0x00c0, 0x801a, 0xc6c4,
3613 0x0078, 0x7fa9, 0x7328, 0x732c, 0x6b56, 0x83ff, 0x0040, 0x802f,
3614 0xa38a, 0x0009, 0x0048, 0x8026, 0x2019, 0x0008, 0x037e, 0x2308,
3615 0x2019, 0xa898, 0xad90, 0x0019, 0x1078, 0x8739, 0x037f, 0xd6cc,
3616 0x0040, 0x8085, 0x7124, 0x695a, 0x81ff, 0x0040, 0x8085, 0xa192,
3617 0x0021, 0x00c8, 0x8046, 0x2071, 0xa898, 0x831c, 0x2300, 0xae18,
3618 0xad90, 0x001d, 0x1078, 0x8739, 0x0078, 0x8085, 0x6838, 0xd0fc,
3619 0x0040, 0x804f, 0x2009, 0x0020, 0x695a, 0x0078, 0x803b, 0x0f7e,
3620 0x2d78, 0x1078, 0x86d1, 0x0f7f, 0x1078, 0x8726, 0x0078, 0x8087,
3621 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0f7f, 0x0040, 0x8075, 0x684c,
3622 0xd0ac, 0x0040, 0x8075, 0x6024, 0xd0dc, 0x00c0, 0x8075, 0x6850,
3623 0xd0bc, 0x00c0, 0x8075, 0x684c, 0xd0f4, 0x00c0, 0x8075, 0x1078,
3624 0x8cfa, 0x0d7f, 0x0e7f, 0x0078, 0x8094, 0x684b, 0x0000, 0x6837,
3625 0x0103, 0x6e46, 0x684c, 0xd0ac, 0x0040, 0x8085, 0x6810, 0x6914,
3626 0xa115, 0x0040, 0x8085, 0x1078, 0x8233, 0x1078, 0x4982, 0x6218,
3627 0x2268, 0x6a3c, 0x8211, 0x6a3e, 0x1078, 0x8cc4, 0x0d7f, 0x0e7f,
3628 0x00c0, 0x8094, 0x1078, 0x753d, 0x007c, 0x0f7e, 0x6003, 0x0003,
3629 0x2079, 0xa88c, 0x7c04, 0x7b00, 0x7e0c, 0x7d08, 0x6010, 0x2078,
3630 0x784c, 0xd0ac, 0x0040, 0x80a8, 0x6003, 0x0002, 0x0f7f, 0x007c,
3631 0x7c12, 0x7b16, 0x7e0a, 0x7d0e, 0x0f7f, 0x603f, 0x0000, 0x2c10,
3632 0x1078, 0x1cab, 0x1078, 0x5c64, 0x1078, 0x61d3, 0x007c, 0x2001,
3633 0xa5a2, 0x2004, 0x603e, 0x6003, 0x0004, 0x6110, 0x20e1, 0x0005,
3634 0x3d18, 0x3e20, 0x2c10, 0x1078, 0x15ec, 0x007c, 0xa182, 0x0040,
3635 0x0079, 0x80ca, 0x80dd, 0x80dd, 0x80dd, 0x80dd, 0x80dd, 0x80df,
3636 0x8182, 0x80dd, 0x80dd, 0x8198, 0x8209, 0x80dd, 0x80dd, 0x80dd,
3637 0x80dd, 0x8218, 0x80dd, 0x80dd, 0x80dd, 0x1078, 0x1328, 0x077e,
3638 0x0f7e, 0x0e7e, 0x0d7e, 0x2071, 0xa88c, 0x6110, 0x2178, 0x7614,
3639 0xa6b4, 0x0fff, 0x7e46, 0x7f4c, 0xc7e5, 0x7f4e, 0x6218, 0x2268,
3640 0x6a3c, 0x8211, 0x6a3e, 0x86ff, 0x0040, 0x817d, 0xa694, 0xff00,
3641 0xa284, 0x0c00, 0x0040, 0x8100, 0x7018, 0x7862, 0x701c, 0x785e,
3642 0xa284, 0x0300, 0x0040, 0x817d, 0x1078, 0x1381, 0x1040, 0x1328,
3643 0x2d00, 0x784a, 0x7f4c, 0xc7cd, 0x7f4e, 0x6837, 0x0103, 0x7838,
3644 0x683a, 0x783c, 0x683e, 0x7840, 0x6842, 0x6e46, 0xa68c, 0x0c00,
3645 0x0040, 0x811e, 0x7318, 0x6b62, 0x731c, 0x6b5e, 0xa68c, 0x00ff,
3646 0xa186, 0x0002, 0x0040, 0x813a, 0xa186, 0x0028, 0x00c0, 0x812c,
3647 0x684b, 0x001c, 0x0078, 0x813c, 0xd6dc, 0x0040, 0x8133, 0x684b,
3648 0x0015, 0x0078, 0x813c, 0xd6d4, 0x0040, 0x813a, 0x684b, 0x0007,
3649 0x0078, 0x813c, 0x684b, 0x0000, 0x6f4e, 0x7850, 0x6852, 0x7854,
3650 0x6856, 0xa01e, 0xd6c4, 0x0040, 0x815a, 0x7328, 0x732c, 0x6b56,
3651 0x83ff, 0x0040, 0x815a, 0xa38a, 0x0009, 0x0048, 0x8151, 0x2019,
3652 0x0008, 0x037e, 0x2308, 0x2019, 0xa898, 0xad90, 0x0019, 0x1078,
3653 0x8739, 0x037f, 0xd6cc, 0x0040, 0x817d, 0x7124, 0x695a, 0x81ff,
3654 0x0040, 0x817d, 0xa192, 0x0021, 0x00c8, 0x8171, 0x2071, 0xa898,
3655 0x831c, 0x2300, 0xae18, 0xad90, 0x001d, 0x1078, 0x8739, 0x0078,
3656 0x817d, 0x7838, 0xd0fc, 0x0040, 0x817a, 0x2009, 0x0020, 0x695a,
3657 0x0078, 0x8166, 0x2d78, 0x1078, 0x86d1, 0x0d7f, 0x0e7f, 0x0f7f,
3658 0x077f, 0x007c, 0x0f7e, 0x6003, 0x0003, 0x2079, 0xa88c, 0x7c04,
3659 0x7b00, 0x7e0c, 0x7d08, 0x6010, 0x2078, 0x7c12, 0x7b16, 0x7e0a,
3660 0x7d0e, 0x0f7f, 0x2c10, 0x1078, 0x1cab, 0x1078, 0x6c26, 0x007c,
3661 0x0d7e, 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0f7f, 0x0040, 0x81a4,
3662 0x2001, 0xa5a2, 0x2004, 0x603e, 0x6003, 0x0002, 0x1078, 0x60b8,
3663 0x1078, 0x61d3, 0x6110, 0x2168, 0x694c, 0xd1e4, 0x0040, 0x8207,
3664 0xd1cc, 0x0040, 0x81de, 0x6948, 0x6838, 0xd0fc, 0x0040, 0x81d6,
3665 0x017e, 0x684c, 0x007e, 0x6850, 0x007e, 0xad90, 0x000d, 0xa198,
3666 0x000d, 0x2009, 0x0020, 0x157e, 0x21a8, 0x2304, 0x2012, 0x8318,
3667 0x8210, 0x00f0, 0x81c5, 0x157f, 0x007f, 0x6852, 0x007f, 0x684e,
3668 0x017f, 0x2168, 0x1078, 0x13aa, 0x0078, 0x8201, 0x017e, 0x1078,
3669 0x13aa, 0x0d7f, 0x1078, 0x8726, 0x0078, 0x8201, 0x6837, 0x0103,
3670 0x6944, 0xa184, 0x00ff, 0xa0b6, 0x0002, 0x0040, 0x81fd, 0xa086,
3671 0x0028, 0x00c0, 0x81ef, 0x684b, 0x001c, 0x0078, 0x81ff, 0xd1dc,
3672 0x0040, 0x81f6, 0x684b, 0x0015, 0x0078, 0x81ff, 0xd1d4, 0x0040,
3673 0x81fd, 0x684b, 0x0007, 0x0078, 0x81ff, 0x684b, 0x0000, 0x1078,
3674 0x4982, 0x1078, 0x8cc4, 0x00c0, 0x8207, 0x1078, 0x753d, 0x0d7f,
3675 0x007c, 0x2019, 0x0001, 0x1078, 0x6e6c, 0x6003, 0x0002, 0x2001,
3676 0xa5a2, 0x2004, 0x603e, 0x1078, 0x60b8, 0x1078, 0x61d3, 0x007c,
3677 0x1078, 0x60b8, 0x1078, 0x2813, 0x0d7e, 0x6110, 0x2168, 0x1078,
3678 0x8a44, 0x0040, 0x822d, 0x6837, 0x0103, 0x684b, 0x0029, 0x6847,
3679 0x0000, 0x1078, 0x4982, 0x1078, 0x8bf4, 0x0d7f, 0x1078, 0x753d,
3680 0x1078, 0x61d3, 0x007c, 0x684b, 0x0015, 0xd1fc, 0x0040, 0x823f,
3681 0x684b, 0x0007, 0x8002, 0x8000, 0x810a, 0xa189, 0x0000, 0x6962,
3682 0x685e, 0x007c, 0xa182, 0x0040, 0x0079, 0x8246, 0x8259, 0x8259,
3683 0x8259, 0x8259, 0x8259, 0x825b, 0x8259, 0x8333, 0x833f, 0x8259,
3684 0x8259, 0x8259, 0x8259, 0x8259, 0x8259, 0x8259, 0x8259, 0x8259,
3685 0x8259, 0x1078, 0x1328, 0x077e, 0x0f7e, 0x0e7e, 0x0d7e, 0x2071,
3686 0xa88c, 0x6110, 0x2178, 0x7614, 0xa6b4, 0x0fff, 0x0f7e, 0x2c78,
3687 0x1078, 0x4893, 0x0f7f, 0x0040, 0x827e, 0xa684, 0x00ff, 0x00c0,
3688 0x827e, 0x6024, 0xd0f4, 0x00c0, 0x827a, 0x7808, 0xa086, 0x0000,
3689 0x00c0, 0x827e, 0x1078, 0x8cfa, 0x0078, 0x832e, 0x7e46, 0x7f4c,
3690 0xc7e5, 0x7f4e, 0x6218, 0x2268, 0x6a3c, 0x8211, 0x6a3e, 0x86ff,
3691 0x0040, 0x8323, 0xa694, 0xff00, 0xa284, 0x0c00, 0x0040, 0x8294,
3692 0x7018, 0x7862, 0x701c, 0x785e, 0xa284, 0x0300, 0x0040, 0x8320,
3693 0xa686, 0x0100, 0x00c0, 0x82a6, 0x2001, 0xa899, 0x2004, 0xa005,
3694 0x00c0, 0x82a6, 0xc6c4, 0x7e46, 0x0078, 0x8287, 0x1078, 0x1381,
3695 0x1040, 0x1328, 0x2d00, 0x784a, 0x7f4c, 0xa7bd, 0x0200, 0x7f4e,
3696 0x6837, 0x0103, 0x7838, 0x683a, 0x783c, 0x683e, 0x7840, 0x6842,
3697 0x6e46, 0xa68c, 0x0c00, 0x0040, 0x82c1, 0x7318, 0x6b62, 0x731c,
3698 0x6b5e, 0xa68c, 0x00ff, 0xa186, 0x0002, 0x0040, 0x82dd, 0xa186,
3699 0x0028, 0x00c0, 0x82cf, 0x684b, 0x001c, 0x0078, 0x82df, 0xd6dc,
3700 0x0040, 0x82d6, 0x684b, 0x0015, 0x0078, 0x82df, 0xd6d4, 0x0040,
3701 0x82dd, 0x684b, 0x0007, 0x0078, 0x82df, 0x684b, 0x0000, 0x6f4e,
3702 0x7850, 0x6852, 0x7854, 0x6856, 0xa01e, 0xd6c4, 0x0040, 0x82fd,
3703 0x7328, 0x732c, 0x6b56, 0x83ff, 0x0040, 0x82fd, 0xa38a, 0x0009,
3704 0x0048, 0x82f4, 0x2019, 0x0008, 0x037e, 0x2308, 0x2019, 0xa898,
3705 0xad90, 0x0019, 0x1078, 0x8739, 0x037f, 0xd6cc, 0x0040, 0x8320,
3706 0x7124, 0x695a, 0x81ff, 0x0040, 0x8320, 0xa192, 0x0021, 0x00c8,
3707 0x8314, 0x2071, 0xa898, 0x831c, 0x2300, 0xae18, 0xad90, 0x001d,
3708 0x1078, 0x8739, 0x0078, 0x8320, 0x7838, 0xd0fc, 0x0040, 0x831d,
3709 0x2009, 0x0020, 0x695a, 0x0078, 0x8309, 0x2d78, 0x1078, 0x86d1,
3710 0xd6dc, 0x00c0, 0x8326, 0xa006, 0x0078, 0x832c, 0x2001, 0x0001,
3711 0x2071, 0xa88c, 0x7218, 0x731c, 0x1078, 0x1645, 0x0d7f, 0x0e7f,
3712 0x0f7f, 0x077f, 0x007c, 0x2001, 0xa5a2, 0x2004, 0x603e, 0x20e1,
3713 0x0005, 0x3d18, 0x3e20, 0x2c10, 0x1078, 0x15ec, 0x007c, 0x2001,
3714 0xa5a2, 0x2004, 0x603e, 0x0d7e, 0x6003, 0x0002, 0x6110, 0x2168,
3715 0x694c, 0xd1e4, 0x0040, 0x846b, 0x603f, 0x0000, 0x0f7e, 0x2c78,
3716 0x1078, 0x4893, 0x0f7f, 0x0040, 0x8385, 0x6814, 0x6910, 0xa115,
3717 0x0040, 0x8385, 0x6a60, 0xa206, 0x00c0, 0x8362, 0x685c, 0xa106,
3718 0x0040, 0x8385, 0x684c, 0xc0e4, 0x684e, 0x6847, 0x0000, 0x6863,
3719 0x0000, 0x685f, 0x0000, 0x6024, 0xd0f4, 0x00c0, 0x837a, 0x697c,
3720 0x6810, 0xa102, 0x603a, 0x6980, 0x6814, 0xa103, 0x6036, 0x6024,
3721 0xc0f5, 0x6026, 0x0d7e, 0x6018, 0x2068, 0x683c, 0x8000, 0x683e,
3722 0x0d7f, 0x1078, 0x8cfa, 0x0078, 0x846b, 0x694c, 0xd1cc, 0x0040,
3723 0x8430, 0x6948, 0x6838, 0xd0fc, 0x0040, 0x83ea, 0x017e, 0x684c,
3724 0x007e, 0x6850, 0x007e, 0x0f7e, 0x2178, 0x7944, 0xa184, 0x00ff,
3725 0xa0b6, 0x0002, 0x0040, 0x83bf, 0xa086, 0x0028, 0x00c0, 0x83a6,
3726 0x684b, 0x001c, 0x784b, 0x001c, 0x0078, 0x83ca, 0xd1dc, 0x0040,
3727 0x83b6, 0x684b, 0x0015, 0x784b, 0x0015, 0x1078, 0x8ea5, 0x0040,
3728 0x83b4, 0x7944, 0xc1dc, 0x7946, 0x0078, 0x83ca, 0xd1d4, 0x0040,
3729 0x83bf, 0x684b, 0x0007, 0x784b, 0x0007, 0x0078, 0x83ca, 0x684c,
3730 0xd0ac, 0x0040, 0x83ca, 0x6810, 0x6914, 0xa115, 0x0040, 0x83ca,
3731 0x1078, 0x8233, 0x6848, 0x784a, 0x6860, 0x7862, 0x685c, 0x785e,
3732 0xad90, 0x000d, 0xaf98, 0x000d, 0x2009, 0x0020, 0x157e, 0x21a8,
3733 0x2304, 0x2012, 0x8318, 0x8210, 0x00f0, 0x83d8, 0x157f, 0x0f7f,
3734 0x007f, 0x6852, 0x007f, 0x684e, 0x017f, 0x2168, 0x1078, 0x13aa,
3735 0x0078, 0x8465, 0x017e, 0x0f7e, 0x2178, 0x7944, 0xa184, 0x00ff,
3736 0xa0b6, 0x0002, 0x0040, 0x8417, 0xa086, 0x0028, 0x00c0, 0x83fe,
3737 0x684b, 0x001c, 0x784b, 0x001c, 0x0078, 0x8422, 0xd1dc, 0x0040,
3738 0x840e, 0x684b, 0x0015, 0x784b, 0x0015, 0x1078, 0x8ea5, 0x0040,
3739 0x840c, 0x7944, 0xc1dc, 0x7946, 0x0078, 0x8422, 0xd1d4, 0x0040,
3740 0x8417, 0x684b, 0x0007, 0x784b, 0x0007, 0x0078, 0x8422, 0x684c,
3741 0xd0ac, 0x0040, 0x8422, 0x6810, 0x6914, 0xa115, 0x0040, 0x8422,
3742 0x1078, 0x8233, 0x6860, 0x7862, 0x685c, 0x785e, 0x684c, 0x784e,
3743 0x0f7f, 0x1078, 0x13aa, 0x0d7f, 0x1078, 0x8726, 0x0078, 0x8465,
3744 0x6837, 0x0103, 0x6944, 0xa184, 0x00ff, 0xa0b6, 0x0002, 0x0040,
3745 0x8456, 0xa086, 0x0028, 0x00c0, 0x8441, 0x684b, 0x001c, 0x0078,
3746 0x8463, 0xd1dc, 0x0040, 0x844f, 0x684b, 0x0015, 0x1078, 0x8ea5,
3747 0x0040, 0x844d, 0x6944, 0xc1dc, 0x6946, 0x0078, 0x8463, 0xd1d4,
3748 0x0040, 0x8456, 0x684b, 0x0007, 0x0078, 0x8463, 0x684b, 0x0000,
3749 0x684c, 0xd0ac, 0x0040, 0x8463, 0x6810, 0x6914, 0xa115, 0x0040,
3750 0x8463, 0x1078, 0x8233, 0x1078, 0x4982, 0x1078, 0x8cc4, 0x00c0,
3751 0x846b, 0x1078, 0x753d, 0x0d7f, 0x007c, 0x1078, 0x6010, 0x0078,
3752 0x8473, 0x1078, 0x60b8, 0x1078, 0x8a44, 0x0040, 0x8492, 0x0d7e,
3753 0x6110, 0x2168, 0x6837, 0x0103, 0x2009, 0xa30c, 0x210c, 0xd18c,
3754 0x00c0, 0x849d, 0xd184, 0x00c0, 0x8499, 0x6108, 0x694a, 0xa18e,
3755 0x0029, 0x00c0, 0x848d, 0x1078, 0xa181, 0x6847, 0x0000, 0x1078,
3756 0x4982, 0x0d7f, 0x1078, 0x753d, 0x1078, 0x6109, 0x1078, 0x61d3,
3757 0x007c, 0x684b, 0x0004, 0x0078, 0x848d, 0x684b, 0x0004, 0x0078,
3758 0x848d, 0xa182, 0x0040, 0x0079, 0x84a5, 0x84b8, 0x84b8, 0x84b8,
3759 0x84b8, 0x84b8, 0x84ba, 0x84b8, 0x84bd, 0x84b8, 0x84b8, 0x84b8,
3760 0x84b8, 0x84b8, 0x84b8, 0x84b8, 0x84b8, 0x84b8, 0x84b8, 0x84b8,
3761 0x1078, 0x1328, 0x1078, 0x753d, 0x007c, 0x007e, 0x027e, 0xa016,
3762 0x1078, 0x15ec, 0x027f, 0x007f, 0x007c, 0xa182, 0x0085, 0x0079,
3763 0x84c9, 0x84d2, 0x84d0, 0x84d0, 0x84de, 0x84d0, 0x84d0, 0x84d0,
3764 0x1078, 0x1328, 0x6003, 0x0001, 0x6106, 0x1078, 0x5bf8, 0x127e,
3765 0x2091, 0x8000, 0x1078, 0x6109, 0x127f, 0x007c, 0x027e, 0x057e,
3766 0x0d7e, 0x0e7e, 0x2071, 0xa880, 0x7224, 0x6212, 0x7220, 0x1078,
3767 0x8a30, 0x0040, 0x8503, 0x2268, 0x6800, 0xa086, 0x0000, 0x0040,
3768 0x8503, 0x6018, 0x6d18, 0xa52e, 0x00c0, 0x8503, 0x0c7e, 0x2d60,
3769 0x1078, 0x874a, 0x0c7f, 0x0040, 0x8503, 0x6803, 0x0002, 0x6007,
3770 0x0086, 0x0078, 0x8505, 0x6007, 0x0087, 0x6003, 0x0001, 0x1078,
3771 0x5bf8, 0x1078, 0x6109, 0x0f7e, 0x2278, 0x1078, 0x4893, 0x0f7f,
3772 0x0040, 0x851d, 0x6824, 0xd0ec, 0x0040, 0x851d, 0x0c7e, 0x2260,
3773 0x603f, 0x0000, 0x1078, 0x8cfa, 0x0c7f, 0x0e7f, 0x0d7f, 0x057f,
3774 0x027f, 0x007c, 0xa186, 0x0013, 0x00c0, 0x8533, 0x6004, 0xa08a,
3775 0x0085, 0x1048, 0x1328, 0xa08a, 0x008c, 0x10c8, 0x1328, 0xa082,
3776 0x0085, 0x0079, 0x8542, 0xa186, 0x0027, 0x0040, 0x853b, 0xa186,
3777 0x0014, 0x10c0, 0x1328, 0x1078, 0x6010, 0x1078, 0x8c01, 0x1078,
3778 0x6109, 0x007c, 0x8549, 0x854b, 0x854b, 0x8549, 0x8549, 0x8549,
3779 0x8549, 0x1078, 0x1328, 0x1078, 0x6010, 0x1078, 0x8c01, 0x1078,
3780 0x6109, 0x007c, 0xa186, 0x0013, 0x00c0, 0x855c, 0x6004, 0xa082,
3781 0x0085, 0x2008, 0x0078, 0x8597, 0xa186, 0x0027, 0x00c0, 0x857f,
3782 0x1078, 0x6010, 0x1078, 0x2813, 0x0d7e, 0x6010, 0x2068, 0x1078,
3783 0x8a44, 0x0040, 0x8575, 0x6837, 0x0103, 0x6847, 0x0000, 0x684b,
3784 0x0029, 0x1078, 0x4982, 0x1078, 0x8bf4, 0x0d7f, 0x1078, 0x753d,
3785 0x1078, 0x6109, 0x007c, 0x1078, 0x7583, 0x0078, 0x857a, 0xa186,
3786 0x0014, 0x00c0, 0x857b, 0x1078, 0x6010, 0x0d7e, 0x6010, 0x2068,
3787 0x1078, 0x8a44, 0x0040, 0x8575, 0x6837, 0x0103, 0x6847, 0x0000,
3788 0x684b, 0x0006, 0x6850, 0xc0ec, 0x6852, 0x0078, 0x8571, 0x0079,
3789 0x8599, 0x85a2, 0x85a0, 0x85a0, 0x85a0, 0x85a0, 0x85a0, 0x85bd,
3790 0x1078, 0x1328, 0x1078, 0x6010, 0x6030, 0xa08c, 0xff00, 0x810f,
3791 0xa186, 0x0039, 0x0040, 0x85b0, 0xa186, 0x0035, 0x00c0, 0x85b4,
3792 0x2001, 0xa5a0, 0x0078, 0x85b6, 0x2001, 0xa5a1, 0x2004, 0x6016,
3793 0x6003, 0x000c, 0x1078, 0x6109, 0x007c, 0x1078, 0x6010, 0x6030,
3794 0xa08c, 0xff00, 0x810f, 0xa186, 0x0039, 0x0040, 0x85cb, 0xa186,
3795 0x0035, 0x00c0, 0x85cf, 0x2001, 0xa5a0, 0x0078, 0x85d1, 0x2001,
3796 0xa5a1, 0x2004, 0x6016, 0x6003, 0x000e, 0x1078, 0x6109, 0x007c,
3797 0xa182, 0x008c, 0x00c8, 0x85e2, 0xa182, 0x0085, 0x0048, 0x85e2,
3798 0x0079, 0x85e5, 0x1078, 0x7583, 0x007c, 0x85ec, 0x85ec, 0x85ec,
3799 0x85ec, 0x85ee, 0x8643, 0x85ec, 0x1078, 0x1328, 0x0f7e, 0x2c78,
3800 0x1078, 0x4893, 0x0f7f, 0x0040, 0x8601, 0x6030, 0xa08c, 0xff00,
3801 0x810f, 0xa186, 0x0039, 0x0040, 0x865a, 0xa186, 0x0035, 0x0040,
3802 0x865a, 0x0d7e, 0x1078, 0x8bf4, 0x1078, 0x8a44, 0x0040, 0x8625,
3803 0x6010, 0x2068, 0x6837, 0x0103, 0x6850, 0xd0b4, 0x0040, 0x8616,
3804 0x684b, 0x0006, 0xc0ec, 0x6852, 0x0078, 0x8621, 0xd0bc, 0x0040,
3805 0x861d, 0x684b, 0x0002, 0x0078, 0x8621, 0x684b, 0x0005, 0x1078,
3806 0x8cc0, 0x6847, 0x0000, 0x1078, 0x4982, 0x2c68, 0x1078, 0x74d7,
3807 0x0040, 0x863e, 0x6003, 0x0001, 0x6007, 0x001e, 0x2009, 0xa88e,
3808 0x210c, 0x6136, 0x2009, 0xa88f, 0x210c, 0x613a, 0x6918, 0x611a,
3809 0x6920, 0x6122, 0x601f, 0x0001, 0x1078, 0x5bf8, 0x2d60, 0x1078,
3810 0x753d, 0x0d7f, 0x007c, 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0f7f,
3811 0x0040, 0x8680, 0x6030, 0xa08c, 0xff00, 0x810f, 0xa186, 0x0035,
3812 0x0040, 0x865a, 0xa186, 0x001e, 0x0040, 0x865a, 0xa186, 0x0039,
3813 0x00c0, 0x8680, 0x0d7e, 0x2c68, 0x1078, 0x8ef5, 0x00c0, 0x86a4,
3814 0x1078, 0x74d7, 0x0040, 0x867d, 0x6106, 0x6003, 0x0001, 0x601f,
3815 0x0001, 0x6918, 0x611a, 0x6928, 0x612a, 0x692c, 0x612e, 0x6930,
3816 0xa18c, 0x00ff, 0x6132, 0x6934, 0x6136, 0x6938, 0x613a, 0x6920,
3817 0x6122, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x2d60, 0x0078, 0x86a4,
3818 0x0d7e, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x86a4, 0x6837,
3819 0x0103, 0x6850, 0xd0b4, 0x0040, 0x8693, 0xc0ec, 0x6852, 0x684b,
3820 0x0006, 0x0078, 0x869e, 0xd0bc, 0x0040, 0x869a, 0x684b, 0x0002,
3821 0x0078, 0x869e, 0x684b, 0x0005, 0x1078, 0x8cc0, 0x6847, 0x0000,
3822 0x1078, 0x4982, 0x1078, 0x8bf4, 0x0d7f, 0x1078, 0x753d, 0x007c,
3823 0x017e, 0x0d7e, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x86b8,
3824 0x6837, 0x0103, 0x684b, 0x0028, 0x6847, 0x0000, 0x1078, 0x4982,
3825 0x0d7f, 0x017f, 0xa186, 0x0013, 0x0040, 0x86ca, 0xa186, 0x0014,
3826 0x0040, 0x86ca, 0xa186, 0x0027, 0x0040, 0x86ca, 0x1078, 0x7583,
3827 0x0078, 0x86d0, 0x1078, 0x6010, 0x1078, 0x8c01, 0x1078, 0x6109,
3828 0x007c, 0x057e, 0x067e, 0x0d7e, 0x0f7e, 0x2029, 0x0001, 0xa182,
3829 0x0101, 0x00c8, 0x86dd, 0x0078, 0x86df, 0x2009, 0x0100, 0x2130,
3830 0x2069, 0xa898, 0x831c, 0x2300, 0xad18, 0x2009, 0x0020, 0xaf90,
3831 0x001d, 0x1078, 0x8739, 0xa6b2, 0x0020, 0x7804, 0xa06d, 0x0040,
3832 0x86f3, 0x1078, 0x13aa, 0x1078, 0x1381, 0x0040, 0x871d, 0x8528,
3833 0x6837, 0x0110, 0x683b, 0x0000, 0x2d20, 0x7c06, 0xa68a, 0x003d,
3834 0x00c8, 0x8709, 0x2608, 0xad90, 0x000f, 0x1078, 0x8739, 0x0078,
3835 0x871d, 0xa6b2, 0x003c, 0x2009, 0x003c, 0x2d78, 0xad90, 0x000f,
3836 0x1078, 0x8739, 0x0078, 0x86f3, 0x0f7f, 0x852f, 0xa5ad, 0x0003,
3837 0x7d36, 0xa5ac, 0x0000, 0x0078, 0x8722, 0x0f7f, 0x852f, 0xa5ad,
3838 0x0003, 0x7d36, 0x0d7f, 0x067f, 0x057f, 0x007c, 0x0f7e, 0x8dff,
3839 0x0040, 0x8737, 0x6804, 0xa07d, 0x0040, 0x8735, 0x6807, 0x0000,
3840 0x1078, 0x4982, 0x2f68, 0x0078, 0x872a, 0x1078, 0x4982, 0x0f7f,
3841 0x007c, 0x157e, 0xa184, 0x0001, 0x0040, 0x873f, 0x8108, 0x810c,
3842 0x21a8, 0x2304, 0x8007, 0x2012, 0x8318, 0x8210, 0x00f0, 0x8741,
3843 0x157f, 0x007c, 0x067e, 0x127e, 0x2091, 0x8000, 0x2031, 0x0001,
3844 0x601c, 0xa084, 0x000f, 0x1079, 0x8766, 0x127f, 0x067f, 0x007c,
3845 0x127e, 0x2091, 0x8000, 0x067e, 0x2031, 0x0000, 0x601c, 0xa084,
3846 0x000f, 0x1079, 0x8766, 0x067f, 0x127f, 0x007c, 0x8780, 0x876e,
3847 0x877b, 0x879c, 0x876e, 0x877b, 0x879c, 0x877b, 0x1078, 0x1328,
3848 0x037e, 0x2019, 0x0010, 0x1078, 0x9a6a, 0x601f, 0x0006, 0x6003,
3849 0x0007, 0x037f, 0x007c, 0xa006, 0x007c, 0xa085, 0x0001, 0x007c,
3850 0x0d7e, 0x86ff, 0x00c0, 0x8797, 0x6010, 0x2068, 0x1078, 0x8a44,
3851 0x0040, 0x8799, 0xa00e, 0x2001, 0x0005, 0x1078, 0x4a60, 0x1078,
3852 0x8cc0, 0x1078, 0x4982, 0x1078, 0x753d, 0xa085, 0x0001, 0x0d7f,
3853 0x007c, 0xa006, 0x0078, 0x8797, 0x6000, 0xa08a, 0x0010, 0x10c8,
3854 0x1328, 0x1079, 0x87a4, 0x007c, 0x87b4, 0x87d4, 0x87b6, 0x87f7,
3855 0x87d0, 0x87b4, 0x877b, 0x8780, 0x8780, 0x877b, 0x877b, 0x877b,
3856 0x877b, 0x877b, 0x877b, 0x877b, 0x1078, 0x1328, 0x86ff, 0x00c0,
3857 0x87cd, 0x0d7e, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x87c2,
3858 0x1078, 0x8cc0, 0x0d7f, 0x6007, 0x0085, 0x6003, 0x000b, 0x601f,
3859 0x0002, 0x1078, 0x5bf8, 0x1078, 0x6109, 0xa085, 0x0001, 0x007c,
3860 0x1078, 0x1749, 0x0078, 0x87b6, 0x0e7e, 0x2071, 0xa5ab, 0x7024,
3861 0xac06, 0x00c0, 0x87dd, 0x1078, 0x6dda, 0x601c, 0xa084, 0x000f,
3862 0xa086, 0x0006, 0x00c0, 0x87ef, 0x087e, 0x097e, 0x2049, 0x0001,
3863 0x2c40, 0x1078, 0x7058, 0x097f, 0x087f, 0x0078, 0x87f1, 0x1078,
3864 0x6cd2, 0x0e7f, 0x00c0, 0x87b6, 0x1078, 0x877b, 0x007c, 0x037e,
3865 0x0e7e, 0x2071, 0xa5ab, 0x703c, 0xac06, 0x00c0, 0x8807, 0x2019,
3866 0x0000, 0x1078, 0x6e6c, 0x0e7f, 0x037f, 0x0078, 0x87b6, 0x1078,
3867 0x719a, 0x0e7f, 0x037f, 0x00c0, 0x87b6, 0x1078, 0x877b, 0x007c,
3868 0x0c7e, 0x601c, 0xa084, 0x000f, 0x1079, 0x8818, 0x0c7f, 0x007c,
3869 0x8827, 0x8895, 0x89cd, 0x8832, 0x8c01, 0x8827, 0x9a5b, 0x753d,
3870 0x8895, 0x1078, 0x8c3b, 0x00c0, 0x8827, 0x1078, 0x7a05, 0x007c,
3871 0x1078, 0x6010, 0x1078, 0x6109, 0x1078, 0x753d, 0x007c, 0x6017,
3872 0x0001, 0x007c, 0x6010, 0xa080, 0x0019, 0x2c02, 0x6000, 0xa08a,
3873 0x0010, 0x10c8, 0x1328, 0x1079, 0x883e, 0x007c, 0x884e, 0x8850,
3874 0x8872, 0x8884, 0x8891, 0x884e, 0x8827, 0x8827, 0x8827, 0x8884,
3875 0x8884, 0x884e, 0x884e, 0x884e, 0x884e, 0x888e, 0x1078, 0x1328,
3876 0x0e7e, 0x6010, 0x2070, 0x7050, 0xc0b5, 0x7052, 0x2071, 0xa5ab,
3877 0x7024, 0xac06, 0x0040, 0x886e, 0x1078, 0x6cd2, 0x6007, 0x0085,
3878 0x6003, 0x000b, 0x601f, 0x0002, 0x2001, 0xa5a1, 0x2004, 0x6016,
3879 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0e7f, 0x007c, 0x6017, 0x0001,
3880 0x0078, 0x886c, 0x0d7e, 0x6010, 0x2068, 0x6850, 0xc0b5, 0x6852,
3881 0x0d7f, 0x6007, 0x0085, 0x6003, 0x000b, 0x601f, 0x0002, 0x1078,
3882 0x5bf8, 0x1078, 0x6109, 0x007c, 0x0d7e, 0x6017, 0x0001, 0x6010,
3883 0x2068, 0x6850, 0xc0b5, 0x6852, 0x0d7f, 0x007c, 0x1078, 0x753d,
3884 0x007c, 0x1078, 0x1749, 0x0078, 0x8872, 0x6000, 0xa08a, 0x0010,
3885 0x10c8, 0x1328, 0x1079, 0x889d, 0x007c, 0x88ad, 0x882f, 0x88af,
3886 0x88ad, 0x88af, 0x88af, 0x8828, 0x88ad, 0x8821, 0x8821, 0x88ad,
3887 0x88ad, 0x88ad, 0x88ad, 0x88ad, 0x88ad, 0x1078, 0x1328, 0x0d7e,
3888 0x6018, 0x2068, 0x6804, 0xa084, 0x00ff, 0x0d7f, 0xa08a, 0x000c,
3889 0x10c8, 0x1328, 0x1079, 0x88bd, 0x007c, 0x88c9, 0x8971, 0x88cb,
3890 0x890b, 0x88cb, 0x890b, 0x88cb, 0x88d8, 0x88c9, 0x890b, 0x88c9,
3891 0x88f5, 0x1078, 0x1328, 0x6004, 0xa08e, 0x0016, 0x0040, 0x8906,
3892 0xa08e, 0x0004, 0x0040, 0x8906, 0xa08e, 0x0002, 0x0040, 0x8906,
3893 0x6004, 0x1078, 0x8c3b, 0x0040, 0x898c, 0xa08e, 0x0021, 0x0040,
3894 0x8990, 0xa08e, 0x0022, 0x0040, 0x898c, 0xa08e, 0x003d, 0x0040,
3895 0x8990, 0xa08e, 0x0039, 0x0040, 0x8994, 0xa08e, 0x0035, 0x0040,
3896 0x8994, 0xa08e, 0x001e, 0x0040, 0x8908, 0xa08e, 0x0001, 0x00c0,
3897 0x8904, 0x0d7e, 0x6018, 0x2068, 0x6804, 0xa084, 0x00ff, 0x0d7f,
3898 0xa086, 0x0006, 0x0040, 0x8906, 0x1078, 0x2813, 0x1078, 0x7a05,
3899 0x1078, 0x8c01, 0x007c, 0x0c7e, 0x0d7e, 0x6104, 0xa186, 0x0016,
3900 0x0040, 0x8961, 0xa186, 0x0002, 0x00c0, 0x8934, 0x6018, 0x2068,
3901 0x68a0, 0xd0bc, 0x00c0, 0x89b8, 0x6840, 0xa084, 0x00ff, 0xa005,
3902 0x0040, 0x8934, 0x8001, 0x6842, 0x6013, 0x0000, 0x601f, 0x0007,
3903 0x6017, 0x0398, 0x1078, 0x74d7, 0x0040, 0x8934, 0x2d00, 0x601a,
3904 0x601f, 0x0001, 0x0078, 0x8961, 0x0d7f, 0x0c7f, 0x6004, 0xa08e,
3905 0x0002, 0x00c0, 0x8952, 0x6018, 0xa080, 0x0028, 0x2004, 0xa086,
3906 0x007e, 0x00c0, 0x8952, 0x2009, 0xa332, 0x2104, 0xc085, 0x200a,
3907 0x0e7e, 0x2071, 0xa300, 0x1078, 0x41f5, 0x0e7f, 0x1078, 0x7a05,
3908 0x0078, 0x8956, 0x1078, 0x7a05, 0x1078, 0x2813, 0x0e7e, 0x127e,
3909 0x2091, 0x8000, 0x1078, 0x2839, 0x127f, 0x0e7f, 0x1078, 0x8c01,
3910 0x007c, 0x2001, 0x0002, 0x1078, 0x443f, 0x6003, 0x0001, 0x6007,
3911 0x0002, 0x1078, 0x5c45, 0x1078, 0x6109, 0x0d7f, 0x0c7f, 0x0078,
3912 0x8960, 0x0c7e, 0x0d7e, 0x6104, 0xa186, 0x0016, 0x0040, 0x8961,
3913 0x6018, 0x2068, 0x6840, 0xa084, 0x00ff, 0xa005, 0x0040, 0x8934,
3914 0x8001, 0x6842, 0x6003, 0x0001, 0x1078, 0x5c45, 0x1078, 0x6109,
3915 0x0d7f, 0x0c7f, 0x0078, 0x8960, 0x1078, 0x7a05, 0x0078, 0x8908,
3916 0x1078, 0x7a28, 0x0078, 0x8908, 0x0d7e, 0x2c68, 0x6104, 0x1078,
3917 0x8ef5, 0x0d7f, 0x0040, 0x89a0, 0x1078, 0x753d, 0x0078, 0x89b7,
3918 0x6004, 0x8007, 0x6130, 0xa18c, 0x00ff, 0xa105, 0x6032, 0x6007,
3919 0x0085, 0x6003, 0x000b, 0x601f, 0x0002, 0x6038, 0x600a, 0x2001,
3920 0xa5a1, 0x2004, 0x6016, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x007c,
3921 0x0d7f, 0x0c7f, 0x1078, 0x7a05, 0x1078, 0x2813, 0x0e7e, 0x127e,
3922 0x2091, 0x8000, 0x1078, 0x2839, 0x6013, 0x0000, 0x601f, 0x0007,
3923 0x6017, 0x0398, 0x127f, 0x0e7f, 0x007c, 0x6000, 0xa08a, 0x0010,
3924 0x10c8, 0x1328, 0x1079, 0x89d5, 0x007c, 0x89e5, 0x89e5, 0x89e5,
3925 0x89e5, 0x89e5, 0x89e5, 0x89e5, 0x89e5, 0x89e5, 0x8827, 0x89e5,
3926 0x882f, 0x89e7, 0x882f, 0x89f5, 0x89e5, 0x1078, 0x1328, 0x6004,
3927 0xa086, 0x008b, 0x0040, 0x89f5, 0x6007, 0x008b, 0x6003, 0x000d,
3928 0x1078, 0x5bf8, 0x1078, 0x6109, 0x007c, 0x1078, 0x8bf4, 0x1078,
3929 0x8a44, 0x0040, 0x8a2d, 0x1078, 0x2813, 0x0d7e, 0x1078, 0x8a44,
3930 0x0040, 0x8a0f, 0x6010, 0x2068, 0x6837, 0x0103, 0x684b, 0x0006,
3931 0x6847, 0x0000, 0x6850, 0xc0ed, 0x6852, 0x1078, 0x4982, 0x2c68,
3932 0x1078, 0x74d7, 0x0040, 0x8a1d, 0x6818, 0x601a, 0x0c7e, 0x2d60,
3933 0x1078, 0x8c01, 0x0c7f, 0x0078, 0x8a1e, 0x2d60, 0x0d7f, 0x6013,
3934 0x0000, 0x601f, 0x0001, 0x6007, 0x0001, 0x6003, 0x0001, 0x1078,
3935 0x5c45, 0x1078, 0x6109, 0x0078, 0x8a2f, 0x1078, 0x8c01, 0x007c,
3936 0xa284, 0x000f, 0x00c0, 0x8a41, 0xa282, 0xaa00, 0x0048, 0x8a41,
3937 0x2001, 0xa315, 0x2004, 0xa202, 0x00c8, 0x8a41, 0xa085, 0x0001,
3938 0x007c, 0xa006, 0x0078, 0x8a40, 0x027e, 0x0e7e, 0x2071, 0xa300,
3939 0x6210, 0x7058, 0xa202, 0x0048, 0x8a56, 0x705c, 0xa202, 0x00c8,
3940 0x8a56, 0xa085, 0x0001, 0x0e7f, 0x027f, 0x007c, 0xa006, 0x0078,
3941 0x8a53, 0x0e7e, 0x0c7e, 0x037e, 0x007e, 0x127e, 0x2091, 0x8000,
3942 0x2061, 0xaa00, 0x2071, 0xa300, 0x7344, 0x7060, 0xa302, 0x00c8,
3943 0x8a83, 0x601c, 0xa206, 0x00c0, 0x8a7b, 0x1078, 0x8d66, 0x0040,
3944 0x8a7b, 0x1078, 0x8c3b, 0x00c0, 0x8a77, 0x1078, 0x7a05, 0x0c7e,
3945 0x1078, 0x753d, 0x0c7f, 0xace0, 0x0010, 0x7054, 0xac02, 0x00c8,
3946 0x8a83, 0x0078, 0x8a64, 0x127f, 0x007f, 0x037f, 0x0c7f, 0x0e7f,
3947 0x007c, 0x0e7e, 0x0c7e, 0x017e, 0xa188, 0xa434, 0x210c, 0x81ff,
3948 0x0040, 0x8aa1, 0x2061, 0xaa00, 0x2071, 0xa300, 0x017e, 0x1078,
3949 0x74d7, 0x017f, 0x0040, 0x8aa4, 0x611a, 0x1078, 0x2813, 0x1078,
3950 0x753d, 0xa006, 0x0078, 0x8aa6, 0xa085, 0x0001, 0x017f, 0x0c7f,
3951 0x0e7f, 0x007c, 0x0c7e, 0x057e, 0x127e, 0x2091, 0x8000, 0x0c7e,
3952 0x1078, 0x74d7, 0x057f, 0x0040, 0x8ac3, 0x6612, 0x651a, 0x601f,
3953 0x0003, 0x2009, 0x004b, 0x1078, 0x756c, 0xa085, 0x0001, 0x127f,
3954 0x057f, 0x0c7f, 0x007c, 0xa006, 0x0078, 0x8abf, 0x0c7e, 0x057e,
3955 0x127e, 0x2091, 0x8000, 0x62a0, 0x0c7e, 0x1078, 0x74d7, 0x057f,
3956 0x0040, 0x8af1, 0x6013, 0x0000, 0x651a, 0x601f, 0x0003, 0x0c7e,
3957 0x2560, 0x1078, 0x471b, 0x0c7f, 0x1078, 0x5d53, 0x077e, 0x2039,
3958 0x0000, 0x1078, 0x5c78, 0x2c08, 0x1078, 0x9c38, 0x077f, 0x2009,
3959 0x004c, 0x1078, 0x756c, 0xa085, 0x0001, 0x127f, 0x057f, 0x0c7f,
3960 0x007c, 0xa006, 0x0078, 0x8aed, 0x0f7e, 0x0c7e, 0x047e, 0x0c7e,
3961 0x1078, 0x74d7, 0x2c78, 0x0c7f, 0x0040, 0x8b0e, 0x7e12, 0x2c00,
3962 0x781a, 0x781f, 0x0003, 0x2021, 0x0005, 0x1078, 0x8b4e, 0x2f60,
3963 0x2009, 0x004d, 0x1078, 0x756c, 0xa085, 0x0001, 0x047f, 0x0c7f,
3964 0x0f7f, 0x007c, 0x0f7e, 0x0c7e, 0x047e, 0x0c7e, 0x1078, 0x74d7,
3965 0x2c78, 0x0c7f, 0x0040, 0x8b2c, 0x7e12, 0x2c00, 0x781a, 0x781f,
3966 0x0003, 0x2021, 0x0005, 0x1078, 0x8b4e, 0x2f60, 0x2009, 0x004e,
3967 0x1078, 0x756c, 0xa085, 0x0001, 0x047f, 0x0c7f, 0x0f7f, 0x007c,
3968 0x0f7e, 0x0c7e, 0x047e, 0x0c7e, 0x1078, 0x74d7, 0x2c78, 0x0c7f,
3969 0x0040, 0x8b4a, 0x7e12, 0x2c00, 0x781a, 0x781f, 0x0003, 0x2021,
3970 0x0004, 0x1078, 0x8b4e, 0x2f60, 0x2009, 0x0052, 0x1078, 0x756c,
3971 0xa085, 0x0001, 0x047f, 0x0c7f, 0x0f7f, 0x007c, 0x097e, 0x077e,
3972 0x127e, 0x2091, 0x8000, 0x1078, 0x46a7, 0x0040, 0x8b5b, 0x2001,
3973 0x8b53, 0x0078, 0x8b61, 0x1078, 0x466d, 0x0040, 0x8b6a, 0x2001,
3974 0x8b5b, 0x007e, 0xa00e, 0x2400, 0x1078, 0x4a60, 0x1078, 0x4982,
3975 0x007f, 0x007a, 0x2418, 0x1078, 0x5fa7, 0x62a0, 0x087e, 0x2041,
3976 0x0001, 0x2039, 0x0001, 0x2608, 0x1078, 0x5d6d, 0x087f, 0x1078,
3977 0x5c78, 0x2f08, 0x2648, 0x1078, 0x9c38, 0x613c, 0x81ff, 0x1040,
3978 0x5e21, 0x127f, 0x077f, 0x097f, 0x007c, 0x0c7e, 0x127e, 0x2091,
3979 0x8000, 0x0c7e, 0x1078, 0x74d7, 0x017f, 0x0040, 0x8b9e, 0x660a,
3980 0x611a, 0x601f, 0x0001, 0x2d00, 0x6012, 0x2009, 0x001f, 0x1078,
3981 0x756c, 0xa085, 0x0001, 0x127f, 0x0c7f, 0x007c, 0xa006, 0x0078,
3982 0x8b9b, 0x0c7e, 0x127e, 0x2091, 0x8000, 0x0c7e, 0x1078, 0x74d7,
3983 0x017f, 0x0040, 0x8bba, 0x660a, 0x611a, 0x601f, 0x0008, 0x2d00,
3984 0x6012, 0x2009, 0x0021, 0x1078, 0x756c, 0xa085, 0x0001, 0x127f,
3985 0x0c7f, 0x007c, 0xa006, 0x0078, 0x8bb7, 0x0c7e, 0x127e, 0x2091,
3986 0x8000, 0x0c7e, 0x1078, 0x74d7, 0x017f, 0x0040, 0x8bd6, 0x660a,
3987 0x611a, 0x601f, 0x0001, 0x2d00, 0x6012, 0x2009, 0x003d, 0x1078,
3988 0x756c, 0xa085, 0x0001, 0x127f, 0x0c7f, 0x007c, 0xa006, 0x0078,
3989 0x8bd3, 0x0c7e, 0x127e, 0x2091, 0x8000, 0x0c7e, 0x1078, 0x74d7,
3990 0x017f, 0x0040, 0x8bf1, 0x611a, 0x601f, 0x0001, 0x2d00, 0x6012,
3991 0x2009, 0x0000, 0x1078, 0x756c, 0xa085, 0x0001, 0x127f, 0x0c7f,
3992 0x007c, 0xa006, 0x0078, 0x8bee, 0x027e, 0x0d7e, 0x6218, 0x2268,
3993 0x6a3c, 0x82ff, 0x0040, 0x8bfe, 0x8211, 0x6a3e, 0x0d7f, 0x027f,
3994 0x007c, 0x007e, 0x6000, 0xa086, 0x0000, 0x0040, 0x8c13, 0x6013,
3995 0x0000, 0x601f, 0x0007, 0x2001, 0xa5a1, 0x2004, 0x6016, 0x1078,
3996 0xa134, 0x603f, 0x0000, 0x007f, 0x007c, 0x067e, 0x0c7e, 0x0d7e,
3997 0x2031, 0xa352, 0x2634, 0xd6e4, 0x0040, 0x8c23, 0x6618, 0x2660,
3998 0x6e48, 0x1078, 0x461b, 0x0d7f, 0x0c7f, 0x067f, 0x007c, 0x007e,
3999 0x017e, 0x6004, 0xa08e, 0x0002, 0x0040, 0x8c38, 0xa08e, 0x0003,
4000 0x0040, 0x8c38, 0xa08e, 0x0004, 0x0040, 0x8c38, 0xa085, 0x0001,
4001 0x017f, 0x007f, 0x007c, 0x007e, 0x0d7e, 0x6010, 0xa06d, 0x0040,
4002 0x8c48, 0x6838, 0xd0fc, 0x0040, 0x8c48, 0xa006, 0x0078, 0x8c4a,
4003 0xa085, 0x0001, 0x0d7f, 0x007f, 0x007c, 0x0c7e, 0x127e, 0x2091,
4004 0x8000, 0x0c7e, 0x1078, 0x74d7, 0x017f, 0x0040, 0x8c67, 0x611a,
4005 0x601f, 0x0001, 0x2d00, 0x6012, 0x1078, 0x2813, 0x2009, 0x0028,
4006 0x1078, 0x756c, 0xa085, 0x0001, 0x127f, 0x0c7f, 0x007c, 0xa006,
4007 0x0078, 0x8c64, 0xa186, 0x0015, 0x00c0, 0x8c7f, 0x2011, 0xa31f,
4008 0x2204, 0xa086, 0x0074, 0x00c0, 0x8c7f, 0x1078, 0x7d0d, 0x6003,
4009 0x0001, 0x6007, 0x0029, 0x1078, 0x5c45, 0x0078, 0x8c83, 0x1078,
4010 0x7a05, 0x1078, 0x753d, 0x007c, 0xa186, 0x0016, 0x00c0, 0x8c8e,
4011 0x2001, 0x0004, 0x1078, 0x443f, 0x0078, 0x8caf, 0xa186, 0x0015,
4012 0x00c0, 0x8cb3, 0x2011, 0xa31f, 0x2204, 0xa086, 0x0014, 0x00c0,
4013 0x8cb3, 0x0d7e, 0x6018, 0x2068, 0x1078, 0x457d, 0x0d7f, 0x1078,
4014 0x7dba, 0x00c0, 0x8cb3, 0x0d7e, 0x6018, 0x2068, 0x6890, 0x0d7f,
4015 0xa005, 0x0040, 0x8cb3, 0x2001, 0x0006, 0x1078, 0x443f, 0x1078,
4016 0x7608, 0x0078, 0x8cb7, 0x1078, 0x7a05, 0x1078, 0x753d, 0x007c,
4017 0x6848, 0xa086, 0x0005, 0x00c0, 0x8cbf, 0x1078, 0x8cc0, 0x007c,
4018 0x6850, 0xc0ad, 0x6852, 0x007c, 0x0e7e, 0x2071, 0xa88c, 0x7014,
4019 0xd0e4, 0x0040, 0x8cd5, 0x6013, 0x0000, 0x6003, 0x0001, 0x6007,
4020 0x0050, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0e7f, 0x007c, 0x0c7e,
4021 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0f7f, 0x0040, 0x8ce4, 0x601c,
4022 0xa084, 0x000f, 0x1079, 0x8ce6, 0x0c7f, 0x007c, 0x8827, 0x8cf1,
4023 0x8cf4, 0x8cf7, 0x9f00, 0x9f1c, 0x9f1f, 0x8827, 0x8827, 0x1078,
4024 0x1328, 0x0005, 0x0005, 0x007c, 0x0005, 0x0005, 0x007c, 0x1078,
4025 0x8cfa, 0x007c, 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0040, 0x8d29,
4026 0x1078, 0x74d7, 0x00c0, 0x8d0a, 0x2001, 0xa5a2, 0x2004, 0x783e,
4027 0x0078, 0x8d29, 0x7818, 0x601a, 0x781c, 0xa086, 0x0003, 0x0040,
4028 0x8d17, 0x7808, 0x6036, 0x2f00, 0x603a, 0x0078, 0x8d1b, 0x7808,
4029 0x603a, 0x2f00, 0x6036, 0x602a, 0x601f, 0x0001, 0x6007, 0x0035,
4030 0x6003, 0x0001, 0x7920, 0x6122, 0x1078, 0x5bf8, 0x1078, 0x6109,
4031 0x2f60, 0x0f7f, 0x007c, 0x017e, 0x0f7e, 0x682c, 0x6032, 0xa08e,
4032 0x0001, 0x0040, 0x8d3c, 0xa086, 0x0005, 0x0040, 0x8d40, 0xa006,
4033 0x602a, 0x602e, 0x0078, 0x8d51, 0x6824, 0xc0f4, 0xc0d5, 0x6826,
4034 0x6810, 0x2078, 0x787c, 0x6938, 0xa102, 0x7880, 0x6934, 0xa103,
4035 0x00c8, 0x8d37, 0x6834, 0x602a, 0x6838, 0xa084, 0xfffc, 0x683a,
4036 0x602e, 0x2d00, 0x6036, 0x6808, 0x603a, 0x6918, 0x611a, 0x6920,
4037 0x6122, 0x601f, 0x0001, 0x6007, 0x0039, 0x6003, 0x0001, 0x1078,
4038 0x5bf8, 0x6803, 0x0002, 0x0f7f, 0x017f, 0x007c, 0x007e, 0x017e,
4039 0x6004, 0xa08e, 0x0034, 0x0040, 0x8d8b, 0xa08e, 0x0035, 0x0040,
4040 0x8d8b, 0xa08e, 0x0036, 0x0040, 0x8d8b, 0xa08e, 0x0037, 0x0040,
4041 0x8d8b, 0xa08e, 0x0038, 0x0040, 0x8d8b, 0xa08e, 0x0039, 0x0040,
4042 0x8d8b, 0xa08e, 0x003a, 0x0040, 0x8d8b, 0xa08e, 0x003b, 0x0040,
4043 0x8d8b, 0xa085, 0x0001, 0x017f, 0x007f, 0x007c, 0x0f7e, 0x2c78,
4044 0x1078, 0x4893, 0x00c0, 0x8d98, 0xa085, 0x0001, 0x0078, 0x8da7,
4045 0x6024, 0xd0f4, 0x00c0, 0x8da6, 0xc0f5, 0x6026, 0x6010, 0x2078,
4046 0x7828, 0x603a, 0x782c, 0x6036, 0x1078, 0x1749, 0xa006, 0x0f7f,
4047 0x007c, 0x007e, 0x017e, 0x027e, 0x037e, 0x0e7e, 0x2001, 0xa59c,
4048 0x200c, 0x8000, 0x2014, 0x2001, 0x0032, 0x1078, 0x5a98, 0x2001,
4049 0xa5a0, 0x82ff, 0x00c0, 0x8dbe, 0x2011, 0x0002, 0x2202, 0x2001,
4050 0xa59e, 0x200c, 0x8000, 0x2014, 0x2071, 0xa58c, 0x711a, 0x721e,
4051 0x2001, 0x0064, 0x1078, 0x5a98, 0x2001, 0xa5a1, 0x82ff, 0x00c0,
4052 0x8dd3, 0x2011, 0x0002, 0x2202, 0x2009, 0xa5a2, 0xa280, 0x000a,
4053 0x200a, 0x0e7f, 0x037f, 0x027f, 0x017f, 0x007f, 0x007c, 0x007e,
4054 0x0e7e, 0x2001, 0xa5a0, 0x2003, 0x0028, 0x2001, 0xa5a1, 0x2003,
4055 0x0014, 0x2071, 0xa58c, 0x701b, 0x0000, 0x701f, 0x07d0, 0x2001,
4056 0xa5a2, 0x2003, 0x001e, 0x0e7f, 0x007f, 0x007c, 0x0c7e, 0x127e,
4057 0x2091, 0x8000, 0x0c7e, 0x1078, 0x74d7, 0x017f, 0x0040, 0x8e0e,
4058 0x611a, 0x601f, 0x0001, 0x2d00, 0x6012, 0x2009, 0x0033, 0x1078,
4059 0x756c, 0xa085, 0x0001, 0x127f, 0x0c7f, 0x007c, 0xa006, 0x0078,
4060 0x8e0b, 0x0d7e, 0x0e7e, 0x0f7e, 0x2071, 0xa300, 0xa186, 0x0015,
4061 0x00c0, 0x8e40, 0x707c, 0xa086, 0x0018, 0x00c0, 0x8e40, 0x6010,
4062 0x2068, 0x6a3c, 0xd2e4, 0x00c0, 0x8e34, 0x2c78, 0x1078, 0x62c6,
4063 0x0040, 0x8e48, 0x7068, 0x6a50, 0xa206, 0x00c0, 0x8e3c, 0x706c,
4064 0x6a54, 0xa206, 0x00c0, 0x8e3c, 0x6218, 0xa290, 0x0028, 0x2214,
4065 0x2009, 0x0000, 0x1078, 0x285b, 0x1078, 0x7608, 0x0078, 0x8e44,
4066 0x1078, 0x7a05, 0x1078, 0x753d, 0x0f7f, 0x0e7f, 0x0d7f, 0x007c,
4067 0x704c, 0xa080, 0x293f, 0x2004, 0x6a54, 0xa206, 0x0040, 0x8e34,
4068 0x0078, 0x8e3c, 0x0c7e, 0x127e, 0x2091, 0x8000, 0x0c7e, 0x1078,
4069 0x74d7, 0x017f, 0x0040, 0x8e6a, 0x611a, 0x601f, 0x0001, 0x2d00,
4070 0x6012, 0x2009, 0x0043, 0x1078, 0x756c, 0xa085, 0x0001, 0x127f,
4071 0x0c7f, 0x007c, 0xa006, 0x0078, 0x8e67, 0x0d7e, 0x0e7e, 0x0f7e,
4072 0x2071, 0xa300, 0xa186, 0x0015, 0x00c0, 0x8e93, 0x707c, 0xa086,
4073 0x0004, 0x00c0, 0x8e93, 0x6010, 0xa0e8, 0x000f, 0x2c78, 0x1078,
4074 0x62c6, 0x0040, 0x8e9b, 0x7068, 0x6a08, 0xa206, 0x00c0, 0x8e8f,
4075 0x706c, 0x6a0c, 0xa206, 0x00c0, 0x8e8f, 0x1078, 0x2813, 0x1078,
4076 0x7608, 0x0078, 0x8e97, 0x1078, 0x7a05, 0x1078, 0x753d, 0x0f7f,
4077 0x0e7f, 0x0d7f, 0x007c, 0x704c, 0xa080, 0x293f, 0x2004, 0x6a0c,
4078 0xa206, 0x0040, 0x8e8d, 0x0078, 0x8e8f, 0x017e, 0x027e, 0x684c,
4079 0xd0ac, 0x0040, 0x8ebd, 0x6914, 0x6a10, 0x2100, 0xa205, 0x0040,
4080 0x8ebd, 0x6860, 0xa106, 0x00c0, 0x8eb9, 0x685c, 0xa206, 0x0040,
4081 0x8ebd, 0x6962, 0x6a5e, 0xa085, 0x0001, 0x027f, 0x017f, 0x007c,
4082 0x0e7e, 0x127e, 0x2071, 0xa300, 0x2091, 0x8000, 0x7544, 0xa582,
4083 0x0001, 0x0048, 0x8ef2, 0x7048, 0x2060, 0x6000, 0xa086, 0x0000,
4084 0x0040, 0x8ede, 0xace0, 0x0010, 0x7054, 0xac02, 0x00c8, 0x8eda,
4085 0x0078, 0x8ecd, 0x2061, 0xaa00, 0x0078, 0x8ecd, 0x6003, 0x0008,
4086 0x8529, 0x7546, 0xaca8, 0x0010, 0x7054, 0xa502, 0x00c8, 0x8eee,
4087 0x754a, 0xa085, 0x0001, 0x127f, 0x0e7f, 0x007c, 0x704b, 0xaa00,
4088 0x0078, 0x8ee9, 0xa006, 0x0078, 0x8eeb, 0x0c7e, 0x027e, 0x017e,
4089 0xa186, 0x0035, 0x0040, 0x8eff, 0x6a34, 0x0078, 0x8f00, 0x6a28,
4090 0x1078, 0x8a30, 0x0040, 0x8f29, 0x2260, 0x611c, 0xa186, 0x0003,
4091 0x0040, 0x8f0e, 0xa186, 0x0006, 0x00c0, 0x8f25, 0x6834, 0xa206,
4092 0x0040, 0x8f1d, 0x6838, 0xa206, 0x00c0, 0x8f25, 0x6108, 0x6834,
4093 0xa106, 0x00c0, 0x8f25, 0x0078, 0x8f22, 0x6008, 0x6938, 0xa106,
4094 0x00c0, 0x8f25, 0x6018, 0x6918, 0xa106, 0x017f, 0x027f, 0x0c7f,
4095 0x007c, 0xa085, 0x0001, 0x0078, 0x8f25, 0x067e, 0x6000, 0xa0b2,
4096 0x0010, 0x10c8, 0x1328, 0x1079, 0x8f37, 0x067f, 0x007c, 0x8f47,
4097 0x93bb, 0x94d3, 0x8f47, 0x8f47, 0x8f47, 0x8f47, 0x8f47, 0x8f81,
4098 0x955e, 0x8f47, 0x8f47, 0x8f47, 0x8f47, 0x8f47, 0x8f47, 0x1078,
4099 0x1328, 0x067e, 0x6000, 0xa0b2, 0x0010, 0x10c8, 0x1328, 0x1079,
4100 0x8f53, 0x067f, 0x007c, 0x8f63, 0x99f6, 0x8f63, 0x8f63, 0x8f63,
4101 0x8f63, 0x8f63, 0x8f63, 0x99b4, 0x9a44, 0x8f63, 0xa053, 0xa087,
4102 0xa053, 0xa087, 0x8f63, 0x1078, 0x1328, 0x067e, 0x6000, 0xa0b2,
4103 0x0010, 0x10c8, 0x1328, 0x1079, 0x8f6f, 0x067f, 0x007c, 0x8f7f,
4104 0x969f, 0x976a, 0x9798, 0x9813, 0x8f7f, 0x9919, 0x98c1, 0x956a,
4105 0x9988, 0x999e, 0x8f7f, 0x8f7f, 0x8f7f, 0x8f7f, 0x8f7f, 0x1078,
4106 0x1328, 0xa1b2, 0x0044, 0x10c8, 0x1328, 0x2100, 0x0079, 0x8f88,
4107 0x8fc8, 0x919a, 0x8fc8, 0x8fc8, 0x8fc8, 0x91a2, 0x8fc8, 0x8fc8,
4108 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8,
4109 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fca,
4110 0x902d, 0x9038, 0x9081, 0x909c, 0x911b, 0x918b, 0x8fc8, 0x8fc8,
4111 0x91a6, 0x8fc8, 0x8fc8, 0x91b5, 0x91bc, 0x8fc8, 0x8fc8, 0x8fc8,
4112 0x8fc8, 0x8fc8, 0x91ea, 0x8fc8, 0x8fc8, 0x91f5, 0x8fc8, 0x8fc8,
4113 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x920a, 0x8fc8, 0x8fc8, 0x8fc8,
4114 0x9291, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x8fc8, 0x9305,
4115 0x1078, 0x1328, 0x1078, 0x4897, 0x00c0, 0x8fd7, 0x2001, 0xa332,
4116 0x2004, 0xa084, 0x0009, 0xa086, 0x0008, 0x00c0, 0x8fdf, 0x6007,
4117 0x0009, 0x602b, 0x0009, 0x6013, 0x0000, 0x0078, 0x9195, 0x1078,
4118 0x4887, 0x0e7e, 0x0c7e, 0x037e, 0x027e, 0x017e, 0x6218, 0x2270,
4119 0x72a0, 0x027e, 0x2019, 0x0029, 0x1078, 0x5d53, 0x077e, 0x2039,
4120 0x0000, 0x1078, 0x5c78, 0x2c08, 0x1078, 0x9c38, 0x077f, 0x017f,
4121 0x2e60, 0x1078, 0x471b, 0x017f, 0x027f, 0x037f, 0x0c7f, 0x0e7f,
4122 0x6618, 0x0c7e, 0x2660, 0x1078, 0x4513, 0x0c7f, 0xa6b0, 0x0001,
4123 0x2634, 0xa684, 0x00ff, 0xa082, 0x0006, 0x0048, 0x901f, 0x1078,
4124 0x9b6c, 0x00c0, 0x907b, 0x1078, 0x9afd, 0x00c0, 0x901b, 0x6007,
4125 0x0008, 0x0078, 0x9195, 0x6007, 0x0009, 0x0078, 0x9195, 0x1078,
4126 0x9d45, 0x0040, 0x9029, 0x1078, 0x9b6c, 0x0040, 0x9013, 0x0078,
4127 0x907b, 0x6013, 0x1900, 0x0078, 0x901b, 0x6106, 0x1078, 0x9aa8,
4128 0x6007, 0x0006, 0x0078, 0x9195, 0x6007, 0x0007, 0x0078, 0x9195,
4129 0x1078, 0xa0bf, 0x00c0, 0x9340, 0x0d7e, 0x6618, 0x2668, 0x6e04,
4130 0xa6b4, 0xff00, 0x8637, 0xa686, 0x0006, 0x0040, 0x905d, 0xa686,
4131 0x0004, 0x0040, 0x905d, 0x6e04, 0xa6b4, 0x00ff, 0xa686, 0x0006,
4132 0x0040, 0x905d, 0xa686, 0x0004, 0x0040, 0x905d, 0xa686, 0x0005,
4133 0x0040, 0x905d, 0x0d7f, 0x0078, 0x907b, 0x1078, 0x9bd2, 0x00c0,
4134 0x9076, 0xa686, 0x0006, 0x00c0, 0x906f, 0x027e, 0x6218, 0xa290,
4135 0x0028, 0x2214, 0x2009, 0x0000, 0x1078, 0x285b, 0x027f, 0x1078,
4136 0x457d, 0x6007, 0x000a, 0x0d7f, 0x0078, 0x9195, 0x6007, 0x000b,
4137 0x0d7f, 0x0078, 0x9195, 0x1078, 0x2813, 0x6007, 0x0001, 0x0078,
4138 0x9195, 0x1078, 0xa0bf, 0x00c0, 0x9340, 0x6618, 0x0d7e, 0x2668,
4139 0x6e04, 0x0d7f, 0xa686, 0x0707, 0x0040, 0x907b, 0x027e, 0x6218,
4140 0xa290, 0x0028, 0x2214, 0x2009, 0x0000, 0x1078, 0x285b, 0x027f,
4141 0x6007, 0x000c, 0x0078, 0x9195, 0x1078, 0x4897, 0x00c0, 0x90a9,
4142 0x2001, 0xa332, 0x2004, 0xa084, 0x0009, 0xa086, 0x0008, 0x00c0,
4143 0x90b1, 0x6007, 0x0009, 0x602b, 0x0009, 0x6013, 0x0000, 0x0078,
4144 0x9195, 0x1078, 0x4887, 0x6618, 0xa6b0, 0x0001, 0x2634, 0xa684,
4145 0x00ff, 0xa082, 0x0006, 0x0048, 0x90f5, 0xa6b4, 0xff00, 0x8637,
4146 0xa686, 0x0004, 0x0040, 0x90c8, 0xa686, 0x0006, 0x00c0, 0x907b,
4147 0x1078, 0x9be1, 0x00c0, 0x90d0, 0x6007, 0x000e, 0x0078, 0x9195,
4148 0x047e, 0x6418, 0xa4a0, 0x0028, 0x2424, 0xa4a4, 0x00ff, 0x8427,
4149 0x047e, 0x1078, 0x2813, 0x047f, 0x017e, 0xa006, 0x2009, 0xa352,
4150 0x210c, 0xd1a4, 0x0040, 0x90ef, 0x2009, 0x0029, 0x1078, 0x9ec0,
4151 0x6018, 0x0d7e, 0x2068, 0x6800, 0xc0e5, 0x6802, 0x0d7f, 0x017f,
4152 0x047f, 0x6007, 0x0001, 0x0078, 0x9195, 0x2001, 0x0001, 0x1078,
4153 0x442b, 0x157e, 0x017e, 0x027e, 0x037e, 0x20a9, 0x0004, 0x2019,
4154 0xa305, 0x2011, 0xa890, 0x1078, 0x7e55, 0x037f, 0x027f, 0x017f,
4155 0x157f, 0xa005, 0x0040, 0x9115, 0xa6b4, 0xff00, 0x8637, 0xa686,
4156 0x0006, 0x0040, 0x90c8, 0x0078, 0x907b, 0x6013, 0x1900, 0x6007,
4157 0x0009, 0x0078, 0x9195, 0x1078, 0x4897, 0x00c0, 0x9128, 0x2001,
4158 0xa332, 0x2004, 0xa084, 0x0009, 0xa086, 0x0008, 0x00c0, 0x9130,
4159 0x6007, 0x0009, 0x602b, 0x0009, 0x6013, 0x0000, 0x0078, 0x9195,
4160 0x1078, 0x4887, 0x6618, 0xa6b0, 0x0001, 0x2634, 0xa684, 0x00ff,
4161 0xa082, 0x0006, 0x0048, 0x9178, 0xa6b4, 0xff00, 0x8637, 0xa686,
4162 0x0004, 0x0040, 0x9147, 0xa686, 0x0006, 0x00c0, 0x907b, 0x1078,
4163 0x9c0c, 0x00c0, 0x9153, 0x1078, 0x9afd, 0x00c0, 0x9153, 0x6007,
4164 0x0010, 0x0078, 0x9195, 0x047e, 0x6418, 0xa4a0, 0x0028, 0x2424,
4165 0xa4a4, 0x00ff, 0x8427, 0x047e, 0x1078, 0x2813, 0x047f, 0x017e,
4166 0xa006, 0x2009, 0xa352, 0x210c, 0xd1a4, 0x0040, 0x9172, 0x2009,
4167 0x0029, 0x1078, 0x9ec0, 0x6018, 0x0d7e, 0x2068, 0x6800, 0xc0e5,
4168 0x6802, 0x0d7f, 0x017f, 0x047f, 0x6007, 0x0001, 0x0078, 0x9195,
4169 0x1078, 0x9d45, 0x0040, 0x9185, 0xa6b4, 0xff00, 0x8637, 0xa686,
4170 0x0006, 0x0040, 0x9147, 0x0078, 0x907b, 0x6013, 0x1900, 0x6007,
4171 0x0009, 0x0078, 0x9195, 0x1078, 0xa0bf, 0x00c0, 0x9340, 0x1078,
4172 0x9343, 0x00c0, 0x907b, 0x6007, 0x0012, 0x6003, 0x0001, 0x1078,
4173 0x5c45, 0x007c, 0x6007, 0x0001, 0x6003, 0x0001, 0x1078, 0x5c45,
4174 0x0078, 0x9199, 0x6007, 0x0005, 0x0078, 0x919c, 0x1078, 0xa0bf,
4175 0x00c0, 0x9340, 0x1078, 0x9343, 0x00c0, 0x907b, 0x6007, 0x0020,
4176 0x6003, 0x0001, 0x1078, 0x5c45, 0x007c, 0x6007, 0x0023, 0x6003,
4177 0x0001, 0x1078, 0x5c45, 0x007c, 0x1078, 0xa0bf, 0x00c0, 0x9340,
4178 0x1078, 0x9343, 0x00c0, 0x907b, 0x017e, 0x027e, 0x2011, 0xa890,
4179 0x2214, 0x2c08, 0x1078, 0x9e8c, 0x00c0, 0x91de, 0x2160, 0x6007,
4180 0x0026, 0x6013, 0x1700, 0x2011, 0xa889, 0x2214, 0xa296, 0xffff,
4181 0x00c0, 0x91e3, 0x6007, 0x0025, 0x0078, 0x91e3, 0x1078, 0x753d,
4182 0x2160, 0x6007, 0x0025, 0x6003, 0x0001, 0x1078, 0x5c45, 0x027f,
4183 0x017f, 0x007c, 0x6106, 0x1078, 0x9363, 0x6007, 0x002b, 0x0078,
4184 0x9195, 0x6007, 0x002c, 0x0078, 0x9195, 0x1078, 0xa0bf, 0x00c0,
4185 0x9340, 0x1078, 0x9343, 0x00c0, 0x907b, 0x6106, 0x1078, 0x9368,
4186 0x00c0, 0x9206, 0x6007, 0x002e, 0x0078, 0x9195, 0x6007, 0x002f,
4187 0x0078, 0x9195, 0x0e7e, 0x0d7e, 0x0c7e, 0x6018, 0xa080, 0x0001,
4188 0x200c, 0xa184, 0x00ff, 0xa086, 0x0006, 0x0040, 0x9223, 0xa184,
4189 0xff00, 0x8007, 0xa086, 0x0006, 0x0040, 0x9223, 0x0c7f, 0x0d7f,
4190 0x0e7f, 0x0078, 0x919a, 0x2001, 0xa371, 0x2004, 0xd0e4, 0x0040,
4191 0x928d, 0x2071, 0xa88c, 0x7010, 0x6036, 0x7014, 0x603a, 0x7108,
4192 0x720c, 0x2001, 0xa352, 0x2004, 0xd0a4, 0x0040, 0x9241, 0x6018,
4193 0x2068, 0x6810, 0xa106, 0x00c0, 0x9241, 0x6814, 0xa206, 0x0040,
4194 0x9265, 0x2001, 0xa352, 0x2004, 0xd0ac, 0x00c0, 0x9281, 0x2069,
4195 0xa300, 0x686c, 0xa206, 0x00c0, 0x9281, 0x6868, 0xa106, 0x00c0,
4196 0x9281, 0x7210, 0x1078, 0x8a30, 0x0040, 0x9287, 0x1078, 0x9f31,
4197 0x0040, 0x9287, 0x622a, 0x6007, 0x0036, 0x6003, 0x0001, 0x1078,
4198 0x5bf8, 0x0c7f, 0x0d7f, 0x0e7f, 0x007c, 0x7214, 0xa286, 0xffff,
4199 0x0040, 0x9277, 0x1078, 0x8a30, 0x0040, 0x9287, 0xa280, 0x0002,
4200 0x2004, 0x7110, 0xa106, 0x00c0, 0x9287, 0x0078, 0x9252, 0x7210,
4201 0x2c08, 0x1078, 0x9e8c, 0x2c10, 0x2160, 0x0040, 0x9287, 0x0078,
4202 0x9252, 0x6007, 0x0037, 0x6013, 0x1500, 0x0078, 0x925d, 0x6007,
4203 0x0037, 0x6013, 0x1700, 0x0078, 0x925d, 0x6007, 0x0012, 0x0078,
4204 0x925d, 0x6018, 0xa080, 0x0001, 0x2004, 0xa084, 0xff00, 0x8007,
4205 0xa086, 0x0006, 0x00c0, 0x919a, 0x0e7e, 0x0d7e, 0x0c7e, 0x2001,
4206 0xa371, 0x2004, 0xd0e4, 0x0040, 0x92fd, 0x2069, 0xa300, 0x2071,
4207 0xa88c, 0x7008, 0x6036, 0x720c, 0x623a, 0xa286, 0xffff, 0x00c0,
4208 0x92ba, 0x7208, 0x0c7e, 0x2c08, 0x1078, 0x9e8c, 0x2c10, 0x0c7f,
4209 0x0040, 0x92f1, 0x1078, 0x8a30, 0x0040, 0x92f1, 0x0c7e, 0x027e,
4210 0x2260, 0x1078, 0x874a, 0x027f, 0x0c7f, 0x7118, 0xa18c, 0xff00,
4211 0x810f, 0xa186, 0x0001, 0x0040, 0x92db, 0xa186, 0x0005, 0x0040,
4212 0x92d5, 0xa186, 0x0007, 0x00c0, 0x92e5, 0xa280, 0x0004, 0x2004,
4213 0xa005, 0x0040, 0x92e5, 0x057e, 0x7510, 0x7614, 0x1078, 0x9f46,
4214 0x057f, 0x0c7f, 0x0d7f, 0x0e7f, 0x007c, 0x6007, 0x003b, 0x602b,
4215 0x0009, 0x6013, 0x2a00, 0x6003, 0x0001, 0x1078, 0x5bf8, 0x0078,
4216 0x92e1, 0x6007, 0x003b, 0x602b, 0x0009, 0x6013, 0x1700, 0x6003,
4217 0x0001, 0x1078, 0x5bf8, 0x0078, 0x92e1, 0x6007, 0x003b, 0x602b,
4218 0x000b, 0x6013, 0x0000, 0x0078, 0x925d, 0x0e7e, 0x027e, 0x1078,
4219 0x4897, 0x0040, 0x933a, 0x1078, 0x4887, 0x1078, 0xa148, 0x00c0,
4220 0x9338, 0x2071, 0xa300, 0x70c8, 0xc085, 0x70ca, 0x0f7e, 0x2079,
4221 0x0100, 0x7294, 0xa284, 0x00ff, 0x706a, 0x78e6, 0xa284, 0xff00,
4222 0x726c, 0xa205, 0x706e, 0x78ea, 0x0f7f, 0x70d3, 0x0000, 0x2001,
4223 0xa352, 0x2004, 0xd0a4, 0x0040, 0x9331, 0x2011, 0xa5c4, 0x2013,
4224 0x07d0, 0xd0ac, 0x00c0, 0x933a, 0x1078, 0x260d, 0x0078, 0x933a,
4225 0x1078, 0xa178, 0x027f, 0x0e7f, 0x1078, 0x753d, 0x0078, 0x9199,
4226 0x1078, 0x753d, 0x007c, 0x0d7e, 0x067e, 0x6618, 0x2668, 0x6e04,
4227 0xa6b4, 0xff00, 0x8637, 0xa686, 0x0006, 0x0040, 0x9360, 0xa686,
4228 0x0004, 0x0040, 0x9360, 0x6e04, 0xa6b4, 0x00ff, 0xa686, 0x0006,
4229 0x0040, 0x9360, 0xa686, 0x0004, 0x0040, 0x9360, 0xa085, 0x0001,
4230 0x067f, 0x0d7f, 0x007c, 0x0d7e, 0x1078, 0x9397, 0x0d7f, 0x007c,
4231 0x0d7e, 0x1078, 0x93a6, 0x00c0, 0x9390, 0x680c, 0xa08c, 0xff00,
4232 0x6820, 0xa084, 0x00ff, 0xa115, 0x6212, 0x6824, 0x602a, 0xd1e4,
4233 0x0040, 0x937e, 0x2009, 0x0001, 0x0078, 0x938c, 0xd1ec, 0x0040,
4234 0x9390, 0x6920, 0xa18c, 0x00ff, 0x6824, 0x1078, 0x24e3, 0x00c0,
4235 0x9390, 0x2110, 0x2009, 0x0000, 0x1078, 0x285b, 0x0078, 0x9394,
4236 0xa085, 0x0001, 0x0078, 0x9395, 0xa006, 0x0d7f, 0x007c, 0x2069,
4237 0xa88d, 0x6800, 0xa082, 0x0010, 0x00c8, 0x93a4, 0x6013, 0x0000,
4238 0xa085, 0x0001, 0x0078, 0x93a5, 0xa006, 0x007c, 0x6013, 0x0000,
4239 0x2069, 0xa88c, 0x6808, 0xa084, 0xff00, 0xa086, 0x0800, 0x00c0,
4240 0x93ba, 0x6800, 0xa084, 0x00ff, 0xa08e, 0x0014, 0x0040, 0x93ba,
4241 0xa08e, 0x0010, 0x007c, 0x6004, 0xa0b2, 0x0044, 0x10c8, 0x1328,
4242 0xa1b6, 0x0013, 0x00c0, 0x93c7, 0x2008, 0x0079, 0x93da, 0xa1b6,
4243 0x0027, 0x0040, 0x93cf, 0xa1b6, 0x0014, 0x10c0, 0x1328, 0x2001,
4244 0x0007, 0x1078, 0x4472, 0x1078, 0x6010, 0x1078, 0x8c01, 0x1078,
4245 0x6109, 0x007c, 0x941a, 0x941c, 0x941a, 0x941a, 0x941a, 0x941c,
4246 0x9424, 0x94ae, 0x9471, 0x94ae, 0x9485, 0x94ae, 0x9424, 0x94ae,
4247 0x94a6, 0x94ae, 0x94a6, 0x94ae, 0x94ae, 0x941a, 0x941a, 0x941a,
4248 0x941a, 0x941a, 0x941a, 0x941a, 0x941a, 0x941a, 0x941a, 0x941a,
4249 0x941c, 0x941a, 0x94ae, 0x941a, 0x941a, 0x94ae, 0x941a, 0x94ae,
4250 0x94ae, 0x941a, 0x941a, 0x941a, 0x941a, 0x94ae, 0x94ae, 0x941a,
4251 0x94ae, 0x94ae, 0x941a, 0x941a, 0x941a, 0x941a, 0x941a, 0x941c,
4252 0x94ae, 0x94ae, 0x941a, 0x941a, 0x94ae, 0x94ae, 0x941a, 0x941a,
4253 0x941a, 0x941a, 0x1078, 0x1328, 0x1078, 0x6010, 0x6003, 0x0002,
4254 0x1078, 0x6109, 0x0078, 0x94b4, 0x0f7e, 0x2079, 0xa351, 0x7804,
4255 0x0f7f, 0xd0ac, 0x00c0, 0x94ae, 0x2001, 0x0000, 0x1078, 0x442b,
4256 0x6018, 0xa080, 0x0004, 0x2004, 0xa086, 0x00ff, 0x0040, 0x94ae,
4257 0x0c7e, 0x6018, 0x2060, 0x6000, 0xd0f4, 0x00c0, 0x9448, 0x6010,
4258 0xa005, 0x0040, 0x9448, 0x0c7f, 0x1078, 0x35f7, 0x0078, 0x94ae,
4259 0x0c7f, 0x2001, 0xa300, 0x2004, 0xa086, 0x0002, 0x00c0, 0x9457,
4260 0x0f7e, 0x2079, 0xa300, 0x788c, 0x8000, 0x788e, 0x0f7f, 0x2001,
4261 0x0002, 0x1078, 0x443f, 0x1078, 0x6010, 0x601f, 0x0001, 0x6003,
4262 0x0001, 0x6007, 0x0002, 0x1078, 0x5c45, 0x1078, 0x6109, 0x0c7e,
4263 0x6118, 0x2160, 0x2009, 0x0001, 0x1078, 0x58e1, 0x0c7f, 0x0078,
4264 0x94b4, 0x6618, 0x0d7e, 0x2668, 0x6e04, 0x0d7f, 0xa6b4, 0xff00,
4265 0x8637, 0xa686, 0x0006, 0x0040, 0x94ae, 0xa686, 0x0004, 0x0040,
4266 0x94ae, 0x2001, 0x0004, 0x0078, 0x94ac, 0x2001, 0xa300, 0x2004,
4267 0xa086, 0x0003, 0x00c0, 0x948e, 0x1078, 0x35f7, 0x2001, 0x0006,
4268 0x1078, 0x94b5, 0x6618, 0x0d7e, 0x2668, 0x6e04, 0x0d7f, 0xa6b4,
4269 0xff00, 0x8637, 0xa686, 0x0006, 0x0040, 0x94ae, 0x2001, 0x0006,
4270 0x0078, 0x94ac, 0x2001, 0x0004, 0x0078, 0x94ac, 0x2001, 0x0006,
4271 0x1078, 0x94b5, 0x0078, 0x94ae, 0x1078, 0x4472, 0x1078, 0x6010,
4272 0x1078, 0x753d, 0x1078, 0x6109, 0x007c, 0x017e, 0x0d7e, 0x6118,
4273 0x2168, 0x6900, 0xd184, 0x0040, 0x94d0, 0x6104, 0xa18e, 0x000a,
4274 0x00c0, 0x94c8, 0x699c, 0xd1a4, 0x00c0, 0x94c8, 0x2001, 0x0007,
4275 0x1078, 0x443f, 0x2001, 0x0000, 0x1078, 0x442b, 0x1078, 0x2839,
4276 0x0d7f, 0x017f, 0x007c, 0x0d7e, 0x6618, 0x2668, 0x6804, 0xa084,
4277 0xff00, 0x8007, 0x0d7f, 0xa0b2, 0x000c, 0x10c8, 0x1328, 0xa1b6,
4278 0x0015, 0x00c0, 0x94e7, 0x1079, 0x94ee, 0x0078, 0x94ed, 0xa1b6,
4279 0x0016, 0x10c0, 0x1328, 0x1079, 0x94fa, 0x007c, 0x7ad0, 0x7ad0,
4280 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0, 0x9547, 0x9506, 0x7ad0, 0x7ad0,
4281 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0,
4282 0x9547, 0x954f, 0x7ad0, 0x7ad0, 0x7ad0, 0x7ad0, 0x0f7e, 0x2079,
4283 0xa351, 0x7804, 0xd0ac, 0x00c0, 0x952d, 0x6018, 0xa07d, 0x0040,
4284 0x952d, 0x7800, 0xd0f4, 0x00c0, 0x9519, 0x7810, 0xa005, 0x00c0,
4285 0x952d, 0x2001, 0x0000, 0x1078, 0x442b, 0x2001, 0x0002, 0x1078,
4286 0x443f, 0x601f, 0x0001, 0x6003, 0x0001, 0x6007, 0x0002, 0x1078,
4287 0x5c45, 0x1078, 0x6109, 0x0078, 0x9545, 0x2011, 0xa883, 0x2204,
4288 0x8211, 0x220c, 0x1078, 0x24e3, 0x00c0, 0x9545, 0x0c7e, 0x1078,
4289 0x4501, 0x0040, 0x9540, 0x0c7f, 0x1078, 0x753d, 0x0078, 0x9545,
4290 0x1078, 0x4235, 0x0c7f, 0x1078, 0x753d, 0x0f7f, 0x007c, 0x6604,
4291 0xa6b6, 0x001e, 0x00c0, 0x954e, 0x1078, 0x753d, 0x007c, 0x1078,
4292 0x7d0a, 0x00c0, 0x955b, 0x6003, 0x0001, 0x6007, 0x0001, 0x1078,
4293 0x5c45, 0x0078, 0x955d, 0x1078, 0x753d, 0x007c, 0x6004, 0xa08a,
4294 0x0044, 0x10c8, 0x1328, 0x1078, 0x6010, 0x1078, 0x8c01, 0x1078,
4295 0x6109, 0x007c, 0xa182, 0x0040, 0x0079, 0x956e, 0x9581, 0x9581,
4296 0x9581, 0x9581, 0x9583, 0x9581, 0x9581, 0x9581, 0x9581, 0x9581,
4297 0x9581, 0x9581, 0x9581, 0x9581, 0x9581, 0x9581, 0x9581, 0x9581,
4298 0x9581, 0x1078, 0x1328, 0x0d7e, 0x0e7e, 0x0f7e, 0x157e, 0x047e,
4299 0x027e, 0x6218, 0xa280, 0x002b, 0x2004, 0xa005, 0x0040, 0x9594,
4300 0x2021, 0x0000, 0x1078, 0xa111, 0x6106, 0x2071, 0xa880, 0x7444,
4301 0xa4a4, 0xff00, 0x0040, 0x95eb, 0xa486, 0x2000, 0x00c0, 0x95a6,
4302 0x2009, 0x0001, 0x2011, 0x0200, 0x1078, 0x5a6d, 0x1078, 0x1381,
4303 0x1040, 0x1328, 0x6003, 0x0007, 0x2d00, 0x6837, 0x010d, 0x6803,
4304 0x0000, 0x683b, 0x0000, 0x6c5a, 0x2c00, 0x685e, 0x6008, 0x68b2,
4305 0x6018, 0x2078, 0x78a0, 0x8007, 0x7130, 0x694a, 0x017e, 0xa084,
4306 0xff00, 0x6846, 0x684f, 0x0000, 0x6857, 0x0036, 0x1078, 0x4982,
4307 0x017f, 0xa486, 0x2000, 0x00c0, 0x95d3, 0x2019, 0x0017, 0x1078,
4308 0x9e3b, 0x0078, 0x9645, 0xa486, 0x0400, 0x00c0, 0x95dd, 0x2019,
4309 0x0002, 0x1078, 0x9dec, 0x0078, 0x9645, 0xa486, 0x0200, 0x00c0,
4310 0x95e3, 0x1078, 0x9dd1, 0xa486, 0x1000, 0x00c0, 0x95e9, 0x1078,
4311 0x9e20, 0x0078, 0x9645, 0x2069, 0xa62d, 0x6a00, 0xd284, 0x0040,
4312 0x969b, 0xa284, 0x0300, 0x00c0, 0x9693, 0x6804, 0xa005, 0x0040,
4313 0x9683, 0x2d78, 0x6003, 0x0007, 0x1078, 0x1366, 0x0040, 0x964c,
4314 0x7800, 0xd08c, 0x00c0, 0x9607, 0x7804, 0x8001, 0x7806, 0x6013,
4315 0x0000, 0x6803, 0x0000, 0x6837, 0x0116, 0x683b, 0x0000, 0x6008,
4316 0x68b2, 0x2c00, 0x684a, 0x6018, 0x2078, 0x78a0, 0x8007, 0x7130,
4317 0x6986, 0x6846, 0x6853, 0x003d, 0x7244, 0xa294, 0x0003, 0xa286,
4318 0x0002, 0x00c0, 0x9627, 0x684f, 0x0040, 0x0078, 0x9631, 0xa286,
4319 0x0001, 0x00c0, 0x962f, 0x684f, 0x0080, 0x0078, 0x9631, 0x684f,
4320 0x0000, 0x20a9, 0x000a, 0x2001, 0xa890, 0xad90, 0x0015, 0x200c,
4321 0x810f, 0x2112, 0x8000, 0x8210, 0x00f0, 0x9637, 0x200c, 0x6982,
4322 0x8000, 0x200c, 0x697e, 0x1078, 0x4982, 0x027f, 0x047f, 0x157f,
4323 0x0f7f, 0x0e7f, 0x0d7f, 0x007c, 0x6013, 0x0100, 0x6003, 0x0001,
4324 0x6007, 0x0041, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0078, 0x9645,
4325 0x2069, 0xa892, 0x2d04, 0xa084, 0xff00, 0xa086, 0x1200, 0x00c0,
4326 0x9677, 0x2069, 0xa880, 0x686c, 0xa084, 0x00ff, 0x017e, 0x6110,
4327 0xa18c, 0x0700, 0xa10d, 0x6112, 0x017f, 0x6003, 0x0001, 0x6007,
4328 0x0043, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0078, 0x9645, 0x6013,
4329 0x0200, 0x6003, 0x0001, 0x6007, 0x0041, 0x1078, 0x5bf8, 0x1078,
4330 0x6109, 0x0078, 0x9645, 0x6013, 0x0300, 0x0078, 0x9689, 0x6013,
4331 0x0100, 0x6003, 0x0001, 0x6007, 0x0041, 0x1078, 0x5bf8, 0x1078,
4332 0x6109, 0x0078, 0x9645, 0x6013, 0x0500, 0x0078, 0x9689, 0x6013,
4333 0x0600, 0x0078, 0x9658, 0x6013, 0x0200, 0x0078, 0x9658, 0xa186,
4334 0x0013, 0x00c0, 0x96b1, 0x6004, 0xa08a, 0x0040, 0x1048, 0x1328,
4335 0xa08a, 0x0053, 0x10c8, 0x1328, 0xa082, 0x0040, 0x2008, 0x0079,
4336 0x9725, 0xa186, 0x0051, 0x0040, 0x96be, 0xa186, 0x0047, 0x00c0,
4337 0x96d7, 0x6004, 0xa086, 0x0041, 0x0040, 0x96e5, 0x2001, 0x0109,
4338 0x2004, 0xd084, 0x0040, 0x96e5, 0x127e, 0x2091, 0x2200, 0x007e,
4339 0x017e, 0x027e, 0x1078, 0x5ad2, 0x027f, 0x017f, 0x007f, 0x127f,
4340 0x6000, 0xa086, 0x0002, 0x00c0, 0x96e5, 0x0078, 0x976a, 0xa186,
4341 0x0027, 0x0040, 0x96df, 0xa186, 0x0014, 0x10c0, 0x1328, 0x6004,
4342 0xa082, 0x0040, 0x2008, 0x0079, 0x96e8, 0x1078, 0x7583, 0x007c,
4343 0x96fb, 0x96fd, 0x96fd, 0x96fb, 0x96fb, 0x96fb, 0x96fb, 0x96fb,
4344 0x96fb, 0x96fb, 0x96fb, 0x96fb, 0x96fb, 0x96fb, 0x96fb, 0x96fb,
4345 0x96fb, 0x96fb, 0x96fb, 0x1078, 0x1328, 0x1078, 0x6010, 0x1078,
4346 0x6109, 0x037e, 0x0d7e, 0x6010, 0xa06d, 0x0040, 0x9722, 0xad84,
4347 0xf000, 0x0040, 0x9722, 0x6003, 0x0002, 0x6018, 0x2004, 0xd0bc,
4348 0x00c0, 0x9722, 0x2019, 0x0004, 0x1078, 0x9e70, 0x6013, 0x0000,
4349 0x6014, 0xa005, 0x00c0, 0x9720, 0x2001, 0xa5a1, 0x2004, 0x6016,
4350 0x6003, 0x0007, 0x0d7f, 0x037f, 0x007c, 0x9738, 0x9757, 0x9741,
4351 0x9764, 0x9738, 0x9738, 0x9738, 0x9738, 0x9738, 0x9738, 0x9738,
4352 0x9738, 0x9738, 0x9738, 0x9738, 0x9738, 0x9738, 0x9738, 0x9738,
4353 0x1078, 0x1328, 0x6010, 0xa088, 0x0013, 0x2104, 0xa085, 0x0400,
4354 0x200a, 0x1078, 0x6010, 0x6010, 0xa080, 0x0013, 0x2004, 0xd0b4,
4355 0x0040, 0x9752, 0x6003, 0x0007, 0x2009, 0x0043, 0x1078, 0x756c,
4356 0x0078, 0x9754, 0x6003, 0x0002, 0x1078, 0x6109, 0x007c, 0x1078,
4357 0x6010, 0x1078, 0xa0c6, 0x00c0, 0x9761, 0x1078, 0x5a41, 0x1078,
4358 0x753d, 0x1078, 0x6109, 0x007c, 0x1078, 0x6010, 0x2009, 0x0041,
4359 0x0078, 0x98c1, 0xa182, 0x0040, 0x0079, 0x976e, 0x9781, 0x9783,
4360 0x9781, 0x9781, 0x9781, 0x9781, 0x9781, 0x9784, 0x9781, 0x9781,
4361 0x9781, 0x9781, 0x9781, 0x9781, 0x9781, 0x9781, 0x9781, 0x978f,
4362 0x9781, 0x1078, 0x1328, 0x007c, 0x6003, 0x0004, 0x6110, 0x20e1,
4363 0x0005, 0x3d18, 0x3e20, 0x2c10, 0x1078, 0x15ec, 0x007c, 0x0d7e,
4364 0x1078, 0x5a41, 0x0d7f, 0x1078, 0xa134, 0x1078, 0x753d, 0x007c,
4365 0xa182, 0x0040, 0x0079, 0x979c, 0x97af, 0x97af, 0x97af, 0x97af,
4366 0x97af, 0x97af, 0x97af, 0x97b1, 0x97af, 0x97b4, 0x97df, 0x97af,
4367 0x97af, 0x97af, 0x97af, 0x97df, 0x97af, 0x97af, 0x97af, 0x1078,
4368 0x1328, 0x1078, 0x7583, 0x007c, 0x1078, 0x60b8, 0x1078, 0x61d3,
4369 0x6010, 0x0d7e, 0x2068, 0x684c, 0xd0fc, 0x0040, 0x97ca, 0xa08c,
4370 0x0003, 0xa18e, 0x0002, 0x0040, 0x97d2, 0x2009, 0x0041, 0x0d7f,
4371 0x0078, 0x98c1, 0x6003, 0x0007, 0x6017, 0x0000, 0x1078, 0x5a41,
4372 0x0d7f, 0x007c, 0x1078, 0xa0c6, 0x0040, 0x97d8, 0x0d7f, 0x007c,
4373 0x1078, 0x5a41, 0x1078, 0x753d, 0x0d7f, 0x0078, 0x97d1, 0x037e,
4374 0x1078, 0x60b8, 0x1078, 0x61d3, 0x6010, 0x0d7e, 0x2068, 0x6018,
4375 0x2004, 0xd0bc, 0x0040, 0x97ff, 0x684c, 0xa084, 0x0003, 0xa086,
4376 0x0002, 0x0040, 0x97fb, 0x687c, 0x632c, 0xa31a, 0x632e, 0x6880,
4377 0x6328, 0xa31b, 0x632a, 0x6003, 0x0002, 0x0078, 0x9810, 0x2019,
4378 0x0004, 0x1078, 0x9e70, 0x6014, 0xa005, 0x00c0, 0x980c, 0x2001,
4379 0xa5a1, 0x2004, 0x8003, 0x6016, 0x6013, 0x0000, 0x6003, 0x0007,
4380 0x0d7f, 0x037f, 0x007c, 0xa186, 0x0013, 0x00c0, 0x9821, 0x6004,
4381 0xa086, 0x0042, 0x10c0, 0x1328, 0x1078, 0x6010, 0x1078, 0x6109,
4382 0x007c, 0xa186, 0x0027, 0x0040, 0x9829, 0xa186, 0x0014, 0x00c0,
4383 0x9839, 0x6004, 0xa086, 0x0042, 0x10c0, 0x1328, 0x2001, 0x0007,
4384 0x1078, 0x4472, 0x1078, 0x6010, 0x1078, 0x8c01, 0x1078, 0x6109,
4385 0x007c, 0xa182, 0x0040, 0x0079, 0x983d, 0x9850, 0x9850, 0x9850,
4386 0x9850, 0x9850, 0x9850, 0x9850, 0x9852, 0x985e, 0x9850, 0x9850,
4387 0x9850, 0x9850, 0x9850, 0x9850, 0x9850, 0x9850, 0x9850, 0x9850,
4388 0x1078, 0x1328, 0x037e, 0x047e, 0x20e1, 0x0005, 0x3d18, 0x3e20,
4389 0x2c10, 0x1078, 0x15ec, 0x047f, 0x037f, 0x007c, 0x6010, 0x0d7e,
4390 0x2068, 0x6810, 0x6a14, 0x6118, 0x210c, 0xd1bc, 0x0040, 0x987d,
4391 0x6124, 0xd1f4, 0x00c0, 0x987d, 0x007e, 0x047e, 0x057e, 0x6c7c,
4392 0xa422, 0x6d80, 0x2200, 0xa52b, 0x602c, 0xa420, 0x642e, 0x6028,
4393 0xa529, 0x652a, 0x057f, 0x047f, 0x007f, 0xa20d, 0x00c0, 0x9891,
4394 0x684c, 0xd0fc, 0x0040, 0x9889, 0x2009, 0x0041, 0x0d7f, 0x0078,
4395 0x98c1, 0x6003, 0x0007, 0x6017, 0x0000, 0x1078, 0x5a41, 0x0d7f,
4396 0x007c, 0x007e, 0x0f7e, 0x2c78, 0x1078, 0x4893, 0x0f7f, 0x007f,
4397 0x0040, 0x989e, 0x6003, 0x0002, 0x0d7f, 0x007c, 0x2009, 0xa30d,
4398 0x210c, 0xd19c, 0x0040, 0x98a8, 0x6003, 0x0007, 0x0078, 0x98aa,
4399 0x6003, 0x0006, 0x1078, 0x98b0, 0x1078, 0x5a43, 0x0d7f, 0x007c,
4400 0xd2fc, 0x0040, 0x98bc, 0x8002, 0x8000, 0x8212, 0xa291, 0x0000,
4401 0x2009, 0x0009, 0x0078, 0x98be, 0x2009, 0x0015, 0x6a6a, 0x6866,
4402 0x007c, 0xa182, 0x0040, 0x0048, 0x98c7, 0x0079, 0x98d4, 0xa186,
4403 0x0013, 0x0040, 0x98cf, 0xa186, 0x0014, 0x10c0, 0x1328, 0x6024,
4404 0xd0dc, 0x1040, 0x1328, 0x007c, 0x98e7, 0x98ee, 0x98fa, 0x9906,
4405 0x98e7, 0x98e7, 0x98e7, 0x9915, 0x98e7, 0x98e9, 0x98e9, 0x98e7,
4406 0x98e7, 0x98e7, 0x98e7, 0x98e7, 0x98e7, 0x98e7, 0x98e7, 0x1078,
4407 0x1328, 0x6024, 0xd0dc, 0x1040, 0x1328, 0x007c, 0x6003, 0x0001,
4408 0x6106, 0x1078, 0x5bf8, 0x127e, 0x2091, 0x8000, 0x1078, 0x6109,
4409 0x127f, 0x007c, 0x6003, 0x0001, 0x6106, 0x1078, 0x5bf8, 0x127e,
4410 0x2091, 0x8000, 0x1078, 0x6109, 0x127f, 0x007c, 0x6003, 0x0003,
4411 0x6106, 0x2c10, 0x1078, 0x1cab, 0x127e, 0x2091, 0x8000, 0x1078,
4412 0x5c64, 0x1078, 0x61d3, 0x127f, 0x007c, 0xa016, 0x1078, 0x15ec,
4413 0x007c, 0x127e, 0x2091, 0x8000, 0x037e, 0x0d7e, 0xa182, 0x0040,
4414 0x1079, 0x9926, 0x0d7f, 0x037f, 0x127f, 0x007c, 0x9936, 0x9938,
4415 0x994d, 0x996c, 0x9936, 0x9936, 0x9936, 0x9984, 0x9936, 0x9936,
4416 0x9936, 0x9936, 0x9936, 0x9936, 0x9936, 0x9936, 0x1078, 0x1328,
4417 0x6010, 0x2068, 0x684c, 0xd0fc, 0x0040, 0x9962, 0xa09c, 0x0003,
4418 0xa39e, 0x0003, 0x0040, 0x9962, 0x6003, 0x0001, 0x6106, 0x1078,
4419 0x5bf8, 0x1078, 0x6109, 0x0078, 0x9987, 0x6010, 0x2068, 0x684c,
4420 0xd0fc, 0x0040, 0x9962, 0xa09c, 0x0003, 0xa39e, 0x0003, 0x0040,
4421 0x9962, 0x6003, 0x0001, 0x6106, 0x1078, 0x5bf8, 0x1078, 0x6109,
4422 0x0078, 0x9987, 0x6013, 0x0000, 0x6017, 0x0000, 0x2019, 0x0004,
4423 0x1078, 0x9e70, 0x0078, 0x9987, 0x6010, 0x2068, 0x684c, 0xd0fc,
4424 0x0040, 0x9962, 0xa09c, 0x0003, 0xa39e, 0x0003, 0x0040, 0x9962,
4425 0x6003, 0x0003, 0x6106, 0x2c10, 0x1078, 0x1cab, 0x1078, 0x5c64,
4426 0x1078, 0x61d3, 0x0078, 0x9987, 0xa016, 0x1078, 0x15ec, 0x007c,
4427 0x1078, 0x6010, 0x6110, 0x81ff, 0x0040, 0x9999, 0x0d7e, 0x2168,
4428 0x1078, 0xa181, 0x037e, 0x2019, 0x0029, 0x1078, 0x9e70, 0x037f,
4429 0x0d7f, 0x1078, 0x8c01, 0x1078, 0x6109, 0x007c, 0x1078, 0x60b8,
4430 0x6110, 0x81ff, 0x0040, 0x99af, 0x0d7e, 0x2168, 0x1078, 0xa181,
4431 0x037e, 0x2019, 0x0029, 0x1078, 0x9e70, 0x037f, 0x0d7f, 0x1078,
4432 0x8c01, 0x1078, 0x61d3, 0x007c, 0xa182, 0x0085, 0x0079, 0x99b8,
4433 0x99c1, 0x99bf, 0x99bf, 0x99cd, 0x99bf, 0x99bf, 0x99bf, 0x1078,
4434 0x1328, 0x6003, 0x000b, 0x6106, 0x1078, 0x5bf8, 0x127e, 0x2091,
4435 0x8000, 0x1078, 0x6109, 0x127f, 0x007c, 0x027e, 0x0e7e, 0x1078,
4436 0xa0bf, 0x0040, 0x99d7, 0x1078, 0x753d, 0x0078, 0x99f3, 0x2071,
4437 0xa880, 0x7224, 0x6212, 0x7220, 0x1078, 0x9d10, 0x0040, 0x99e4,
4438 0x6007, 0x0086, 0x0078, 0x99ed, 0x6007, 0x0087, 0x7224, 0xa296,
4439 0xffff, 0x00c0, 0x99ed, 0x6007, 0x0086, 0x6003, 0x0001, 0x1078,
4440 0x5bf8, 0x1078, 0x6109, 0x0e7f, 0x027f, 0x007c, 0xa186, 0x0013,
4441 0x00c0, 0x9a07, 0x6004, 0xa08a, 0x0085, 0x1048, 0x1328, 0xa08a,
4442 0x008c, 0x10c8, 0x1328, 0xa082, 0x0085, 0x0079, 0x9a1e, 0xa186,
4443 0x0027, 0x0040, 0x9a13, 0xa186, 0x0014, 0x0040, 0x9a13, 0x1078,
4444 0x7583, 0x0078, 0x9a1d, 0x2001, 0x0007, 0x1078, 0x4472, 0x1078,
4445 0x6010, 0x1078, 0x8c01, 0x1078, 0x6109, 0x007c, 0x9a25, 0x9a27,
4446 0x9a27, 0x9a25, 0x9a25, 0x9a25, 0x9a25, 0x1078, 0x1328, 0x1078,
4447 0x6010, 0x1078, 0x8c01, 0x1078, 0x6109, 0x007c, 0xa182, 0x0085,
4448 0x1048, 0x1328, 0xa182, 0x008c, 0x10c8, 0x1328, 0xa182, 0x0085,
4449 0x0079, 0x9a3a, 0x9a41, 0x9a41, 0x9a41, 0x9a43, 0x9a41, 0x9a41,
4450 0x9a41, 0x1078, 0x1328, 0x007c, 0xa186, 0x0013, 0x0040, 0x9a54,
4451 0xa186, 0x0014, 0x0040, 0x9a54, 0xa186, 0x0027, 0x0040, 0x9a54,
4452 0x1078, 0x7583, 0x0078, 0x9a5a, 0x1078, 0x6010, 0x1078, 0x8c01,
4453 0x1078, 0x6109, 0x007c, 0x037e, 0x1078, 0xa134, 0x603f, 0x0000,
4454 0x2019, 0x000b, 0x1078, 0x9a6a, 0x601f, 0x0006, 0x6003, 0x0007,
4455 0x037f, 0x007c, 0x127e, 0x037e, 0x2091, 0x8000, 0x087e, 0x2c40,
4456 0x097e, 0x2049, 0x0000, 0x1078, 0x7058, 0x097f, 0x087f, 0x00c0,
4457 0x9aa5, 0x077e, 0x2c38, 0x1078, 0x7105, 0x077f, 0x00c0, 0x9aa5,
4458 0x6000, 0xa086, 0x0000, 0x0040, 0x9aa5, 0x601c, 0xa086, 0x0007,
4459 0x0040, 0x9aa5, 0x0d7e, 0x6000, 0xa086, 0x0004, 0x00c0, 0x9a96,
4460 0x1078, 0xa134, 0x601f, 0x0007, 0x1078, 0x1749, 0x6010, 0x2068,
4461 0x1078, 0x8a44, 0x0040, 0x9a9e, 0x1078, 0x9e70, 0x0d7f, 0x6013,
4462 0x0000, 0x1078, 0xa134, 0x601f, 0x0007, 0x037f, 0x127f, 0x007c,
4463 0x0f7e, 0x0c7e, 0x037e, 0x157e, 0x2079, 0xa880, 0x7938, 0x783c,
4464 0x1078, 0x24e3, 0x00c0, 0x9af6, 0x017e, 0x0c7e, 0x1078, 0x4501,
4465 0x00c0, 0x9af6, 0x2011, 0xa890, 0xac98, 0x000a, 0x20a9, 0x0004,
4466 0x1078, 0x7e55, 0x00c0, 0x9af6, 0x017f, 0x027f, 0x027e, 0x017e,
4467 0x2019, 0x0029, 0x1078, 0x71e0, 0x1078, 0x5d53, 0x077e, 0x2039,
4468 0x0000, 0x1078, 0x5c78, 0x077f, 0x017f, 0x077e, 0x2039, 0x0000,
4469 0x1078, 0x9c38, 0x077f, 0x1078, 0x471b, 0x027e, 0x6204, 0xa294,
4470 0xff00, 0x8217, 0xa286, 0x0006, 0x0040, 0x9aea, 0xa286, 0x0004,
4471 0x00c0, 0x9aed, 0x62a0, 0x1078, 0x28d5, 0x027f, 0x017f, 0x1078,
4472 0x4235, 0x6612, 0x6516, 0xa006, 0x0078, 0x9af8, 0x0c7f, 0x017f,
4473 0x157f, 0x037f, 0x0c7f, 0x0f7f, 0x007c, 0x0c7e, 0x0d7e, 0x0e7e,
4474 0x017e, 0x2009, 0xa31f, 0x2104, 0xa086, 0x0074, 0x00c0, 0x9b60,
4475 0x2069, 0xa88e, 0x690c, 0xa182, 0x0100, 0x0048, 0x9b50, 0x6908,
4476 0xa184, 0x8000, 0x0040, 0x9b5c, 0x6018, 0x2070, 0x7010, 0xa084,
4477 0x00ff, 0x0040, 0x9b1f, 0x7000, 0xd0f4, 0x0040, 0x9b23, 0xa184,
4478 0x0800, 0x0040, 0x9b5c, 0x6910, 0xa18a, 0x0001, 0x0048, 0x9b54,
4479 0x6914, 0x2069, 0xa8ae, 0x6904, 0x81ff, 0x00c0, 0x9b48, 0x690c,
4480 0xa182, 0x0100, 0x0048, 0x9b50, 0x6908, 0x81ff, 0x00c0, 0x9b4c,
4481 0x6910, 0xa18a, 0x0001, 0x0048, 0x9b54, 0x6918, 0xa18a, 0x0001,
4482 0x0048, 0x9b5c, 0x0078, 0x9b66, 0x6013, 0x0100, 0x0078, 0x9b62,
4483 0x6013, 0x0300, 0x0078, 0x9b62, 0x6013, 0x0500, 0x0078, 0x9b62,
4484 0x6013, 0x0700, 0x0078, 0x9b62, 0x6013, 0x0900, 0x0078, 0x9b62,
4485 0x6013, 0x0b00, 0x0078, 0x9b62, 0x6013, 0x0f00, 0x0078, 0x9b62,
4486 0x6013, 0x2d00, 0xa085, 0x0001, 0x0078, 0x9b67, 0xa006, 0x017f,
4487 0x0e7f, 0x0d7f, 0x0c7f, 0x007c, 0x0c7e, 0x0d7e, 0x027e, 0x037e,
4488 0x157e, 0x6218, 0x2268, 0x6b04, 0xa394, 0x00ff, 0xa286, 0x0006,
4489 0x0040, 0x9b90, 0xa286, 0x0004, 0x0040, 0x9b90, 0xa394, 0xff00,
4490 0x8217, 0xa286, 0x0006, 0x0040, 0x9b90, 0xa286, 0x0004, 0x0040,
4491 0x9b90, 0x0c7e, 0x2d60, 0x1078, 0x4513, 0x0c7f, 0x0078, 0x9bcb,
4492 0x2011, 0xa896, 0xad98, 0x000a, 0x20a9, 0x0004, 0x1078, 0x7e55,
4493 0x00c0, 0x9bcc, 0x2011, 0xa89a, 0xad98, 0x0006, 0x20a9, 0x0004,
4494 0x1078, 0x7e55, 0x00c0, 0x9bcc, 0x047e, 0x017e, 0x6aa0, 0xa294,
4495 0x00ff, 0x8227, 0xa006, 0x2009, 0xa352, 0x210c, 0xd1a4, 0x0040,
4496 0x9bb8, 0x2009, 0x0029, 0x1078, 0x9ec0, 0x6800, 0xc0e5, 0x6802,
4497 0x2019, 0x0029, 0x1078, 0x5d53, 0x077e, 0x2039, 0x0000, 0x1078,
4498 0x5c78, 0x2c08, 0x1078, 0x9c38, 0x077f, 0x2001, 0x0007, 0x1078,
4499 0x4472, 0x017f, 0x047f, 0xa006, 0x157f, 0x037f, 0x027f, 0x0d7f,
4500 0x0c7f, 0x007c, 0x0d7e, 0x2069, 0xa88e, 0x6800, 0xa086, 0x0800,
4501 0x0040, 0x9bde, 0x6013, 0x0000, 0x0078, 0x9bdf, 0xa006, 0x0d7f,
4502 0x007c, 0x0c7e, 0x0f7e, 0x017e, 0x027e, 0x037e, 0x157e, 0x2079,
4503 0xa88c, 0x7930, 0x7834, 0x1078, 0x24e3, 0x00c0, 0x9c05, 0x1078,
4504 0x4501, 0x00c0, 0x9c05, 0x2011, 0xa890, 0xac98, 0x000a, 0x20a9,
4505 0x0004, 0x1078, 0x7e55, 0x00c0, 0x9c05, 0x2011, 0xa894, 0xac98,
4506 0x0006, 0x20a9, 0x0004, 0x1078, 0x7e55, 0x157f, 0x037f, 0x027f,
4507 0x017f, 0x0f7f, 0x0c7f, 0x007c, 0x0c7e, 0x007e, 0x017e, 0x027e,
4508 0x037e, 0x157e, 0x2011, 0xa883, 0x2204, 0x8211, 0x220c, 0x1078,
4509 0x24e3, 0x00c0, 0x9c31, 0x1078, 0x4501, 0x00c0, 0x9c31, 0x2011,
4510 0xa896, 0xac98, 0x000a, 0x20a9, 0x0004, 0x1078, 0x7e55, 0x00c0,
4511 0x9c31, 0x2011, 0xa89a, 0xac98, 0x0006, 0x20a9, 0x0004, 0x1078,
4512 0x7e55, 0x157f, 0x037f, 0x027f, 0x017f, 0x007f, 0x0c7f, 0x007c,
4513 0x0e7e, 0x0c7e, 0x087e, 0x077e, 0x067e, 0x057e, 0x047e, 0x027e,
4514 0x127e, 0x2091, 0x8000, 0x2740, 0x2029, 0xa5b4, 0x252c, 0x2021,
4515 0xa5ba, 0x2424, 0x2061, 0xaa00, 0x2071, 0xa300, 0x7644, 0x7060,
4516 0x81ff, 0x0040, 0x9c59, 0x8001, 0xa602, 0x00c8, 0x9cc3, 0x0078,
4517 0x9c5c, 0xa606, 0x0040, 0x9cc3, 0x2100, 0xac06, 0x0040, 0x9cb9,
4518 0x1078, 0x9ee5, 0x0040, 0x9cb9, 0x671c, 0xa786, 0x0001, 0x0040,
4519 0x9cde, 0xa786, 0x0004, 0x0040, 0x9cde, 0xa786, 0x0007, 0x0040,
4520 0x9cb9, 0x2500, 0xac06, 0x0040, 0x9cb9, 0x2400, 0xac06, 0x0040,
4521 0x9cb9, 0x1078, 0x9ef9, 0x00c0, 0x9cb9, 0x88ff, 0x0040, 0x9c84,
4522 0x6020, 0xa906, 0x00c0, 0x9cb9, 0x0d7e, 0x6000, 0xa086, 0x0004,
4523 0x00c0, 0x9c8e, 0x017e, 0x1078, 0x1749, 0x017f, 0xa786, 0x0008,
4524 0x00c0, 0x9c9d, 0x1078, 0x8c3b, 0x00c0, 0x9c9d, 0x1078, 0x7a05,
4525 0x0d7f, 0x1078, 0x8c01, 0x0078, 0x9cb9, 0x6010, 0x2068, 0x1078,
4526 0x8a44, 0x0040, 0x9cb6, 0xa786, 0x0003, 0x00c0, 0x9ccd, 0x6837,
4527 0x0103, 0x6b4a, 0x6847, 0x0000, 0x1078, 0xa181, 0x017e, 0x1078,
4528 0x8cb8, 0x1078, 0x4982, 0x017f, 0x1078, 0x8bf4, 0x0d7f, 0x1078,
4529 0x8c01, 0xace0, 0x0010, 0x2001, 0xa315, 0x2004, 0xac02, 0x00c8,
4530 0x9cc3, 0x0078, 0x9c4c, 0x127f, 0x027f, 0x047f, 0x057f, 0x067f,
4531 0x077f, 0x087f, 0x0c7f, 0x0e7f, 0x007c, 0xa786, 0x0006, 0x00c0,
4532 0x9ca7, 0xa386, 0x0005, 0x0040, 0x9cdb, 0x1078, 0xa181, 0x1078,
4533 0x9e70, 0x0078, 0x9cb6, 0x0d7f, 0x0078, 0x9cb9, 0x1078, 0x9ef9,
4534 0x00c0, 0x9cb9, 0x81ff, 0x0040, 0x9cb9, 0xa180, 0x0001, 0x2004,
4535 0xa086, 0x0018, 0x0040, 0x9cf3, 0xa180, 0x0001, 0x2004, 0xa086,
4536 0x002d, 0x00c0, 0x9cb9, 0x6000, 0xa086, 0x0002, 0x00c0, 0x9cb9,
4537 0x1078, 0x8c27, 0x0040, 0x9d04, 0x1078, 0x8c3b, 0x00c0, 0x9cb9,
4538 0x1078, 0x7a05, 0x0078, 0x9d0c, 0x1078, 0x2839, 0x1078, 0x8c3b,
4539 0x00c0, 0x9d0c, 0x1078, 0x7a05, 0x1078, 0x8c01, 0x0078, 0x9cb9,
4540 0x0c7e, 0x0e7e, 0x017e, 0x2c08, 0x2170, 0x1078, 0x9e8c, 0x017f,
4541 0x0040, 0x9d1f, 0x601c, 0xa084, 0x000f, 0x1079, 0x9d22, 0x0e7f,
4542 0x0c7f, 0x007c, 0x9d2a, 0x9d2a, 0x9d2a, 0x9d2a, 0x9d2a, 0x9d2a,
4543 0x9d2c, 0x9d2a, 0xa006, 0x007c, 0x047e, 0x017e, 0x7018, 0xa080,
4544 0x0028, 0x2024, 0xa4a4, 0x00ff, 0x8427, 0x2c00, 0x2009, 0x0020,
4545 0x1078, 0x9ec0, 0x017f, 0x047f, 0x037e, 0x2019, 0x0002, 0x1078,
4546 0x9a6a, 0x037f, 0xa085, 0x0001, 0x007c, 0x2001, 0x0001, 0x1078,
4547 0x442b, 0x157e, 0x017e, 0x027e, 0x037e, 0x20a9, 0x0004, 0x2019,
4548 0xa305, 0x2011, 0xa896, 0x1078, 0x7e55, 0x037f, 0x027f, 0x017f,
4549 0x157f, 0xa005, 0x007c, 0x0f7e, 0x0e7e, 0x0c7e, 0x087e, 0x077e,
4550 0x067e, 0x027e, 0x127e, 0x2091, 0x8000, 0x2740, 0x2061, 0xaa00,
4551 0x2079, 0x0001, 0x8fff, 0x0040, 0x9dc3, 0x2071, 0xa300, 0x7644,
4552 0x7060, 0x8001, 0xa602, 0x00c8, 0x9dc3, 0x88ff, 0x0040, 0x9d7e,
4553 0x2800, 0xac06, 0x00c0, 0x9db9, 0x2079, 0x0000, 0x1078, 0x9ee5,
4554 0x0040, 0x9db9, 0x2400, 0xac06, 0x0040, 0x9db9, 0x671c, 0xa786,
4555 0x0006, 0x00c0, 0x9db9, 0xa786, 0x0007, 0x0040, 0x9db9, 0x88ff,
4556 0x00c0, 0x9d9d, 0x6018, 0xa206, 0x00c0, 0x9db9, 0x85ff, 0x0040,
4557 0x9d9d, 0x6020, 0xa106, 0x00c0, 0x9db9, 0x0d7e, 0x6000, 0xa086,
4558 0x0004, 0x00c0, 0x9da9, 0x1078, 0xa134, 0x601f, 0x0007, 0x1078,
4559 0x1749, 0x6010, 0x2068, 0x1078, 0x8a44, 0x0040, 0x9db3, 0x047e,
4560 0x1078, 0x9e70, 0x047f, 0x0d7f, 0x1078, 0x8c01, 0x88ff, 0x00c0,
4561 0x9dcd, 0xace0, 0x0010, 0x2001, 0xa315, 0x2004, 0xac02, 0x00c8,
4562 0x9dc3, 0x0078, 0x9d6a, 0xa006, 0x127f, 0x027f, 0x067f, 0x077f,
4563 0x087f, 0x0c7f, 0x0e7f, 0x0f7f, 0x007c, 0xa8c5, 0x0001, 0x0078,
4564 0x9dc4, 0x077e, 0x057e, 0x087e, 0x2041, 0x0000, 0x2029, 0x0001,
4565 0x2c20, 0x2019, 0x0002, 0x6218, 0x097e, 0x2049, 0x0000, 0x1078,
4566 0x7058, 0x097f, 0x087f, 0x2039, 0x0000, 0x1078, 0x7105, 0x1078,
4567 0x9d5b, 0x057f, 0x077f, 0x007c, 0x027e, 0x047e, 0x057e, 0x077e,
4568 0x0c7e, 0x157e, 0x2c20, 0x2128, 0x20a9, 0x007f, 0x2009, 0x0000,
4569 0x017e, 0x037e, 0x1078, 0x4501, 0x00c0, 0x9e14, 0x2c10, 0x057e,
4570 0x087e, 0x2041, 0x0000, 0x2508, 0x2029, 0x0001, 0x097e, 0x2049,
4571 0x0000, 0x1078, 0x7058, 0x097f, 0x087f, 0x2039, 0x0000, 0x1078,
4572 0x7105, 0x1078, 0x9d5b, 0x057f, 0x037f, 0x017f, 0x8108, 0x00f0,
4573 0x9df8, 0x157f, 0x0c7f, 0x077f, 0x057f, 0x047f, 0x027f, 0x007c,
4574 0x077e, 0x057e, 0x6218, 0x087e, 0x2041, 0x0000, 0x2029, 0x0001,
4575 0x2019, 0x0048, 0x097e, 0x2049, 0x0000, 0x1078, 0x7058, 0x097f,
4576 0x087f, 0x2039, 0x0000, 0x1078, 0x7105, 0x2c20, 0x1078, 0x9d5b,
4577 0x057f, 0x077f, 0x007c, 0x027e, 0x047e, 0x057e, 0x077e, 0x0c7e,
4578 0x157e, 0x2c20, 0x20a9, 0x007f, 0x2009, 0x0000, 0x017e, 0x037e,
4579 0x1078, 0x4501, 0x00c0, 0x9e64, 0x2c10, 0x087e, 0x2041, 0x0000,
4580 0x2828, 0x047e, 0x2021, 0x0001, 0x1078, 0xa111, 0x047f, 0x097e,
4581 0x2049, 0x0000, 0x1078, 0x7058, 0x097f, 0x087f, 0x2039, 0x0000,
4582 0x1078, 0x7105, 0x1078, 0x9d5b, 0x037f, 0x017f, 0x8108, 0x00f0,
4583 0x9e46, 0x157f, 0x0c7f, 0x077f, 0x057f, 0x047f, 0x027f, 0x007c,
4584 0x017e, 0x0f7e, 0xad82, 0xca00, 0x0048, 0x9e89, 0xad82, 0xffff,
4585 0x00c8, 0x9e89, 0x6800, 0xa07d, 0x0040, 0x9e86, 0x6803, 0x0000,
4586 0x6b52, 0x1078, 0x4982, 0x2f68, 0x0078, 0x9e7a, 0x6b52, 0x1078,
4587 0x4982, 0x0f7f, 0x017f, 0x007c, 0x0e7e, 0x047e, 0x037e, 0x2061,
4588 0xaa00, 0x2071, 0xa300, 0x7444, 0x7060, 0x8001, 0xa402, 0x00c8,
4589 0x9ebb, 0x2100, 0xac06, 0x0040, 0x9ead, 0x6000, 0xa086, 0x0000,
4590 0x0040, 0x9ead, 0x6008, 0xa206, 0x00c0, 0x9ead, 0x6018, 0xa1a0,
4591 0x0006, 0x2424, 0xa406, 0x0040, 0x9eb7, 0xace0, 0x0010, 0x2001,
4592 0xa315, 0x2004, 0xac02, 0x00c8, 0x9ebb, 0x0078, 0x9e91, 0xa085,
4593 0x0001, 0x0078, 0x9ebc, 0xa006, 0x037f, 0x047f, 0x0e7f, 0x007c,
4594 0x0d7e, 0x007e, 0x1078, 0x1381, 0x007f, 0x1040, 0x1328, 0x6837,
4595 0x010d, 0x685e, 0x027e, 0x2010, 0x1078, 0x8a30, 0x2001, 0x0000,
4596 0x0040, 0x9ed6, 0x2200, 0xa080, 0x0008, 0x2004, 0x027f, 0x684a,
4597 0x6956, 0x6c46, 0x684f, 0x0000, 0xa006, 0x68b2, 0x6802, 0x683a,
4598 0x685a, 0x1078, 0x4982, 0x0d7f, 0x007c, 0x6700, 0xa786, 0x0000,
4599 0x0040, 0x9ef8, 0xa786, 0x0001, 0x0040, 0x9ef8, 0xa786, 0x000a,
4600 0x0040, 0x9ef8, 0xa786, 0x0009, 0x0040, 0x9ef8, 0xa085, 0x0001,
4601 0x007c, 0x0e7e, 0x6018, 0x2070, 0x70a0, 0xa206, 0x0e7f, 0x007c,
4602 0x017e, 0x6004, 0xa08e, 0x001e, 0x00c0, 0x9f1a, 0x8007, 0x6130,
4603 0xa18c, 0x00ff, 0xa105, 0x6032, 0x6007, 0x0085, 0x6003, 0x000b,
4604 0x601f, 0x0005, 0x2001, 0xa5a1, 0x2004, 0x6016, 0x1078, 0x5bf8,
4605 0x1078, 0x6109, 0x017f, 0x007c, 0x0005, 0x0005, 0x007c, 0x6024,
4606 0xd0e4, 0x0040, 0x9f30, 0xd0cc, 0x0040, 0x9f2a, 0x1078, 0x8cfa,
4607 0x0078, 0x9f30, 0x1078, 0xa134, 0x1078, 0x5a41, 0x1078, 0x753d,
4608 0x007c, 0xa280, 0x0007, 0x2004, 0xa084, 0x000f, 0x0079, 0x9f38,
4609 0x9f41, 0x9f41, 0x9f41, 0x9f43, 0x9f41, 0x9f43, 0x9f43, 0x9f41,
4610 0x9f43, 0xa006, 0x007c, 0xa085, 0x0001, 0x007c, 0xa280, 0x0007,
4611 0x2004, 0xa084, 0x000f, 0x0079, 0x9f4d, 0x9f56, 0x9f56, 0x9f56,
4612 0x9f56, 0x9f56, 0x9f56, 0x9f61, 0x9f56, 0x9f56, 0x6007, 0x003b,
4613 0x602b, 0x0009, 0x6013, 0x2a00, 0x6003, 0x0001, 0x1078, 0x5bf8,
4614 0x007c, 0x0c7e, 0x2260, 0x1078, 0xa134, 0x603f, 0x0000, 0x6024,
4615 0xc0f4, 0xc0cc, 0x6026, 0x0c7f, 0x0d7e, 0x2268, 0xa186, 0x0007,
4616 0x00c0, 0x9fc2, 0x6810, 0xa005, 0x0040, 0x9f7f, 0xa080, 0x0013,
4617 0x2004, 0xd0fc, 0x00c0, 0x9f7f, 0x0d7f, 0x0078, 0x9f56, 0x6007,
4618 0x003a, 0x6003, 0x0001, 0x1078, 0x5bf8, 0x1078, 0x6109, 0x0c7e,
4619 0x2d60, 0x6100, 0xa186, 0x0002, 0x00c0, 0xa050, 0x6010, 0xa005,
4620 0x00c0, 0x9f99, 0x6000, 0xa086, 0x0007, 0x10c0, 0x1328, 0x0078,
4621 0xa050, 0xa08c, 0xf000, 0x00c0, 0x9fa5, 0x0078, 0x9fa5, 0x2068,
4622 0x6800, 0xa005, 0x00c0, 0x9f9f, 0x2d00, 0xa080, 0x0013, 0x2004,
4623 0xa084, 0x0003, 0xa086, 0x0002, 0x00c0, 0x9fbe, 0x6010, 0x2068,
4624 0x684c, 0xc0dc, 0xc0f4, 0x684e, 0x6850, 0xc0f4, 0xc0fc, 0x6852,
4625 0x2009, 0x0043, 0x1078, 0x98c1, 0x0078, 0xa050, 0x2009, 0x0041,
4626 0x0078, 0xa04a, 0xa186, 0x0005, 0x00c0, 0xa009, 0x6810, 0xa080,
4627 0x0013, 0x2004, 0xd0bc, 0x00c0, 0x9fd0, 0x0d7f, 0x0078, 0x9f56,
4628 0xd0b4, 0x0040, 0x9fd8, 0xd0fc, 0x1040, 0x1328, 0x0078, 0x9f72,
4629 0x6007, 0x003a, 0x6003, 0x0001, 0x1078, 0x5bf8, 0x1078, 0x6109,
4630 0x0c7e, 0x2d60, 0x6100, 0xa186, 0x0002, 0x0040, 0x9feb, 0xa186,
4631 0x0004, 0x00c0, 0xa050, 0x2071, 0xa5e1, 0x7000, 0xa086, 0x0003,
4632 0x00c0, 0x9ff8, 0x7004, 0xac06, 0x00c0, 0x9ff8, 0x7003, 0x0000,
4633 0x6810, 0xa080, 0x0013, 0x200c, 0xc1f4, 0xc1dc, 0x2102, 0x8000,
4634 0x200c, 0xc1f4, 0xc1fc, 0xc1bc, 0x2102, 0x2009, 0x0042, 0x0078,
4635 0xa04a, 0x037e, 0x0d7e, 0x0d7e, 0x1078, 0x1381, 0x037f, 0x1040,
4636 0x1328, 0x6837, 0x010d, 0x6803, 0x0000, 0x683b, 0x0000, 0x685b,
4637 0x0000, 0x6b5e, 0x6857, 0x0045, 0x2c00, 0x6862, 0x6034, 0x6872,
4638 0x2360, 0x6024, 0xc0dd, 0x6026, 0x6018, 0xa080, 0x0028, 0x2004,
4639 0xa084, 0x00ff, 0x8007, 0x6320, 0x6b4a, 0x6846, 0x684f, 0x0000,
4640 0x6d6a, 0x6e66, 0x686f, 0x0001, 0x1078, 0x4982, 0x2019, 0x0045,
4641 0x6008, 0x2068, 0x1078, 0x9a6a, 0x2d00, 0x600a, 0x601f, 0x0006,
4642 0x6003, 0x0007, 0x6017, 0x0000, 0x603f, 0x0000, 0x0d7f, 0x037f,
4643 0x0078, 0xa051, 0x603f, 0x0000, 0x6003, 0x0007, 0x1078, 0x98c1,
4644 0x0c7f, 0x0d7f, 0x007c, 0xa186, 0x0013, 0x00c0, 0xa05d, 0x6004,
4645 0xa082, 0x0085, 0x2008, 0x0079, 0xa077, 0xa186, 0x0027, 0x00c0,
4646 0xa070, 0x1078, 0x6010, 0x037e, 0x0d7e, 0x6010, 0x2068, 0x2019,
4647 0x0004, 0x1078, 0x9e70, 0x0d7f, 0x037f, 0x1078, 0x6109, 0x007c,
4648 0xa186, 0x0014, 0x0040, 0xa061, 0x1078, 0x7583, 0x007c, 0xa080,
4649 0xa07e, 0xa07e, 0xa07e, 0xa07e, 0xa07e, 0xa080, 0x1078, 0x1328,
4650 0x1078, 0x6010, 0x6003, 0x000c, 0x1078, 0x6109, 0x007c, 0xa182,
4651 0x008c, 0x00c8, 0xa091, 0xa182, 0x0085, 0x0048, 0xa091, 0x0079,
4652 0xa094, 0x1078, 0x7583, 0x007c, 0xa09b, 0xa09b, 0xa09b, 0xa09b,
4653 0xa09d, 0xa0bc, 0xa09b, 0x1078, 0x1328, 0x0d7e, 0x2c68, 0x1078,
4654 0x74d7, 0x0040, 0xa0b7, 0x6003, 0x0001, 0x6007, 0x001e, 0x2009,
4655 0xa88e, 0x210c, 0x6136, 0x2009, 0xa88f, 0x210c, 0x613a, 0x600b,
4656 0xffff, 0x6918, 0x611a, 0x601f, 0x0004, 0x1078, 0x5bf8, 0x2d60,
4657 0x1078, 0x753d, 0x0d7f, 0x007c, 0x1078, 0x753d, 0x007c, 0x0e7e,
4658 0x6018, 0x2070, 0x7000, 0xd0ec, 0x0e7f, 0x007c, 0x6010, 0xa080,
4659 0x0013, 0x200c, 0xd1ec, 0x0040, 0xa110, 0x2001, 0xa371, 0x2004,
4660 0xd0ec, 0x0040, 0xa110, 0x6003, 0x0002, 0x6024, 0xc0e5, 0x6026,
4661 0xd1ac, 0x0040, 0xa0ee, 0x0f7e, 0x2c78, 0x1078, 0x488f, 0x0f7f,
4662 0x0040, 0xa0ee, 0x2001, 0xa5a2, 0x2004, 0x603e, 0x2009, 0xa371,
4663 0x210c, 0xd1f4, 0x00c0, 0xa10e, 0x0078, 0xa100, 0x2009, 0xa371,
4664 0x210c, 0xd1f4, 0x0040, 0xa0fa, 0x6024, 0xc0e4, 0x6026, 0xa006,
4665 0x0078, 0xa110, 0x2001, 0xa5a2, 0x200c, 0x8103, 0xa100, 0x603e,
4666 0x6018, 0xa088, 0x002b, 0x2104, 0xa005, 0x0040, 0xa10b, 0xa088,
4667 0x0003, 0x0078, 0xa103, 0x2c0a, 0x600f, 0x0000, 0xa085, 0x0001,
4668 0x007c, 0x017e, 0x0c7e, 0x0e7e, 0x6120, 0xa2f0, 0x002b, 0x2e04,
4669 0x2060, 0x8cff, 0x0040, 0xa130, 0x84ff, 0x00c0, 0xa123, 0x6020,
4670 0xa106, 0x00c0, 0xa12b, 0x600c, 0x2072, 0x1078, 0x5a41, 0x1078,
4671 0x753d, 0x0078, 0xa12d, 0xacf0, 0x0003, 0x2e64, 0x0078, 0xa119,
4672 0x0e7f, 0x0c7f, 0x017f, 0x007c, 0x0d7e, 0x6018, 0xa0e8, 0x002b,
4673 0x2d04, 0xa005, 0x0040, 0xa146, 0xac06, 0x0040, 0xa144, 0x2d04,
4674 0xa0e8, 0x0003, 0x0078, 0xa138, 0x600c, 0x206a, 0x0d7f, 0x007c,
4675 0x027e, 0x037e, 0x157e, 0x2011, 0xa325, 0x2204, 0xa084, 0x00ff,
4676 0x2019, 0xa88e, 0x2334, 0xa636, 0x00c0, 0xa174, 0x8318, 0x2334,
4677 0x2204, 0xa084, 0xff00, 0xa636, 0x00c0, 0xa174, 0x2011, 0xa890,
4678 0x6018, 0xa098, 0x000a, 0x20a9, 0x0004, 0x1078, 0x7e55, 0x00c0,
4679 0xa174, 0x2011, 0xa894, 0x6018, 0xa098, 0x0006, 0x20a9, 0x0004,
4680 0x1078, 0x7e55, 0x00c0, 0xa174, 0x157f, 0x037f, 0x027f, 0x007c,
4681 0x0e7e, 0x2071, 0xa300, 0x1078, 0x41f5, 0x1078, 0x260d, 0x0e7f,
4682 0x007c, 0x0e7e, 0x6018, 0x2070, 0x7000, 0xd0fc, 0x0040, 0xa18a,
4683 0x1078, 0xa18c, 0x0e7f, 0x007c, 0x6850, 0xc0e5, 0x6852, 0x007c,
4684 0x0e7e, 0x0c7e, 0x077e, 0x067e, 0x057e, 0x047e, 0x027e, 0x017e,
4685 0x127e, 0x2091, 0x8000, 0x2029, 0xa5b4, 0x252c, 0x2021, 0xa5ba,
4686 0x2424, 0x2061, 0xaa00, 0x2071, 0xa300, 0x7644, 0x7060, 0xa606,
4687 0x0040, 0xa1e4, 0x671c, 0xa786, 0x0001, 0x0040, 0xa1b3, 0xa786,
4688 0x0008, 0x00c0, 0xa1da, 0x2500, 0xac06, 0x0040, 0xa1da, 0x2400,
4689 0xac06, 0x0040, 0xa1da, 0x1078, 0x9ee5, 0x0040, 0xa1da, 0x1078,
4690 0x9ef9, 0x00c0, 0xa1da, 0x6000, 0xa086, 0x0004, 0x00c0, 0xa1cc,
4691 0x017e, 0x1078, 0x1749, 0x017f, 0x1078, 0x8c27, 0x00c0, 0xa1d2,
4692 0x1078, 0x2839, 0x1078, 0x8c3b, 0x00c0, 0xa1d8, 0x1078, 0x7a05,
4693 0x1078, 0x8c01, 0xace0, 0x0010, 0x2001, 0xa315, 0x2004, 0xac02,
4694 0x00c8, 0xa1e4, 0x0078, 0xa1a3, 0x127f, 0x017f, 0x027f, 0x047f,
4695 0x057f, 0x067f, 0x077f, 0x0c7f, 0x0e7f, 0x007c, 0x127e, 0x007e,
4696 0x0e7e, 0x2091, 0x8000, 0x2071, 0xa340, 0xd5a4, 0x0040, 0xa1fb,
4697 0x7034, 0x8000, 0x7036, 0xd5b4, 0x0040, 0xa201, 0x7030, 0x8000,
4698 0x7032, 0xd5ac, 0x0040, 0xa208, 0x2071, 0xa34a, 0x1078, 0xa237,
4699 0x0e7f, 0x007f, 0x127f, 0x007c, 0x127e, 0x007e, 0x0e7e, 0x2091,
4700 0x8000, 0x2071, 0xa340, 0xd5a4, 0x0040, 0xa219, 0x7034, 0x8000,
4701 0x7036, 0xd5b4, 0x0040, 0xa21f, 0x7030, 0x8000, 0x7032, 0xd5ac,
4702 0x0040, 0xa226, 0x2071, 0xa34a, 0x1078, 0xa237, 0x0e7f, 0x007f,
4703 0x127f, 0x007c, 0x127e, 0x007e, 0x0e7e, 0x2091, 0x8000, 0x2071,
4704 0xa342, 0x1078, 0xa237, 0x0e7f, 0x007f, 0x127f, 0x007c, 0x2e04,
4705 0x8000, 0x2072, 0x00c8, 0xa240, 0x8e70, 0x2e04, 0x8000, 0x2072,
4706 0x007c, 0x0e7e, 0x2071, 0xa340, 0x1078, 0xa237, 0x0e7f, 0x007c,
4707 0x0e7e, 0x2071, 0xa344, 0x1078, 0xa237, 0x0e7f, 0x007c, 0x0001,
4708 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100,
4709 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0x6286
4710};
4711
4712/************************************************************************
4713 * *
4714 * --- ISP2200 Initiator/Target Firmware --- *
4715 * with Fabric (Public Loop), Point-point, and *
4716 * expanded LUN addressing for FCTAPE *
4717 * *
4718 ************************************************************************
4719 Copyright (C) 2000 and 2100 Qlogic Corporation
4720 (www.qlogic.com)
4721
4722 This program is distributed in the hope that it will be useful, but
4723 WITHOUT ANY WARRANTY; without even the implied warranty of
4724 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4725 General Public License for more details.
4726************************************************************************/
4727
4728/*
4729 * Firmware Version 2.01.27 (11:07 Dec 18, 2000)
4730 */
4731
4732static unsigned short risc_code_length2200 = 0x9cbf;
4733static unsigned short risc_code2200[] = {
4734 0x0470, 0x0000, 0x0000, 0x9cbf, 0x0000, 0x0002, 0x0001, 0x001b,
4735 0x0017, 0x2043, 0x4f50, 0x5952, 0x4947, 0x4854, 0x2031, 0x3939,
4736 0x3920, 0x514c, 0x4f47, 0x4943, 0x2043, 0x4f52, 0x504f, 0x5241,
4737 0x5449, 0x4f4e, 0x2049, 0x5350, 0x3232, 0x3030, 0x2046, 0x6972,
4738 0x6d77, 0x6172, 0x6520, 0x2056, 0x6572, 0x7369, 0x6f6e, 0x2030,
4739 0x322e, 0x3031, 0x2e32, 0x3720, 0x2020, 0x2020, 0x2400, 0x20c1,
4740 0x0005, 0x2001, 0x017f, 0x2003, 0x0000, 0x20c9, 0xb1ff, 0x2091,
4741 0x2000, 0x2059, 0x0000, 0x2b78, 0x7823, 0x0004, 0x2089, 0x27b5,
4742 0x2051, 0xad00, 0x2a70, 0x2029, 0xe400, 0x2031, 0xffff, 0x2039,
4743 0xe3e9, 0x2021, 0x0200, 0x0804, 0x1449, 0x20a1, 0xacbf, 0xa00e,
4744 0x20a9, 0x0741, 0x41a4, 0x3400, 0x755e, 0x7662, 0x775a, 0x7466,
4745 0x746a, 0x20a1, 0xb400, 0x7160, 0x810d, 0x810d, 0x810d, 0x810d,
4746 0xa18c, 0x000f, 0x2001, 0x000b, 0xa112, 0xa00e, 0x21a8, 0x41a4,
4747 0x3400, 0x8211, 0x1dd8, 0x7160, 0x3400, 0xa102, 0x0120, 0x0218,
4748 0x20a8, 0xa00e, 0x41a4, 0x3800, 0xd08c, 0x01d8, 0x2009, 0xad00,
4749 0x810d, 0x810d, 0x810d, 0x810d, 0xa18c, 0x000f, 0x2001, 0x0001,
4750 0xa112, 0x20a1, 0x1000, 0xa00e, 0x21a8, 0x41a4, 0x8211, 0x1de0,
4751 0x2009, 0xad00, 0x3400, 0xa102, 0x0120, 0x0218, 0x20a8, 0xa00e,
4752 0x41a4, 0x080c, 0x13fc, 0x080c, 0x1613, 0x080c, 0x17ac, 0x080c,
4753 0x1e67, 0x080c, 0x492e, 0x080c, 0x801a, 0x080c, 0x159c, 0x080c,
4754 0x2ce6, 0x080c, 0x5a01, 0x080c, 0x5045, 0x080c, 0x6487, 0x080c,
4755 0x236a, 0x080c, 0x6686, 0x080c, 0x5fae, 0x080c, 0x226b, 0x080c,
4756 0x2338, 0x2091, 0x3009, 0x7823, 0x0000, 0x1004, 0x10c5, 0x7820,
4757 0xa086, 0x0002, 0x1150, 0x7823, 0x4000, 0x0e04, 0x10bd, 0x781b,
4758 0x0001, 0x2091, 0x5000, 0x2091, 0x4080, 0x2a70, 0x7003, 0x0000,
4759 0x2a70, 0x7000, 0xa08e, 0x0003, 0x1158, 0x080c, 0x3c98, 0x080c,
4760 0x2d0d, 0x080c, 0x5a4f, 0x080c, 0x51f4, 0x080c, 0x64a2, 0x0c80,
4761 0x000b, 0x0c98, 0x10e4, 0x10e5, 0x1203, 0x10e2, 0x12cc, 0x13f9,
4762 0x13fa, 0x13fb, 0x080c, 0x14f6, 0x0005, 0x0126, 0x00f6, 0x2091,
4763 0x8000, 0x7000, 0xa086, 0x0001, 0x1904, 0x11d1, 0x080c, 0x1569,
4764 0x080c, 0x574f, 0x0150, 0x080c, 0x5775, 0x1580, 0x2079, 0x0100,
4765 0x7828, 0xa085, 0x1800, 0x782a, 0x0448, 0x080c, 0x569a, 0x7000,
4766 0xa086, 0x0001, 0x1904, 0x11d1, 0x7088, 0xa086, 0x0028, 0x1904,
4767 0x11d1, 0x2079, 0x0100, 0x7827, 0xffff, 0x7a28, 0xa295, 0x1e2f,
4768 0x7a2a, 0x2011, 0x566e, 0x080c, 0x650d, 0x2011, 0x567b, 0x080c,
4769 0x650d, 0x2011, 0x481b, 0x080c, 0x650d, 0x2011, 0x8030, 0x2019,
4770 0x0000, 0x7087, 0x0000, 0x080c, 0x1d0f, 0x00e8, 0x080c, 0x41d1,
4771 0x2079, 0x0100, 0x7844, 0xa005, 0x1904, 0x11d1, 0x2011, 0x481b,
4772 0x080c, 0x650d, 0x2011, 0x567b, 0x080c, 0x650d, 0x080c, 0x1d0f,
4773 0x2001, 0xaf8c, 0x2004, 0x780e, 0x7840, 0xa084, 0xfffb, 0x7842,
4774 0x2011, 0x8010, 0x73c8, 0x080c, 0x3c5c, 0x7238, 0xc284, 0x723a,
4775 0x2001, 0xad0c, 0x200c, 0xc1ac, 0x2102, 0x080c, 0x79bd, 0x2011,
4776 0x0004, 0x080c, 0x959c, 0x080c, 0x4f71, 0x080c, 0x574f, 0x0158,
4777 0x080c, 0x4917, 0x0140, 0x7087, 0x0001, 0x70c3, 0x0000, 0x080c,
4778 0x436e, 0x0804, 0x11d1, 0x080c, 0x502d, 0x0120, 0x7a0c, 0xc2b4,
4779 0x7a0e, 0x0050, 0x080c, 0x9937, 0x70d0, 0xd09c, 0x1128, 0x709c,
4780 0xa005, 0x0110, 0x080c, 0x48f5, 0x70db, 0x0000, 0x70d7, 0x0000,
4781 0x72d0, 0x080c, 0x574f, 0x1178, 0x2011, 0x0000, 0x0016, 0x080c,
4782 0x2744, 0x2019, 0xaf8e, 0x211a, 0x001e, 0x704f, 0xffff, 0x7053,
4783 0x00ef, 0x7073, 0x0000, 0x2079, 0xad51, 0x7804, 0xd0ac, 0x0108,
4784 0xc295, 0x72d2, 0x080c, 0x574f, 0x0118, 0xa296, 0x0004, 0x0508,
4785 0x2011, 0x0001, 0x080c, 0x959c, 0x7097, 0x0000, 0x709b, 0xffff,
4786 0x7003, 0x0002, 0x00fe, 0x080c, 0x28fa, 0x2011, 0x0005, 0x080c,
4787 0x7adf, 0x080c, 0x6c50, 0x080c, 0x574f, 0x0148, 0x00c6, 0x2061,
4788 0x0100, 0x0016, 0x080c, 0x2744, 0x61e2, 0x001e, 0x00ce, 0x012e,
4789 0x00d0, 0x7097, 0x0000, 0x709b, 0xffff, 0x7003, 0x0002, 0x2011,
4790 0x0005, 0x080c, 0x7adf, 0x080c, 0x6c50, 0x080c, 0x574f, 0x0148,
4791 0x00c6, 0x2061, 0x0100, 0x0016, 0x080c, 0x2744, 0x61e2, 0x001e,
4792 0x00ce, 0x00fe, 0x012e, 0x0005, 0x00c6, 0x080c, 0x574f, 0x1118,
4793 0x20a9, 0x0100, 0x0010, 0x20a9, 0x0082, 0x080c, 0x574f, 0x1118,
4794 0x2009, 0x0000, 0x0010, 0x2009, 0x007e, 0x0016, 0x0026, 0x0036,
4795 0x2110, 0x0026, 0x2019, 0x0029, 0x080c, 0x7cf4, 0x002e, 0x080c,
4796 0xac07, 0x003e, 0x002e, 0x001e, 0x080c, 0x2bc9, 0x8108, 0x1f04,
4797 0x11e5, 0x00ce, 0x706f, 0x0000, 0x7070, 0xa084, 0x00ff, 0x7072,
4798 0x709f, 0x0000, 0x0005, 0x0126, 0x2091, 0x8000, 0x7000, 0xa086,
4799 0x0002, 0x1904, 0x12ca, 0x7098, 0xa086, 0xffff, 0x0130, 0x080c,
4800 0x28fa, 0x080c, 0x6c50, 0x0804, 0x12ca, 0x70d0, 0xd0ac, 0x1110,
4801 0xd09c, 0x0540, 0xd084, 0x0530, 0x0006, 0x0016, 0x2001, 0x0103,
4802 0x2009, 0xaf8c, 0x210c, 0x2102, 0x001e, 0x000e, 0xd08c, 0x01d0,
4803 0x70d4, 0xa086, 0xffff, 0x0190, 0x080c, 0x2a56, 0x080c, 0x6c50,
4804 0x70d0, 0xd094, 0x1904, 0x12ca, 0x2011, 0x0001, 0x2019, 0x0000,
4805 0x080c, 0x2a8c, 0x080c, 0x6c50, 0x0804, 0x12ca, 0x70d8, 0xa005,
4806 0x1904, 0x12ca, 0x7094, 0xa005, 0x1904, 0x12ca, 0x70d0, 0xd0a4,
4807 0x0118, 0xd0b4, 0x0904, 0x12ca, 0x080c, 0x502d, 0x1904, 0x12ca,
4808 0x2001, 0xad52, 0x2004, 0xd0ac, 0x01c8, 0x0156, 0x00c6, 0x20a9,
4809 0x007f, 0x2009, 0x0000, 0x0016, 0x080c, 0x4cdc, 0x1118, 0x6000,
4810 0xd0ec, 0x1138, 0x001e, 0x8108, 0x1f04, 0x125b, 0x00ce, 0x015e,
4811 0x0028, 0x001e, 0x00ce, 0x015e, 0x0804, 0x12ca, 0x0006, 0x0016,
4812 0x2001, 0x0103, 0x2009, 0xaf8c, 0x210c, 0x2102, 0x001e, 0x000e,
4813 0xa006, 0x2009, 0x0700, 0x20a9, 0x0002, 0x20a1, 0xafb5, 0x40a1,
4814 0x706c, 0x8007, 0x7170, 0x810f, 0x20a9, 0x0002, 0x40a1, 0x2009,
4815 0x0000, 0x080c, 0x14dc, 0x2001, 0x0000, 0x810f, 0x20a9, 0x0002,
4816 0x40a1, 0xa006, 0x2009, 0x0200, 0x20a9, 0x0002, 0x20a1, 0xafc5,
4817 0x40a1, 0x7030, 0xc08c, 0x7032, 0x7003, 0x0003, 0x709b, 0xffff,
4818 0x080c, 0x1562, 0xa006, 0x080c, 0x261e, 0x080c, 0x3cce, 0x00f6,
4819 0x2079, 0x0100, 0x080c, 0x5775, 0x0150, 0x080c, 0x574f, 0x7828,
4820 0x0118, 0xa084, 0xe1ff, 0x0010, 0xa084, 0xffdf, 0x782a, 0x00fe,
4821 0x2001, 0xafc8, 0x2004, 0xa086, 0x0005, 0x1120, 0x2011, 0x0000,
4822 0x080c, 0x7adf, 0x2011, 0x0000, 0x080c, 0x7ae9, 0x080c, 0x6c50,
4823 0x080c, 0x6d0d, 0x012e, 0x0005, 0x0016, 0x0046, 0x00f6, 0x0126,
4824 0x2091, 0x8000, 0x2079, 0x0100, 0x2009, 0xad33, 0x2104, 0xa005,
4825 0x1110, 0x080c, 0x2770, 0x2009, 0x00f7, 0x080c, 0x48de, 0x7940,
4826 0xa18c, 0x0010, 0x7942, 0x7924, 0xd1b4, 0x0110, 0x7827, 0x0040,
4827 0xd19c, 0x0110, 0x7827, 0x0008, 0x0006, 0x0036, 0x0156, 0x7954,
4828 0xd1ac, 0x1904, 0x133a, 0x080c, 0x5761, 0x0158, 0x080c, 0x5775,
4829 0x1128, 0x2001, 0xaf9d, 0x2003, 0x0000, 0x0070, 0x080c, 0x5757,
4830 0x0dc0, 0x2001, 0xaf9d, 0x2003, 0xaaaa, 0x2001, 0xaf9e, 0x2003,
4831 0x0001, 0x080c, 0x569a, 0x0058, 0x080c, 0x574f, 0x0140, 0x2009,
4832 0x00f8, 0x080c, 0x48de, 0x7843, 0x0090, 0x7843, 0x0010, 0x20a9,
4833 0x09c4, 0x7820, 0xd09c, 0x1138, 0x080c, 0x574f, 0x0138, 0x7824,
4834 0xd0ac, 0x1904, 0x13e0, 0x1f04, 0x1319, 0x0070, 0x7824, 0x080c,
4835 0x576b, 0x0118, 0xd0ac, 0x1904, 0x13e0, 0xa084, 0x1800, 0x0d98,
4836 0x7003, 0x0001, 0x0804, 0x13e0, 0x2001, 0x0001, 0x080c, 0x261e,
4837 0x0804, 0x13ef, 0x7850, 0xa084, 0x0180, 0x7852, 0x782f, 0x0020,
4838 0x20a9, 0x0046, 0x1d04, 0x1342, 0x2091, 0x6000, 0x1f04, 0x1342,
4839 0x7850, 0xa084, 0x0180, 0xa085, 0x0400, 0x7852, 0x782f, 0x0000,
4840 0x080c, 0x5761, 0x0158, 0x080c, 0x5775, 0x1128, 0x2001, 0xaf9d,
4841 0x2003, 0x0000, 0x0070, 0x080c, 0x5757, 0x0dc0, 0x2001, 0xaf9d,
4842 0x2003, 0xaaaa, 0x2001, 0xaf9e, 0x2003, 0x0001, 0x080c, 0x569a,
4843 0x0020, 0x2009, 0x00f8, 0x080c, 0x48de, 0x20a9, 0x000e, 0xe000,
4844 0x1f04, 0x136f, 0x7850, 0xa084, 0x0180, 0xa085, 0x1400, 0x7852,
4845 0x080c, 0x574f, 0x0120, 0x7843, 0x0090, 0x7843, 0x0010, 0x2021,
4846 0xe678, 0x2019, 0xea60, 0x7820, 0xd09c, 0x1558, 0x080c, 0x574f,
4847 0x05b8, 0x7824, 0xd0ac, 0x1904, 0x13e0, 0x080c, 0x5775, 0x1508,
4848 0x0046, 0x2021, 0x0190, 0x8421, 0x1df0, 0x004e, 0x8421, 0x11c8,
4849 0x7827, 0x0048, 0x20a9, 0x01f4, 0x1d04, 0x139c, 0x2091, 0x6000,
4850 0x1f04, 0x139c, 0x7824, 0xa084, 0x0068, 0x15a8, 0x2001, 0xaf9d,
4851 0x2003, 0xaaaa, 0x2001, 0xaf9e, 0x2003, 0x0001, 0x7003, 0x0001,
4852 0x0478, 0x8319, 0x1980, 0x2009, 0xad33, 0x2104, 0x8000, 0x200a,
4853 0xa084, 0xfff0, 0x0120, 0x200b, 0x0000, 0x080c, 0x2770, 0x00d8,
4854 0x080c, 0x5761, 0x1140, 0xa4a2, 0x0064, 0x1128, 0x080c, 0x5726,
4855 0x7003, 0x0001, 0x00a8, 0x7827, 0x1800, 0xe000, 0xe000, 0x7824,
4856 0x080c, 0x576b, 0x0110, 0xd0ac, 0x1158, 0xa084, 0x1800, 0x09c8,
4857 0x7003, 0x0001, 0x0028, 0x2001, 0x0001, 0x080c, 0x261e, 0x0048,
4858 0x2001, 0xad33, 0x2003, 0x0000, 0x7827, 0x0048, 0x7828, 0xc09d,
4859 0x782a, 0x7850, 0xa084, 0x0180, 0xa085, 0x0400, 0x7852, 0x015e,
4860 0x003e, 0x000e, 0x080c, 0x1539, 0x012e, 0x00fe, 0x004e, 0x001e,
4861 0x0005, 0x0005, 0x0005, 0x0005, 0x2a70, 0x2001, 0xaf9d, 0x2003,
4862 0x0000, 0x7087, 0x0000, 0x2009, 0x0100, 0x2104, 0xa082, 0x0002,
4863 0x0218, 0x704f, 0xffff, 0x0010, 0x704f, 0x0000, 0x7057, 0xffff,
4864 0x706f, 0x0000, 0x7073, 0x0000, 0x080c, 0x9937, 0x2061, 0xaf8d,
4865 0x6003, 0x0909, 0x6007, 0x0000, 0x600b, 0x8800, 0x600f, 0x0200,
4866 0x6013, 0x00ff, 0x6017, 0x0003, 0x601b, 0x0000, 0x601f, 0x07d0,
4867 0x2061, 0xaf95, 0x6003, 0x8000, 0x6007, 0x0000, 0x600b, 0x0000,
4868 0x600f, 0x0200, 0x6013, 0x00ff, 0x6017, 0x0000, 0x601b, 0x0001,
4869 0x601f, 0x0000, 0x2061, 0xafa6, 0x6003, 0x514c, 0x6007, 0x4f47,
4870 0x600b, 0x4943, 0x600f, 0x2020, 0x2001, 0xad27, 0x2003, 0x0000,
4871 0x0005, 0x04a0, 0x2011, 0x0000, 0x81ff, 0x0570, 0xa186, 0x0001,
4872 0x1148, 0x2031, 0x8fff, 0x2039, 0xcc01, 0x2021, 0x0100, 0x2029,
4873 0xcc00, 0x00e8, 0xa186, 0x0002, 0x1118, 0x2011, 0x0000, 0x00b8,
4874 0xa186, 0x0005, 0x1118, 0x2011, 0x0001, 0x0088, 0xa186, 0x0009,
4875 0x1118, 0x2011, 0x0002, 0x0058, 0xa186, 0x000a, 0x1118, 0x2011,
4876 0x0002, 0x0028, 0xa186, 0x0055, 0x1110, 0x2011, 0x0003, 0x3800,
4877 0xa084, 0xfffc, 0xa205, 0x20c0, 0x0804, 0x104d, 0xa00e, 0x2011,
4878 0x0003, 0x2019, 0x1485, 0x0804, 0x14d6, 0x2019, 0xaaaa, 0x2061,
4879 0xffff, 0x2c14, 0x2362, 0xe000, 0xe000, 0x2c04, 0xa306, 0x2262,
4880 0x1110, 0xc1b5, 0xc1a5, 0x2011, 0x0000, 0x2019, 0x1498, 0x04f0,
4881 0x2019, 0xaaaa, 0x2061, 0xffff, 0x2c14, 0x2362, 0xe000, 0xe000,
4882 0x2c1c, 0x2061, 0x7fff, 0xe000, 0xe000, 0x2c04, 0x2061, 0xffff,
4883 0x2262, 0xa306, 0x0110, 0xc18d, 0x0008, 0xc185, 0x2011, 0x0002,
4884 0x2019, 0x14b3, 0x0418, 0x2061, 0xffff, 0x2019, 0xaaaa, 0x2c14,
4885 0x2362, 0xe000, 0xe000, 0x2c04, 0x2262, 0xa306, 0x1180, 0x2c14,
4886 0x2362, 0xe000, 0xe000, 0x2c1c, 0x2061, 0x7fff, 0x2c04, 0x2061,
4887 0xffff, 0x2262, 0xa306, 0x1110, 0xc195, 0x0008, 0xc19d, 0x2011,
4888 0x0001, 0x2019, 0x14d4, 0x0010, 0x0804, 0x144a, 0x3800, 0xa084,
4889 0xfffc, 0xa205, 0x20c0, 0x0837, 0x2011, 0x0000, 0x080c, 0x4cdc,
4890 0x1178, 0x6004, 0xa0c4, 0x00ff, 0xa8c6, 0x0006, 0x0128, 0xa0c4,
4891 0xff00, 0xa8c6, 0x0600, 0x1120, 0xa186, 0x0080, 0x0108, 0x8210,
4892 0x8108, 0xa186, 0x0100, 0x1d50, 0x2208, 0x0005, 0x2091, 0x8000,
4893 0x0e04, 0x14f8, 0x0006, 0x0016, 0x2079, 0x0000, 0x7818, 0xd084,
4894 0x1de8, 0x001e, 0x792e, 0x000e, 0x782a, 0x000e, 0x7826, 0x3900,
4895 0x783a, 0x7823, 0x8002, 0x781b, 0x0001, 0x2091, 0x5000, 0x0126,
4896 0x0156, 0x0146, 0x20a9, 0x0010, 0x20a1, 0xb0c8, 0x2091, 0x2000,
4897 0x40a1, 0x20a9, 0x0010, 0x2091, 0x2200, 0x40a1, 0x20a9, 0x0010,
4898 0x2091, 0x2400, 0x40a1, 0x20a9, 0x0010, 0x2091, 0x2600, 0x40a1,
4899 0x20a9, 0x0010, 0x2091, 0x2800, 0x40a1, 0x014e, 0x015e, 0x012e,
4900 0x2079, 0xad00, 0x7803, 0x0005, 0x2091, 0x4080, 0x04c9, 0x0cf8,
4901 0x0005, 0x0006, 0x080c, 0x1584, 0x1518, 0x00f6, 0x2079, 0xad23,
4902 0x2f04, 0x8000, 0x207a, 0xa082, 0x000f, 0x0258, 0xa006, 0x207a,
4903 0x2079, 0xad25, 0x2f04, 0xa084, 0x0001, 0xa086, 0x0001, 0x207a,
4904 0x0070, 0x2079, 0xad25, 0x2f7c, 0x8fff, 0x1128, 0x2001, 0x0c03,
4905 0x2003, 0x0040, 0x0020, 0x2001, 0x0c03, 0x2003, 0x00c0, 0x00fe,
4906 0x000e, 0x0005, 0x0409, 0x1120, 0x2001, 0x0c03, 0x2003, 0x0080,
4907 0x0005, 0x00d1, 0x1120, 0x2001, 0x0c03, 0x2003, 0x0040, 0x0005,
4908 0x0006, 0x0091, 0x1178, 0x2001, 0x0c03, 0x2003, 0x0040, 0x2009,
4909 0x0fff, 0x00a1, 0x2001, 0x0c03, 0x2003, 0x0080, 0x2009, 0x0fff,
4910 0x0069, 0x0c88, 0x000e, 0x0005, 0x00c6, 0x2061, 0x0c00, 0x2c04,
4911 0xa084, 0x00ff, 0xa086, 0x00aa, 0x00ce, 0x0005, 0x0156, 0x0126,
4912 0xa18c, 0x0fff, 0x21a8, 0x1d04, 0x1593, 0x2091, 0x6000, 0x1f04,
4913 0x1593, 0x012e, 0x015e, 0x0005, 0x2071, 0xad00, 0x715c, 0x712e,
4914 0x2021, 0x0001, 0xa190, 0x0030, 0xa298, 0x0030, 0x0240, 0x7060,
4915 0xa302, 0x1228, 0x220a, 0x2208, 0x2310, 0x8420, 0x0ca8, 0x3800,
4916 0xd08c, 0x0148, 0x7060, 0xa086, 0xad00, 0x0128, 0x7063, 0xad00,
4917 0x2011, 0x1000, 0x0c48, 0x200b, 0x0000, 0x74ae, 0x74b2, 0x0005,
4918 0x00e6, 0x0126, 0x2091, 0x8000, 0x2071, 0xad00, 0x70b0, 0xa0ea,
4919 0x0010, 0x0268, 0x8001, 0x70b2, 0x702c, 0x2068, 0x2d04, 0x702e,
4920 0x206b, 0x0000, 0x6807, 0x0000, 0x012e, 0x00ee, 0x0005, 0xa06e,
4921 0x0cd8, 0x00e6, 0x2071, 0xad00, 0x0126, 0x2091, 0x8000, 0x70b0,
4922 0x8001, 0x0260, 0x70b2, 0x702c, 0x2068, 0x2d04, 0x702e, 0x206b,
4923 0x0000, 0x6807, 0x0000, 0x012e, 0x00ee, 0x0005, 0xa06e, 0x0cd8,
4924 0x00e6, 0x0126, 0x2091, 0x8000, 0x2071, 0xad00, 0x702c, 0x206a,
4925 0x2d00, 0x702e, 0x70b0, 0x8000, 0x70b2, 0x012e, 0x00ee, 0x0005,
4926 0x8dff, 0x0138, 0x6804, 0x6807, 0x0000, 0x0006, 0x0c49, 0x00de,
4927 0x0cb8, 0x0005, 0x00e6, 0x2071, 0xad00, 0x70b0, 0xa08a, 0x0010,
4928 0xa00d, 0x00ee, 0x0005, 0x00e6, 0x2071, 0xafec, 0x7007, 0x0000,
4929 0x701b, 0x0000, 0x701f, 0x0000, 0x2071, 0x0000, 0x7010, 0xa085,
4930 0x8004, 0x7012, 0x00ee, 0x0005, 0x00e6, 0x2270, 0x700b, 0x0000,
4931 0x2071, 0xafec, 0x7018, 0xa088, 0xaff5, 0x220a, 0x8000, 0xa084,
4932 0x0007, 0x701a, 0x7004, 0xa005, 0x1128, 0x00f6, 0x2079, 0x0010,
4933 0x0081, 0x00fe, 0x00ee, 0x0005, 0x00e6, 0x2071, 0xafec, 0x7004,
4934 0xa005, 0x1128, 0x00f6, 0x2079, 0x0010, 0x0019, 0x00fe, 0x00ee,
4935 0x0005, 0x7000, 0x0002, 0x164f, 0x16b3, 0x16d0, 0x16d0, 0x7018,
4936 0x711c, 0xa106, 0x1118, 0x7007, 0x0000, 0x0005, 0x00d6, 0xa180,
4937 0xaff5, 0x2004, 0x700a, 0x2068, 0x8108, 0xa18c, 0x0007, 0x711e,
4938 0x7803, 0x0026, 0x6824, 0x7832, 0x6828, 0x7836, 0x682c, 0x783a,
4939 0x6830, 0x783e, 0x6810, 0x700e, 0x680c, 0x7016, 0x6804, 0x00de,
4940 0xd084, 0x0120, 0x7007, 0x0001, 0x0029, 0x0005, 0x7007, 0x0002,
4941 0x00b1, 0x0005, 0x0016, 0x0026, 0x710c, 0x2011, 0x0040, 0xa182,
4942 0x0040, 0x1210, 0x2110, 0xa006, 0x700e, 0x7212, 0x8203, 0x7822,
4943 0x7803, 0x0020, 0x7803, 0x0041, 0x002e, 0x001e, 0x0005, 0x0016,
4944 0x0026, 0x0136, 0x0146, 0x0156, 0x7014, 0x2098, 0x20a1, 0x0014,
4945 0x7803, 0x0026, 0x710c, 0x2011, 0x0040, 0xa182, 0x0040, 0x1210,
4946 0x2110, 0xa006, 0x700e, 0x22a8, 0x53a6, 0x8203, 0x7822, 0x7803,
4947 0x0020, 0x3300, 0x7016, 0x7803, 0x0001, 0x015e, 0x014e, 0x013e,
4948 0x002e, 0x001e, 0x0005, 0x0136, 0x0146, 0x0156, 0x2099, 0xadf9,
4949 0x20a1, 0x0018, 0x20a9, 0x0008, 0x53a3, 0x7803, 0x0020, 0x0126,
4950 0x2091, 0x8000, 0x7803, 0x0041, 0x7007, 0x0003, 0x7000, 0xc084,
4951 0x7002, 0x700b, 0xadf4, 0x012e, 0x015e, 0x014e, 0x013e, 0x0005,
4952 0x0136, 0x0146, 0x0156, 0x2001, 0xae28, 0x209c, 0x20a1, 0x0014,
4953 0x7803, 0x0026, 0x2001, 0xae29, 0x20ac, 0x53a6, 0x2099, 0xae2a,
4954 0x20a1, 0x0018, 0x20a9, 0x0008, 0x53a3, 0x7803, 0x0020, 0x0126,
4955 0x2091, 0x8000, 0x7803, 0x0001, 0x7007, 0x0004, 0x7000, 0xc08c,
4956 0x7002, 0x700b, 0xae25, 0x012e, 0x015e, 0x014e, 0x013e, 0x0005,
4957 0x0016, 0x00e6, 0x2071, 0xafec, 0x00f6, 0x2079, 0x0010, 0x7904,
4958 0x7803, 0x0002, 0xd1fc, 0x0120, 0xa18c, 0x0700, 0x7004, 0x0023,
4959 0x00fe, 0x00ee, 0x001e, 0x0005, 0x1649, 0x1713, 0x1741, 0x176b,
4960 0x179b, 0x1712, 0x0cf8, 0xa18c, 0x0700, 0x1528, 0x0136, 0x0146,
4961 0x0156, 0x7014, 0x20a0, 0x2099, 0x0014, 0x7803, 0x0040, 0x7010,
4962 0x20a8, 0x53a5, 0x3400, 0x7016, 0x015e, 0x014e, 0x013e, 0x700c,
4963 0xa005, 0x0570, 0x7830, 0x7832, 0x7834, 0x7836, 0x080c, 0x167a,
4964 0x0005, 0x7008, 0xa080, 0x0002, 0x2003, 0x0100, 0x7007, 0x0000,
4965 0x080c, 0x1649, 0x0005, 0x7008, 0xa080, 0x0002, 0x2003, 0x0200,
4966 0x0ca8, 0xa18c, 0x0700, 0x1150, 0x700c, 0xa005, 0x0188, 0x7830,
4967 0x7832, 0x7834, 0x7836, 0x080c, 0x168f, 0x0005, 0x7008, 0xa080,
4968 0x0002, 0x2003, 0x0200, 0x7007, 0x0000, 0x080c, 0x1649, 0x0005,
4969 0x00d6, 0x7008, 0x2068, 0x7830, 0x6826, 0x7834, 0x682a, 0x7838,
4970 0x682e, 0x783c, 0x6832, 0x680b, 0x0100, 0x00de, 0x7007, 0x0000,
4971 0x080c, 0x1649, 0x0005, 0xa18c, 0x0700, 0x1540, 0x0136, 0x0146,
4972 0x0156, 0x2001, 0xadf7, 0x2004, 0xa080, 0x000d, 0x20a0, 0x2099,
4973 0x0014, 0x7803, 0x0040, 0x20a9, 0x0020, 0x53a5, 0x2001, 0xadf9,
4974 0x2004, 0xd0bc, 0x0148, 0x2001, 0xae02, 0x2004, 0xa080, 0x000d,
4975 0x20a0, 0x20a9, 0x0020, 0x53a5, 0x015e, 0x014e, 0x013e, 0x7007,
4976 0x0000, 0x080c, 0x5ae6, 0x080c, 0x1649, 0x0005, 0x2011, 0x8003,
4977 0x080c, 0x3c5c, 0x0cf8, 0xa18c, 0x0700, 0x1148, 0x2001, 0xae27,
4978 0x2003, 0x0100, 0x7007, 0x0000, 0x080c, 0x1649, 0x0005, 0x2011,
4979 0x8004, 0x080c, 0x3c5c, 0x0cf8, 0x0126, 0x2091, 0x2200, 0x2079,
4980 0x0030, 0x2071, 0xaffd, 0x7003, 0x0000, 0x700f, 0xb003, 0x7013,
4981 0xb003, 0x780f, 0x00f6, 0x7803, 0x0004, 0x012e, 0x0005, 0x6934,
4982 0xa184, 0x0007, 0x0002, 0x17cb, 0x1809, 0x17cb, 0x17cb, 0x17cb,
4983 0x17f1, 0x17d8, 0x17cf, 0xa085, 0x0001, 0x0804, 0x1823, 0x684c,
4984 0xd0bc, 0x0dc8, 0x6860, 0x682e, 0x685c, 0x682a, 0x6858, 0x04c8,
4985 0xa18c, 0x00ff, 0xa186, 0x001e, 0x1d70, 0x684c, 0xd0bc, 0x0d58,
4986 0x6860, 0x682e, 0x685c, 0x682a, 0x6804, 0x681a, 0xa080, 0x000d,
4987 0x2004, 0xa084, 0x000f, 0xa080, 0x2186, 0x2005, 0x6832, 0x6858,
4988 0x0440, 0xa18c, 0x00ff, 0xa186, 0x0015, 0x19a8, 0x684c, 0xd0ac,
4989 0x0990, 0x6804, 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f,
4990 0xa080, 0x2186, 0x2005, 0x6832, 0xa006, 0x682e, 0x682a, 0x6858,
4991 0x0080, 0x684c, 0xd0ac, 0x0904, 0x17cb, 0xa006, 0x682e, 0x682a,
4992 0x6858, 0xa18c, 0x000f, 0xa188, 0x2186, 0x210d, 0x6932, 0x2d08,
4993 0x691a, 0x6826, 0x684c, 0xc0dd, 0x684e, 0xa006, 0x680a, 0x697c,
4994 0x6912, 0x6980, 0x6916, 0x0005, 0x20e1, 0x0007, 0x20e1, 0x2000,
4995 0x2001, 0x020a, 0x2004, 0x82ff, 0x01a8, 0xa280, 0x0004, 0x00d6,
4996 0x206c, 0x684c, 0xd0dc, 0x1150, 0x080c, 0x17bf, 0x0138, 0x00de,
4997 0xa280, 0x0000, 0x2003, 0x0002, 0xa016, 0x0020, 0x6808, 0x8000,
4998 0x680a, 0x00de, 0x0126, 0x0046, 0x0036, 0x0026, 0x2091, 0x2200,
4999 0x002e, 0x003e, 0x004e, 0x7000, 0xa005, 0x01d0, 0x710c, 0x220a,
5000 0x8108, 0x230a, 0x8108, 0x240a, 0x8108, 0xa182, 0xb01e, 0x0210,
5001 0x2009, 0xb003, 0x710e, 0x7010, 0xa102, 0xa082, 0x0009, 0x0118,
5002 0xa080, 0x001b, 0x1118, 0x2009, 0x0138, 0x200a, 0x012e, 0x0005,
5003 0x7206, 0x2001, 0x1866, 0x0006, 0x2260, 0x0804, 0x197a, 0x0126,
5004 0x0026, 0x0036, 0x00c6, 0x0006, 0x2091, 0x2200, 0x000e, 0x004e,
5005 0x003e, 0x002e, 0x00d6, 0x00c6, 0x2460, 0x6110, 0x2168, 0x6a62,
5006 0x6b5e, 0xa005, 0x0904, 0x18c8, 0x6808, 0xa005, 0x0904, 0x18ff,
5007 0x7000, 0xa005, 0x1108, 0x0488, 0x700c, 0x7110, 0xa106, 0x1904,
5008 0x1907, 0x7004, 0xa406, 0x1548, 0x2001, 0x0005, 0x2004, 0xd08c,
5009 0x0168, 0x0046, 0x080c, 0x1a6c, 0x004e, 0x2460, 0x6010, 0xa080,
5010 0x0002, 0x2004, 0xa005, 0x0904, 0x18ff, 0x0c10, 0x2001, 0x0207,
5011 0x2004, 0xd09c, 0x1d48, 0x7804, 0xa084, 0x6000, 0x0120, 0xa086,
5012 0x6000, 0x0108, 0x0c08, 0x7818, 0x6812, 0x781c, 0x6816, 0x7803,
5013 0x0004, 0x7003, 0x0000, 0x7004, 0x2060, 0x6100, 0xa18e, 0x0004,
5014 0x1904, 0x1907, 0x2009, 0x0048, 0x080c, 0x80a7, 0x0804, 0x1907,
5015 0x6808, 0xa005, 0x05a0, 0x7000, 0xa005, 0x0588, 0x700c, 0x7110,
5016 0xa106, 0x1118, 0x7004, 0xa406, 0x1550, 0x2001, 0x0005, 0x2004,
5017 0xd08c, 0x0160, 0x0046, 0x080c, 0x1a6c, 0x004e, 0x2460, 0x6010,
5018 0xa080, 0x0002, 0x2004, 0xa005, 0x01d0, 0x0c28, 0x2001, 0x0207,
5019 0x2004, 0xd09c, 0x1d50, 0x2001, 0x0005, 0x2004, 0xd08c, 0x1d50,
5020 0x7804, 0xa084, 0x6000, 0x0118, 0xa086, 0x6000, 0x19f0, 0x7818,
5021 0x6812, 0x781c, 0x6816, 0x7803, 0x0004, 0x7003, 0x0000, 0x6100,
5022 0xa18e, 0x0004, 0x1120, 0x2009, 0x0048, 0x080c, 0x80a7, 0x00ce,
5023 0x00de, 0x012e, 0x0005, 0x00f6, 0x00e6, 0x0026, 0x0036, 0x0046,
5024 0x0056, 0x080c, 0x1d86, 0x0026, 0x0056, 0x2071, 0xaffd, 0x7000,
5025 0xa086, 0x0000, 0x0580, 0x7004, 0xac06, 0x11f8, 0x2079, 0x0030,
5026 0x7000, 0xa086, 0x0003, 0x01c8, 0x7804, 0xd0fc, 0x1198, 0x2001,
5027 0x0207, 0x2004, 0xd09c, 0x1dc0, 0x7803, 0x0004, 0x7804, 0xd0ac,
5028 0x1de8, 0x7803, 0x0002, 0x7803, 0x0009, 0x7003, 0x0003, 0x7007,
5029 0x0000, 0x0018, 0x080c, 0x1a6c, 0x08d0, 0x0156, 0x20a9, 0x0009,
5030 0x2009, 0xb003, 0x2104, 0xac06, 0x1108, 0x200a, 0xa188, 0x0003,
5031 0x1f04, 0x1942, 0x015e, 0x005e, 0x002e, 0x2001, 0x015d, 0x201c,
5032 0x831a, 0x2302, 0x2001, 0x0160, 0x2502, 0x2001, 0x0138, 0x2202,
5033 0x005e, 0x004e, 0x003e, 0x002e, 0x00ee, 0x00fe, 0x0005, 0x700c,
5034 0x7110, 0xa106, 0x0904, 0x19dd, 0x2104, 0x7006, 0x2060, 0x8108,
5035 0x211c, 0x8108, 0x2124, 0x8108, 0xa182, 0xb01e, 0x0210, 0x2009,
5036 0xb003, 0x7112, 0x700c, 0xa106, 0x1128, 0x080c, 0x2744, 0x2001,
5037 0x0138, 0x2102, 0x8cff, 0x0588, 0x6010, 0x2068, 0x2d58, 0x6828,
5038 0xa406, 0x1580, 0x682c, 0xa306, 0x1568, 0x7004, 0x2060, 0x6020,
5039 0xc0d4, 0x6022, 0x684c, 0xd0f4, 0x0128, 0x6817, 0xffff, 0x6813,
5040 0xffff, 0x00d8, 0x6850, 0xd0f4, 0x1130, 0x7803, 0x0004, 0x6810,
5041 0x781a, 0x6814, 0x781e, 0x6824, 0x2050, 0x6818, 0x2060, 0x6830,
5042 0x2040, 0x6034, 0xa0cc, 0x000f, 0x2009, 0x0011, 0x04c9, 0x0118,
5043 0x2009, 0x0001, 0x04a9, 0x2d58, 0x0005, 0x080c, 0x1ced, 0x0904,
5044 0x195f, 0x0cd0, 0x6020, 0xd0d4, 0x01b8, 0x6038, 0xa402, 0x6034,
5045 0xa303, 0x0108, 0x1288, 0x643a, 0x6336, 0x6c2a, 0x6b2e, 0x0046,
5046 0x0036, 0x2400, 0x6c7c, 0xa402, 0x6812, 0x2300, 0x6b80, 0xa303,
5047 0x6816, 0x003e, 0x004e, 0x0018, 0x080c, 0x98cb, 0x09f0, 0x601c,
5048 0xa08e, 0x0008, 0x0904, 0x1985, 0xa08e, 0x000a, 0x0904, 0x1985,
5049 0x080c, 0x21a6, 0x1990, 0x0804, 0x1985, 0x7003, 0x0000, 0x0005,
5050 0x8aff, 0x0904, 0x1a46, 0xa03e, 0x2730, 0x6850, 0xd0fc, 0x11b8,
5051 0xd0f4, 0x1528, 0x00d6, 0x2805, 0xac68, 0x2900, 0x0002, 0x1a30,
5052 0x1a15, 0x1a15, 0x1a30, 0x1a30, 0x1a29, 0x1a30, 0x1a15, 0x1a30,
5053 0x1a1a, 0x1a1a, 0x1a30, 0x1a30, 0x1a30, 0x1a21, 0x1a1a, 0x7803,
5054 0x0004, 0xc0fc, 0x6852, 0x6b6c, 0x6a70, 0x6d1c, 0x6c20, 0x00d6,
5055 0xd99c, 0x0548, 0x2805, 0xac68, 0x6f08, 0x6e0c, 0x0420, 0xc0f4,
5056 0x6852, 0x6b6c, 0x6a70, 0x00d6, 0x0428, 0x6b08, 0x6a0c, 0x6d00,
5057 0x6c04, 0x00c8, 0x6b10, 0x6a14, 0x6d00, 0x6c04, 0x6f08, 0x6e0c,
5058 0x0090, 0x00de, 0x00d6, 0x6834, 0xa084, 0x00ff, 0xa086, 0x001e,
5059 0x1138, 0x00de, 0x080c, 0x2148, 0x1904, 0x19e0, 0xa00e, 0x00b0,
5060 0x00de, 0x080c, 0x14f6, 0x7b22, 0x7a26, 0x7d32, 0x7c36, 0x7f3a,
5061 0x7e3e, 0x7902, 0x7000, 0x8000, 0x7002, 0x00de, 0x6828, 0xa300,
5062 0x682a, 0x682c, 0xa201, 0x682e, 0x080c, 0x2148, 0x0005, 0x080c,
5063 0x14f6, 0x080c, 0x1e1a, 0x7004, 0x2060, 0x00d6, 0x6010, 0x2068,
5064 0x7003, 0x0000, 0x080c, 0x1d22, 0x080c, 0x9596, 0x0170, 0x6808,
5065 0x8001, 0x680a, 0x697c, 0x6912, 0x6980, 0x6916, 0x682b, 0xffff,
5066 0x682f, 0xffff, 0x6850, 0xc0bd, 0x6852, 0x00de, 0x080c, 0x929c,
5067 0x0804, 0x1c5e, 0x080c, 0x14f6, 0x0126, 0x2091, 0x2200, 0x0006,
5068 0x0016, 0x2b68, 0x6818, 0x2060, 0x7904, 0x7803, 0x0002, 0xa184,
5069 0x0700, 0x1978, 0xa184, 0x0003, 0xa086, 0x0003, 0x0d58, 0x7000,
5070 0x0002, 0x1a89, 0x1a8f, 0x1b92, 0x1c39, 0x1c4d, 0x1a89, 0x1a89,
5071 0x1a89, 0x7804, 0xd09c, 0x1904, 0x1c5e, 0x080c, 0x14f6, 0x8001,
5072 0x7002, 0xa184, 0x0880, 0x1190, 0xd19c, 0x1904, 0x1b20, 0x8aff,
5073 0x0904, 0x1b20, 0x2009, 0x0001, 0x080c, 0x19e0, 0x0904, 0x1c5e,
5074 0x2009, 0x0001, 0x080c, 0x19e0, 0x0804, 0x1c5e, 0x7803, 0x0004,
5075 0x7003, 0x0000, 0xd1bc, 0x1904, 0x1b00, 0x0026, 0x0036, 0x7c20,
5076 0x7d24, 0x7e30, 0x7f34, 0x7818, 0x6812, 0x781c, 0x6816, 0x2001,
5077 0x0201, 0x2004, 0xa005, 0x0140, 0x7808, 0xd0ec, 0x1128, 0x7803,
5078 0x0009, 0x7003, 0x0004, 0x0010, 0x080c, 0x1c62, 0x6b28, 0x6a2c,
5079 0x2400, 0x686e, 0xa31a, 0x2500, 0x6872, 0xa213, 0x6b2a, 0x6a2e,
5080 0x00c6, 0x7004, 0x2060, 0x6020, 0xd0f4, 0x1110, 0x633a, 0x6236,
5081 0x00ce, 0x003e, 0x002e, 0x6e1e, 0x6f22, 0x080c, 0x215e, 0x2a00,
5082 0x6826, 0x2c00, 0x681a, 0x2800, 0x6832, 0x6850, 0xc0fd, 0x6852,
5083 0x6808, 0x8001, 0x680a, 0x1148, 0x684c, 0xd0e4, 0x0130, 0x7004,
5084 0x2060, 0x2009, 0x0048, 0x080c, 0x80a7, 0x7000, 0xa086, 0x0004,
5085 0x0904, 0x1c5e, 0x7003, 0x0000, 0x080c, 0x195f, 0x0804, 0x1c5e,
5086 0x0056, 0x7d0c, 0xd5bc, 0x1110, 0x080c, 0xac73, 0x005e, 0x080c,
5087 0x1d22, 0x00f6, 0x7004, 0x2078, 0x080c, 0x5029, 0x0118, 0x7820,
5088 0xc0f5, 0x7822, 0x00fe, 0x682b, 0xffff, 0x682f, 0xffff, 0x6808,
5089 0x8001, 0x680a, 0x697c, 0x791a, 0x6980, 0x791e, 0x0804, 0x1c5e,
5090 0x7004, 0x00c6, 0x2060, 0x6020, 0x00ce, 0xd0f4, 0x0128, 0x6808,
5091 0x8001, 0x680a, 0x0804, 0x1c5e, 0x7818, 0x6812, 0x7a1c, 0x6a16,
5092 0xd19c, 0x0160, 0xa205, 0x0150, 0x7004, 0xa080, 0x0007, 0x2004,
5093 0xa084, 0xfffd, 0xa086, 0x0008, 0x1904, 0x1aa6, 0x684c, 0xc0f5,
5094 0x684e, 0x7814, 0xa005, 0x1180, 0x7003, 0x0000, 0x6808, 0x8001,
5095 0x680a, 0x1130, 0x7004, 0x2060, 0x2009, 0x0048, 0x080c, 0x80a7,
5096 0x080c, 0x195f, 0x0804, 0x1c5e, 0x7818, 0x6812, 0x781c, 0x6816,
5097 0x7814, 0x7908, 0xa18c, 0x0fff, 0xa188, 0x0007, 0x8114, 0x8214,
5098 0x8214, 0xa10a, 0x8104, 0x8004, 0x8004, 0xa20a, 0x810b, 0x810b,
5099 0x810b, 0x080c, 0x1da5, 0x7803, 0x0004, 0x780f, 0xffff, 0x7803,
5100 0x0001, 0x7804, 0xd0fc, 0x0de8, 0x7803, 0x0002, 0x7803, 0x0004,
5101 0x780f, 0x00f6, 0x7004, 0x7007, 0x0000, 0x2060, 0x2009, 0x0048,
5102 0x080c, 0x80a7, 0x080c, 0x1dd7, 0x0958, 0x7908, 0xd1ec, 0x1118,
5103 0x2009, 0x0009, 0x0010, 0x2009, 0x0019, 0x7902, 0x7003, 0x0003,
5104 0x0804, 0x1c5e, 0x8001, 0x7002, 0xd194, 0x01a8, 0x7804, 0xd0fc,
5105 0x1904, 0x1c2c, 0xd09c, 0x0130, 0x7804, 0xd0fc, 0x1904, 0x1a74,
5106 0xd09c, 0x11a8, 0x8aff, 0x0904, 0x1c5e, 0x2009, 0x0001, 0x080c,
5107 0x19e0, 0x0804, 0x1c5e, 0xa184, 0x0888, 0x1148, 0x8aff, 0x0904,
5108 0x1c5e, 0x2009, 0x0001, 0x080c, 0x19e0, 0x0804, 0x1c5e, 0x7818,
5109 0x6812, 0x7a1c, 0x6a16, 0xa205, 0x0904, 0x1b3e, 0x7803, 0x0004,
5110 0x7003, 0x0000, 0xd1bc, 0x1904, 0x1c0f, 0x6834, 0xa084, 0x00ff,
5111 0xa086, 0x0029, 0x1118, 0xd19c, 0x1904, 0x1b3e, 0x0026, 0x0036,
5112 0x7c20, 0x7d24, 0x7e30, 0x7f34, 0x7818, 0x6812, 0x781c, 0x6816,
5113 0x2001, 0x0201, 0x2004, 0xa005, 0x0140, 0x7808, 0xd0ec, 0x1128,
5114 0x7803, 0x0009, 0x7003, 0x0004, 0x0020, 0x0016, 0x080c, 0x1c62,
5115 0x001e, 0x6b28, 0x6a2c, 0x080c, 0x215e, 0x00d6, 0x2805, 0xac68,
5116 0x6034, 0xd09c, 0x1128, 0x6808, 0xa31a, 0x680c, 0xa213, 0x0020,
5117 0x6810, 0xa31a, 0x6814, 0xa213, 0x00de, 0xd194, 0x0904, 0x1ac8,
5118 0x2a00, 0x6826, 0x2c00, 0x681a, 0x2800, 0x6832, 0x6808, 0x8001,
5119 0x680a, 0x6b2a, 0x6a2e, 0x003e, 0x002e, 0x0804, 0x1b50, 0x0056,
5120 0x7d0c, 0x080c, 0xac73, 0x005e, 0x080c, 0x1d22, 0x00f6, 0x7004,
5121 0x2078, 0x080c, 0x5029, 0x0118, 0x7820, 0xc0f5, 0x7822, 0x00fe,
5122 0x682b, 0xffff, 0x682f, 0xffff, 0x6808, 0x8001, 0x680a, 0x697c,
5123 0x791a, 0x6980, 0x791e, 0x0490, 0x7804, 0xd09c, 0x0904, 0x1a74,
5124 0x7c20, 0x7824, 0xa405, 0x1904, 0x1a74, 0x7803, 0x0002, 0x0804,
5125 0x1bb7, 0x7803, 0x0004, 0x7003, 0x0000, 0x7004, 0xa00d, 0x0150,
5126 0x6808, 0x8001, 0x680a, 0x1130, 0x7004, 0x2060, 0x2009, 0x0048,
5127 0x080c, 0x80a7, 0x080c, 0x195f, 0x0088, 0x7803, 0x0004, 0x7003,
5128 0x0000, 0x7004, 0x2060, 0x6010, 0xa005, 0x0da0, 0x2068, 0x6808,
5129 0x8000, 0x680a, 0x6c28, 0x6b2c, 0x080c, 0x197a, 0x001e, 0x000e,
5130 0x012e, 0x0005, 0x700c, 0x7110, 0xa106, 0x0904, 0x1ce1, 0x7004,
5131 0x0016, 0x210c, 0xa106, 0x001e, 0x0904, 0x1ce1, 0x00d6, 0x00c6,
5132 0x216c, 0x2d00, 0xa005, 0x0904, 0x1cdf, 0x6820, 0xd0d4, 0x1904,
5133 0x1cdf, 0x6810, 0x2068, 0x6850, 0xd0fc, 0x0558, 0x8108, 0x2104,
5134 0x6b2c, 0xa306, 0x1904, 0x1cdf, 0x8108, 0x2104, 0x6a28, 0xa206,
5135 0x1904, 0x1cdf, 0x6850, 0xc0fc, 0xc0f5, 0x6852, 0x686c, 0x7822,
5136 0x6870, 0x7826, 0x681c, 0x7832, 0x6820, 0x7836, 0x6818, 0x2060,
5137 0x6034, 0xd09c, 0x0150, 0x6830, 0x2005, 0x00d6, 0xac68, 0x6808,
5138 0x783a, 0x680c, 0x783e, 0x00de, 0x04a0, 0xa006, 0x783a, 0x783e,
5139 0x0480, 0x8108, 0x2104, 0xa005, 0x1590, 0x8108, 0x2104, 0xa005,
5140 0x1570, 0x6850, 0xc0f5, 0x6852, 0x6830, 0x2005, 0x6918, 0xa160,
5141 0xa180, 0x000d, 0x2004, 0xd09c, 0x1170, 0x6008, 0x7822, 0x686e,
5142 0x600c, 0x7826, 0x6872, 0x6000, 0x7832, 0x6004, 0x7836, 0xa006,
5143 0x783a, 0x783e, 0x0070, 0x6010, 0x7822, 0x686e, 0x6014, 0x7826,
5144 0x6872, 0x6000, 0x7832, 0x6004, 0x7836, 0x6008, 0x783a, 0x600c,
5145 0x783e, 0x6810, 0x781a, 0x6814, 0x781e, 0x7803, 0x0011, 0x00ce,
5146 0x00de, 0x0005, 0x2011, 0x0201, 0x2009, 0x003c, 0x2204, 0xa005,
5147 0x1118, 0x8109, 0x1dd8, 0x0005, 0x0005, 0x0ca1, 0x01e0, 0x7908,
5148 0xd1ec, 0x1160, 0x080c, 0x1dd7, 0x0148, 0x7803, 0x0009, 0x7904,
5149 0xd1fc, 0x0de8, 0x7803, 0x0006, 0x0c29, 0x0168, 0x780c, 0xd0a4,
5150 0x1150, 0x7007, 0x0000, 0x080c, 0x1dd7, 0x0140, 0x7803, 0x0019,
5151 0x7003, 0x0003, 0x0018, 0x00b1, 0xa085, 0x0001, 0x0005, 0x0126,
5152 0x2091, 0x2200, 0x7000, 0xa086, 0x0003, 0x1150, 0x700c, 0x7110,
5153 0xa106, 0x0130, 0x20e1, 0x9028, 0x700f, 0xb003, 0x7013, 0xb003,
5154 0x012e, 0x0005, 0x00c6, 0x080c, 0x574f, 0x1550, 0x2001, 0x0160,
5155 0x2003, 0x0000, 0x2001, 0x0138, 0x2003, 0x0000, 0x2011, 0x00c8,
5156 0xe000, 0xe000, 0x8211, 0x1de0, 0x080c, 0x1d7e, 0x700c, 0x7110,
5157 0xa106, 0x0190, 0x2104, 0xa005, 0x0130, 0x2060, 0x6010, 0x2060,
5158 0x6008, 0x8001, 0x600a, 0xa188, 0x0003, 0xa182, 0xb01e, 0x0210,
5159 0x2009, 0xb003, 0x7112, 0x0c50, 0x080c, 0x57d1, 0x00ce, 0x0005,
5160 0x04a9, 0x20e1, 0x9028, 0x700c, 0x7110, 0xa106, 0x01d0, 0x2104,
5161 0xa005, 0x0130, 0x2060, 0x6010, 0x2060, 0x6008, 0x8001, 0x600a,
5162 0xa188, 0x0003, 0xa182, 0xb01e, 0x0210, 0x2009, 0xb003, 0x7112,
5163 0x700c, 0xa106, 0x1d40, 0x080c, 0x2744, 0x2001, 0x0138, 0x2102,
5164 0x0c10, 0x2001, 0x015d, 0x200c, 0x810a, 0x2102, 0x2001, 0x0160,
5165 0x2502, 0x2001, 0x0138, 0x2202, 0x00ce, 0x0005, 0x20e1, 0x9028,
5166 0x2001, 0x015d, 0x200c, 0x810a, 0x2102, 0x0005, 0x2001, 0x0138,
5167 0x2014, 0x2003, 0x0000, 0x2001, 0x0160, 0x202c, 0x2003, 0x0000,
5168 0x2021, 0xb015, 0x2001, 0x0141, 0x201c, 0xd3dc, 0x1168, 0x2001,
5169 0x0109, 0x201c, 0xa39c, 0x0048, 0x1138, 0x2001, 0x0111, 0x201c,
5170 0x83ff, 0x1110, 0x8421, 0x1d70, 0x0005, 0x00e6, 0x2071, 0x0200,
5171 0x7808, 0xa084, 0xf000, 0xa10d, 0x08c9, 0x2019, 0x5000, 0x8319,
5172 0x0168, 0x2001, 0xb01e, 0x2004, 0xa086, 0x0000, 0x0138, 0x2001,
5173 0x0021, 0xd0fc, 0x0da0, 0x080c, 0x1ff4, 0x0c78, 0x20e1, 0x7000,
5174 0x7324, 0x7420, 0x7028, 0x7028, 0x7426, 0x7037, 0x0001, 0x810f,
5175 0x712e, 0x702f, 0x0100, 0x7037, 0x0008, 0x7326, 0x7422, 0x2001,
5176 0x0160, 0x2502, 0x2001, 0x0138, 0x2202, 0x00ee, 0x0005, 0x7908,
5177 0xa18c, 0x0fff, 0xa182, 0x0009, 0x0218, 0xa085, 0x0001, 0x0088,
5178 0x2001, 0x020a, 0x81ff, 0x0130, 0x20e1, 0x6000, 0x200c, 0x200c,
5179 0x200c, 0x200c, 0x20e1, 0x7000, 0x200c, 0x200c, 0x7003, 0x0000,
5180 0xa006, 0x0005, 0x00f6, 0x00e6, 0x0016, 0x0026, 0x2071, 0xaffd,
5181 0x2079, 0x0030, 0x2011, 0x0050, 0x7000, 0xa086, 0x0000, 0x01a8,
5182 0x8211, 0x0188, 0x2001, 0x0005, 0x2004, 0xd08c, 0x0dc8, 0x7904,
5183 0xa18c, 0x0780, 0x0016, 0x080c, 0x1a6c, 0x001e, 0x81ff, 0x1118,
5184 0x2011, 0x0050, 0x0c48, 0xa085, 0x0001, 0x002e, 0x001e, 0x00ee,
5185 0x00fe, 0x0005, 0x7803, 0x0004, 0x2009, 0x0064, 0x7804, 0xd0ac,
5186 0x0904, 0x1e66, 0x8109, 0x1dd0, 0x2009, 0x0100, 0x210c, 0xa18a,
5187 0x0003, 0x0a0c, 0x14f6, 0x080c, 0x20f2, 0x00e6, 0x00f6, 0x2071,
5188 0xafec, 0x2079, 0x0010, 0x7004, 0xa086, 0x0000, 0x0538, 0x7800,
5189 0x0006, 0x7820, 0x0006, 0x7830, 0x0006, 0x7834, 0x0006, 0x7838,
5190 0x0006, 0x783c, 0x0006, 0x7803, 0x0004, 0xe000, 0xe000, 0x2079,
5191 0x0030, 0x7804, 0xd0ac, 0x190c, 0x14f6, 0x2079, 0x0010, 0x000e,
5192 0x783e, 0x000e, 0x783a, 0x000e, 0x7836, 0x000e, 0x7832, 0x000e,
5193 0x7822, 0x000e, 0x7802, 0x00fe, 0x00ee, 0x0030, 0x00fe, 0x00ee,
5194 0x7804, 0xd0ac, 0x190c, 0x14f6, 0x080c, 0x6d0d, 0x0005, 0x00e6,
5195 0x2071, 0xb01e, 0x7003, 0x0000, 0x00ee, 0x0005, 0x00d6, 0xa280,
5196 0x0004, 0x206c, 0x694c, 0xd1dc, 0x1904, 0x1ee4, 0x6934, 0xa184,
5197 0x0007, 0x0002, 0x1e82, 0x1ecf, 0x1e82, 0x1e82, 0x1e82, 0x1eb6,
5198 0x1e95, 0x1e84, 0x080c, 0x14f6, 0x684c, 0xd0b4, 0x0904, 0x1fcc,
5199 0x6860, 0x682e, 0x6816, 0x685c, 0x682a, 0x6812, 0x687c, 0x680a,
5200 0x6880, 0x680e, 0x6958, 0x0804, 0x1ed7, 0x6834, 0xa084, 0x00ff,
5201 0xa086, 0x001e, 0x1d38, 0x684c, 0xd0b4, 0x0904, 0x1fcc, 0x6860,
5202 0x682e, 0x6816, 0x685c, 0x682a, 0x6812, 0x687c, 0x680a, 0x6880,
5203 0x680e, 0x6804, 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f,
5204 0xa080, 0x2186, 0x2005, 0x6832, 0x6958, 0x0450, 0xa18c, 0x00ff,
5205 0xa186, 0x0015, 0x1548, 0x684c, 0xd0b4, 0x0904, 0x1fcc, 0x6804,
5206 0x681a, 0xa080, 0x000d, 0x2004, 0xa084, 0x000f, 0xa080, 0x2186,
5207 0x2005, 0x6832, 0x6958, 0xa006, 0x682e, 0x682a, 0x0088, 0x684c,
5208 0xd0b4, 0x0904, 0x1a47, 0x6958, 0xa006, 0x682e, 0x682a, 0x2d00,
5209 0x681a, 0x6834, 0xa084, 0x000f, 0xa080, 0x2186, 0x2005, 0x6832,
5210 0x6926, 0x684c, 0xc0dd, 0x684e, 0x00de, 0x0005, 0x00f6, 0x2079,
5211 0x0020, 0x7804, 0xd0fc, 0x190c, 0x1ff4, 0x00e6, 0x00d6, 0x2071,
5212 0xb01e, 0x7000, 0xa005, 0x1904, 0x1f4c, 0x00c6, 0x7206, 0xa280,
5213 0x0004, 0x205c, 0x7004, 0x2068, 0x7803, 0x0004, 0x6818, 0x00d6,
5214 0x2068, 0x686c, 0x7812, 0x6890, 0x00f6, 0x20e1, 0x9040, 0x2079,
5215 0x0200, 0x781a, 0x2079, 0x0100, 0x8004, 0x78d6, 0x00fe, 0x00de,
5216 0x2b68, 0x6824, 0x2050, 0x6818, 0x2060, 0x6830, 0x2040, 0x6034,
5217 0xa0cc, 0x000f, 0x6908, 0x791a, 0x7116, 0x680c, 0x781e, 0x701a,
5218 0xa006, 0x700e, 0x7012, 0x7004, 0x692c, 0x6814, 0xa106, 0x1120,
5219 0x6928, 0x6810, 0xa106, 0x0158, 0x0036, 0x0046, 0x6b14, 0x6c10,
5220 0x080c, 0x21a6, 0x004e, 0x003e, 0x0110, 0x00ce, 0x00a8, 0x8aff,
5221 0x1120, 0x00ce, 0xa085, 0x0001, 0x0078, 0x0126, 0x2091, 0x8000,
5222 0x2079, 0x0020, 0x2009, 0x0001, 0x0059, 0x0118, 0x2009, 0x0001,
5223 0x0039, 0x012e, 0x00ce, 0xa006, 0x00de, 0x00ee, 0x00fe, 0x0005,
5224 0x0076, 0x0066, 0x0056, 0x0046, 0x0036, 0x0026, 0x8aff, 0x0904,
5225 0x1fc5, 0x700c, 0x7214, 0xa23a, 0x7010, 0x7218, 0xa203, 0x0a04,
5226 0x1fc4, 0xa705, 0x0904, 0x1fc4, 0xa03e, 0x2730, 0x6850, 0xd0fc,
5227 0x11a8, 0x00d6, 0x2805, 0xac68, 0x2900, 0x0002, 0x1fa7, 0x1f8c,
5228 0x1f8c, 0x1fa7, 0x1fa7, 0x1fa0, 0x1fa7, 0x1f8c, 0x1fa7, 0x1f91,
5229 0x1f91, 0x1fa7, 0x1fa7, 0x1fa7, 0x1f98, 0x1f91, 0xc0fc, 0x6852,
5230 0x6b6c, 0x6a70, 0x6d1c, 0x6c20, 0xd99c, 0x0528, 0x00d6, 0x2805,
5231 0xac68, 0x6f08, 0x6e0c, 0x00f0, 0x6b08, 0x6a0c, 0x6d00, 0x6c04,
5232 0x00c8, 0x6b10, 0x6a14, 0x6d00, 0x6c04, 0x6f08, 0x6e0c, 0x0090,
5233 0x00de, 0x00d6, 0x6834, 0xa084, 0x00ff, 0xa086, 0x001e, 0x1138,
5234 0x00de, 0x080c, 0x2148, 0x1904, 0x1f56, 0xa00e, 0x00f0, 0x00de,
5235 0x080c, 0x14f6, 0x00de, 0x7b22, 0x7a26, 0x7d32, 0x7c36, 0x7f3a,
5236 0x7e3e, 0x7902, 0x7000, 0x8000, 0x7002, 0x6828, 0xa300, 0x682a,
5237 0x682c, 0xa201, 0x682e, 0x700c, 0xa300, 0x700e, 0x7010, 0xa201,
5238 0x7012, 0x080c, 0x2148, 0x0008, 0xa006, 0x002e, 0x003e, 0x004e,
5239 0x005e, 0x006e, 0x007e, 0x0005, 0x080c, 0x14f6, 0x0026, 0x2001,
5240 0x0105, 0x2003, 0x0010, 0x20e1, 0x9040, 0x7803, 0x0004, 0x7003,
5241 0x0000, 0x7004, 0x2060, 0x00d6, 0x6010, 0x2068, 0x080c, 0x9596,
5242 0x0118, 0x6850, 0xc0bd, 0x6852, 0x00de, 0x080c, 0x929c, 0x20e1,
5243 0x9040, 0x080c, 0x7cb8, 0x2011, 0x0000, 0x080c, 0x7ae9, 0x080c,
5244 0x6d0d, 0x002e, 0x0804, 0x20ad, 0x0126, 0x2091, 0x2400, 0x0006,
5245 0x0016, 0x00f6, 0x00e6, 0x00d6, 0x00c6, 0x2079, 0x0020, 0x2071,
5246 0xb01e, 0x2b68, 0x6818, 0x2060, 0x7904, 0x7803, 0x0002, 0xa184,
5247 0x0700, 0x1920, 0x7000, 0x0002, 0x20ad, 0x2010, 0x2080, 0x20ab,
5248 0x8001, 0x7002, 0xd19c, 0x1170, 0x8aff, 0x05d0, 0x2009, 0x0001,
5249 0x080c, 0x1f50, 0x0904, 0x20ad, 0x2009, 0x0001, 0x080c, 0x1f50,
5250 0x0804, 0x20ad, 0x7803, 0x0004, 0xd194, 0x0148, 0x6850, 0xc0fc,
5251 0x6852, 0x8aff, 0x11d8, 0x684c, 0xc0f5, 0x684e, 0x00b8, 0x0026,
5252 0x0036, 0x6b28, 0x6a2c, 0x7820, 0x686e, 0xa31a, 0x7824, 0x6872,
5253 0xa213, 0x7830, 0x681e, 0x7834, 0x6822, 0x6b2a, 0x6a2e, 0x003e,
5254 0x002e, 0x080c, 0x215e, 0x6850, 0xc0fd, 0x6852, 0x2a00, 0x6826,
5255 0x2c00, 0x681a, 0x2800, 0x6832, 0x7003, 0x0000, 0x0804, 0x20ad,
5256 0x00f6, 0x0026, 0x781c, 0x0006, 0x7818, 0x0006, 0x2079, 0x0100,
5257 0x7a14, 0xa284, 0x0184, 0xa085, 0x0012, 0x7816, 0x0036, 0x2019,
5258 0x1000, 0x8319, 0x090c, 0x14f6, 0x7820, 0xd0bc, 0x1dd0, 0x003e,
5259 0x79c8, 0x000e, 0xa102, 0x001e, 0x0006, 0x0016, 0x79c4, 0x000e,
5260 0xa103, 0x78c6, 0x000e, 0x78ca, 0xa284, 0x0184, 0xa085, 0x0012,
5261 0x7816, 0x002e, 0x00fe, 0x7803, 0x0008, 0x7003, 0x0000, 0x0468,
5262 0x8001, 0x7002, 0xd194, 0x0168, 0x7804, 0xd0fc, 0x1904, 0x2004,
5263 0xd19c, 0x11f8, 0x8aff, 0x0508, 0x2009, 0x0001, 0x080c, 0x1f50,
5264 0x00e0, 0x0026, 0x0036, 0x6b28, 0x6a2c, 0x080c, 0x215e, 0x00d6,
5265 0x2805, 0xac68, 0x6034, 0xd09c, 0x1128, 0x6808, 0xa31a, 0x680c,
5266 0xa213, 0x0020, 0x6810, 0xa31a, 0x6814, 0xa213, 0x00de, 0x0804,
5267 0x2033, 0x0804, 0x202f, 0x080c, 0x14f6, 0x00ce, 0x00de, 0x00ee,
5268 0x00fe, 0x001e, 0x000e, 0x012e, 0x0005, 0x00f6, 0x00e6, 0x2071,
5269 0xb01e, 0x7000, 0xa086, 0x0000, 0x0590, 0x2079, 0x0020, 0x0016,
5270 0x2009, 0x0207, 0x210c, 0xd194, 0x0158, 0x2009, 0x020c, 0x210c,
5271 0xa184, 0x0003, 0x0128, 0x20e1, 0x9040, 0x2001, 0x020c, 0x2102,
5272 0x2009, 0x0206, 0x2104, 0x2009, 0x0203, 0x210c, 0xa106, 0x1110,
5273 0x20e1, 0x9040, 0x7804, 0xd0fc, 0x0d18, 0x080c, 0x1ff4, 0x7000,
5274 0xa086, 0x0000, 0x19e8, 0x001e, 0x7803, 0x0004, 0x7804, 0xd0ac,
5275 0x1de8, 0x20e1, 0x9040, 0x7803, 0x0002, 0x7003, 0x0000, 0x00ee,
5276 0x00fe, 0x0005, 0x0026, 0x00c6, 0x00d6, 0x00e6, 0x00f6, 0x2071,
5277 0xb01e, 0x2079, 0x0020, 0x7000, 0xa086, 0x0000, 0x0540, 0x7004,
5278 0x2060, 0x6010, 0x2068, 0x080c, 0x9596, 0x0158, 0x6850, 0xc0b5,
5279 0x6852, 0x680c, 0x7a1c, 0xa206, 0x1120, 0x6808, 0x7a18, 0xa206,
5280 0x01e0, 0x2001, 0x0105, 0x2003, 0x0010, 0x20e1, 0x9040, 0x7803,
5281 0x0004, 0x7003, 0x0000, 0x7004, 0x2060, 0x080c, 0x929c, 0x20e1,
5282 0x9040, 0x080c, 0x7cb8, 0x2011, 0x0000, 0x080c, 0x7ae9, 0x00fe,
5283 0x00ee, 0x00de, 0x00ce, 0x002e, 0x0005, 0x6810, 0x6a14, 0xa205,
5284 0x1d00, 0x684c, 0xc0dc, 0x684e, 0x2c10, 0x080c, 0x1e6e, 0x2001,
5285 0x0105, 0x2003, 0x0010, 0x20e1, 0x9040, 0x7803, 0x0004, 0x7003,
5286 0x0000, 0x2069, 0xafc7, 0x6833, 0x0000, 0x683f, 0x0000, 0x08f8,
5287 0x8840, 0x2805, 0xa005, 0x1170, 0x6004, 0xa005, 0x0168, 0x681a,
5288 0x2060, 0x6034, 0xa084, 0x000f, 0xa080, 0x2186, 0x2045, 0x88ff,
5289 0x090c, 0x14f6, 0x8a51, 0x0005, 0x2050, 0x0005, 0x8a50, 0x8841,
5290 0x2805, 0xa005, 0x1190, 0x2c00, 0xad06, 0x0120, 0x6000, 0xa005,
5291 0x1108, 0x2d00, 0x2060, 0x681a, 0x6034, 0xa084, 0x000f, 0xa080,
5292 0x2196, 0x2045, 0x88ff, 0x090c, 0x14f6, 0x0005, 0x0000, 0x0011,
5293 0x0015, 0x0019, 0x001d, 0x0021, 0x0025, 0x0029, 0x0000, 0x000f,
5294 0x0015, 0x001b, 0x0021, 0x0027, 0x0000, 0x0000, 0x0000, 0x217b,
5295 0x2177, 0x0000, 0x0000, 0x2185, 0x0000, 0x217b, 0x0000, 0x2182,
5296 0x217f, 0x0000, 0x0000, 0x0000, 0x2185, 0x2182, 0x0000, 0x217d,
5297 0x217d, 0x0000, 0x0000, 0x2185, 0x0000, 0x217d, 0x0000, 0x2183,
5298 0x2183, 0x0000, 0x0000, 0x0000, 0x2185, 0x2183, 0x00a6, 0x0096,
5299 0x0086, 0x6b2e, 0x6c2a, 0x6858, 0xa055, 0x0904, 0x2237, 0x2d60,
5300 0x6034, 0xa0cc, 0x000f, 0xa9c0, 0x2186, 0xa986, 0x0007, 0x0130,
5301 0xa986, 0x000e, 0x0118, 0xa986, 0x000f, 0x1120, 0x605c, 0xa422,
5302 0x6060, 0xa31a, 0x2805, 0xa045, 0x1140, 0x0310, 0x0804, 0x2237,
5303 0x6004, 0xa065, 0x0904, 0x2237, 0x0c18, 0x2805, 0xa005, 0x01a8,
5304 0xac68, 0xd99c, 0x1128, 0x6808, 0xa422, 0x680c, 0xa31b, 0x0020,
5305 0x6810, 0xa422, 0x6814, 0xa31b, 0x0620, 0x2300, 0xa405, 0x0150,
5306 0x8a51, 0x0904, 0x2237, 0x8840, 0x0c40, 0x6004, 0xa065, 0x0904,
5307 0x2237, 0x0830, 0x8a51, 0x0904, 0x2237, 0x8840, 0x2805, 0xa005,
5308 0x1158, 0x6004, 0xa065, 0x0904, 0x2237, 0x6034, 0xa0cc, 0x000f,
5309 0xa9c0, 0x2186, 0x2805, 0x2040, 0x2b68, 0x6850, 0xc0fc, 0x6852,
5310 0x0458, 0x8422, 0x8420, 0x831a, 0xa399, 0x0000, 0x00d6, 0x2b68,
5311 0x6c6e, 0x6b72, 0x00de, 0xd99c, 0x1168, 0x6908, 0x2400, 0xa122,
5312 0x690c, 0x2300, 0xa11b, 0x0a0c, 0x14f6, 0x6800, 0xa420, 0x6804,
5313 0xa319, 0x0060, 0x6910, 0x2400, 0xa122, 0x6914, 0x2300, 0xa11b,
5314 0x0a0c, 0x14f6, 0x6800, 0xa420, 0x6804, 0xa319, 0x2b68, 0x6c1e,
5315 0x6b22, 0x6850, 0xc0fd, 0x6852, 0x2c00, 0x681a, 0x2800, 0x6832,
5316 0x2a00, 0x6826, 0x000e, 0x000e, 0x000e, 0xa006, 0x0028, 0x008e,
5317 0x009e, 0x00ae, 0xa085, 0x0001, 0x0005, 0x2001, 0x0005, 0x2004,
5318 0xa084, 0x0007, 0x0002, 0x224b, 0x224c, 0x224f, 0x2252, 0x2257,
5319 0x225a, 0x225f, 0x2264, 0x0005, 0x080c, 0x1ff4, 0x0005, 0x080c,
5320 0x1a6c, 0x0005, 0x080c, 0x1a6c, 0x080c, 0x1ff4, 0x0005, 0x080c,
5321 0x16f8, 0x0005, 0x080c, 0x1ff4, 0x080c, 0x16f8, 0x0005, 0x080c,
5322 0x1a6c, 0x080c, 0x16f8, 0x0005, 0x080c, 0x1a6c, 0x080c, 0x1ff4,
5323 0x080c, 0x16f8, 0x0005, 0x0126, 0x2091, 0x2600, 0x2079, 0x0200,
5324 0x2071, 0xb280, 0x2069, 0xad00, 0x2009, 0x0004, 0x7912, 0x7817,
5325 0x0004, 0x080c, 0x2651, 0x781b, 0x0002, 0x20e1, 0x9080, 0x20e1,
5326 0x4000, 0x20a9, 0x0080, 0x782f, 0x0000, 0x1f04, 0x2283, 0x20e1,
5327 0x9080, 0x783b, 0x001f, 0x20e1, 0x8700, 0x012e, 0x0005, 0x0126,
5328 0x2091, 0x2600, 0x781c, 0xd0a4, 0x190c, 0x2335, 0xa084, 0x0007,
5329 0x0002, 0x22b3, 0x22a1, 0x22a4, 0x22a7, 0x22ac, 0x22ae, 0x22b0,
5330 0x22b2, 0x080c, 0x5fb7, 0x0078, 0x080c, 0x5ff0, 0x0060, 0x080c,
5331 0x5fb7, 0x080c, 0x5ff0, 0x0038, 0x0041, 0x0028, 0x0031, 0x0018,
5332 0x0021, 0x0008, 0x0011, 0x012e, 0x0005, 0x0006, 0x0016, 0x0026,
5333 0x7930, 0xa184, 0x0003, 0x0118, 0x20e1, 0x9040, 0x04a0, 0xa184,
5334 0x0030, 0x01e0, 0x6a00, 0xa286, 0x0003, 0x1108, 0x00a0, 0x080c,
5335 0x574f, 0x1178, 0x2001, 0xaf9e, 0x2003, 0x0001, 0x2001, 0xad00,
5336 0x2003, 0x0001, 0xa085, 0x0001, 0x080c, 0x5793, 0x080c, 0x569a,
5337 0x0010, 0x080c, 0x485e, 0x20e1, 0x9010, 0x00a8, 0xa184, 0x00c0,
5338 0x0168, 0x00e6, 0x0036, 0x0046, 0x0056, 0x2071, 0xaffd, 0x080c,
5339 0x1d22, 0x005e, 0x004e, 0x003e, 0x00ee, 0x0028, 0xa184, 0x0300,
5340 0x0110, 0x20e1, 0x9020, 0x7932, 0x002e, 0x001e, 0x000e, 0x0005,
5341 0x0016, 0x00e6, 0x00f6, 0x2071, 0xad00, 0x7128, 0x2001, 0xaf90,
5342 0x2102, 0x2001, 0xaf98, 0x2102, 0xa182, 0x0211, 0x1218, 0x2009,
5343 0x0008, 0x0400, 0xa182, 0x0259, 0x1218, 0x2009, 0x0007, 0x00d0,
5344 0xa182, 0x02c1, 0x1218, 0x2009, 0x0006, 0x00a0, 0xa182, 0x0349,
5345 0x1218, 0x2009, 0x0005, 0x0070, 0xa182, 0x0421, 0x1218, 0x2009,
5346 0x0004, 0x0040, 0xa182, 0x0581, 0x1218, 0x2009, 0x0003, 0x0010,
5347 0x2009, 0x0002, 0x2079, 0x0200, 0x7912, 0x7817, 0x0004, 0x080c,
5348 0x2651, 0x00fe, 0x00ee, 0x001e, 0x0005, 0x7938, 0x080c, 0x14f6,
5349 0x0126, 0x2091, 0x2800, 0x2061, 0x0100, 0x2071, 0xad00, 0x6024,
5350 0x6026, 0x6053, 0x0030, 0x080c, 0x2690, 0x6050, 0xa084, 0xfe7f,
5351 0x6052, 0x2009, 0x00ef, 0x6132, 0x6136, 0x080c, 0x26a0, 0x60e7,
5352 0x0000, 0x61ea, 0x60e3, 0x0008, 0x604b, 0xf7f7, 0x6043, 0x0000,
5353 0x602f, 0x0080, 0x602f, 0x0000, 0x6007, 0x0e9f, 0x601b, 0x001e,
5354 0x600f, 0x00ff, 0x2001, 0xaf8c, 0x2003, 0x00ff, 0x602b, 0x002f,
5355 0x012e, 0x0005, 0x2001, 0xad31, 0x2003, 0x0000, 0x2001, 0xad30,
5356 0x2003, 0x0001, 0x0005, 0x0126, 0x2091, 0x2800, 0x0006, 0x0016,
5357 0x0026, 0x6124, 0xa184, 0x1e2c, 0x1118, 0xa184, 0x0007, 0x002a,
5358 0xa195, 0x0004, 0xa284, 0x0007, 0x0002, 0x23a7, 0x238d, 0x2390,
5359 0x2393, 0x2398, 0x239a, 0x239e, 0x23a2, 0x080c, 0x6699, 0x00b8,
5360 0x080c, 0x6774, 0x00a0, 0x080c, 0x6774, 0x080c, 0x6699, 0x0078,
5361 0x0099, 0x0068, 0x080c, 0x6699, 0x0079, 0x0048, 0x080c, 0x6774,
5362 0x0059, 0x0028, 0x080c, 0x6774, 0x080c, 0x6699, 0x0029, 0x002e,
5363 0x001e, 0x000e, 0x012e, 0x0005, 0x6124, 0xd19c, 0x1904, 0x25bf,
5364 0x080c, 0x574f, 0x0578, 0x7000, 0xa086, 0x0003, 0x0198, 0x6024,
5365 0xa084, 0x1800, 0x0178, 0x080c, 0x5775, 0x0118, 0x080c, 0x5761,
5366 0x1148, 0x6027, 0x0020, 0x6043, 0x0000, 0x2001, 0xaf9d, 0x2003,
5367 0xaaaa, 0x0458, 0x080c, 0x5775, 0x15d0, 0x6024, 0xa084, 0x1800,
5368 0x1108, 0x04a8, 0x2001, 0xaf9d, 0x2003, 0xaaaa, 0x2001, 0xaf9e,
5369 0x2003, 0x0001, 0x2001, 0xad00, 0x2003, 0x0001, 0x080c, 0x569a,
5370 0x0804, 0x25bf, 0xd1ac, 0x1518, 0x6024, 0xd0dc, 0x1170, 0xd0e4,
5371 0x1188, 0xd0d4, 0x11a0, 0xd0cc, 0x0130, 0x7088, 0xa086, 0x0028,
5372 0x1110, 0x080c, 0x58da, 0x0804, 0x25bf, 0x2001, 0xaf9e, 0x2003,
5373 0x0000, 0x0048, 0x2001, 0xaf9e, 0x2003, 0x0002, 0x0020, 0x080c,
5374 0x584d, 0x0804, 0x25bf, 0x080c, 0x597a, 0x0804, 0x25bf, 0xd1ac,
5375 0x0904, 0x2507, 0x080c, 0x574f, 0x11d8, 0x6027, 0x0020, 0x0006,
5376 0x0026, 0x0036, 0x080c, 0x576b, 0x1170, 0x2001, 0xaf9e, 0x2003,
5377 0x0001, 0x2001, 0xad00, 0x2003, 0x0001, 0x080c, 0x569a, 0x003e,
5378 0x002e, 0x000e, 0x0005, 0x003e, 0x002e, 0x000e, 0x080c, 0x5726,
5379 0x0016, 0x0046, 0x00c6, 0x644c, 0xa486, 0xf0f0, 0x1138, 0x2061,
5380 0x0100, 0x644a, 0x6043, 0x0090, 0x6043, 0x0010, 0x74ca, 0xa48c,
5381 0xff00, 0x7034, 0xd084, 0x0178, 0xa186, 0xf800, 0x1160, 0x7038,
5382 0xd084, 0x1148, 0xc085, 0x703a, 0x0036, 0x2418, 0x2011, 0x8016,
5383 0x080c, 0x3c5c, 0x003e, 0xa196, 0xff00, 0x05b8, 0x7050, 0xa084,
5384 0x00ff, 0x810f, 0xa116, 0x0588, 0x7130, 0xd184, 0x1570, 0x2011,
5385 0xad52, 0x2214, 0xd2ec, 0x0138, 0xc18d, 0x7132, 0x2011, 0xad52,
5386 0x2214, 0xd2ac, 0x1510, 0x6240, 0xa294, 0x0010, 0x0130, 0x6248,
5387 0xa294, 0xff00, 0xa296, 0xff00, 0x01c0, 0x7030, 0xd08c, 0x0904,
5388 0x24d2, 0x7034, 0xd08c, 0x1140, 0x2001, 0xad0c, 0x200c, 0xd1ac,
5389 0x1904, 0x24d2, 0xc1ad, 0x2102, 0x0036, 0x73c8, 0x2011, 0x8013,
5390 0x080c, 0x3c5c, 0x003e, 0x0804, 0x24d2, 0x7034, 0xd08c, 0x1140,
5391 0x2001, 0xad0c, 0x200c, 0xd1ac, 0x1904, 0x24d2, 0xc1ad, 0x2102,
5392 0x0036, 0x73c8, 0x2011, 0x8013, 0x080c, 0x3c5c, 0x003e, 0x7130,
5393 0xc185, 0x7132, 0x2011, 0xad52, 0x220c, 0xd1a4, 0x01d0, 0x0016,
5394 0x2009, 0x0001, 0x2011, 0x0100, 0x080c, 0x663f, 0x2019, 0x000e,
5395 0x080c, 0xa8eb, 0xa484, 0x00ff, 0xa080, 0x2be6, 0x200d, 0xa18c,
5396 0xff00, 0x810f, 0x8127, 0xa006, 0x2009, 0x000e, 0x080c, 0xa96c,
5397 0x001e, 0xd1ac, 0x1148, 0x0016, 0x2009, 0x0000, 0x2019, 0x0004,
5398 0x080c, 0x2aac, 0x001e, 0x0070, 0x0156, 0x20a9, 0x007f, 0x2009,
5399 0x0000, 0x080c, 0x4cdc, 0x1110, 0x080c, 0x493a, 0x8108, 0x1f04,
5400 0x24c9, 0x015e, 0x00ce, 0x004e, 0x2011, 0x0003, 0x080c, 0x7adf,
5401 0x2011, 0x0002, 0x080c, 0x7ae9, 0x080c, 0x79e1, 0x080c, 0x6581,
5402 0x0036, 0x2019, 0x0000, 0x080c, 0x7a64, 0x003e, 0x60e3, 0x0000,
5403 0x001e, 0x2001, 0xad00, 0x2014, 0xa296, 0x0004, 0x1128, 0xd19c,
5404 0x1118, 0x6228, 0xc29d, 0x622a, 0x2003, 0x0001, 0x2001, 0xad22,
5405 0x2003, 0x0000, 0x6027, 0x0020, 0x080c, 0x5775, 0x1140, 0x0016,
5406 0x2009, 0x07d0, 0x2011, 0x567b, 0x080c, 0x6593, 0x001e, 0xd194,
5407 0x0904, 0x25bf, 0x0016, 0x6220, 0xd2b4, 0x0904, 0x2570, 0x080c,
5408 0x6581, 0x080c, 0x7834, 0x6027, 0x0004, 0x00f6, 0x2019, 0xafd0,
5409 0x2304, 0xa07d, 0x0570, 0x7804, 0xa086, 0x0032, 0x1550, 0x00d6,
5410 0x00c6, 0x00e6, 0x2069, 0x0140, 0x618c, 0x6288, 0x7818, 0x608e,
5411 0x7808, 0x608a, 0x6043, 0x0002, 0x2001, 0x0003, 0x8001, 0x1df0,
5412 0x6043, 0x0000, 0x6803, 0x1000, 0x6803, 0x0000, 0x618e, 0x628a,
5413 0x080c, 0x6b73, 0x080c, 0x6c50, 0x7810, 0x2070, 0x7037, 0x0103,
5414 0x2f60, 0x080c, 0x8078, 0x00ee, 0x00ce, 0x00de, 0x00fe, 0x001e,
5415 0x0005, 0x00fe, 0x00d6, 0x2069, 0x0140, 0x6804, 0xa084, 0x4000,
5416 0x0120, 0x6803, 0x1000, 0x6803, 0x0000, 0x00de, 0x00c6, 0x2061,
5417 0xafc7, 0x6028, 0xa09a, 0x00c8, 0x1238, 0x8000, 0x602a, 0x00ce,
5418 0x080c, 0x7827, 0x0804, 0x25be, 0x2019, 0xafd0, 0x2304, 0xa065,
5419 0x0120, 0x2009, 0x0027, 0x080c, 0x80a7, 0x00ce, 0x0804, 0x25be,
5420 0xd2bc, 0x0904, 0x25be, 0x080c, 0x658e, 0x6014, 0xa084, 0x0184,
5421 0xa085, 0x0010, 0x6016, 0x6027, 0x0004, 0x00d6, 0x2069, 0x0140,
5422 0x6804, 0xa084, 0x4000, 0x0120, 0x6803, 0x1000, 0x6803, 0x0000,
5423 0x00de, 0x00c6, 0x2061, 0xafc7, 0x6044, 0xa09a, 0x00c8, 0x12f0,
5424 0x8000, 0x6046, 0x603c, 0x00ce, 0xa005, 0x0540, 0x2009, 0x07d0,
5425 0x080c, 0x6586, 0xa080, 0x0007, 0x2004, 0xa086, 0x0006, 0x1138,
5426 0x6114, 0xa18c, 0x0184, 0xa18d, 0x0012, 0x6116, 0x00b8, 0x6114,
5427 0xa18c, 0x0184, 0xa18d, 0x0016, 0x6116, 0x0080, 0x0036, 0x2019,
5428 0x0001, 0x080c, 0x7a64, 0x003e, 0x2019, 0xafd6, 0x2304, 0xa065,
5429 0x0120, 0x2009, 0x004f, 0x080c, 0x80a7, 0x00ce, 0x001e, 0xd19c,
5430 0x0904, 0x261a, 0x7034, 0xd0ac, 0x1560, 0x0016, 0x0156, 0x6027,
5431 0x0008, 0x602f, 0x0020, 0x20a9, 0x0006, 0x1d04, 0x25cd, 0x2091,
5432 0x6000, 0x1f04, 0x25cd, 0x602f, 0x0000, 0x6150, 0xa185, 0x1400,
5433 0x6052, 0x20a9, 0x0366, 0x1d04, 0x25db, 0x2091, 0x6000, 0x6020,
5434 0xd09c, 0x1130, 0x015e, 0x6152, 0x001e, 0x6027, 0x0008, 0x0490,
5435 0x080c, 0x2760, 0x1f04, 0x25db, 0x015e, 0x6152, 0x001e, 0x6027,
5436 0x0008, 0x0016, 0x6028, 0xc09c, 0x602a, 0x2011, 0x0003, 0x080c,
5437 0x7adf, 0x2011, 0x0002, 0x080c, 0x7ae9, 0x080c, 0x79e1, 0x080c,
5438 0x6581, 0x0036, 0x2019, 0x0000, 0x080c, 0x7a64, 0x003e, 0x60e3,
5439 0x0000, 0x080c, 0xac8d, 0x080c, 0xaca8, 0xa085, 0x0001, 0x080c,
5440 0x5793, 0x2001, 0xad00, 0x2003, 0x0004, 0x6027, 0x0008, 0x080c,
5441 0x12cc, 0x001e, 0xa18c, 0xffd0, 0x6126, 0x0005, 0x0006, 0x0016,
5442 0x0026, 0x00e6, 0x00f6, 0x0126, 0x2091, 0x8000, 0x2071, 0xad00,
5443 0x71c0, 0x70c2, 0xa116, 0x01f0, 0x81ff, 0x0128, 0x2011, 0x8011,
5444 0x080c, 0x3c5c, 0x00b8, 0x2011, 0x8012, 0x080c, 0x3c5c, 0x2001,
5445 0xad71, 0x2004, 0xd0fc, 0x1170, 0x0036, 0x00c6, 0x080c, 0x26eb,
5446 0x2061, 0x0100, 0x2019, 0x0028, 0x2009, 0x0000, 0x080c, 0x2aac,
5447 0x00ce, 0x003e, 0x012e, 0x00fe, 0x00ee, 0x002e, 0x001e, 0x000e,
5448 0x0005, 0x00c6, 0x00f6, 0x0006, 0x0026, 0x2061, 0x0100, 0xa190,
5449 0x2664, 0x2205, 0x60f2, 0x2011, 0x2671, 0x2205, 0x60ee, 0x002e,
5450 0x000e, 0x00fe, 0x00ce, 0x0005, 0x0840, 0x0840, 0x0840, 0x0580,
5451 0x0420, 0x0348, 0x02c0, 0x0258, 0x0210, 0x01a8, 0x01a8, 0x01a8,
5452 0x01a8, 0x0140, 0x00f8, 0x00d0, 0x00b0, 0x00a0, 0x2028, 0xa18c,
5453 0x00ff, 0x2130, 0xa094, 0xff00, 0x1110, 0x81ff, 0x0118, 0x080c,
5454 0x6278, 0x0038, 0xa080, 0x2be6, 0x200d, 0xa18c, 0xff00, 0x810f,
5455 0xa006, 0x0005, 0xa080, 0x2be6, 0x200d, 0xa18c, 0x00ff, 0x0005,
5456 0x00d6, 0x2069, 0x0140, 0x2001, 0xad14, 0x2003, 0x00ef, 0x20a9,
5457 0x0010, 0xa006, 0x6852, 0x6856, 0x1f04, 0x269b, 0x00de, 0x0005,
5458 0x0006, 0x00d6, 0x0026, 0x2069, 0x0140, 0x2001, 0xad14, 0x2102,
5459 0x8114, 0x8214, 0x8214, 0x8214, 0x20a9, 0x0010, 0x6853, 0x0000,
5460 0xa006, 0x82ff, 0x1128, 0xa184, 0x000f, 0xa080, 0xacae, 0x2005,
5461 0x6856, 0x8211, 0x1f04, 0x26b0, 0x002e, 0x00de, 0x000e, 0x0005,
5462 0x00c6, 0x2061, 0xad00, 0x6030, 0x0110, 0xc09d, 0x0008, 0xc09c,
5463 0x6032, 0x00ce, 0x0005, 0x0156, 0x00d6, 0x0026, 0x0016, 0x0006,
5464 0x2069, 0x0140, 0x6980, 0xa116, 0x0180, 0xa112, 0x1230, 0x8212,
5465 0x8210, 0x22a8, 0x2001, 0x0402, 0x0018, 0x22a8, 0x2001, 0x0404,
5466 0x680e, 0x1f04, 0x26e0, 0x680f, 0x0000, 0x000e, 0x001e, 0x002e,
5467 0x00de, 0x015e, 0x0005, 0x2001, 0xad52, 0x2004, 0xd0c4, 0x0150,
5468 0xd0a4, 0x0140, 0xa006, 0x0046, 0x2020, 0x2009, 0x002e, 0x080c,
5469 0xa96c, 0x004e, 0x0005, 0x00f6, 0x0016, 0x0026, 0x2079, 0x0140,
5470 0x78c4, 0xd0dc, 0x0548, 0xa084, 0x0700, 0xa08e, 0x0300, 0x1520,
5471 0x2011, 0x0000, 0x2009, 0x0002, 0x2300, 0xa080, 0x0020, 0x2018,
5472 0x2300, 0x080c, 0x6665, 0x2011, 0x0030, 0x2200, 0x8007, 0xa085,
5473 0x004c, 0x78c2, 0x2009, 0x0204, 0x210c, 0x2200, 0xa100, 0x2009,
5474 0x0138, 0x200a, 0x080c, 0x574f, 0x1118, 0x2009, 0xaf8e, 0x200a,
5475 0x002e, 0x001e, 0x00fe, 0x0005, 0x78c3, 0x0000, 0x0cc8, 0x0126,
5476 0x2091, 0x2800, 0x0006, 0x0016, 0x0026, 0x2001, 0x0170, 0x200c,
5477 0x8000, 0x2014, 0xa184, 0x0003, 0x0110, 0x0804, 0x1a6a, 0x002e,
5478 0x001e, 0x000e, 0x012e, 0x0005, 0x0006, 0x2001, 0x0100, 0x2004,
5479 0xa082, 0x0005, 0x000e, 0x0268, 0x2001, 0x0170, 0x200c, 0xa18c,
5480 0x00ff, 0xa18e, 0x004c, 0x1128, 0x200c, 0xa18c, 0xff00, 0x810f,
5481 0x0010, 0x2009, 0x0000, 0x2001, 0x0204, 0x2004, 0xa108, 0x0005,
5482 0x0006, 0x0156, 0x00f6, 0x2079, 0x0100, 0x20a9, 0x000a, 0x7854,
5483 0xd08c, 0x1110, 0x1f04, 0x2767, 0x00fe, 0x015e, 0x000e, 0x0005,
5484 0x0016, 0x00c6, 0x0006, 0x2061, 0x0100, 0x6030, 0x0006, 0x6048,
5485 0x0006, 0x60e4, 0x0006, 0x60e8, 0x0006, 0x6050, 0x0006, 0x60f0,
5486 0x0006, 0x60ec, 0x0006, 0x600c, 0x0006, 0x6004, 0x0006, 0x6028,
5487 0x0006, 0x60e0, 0x0006, 0x602f, 0x0100, 0x602f, 0x0000, 0xe000,
5488 0xe000, 0xe000, 0xe000, 0x602f, 0x0040, 0x602f, 0x0000, 0x000e,
5489 0x60e2, 0x000e, 0x602a, 0x000e, 0x6006, 0x000e, 0x600e, 0x000e,
5490 0x60ee, 0x000e, 0x60f2, 0x000e, 0x6052, 0x000e, 0x60ea, 0x000e,
5491 0x60e6, 0x000e, 0x604a, 0x000e, 0x6032, 0x6036, 0x2008, 0x080c,
5492 0x26a0, 0x000e, 0x00ce, 0x001e, 0x0005, 0x2845, 0x2849, 0x284d,
5493 0x2853, 0x2859, 0x285f, 0x2865, 0x286d, 0x2875, 0x287b, 0x2881,
5494 0x2889, 0x2891, 0x2899, 0x28a1, 0x28ab, 0x28b5, 0x28b5, 0x28b5,
5495 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5496 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5497 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5498 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5499 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5500 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b7, 0x28b7, 0x28bc,
5501 0x28bc, 0x28c3, 0x28c3, 0x28ca, 0x28ca, 0x28d3, 0x28d3, 0x28da,
5502 0x28da, 0x28e3, 0x28e3, 0x28ec, 0x28ec, 0x28b5, 0x28b5, 0x28b5,
5503 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5504 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5505 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5506 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5507 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5508 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5509 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5,
5510 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x28b5, 0x0106, 0x0006, 0x0804,
5511 0x28f7, 0x0106, 0x0006, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c,
5512 0x2373, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c, 0x2373, 0x0804,
5513 0x28f7, 0x0106, 0x0006, 0x080c, 0x223d, 0x0804, 0x28f7, 0x0106,
5514 0x0006, 0x080c, 0x223d, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c,
5515 0x2373, 0x080c, 0x223d, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c,
5516 0x2373, 0x080c, 0x223d, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c,
5517 0x228f, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c, 0x228f, 0x0804,
5518 0x28f7, 0x0106, 0x0006, 0x080c, 0x2373, 0x080c, 0x228f, 0x0804,
5519 0x28f7, 0x0106, 0x0006, 0x080c, 0x2373, 0x080c, 0x228f, 0x0804,
5520 0x28f7, 0x0106, 0x0006, 0x080c, 0x223d, 0x080c, 0x228f, 0x0804,
5521 0x28f7, 0x0106, 0x0006, 0x080c, 0x223d, 0x080c, 0x228f, 0x0804,
5522 0x28f7, 0x0106, 0x0006, 0x080c, 0x2373, 0x080c, 0x223d, 0x080c,
5523 0x228f, 0x0804, 0x28f7, 0x0106, 0x0006, 0x080c, 0x2373, 0x080c,
5524 0x223d, 0x080c, 0x228f, 0x0804, 0x28f7, 0xe000, 0x0cf0, 0x0106,
5525 0x0006, 0x080c, 0x272f, 0x04d8, 0x0106, 0x0006, 0x080c, 0x272f,
5526 0x080c, 0x2373, 0x04a0, 0x0106, 0x0006, 0x080c, 0x272f, 0x080c,
5527 0x223d, 0x0468, 0x0106, 0x0006, 0x080c, 0x272f, 0x080c, 0x2373,
5528 0x080c, 0x223d, 0x0420, 0x0106, 0x0006, 0x080c, 0x272f, 0x080c,
5529 0x228f, 0x00e8, 0x0106, 0x0006, 0x080c, 0x272f, 0x080c, 0x2373,
5530 0x080c, 0x228f, 0x00a0, 0x0106, 0x0006, 0x080c, 0x272f, 0x080c,
5531 0x223d, 0x080c, 0x228f, 0x0058, 0x0106, 0x0006, 0x080c, 0x272f,
5532 0x080c, 0x2373, 0x080c, 0x223d, 0x080c, 0x228f, 0x0000, 0x000e,
5533 0x010e, 0x000d, 0x00c6, 0x0026, 0x0046, 0x2021, 0x0000, 0x080c,
5534 0x502d, 0x1904, 0x29d4, 0x72d0, 0x2001, 0xaf9d, 0x2004, 0xa005,
5535 0x1110, 0xd29c, 0x0148, 0xd284, 0x1138, 0xd2bc, 0x1904, 0x29d4,
5536 0x080c, 0x29d8, 0x0804, 0x29d4, 0x080c, 0x574f, 0x1120, 0x709b,
5537 0xffff, 0x0804, 0x29d4, 0xd294, 0x0120, 0x709b, 0xffff, 0x0804,
5538 0x29d4, 0x2001, 0xad14, 0x203c, 0x7284, 0xd284, 0x0904, 0x2976,
5539 0xd28c, 0x1904, 0x2976, 0x0036, 0x7398, 0xa38e, 0xffff, 0x1110,
5540 0x2019, 0x0001, 0x8314, 0xa2e0, 0xb3c0, 0x2c04, 0xa38c, 0x0001,
5541 0x0120, 0xa084, 0xff00, 0x8007, 0x0010, 0xa084, 0x00ff, 0xa70e,
5542 0x0560, 0xa08e, 0x0000, 0x0548, 0xa08e, 0x00ff, 0x1150, 0x7230,
5543 0xd284, 0x1538, 0x7284, 0xc28d, 0x7286, 0x709b, 0xffff, 0x003e,
5544 0x0428, 0x2009, 0x0000, 0x080c, 0x2676, 0x080c, 0x4c80, 0x11b8,
5545 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x1150, 0x7030, 0xd08c,
5546 0x0118, 0x6000, 0xd0bc, 0x0120, 0x080c, 0x29eb, 0x0140, 0x0028,
5547 0x080c, 0x2b1a, 0x080c, 0x2a19, 0x0110, 0x8318, 0x0818, 0x739a,
5548 0x0010, 0x709b, 0xffff, 0x003e, 0x0804, 0x29d4, 0xa780, 0x2be6,
5549 0x203d, 0xa7bc, 0xff00, 0x873f, 0x2041, 0x007e, 0x7098, 0xa096,
5550 0xffff, 0x1120, 0x2009, 0x0000, 0x28a8, 0x0050, 0xa812, 0x0220,
5551 0x2008, 0xa802, 0x20a8, 0x0020, 0x709b, 0xffff, 0x0804, 0x29d4,
5552 0x2700, 0x0156, 0x0016, 0xa106, 0x05a0, 0xc484, 0x080c, 0x4cdc,
5553 0x0120, 0x080c, 0x4c80, 0x15a8, 0x0008, 0xc485, 0x6004, 0xa084,
5554 0x00ff, 0xa086, 0x0006, 0x1130, 0x7030, 0xd08c, 0x01e8, 0x6000,
5555 0xd0bc, 0x11d0, 0x7284, 0xd28c, 0x0188, 0x6004, 0xa084, 0x00ff,
5556 0xa082, 0x0006, 0x02b0, 0xd484, 0x1118, 0x080c, 0x4c9f, 0x0028,
5557 0x080c, 0x2b9c, 0x0170, 0x080c, 0x2bc9, 0x0058, 0x080c, 0x2b1a,
5558 0x080c, 0x2a19, 0x0170, 0x0028, 0x080c, 0x2b9c, 0x0110, 0x0419,
5559 0x0140, 0x001e, 0x8108, 0x015e, 0x1f04, 0x2990, 0x709b, 0xffff,
5560 0x0018, 0x001e, 0x015e, 0x719a, 0x004e, 0x002e, 0x00ce, 0x0005,
5561 0x00c6, 0x0016, 0x709b, 0x0000, 0x2009, 0x007e, 0x080c, 0x4c80,
5562 0x1138, 0x080c, 0x2b1a, 0x04a9, 0x0118, 0x70d0, 0xc0bd, 0x70d2,
5563 0x001e, 0x00ce, 0x0005, 0x0016, 0x0076, 0x00d6, 0x00c6, 0x2c68,
5564 0x2001, 0xad56, 0x2004, 0xa084, 0x00ff, 0x6842, 0x080c, 0x9807,
5565 0x01d8, 0x2d00, 0x601a, 0x080c, 0x9956, 0x601f, 0x0001, 0x2001,
5566 0x0000, 0x080c, 0x4c1e, 0x2001, 0x0000, 0x080c, 0x4c30, 0x0126,
5567 0x2091, 0x8000, 0x7094, 0x8000, 0x7096, 0x012e, 0x2009, 0x0004,
5568 0x080c, 0x80a7, 0xa085, 0x0001, 0x00ce, 0x00de, 0x007e, 0x001e,
5569 0x0005, 0x0016, 0x0076, 0x00d6, 0x00c6, 0x2c68, 0x2001, 0xad56,
5570 0x2004, 0xa084, 0x00ff, 0x6842, 0x080c, 0x9807, 0x0550, 0x2d00,
5571 0x601a, 0x6800, 0xc0c4, 0x6802, 0x68a0, 0xa086, 0x007e, 0x0140,
5572 0x6804, 0xa084, 0x00ff, 0xa086, 0x0006, 0x1110, 0x080c, 0x2ad9,
5573 0x080c, 0x9956, 0x601f, 0x0001, 0x2001, 0x0000, 0x080c, 0x4c1e,
5574 0x2001, 0x0002, 0x080c, 0x4c30, 0x0126, 0x2091, 0x8000, 0x7094,
5575 0x8000, 0x7096, 0x012e, 0x2009, 0x0002, 0x080c, 0x80a7, 0xa085,
5576 0x0001, 0x00ce, 0x00de, 0x007e, 0x001e, 0x0005, 0x00c6, 0x0026,
5577 0x2009, 0x0080, 0x080c, 0x4c80, 0x1120, 0x0031, 0x0110, 0x70d7,
5578 0xffff, 0x002e, 0x00ce, 0x0005, 0x0016, 0x0076, 0x00d6, 0x00c6,
5579 0x2c68, 0x080c, 0x8022, 0x01d8, 0x2d00, 0x601a, 0x080c, 0x9956,
5580 0x601f, 0x0001, 0x2001, 0x0000, 0x080c, 0x4c1e, 0x2001, 0x0002,
5581 0x080c, 0x4c30, 0x0126, 0x2091, 0x8000, 0x70d8, 0x8000, 0x70da,
5582 0x012e, 0x2009, 0x0002, 0x080c, 0x80a7, 0xa085, 0x0001, 0x00ce,
5583 0x00de, 0x007e, 0x001e, 0x0005, 0x00c6, 0x00d6, 0x0126, 0x2091,
5584 0x8000, 0x2009, 0x007f, 0x080c, 0x4c80, 0x1190, 0x2c68, 0x080c,
5585 0x8022, 0x0170, 0x2d00, 0x601a, 0x6312, 0x601f, 0x0001, 0x620a,
5586 0x080c, 0x9956, 0x2009, 0x0022, 0x080c, 0x80a7, 0xa085, 0x0001,
5587 0x012e, 0x00de, 0x00ce, 0x0005, 0x00e6, 0x00c6, 0x0066, 0x0036,
5588 0x0026, 0x080c, 0x68f3, 0x080c, 0x689d, 0x080c, 0x8a15, 0x2130,
5589 0x81ff, 0x0128, 0x20a9, 0x007e, 0x2009, 0x0000, 0x0020, 0x20a9,
5590 0x007f, 0x2009, 0x0000, 0x0016, 0x080c, 0x4cdc, 0x1120, 0x080c,
5591 0x4ecf, 0x080c, 0x493a, 0x001e, 0x8108, 0x1f04, 0x2ac3, 0x86ff,
5592 0x1110, 0x080c, 0x11d4, 0x002e, 0x003e, 0x006e, 0x00ce, 0x00ee,
5593 0x0005, 0x00e6, 0x00c6, 0x0036, 0x0026, 0x0016, 0x6218, 0x2270,
5594 0x72a0, 0x0026, 0x2019, 0x0029, 0x080c, 0x68e7, 0x0076, 0x2039,
5595 0x0000, 0x080c, 0x681d, 0x2c08, 0x080c, 0xa712, 0x007e, 0x001e,
5596 0x2e60, 0x080c, 0x4ecf, 0x6210, 0x6314, 0x080c, 0x493a, 0x6212,
5597 0x6316, 0x001e, 0x002e, 0x003e, 0x00ce, 0x00ee, 0x0005, 0x00e6,
5598 0x0006, 0x6018, 0xa080, 0x0028, 0x2004, 0xa086, 0x0080, 0x0150,
5599 0x2071, 0xad00, 0x7094, 0xa005, 0x0110, 0x8001, 0x7096, 0x000e,
5600 0x00ee, 0x0005, 0x2071, 0xad00, 0x70d8, 0xa005, 0x0dc0, 0x8001,
5601 0x70da, 0x0ca8, 0x6000, 0xc08c, 0x6002, 0x0005, 0x00f6, 0x00e6,
5602 0x00c6, 0x0036, 0x0026, 0x0016, 0x0156, 0x2178, 0x81ff, 0x1118,
5603 0x20a9, 0x0001, 0x0098, 0x2001, 0xad52, 0x2004, 0xd0c4, 0x0150,
5604 0xd0a4, 0x0140, 0xa006, 0x0046, 0x2020, 0x2009, 0x002d, 0x080c,
5605 0xa96c, 0x004e, 0x20a9, 0x00ff, 0x2011, 0x0000, 0x0026, 0xa28e,
5606 0x007e, 0x05c8, 0xa28e, 0x007f, 0x05b0, 0xa28e, 0x0080, 0x0598,
5607 0xa288, 0xae34, 0x210c, 0x81ff, 0x0570, 0x8fff, 0x05c1, 0x00c6,
5608 0x2160, 0x2001, 0x0001, 0x080c, 0x5037, 0x00ce, 0x2019, 0x0029,
5609 0x080c, 0x68e7, 0x0076, 0x2039, 0x0000, 0x080c, 0x681d, 0x00c6,
5610 0x0026, 0x2160, 0x6204, 0xa294, 0x00ff, 0xa286, 0x0006, 0x1118,
5611 0x6007, 0x0404, 0x0028, 0x2001, 0x0004, 0x8007, 0xa215, 0x6206,
5612 0x002e, 0x00ce, 0x0016, 0x2c08, 0x080c, 0xa712, 0x001e, 0x007e,
5613 0x2160, 0x080c, 0x4ecf, 0x002e, 0x8210, 0x1f04, 0x2b3e, 0x015e,
5614 0x001e, 0x002e, 0x003e, 0x00ce, 0x00ee, 0x00fe, 0x0005, 0x0046,
5615 0x0026, 0x0016, 0x2001, 0xad52, 0x2004, 0xd0c4, 0x0148, 0xd0a4,
5616 0x0138, 0xa006, 0x2220, 0x8427, 0x2009, 0x0029, 0x080c, 0xa96c,
5617 0x001e, 0x002e, 0x004e, 0x0005, 0x0016, 0x0026, 0x0036, 0x00c6,
5618 0x7284, 0x82ff, 0x01f8, 0x2011, 0xad52, 0x2214, 0xd2ac, 0x11d0,
5619 0x2100, 0x080c, 0x268a, 0x81ff, 0x01b8, 0x2019, 0x0001, 0x8314,
5620 0xa2e0, 0xb3c0, 0x2c04, 0xd384, 0x0120, 0xa084, 0xff00, 0x8007,
5621 0x0010, 0xa084, 0x00ff, 0xa116, 0x0138, 0xa096, 0x00ff, 0x0110,
5622 0x8318, 0x0c68, 0xa085, 0x0001, 0x00ce, 0x003e, 0x002e, 0x001e,
5623 0x0005, 0x0016, 0x00c6, 0x0126, 0x2091, 0x8000, 0xa180, 0xae34,
5624 0x2004, 0xa065, 0x0178, 0x0016, 0x00c6, 0x080c, 0x9807, 0x001e,
5625 0x090c, 0x14f6, 0x611a, 0x080c, 0x2ad9, 0x080c, 0x8078, 0x001e,
5626 0x080c, 0x4c9f, 0x012e, 0x00ce, 0x001e, 0x0005, 0x7eef, 0x7de8,
5627 0x7ce4, 0x80e2, 0x7be1, 0x80e0, 0x80dc, 0x80da, 0x7ad9, 0x80d6,
5628 0x80d5, 0x80d4, 0x80d3, 0x80d2, 0x80d1, 0x79ce, 0x78cd, 0x80cc,
5629 0x80cb, 0x80ca, 0x80c9, 0x80c7, 0x80c6, 0x77c5, 0x76c3, 0x80bc,
5630 0x80ba, 0x75b9, 0x80b6, 0x74b5, 0x73b4, 0x72b3, 0x80b2, 0x80b1,
5631 0x80ae, 0x71ad, 0x80ac, 0x70ab, 0x6faa, 0x6ea9, 0x80a7, 0x6da6,
5632 0x6ca5, 0x6ba3, 0x6a9f, 0x699e, 0x689d, 0x809b, 0x8098, 0x6797,
5633 0x6690, 0x658f, 0x6488, 0x6384, 0x6282, 0x8081, 0x8080, 0x617c,
5634 0x607a, 0x8079, 0x5f76, 0x8075, 0x8074, 0x8073, 0x8072, 0x8071,
5635 0x806e, 0x5e6d, 0x806c, 0x5d6b, 0x5c6a, 0x5b69, 0x8067, 0x5a66,
5636 0x5965, 0x5863, 0x575c, 0x565a, 0x5559, 0x8056, 0x8055, 0x5454,
5637 0x5353, 0x5252, 0x5151, 0x504e, 0x4f4d, 0x804c, 0x804b, 0x4e4a,
5638 0x4d49, 0x8047, 0x4c46, 0x8045, 0x8043, 0x803c, 0x803a, 0x8039,
5639 0x8036, 0x4b35, 0x8034, 0x4a33, 0x4932, 0x4831, 0x802e, 0x472d,
5640 0x462c, 0x452b, 0x442a, 0x4329, 0x4227, 0x8026, 0x8025, 0x4123,
5641 0x401f, 0x3f1e, 0x3e1d, 0x3d1b, 0x3c18, 0x8017, 0x8010, 0x3b0f,
5642 0x3a08, 0x8004, 0x3902, 0x8001, 0x8000, 0x8000, 0x3800, 0x3700,
5643 0x3600, 0x8000, 0x3500, 0x8000, 0x8000, 0x8000, 0x3400, 0x8000,
5644 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x3300, 0x3200, 0x8000,
5645 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x3100, 0x3000, 0x8000,
5646 0x8000, 0x2f00, 0x8000, 0x2e00, 0x2d00, 0x2c00, 0x8000, 0x8000,
5647 0x8000, 0x2b00, 0x8000, 0x2a00, 0x2900, 0x2800, 0x8000, 0x2700,
5648 0x2600, 0x2500, 0x2400, 0x2300, 0x2200, 0x8000, 0x8000, 0x2100,
5649 0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x8000, 0x8000, 0x1b00,
5650 0x1a00, 0x8000, 0x1900, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
5651 0x8000, 0x1800, 0x8000, 0x1700, 0x1600, 0x1500, 0x8000, 0x1400,
5652 0x1300, 0x1200, 0x1100, 0x1000, 0x0f00, 0x8000, 0x8000, 0x0e00,
5653 0x0d00, 0x0c00, 0x0b00, 0x0a00, 0x0900, 0x8000, 0x8000, 0x0800,
5654 0x0700, 0x8000, 0x0600, 0x8000, 0x8000, 0x8000, 0x0500, 0x0400,
5655 0x0300, 0x8000, 0x0200, 0x8000, 0x8000, 0x8000, 0x0100, 0x8000,
5656 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x8000, 0x8000,
5657 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
5658 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x2071, 0xad81,
5659 0x7003, 0x0002, 0xa006, 0x7012, 0x7016, 0x703a, 0x703e, 0x7033,
5660 0xad91, 0x7037, 0xad91, 0x7007, 0x0001, 0x2061, 0xadd1, 0x6003,
5661 0x0002, 0x0005, 0x1004, 0x2d0c, 0x0e04, 0x2d0c, 0x2071, 0xad81,
5662 0x2b78, 0x7818, 0xd084, 0x1140, 0x2a60, 0x7820, 0xa08e, 0x0069,
5663 0x1904, 0x2df1, 0x0804, 0x2d8a, 0x0005, 0x2071, 0xad81, 0x7004,
5664 0x0002, 0x2d15, 0x2d16, 0x2d1f, 0x2d30, 0x0005, 0x1004, 0x2d1e,
5665 0x0e04, 0x2d1e, 0x2b78, 0x7818, 0xd084, 0x01e8, 0x0005, 0x2b78,
5666 0x2061, 0xadd1, 0x6008, 0xa08e, 0x0100, 0x0128, 0xa086, 0x0200,
5667 0x0904, 0x2deb, 0x0005, 0x7014, 0x2068, 0x2a60, 0x7018, 0x0807,
5668 0x7010, 0x2068, 0x6834, 0xa086, 0x0103, 0x0108, 0x0005, 0x2a60,
5669 0x2b78, 0x7018, 0x0807, 0x2a60, 0x7820, 0xa08a, 0x0040, 0x1210,
5670 0x61c0, 0x0042, 0x2100, 0xa08a, 0x003f, 0x1a04, 0x2de8, 0x61c0,
5671 0x0804, 0x2d8a, 0x2dcc, 0x2df7, 0x2dff, 0x2e03, 0x2e0b, 0x2e11,
5672 0x2e15, 0x2e21, 0x2e24, 0x2e2e, 0x2e31, 0x2de8, 0x2de8, 0x2de8,
5673 0x2e34, 0x2de8, 0x2e43, 0x2e5a, 0x2e71, 0x2ee8, 0x2eed, 0x2f16,
5674 0x2f67, 0x2f78, 0x2f96, 0x2fcd, 0x2fd7, 0x2fe4, 0x2ff7, 0x3018,
5675 0x3021, 0x3057, 0x305d, 0x2de8, 0x3086, 0x2de8, 0x2de8, 0x2de8,
5676 0x2de8, 0x2de8, 0x308d, 0x3097, 0x2de8, 0x2de8, 0x2de8, 0x2de8,
5677 0x2de8, 0x2de8, 0x2de8, 0x2de8, 0x309f, 0x2de8, 0x2de8, 0x2de8,
5678 0x2de8, 0x2de8, 0x30b1, 0x30b9, 0x2de8, 0x2de8, 0x2de8, 0x2de8,
5679 0x2de8, 0x2de8, 0x0002, 0x30cb, 0x311f, 0x317a, 0x318a, 0x2de8,
5680 0x31a4, 0x35cb, 0x3fbb, 0x2de8, 0x2de8, 0x2de8, 0x2de8, 0x2de8,
5681 0x2de8, 0x2de8, 0x2de8, 0x2e2e, 0x2e31, 0x35cd, 0x2de8, 0x35da,
5682 0x403c, 0x4097, 0x40fb, 0x2de8, 0x415a, 0x4180, 0x419f, 0x2de8,
5683 0x2de8, 0x2de8, 0x2de8, 0x35de, 0x376b, 0x3785, 0x37a3, 0x3804,
5684 0x3858, 0x3863, 0x389a, 0x38a9, 0x38b8, 0x38bb, 0x38de, 0x3928,
5685 0x398e, 0x399b, 0x3a9c, 0x3bb3, 0x3bdc, 0x3cda, 0x3cfc, 0x3d08,
5686 0x3d41, 0x3e05, 0x2de8, 0x2de8, 0x2de8, 0x2de8, 0x3e6d, 0x3e88,
5687 0x3efa, 0x3fac, 0x713c, 0x0000, 0x2021, 0x4000, 0x080c, 0x3c39,
5688 0x0126, 0x2091, 0x8000, 0x0e04, 0x2dd8, 0x7818, 0xd084, 0x0110,
5689 0x012e, 0x0cb0, 0x7c22, 0x7926, 0x7a2a, 0x7b2e, 0x781b, 0x0001,
5690 0x2091, 0x4080, 0x7007, 0x0001, 0x2091, 0x5000, 0x012e, 0x0005,
5691 0x2021, 0x4001, 0x0c18, 0x2021, 0x4002, 0x0c00, 0x2021, 0x4003,
5692 0x08e8, 0x2021, 0x4005, 0x08d0, 0x2021, 0x4006, 0x08b8, 0xa02e,
5693 0x2520, 0x7b28, 0x7a2c, 0x7824, 0x7930, 0x0804, 0x3c46, 0x7823,
5694 0x0004, 0x7824, 0x0807, 0xa02e, 0x2520, 0x7b28, 0x7a2c, 0x7824,
5695 0x7930, 0x0804, 0x3c49, 0x7924, 0x7828, 0x2114, 0x200a, 0x0804,
5696 0x2dcc, 0x7924, 0x2114, 0x0804, 0x2dcc, 0x2099, 0x0009, 0x20a1,
5697 0x0009, 0x20a9, 0x0007, 0x53a3, 0x7924, 0x7a28, 0x7b2c, 0x0804,
5698 0x2dcc, 0x7824, 0x2060, 0x0090, 0x2009, 0x0002, 0x2011, 0x0001,
5699 0x2019, 0x001b, 0x783b, 0x0017, 0x0804, 0x2dcc, 0x7d38, 0x7c3c,
5700 0x0840, 0x7d38, 0x7c3c, 0x0888, 0x2061, 0x1000, 0xe10c, 0xa006,
5701 0x2c15, 0xa200, 0x8c60, 0x8109, 0x1dd8, 0x2010, 0xa005, 0x0904,
5702 0x2dcc, 0x0804, 0x2dee, 0x2069, 0xad51, 0x7824, 0x7930, 0xa11a,
5703 0x1a04, 0x2df4, 0x8019, 0x0904, 0x2df4, 0x684a, 0x6942, 0x782c,
5704 0x6852, 0x7828, 0x6856, 0xa006, 0x685a, 0x685e, 0x080c, 0x5a1c,
5705 0x0804, 0x2dcc, 0x2069, 0xad51, 0x7824, 0x7934, 0xa11a, 0x1a04,
5706 0x2df4, 0x8019, 0x0904, 0x2df4, 0x684e, 0x6946, 0x782c, 0x6862,
5707 0x7828, 0x6866, 0xa006, 0x686a, 0x686e, 0x080c, 0x50d9, 0x0804,
5708 0x2dcc, 0xa02e, 0x2520, 0x81ff, 0x1904, 0x2df1, 0x7924, 0x7b28,
5709 0x7a2c, 0x20a9, 0x0005, 0x20a1, 0xad88, 0x41a1, 0x080c, 0x3c05,
5710 0x0904, 0x2df1, 0x2009, 0x0020, 0x080c, 0x3c46, 0x701b, 0x2e89,
5711 0x0005, 0x6834, 0x2008, 0xa084, 0x00ff, 0xa096, 0x0011, 0x0120,
5712 0xa096, 0x0019, 0x1904, 0x2df1, 0x810f, 0xa18c, 0x00ff, 0x0904,
5713 0x2df1, 0x710e, 0x700c, 0x8001, 0x0528, 0x700e, 0x080c, 0x3c05,
5714 0x0904, 0x2df1, 0x2009, 0x0020, 0x2061, 0xadd1, 0x6224, 0x6328,
5715 0x642c, 0x6530, 0xa290, 0x0040, 0xa399, 0x0000, 0xa4a1, 0x0000,
5716 0xa5a9, 0x0000, 0x080c, 0x3c46, 0x701b, 0x2eb7, 0x0005, 0x6834,
5717 0xa084, 0x00ff, 0xa096, 0x0002, 0x0120, 0xa096, 0x000a, 0x1904,
5718 0x2df1, 0x08c0, 0x7010, 0x2068, 0x6838, 0xc0fd, 0x683a, 0x080c,
5719 0x4b7c, 0x1128, 0x7007, 0x0003, 0x701b, 0x2ed1, 0x0005, 0x080c,
5720 0x51df, 0x0126, 0x2091, 0x8000, 0x20a9, 0x0005, 0x2099, 0xad88,
5721 0x530a, 0x2100, 0xa210, 0xa399, 0x0000, 0xa4a1, 0x0000, 0xa5a9,
5722 0x0000, 0xad80, 0x000d, 0x2009, 0x0020, 0x012e, 0x0804, 0x3c49,
5723 0x61a8, 0x7824, 0x60aa, 0x0804, 0x2dcc, 0x2091, 0x8000, 0x7823,
5724 0x4000, 0x7827, 0x4953, 0x782b, 0x5020, 0x782f, 0x2020, 0x2009,
5725 0x017f, 0x2104, 0x7832, 0x3f00, 0x7836, 0x2061, 0x0100, 0x6200,
5726 0x2061, 0x0200, 0x603c, 0x8007, 0xa205, 0x783a, 0x2009, 0x04fd,
5727 0x2104, 0x783e, 0x781b, 0x0001, 0x2091, 0x5000, 0x2091, 0x4080,
5728 0x2071, 0x0010, 0x20c1, 0x00f0, 0x0804, 0x0427, 0x81ff, 0x1904,
5729 0x2df1, 0x7924, 0x810f, 0xa18c, 0x00ff, 0x080c, 0x4cdc, 0x1904,
5730 0x2df4, 0x7e38, 0xa684, 0x3fff, 0xa082, 0x4000, 0x0210, 0x0804,
5731 0x2df4, 0x7c28, 0x7d2c, 0x080c, 0x4e96, 0xd28c, 0x1118, 0x080c,
5732 0x4e41, 0x0010, 0x080c, 0x4e6f, 0x1518, 0x2061, 0xb400, 0x0126,
5733 0x2091, 0x8000, 0x6000, 0xa086, 0x0000, 0x0148, 0x6010, 0xa06d,
5734 0x0130, 0x683c, 0xa406, 0x1118, 0x6840, 0xa506, 0x0150, 0x012e,
5735 0xace0, 0x0018, 0x2001, 0xad16, 0x2004, 0xac02, 0x1a04, 0x2df1,
5736 0x0c30, 0x080c, 0x929c, 0x012e, 0x0904, 0x2df1, 0x0804, 0x2dcc,
5737 0xa00e, 0x2001, 0x0005, 0x080c, 0x51df, 0x0126, 0x2091, 0x8000,
5738 0x080c, 0x9803, 0x080c, 0x510c, 0x012e, 0x0804, 0x2dcc, 0x81ff,
5739 0x1904, 0x2df1, 0x080c, 0x3c1a, 0x0904, 0x2df4, 0x080c, 0x4d96,
5740 0x0904, 0x2df1, 0x080c, 0x4ea2, 0x0904, 0x2df1, 0x0804, 0x2dcc,
5741 0x81ff, 0x1904, 0x2df1, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x080c,
5742 0x4f0d, 0x0904, 0x2df1, 0x2019, 0x0005, 0x080c, 0x4ebd, 0x0904,
5743 0x2df1, 0x7828, 0xa08a, 0x1000, 0x1a04, 0x2df4, 0x8003, 0x800b,
5744 0x810b, 0xa108, 0x080c, 0x6519, 0x0804, 0x2dcc, 0x0126, 0x2091,
5745 0x8000, 0x81ff, 0x0118, 0x2009, 0x0001, 0x0448, 0x2029, 0x00ff,
5746 0x644c, 0x2400, 0xa506, 0x01f0, 0x2508, 0x080c, 0x4cdc, 0x11d0,
5747 0x080c, 0x4f0d, 0x1128, 0x2009, 0x0002, 0x62b0, 0x2518, 0x00b8,
5748 0x2019, 0x0004, 0x080c, 0x4ebd, 0x1118, 0x2009, 0x0006, 0x0078,
5749 0x7824, 0xa08a, 0x1000, 0x1270, 0x8003, 0x800b, 0x810b, 0xa108,
5750 0x080c, 0x6519, 0x8529, 0x1ae8, 0x012e, 0x0804, 0x2dcc, 0x012e,
5751 0x0804, 0x2df1, 0x012e, 0x0804, 0x2df4, 0x080c, 0x3c1a, 0x0904,
5752 0x2df4, 0x080c, 0x4dfc, 0x080c, 0x4e96, 0x0804, 0x2dcc, 0x81ff,
5753 0x1904, 0x2df1, 0x080c, 0x3c1a, 0x0904, 0x2df4, 0x080c, 0x4ded,
5754 0x080c, 0x4e96, 0x0804, 0x2dcc, 0x81ff, 0x1904, 0x2df1, 0x080c,
5755 0x3c1a, 0x0904, 0x2df4, 0x080c, 0x4e71, 0x0904, 0x2df1, 0x080c,
5756 0x4bc0, 0x080c, 0x4e3a, 0x080c, 0x4e96, 0x0804, 0x2dcc, 0x080c,
5757 0x3c1a, 0x0904, 0x2df4, 0x080c, 0x4d96, 0x0904, 0x2df1, 0x62a0,
5758 0x2019, 0x0005, 0x00c6, 0x080c, 0x4ecf, 0x2061, 0x0000, 0x080c,
5759 0x68e7, 0x0076, 0x2039, 0x0000, 0x080c, 0x681d, 0x2009, 0x0000,
5760 0x080c, 0xa712, 0x007e, 0x00ce, 0x080c, 0x4e96, 0x0804, 0x2dcc,
5761 0x080c, 0x3c1a, 0x0904, 0x2df4, 0x080c, 0x4e96, 0x2208, 0x0804,
5762 0x2dcc, 0x0156, 0x00d6, 0x00e6, 0x2069, 0xae13, 0x6810, 0x6914,
5763 0xa10a, 0x1210, 0x2009, 0x0000, 0x6816, 0x2011, 0x0000, 0x2019,
5764 0x0000, 0x20a9, 0x007e, 0x2069, 0xae34, 0x2d04, 0xa075, 0x0130,
5765 0x704c, 0x0071, 0xa210, 0x7080, 0x0059, 0xa318, 0x8d68, 0x1f04,
5766 0x3035, 0x2300, 0xa218, 0x00ee, 0x00de, 0x015e, 0x0804, 0x2dcc,
5767 0x00f6, 0x0016, 0xa07d, 0x0140, 0x2001, 0x0000, 0x8000, 0x2f0c,
5768 0x81ff, 0x0110, 0x2178, 0x0cd0, 0x001e, 0x00fe, 0x0005, 0x2069,
5769 0xae13, 0x6910, 0x62ac, 0x0804, 0x2dcc, 0x81ff, 0x1904, 0x2df1,
5770 0x614c, 0xa190, 0x2be6, 0x2215, 0xa294, 0x00ff, 0x636c, 0x83ff,
5771 0x0108, 0x6270, 0x67d0, 0xd79c, 0x0118, 0x2031, 0x0001, 0x0090,
5772 0xd7ac, 0x0118, 0x2031, 0x0003, 0x0068, 0xd7a4, 0x0118, 0x2031,
5773 0x0002, 0x0040, 0x080c, 0x574f, 0x1118, 0x2031, 0x0004, 0x0010,
5774 0x2031, 0x0000, 0x7e3a, 0x7f3e, 0x0804, 0x2dcc, 0x613c, 0x6240,
5775 0x2019, 0xafa3, 0x231c, 0x0804, 0x2dcc, 0x0126, 0x2091, 0x8000,
5776 0x6134, 0xa006, 0x2010, 0x2018, 0x012e, 0x0804, 0x2dcc, 0x080c,
5777 0x3c2a, 0x0904, 0x2df4, 0x6244, 0x6338, 0x0804, 0x2dcc, 0x613c,
5778 0x6240, 0x7824, 0x603e, 0x7b28, 0x6342, 0x2069, 0xad51, 0x831f,
5779 0xa305, 0x6816, 0x782c, 0x2069, 0xafa3, 0x2d1c, 0x206a, 0x0804,
5780 0x2dcc, 0x0126, 0x2091, 0x8000, 0x7824, 0x6036, 0x012e, 0x0804,
5781 0x2dcc, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x7828, 0xa00d, 0x0904,
5782 0x2df4, 0x782c, 0xa005, 0x0904, 0x2df4, 0x6244, 0x6146, 0x6338,
5783 0x603a, 0x0804, 0x2dcc, 0x2001, 0xad00, 0x2004, 0xa086, 0x0003,
5784 0x1904, 0x2df1, 0x00c6, 0x2061, 0x0100, 0x7924, 0x810f, 0xa18c,
5785 0x00ff, 0xa196, 0x00ff, 0x1130, 0x2001, 0xad14, 0x2004, 0xa085,
5786 0xff00, 0x0078, 0xa182, 0x007f, 0x16a0, 0xa188, 0x2be6, 0x210d,
5787 0xa18c, 0x00ff, 0x2001, 0xad14, 0x2004, 0xa116, 0x0550, 0x810f,
5788 0xa105, 0x0126, 0x2091, 0x8000, 0x0006, 0x080c, 0x8022, 0x000e,
5789 0x01e0, 0x601a, 0x600b, 0xbc09, 0x601f, 0x0001, 0x080c, 0x3c05,
5790 0x01d8, 0x6837, 0x0000, 0x7007, 0x0003, 0x6833, 0x0000, 0x6838,
5791 0xc0fd, 0x683a, 0x701b, 0x3173, 0x2d00, 0x6012, 0x2009, 0x0032,
5792 0x080c, 0x80a7, 0x012e, 0x00ce, 0x0005, 0x012e, 0x00ce, 0x0804,
5793 0x2df1, 0x00ce, 0x0804, 0x2df4, 0x080c, 0x8078, 0x0cb0, 0x2001,
5794 0xad00, 0x2004, 0xa086, 0x0003, 0x1904, 0x2df1, 0x00c6, 0x2061,
5795 0x0100, 0x7924, 0x810f, 0xa18c, 0x00ff, 0xa196, 0x00ff, 0x1130,
5796 0x2001, 0xad14, 0x2004, 0xa085, 0xff00, 0x0078, 0xa182, 0x007f,
5797 0x16a0, 0xa188, 0x2be6, 0x210d, 0xa18c, 0x00ff, 0x2001, 0xad14,
5798 0x2004, 0xa116, 0x0550, 0x810f, 0xa105, 0x0126, 0x2091, 0x8000,
5799 0x0006, 0x080c, 0x8022, 0x000e, 0x01e0, 0x601a, 0x600b, 0xbc05,
5800 0x601f, 0x0001, 0x080c, 0x3c05, 0x01d8, 0x6837, 0x0000, 0x7007,
5801 0x0003, 0x6833, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x701b, 0x3173,
5802 0x2d00, 0x6012, 0x2009, 0x0032, 0x080c, 0x80a7, 0x012e, 0x00ce,
5803 0x0005, 0x012e, 0x00ce, 0x0804, 0x2df1, 0x00ce, 0x0804, 0x2df4,
5804 0x080c, 0x8078, 0x0cb0, 0x6830, 0xa086, 0x0100, 0x0904, 0x2df1,
5805 0x0804, 0x2dcc, 0x2061, 0xb048, 0x0126, 0x2091, 0x8000, 0x6000,
5806 0xd084, 0x0128, 0x6104, 0x6208, 0x012e, 0x0804, 0x2dcc, 0x012e,
5807 0x0804, 0x2df4, 0x81ff, 0x1904, 0x2df1, 0x080c, 0x574f, 0x0904,
5808 0x2df1, 0x0126, 0x2091, 0x8000, 0x6244, 0x6064, 0xa202, 0x0248,
5809 0xa085, 0x0001, 0x080c, 0x26c0, 0x080c, 0x436e, 0x012e, 0x0804,
5810 0x2dcc, 0x012e, 0x0804, 0x2df4, 0x0126, 0x2091, 0x8000, 0x7824,
5811 0xa084, 0x0007, 0x0002, 0x31b6, 0x31bf, 0x31c6, 0x31b3, 0x31b3,
5812 0x31b3, 0x31b3, 0x31b3, 0x012e, 0x0804, 0x2df4, 0x2009, 0x0114,
5813 0x2104, 0xa085, 0x0800, 0x200a, 0x080c, 0x332f, 0x0070, 0x2009,
5814 0x010b, 0x200b, 0x0010, 0x080c, 0x332f, 0x0038, 0x81ff, 0x0128,
5815 0x012e, 0x2021, 0x400b, 0x0804, 0x2dce, 0x0086, 0x0096, 0x00a6,
5816 0x00b6, 0x00c6, 0x00d6, 0x00e6, 0x00f6, 0x2009, 0x0101, 0x210c,
5817 0x0016, 0x2001, 0x0138, 0x200c, 0x2003, 0x0001, 0x0016, 0x2001,
5818 0x007a, 0x2034, 0x2001, 0x007b, 0x202c, 0xa006, 0x2048, 0x2050,
5819 0x2058, 0x080c, 0x3570, 0x080c, 0x34da, 0xa03e, 0x2720, 0x00f6,
5820 0x00e6, 0x00c6, 0x2d60, 0x2071, 0xb01e, 0x2079, 0x0020, 0x00d6,
5821 0x2069, 0x0000, 0x6824, 0xd0b4, 0x0140, 0x2001, 0x007d, 0x2004,
5822 0x783e, 0x2001, 0x007c, 0x2004, 0x783a, 0x00de, 0x2011, 0x0001,
5823 0x080c, 0x3486, 0x080c, 0x3486, 0x00ce, 0x00ee, 0x00fe, 0x080c,
5824 0x33d5, 0x080c, 0x34ae, 0x080c, 0x342b, 0x080c, 0x3394, 0x080c,
5825 0x33c5, 0x00f6, 0x2079, 0x0100, 0x7824, 0xd094, 0x0530, 0x7814,
5826 0xa084, 0x0184, 0xa085, 0x0010, 0x7816, 0x2079, 0x0140, 0x080c,
5827 0x330d, 0x1110, 0x00fe, 0x0430, 0x7804, 0xd0dc, 0x0dc0, 0x2079,
5828 0x0100, 0x7827, 0x0086, 0x7814, 0xa084, 0x0184, 0xa085, 0x0032,
5829 0x7816, 0x080c, 0x330d, 0x1110, 0x00fe, 0x00a0, 0x7824, 0xd0bc,
5830 0x0dc0, 0x7827, 0x0080, 0xa026, 0x7c16, 0x7824, 0xd0ac, 0x0130,
5831 0x8b58, 0x080c, 0x3317, 0x00fe, 0x0804, 0x32d7, 0x00fe, 0x080c,
5832 0x330d, 0x1150, 0x8948, 0x2001, 0x007a, 0x2602, 0x2001, 0x007b,
5833 0x2502, 0x080c, 0x3317, 0x0088, 0x87ff, 0x0140, 0x2001, 0x0201,
5834 0x2004, 0xa005, 0x1904, 0x3211, 0x8739, 0x0038, 0x2001, 0xaffd,
5835 0x2004, 0xa086, 0x0000, 0x1904, 0x3211, 0x2001, 0x0033, 0x2003,
5836 0x00f6, 0x8631, 0x1208, 0x8529, 0x2500, 0xa605, 0x0904, 0x32d7,
5837 0x7824, 0xd0bc, 0x0128, 0x2900, 0xaa05, 0xab05, 0x1904, 0x32d7,
5838 0x6033, 0x000d, 0x2001, 0x0030, 0x2003, 0x0004, 0x7824, 0xd0ac,
5839 0x1148, 0x2001, 0xaffd, 0x2003, 0x0003, 0x2001, 0x0030, 0x2003,
5840 0x0009, 0x0040, 0x6027, 0x0001, 0x2001, 0x0075, 0x2004, 0xa005,
5841 0x0108, 0x6026, 0x2c00, 0x601a, 0x20e1, 0x9040, 0x2d00, 0x681a,
5842 0x6833, 0x000d, 0x7824, 0xd0a4, 0x1180, 0x6827, 0x0000, 0x00c6,
5843 0x20a9, 0x0004, 0x2061, 0x0020, 0x6003, 0x0008, 0x2001, 0x0203,
5844 0x2004, 0x1f04, 0x32ac, 0x00ce, 0x0040, 0x6827, 0x0001, 0x2001,
5845 0x0074, 0x2004, 0xa005, 0x0108, 0x6826, 0x00f6, 0x00c6, 0x2079,
5846 0x0100, 0x2061, 0x0020, 0x7827, 0x0002, 0x2001, 0x0072, 0x2004,
5847 0xa084, 0xfff8, 0x601a, 0x0006, 0x2001, 0x0073, 0x2004, 0x601e,
5848 0x78c6, 0x000e, 0x78ca, 0x00ce, 0x00fe, 0x0804, 0x31ef, 0x2061,
5849 0x0100, 0x6027, 0x0002, 0x001e, 0x61e2, 0x001e, 0x6106, 0x7824,
5850 0xa084, 0x0003, 0xa086, 0x0002, 0x0188, 0x20e1, 0x9028, 0x6050,
5851 0xa084, 0xf7ef, 0x6052, 0x602f, 0x0000, 0x602c, 0xc0ac, 0x602e,
5852 0x604b, 0xf7f7, 0x6043, 0x0090, 0x6043, 0x0010, 0x2908, 0x2a10,
5853 0x2b18, 0x2b00, 0xaa05, 0xa905, 0x00fe, 0x00ee, 0x00de, 0x00ce,
5854 0x00be, 0x00ae, 0x009e, 0x008e, 0x1118, 0x012e, 0x0804, 0x2dcc,
5855 0x012e, 0x2021, 0x400c, 0x0804, 0x2dce, 0xa085, 0x0001, 0x1d04,
5856 0x3316, 0x2091, 0x6000, 0x8420, 0xa486, 0x0064, 0x0005, 0x2001,
5857 0x0105, 0x2003, 0x0010, 0x2001, 0x0030, 0x2003, 0x0004, 0x2001,
5858 0x0020, 0x2003, 0x0004, 0x2001, 0xaffd, 0x2003, 0x0000, 0x2001,
5859 0xb01e, 0x2003, 0x0000, 0x20e1, 0xf000, 0xa026, 0x0005, 0x00f6,
5860 0x2079, 0x0100, 0x2001, 0xad14, 0x200c, 0x7932, 0x7936, 0x080c,
5861 0x26a0, 0x7850, 0xa084, 0x0980, 0xa085, 0x0030, 0x7852, 0x2019,
5862 0x01f4, 0x8319, 0x1df0, 0xa084, 0x0980, 0x7852, 0x782c, 0xc0ad,
5863 0x782e, 0x20a9, 0x0046, 0x1d04, 0x334b, 0x2091, 0x6000, 0x1f04,
5864 0x334b, 0x7850, 0xa085, 0x0400, 0x7852, 0x2001, 0x0009, 0x2004,
5865 0xa084, 0x0003, 0xa086, 0x0001, 0x1118, 0x782c, 0xc0ac, 0x782e,
5866 0x784b, 0xf7f7, 0x7843, 0x0090, 0x7843, 0x0010, 0x20a9, 0x000e,
5867 0xe000, 0x1f04, 0x3368, 0x7850, 0xa085, 0x1400, 0x7852, 0x2019,
5868 0x61a8, 0x7854, 0xe000, 0xe000, 0xd08c, 0x1110, 0x8319, 0x1dc8,
5869 0x7827, 0x0048, 0x7850, 0xa085, 0x0400, 0x7852, 0x7843, 0x0040,
5870 0x2019, 0x01f4, 0xe000, 0xe000, 0x8319, 0x1de0, 0x2001, 0x0140,
5871 0x2003, 0x0100, 0x7827, 0x0020, 0x7843, 0x0000, 0x2003, 0x0000,
5872 0x7827, 0x0048, 0x00fe, 0x0005, 0x7824, 0xd0ac, 0x11c8, 0x00f6,
5873 0x00e6, 0x2071, 0xaffd, 0x2079, 0x0030, 0x2001, 0x0201, 0x2004,
5874 0xa005, 0x0160, 0x7000, 0xa086, 0x0000, 0x1140, 0x0051, 0xd0bc,
5875 0x0108, 0x8738, 0x7003, 0x0003, 0x7803, 0x0019, 0x00ee, 0x00fe,
5876 0x0005, 0x780c, 0xa08c, 0x0070, 0x0178, 0x2009, 0x007a, 0x260a,
5877 0x2009, 0x007b, 0x250a, 0xd0b4, 0x0108, 0x8a50, 0xd0ac, 0x0108,
5878 0x8948, 0xd0a4, 0x0108, 0x8b58, 0x0005, 0x00f6, 0x2079, 0x0200,
5879 0x781c, 0xd084, 0x0140, 0x20e1, 0x0007, 0x20e1, 0x2000, 0x2001,
5880 0x020a, 0x2004, 0x0ca8, 0x00fe, 0x0005, 0x00e6, 0x2071, 0x0100,
5881 0x2009, 0xad14, 0x210c, 0x716e, 0x7063, 0x0100, 0x7166, 0x719e,
5882 0x706b, 0x0000, 0x7073, 0x0809, 0x7077, 0x0008, 0x7078, 0xa080,
5883 0x0100, 0x707a, 0x7080, 0x8000, 0x7082, 0x7087, 0xaaaa, 0xa006,
5884 0x708a, 0x708e, 0x707e, 0x70d6, 0x70ab, 0x0036, 0x70af, 0x95d5,
5885 0x7027, 0x0080, 0x7014, 0xa084, 0x0184, 0xa085, 0x0032, 0x7016,
5886 0x080c, 0x34ae, 0x080c, 0x330d, 0x1110, 0x8421, 0x0028, 0x7024,
5887 0xd0bc, 0x0db0, 0x7027, 0x0080, 0x00f6, 0x00e6, 0x2071, 0xaffd,
5888 0x2079, 0x0030, 0x00d6, 0x2069, 0x0000, 0x6824, 0xd0b4, 0x0120,
5889 0x683c, 0x783e, 0x6838, 0x783a, 0x00de, 0x2011, 0x0011, 0x080c,
5890 0x3486, 0x2011, 0x0001, 0x080c, 0x3486, 0x00ee, 0x00fe, 0x7017,
5891 0x0000, 0x00ee, 0x0005, 0x00f6, 0x00e6, 0x2071, 0xaffd, 0x2079,
5892 0x0030, 0x7904, 0xd1fc, 0x0904, 0x3483, 0x7803, 0x0002, 0xa026,
5893 0xd19c, 0x1904, 0x347f, 0x7000, 0x0002, 0x3483, 0x3441, 0x3465,
5894 0x347f, 0xd1bc, 0x1150, 0xd1dc, 0x1150, 0x8001, 0x7002, 0x2011,
5895 0x0001, 0x04e1, 0x05c0, 0x04d1, 0x04b0, 0x780f, 0x0000, 0x7820,
5896 0x7924, 0x7803, 0x0004, 0x7822, 0x7926, 0x2001, 0x0201, 0x200c,
5897 0x81ff, 0x0de8, 0x080c, 0x33b1, 0x2009, 0x0001, 0x7808, 0xd0ec,
5898 0x0110, 0x2009, 0x0011, 0x7902, 0x00f0, 0x8001, 0x7002, 0xa184,
5899 0x0880, 0x1138, 0x7804, 0xd0fc, 0x1940, 0x2011, 0x0001, 0x00b1,
5900 0x0090, 0x6030, 0xa092, 0x0004, 0xa086, 0x0009, 0x1120, 0x6000,
5901 0x601a, 0x2011, 0x0025, 0x6232, 0xd1dc, 0x1988, 0x0870, 0x7803,
5902 0x0004, 0x7003, 0x0000, 0x00ee, 0x00fe, 0x0005, 0x6024, 0xa005,
5903 0x0520, 0x8001, 0x6026, 0x6018, 0x6130, 0xa140, 0x2804, 0x7832,
5904 0x8840, 0x2804, 0x7836, 0x8840, 0x2804, 0x7822, 0x8840, 0x2804,
5905 0x7826, 0x8840, 0x7a02, 0x7000, 0x8000, 0x7002, 0x6018, 0xa802,
5906 0xa08a, 0x0029, 0x1138, 0x6018, 0xa080, 0x0001, 0x2004, 0x601a,
5907 0x2001, 0x000d, 0x6032, 0xa085, 0x0001, 0x0005, 0x00f6, 0x00e6,
5908 0x00c6, 0x2071, 0xb01e, 0x2079, 0x0020, 0x7904, 0xd1fc, 0x01f0,
5909 0x7803, 0x0002, 0x2d60, 0xa026, 0x7000, 0x0002, 0x34d6, 0x34c1,
5910 0x34cd, 0x8001, 0x7002, 0xd19c, 0x1188, 0x2011, 0x0001, 0x080c,
5911 0x3486, 0x0160, 0x080c, 0x3486, 0x0048, 0x8001, 0x7002, 0x7804,
5912 0xd0fc, 0x1d30, 0x2011, 0x0001, 0x080c, 0x3486, 0x00ce, 0x00ee,
5913 0x00fe, 0x0005, 0x00f6, 0x00e6, 0x00c6, 0x2061, 0x0200, 0x601b,
5914 0x0004, 0x2061, 0x0100, 0x60cf, 0x0400, 0x6004, 0xc0ac, 0xa085,
5915 0x0200, 0x6006, 0x2001, 0x0074, 0x2004, 0xa005, 0x01f8, 0x2038,
5916 0x2001, 0x0076, 0x2024, 0x2001, 0x0077, 0x201c, 0x080c, 0x3c05,
5917 0x6833, 0x000d, 0x6f26, 0x2d00, 0x681a, 0xa78a, 0x0007, 0x0220,
5918 0x2138, 0x2009, 0x0007, 0x0010, 0x2708, 0xa03e, 0x6818, 0xa080,
5919 0x000d, 0x04a1, 0x1d90, 0x2d00, 0x681a, 0x0088, 0x080c, 0x3c05,
5920 0x6833, 0x000d, 0x2070, 0x6827, 0x0001, 0x2d00, 0x681a, 0x2001,
5921 0x0076, 0x2004, 0x2072, 0x2001, 0x0077, 0x2004, 0x7006, 0x2061,
5922 0x0020, 0x2079, 0x0100, 0x6013, 0x0400, 0x20e1, 0x9040, 0x2001,
5923 0x0072, 0x2004, 0xa084, 0xfff8, 0x700a, 0x601a, 0x0006, 0x2001,
5924 0x0073, 0x2004, 0x700e, 0x601e, 0x78c6, 0x000e, 0x78ca, 0xa006,
5925 0x603a, 0x603e, 0x00ce, 0x00ee, 0x00fe, 0x0005, 0x00e6, 0x2071,
5926 0x0010, 0x20a0, 0x2099, 0x0014, 0x7003, 0x0026, 0x7432, 0x7336,
5927 0xa006, 0x703a, 0x703e, 0x810b, 0x810b, 0x21a8, 0x810b, 0x7122,
5928 0x7003, 0x0041, 0x7004, 0xd0fc, 0x0de8, 0x7003, 0x0002, 0x7003,
5929 0x0040, 0x53a5, 0x7430, 0x7334, 0x87ff, 0x0180, 0x00c6, 0x00d6,
5930 0x2d60, 0x00c6, 0x080c, 0x3c05, 0x00ce, 0x6018, 0x2070, 0x2d00,
5931 0x7006, 0x601a, 0x00de, 0x00ce, 0xa085, 0x0001, 0x00ee, 0x0005,
5932 0x00e6, 0x2001, 0x0075, 0x2004, 0xa005, 0x0508, 0x2038, 0x2001,
5933 0x0078, 0x2024, 0x2001, 0x0079, 0x201c, 0x080c, 0x3c05, 0x2d60,
5934 0x6833, 0x000d, 0x6f26, 0x2d00, 0x681a, 0xa78a, 0x0007, 0x0220,
5935 0x2138, 0x2009, 0x0007, 0x0010, 0x2708, 0xa03e, 0x6818, 0xa080,
5936 0x000d, 0x080c, 0x353e, 0x1d88, 0x2d00, 0x681a, 0x00e0, 0x080c,
5937 0x3c05, 0x2d60, 0x6033, 0x000d, 0x2070, 0x6027, 0x0001, 0x2c00,
5938 0x601a, 0x2001, 0x0078, 0x2004, 0x2072, 0x2001, 0x0079, 0x2004,
5939 0x7006, 0x2001, 0x0072, 0x2004, 0xa084, 0xfff8, 0x700a, 0x2001,
5940 0x0073, 0x2004, 0x700e, 0x2001, 0x0030, 0x2003, 0x0004, 0x7824,
5941 0xd0ac, 0x1178, 0x2001, 0x0101, 0x200c, 0xc1ed, 0x2102, 0x6027,
5942 0x0000, 0x2001, 0xaffd, 0x2003, 0x0003, 0x2001, 0x0030, 0x2003,
5943 0x0009, 0x00ee, 0x0005, 0x0804, 0x2dcc, 0x0126, 0x2091, 0x8000,
5944 0x20a9, 0x0011, 0x2001, 0xad40, 0x20a0, 0xa006, 0x40a4, 0x012e,
5945 0x0804, 0x2dcc, 0x7d38, 0x7c3c, 0x0804, 0x2e73, 0x080c, 0x3c05,
5946 0x0904, 0x2df1, 0x080c, 0x574f, 0x0110, 0x080c, 0x491f, 0x2009,
5947 0x001c, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x080c, 0x3c46, 0x701b,
5948 0x35f2, 0x0005, 0xade8, 0x000d, 0x6800, 0xa005, 0x0904, 0x2df4,
5949 0x6804, 0xd0ac, 0x0118, 0xd0a4, 0x0904, 0x2df4, 0xd094, 0x00c6,
5950 0x2061, 0x0100, 0x6104, 0x0138, 0x6200, 0xa292, 0x0005, 0x0218,
5951 0xa18c, 0xffdf, 0x0010, 0xa18d, 0x0020, 0x6106, 0x00ce, 0xd08c,
5952 0x00c6, 0x2061, 0x0100, 0x6104, 0x0118, 0xa18d, 0x0010, 0x0010,
5953 0xa18c, 0xffef, 0x6106, 0x00ce, 0x2009, 0x0100, 0x210c, 0xa18a,
5954 0x0002, 0x0268, 0xd084, 0x0158, 0x6a28, 0xa28a, 0x007f, 0x1a04,
5955 0x2df4, 0xa288, 0x2be6, 0x210d, 0xa18c, 0x00ff, 0x6156, 0xd0dc,
5956 0x0130, 0x6828, 0xa08a, 0x007f, 0x1a04, 0x2df4, 0x604e, 0x6808,
5957 0xa08a, 0x0100, 0x0a04, 0x2df4, 0xa08a, 0x0841, 0x1a04, 0x2df4,
5958 0xa084, 0x0007, 0x1904, 0x2df4, 0x680c, 0xa005, 0x0904, 0x2df4,
5959 0x6810, 0xa005, 0x0904, 0x2df4, 0x6848, 0x6940, 0xa10a, 0x1a04,
5960 0x2df4, 0x8001, 0x0904, 0x2df4, 0x684c, 0x6944, 0xa10a, 0x1a04,
5961 0x2df4, 0x8001, 0x0904, 0x2df4, 0x6804, 0xd0fc, 0x0560, 0x080c,
5962 0x3c05, 0x0904, 0x2df1, 0x2009, 0x0014, 0x7a2c, 0x7b28, 0x7c3c,
5963 0x7d38, 0xa290, 0x0038, 0xa399, 0x0000, 0x080c, 0x3c46, 0x701b,
5964 0x3672, 0x0005, 0xade8, 0x000d, 0x20a9, 0x0014, 0x2d98, 0x2069,
5965 0xad6d, 0x2da0, 0x53a3, 0x7010, 0xa0e8, 0x000d, 0x2001, 0xad71,
5966 0x200c, 0xd1e4, 0x0140, 0x00c6, 0x2061, 0x0100, 0x6004, 0xa085,
5967 0x0b00, 0x6006, 0x00ce, 0x20a9, 0x001c, 0x2d98, 0x2069, 0xad51,
5968 0x2da0, 0x53a3, 0x6814, 0xa08c, 0x00ff, 0x613e, 0x8007, 0xa084,
5969 0x00ff, 0x6042, 0x080c, 0x5a1c, 0x080c, 0x5070, 0x080c, 0x50d9,
5970 0x6000, 0xa086, 0x0000, 0x1904, 0x3755, 0x6808, 0x602a, 0x080c,
5971 0x22f8, 0x0006, 0x2001, 0x0100, 0x2004, 0xa082, 0x0005, 0x000e,
5972 0x0268, 0x2009, 0x0170, 0x200b, 0x0080, 0xe000, 0xe000, 0x200b,
5973 0x0000, 0x0036, 0x6b08, 0x080c, 0x26fb, 0x003e, 0x6818, 0x691c,
5974 0x6a20, 0x6b24, 0x8007, 0x810f, 0x8217, 0x831f, 0x6016, 0x611a,
5975 0x621e, 0x6322, 0x6c04, 0xd4f4, 0x0148, 0x6830, 0x6934, 0x6a38,
5976 0x6b3c, 0x8007, 0x810f, 0x8217, 0x831f, 0x0010, 0xa084, 0xf0ff,
5977 0x6006, 0x610a, 0x620e, 0x6312, 0x8007, 0x810f, 0x8217, 0x831f,
5978 0x20a9, 0x0004, 0x20a1, 0xafad, 0x40a1, 0x080c, 0x659c, 0x6904,
5979 0xd1fc, 0x0520, 0x00c6, 0x2009, 0x0000, 0x20a9, 0x0001, 0x6b70,
5980 0xd384, 0x01c8, 0x0020, 0x839d, 0x12b0, 0x3508, 0x8109, 0x080c,
5981 0x5fa9, 0x6878, 0x6016, 0x6874, 0x2008, 0xa084, 0xff00, 0x8007,
5982 0x600a, 0xa184, 0x00ff, 0x6006, 0x8108, 0x1118, 0x6003, 0x0003,
5983 0x0010, 0x6003, 0x0001, 0x1f04, 0x36f3, 0x00ce, 0x2069, 0xad51,
5984 0x2001, 0xaf9d, 0x6a80, 0xa294, 0x0030, 0xa28e, 0x0000, 0x0170,
5985 0xa28e, 0x0010, 0x0118, 0xa28e, 0x0020, 0x0140, 0x2003, 0xaaaa,
5986 0x080c, 0x2744, 0x2001, 0xaf8e, 0x2102, 0x0008, 0x2102, 0x00c6,
5987 0x2061, 0x0100, 0x602f, 0x0040, 0x602f, 0x0000, 0x00ce, 0x080c,
5988 0x574f, 0x0128, 0x080c, 0x3e5f, 0x0110, 0x080c, 0x26c0, 0x60c4,
5989 0xa005, 0x01b0, 0x6003, 0x0001, 0x2009, 0x373f, 0x00c0, 0x080c,
5990 0x574f, 0x1158, 0x2011, 0x566e, 0x080c, 0x650d, 0x2001, 0xaf9e,
5991 0x2003, 0x0000, 0x080c, 0x569a, 0x0040, 0x080c, 0x485e, 0x0028,
5992 0x6003, 0x0004, 0x2009, 0x3755, 0x0010, 0x0804, 0x2dcc, 0x2001,
5993 0x0100, 0x2004, 0xa082, 0x0005, 0x0258, 0x2001, 0x0170, 0x2004,
5994 0xa084, 0x00ff, 0xa086, 0x004c, 0x1118, 0x2091, 0x309d, 0x0817,
5995 0x2091, 0x301d, 0x0817, 0x6000, 0xa086, 0x0000, 0x0904, 0x2df1,
5996 0x2069, 0xad51, 0x7830, 0x6842, 0x7834, 0x6846, 0x6804, 0xd0fc,
5997 0x0118, 0x2009, 0x0030, 0x0010, 0x2009, 0x001c, 0x2d00, 0x7a2c,
5998 0x7b28, 0x7c3c, 0x7d38, 0x0804, 0x3c49, 0xa006, 0x080c, 0x26c0,
5999 0x81ff, 0x1904, 0x2df1, 0x080c, 0x574f, 0x1178, 0x2001, 0xaf9e,
6000 0x2003, 0x0001, 0x2001, 0xad00, 0x2003, 0x0001, 0xa085, 0x0001,
6001 0x080c, 0x5793, 0x080c, 0x569a, 0x0020, 0x080c, 0x491f, 0x080c,
6002 0x485e, 0x0804, 0x2dcc, 0x81ff, 0x1904, 0x2df1, 0x080c, 0x574f,
6003 0x1110, 0x0804, 0x2df1, 0x6184, 0x81ff, 0x0198, 0x703f, 0x0000,
6004 0x2001, 0xb3c0, 0x2009, 0x0040, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38,
6005 0x0126, 0x2091, 0x8000, 0x080c, 0x3c49, 0x701b, 0x2dca, 0x012e,
6006 0x0005, 0x703f, 0x0001, 0x00d6, 0x2069, 0xb3c0, 0x20a9, 0x0040,
6007 0x20a1, 0xb3c0, 0x2019, 0xffff, 0x43a4, 0x654c, 0xa588, 0x2be6,
6008 0x210d, 0xa18c, 0x00ff, 0x216a, 0xa00e, 0x2011, 0x0002, 0x2100,
6009 0xa506, 0x01a8, 0x080c, 0x4cdc, 0x1190, 0x6014, 0x821c, 0x0238,
6010 0xa398, 0xb3c0, 0xa085, 0xff00, 0x8007, 0x201a, 0x0038, 0xa398,
6011 0xb3c0, 0x2324, 0xa4a4, 0xff00, 0xa405, 0x201a, 0x8210, 0x8108,
6012 0xa182, 0x0080, 0x1208, 0x0c18, 0x8201, 0x8007, 0x2d0c, 0xa105,
6013 0x206a, 0x00de, 0x20a9, 0x0040, 0x20a1, 0xb3c0, 0x2099, 0xb3c0,
6014 0x080c, 0x48be, 0x0804, 0x37b0, 0x080c, 0x3c2a, 0x0904, 0x2df4,
6015 0x00c6, 0x080c, 0x3c05, 0x00ce, 0x1120, 0x2009, 0x0002, 0x0804,
6016 0x2df1, 0x2001, 0xad52, 0x2004, 0xd0b4, 0x01f0, 0x6000, 0xd08c,
6017 0x11d8, 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x11a8, 0x6837,
6018 0x0000, 0x6838, 0xc0fd, 0x683a, 0x080c, 0x970b, 0x1120, 0x2009,
6019 0x0003, 0x0804, 0x2df1, 0x7007, 0x0003, 0x701b, 0x3830, 0x0005,
6020 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x20a9, 0x002b, 0x2c98, 0xade8,
6021 0x0002, 0x2da0, 0x53a3, 0x20a9, 0x0004, 0xac80, 0x0006, 0x2098,
6022 0xad80, 0x0006, 0x20a0, 0x080c, 0x48be, 0x20a9, 0x0004, 0xac80,
6023 0x000a, 0x2098, 0xad80, 0x000a, 0x20a0, 0x080c, 0x48be, 0x2d00,
6024 0x2009, 0x002b, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0804, 0x3c49,
6025 0x81ff, 0x1904, 0x2df1, 0x080c, 0x3c1a, 0x0904, 0x2df4, 0x080c,
6026 0x4eab, 0x0804, 0x2dcc, 0x81ff, 0x1904, 0x2df1, 0x7828, 0xa08a,
6027 0x1000, 0x1a04, 0x2df4, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x080c,
6028 0x4f0d, 0x0904, 0x2df1, 0x2019, 0x0004, 0x080c, 0x4ebd, 0x7924,
6029 0x810f, 0x7a28, 0x0011, 0x0804, 0x2dcc, 0xa186, 0x00ff, 0x0110,
6030 0x0071, 0x0060, 0x2029, 0x007e, 0x2061, 0xad00, 0x644c, 0x2400,
6031 0xa506, 0x0110, 0x2508, 0x0019, 0x8529, 0x1ec8, 0x0005, 0x080c,
6032 0x4cdc, 0x1138, 0x2200, 0x8003, 0x800b, 0x810b, 0xa108, 0x080c,
6033 0x6519, 0x0005, 0x81ff, 0x1904, 0x2df1, 0x080c, 0x3c1a, 0x0904,
6034 0x2df4, 0x080c, 0x4d96, 0x0904, 0x2df1, 0x080c, 0x4eb4, 0x0804,
6035 0x2dcc, 0x81ff, 0x1904, 0x2df1, 0x080c, 0x3c1a, 0x0904, 0x2df4,
6036 0x080c, 0x4d96, 0x0904, 0x2df1, 0x080c, 0x4ea2, 0x0804, 0x2dcc,
6037 0x6100, 0x0804, 0x2dcc, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x2001,
6038 0xad00, 0x2004, 0xa086, 0x0003, 0x1904, 0x2df1, 0x00d6, 0xace8,
6039 0x000a, 0x7924, 0xd184, 0x0110, 0xace8, 0x0006, 0x680c, 0x8007,
6040 0x783e, 0x6808, 0x8007, 0x783a, 0x6b04, 0x831f, 0x6a00, 0x8217,
6041 0x00de, 0x6100, 0xa18c, 0x0200, 0x0804, 0x2dcc, 0x7824, 0xa09c,
6042 0x00ff, 0xa39a, 0x0003, 0x1a04, 0x2df1, 0x624c, 0xa294, 0x00ff,
6043 0xa084, 0xff00, 0x8007, 0xa206, 0x1150, 0x2001, 0xad40, 0x2009,
6044 0x000c, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0804, 0x3c49, 0x81ff,
6045 0x1904, 0x2df1, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x6004, 0xa084,
6046 0x00ff, 0xa086, 0x0006, 0x1904, 0x2df1, 0x00c6, 0x080c, 0x3c05,
6047 0x00ce, 0x0904, 0x2df1, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a,
6048 0x080c, 0x96b7, 0x0904, 0x2df1, 0x7007, 0x0003, 0x701b, 0x3919,
6049 0x0005, 0x6830, 0xa086, 0x0100, 0x0904, 0x2df1, 0xad80, 0x000e,
6050 0x2009, 0x000c, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0804, 0x3c49,
6051 0xa006, 0x080c, 0x26c0, 0x7824, 0xa084, 0x00ff, 0xa086, 0x00ff,
6052 0x0118, 0x81ff, 0x1904, 0x2df1, 0x080c, 0x574f, 0x0110, 0x080c,
6053 0x491f, 0x7828, 0xa08a, 0x1000, 0x1a04, 0x2df4, 0x7924, 0xa18c,
6054 0xff00, 0x810f, 0xa186, 0x00ff, 0x0138, 0xa182, 0x007f, 0x1a04,
6055 0x2df4, 0x2100, 0x080c, 0x268a, 0x0026, 0x00c6, 0x0126, 0x2091,
6056 0x8000, 0x2061, 0xafda, 0x601b, 0x0000, 0x601f, 0x0000, 0x080c,
6057 0x574f, 0x1178, 0x2001, 0xaf9e, 0x2003, 0x0001, 0x2001, 0xad00,
6058 0x2003, 0x0001, 0xa085, 0x0001, 0x080c, 0x5793, 0x080c, 0x569a,
6059 0x00a0, 0x2061, 0x0100, 0x2001, 0xad14, 0x2004, 0xa084, 0x00ff,
6060 0x810f, 0xa105, 0x604a, 0x6043, 0x0090, 0x6043, 0x0010, 0x2009,
6061 0x002d, 0x2011, 0x4883, 0x080c, 0x6593, 0x7924, 0xa18c, 0xff00,
6062 0x810f, 0x080c, 0x574f, 0x1110, 0x2009, 0x00ff, 0x7a28, 0x080c,
6063 0x387d, 0x012e, 0x00ce, 0x002e, 0x0804, 0x2dcc, 0x7924, 0xa18c,
6064 0xff00, 0x810f, 0x00c6, 0x080c, 0x4c80, 0x2c08, 0x00ce, 0x1904,
6065 0x2df4, 0x0804, 0x2dcc, 0x81ff, 0x0120, 0x2009, 0x0001, 0x0804,
6066 0x2df1, 0x60d0, 0xd0ac, 0x1130, 0xd09c, 0x1120, 0x2009, 0x0005,
6067 0x0804, 0x2df1, 0x080c, 0x3c05, 0x1120, 0x2009, 0x0002, 0x0804,
6068 0x2df1, 0x7924, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x080c, 0x3c46,
6069 0x701b, 0x39bb, 0x0005, 0x2009, 0x0080, 0x080c, 0x4cdc, 0x1130,
6070 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x0120, 0x2021, 0x400a,
6071 0x0804, 0x2dce, 0x00d6, 0xade8, 0x000d, 0x6900, 0x6a08, 0x6b0c,
6072 0x6c10, 0x6d14, 0x6e18, 0x6820, 0xa0be, 0x0100, 0x0904, 0x3a32,
6073 0xa0be, 0x0112, 0x0904, 0x3a32, 0xa0be, 0x0113, 0x0904, 0x3a32,
6074 0xa0be, 0x0114, 0x0904, 0x3a32, 0xa0be, 0x0117, 0x0904, 0x3a32,
6075 0xa0be, 0x011a, 0x0904, 0x3a32, 0xa0be, 0x011c, 0x0904, 0x3a32,
6076 0xa0be, 0x0121, 0x05b0, 0xa0be, 0x0131, 0x0598, 0xa0be, 0x0171,
6077 0x05c8, 0xa0be, 0x0173, 0x05b0, 0xa0be, 0x01a1, 0x1120, 0x6830,
6078 0x8007, 0x6832, 0x04a8, 0xa0be, 0x0212, 0x0540, 0xa0be, 0x0213,
6079 0x0528, 0xa0be, 0x0214, 0x01b0, 0xa0be, 0x0217, 0x0168, 0xa0be,
6080 0x021a, 0x1120, 0x6838, 0x8007, 0x683a, 0x00e0, 0xa0be, 0x0300,
6081 0x01c8, 0x00de, 0x0804, 0x2df4, 0xad80, 0x0010, 0x20a9, 0x0007,
6082 0x080c, 0x3a78, 0xad80, 0x000e, 0x20a9, 0x0001, 0x080c, 0x3a78,
6083 0x0048, 0xad80, 0x000c, 0x080c, 0x3a86, 0x0050, 0xad80, 0x000e,
6084 0x080c, 0x3a86, 0xad80, 0x000c, 0x20a9, 0x0001, 0x080c, 0x3a78,
6085 0x00c6, 0x080c, 0x3c05, 0x0568, 0x6838, 0xc0fd, 0x683a, 0x6837,
6086 0x0119, 0x6853, 0x0000, 0x684f, 0x0020, 0x685b, 0x0001, 0x810b,
6087 0x697e, 0x6883, 0x0000, 0x6a86, 0x6b8a, 0x6c8e, 0x6d92, 0x6996,
6088 0x689b, 0x0000, 0x00ce, 0x00de, 0x6837, 0x0000, 0x6838, 0xc0fd,
6089 0x683a, 0x6823, 0x0000, 0x6804, 0x2068, 0x080c, 0x96d3, 0x1120,
6090 0x2009, 0x0003, 0x0804, 0x2df1, 0x7007, 0x0003, 0x701b, 0x3a6f,
6091 0x0005, 0x00ce, 0x00de, 0x2009, 0x0002, 0x0804, 0x2df1, 0x6820,
6092 0xa086, 0x8001, 0x1904, 0x2dcc, 0x2009, 0x0004, 0x0804, 0x2df1,
6093 0x0016, 0x2008, 0x2044, 0x8000, 0x204c, 0x8000, 0x290a, 0x8108,
6094 0x280a, 0x8108, 0x1f04, 0x3a7a, 0x001e, 0x0005, 0x0016, 0x00a6,
6095 0x00b6, 0x2008, 0x2044, 0x8000, 0x204c, 0x8000, 0x2054, 0x8000,
6096 0x205c, 0x2b0a, 0x8108, 0x2a0a, 0x8108, 0x290a, 0x8108, 0x280a,
6097 0x00be, 0x00ae, 0x001e, 0x0005, 0x81ff, 0x0120, 0x2009, 0x0001,
6098 0x0804, 0x2df1, 0x7924, 0x2140, 0xa18c, 0xff00, 0x810f, 0x60d0,
6099 0xd0ac, 0x1120, 0xa182, 0x0080, 0x0a04, 0x2df4, 0xa182, 0x00ff,
6100 0x1a04, 0x2df4, 0x7a2c, 0x7b28, 0x606c, 0xa306, 0x1140, 0x6070,
6101 0xa24e, 0x0904, 0x2df4, 0xa9cc, 0xff00, 0x0904, 0x2df4, 0x00c6,
6102 0x080c, 0x3b58, 0x2c68, 0x00ce, 0x0538, 0xa0c6, 0x4000, 0x1180,
6103 0x00c6, 0x0006, 0x2d60, 0x2009, 0x0000, 0x080c, 0x4f6e, 0x1108,
6104 0xc185, 0x6000, 0xd0bc, 0x0108, 0xc18d, 0x000e, 0x00ce, 0x0088,
6105 0xa0c6, 0x4007, 0x1110, 0x2408, 0x0060, 0xa0c6, 0x4008, 0x1118,
6106 0x2708, 0x2610, 0x0030, 0xa0c6, 0x4009, 0x1108, 0x0010, 0x2001,
6107 0x4006, 0x2020, 0x0804, 0x2dce, 0x2d00, 0x7022, 0x0016, 0x00b6,
6108 0x00c6, 0x00e6, 0x2c70, 0x080c, 0x8022, 0x05d8, 0x2d00, 0x601a,
6109 0x080c, 0x9956, 0x2e58, 0x00ee, 0x00e6, 0x00c6, 0x080c, 0x3c05,
6110 0x00ce, 0x2b70, 0x1150, 0x080c, 0x8078, 0x00ee, 0x00ce, 0x00be,
6111 0x001e, 0x2009, 0x0002, 0x0804, 0x2df1, 0x6837, 0x0000, 0x683b,
6112 0x0000, 0x2d00, 0x6012, 0x6833, 0x0000, 0x6838, 0xc0fd, 0xd88c,
6113 0x0108, 0xc0f5, 0x683a, 0x0126, 0x2091, 0x8000, 0x080c, 0x2ad9,
6114 0x012e, 0x601f, 0x0001, 0x2001, 0x0000, 0x080c, 0x4c1e, 0x2001,
6115 0x0002, 0x080c, 0x4c30, 0x2009, 0x0002, 0x080c, 0x80a7, 0xa085,
6116 0x0001, 0x00ee, 0x00ce, 0x00be, 0x001e, 0x1120, 0x2009, 0x0003,
6117 0x0804, 0x2df1, 0x7007, 0x0003, 0x701b, 0x3b3f, 0x0005, 0x6830,
6118 0xa086, 0x0100, 0x7020, 0x2060, 0x1138, 0x2009, 0x0004, 0x6204,
6119 0xa294, 0x00ff, 0x0804, 0x2df1, 0x2009, 0x0000, 0x080c, 0x4f6e,
6120 0x1108, 0xc185, 0x6000, 0xd0bc, 0x0108, 0xc18d, 0x0804, 0x2dcc,
6121 0x00e6, 0x00d6, 0x2029, 0x0000, 0x2001, 0xad34, 0x2004, 0xd0ac,
6122 0x0138, 0x2021, 0x0000, 0x20a9, 0x00ff, 0x2071, 0xae34, 0x0030,
6123 0x2021, 0x0080, 0x20a9, 0x007f, 0x2071, 0xaeb4, 0x2e04, 0xa005,
6124 0x1130, 0x2100, 0xa406, 0x1548, 0x2428, 0xc5fd, 0x0430, 0x2068,
6125 0x6f10, 0x2700, 0xa306, 0x11b0, 0x6e14, 0x2600, 0xa206, 0x1190,
6126 0x2400, 0xa106, 0x1160, 0x2d60, 0xd884, 0x0540, 0x6004, 0xa084,
6127 0x00ff, 0xa086, 0x0006, 0x1510, 0x2001, 0x4000, 0x0400, 0x2001,
6128 0x4007, 0x00e8, 0x2400, 0xa106, 0x1140, 0x6e14, 0x87ff, 0x1110,
6129 0x86ff, 0x09d0, 0x2001, 0x4008, 0x0090, 0x8420, 0x8e70, 0x1f04,
6130 0x3b6e, 0x85ff, 0x1130, 0x2001, 0x4009, 0x0048, 0x2001, 0x0001,
6131 0x0030, 0x080c, 0x4c80, 0x1dd0, 0x6312, 0x6216, 0xa006, 0xa005,
6132 0x00de, 0x00ee, 0x0005, 0x81ff, 0x1904, 0x2df1, 0x080c, 0x3c05,
6133 0x0904, 0x2df1, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x7824,
6134 0xa005, 0x0904, 0x2df4, 0xa096, 0x00ff, 0x0120, 0xa092, 0x0004,
6135 0x1a04, 0x2df4, 0x2010, 0x2d18, 0x080c, 0x2a8c, 0x0904, 0x2df1,
6136 0x7007, 0x0003, 0x701b, 0x3bd5, 0x0005, 0x6830, 0xa086, 0x0100,
6137 0x0904, 0x2df1, 0x0804, 0x2dcc, 0x7924, 0xa18c, 0xff00, 0x810f,
6138 0x60d0, 0xd0ac, 0x1120, 0xa182, 0x0080, 0x0a04, 0x2df4, 0xa182,
6139 0x00ff, 0x1a04, 0x2df4, 0x0126, 0x2091, 0x8000, 0x080c, 0x95c6,
6140 0x1188, 0xa190, 0xae34, 0x2204, 0xa065, 0x0160, 0x080c, 0x493a,
6141 0x2001, 0xad34, 0x2004, 0xd0ac, 0x0110, 0x6017, 0x0000, 0x012e,
6142 0x0804, 0x2dcc, 0x012e, 0x0804, 0x2df1, 0x080c, 0x15d9, 0x0188,
6143 0xa006, 0x6802, 0x7010, 0xa005, 0x1120, 0x2d00, 0x7012, 0x7016,
6144 0x0030, 0x7014, 0x6802, 0x2060, 0x2d00, 0x6006, 0x7016, 0xad80,
6145 0x000d, 0x0005, 0x7924, 0x810f, 0xa18c, 0x00ff, 0x080c, 0x4cdc,
6146 0x1130, 0x7e28, 0xa684, 0x3fff, 0xa082, 0x4000, 0x0208, 0xa066,
6147 0x8cff, 0x0005, 0x7e24, 0x860f, 0xa18c, 0x00ff, 0x080c, 0x4cdc,
6148 0x1128, 0xa6b4, 0x00ff, 0xa682, 0x4000, 0x0208, 0xa066, 0x8cff,
6149 0x0005, 0x0016, 0x7110, 0x81ff, 0x0128, 0x2168, 0x6904, 0x080c,
6150 0x15f0, 0x0cc8, 0x7112, 0x7116, 0x001e, 0x0005, 0x2031, 0x0001,
6151 0x0010, 0x2031, 0x0000, 0x2061, 0xadd1, 0x6606, 0x6112, 0x600e,
6152 0x6226, 0x632a, 0x642e, 0x6532, 0x2c10, 0x080c, 0x1624, 0x7007,
6153 0x0002, 0x701b, 0x2dcc, 0x0005, 0x00f6, 0x0126, 0x2091, 0x8000,
6154 0x2079, 0x0000, 0x2001, 0xad8f, 0x2004, 0xa005, 0x1168, 0x0e04,
6155 0x3c74, 0x7818, 0xd084, 0x1140, 0x7a22, 0x7b26, 0x7c2a, 0x781b,
6156 0x0001, 0x2091, 0x4080, 0x0408, 0x0016, 0x00c6, 0x00e6, 0x2071,
6157 0xad81, 0x7138, 0xa182, 0x0010, 0x0218, 0x7030, 0x2060, 0x0078,
6158 0x7030, 0xa0e0, 0x0004, 0xac82, 0xadd1, 0x0210, 0x2061, 0xad91,
6159 0x2c00, 0x7032, 0x81ff, 0x1108, 0x7036, 0x8108, 0x713a, 0x2262,
6160 0x6306, 0x640a, 0x00ee, 0x00ce, 0x001e, 0x012e, 0x00fe, 0x0005,
6161 0x00e6, 0x2071, 0xad81, 0x7038, 0xa005, 0x0570, 0x0126, 0x2091,
6162 0x8000, 0x0e04, 0x3ccb, 0x00f6, 0x2079, 0x0000, 0x7818, 0xd084,
6163 0x1508, 0x00c6, 0x7034, 0x2060, 0x2c04, 0x7822, 0x6004, 0x7826,
6164 0x6008, 0x782a, 0x781b, 0x0001, 0x2091, 0x4080, 0x7038, 0x8001,
6165 0x703a, 0xa005, 0x1130, 0x7033, 0xad91, 0x7037, 0xad91, 0x00ce,
6166 0x0048, 0xac80, 0x0004, 0xa0fa, 0xadd1, 0x0210, 0x2001, 0xad91,
6167 0x7036, 0x00ce, 0x00fe, 0x012e, 0x00ee, 0x0005, 0x0026, 0x2001,
6168 0xad52, 0x2004, 0xd0c4, 0x0120, 0x2011, 0x8014, 0x080c, 0x3c5c,
6169 0x002e, 0x0005, 0x81ff, 0x1904, 0x2df1, 0x0126, 0x2091, 0x8000,
6170 0x6030, 0xc08d, 0xc085, 0xc0ac, 0x6032, 0x080c, 0x574f, 0x1178,
6171 0x2001, 0xaf9e, 0x2003, 0x0001, 0x2001, 0xad00, 0x2003, 0x0001,
6172 0xa085, 0x0001, 0x080c, 0x5793, 0x080c, 0x569a, 0x0010, 0x080c,
6173 0x485e, 0x012e, 0x0804, 0x2dcc, 0x7824, 0x2008, 0xa18c, 0xfffd,
6174 0x1128, 0x61dc, 0xa10d, 0x61de, 0x0804, 0x2dcc, 0x0804, 0x2df4,
6175 0x81ff, 0x1904, 0x2df1, 0x6000, 0xa086, 0x0003, 0x1904, 0x2df1,
6176 0x2001, 0xad52, 0x2004, 0xd0ac, 0x1904, 0x2df1, 0x080c, 0x3c2a,
6177 0x0904, 0x2df4, 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x1120,
6178 0x7828, 0xa005, 0x0904, 0x2dcc, 0x00c6, 0x080c, 0x3c05, 0x00ce,
6179 0x0904, 0x2df1, 0x6837, 0x0000, 0x6833, 0x0000, 0x6838, 0xc0fd,
6180 0x683a, 0x080c, 0x979c, 0x0904, 0x2df1, 0x7007, 0x0003, 0x701b,
6181 0x3d3a, 0x0005, 0x6830, 0xa086, 0x0100, 0x0904, 0x2df1, 0x0804,
6182 0x2dcc, 0x2001, 0xad00, 0x2004, 0xa086, 0x0003, 0x1904, 0x2df1,
6183 0x7f24, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x080c, 0x3c05, 0x0904,
6184 0x2df1, 0x2009, 0x0000, 0x2031, 0x0000, 0x7023, 0x0000, 0x702f,
6185 0x0000, 0xad80, 0x0005, 0x7026, 0x20a0, 0x080c, 0x4cdc, 0x1904,
6186 0x3db4, 0x6004, 0xa0c4, 0x00ff, 0xa8c6, 0x0006, 0x0130, 0xa0c4,
6187 0xff00, 0xa8c6, 0x0600, 0x1904, 0x3db4, 0x2001, 0xad52, 0x2004,
6188 0xd0ac, 0x1128, 0x080c, 0x4f6e, 0x1110, 0xd79c, 0x05e8, 0xd794,
6189 0x1110, 0xd784, 0x0158, 0xac80, 0x0006, 0x2098, 0x3400, 0x20a9,
6190 0x0004, 0x53a3, 0x080c, 0x3a86, 0xd794, 0x0148, 0xac80, 0x000a,
6191 0x2098, 0x3400, 0x20a9, 0x0004, 0x53a3, 0x080c, 0x3a86, 0x21a2,
6192 0xd794, 0x01d8, 0xac80, 0x0000, 0x2098, 0x94a0, 0x20a9, 0x0002,
6193 0x53a3, 0xac80, 0x0003, 0x20a6, 0x94a0, 0xac80, 0x0004, 0x2098,
6194 0x3400, 0x20a9, 0x0002, 0x53a3, 0x080c, 0x3a78, 0xac80, 0x0026,
6195 0x2098, 0x20a9, 0x0002, 0x53a3, 0x0008, 0x94a0, 0xd794, 0x0110,
6196 0xa6b0, 0x000b, 0xa6b0, 0x0005, 0x8108, 0x2001, 0xad34, 0x2004,
6197 0xd0ac, 0x0118, 0xa186, 0x0100, 0x0040, 0xd78c, 0x0120, 0xa186,
6198 0x0100, 0x0170, 0x0018, 0xa186, 0x007e, 0x0150, 0xd794, 0x0118,
6199 0xa686, 0x0020, 0x0010, 0xa686, 0x0028, 0x0150, 0x0804, 0x3d5d,
6200 0x86ff, 0x1120, 0x7120, 0x810b, 0x0804, 0x2dcc, 0x702f, 0x0001,
6201 0x711e, 0x7020, 0xa600, 0x7022, 0x772a, 0x2061, 0xadd1, 0x6007,
6202 0x0000, 0x6612, 0x7024, 0x600e, 0x6226, 0x632a, 0x642e, 0x6532,
6203 0x2c10, 0x080c, 0x1624, 0x7007, 0x0002, 0x701b, 0x3df0, 0x0005,
6204 0x702c, 0xa005, 0x1170, 0x711c, 0x7024, 0x20a0, 0x7728, 0x2031,
6205 0x0000, 0x2061, 0xadd1, 0x6224, 0x6328, 0x642c, 0x6530, 0x0804,
6206 0x3d5d, 0x7120, 0x810b, 0x0804, 0x2dcc, 0x2029, 0x007e, 0x7924,
6207 0x7a28, 0x7b2c, 0x7c38, 0xa184, 0xff00, 0x8007, 0xa0e2, 0x0020,
6208 0x0a04, 0x2df4, 0xa502, 0x0a04, 0x2df4, 0xa184, 0x00ff, 0xa0e2,
6209 0x0020, 0x0a04, 0x2df4, 0xa502, 0x0a04, 0x2df4, 0xa284, 0xff00,
6210 0x8007, 0xa0e2, 0x0020, 0x0a04, 0x2df4, 0xa502, 0x0a04, 0x2df4,
6211 0xa284, 0x00ff, 0xa0e2, 0x0020, 0x0a04, 0x2df4, 0xa502, 0x0a04,
6212 0x2df4, 0xa384, 0xff00, 0x8007, 0xa0e2, 0x0020, 0x0a04, 0x2df4,
6213 0xa502, 0x0a04, 0x2df4, 0xa384, 0x00ff, 0xa0e2, 0x0020, 0x0a04,
6214 0x2df4, 0xa502, 0x0a04, 0x2df4, 0xa484, 0xff00, 0x8007, 0xa0e2,
6215 0x0020, 0x0a04, 0x2df4, 0xa502, 0x0a04, 0x2df4, 0xa484, 0x00ff,
6216 0xa0e2, 0x0020, 0x0a04, 0x2df4, 0xa502, 0x0a04, 0x2df4, 0x2061,
6217 0xafa6, 0x6102, 0x6206, 0x630a, 0x640e, 0x0804, 0x2dcc, 0x0006,
6218 0x2001, 0xad52, 0x2004, 0xd0cc, 0x000e, 0x0005, 0x0006, 0x2001,
6219 0xad71, 0x2004, 0xd0bc, 0x000e, 0x0005, 0x6164, 0x7a24, 0x6300,
6220 0x82ff, 0x1118, 0x7926, 0x0804, 0x2dcc, 0x83ff, 0x1904, 0x2df4,
6221 0x2001, 0xfff0, 0xa200, 0x1a04, 0x2df4, 0x2019, 0xffff, 0x6068,
6222 0xa302, 0xa200, 0x0a04, 0x2df4, 0x7926, 0x6266, 0x0804, 0x2dcc,
6223 0x2001, 0xad00, 0x2004, 0xa086, 0x0003, 0x1904, 0x2df1, 0x7c28,
6224 0x7d24, 0x7e38, 0x7f2c, 0x080c, 0x3c05, 0x0904, 0x2df1, 0x2009,
6225 0x0000, 0x2019, 0x0000, 0x7023, 0x0000, 0x702f, 0x0000, 0xad80,
6226 0x0003, 0x7026, 0x20a0, 0xa1e0, 0xae34, 0x2c64, 0x8cff, 0x01b8,
6227 0x6004, 0xa084, 0x00ff, 0xa086, 0x0006, 0x0130, 0x6004, 0xa084,
6228 0xff00, 0xa086, 0x0600, 0x1158, 0x6014, 0x20a2, 0x94a0, 0x6010,
6229 0x8007, 0xa105, 0x8007, 0x20a2, 0x94a0, 0xa398, 0x0002, 0x8108,
6230 0xa182, 0x00ff, 0x0120, 0xa386, 0x002a, 0x0148, 0x08e0, 0x83ff,
6231 0x1120, 0x7120, 0x810c, 0x0804, 0x2dcc, 0x702f, 0x0001, 0x711e,
6232 0x7020, 0xa300, 0x7022, 0x2061, 0xadd1, 0x6007, 0x0000, 0x6312,
6233 0x7024, 0x600e, 0x6426, 0x652a, 0x662e, 0x6732, 0x2c10, 0x080c,
6234 0x1624, 0x7007, 0x0002, 0x701b, 0x3ee6, 0x0005, 0x702c, 0xa005,
6235 0x1168, 0x711c, 0x7024, 0x20a0, 0x2019, 0x0000, 0x2061, 0xadd1,
6236 0x6424, 0x6528, 0x662c, 0x6730, 0x0804, 0x3ea3, 0x7120, 0x810c,
6237 0x0804, 0x2dcc, 0x81ff, 0x1904, 0x2df1, 0x60d0, 0xd0ac, 0x1118,
6238 0xd09c, 0x0904, 0x2df1, 0x080c, 0x3c05, 0x0904, 0x2df1, 0x7924,
6239 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x080c, 0x3c46, 0x701b, 0x3f11,
6240 0x0005, 0x00d6, 0xade8, 0x000d, 0x6828, 0xa0be, 0x7000, 0x0148,
6241 0xa0be, 0x7100, 0x0130, 0xa0be, 0x7200, 0x0118, 0x00de, 0x0804,
6242 0x2df4, 0x6820, 0x6924, 0x080c, 0x2676, 0x1510, 0x080c, 0x4c80,
6243 0x11f8, 0x7122, 0x6612, 0x6516, 0x6e18, 0x00c6, 0x080c, 0x3c05,
6244 0x01b8, 0x080c, 0x3c05, 0x01a0, 0x00ce, 0x00de, 0x6837, 0x0000,
6245 0x6838, 0xc0fd, 0x683a, 0x6823, 0x0000, 0x6804, 0x2068, 0x080c,
6246 0x96ef, 0x0904, 0x2df1, 0x7007, 0x0003, 0x701b, 0x3f4b, 0x0005,
6247 0x00de, 0x0804, 0x2df1, 0x7120, 0x080c, 0x2bc9, 0x6820, 0xa086,
6248 0x8001, 0x0904, 0x2df1, 0x2d00, 0x701e, 0x6804, 0xa080, 0x0002,
6249 0x0006, 0x20a9, 0x002a, 0x2098, 0x20a0, 0x080c, 0x48be, 0x000e,
6250 0xade8, 0x000d, 0x6a08, 0x6b0c, 0x6c10, 0x6d14, 0x2061, 0xadd1,
6251 0x6007, 0x0000, 0x6e00, 0x6f28, 0xa7c6, 0x7000, 0x1108, 0x0018,
6252 0xa7c6, 0x7100, 0x1140, 0xa6c2, 0x0004, 0x0a04, 0x2df4, 0x2009,
6253 0x0004, 0x0804, 0x3c49, 0xa7c6, 0x7200, 0x1904, 0x2df4, 0xa6c2,
6254 0x0054, 0x0a04, 0x2df4, 0x600e, 0x6013, 0x002a, 0x6226, 0x632a,
6255 0x642e, 0x6532, 0x2c10, 0x080c, 0x1624, 0x7007, 0x0002, 0x701b,
6256 0x3f92, 0x0005, 0x701c, 0x2068, 0x6804, 0xa080, 0x0001, 0x2004,
6257 0xa080, 0x0002, 0x0006, 0x20a9, 0x002a, 0x2098, 0x20a0, 0x080c,
6258 0x48be, 0x000e, 0x2009, 0x002a, 0x2061, 0xadd1, 0x6224, 0x6328,
6259 0x642c, 0x6530, 0x0804, 0x3c49, 0x81ff, 0x1904, 0x2df1, 0x080c,
6260 0x3c1a, 0x0904, 0x2df4, 0x080c, 0x4d96, 0x0904, 0x2df1, 0x080c,
6261 0x4ec6, 0x0804, 0x2dcc, 0x7824, 0xd084, 0x0904, 0x3804, 0x080c,
6262 0x3c2a, 0x0904, 0x2df4, 0x00c6, 0x080c, 0x3c05, 0x00ce, 0x1120,
6263 0x2009, 0x0002, 0x0804, 0x2df1, 0x6004, 0xa084, 0x00ff, 0xa086,
6264 0x0006, 0x0128, 0xa08e, 0x0004, 0x0110, 0xa08e, 0x0005, 0x1508,
6265 0x2001, 0xad52, 0x2004, 0xd0b4, 0x0904, 0x3834, 0x6000, 0xd08c,
6266 0x1904, 0x3834, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x080c,
6267 0x970b, 0x1120, 0x2009, 0x0003, 0x0804, 0x2df1, 0x7007, 0x0003,
6268 0x701b, 0x3ff3, 0x0005, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x0804,
6269 0x3834, 0x2009, 0xad30, 0x210c, 0x81ff, 0x0120, 0x2009, 0x0001,
6270 0x0804, 0x2df1, 0x2001, 0xad00, 0x2004, 0xa086, 0x0003, 0x0120,
6271 0x2009, 0x0007, 0x0804, 0x2df1, 0x2001, 0xad52, 0x2004, 0xd0ac,
6272 0x0120, 0x2009, 0x0008, 0x0804, 0x2df1, 0x609c, 0xd0a4, 0x1118,
6273 0xd0ac, 0x1904, 0x3834, 0x6837, 0x0000, 0x6833, 0x0000, 0x6838,
6274 0xc0fd, 0x683a, 0x080c, 0x979c, 0x1120, 0x2009, 0x0003, 0x0804,
6275 0x2df1, 0x7007, 0x0003, 0x701b, 0x402e, 0x0005, 0x6830, 0xa086,
6276 0x0100, 0x1120, 0x2009, 0x0004, 0x0804, 0x2df1, 0x080c, 0x3c2a,
6277 0x0904, 0x2df4, 0x0804, 0x3fd8, 0x81ff, 0x2009, 0x0001, 0x1904,
6278 0x2df1, 0x6000, 0xa086, 0x0003, 0x2009, 0x0007, 0x1904, 0x2df1,
6279 0x2001, 0xad52, 0x2004, 0xd0ac, 0x2009, 0x0008, 0x1904, 0x2df1,
6280 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x6004, 0xa084, 0x00ff, 0xa086,
6281 0x0006, 0x2009, 0x0009, 0x1904, 0x2df1, 0x00c6, 0x080c, 0x3c05,
6282 0x00ce, 0x2009, 0x0002, 0x0904, 0x2df1, 0x6837, 0x0000, 0x6833,
6283 0x0000, 0x6838, 0xc0fd, 0x683a, 0x7928, 0xa194, 0xff00, 0xa18c,
6284 0x00ff, 0xa006, 0x82ff, 0x1128, 0xc0ed, 0x6952, 0x792c, 0x6956,
6285 0x0048, 0xa28e, 0x0100, 0x1904, 0x2df4, 0xc0e5, 0x6853, 0x0000,
6286 0x6857, 0x0000, 0x683e, 0x080c, 0x9957, 0x2009, 0x0003, 0x0904,
6287 0x2df1, 0x7007, 0x0003, 0x701b, 0x408e, 0x0005, 0x6830, 0xa086,
6288 0x0100, 0x2009, 0x0004, 0x0904, 0x2df1, 0x0804, 0x2dcc, 0x81ff,
6289 0x2009, 0x0001, 0x1904, 0x2df1, 0x6000, 0xa086, 0x0003, 0x2009,
6290 0x0007, 0x1904, 0x2df1, 0x080c, 0x3c2a, 0x0904, 0x2df4, 0x6004,
6291 0xa084, 0x00ff, 0xa086, 0x0006, 0x2009, 0x0009, 0x1904, 0x2df1,
6292 0x00c6, 0x080c, 0x3c05, 0x00ce, 0x2009, 0x0002, 0x0904, 0x2df1,
6293 0xad80, 0x000f, 0x2009, 0x0008, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38,
6294 0x080c, 0x3c46, 0x701b, 0x40c5, 0x0005, 0x00d6, 0xade8, 0x000f,
6295 0x6800, 0xa086, 0x0500, 0x1140, 0x6804, 0xa005, 0x1128, 0x6808,
6296 0xa084, 0xff00, 0x1108, 0x0018, 0x00de, 0x1904, 0x2df4, 0x00de,
6297 0x6837, 0x0000, 0x6833, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x00c6,
6298 0x080c, 0x3c2a, 0x1118, 0x00ce, 0x0804, 0x2df4, 0x080c, 0x99a6,
6299 0x2009, 0x0003, 0x00ce, 0x0904, 0x2df1, 0x7007, 0x0003, 0x701b,
6300 0x40f2, 0x0005, 0x6830, 0xa086, 0x0100, 0x2009, 0x0004, 0x0904,
6301 0x2df1, 0x0804, 0x2dcc, 0x81ff, 0x0120, 0x2009, 0x0001, 0x0804,
6302 0x2df1, 0x6000, 0xa086, 0x0003, 0x0120, 0x2009, 0x0007, 0x0804,
6303 0x2df1, 0x7e24, 0x860f, 0xa18c, 0x00ff, 0xa6b4, 0x00ff, 0x080c,
6304 0x4cdc, 0x1904, 0x2df4, 0xa186, 0x007f, 0x0150, 0x6004, 0xa084,
6305 0x00ff, 0xa086, 0x0006, 0x0120, 0x2009, 0x0009, 0x0804, 0x2df1,
6306 0x00c6, 0x080c, 0x3c05, 0x00ce, 0x1120, 0x2009, 0x0002, 0x0804,
6307 0x2df1, 0x6837, 0x0000, 0x6838, 0xc0fd, 0x683a, 0x080c, 0x9726,
6308 0x1120, 0x2009, 0x0003, 0x0804, 0x2df1, 0x7007, 0x0003, 0x701b,
6309 0x413a, 0x0005, 0x6808, 0x8007, 0xa086, 0x0100, 0x1120, 0x2009,
6310 0x0004, 0x0804, 0x2df1, 0x68b0, 0x6836, 0x6810, 0x8007, 0xa084,
6311 0x00ff, 0x808e, 0x6814, 0x8007, 0xa084, 0x00ff, 0x8086, 0xa080,
6312 0x0002, 0xa108, 0xad80, 0x0004, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38,
6313 0x0804, 0x3c49, 0x080c, 0x3c05, 0x1120, 0x2009, 0x0002, 0x0804,
6314 0x2df1, 0x7924, 0xa194, 0xff00, 0xa18c, 0x00ff, 0x8217, 0x82ff,
6315 0x0110, 0x0804, 0x2df4, 0x2009, 0x001a, 0x7a2c, 0x7b28, 0x7c3c,
6316 0x7d38, 0x080c, 0x3c46, 0x701b, 0x4176, 0x0005, 0xad80, 0x000d,
6317 0x2098, 0x20a9, 0x001a, 0x20a1, 0xafad, 0x53a3, 0x0804, 0x2dcc,
6318 0x080c, 0x3c05, 0x1120, 0x2009, 0x0002, 0x0804, 0x2df1, 0x7924,
6319 0xa194, 0xff00, 0xa18c, 0x00ff, 0x8217, 0x82ff, 0x0110, 0x0804,
6320 0x2df4, 0x2099, 0xafad, 0x20a0, 0x20a9, 0x001a, 0x53a3, 0x2009,
6321 0x001a, 0x7a2c, 0x7b28, 0x7c3c, 0x7d38, 0x0804, 0x3c49, 0x7824,
6322 0xa08a, 0x1000, 0x1a04, 0x2df4, 0x0126, 0x2091, 0x8000, 0x8003,
6323 0x800b, 0x810b, 0xa108, 0x00c6, 0x2061, 0xafda, 0x6142, 0x00ce,
6324 0x012e, 0x0804, 0x2dcc, 0x00c6, 0x080c, 0x574f, 0x1188, 0x2001,
6325 0xaf9e, 0x2003, 0x0001, 0x2001, 0xad00, 0x2003, 0x0001, 0xa085,
6326 0x0001, 0x080c, 0x5793, 0x080c, 0x569a, 0x080c, 0x14f6, 0x0038,
6327 0x2061, 0xad00, 0x6030, 0xc09d, 0x6032, 0x080c, 0x485e, 0x00ce,
6328 0x0005, 0x0126, 0x00c6, 0x00e6, 0x2061, 0x0100, 0x2071, 0xad00,
6329 0x6044, 0xd0a4, 0x11b0, 0xd084, 0x0118, 0x080c, 0x4348, 0x0068,
6330 0xd08c, 0x0118, 0x080c, 0x4269, 0x0040, 0xd094, 0x0118, 0x080c,
6331 0x423a, 0x0018, 0xd09c, 0x0108, 0x0061, 0x00ee, 0x00ce, 0x012e,
6332 0x0005, 0x0016, 0x6128, 0xd19c, 0x1110, 0xc19d, 0x612a, 0x001e,
6333 0x0ca0, 0x624c, 0xa286, 0xf0f0, 0x1150, 0x6048, 0xa086, 0xf0f0,
6334 0x0130, 0x624a, 0x6043, 0x0090, 0x6043, 0x0010, 0x0490, 0xa294,
6335 0xff00, 0xa296, 0xf700, 0x0178, 0x7134, 0xd1a4, 0x1160, 0x6240,
6336 0xa295, 0x0100, 0x6242, 0xa294, 0x0010, 0x0128, 0x2009, 0x00f7,
6337 0x080c, 0x48de, 0x00f0, 0x6040, 0xa084, 0x0010, 0xa085, 0x0040,
6338 0x6042, 0x6043, 0x0000, 0x7077, 0x0000, 0x7093, 0x0001, 0x70b7,
6339 0x0000, 0x70d3, 0x0000, 0x2009, 0xb3c0, 0x200b, 0x0000, 0x7087,
6340 0x0000, 0x707b, 0x000a, 0x2009, 0x000a, 0x2011, 0x4814, 0x080c,
6341 0x6593, 0x0005, 0x0156, 0x2001, 0xad73, 0x2004, 0xd08c, 0x0110,
6342 0x704f, 0xffff, 0x7078, 0xa005, 0x1510, 0x2011, 0x4814, 0x080c,
6343 0x650d, 0x6040, 0xa094, 0x0010, 0xa285, 0x0020, 0x6042, 0x20a9,
6344 0x00c8, 0x6044, 0xd08c, 0x1168, 0x1f04, 0x4251, 0x6242, 0x708b,
6345 0x0000, 0x6040, 0xa094, 0x0010, 0xa285, 0x0080, 0x6042, 0x6242,
6346 0x0030, 0x6242, 0x708b, 0x0000, 0x707f, 0x0000, 0x0000, 0x015e,
6347 0x0005, 0x707c, 0xa08a, 0x0003, 0x1210, 0x0023, 0x0010, 0x080c,
6348 0x14f6, 0x0005, 0x4275, 0x42c5, 0x4347, 0x00f6, 0x707f, 0x0001,
6349 0x20e1, 0xa000, 0xe000, 0x20e1, 0x8700, 0x080c, 0x22f8, 0x20e1,
6350 0x9080, 0x20e1, 0x4000, 0x2079, 0xb200, 0x207b, 0x2200, 0x7807,
6351 0x00ef, 0x780b, 0x0000, 0x780f, 0x00ef, 0x7813, 0x0138, 0x7817,
6352 0x0000, 0x781b, 0x0000, 0x781f, 0x0000, 0x7823, 0xffff, 0x7827,
6353 0xffff, 0x782b, 0x0000, 0x782f, 0x0000, 0x2079, 0xb20c, 0x207b,
6354 0x1101, 0x7807, 0x0000, 0x2099, 0xad05, 0x20a1, 0xb20e, 0x20a9,
6355 0x0004, 0x53a3, 0x2079, 0xb212, 0x207b, 0x0000, 0x7807, 0x0000,
6356 0x2099, 0xb200, 0x20a1, 0x020b, 0x20a9, 0x0014, 0x53a6, 0x60c3,
6357 0x000c, 0x600f, 0x0000, 0x080c, 0x4845, 0x00fe, 0x7083, 0x0000,
6358 0x6043, 0x0008, 0x6043, 0x0000, 0x0005, 0x00d6, 0x7080, 0x7083,
6359 0x0000, 0xa025, 0x0904, 0x432f, 0x6020, 0xd0b4, 0x1904, 0x432d,
6360 0x7190, 0x81ff, 0x0904, 0x431d, 0xa486, 0x000c, 0x1904, 0x4328,
6361 0xa480, 0x0018, 0x8004, 0x20a8, 0x2011, 0xb280, 0x2019, 0xb200,
6362 0x220c, 0x2304, 0xa106, 0x11b8, 0x8210, 0x8318, 0x1f04, 0x42e0,
6363 0x6043, 0x0004, 0x608b, 0xbc94, 0x608f, 0xf0f0, 0x6043, 0x0006,
6364 0x707f, 0x0002, 0x708b, 0x0002, 0x2009, 0x07d0, 0x2011, 0x481b,
6365 0x080c, 0x6593, 0x0490, 0x2069, 0xb280, 0x6930, 0xa18e, 0x1101,
6366 0x1538, 0x6834, 0xa005, 0x1520, 0x6900, 0xa18c, 0x00ff, 0x1118,
6367 0x6804, 0xa005, 0x0190, 0x2011, 0xb28e, 0x2019, 0xad05, 0x20a9,
6368 0x0004, 0x220c, 0x2304, 0xa102, 0x0230, 0x1190, 0x8210, 0x8318,
6369 0x1f04, 0x4311, 0x0068, 0x7093, 0x0000, 0x20e1, 0x9080, 0x20e1,
6370 0x4000, 0x2099, 0xb280, 0x20a1, 0x020b, 0x20a9, 0x0014, 0x53a6,
6371 0x6043, 0x0008, 0x6043, 0x0000, 0x0010, 0x00de, 0x0005, 0x6040,
6372 0xa085, 0x0100, 0x6042, 0x6020, 0xd0b4, 0x1db8, 0x60c3, 0x000c,
6373 0x2011, 0xafd1, 0x2013, 0x0000, 0x7083, 0x0000, 0x20e1, 0x9080,
6374 0x60a3, 0x0056, 0x60a7, 0x9575, 0x080c, 0x782b, 0x0c30, 0x0005,
6375 0x7088, 0xa08a, 0x001d, 0x1210, 0x0023, 0x0010, 0x080c, 0x14f6,
6376 0x0005, 0x437b, 0x438a, 0x43b2, 0x43cb, 0x43ef, 0x4417, 0x443b,
6377 0x446c, 0x4490, 0x44b8, 0x44ef, 0x4517, 0x4533, 0x4549, 0x4569,
6378 0x457c, 0x4584, 0x45b1, 0x45d5, 0x45fd, 0x4621, 0x4652, 0x468f,
6379 0x46be, 0x46da, 0x4719, 0x4739, 0x4752, 0x4753, 0x00c6, 0x2061,
6380 0xad00, 0x6003, 0x0007, 0x2061, 0x0100, 0x6004, 0xa084, 0xfff9,
6381 0x6006, 0x00ce, 0x0005, 0x608b, 0xbc94, 0x608f, 0xf0f0, 0x6043,
6382 0x0002, 0x708b, 0x0001, 0x2009, 0x07d0, 0x2011, 0x481b, 0x080c,
6383 0x6593, 0x0005, 0x00f6, 0x7080, 0xa086, 0x0014, 0x1508, 0x6043,
6384 0x0000, 0x6020, 0xd0b4, 0x11e0, 0x2079, 0xb280, 0x7a30, 0xa296,
6385 0x1102, 0x11a0, 0x7834, 0xa005, 0x1188, 0x7a38, 0xd2fc, 0x0128,
6386 0x70b4, 0xa005, 0x1110, 0x70b7, 0x0001, 0x2011, 0x481b, 0x080c,
6387 0x650d, 0x708b, 0x0010, 0x080c, 0x4584, 0x0010, 0x080c, 0x485e,
6388 0x00fe, 0x0005, 0x708b, 0x0003, 0x6043, 0x0004, 0x2011, 0x481b,
6389 0x080c, 0x650d, 0x080c, 0x48c6, 0x20a3, 0x1102, 0x20a3, 0x0000,
6390 0x20a9, 0x000a, 0x20a3, 0x0000, 0x1f04, 0x43c2, 0x60c3, 0x0014,
6391 0x080c, 0x4845, 0x0005, 0x00f6, 0x7080, 0xa005, 0x01f0, 0x2011,
6392 0x481b, 0x080c, 0x650d, 0xa086, 0x0014, 0x11a8, 0x2079, 0xb280,
6393 0x7a30, 0xa296, 0x1102, 0x1178, 0x7834, 0xa005, 0x1160, 0x7a38,
6394 0xd2fc, 0x0128, 0x70b4, 0xa005, 0x1110, 0x70b7, 0x0001, 0x708b,
6395 0x0004, 0x0029, 0x0010, 0x080c, 0x485e, 0x00fe, 0x0005, 0x708b,
6396 0x0005, 0x080c, 0x48c6, 0x20a3, 0x1103, 0x20a3, 0x0000, 0x3430,
6397 0x2011, 0xb28e, 0x080c, 0x4917, 0x1160, 0x7074, 0xa005, 0x1148,
6398 0x714c, 0xa186, 0xffff, 0x0128, 0x080c, 0x47df, 0x0110, 0x080c,
6399 0x48f5, 0x20a9, 0x0008, 0x2298, 0x26a0, 0x53a6, 0x20a3, 0x0000,
6400 0x20a3, 0x0000, 0x60c3, 0x0014, 0x080c, 0x4845, 0x0005, 0x00f6,
6401 0x7080, 0xa005, 0x01f0, 0x2011, 0x481b, 0x080c, 0x650d, 0xa086,
6402 0x0014, 0x11a8, 0x2079, 0xb280, 0x7a30, 0xa296, 0x1103, 0x1178,
6403 0x7834, 0xa005, 0x1160, 0x7a38, 0xd2fc, 0x0128, 0x70b4, 0xa005,
6404 0x1110, 0x70b7, 0x0001, 0x708b, 0x0006, 0x0029, 0x0010, 0x080c,
6405 0x485e, 0x00fe, 0x0005, 0x708b, 0x0007, 0x080c, 0x48c6, 0x20a3,
6406 0x1104, 0x20a3, 0x0000, 0x3430, 0x2011, 0xb28e, 0x080c, 0x4917,
6407 0x11a8, 0x7074, 0xa005, 0x1190, 0x7154, 0xa186, 0xffff, 0x0170,
6408 0xa180, 0x2be6, 0x200d, 0xa18c, 0xff00, 0x810f, 0x080c, 0x47df,
6409 0x0128, 0x080c, 0x3e66, 0x0110, 0x080c, 0x26c0, 0x20a9, 0x0008,
6410 0x2298, 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3,
6411 0x0014, 0x080c, 0x4845, 0x0005, 0x00f6, 0x7080, 0xa005, 0x01f0,
6412 0x2011, 0x481b, 0x080c, 0x650d, 0xa086, 0x0014, 0x11a8, 0x2079,
6413 0xb280, 0x7a30, 0xa296, 0x1104, 0x1178, 0x7834, 0xa005, 0x1160,
6414 0x7a38, 0xd2fc, 0x0128, 0x70b4, 0xa005, 0x1110, 0x70b7, 0x0001,
6415 0x708b, 0x0008, 0x0029, 0x0010, 0x080c, 0x485e, 0x00fe, 0x0005,
6416 0x708b, 0x0009, 0x080c, 0x48c6, 0x20a3, 0x1105, 0x20a3, 0x0100,
6417 0x3430, 0x080c, 0x4917, 0x1150, 0x7074, 0xa005, 0x1138, 0x080c,
6418 0x4754, 0x1170, 0xa085, 0x0001, 0x080c, 0x26c0, 0x20a9, 0x0008,
6419 0x2099, 0xb28e, 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000,
6420 0x60c3, 0x0014, 0x080c, 0x4845, 0x0010, 0x080c, 0x436e, 0x0005,
6421 0x00f6, 0x7080, 0xa005, 0x0588, 0x2011, 0x481b, 0x080c, 0x650d,
6422 0xa086, 0x0014, 0x1540, 0x2079, 0xb280, 0x7a30, 0xa296, 0x1105,
6423 0x1510, 0x7834, 0x2011, 0x0100, 0xa21e, 0x1160, 0x7a38, 0xd2fc,
6424 0x0128, 0x70b4, 0xa005, 0x1110, 0x70b7, 0x0001, 0x708b, 0x000a,
6425 0x00b1, 0x0098, 0xa005, 0x1178, 0x7a38, 0xd2fc, 0x0128, 0x70b4,
6426 0xa005, 0x1110, 0x70b7, 0x0001, 0x7087, 0x0000, 0x708b, 0x000e,
6427 0x080c, 0x4569, 0x0010, 0x080c, 0x485e, 0x00fe, 0x0005, 0x708b,
6428 0x000b, 0x2011, 0xb20e, 0x22a0, 0x20a9, 0x0040, 0x2019, 0xffff,
6429 0x43a4, 0x20a9, 0x0002, 0x2009, 0x0000, 0x41a4, 0x080c, 0x48c6,
6430 0x20a3, 0x1106, 0x20a3, 0x0000, 0x080c, 0x4917, 0x0118, 0x2013,
6431 0x0000, 0x0020, 0x7050, 0xa085, 0x0100, 0x2012, 0x2298, 0x20a9,
6432 0x0042, 0x53a6, 0x60c3, 0x0084, 0x080c, 0x4845, 0x0005, 0x00f6,
6433 0x7080, 0xa005, 0x01b0, 0x2011, 0x481b, 0x080c, 0x650d, 0xa086,
6434 0x0084, 0x1168, 0x2079, 0xb280, 0x7a30, 0xa296, 0x1106, 0x1138,
6435 0x7834, 0xa005, 0x1120, 0x708b, 0x000c, 0x0029, 0x0010, 0x080c,
6436 0x485e, 0x00fe, 0x0005, 0x708b, 0x000d, 0x080c, 0x48c6, 0x20a3,
6437 0x1107, 0x20a3, 0x0000, 0x2099, 0xb28e, 0x20a9, 0x0040, 0x53a6,
6438 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0084, 0x080c, 0x4845,
6439 0x0005, 0x00f6, 0x7080, 0xa005, 0x01d0, 0x2011, 0x481b, 0x080c,
6440 0x650d, 0xa086, 0x0084, 0x1188, 0x2079, 0xb280, 0x7a30, 0xa296,
6441 0x1107, 0x1158, 0x7834, 0xa005, 0x1140, 0x7087, 0x0001, 0x080c,
6442 0x48b8, 0x708b, 0x000e, 0x0029, 0x0010, 0x080c, 0x485e, 0x00fe,
6443 0x0005, 0x708b, 0x000f, 0x7083, 0x0000, 0x608b, 0xbc85, 0x608f,
6444 0xb5b5, 0x6043, 0x0005, 0x6043, 0x0004, 0x2009, 0x07d0, 0x2011,
6445 0x481b, 0x080c, 0x6501, 0x0005, 0x7080, 0xa005, 0x0120, 0x2011,
6446 0x481b, 0x080c, 0x650d, 0x0005, 0x708b, 0x0011, 0x080c, 0x4917,
6447 0x1188, 0x716c, 0x81ff, 0x0170, 0x2009, 0x0000, 0x7070, 0xa084,
6448 0x00ff, 0x080c, 0x2676, 0xa186, 0x0080, 0x0120, 0x2011, 0xb28e,
6449 0x080c, 0x47df, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2099, 0xb280,
6450 0x20a1, 0x020b, 0x7480, 0xa480, 0x0018, 0xa080, 0x0007, 0xa084,
6451 0x03f8, 0x8004, 0x20a8, 0x53a6, 0x60c3, 0x0014, 0x080c, 0x4845,
6452 0x0005, 0x00f6, 0x7080, 0xa005, 0x01f0, 0x2011, 0x481b, 0x080c,
6453 0x650d, 0xa086, 0x0014, 0x11a8, 0x2079, 0xb280, 0x7a30, 0xa296,
6454 0x1103, 0x1178, 0x7834, 0xa005, 0x1160, 0x7a38, 0xd2fc, 0x0128,
6455 0x70b4, 0xa005, 0x1110, 0x70b7, 0x0001, 0x708b, 0x0012, 0x0029,
6456 0x0010, 0x080c, 0x485e, 0x00fe, 0x0005, 0x708b, 0x0013, 0x080c,
6457 0x48d2, 0x20a3, 0x1103, 0x20a3, 0x0000, 0x3430, 0x2011, 0xb28e,
6458 0x080c, 0x4917, 0x1160, 0x7074, 0xa005, 0x1148, 0x714c, 0xa186,
6459 0xffff, 0x0128, 0x080c, 0x47df, 0x0110, 0x080c, 0x48f5, 0x20a9,
6460 0x0008, 0x2298, 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000,
6461 0x60c3, 0x0014, 0x080c, 0x4845, 0x0005, 0x00f6, 0x7080, 0xa005,
6462 0x01f0, 0x2011, 0x481b, 0x080c, 0x650d, 0xa086, 0x0014, 0x11a8,
6463 0x2079, 0xb280, 0x7a30, 0xa296, 0x1104, 0x1178, 0x7834, 0xa005,
6464 0x1160, 0x7a38, 0xd2fc, 0x0128, 0x70b4, 0xa005, 0x1110, 0x70b7,
6465 0x0001, 0x708b, 0x0014, 0x0029, 0x0010, 0x080c, 0x485e, 0x00fe,
6466 0x0005, 0x708b, 0x0015, 0x080c, 0x48d2, 0x20a3, 0x1104, 0x20a3,
6467 0x0000, 0x3430, 0x2011, 0xb28e, 0x080c, 0x4917, 0x11a8, 0x7074,
6468 0xa005, 0x1190, 0x7154, 0xa186, 0xffff, 0x0170, 0xa180, 0x2be6,
6469 0x200d, 0xa18c, 0xff00, 0x810f, 0x080c, 0x47df, 0x0128, 0x080c,
6470 0x3e66, 0x0110, 0x080c, 0x26c0, 0x20a9, 0x0008, 0x2298, 0x26a0,
6471 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014, 0x080c,
6472 0x4845, 0x0005, 0x00f6, 0x7080, 0xa005, 0x05b8, 0x2011, 0x481b,
6473 0x080c, 0x650d, 0xa086, 0x0014, 0x1570, 0x2079, 0xb280, 0x7a30,
6474 0xa296, 0x1105, 0x1540, 0x7834, 0x2011, 0x0100, 0xa21e, 0x1148,
6475 0x7a38, 0xd2fc, 0x0128, 0x70b4, 0xa005, 0x1110, 0x70b7, 0x0001,
6476 0x0060, 0xa005, 0x11c0, 0x7a38, 0xd2fc, 0x0128, 0x70b4, 0xa005,
6477 0x1110, 0x70b7, 0x0001, 0x7087, 0x0000, 0x7a38, 0xd2f4, 0x0138,
6478 0x2001, 0xad73, 0x2004, 0xd0a4, 0x1110, 0x70d3, 0x0008, 0x708b,
6479 0x0016, 0x0029, 0x0010, 0x080c, 0x485e, 0x00fe, 0x0005, 0x20e1,
6480 0x9080, 0x20e1, 0x4000, 0x2099, 0xb280, 0x20a1, 0x020b, 0x20a9,
6481 0x000e, 0x53a6, 0x3430, 0x2011, 0xb28e, 0x708b, 0x0017, 0x080c,
6482 0x4917, 0x1150, 0x7074, 0xa005, 0x1138, 0x080c, 0x4754, 0x1170,
6483 0xa085, 0x0001, 0x080c, 0x26c0, 0x20a9, 0x0008, 0x2099, 0xb28e,
6484 0x26a0, 0x53a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014,
6485 0x080c, 0x4845, 0x0010, 0x080c, 0x436e, 0x0005, 0x00f6, 0x7080,
6486 0xa005, 0x01b0, 0x2011, 0x481b, 0x080c, 0x650d, 0xa086, 0x0084,
6487 0x1168, 0x2079, 0xb280, 0x7a30, 0xa296, 0x1106, 0x1138, 0x7834,
6488 0xa005, 0x1120, 0x708b, 0x0018, 0x0029, 0x0010, 0x080c, 0x485e,
6489 0x00fe, 0x0005, 0x708b, 0x0019, 0x080c, 0x48d2, 0x20a3, 0x1106,
6490 0x20a3, 0x0000, 0x3430, 0x2099, 0xb28e, 0x2039, 0xb20e, 0x27a0,
6491 0x20a9, 0x0040, 0x53a3, 0x080c, 0x4917, 0x11e8, 0x2728, 0x2514,
6492 0x8207, 0xa084, 0x00ff, 0x8000, 0x2018, 0xa294, 0x00ff, 0x8007,
6493 0xa205, 0x202a, 0x7050, 0x2310, 0x8214, 0xa2a0, 0xb20e, 0x2414,
6494 0xa38c, 0x0001, 0x0118, 0xa294, 0xff00, 0x0018, 0xa294, 0x00ff,
6495 0x8007, 0xa215, 0x2222, 0x2798, 0x26a0, 0x20a9, 0x0040, 0x53a6,
6496 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0084, 0x080c, 0x4845,
6497 0x0005, 0x00f6, 0x7080, 0xa005, 0x01d0, 0x2011, 0x481b, 0x080c,
6498 0x650d, 0xa086, 0x0084, 0x1188, 0x2079, 0xb280, 0x7a30, 0xa296,
6499 0x1107, 0x1158, 0x7834, 0xa005, 0x1140, 0x7087, 0x0001, 0x080c,
6500 0x48b8, 0x708b, 0x001a, 0x0029, 0x0010, 0x080c, 0x485e, 0x00fe,
6501 0x0005, 0x708b, 0x001b, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2099,
6502 0xb280, 0x20a1, 0x020b, 0x7480, 0xa480, 0x0018, 0xa080, 0x0007,
6503 0xa084, 0x03f8, 0x8004, 0x20a8, 0x53a6, 0x60c3, 0x0084, 0x080c,
6504 0x4845, 0x0005, 0x0005, 0x0005, 0x0086, 0x0096, 0x2029, 0xad52,
6505 0x252c, 0x20a9, 0x0008, 0x2041, 0xb20e, 0x28a0, 0x2099, 0xb28e,
6506 0x53a3, 0x20a9, 0x0008, 0x2011, 0x0007, 0xd5d4, 0x0110, 0x2011,
6507 0x0000, 0x2800, 0xa200, 0x200c, 0xa1a6, 0xffff, 0x1148, 0xd5d4,
6508 0x0110, 0x8210, 0x0008, 0x8211, 0x1f04, 0x4769, 0x0804, 0x47d7,
6509 0x82ff, 0x1160, 0xd5d4, 0x0120, 0xa1a6, 0x3fff, 0x0d90, 0x0020,
6510 0xa1a6, 0x3fff, 0x0904, 0x47d7, 0xa18d, 0xc000, 0x20a9, 0x0010,
6511 0x2019, 0x0001, 0xd5d4, 0x0110, 0x2019, 0x0010, 0x2120, 0xd5d4,
6512 0x0110, 0x8423, 0x0008, 0x8424, 0x1240, 0xd5d4, 0x0110, 0x8319,
6513 0x0008, 0x8318, 0x1f04, 0x478f, 0x04d0, 0x23a8, 0x2021, 0x0001,
6514 0x8426, 0x8425, 0x1f04, 0x47a1, 0x2328, 0x8529, 0xa2be, 0x0007,
6515 0x0158, 0x0006, 0x2039, 0x0007, 0x2200, 0xa73a, 0x000e, 0x27a8,
6516 0xa5a8, 0x0010, 0x1f04, 0x47b0, 0x754e, 0xa5c8, 0x2be6, 0x292d,
6517 0xa5ac, 0x00ff, 0x7572, 0x6532, 0x6536, 0x0016, 0x2508, 0x080c,
6518 0x26a0, 0x001e, 0x60e7, 0x0000, 0x65ea, 0x2018, 0x2304, 0xa405,
6519 0x201a, 0x7077, 0x0001, 0x26a0, 0x2898, 0x20a9, 0x0008, 0x53a6,
6520 0x20a3, 0x0000, 0x20a3, 0x0000, 0xa085, 0x0001, 0x0028, 0xa006,
6521 0x0018, 0xa006, 0x080c, 0x14f6, 0x009e, 0x008e, 0x0005, 0x2118,
6522 0x2021, 0x0000, 0x2001, 0x0007, 0xa39a, 0x0010, 0x0218, 0x8420,
6523 0x8001, 0x0cd0, 0x2118, 0x84ff, 0x0120, 0xa39a, 0x0010, 0x8421,
6524 0x1de0, 0x2021, 0x0001, 0x83ff, 0x0118, 0x8423, 0x8319, 0x1de8,
6525 0xa238, 0x2704, 0xa42c, 0x11b8, 0xa405, 0x203a, 0x714e, 0xa1a0,
6526 0x2be6, 0x242d, 0xa5ac, 0x00ff, 0x7572, 0x6532, 0x6536, 0x0016,
6527 0x2508, 0x080c, 0x26a0, 0x001e, 0x60e7, 0x0000, 0x65ea, 0x7077,
6528 0x0001, 0xa084, 0x0000, 0x0005, 0x00e6, 0x2071, 0xad00, 0x707b,
6529 0x0000, 0x00ee, 0x0005, 0x00e6, 0x00f6, 0x2079, 0x0100, 0x2071,
6530 0x0140, 0x080c, 0x7834, 0x7004, 0xa084, 0x4000, 0x0120, 0x7003,
6531 0x1000, 0x7003, 0x0000, 0x0126, 0x2091, 0x8000, 0x2071, 0xad22,
6532 0x2073, 0x0000, 0x7840, 0x0026, 0x0016, 0x2009, 0x00f7, 0x080c,
6533 0x48de, 0x001e, 0xa094, 0x0010, 0xa285, 0x0080, 0x7842, 0x7a42,
6534 0x002e, 0x012e, 0x00fe, 0x00ee, 0x0005, 0x0126, 0x2091, 0x8000,
6535 0x2011, 0xafd1, 0x2013, 0x0000, 0x7083, 0x0000, 0x012e, 0x20e1,
6536 0x9080, 0x60a3, 0x0056, 0x60a7, 0x9575, 0x080c, 0x782b, 0x2009,
6537 0x07d0, 0x2011, 0x481b, 0x080c, 0x6593, 0x0005, 0x0016, 0x0026,
6538 0x00c6, 0x0126, 0x2091, 0x8000, 0x2009, 0x00f7, 0x080c, 0x48de,
6539 0x2061, 0xafda, 0x601b, 0x0000, 0x601f, 0x0000, 0x2061, 0xad00,
6540 0x6003, 0x0001, 0x2061, 0x0100, 0x6043, 0x0090, 0x6043, 0x0010,
6541 0x2009, 0x002d, 0x2011, 0x4883, 0x080c, 0x6501, 0x012e, 0x00ce,
6542 0x002e, 0x001e, 0x0005, 0x00e6, 0x0006, 0x0126, 0x2091, 0x8000,
6543 0x2071, 0x0100, 0x080c, 0x7834, 0x2071, 0x0140, 0x7004, 0xa084,
6544 0x4000, 0x0120, 0x7003, 0x1000, 0x7003, 0x0000, 0x080c, 0x5757,
6545 0x01a8, 0x080c, 0x5775, 0x1190, 0x2001, 0xaf9d, 0x2003, 0xaaaa,
6546 0x0016, 0x080c, 0x2744, 0x2001, 0xaf8e, 0x2102, 0x001e, 0x2001,
6547 0xaf9e, 0x2003, 0x0000, 0x080c, 0x569a, 0x0030, 0x2001, 0x0001,
6548 0x080c, 0x261e, 0x080c, 0x485e, 0x012e, 0x000e, 0x00ee, 0x0005,
6549 0x20a9, 0x0040, 0x20a1, 0xb3c0, 0x2099, 0xb28e, 0x3304, 0x8007,
6550 0x20a2, 0x9398, 0x94a0, 0x1f04, 0x48be, 0x0005, 0x20e1, 0x9080,
6551 0x20e1, 0x4000, 0x2099, 0xb200, 0x20a1, 0x020b, 0x20a9, 0x000c,
6552 0x53a6, 0x0005, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x2099, 0xb280,
6553 0x20a1, 0x020b, 0x20a9, 0x000c, 0x53a6, 0x0005, 0x00c6, 0x0006,
6554 0x2061, 0x0100, 0x810f, 0x2001, 0xad30, 0x2004, 0xa005, 0x1138,
6555 0x2001, 0xad14, 0x2004, 0xa084, 0x00ff, 0xa105, 0x0010, 0xa185,
6556 0x00f7, 0x604a, 0x000e, 0x00ce, 0x0005, 0x0016, 0x0046, 0x2001,
6557 0xad52, 0x2004, 0xd0a4, 0x0158, 0xa006, 0x2020, 0x2009, 0x002a,
6558 0x080c, 0xa96c, 0x2001, 0xad0c, 0x200c, 0xc195, 0x2102, 0x2019,
6559 0x002a, 0x2009, 0x0000, 0x080c, 0x2aac, 0x004e, 0x001e, 0x0005,
6560 0x080c, 0x485e, 0x708b, 0x0000, 0x7083, 0x0000, 0x0005, 0x0006,
6561 0x2001, 0xad0c, 0x2004, 0xd09c, 0x0100, 0x000e, 0x0005, 0x0006,
6562 0x0016, 0x0126, 0x2091, 0x8000, 0x2001, 0x0101, 0x200c, 0xa18d,
6563 0x0006, 0x2102, 0x012e, 0x001e, 0x000e, 0x0005, 0x0156, 0x20a9,
6564 0x00ff, 0x2009, 0xae34, 0xa006, 0x200a, 0x8108, 0x1f04, 0x4934,
6565 0x015e, 0x0005, 0x00d6, 0x0036, 0x0156, 0x0136, 0x0146, 0x2069,
6566 0xad51, 0xa006, 0x6002, 0x6007, 0x0707, 0x600a, 0x600e, 0x6012,
6567 0xa198, 0x2be6, 0x231d, 0xa39c, 0x00ff, 0x6316, 0x20a9, 0x0004,
6568 0xac98, 0x0006, 0x23a0, 0x40a4, 0x20a9, 0x0004, 0xac98, 0x000a,
6569 0x23a0, 0x40a4, 0x603e, 0x6042, 0x604e, 0x6052, 0x6056, 0x605a,
6570 0x605e, 0x6062, 0x6066, 0x606a, 0x606e, 0x6072, 0x6076, 0x607a,
6571 0x607e, 0x6082, 0x6086, 0x608a, 0x608e, 0x6092, 0x6096, 0x609a,
6572 0x609e, 0x60ae, 0x61a2, 0x00d6, 0x60a4, 0xa06d, 0x0110, 0x080c,
6573 0x15f0, 0x60a7, 0x0000, 0x60a8, 0xa06d, 0x0110, 0x080c, 0x15f0,
6574 0x60ab, 0x0000, 0x00de, 0xa006, 0x604a, 0x6810, 0x603a, 0x680c,
6575 0x6046, 0x6814, 0xa084, 0x00ff, 0x6042, 0x014e, 0x013e, 0x015e,
6576 0x003e, 0x00de, 0x0005, 0x0126, 0x2091, 0x8000, 0x6944, 0x6e48,
6577 0xa684, 0x3fff, 0xa082, 0x4000, 0x1a04, 0x4a49, 0xa18c, 0xff00,
6578 0x810f, 0xa182, 0x00ff, 0x1a04, 0x4a4e, 0x2001, 0xad0c, 0x2004,
6579 0xa084, 0x0003, 0x01c0, 0x2001, 0xad0c, 0x2004, 0xd084, 0x1904,
6580 0x4a31, 0xa188, 0xae34, 0x2104, 0xa065, 0x0904, 0x4a31, 0x6004,
6581 0xa084, 0x00ff, 0xa08e, 0x0006, 0x1904, 0x4a31, 0x6000, 0xd0c4,
6582 0x0904, 0x4a31, 0x0068, 0xa188, 0xae34, 0x2104, 0xa065, 0x0904,
6583 0x4a15, 0x6004, 0xa084, 0x00ff, 0xa08e, 0x0006, 0x1904, 0x4a1a,
6584 0x60a4, 0xa00d, 0x0118, 0x080c, 0x4ef9, 0x05d0, 0x60a8, 0xa00d,
6585 0x0188, 0x080c, 0x4f43, 0x1170, 0x694c, 0xd1fc, 0x1118, 0x080c,
6586 0x4c11, 0x0448, 0x080c, 0x4bd3, 0x694c, 0xd1ec, 0x1520, 0x080c,
6587 0x4ded, 0x0408, 0x694c, 0xa184, 0xa000, 0x0178, 0xd1ec, 0x0140,
6588 0xd1fc, 0x0118, 0x080c, 0x4dfc, 0x0028, 0x080c, 0x4dfc, 0x0028,
6589 0xd1fc, 0x0118, 0x080c, 0x4bd3, 0x0070, 0x6050, 0xa00d, 0x0130,
6590 0x2d00, 0x200a, 0x6803, 0x0000, 0x6052, 0x0028, 0x2d00, 0x6052,
6591 0x604e, 0x6803, 0x0000, 0x080c, 0x67c5, 0xa006, 0x012e, 0x0005,
6592 0x2001, 0x0005, 0x2009, 0x0000, 0x04e8, 0x2001, 0x0028, 0x2009,
6593 0x0000, 0x04c0, 0xa082, 0x0006, 0x12a0, 0x2001, 0xad34, 0x2004,
6594 0xd0ac, 0x1160, 0x60a0, 0xd0bc, 0x1148, 0x6100, 0xd1fc, 0x0904,
6595 0x49d0, 0x2001, 0x0029, 0x2009, 0x1000, 0x0420, 0x2001, 0x0028,
6596 0x00a8, 0x2009, 0xad0c, 0x210c, 0xd18c, 0x0118, 0x2001, 0x0004,
6597 0x0068, 0xd184, 0x0118, 0x2001, 0x0004, 0x0040, 0x2001, 0x0029,
6598 0x6100, 0xd1fc, 0x0118, 0x2009, 0x1000, 0x0060, 0x2009, 0x0000,
6599 0x0048, 0x2001, 0x0029, 0x2009, 0x0000, 0x0020, 0x2001, 0x0029,
6600 0x2009, 0x0000, 0xa005, 0x012e, 0x0005, 0x00e6, 0x0126, 0x2091,
6601 0x8000, 0x6844, 0x8007, 0xa084, 0x00ff, 0x2008, 0xa182, 0x00ff,
6602 0x1a04, 0x4aa8, 0xa188, 0xae34, 0x2104, 0xa065, 0x01c0, 0x6004,
6603 0xa084, 0x00ff, 0xa08e, 0x0006, 0x11a8, 0x2c70, 0x080c, 0x8022,
6604 0x05e8, 0x2e00, 0x601a, 0x2d00, 0x6012, 0x600b, 0xffff, 0x601f,
6605 0x000a, 0x2009, 0x0003, 0x080c, 0x80a7, 0xa006, 0x0460, 0x2001,
6606 0x0028, 0x0440, 0xa082, 0x0006, 0x1298, 0x2001, 0xad34, 0x2004,
6607 0xd0ac, 0x1158, 0x60a0, 0xd0bc, 0x1140, 0x6100, 0xd1fc, 0x09e8,
6608 0x2001, 0x0029, 0x2009, 0x1000, 0x00a8, 0x2001, 0x0028, 0x0090,
6609 0x2009, 0xad0c, 0x210c, 0xd18c, 0x0118, 0x2001, 0x0004, 0x0050,
6610 0xd184, 0x0118, 0x2001, 0x0004, 0x0028, 0x2001, 0x0029, 0x0010,
6611 0x2001, 0x0029, 0xa005, 0x012e, 0x00ee, 0x0005, 0x2001, 0x002c,
6612 0x0cc8, 0x00f6, 0x00e6, 0x0126, 0x2091, 0x8000, 0x2011, 0x0000,
6613 0x2079, 0xad00, 0x6944, 0xa18c, 0xff00, 0x810f, 0xa182, 0x00ff,
6614 0x1a04, 0x4b77, 0x2001, 0xad0c, 0x2004, 0xa084, 0x0003, 0x1904,
6615 0x4b65, 0x080c, 0x4cdc, 0x1180, 0x6004, 0xa084, 0x00ff, 0xa082,
6616 0x0006, 0x1250, 0x2001, 0xad34, 0x2004, 0xd0ac, 0x1904, 0x4b60,
6617 0x60a0, 0xd0bc, 0x1904, 0x4b60, 0x6864, 0xa0c6, 0x006f, 0x0118,
6618 0x2008, 0x0804, 0x4b28, 0x6968, 0x2140, 0xa18c, 0xff00, 0x810f,
6619 0x78d0, 0xd0ac, 0x1118, 0xa182, 0x0080, 0x06d0, 0xa182, 0x00ff,
6620 0x16b8, 0x6a70, 0x6b6c, 0x786c, 0xa306, 0x1160, 0x7870, 0xa24e,
6621 0x1118, 0x2208, 0x2310, 0x0460, 0xa9cc, 0xff00, 0x1118, 0x2208,
6622 0x2310, 0x0430, 0x080c, 0x3b58, 0x2c70, 0x0550, 0x2009, 0x0000,
6623 0x2011, 0x0000, 0xa0c6, 0x4000, 0x1160, 0x0006, 0x2e60, 0x080c,
6624 0x4f6e, 0x1108, 0xc185, 0x7000, 0xd0bc, 0x0108, 0xc18d, 0x000e,
6625 0x0088, 0xa0c6, 0x4007, 0x1110, 0x2408, 0x0060, 0xa0c6, 0x4008,
6626 0x1118, 0x2708, 0x2610, 0x0030, 0xa0c6, 0x4009, 0x1108, 0x0010,
6627 0x2001, 0x4006, 0x6866, 0x696a, 0x6a6e, 0x2001, 0x0030, 0x0458,
6628 0x080c, 0x8022, 0x1138, 0x2001, 0x4005, 0x2009, 0x0003, 0x2011,
6629 0x0000, 0x0c80, 0x2e00, 0x601a, 0x080c, 0x9956, 0x2d00, 0x6012,
6630 0x601f, 0x0001, 0xa006, 0xd88c, 0x0110, 0x2001, 0x4000, 0x683a,
6631 0x0126, 0x2091, 0x8000, 0x080c, 0x2ad9, 0x012e, 0x2001, 0x0000,
6632 0x080c, 0x4c1e, 0x2001, 0x0002, 0x080c, 0x4c30, 0x2009, 0x0002,
6633 0x080c, 0x80a7, 0xa006, 0xa005, 0x012e, 0x00ee, 0x00fe, 0x0005,
6634 0x2001, 0x0028, 0x2009, 0x0000, 0x0cb0, 0x2009, 0xad0c, 0x210c,
6635 0xd18c, 0x0118, 0x2001, 0x0004, 0x0038, 0xd184, 0x0118, 0x2001,
6636 0x0004, 0x0010, 0x2001, 0x0029, 0x2009, 0x0000, 0x0c20, 0x2001,
6637 0x0029, 0x2009, 0x0000, 0x08f8, 0x6944, 0x6e48, 0xa684, 0x3fff,
6638 0xa082, 0x4000, 0x16b8, 0xa18c, 0xff00, 0x810f, 0xa182, 0x00ff,
6639 0x12e0, 0xa188, 0xae34, 0x2104, 0xa065, 0x01b8, 0x6004, 0xa084,
6640 0x00ff, 0xa08e, 0x0006, 0x11b0, 0x684c, 0xd0ec, 0x0120, 0x080c,
6641 0x4dfc, 0x04c9, 0x0030, 0x04b9, 0x684c, 0xd0fc, 0x0110, 0x080c,
6642 0x4ded, 0x080c, 0x4e3a, 0xa006, 0x00c8, 0x2001, 0x0028, 0x2009,
6643 0x0000, 0x00a0, 0xa082, 0x0006, 0x1240, 0x6100, 0xd1fc, 0x0d20,
6644 0x2001, 0x0029, 0x2009, 0x1000, 0x0048, 0x2001, 0x0029, 0x2009,
6645 0x0000, 0x0020, 0x2001, 0x0029, 0x2009, 0x0000, 0xa005, 0x0005,
6646 0x0126, 0x2091, 0x8000, 0x6050, 0xa00d, 0x0138, 0x2d00, 0x200a,
6647 0x6803, 0x0000, 0x6052, 0x012e, 0x0005, 0x2d00, 0x6052, 0x604e,
6648 0x6803, 0x0000, 0x0cc0, 0x0126, 0x2091, 0x8000, 0x604c, 0xa005,
6649 0x0170, 0x00e6, 0x2071, 0xafc7, 0x7004, 0xa086, 0x0002, 0x0168,
6650 0x00ee, 0x604c, 0x6802, 0x2d00, 0x604e, 0x012e, 0x0005, 0x2d00,
6651 0x6052, 0x604e, 0x6803, 0x0000, 0x0cc0, 0x701c, 0xac06, 0x1d80,
6652 0x604c, 0x2070, 0x7000, 0x6802, 0x2d00, 0x7002, 0x00ee, 0x012e,
6653 0x0005, 0x0126, 0x2091, 0x8000, 0x604c, 0xa06d, 0x0130, 0x6800,
6654 0xa005, 0x1108, 0x6052, 0x604e, 0xad05, 0x012e, 0x0005, 0x604c,
6655 0xa06d, 0x0130, 0x6800, 0xa005, 0x1108, 0x6052, 0x604e, 0xad05,
6656 0x0005, 0x6803, 0x0000, 0x6084, 0xa00d, 0x0120, 0x2d00, 0x200a,
6657 0x6086, 0x0005, 0x2d00, 0x6086, 0x6082, 0x0cd8, 0x0126, 0x00c6,
6658 0x0026, 0x2091, 0x8000, 0x6218, 0x2260, 0x6200, 0xa005, 0x0110,
6659 0xc285, 0x0008, 0xc284, 0x6202, 0x002e, 0x00ce, 0x012e, 0x0005,
6660 0x0126, 0x00c6, 0x2091, 0x8000, 0x6218, 0x2260, 0x6204, 0x0006,
6661 0xa086, 0x0006, 0x1180, 0x609c, 0xd0ac, 0x0168, 0x2001, 0xad52,
6662 0x2004, 0xd0a4, 0x0140, 0xa284, 0xff00, 0x8007, 0xa086, 0x0007,
6663 0x1110, 0x2011, 0x0600, 0x000e, 0xa294, 0xff00, 0xa215, 0x6206,
6664 0x0006, 0xa086, 0x0006, 0x1128, 0x6290, 0x82ff, 0x1110, 0x080c,
6665 0x14f6, 0x000e, 0x00ce, 0x012e, 0x0005, 0x0126, 0x00c6, 0x2091,
6666 0x8000, 0x6218, 0x2260, 0x6204, 0x0006, 0xa086, 0x0006, 0x1178,
6667 0x609c, 0xd0a4, 0x0160, 0x2001, 0xad52, 0x2004, 0xd0ac, 0x1138,
6668 0xa284, 0x00ff, 0xa086, 0x0007, 0x1110, 0x2011, 0x0006, 0x000e,
6669 0xa294, 0x00ff, 0x8007, 0xa215, 0x6206, 0x00ce, 0x012e, 0x0005,
6670 0x0026, 0xa182, 0x00ff, 0x0218, 0xa085, 0x0001, 0x00b0, 0xa190,
6671 0xae34, 0x2204, 0xa065, 0x1180, 0x0016, 0x00d6, 0x080c, 0x15c0,
6672 0x2d60, 0x00de, 0x001e, 0x0d80, 0x2c00, 0x2012, 0x60a7, 0x0000,
6673 0x60ab, 0x0000, 0x080c, 0x493a, 0xa006, 0x002e, 0x0005, 0x0126,
6674 0x2091, 0x8000, 0x0026, 0xa182, 0x00ff, 0x0218, 0xa085, 0x0001,
6675 0x0480, 0x00d6, 0xa190, 0xae34, 0x2204, 0xa06d, 0x0540, 0x2013,
6676 0x0000, 0x00d6, 0x00c6, 0x2d60, 0x60a4, 0xa06d, 0x0110, 0x080c,
6677 0x15f0, 0x60a8, 0xa06d, 0x0110, 0x080c, 0x15f0, 0x00ce, 0x00de,
6678 0x00d6, 0x00c6, 0x68ac, 0x2060, 0x8cff, 0x0168, 0x600c, 0x0006,
6679 0x6010, 0x2068, 0x080c, 0x9596, 0x0110, 0x080c, 0x1600, 0x080c,
6680 0x8078, 0x00ce, 0x0c88, 0x00ce, 0x00de, 0x080c, 0x15f0, 0x00de,
6681 0xa006, 0x002e, 0x012e, 0x0005, 0x0016, 0xa182, 0x00ff, 0x0218,
6682 0xa085, 0x0001, 0x0030, 0xa188, 0xae34, 0x2104, 0xa065, 0x0dc0,
6683 0xa006, 0x001e, 0x0005, 0x00d6, 0x0156, 0x0136, 0x0146, 0x600b,
6684 0x0000, 0x600f, 0x0000, 0x6000, 0xc08c, 0x6002, 0x080c, 0x574f,
6685 0x1538, 0x60a0, 0xa086, 0x007e, 0x2069, 0xb290, 0x0130, 0x2001,
6686 0xad34, 0x2004, 0xd0ac, 0x11e0, 0x0098, 0x2d04, 0xd0e4, 0x01c0,
6687 0x00d6, 0x2069, 0xb28e, 0x00c6, 0x2061, 0xaf9f, 0x6810, 0x2062,
6688 0x6814, 0x6006, 0x6818, 0x600a, 0x681c, 0x600e, 0x00ce, 0x00de,
6689 0x8d69, 0x2d04, 0x2069, 0x0140, 0x6886, 0x2069, 0xad00, 0x68a2,
6690 0x2069, 0xb28e, 0x6808, 0x605e, 0x6810, 0x6062, 0x6138, 0xa10a,
6691 0x0208, 0x603a, 0x6814, 0x6066, 0x2099, 0xb296, 0xac88, 0x000a,
6692 0x21a0, 0x20a9, 0x0004, 0x53a3, 0x2099, 0xb29a, 0xac88, 0x0006,
6693 0x21a0, 0x20a9, 0x0004, 0x53a3, 0x2069, 0xb2ae, 0x6808, 0x606a,
6694 0x690c, 0x616e, 0x6810, 0x6072, 0x6818, 0x6076, 0xa182, 0x0211,
6695 0x1218, 0x2009, 0x0008, 0x0400, 0xa182, 0x0259, 0x1218, 0x2009,
6696 0x0007, 0x00d0, 0xa182, 0x02c1, 0x1218, 0x2009, 0x0006, 0x00a0,
6697 0xa182, 0x0349, 0x1218, 0x2009, 0x0005, 0x0070, 0xa182, 0x0421,
6698 0x1218, 0x2009, 0x0004, 0x0040, 0xa182, 0x0581, 0x1218, 0x2009,
6699 0x0003, 0x0010, 0x2009, 0x0002, 0x6192, 0x014e, 0x013e, 0x015e,
6700 0x00de, 0x0005, 0x0016, 0x0026, 0x00e6, 0x2071, 0xb28d, 0x2e04,
6701 0x6896, 0x2071, 0xb28e, 0x7004, 0x689a, 0x701c, 0x689e, 0x6a00,
6702 0x2009, 0xad71, 0x210c, 0xd0bc, 0x0120, 0xd1ec, 0x0110, 0xc2ad,
6703 0x0008, 0xc2ac, 0xd0c4, 0x0120, 0xd1e4, 0x0110, 0xc2bd, 0x0008,
6704 0xc2bc, 0x6a02, 0x00ee, 0x002e, 0x001e, 0x0005, 0x00d6, 0x0126,
6705 0x2091, 0x8000, 0x60a4, 0xa06d, 0x01c0, 0x6900, 0x81ff, 0x1540,
6706 0x6a04, 0xa282, 0x0010, 0x1648, 0xad88, 0x0004, 0x20a9, 0x0010,
6707 0x2104, 0xa086, 0xffff, 0x0128, 0x8108, 0x1f04, 0x4da8, 0x080c,
6708 0x14f6, 0x260a, 0x8210, 0x6a06, 0x0098, 0x080c, 0x15d9, 0x01a8,
6709 0x2d00, 0x60a6, 0x6803, 0x0000, 0xad88, 0x0004, 0x20a9, 0x0010,
6710 0x200b, 0xffff, 0x8108, 0x1f04, 0x4dc0, 0x6807, 0x0001, 0x6e12,
6711 0xa085, 0x0001, 0x012e, 0x00de, 0x0005, 0xa006, 0x0cd8, 0x0126,
6712 0x2091, 0x8000, 0x00d6, 0x60a4, 0xa00d, 0x01a0, 0x2168, 0x6800,
6713 0xa005, 0x1160, 0x080c, 0x4ef9, 0x1168, 0x200b, 0xffff, 0x6804,
6714 0xa08a, 0x0002, 0x0218, 0x8001, 0x6806, 0x0020, 0x080c, 0x15f0,
6715 0x60a7, 0x0000, 0x00de, 0x012e, 0x0005, 0x0126, 0x2091, 0x8000,
6716 0x080c, 0x4f56, 0x0010, 0x080c, 0x4bc0, 0x080c, 0x4e71, 0x1dd8,
6717 0x080c, 0x4e3a, 0x012e, 0x0005, 0x00d6, 0x0126, 0x2091, 0x8000,
6718 0x60a8, 0xa06d, 0x01c0, 0x6950, 0x81ff, 0x1540, 0x6a54, 0xa282,
6719 0x0010, 0x1670, 0xad88, 0x0018, 0x20a9, 0x0010, 0x2104, 0xa086,
6720 0xffff, 0x0128, 0x8108, 0x1f04, 0x4e0e, 0x080c, 0x14f6, 0x260a,
6721 0x8210, 0x6a56, 0x0098, 0x080c, 0x15d9, 0x01d0, 0x2d00, 0x60aa,
6722 0x6853, 0x0000, 0xad88, 0x0018, 0x20a9, 0x0010, 0x200b, 0xffff,
6723 0x8108, 0x1f04, 0x4e26, 0x6857, 0x0001, 0x6e62, 0x0010, 0x080c,
6724 0x4c11, 0x0089, 0x1de0, 0xa085, 0x0001, 0x012e, 0x00de, 0x0005,
6725 0xa006, 0x0cd8, 0x0126, 0x2091, 0x8000, 0x080c, 0x67c5, 0x012e,
6726 0x0005, 0xa01e, 0x0010, 0x2019, 0x0001, 0xa00e, 0x0126, 0x2091,
6727 0x8000, 0x604c, 0x2068, 0x6000, 0xd0dc, 0x1170, 0x8dff, 0x01e8,
6728 0x83ff, 0x0120, 0x6848, 0xa606, 0x0158, 0x0030, 0x683c, 0xa406,
6729 0x1118, 0x6840, 0xa506, 0x0120, 0x2d08, 0x6800, 0x2068, 0x0c70,
6730 0x6a00, 0x604c, 0xad06, 0x1110, 0x624e, 0x0018, 0xa180, 0x0000,
6731 0x2202, 0x82ff, 0x1110, 0x6152, 0x8dff, 0x012e, 0x0005, 0xa01e,
6732 0x0010, 0x2019, 0x0001, 0xa00e, 0x6080, 0x2068, 0x8dff, 0x01e8,
6733 0x83ff, 0x0120, 0x6848, 0xa606, 0x0158, 0x0030, 0x683c, 0xa406,
6734 0x1118, 0x6840, 0xa506, 0x0120, 0x2d08, 0x6800, 0x2068, 0x0c70,
6735 0x6a00, 0x6080, 0xad06, 0x1110, 0x6282, 0x0018, 0xa180, 0x0000,
6736 0x2202, 0x82ff, 0x1110, 0x6186, 0x8dff, 0x0005, 0xa016, 0x080c,
6737 0x4ef3, 0x1110, 0x2011, 0x0001, 0x080c, 0x4f3d, 0x1110, 0xa295,
6738 0x0002, 0x0005, 0x080c, 0x4f6e, 0x0118, 0x080c, 0x964b, 0x0010,
6739 0xa085, 0x0001, 0x0005, 0x080c, 0x4f6e, 0x0118, 0x080c, 0x95e4,
6740 0x0010, 0xa085, 0x0001, 0x0005, 0x080c, 0x4f6e, 0x0118, 0x080c,
6741 0x962e, 0x0010, 0xa085, 0x0001, 0x0005, 0x080c, 0x4f6e, 0x0118,
6742 0x080c, 0x9600, 0x0010, 0xa085, 0x0001, 0x0005, 0x080c, 0x4f6e,
6743 0x0118, 0x080c, 0x9667, 0x0010, 0xa085, 0x0001, 0x0005, 0x0126,
6744 0x0006, 0x00d6, 0x2091, 0x8000, 0x6080, 0xa06d, 0x01a0, 0x6800,
6745 0x0006, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c, 0x97fd,
6746 0x0006, 0x6000, 0xd0fc, 0x0110, 0x080c, 0xac03, 0x000e, 0x080c,
6747 0x510c, 0x000e, 0x0c50, 0x6083, 0x0000, 0x6087, 0x0000, 0x00de,
6748 0x000e, 0x012e, 0x0005, 0x60a4, 0xa00d, 0x1118, 0xa085, 0x0001,
6749 0x0005, 0x00e6, 0x2170, 0x7000, 0xa005, 0x1160, 0x20a9, 0x0010,
6750 0xae88, 0x0004, 0x2104, 0xa606, 0x0128, 0x8108, 0x1f04, 0x4f02,
6751 0xa085, 0x0001, 0xa006, 0x00ee, 0x0005, 0x00d6, 0x0126, 0x2091,
6752 0x8000, 0x60a4, 0xa06d, 0x1128, 0x080c, 0x15d9, 0x01a0, 0x2d00,
6753 0x60a6, 0x6803, 0x0001, 0x6807, 0x0000, 0xad88, 0x0004, 0x20a9,
6754 0x0010, 0x200b, 0xffff, 0x8108, 0x1f04, 0x4f21, 0xa085, 0x0001,
6755 0x012e, 0x00de, 0x0005, 0xa006, 0x0cd8, 0x00d6, 0x0126, 0x2091,
6756 0x8000, 0x60a4, 0xa06d, 0x0130, 0x60a7, 0x0000, 0x080c, 0x15f0,
6757 0xa085, 0x0001, 0x012e, 0x00de, 0x0005, 0x60a8, 0xa00d, 0x1118,
6758 0xa085, 0x0001, 0x0005, 0x00e6, 0x2170, 0x7050, 0xa005, 0x1160,
6759 0x20a9, 0x0010, 0xae88, 0x0018, 0x2104, 0xa606, 0x0128, 0x8108,
6760 0x1f04, 0x4f4c, 0xa085, 0x0001, 0x00ee, 0x0005, 0x0126, 0x2091,
6761 0x8000, 0x0c19, 0x1188, 0x200b, 0xffff, 0x00d6, 0x60a8, 0x2068,
6762 0x6854, 0xa08a, 0x0002, 0x0218, 0x8001, 0x6856, 0x0020, 0x080c,
6763 0x15f0, 0x60ab, 0x0000, 0x00de, 0x012e, 0x0005, 0x609c, 0xd0a4,
6764 0x0005, 0x00f6, 0x080c, 0x574f, 0x01b0, 0x71b4, 0x81ff, 0x1198,
6765 0x71d0, 0xd19c, 0x0180, 0x2001, 0x007e, 0xa080, 0xae34, 0x2004,
6766 0xa07d, 0x0148, 0x7804, 0xa084, 0x00ff, 0xa086, 0x0006, 0x1118,
6767 0x7800, 0xc0ed, 0x7802, 0x2079, 0xad51, 0x7804, 0xd0a4, 0x01e8,
6768 0x0156, 0x00c6, 0x20a9, 0x007f, 0x2009, 0x0000, 0x0016, 0x080c,
6769 0x4cdc, 0x1168, 0x6004, 0xa084, 0xff00, 0x8007, 0xa096, 0x0004,
6770 0x0118, 0xa086, 0x0006, 0x1118, 0x6000, 0xc0ed, 0x6002, 0x001e,
6771 0x8108, 0x1f04, 0x4f96, 0x00ce, 0x015e, 0x080c, 0x502d, 0x0120,
6772 0x2001, 0xafa2, 0x200c, 0x0038, 0x2079, 0xad51, 0x7804, 0xd0a4,
6773 0x0130, 0x2009, 0x07d0, 0x2011, 0x4fc1, 0x080c, 0x6593, 0x00fe,
6774 0x0005, 0x2011, 0x4fc1, 0x080c, 0x650d, 0x080c, 0x502d, 0x01f0,
6775 0x2001, 0xaeb2, 0x2004, 0xa080, 0x0000, 0x200c, 0xc1ec, 0x2102,
6776 0x2001, 0xad52, 0x2004, 0xd0a4, 0x0130, 0x2009, 0x07d0, 0x2011,
6777 0x4fc1, 0x080c, 0x6593, 0x00e6, 0x2071, 0xad00, 0x706f, 0x0000,
6778 0x7073, 0x0000, 0x080c, 0x28fa, 0x00ee, 0x04b0, 0x0156, 0x00c6,
6779 0x20a9, 0x007f, 0x2009, 0x0000, 0x0016, 0x080c, 0x4cdc, 0x1530,
6780 0x6000, 0xd0ec, 0x0518, 0x0046, 0x62a0, 0xa294, 0x00ff, 0x8227,
6781 0xa006, 0x2009, 0x0029, 0x080c, 0xa96c, 0x6000, 0xc0e5, 0xc0ec,
6782 0x6002, 0x6004, 0xa084, 0x00ff, 0xa085, 0x0700, 0x6006, 0x2019,
6783 0x0029, 0x080c, 0x68e7, 0x0076, 0x2039, 0x0000, 0x080c, 0x681d,
6784 0x2009, 0x0000, 0x080c, 0xa712, 0x007e, 0x004e, 0x001e, 0x8108,
6785 0x1f04, 0x4fec, 0x00ce, 0x015e, 0x0005, 0x00c6, 0x6018, 0x2060,
6786 0x6000, 0xc0ec, 0x6002, 0x00ce, 0x0005, 0x7818, 0x2004, 0xd0ac,
6787 0x0005, 0x7818, 0x2004, 0xd0bc, 0x0005, 0x00f6, 0x2001, 0xaeb2,
6788 0x2004, 0xa07d, 0x0110, 0x7800, 0xd0ec, 0x00fe, 0x0005, 0x0126,
6789 0x0026, 0x2091, 0x8000, 0x6200, 0xa005, 0x0110, 0xc2fd, 0x0008,
6790 0xc2fc, 0x6202, 0x002e, 0x012e, 0x0005, 0x2071, 0xae13, 0x7003,
6791 0x0001, 0x7007, 0x0000, 0x7013, 0x0000, 0x7017, 0x0000, 0x701b,
6792 0x0000, 0x701f, 0x0000, 0x700b, 0x0000, 0x704b, 0x0001, 0x704f,
6793 0x0000, 0x705b, 0x0020, 0x705f, 0x0040, 0x707f, 0x0000, 0x2071,
6794 0xaf7c, 0x7003, 0xae13, 0x7007, 0x0000, 0x700b, 0x0000, 0x700f,
6795 0xaf5c, 0x7013, 0x0020, 0x7017, 0x0040, 0x7037, 0x0000, 0x0005,
6796 0x0016, 0x00e6, 0x2071, 0xaf34, 0xa00e, 0x7186, 0x718a, 0x7097,
6797 0x0001, 0x2001, 0xad52, 0x2004, 0xd0fc, 0x1150, 0x2001, 0xad52,
6798 0x2004, 0xa00e, 0xd09c, 0x0108, 0x8108, 0x7102, 0x0804, 0x50d6,
6799 0x2001, 0xad71, 0x200c, 0xa184, 0x000f, 0x2009, 0xad72, 0x210c,
6800 0x0002, 0x507e, 0x50b1, 0x50b8, 0x50c2, 0x50c7, 0x507e, 0x507e,
6801 0x507e, 0x50a1, 0x507e, 0x507e, 0x507e, 0x507e, 0x507e, 0x507e,
6802 0x507e, 0x7003, 0x0004, 0x0136, 0x0146, 0x0156, 0x2099, 0xad75,
6803 0x20a1, 0xaf85, 0x20a9, 0x0004, 0x53a3, 0x015e, 0x014e, 0x013e,
6804 0x0428, 0x708f, 0x0005, 0x7007, 0x0122, 0x2001, 0x0002, 0x0030,
6805 0x708f, 0x0002, 0x7007, 0x0121, 0x2001, 0x0003, 0x7002, 0x7097,
6806 0x0001, 0x0088, 0x7007, 0x0122, 0x2001, 0x0002, 0x0020, 0x7007,
6807 0x0121, 0x2001, 0x0003, 0x7002, 0xa006, 0x7096, 0x708e, 0xa184,
6808 0xff00, 0x8007, 0x709a, 0xa184, 0x00ff, 0x7092, 0x00ee, 0x001e,
6809 0x0005, 0x00e6, 0x2071, 0xae13, 0x684c, 0xa005, 0x1130, 0x7028,
6810 0xc085, 0x702a, 0xa085, 0x0001, 0x0428, 0x6a60, 0x7236, 0x6b64,
6811 0x733a, 0x6868, 0x703e, 0x7076, 0x686c, 0x7042, 0x707a, 0x684c,
6812 0x702e, 0x6844, 0x7032, 0x2009, 0x000d, 0x200a, 0x700b, 0x0000,
6813 0x8007, 0x8006, 0x8006, 0xa08c, 0x003f, 0xa084, 0xffc0, 0xa210,
6814 0x2100, 0xa319, 0x726e, 0x7372, 0x7028, 0xc084, 0x702a, 0x7007,
6815 0x0001, 0xa006, 0x00ee, 0x0005, 0x0156, 0x00e6, 0x0026, 0x6838,
6816 0xd0fc, 0x1904, 0x5165, 0x6804, 0xa00d, 0x0188, 0x00d6, 0x2071,
6817 0xad00, 0xa016, 0x702c, 0x2168, 0x6904, 0x206a, 0x8210, 0x2d00,
6818 0x81ff, 0x1dc8, 0x702e, 0x70b0, 0xa200, 0x70b2, 0x00de, 0x2071,
6819 0xae13, 0x701c, 0xa005, 0x1904, 0x5175, 0x20a9, 0x0032, 0x0f04,
6820 0x5173, 0x0e04, 0x512f, 0x2071, 0xaf34, 0x7200, 0x82ff, 0x05d8,
6821 0x6934, 0xa186, 0x0103, 0x1904, 0x5183, 0x6948, 0x6844, 0xa105,
6822 0x1540, 0x2009, 0x8020, 0x2200, 0x0002, 0x5173, 0x514a, 0x519b,
6823 0x51a7, 0x5173, 0x2071, 0x0000, 0x20a9, 0x0032, 0x0f04, 0x5173,
6824 0x7018, 0xd084, 0x1dd8, 0x7122, 0x683c, 0x7026, 0x6840, 0x702a,
6825 0x701b, 0x0001, 0x2091, 0x4080, 0x2071, 0xad00, 0x702c, 0x206a,
6826 0x2d00, 0x702e, 0x70b0, 0x8000, 0x70b2, 0x002e, 0x00ee, 0x015e,
6827 0x0005, 0x6844, 0xa086, 0x0100, 0x1130, 0x6868, 0xa005, 0x1118,
6828 0x2009, 0x8020, 0x0880, 0x2071, 0xae13, 0x2d08, 0x206b, 0x0000,
6829 0x7010, 0x8000, 0x7012, 0x7018, 0xa06d, 0x711a, 0x0110, 0x6902,
6830 0x0008, 0x711e, 0x0c10, 0xa18c, 0x00ff, 0xa186, 0x0017, 0x0130,
6831 0xa186, 0x001e, 0x0118, 0xa18e, 0x001f, 0x1d28, 0x684c, 0xd0cc,
6832 0x0d10, 0x6850, 0xa084, 0x00ff, 0xa086, 0x0001, 0x19e0, 0x2009,
6833 0x8021, 0x0804, 0x5143, 0x7084, 0x8008, 0xa092, 0x001e, 0x1a98,
6834 0x7186, 0xae90, 0x0003, 0xa210, 0x683c, 0x2012, 0x0078, 0x7084,
6835 0x8008, 0xa092, 0x000f, 0x1a38, 0x7186, 0xae90, 0x0003, 0x8003,
6836 0xa210, 0x683c, 0x2012, 0x8210, 0x6840, 0x2012, 0x7088, 0xa10a,
6837 0x0a04, 0x515c, 0x718c, 0x7084, 0xa10a, 0x0a04, 0x515c, 0x2071,
6838 0x0000, 0x7018, 0xd084, 0x1904, 0x515c, 0x2071, 0xaf34, 0x7000,
6839 0xa086, 0x0002, 0x1150, 0x080c, 0x5426, 0x2071, 0x0000, 0x701b,
6840 0x0001, 0x2091, 0x4080, 0x0804, 0x515c, 0x080c, 0x5450, 0x2071,
6841 0x0000, 0x701b, 0x0001, 0x2091, 0x4080, 0x0804, 0x515c, 0x0006,
6842 0x684c, 0x0006, 0x6837, 0x0103, 0x20a9, 0x001c, 0xad80, 0x0011,
6843 0x20a0, 0x2001, 0x0000, 0x40a4, 0x000e, 0xa084, 0x00ff, 0x684e,
6844 0x000e, 0x684a, 0x6952, 0x0005, 0x2071, 0xae13, 0x7004, 0x0002,
6845 0x5202, 0x5213, 0x5411, 0x5412, 0x541f, 0x5425, 0x5203, 0x5402,
6846 0x5398, 0x53ee, 0x0005, 0x0126, 0x2091, 0x8000, 0x0e04, 0x5212,
6847 0x2009, 0x000d, 0x7030, 0x200a, 0x2091, 0x4080, 0x7007, 0x0001,
6848 0x700b, 0x0000, 0x012e, 0x2069, 0xafda, 0x683c, 0xa005, 0x03f8,
6849 0x11f0, 0x0126, 0x2091, 0x8000, 0x2069, 0x0000, 0x6934, 0x2001,
6850 0xae1f, 0x2004, 0xa10a, 0x0170, 0x0e04, 0x5236, 0x2069, 0x0000,
6851 0x6818, 0xd084, 0x1158, 0x2009, 0x8040, 0x6922, 0x681b, 0x0001,
6852 0x2091, 0x4080, 0x2069, 0xafda, 0x683f, 0xffff, 0x012e, 0x2069,
6853 0xad00, 0x6844, 0x6964, 0xa102, 0x2069, 0xaf34, 0x688a, 0x6984,
6854 0x701c, 0xa06d, 0x0120, 0x81ff, 0x0904, 0x528c, 0x00a0, 0x81ff,
6855 0x0904, 0x5352, 0x2071, 0xaf34, 0x7184, 0x7088, 0xa10a, 0x1258,
6856 0x7190, 0x2071, 0xafda, 0x7038, 0xa005, 0x0128, 0x1b04, 0x5352,
6857 0x713a, 0x0804, 0x5352, 0x2071, 0xaf34, 0x718c, 0x0126, 0x2091,
6858 0x8000, 0x7084, 0xa10a, 0x0a04, 0x536d, 0x0e04, 0x530e, 0x2071,
6859 0x0000, 0x7018, 0xd084, 0x1904, 0x530e, 0x2001, 0xffff, 0x2071,
6860 0xafda, 0x703a, 0x2071, 0xaf34, 0x7000, 0xa086, 0x0002, 0x1150,
6861 0x080c, 0x5426, 0x2071, 0x0000, 0x701b, 0x0001, 0x2091, 0x4080,
6862 0x0804, 0x530e, 0x080c, 0x5450, 0x2071, 0x0000, 0x701b, 0x0001,
6863 0x2091, 0x4080, 0x0804, 0x530e, 0x2071, 0xaf34, 0x7000, 0xa005,
6864 0x0904, 0x5334, 0x6934, 0xa186, 0x0103, 0x1904, 0x5311, 0x684c,
6865 0xd0bc, 0x1904, 0x5334, 0x6948, 0x6844, 0xa105, 0x1904, 0x5329,
6866 0x2009, 0x8020, 0x2071, 0xaf34, 0x7000, 0x0002, 0x5334, 0x52f4,
6867 0x52cc, 0x52de, 0x52ab, 0x0136, 0x0146, 0x0156, 0x2099, 0xad75,
6868 0x20a1, 0xaf85, 0x20a9, 0x0004, 0x53a3, 0x015e, 0x014e, 0x013e,
6869 0x2071, 0xaf7c, 0xad80, 0x000f, 0x700e, 0x7013, 0x0002, 0x7007,
6870 0x0002, 0x700b, 0x0000, 0x2e10, 0x080c, 0x1624, 0x2071, 0xae13,
6871 0x7007, 0x0009, 0x0804, 0x5352, 0x7084, 0x8008, 0xa092, 0x001e,
6872 0x1a04, 0x5352, 0xae90, 0x0003, 0xa210, 0x683c, 0x2012, 0x7186,
6873 0x2071, 0xae13, 0x080c, 0x54a7, 0x0804, 0x5352, 0x7084, 0x8008,
6874 0xa092, 0x000f, 0x1a04, 0x5352, 0xae90, 0x0003, 0x8003, 0xa210,
6875 0x683c, 0x2012, 0x8210, 0x6840, 0x2012, 0x7186, 0x2071, 0xae13,
6876 0x080c, 0x54a7, 0x0804, 0x5352, 0x0126, 0x2091, 0x8000, 0x0e04,
6877 0x530e, 0x2071, 0x0000, 0x7018, 0xd084, 0x1180, 0x7122, 0x683c,
6878 0x7026, 0x6840, 0x702a, 0x701b, 0x0001, 0x2091, 0x4080, 0x012e,
6879 0x2071, 0xae13, 0x080c, 0x54a7, 0x0804, 0x5352, 0x012e, 0x0804,
6880 0x5352, 0xa18c, 0x00ff, 0xa186, 0x0017, 0x0130, 0xa186, 0x001e,
6881 0x0118, 0xa18e, 0x001f, 0x11c0, 0x684c, 0xd0cc, 0x01a8, 0x6850,
6882 0xa084, 0x00ff, 0xa086, 0x0001, 0x1178, 0x2009, 0x8021, 0x0804,
6883 0x52a2, 0x6844, 0xa086, 0x0100, 0x1138, 0x6868, 0xa005, 0x1120,
6884 0x2009, 0x8020, 0x0804, 0x52a2, 0x2071, 0xae13, 0x080c, 0x54b9,
6885 0x01c8, 0x2071, 0xae13, 0x700f, 0x0001, 0x6934, 0xa184, 0x00ff,
6886 0xa086, 0x0003, 0x1130, 0x810f, 0xa18c, 0x00ff, 0x8101, 0x0108,
6887 0x710e, 0x7007, 0x0003, 0x080c, 0x54d2, 0x7050, 0xa086, 0x0100,
6888 0x0904, 0x5412, 0x0126, 0x2091, 0x8000, 0x2071, 0xae13, 0x7008,
6889 0xa086, 0x0001, 0x1180, 0x0e04, 0x536b, 0x2009, 0x000d, 0x7030,
6890 0x200a, 0x2091, 0x4080, 0x700b, 0x0000, 0x7004, 0xa086, 0x0006,
6891 0x1110, 0x7007, 0x0001, 0x012e, 0x0005, 0x2071, 0xae13, 0x080c,
6892 0x54b9, 0x0518, 0x2071, 0xaf34, 0x7084, 0x700a, 0x20a9, 0x0020,
6893 0x2099, 0xaf35, 0x20a1, 0xaf5c, 0x53a3, 0x7087, 0x0000, 0x2071,
6894 0xae13, 0x2069, 0xaf7c, 0x706c, 0x6826, 0x7070, 0x682a, 0x7074,
6895 0x682e, 0x7078, 0x6832, 0x2d10, 0x080c, 0x1624, 0x7007, 0x0008,
6896 0x2001, 0xffff, 0x2071, 0xafda, 0x703a, 0x012e, 0x0804, 0x5352,
6897 0x2069, 0xaf7c, 0x6808, 0xa08e, 0x0000, 0x0904, 0x53ed, 0xa08e,
6898 0x0200, 0x0904, 0x53eb, 0xa08e, 0x0100, 0x1904, 0x53ed, 0x0126,
6899 0x2091, 0x8000, 0x0e04, 0x53e9, 0x2069, 0x0000, 0x6818, 0xd084,
6900 0x15c0, 0x702c, 0x7130, 0x8108, 0xa102, 0x0230, 0xa00e, 0x7034,
6901 0x706e, 0x7038, 0x7072, 0x0048, 0x706c, 0xa080, 0x0040, 0x706e,
6902 0x1220, 0x7070, 0xa081, 0x0000, 0x7072, 0x7132, 0x6936, 0x700b,
6903 0x0000, 0x2001, 0xaf59, 0x2004, 0xa005, 0x1190, 0x6934, 0x2069,
6904 0xaf34, 0x689c, 0x699e, 0x2069, 0xafda, 0xa102, 0x1118, 0x683c,
6905 0xa005, 0x1368, 0x2001, 0xaf5a, 0x200c, 0x810d, 0x693e, 0x0038,
6906 0x2009, 0x8040, 0x6922, 0x681b, 0x0001, 0x2091, 0x4080, 0x7007,
6907 0x0001, 0x012e, 0x0010, 0x7007, 0x0005, 0x0005, 0x2001, 0xaf7e,
6908 0x2004, 0xa08e, 0x0100, 0x1128, 0x7007, 0x0001, 0x080c, 0x54a7,
6909 0x0005, 0xa08e, 0x0000, 0x0de0, 0xa08e, 0x0200, 0x1dc8, 0x7007,
6910 0x0005, 0x0005, 0x701c, 0xa06d, 0x0158, 0x080c, 0x54b9, 0x0140,
6911 0x7007, 0x0003, 0x080c, 0x54d2, 0x7050, 0xa086, 0x0100, 0x0110,
6912 0x0005, 0x0005, 0x7050, 0xa09e, 0x0100, 0x1118, 0x7007, 0x0004,
6913 0x0030, 0xa086, 0x0200, 0x1110, 0x7007, 0x0005, 0x0005, 0x080c,
6914 0x5475, 0x7006, 0x080c, 0x54a7, 0x0005, 0x0005, 0x00e6, 0x0156,
6915 0x2071, 0xaf34, 0x7184, 0x81ff, 0x0500, 0xa006, 0x7086, 0xae80,
6916 0x0003, 0x2071, 0x0000, 0x21a8, 0x2014, 0x7226, 0x8000, 0x0f04,
6917 0x544a, 0x2014, 0x722a, 0x8000, 0x0f04, 0x544a, 0x2014, 0x722e,
6918 0x8000, 0x0f04, 0x544a, 0x2014, 0x723a, 0x8000, 0x0f04, 0x544a,
6919 0x2014, 0x723e, 0xa180, 0x8030, 0x7022, 0x015e, 0x00ee, 0x0005,
6920 0x00e6, 0x0156, 0x2071, 0xaf34, 0x7184, 0x81ff, 0x01d8, 0xa006,
6921 0x7086, 0xae80, 0x0003, 0x2071, 0x0000, 0x21a8, 0x2014, 0x7226,
6922 0x8000, 0x2014, 0x722a, 0x8000, 0x0f04, 0x546c, 0x2014, 0x723a,
6923 0x8000, 0x2014, 0x723e, 0x0018, 0x2001, 0x8020, 0x0010, 0x2001,
6924 0x8042, 0x7022, 0x015e, 0x00ee, 0x0005, 0x702c, 0x7130, 0x8108,
6925 0xa102, 0x0230, 0xa00e, 0x7034, 0x706e, 0x7038, 0x7072, 0x0048,
6926 0x706c, 0xa080, 0x0040, 0x706e, 0x1220, 0x7070, 0xa081, 0x0000,
6927 0x7072, 0x7132, 0x700c, 0x8001, 0x700e, 0x1180, 0x0126, 0x2091,
6928 0x8000, 0x0e04, 0x54a1, 0x2001, 0x000d, 0x2102, 0x2091, 0x4080,
6929 0x2001, 0x0001, 0x700b, 0x0000, 0x012e, 0x0005, 0x2001, 0x0007,
6930 0x0005, 0x2001, 0x0006, 0x700b, 0x0001, 0x012e, 0x0005, 0x701c,
6931 0xa06d, 0x0170, 0x0126, 0x2091, 0x8000, 0x7010, 0x8001, 0x7012,
6932 0x2d04, 0x701e, 0xa005, 0x1108, 0x701a, 0x012e, 0x080c, 0x15f0,
6933 0x0005, 0x2019, 0x000d, 0x2304, 0x230c, 0xa10e, 0x0130, 0x2304,
6934 0x230c, 0xa10e, 0x0110, 0xa006, 0x0060, 0x732c, 0x8319, 0x7130,
6935 0xa102, 0x1118, 0x2300, 0xa005, 0x0020, 0x0210, 0xa302, 0x0008,
6936 0x8002, 0x0005, 0x2d00, 0x7026, 0xa080, 0x000d, 0x7056, 0x7053,
6937 0x0000, 0x0126, 0x2091, 0x8000, 0x2009, 0xafec, 0x2104, 0xc08d,
6938 0x200a, 0x012e, 0x080c, 0x163c, 0x0005, 0x7088, 0xa08a, 0x0029,
6939 0x1220, 0xa082, 0x001d, 0x0033, 0x0010, 0x080c, 0x14f6, 0x6027,
6940 0x1e00, 0x0005, 0x55c1, 0x555b, 0x5571, 0x5595, 0x55b4, 0x55e6,
6941 0x55f8, 0x5571, 0x55d2, 0x54ff, 0x552d, 0x54fe, 0x0005, 0x00d6,
6942 0x2069, 0x0200, 0x6804, 0xa005, 0x1180, 0x6808, 0xa005, 0x1518,
6943 0x708b, 0x0028, 0x2069, 0xafac, 0x2d04, 0x7002, 0x080c, 0x584d,
6944 0x6028, 0xa085, 0x0600, 0x602a, 0x00b0, 0x708b, 0x0028, 0x2069,
6945 0xafac, 0x2d04, 0x7002, 0x6028, 0xa085, 0x0600, 0x602a, 0x00e6,
6946 0x0036, 0x0046, 0x0056, 0x2071, 0xaffd, 0x080c, 0x1d22, 0x005e,
6947 0x004e, 0x003e, 0x00ee, 0x00de, 0x0005, 0x00d6, 0x2069, 0x0200,
6948 0x6804, 0xa005, 0x1180, 0x6808, 0xa005, 0x1518, 0x708b, 0x0028,
6949 0x2069, 0xafac, 0x2d04, 0x7002, 0x080c, 0x58da, 0x6028, 0xa085,
6950 0x0600, 0x602a, 0x00b0, 0x708b, 0x0028, 0x2069, 0xafac, 0x2d04,
6951 0x7002, 0x6028, 0xa085, 0x0600, 0x602a, 0x00e6, 0x0036, 0x0046,
6952 0x0056, 0x2071, 0xaffd, 0x080c, 0x1d22, 0x005e, 0x004e, 0x003e,
6953 0x00ee, 0x00de, 0x0005, 0x6803, 0x0090, 0x6124, 0xd1e4, 0x1180,
6954 0x080c, 0x5663, 0xd1d4, 0x1150, 0xd1dc, 0x1128, 0xd1cc, 0x0140,
6955 0x708b, 0x0020, 0x0028, 0x708b, 0x001d, 0x0010, 0x708b, 0x001f,
6956 0x0005, 0x6803, 0x0088, 0x6124, 0xd1cc, 0x11c8, 0xd1dc, 0x11a0,
6957 0xd1e4, 0x1178, 0xa184, 0x1e00, 0x11b8, 0x60e3, 0x0001, 0x600c,
6958 0xc0b4, 0x600e, 0x080c, 0x577f, 0x6803, 0x0080, 0x708b, 0x0028,
6959 0x0058, 0x708b, 0x001e, 0x0040, 0x708b, 0x001d, 0x0028, 0x708b,
6960 0x0020, 0x0010, 0x708b, 0x001f, 0x0005, 0x60e3, 0x0001, 0x600c,
6961 0xc0b4, 0x600e, 0x080c, 0x577f, 0x6803, 0x0080, 0x6124, 0xd1d4,
6962 0x1180, 0xd1dc, 0x1158, 0xd1e4, 0x1130, 0xa184, 0x1e00, 0x1158,
6963 0x708b, 0x0028, 0x0040, 0x708b, 0x001e, 0x0028, 0x708b, 0x001d,
6964 0x0010, 0x708b, 0x001f, 0x0005, 0x6803, 0x00a0, 0x6124, 0xd1dc,
6965 0x1128, 0xd1e4, 0x0128, 0x708b, 0x001e, 0x0010, 0x708b, 0x001d,
6966 0x0005, 0x080c, 0x568d, 0x6124, 0xd1dc, 0x1158, 0x080c, 0x5663,
6967 0xd1d4, 0x1128, 0xd1e4, 0x0128, 0x708b, 0x001e, 0x0010, 0x708b,
6968 0x001f, 0x0005, 0x6803, 0x00a0, 0x6124, 0xd1d4, 0x1160, 0xd1cc,
6969 0x1150, 0xd1dc, 0x1128, 0xd1e4, 0x0140, 0x708b, 0x001e, 0x0028,
6970 0x708b, 0x001d, 0x0010, 0x708b, 0x0021, 0x0005, 0x080c, 0x568d,
6971 0x6124, 0xd1d4, 0x1150, 0xd1dc, 0x1128, 0xd1e4, 0x0140, 0x708b,
6972 0x001e, 0x0028, 0x708b, 0x001d, 0x0010, 0x708b, 0x001f, 0x0005,
6973 0x6803, 0x0090, 0x6124, 0xd1d4, 0x1178, 0xd1cc, 0x1150, 0xd1dc,
6974 0x1128, 0xd1e4, 0x0158, 0x708b, 0x001e, 0x0040, 0x708b, 0x001d,
6975 0x0028, 0x708b, 0x0020, 0x0010, 0x708b, 0x001f, 0x0005, 0x0016,
6976 0x00c6, 0x00d6, 0x00e6, 0x0126, 0x2061, 0x0100, 0x2069, 0x0140,
6977 0x2071, 0xad00, 0x2091, 0x8000, 0x080c, 0x574f, 0x11e8, 0x2001,
6978 0xad0c, 0x200c, 0xd1b4, 0x01c0, 0xc1b4, 0x2102, 0x6027, 0x0200,
6979 0xe000, 0xe000, 0x6024, 0xd0cc, 0x0158, 0x6803, 0x00a0, 0x2001,
6980 0xaf9e, 0x2003, 0x0001, 0x2001, 0xad00, 0x2003, 0x0001, 0x0428,
6981 0x6028, 0xc0cd, 0x602a, 0x0408, 0x080c, 0x576b, 0x0150, 0x080c,
6982 0x5761, 0x1138, 0x2001, 0x0001, 0x080c, 0x261e, 0x080c, 0x5726,
6983 0x00a0, 0x080c, 0x568a, 0x0178, 0x2001, 0x0001, 0x080c, 0x261e,
6984 0x7088, 0xa086, 0x001e, 0x0120, 0x7088, 0xa086, 0x0022, 0x1118,
6985 0x708b, 0x0025, 0x0010, 0x708b, 0x0021, 0x012e, 0x00ee, 0x00de,
6986 0x00ce, 0x001e, 0x0005, 0x0016, 0x0026, 0x2009, 0x0064, 0x2011,
6987 0x566e, 0x080c, 0x6501, 0x002e, 0x001e, 0x0005, 0x00e6, 0x00f6,
6988 0x0016, 0x080c, 0x7834, 0x2071, 0xad00, 0x080c, 0x560f, 0x001e,
6989 0x00fe, 0x00ee, 0x0005, 0x2001, 0xad00, 0x2004, 0xa086, 0x0004,
6990 0x0140, 0x2001, 0xaf9d, 0x2003, 0xaaaa, 0x2001, 0xaf9e, 0x2003,
6991 0x0000, 0x0005, 0x6020, 0xd09c, 0x0005, 0x6803, 0x00c0, 0x0156,
6992 0x20a9, 0x002d, 0x1d04, 0x5692, 0x2091, 0x6000, 0x1f04, 0x5692,
6993 0x015e, 0x0005, 0x00c6, 0x00d6, 0x00e6, 0x2061, 0x0100, 0x2069,
6994 0x0140, 0x2071, 0xad00, 0x2001, 0xaf9e, 0x200c, 0xa186, 0x0000,
6995 0x0158, 0xa186, 0x0001, 0x0158, 0xa186, 0x0002, 0x0158, 0xa186,
6996 0x0003, 0x0158, 0x0804, 0x5714, 0x708b, 0x0022, 0x0040, 0x708b,
6997 0x0021, 0x0028, 0x708b, 0x0023, 0x0020, 0x708b, 0x0024, 0x6043,
6998 0x0000, 0x60e3, 0x0000, 0x6887, 0x0001, 0x2001, 0x0001, 0x080c,
6999 0x26cb, 0x0026, 0x2011, 0x0003, 0x080c, 0x7adf, 0x2011, 0x0002,
7000 0x080c, 0x7ae9, 0x002e, 0x7000, 0xa08e, 0x0004, 0x0118, 0x602b,
7001 0x0028, 0x0010, 0x602b, 0x0020, 0x0156, 0x0126, 0x2091, 0x8000,
7002 0x20a9, 0x0005, 0x6024, 0xd0ac, 0x0118, 0x012e, 0x015e, 0x04d0,
7003 0x6800, 0xa084, 0x00a0, 0xc0bd, 0x6802, 0x6904, 0xd1d4, 0x1130,
7004 0x6803, 0x0100, 0x1f04, 0x56e2, 0x080c, 0x57a0, 0x012e, 0x015e,
7005 0x080c, 0x5761, 0x01a8, 0x6044, 0xa005, 0x0168, 0x6050, 0x0006,
7006 0xa085, 0x0020, 0x6052, 0x080c, 0x57a0, 0xa006, 0x8001, 0x1df0,
7007 0x000e, 0x6052, 0x0028, 0x6804, 0xd0d4, 0x1110, 0x080c, 0x57a0,
7008 0x2001, 0xaf9e, 0x2003, 0x0004, 0x080c, 0x54e5, 0x080c, 0x5761,
7009 0x0148, 0x6804, 0xd0d4, 0x1130, 0xd0dc, 0x1100, 0x2001, 0xaf9e,
7010 0x2003, 0x0000, 0x00ee, 0x00de, 0x00ce, 0x0005, 0x00c6, 0x00d6,
7011 0x00e6, 0x2061, 0x0100, 0x2069, 0x0140, 0x2071, 0xad00, 0x2001,
7012 0xaf9d, 0x2003, 0x0000, 0x2001, 0xaf8e, 0x2003, 0x0000, 0x708b,
7013 0x0000, 0x60e3, 0x0000, 0x6887, 0x0000, 0x2001, 0x0000, 0x080c,
7014 0x26cb, 0x6803, 0x0000, 0x6043, 0x0090, 0x6043, 0x0010, 0x6027,
7015 0xffff, 0x602b, 0x182f, 0x00ee, 0x00de, 0x00ce, 0x0005, 0x0006,
7016 0x2001, 0xaf9d, 0x2004, 0xa086, 0xaaaa, 0x000e, 0x0005, 0x0006,
7017 0x2001, 0xad71, 0x2004, 0xa084, 0x0030, 0xa086, 0x0000, 0x000e,
7018 0x0005, 0x0006, 0x2001, 0xad71, 0x2004, 0xa084, 0x0030, 0xa086,
7019 0x0030, 0x000e, 0x0005, 0x0006, 0x2001, 0xad71, 0x2004, 0xa084,
7020 0x0030, 0xa086, 0x0010, 0x000e, 0x0005, 0x0006, 0x2001, 0xad71,
7021 0x2004, 0xa084, 0x0030, 0xa086, 0x0020, 0x000e, 0x0005, 0x2001,
7022 0xad0c, 0x2004, 0xd0a4, 0x0170, 0x080c, 0x26eb, 0x0036, 0x0016,
7023 0x2009, 0x0000, 0x2019, 0x0028, 0x080c, 0x2aac, 0x001e, 0x003e,
7024 0xa006, 0x0009, 0x0005, 0x00e6, 0x2071, 0xad0c, 0x2e04, 0x0118,
7025 0xa085, 0x0010, 0x0010, 0xa084, 0xffef, 0x2072, 0x00ee, 0x0005,
7026 0x6050, 0x0006, 0x60f0, 0x0006, 0x60ec, 0x0006, 0x600c, 0x0006,
7027 0x6004, 0x0006, 0x6028, 0x0006, 0x602f, 0x0100, 0x602f, 0x0000,
7028 0x602f, 0x0040, 0x602f, 0x0000, 0x000e, 0x602a, 0x000e, 0x6006,
7029 0x000e, 0x600e, 0x000e, 0x60ee, 0x000e, 0x60f2, 0x60e3, 0x0000,
7030 0x6887, 0x0001, 0x2001, 0x0001, 0x080c, 0x26cb, 0x6800, 0xa084,
7031 0x00a0, 0xc0bd, 0x6802, 0x6803, 0x00a0, 0x000e, 0x6052, 0x6050,
7032 0x0005, 0x0156, 0x0016, 0x0026, 0x0036, 0x00c6, 0x00d6, 0x00e6,
7033 0x2061, 0x0100, 0x2069, 0x0140, 0x2071, 0xad00, 0x6020, 0xa084,
7034 0x0080, 0x0138, 0x2001, 0xad0c, 0x200c, 0xc1bd, 0x2102, 0x0804,
7035 0x5845, 0x2001, 0xad0c, 0x200c, 0xc1bc, 0x2102, 0x6028, 0xa084,
7036 0xe1ff, 0x602a, 0x6027, 0x0200, 0x6803, 0x0090, 0x20a9, 0x0384,
7037 0x6024, 0xd0cc, 0x1518, 0x1d04, 0x57f8, 0x2091, 0x6000, 0x1f04,
7038 0x57f8, 0x2011, 0x0003, 0x080c, 0x7adf, 0x2011, 0x0002, 0x080c,
7039 0x7ae9, 0x080c, 0x79e1, 0x080c, 0x6581, 0x2019, 0x0000, 0x080c,
7040 0x7a64, 0x6803, 0x00a0, 0x2001, 0xaf9e, 0x2003, 0x0001, 0x2001,
7041 0xad00, 0x2003, 0x0001, 0xa085, 0x0001, 0x0438, 0x60e3, 0x0000,
7042 0x2001, 0xaf8e, 0x2004, 0x080c, 0x26cb, 0x60e2, 0x6803, 0x0080,
7043 0x20a9, 0x0384, 0x6027, 0x1e00, 0x2009, 0x1e00, 0xe000, 0x6024,
7044 0xa10c, 0x0138, 0x1d04, 0x582a, 0x2091, 0x6000, 0x1f04, 0x582a,
7045 0x0840, 0x6028, 0xa085, 0x1e00, 0x602a, 0x70a0, 0xa005, 0x1118,
7046 0x6887, 0x0001, 0x0008, 0x6886, 0xa006, 0x00ee, 0x00de, 0x00ce,
7047 0x003e, 0x002e, 0x001e, 0x015e, 0x0005, 0x0156, 0x0016, 0x0026,
7048 0x0036, 0x00c6, 0x00d6, 0x00e6, 0x2061, 0x0100, 0x2071, 0xad00,
7049 0x2069, 0x0140, 0x6020, 0xa084, 0x00c0, 0x0120, 0x6884, 0xa005,
7050 0x1904, 0x58a1, 0x6803, 0x0088, 0x60e3, 0x0000, 0x6887, 0x0000,
7051 0x2001, 0x0000, 0x080c, 0x26cb, 0x2069, 0x0200, 0x6804, 0xa005,
7052 0x1118, 0x6808, 0xa005, 0x01c0, 0x6028, 0xa084, 0xfbff, 0x602a,
7053 0x6027, 0x0400, 0x2069, 0xafac, 0x7000, 0x206a, 0x708b, 0x0026,
7054 0x7003, 0x0001, 0x20a9, 0x0002, 0x1d04, 0x5884, 0x2091, 0x6000,
7055 0x1f04, 0x5884, 0x0804, 0x58d2, 0x2069, 0x0140, 0x20a9, 0x0384,
7056 0x6027, 0x1e00, 0x2009, 0x1e00, 0xe000, 0x6024, 0xa10c, 0x0530,
7057 0xa084, 0x1a00, 0x1518, 0x1d04, 0x5890, 0x2091, 0x6000, 0x1f04,
7058 0x5890, 0x2011, 0x0003, 0x080c, 0x7adf, 0x2011, 0x0002, 0x080c,
7059 0x7ae9, 0x080c, 0x79e1, 0x080c, 0x6581, 0x2019, 0x0000, 0x080c,
7060 0x7a64, 0x6803, 0x00a0, 0x2001, 0xaf9e, 0x2003, 0x0001, 0x2001,
7061 0xad00, 0x2003, 0x0001, 0xa085, 0x0001, 0x00a0, 0x6803, 0x0080,
7062 0x2069, 0x0140, 0x60e3, 0x0000, 0x70a0, 0xa005, 0x1118, 0x6887,
7063 0x0001, 0x0008, 0x6886, 0x2001, 0xaf8e, 0x2004, 0x080c, 0x26cb,
7064 0x60e2, 0xa006, 0x00ee, 0x00de, 0x00ce, 0x003e, 0x002e, 0x001e,
7065 0x015e, 0x0005, 0x0156, 0x0016, 0x0026, 0x0036, 0x00c6, 0x00d6,
7066 0x00e6, 0x2061, 0x0100, 0x2071, 0xad00, 0x6020, 0xa084, 0x00c0,
7067 0x01f0, 0x2011, 0x0003, 0x080c, 0x7adf, 0x2011, 0x0002, 0x080c,
7068 0x7ae9, 0x080c, 0x79e1, 0x080c, 0x6581, 0x2019, 0x0000, 0x080c,
7069 0x7a64, 0x2069, 0x0140, 0x6803, 0x00a0, 0x2001, 0xaf9e, 0x2003,
7070 0x0001, 0x2001, 0xad00, 0x2003, 0x0001, 0x0804, 0x5972, 0x2001,
7071 0xad0c, 0x200c, 0xd1b4, 0x1150, 0xc1b5, 0x2102, 0x080c, 0x5663,
7072 0x2069, 0x0140, 0x6803, 0x0080, 0x60e3, 0x0000, 0x2069, 0x0200,
7073 0x6804, 0xa005, 0x1118, 0x6808, 0xa005, 0x01b8, 0x6028, 0xa084,
7074 0xfdff, 0x602a, 0x6027, 0x0200, 0x2069, 0xafac, 0x7000, 0x206a,
7075 0x708b, 0x0027, 0x7003, 0x0001, 0x20a9, 0x0002, 0x1d04, 0x592e,
7076 0x2091, 0x6000, 0x1f04, 0x592e, 0x04e8, 0x6027, 0x1e00, 0x2009,
7077 0x1e00, 0xe000, 0x6024, 0xa10c, 0x01c8, 0xa084, 0x1c00, 0x11b0,
7078 0x1d04, 0x5935, 0x0006, 0x0016, 0x00c6, 0x00d6, 0x00e6, 0x080c,
7079 0x64a2, 0x00ee, 0x00de, 0x00ce, 0x001e, 0x000e, 0x00e6, 0x2071,
7080 0xafda, 0x7018, 0x00ee, 0xa005, 0x1d00, 0x01e0, 0x0026, 0x2011,
7081 0x566e, 0x080c, 0x650d, 0x002e, 0x2069, 0x0140, 0x60e3, 0x0000,
7082 0x70a0, 0xa005, 0x1118, 0x6887, 0x0001, 0x0008, 0x6886, 0x2001,
7083 0xaf8e, 0x2004, 0x080c, 0x26cb, 0x60e2, 0x2001, 0xad0c, 0x200c,
7084 0xc1b4, 0x2102, 0x00ee, 0x00de, 0x00ce, 0x003e, 0x002e, 0x001e,
7085 0x015e, 0x0005, 0x0156, 0x0016, 0x0026, 0x0036, 0x0046, 0x00c6,
7086 0x00e6, 0x2061, 0x0100, 0x2071, 0xad00, 0x7130, 0xd184, 0x1180,
7087 0x2011, 0xad52, 0x2214, 0xd2ec, 0x0138, 0xc18d, 0x7132, 0x2011,
7088 0xad52, 0x2214, 0xd2ac, 0x1120, 0x7030, 0xd08c, 0x0904, 0x59df,
7089 0x7130, 0xc185, 0x7132, 0x2011, 0xad52, 0x220c, 0xd1a4, 0x0530,
7090 0x0016, 0x2009, 0x0001, 0x2011, 0x0100, 0x080c, 0x663f, 0x2019,
7091 0x000e, 0x080c, 0xa8eb, 0x0156, 0x20a9, 0x007f, 0x2009, 0x0000,
7092 0xa186, 0x007e, 0x0170, 0xa186, 0x0080, 0x0158, 0x080c, 0x4cdc,
7093 0x1140, 0x8127, 0xa006, 0x0016, 0x2009, 0x000e, 0x080c, 0xa96c,
7094 0x001e, 0x8108, 0x1f04, 0x59b0, 0x015e, 0x001e, 0xd1ac, 0x1148,
7095 0x0016, 0x2009, 0x0000, 0x2019, 0x0004, 0x080c, 0x2aac, 0x001e,
7096 0x0070, 0x0156, 0x20a9, 0x007f, 0x2009, 0x0000, 0x080c, 0x4cdc,
7097 0x1110, 0x080c, 0x493a, 0x8108, 0x1f04, 0x59d6, 0x015e, 0x2011,
7098 0x0003, 0x080c, 0x7adf, 0x2011, 0x0002, 0x080c, 0x7ae9, 0x080c,
7099 0x79e1, 0x080c, 0x6581, 0x0036, 0x2019, 0x0000, 0x080c, 0x7a64,
7100 0x003e, 0x60e3, 0x0000, 0x2001, 0xad00, 0x2003, 0x0001, 0x080c,
7101 0x569a, 0x00ee, 0x00ce, 0x004e, 0x003e, 0x002e, 0x001e, 0x015e,
7102 0x0005, 0x2071, 0xade1, 0x7003, 0x0000, 0x7007, 0x0000, 0x700f,
7103 0x0000, 0x702b, 0x0001, 0x704f, 0x0000, 0x7053, 0x0001, 0x705f,
7104 0x0020, 0x7063, 0x0040, 0x7083, 0x0000, 0x708b, 0x0000, 0x708f,
7105 0x0001, 0x70bf, 0x0000, 0x0005, 0x00e6, 0x2071, 0xade1, 0x6848,
7106 0xa005, 0x1130, 0x7028, 0xc085, 0x702a, 0xa085, 0x0001, 0x0428,
7107 0x6a50, 0x7236, 0x6b54, 0x733a, 0x6858, 0x703e, 0x707a, 0x685c,
7108 0x7042, 0x707e, 0x6848, 0x702e, 0x6840, 0x7032, 0x2009, 0x000c,
7109 0x200a, 0x8007, 0x8006, 0x8006, 0xa08c, 0x003f, 0xa084, 0xffc0,
7110 0xa210, 0x2100, 0xa319, 0x7272, 0x7376, 0x7028, 0xc084, 0x702a,
7111 0x7007, 0x0001, 0x700f, 0x0000, 0xa006, 0x00ee, 0x0005, 0x2b78,
7112 0x2071, 0xade1, 0x7004, 0x0043, 0x700c, 0x0002, 0x5a5b, 0x5a52,
7113 0x5a52, 0x5a52, 0x5a52, 0x0005, 0x5ab1, 0x5ab2, 0x5ae4, 0x5ae5,
7114 0x5aaf, 0x5b33, 0x5b38, 0x5b69, 0x5b6a, 0x5b85, 0x5b86, 0x5b87,
7115 0x5b88, 0x5b89, 0x5b8a, 0x5c40, 0x5c67, 0x700c, 0x0002, 0x5a74,
7116 0x5aaf, 0x5aaf, 0x5ab0, 0x5ab0, 0x7830, 0x7930, 0xa106, 0x0120,
7117 0x7830, 0x7930, 0xa106, 0x1510, 0x7030, 0xa10a, 0x01f8, 0x1210,
7118 0x712c, 0xa10a, 0xa18a, 0x0002, 0x12d0, 0x080c, 0x15c0, 0x01b0,
7119 0x2d00, 0x705a, 0x7063, 0x0040, 0x2001, 0x0003, 0x7057, 0x0000,
7120 0x0126, 0x0006, 0x2091, 0x8000, 0x2009, 0xafec, 0x2104, 0xc085,
7121 0x200a, 0x000e, 0x700e, 0x012e, 0x080c, 0x163c, 0x0005, 0x080c,
7122 0x15c0, 0x0de0, 0x2d00, 0x705a, 0x080c, 0x15c0, 0x1108, 0x0c10,
7123 0x2d00, 0x7086, 0x7063, 0x0080, 0x2001, 0x0004, 0x08f8, 0x0005,
7124 0x0005, 0x0005, 0x700c, 0x0002, 0x5ab9, 0x5abc, 0x5aca, 0x5ae3,
7125 0x5ae3, 0x080c, 0x5a6d, 0x0005, 0x0126, 0x8001, 0x700e, 0x7058,
7126 0x0006, 0x080c, 0x5f90, 0x0120, 0x2091, 0x8000, 0x080c, 0x5a6d,
7127 0x00de, 0x0048, 0x0126, 0x8001, 0x700e, 0x080c, 0x5f90, 0x7058,
7128 0x2068, 0x7084, 0x705a, 0x6803, 0x0000, 0x6807, 0x0000, 0x6834,
7129 0xa084, 0x00ff, 0xa08a, 0x003a, 0x1218, 0x00db, 0x012e, 0x0005,
7130 0x012e, 0x080c, 0x5b8b, 0x0005, 0x0005, 0x0005, 0x00e6, 0x2071,
7131 0xade1, 0x700c, 0x0002, 0x5af0, 0x5af0, 0x5af0, 0x5af2, 0x5af5,
7132 0x00ee, 0x0005, 0x700f, 0x0001, 0x0010, 0x700f, 0x0002, 0x00ee,
7133 0x0005, 0x5b8b, 0x5b8b, 0x5ba7, 0x5b8b, 0x5d22, 0x5b8b, 0x5b8b,
7134 0x5b8b, 0x5b8b, 0x5b8b, 0x5ba7, 0x5d64, 0x5da7, 0x5df0, 0x5e04,
7135 0x5b8b, 0x5b8b, 0x5bc3, 0x5ba7, 0x5b8b, 0x5b8b, 0x5c1d, 0x5ead,
7136 0x5ec8, 0x5b8b, 0x5bc3, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5c13,
7137 0x5ec8, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b,
7138 0x5b8b, 0x5b8b, 0x5bd7, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b,
7139 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b, 0x5b8b,
7140 0x5b8b, 0x5b8b, 0x5bec, 0x7020, 0x2068, 0x080c, 0x15f0, 0x0005,
7141 0x700c, 0x0002, 0x5b3f, 0x5b42, 0x5b50, 0x5b68, 0x5b68, 0x080c,
7142 0x5a6d, 0x0005, 0x0126, 0x8001, 0x700e, 0x7058, 0x0006, 0x080c,
7143 0x5f90, 0x0120, 0x2091, 0x8000, 0x080c, 0x5a6d, 0x00de, 0x0048,
7144 0x0126, 0x8001, 0x700e, 0x080c, 0x5f90, 0x7058, 0x2068, 0x7084,
7145 0x705a, 0x6803, 0x0000, 0x6807, 0x0000, 0x6834, 0xa084, 0x00ff,
7146 0xa08a, 0x001a, 0x1218, 0x003b, 0x012e, 0x0005, 0x012e, 0x0419,
7147 0x0005, 0x0005, 0x0005, 0x5b8b, 0x5ba7, 0x5d0e, 0x5b8b, 0x5ba7,
7148 0x5b8b, 0x5ba7, 0x5ba7, 0x5b8b, 0x5ba7, 0x5d0e, 0x5ba7, 0x5ba7,
7149 0x5ba7, 0x5ba7, 0x5ba7, 0x5b8b, 0x5ba7, 0x5d0e, 0x5b8b, 0x5b8b,
7150 0x5ba7, 0x5b8b, 0x5b8b, 0x5b8b, 0x5ba7, 0x0005, 0x0005, 0x0005,
7151 0x0005, 0x0005, 0x0005, 0x7007, 0x0001, 0x6838, 0xa084, 0x00ff,
7152 0xc0d5, 0x683a, 0x0126, 0x2091, 0x8000, 0x080c, 0x510c, 0x012e,
7153 0x0005, 0x7007, 0x0001, 0x6838, 0xa084, 0x00ff, 0xc0e5, 0x683a,
7154 0x0126, 0x2091, 0x8000, 0x080c, 0x510c, 0x012e, 0x0005, 0x7007,
7155 0x0001, 0x6838, 0xa084, 0x00ff, 0xc0ed, 0x683a, 0x0126, 0x2091,
7156 0x8000, 0x080c, 0x510c, 0x012e, 0x0005, 0x7007, 0x0001, 0x6838,
7157 0xa084, 0x00ff, 0xc0dd, 0x683a, 0x0126, 0x2091, 0x8000, 0x080c,
7158 0x510c, 0x012e, 0x0005, 0x6834, 0x8007, 0xa084, 0x00ff, 0x0988,
7159 0x8001, 0x1120, 0x7007, 0x0001, 0x0804, 0x5cd0, 0x7007, 0x0006,
7160 0x7012, 0x2d00, 0x7016, 0x701a, 0x704b, 0x5cd0, 0x0005, 0x6834,
7161 0x8007, 0xa084, 0x00ff, 0x0904, 0x5b99, 0x8001, 0x1120, 0x7007,
7162 0x0001, 0x0804, 0x5ced, 0x7007, 0x0006, 0x7012, 0x2d00, 0x7016,
7163 0x701a, 0x704b, 0x5ced, 0x0005, 0x6834, 0x8007, 0xa084, 0x00ff,
7164 0xa086, 0x0001, 0x1904, 0x5b99, 0x7007, 0x0001, 0x2009, 0xad30,
7165 0x210c, 0x81ff, 0x11a8, 0x6838, 0xa084, 0x00ff, 0x683a, 0x6853,
7166 0x0000, 0x080c, 0x4ab1, 0x1108, 0x0005, 0x0126, 0x2091, 0x8000,
7167 0x6837, 0x0139, 0x684a, 0x6952, 0x080c, 0x510c, 0x012e, 0x0ca0,
7168 0x2001, 0x0028, 0x0c90, 0x684c, 0xa084, 0x00c0, 0xa086, 0x00c0,
7169 0x1120, 0x7007, 0x0001, 0x0804, 0x5ee0, 0x2d00, 0x7016, 0x701a,
7170 0x20a9, 0x0004, 0xa080, 0x0024, 0x2098, 0x20a1, 0xae0c, 0x53a3,
7171 0x6858, 0x7012, 0xa082, 0x0401, 0x1a04, 0x5bb5, 0x6a84, 0xa28a,
7172 0x0002, 0x1a04, 0x5bb5, 0x82ff, 0x1138, 0x6888, 0x698c, 0xa105,
7173 0x0118, 0x2001, 0x5ca3, 0x0018, 0xa280, 0x5c99, 0x2005, 0x70c6,
7174 0x7010, 0xa015, 0x0904, 0x5c85, 0x080c, 0x15c0, 0x1118, 0x7007,
7175 0x000f, 0x0005, 0x2d00, 0x7022, 0x70c4, 0x2060, 0x2c05, 0x6836,
7176 0xe004, 0xad00, 0x7096, 0xe008, 0xa20a, 0x1210, 0xa00e, 0x2200,
7177 0x7112, 0xe20c, 0x8003, 0x800b, 0xa296, 0x0004, 0x0108, 0xa108,
7178 0x719a, 0x810b, 0x719e, 0xae90, 0x0022, 0x080c, 0x1624, 0x7090,
7179 0xa08e, 0x0100, 0x0170, 0xa086, 0x0200, 0x0118, 0x7007, 0x0010,
7180 0x0005, 0x7020, 0x2068, 0x080c, 0x15f0, 0x7014, 0x2068, 0x0804,
7181 0x5bb5, 0x7020, 0x2068, 0x7018, 0x6802, 0x6807, 0x0000, 0x2d08,
7182 0x2068, 0x6906, 0x711a, 0x0804, 0x5c40, 0x7014, 0x2068, 0x7007,
7183 0x0001, 0x6884, 0xa005, 0x1128, 0x6888, 0x698c, 0xa105, 0x0108,
7184 0x00b1, 0x6834, 0xa084, 0x00ff, 0xa086, 0x001e, 0x0904, 0x5ee0,
7185 0x04b8, 0x5c9b, 0x5c9f, 0x0002, 0x0011, 0x0007, 0x0004, 0x000a,
7186 0x000f, 0x0005, 0x0006, 0x000a, 0x0011, 0x0005, 0x0004, 0x00f6,
7187 0x00e6, 0x00c6, 0x0076, 0x0066, 0x6f88, 0x6e8c, 0x6804, 0x2060,
7188 0xacf0, 0x0021, 0xacf8, 0x0027, 0x2009, 0x0005, 0x700c, 0x7816,
7189 0x7008, 0x7812, 0x7004, 0x7806, 0x7000, 0x7802, 0x7e0e, 0x7f0a,
7190 0x8109, 0x0128, 0xaef2, 0x0004, 0xaffa, 0x0006, 0x0c78, 0x6004,
7191 0xa065, 0x1d30, 0x006e, 0x007e, 0x00ce, 0x00ee, 0x00fe, 0x0005,
7192 0x2009, 0xad30, 0x210c, 0x81ff, 0x1198, 0x6838, 0xa084, 0x00ff,
7193 0x683a, 0x080c, 0x4993, 0x1108, 0x0005, 0x080c, 0x51df, 0x0126,
7194 0x2091, 0x8000, 0x080c, 0x97fd, 0x080c, 0x510c, 0x012e, 0x0ca0,
7195 0x2001, 0x0028, 0x2009, 0x0000, 0x0c80, 0x2009, 0xad30, 0x210c,
7196 0x81ff, 0x11b0, 0x6858, 0xa005, 0x01b0, 0x6838, 0xa084, 0x00ff,
7197 0x683a, 0x6853, 0x0000, 0x080c, 0x4a55, 0x1108, 0x0005, 0x0126,
7198 0x2091, 0x8000, 0x080c, 0x51df, 0x080c, 0x510c, 0x012e, 0x0cb0,
7199 0x2001, 0x0028, 0x0ca0, 0x2001, 0x0000, 0x0c88, 0x7018, 0x6802,
7200 0x2d08, 0x2068, 0x6906, 0x711a, 0x7010, 0x8001, 0x7012, 0x0118,
7201 0x7007, 0x0006, 0x0030, 0x7014, 0x2068, 0x7007, 0x0001, 0x7048,
7202 0x080f, 0x0005, 0x7007, 0x0001, 0x6944, 0x810f, 0xa18c, 0x00ff,
7203 0x6848, 0xa084, 0x00ff, 0x20a9, 0x0001, 0xa096, 0x0001, 0x01b0,
7204 0x2009, 0x0000, 0x20a9, 0x00ff, 0xa096, 0x0002, 0x0178, 0xa005,
7205 0x11f0, 0x6944, 0x810f, 0xa18c, 0x00ff, 0x080c, 0x4cdc, 0x11b8,
7206 0x0066, 0x6e50, 0x080c, 0x4dcf, 0x006e, 0x0088, 0x0046, 0x2011,
7207 0xad0c, 0x2224, 0xc484, 0x2412, 0x004e, 0x00c6, 0x080c, 0x4cdc,
7208 0x1110, 0x080c, 0x4f2d, 0x8108, 0x1f04, 0x5d4e, 0x00ce, 0x684c,
7209 0xd084, 0x1118, 0x080c, 0x15f0, 0x0005, 0x0126, 0x2091, 0x8000,
7210 0x080c, 0x510c, 0x012e, 0x0005, 0x0126, 0x2091, 0x8000, 0x7007,
7211 0x0001, 0x2001, 0xad52, 0x2004, 0xd0a4, 0x0580, 0x2061, 0xb048,
7212 0x6100, 0xd184, 0x0178, 0x6858, 0xa084, 0x00ff, 0x1550, 0x6000,
7213 0xd084, 0x0520, 0x6004, 0xa005, 0x1538, 0x6003, 0x0000, 0x600b,
7214 0x0000, 0x00c8, 0x2011, 0x0001, 0x6860, 0xa005, 0x1110, 0x2001,
7215 0x001e, 0x8000, 0x6016, 0x6858, 0xa084, 0x00ff, 0x0178, 0x6006,
7216 0x6858, 0x8007, 0xa084, 0x00ff, 0x0148, 0x600a, 0x6858, 0x8000,
7217 0x1108, 0xc28d, 0x6202, 0x012e, 0x0804, 0x5f7f, 0x012e, 0x0804,
7218 0x5f79, 0x012e, 0x0804, 0x5f73, 0x012e, 0x0804, 0x5f76, 0x0126,
7219 0x2091, 0x8000, 0x7007, 0x0001, 0x2001, 0xad52, 0x2004, 0xd0a4,
7220 0x05e0, 0x2061, 0xb048, 0x6000, 0xd084, 0x05b8, 0x6204, 0x6308,
7221 0xd08c, 0x1530, 0x6c48, 0xa484, 0x0003, 0x0170, 0x6958, 0xa18c,
7222 0x00ff, 0x8001, 0x1120, 0x2100, 0xa210, 0x0620, 0x0028, 0x8001,
7223 0x1508, 0x2100, 0xa212, 0x02f0, 0xa484, 0x000c, 0x0188, 0x6958,
7224 0x810f, 0xa18c, 0x00ff, 0xa082, 0x0004, 0x1120, 0x2100, 0xa318,
7225 0x0288, 0x0030, 0xa082, 0x0004, 0x1168, 0x2100, 0xa31a, 0x0250,
7226 0x6860, 0xa005, 0x0110, 0x8000, 0x6016, 0x6206, 0x630a, 0x012e,
7227 0x0804, 0x5f7f, 0x012e, 0x0804, 0x5f7c, 0x012e, 0x0804, 0x5f79,
7228 0x0126, 0x2091, 0x8000, 0x7007, 0x0001, 0x2061, 0xb048, 0x6300,
7229 0xd38c, 0x1120, 0x6308, 0x8318, 0x0220, 0x630a, 0x012e, 0x0804,
7230 0x5f8d, 0x012e, 0x0804, 0x5f7c, 0x0126, 0x00c6, 0x2091, 0x8000,
7231 0x7007, 0x0001, 0x684c, 0xd0ac, 0x0148, 0x00c6, 0x2061, 0xb048,
7232 0x6000, 0xa084, 0xfcff, 0x6002, 0x00ce, 0x0448, 0x6858, 0xa005,
7233 0x05d0, 0x685c, 0xa065, 0x0598, 0x2001, 0xad30, 0x2004, 0xa005,
7234 0x0118, 0x080c, 0x974e, 0x0068, 0x6013, 0x0400, 0x6057, 0x0000,
7235 0x694c, 0xd1a4, 0x0110, 0x6950, 0x6156, 0x2009, 0x0041, 0x080c,
7236 0x80a7, 0x6958, 0xa18c, 0xff00, 0xa186, 0x2000, 0x1140, 0x0026,
7237 0x2009, 0x0000, 0x2011, 0xfdff, 0x080c, 0x663f, 0x002e, 0x684c,
7238 0xd0c4, 0x0148, 0x2061, 0xb048, 0x6000, 0xd08c, 0x1120, 0x6008,
7239 0x8000, 0x0208, 0x600a, 0x00ce, 0x012e, 0x0804, 0x5f7f, 0x00ce,
7240 0x012e, 0x0804, 0x5f79, 0x6954, 0xa186, 0x002e, 0x0d40, 0xa186,
7241 0x002d, 0x0d28, 0xa186, 0x0045, 0x0510, 0xa186, 0x002a, 0x1130,
7242 0x2001, 0xad0c, 0x200c, 0xc194, 0x2102, 0x08c8, 0xa186, 0x0020,
7243 0x0170, 0xa186, 0x0029, 0x1d18, 0x6944, 0xa18c, 0xff00, 0x810f,
7244 0x080c, 0x4cdc, 0x1960, 0x6000, 0xc0e4, 0x6002, 0x0840, 0x685c,
7245 0xa065, 0x09a8, 0x2001, 0xafa3, 0x2004, 0x6016, 0x0800, 0x685c,
7246 0xa065, 0x0968, 0x00e6, 0x6860, 0xa075, 0x2001, 0xad30, 0x2004,
7247 0xa005, 0x0150, 0x080c, 0x974e, 0x8eff, 0x0118, 0x2e60, 0x080c,
7248 0x974e, 0x00ee, 0x0804, 0x5e3f, 0x6020, 0xc0dc, 0xc0d5, 0x6022,
7249 0x2e60, 0x6007, 0x003a, 0x6870, 0xa005, 0x0130, 0x6007, 0x003b,
7250 0x6874, 0x602a, 0x6878, 0x6012, 0x6003, 0x0001, 0x080c, 0x67a8,
7251 0x080c, 0x6c50, 0x00ee, 0x0804, 0x5e3f, 0x2061, 0xb048, 0x6000,
7252 0xd084, 0x0190, 0xd08c, 0x1904, 0x5f8d, 0x0126, 0x2091, 0x8000,
7253 0x6204, 0x8210, 0x0220, 0x6206, 0x012e, 0x0804, 0x5f8d, 0x012e,
7254 0x6853, 0x0016, 0x0804, 0x5f86, 0x6853, 0x0007, 0x0804, 0x5f86,
7255 0x6834, 0x8007, 0xa084, 0x00ff, 0x1118, 0x080c, 0x5b99, 0x0078,
7256 0x2030, 0x8001, 0x1120, 0x7007, 0x0001, 0x0051, 0x0040, 0x7007,
7257 0x0006, 0x7012, 0x2d00, 0x7016, 0x701a, 0x704b, 0x5ee0, 0x0005,
7258 0x00e6, 0x0126, 0x2091, 0x8000, 0x2009, 0xad30, 0x210c, 0x81ff,
7259 0x1904, 0x5f5b, 0x2009, 0xad0c, 0x210c, 0xd194, 0x1904, 0x5f63,
7260 0x6848, 0x2070, 0xae82, 0xb400, 0x0a04, 0x5f4f, 0x2001, 0xad16,
7261 0x2004, 0xae02, 0x1a04, 0x5f4f, 0x2061, 0xb048, 0x6100, 0xa184,
7262 0x0301, 0xa086, 0x0001, 0x15a8, 0x711c, 0xa186, 0x0006, 0x15b0,
7263 0x7018, 0xa005, 0x0904, 0x5f5b, 0x2004, 0xd0e4, 0x1904, 0x5f5e,
7264 0x7020, 0xd0dc, 0x1904, 0x5f66, 0x6853, 0x0000, 0x6803, 0x0000,
7265 0x2d08, 0x7010, 0xa005, 0x1158, 0x7112, 0x684c, 0xd0f4, 0x1904,
7266 0x5f69, 0x2e60, 0x080c, 0x65aa, 0x012e, 0x00ee, 0x0005, 0x2068,
7267 0x6800, 0xa005, 0x1de0, 0x6902, 0x2168, 0x684c, 0xd0f4, 0x15c8,
7268 0x012e, 0x00ee, 0x0005, 0x012e, 0x00ee, 0x6853, 0x0006, 0x0804,
7269 0x5f86, 0xd184, 0x0dc0, 0xd1c4, 0x11a8, 0x00b8, 0x6944, 0xa18c,
7270 0xff00, 0x810f, 0x080c, 0x4cdc, 0x11c8, 0x6000, 0xd0e4, 0x11b0,
7271 0x711c, 0xa186, 0x0007, 0x1118, 0x6853, 0x0002, 0x0088, 0x6853,
7272 0x0008, 0x0070, 0x6853, 0x000e, 0x0058, 0x6853, 0x0017, 0x0040,
7273 0x6853, 0x0035, 0x0028, 0x6853, 0x0028, 0x0010, 0x6853, 0x0029,
7274 0x012e, 0x00ee, 0x0418, 0x6853, 0x002a, 0x0cd0, 0x6853, 0x0045,
7275 0x0cb8, 0x2e60, 0x2019, 0x0002, 0x6017, 0x0014, 0x080c, 0xa566,
7276 0x012e, 0x00ee, 0x0005, 0x2009, 0x003e, 0x0058, 0x2009, 0x0004,
7277 0x0040, 0x2009, 0x0006, 0x0028, 0x2009, 0x0016, 0x0010, 0x2009,
7278 0x0001, 0x6854, 0xa084, 0xff00, 0xa105, 0x6856, 0x0126, 0x2091,
7279 0x8000, 0x080c, 0x510c, 0x012e, 0x0005, 0x080c, 0x15f0, 0x0005,
7280 0x702c, 0x7130, 0x8108, 0xa102, 0x0230, 0xa00e, 0x7034, 0x7072,
7281 0x7038, 0x7076, 0x0058, 0x7070, 0xa080, 0x0040, 0x7072, 0x1230,
7282 0x7074, 0xa081, 0x0000, 0x7076, 0xa085, 0x0001, 0x7932, 0x7132,
7283 0x0005, 0x00d6, 0x080c, 0x65a1, 0x00de, 0x0005, 0x00d6, 0x2011,
7284 0x0004, 0x2204, 0xa085, 0x8002, 0x2012, 0x00de, 0x0005, 0x20e1,
7285 0x0002, 0x3d08, 0x20e1, 0x2000, 0x3d00, 0xa084, 0x7000, 0x0118,
7286 0xa086, 0x1000, 0x1540, 0x20e1, 0x0000, 0x3d00, 0xa094, 0xff00,
7287 0x8217, 0xa084, 0xf000, 0xa086, 0x3000, 0x1118, 0x080c, 0x61c6,
7288 0x00b0, 0x20e1, 0x0004, 0x3d60, 0xd1bc, 0x1108, 0x3e60, 0xac84,
7289 0x0007, 0x1188, 0xac82, 0xb400, 0x0270, 0x6858, 0xac02, 0x1258,
7290 0x6120, 0xd1f4, 0x1160, 0x2009, 0x0047, 0x080c, 0x80a7, 0x7a1c,
7291 0xd284, 0x1968, 0x0005, 0xa016, 0x080c, 0x1824, 0x0cc0, 0x0cd8,
7292 0x781c, 0xd08c, 0x0500, 0x0156, 0x0136, 0x0146, 0x20e1, 0x3000,
7293 0x3d20, 0x3e28, 0xa584, 0x0076, 0x1530, 0xa484, 0x7000, 0xa086,
7294 0x1000, 0x11a8, 0x080c, 0x604e, 0x01f0, 0x20e1, 0x3000, 0x7828,
7295 0x7828, 0x080c, 0x606a, 0x014e, 0x013e, 0x015e, 0x2009, 0xafcf,
7296 0x2104, 0xa005, 0x1108, 0x0005, 0x080c, 0x6c50, 0x0ce0, 0xa484,
7297 0x7000, 0x1518, 0x0499, 0x01b8, 0x7000, 0xa084, 0xff00, 0xa086,
7298 0x8100, 0x0d18, 0x0080, 0xd5a4, 0x0158, 0x080c, 0x1d86, 0x20e1,
7299 0x9010, 0x2001, 0x0160, 0x2502, 0x2001, 0x0138, 0x2202, 0x0048,
7300 0x00e9, 0x6883, 0x0000, 0x080c, 0xac59, 0x20e1, 0x3000, 0x7828,
7301 0x7828, 0x014e, 0x013e, 0x015e, 0x08b0, 0x0081, 0x1130, 0x7000,
7302 0xa084, 0xff00, 0xa086, 0x8100, 0x1d70, 0x080c, 0xac59, 0x20e1,
7303 0x3000, 0x7828, 0x7828, 0x080c, 0x642d, 0x0c58, 0xa484, 0x01ff,
7304 0x6882, 0xa005, 0x0160, 0xa080, 0x001f, 0xa084, 0x03f8, 0x80ac,
7305 0x20e1, 0x1000, 0x2ea0, 0x2099, 0x020a, 0x53a5, 0x0005, 0x20a9,
7306 0x000c, 0x20e1, 0x1000, 0x2ea0, 0x2099, 0x020a, 0x53a5, 0xa085,
7307 0x0001, 0x0ca0, 0x7000, 0xa084, 0xff00, 0xa08c, 0xf000, 0x8007,
7308 0xa196, 0x0000, 0x1118, 0x0804, 0x62cf, 0x0005, 0xa196, 0x2000,
7309 0x1148, 0x6900, 0xa18e, 0x0001, 0x1118, 0x080c, 0x41d1, 0x0ca8,
7310 0x0039, 0x0c98, 0xa196, 0x8000, 0x1d80, 0x080c, 0x6372, 0x0c68,
7311 0x00c6, 0x6a80, 0x82ff, 0x0904, 0x61c0, 0x7110, 0xa18c, 0xff00,
7312 0x810f, 0xa196, 0x0001, 0x0120, 0xa196, 0x0023, 0x1904, 0x61c0,
7313 0xa08e, 0x0023, 0x1570, 0x080c, 0x6408, 0x0904, 0x61c0, 0x7124,
7314 0x610a, 0x7030, 0xa08e, 0x0200, 0x1150, 0x7034, 0xa005, 0x1904,
7315 0x61c0, 0x2009, 0x0015, 0x080c, 0x80a7, 0x0804, 0x61c0, 0xa08e,
7316 0x0214, 0x0118, 0xa08e, 0x0210, 0x1130, 0x2009, 0x0015, 0x080c,
7317 0x80a7, 0x0804, 0x61c0, 0xa08e, 0x0100, 0x1904, 0x61c0, 0x7034,
7318 0xa005, 0x1904, 0x61c0, 0x2009, 0x0016, 0x080c, 0x80a7, 0x0804,
7319 0x61c0, 0xa08e, 0x0022, 0x1904, 0x61c0, 0x7030, 0xa08e, 0x0300,
7320 0x1580, 0x68d0, 0xd0a4, 0x0528, 0xc0b5, 0x68d2, 0x7100, 0xa18c,
7321 0x00ff, 0x696e, 0x7004, 0x6872, 0x00f6, 0x2079, 0x0100, 0x79e6,
7322 0x78ea, 0x0006, 0xa084, 0x00ff, 0x0016, 0x2008, 0x080c, 0x26a0,
7323 0x7932, 0x7936, 0x001e, 0x000e, 0x00fe, 0x080c, 0x2676, 0x694e,
7324 0x703c, 0x00e6, 0x2071, 0x0140, 0x7086, 0x2071, 0xad00, 0x70a2,
7325 0x00ee, 0x7034, 0xa005, 0x1904, 0x61c0, 0x2009, 0x0017, 0x0804,
7326 0x6193, 0xa08e, 0x0400, 0x1158, 0x7034, 0xa005, 0x1904, 0x61c0,
7327 0x68d0, 0xc0a5, 0x68d2, 0x2009, 0x0030, 0x0804, 0x6193, 0xa08e,
7328 0x0500, 0x1140, 0x7034, 0xa005, 0x1904, 0x61c0, 0x2009, 0x0018,
7329 0x0804, 0x6193, 0xa08e, 0x2010, 0x1120, 0x2009, 0x0019, 0x0804,
7330 0x6193, 0xa08e, 0x2110, 0x1120, 0x2009, 0x001a, 0x0804, 0x6193,
7331 0xa08e, 0x5200, 0x1140, 0x7034, 0xa005, 0x1904, 0x61c0, 0x2009,
7332 0x001b, 0x0804, 0x6193, 0xa08e, 0x5000, 0x1140, 0x7034, 0xa005,
7333 0x1904, 0x61c0, 0x2009, 0x001c, 0x0804, 0x6193, 0xa08e, 0x1300,
7334 0x1120, 0x2009, 0x0034, 0x0804, 0x6193, 0xa08e, 0x1200, 0x1140,
7335 0x7034, 0xa005, 0x1904, 0x61c0, 0x2009, 0x0024, 0x0804, 0x6193,
7336 0xa08c, 0xff00, 0xa18e, 0x2400, 0x1118, 0x2009, 0x002d, 0x04d8,
7337 0xa08c, 0xff00, 0xa18e, 0x5300, 0x1118, 0x2009, 0x002a, 0x0498,
7338 0xa08e, 0x0f00, 0x1118, 0x2009, 0x0020, 0x0468, 0xa08e, 0x5300,
7339 0x1108, 0x00d8, 0xa08e, 0x6104, 0x11c0, 0x2011, 0xb28d, 0x8208,
7340 0x2204, 0xa082, 0x0004, 0x20a8, 0x95ac, 0x95ac, 0x2011, 0x8015,
7341 0x211c, 0x8108, 0x0046, 0x2124, 0x080c, 0x3c5c, 0x004e, 0x8108,
7342 0x1f04, 0x6176, 0x2009, 0x0023, 0x0070, 0xa08e, 0x6000, 0x1118,
7343 0x2009, 0x003f, 0x0040, 0xa08e, 0x7800, 0x1118, 0x2009, 0x0045,
7344 0x0010, 0x2009, 0x001d, 0x0016, 0x2011, 0xb283, 0x2204, 0x8211,
7345 0x220c, 0x080c, 0x2676, 0x1530, 0x080c, 0x4c80, 0x1518, 0x6612,
7346 0x6516, 0x86ff, 0x0180, 0x001e, 0x0016, 0xa186, 0x0017, 0x1158,
7347 0x686c, 0xa606, 0x1140, 0x6870, 0xa506, 0xa084, 0xff00, 0x1118,
7348 0x6000, 0xc0f5, 0x6002, 0x00c6, 0x080c, 0x8022, 0x0168, 0x001e,
7349 0x611a, 0x601f, 0x0004, 0x7120, 0x610a, 0x001e, 0x080c, 0x80a7,
7350 0x00ce, 0x0005, 0x001e, 0x0ce0, 0x00ce, 0x0ce0, 0x00c6, 0x0046,
7351 0x080c, 0x6221, 0x1904, 0x621e, 0xa184, 0xff00, 0x8007, 0xa086,
7352 0x0008, 0x1904, 0x621e, 0xa28e, 0x0033, 0x11e8, 0x080c, 0x6408,
7353 0x0904, 0x621e, 0x7124, 0x610a, 0x7030, 0xa08e, 0x0200, 0x1140,
7354 0x7034, 0xa005, 0x15d8, 0x2009, 0x0015, 0x080c, 0x80a7, 0x04b0,
7355 0xa08e, 0x0100, 0x1598, 0x7034, 0xa005, 0x1580, 0x2009, 0x0016,
7356 0x080c, 0x80a7, 0x0458, 0xa28e, 0x0032, 0x1540, 0x7030, 0xa08e,
7357 0x1400, 0x1520, 0x2009, 0x0038, 0x0016, 0x2011, 0xb283, 0x2204,
7358 0x8211, 0x220c, 0x080c, 0x2676, 0x11c0, 0x080c, 0x4c80, 0x11a8,
7359 0x6612, 0x6516, 0x00c6, 0x080c, 0x8022, 0x0170, 0x001e, 0x611a,
7360 0x080c, 0x9956, 0x601f, 0x0004, 0x7120, 0x610a, 0x001e, 0x080c,
7361 0x80a7, 0x080c, 0x6c50, 0x0010, 0x00ce, 0x001e, 0x004e, 0x00ce,
7362 0x0005, 0x00f6, 0x00d6, 0x0026, 0x0016, 0x0136, 0x0146, 0x0156,
7363 0x3c00, 0x0006, 0x2079, 0x0030, 0x2069, 0x0200, 0x080c, 0x1df2,
7364 0x1590, 0x080c, 0x1ce2, 0x05c8, 0x04d9, 0x1130, 0x7908, 0xa18c,
7365 0x1fff, 0xa182, 0x0011, 0x1688, 0x20a9, 0x000c, 0x20e1, 0x0000,
7366 0x2ea0, 0x2099, 0x020a, 0x53a5, 0x20e1, 0x2000, 0x2001, 0x020a,
7367 0x2004, 0x7a0c, 0x7808, 0xa080, 0x0007, 0xa084, 0x1ff8, 0x0401,
7368 0x1120, 0xa08a, 0x0140, 0x1a0c, 0x14f6, 0x80ac, 0x20e1, 0x6000,
7369 0x2099, 0x020a, 0x53a5, 0x20e1, 0x7000, 0x6828, 0x6828, 0x7803,
7370 0x0004, 0xa294, 0x0070, 0x000e, 0x20e0, 0x015e, 0x014e, 0x013e,
7371 0x001e, 0x002e, 0x00de, 0x00fe, 0x0005, 0xa085, 0x0001, 0x0c98,
7372 0x0006, 0x2001, 0x0111, 0x2004, 0xa084, 0x0003, 0x000e, 0x0005,
7373 0x0046, 0x00e6, 0x00d6, 0x2028, 0x2130, 0xa696, 0x00ff, 0x1198,
7374 0xa596, 0xfffd, 0x1120, 0x2009, 0x007f, 0x0804, 0x62ca, 0xa596,
7375 0xfffe, 0x1118, 0x2009, 0x007e, 0x04e8, 0xa596, 0xfffc, 0x1118,
7376 0x2009, 0x0080, 0x04b8, 0x2011, 0x0000, 0x2019, 0xad34, 0x231c,
7377 0xd3ac, 0x0138, 0x2021, 0x0000, 0x20a9, 0x00ff, 0x2071, 0xae34,
7378 0x0030, 0x2021, 0x0081, 0x20a9, 0x007e, 0x2071, 0xaeb5, 0x2e1c,
7379 0x83ff, 0x1128, 0x82ff, 0x1198, 0x2410, 0xc2fd, 0x0080, 0x2368,
7380 0x6f10, 0x0006, 0x2100, 0xa706, 0x000e, 0x6b14, 0x1120, 0xa346,
7381 0x1110, 0x2408, 0x0078, 0x87ff, 0x1110, 0x83ff, 0x0d58, 0x8420,
7382 0x8e70, 0x1f04, 0x62a7, 0x82ff, 0x1118, 0xa085, 0x0001, 0x0018,
7383 0xc2fc, 0x2208, 0xa006, 0x00de, 0x00ee, 0x004e, 0x0005, 0xa084,
7384 0x0007, 0x000a, 0x0005, 0x62db, 0x62db, 0x62db, 0x641a, 0x62db,
7385 0x62dc, 0x62f1, 0x635d, 0x0005, 0x7110, 0xd1bc, 0x0188, 0x7120,
7386 0x2160, 0xac8c, 0x0007, 0x1160, 0xac8a, 0xb400, 0x0248, 0x6858,
7387 0xac02, 0x1230, 0x7124, 0x610a, 0x2009, 0x0046, 0x080c, 0x80a7,
7388 0x0005, 0x00c6, 0x7110, 0xd1bc, 0x1904, 0x6344, 0x2011, 0xb283,
7389 0x2204, 0x8211, 0x220c, 0x080c, 0x2676, 0x1904, 0x6344, 0x080c,
7390 0x4c80, 0x1904, 0x6344, 0x6612, 0x6516, 0x6000, 0xd0ec, 0x15e0,
7391 0x6204, 0xa294, 0xff00, 0x8217, 0xa286, 0x0006, 0x0160, 0x080c,
7392 0x574f, 0x11d0, 0x6204, 0xa294, 0x00ff, 0xa286, 0x0006, 0x11a0,
7393 0xa295, 0x0600, 0x6206, 0x00c6, 0x080c, 0x8022, 0x001e, 0x0530,
7394 0x611a, 0x601f, 0x0006, 0x7120, 0x610a, 0x7130, 0x6152, 0x2009,
7395 0x0044, 0x080c, 0x80a7, 0x00c0, 0x00c6, 0x080c, 0x8022, 0x001e,
7396 0x0198, 0x611a, 0x601f, 0x0004, 0x7120, 0x610a, 0xa286, 0x0004,
7397 0x1118, 0x6007, 0x0005, 0x0010, 0x6007, 0x0001, 0x6003, 0x0001,
7398 0x080c, 0x67ee, 0x080c, 0x6c50, 0x00ce, 0x0005, 0x00c6, 0x080c,
7399 0x9807, 0x001e, 0x0dc8, 0x611a, 0x601f, 0x0006, 0x7120, 0x610a,
7400 0x7130, 0x6152, 0x6013, 0x0300, 0x6003, 0x0001, 0x6007, 0x0041,
7401 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0c38, 0x7110, 0xd1bc, 0x0188,
7402 0x7020, 0x2060, 0xac84, 0x0007, 0x1160, 0xac82, 0xb400, 0x0248,
7403 0x6858, 0xac02, 0x1230, 0x7124, 0x610a, 0x2009, 0x0045, 0x080c,
7404 0x80a7, 0x0005, 0x7110, 0xa18c, 0xff00, 0x810f, 0xa18e, 0x0000,
7405 0x1130, 0xa084, 0x000f, 0xa08a, 0x0006, 0x1208, 0x000b, 0x0005,
7406 0x6386, 0x6387, 0x6386, 0x6386, 0x63f0, 0x63fc, 0x0005, 0x7110,
7407 0xd1bc, 0x0120, 0x702c, 0xd084, 0x0904, 0x63ef, 0x700c, 0x7108,
7408 0x080c, 0x2676, 0x1904, 0x63ef, 0x080c, 0x4c80, 0x1904, 0x63ef,
7409 0x6612, 0x6516, 0x6204, 0x7110, 0xd1bc, 0x01f8, 0xa28c, 0x00ff,
7410 0xa186, 0x0004, 0x0118, 0xa186, 0x0006, 0x15c8, 0x00c6, 0x080c,
7411 0x6408, 0x00ce, 0x0904, 0x63ef, 0x00c6, 0x080c, 0x8022, 0x001e,
7412 0x05f0, 0x611a, 0x080c, 0x9956, 0x601f, 0x0002, 0x7120, 0x610a,
7413 0x2009, 0x0088, 0x080c, 0x80a7, 0x0490, 0xa28c, 0x00ff, 0xa186,
7414 0x0006, 0x0160, 0xa186, 0x0004, 0x0148, 0xa294, 0xff00, 0x8217,
7415 0xa286, 0x0004, 0x0118, 0xa286, 0x0006, 0x1188, 0x00c6, 0x080c,
7416 0x8022, 0x001e, 0x01e0, 0x611a, 0x080c, 0x9956, 0x601f, 0x0005,
7417 0x7120, 0x610a, 0x2009, 0x0088, 0x080c, 0x80a7, 0x0080, 0x00c6,
7418 0x080c, 0x8022, 0x001e, 0x0158, 0x611a, 0x080c, 0x9956, 0x601f,
7419 0x0004, 0x7120, 0x610a, 0x2009, 0x0001, 0x080c, 0x80a7, 0x0005,
7420 0x7110, 0xd1bc, 0x0140, 0x00a1, 0x0130, 0x7124, 0x610a, 0x2009,
7421 0x0089, 0x080c, 0x80a7, 0x0005, 0x7110, 0xd1bc, 0x0140, 0x0041,
7422 0x0130, 0x7124, 0x610a, 0x2009, 0x008a, 0x080c, 0x80a7, 0x0005,
7423 0x7020, 0x2060, 0xac84, 0x0007, 0x1158, 0xac82, 0xb400, 0x0240,
7424 0x2001, 0xad16, 0x2004, 0xac02, 0x1218, 0xa085, 0x0001, 0x0005,
7425 0xa006, 0x0ce8, 0x7110, 0xd1bc, 0x1178, 0x7024, 0x2060, 0xac84,
7426 0x0007, 0x1150, 0xac82, 0xb400, 0x0238, 0x6858, 0xac02, 0x1220,
7427 0x2009, 0x0051, 0x080c, 0x80a7, 0x0005, 0x2031, 0x0105, 0x0069,
7428 0x0005, 0x2031, 0x0206, 0x0049, 0x0005, 0x2031, 0x0207, 0x0029,
7429 0x0005, 0x2031, 0x0213, 0x0009, 0x0005, 0x00c6, 0x00d6, 0x00f6,
7430 0x7000, 0xa084, 0xf000, 0xa086, 0xc000, 0x05b0, 0x080c, 0x8022,
7431 0x0598, 0x0066, 0x00c6, 0x0046, 0x2011, 0xb283, 0x2204, 0x8211,
7432 0x220c, 0x080c, 0x2676, 0x1580, 0x080c, 0x4c80, 0x1568, 0x6612,
7433 0x6516, 0x2c00, 0x004e, 0x00ce, 0x601a, 0x080c, 0x9956, 0x080c,
7434 0x15d9, 0x01f0, 0x2d00, 0x6056, 0x6803, 0x0000, 0x6837, 0x0000,
7435 0x6c3a, 0xadf8, 0x000f, 0x20a9, 0x000e, 0x2fa0, 0x2e98, 0x53a3,
7436 0x006e, 0x6612, 0x6007, 0x003e, 0x601f, 0x0001, 0x6003, 0x0001,
7437 0x080c, 0x67ee, 0x080c, 0x6c50, 0x00fe, 0x00de, 0x00ce, 0x0005,
7438 0x080c, 0x8078, 0x006e, 0x0cc0, 0x004e, 0x00ce, 0x0cc8, 0x2071,
7439 0xafda, 0x7003, 0x0003, 0x700f, 0x0361, 0xa006, 0x701a, 0x7012,
7440 0x7017, 0xb400, 0x7007, 0x0000, 0x7026, 0x702b, 0x7841, 0x7032,
7441 0x7037, 0x789d, 0x703b, 0xffff, 0x703f, 0xffff, 0x7042, 0x7047,
7442 0x41b3, 0x0005, 0x2071, 0xafda, 0x1d04, 0x64fc, 0x2091, 0x6000,
7443 0x700c, 0x8001, 0x700e, 0x1180, 0x700f, 0x0361, 0x7007, 0x0001,
7444 0x0126, 0x2091, 0x8000, 0x7040, 0xa00d, 0x0148, 0x8109, 0x7142,
7445 0x1130, 0x7044, 0x080f, 0x0018, 0x0126, 0x2091, 0x8000, 0x7024,
7446 0xa00d, 0x0188, 0x7020, 0x8001, 0x7022, 0x1168, 0x7023, 0x0009,
7447 0x8109, 0x7126, 0xa186, 0x03e8, 0x1110, 0x7028, 0x080f, 0x81ff,
7448 0x1110, 0x7028, 0x080f, 0x7030, 0xa00d, 0x0158, 0x702c, 0x8001,
7449 0x702e, 0x1138, 0x702f, 0x0009, 0x8109, 0x7132, 0x1110, 0x7034,
7450 0x080f, 0x7038, 0xa005, 0x0118, 0x0310, 0x8001, 0x703a, 0x703c,
7451 0xa005, 0x0118, 0x0310, 0x8001, 0x703e, 0x7018, 0xa00d, 0x0158,
7452 0x7008, 0x8001, 0x700a, 0x1138, 0x700b, 0x0009, 0x8109, 0x711a,
7453 0x1110, 0x701c, 0x080f, 0x012e, 0x7004, 0x0002, 0x6522, 0x6523,
7454 0x653b, 0x00e6, 0x2071, 0xafda, 0x7018, 0xa005, 0x1120, 0x711a,
7455 0x721e, 0x700b, 0x0009, 0x00ee, 0x0005, 0x00e6, 0x0006, 0x2071,
7456 0xafda, 0x701c, 0xa206, 0x1110, 0x701a, 0x701e, 0x000e, 0x00ee,
7457 0x0005, 0x00e6, 0x2071, 0xafda, 0x6088, 0xa102, 0x0208, 0x618a,
7458 0x00ee, 0x0005, 0x0005, 0x7110, 0x080c, 0x4cdc, 0x1158, 0x6088,
7459 0x8001, 0x0240, 0x608a, 0x1130, 0x0126, 0x2091, 0x8000, 0x080c,
7460 0x6c50, 0x012e, 0x8108, 0xa182, 0x00ff, 0x0218, 0xa00e, 0x7007,
7461 0x0002, 0x7112, 0x0005, 0x7014, 0x2060, 0x0126, 0x2091, 0x8000,
7462 0x603c, 0xa005, 0x0128, 0x8001, 0x603e, 0x1110, 0x080c, 0x9846,
7463 0x6014, 0xa005, 0x0500, 0x8001, 0x6016, 0x11e8, 0x611c, 0xa186,
7464 0x0003, 0x0118, 0xa186, 0x0006, 0x11a0, 0x6010, 0x2068, 0x6854,
7465 0xa08a, 0x199a, 0x0270, 0xa082, 0x1999, 0x6856, 0xa08a, 0x199a,
7466 0x0210, 0x2001, 0x1999, 0x8003, 0x800b, 0x810b, 0xa108, 0x6116,
7467 0x0010, 0x080c, 0x9350, 0x012e, 0xac88, 0x0018, 0x7116, 0x2001,
7468 0xe400, 0xa102, 0x0220, 0x7017, 0xb400, 0x7007, 0x0000, 0x0005,
7469 0x00e6, 0x2071, 0xafda, 0x7027, 0x07d0, 0x7023, 0x0009, 0x00ee,
7470 0x0005, 0x2001, 0xafe3, 0x2003, 0x0000, 0x0005, 0x00e6, 0x2071,
7471 0xafda, 0x7132, 0x702f, 0x0009, 0x00ee, 0x0005, 0x2011, 0xafe6,
7472 0x2013, 0x0000, 0x0005, 0x00e6, 0x2071, 0xafda, 0x711a, 0x721e,
7473 0x700b, 0x0009, 0x00ee, 0x0005, 0x00c6, 0x2061, 0xb048, 0x00ce,
7474 0x0005, 0xa184, 0x000f, 0x8003, 0x8003, 0x8003, 0xa080, 0xb048,
7475 0x2060, 0x0005, 0x6854, 0xa08a, 0x199a, 0x0210, 0x2001, 0x1999,
7476 0xa005, 0x1150, 0x00c6, 0x2061, 0xb048, 0x6014, 0x00ce, 0xa005,
7477 0x1138, 0x2001, 0x001e, 0x0020, 0xa08e, 0xffff, 0x1108, 0xa006,
7478 0x8003, 0x800b, 0x810b, 0xa108, 0x6116, 0x684c, 0xa08c, 0x00c0,
7479 0xa18e, 0x00c0, 0x05b0, 0xd0b4, 0x1138, 0xd0bc, 0x1528, 0x2009,
7480 0x0006, 0x080c, 0x661a, 0x0005, 0xd0fc, 0x0130, 0xa084, 0x0003,
7481 0x0118, 0xa086, 0x0003, 0x15c0, 0x6020, 0xd0d4, 0x0130, 0xc0d4,
7482 0x6022, 0x6860, 0x602a, 0x685c, 0x602e, 0x2009, 0xad73, 0x2104,
7483 0xd084, 0x0128, 0x2009, 0x0042, 0x080c, 0x80a7, 0x0005, 0x2009,
7484 0x0043, 0x080c, 0x80a7, 0x0005, 0xd0fc, 0x0130, 0xa084, 0x0003,
7485 0x0118, 0xa086, 0x0003, 0x11c0, 0x2009, 0x0042, 0x080c, 0x80a7,
7486 0x0005, 0xd0fc, 0x0150, 0xa084, 0x0003, 0xa08e, 0x0002, 0x0138,
7487 0x2009, 0x0041, 0x080c, 0x80a7, 0x0005, 0x0051, 0x0ce8, 0x2009,
7488 0x0043, 0x080c, 0x80a7, 0x0cc0, 0x2009, 0x0004, 0x0019, 0x0005,
7489 0x2009, 0x0001, 0x00d6, 0x6010, 0xa0ec, 0xf000, 0x01f0, 0x2068,
7490 0x6952, 0x6800, 0x6012, 0xa186, 0x0001, 0x1188, 0x694c, 0xa18c,
7491 0x8100, 0xa18e, 0x8100, 0x1158, 0x00c6, 0x2061, 0xb048, 0x6200,
7492 0xd28c, 0x1120, 0x6204, 0x8210, 0x0208, 0x6206, 0x00ce, 0x080c,
7493 0x510c, 0x6010, 0xa06d, 0x190c, 0x65aa, 0x00de, 0x0005, 0x0156,
7494 0x00c6, 0x2061, 0xb048, 0x6000, 0x81ff, 0x0110, 0xa205, 0x0008,
7495 0xa204, 0x6002, 0x00ce, 0x015e, 0x0005, 0x6800, 0xd08c, 0x1138,
7496 0x6808, 0xa005, 0x0120, 0x8001, 0x680a, 0xa085, 0x0001, 0x0005,
7497 0x20a9, 0x0010, 0xa006, 0x8004, 0x8086, 0x818e, 0x1208, 0xa200,
7498 0x1f04, 0x665c, 0x8086, 0x818e, 0x0005, 0x0156, 0x20a9, 0x0010,
7499 0xa005, 0x01b8, 0xa11a, 0x12a8, 0x8213, 0x818d, 0x0228, 0xa11a,
7500 0x1220, 0x1f04, 0x666c, 0x0028, 0xa11a, 0x2308, 0x8210, 0x1f04,
7501 0x666c, 0x0006, 0x3200, 0xa084, 0xefff, 0x2080, 0x000e, 0x015e,
7502 0x0005, 0x0006, 0x3200, 0xa085, 0x1000, 0x0cb8, 0x0126, 0x2091,
7503 0x2800, 0x2079, 0xafc7, 0x012e, 0x00d6, 0x2069, 0xafc7, 0x6803,
7504 0x0005, 0x2069, 0x0004, 0x2d04, 0xa085, 0x8001, 0x206a, 0x00de,
7505 0x0005, 0x00c6, 0x6027, 0x0001, 0x7804, 0xa084, 0x0007, 0x0002,
7506 0x66aa, 0x66cb, 0x671e, 0x66b0, 0x66cb, 0x66aa, 0x66a8, 0x66a8,
7507 0x080c, 0x14f6, 0x080c, 0x6581, 0x080c, 0x6c50, 0x00ce, 0x0005,
7508 0x62c0, 0x82ff, 0x1110, 0x00ce, 0x0005, 0x2011, 0x481b, 0x080c,
7509 0x650d, 0x7828, 0xa092, 0x00c8, 0x1228, 0x8000, 0x782a, 0x080c,
7510 0x4855, 0x0c88, 0x080c, 0x481b, 0x7807, 0x0003, 0x7827, 0x0000,
7511 0x782b, 0x0000, 0x0c40, 0x080c, 0x6581, 0x3c00, 0x0006, 0x2011,
7512 0x0209, 0x20e1, 0x4000, 0x2214, 0x000e, 0x20e0, 0x82ff, 0x0178,
7513 0x62c0, 0x82ff, 0x1160, 0x782b, 0x0000, 0x7824, 0xa065, 0x090c,
7514 0x14f6, 0x2009, 0x0013, 0x080c, 0x80a7, 0x00ce, 0x0005, 0x3900,
7515 0xa082, 0xb0e8, 0x1210, 0x080c, 0x7d8d, 0x00c6, 0x7824, 0xa065,
7516 0x090c, 0x14f6, 0x7804, 0xa086, 0x0004, 0x0904, 0x675e, 0x7828,
7517 0xa092, 0x2710, 0x1230, 0x8000, 0x782a, 0x00ce, 0x080c, 0x7827,
7518 0x0c20, 0x6104, 0xa186, 0x0003, 0x1188, 0x00e6, 0x2071, 0xad00,
7519 0x70dc, 0x00ee, 0xd08c, 0x0150, 0x00c6, 0x00e6, 0x2061, 0x0100,
7520 0x2071, 0xad00, 0x080c, 0x485e, 0x00ee, 0x00ce, 0x080c, 0xaca2,
7521 0x2009, 0x0014, 0x080c, 0x80a7, 0x00ce, 0x0838, 0x2001, 0xafe3,
7522 0x2003, 0x0000, 0x62c0, 0x82ff, 0x1160, 0x782b, 0x0000, 0x7824,
7523 0xa065, 0x090c, 0x14f6, 0x2009, 0x0013, 0x080c, 0x80fb, 0x00ce,
7524 0x0005, 0x00c6, 0x00d6, 0x3900, 0xa082, 0xb0e8, 0x1210, 0x080c,
7525 0x7d8d, 0x7824, 0xa005, 0x090c, 0x14f6, 0x781c, 0xa06d, 0x090c,
7526 0x14f6, 0x6800, 0xc0dc, 0x6802, 0x7924, 0x2160, 0x080c, 0x8078,
7527 0x693c, 0x81ff, 0x090c, 0x14f6, 0x8109, 0x693e, 0x6854, 0xa015,
7528 0x0110, 0x7a1e, 0x0010, 0x7918, 0x791e, 0x7807, 0x0000, 0x7827,
7529 0x0000, 0x00de, 0x00ce, 0x080c, 0x6c50, 0x0888, 0x6104, 0xa186,
7530 0x0002, 0x0128, 0xa186, 0x0004, 0x0110, 0x0804, 0x66f7, 0x7808,
7531 0xac06, 0x0904, 0x66f7, 0x080c, 0x6b73, 0x080c, 0x67ee, 0x00ce,
7532 0x080c, 0x6c50, 0x0804, 0x66e5, 0x00c6, 0x6027, 0x0002, 0x62c8,
7533 0x60c4, 0xa205, 0x1178, 0x793c, 0xa1e5, 0x0000, 0x0130, 0x2009,
7534 0x0049, 0x080c, 0x80a7, 0x00ce, 0x0005, 0x2011, 0xafe6, 0x2013,
7535 0x0000, 0x0cc8, 0x3908, 0xa192, 0xb0e8, 0x1210, 0x080c, 0x7d8d,
7536 0x793c, 0x81ff, 0x0d90, 0x793c, 0xa188, 0x0007, 0x210c, 0xa18e,
7537 0x0006, 0x1138, 0x6014, 0xa084, 0x0184, 0xa085, 0x0012, 0x6016,
7538 0x0c10, 0x6014, 0xa084, 0x0184, 0xa085, 0x0016, 0x6016, 0x08d8,
7539 0x0006, 0x0016, 0x00c6, 0x0126, 0x2091, 0x8000, 0x600f, 0x0000,
7540 0x2c08, 0x2061, 0xafc7, 0x6020, 0x8000, 0x6022, 0x6010, 0xa005,
7541 0x0148, 0xa080, 0x0003, 0x2102, 0x6112, 0x012e, 0x00ce, 0x001e,
7542 0x000e, 0x0005, 0x6116, 0x6112, 0x0cc0, 0x00d6, 0x2069, 0xafc7,
7543 0x6000, 0xd0d4, 0x0168, 0x6820, 0x8000, 0x6822, 0xa086, 0x0001,
7544 0x1110, 0x2c00, 0x681e, 0x6804, 0xa084, 0x0007, 0x0804, 0x6c56,
7545 0xc0d5, 0x6002, 0x6818, 0xa005, 0x0158, 0x6056, 0x605b, 0x0000,
7546 0x0006, 0x2c00, 0x681a, 0x00de, 0x685a, 0x2069, 0xafc7, 0x0c18,
7547 0x6056, 0x605a, 0x2c00, 0x681a, 0x681e, 0x08e8, 0x0006, 0x0016,
7548 0x00c6, 0x0126, 0x2091, 0x8000, 0x600f, 0x0000, 0x2c08, 0x2061,
7549 0xafc7, 0x6020, 0x8000, 0x6022, 0x6008, 0xa005, 0x0148, 0xa080,
7550 0x0003, 0x2102, 0x610a, 0x012e, 0x00ce, 0x001e, 0x000e, 0x0005,
7551 0x610e, 0x610a, 0x0cc0, 0x00c6, 0x600f, 0x0000, 0x2c08, 0x2061,
7552 0xafc7, 0x6034, 0xa005, 0x0130, 0xa080, 0x0003, 0x2102, 0x6136,
7553 0x00ce, 0x0005, 0x613a, 0x6136, 0x0cd8, 0x00f6, 0x00e6, 0x00d6,
7554 0x00c6, 0x0076, 0x0066, 0x0026, 0x0016, 0x0006, 0x0126, 0x2071,
7555 0xafc7, 0x7638, 0x2660, 0x2678, 0x2091, 0x8000, 0x8cff, 0x0904,
7556 0x6889, 0x6018, 0xa080, 0x0028, 0x2004, 0xa206, 0x1904, 0x6884,
7557 0x87ff, 0x0120, 0x6050, 0xa106, 0x1904, 0x6884, 0x703c, 0xac06,
7558 0x1170, 0x0036, 0x2019, 0x0001, 0x080c, 0x7a64, 0x7033, 0x0000,
7559 0x703f, 0x0000, 0x7043, 0x0000, 0x7047, 0x0000, 0x003e, 0x7038,
7560 0xac36, 0x1110, 0x660c, 0x763a, 0x7034, 0xac36, 0x1140, 0x2c00,
7561 0xaf36, 0x0118, 0x2f00, 0x7036, 0x0010, 0x7037, 0x0000, 0x660c,
7562 0x0066, 0x2c00, 0xaf06, 0x0110, 0x7e0e, 0x0008, 0x2678, 0x600f,
7563 0x0000, 0x080c, 0x9596, 0x0198, 0x6010, 0x2068, 0x601c, 0xa086,
7564 0x0003, 0x1510, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c,
7565 0x97fd, 0x080c, 0xabfa, 0x080c, 0x510c, 0x080c, 0x9742, 0x080c,
7566 0x974e, 0x00ce, 0x0804, 0x682e, 0x2c78, 0x600c, 0x2060, 0x0804,
7567 0x682e, 0x012e, 0x000e, 0x001e, 0x002e, 0x006e, 0x007e, 0x00ce,
7568 0x00de, 0x00ee, 0x00fe, 0x0005, 0x601c, 0xa086, 0x0006, 0x19d0,
7569 0x080c, 0xabfa, 0x080c, 0xa91f, 0x0c10, 0x0006, 0x0066, 0x00c6,
7570 0x00d6, 0x00f6, 0x2031, 0x0000, 0x0126, 0x2091, 0x8000, 0x2079,
7571 0xafc7, 0x7838, 0xa065, 0x0558, 0x600c, 0x0006, 0x600f, 0x0000,
7572 0x783c, 0xac06, 0x1170, 0x0036, 0x2019, 0x0001, 0x080c, 0x7a64,
7573 0x7833, 0x0000, 0x783f, 0x0000, 0x7843, 0x0000, 0x7847, 0x0000,
7574 0x003e, 0x080c, 0x9596, 0x0178, 0x6010, 0x2068, 0x601c, 0xa086,
7575 0x0003, 0x11b0, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c,
7576 0x510c, 0x080c, 0x9742, 0x080c, 0x974e, 0x000e, 0x0898, 0x7e3a,
7577 0x7e36, 0x012e, 0x00fe, 0x00de, 0x00ce, 0x006e, 0x000e, 0x0005,
7578 0x601c, 0xa086, 0x0006, 0x1d30, 0x080c, 0xa91f, 0x0c60, 0x0016,
7579 0x0026, 0x0086, 0x2041, 0x0000, 0x0099, 0x080c, 0x69a9, 0x008e,
7580 0x002e, 0x001e, 0x0005, 0x00f6, 0x0126, 0x2079, 0xafc7, 0x2091,
7581 0x8000, 0x080c, 0x6a36, 0x080c, 0x6aa8, 0x012e, 0x00fe, 0x0005,
7582 0x00f6, 0x00e6, 0x00d6, 0x00c6, 0x0066, 0x0016, 0x0006, 0x0126,
7583 0x2091, 0x8000, 0x2071, 0xafc7, 0x7614, 0x2660, 0x2678, 0x8cff,
7584 0x0904, 0x6985, 0x6018, 0xa080, 0x0028, 0x2004, 0xa206, 0x1904,
7585 0x6980, 0x88ff, 0x0120, 0x6050, 0xa106, 0x1904, 0x6980, 0x7024,
7586 0xac06, 0x1538, 0x2069, 0x0100, 0x68c0, 0xa005, 0x01f0, 0x080c,
7587 0x6581, 0x080c, 0x7834, 0x68c3, 0x0000, 0x080c, 0x7ca8, 0x7027,
7588 0x0000, 0x0036, 0x2069, 0x0140, 0x6b04, 0xa384, 0x1000, 0x0120,
7589 0x6803, 0x0100, 0x6803, 0x0000, 0x2069, 0x0100, 0x6824, 0xd084,
7590 0x0110, 0x6827, 0x0001, 0x003e, 0x0020, 0x6003, 0x0009, 0x630a,
7591 0x04b8, 0x7014, 0xac36, 0x1110, 0x660c, 0x7616, 0x7010, 0xac36,
7592 0x1140, 0x2c00, 0xaf36, 0x0118, 0x2f00, 0x7012, 0x0010, 0x7013,
7593 0x0000, 0x660c, 0x0066, 0x2c00, 0xaf06, 0x0110, 0x7e0e, 0x0008,
7594 0x2678, 0x600f, 0x0000, 0x6010, 0x2068, 0x080c, 0x9596, 0x0188,
7595 0x601c, 0xa086, 0x0003, 0x1510, 0x6837, 0x0103, 0x6b4a, 0x6847,
7596 0x0000, 0x080c, 0x97fd, 0x080c, 0xabfa, 0x080c, 0x510c, 0x080c,
7597 0x9742, 0x080c, 0x974e, 0x080c, 0x7b88, 0x00ce, 0x0804, 0x690f,
7598 0x2c78, 0x600c, 0x2060, 0x0804, 0x690f, 0x012e, 0x000e, 0x001e,
7599 0x006e, 0x00ce, 0x00de, 0x00ee, 0x00fe, 0x0005, 0x601c, 0xa086,
7600 0x0006, 0x1128, 0x080c, 0xabfa, 0x080c, 0xa91f, 0x0c10, 0x601c,
7601 0xa086, 0x0002, 0x1128, 0x6004, 0xa086, 0x0085, 0x0968, 0x08c8,
7602 0x601c, 0xa086, 0x0005, 0x19a8, 0x6004, 0xa086, 0x0085, 0x0d50,
7603 0x0880, 0x00c6, 0x0006, 0x0126, 0x2091, 0x8000, 0xa280, 0xae34,
7604 0x2004, 0xa065, 0x0904, 0x6a32, 0x00f6, 0x00e6, 0x00d6, 0x0066,
7605 0x2071, 0xafc7, 0x6654, 0x7018, 0xac06, 0x1108, 0x761a, 0x701c,
7606 0xac06, 0x1130, 0x86ff, 0x1118, 0x7018, 0x701e, 0x0008, 0x761e,
7607 0x6058, 0xa07d, 0x0108, 0x7e56, 0xa6ed, 0x0000, 0x0110, 0x2f00,
7608 0x685a, 0x6057, 0x0000, 0x605b, 0x0000, 0x6000, 0xc0d4, 0xc0dc,
7609 0x6002, 0x080c, 0x4c07, 0x0904, 0x6a2e, 0x7624, 0x86ff, 0x05e8,
7610 0xa680, 0x0004, 0x2004, 0xad06, 0x15c0, 0x00d6, 0x2069, 0x0100,
7611 0x68c0, 0xa005, 0x0548, 0x080c, 0x6581, 0x080c, 0x7834, 0x68c3,
7612 0x0000, 0x080c, 0x7ca8, 0x7027, 0x0000, 0x0036, 0x2069, 0x0140,
7613 0x6b04, 0xa384, 0x1000, 0x0120, 0x6803, 0x0100, 0x6803, 0x0000,
7614 0x2069, 0x0100, 0x6824, 0xd084, 0x0110, 0x6827, 0x0001, 0x003e,
7615 0x00de, 0x00c6, 0x603c, 0xa005, 0x0110, 0x8001, 0x603e, 0x2660,
7616 0x080c, 0x974e, 0x00ce, 0x0048, 0x00de, 0x00c6, 0x2660, 0x6003,
7617 0x0009, 0x630a, 0x00ce, 0x0804, 0x69d9, 0x8dff, 0x0158, 0x6837,
7618 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c, 0x97fd, 0x080c, 0xabfa,
7619 0x080c, 0x510c, 0x080c, 0x7b88, 0x0804, 0x69d9, 0x006e, 0x00de,
7620 0x00ee, 0x00fe, 0x012e, 0x000e, 0x00ce, 0x0005, 0x0006, 0x0066,
7621 0x00c6, 0x00d6, 0x2031, 0x0000, 0x7814, 0xa065, 0x0904, 0x6a88,
7622 0x600c, 0x0006, 0x600f, 0x0000, 0x7824, 0xac06, 0x1540, 0x2069,
7623 0x0100, 0x68c0, 0xa005, 0x01f0, 0x080c, 0x6581, 0x080c, 0x7834,
7624 0x68c3, 0x0000, 0x080c, 0x7ca8, 0x7827, 0x0000, 0x0036, 0x2069,
7625 0x0140, 0x6b04, 0xa384, 0x1000, 0x0120, 0x6803, 0x0100, 0x6803,
7626 0x0000, 0x2069, 0x0100, 0x6824, 0xd084, 0x0110, 0x6827, 0x0001,
7627 0x003e, 0x0028, 0x6003, 0x0009, 0x630a, 0x2c30, 0x00b0, 0x6010,
7628 0x2068, 0x080c, 0x9596, 0x0168, 0x601c, 0xa086, 0x0003, 0x11b8,
7629 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c, 0x510c, 0x080c,
7630 0x9742, 0x080c, 0x974e, 0x080c, 0x7b88, 0x000e, 0x0804, 0x6a3d,
7631 0x7e16, 0x7e12, 0x00de, 0x00ce, 0x006e, 0x000e, 0x0005, 0x601c,
7632 0xa086, 0x0006, 0x1118, 0x080c, 0xa91f, 0x0c58, 0x601c, 0xa086,
7633 0x0002, 0x1128, 0x6004, 0xa086, 0x0085, 0x09d0, 0x0c10, 0x601c,
7634 0xa086, 0x0005, 0x19f0, 0x6004, 0xa086, 0x0085, 0x0d60, 0x08c8,
7635 0x0006, 0x0066, 0x00c6, 0x00d6, 0x7818, 0xa065, 0x0904, 0x6b0e,
7636 0x6054, 0x0006, 0x6057, 0x0000, 0x605b, 0x0000, 0x6000, 0xc0d4,
7637 0xc0dc, 0x6002, 0x080c, 0x4c07, 0x0904, 0x6b0b, 0x7e24, 0x86ff,
7638 0x05e8, 0xa680, 0x0004, 0x2004, 0xad06, 0x15c0, 0x00d6, 0x2069,
7639 0x0100, 0x68c0, 0xa005, 0x0548, 0x080c, 0x6581, 0x080c, 0x7834,
7640 0x68c3, 0x0000, 0x080c, 0x7ca8, 0x7827, 0x0000, 0x0036, 0x2069,
7641 0x0140, 0x6b04, 0xa384, 0x1000, 0x0120, 0x6803, 0x0100, 0x6803,
7642 0x0000, 0x2069, 0x0100, 0x6824, 0xd084, 0x0110, 0x6827, 0x0001,
7643 0x003e, 0x00de, 0x00c6, 0x603c, 0xa005, 0x0110, 0x8001, 0x603e,
7644 0x2660, 0x080c, 0x974e, 0x00ce, 0x0048, 0x00de, 0x00c6, 0x2660,
7645 0x6003, 0x0009, 0x630a, 0x00ce, 0x0804, 0x6aba, 0x8dff, 0x0138,
7646 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c, 0x510c, 0x080c,
7647 0x7b88, 0x0804, 0x6aba, 0x000e, 0x0804, 0x6aad, 0x781e, 0x781a,
7648 0x00de, 0x00ce, 0x006e, 0x000e, 0x0005, 0x00e6, 0x00d6, 0x0066,
7649 0x6000, 0xd0dc, 0x0188, 0x604c, 0xa06d, 0x0170, 0x6848, 0xa606,
7650 0x1158, 0x2071, 0xafc7, 0x7024, 0xa035, 0x0130, 0xa080, 0x0004,
7651 0x2004, 0xad06, 0x1108, 0x0021, 0x006e, 0x00de, 0x00ee, 0x0005,
7652 0x00f6, 0x2079, 0x0100, 0x78c0, 0xa005, 0x1138, 0x00c6, 0x2660,
7653 0x6003, 0x0009, 0x630a, 0x00ce, 0x04a0, 0x080c, 0x7834, 0x78c3,
7654 0x0000, 0x080c, 0x7ca8, 0x7027, 0x0000, 0x0036, 0x2079, 0x0140,
7655 0x7b04, 0xa384, 0x1000, 0x0120, 0x7803, 0x0100, 0x7803, 0x0000,
7656 0x2079, 0x0100, 0x7824, 0xd084, 0x0110, 0x7827, 0x0001, 0x080c,
7657 0x7ca8, 0x003e, 0x080c, 0x4c07, 0x00c6, 0x603c, 0xa005, 0x0110,
7658 0x8001, 0x603e, 0x2660, 0x080c, 0x8078, 0x00ce, 0x6837, 0x0103,
7659 0x6b4a, 0x6847, 0x0000, 0x080c, 0x97fd, 0x080c, 0x510c, 0x080c,
7660 0x7b88, 0x00fe, 0x0005, 0x00e6, 0x00c6, 0x2071, 0xafc7, 0x7004,
7661 0xa084, 0x0007, 0x0002, 0x6b85, 0x6b88, 0x6b9e, 0x6bb7, 0x6bf0,
7662 0x6b85, 0x6b83, 0x6b83, 0x080c, 0x14f6, 0x00ce, 0x00ee, 0x0005,
7663 0x7024, 0xa065, 0x0148, 0x7020, 0x8001, 0x7022, 0x600c, 0xa015,
7664 0x0150, 0x7216, 0x600f, 0x0000, 0x7007, 0x0000, 0x7027, 0x0000,
7665 0x00ce, 0x00ee, 0x0005, 0x7216, 0x7212, 0x0cb0, 0x6018, 0x2060,
7666 0x080c, 0x4c07, 0x6000, 0xc0dc, 0x6002, 0x7020, 0x8001, 0x7022,
7667 0x0120, 0x6054, 0xa015, 0x0140, 0x721e, 0x7007, 0x0000, 0x7027,
7668 0x0000, 0x00ce, 0x00ee, 0x0005, 0x7218, 0x721e, 0x0cb0, 0x7024,
7669 0xa065, 0x0598, 0x700c, 0xac06, 0x1160, 0x080c, 0x7b88, 0x600c,
7670 0xa015, 0x0120, 0x720e, 0x600f, 0x0000, 0x0428, 0x720e, 0x720a,
7671 0x0410, 0x7014, 0xac06, 0x1160, 0x080c, 0x7b88, 0x600c, 0xa015,
7672 0x0120, 0x7216, 0x600f, 0x0000, 0x00b0, 0x7216, 0x7212, 0x0098,
7673 0x6018, 0x2060, 0x080c, 0x4c07, 0x6000, 0xc0dc, 0x6002, 0x080c,
7674 0x7b88, 0x701c, 0xa065, 0x0138, 0x6054, 0xa015, 0x0110, 0x721e,
7675 0x0010, 0x7218, 0x721e, 0x7027, 0x0000, 0x00ce, 0x00ee, 0x0005,
7676 0x7024, 0xa065, 0x0140, 0x080c, 0x7b88, 0x600c, 0xa015, 0x0150,
7677 0x720e, 0x600f, 0x0000, 0x080c, 0x7ca8, 0x7027, 0x0000, 0x00ce,
7678 0x00ee, 0x0005, 0x720e, 0x720a, 0x0cb0, 0x00d6, 0x2069, 0xafc7,
7679 0x6830, 0xa084, 0x0003, 0x0002, 0x6c12, 0x6c14, 0x6c38, 0x6c10,
7680 0x080c, 0x14f6, 0x00de, 0x0005, 0x00c6, 0x6840, 0xa086, 0x0001,
7681 0x01b8, 0x683c, 0xa065, 0x0130, 0x600c, 0xa015, 0x0170, 0x6a3a,
7682 0x600f, 0x0000, 0x6833, 0x0000, 0x683f, 0x0000, 0x2011, 0xafe6,
7683 0x2013, 0x0000, 0x00ce, 0x00de, 0x0005, 0x683a, 0x6836, 0x0c90,
7684 0x6843, 0x0000, 0x6838, 0xa065, 0x0d68, 0x6003, 0x0003, 0x0c50,
7685 0x00c6, 0x6843, 0x0000, 0x6847, 0x0000, 0x683c, 0xa065, 0x0168,
7686 0x600c, 0xa015, 0x0130, 0x6a3a, 0x600f, 0x0000, 0x683f, 0x0000,
7687 0x0020, 0x683f, 0x0000, 0x683a, 0x6836, 0x00ce, 0x00de, 0x0005,
7688 0x00d6, 0x2069, 0xafc7, 0x6804, 0xa084, 0x0007, 0x0002, 0x6c61,
7689 0x6cfd, 0x6cfd, 0x6cfd, 0x6cfd, 0x6cff, 0x6c5f, 0x6c5f, 0x080c,
7690 0x14f6, 0x6820, 0xa005, 0x1110, 0x00de, 0x0005, 0x00c6, 0x680c,
7691 0xa065, 0x0150, 0x6807, 0x0004, 0x6826, 0x682b, 0x0000, 0x080c,
7692 0x6d49, 0x00ce, 0x00de, 0x0005, 0x6814, 0xa065, 0x0150, 0x6807,
7693 0x0001, 0x6826, 0x682b, 0x0000, 0x080c, 0x6d49, 0x00ce, 0x00de,
7694 0x0005, 0x00e6, 0x0036, 0x6a1c, 0xa2f5, 0x0000, 0x0904, 0x6cf9,
7695 0x704c, 0xa00d, 0x0118, 0x7088, 0xa005, 0x01a0, 0x7054, 0xa075,
7696 0x0120, 0xa20e, 0x0904, 0x6cf9, 0x0028, 0x6818, 0xa20e, 0x0904,
7697 0x6cf9, 0x2070, 0x704c, 0xa00d, 0x0d88, 0x7088, 0xa005, 0x1d70,
7698 0x2e00, 0x681e, 0x733c, 0x7038, 0xa302, 0x1e40, 0x080c, 0x804f,
7699 0x0904, 0x6cf9, 0x8318, 0x733e, 0x6112, 0x2e10, 0x621a, 0xa180,
7700 0x0014, 0x2004, 0xa084, 0x00ff, 0x605a, 0xa180, 0x0014, 0x2003,
7701 0x0000, 0xa180, 0x0015, 0x2004, 0xa08a, 0x199a, 0x0210, 0x2001,
7702 0x1999, 0x8003, 0x801b, 0x831b, 0xa318, 0x6316, 0x003e, 0x00f6,
7703 0x2c78, 0x71a0, 0x2001, 0xad34, 0x2004, 0xd0ac, 0x1110, 0xd1bc,
7704 0x0150, 0x7100, 0xd1f4, 0x0120, 0x7114, 0xa18c, 0x00ff, 0x0040,
7705 0x2009, 0x0000, 0x0028, 0xa1e0, 0x2be6, 0x2c0d, 0xa18c, 0x00ff,
7706 0x2061, 0x0100, 0x619a, 0x080c, 0x736f, 0x7300, 0xc3dd, 0x7302,
7707 0x6807, 0x0002, 0x2f18, 0x6b26, 0x682b, 0x0000, 0x781f, 0x0003,
7708 0x7803, 0x0001, 0x7807, 0x0040, 0x00fe, 0x00ee, 0x00ce, 0x00de,
7709 0x0005, 0x003e, 0x00ee, 0x00ce, 0x0cd0, 0x00de, 0x0005, 0x00c6,
7710 0x680c, 0xa065, 0x0138, 0x6807, 0x0004, 0x6826, 0x682b, 0x0000,
7711 0x080c, 0x6d49, 0x00ce, 0x00de, 0x0005, 0x00f6, 0x00d6, 0x2069,
7712 0xafc7, 0x6830, 0xa086, 0x0000, 0x11c0, 0x2001, 0xad0c, 0x200c,
7713 0xd1bc, 0x1550, 0x6838, 0xa07d, 0x0180, 0x6833, 0x0001, 0x683e,
7714 0x6847, 0x0000, 0x0126, 0x00f6, 0x2091, 0x2400, 0x002e, 0x080c,
7715 0x1ee6, 0x1130, 0x012e, 0x080c, 0x76a5, 0x00de, 0x00fe, 0x0005,
7716 0x012e, 0xe000, 0x6843, 0x0000, 0x7803, 0x0002, 0x780c, 0xa015,
7717 0x0140, 0x6a3a, 0x780f, 0x0000, 0x6833, 0x0000, 0x683f, 0x0000,
7718 0x0c60, 0x683a, 0x6836, 0x0cc0, 0xc1bc, 0x2102, 0x080c, 0x57d1,
7719 0x0888, 0x601c, 0xa084, 0x000f, 0x000b, 0x0005, 0x6d57, 0x6d5c,
7720 0x7210, 0x732c, 0x6d5c, 0x7210, 0x732c, 0x6d57, 0x6d5c, 0x080c,
7721 0x6b73, 0x080c, 0x6c50, 0x0005, 0x0156, 0x0136, 0x0146, 0x00c6,
7722 0x00f6, 0x6004, 0xa08a, 0x0080, 0x1a0c, 0x14f6, 0x6118, 0x2178,
7723 0x79a0, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110, 0xd1bc, 0x0150,
7724 0x7900, 0xd1f4, 0x0120, 0x7914, 0xa18c, 0x00ff, 0x0040, 0x2009,
7725 0x0000, 0x0028, 0xa1f8, 0x2be6, 0x2f0d, 0xa18c, 0x00ff, 0x2c78,
7726 0x2061, 0x0100, 0x619a, 0xa08a, 0x0040, 0x1a04, 0x6dd0, 0x0033,
7727 0x00fe, 0x00ce, 0x014e, 0x013e, 0x015e, 0x0005, 0x6e7c, 0x6ec7,
7728 0x6ef4, 0x6fc1, 0x6fef, 0x6ff7, 0x701d, 0x702e, 0x703f, 0x7047,
7729 0x705d, 0x7047, 0x70b7, 0x702e, 0x70d8, 0x70e0, 0x703f, 0x70e0,
7730 0x70f1, 0x6dce, 0x6dce, 0x6dce, 0x6dce, 0x6dce, 0x6dce, 0x6dce,
7731 0x6dce, 0x6dce, 0x6dce, 0x6dce, 0x790d, 0x7932, 0x7947, 0x796a,
7732 0x798b, 0x701d, 0x6dce, 0x701d, 0x7047, 0x6dce, 0x6ef4, 0x6fc1,
7733 0x6dce, 0x7daa, 0x7047, 0x6dce, 0x7dca, 0x7047, 0x6dce, 0x703f,
7734 0x6e75, 0x6de0, 0x6dce, 0x7def, 0x7e64, 0x7f3b, 0x6dce, 0x7f4c,
7735 0x7018, 0x7f68, 0x6dce, 0x79a0, 0x7fc3, 0x6dce, 0x080c, 0x14f6,
7736 0x2100, 0x0033, 0x00fe, 0x00ce, 0x014e, 0x013e, 0x015e, 0x0005,
7737 0x6dde, 0x6dde, 0x6dde, 0x6e14, 0x6e32, 0x6e48, 0x080c, 0x14f6,
7738 0x00d6, 0x20a1, 0x020b, 0x080c, 0x710e, 0x7810, 0x2068, 0x20a3,
7739 0x2414, 0x20a3, 0x0018, 0x20a3, 0x0800, 0x683c, 0x20a2, 0x20a3,
7740 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x6850,
7741 0x20a2, 0x6854, 0x20a2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3,
7742 0x0018, 0x080c, 0x7821, 0x00de, 0x0005, 0x00d6, 0x7818, 0x2068,
7743 0x68a0, 0x2069, 0xad00, 0x6ad0, 0xd2ac, 0x1110, 0xd0bc, 0x0110,
7744 0xa085, 0x0001, 0x00de, 0x0005, 0x00d6, 0x20a1, 0x020b, 0x080c,
7745 0x710e, 0x20a3, 0x0500, 0x20a3, 0x0000, 0x7810, 0xa0e8, 0x000f,
7746 0x6808, 0x20a2, 0x680c, 0x20a2, 0x6810, 0x20a2, 0x6814, 0x20a2,
7747 0x6818, 0x20a2, 0x681c, 0x20a2, 0x60c3, 0x0010, 0x080c, 0x7821,
7748 0x00de, 0x0005, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x710e,
7749 0x20a3, 0x7800, 0x20a3, 0x0000, 0x7808, 0x8007, 0x20a2, 0x20a3,
7750 0x0000, 0x60c3, 0x0008, 0x080c, 0x7821, 0x014e, 0x015e, 0x0005,
7751 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0200,
7752 0x20a3, 0x0000, 0x20a3, 0xdf10, 0x20a3, 0x0034, 0x2099, 0xad05,
7753 0x20a9, 0x0004, 0x53a6, 0x2099, 0xad01, 0x20a9, 0x0004, 0x53a6,
7754 0x2099, 0xafad, 0x20a9, 0x001a, 0x3304, 0x8007, 0x20a2, 0x9398,
7755 0x1f04, 0x6e64, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x004c,
7756 0x080c, 0x7821, 0x014e, 0x015e, 0x0005, 0x2001, 0xad14, 0x2004,
7757 0x609a, 0x080c, 0x7821, 0x0005, 0x20a1, 0x020b, 0x080c, 0x710e,
7758 0x20a3, 0x5200, 0x20a3, 0x0000, 0x00d6, 0x2069, 0xad51, 0x6804,
7759 0xd084, 0x0150, 0x6828, 0x20a3, 0x0000, 0x0016, 0x080c, 0x268a,
7760 0x21a2, 0x001e, 0x00de, 0x0028, 0x00de, 0x20a3, 0x0000, 0x20a3,
7761 0x0000, 0x20a9, 0x0004, 0x2099, 0xad05, 0x53a6, 0x20a9, 0x0004,
7762 0x2099, 0xad01, 0x53a6, 0x2001, 0xad34, 0x2004, 0xd0ac, 0x1138,
7763 0x7818, 0xa080, 0x0028, 0x2004, 0xa082, 0x007f, 0x0238, 0x2001,
7764 0xad1b, 0x20a6, 0x2001, 0xad1c, 0x20a6, 0x0040, 0x20a3, 0x0000,
7765 0x2001, 0xad14, 0x2004, 0xa084, 0x00ff, 0x20a2, 0x20a3, 0x0000,
7766 0x20a3, 0x0000, 0x60c3, 0x001c, 0x080c, 0x7821, 0x0005, 0x20a1,
7767 0x020b, 0x080c, 0x710e, 0x20a3, 0x0500, 0x20a3, 0x0000, 0x2001,
7768 0xad34, 0x2004, 0xd0ac, 0x1138, 0x7818, 0xa080, 0x0028, 0x2004,
7769 0xa082, 0x007f, 0x0238, 0x2001, 0xad1b, 0x20a6, 0x2001, 0xad1c,
7770 0x20a6, 0x0040, 0x20a3, 0x0000, 0x2001, 0xad14, 0x2004, 0xa084,
7771 0x00ff, 0x20a2, 0x20a9, 0x0004, 0x2099, 0xad05, 0x53a6, 0x60c3,
7772 0x0010, 0x080c, 0x7821, 0x0005, 0x20a1, 0x020b, 0x080c, 0x710e,
7773 0x00c6, 0x7818, 0x2060, 0x2001, 0x0000, 0x080c, 0x5037, 0x00ce,
7774 0x7818, 0xa080, 0x0028, 0x2004, 0xa086, 0x007e, 0x1130, 0x20a3,
7775 0x0400, 0x620c, 0xc2b4, 0x620e, 0x0010, 0x20a3, 0x0300, 0x20a3,
7776 0x0000, 0x7818, 0xa080, 0x0028, 0x2004, 0xa086, 0x007e, 0x1904,
7777 0x6f83, 0x2001, 0xad34, 0x2004, 0xd0a4, 0x01c8, 0x2099, 0xaf8d,
7778 0x33a6, 0x9398, 0x20a3, 0x0000, 0x9398, 0x3304, 0xa084, 0x2000,
7779 0x20a2, 0x9398, 0x33a6, 0x9398, 0x20a3, 0x0000, 0x9398, 0x2001,
7780 0x2710, 0x20a2, 0x9398, 0x33a6, 0x9398, 0x33a6, 0x00d0, 0x2099,
7781 0xaf8d, 0x33a6, 0x9398, 0x33a6, 0x9398, 0x3304, 0x080c, 0x574f,
7782 0x1118, 0xa084, 0x37ff, 0x0010, 0xa084, 0x3fff, 0x20a2, 0x9398,
7783 0x33a6, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
7784 0x0000, 0x20a9, 0x0004, 0x2099, 0xad05, 0x53a6, 0x20a9, 0x0004,
7785 0x2099, 0xad01, 0x53a6, 0x20a9, 0x0008, 0x20a3, 0x0000, 0x1f04,
7786 0x6f5d, 0x20a9, 0x0008, 0x20a3, 0x0000, 0x1f04, 0x6f63, 0x2099,
7787 0xaf95, 0x3304, 0xc0dd, 0x20a2, 0x2001, 0xad71, 0x2004, 0xd0e4,
7788 0x0158, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x9398, 0x9398, 0x9398,
7789 0x33a6, 0x20a9, 0x0004, 0x0010, 0x20a9, 0x0007, 0x20a3, 0x0000,
7790 0x1f04, 0x6f7e, 0x0468, 0x2001, 0xad34, 0x2004, 0xd0a4, 0x0140,
7791 0x2001, 0xaf8e, 0x2004, 0x60e3, 0x0000, 0x080c, 0x26cb, 0x60e2,
7792 0x2099, 0xaf8d, 0x20a9, 0x0008, 0x53a6, 0x20a9, 0x0004, 0x2099,
7793 0xad05, 0x53a6, 0x20a9, 0x0004, 0x2099, 0xad01, 0x53a6, 0x20a9,
7794 0x0008, 0x20a3, 0x0000, 0x1f04, 0x6fa1, 0x20a9, 0x0008, 0x20a3,
7795 0x0000, 0x1f04, 0x6fa7, 0x2099, 0xaf95, 0x20a9, 0x0008, 0x53a6,
7796 0x20a9, 0x0008, 0x20a3, 0x0000, 0x1f04, 0x6fb2, 0x20a9, 0x000a,
7797 0x20a3, 0x0000, 0x1f04, 0x6fb8, 0x60c3, 0x0074, 0x080c, 0x7821,
7798 0x0005, 0x20a1, 0x020b, 0x080c, 0x710e, 0x20a3, 0x2010, 0x20a3,
7799 0x0014, 0x20a3, 0x0800, 0x20a3, 0x2000, 0xa006, 0x20a2, 0x20a2,
7800 0x20a2, 0x20a2, 0x20a2, 0x00f6, 0x2079, 0xad51, 0x7904, 0x00fe,
7801 0xd1ac, 0x1110, 0xa085, 0x0020, 0xd1a4, 0x0110, 0xa085, 0x0010,
7802 0xa085, 0x0002, 0x00d6, 0x0804, 0x7099, 0x20a2, 0x20a3, 0x0000,
7803 0x20a3, 0x0000, 0x60c3, 0x0014, 0x080c, 0x7821, 0x0005, 0x20a1,
7804 0x020b, 0x080c, 0x710e, 0x20a3, 0x5000, 0x0804, 0x6f0f, 0x20a1,
7805 0x020b, 0x080c, 0x710e, 0x20a3, 0x2110, 0x20a3, 0x0014, 0x20a3,
7806 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
7807 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
7808 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014, 0x080c, 0x7821, 0x0005,
7809 0x20a1, 0x020b, 0x080c, 0x71a2, 0x0020, 0x20a1, 0x020b, 0x080c,
7810 0x71aa, 0x20a3, 0x0200, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
7811 0x0000, 0x60c3, 0x0004, 0x080c, 0x7821, 0x0005, 0x20a1, 0x020b,
7812 0x080c, 0x71aa, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x20a3, 0x0003,
7813 0x20a3, 0x2a00, 0x60c3, 0x0008, 0x080c, 0x7821, 0x0005, 0x20a1,
7814 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0200, 0x0804, 0x6f0f, 0x20a1,
7815 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x7828,
7816 0xa005, 0x0110, 0x20a2, 0x0010, 0x20a3, 0x0003, 0x7810, 0x20a2,
7817 0x60c3, 0x0008, 0x080c, 0x7821, 0x0005, 0x00d6, 0x20a1, 0x020b,
7818 0x080c, 0x71aa, 0x20a3, 0x0210, 0x20a3, 0x0014, 0x20a3, 0x0800,
7819 0x7818, 0x2068, 0x6894, 0xa086, 0x0014, 0x1178, 0x6998, 0xa184,
7820 0xc000, 0x1140, 0xd1ec, 0x0118, 0x20a3, 0x2100, 0x0040, 0x20a3,
7821 0x0100, 0x0028, 0x20a3, 0x0400, 0x0010, 0x20a3, 0x0700, 0xa006,
7822 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x00f6, 0x2079, 0xad51,
7823 0x7904, 0x00fe, 0xd1ac, 0x1110, 0xa085, 0x0020, 0xd1a4, 0x0110,
7824 0xa085, 0x0010, 0x2009, 0xad73, 0x210c, 0xd184, 0x1110, 0xa085,
7825 0x0002, 0x0026, 0x2009, 0xad71, 0x210c, 0xd1e4, 0x0130, 0xc0c5,
7826 0xa094, 0x0030, 0xa296, 0x0010, 0x0140, 0xd1ec, 0x0130, 0xa094,
7827 0x0030, 0xa296, 0x0010, 0x0108, 0xc0bd, 0x002e, 0x20a2, 0x20a2,
7828 0x20a2, 0x60c3, 0x0014, 0x080c, 0x7821, 0x00de, 0x0005, 0x20a1,
7829 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0210, 0x20a3, 0x0014, 0x20a3,
7830 0x0000, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
7831 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3,
7832 0x0000, 0x20a3, 0x0000, 0x60c3, 0x0014, 0x080c, 0x7821, 0x0005,
7833 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0200, 0x0804, 0x6e82,
7834 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0100, 0x20a3, 0x0000,
7835 0x20a3, 0x0003, 0x20a3, 0x2a00, 0x60c3, 0x0008, 0x080c, 0x7821,
7836 0x0005, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x20a1, 0x020b, 0x080c,
7837 0x71aa, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x20a3, 0x000b, 0x20a3,
7838 0x0000, 0x60c3, 0x0008, 0x080c, 0x7821, 0x0005, 0x0026, 0x0036,
7839 0x0046, 0x2019, 0x3200, 0x2021, 0x0800, 0x0038, 0x0026, 0x0036,
7840 0x0046, 0x2019, 0x2200, 0x2021, 0x0100, 0x20e1, 0x9080, 0x20e1,
7841 0x4000, 0x7818, 0xa080, 0x0028, 0x2014, 0xa286, 0x007e, 0x11a0,
7842 0xa385, 0x00ff, 0x20a2, 0x20a3, 0xfffe, 0x20a3, 0x0000, 0x2011,
7843 0xad14, 0x2214, 0x2001, 0xaf9d, 0x2004, 0xa005, 0x0118, 0x2011,
7844 0xad1c, 0x2214, 0x22a2, 0x04d0, 0xa286, 0x007f, 0x1138, 0x00d6,
7845 0xa385, 0x00ff, 0x20a2, 0x20a3, 0xfffd, 0x00c8, 0x2001, 0xad34,
7846 0x2004, 0xd0ac, 0x1110, 0xd2bc, 0x01c8, 0xa286, 0x0080, 0x00d6,
7847 0x1130, 0xa385, 0x00ff, 0x20a2, 0x20a3, 0xfffc, 0x0040, 0xa2e8,
7848 0xae34, 0x2d6c, 0x6810, 0xa305, 0x20a2, 0x6814, 0x20a2, 0x2069,
7849 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de, 0x0080, 0x00d6, 0xa2e8,
7850 0xae34, 0x2d6c, 0x6810, 0xa305, 0x20a2, 0x6814, 0x20a2, 0x00de,
7851 0x20a3, 0x0000, 0x2011, 0xad14, 0x2214, 0x22a2, 0xa485, 0x0029,
7852 0x20a2, 0x004e, 0x003e, 0x20a3, 0x0000, 0x080c, 0x7810, 0x22a2,
7853 0x20a3, 0x0000, 0x2fa2, 0x20a3, 0xffff, 0x20a3, 0x0000, 0x20a3,
7854 0x0000, 0x002e, 0x0005, 0x0026, 0x20e1, 0x9080, 0x20e1, 0x4000,
7855 0x20a3, 0x02ff, 0x2011, 0xfffc, 0x22a2, 0x00d6, 0x2069, 0xad1b,
7856 0x2da6, 0x8d68, 0x2da6, 0x00de, 0x20a3, 0x2029, 0x20a3, 0x0000,
7857 0x08e0, 0x20a3, 0x0100, 0x20a3, 0x0000, 0x20a3, 0xfc02, 0x20a3,
7858 0x0000, 0x0005, 0x0026, 0x0036, 0x0046, 0x2019, 0x3300, 0x2021,
7859 0x0800, 0x0038, 0x0026, 0x0036, 0x0046, 0x2019, 0x2300, 0x2021,
7860 0x0100, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028,
7861 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1118, 0xa092, 0x007e,
7862 0x02d8, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa305, 0x20a2,
7863 0x6814, 0x20a2, 0x6810, 0xa005, 0x1140, 0x6814, 0xa005, 0x1128,
7864 0x20a3, 0x00ff, 0x20a3, 0xfffe, 0x0028, 0x2069, 0xad1b, 0x2da6,
7865 0x8d68, 0x2da6, 0x00de, 0x0080, 0x00d6, 0xa0e8, 0xae34, 0x2d6c,
7866 0x6810, 0xa305, 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000,
7867 0x2011, 0xad14, 0x2214, 0x22a2, 0xa485, 0x0098, 0x20a2, 0x20a3,
7868 0x0000, 0x004e, 0x003e, 0x080c, 0x7810, 0x22a2, 0x20a3, 0x0000,
7869 0x7a08, 0x22a2, 0x2fa2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x002e,
7870 0x0005, 0x080c, 0x7810, 0x22a2, 0x20a3, 0x0000, 0x7a08, 0x22a2,
7871 0x7810, 0x20a2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x002e, 0x0005,
7872 0x00c6, 0x00f6, 0x6004, 0xa08a, 0x0085, 0x0a0c, 0x14f6, 0xa08a,
7873 0x008c, 0x1a0c, 0x14f6, 0x6118, 0x2178, 0x79a0, 0x2011, 0xad34,
7874 0x2214, 0xd2ac, 0x1110, 0xd1bc, 0x0150, 0x7900, 0xd1f4, 0x0120,
7875 0x7914, 0xa18c, 0x00ff, 0x0040, 0x2009, 0x0000, 0x0028, 0xa1f8,
7876 0x2be6, 0x2f0d, 0xa18c, 0x00ff, 0x2c78, 0x2061, 0x0100, 0x619a,
7877 0xa082, 0x0085, 0x001b, 0x00fe, 0x00ce, 0x0005, 0x7247, 0x7251,
7878 0x726c, 0x7245, 0x7245, 0x7245, 0x7247, 0x080c, 0x14f6, 0x0146,
7879 0x20a1, 0x020b, 0x04a1, 0x60c3, 0x0000, 0x080c, 0x7821, 0x014e,
7880 0x0005, 0x0146, 0x20a1, 0x020b, 0x080c, 0x72b8, 0x20a3, 0x0000,
7881 0x20a3, 0x0000, 0x7808, 0x20a2, 0x7810, 0x20a2, 0x20a3, 0x0000,
7882 0x20a3, 0xffff, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x000c,
7883 0x080c, 0x7821, 0x014e, 0x0005, 0x0146, 0x20a1, 0x020b, 0x080c,
7884 0x72f2, 0x20a3, 0x0003, 0x20a3, 0x0300, 0x20a3, 0x0000, 0x20a3,
7885 0x0000, 0x60c3, 0x0004, 0x080c, 0x7821, 0x014e, 0x0005, 0x0026,
7886 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028, 0x2004,
7887 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1118, 0xa092, 0x007e, 0x0288,
7888 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x8100, 0x20a2,
7889 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de,
7890 0x0088, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x8100,
7891 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2011, 0xad14,
7892 0x2214, 0x22a2, 0x20a3, 0x0009, 0x20a3, 0x0000, 0x0804, 0x7175,
7893 0x0026, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028,
7894 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1118, 0xa092, 0x007e,
7895 0x0288, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x8400,
7896 0x20a2, 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6,
7897 0x00de, 0x0088, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085,
7898 0x8400, 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2011,
7899 0xad14, 0x2214, 0x22a2, 0x2001, 0x0099, 0x20a2, 0x20a3, 0x0000,
7900 0x0804, 0x7201, 0x0026, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818,
7901 0xa080, 0x0028, 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1118,
7902 0xa092, 0x007e, 0x0288, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810,
7903 0xa085, 0x8500, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6,
7904 0x8d68, 0x2da6, 0x00de, 0x0088, 0x00d6, 0xa0e8, 0xae34, 0x2d6c,
7905 0x6810, 0xa085, 0x8500, 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3,
7906 0x0000, 0x2011, 0xad14, 0x2214, 0x22a2, 0x2001, 0x0099, 0x20a2,
7907 0x20a3, 0x0000, 0x0804, 0x7201, 0x00c6, 0x00f6, 0x2c78, 0x7804,
7908 0xa08a, 0x0040, 0x0a0c, 0x14f6, 0xa08a, 0x0053, 0x1a0c, 0x14f6,
7909 0x7918, 0x2160, 0x61a0, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110,
7910 0xd1bc, 0x0150, 0x6100, 0xd1f4, 0x0120, 0x6114, 0xa18c, 0x00ff,
7911 0x0040, 0x2009, 0x0000, 0x0028, 0xa1e0, 0x2be6, 0x2c0d, 0xa18c,
7912 0x00ff, 0x2061, 0x0100, 0x619a, 0xa082, 0x0040, 0x001b, 0x00fe,
7913 0x00ce, 0x0005, 0x736f, 0x747b, 0x7418, 0x761a, 0x736d, 0x736d,
7914 0x736d, 0x736d, 0x736d, 0x736d, 0x736d, 0x7b41, 0x7b51, 0x7b61,
7915 0x7b71, 0x736d, 0x7f79, 0x736d, 0x7b30, 0x080c, 0x14f6, 0x00d6,
7916 0x0156, 0x0146, 0x780b, 0xffff, 0x20a1, 0x020b, 0x080c, 0x73cf,
7917 0x7910, 0x2168, 0x6948, 0x7952, 0x21a2, 0xa016, 0x22a2, 0x22a2,
7918 0x22a2, 0x694c, 0xa184, 0x000f, 0x1118, 0x2001, 0x0005, 0x0040,
7919 0xd184, 0x0118, 0x2001, 0x0004, 0x0018, 0xa084, 0x0006, 0x8004,
7920 0x0016, 0x2008, 0x7858, 0xa084, 0x00ff, 0x8007, 0xa105, 0x001e,
7921 0x20a2, 0xd1ac, 0x0118, 0x20a3, 0x0002, 0x0048, 0xd1b4, 0x0118,
7922 0x20a3, 0x0001, 0x0020, 0x20a3, 0x0000, 0x2230, 0x0010, 0x6a80,
7923 0x6e7c, 0x20a9, 0x0008, 0x0136, 0xad88, 0x0017, 0x2198, 0x20a1,
7924 0x021b, 0x53a6, 0x013e, 0x20a1, 0x020b, 0x22a2, 0x26a2, 0x60c3,
7925 0x0020, 0x20e1, 0x9080, 0x6014, 0xa084, 0x0004, 0xa085, 0x0009,
7926 0x6016, 0x2001, 0xafe3, 0x2003, 0x07d0, 0x2001, 0xafe2, 0x2003,
7927 0x0009, 0x080c, 0x17bf, 0x014e, 0x015e, 0x00de, 0x0005, 0x20e1,
7928 0x9080, 0x20e1, 0x4000, 0x7a18, 0xa280, 0x0023, 0x2014, 0x8210,
7929 0xa294, 0x00ff, 0x2202, 0x8217, 0x7818, 0xa080, 0x0028, 0x2004,
7930 0x2019, 0xad34, 0x231c, 0xd3ac, 0x1110, 0xd0bc, 0x0188, 0x00d6,
7931 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0600, 0x20a2, 0x6814,
7932 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de, 0x0088,
7933 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0600, 0x20a2,
7934 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2009, 0xad14, 0x210c,
7935 0x21a2, 0x20a3, 0x0829, 0x20a3, 0x0000, 0x22a2, 0x20a3, 0x0000,
7936 0x2fa2, 0x20a3, 0xffff, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x0005,
7937 0x00d6, 0x0156, 0x0136, 0x0146, 0x20a1, 0x020b, 0x00c1, 0x7810,
7938 0x2068, 0x6860, 0x20a2, 0x685c, 0x20a2, 0x6880, 0x20a2, 0x687c,
7939 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x60c3, 0x000c,
7940 0x080c, 0x7821, 0x014e, 0x013e, 0x015e, 0x00de, 0x0005, 0x0026,
7941 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028, 0x2004,
7942 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110, 0xd0bc, 0x0188, 0x00d6,
7943 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0500, 0x20a2, 0x6814,
7944 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de, 0x0088,
7945 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0500, 0x20a2,
7946 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2011, 0xad14, 0x2214,
7947 0x22a2, 0x20a3, 0x0889, 0x20a3, 0x0000, 0x080c, 0x7810, 0x22a2,
7948 0x20a3, 0x0000, 0x7a08, 0x22a2, 0x2fa2, 0x20a3, 0x0000, 0x20a3,
7949 0x0000, 0x002e, 0x0005, 0x00d6, 0x0156, 0x0136, 0x0146, 0x7810,
7950 0xa06d, 0x080c, 0x5025, 0x0148, 0x684c, 0xa084, 0x2020, 0xa086,
7951 0x2020, 0x1118, 0x7820, 0xc0cd, 0x7822, 0x20a1, 0x020b, 0x080c,
7952 0x75d0, 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x7810,
7953 0xa084, 0xf000, 0x1130, 0x7810, 0xa084, 0x0700, 0x8007, 0x0043,
7954 0x0010, 0xa006, 0x002b, 0x014e, 0x013e, 0x015e, 0x00de, 0x0005,
7955 0x74b2, 0x7547, 0x7550, 0x7579, 0x758c, 0x75a7, 0x75b0, 0x74b0,
7956 0x080c, 0x14f6, 0x0016, 0x0036, 0x694c, 0xa18c, 0x0003, 0x0118,
7957 0xa186, 0x0003, 0x1170, 0x6b78, 0x7820, 0xd0cc, 0x0108, 0xc3e5,
7958 0x23a2, 0x6868, 0x20a2, 0x6864, 0x20a2, 0x003e, 0x001e, 0x0804,
7959 0x7583, 0xa186, 0x0001, 0x190c, 0x14f6, 0x6b78, 0x7820, 0xd0cc,
7960 0x0108, 0xc3e5, 0x23a2, 0x6868, 0x20a2, 0x6864, 0x20a2, 0x22a2,
7961 0x6874, 0x20a2, 0x22a2, 0x687c, 0x20a2, 0x2009, 0x0018, 0xa384,
7962 0x0300, 0x0904, 0x7541, 0xd3c4, 0x0110, 0x687c, 0xa108, 0xd3cc,
7963 0x0110, 0x6874, 0xa108, 0x0156, 0x20a9, 0x000d, 0xad80, 0x0020,
7964 0x201c, 0x831f, 0x23a2, 0x8000, 0x1f04, 0x74f0, 0x015e, 0x22a2,
7965 0x22a2, 0x22a2, 0xa184, 0x0003, 0x0904, 0x7541, 0x20a1, 0x020b,
7966 0x20e1, 0x9080, 0x20e1, 0x4000, 0x0006, 0x7818, 0xa080, 0x0028,
7967 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110, 0xd0bc, 0x0188,
7968 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0700, 0x20a2,
7969 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de,
7970 0x0088, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0700,
7971 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2011, 0xad14,
7972 0x2214, 0x22a2, 0x000e, 0x7b20, 0xd3cc, 0x0118, 0x20a3, 0x0889,
7973 0x0010, 0x20a3, 0x0898, 0x20a2, 0x080c, 0x7810, 0x22a2, 0x20a3,
7974 0x0000, 0x61c2, 0x003e, 0x001e, 0x080c, 0x7821, 0x0005, 0x2011,
7975 0x0008, 0x7820, 0xd0cc, 0x0108, 0xc2e5, 0x22a2, 0xa016, 0x0488,
7976 0x2011, 0x0302, 0x7820, 0xd0cc, 0x0108, 0xc2e5, 0x22a2, 0xa016,
7977 0x22a2, 0x22a2, 0x22a2, 0x20a3, 0x0012, 0x22a2, 0x20a3, 0x0008,
7978 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x20a3, 0x7000, 0x20a3, 0x0500,
7979 0x22a2, 0x20a3, 0x000a, 0x22a2, 0x22a2, 0x20a3, 0x2500, 0x22a2,
7980 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x60c3, 0x0032, 0x080c, 0x7821,
7981 0x0005, 0x2011, 0x0028, 0x7820, 0xd0cc, 0x0108, 0xc2e5, 0x22a2,
7982 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x22a2, 0x60c3,
7983 0x0018, 0x080c, 0x7821, 0x0005, 0x2011, 0x0100, 0x7820, 0xd0cc,
7984 0x0108, 0xc2e5, 0x22a2, 0xa016, 0x22a2, 0x22a2, 0x22a2, 0x22a2,
7985 0x22a2, 0x20a3, 0x0008, 0x22a2, 0x7854, 0xa084, 0x00ff, 0x20a2,
7986 0x22a2, 0x22a2, 0x60c3, 0x0020, 0x080c, 0x7821, 0x0005, 0x2011,
7987 0x0008, 0x7820, 0xd0cc, 0x0108, 0xc2e5, 0x22a2, 0xa016, 0x0888,
7988 0x0036, 0x7b10, 0xa384, 0xff00, 0x7812, 0xa384, 0x00ff, 0x8001,
7989 0x1138, 0x7820, 0xd0cc, 0x0108, 0xc2e5, 0x22a2, 0x003e, 0x0808,
7990 0x0046, 0x2021, 0x0800, 0x0006, 0x7820, 0xd0cc, 0x000e, 0x0108,
7991 0xc4e5, 0x24a2, 0x004e, 0x22a2, 0x20a2, 0x003e, 0x0804, 0x7583,
7992 0x0026, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028,
7993 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110, 0xd0bc, 0x0188,
7994 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0700, 0x20a2,
7995 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de,
7996 0x0088, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0700,
7997 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2011, 0xad14,
7998 0x2214, 0x22a2, 0x7820, 0xd0cc, 0x0118, 0x20a3, 0x0889, 0x0010,
7999 0x20a3, 0x0898, 0x20a3, 0x0000, 0x080c, 0x7810, 0x22a2, 0x20a3,
8000 0x0000, 0x7a08, 0x22a2, 0x2fa2, 0x20a3, 0x0000, 0x20a3, 0x0000,
8001 0x002e, 0x0005, 0x00d6, 0x0156, 0x0136, 0x0146, 0x0016, 0x0036,
8002 0x7810, 0xa084, 0x0700, 0x8007, 0x003b, 0x003e, 0x001e, 0x014e,
8003 0x013e, 0x015e, 0x00de, 0x0005, 0x7634, 0x7634, 0x7636, 0x7634,
8004 0x7634, 0x7634, 0x7658, 0x7634, 0x080c, 0x14f6, 0x7910, 0xa18c,
8005 0xf8ff, 0xa18d, 0x0600, 0x7912, 0x20a1, 0x020b, 0x2009, 0x0003,
8006 0x00f9, 0x00d6, 0x2069, 0xad51, 0x6804, 0xd0bc, 0x0130, 0x682c,
8007 0xa084, 0x00ff, 0x8007, 0x20a2, 0x0010, 0x20a3, 0x3f00, 0x00de,
8008 0x22a2, 0x22a2, 0x22a2, 0x60c3, 0x0001, 0x080c, 0x7821, 0x0005,
8009 0x20a1, 0x020b, 0x2009, 0x0003, 0x0019, 0x20a3, 0x7f00, 0x0c80,
8010 0x0026, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818, 0xa080, 0x0028,
8011 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110, 0xd0bc, 0x0188,
8012 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0100, 0x20a2,
8013 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6, 0x00de,
8014 0x0088, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085, 0x0100,
8015 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000, 0x2011, 0xad14,
8016 0x2214, 0x22a2, 0x20a3, 0x0888, 0xa18d, 0x0008, 0x21a2, 0x080c,
8017 0x7810, 0x22a2, 0x20a3, 0x0000, 0x7a08, 0x22a2, 0x2fa2, 0x20a3,
8018 0x0000, 0x20a3, 0x0000, 0x002e, 0x0005, 0x00e6, 0x00d6, 0x00c6,
8019 0x0056, 0x0046, 0x0036, 0x2061, 0x0100, 0x2071, 0xad00, 0x7150,
8020 0x7818, 0x2068, 0x68a0, 0x2028, 0x76d0, 0xd6ac, 0x1130, 0xd0bc,
8021 0x1120, 0x6910, 0x6a14, 0x7450, 0x0020, 0x6910, 0x6a14, 0x736c,
8022 0x7470, 0x781c, 0xa0be, 0x0006, 0x0904, 0x775b, 0xa0be, 0x000a,
8023 0x15e8, 0xa185, 0x0200, 0x6062, 0x6266, 0x636a, 0x646e, 0x6073,
8024 0x2029, 0x6077, 0x0000, 0x688c, 0x8000, 0xa084, 0x00ff, 0x688e,
8025 0x8007, 0x607a, 0x607f, 0x0000, 0x2f00, 0x6082, 0x7808, 0x6086,
8026 0x7810, 0x2070, 0x7014, 0x608a, 0x7010, 0x608e, 0x700c, 0x60c6,
8027 0x7008, 0x60ca, 0x686c, 0x60ce, 0x60af, 0x95d5, 0x60d7, 0x0000,
8028 0x609f, 0x0000, 0x080c, 0x8014, 0x2009, 0x07d0, 0x60c4, 0xa084,
8029 0xfff0, 0xa005, 0x0110, 0x2009, 0x1b58, 0x080c, 0x6586, 0x003e,
8030 0x004e, 0x005e, 0x00ce, 0x00de, 0x00ee, 0x0005, 0x70d0, 0xd0ac,
8031 0x1110, 0xd5bc, 0x0138, 0xa185, 0x0100, 0x6062, 0x6266, 0x636a,
8032 0x646e, 0x0038, 0xa185, 0x0100, 0x6062, 0x6266, 0x606b, 0x0000,
8033 0x646e, 0x6073, 0x0809, 0x6077, 0x0008, 0x688c, 0x8000, 0xa084,
8034 0x00ff, 0x688e, 0x8007, 0x607a, 0x607f, 0x0000, 0x2f00, 0x6082,
8035 0x7808, 0x6086, 0x7810, 0x2070, 0x7014, 0x608a, 0x7010, 0x608e,
8036 0x700c, 0x60c6, 0x7008, 0x60ca, 0x686c, 0x60ce, 0x60af, 0x95d5,
8037 0x60d7, 0x0000, 0xa582, 0x0080, 0x0248, 0x6a00, 0xd2f4, 0x0120,
8038 0x6a14, 0xa294, 0x00ff, 0x0010, 0x2011, 0x0000, 0x629e, 0x080c,
8039 0x8014, 0x2009, 0x07d0, 0x60c4, 0xa084, 0xfff0, 0xa005, 0x0110,
8040 0x2009, 0x1b58, 0x080c, 0x6586, 0x003e, 0x004e, 0x005e, 0x00ce,
8041 0x00de, 0x00ee, 0x0005, 0x7810, 0x2070, 0x704c, 0xa084, 0x0003,
8042 0xa086, 0x0002, 0x0904, 0x77b1, 0x2001, 0xad34, 0x2004, 0xd0ac,
8043 0x1110, 0xd5bc, 0x0138, 0xa185, 0x0100, 0x6062, 0x6266, 0x636a,
8044 0x646e, 0x0038, 0xa185, 0x0100, 0x6062, 0x6266, 0x606b, 0x0000,
8045 0x646e, 0x6073, 0x0880, 0x6077, 0x0008, 0x688c, 0x8000, 0xa084,
8046 0x00ff, 0x688e, 0x8007, 0x607a, 0x7834, 0x607e, 0x2f00, 0x6086,
8047 0x7808, 0x6082, 0x7060, 0x608a, 0x705c, 0x608e, 0x7080, 0x60c6,
8048 0x707c, 0x60ca, 0x707c, 0x792c, 0xa108, 0x792e, 0x7080, 0x7928,
8049 0xa109, 0x792a, 0x686c, 0x60ce, 0x60af, 0x95d5, 0x60d7, 0x0000,
8050 0xa582, 0x0080, 0x0248, 0x6a00, 0xd2f4, 0x0120, 0x6a14, 0xa294,
8051 0x00ff, 0x0010, 0x2011, 0x0000, 0x629e, 0x080c, 0x8011, 0x0804,
8052 0x7749, 0x2001, 0xad34, 0x2004, 0xd0ac, 0x1110, 0xd5bc, 0x0138,
8053 0xa185, 0x0700, 0x6062, 0x6266, 0x636a, 0x646e, 0x0038, 0xa185,
8054 0x0700, 0x6062, 0x6266, 0x606b, 0x0000, 0x646e, 0x080c, 0x5025,
8055 0x0180, 0x00d6, 0x7810, 0xa06d, 0x684c, 0x00de, 0xa084, 0x2020,
8056 0xa086, 0x2020, 0x1130, 0x7820, 0xc0cd, 0x7822, 0x6073, 0x0889,
8057 0x0010, 0x6073, 0x0898, 0x6077, 0x0000, 0x688c, 0x8000, 0xa084,
8058 0x00ff, 0x688e, 0x8007, 0x607a, 0x607f, 0x0000, 0x2f00, 0x6086,
8059 0x7808, 0x6082, 0x7014, 0x608a, 0x7010, 0x608e, 0x700c, 0x60c6,
8060 0x7008, 0x60ca, 0x686c, 0x60ce, 0x60af, 0x95d5, 0x60d7, 0x0000,
8061 0xa582, 0x0080, 0x0248, 0x6a00, 0xd2f4, 0x0120, 0x6a14, 0xa294,
8062 0x00ff, 0x0010, 0x2011, 0x0000, 0x629e, 0x7820, 0xd0cc, 0x0120,
8063 0x080c, 0x8014, 0x0804, 0x7749, 0x080c, 0x8011, 0x0804, 0x7749,
8064 0x7a18, 0xa280, 0x0023, 0x2014, 0x8210, 0xa294, 0x00ff, 0x2202,
8065 0x8217, 0x0005, 0x00d6, 0x2069, 0xafc7, 0x6843, 0x0001, 0x00de,
8066 0x0005, 0x20e1, 0x9080, 0x60a3, 0x0056, 0x60a7, 0x9575, 0x0019,
8067 0x080c, 0x6578, 0x0005, 0x0006, 0x6014, 0xa084, 0x0004, 0xa085,
8068 0x0009, 0x6016, 0x000e, 0x0005, 0x0006, 0x00c6, 0x2061, 0x0100,
8069 0x6014, 0xa084, 0x0004, 0xa085, 0x0008, 0x6016, 0x00ce, 0x000e,
8070 0x0005, 0x00c6, 0x00d6, 0x0016, 0x0026, 0x2061, 0x0100, 0x2069,
8071 0x0140, 0x080c, 0x574f, 0x1178, 0x2001, 0xafe3, 0x2004, 0xa005,
8072 0x1598, 0x080c, 0x57d1, 0x1118, 0x080c, 0x6578, 0x0468, 0x00c6,
8073 0x2061, 0xafc7, 0x00d8, 0x6904, 0xa194, 0x4000, 0x0550, 0x08a1,
8074 0x6803, 0x1000, 0x6803, 0x0000, 0x00c6, 0x2061, 0xafc7, 0x6128,
8075 0xa192, 0x00c8, 0x1258, 0x8108, 0x612a, 0x6124, 0x00ce, 0x81ff,
8076 0x0198, 0x080c, 0x6578, 0x080c, 0x782b, 0x0070, 0x6124, 0xa1e5,
8077 0x0000, 0x0140, 0x080c, 0xaca2, 0x2009, 0x0014, 0x080c, 0x80a7,
8078 0x080c, 0x6581, 0x00ce, 0x0000, 0x002e, 0x001e, 0x00de, 0x00ce,
8079 0x0005, 0x2001, 0xafe3, 0x2004, 0xa005, 0x1db0, 0x00c6, 0x2061,
8080 0xafc7, 0x6128, 0xa192, 0x0003, 0x1e08, 0x8108, 0x612a, 0x00ce,
8081 0x080c, 0x6578, 0x080c, 0x485e, 0x0c38, 0x00c6, 0x00d6, 0x00e6,
8082 0x0016, 0x0026, 0x080c, 0x658e, 0x2071, 0xafc7, 0x713c, 0x81ff,
8083 0x0570, 0x2061, 0x0100, 0x2069, 0x0140, 0x080c, 0x574f, 0x1188,
8084 0x0036, 0x2019, 0x0001, 0x080c, 0x7a64, 0x003e, 0x713c, 0x2160,
8085 0x080c, 0xaca2, 0x2009, 0x004a, 0x080c, 0x80a7, 0x080c, 0x57d1,
8086 0x00b0, 0x6904, 0xa194, 0x4000, 0x01c0, 0x6803, 0x1000, 0x6803,
8087 0x0000, 0x0036, 0x2019, 0x0001, 0x080c, 0x7a64, 0x003e, 0x713c,
8088 0x2160, 0x080c, 0xaca2, 0x2009, 0x004a, 0x080c, 0x80a7, 0x002e,
8089 0x001e, 0x00ee, 0x00de, 0x00ce, 0x0005, 0x0c58, 0x00e6, 0x00d6,
8090 0x00c6, 0x0066, 0x0056, 0x0046, 0x0006, 0x0126, 0x2091, 0x8000,
8091 0x6018, 0x2068, 0x6ca0, 0x2071, 0xafc7, 0x7018, 0x2068, 0x8dff,
8092 0x0198, 0x68a0, 0xa406, 0x0118, 0x6854, 0x2068, 0x0cc0, 0x6010,
8093 0x2060, 0x643c, 0x6540, 0x6e48, 0x2d60, 0x080c, 0x4e41, 0x0120,
8094 0x080c, 0x7b88, 0xa085, 0x0001, 0x012e, 0x000e, 0x004e, 0x005e,
8095 0x006e, 0x00ce, 0x00de, 0x00ee, 0x0005, 0x20a1, 0x020b, 0x080c,
8096 0x710e, 0x20a3, 0x1200, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x781c,
8097 0xa086, 0x0004, 0x1110, 0x6098, 0x0018, 0x2001, 0xad14, 0x2004,
8098 0x20a2, 0x7834, 0x20a2, 0x7838, 0x20a2, 0x20a9, 0x0010, 0xa006,
8099 0x20a2, 0x1f04, 0x7928, 0x20a2, 0x20a2, 0x60c3, 0x002c, 0x080c,
8100 0x7821, 0x0005, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x710e,
8101 0x20a3, 0x0f00, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x7808, 0x20a2,
8102 0x60c3, 0x0008, 0x080c, 0x7821, 0x014e, 0x015e, 0x0005, 0x0156,
8103 0x0146, 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0200, 0x20a3,
8104 0x0000, 0x20a9, 0x0006, 0x2011, 0xad40, 0x2019, 0xad41, 0x23a6,
8105 0x22a6, 0xa398, 0x0002, 0xa290, 0x0002, 0x1f04, 0x7957, 0x20a3,
8106 0x0000, 0x20a3, 0x0000, 0x60c3, 0x001c, 0x080c, 0x7821, 0x014e,
8107 0x015e, 0x0005, 0x0156, 0x0146, 0x0016, 0x0026, 0x20a1, 0x020b,
8108 0x080c, 0x7183, 0x080c, 0x7199, 0x7810, 0xa080, 0x0000, 0x2004,
8109 0xa080, 0x0015, 0x2098, 0x7808, 0xa088, 0x0002, 0x21a8, 0x53a6,
8110 0xa080, 0x0004, 0x8003, 0x60c2, 0x080c, 0x7821, 0x002e, 0x001e,
8111 0x014e, 0x015e, 0x0005, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c,
8112 0x710e, 0x20a3, 0x6200, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x7808,
8113 0x20a2, 0x60c3, 0x0008, 0x080c, 0x7821, 0x014e, 0x015e, 0x0005,
8114 0x0156, 0x0146, 0x0016, 0x0026, 0x20a1, 0x020b, 0x080c, 0x710e,
8115 0x7810, 0xa080, 0x0000, 0x2004, 0xa080, 0x0017, 0x2098, 0x7808,
8116 0xa088, 0x0002, 0x21a8, 0x53a6, 0x8003, 0x60c2, 0x080c, 0x7821,
8117 0x002e, 0x001e, 0x014e, 0x015e, 0x0005, 0x00e6, 0x00c6, 0x0006,
8118 0x0126, 0x2091, 0x8000, 0x2071, 0xafc7, 0x700c, 0x2060, 0x8cff,
8119 0x0178, 0x080c, 0x9789, 0x1110, 0x080c, 0x85f3, 0x600c, 0x0006,
8120 0x080c, 0x994e, 0x080c, 0x8078, 0x080c, 0x7b88, 0x00ce, 0x0c78,
8121 0x700f, 0x0000, 0x700b, 0x0000, 0x012e, 0x000e, 0x00ce, 0x00ee,
8122 0x0005, 0x0126, 0x0156, 0x00f6, 0x00e6, 0x00d6, 0x00c6, 0x0026,
8123 0x0016, 0x0006, 0x2091, 0x8000, 0x2069, 0x0100, 0x2079, 0x0140,
8124 0x2071, 0xafc7, 0x7024, 0x2060, 0x8cff, 0x05a0, 0x080c, 0x7834,
8125 0x68c3, 0x0000, 0x080c, 0x6581, 0x2009, 0x0013, 0x080c, 0x80a7,
8126 0x20a9, 0x01f4, 0x6824, 0xd094, 0x0158, 0x6827, 0x0004, 0x7804,
8127 0xa084, 0x4000, 0x01a0, 0x7803, 0x1000, 0x7803, 0x0000, 0x0078,
8128 0xd084, 0x0118, 0x6827, 0x0001, 0x0010, 0x1f04, 0x7a02, 0x7804,
8129 0xa084, 0x1000, 0x0120, 0x7803, 0x0100, 0x7803, 0x0000, 0x6824,
8130 0x000e, 0x001e, 0x002e, 0x00ce, 0x00de, 0x00ee, 0x00fe, 0x015e,
8131 0x012e, 0x0005, 0x2001, 0xad00, 0x2004, 0xa096, 0x0001, 0x0550,
8132 0xa096, 0x0004, 0x0538, 0x6817, 0x0008, 0x68c3, 0x0000, 0x2011,
8133 0x481b, 0x080c, 0x650d, 0x20a9, 0x01f4, 0x6824, 0xd094, 0x0158,
8134 0x6827, 0x0004, 0x7804, 0xa084, 0x4000, 0x01a0, 0x7803, 0x1000,
8135 0x7803, 0x0000, 0x0078, 0xd084, 0x0118, 0x6827, 0x0001, 0x0010,
8136 0x1f04, 0x7a3d, 0x7804, 0xa084, 0x1000, 0x0120, 0x7803, 0x0100,
8137 0x7803, 0x0000, 0x000e, 0x001e, 0x002e, 0x00ce, 0x00de, 0x00ee,
8138 0x00fe, 0x015e, 0x012e, 0x0005, 0x0126, 0x0156, 0x00f6, 0x00e6,
8139 0x00d6, 0x00c6, 0x0026, 0x0016, 0x0006, 0x2091, 0x8000, 0x2069,
8140 0x0100, 0x2079, 0x0140, 0x2071, 0xafc7, 0x703c, 0x2060, 0x8cff,
8141 0x0904, 0x7ad5, 0x6817, 0x0010, 0x2009, 0x00fa, 0x8109, 0x1df0,
8142 0x68c7, 0x0000, 0x68cb, 0x0008, 0x080c, 0x658e, 0x080c, 0x20b5,
8143 0x0046, 0x2009, 0x017f, 0x200b, 0x00a5, 0x2021, 0x0169, 0x2404,
8144 0xa084, 0x000f, 0xa086, 0x0004, 0x11b0, 0x68c7, 0x0000, 0x68cb,
8145 0x0008, 0x00e6, 0x00f6, 0x2079, 0x0020, 0x2071, 0xb01e, 0x6814,
8146 0xa084, 0x0184, 0xa085, 0x0012, 0x6816, 0x7803, 0x0008, 0x7003,
8147 0x0000, 0x00fe, 0x00ee, 0x200b, 0x0000, 0x004e, 0xa39d, 0x0000,
8148 0x1120, 0x2009, 0x0049, 0x080c, 0x80a7, 0x20a9, 0x03e8, 0x6824,
8149 0xd094, 0x0158, 0x6827, 0x0004, 0x7804, 0xa084, 0x4000, 0x01a0,
8150 0x7803, 0x1000, 0x7803, 0x0000, 0x0078, 0xd08c, 0x0118, 0x6827,
8151 0x0002, 0x0010, 0x1f04, 0x7ab7, 0x7804, 0xa084, 0x1000, 0x0120,
8152 0x7803, 0x0100, 0x7803, 0x0000, 0x6824, 0x000e, 0x001e, 0x002e,
8153 0x00ce, 0x00de, 0x00ee, 0x00fe, 0x015e, 0x012e, 0x0005, 0x00d6,
8154 0x0126, 0x2091, 0x8000, 0x2069, 0xafc7, 0x6a06, 0x012e, 0x00de,
8155 0x0005, 0x00d6, 0x0126, 0x2091, 0x8000, 0x2069, 0xafc7, 0x6a32,
8156 0x012e, 0x00de, 0x0005, 0x00f6, 0x00e6, 0x00c6, 0x0066, 0x0006,
8157 0x0126, 0x2071, 0xafc7, 0x7614, 0x2660, 0x2678, 0x2091, 0x8000,
8158 0x8cff, 0x0538, 0x601c, 0xa206, 0x1500, 0x7014, 0xac36, 0x1110,
8159 0x660c, 0x7616, 0x7010, 0xac36, 0x1140, 0x2c00, 0xaf36, 0x0118,
8160 0x2f00, 0x7012, 0x0010, 0x7013, 0x0000, 0x660c, 0x0066, 0x2c00,
8161 0xaf06, 0x0110, 0x7e0e, 0x0008, 0x2678, 0x600f, 0x0000, 0x080c,
8162 0x974e, 0x080c, 0x7b88, 0x00ce, 0x08d8, 0x2c78, 0x600c, 0x2060,
8163 0x08b8, 0x012e, 0x000e, 0x006e, 0x00ce, 0x00ee, 0x00fe, 0x0005,
8164 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x73cf, 0x7810, 0x20a2,
8165 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x1000, 0x0804,
8166 0x7b80, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x73cf, 0x7810,
8167 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x4000,
8168 0x0478, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x73cf, 0x7810,
8169 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x2000,
8170 0x00f8, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x73cf, 0x7810,
8171 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x0400,
8172 0x0078, 0x0156, 0x0146, 0x20a1, 0x020b, 0x080c, 0x73cf, 0x7810,
8173 0x20a2, 0xa006, 0x20a2, 0x20a2, 0x20a2, 0x20a2, 0x20a3, 0x0200,
8174 0x0089, 0x60c3, 0x0020, 0x080c, 0x7821, 0x014e, 0x015e, 0x0005,
8175 0x00e6, 0x2071, 0xafc7, 0x7020, 0xa005, 0x0110, 0x8001, 0x7022,
8176 0x00ee, 0x0005, 0x20a9, 0x0008, 0x20a2, 0x1f04, 0x7b94, 0x20a2,
8177 0x20a2, 0x0005, 0x00f6, 0x00e6, 0x00d6, 0x00c6, 0x0076, 0x0066,
8178 0x0006, 0x0126, 0x2091, 0x8000, 0x2071, 0xafc7, 0x7614, 0x2660,
8179 0x2678, 0x2039, 0x0001, 0x87ff, 0x0904, 0x7c24, 0x8cff, 0x0904,
8180 0x7c24, 0x601c, 0xa086, 0x0006, 0x1904, 0x7c1f, 0x88ff, 0x0138,
8181 0x2800, 0xac06, 0x1904, 0x7c1f, 0x2039, 0x0000, 0x0050, 0x6018,
8182 0xa206, 0x1904, 0x7c1f, 0x85ff, 0x0120, 0x6050, 0xa106, 0x1904,
8183 0x7c1f, 0x7024, 0xac06, 0x1538, 0x2069, 0x0100, 0x68c0, 0xa005,
8184 0x01f0, 0x080c, 0x6581, 0x6817, 0x0008, 0x68c3, 0x0000, 0x080c,
8185 0x7ca8, 0x7027, 0x0000, 0x0036, 0x2069, 0x0140, 0x6b04, 0xa384,
8186 0x1000, 0x0120, 0x6803, 0x0100, 0x6803, 0x0000, 0x2069, 0x0100,
8187 0x6824, 0xd084, 0x0110, 0x6827, 0x0001, 0x003e, 0x0020, 0x6003,
8188 0x0009, 0x630a, 0x0460, 0x7014, 0xac36, 0x1110, 0x660c, 0x7616,
8189 0x7010, 0xac36, 0x1140, 0x2c00, 0xaf36, 0x0118, 0x2f00, 0x7012,
8190 0x0010, 0x7013, 0x0000, 0x660c, 0x0066, 0x2c00, 0xaf06, 0x0110,
8191 0x7e0e, 0x0008, 0x2678, 0x89ff, 0x1158, 0x600f, 0x0000, 0x6010,
8192 0x2068, 0x080c, 0x9596, 0x0110, 0x080c, 0xa91f, 0x080c, 0x974e,
8193 0x080c, 0x7b88, 0x88ff, 0x1190, 0x00ce, 0x0804, 0x7bab, 0x2c78,
8194 0x600c, 0x2060, 0x0804, 0x7bab, 0xa006, 0x012e, 0x000e, 0x006e,
8195 0x007e, 0x00ce, 0x00de, 0x00ee, 0x00fe, 0x0005, 0x6017, 0x0000,
8196 0x00ce, 0xa8c5, 0x0001, 0x0c88, 0x00f6, 0x00e6, 0x00d6, 0x00c6,
8197 0x0066, 0x0026, 0x0006, 0x0126, 0x2091, 0x8000, 0x2071, 0xafc7,
8198 0x7638, 0x2660, 0x2678, 0x8cff, 0x0904, 0x7c98, 0x601c, 0xa086,
8199 0x0006, 0x1904, 0x7c93, 0x87ff, 0x0128, 0x2700, 0xac06, 0x1904,
8200 0x7c93, 0x0040, 0x6018, 0xa206, 0x15f0, 0x85ff, 0x0118, 0x6050,
8201 0xa106, 0x15c8, 0x703c, 0xac06, 0x1170, 0x0036, 0x2019, 0x0001,
8202 0x080c, 0x7a64, 0x7033, 0x0000, 0x703f, 0x0000, 0x7043, 0x0000,
8203 0x7047, 0x0000, 0x003e, 0x7038, 0xac36, 0x1110, 0x660c, 0x763a,
8204 0x7034, 0xac36, 0x1140, 0x2c00, 0xaf36, 0x0118, 0x2f00, 0x7036,
8205 0x0010, 0x7037, 0x0000, 0x660c, 0x0066, 0x2c00, 0xaf06, 0x0110,
8206 0x7e0e, 0x0008, 0x2678, 0x600f, 0x0000, 0x6010, 0x2068, 0x080c,
8207 0x9596, 0x0110, 0x080c, 0xa91f, 0x080c, 0x974e, 0x87ff, 0x1190,
8208 0x00ce, 0x0804, 0x7c43, 0x2c78, 0x600c, 0x2060, 0x0804, 0x7c43,
8209 0xa006, 0x012e, 0x000e, 0x002e, 0x006e, 0x00ce, 0x00de, 0x00ee,
8210 0x00fe, 0x0005, 0x6017, 0x0000, 0x00ce, 0xa7bd, 0x0001, 0x0c88,
8211 0x00e6, 0x2071, 0xafc7, 0x2001, 0xad00, 0x2004, 0xa086, 0x0002,
8212 0x1118, 0x7007, 0x0005, 0x0010, 0x7007, 0x0000, 0x00ee, 0x0005,
8213 0x00f6, 0x00e6, 0x00c6, 0x0066, 0x0026, 0x0006, 0x0126, 0x2091,
8214 0x8000, 0x2071, 0xafc7, 0x2c10, 0x7638, 0x2660, 0x2678, 0x8cff,
8215 0x0518, 0x2200, 0xac06, 0x11e0, 0x7038, 0xac36, 0x1110, 0x660c,
8216 0x763a, 0x7034, 0xac36, 0x1140, 0x2c00, 0xaf36, 0x0118, 0x2f00,
8217 0x7036, 0x0010, 0x7037, 0x0000, 0x660c, 0x2c00, 0xaf06, 0x0110,
8218 0x7e0e, 0x0008, 0x2678, 0x600f, 0x0000, 0xa085, 0x0001, 0x0020,
8219 0x2c78, 0x600c, 0x2060, 0x08d8, 0x012e, 0x000e, 0x002e, 0x006e,
8220 0x00ce, 0x00ee, 0x00fe, 0x0005, 0x00f6, 0x00e6, 0x00d6, 0x00c6,
8221 0x0066, 0x0006, 0x0126, 0x2091, 0x8000, 0x2071, 0xafc7, 0x760c,
8222 0x2660, 0x2678, 0x8cff, 0x0904, 0x7d7e, 0x6018, 0xa080, 0x0028,
8223 0x2004, 0xa206, 0x1904, 0x7d79, 0x7024, 0xac06, 0x1508, 0x2069,
8224 0x0100, 0x68c0, 0xa005, 0x0904, 0x7d55, 0x080c, 0x7834, 0x68c3,
8225 0x0000, 0x080c, 0x7ca8, 0x7027, 0x0000, 0x0036, 0x2069, 0x0140,
8226 0x6b04, 0xa384, 0x1000, 0x0120, 0x6803, 0x0100, 0x6803, 0x0000,
8227 0x2069, 0x0100, 0x6824, 0xd084, 0x0110, 0x6827, 0x0001, 0x003e,
8228 0x700c, 0xac36, 0x1110, 0x660c, 0x760e, 0x7008, 0xac36, 0x1140,
8229 0x2c00, 0xaf36, 0x0118, 0x2f00, 0x700a, 0x0010, 0x700b, 0x0000,
8230 0x660c, 0x0066, 0x2c00, 0xaf06, 0x0110, 0x7e0e, 0x0008, 0x2678,
8231 0x600f, 0x0000, 0x080c, 0x9778, 0x1158, 0x080c, 0x2aff, 0x080c,
8232 0x9789, 0x11f0, 0x080c, 0x85f3, 0x00d8, 0x080c, 0x7ca8, 0x08c0,
8233 0x080c, 0x9789, 0x1118, 0x080c, 0x85f3, 0x0090, 0x6010, 0x2068,
8234 0x080c, 0x9596, 0x0168, 0x601c, 0xa086, 0x0003, 0x11f8, 0x6837,
8235 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c, 0x510c, 0x080c, 0x9742,
8236 0x080c, 0x994e, 0x080c, 0x974e, 0x080c, 0x7b88, 0x00ce, 0x0804,
8237 0x7d02, 0x2c78, 0x600c, 0x2060, 0x0804, 0x7d02, 0x012e, 0x000e,
8238 0x006e, 0x00ce, 0x00de, 0x00ee, 0x00fe, 0x0005, 0x601c, 0xa086,
8239 0x0006, 0x1d30, 0x080c, 0xa91f, 0x0c18, 0x0036, 0x0156, 0x0136,
8240 0x0146, 0x3908, 0xa006, 0xa190, 0x0020, 0x221c, 0xa39e, 0x28f9,
8241 0x1118, 0x8210, 0x8000, 0x0cc8, 0xa005, 0x0138, 0x20a9, 0x0020,
8242 0x2198, 0xa110, 0x22a0, 0x22c8, 0x53a3, 0x014e, 0x013e, 0x015e,
8243 0x003e, 0x0005, 0x00d6, 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3,
8244 0x0200, 0x20a3, 0x0014, 0x60c3, 0x0014, 0x20a3, 0x0000, 0x20a3,
8245 0x0000, 0x2099, 0xafa6, 0x20a9, 0x0004, 0x53a6, 0x20a3, 0x0004,
8246 0x20a3, 0x7878, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x080c, 0x7821,
8247 0x00de, 0x0005, 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3, 0x0214,
8248 0x20a3, 0x0018, 0x20a3, 0x0800, 0x7810, 0xa084, 0xff00, 0x20a2,
8249 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x20a3, 0x0000,
8250 0x7810, 0xa084, 0x00ff, 0x20a2, 0x7828, 0x20a2, 0x20a3, 0x0000,
8251 0x20a3, 0x0000, 0x60c3, 0x0018, 0x080c, 0x7821, 0x0005, 0x00d6,
8252 0x0016, 0x2f68, 0x2009, 0x0035, 0x080c, 0x9a34, 0x1904, 0x7e5d,
8253 0x20a1, 0x020b, 0x080c, 0x710e, 0x20a3, 0x1300, 0x20a3, 0x0000,
8254 0x7828, 0x2068, 0x681c, 0xa086, 0x0003, 0x0580, 0x7818, 0xa080,
8255 0x0028, 0x2014, 0x2001, 0xad34, 0x2004, 0xd0ac, 0x11d0, 0xa286,
8256 0x007e, 0x1128, 0x20a3, 0x00ff, 0x20a3, 0xfffe, 0x04b8, 0xa286,
8257 0x007f, 0x1128, 0x20a3, 0x00ff, 0x20a3, 0xfffd, 0x0478, 0xd2bc,
8258 0x0180, 0xa286, 0x0080, 0x1128, 0x20a3, 0x00ff, 0x20a3, 0xfffc,
8259 0x0428, 0xa2e8, 0xae34, 0x2d6c, 0x6810, 0x20a2, 0x6814, 0x20a2,
8260 0x00e8, 0x20a3, 0x0000, 0x6098, 0x20a2, 0x00c0, 0x2001, 0xad34,
8261 0x2004, 0xd0ac, 0x1138, 0x7818, 0xa080, 0x0028, 0x2004, 0xa082,
8262 0x007e, 0x0240, 0x00d6, 0x2069, 0xad1b, 0x2da6, 0x8d68, 0x2da6,
8263 0x00de, 0x0020, 0x20a3, 0x0000, 0x6034, 0x20a2, 0x7834, 0x20a2,
8264 0x7838, 0x20a2, 0x20a3, 0x0000, 0x20a3, 0x0000, 0x60c3, 0x000c,
8265 0x080c, 0x7821, 0x001e, 0x00de, 0x0005, 0x7817, 0x0001, 0x7803,
8266 0x0006, 0x001e, 0x00de, 0x0005, 0x00d6, 0x0026, 0x7928, 0x2168,
8267 0x691c, 0xa186, 0x0006, 0x01c0, 0xa186, 0x0003, 0x0904, 0x7ed3,
8268 0xa186, 0x0005, 0x0904, 0x7ebc, 0xa186, 0x0004, 0x05b8, 0xa186,
8269 0x0008, 0x0904, 0x7ec4, 0x7807, 0x0037, 0x7813, 0x1700, 0x080c,
8270 0x7f3b, 0x002e, 0x00de, 0x0005, 0x080c, 0x7ef7, 0x2009, 0x4000,
8271 0x6800, 0x0002, 0x7e9d, 0x7ea8, 0x7e9f, 0x7ea8, 0x7ea4, 0x7e9d,
8272 0x7e9d, 0x7ea8, 0x7ea8, 0x7ea8, 0x7ea8, 0x7e9d, 0x7e9d, 0x7e9d,
8273 0x7e9d, 0x7e9d, 0x7ea8, 0x7e9d, 0x7ea8, 0x080c, 0x14f6, 0x6820,
8274 0xd0e4, 0x0110, 0xd0cc, 0x0110, 0xa00e, 0x0010, 0x2009, 0x2000,
8275 0x6828, 0x20a2, 0x682c, 0x20a2, 0x0804, 0x7eed, 0x080c, 0x7ef7,
8276 0x20a3, 0x0000, 0x20a3, 0x0000, 0x2009, 0x4000, 0x6a00, 0xa286,
8277 0x0002, 0x1108, 0xa00e, 0x0488, 0x04d1, 0x20a3, 0x0000, 0x20a3,
8278 0x0000, 0x2009, 0x4000, 0x0448, 0x0491, 0x20a3, 0x0000, 0x20a3,
8279 0x0000, 0x2009, 0x4000, 0xa286, 0x0005, 0x0118, 0xa286, 0x0002,
8280 0x1108, 0xa00e, 0x00d0, 0x0419, 0x6810, 0x2068, 0x697c, 0x6810,
8281 0xa112, 0x6980, 0x6814, 0xa103, 0x20a2, 0x22a2, 0x7928, 0xa180,
8282 0x0000, 0x2004, 0xa08e, 0x0002, 0x0130, 0xa08e, 0x0004, 0x0118,
8283 0x2009, 0x4000, 0x0010, 0x2009, 0x0000, 0x21a2, 0x20a3, 0x0000,
8284 0x60c3, 0x0018, 0x080c, 0x7821, 0x002e, 0x00de, 0x0005, 0x0036,
8285 0x0046, 0x0056, 0x0066, 0x20a1, 0x020b, 0x080c, 0x71aa, 0xa006,
8286 0x20a3, 0x0200, 0x20a2, 0x7934, 0x21a2, 0x7938, 0x21a2, 0x7818,
8287 0xa080, 0x0028, 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1118,
8288 0xa092, 0x007e, 0x0268, 0x00d6, 0x2069, 0xad1b, 0x2d2c, 0x8d68,
8289 0x2d34, 0xa0e8, 0xae34, 0x2d6c, 0x6b10, 0x6c14, 0x00de, 0x0030,
8290 0x2019, 0x0000, 0x6498, 0x2029, 0x0000, 0x6634, 0x7828, 0xa080,
8291 0x0007, 0x2004, 0xa086, 0x0003, 0x1128, 0x25a2, 0x26a2, 0x23a2,
8292 0x24a2, 0x0020, 0x23a2, 0x24a2, 0x25a2, 0x26a2, 0x006e, 0x005e,
8293 0x004e, 0x003e, 0x0005, 0x20a1, 0x020b, 0x080c, 0x71aa, 0x20a3,
8294 0x0100, 0x20a3, 0x0000, 0x20a3, 0x0009, 0x7810, 0x20a2, 0x60c3,
8295 0x0008, 0x080c, 0x7821, 0x0005, 0x20a1, 0x020b, 0x080c, 0x7106,
8296 0x20a3, 0x1400, 0x20a3, 0x0000, 0x7834, 0x20a2, 0x7838, 0x20a2,
8297 0x7828, 0x20a2, 0x782c, 0x20a2, 0x7830, 0xa084, 0x00ff, 0x8007,
8298 0x20a2, 0x20a3, 0x0000, 0x60c3, 0x0010, 0x080c, 0x7821, 0x0005,
8299 0x20a1, 0x020b, 0x080c, 0x71a2, 0x20a3, 0x0100, 0x20a3, 0x0000,
8300 0x7828, 0x20a2, 0x7810, 0x20a2, 0x60c3, 0x0008, 0x080c, 0x7821,
8301 0x0005, 0x0146, 0x20a1, 0x020b, 0x0031, 0x60c3, 0x0000, 0x080c,
8302 0x7821, 0x014e, 0x0005, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7818,
8303 0xa080, 0x0028, 0x2004, 0x2011, 0xad34, 0x2214, 0xd2ac, 0x1110,
8304 0xd0bc, 0x0188, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810, 0xa085,
8305 0x0300, 0x20a2, 0x6814, 0x20a2, 0x2069, 0xad1b, 0x2da6, 0x8d68,
8306 0x2da6, 0x00de, 0x0078, 0x00d6, 0xa0e8, 0xae34, 0x2d6c, 0x6810,
8307 0xa085, 0x0300, 0x20a2, 0x6814, 0x20a2, 0x00de, 0x20a3, 0x0000,
8308 0x6234, 0x22a2, 0x20a3, 0x0819, 0x20a3, 0x0000, 0x080c, 0x7810,
8309 0x22a2, 0x20a3, 0x0000, 0x2fa2, 0x7a08, 0x22a2, 0x20a3, 0x0000,
8310 0x20a3, 0x0000, 0x0005, 0x20a1, 0x020b, 0x0079, 0x7910, 0x21a2,
8311 0x20a3, 0x0000, 0x60c3, 0x0000, 0x20e1, 0x9080, 0x60a7, 0x9575,
8312 0x080c, 0x782b, 0x080c, 0x6578, 0x0005, 0x0156, 0x0136, 0x0036,
8313 0x00d6, 0x00e6, 0x20e1, 0x9080, 0x20e1, 0x4000, 0x7854, 0x2068,
8314 0xadf0, 0x000f, 0x7210, 0xa296, 0x00c0, 0xa294, 0xfffd, 0x7212,
8315 0x7214, 0xa294, 0x0300, 0x7216, 0x7100, 0xa194, 0x00ff, 0x7308,
8316 0xa384, 0x00ff, 0xa08d, 0xc200, 0x7102, 0xa384, 0xff00, 0xa215,
8317 0x720a, 0x7004, 0x720c, 0x700e, 0x7206, 0x20a9, 0x000a, 0x2e98,
8318 0x53a6, 0x60a3, 0x0035, 0x6a38, 0xa294, 0x7000, 0xa286, 0x3000,
8319 0x0110, 0x60a3, 0x0037, 0x00ee, 0x00de, 0x003e, 0x013e, 0x015e,
8320 0x0005, 0x2009, 0x0092, 0x0010, 0x2009, 0x0096, 0x60ab, 0x0036,
8321 0x6116, 0x0005, 0x2061, 0xb400, 0x2a70, 0x7064, 0x7046, 0x704b,
8322 0xb400, 0x0005, 0x00e6, 0x0126, 0x2071, 0xad00, 0x2091, 0x8000,
8323 0x7544, 0xa582, 0x0010, 0x0608, 0x7048, 0x2060, 0x6000, 0xa086,
8324 0x0000, 0x0148, 0xace0, 0x0018, 0x7058, 0xac02, 0x1208, 0x0cb0,
8325 0x2061, 0xb400, 0x0c98, 0x6003, 0x0008, 0x8529, 0x7546, 0xaca8,
8326 0x0018, 0x7058, 0xa502, 0x1230, 0x754a, 0xa085, 0x0001, 0x012e,
8327 0x00ee, 0x0005, 0x704b, 0xb400, 0x0cc0, 0xa006, 0x0cc0, 0x00e6,
8328 0x2071, 0xad00, 0x7544, 0xa582, 0x0010, 0x0600, 0x7048, 0x2060,
8329 0x6000, 0xa086, 0x0000, 0x0148, 0xace0, 0x0018, 0x7058, 0xac02,
8330 0x1208, 0x0cb0, 0x2061, 0xb400, 0x0c98, 0x6003, 0x0008, 0x8529,
8331 0x7546, 0xaca8, 0x0018, 0x7058, 0xa502, 0x1228, 0x754a, 0xa085,
8332 0x0001, 0x00ee, 0x0005, 0x704b, 0xb400, 0x0cc8, 0xa006, 0x0cc8,
8333 0xac82, 0xb400, 0x0a0c, 0x14f6, 0x2001, 0xad16, 0x2004, 0xac02,
8334 0x1a0c, 0x14f6, 0xa006, 0x6006, 0x600a, 0x600e, 0x6012, 0x6016,
8335 0x601a, 0x601f, 0x0000, 0x6003, 0x0000, 0x6052, 0x6056, 0x6022,
8336 0x6026, 0x602a, 0x602e, 0x6032, 0x6036, 0x603a, 0x603e, 0x2061,
8337 0xad00, 0x6044, 0x8000, 0x6046, 0xa086, 0x0001, 0x0108, 0x0005,
8338 0x0126, 0x2091, 0x8000, 0x080c, 0x6c50, 0x012e, 0x0cc0, 0x601c,
8339 0xa084, 0x000f, 0x0002, 0x80b6, 0x80c5, 0x80e0, 0x80fb, 0x9a61,
8340 0x9a7c, 0x9a97, 0x80b6, 0x80c5, 0x80b6, 0x8116, 0xa186, 0x0013,
8341 0x1128, 0x080c, 0x6b73, 0x080c, 0x6c50, 0x0005, 0xa18e, 0x0047,
8342 0x1118, 0xa016, 0x080c, 0x1824, 0x0005, 0x0066, 0x6000, 0xa0b2,
8343 0x0010, 0x1a0c, 0x14f6, 0x0013, 0x006e, 0x0005, 0x80de, 0x8478,
8344 0x862d, 0x80de, 0x86a2, 0x81cf, 0x80de, 0x80de, 0x840a, 0x8a91,
8345 0x80de, 0x80de, 0x80de, 0x80de, 0x80de, 0x80de, 0x080c, 0x14f6,
8346 0x0066, 0x6000, 0xa0b2, 0x0010, 0x1a0c, 0x14f6, 0x0013, 0x006e,
8347 0x0005, 0x80f9, 0x909a, 0x80f9, 0x80f9, 0x80f9, 0x80f9, 0x80f9,
8348 0x80f9, 0x9045, 0x9200, 0x80f9, 0x90c7, 0x913e, 0x90c7, 0x913e,
8349 0x80f9, 0x080c, 0x14f6, 0x0066, 0x6000, 0xa0b2, 0x0010, 0x1a0c,
8350 0x14f6, 0x0013, 0x006e, 0x0005, 0x8114, 0x8ad2, 0x8b98, 0x8cb8,
8351 0x8e12, 0x8114, 0x8114, 0x8114, 0x8aac, 0x8ff5, 0x8ff8, 0x8114,
8352 0x8114, 0x8114, 0x8114, 0x9022, 0x080c, 0x14f6, 0x0066, 0x6000,
8353 0xa0b2, 0x0010, 0x1a0c, 0x14f6, 0x0013, 0x006e, 0x0005, 0x812f,
8354 0x812f, 0x812f, 0x8152, 0x81a5, 0x812f, 0x812f, 0x812f, 0x8131,
8355 0x812f, 0x812f, 0x812f, 0x812f, 0x812f, 0x812f, 0x812f, 0x080c,
8356 0x14f6, 0xa186, 0x0003, 0x190c, 0x14f6, 0x00d6, 0x6003, 0x0003,
8357 0x6106, 0x6010, 0x2068, 0x684f, 0x0040, 0x687c, 0x680a, 0x6880,
8358 0x680e, 0x6813, 0x0000, 0x6817, 0x0000, 0x00de, 0x2c10, 0x080c,
8359 0x1e6e, 0x080c, 0x680b, 0x0126, 0x2091, 0x8000, 0x080c, 0x6d0d,
8360 0x012e, 0x0005, 0xa182, 0x0047, 0x0002, 0x815e, 0x815e, 0x8160,
8361 0x817f, 0x815e, 0x815e, 0x815e, 0x815e, 0x8191, 0x080c, 0x14f6,
8362 0x00d6, 0x0016, 0x080c, 0x6c05, 0x080c, 0x6d0d, 0x6003, 0x0004,
8363 0x6110, 0x2168, 0x6854, 0x8003, 0x800b, 0x810b, 0xa108, 0x6116,
8364 0x684f, 0x0020, 0x685c, 0x685a, 0x6874, 0x687e, 0x6878, 0x6882,
8365 0x6897, 0x0000, 0x689b, 0x0000, 0x001e, 0x00de, 0x0005, 0x080c,
8366 0x6c05, 0x00d6, 0x6110, 0x2168, 0x080c, 0x9596, 0x0120, 0x684b,
8367 0x0006, 0x080c, 0x510c, 0x00de, 0x080c, 0x8078, 0x080c, 0x6d0d,
8368 0x0005, 0x080c, 0x6c05, 0x080c, 0x2ad9, 0x00d6, 0x6110, 0x2168,
8369 0x080c, 0x9596, 0x0120, 0x684b, 0x0029, 0x080c, 0x510c, 0x00de,
8370 0x080c, 0x8078, 0x080c, 0x6d0d, 0x0005, 0xa182, 0x0047, 0x0002,
8371 0x81b3, 0x81c2, 0x81b1, 0x81b1, 0x81b1, 0x81b1, 0x81b1, 0x81b1,
8372 0x81b1, 0x080c, 0x14f6, 0x00d6, 0x6010, 0x2068, 0x684c, 0xc0f4,
8373 0x684e, 0x00de, 0x20e1, 0x0005, 0x3d18, 0x3e20, 0x2c10, 0x080c,
8374 0x1824, 0x0005, 0x00d6, 0x6110, 0x2168, 0x684b, 0x0000, 0x6853,
8375 0x0000, 0x080c, 0x510c, 0x00de, 0x080c, 0x8078, 0x0005, 0xa1b6,
8376 0x0015, 0x1118, 0x080c, 0x8078, 0x0030, 0xa1b6, 0x0016, 0x190c,
8377 0x14f6, 0x080c, 0x8078, 0x0005, 0x20a9, 0x000e, 0x2e98, 0x6010,
8378 0x20a0, 0x53a3, 0x20a9, 0x0006, 0x3310, 0x3420, 0x9398, 0x94a0,
8379 0x3318, 0x3428, 0x222e, 0x2326, 0xa290, 0x0002, 0xa5a8, 0x0002,
8380 0xa398, 0x0002, 0xa4a0, 0x0002, 0x1f04, 0x81ea, 0x00e6, 0x080c,
8381 0x9596, 0x0130, 0x6010, 0x2070, 0x7007, 0x0000, 0x7037, 0x0103,
8382 0x00ee, 0x080c, 0x8078, 0x0005, 0x00d6, 0x0036, 0x7330, 0xa386,
8383 0x0200, 0x1130, 0x6018, 0x2068, 0x6813, 0x00ff, 0x6817, 0xfffd,
8384 0x6010, 0xa005, 0x0130, 0x2068, 0x6807, 0x0000, 0x6837, 0x0103,
8385 0x6b32, 0x080c, 0x8078, 0x003e, 0x00de, 0x0005, 0x0016, 0x20a9,
8386 0x002a, 0xae80, 0x000c, 0x2098, 0x6010, 0xa080, 0x0002, 0x20a0,
8387 0x53a3, 0x20a9, 0x002a, 0x6010, 0xa080, 0x0001, 0x2004, 0xa080,
8388 0x0002, 0x20a0, 0x53a3, 0x00e6, 0x6010, 0x2004, 0x2070, 0x7037,
8389 0x0103, 0x00ee, 0x080c, 0x8078, 0x001e, 0x0005, 0x0016, 0x2009,
8390 0x0000, 0x7030, 0xa086, 0x0100, 0x0140, 0x7038, 0xa084, 0x00ff,
8391 0x808e, 0x703c, 0xa084, 0x00ff, 0x8086, 0xa080, 0x0004, 0xa108,
8392 0x21a8, 0xae80, 0x000c, 0x2098, 0x6010, 0xa080, 0x0002, 0x20a0,
8393 0x080c, 0x48be, 0x00e6, 0x080c, 0x9596, 0x0140, 0x6010, 0x2070,
8394 0x7007, 0x0000, 0x7034, 0x70b2, 0x7037, 0x0103, 0x00ee, 0x080c,
8395 0x8078, 0x001e, 0x0005, 0x00e6, 0x00d6, 0x603f, 0x0000, 0x2c68,
8396 0x0016, 0x2009, 0x0035, 0x080c, 0x9a34, 0x001e, 0x1168, 0x0026,
8397 0x6228, 0x2268, 0x002e, 0x2071, 0xb28c, 0x6b1c, 0xa386, 0x0003,
8398 0x0130, 0xa386, 0x0006, 0x0128, 0x080c, 0x8078, 0x0020, 0x0031,
8399 0x0010, 0x080c, 0x8323, 0x00de, 0x00ee, 0x0005, 0x00f6, 0x6810,
8400 0x2078, 0xa186, 0x0015, 0x0904, 0x830c, 0xa18e, 0x0016, 0x1904,
8401 0x8321, 0x700c, 0xa084, 0xff00, 0xa086, 0x1700, 0x1904, 0x82eb,
8402 0x8fff, 0x0904, 0x831f, 0x6808, 0xa086, 0xffff, 0x1904, 0x830e,
8403 0x784c, 0xa084, 0x0060, 0xa086, 0x0020, 0x1150, 0x797c, 0x7810,
8404 0xa106, 0x1904, 0x830e, 0x7980, 0x7814, 0xa106, 0x1904, 0x830e,
8405 0x080c, 0x9742, 0x6858, 0x7852, 0x784c, 0xc0dc, 0xc0f4, 0xc0d4,
8406 0x784e, 0x0026, 0xa00e, 0x6a14, 0x2001, 0x000a, 0x080c, 0x6665,
8407 0x7854, 0xa20a, 0x0208, 0x8011, 0x7a56, 0x82ff, 0x002e, 0x1138,
8408 0x00c6, 0x2d60, 0x080c, 0x9374, 0x00ce, 0x0804, 0x831f, 0x00c6,
8409 0x00d6, 0x2f68, 0x6838, 0xd0fc, 0x1118, 0x080c, 0x4993, 0x0010,
8410 0x080c, 0x4b7c, 0x00de, 0x00ce, 0x1548, 0x00c6, 0x2d60, 0x080c,
8411 0x8078, 0x00ce, 0x04a0, 0x7008, 0xa086, 0x000b, 0x11a0, 0x6018,
8412 0x200c, 0xc1bc, 0x2102, 0x00c6, 0x2d60, 0x7853, 0x0003, 0x6007,
8413 0x0085, 0x6003, 0x000b, 0x601f, 0x0002, 0x080c, 0x67a8, 0x080c,
8414 0x6c50, 0x00ce, 0x00e0, 0x700c, 0xa086, 0x2a00, 0x1138, 0x2001,
8415 0xafa5, 0x2004, 0x683e, 0x0098, 0x0471, 0x0098, 0x8fff, 0x090c,
8416 0x14f6, 0x00c6, 0x00d6, 0x2d60, 0x2f68, 0x684b, 0x0003, 0x080c,
8417 0x926f, 0x080c, 0x9742, 0x080c, 0x974e, 0x00de, 0x00ce, 0x080c,
8418 0x8078, 0x00fe, 0x0005, 0xa186, 0x0015, 0x1128, 0x2001, 0xafa5,
8419 0x2004, 0x683e, 0x0068, 0xa18e, 0x0016, 0x1160, 0x00c6, 0x2d00,
8420 0x2060, 0x080c, 0xabb4, 0x080c, 0x6618, 0x080c, 0x8078, 0x00ce,
8421 0x080c, 0x8078, 0x0005, 0x0026, 0x0036, 0x0046, 0x7228, 0x7c80,
8422 0x7b7c, 0xd2f4, 0x0130, 0x2001, 0xafa5, 0x2004, 0x683e, 0x0804,
8423 0x839d, 0x00c6, 0x2d60, 0x080c, 0x928f, 0x00ce, 0x6804, 0xa086,
8424 0x0050, 0x1168, 0x00c6, 0x2d00, 0x2060, 0x6003, 0x0001, 0x6007,
8425 0x0050, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x00ce, 0x04f0, 0x6800,
8426 0xa086, 0x000f, 0x01c8, 0x8fff, 0x090c, 0x14f6, 0x6820, 0xd0dc,
8427 0x1198, 0x6800, 0xa086, 0x0004, 0x1198, 0x784c, 0xd0ac, 0x0180,
8428 0x784c, 0xc0dc, 0xc0f4, 0x784e, 0x7850, 0xc0f4, 0xc0fc, 0x7852,
8429 0x2001, 0x0001, 0x682e, 0x00e0, 0x2001, 0x0007, 0x682e, 0x00c0,
8430 0x784c, 0xd0b4, 0x1130, 0xd0ac, 0x0db8, 0x784c, 0xd0f4, 0x1da0,
8431 0x0c38, 0xd2ec, 0x1d88, 0x7024, 0xa306, 0x1118, 0x7020, 0xa406,
8432 0x0d58, 0x7020, 0x6836, 0x7024, 0x683a, 0x2001, 0x0005, 0x682e,
8433 0x080c, 0x9894, 0x080c, 0x6c50, 0x0010, 0x080c, 0x8078, 0x004e,
8434 0x003e, 0x002e, 0x0005, 0x00e6, 0x00d6, 0x0026, 0x6034, 0x2068,
8435 0x6a1c, 0xa286, 0x0007, 0x0904, 0x83ee, 0xa286, 0x0002, 0x05f0,
8436 0xa286, 0x0000, 0x05d8, 0x6808, 0x6338, 0xa306, 0x15b8, 0x2071,
8437 0xb28c, 0xa186, 0x0015, 0x0560, 0xa18e, 0x0016, 0x1190, 0x6030,
8438 0xa084, 0x00ff, 0xa086, 0x0001, 0x1160, 0x700c, 0xa086, 0x2a00,
8439 0x1140, 0x6034, 0xa080, 0x0008, 0x200c, 0xc1dd, 0xc1f5, 0x2102,
8440 0x00b8, 0x00c6, 0x6034, 0x2060, 0x6010, 0x2068, 0x080c, 0x9596,
8441 0x090c, 0x14f6, 0x6853, 0x0003, 0x6007, 0x0085, 0x6003, 0x000b,
8442 0x601f, 0x0002, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x00ce, 0x0030,
8443 0x6034, 0x2070, 0x2001, 0xafa5, 0x2004, 0x703e, 0x080c, 0x8078,
8444 0x002e, 0x00de, 0x00ee, 0x0005, 0x00d6, 0x20a9, 0x000e, 0x2e98,
8445 0x6010, 0x20a0, 0x53a3, 0xa1b6, 0x0015, 0x1148, 0x6018, 0x2068,
8446 0x7038, 0x680a, 0x703c, 0x680e, 0x6800, 0xc08d, 0x6802, 0x00de,
8447 0x0804, 0x81f6, 0x2100, 0xa1b2, 0x0080, 0x1a0c, 0x14f6, 0xa1b2,
8448 0x0040, 0x1a04, 0x846e, 0x0002, 0x8462, 0x8456, 0x8462, 0x8462,
8449 0x8462, 0x8462, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454,
8450 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454,
8451 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454,
8452 0x8454, 0x8454, 0x8454, 0x8462, 0x8454, 0x8462, 0x8462, 0x8454,
8453 0x8454, 0x8454, 0x8454, 0x8454, 0x8462, 0x8454, 0x8454, 0x8454,
8454 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8462, 0x8462,
8455 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454, 0x8454,
8456 0x8454, 0x8462, 0x8454, 0x8454, 0x080c, 0x14f6, 0x6003, 0x0001,
8457 0x6106, 0x080c, 0x67ee, 0x0126, 0x2091, 0x8000, 0x080c, 0x6c50,
8458 0x012e, 0x0005, 0x6003, 0x0001, 0x6106, 0x080c, 0x67ee, 0x0126,
8459 0x2091, 0x8000, 0x080c, 0x6c50, 0x012e, 0x0005, 0x2600, 0x0002,
8460 0x8462, 0x8476, 0x8476, 0x8462, 0x8462, 0x8476, 0x080c, 0x14f6,
8461 0x6004, 0xa0b2, 0x0080, 0x1a0c, 0x14f6, 0xa1b6, 0x0013, 0x0904,
8462 0x8518, 0xa1b6, 0x0027, 0x1904, 0x84de, 0x080c, 0x6b73, 0x6004,
8463 0x080c, 0x9778, 0x0188, 0x080c, 0x9789, 0x0904, 0x84d8, 0xa08e,
8464 0x0021, 0x0904, 0x84db, 0xa08e, 0x0022, 0x0904, 0x84d8, 0xa08e,
8465 0x003d, 0x0904, 0x84db, 0x04a8, 0x080c, 0x2aff, 0x2001, 0x0007,
8466 0x080c, 0x4c30, 0x6018, 0xa080, 0x0028, 0x200c, 0x080c, 0x85f3,
8467 0xa186, 0x007e, 0x1148, 0x2001, 0xad34, 0x2014, 0xc285, 0x080c,
8468 0x574f, 0x1108, 0xc2ad, 0x2202, 0x0016, 0x0026, 0x0036, 0x2110,
8469 0x2019, 0x0028, 0x080c, 0x68e7, 0x0076, 0x2039, 0x0000, 0x080c,
8470 0x681d, 0x00c6, 0x6018, 0xa065, 0x0110, 0x080c, 0x4ecf, 0x00ce,
8471 0x2c08, 0x080c, 0xa712, 0x007e, 0x003e, 0x002e, 0x001e, 0x080c,
8472 0x4c9f, 0x080c, 0x994e, 0x080c, 0x8078, 0x080c, 0x6c50, 0x0005,
8473 0x080c, 0x85f3, 0x0cb0, 0x080c, 0x8621, 0x0c98, 0xa186, 0x0014,
8474 0x1db0, 0x080c, 0x6b73, 0x080c, 0x2ad9, 0x080c, 0x9778, 0x1188,
8475 0x080c, 0x2aff, 0x6018, 0xa080, 0x0028, 0x200c, 0x080c, 0x85f3,
8476 0xa186, 0x007e, 0x1128, 0x2001, 0xad34, 0x200c, 0xc185, 0x2102,
8477 0x08c0, 0x080c, 0x9789, 0x1118, 0x080c, 0x85f3, 0x0890, 0x6004,
8478 0xa08e, 0x0032, 0x1158, 0x00e6, 0x00f6, 0x2071, 0xad81, 0x2079,
8479 0x0000, 0x080c, 0x2df1, 0x00fe, 0x00ee, 0x0818, 0x6004, 0xa08e,
8480 0x0021, 0x0d50, 0xa08e, 0x0022, 0x090c, 0x85f3, 0x0804, 0x84d1,
8481 0xa0b2, 0x0040, 0x1a04, 0x85db, 0x2008, 0x0002, 0x8560, 0x8561,
8482 0x8564, 0x8567, 0x856a, 0x856d, 0x855e, 0x855e, 0x855e, 0x855e,
8483 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e,
8484 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e,
8485 0x855e, 0x855e, 0x855e, 0x855e, 0x8570, 0x857f, 0x855e, 0x8581,
8486 0x857f, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x857f, 0x857f,
8487 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e, 0x855e,
8488 0x85bb, 0x857f, 0x855e, 0x857b, 0x855e, 0x855e, 0x855e, 0x857c,
8489 0x855e, 0x855e, 0x855e, 0x857f, 0x85b2, 0x855e, 0x080c, 0x14f6,
8490 0x00f0, 0x2001, 0x000b, 0x0460, 0x2001, 0x0003, 0x0448, 0x2001,
8491 0x0005, 0x0430, 0x2001, 0x0001, 0x0418, 0x2001, 0x0009, 0x0400,
8492 0x080c, 0x6b73, 0x6003, 0x0005, 0x2001, 0xafa5, 0x2004, 0x603e,
8493 0x080c, 0x6c50, 0x00a0, 0x0018, 0x0010, 0x080c, 0x4c30, 0x0804,
8494 0x85cc, 0x080c, 0x6b73, 0x2001, 0xafa3, 0x2004, 0x6016, 0x2001,
8495 0xafa5, 0x2004, 0x603e, 0x6003, 0x0004, 0x080c, 0x6c50, 0x0005,
8496 0x080c, 0x4c30, 0x080c, 0x6b73, 0x6003, 0x0002, 0x2001, 0xafa5,
8497 0x2004, 0x603e, 0x0036, 0x2019, 0xad5c, 0x2304, 0xa084, 0xff00,
8498 0x1120, 0x2001, 0xafa3, 0x201c, 0x0040, 0x8007, 0xa09a, 0x0004,
8499 0x0ec0, 0x8003, 0x801b, 0x831b, 0xa318, 0x6316, 0x003e, 0x080c,
8500 0x6c50, 0x08e8, 0x080c, 0x6b73, 0x080c, 0x994e, 0x080c, 0x8078,
8501 0x080c, 0x6c50, 0x08a0, 0x00e6, 0x00f6, 0x2071, 0xad81, 0x2079,
8502 0x0000, 0x080c, 0x2df1, 0x00fe, 0x00ee, 0x080c, 0x6b73, 0x080c,
8503 0x8078, 0x080c, 0x6c50, 0x0818, 0x080c, 0x6b73, 0x2001, 0xafa5,
8504 0x2004, 0x603e, 0x6003, 0x0002, 0x2001, 0xafa3, 0x2004, 0x6016,
8505 0x080c, 0x6c50, 0x0005, 0x2600, 0x2008, 0x0002, 0x85e6, 0x85e4,
8506 0x85e4, 0x85cc, 0x85cc, 0x85e4, 0x080c, 0x14f6, 0x080c, 0x6b73,
8507 0x00d6, 0x6010, 0x2068, 0x080c, 0x15f0, 0x00de, 0x080c, 0x8078,
8508 0x080c, 0x6c50, 0x0005, 0x00e6, 0x0026, 0x0016, 0x080c, 0x9596,
8509 0x0508, 0x6010, 0x2070, 0x7034, 0xa086, 0x0139, 0x1148, 0x2001,
8510 0x0030, 0x2009, 0x0000, 0x2011, 0x4005, 0x080c, 0x9a05, 0x0090,
8511 0x7038, 0xd0fc, 0x0178, 0x7007, 0x0000, 0x0016, 0x6004, 0xa08e,
8512 0x0021, 0x0160, 0xa08e, 0x003d, 0x0148, 0x001e, 0x7037, 0x0103,
8513 0x7033, 0x0100, 0x001e, 0x002e, 0x00ee, 0x0005, 0x001e, 0x0009,
8514 0x0cc8, 0x00e6, 0xacf0, 0x0004, 0x2e74, 0x7000, 0x2070, 0x7037,
8515 0x0103, 0x7023, 0x8001, 0x00ee, 0x0005, 0x00d6, 0x6618, 0x2668,
8516 0x6804, 0xa084, 0x00ff, 0x00de, 0xa0b2, 0x000c, 0x1a0c, 0x14f6,
8517 0x6604, 0xa6b6, 0x0043, 0x1120, 0x080c, 0x99c1, 0x0804, 0x8692,
8518 0x6604, 0xa6b6, 0x0033, 0x1120, 0x080c, 0x9971, 0x0804, 0x8692,
8519 0x6604, 0xa6b6, 0x0028, 0x1120, 0x080c, 0x97b9, 0x0804, 0x8692,
8520 0x6604, 0xa6b6, 0x0029, 0x1118, 0x080c, 0x97d0, 0x04d8, 0x6604,
8521 0xa6b6, 0x001f, 0x1118, 0x080c, 0x81dc, 0x04a0, 0x6604, 0xa6b6,
8522 0x0000, 0x1118, 0x080c, 0x83f4, 0x0468, 0x6604, 0xa6b6, 0x0022,
8523 0x1118, 0x080c, 0x8204, 0x0430, 0x6604, 0xa6b6, 0x0035, 0x1118,
8524 0x080c, 0x826b, 0x00f8, 0x6604, 0xa6b6, 0x0039, 0x1118, 0x080c,
8525 0x83a3, 0x00c0, 0x6604, 0xa6b6, 0x003d, 0x1118, 0x080c, 0x821e,
8526 0x0088, 0x6604, 0xa6b6, 0x0044, 0x1118, 0x080c, 0x823e, 0x0050,
8527 0xa1b6, 0x0015, 0x1110, 0x0053, 0x0028, 0xa1b6, 0x0016, 0x1118,
8528 0x0804, 0x883f, 0x0005, 0x080c, 0x80be, 0x0ce0, 0x86b9, 0x86bc,
8529 0x86b9, 0x86fe, 0x86b9, 0x87cc, 0x884d, 0x86b9, 0x86b9, 0x881b,
8530 0x86b9, 0x882f, 0xa1b6, 0x0048, 0x0140, 0x20e1, 0x0005, 0x3d18,
8531 0x3e20, 0x2c10, 0x080c, 0x1824, 0x0005, 0x00e6, 0xacf0, 0x0004,
8532 0x2e74, 0x7000, 0x2070, 0x7037, 0x0103, 0x00ee, 0x080c, 0x8078,
8533 0x0005, 0xe000, 0xe000, 0x0005, 0x00e6, 0x2071, 0xad00, 0x7080,
8534 0xa086, 0x0074, 0x1530, 0x080c, 0xa6e9, 0x11b0, 0x00d6, 0x6018,
8535 0x2068, 0x7030, 0xd08c, 0x0128, 0x6800, 0xd0bc, 0x0110, 0xc0c5,
8536 0x6802, 0x00d9, 0x00de, 0x2001, 0x0006, 0x080c, 0x4c30, 0x080c,
8537 0x2aff, 0x080c, 0x8078, 0x0078, 0x2001, 0x000a, 0x080c, 0x4c30,
8538 0x080c, 0x2aff, 0x6003, 0x0001, 0x6007, 0x0001, 0x080c, 0x67ee,
8539 0x0010, 0x080c, 0x87bd, 0x00ee, 0x0005, 0x6800, 0xd084, 0x0168,
8540 0x2001, 0x0000, 0x080c, 0x4c1e, 0x2069, 0xad51, 0x6804, 0xd0a4,
8541 0x0120, 0x2001, 0x0006, 0x080c, 0x4c5d, 0x0005, 0x00d6, 0x2011,
8542 0xad20, 0x2204, 0xa086, 0x0074, 0x1904, 0x87ba, 0x6018, 0x2068,
8543 0x6aa0, 0xa286, 0x007e, 0x1120, 0x080c, 0x894d, 0x0804, 0x875e,
8544 0x080c, 0x8943, 0x6018, 0x2068, 0xa080, 0x0028, 0x2014, 0xa286,
8545 0x0080, 0x11c0, 0x6813, 0x00ff, 0x6817, 0xfffc, 0x6010, 0xa005,
8546 0x0138, 0x2068, 0x6807, 0x0000, 0x6837, 0x0103, 0x6833, 0x0200,
8547 0x2001, 0x0006, 0x080c, 0x4c30, 0x080c, 0x2aff, 0x080c, 0x8078,
8548 0x0804, 0x87bb, 0x00e6, 0x2071, 0xad34, 0x2e04, 0xd09c, 0x0188,
8549 0x2071, 0xb280, 0x7108, 0x720c, 0xa18c, 0x00ff, 0x1118, 0xa284,
8550 0xff00, 0x0138, 0x6018, 0x2070, 0x70a0, 0xd0bc, 0x1110, 0x7112,
8551 0x7216, 0x00ee, 0x6010, 0xa005, 0x0128, 0x2068, 0x6838, 0xd0f4,
8552 0x0108, 0x0880, 0x2001, 0x0004, 0x080c, 0x4c30, 0x6003, 0x0001,
8553 0x6007, 0x0003, 0x080c, 0x67ee, 0x0804, 0x87bb, 0x685c, 0xd0e4,
8554 0x01d0, 0x080c, 0x9903, 0x080c, 0x574f, 0x0110, 0xd0dc, 0x1900,
8555 0x2011, 0xad34, 0x2204, 0xc0ad, 0x2012, 0x2001, 0xaf8e, 0x2004,
8556 0x00f6, 0x2079, 0x0100, 0x78e3, 0x0000, 0x080c, 0x26cb, 0x78e2,
8557 0x00fe, 0x0804, 0x8728, 0x080c, 0x9937, 0x2011, 0xad34, 0x2204,
8558 0xc0a5, 0x2012, 0x0006, 0x080c, 0xa801, 0x000e, 0x1904, 0x8728,
8559 0xc0b5, 0x2012, 0x2001, 0x0000, 0x080c, 0x4c1e, 0x00c6, 0x2009,
8560 0x00ef, 0x00f6, 0x2079, 0x0100, 0x79ea, 0x7932, 0x7936, 0x00fe,
8561 0x080c, 0x26a0, 0x00f6, 0x2079, 0xad00, 0x7972, 0x2100, 0x2009,
8562 0x0000, 0x080c, 0x2676, 0x794e, 0x00fe, 0x8108, 0x080c, 0x4c80,
8563 0x2c00, 0x00ce, 0x1904, 0x8728, 0x601a, 0x2001, 0x0002, 0x080c,
8564 0x4c30, 0x601f, 0x0001, 0x6003, 0x0001, 0x6007, 0x0002, 0x080c,
8565 0x67ee, 0x0008, 0x0011, 0x00de, 0x0005, 0x2001, 0xad00, 0x2004,
8566 0xa086, 0x0003, 0x0120, 0x2001, 0x0007, 0x080c, 0x4c30, 0x080c,
8567 0x2aff, 0x080c, 0x8078, 0x0005, 0x00e6, 0x0026, 0x0016, 0x2071,
8568 0xad00, 0x7080, 0xa086, 0x0014, 0x15f0, 0x7000, 0xa086, 0x0003,
8569 0x1128, 0x6010, 0xa005, 0x1110, 0x080c, 0x3cce, 0x00d6, 0x6018,
8570 0x2068, 0x080c, 0x4d72, 0x080c, 0x86ed, 0x00de, 0x080c, 0x89f7,
8571 0x1550, 0x00d6, 0x6018, 0x2068, 0x6890, 0x00de, 0xa005, 0x0518,
8572 0x2001, 0x0006, 0x080c, 0x4c30, 0x00e6, 0x6010, 0xa075, 0x01a8,
8573 0x7034, 0xa084, 0x00ff, 0xa086, 0x0039, 0x1148, 0x2001, 0x0000,
8574 0x2009, 0x0000, 0x2011, 0x4000, 0x080c, 0x9a05, 0x0030, 0x7007,
8575 0x0000, 0x7037, 0x0103, 0x7033, 0x0200, 0x00ee, 0x080c, 0x2aff,
8576 0x080c, 0x8078, 0x0020, 0x080c, 0x85f3, 0x080c, 0x87bd, 0x001e,
8577 0x002e, 0x00ee, 0x0005, 0x2011, 0xad20, 0x2204, 0xa086, 0x0014,
8578 0x1158, 0x2001, 0x0002, 0x080c, 0x4c30, 0x6003, 0x0001, 0x6007,
8579 0x0001, 0x080c, 0x67ee, 0x0010, 0x080c, 0x87bd, 0x0005, 0x2011,
8580 0xad20, 0x2204, 0xa086, 0x0004, 0x1138, 0x2001, 0x0007, 0x080c,
8581 0x4c30, 0x080c, 0x8078, 0x0010, 0x080c, 0x87bd, 0x0005, 0x000b,
8582 0x0005, 0x86b9, 0x8854, 0x86b9, 0x888a, 0x86b9, 0x88ff, 0x884d,
8583 0x86b9, 0x86b9, 0x8912, 0x86b9, 0x8922, 0x6604, 0xa6b6, 0x001e,
8584 0x1110, 0x080c, 0x8078, 0x0005, 0x00d6, 0x00c6, 0x080c, 0x8932,
8585 0x1178, 0x2001, 0x0000, 0x080c, 0x4c1e, 0x2001, 0x0002, 0x080c,
8586 0x4c30, 0x6003, 0x0001, 0x6007, 0x0002, 0x080c, 0x67ee, 0x00f8,
8587 0x2009, 0xb28e, 0x2104, 0xa086, 0x0009, 0x1160, 0x6018, 0x2068,
8588 0x6840, 0xa084, 0x00ff, 0xa005, 0x0180, 0x8001, 0x6842, 0x6017,
8589 0x000a, 0x0068, 0x2009, 0xb28f, 0x2104, 0xa084, 0xff00, 0xa086,
8590 0x1900, 0x1118, 0x080c, 0x8078, 0x0010, 0x080c, 0x87bd, 0x00ce,
8591 0x00de, 0x0005, 0x080c, 0x8940, 0x00d6, 0x2069, 0xaf9d, 0x2d04,
8592 0xa005, 0x0168, 0x6018, 0x2068, 0x68a0, 0xa086, 0x007e, 0x1138,
8593 0x2069, 0xad1c, 0x2d04, 0x8000, 0x206a, 0x00de, 0x0010, 0x00de,
8594 0x0078, 0x2001, 0x0000, 0x080c, 0x4c1e, 0x2001, 0x0002, 0x080c,
8595 0x4c30, 0x6003, 0x0001, 0x6007, 0x0002, 0x080c, 0x67ee, 0x0428,
8596 0x080c, 0x85f3, 0x2009, 0xb28e, 0x2134, 0xa6b4, 0x00ff, 0xa686,
8597 0x0005, 0x01e0, 0xa686, 0x000b, 0x01b0, 0x2009, 0xb28f, 0x2104,
8598 0xa084, 0xff00, 0x1118, 0xa686, 0x0009, 0x0180, 0xa086, 0x1900,
8599 0x1150, 0xa686, 0x0009, 0x0150, 0x2001, 0x0004, 0x080c, 0x4c30,
8600 0x080c, 0x8078, 0x0010, 0x080c, 0x87bd, 0x0005, 0x00d6, 0x6010,
8601 0x2068, 0x080c, 0x9596, 0x0128, 0x6838, 0xd0fc, 0x0110, 0x00de,
8602 0x0c90, 0x6018, 0x2068, 0x6840, 0xa084, 0x00ff, 0xa005, 0x0140,
8603 0x8001, 0x6842, 0x6017, 0x000a, 0x6007, 0x0016, 0x00de, 0x0c28,
8604 0x68a0, 0xa086, 0x007e, 0x1138, 0x00e6, 0x2071, 0xad00, 0x080c,
8605 0x48f5, 0x00ee, 0x0010, 0x080c, 0x2ad9, 0x00de, 0x08a0, 0x080c,
8606 0x8940, 0x1158, 0x2001, 0x0004, 0x080c, 0x4c30, 0x6003, 0x0001,
8607 0x6007, 0x0003, 0x080c, 0x67ee, 0x0020, 0x080c, 0x85f3, 0x080c,
8608 0x87bd, 0x0005, 0x0469, 0x1158, 0x2001, 0x0008, 0x080c, 0x4c30,
8609 0x6003, 0x0001, 0x6007, 0x0005, 0x080c, 0x67ee, 0x0010, 0x080c,
8610 0x87bd, 0x0005, 0x00e9, 0x1158, 0x2001, 0x000a, 0x080c, 0x4c30,
8611 0x6003, 0x0001, 0x6007, 0x0001, 0x080c, 0x67ee, 0x0010, 0x080c,
8612 0x87bd, 0x0005, 0x2009, 0xb28e, 0x2104, 0xa086, 0x0003, 0x1138,
8613 0x2009, 0xb28f, 0x2104, 0xa084, 0xff00, 0xa086, 0x2a00, 0x0005,
8614 0xa085, 0x0001, 0x0005, 0x00c6, 0x0016, 0xac88, 0x0006, 0x2164,
8615 0x080c, 0x4ceb, 0x001e, 0x00ce, 0x0005, 0x00f6, 0x00e6, 0x00d6,
8616 0x0036, 0x0016, 0x6018, 0x2068, 0x2071, 0xad34, 0x2e04, 0xa085,
8617 0x0003, 0x2072, 0x080c, 0x89cc, 0x0538, 0x2001, 0xad52, 0x2004,
8618 0xd0a4, 0x0158, 0xa006, 0x2020, 0x2009, 0x002a, 0x080c, 0xa96c,
8619 0x2001, 0xad0c, 0x200c, 0xc195, 0x2102, 0x2019, 0x002a, 0x2009,
8620 0x0001, 0x080c, 0x2aac, 0x2071, 0xad00, 0x080c, 0x28fa, 0x00c6,
8621 0x0156, 0x20a9, 0x0081, 0x2009, 0x007f, 0x080c, 0x2bc9, 0x8108,
8622 0x1f04, 0x897d, 0x015e, 0x00ce, 0x080c, 0x8943, 0x6813, 0x00ff,
8623 0x6817, 0xfffe, 0x2071, 0xb280, 0x2079, 0x0100, 0x2e04, 0xa084,
8624 0x00ff, 0x2069, 0xad1b, 0x206a, 0x78e6, 0x0006, 0x8e70, 0x2e04,
8625 0x2069, 0xad1c, 0x206a, 0x78ea, 0x7832, 0x7836, 0x2010, 0xa084,
8626 0xff00, 0x001e, 0xa105, 0x2009, 0xad27, 0x200a, 0x2200, 0xa084,
8627 0x00ff, 0x2008, 0x080c, 0x26a0, 0x080c, 0x574f, 0x0170, 0x2069,
8628 0xb28e, 0x2071, 0xaf9f, 0x6810, 0x2072, 0x6814, 0x7006, 0x6818,
8629 0x700a, 0x681c, 0x700e, 0x080c, 0x9903, 0x0040, 0x2001, 0x0006,
8630 0x080c, 0x4c30, 0x080c, 0x2aff, 0x080c, 0x8078, 0x001e, 0x003e,
8631 0x00de, 0x00ee, 0x00fe, 0x0005, 0x0026, 0x0036, 0x00e6, 0x0156,
8632 0x2019, 0xad27, 0x231c, 0x83ff, 0x01e8, 0x2071, 0xb280, 0x2e14,
8633 0xa294, 0x00ff, 0x7004, 0xa084, 0xff00, 0xa205, 0xa306, 0x1190,
8634 0x2011, 0xb296, 0xad98, 0x000a, 0x20a9, 0x0004, 0x080c, 0x8a7c,
8635 0x1148, 0x2011, 0xb29a, 0xad98, 0x0006, 0x20a9, 0x0004, 0x080c,
8636 0x8a7c, 0x1100, 0x015e, 0x00ee, 0x003e, 0x002e, 0x0005, 0x00e6,
8637 0x2071, 0xb28c, 0x7004, 0xa086, 0x0014, 0x11a8, 0x7008, 0xa086,
8638 0x0800, 0x1188, 0x700c, 0xd0ec, 0x0160, 0xa084, 0x0f00, 0xa086,
8639 0x0100, 0x1138, 0x7024, 0xd0a4, 0x1110, 0xd0ac, 0x0110, 0xa006,
8640 0x0010, 0xa085, 0x0001, 0x00ee, 0x0005, 0x00e6, 0x00d6, 0x00c6,
8641 0x0076, 0x0056, 0x0046, 0x0026, 0x0006, 0x0126, 0x2091, 0x8000,
8642 0x2029, 0xafd0, 0x252c, 0x2021, 0xafd6, 0x2424, 0x2061, 0xb400,
8643 0x2071, 0xad00, 0x7244, 0x7064, 0xa202, 0x16f0, 0x080c, 0xa990,
8644 0x05a0, 0x671c, 0xa786, 0x0001, 0x0580, 0xa786, 0x0007, 0x0568,
8645 0x2500, 0xac06, 0x0550, 0x2400, 0xac06, 0x0538, 0x00c6, 0x6000,
8646 0xa086, 0x0004, 0x1110, 0x080c, 0x190b, 0xa786, 0x0008, 0x1148,
8647 0x080c, 0x9789, 0x1130, 0x00ce, 0x080c, 0x85f3, 0x080c, 0x974e,
8648 0x00a0, 0x6010, 0x2068, 0x080c, 0x9596, 0x0160, 0xa786, 0x0003,
8649 0x11e8, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000, 0x080c, 0x510c,
8650 0x080c, 0x9742, 0x080c, 0x974e, 0x00ce, 0xace0, 0x0018, 0x7058,
8651 0xac02, 0x1210, 0x0804, 0x8a2a, 0x012e, 0x000e, 0x002e, 0x004e,
8652 0x005e, 0x007e, 0x00ce, 0x00de, 0x00ee, 0x0005, 0xa786, 0x0006,
8653 0x1d00, 0x080c, 0xa91f, 0x0c30, 0x220c, 0x2304, 0xa106, 0x1130,
8654 0x8210, 0x8318, 0x1f04, 0x8a7c, 0xa006, 0x0005, 0x2304, 0xa102,
8655 0x0218, 0x2001, 0x0001, 0x0010, 0x2001, 0x0000, 0xa18d, 0x0001,
8656 0x0005, 0x6004, 0xa08a, 0x0080, 0x1a0c, 0x14f6, 0x080c, 0x9778,
8657 0x0120, 0x080c, 0x9789, 0x0168, 0x0028, 0x080c, 0x2aff, 0x080c,
8658 0x9789, 0x0138, 0x080c, 0x6b73, 0x080c, 0x8078, 0x080c, 0x6c50,
8659 0x0005, 0x080c, 0x85f3, 0x0cb0, 0xa182, 0x0040, 0x0002, 0x8ac2,
8660 0x8ac2, 0x8ac2, 0x8ac2, 0x8ac2, 0x8ac2, 0x8ac2, 0x8ac2, 0x8ac2,
8661 0x8ac2, 0x8ac2, 0x8ac4, 0x8ac4, 0x8ac4, 0x8ac4, 0x8ac2, 0x8ac2,
8662 0x8ac2, 0x8ac4, 0x080c, 0x14f6, 0x600b, 0xffff, 0x6003, 0x0001,
8663 0x6106, 0x080c, 0x67a8, 0x0126, 0x2091, 0x8000, 0x080c, 0x6c50,
8664 0x012e, 0x0005, 0xa186, 0x0013, 0x1128, 0x6004, 0xa082, 0x0040,
8665 0x0804, 0x8b5e, 0xa186, 0x0027, 0x11e8, 0x080c, 0x6b73, 0x080c,
8666 0x2ad9, 0x00d6, 0x6110, 0x2168, 0x080c, 0x9596, 0x0168, 0x6837,
8667 0x0103, 0x684b, 0x0029, 0x6847, 0x0000, 0x694c, 0xc1c5, 0x694e,
8668 0x080c, 0x510c, 0x080c, 0x9742, 0x00de, 0x080c, 0x8078, 0x080c,
8669 0x6c50, 0x0005, 0xa186, 0x0014, 0x1120, 0x6004, 0xa082, 0x0040,
8670 0x0428, 0xa186, 0x0046, 0x0138, 0xa186, 0x0045, 0x0120, 0xa186,
8671 0x0047, 0x190c, 0x14f6, 0x2001, 0x0109, 0x2004, 0xd084, 0x0198,
8672 0x0126, 0x2091, 0x2800, 0x0006, 0x0016, 0x0026, 0x080c, 0x6699,
8673 0x002e, 0x001e, 0x000e, 0x012e, 0xe000, 0x6000, 0xa086, 0x0002,
8674 0x1110, 0x0804, 0x8b98, 0x080c, 0x80be, 0x0005, 0x0002, 0x8b3c,
8675 0x8b3a, 0x8b3a, 0x8b3a, 0x8b3a, 0x8b3a, 0x8b3a, 0x8b3a, 0x8b3a,
8676 0x8b3a, 0x8b3a, 0x8b57, 0x8b57, 0x8b57, 0x8b57, 0x8b3a, 0x8b57,
8677 0x8b3a, 0x8b57, 0x080c, 0x14f6, 0x080c, 0x6b73, 0x00d6, 0x6110,
8678 0x2168, 0x080c, 0x9596, 0x0168, 0x6837, 0x0103, 0x684b, 0x0006,
8679 0x6847, 0x0000, 0x6850, 0xc0ec, 0x6852, 0x080c, 0x510c, 0x080c,
8680 0x9742, 0x00de, 0x080c, 0x8078, 0x080c, 0x6c50, 0x0005, 0x080c,
8681 0x6b73, 0x080c, 0x8078, 0x080c, 0x6c50, 0x0005, 0x0002, 0x8b74,
8682 0x8b72, 0x8b72, 0x8b72, 0x8b72, 0x8b72, 0x8b72, 0x8b72, 0x8b72,
8683 0x8b72, 0x8b72, 0x8b86, 0x8b86, 0x8b86, 0x8b86, 0x8b72, 0x8b91,
8684 0x8b72, 0x8b86, 0x080c, 0x14f6, 0x080c, 0x6b73, 0x2001, 0xafa5,
8685 0x2004, 0x603e, 0x6003, 0x0002, 0x080c, 0x6c50, 0x6010, 0xa088,
8686 0x0013, 0x2104, 0xa085, 0x0400, 0x200a, 0x0005, 0x080c, 0x6b73,
8687 0x2001, 0xafa5, 0x2004, 0x603e, 0x6003, 0x000f, 0x080c, 0x6c50,
8688 0x0005, 0x080c, 0x6b73, 0x080c, 0x8078, 0x080c, 0x6c50, 0x0005,
8689 0xa182, 0x0040, 0x0002, 0x8bae, 0x8bae, 0x8bae, 0x8bae, 0x8bae,
8690 0x8bb0, 0x8c88, 0x8ca9, 0x8bae, 0x8bae, 0x8bae, 0x8bae, 0x8bae,
8691 0x8bae, 0x8bae, 0x8bae, 0x8bae, 0x8bae, 0x8bae, 0x080c, 0x14f6,
8692 0x00e6, 0x00d6, 0x603f, 0x0000, 0x2071, 0xb280, 0x7124, 0x610a,
8693 0x2071, 0xb28c, 0x6110, 0x2168, 0x7614, 0xa6b4, 0x0fff, 0x86ff,
8694 0x0904, 0x8c54, 0xa68c, 0x0c00, 0x01e8, 0x00f6, 0x2c78, 0x080c,
8695 0x5029, 0x00fe, 0x0198, 0x684c, 0xd0ac, 0x0180, 0x6020, 0xd0dc,
8696 0x1168, 0x6850, 0xd0bc, 0x1150, 0x7318, 0x6814, 0xa306, 0x1904,
8697 0x8c66, 0x731c, 0x6810, 0xa306, 0x1904, 0x8c66, 0x7318, 0x6b62,
8698 0x731c, 0x6b5e, 0xa68c, 0x00ff, 0xa186, 0x0002, 0x0518, 0xa186,
8699 0x0028, 0x1128, 0x080c, 0x9767, 0x684b, 0x001c, 0x00e8, 0xd6dc,
8700 0x01a0, 0x684b, 0x0015, 0x684c, 0xd0ac, 0x0170, 0x6914, 0x6a10,
8701 0x2100, 0xa205, 0x0148, 0x7018, 0xa106, 0x1118, 0x701c, 0xa206,
8702 0x0118, 0x6962, 0x6a5e, 0xc6dc, 0x0038, 0xd6d4, 0x0118, 0x684b,
8703 0x0007, 0x0010, 0x684b, 0x0000, 0x6837, 0x0103, 0x6e46, 0xa01e,
8704 0xd6c4, 0x01f0, 0xa686, 0x0100, 0x1140, 0x2001, 0xb299, 0x2004,
8705 0xa005, 0x1118, 0xc6c4, 0x0804, 0x8bbf, 0x7328, 0x732c, 0x6b56,
8706 0x83ff, 0x0170, 0xa38a, 0x0009, 0x0210, 0x2019, 0x0008, 0x0036,
8707 0x2308, 0x2019, 0xb298, 0xad90, 0x0019, 0x080c, 0x927f, 0x003e,
8708 0xd6cc, 0x0904, 0x8c79, 0x7124, 0x695a, 0x81ff, 0x0904, 0x8c79,
8709 0xa192, 0x0021, 0x1250, 0x2071, 0xb298, 0x831c, 0x2300, 0xae18,
8710 0xad90, 0x001d, 0x080c, 0x927f, 0x04a0, 0x6838, 0xd0fc, 0x0120,
8711 0x2009, 0x0020, 0x695a, 0x0c78, 0x00f6, 0x2d78, 0x080c, 0x9224,
8712 0x00fe, 0x080c, 0x926f, 0x0438, 0x00f6, 0x2c78, 0x080c, 0x5029,
8713 0x00fe, 0x0188, 0x684c, 0xd0ac, 0x0170, 0x6020, 0xd0dc, 0x1158,
8714 0x6850, 0xd0bc, 0x1140, 0x684c, 0xd0f4, 0x1128, 0x080c, 0x9866,
8715 0x00de, 0x00ee, 0x00e0, 0x684b, 0x0000, 0x6837, 0x0103, 0x6e46,
8716 0x684c, 0xd0ac, 0x0130, 0x6810, 0x6914, 0xa115, 0x0110, 0x080c,
8717 0x8e04, 0x080c, 0x510c, 0x6218, 0x2268, 0x6a3c, 0x8211, 0x6a3e,
8718 0x080c, 0x9834, 0x00de, 0x00ee, 0x1110, 0x080c, 0x8078, 0x0005,
8719 0x00f6, 0x6003, 0x0003, 0x2079, 0xb28c, 0x7c04, 0x7b00, 0x7e0c,
8720 0x7d08, 0x6010, 0x2078, 0x784c, 0xd0ac, 0x0120, 0x6003, 0x0002,
8721 0x00fe, 0x0005, 0x7c12, 0x7b16, 0x7e0a, 0x7d0e, 0x00fe, 0x603f,
8722 0x0000, 0x2c10, 0x080c, 0x1e6e, 0x080c, 0x680b, 0x080c, 0x6d0d,
8723 0x0005, 0x2001, 0xafa5, 0x2004, 0x603e, 0x6003, 0x0004, 0x6110,
8724 0x20e1, 0x0005, 0x3d18, 0x3e20, 0x2c10, 0x080c, 0x1824, 0x0005,
8725 0xa182, 0x0040, 0x0002, 0x8cce, 0x8cce, 0x8cce, 0x8cce, 0x8cce,
8726 0x8cd0, 0x8d61, 0x8cce, 0x8cce, 0x8d77, 0x8ddb, 0x8cce, 0x8cce,
8727 0x8cce, 0x8cce, 0x8dea, 0x8cce, 0x8cce, 0x8cce, 0x080c, 0x14f6,
8728 0x0076, 0x00f6, 0x00e6, 0x00d6, 0x2071, 0xb28c, 0x6110, 0x2178,
8729 0x7614, 0xa6b4, 0x0fff, 0x7e46, 0x7f4c, 0xc7e5, 0x7f4e, 0x6218,
8730 0x2268, 0x6a3c, 0x8211, 0x6a3e, 0x86ff, 0x0904, 0x8d5c, 0xa694,
8731 0xff00, 0xa284, 0x0c00, 0x0120, 0x7018, 0x7862, 0x701c, 0x785e,
8732 0xa284, 0x0300, 0x0904, 0x8d5c, 0x080c, 0x15d9, 0x090c, 0x14f6,
8733 0x2d00, 0x784a, 0x7f4c, 0xc7cd, 0x7f4e, 0x6837, 0x0103, 0x7838,
8734 0x683a, 0x783c, 0x683e, 0x7840, 0x6842, 0x6e46, 0xa68c, 0x0c00,
8735 0x0120, 0x7318, 0x6b62, 0x731c, 0x6b5e, 0xa68c, 0x00ff, 0xa186,
8736 0x0002, 0x0180, 0xa186, 0x0028, 0x1118, 0x684b, 0x001c, 0x0060,
8737 0xd6dc, 0x0118, 0x684b, 0x0015, 0x0038, 0xd6d4, 0x0118, 0x684b,
8738 0x0007, 0x0010, 0x684b, 0x0000, 0x6f4e, 0x7850, 0x6852, 0x7854,
8739 0x6856, 0xa01e, 0xd6c4, 0x0198, 0x7328, 0x732c, 0x6b56, 0x83ff,
8740 0x0170, 0xa38a, 0x0009, 0x0210, 0x2019, 0x0008, 0x0036, 0x2308,
8741 0x2019, 0xb298, 0xad90, 0x0019, 0x080c, 0x927f, 0x003e, 0xd6cc,
8742 0x01d8, 0x7124, 0x695a, 0x81ff, 0x01b8, 0xa192, 0x0021, 0x1250,
8743 0x2071, 0xb298, 0x831c, 0x2300, 0xae18, 0xad90, 0x001d, 0x080c,
8744 0x927f, 0x0050, 0x7838, 0xd0fc, 0x0120, 0x2009, 0x0020, 0x695a,
8745 0x0c78, 0x2d78, 0x080c, 0x9224, 0x00de, 0x00ee, 0x00fe, 0x007e,
8746 0x0005, 0x00f6, 0x6003, 0x0003, 0x2079, 0xb28c, 0x7c04, 0x7b00,
8747 0x7e0c, 0x7d08, 0x6010, 0x2078, 0x7c12, 0x7b16, 0x7e0a, 0x7d0e,
8748 0x00fe, 0x2c10, 0x080c, 0x1e6e, 0x080c, 0x781a, 0x0005, 0x00d6,
8749 0x00f6, 0x2c78, 0x080c, 0x5029, 0x00fe, 0x0120, 0x2001, 0xafa5,
8750 0x2004, 0x603e, 0x6003, 0x0002, 0x080c, 0x6c05, 0x080c, 0x6d0d,
8751 0x6110, 0x2168, 0x694c, 0xd1e4, 0x0904, 0x8dd9, 0xd1cc, 0x0540,
8752 0x6948, 0x6838, 0xd0fc, 0x01e8, 0x0016, 0x684c, 0x0006, 0x6850,
8753 0x0006, 0xad90, 0x000d, 0xa198, 0x000d, 0x2009, 0x0020, 0x0156,
8754 0x21a8, 0x2304, 0x2012, 0x8318, 0x8210, 0x1f04, 0x8da1, 0x015e,
8755 0x000e, 0x6852, 0x000e, 0x684e, 0x001e, 0x2168, 0x080c, 0x1600,
8756 0x0418, 0x0016, 0x080c, 0x1600, 0x00de, 0x080c, 0x926f, 0x00e0,
8757 0x6837, 0x0103, 0x6944, 0xa184, 0x00ff, 0xa0b6, 0x0002, 0x0180,
8758 0xa086, 0x0028, 0x1118, 0x684b, 0x001c, 0x0060, 0xd1dc, 0x0118,
8759 0x684b, 0x0015, 0x0038, 0xd1d4, 0x0118, 0x684b, 0x0007, 0x0010,
8760 0x684b, 0x0000, 0x080c, 0x510c, 0x080c, 0x9834, 0x1110, 0x080c,
8761 0x8078, 0x00de, 0x0005, 0x2019, 0x0001, 0x080c, 0x7a64, 0x6003,
8762 0x0002, 0x2001, 0xafa5, 0x2004, 0x603e, 0x080c, 0x6c05, 0x080c,
8763 0x6d0d, 0x0005, 0x080c, 0x6c05, 0x080c, 0x2ad9, 0x00d6, 0x6110,
8764 0x2168, 0x080c, 0x9596, 0x0150, 0x6837, 0x0103, 0x684b, 0x0029,
8765 0x6847, 0x0000, 0x080c, 0x510c, 0x080c, 0x9742, 0x00de, 0x080c,
8766 0x8078, 0x080c, 0x6d0d, 0x0005, 0x684b, 0x0015, 0xd1fc, 0x0138,
8767 0x684b, 0x0007, 0x8002, 0x8000, 0x810a, 0xa189, 0x0000, 0x6962,
8768 0x685e, 0x0005, 0xa182, 0x0040, 0x0002, 0x8e28, 0x8e28, 0x8e28,
8769 0x8e28, 0x8e28, 0x8e2a, 0x8e28, 0x8ee3, 0x8eef, 0x8e28, 0x8e28,
8770 0x8e28, 0x8e28, 0x8e28, 0x8e28, 0x8e28, 0x8e28, 0x8e28, 0x8e28,
8771 0x080c, 0x14f6, 0x0076, 0x00f6, 0x00e6, 0x00d6, 0x2071, 0xb28c,
8772 0x6110, 0x2178, 0x7614, 0xa6b4, 0x0fff, 0x00f6, 0x2c78, 0x080c,
8773 0x5029, 0x00fe, 0x0150, 0xa684, 0x00ff, 0x1138, 0x6020, 0xd0f4,
8774 0x0120, 0x080c, 0x9866, 0x0804, 0x8ede, 0x7e46, 0x7f4c, 0xc7e5,
8775 0x7f4e, 0x6218, 0x2268, 0x6a3c, 0x8211, 0x6a3e, 0x86ff, 0x0904,
8776 0x8ed4, 0xa694, 0xff00, 0xa284, 0x0c00, 0x0120, 0x7018, 0x7862,
8777 0x701c, 0x785e, 0xa284, 0x0300, 0x0904, 0x8ed2, 0xa686, 0x0100,
8778 0x1140, 0x2001, 0xb299, 0x2004, 0xa005, 0x1118, 0xc6c4, 0x7e46,
8779 0x0c28, 0x080c, 0x15d9, 0x090c, 0x14f6, 0x2d00, 0x784a, 0x7f4c,
8780 0xa7bd, 0x0200, 0x7f4e, 0x6837, 0x0103, 0x7838, 0x683a, 0x783c,
8781 0x683e, 0x7840, 0x6842, 0x6e46, 0xa68c, 0x0c00, 0x0120, 0x7318,
8782 0x6b62, 0x731c, 0x6b5e, 0xa68c, 0x00ff, 0xa186, 0x0002, 0x0180,
8783 0xa186, 0x0028, 0x1118, 0x684b, 0x001c, 0x0060, 0xd6dc, 0x0118,
8784 0x684b, 0x0015, 0x0038, 0xd6d4, 0x0118, 0x684b, 0x0007, 0x0010,
8785 0x684b, 0x0000, 0x6f4e, 0x7850, 0x6852, 0x7854, 0x6856, 0xa01e,
8786 0xd6c4, 0x0198, 0x7328, 0x732c, 0x6b56, 0x83ff, 0x0170, 0xa38a,
8787 0x0009, 0x0210, 0x2019, 0x0008, 0x0036, 0x2308, 0x2019, 0xb298,
8788 0xad90, 0x0019, 0x080c, 0x927f, 0x003e, 0xd6cc, 0x01d8, 0x7124,
8789 0x695a, 0x81ff, 0x01b8, 0xa192, 0x0021, 0x1250, 0x2071, 0xb298,
8790 0x831c, 0x2300, 0xae18, 0xad90, 0x001d, 0x080c, 0x927f, 0x0050,
8791 0x7838, 0xd0fc, 0x0120, 0x2009, 0x0020, 0x695a, 0x0c78, 0x2d78,
8792 0x080c, 0x9224, 0xd6dc, 0x1110, 0xa006, 0x0030, 0x2001, 0x0001,
8793 0x2071, 0xb28c, 0x7218, 0x731c, 0x080c, 0x186f, 0x00de, 0x00ee,
8794 0x00fe, 0x007e, 0x0005, 0x2001, 0xafa5, 0x2004, 0x603e, 0x20e1,
8795 0x0005, 0x3d18, 0x3e20, 0x2c10, 0x080c, 0x1824, 0x0005, 0x2001,
8796 0xafa5, 0x2004, 0x603e, 0x00d6, 0x6003, 0x0002, 0x6110, 0x2168,
8797 0x694c, 0xd1e4, 0x0904, 0x8ff3, 0x603f, 0x0000, 0x00f6, 0x2c78,
8798 0x080c, 0x5029, 0x00fe, 0x0548, 0x6814, 0x6910, 0xa115, 0x0528,
8799 0x6a60, 0xa206, 0x1118, 0x685c, 0xa106, 0x01f8, 0x684c, 0xc0e4,
8800 0x684e, 0x6847, 0x0000, 0x6863, 0x0000, 0x685f, 0x0000, 0x697c,
8801 0x6810, 0xa102, 0x603a, 0x6980, 0x6814, 0xa103, 0x6036, 0x6020,
8802 0xc0f5, 0x6022, 0x00d6, 0x6018, 0x2068, 0x683c, 0x8000, 0x683e,
8803 0x00de, 0x080c, 0x9866, 0x0804, 0x8ff3, 0x694c, 0xd1cc, 0x0904,
8804 0x8fc3, 0x6948, 0x6838, 0xd0fc, 0x0904, 0x8f88, 0x0016, 0x684c,
8805 0x0006, 0x6850, 0x0006, 0x00f6, 0x2178, 0x7944, 0xa184, 0x00ff,
8806 0xa0b6, 0x0002, 0x01e0, 0xa086, 0x0028, 0x1128, 0x684b, 0x001c,
8807 0x784b, 0x001c, 0x00e8, 0xd1dc, 0x0158, 0x684b, 0x0015, 0x784b,
8808 0x0015, 0x080c, 0x99ee, 0x0118, 0x7944, 0xc1dc, 0x7946, 0x0080,
8809 0xd1d4, 0x0128, 0x684b, 0x0007, 0x784b, 0x0007, 0x0048, 0x684c,
8810 0xd0ac, 0x0130, 0x6810, 0x6914, 0xa115, 0x0110, 0x080c, 0x8e04,
8811 0x6848, 0x784a, 0x6860, 0x7862, 0x685c, 0x785e, 0xad90, 0x000d,
8812 0xaf98, 0x000d, 0x2009, 0x0020, 0x0156, 0x21a8, 0x2304, 0x2012,
8813 0x8318, 0x8210, 0x1f04, 0x8f76, 0x015e, 0x00fe, 0x000e, 0x6852,
8814 0x000e, 0x684e, 0x001e, 0x2168, 0x080c, 0x1600, 0x0804, 0x8fee,
8815 0x0016, 0x00f6, 0x2178, 0x7944, 0xa184, 0x00ff, 0xa0b6, 0x0002,
8816 0x01e0, 0xa086, 0x0028, 0x1128, 0x684b, 0x001c, 0x784b, 0x001c,
8817 0x00e8, 0xd1dc, 0x0158, 0x684b, 0x0015, 0x784b, 0x0015, 0x080c,
8818 0x99ee, 0x0118, 0x7944, 0xc1dc, 0x7946, 0x0080, 0xd1d4, 0x0128,
8819 0x684b, 0x0007, 0x784b, 0x0007, 0x0048, 0x684c, 0xd0ac, 0x0130,
8820 0x6810, 0x6914, 0xa115, 0x0110, 0x080c, 0x8e04, 0x6860, 0x7862,
8821 0x685c, 0x785e, 0x684c, 0x784e, 0x00fe, 0x080c, 0x1600, 0x00de,
8822 0x080c, 0x926f, 0x0458, 0x6837, 0x0103, 0x6944, 0xa184, 0x00ff,
8823 0xa0b6, 0x0002, 0x01b0, 0xa086, 0x0028, 0x1118, 0x684b, 0x001c,
8824 0x00d8, 0xd1dc, 0x0148, 0x684b, 0x0015, 0x080c, 0x99ee, 0x0118,
8825 0x6944, 0xc1dc, 0x6946, 0x0080, 0xd1d4, 0x0118, 0x684b, 0x0007,
8826 0x0058, 0x684b, 0x0000, 0x684c, 0xd0ac, 0x0130, 0x6810, 0x6914,
8827 0xa115, 0x0110, 0x080c, 0x8e04, 0x080c, 0x510c, 0x080c, 0x9834,
8828 0x1110, 0x080c, 0x8078, 0x00de, 0x0005, 0x080c, 0x6b73, 0x0010,
8829 0x080c, 0x6c05, 0x080c, 0x9596, 0x01c0, 0x00d6, 0x6110, 0x2168,
8830 0x6837, 0x0103, 0x2009, 0xad0c, 0x210c, 0xd18c, 0x11c0, 0xd184,
8831 0x1198, 0x6108, 0x694a, 0xa18e, 0x0029, 0x1110, 0x080c, 0xabfa,
8832 0x6847, 0x0000, 0x080c, 0x510c, 0x00de, 0x080c, 0x8078, 0x080c,
8833 0x6c50, 0x080c, 0x6d0d, 0x0005, 0x684b, 0x0004, 0x0c88, 0x684b,
8834 0x0004, 0x0c70, 0xa182, 0x0040, 0x0002, 0x9038, 0x9038, 0x9038,
8835 0x9038, 0x9038, 0x903a, 0x9038, 0x903d, 0x9038, 0x9038, 0x9038,
8836 0x9038, 0x9038, 0x9038, 0x9038, 0x9038, 0x9038, 0x9038, 0x9038,
8837 0x080c, 0x14f6, 0x080c, 0x8078, 0x0005, 0x0006, 0x0026, 0xa016,
8838 0x080c, 0x1824, 0x002e, 0x000e, 0x0005, 0xa182, 0x0085, 0x0002,
8839 0x9051, 0x904f, 0x904f, 0x905d, 0x904f, 0x904f, 0x904f, 0x080c,
8840 0x14f6, 0x6003, 0x0001, 0x6106, 0x080c, 0x67a8, 0x0126, 0x2091,
8841 0x8000, 0x080c, 0x6c50, 0x012e, 0x0005, 0x0026, 0x0056, 0x00d6,
8842 0x00e6, 0x2071, 0xb280, 0x7224, 0x6212, 0x7220, 0x080c, 0x9586,
8843 0x01a0, 0x2268, 0x6800, 0xa086, 0x0000, 0x0178, 0x6018, 0x6d18,
8844 0xa52e, 0x1158, 0x00c6, 0x2d60, 0x080c, 0x928f, 0x00ce, 0x0128,
8845 0x6803, 0x0002, 0x6007, 0x0086, 0x0010, 0x6007, 0x0087, 0x6003,
8846 0x0001, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x00f6, 0x2278, 0x080c,
8847 0x5029, 0x00fe, 0x0150, 0x6820, 0xd0ec, 0x0138, 0x00c6, 0x2260,
8848 0x603f, 0x0000, 0x080c, 0x9866, 0x00ce, 0x00ee, 0x00de, 0x005e,
8849 0x002e, 0x0005, 0xa186, 0x0013, 0x1160, 0x6004, 0xa08a, 0x0085,
8850 0x0a0c, 0x14f6, 0xa08a, 0x008c, 0x1a0c, 0x14f6, 0xa082, 0x0085,
8851 0x0072, 0xa186, 0x0027, 0x0120, 0xa186, 0x0014, 0x190c, 0x14f6,
8852 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005, 0x90be,
8853 0x90c0, 0x90c0, 0x90be, 0x90be, 0x90be, 0x90be, 0x080c, 0x14f6,
8854 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005, 0xa186,
8855 0x0013, 0x1128, 0x6004, 0xa082, 0x0085, 0x2008, 0x04a8, 0xa186,
8856 0x0027, 0x11e8, 0x080c, 0x6b73, 0x080c, 0x2ad9, 0x00d6, 0x6010,
8857 0x2068, 0x080c, 0x9596, 0x0150, 0x6837, 0x0103, 0x6847, 0x0000,
8858 0x684b, 0x0029, 0x080c, 0x510c, 0x080c, 0x9742, 0x00de, 0x080c,
8859 0x8078, 0x080c, 0x6c50, 0x0005, 0x080c, 0x80be, 0x0ce0, 0xa186,
8860 0x0014, 0x1dd0, 0x080c, 0x6b73, 0x00d6, 0x6010, 0x2068, 0x080c,
8861 0x9596, 0x0d60, 0x6837, 0x0103, 0x6847, 0x0000, 0x684b, 0x0006,
8862 0x6850, 0xc0ec, 0x6852, 0x08f0, 0x0002, 0x910e, 0x910c, 0x910c,
8863 0x910c, 0x910c, 0x910c, 0x9126, 0x080c, 0x14f6, 0x080c, 0x6b73,
8864 0x6030, 0xa08c, 0xff00, 0x810f, 0xa186, 0x0039, 0x0118, 0xa186,
8865 0x0035, 0x1118, 0x2001, 0xafa3, 0x0010, 0x2001, 0xafa4, 0x2004,
8866 0x6016, 0x6003, 0x000c, 0x080c, 0x6c50, 0x0005, 0x080c, 0x6b73,
8867 0x6030, 0xa08c, 0xff00, 0x810f, 0xa186, 0x0039, 0x0118, 0xa186,
8868 0x0035, 0x1118, 0x2001, 0xafa3, 0x0010, 0x2001, 0xafa4, 0x2004,
8869 0x6016, 0x6003, 0x000e, 0x080c, 0x6c50, 0x0005, 0xa182, 0x008c,
8870 0x1220, 0xa182, 0x0085, 0x0208, 0x001a, 0x080c, 0x80be, 0x0005,
8871 0x914f, 0x914f, 0x914f, 0x914f, 0x9151, 0x91a4, 0x914f, 0x080c,
8872 0x14f6, 0x00d6, 0x00f6, 0x2c78, 0x080c, 0x5029, 0x00fe, 0x0168,
8873 0x6030, 0xa08c, 0xff00, 0x810f, 0xa186, 0x0039, 0x0118, 0xa186,
8874 0x0035, 0x1118, 0x00de, 0x0804, 0x91b7, 0x080c, 0x9742, 0x080c,
8875 0x9596, 0x01c8, 0x6010, 0x2068, 0x6837, 0x0103, 0x6850, 0xd0b4,
8876 0x0128, 0x684b, 0x0006, 0xc0ec, 0x6852, 0x0048, 0xd0bc, 0x0118,
8877 0x684b, 0x0002, 0x0020, 0x684b, 0x0005, 0x080c, 0x9803, 0x6847,
8878 0x0000, 0x080c, 0x510c, 0x2c68, 0x080c, 0x8022, 0x01c0, 0x6003,
8879 0x0001, 0x6007, 0x001e, 0x600b, 0xffff, 0x2009, 0xb28e, 0x210c,
8880 0x6136, 0x2009, 0xb28f, 0x210c, 0x613a, 0x6918, 0x611a, 0x080c,
8881 0x9956, 0x6950, 0x6152, 0x601f, 0x0001, 0x080c, 0x67a8, 0x2d60,
8882 0x080c, 0x8078, 0x00de, 0x0005, 0x00f6, 0x2c78, 0x080c, 0x5029,
8883 0x00fe, 0x0598, 0x6030, 0xa08c, 0xff00, 0x810f, 0xa186, 0x0035,
8884 0x0130, 0xa186, 0x001e, 0x0118, 0xa186, 0x0039, 0x1530, 0x00d6,
8885 0x2c68, 0x080c, 0x9a34, 0x1904, 0x91fc, 0x080c, 0x8022, 0x01d8,
8886 0x6106, 0x6003, 0x0001, 0x601f, 0x0001, 0x6918, 0x611a, 0x6928,
8887 0x612a, 0x692c, 0x612e, 0x6930, 0xa18c, 0x00ff, 0x6132, 0x6934,
8888 0x6136, 0x6938, 0x613a, 0x6950, 0x6152, 0x080c, 0x9956, 0x080c,
8889 0x67a8, 0x080c, 0x6c50, 0x2d60, 0x00f8, 0x00d6, 0x6010, 0x2068,
8890 0x080c, 0x9596, 0x01c8, 0x6837, 0x0103, 0x6850, 0xd0b4, 0x0128,
8891 0xc0ec, 0x6852, 0x684b, 0x0006, 0x0048, 0xd0bc, 0x0118, 0x684b,
8892 0x0002, 0x0020, 0x684b, 0x0005, 0x080c, 0x9803, 0x6847, 0x0000,
8893 0x080c, 0x510c, 0x080c, 0x9742, 0x00de, 0x080c, 0x8078, 0x0005,
8894 0x0016, 0x00d6, 0x6010, 0x2068, 0x080c, 0x9596, 0x0140, 0x6837,
8895 0x0103, 0x684b, 0x0028, 0x6847, 0x0000, 0x080c, 0x510c, 0x00de,
8896 0x001e, 0xa186, 0x0013, 0x0148, 0xa186, 0x0014, 0x0130, 0xa186,
8897 0x0027, 0x0118, 0x080c, 0x80be, 0x0030, 0x080c, 0x6b73, 0x080c,
8898 0x974e, 0x080c, 0x6c50, 0x0005, 0x0056, 0x0066, 0x00d6, 0x00f6,
8899 0x2029, 0x0001, 0xa182, 0x0101, 0x1208, 0x0010, 0x2009, 0x0100,
8900 0x2130, 0x2069, 0xb298, 0x831c, 0x2300, 0xad18, 0x2009, 0x0020,
8901 0xaf90, 0x001d, 0x080c, 0x927f, 0xa6b2, 0x0020, 0x7804, 0xa06d,
8902 0x0110, 0x080c, 0x1600, 0x080c, 0x15d9, 0x0500, 0x8528, 0x6837,
8903 0x0110, 0x683b, 0x0000, 0x2d20, 0x7c06, 0xa68a, 0x003d, 0x1228,
8904 0x2608, 0xad90, 0x000f, 0x0459, 0x0088, 0xa6b2, 0x003c, 0x2009,
8905 0x003c, 0x2d78, 0xad90, 0x000f, 0x0411, 0x0c28, 0x00fe, 0x852f,
8906 0xa5ad, 0x0003, 0x7d36, 0xa5ac, 0x0000, 0x0028, 0x00fe, 0x852f,
8907 0xa5ad, 0x0003, 0x7d36, 0x00de, 0x006e, 0x005e, 0x0005, 0x00f6,
8908 0x8dff, 0x0158, 0x6804, 0xa07d, 0x0130, 0x6807, 0x0000, 0x080c,
8909 0x510c, 0x2f68, 0x0cb8, 0x080c, 0x510c, 0x00fe, 0x0005, 0x0156,
8910 0xa184, 0x0001, 0x0108, 0x8108, 0x810c, 0x21a8, 0x2304, 0x8007,
8911 0x2012, 0x8318, 0x8210, 0x1f04, 0x9286, 0x015e, 0x0005, 0x0066,
8912 0x0126, 0x2091, 0x8000, 0x2031, 0x0001, 0x601c, 0xa084, 0x000f,
8913 0x0083, 0x012e, 0x006e, 0x0005, 0x0126, 0x2091, 0x8000, 0x0066,
8914 0x2031, 0x0000, 0x601c, 0xa084, 0x000f, 0x001b, 0x006e, 0x012e,
8915 0x0005, 0x92c3, 0x92c3, 0x92be, 0x92e5, 0x92b1, 0x92be, 0x92e5,
8916 0x92be, 0x080c, 0x14f6, 0x0036, 0x2019, 0x0010, 0x080c, 0xa566,
8917 0x601f, 0x0006, 0x6003, 0x0007, 0x003e, 0x0005, 0xa006, 0x0005,
8918 0xa085, 0x0001, 0x0005, 0x00d6, 0x86ff, 0x11d8, 0x6010, 0x2068,
8919 0x080c, 0x9596, 0x01c0, 0x6834, 0xa086, 0x0139, 0x1128, 0x684b,
8920 0x0005, 0x6853, 0x0000, 0x0028, 0xa00e, 0x2001, 0x0005, 0x080c,
8921 0x51df, 0x080c, 0x9803, 0x080c, 0x510c, 0x080c, 0x8078, 0xa085,
8922 0x0001, 0x00de, 0x0005, 0xa006, 0x0ce0, 0x6000, 0xa08a, 0x0010,
8923 0x1a0c, 0x14f6, 0x000b, 0x0005, 0x92fc, 0x9319, 0x92fe, 0x9338,
8924 0x9316, 0x92fc, 0x92be, 0x92c3, 0x92c3, 0x92be, 0x92be, 0x92be,
8925 0x92be, 0x92be, 0x92be, 0x92be, 0x080c, 0x14f6, 0x86ff, 0x1198,
8926 0x00d6, 0x6010, 0x2068, 0x080c, 0x9596, 0x0110, 0x080c, 0x9803,
8927 0x00de, 0x6007, 0x0085, 0x6003, 0x000b, 0x601f, 0x0002, 0x080c,
8928 0x67a8, 0x080c, 0x6c50, 0xa085, 0x0001, 0x0005, 0x080c, 0x190b,
8929 0x0c28, 0x00e6, 0x2071, 0xafc7, 0x7024, 0xac06, 0x1110, 0x080c,
8930 0x79e1, 0x601c, 0xa084, 0x000f, 0xa086, 0x0006, 0x1150, 0x0086,
8931 0x0096, 0x2049, 0x0001, 0x2c40, 0x080c, 0x7b9a, 0x009e, 0x008e,
8932 0x0010, 0x080c, 0x78de, 0x00ee, 0x1948, 0x080c, 0x92be, 0x0005,
8933 0x0036, 0x00e6, 0x2071, 0xafc7, 0x703c, 0xac06, 0x1140, 0x2019,
8934 0x0000, 0x080c, 0x7a64, 0x00ee, 0x003e, 0x0804, 0x92fe, 0x080c,
8935 0x7cb8, 0x00ee, 0x003e, 0x1904, 0x92fe, 0x080c, 0x92be, 0x0005,
8936 0x00c6, 0x601c, 0xa084, 0x000f, 0x0013, 0x00ce, 0x0005, 0x9369,
8937 0x93d3, 0x9501, 0x9374, 0x974e, 0x9369, 0xa558, 0x8078, 0x93d3,
8938 0x9362, 0x955f, 0x080c, 0x14f6, 0x080c, 0x9789, 0x1110, 0x080c,
8939 0x85f3, 0x0005, 0x080c, 0x6b73, 0x080c, 0x6c50, 0x080c, 0x8078,
8940 0x0005, 0x6017, 0x0001, 0x0005, 0x6010, 0xa080, 0x0019, 0x2c02,
8941 0x6000, 0xa08a, 0x0010, 0x1a0c, 0x14f6, 0x000b, 0x0005, 0x938f,
8942 0x9391, 0x93b1, 0x93c3, 0x93d0, 0x938f, 0x9369, 0x9369, 0x9369,
8943 0x93c3, 0x93c3, 0x938f, 0x938f, 0x938f, 0x938f, 0x93cd, 0x080c,
8944 0x14f6, 0x00e6, 0x6010, 0x2070, 0x7050, 0xc0b5, 0x7052, 0x2071,
8945 0xafc7, 0x7024, 0xac06, 0x0190, 0x080c, 0x78de, 0x6007, 0x0085,
8946 0x6003, 0x000b, 0x601f, 0x0002, 0x2001, 0xafa4, 0x2004, 0x6016,
8947 0x080c, 0x67a8, 0x080c, 0x6c50, 0x00ee, 0x0005, 0x6017, 0x0001,
8948 0x0cd8, 0x00d6, 0x6010, 0x2068, 0x6850, 0xc0b5, 0x6852, 0x00de,
8949 0x6007, 0x0085, 0x6003, 0x000b, 0x601f, 0x0002, 0x080c, 0x67a8,
8950 0x080c, 0x6c50, 0x0005, 0x00d6, 0x6017, 0x0001, 0x6010, 0x2068,
8951 0x6850, 0xc0b5, 0x6852, 0x00de, 0x0005, 0x080c, 0x8078, 0x0005,
8952 0x080c, 0x190b, 0x08f0, 0x6000, 0xa08a, 0x0010, 0x1a0c, 0x14f6,
8953 0x000b, 0x0005, 0x93ea, 0x9371, 0x93ec, 0x93ea, 0x93ec, 0x93ec,
8954 0x936a, 0x93ea, 0x9364, 0x9364, 0x93ea, 0x93ea, 0x93ea, 0x93ea,
8955 0x93ea, 0x93ea, 0x080c, 0x14f6, 0x00d6, 0x6018, 0x2068, 0x6804,
8956 0xa084, 0x00ff, 0x00de, 0xa08a, 0x000c, 0x1a0c, 0x14f6, 0x000b,
8957 0x0005, 0x9405, 0x94a7, 0x9407, 0x9441, 0x9407, 0x9441, 0x9407,
8958 0x9411, 0x9405, 0x9441, 0x9405, 0x942d, 0x080c, 0x14f6, 0x6004,
8959 0xa08e, 0x0016, 0x0588, 0xa08e, 0x0004, 0x0570, 0xa08e, 0x0002,
8960 0x0558, 0x6004, 0x080c, 0x9789, 0x0904, 0x94c0, 0xa08e, 0x0021,
8961 0x0904, 0x94c4, 0xa08e, 0x0022, 0x0904, 0x94c0, 0xa08e, 0x003d,
8962 0x0904, 0x94c4, 0xa08e, 0x0039, 0x0904, 0x94c8, 0xa08e, 0x0035,
8963 0x0904, 0x94c8, 0xa08e, 0x001e, 0x0188, 0xa08e, 0x0001, 0x1150,
8964 0x00d6, 0x6018, 0x2068, 0x6804, 0xa084, 0x00ff, 0x00de, 0xa086,
8965 0x0006, 0x0110, 0x080c, 0x2ad9, 0x080c, 0x85f3, 0x080c, 0x974e,
8966 0x0005, 0x00c6, 0x00d6, 0x6104, 0xa186, 0x0016, 0x0904, 0x9498,
8967 0xa186, 0x0002, 0x1518, 0x6018, 0x2068, 0x2001, 0xad34, 0x2004,
8968 0xd0ac, 0x1904, 0x94ea, 0x68a0, 0xd0bc, 0x1904, 0x94ea, 0x6840,
8969 0xa084, 0x00ff, 0xa005, 0x0190, 0x8001, 0x6842, 0x6013, 0x0000,
8970 0x601f, 0x0007, 0x6017, 0x0398, 0x603f, 0x0000, 0x080c, 0x8022,
8971 0x0128, 0x2d00, 0x601a, 0x601f, 0x0001, 0x0450, 0x00de, 0x00ce,
8972 0x6004, 0xa08e, 0x0002, 0x11a8, 0x6018, 0xa080, 0x0028, 0x2004,
8973 0xa086, 0x007e, 0x1170, 0x2009, 0xad34, 0x2104, 0xc085, 0x200a,
8974 0x00e6, 0x2071, 0xad00, 0x080c, 0x48f5, 0x00ee, 0x080c, 0x85f3,
8975 0x0020, 0x080c, 0x85f3, 0x080c, 0x2ad9, 0x00e6, 0x0126, 0x2091,
8976 0x8000, 0x080c, 0x2aff, 0x012e, 0x00ee, 0x080c, 0x974e, 0x0005,
8977 0x2001, 0x0002, 0x080c, 0x4c30, 0x6003, 0x0001, 0x6007, 0x0002,
8978 0x080c, 0x67ee, 0x080c, 0x6c50, 0x00de, 0x00ce, 0x0c80, 0x00c6,
8979 0x00d6, 0x6104, 0xa186, 0x0016, 0x0d58, 0x6018, 0x2068, 0x6840,
8980 0xa084, 0x00ff, 0xa005, 0x0904, 0x946e, 0x8001, 0x6842, 0x6003,
8981 0x0001, 0x080c, 0x67ee, 0x080c, 0x6c50, 0x00de, 0x00ce, 0x08b8,
8982 0x080c, 0x85f3, 0x0804, 0x943e, 0x080c, 0x8621, 0x0804, 0x943e,
8983 0x00d6, 0x2c68, 0x6104, 0x080c, 0x9a34, 0x00de, 0x0118, 0x080c,
8984 0x8078, 0x00b8, 0x6004, 0x8007, 0x6130, 0xa18c, 0x00ff, 0xa105,
8985 0x6032, 0x6007, 0x0085, 0x6003, 0x000b, 0x601f, 0x0002, 0x6038,
8986 0x600a, 0x2001, 0xafa4, 0x2004, 0x6016, 0x080c, 0x67a8, 0x080c,
8987 0x6c50, 0x0005, 0x00de, 0x00ce, 0x080c, 0x85f3, 0x080c, 0x2ad9,
8988 0x00e6, 0x0126, 0x2091, 0x8000, 0x080c, 0x2aff, 0x6013, 0x0000,
8989 0x601f, 0x0007, 0x6017, 0x0398, 0x603f, 0x0000, 0x012e, 0x00ee,
8990 0x0005, 0x6000, 0xa08a, 0x0010, 0x1a0c, 0x14f6, 0x000b, 0x0005,
8991 0x9518, 0x9518, 0x9518, 0x9518, 0x9518, 0x9518, 0x9518, 0x9518,
8992 0x9518, 0x9369, 0x9518, 0x9371, 0x951a, 0x9371, 0x9527, 0x9518,
8993 0x080c, 0x14f6, 0x6004, 0xa086, 0x008b, 0x0148, 0x6007, 0x008b,
8994 0x6003, 0x000d, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0005, 0x080c,
8995 0x9742, 0x080c, 0x9596, 0x0580, 0x080c, 0x2ad9, 0x00d6, 0x080c,
8996 0x9596, 0x0168, 0x6010, 0x2068, 0x6837, 0x0103, 0x684b, 0x0006,
8997 0x6847, 0x0000, 0x6850, 0xc0ed, 0x6852, 0x080c, 0x510c, 0x2c68,
8998 0x080c, 0x8022, 0x0150, 0x6818, 0x601a, 0x080c, 0x9956, 0x00c6,
8999 0x2d60, 0x080c, 0x974e, 0x00ce, 0x0008, 0x2d60, 0x00de, 0x6013,
9000 0x0000, 0x601f, 0x0001, 0x6007, 0x0001, 0x6003, 0x0001, 0x080c,
9001 0x67ee, 0x080c, 0x6c50, 0x0010, 0x080c, 0x974e, 0x0005, 0x6000,
9002 0xa08a, 0x0010, 0x1a0c, 0x14f6, 0x000b, 0x0005, 0x9576, 0x9576,
9003 0x9576, 0x9578, 0x9579, 0x9576, 0x9576, 0x9576, 0x9576, 0x9576,
9004 0x9576, 0x9576, 0x9576, 0x9576, 0x9576, 0x9576, 0x080c, 0x14f6,
9005 0x0005, 0x080c, 0x7cb8, 0x190c, 0x14f6, 0x6110, 0x2168, 0x684b,
9006 0x0006, 0x080c, 0x510c, 0x080c, 0x8078, 0x0005, 0xa284, 0x0007,
9007 0x1158, 0xa282, 0xb400, 0x0240, 0x2001, 0xad16, 0x2004, 0xa202,
9008 0x1218, 0xa085, 0x0001, 0x0005, 0xa006, 0x0ce8, 0x0026, 0x6210,
9009 0xa294, 0xf000, 0x002e, 0x0005, 0x00e6, 0x00c6, 0x0036, 0x0006,
9010 0x0126, 0x2091, 0x8000, 0x2061, 0xb400, 0x2071, 0xad00, 0x7344,
9011 0x7064, 0xa302, 0x12a8, 0x601c, 0xa206, 0x1160, 0x080c, 0x98e3,
9012 0x0148, 0x080c, 0x9789, 0x1110, 0x080c, 0x85f3, 0x00c6, 0x080c,
9013 0x8078, 0x00ce, 0xace0, 0x0018, 0x7058, 0xac02, 0x1208, 0x0c38,
9014 0x012e, 0x000e, 0x003e, 0x00ce, 0x00ee, 0x0005, 0x00e6, 0x00c6,
9015 0x0016, 0xa188, 0xae34, 0x210c, 0x81ff, 0x0170, 0x2061, 0xb400,
9016 0x2071, 0xad00, 0x0016, 0x080c, 0x8022, 0x001e, 0x0138, 0x611a,
9017 0x080c, 0x2ad9, 0x080c, 0x8078, 0xa006, 0x0010, 0xa085, 0x0001,
9018 0x001e, 0x00ce, 0x00ee, 0x0005, 0x00c6, 0x0056, 0x0126, 0x2091,
9019 0x8000, 0x00c6, 0x080c, 0x8022, 0x005e, 0x0180, 0x6612, 0x651a,
9020 0x080c, 0x9956, 0x601f, 0x0003, 0x2009, 0x004b, 0x080c, 0x80a7,
9021 0xa085, 0x0001, 0x012e, 0x005e, 0x00ce, 0x0005, 0xa006, 0x0cd0,
9022 0x00c6, 0x0056, 0x0126, 0x2091, 0x8000, 0x62a0, 0x00c6, 0x080c,
9023 0x8022, 0x005e, 0x0508, 0x6013, 0x0000, 0x651a, 0x080c, 0x9956,
9024 0x601f, 0x0003, 0x00c6, 0x2560, 0x080c, 0x4ecf, 0x00ce, 0x080c,
9025 0x68e7, 0x0076, 0x2039, 0x0000, 0x080c, 0x681d, 0x2c08, 0x080c,
9026 0xa712, 0x007e, 0x2009, 0x004c, 0x080c, 0x80a7, 0xa085, 0x0001,
9027 0x012e, 0x005e, 0x00ce, 0x0005, 0xa006, 0x0cd0, 0x00f6, 0x00c6,
9028 0x0046, 0x00c6, 0x080c, 0x8022, 0x2c78, 0x00ce, 0x0180, 0x7e12,
9029 0x2c00, 0x781a, 0x781f, 0x0003, 0x2021, 0x0005, 0x080c, 0x9683,
9030 0x2f60, 0x2009, 0x004d, 0x080c, 0x80a7, 0xa085, 0x0001, 0x004e,
9031 0x00ce, 0x00fe, 0x0005, 0x00f6, 0x00c6, 0x0046, 0x00c6, 0x080c,
9032 0x8022, 0x2c78, 0x00ce, 0x0178, 0x7e12, 0x2c00, 0x781a, 0x781f,
9033 0x0003, 0x2021, 0x0005, 0x0439, 0x2f60, 0x2009, 0x004e, 0x080c,
9034 0x80a7, 0xa085, 0x0001, 0x004e, 0x00ce, 0x00fe, 0x0005, 0x00f6,
9035 0x00c6, 0x0046, 0x00c6, 0x080c, 0x8022, 0x2c78, 0x00ce, 0x0178,
9036 0x7e12, 0x2c00, 0x781a, 0x781f, 0x0003, 0x2021, 0x0004, 0x0059,
9037 0x2f60, 0x2009, 0x0052, 0x080c, 0x80a7, 0xa085, 0x0001, 0x004e,
9038 0x00ce, 0x00fe, 0x0005, 0x0096, 0x0076, 0x0126, 0x2091, 0x8000,
9039 0x080c, 0x4e71, 0x0118, 0x2001, 0x9688, 0x0028, 0x080c, 0x4e43,
9040 0x0158, 0x2001, 0x968e, 0x0006, 0xa00e, 0x2400, 0x080c, 0x51df,
9041 0x080c, 0x510c, 0x000e, 0x0807, 0x2418, 0x080c, 0x6b15, 0x62a0,
9042 0x0086, 0x2041, 0x0001, 0x2039, 0x0001, 0x2608, 0x080c, 0x6900,
9043 0x008e, 0x080c, 0x681d, 0x2f08, 0x2648, 0x080c, 0xa712, 0x613c,
9044 0x81ff, 0x090c, 0x69a9, 0x012e, 0x007e, 0x009e, 0x0005, 0x00c6,
9045 0x0126, 0x2091, 0x8000, 0x00c6, 0x080c, 0x8022, 0x001e, 0x0188,
9046 0x660a, 0x611a, 0x080c, 0x9956, 0x601f, 0x0001, 0x2d00, 0x6012,
9047 0x2009, 0x001f, 0x080c, 0x80a7, 0xa085, 0x0001, 0x012e, 0x00ce,
9048 0x0005, 0xa006, 0x0cd8, 0x00c6, 0x0126, 0x2091, 0x8000, 0x00c6,
9049 0x080c, 0x8022, 0x001e, 0x0188, 0x660a, 0x611a, 0x080c, 0x9956,
9050 0x601f, 0x0008, 0x2d00, 0x6012, 0x2009, 0x0021, 0x080c, 0x80a7,
9051 0xa085, 0x0001, 0x012e, 0x00ce, 0x0005, 0xa006, 0x0cd8, 0x00c6,
9052 0x0126, 0x2091, 0x8000, 0x00c6, 0x080c, 0x8022, 0x001e, 0x0188,
9053 0x660a, 0x611a, 0x080c, 0x9956, 0x601f, 0x0001, 0x2d00, 0x6012,
9054 0x2009, 0x003d, 0x080c, 0x80a7, 0xa085, 0x0001, 0x012e, 0x00ce,
9055 0x0005, 0xa006, 0x0cd8, 0x00c6, 0x0126, 0x2091, 0x8000, 0x00c6,
9056 0x080c, 0x9807, 0x001e, 0x0180, 0x611a, 0x080c, 0x9956, 0x601f,
9057 0x0001, 0x2d00, 0x6012, 0x2009, 0x0000, 0x080c, 0x80a7, 0xa085,
9058 0x0001, 0x012e, 0x00ce, 0x0005, 0xa006, 0x0cd8, 0x00c6, 0x0126,
9059 0x2091, 0x8000, 0x00c6, 0x080c, 0x8022, 0x001e, 0x0188, 0x660a,
9060 0x611a, 0x080c, 0x9956, 0x601f, 0x0001, 0x2d00, 0x6012, 0x2009,
9061 0x0044, 0x080c, 0x80a7, 0xa085, 0x0001, 0x012e, 0x00ce, 0x0005,
9062 0xa006, 0x0cd8, 0x0026, 0x00d6, 0x6218, 0x2268, 0x6a3c, 0x82ff,
9063 0x0110, 0x8211, 0x6a3e, 0x00de, 0x002e, 0x0005, 0x0006, 0x6000,
9064 0xa086, 0x0000, 0x0190, 0x6013, 0x0000, 0x601f, 0x0007, 0x2001,
9065 0xafa3, 0x2004, 0x0006, 0xa082, 0x0051, 0x000e, 0x0208, 0x8004,
9066 0x6016, 0x080c, 0xabb4, 0x603f, 0x0000, 0x000e, 0x0005, 0x0066,
9067 0x00c6, 0x00d6, 0x2031, 0xad52, 0x2634, 0xd6e4, 0x0128, 0x6618,
9068 0x2660, 0x6e48, 0x080c, 0x4dfc, 0x00de, 0x00ce, 0x006e, 0x0005,
9069 0x0006, 0x0016, 0x6004, 0xa08e, 0x0002, 0x0140, 0xa08e, 0x0003,
9070 0x0128, 0xa08e, 0x0004, 0x0110, 0xa085, 0x0001, 0x001e, 0x000e,
9071 0x0005, 0x0006, 0x00d6, 0x6010, 0xa06d, 0x0148, 0x6834, 0xa086,
9072 0x0139, 0x0138, 0x6838, 0xd0fc, 0x0110, 0xa006, 0x0010, 0xa085,
9073 0x0001, 0x00de, 0x000e, 0x0005, 0x00c6, 0x0126, 0x2091, 0x8000,
9074 0x00c6, 0x080c, 0x8022, 0x001e, 0x0190, 0x611a, 0x080c, 0x9956,
9075 0x601f, 0x0001, 0x2d00, 0x6012, 0x080c, 0x2ad9, 0x2009, 0x0028,
9076 0x080c, 0x80a7, 0xa085, 0x0001, 0x012e, 0x00ce, 0x0005, 0xa006,
9077 0x0cd8, 0xa186, 0x0015, 0x1178, 0x2011, 0xad20, 0x2204, 0xa086,
9078 0x0074, 0x1148, 0x080c, 0x8943, 0x6003, 0x0001, 0x6007, 0x0029,
9079 0x080c, 0x67ee, 0x0020, 0x080c, 0x85f3, 0x080c, 0x8078, 0x0005,
9080 0xa186, 0x0016, 0x1128, 0x2001, 0x0004, 0x080c, 0x4c30, 0x00e8,
9081 0xa186, 0x0015, 0x11e8, 0x2011, 0xad20, 0x2204, 0xa086, 0x0014,
9082 0x11b8, 0x00d6, 0x6018, 0x2068, 0x080c, 0x4d72, 0x00de, 0x080c,
9083 0x89f7, 0x1170, 0x00d6, 0x6018, 0x2068, 0x6890, 0x00de, 0xa005,
9084 0x0138, 0x2001, 0x0006, 0x080c, 0x4c30, 0x080c, 0x81f6, 0x0020,
9085 0x080c, 0x85f3, 0x080c, 0x8078, 0x0005, 0x6848, 0xa086, 0x0005,
9086 0x1108, 0x0009, 0x0005, 0x6850, 0xc0ad, 0x6852, 0x0005, 0x00e6,
9087 0x0126, 0x2071, 0xad00, 0x2091, 0x8000, 0x7544, 0xa582, 0x0001,
9088 0x0608, 0x7048, 0x2060, 0x6000, 0xa086, 0x0000, 0x0148, 0xace0,
9089 0x0018, 0x7058, 0xac02, 0x1208, 0x0cb0, 0x2061, 0xb400, 0x0c98,
9090 0x6003, 0x0008, 0x8529, 0x7546, 0xaca8, 0x0018, 0x7058, 0xa502,
9091 0x1230, 0x754a, 0xa085, 0x0001, 0x012e, 0x00ee, 0x0005, 0x704b,
9092 0xb400, 0x0cc0, 0xa006, 0x0cc0, 0x00e6, 0x2071, 0xb28c, 0x7014,
9093 0xd0e4, 0x0150, 0x6013, 0x0000, 0x6003, 0x0001, 0x6007, 0x0050,
9094 0x080c, 0x67a8, 0x080c, 0x6c50, 0x00ee, 0x0005, 0x00c6, 0x00f6,
9095 0x2c78, 0x080c, 0x5029, 0x00fe, 0x0120, 0x601c, 0xa084, 0x000f,
9096 0x0013, 0x00ce, 0x0005, 0x9369, 0x985e, 0x9861, 0x9864, 0xa9a7,
9097 0xa9c2, 0xa9c5, 0x9369, 0x9369, 0x080c, 0x14f6, 0xe000, 0xe000,
9098 0x0005, 0xe000, 0xe000, 0x0005, 0x0009, 0x0005, 0x00f6, 0x2c78,
9099 0x080c, 0x5029, 0x0538, 0x080c, 0x8022, 0x1128, 0x2001, 0xafa5,
9100 0x2004, 0x783e, 0x00f8, 0x7818, 0x601a, 0x080c, 0x9956, 0x781c,
9101 0xa086, 0x0003, 0x0128, 0x7808, 0x6036, 0x2f00, 0x603a, 0x0020,
9102 0x7808, 0x603a, 0x2f00, 0x6036, 0x602a, 0x601f, 0x0001, 0x6007,
9103 0x0035, 0x6003, 0x0001, 0x7950, 0x6152, 0x080c, 0x67a8, 0x080c,
9104 0x6c50, 0x2f60, 0x00fe, 0x0005, 0x0016, 0x00f6, 0x682c, 0x6032,
9105 0xa08e, 0x0001, 0x0138, 0xa086, 0x0005, 0x0140, 0xa006, 0x602a,
9106 0x602e, 0x00a0, 0x6820, 0xc0f4, 0xc0d5, 0x6822, 0x6810, 0x2078,
9107 0x787c, 0x6938, 0xa102, 0x7880, 0x6934, 0xa103, 0x1e78, 0x6834,
9108 0x602a, 0x6838, 0xa084, 0xfffc, 0x683a, 0x602e, 0x2d00, 0x6036,
9109 0x6808, 0x603a, 0x6918, 0x611a, 0x6950, 0x6152, 0x601f, 0x0001,
9110 0x6007, 0x0039, 0x6003, 0x0001, 0x080c, 0x67a8, 0x6803, 0x0002,
9111 0x00fe, 0x001e, 0x0005, 0x00f6, 0x2c78, 0x080c, 0x5029, 0x1118,
9112 0xa085, 0x0001, 0x0070, 0x6020, 0xd0f4, 0x1150, 0xc0f5, 0x6022,
9113 0x6010, 0x2078, 0x7828, 0x603a, 0x782c, 0x6036, 0x080c, 0x190b,
9114 0xa006, 0x00fe, 0x0005, 0x0006, 0x0016, 0x6004, 0xa08e, 0x0034,
9115 0x01b8, 0xa08e, 0x0035, 0x01a0, 0xa08e, 0x0036, 0x0188, 0xa08e,
9116 0x0037, 0x0170, 0xa08e, 0x0038, 0x0158, 0xa08e, 0x0039, 0x0140,
9117 0xa08e, 0x003a, 0x0128, 0xa08e, 0x003b, 0x0110, 0xa085, 0x0001,
9118 0x001e, 0x000e, 0x0005, 0x0006, 0x0016, 0x0026, 0x0036, 0x00e6,
9119 0x2001, 0xaf9f, 0x200c, 0x8000, 0x2014, 0x2001, 0x0032, 0x080c,
9120 0x6665, 0x2001, 0xafa3, 0x82ff, 0x1110, 0x2011, 0x0002, 0x2202,
9121 0x2001, 0xafa1, 0x200c, 0x8000, 0x2014, 0x2071, 0xaf8d, 0x711a,
9122 0x721e, 0x2001, 0x0064, 0x080c, 0x6665, 0x2001, 0xafa4, 0x82ff,
9123 0x1110, 0x2011, 0x0002, 0x2202, 0x2009, 0xafa5, 0xa280, 0x000a,
9124 0x200a, 0x00ee, 0x003e, 0x002e, 0x001e, 0x000e, 0x0005, 0x0006,
9125 0x00e6, 0x2001, 0xafa3, 0x2003, 0x0028, 0x2001, 0xafa4, 0x2003,
9126 0x0014, 0x2071, 0xaf8d, 0x701b, 0x0000, 0x701f, 0x07d0, 0x2001,
9127 0xafa5, 0x2003, 0x001e, 0x00ee, 0x000e, 0x0005, 0x00d6, 0x6054,
9128 0xa06d, 0x0110, 0x080c, 0x15f0, 0x00de, 0x0005, 0x0005, 0x00c6,
9129 0x0126, 0x2091, 0x8000, 0x00c6, 0x080c, 0x8022, 0x001e, 0x0178,
9130 0x611a, 0x0ca1, 0x601f, 0x0001, 0x2d00, 0x6012, 0x2009, 0x0033,
9131 0x080c, 0x80a7, 0xa085, 0x0001, 0x012e, 0x00ce, 0x0005, 0xa006,
9132 0x0cd8, 0x00d6, 0x00e6, 0x00f6, 0x2071, 0xad00, 0xa186, 0x0015,
9133 0x1500, 0x7080, 0xa086, 0x0018, 0x11e0, 0x6010, 0x2068, 0x6a3c,
9134 0xd2e4, 0x1160, 0x2c78, 0x080c, 0x6e05, 0x01d8, 0x706c, 0x6a50,
9135 0xa206, 0x1160, 0x7070, 0x6a54, 0xa206, 0x1140, 0x6218, 0xa290,
9136 0x0028, 0x2214, 0x2009, 0x0000, 0x080c, 0x2b1e, 0x080c, 0x81f6,
9137 0x0020, 0x080c, 0x85f3, 0x080c, 0x8078, 0x00fe, 0x00ee, 0x00de,
9138 0x0005, 0x7050, 0x6a54, 0xa206, 0x0d48, 0x0c80, 0x00c6, 0x0126,
9139 0x2091, 0x8000, 0x00c6, 0x080c, 0x8022, 0x001e, 0x0180, 0x611a,
9140 0x080c, 0x9956, 0x601f, 0x0001, 0x2d00, 0x6012, 0x2009, 0x0043,
9141 0x080c, 0x80a7, 0xa085, 0x0001, 0x012e, 0x00ce, 0x0005, 0xa006,
9142 0x0cd8, 0x00d6, 0x00e6, 0x00f6, 0x2071, 0xad00, 0xa186, 0x0015,
9143 0x11c0, 0x7080, 0xa086, 0x0004, 0x11a0, 0x6010, 0xa0e8, 0x000f,
9144 0x2c78, 0x080c, 0x6e05, 0x01a8, 0x706c, 0x6a08, 0xa206, 0x1130,
9145 0x7070, 0x6a0c, 0xa206, 0x1110, 0x080c, 0x2ad9, 0x080c, 0x81f6,
9146 0x0020, 0x080c, 0x85f3, 0x080c, 0x8078, 0x00fe, 0x00ee, 0x00de,
9147 0x0005, 0x7050, 0x6a0c, 0xa206, 0x0d78, 0x0c80, 0x0016, 0x0026,
9148 0x684c, 0xd0ac, 0x0178, 0x6914, 0x6a10, 0x2100, 0xa205, 0x0150,
9149 0x6860, 0xa106, 0x1118, 0x685c, 0xa206, 0x0120, 0x6962, 0x6a5e,
9150 0xa085, 0x0001, 0x002e, 0x001e, 0x0005, 0x00d6, 0x0036, 0x6310,
9151 0x2368, 0x684a, 0x6952, 0xa29e, 0x4000, 0x1188, 0x00c6, 0x6318,
9152 0x2360, 0x2009, 0x0000, 0x080c, 0x4f6e, 0x1108, 0xc185, 0x6000,
9153 0xd0bc, 0x0108, 0xc18d, 0x6a66, 0x696a, 0x00ce, 0x0080, 0x6a66,
9154 0x3918, 0xa398, 0x0006, 0x231c, 0x686b, 0x0004, 0x6b72, 0x00c6,
9155 0x6318, 0x2360, 0x6004, 0xa084, 0x00ff, 0x686e, 0x00ce, 0x080c,
9156 0x510c, 0x003e, 0x00de, 0x0005, 0x00c6, 0x0026, 0x0016, 0xa186,
9157 0x0035, 0x0110, 0x6a34, 0x0008, 0x6a28, 0x080c, 0x9586, 0x01f0,
9158 0x2260, 0x611c, 0xa186, 0x0003, 0x0118, 0xa186, 0x0006, 0x1190,
9159 0x6834, 0xa206, 0x0140, 0x6838, 0xa206, 0x1160, 0x6108, 0x6834,
9160 0xa106, 0x1140, 0x0020, 0x6008, 0x6938, 0xa106, 0x1118, 0x6018,
9161 0x6918, 0xa106, 0x001e, 0x002e, 0x00ce, 0x0005, 0xa085, 0x0001,
9162 0x0cc8, 0x0066, 0x6000, 0xa0b2, 0x0010, 0x1a0c, 0x14f6, 0x0013,
9163 0x006e, 0x0005, 0x9a7a, 0x9eff, 0xa027, 0x9a7a, 0x9a7a, 0x9a7a,
9164 0x9a7a, 0x9a7a, 0x9ab2, 0xa0a3, 0x9a7a, 0x9a7a, 0x9a7a, 0x9a7a,
9165 0x9a7a, 0x9a7a, 0x080c, 0x14f6, 0x0066, 0x6000, 0xa0b2, 0x0010,
9166 0x1a0c, 0x14f6, 0x0013, 0x006e, 0x0005, 0x9a95, 0xa4fd, 0x9a95,
9167 0x9a95, 0x9a95, 0x9a95, 0x9a95, 0x9a95, 0xa4c1, 0xa545, 0x9a95,
9168 0xaaea, 0xab1a, 0xaaea, 0xab1a, 0x9a95, 0x080c, 0x14f6, 0x0066,
9169 0x6000, 0xa0b2, 0x0010, 0x1a0c, 0x14f6, 0x0013, 0x006e, 0x0005,
9170 0x9ab0, 0xa1d8, 0xa295, 0xa2c2, 0xa346, 0x9ab0, 0xa433, 0xa3de,
9171 0xa0af, 0xa497, 0xa4ac, 0x9ab0, 0x9ab0, 0x9ab0, 0x9ab0, 0x9ab0,
9172 0x080c, 0x14f6, 0xa1b2, 0x0080, 0x1a0c, 0x14f6, 0x2100, 0xa1b2,
9173 0x0040, 0x1a04, 0x9e79, 0x0002, 0x9afc, 0x9cab, 0x9afc, 0x9afc,
9174 0x9afc, 0x9cb2, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc,
9175 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc,
9176 0x9afc, 0x9afc, 0x9afc, 0x9afe, 0x9b5a, 0x9b65, 0x9ba6, 0x9bc0,
9177 0x9c3e, 0x9c9c, 0x9afc, 0x9afc, 0x9cb5, 0x9afc, 0x9afc, 0x9cc4,
9178 0x9ccb, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9afc, 0x9d42, 0x9afc,
9179 0x9afc, 0x9d4d, 0x9afc, 0x9afc, 0x9d18, 0x9afc, 0x9afc, 0x9afc,
9180 0x9d61, 0x9afc, 0x9afc, 0x9afc, 0x9dd5, 0x9afc, 0x9afc, 0x9afc,
9181 0x9afc, 0x9afc, 0x9afc, 0x9e40, 0x080c, 0x14f6, 0x080c, 0x502d,
9182 0x1140, 0x2001, 0xad34, 0x2004, 0xa084, 0x0009, 0xa086, 0x0008,
9183 0x1140, 0x6007, 0x0009, 0x602b, 0x0009, 0x6013, 0x0000, 0x0804,
9184 0x9ca6, 0x080c, 0x501d, 0x00e6, 0x00c6, 0x0036, 0x0026, 0x0016,
9185 0x6218, 0x2270, 0x72a0, 0x0026, 0x2019, 0x0029, 0x080c, 0x68e7,
9186 0x0076, 0x2039, 0x0000, 0x080c, 0x681d, 0x2c08, 0x080c, 0xa712,
9187 0x007e, 0x001e, 0x2e60, 0x080c, 0x4ecf, 0x001e, 0x002e, 0x003e,
9188 0x00ce, 0x00ee, 0x6618, 0x00c6, 0x2660, 0x080c, 0x4ceb, 0x00ce,
9189 0xa6b0, 0x0001, 0x2634, 0xa684, 0x00ff, 0xa082, 0x0006, 0x0278,
9190 0x080c, 0xa656, 0x1904, 0x9ba0, 0x080c, 0xa5f6, 0x1120, 0x6007,
9191 0x0008, 0x0804, 0x9ca6, 0x6007, 0x0009, 0x0804, 0x9ca6, 0x080c,
9192 0xa801, 0x0128, 0x080c, 0xa656, 0x0d78, 0x0804, 0x9ba0, 0x6013,
9193 0x1900, 0x0c88, 0x6106, 0x080c, 0xa5a6, 0x6007, 0x0006, 0x0804,
9194 0x9ca6, 0x6007, 0x0007, 0x0804, 0x9ca6, 0x080c, 0xab4e, 0x1904,
9195 0x9e76, 0x00d6, 0x6618, 0x2668, 0x6e04, 0xa6b4, 0xff00, 0x8637,
9196 0xa686, 0x0006, 0x0188, 0xa686, 0x0004, 0x0170, 0x6e04, 0xa6b4,
9197 0x00ff, 0xa686, 0x0006, 0x0140, 0xa686, 0x0004, 0x0128, 0xa686,
9198 0x0005, 0x0110, 0x00de, 0x00e0, 0x080c, 0xa6b4, 0x11a0, 0xa686,
9199 0x0006, 0x1150, 0x0026, 0x6218, 0xa290, 0x0028, 0x2214, 0x2009,
9200 0x0000, 0x080c, 0x2b1e, 0x002e, 0x080c, 0x4d72, 0x6007, 0x000a,
9201 0x00de, 0x0804, 0x9ca6, 0x6007, 0x000b, 0x00de, 0x0804, 0x9ca6,
9202 0x080c, 0x2ad9, 0x6007, 0x0001, 0x0804, 0x9ca6, 0x080c, 0xab4e,
9203 0x1904, 0x9e76, 0x6618, 0x00d6, 0x2668, 0x6e04, 0x00de, 0xa686,
9204 0x0707, 0x0d70, 0x0026, 0x6218, 0xa290, 0x0028, 0x2214, 0x2009,
9205 0x0000, 0x080c, 0x2b1e, 0x002e, 0x6007, 0x000c, 0x0804, 0x9ca6,
9206 0x080c, 0x502d, 0x1140, 0x2001, 0xad34, 0x2004, 0xa084, 0x0009,
9207 0xa086, 0x0008, 0x1110, 0x0804, 0x9b09, 0x080c, 0x501d, 0x6618,
9208 0xa6b0, 0x0001, 0x2634, 0xa684, 0x00ff, 0xa082, 0x0006, 0x06e8,
9209 0x1138, 0x0026, 0x2001, 0x0006, 0x080c, 0x4c5d, 0x002e, 0x0050,
9210 0xa6b4, 0xff00, 0x8637, 0xa686, 0x0004, 0x0120, 0xa686, 0x0006,
9211 0x1904, 0x9ba0, 0x080c, 0xa6c1, 0x1120, 0x6007, 0x000e, 0x0804,
9212 0x9ca6, 0x0046, 0x6418, 0xa4a0, 0x0028, 0x2424, 0xa4a4, 0x00ff,
9213 0x8427, 0x0046, 0x080c, 0x2ad9, 0x004e, 0x0016, 0xa006, 0x2009,
9214 0xad52, 0x210c, 0xd1a4, 0x0158, 0x2009, 0x0029, 0x080c, 0xa96c,
9215 0x6018, 0x00d6, 0x2068, 0x6800, 0xc0e5, 0x6802, 0x00de, 0x001e,
9216 0x004e, 0x6007, 0x0001, 0x0804, 0x9ca6, 0x2001, 0x0001, 0x080c,
9217 0x4c1e, 0x0156, 0x0016, 0x0026, 0x0036, 0x20a9, 0x0004, 0x2019,
9218 0xad05, 0x2011, 0xb290, 0x080c, 0x8a7c, 0x003e, 0x002e, 0x001e,
9219 0x015e, 0xa005, 0x0168, 0xa6b4, 0xff00, 0x8637, 0xa682, 0x0004,
9220 0x0a04, 0x9ba0, 0xa682, 0x0007, 0x0a04, 0x9bea, 0x0804, 0x9ba0,
9221 0x6013, 0x1900, 0x6007, 0x0009, 0x0804, 0x9ca6, 0x080c, 0x502d,
9222 0x1140, 0x2001, 0xad34, 0x2004, 0xa084, 0x0009, 0xa086, 0x0008,
9223 0x1110, 0x0804, 0x9b09, 0x080c, 0x501d, 0x6618, 0xa6b0, 0x0001,
9224 0x2634, 0xa684, 0x00ff, 0xa082, 0x0006, 0x06b0, 0xa6b4, 0xff00,
9225 0x8637, 0xa686, 0x0004, 0x0120, 0xa686, 0x0006, 0x1904, 0x9ba0,
9226 0x080c, 0xa6e9, 0x1130, 0x080c, 0xa5f6, 0x1118, 0x6007, 0x0010,
9227 0x04e8, 0x0046, 0x6418, 0xa4a0, 0x0028, 0x2424, 0xa4a4, 0x00ff,
9228 0x8427, 0x0046, 0x080c, 0x2ad9, 0x004e, 0x0016, 0xa006, 0x2009,
9229 0xad52, 0x210c, 0xd1a4, 0x0158, 0x2009, 0x0029, 0x080c, 0xa96c,
9230 0x6018, 0x00d6, 0x2068, 0x6800, 0xc0e5, 0x6802, 0x00de, 0x001e,
9231 0x004e, 0x6007, 0x0001, 0x00d0, 0x080c, 0xa801, 0x0140, 0xa6b4,
9232 0xff00, 0x8637, 0xa686, 0x0006, 0x0958, 0x0804, 0x9ba0, 0x6013,
9233 0x1900, 0x6007, 0x0009, 0x0050, 0x080c, 0xab4e, 0x1904, 0x9e76,
9234 0x080c, 0x9e98, 0x1904, 0x9ba0, 0x6007, 0x0012, 0x6003, 0x0001,
9235 0x080c, 0x67ee, 0x0005, 0x6007, 0x0001, 0x6003, 0x0001, 0x080c,
9236 0x67ee, 0x0cc0, 0x6007, 0x0005, 0x0cc0, 0x080c, 0xab4e, 0x1904,
9237 0x9e76, 0x080c, 0x9e98, 0x1904, 0x9ba0, 0x6007, 0x0020, 0x6003,
9238 0x0001, 0x080c, 0x67ee, 0x0005, 0x6007, 0x0023, 0x6003, 0x0001,
9239 0x080c, 0x67ee, 0x0005, 0x080c, 0xab4e, 0x1904, 0x9e76, 0x080c,
9240 0x9e98, 0x1904, 0x9ba0, 0x0016, 0x0026, 0x2011, 0xb291, 0x2214,
9241 0xa286, 0xffff, 0x0190, 0x2c08, 0x080c, 0x9586, 0x01d8, 0x2260,
9242 0x2011, 0xb290, 0x2214, 0x6008, 0xa206, 0x11a0, 0x6018, 0xa190,
9243 0x0006, 0x2214, 0xa206, 0x01e0, 0x0068, 0x2011, 0xb290, 0x2214,
9244 0x2c08, 0x080c, 0xa940, 0x11a0, 0x2011, 0xb291, 0x2214, 0xa286,
9245 0xffff, 0x01a0, 0x2160, 0x6007, 0x0026, 0x6013, 0x1700, 0x2011,
9246 0xb289, 0x2214, 0xa296, 0xffff, 0x1160, 0x6007, 0x0025, 0x0048,
9247 0x601c, 0xa086, 0x0007, 0x1d70, 0x080c, 0x8078, 0x2160, 0x6007,
9248 0x0025, 0x6003, 0x0001, 0x080c, 0x67ee, 0x002e, 0x001e, 0x0005,
9249 0x2001, 0x0001, 0x080c, 0x4c1e, 0x0156, 0x0016, 0x0026, 0x0036,
9250 0x20a9, 0x0004, 0x2019, 0xad05, 0x2011, 0xb296, 0x080c, 0x8a7c,
9251 0x003e, 0x002e, 0x001e, 0x015e, 0x0120, 0x6007, 0x0031, 0x0804,
9252 0x9ca6, 0x080c, 0x87bd, 0x080c, 0x574f, 0x1158, 0x0006, 0x0026,
9253 0x0036, 0x080c, 0x576b, 0x0110, 0x080c, 0x5726, 0x003e, 0x002e,
9254 0x000e, 0x0005, 0x6106, 0x080c, 0x9eb4, 0x6007, 0x002b, 0x0804,
9255 0x9ca6, 0x6007, 0x002c, 0x0804, 0x9ca6, 0x080c, 0xab4e, 0x1904,
9256 0x9e76, 0x080c, 0x9e98, 0x1904, 0x9ba0, 0x6106, 0x080c, 0x9eb8,
9257 0x1120, 0x6007, 0x002e, 0x0804, 0x9ca6, 0x6007, 0x002f, 0x0804,
9258 0x9ca6, 0x00e6, 0x00d6, 0x00c6, 0x6018, 0xa080, 0x0001, 0x200c,
9259 0xa184, 0x00ff, 0xa086, 0x0006, 0x0158, 0xa184, 0xff00, 0x8007,
9260 0xa086, 0x0006, 0x0128, 0x00ce, 0x00de, 0x00ee, 0x0804, 0x9cab,
9261 0x2001, 0xad71, 0x2004, 0xd0e4, 0x0904, 0x9dd2, 0x2071, 0xb28c,
9262 0x7010, 0x6036, 0x7014, 0x603a, 0x7108, 0x720c, 0x2001, 0xad52,
9263 0x2004, 0xd0a4, 0x0140, 0x6018, 0x2068, 0x6810, 0xa106, 0x1118,
9264 0x6814, 0xa206, 0x01f8, 0x2001, 0xad52, 0x2004, 0xd0ac, 0x1580,
9265 0x2069, 0xad00, 0x6870, 0xa206, 0x1558, 0x686c, 0xa106, 0x1540,
9266 0x7210, 0x080c, 0x9586, 0x0548, 0x080c, 0xa9d4, 0x0530, 0x622a,
9267 0x6007, 0x0036, 0x6003, 0x0001, 0x080c, 0x67a8, 0x00ce, 0x00de,
9268 0x00ee, 0x0005, 0x7214, 0xa286, 0xffff, 0x0150, 0x080c, 0x9586,
9269 0x01a0, 0xa280, 0x0002, 0x2004, 0x7110, 0xa106, 0x1170, 0x0c08,
9270 0x7210, 0x2c08, 0x080c, 0xa940, 0x2c10, 0x2160, 0x0130, 0x08c8,
9271 0x6007, 0x0037, 0x6013, 0x1500, 0x08e8, 0x6007, 0x0037, 0x6013,
9272 0x1700, 0x08c0, 0x6007, 0x0012, 0x08a8, 0x6018, 0xa080, 0x0001,
9273 0x2004, 0xa084, 0xff00, 0x8007, 0xa086, 0x0006, 0x1904, 0x9cab,
9274 0x00e6, 0x00d6, 0x00c6, 0x2001, 0xad71, 0x2004, 0xd0e4, 0x0904,
9275 0x9e38, 0x2069, 0xad00, 0x2071, 0xb28c, 0x7008, 0x6036, 0x720c,
9276 0x623a, 0xa286, 0xffff, 0x1140, 0x7208, 0x00c6, 0x2c08, 0x080c,
9277 0xa940, 0x2c10, 0x00ce, 0x0588, 0x080c, 0x9586, 0x0570, 0x00c6,
9278 0x0026, 0x2260, 0x080c, 0x928f, 0x002e, 0x00ce, 0x7118, 0xa18c,
9279 0xff00, 0x810f, 0xa186, 0x0001, 0x0158, 0xa186, 0x0005, 0x0118,
9280 0xa186, 0x0007, 0x1178, 0xa280, 0x0004, 0x2004, 0xa005, 0x0150,
9281 0x0056, 0x7510, 0x7614, 0x080c, 0xa9eb, 0x005e, 0x00ce, 0x00de,
9282 0x00ee, 0x0005, 0x6007, 0x003b, 0x602b, 0x0009, 0x6013, 0x2a00,
9283 0x6003, 0x0001, 0x080c, 0x67a8, 0x0c88, 0x6007, 0x003b, 0x602b,
9284 0x0009, 0x6013, 0x1700, 0x6003, 0x0001, 0x080c, 0x67a8, 0x0c30,
9285 0x6007, 0x003b, 0x602b, 0x000b, 0x6013, 0x0000, 0x0804, 0x9daa,
9286 0x00e6, 0x0026, 0x080c, 0x502d, 0x0558, 0x080c, 0x501d, 0x080c,
9287 0xabc5, 0x1520, 0x2071, 0xad00, 0x70d0, 0xc085, 0x70d2, 0x00f6,
9288 0x2079, 0x0100, 0x729c, 0xa284, 0x00ff, 0x706e, 0x78e6, 0xa284,
9289 0xff00, 0x7270, 0xa205, 0x7072, 0x78ea, 0x00fe, 0x70db, 0x0000,
9290 0x2001, 0xad52, 0x2004, 0xd0a4, 0x0120, 0x2011, 0xafe0, 0x2013,
9291 0x07d0, 0xd0ac, 0x1128, 0x080c, 0x28fa, 0x0010, 0x080c, 0xabf1,
9292 0x002e, 0x00ee, 0x080c, 0x8078, 0x0804, 0x9caa, 0x080c, 0x8078,
9293 0x0005, 0x2600, 0x0002, 0x9e81, 0x9e81, 0x9e81, 0x9e81, 0x9e81,
9294 0x9e83, 0x080c, 0x14f6, 0x080c, 0xab4e, 0x1d80, 0x0089, 0x1138,
9295 0x6007, 0x0045, 0x6003, 0x0001, 0x080c, 0x67ee, 0x0005, 0x080c,
9296 0x2ad9, 0x6007, 0x0001, 0x6003, 0x0001, 0x080c, 0x67ee, 0x0005,
9297 0x00d6, 0x0066, 0x6618, 0x2668, 0x6e04, 0xa6b4, 0xff00, 0x8637,
9298 0xa686, 0x0006, 0x0170, 0xa686, 0x0004, 0x0158, 0x6e04, 0xa6b4,
9299 0x00ff, 0xa686, 0x0006, 0x0128, 0xa686, 0x0004, 0x0110, 0xa085,
9300 0x0001, 0x006e, 0x00de, 0x0005, 0x00d6, 0x0449, 0x00de, 0x0005,
9301 0x00d6, 0x0491, 0x11f0, 0x680c, 0xa08c, 0xff00, 0x6820, 0xa084,
9302 0x00ff, 0xa115, 0x6212, 0x6824, 0x602a, 0xd1e4, 0x0118, 0x2009,
9303 0x0001, 0x0060, 0xd1ec, 0x0168, 0x6920, 0xa18c, 0x00ff, 0x6824,
9304 0x080c, 0x2676, 0x1130, 0x2110, 0x2009, 0x0000, 0x080c, 0x2b1e,
9305 0x0018, 0xa085, 0x0001, 0x0008, 0xa006, 0x00de, 0x0005, 0x2069,
9306 0xb28d, 0x6800, 0xa082, 0x0010, 0x1228, 0x6013, 0x0000, 0xa085,
9307 0x0001, 0x0008, 0xa006, 0x0005, 0x6013, 0x0000, 0x2069, 0xb28c,
9308 0x6808, 0xa084, 0xff00, 0xa086, 0x0800, 0x1140, 0x6800, 0xa084,
9309 0x00ff, 0xa08e, 0x0014, 0x0110, 0xa08e, 0x0010, 0x0005, 0x6004,
9310 0xa0b2, 0x0080, 0x1a0c, 0x14f6, 0xa1b6, 0x0013, 0x1130, 0x2008,
9311 0xa1b2, 0x0040, 0x1a04, 0x9ffb, 0x0092, 0xa1b6, 0x0027, 0x0120,
9312 0xa1b6, 0x0014, 0x190c, 0x14f6, 0x2001, 0x0007, 0x080c, 0x4c5d,
9313 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005, 0x9f5f,
9314 0x9f61, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f61, 0x9f6f, 0x9ff4, 0x9fbf,
9315 0x9ff4, 0x9fd0, 0x9ff4, 0x9f6f, 0x9ff4, 0x9fec, 0x9ff4, 0x9fec,
9316 0x9ff4, 0x9ff4, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f,
9317 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f61, 0x9f5f, 0x9ff4,
9318 0x9f5f, 0x9f5f, 0x9ff4, 0x9f5f, 0x9ff1, 0x9ff4, 0x9f5f, 0x9f5f,
9319 0x9f5f, 0x9f5f, 0x9ff4, 0x9ff4, 0x9f5f, 0x9ff4, 0x9ff4, 0x9f5f,
9320 0x9f69, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f, 0x9ff0, 0x9ff4, 0x9f5f,
9321 0x9f5f, 0x9ff4, 0x9ff4, 0x9f5f, 0x9f5f, 0x9f5f, 0x9f5f, 0x080c,
9322 0x14f6, 0x080c, 0x6b73, 0x6003, 0x0002, 0x080c, 0x6c50, 0x0804,
9323 0x9ffa, 0x2001, 0x0000, 0x080c, 0x4c1e, 0x0804, 0x9ff4, 0x00f6,
9324 0x2079, 0xad51, 0x7804, 0x00fe, 0xd0ac, 0x1904, 0x9ff4, 0x2001,
9325 0x0000, 0x080c, 0x4c1e, 0x6018, 0xa080, 0x0004, 0x2004, 0xa086,
9326 0x00ff, 0x1140, 0x00f6, 0x2079, 0xad00, 0x7894, 0x8000, 0x7896,
9327 0x00fe, 0x00e0, 0x00c6, 0x6018, 0x2060, 0x6000, 0xd0f4, 0x1140,
9328 0x6010, 0xa005, 0x0128, 0x00ce, 0x080c, 0x3cce, 0x0804, 0x9ff4,
9329 0x00ce, 0x2001, 0xad00, 0x2004, 0xa086, 0x0002, 0x1138, 0x00f6,
9330 0x2079, 0xad00, 0x7894, 0x8000, 0x7896, 0x00fe, 0x2001, 0x0002,
9331 0x080c, 0x4c30, 0x080c, 0x6b73, 0x601f, 0x0001, 0x6003, 0x0001,
9332 0x6007, 0x0002, 0x080c, 0x67ee, 0x080c, 0x6c50, 0x00c6, 0x6118,
9333 0x2160, 0x2009, 0x0001, 0x080c, 0x6519, 0x00ce, 0x04d8, 0x6618,
9334 0x00d6, 0x2668, 0x6e04, 0x00de, 0xa6b4, 0xff00, 0x8637, 0xa686,
9335 0x0006, 0x0550, 0xa686, 0x0004, 0x0538, 0x2001, 0x0004, 0x0410,
9336 0x2001, 0xad00, 0x2004, 0xa086, 0x0003, 0x1110, 0x080c, 0x3cce,
9337 0x2001, 0x0006, 0x0489, 0x6618, 0x00d6, 0x2668, 0x6e04, 0x00de,
9338 0xa6b4, 0xff00, 0x8637, 0xa686, 0x0006, 0x0170, 0x2001, 0x0006,
9339 0x0048, 0x2001, 0x0004, 0x0030, 0x2001, 0x0006, 0x00e9, 0x0020,
9340 0x0018, 0x0010, 0x080c, 0x4c5d, 0x080c, 0x6b73, 0x080c, 0x8078,
9341 0x080c, 0x6c50, 0x0005, 0x2600, 0x0002, 0xa003, 0xa003, 0xa003,
9342 0xa003, 0xa003, 0xa005, 0x080c, 0x14f6, 0x080c, 0x6b73, 0x080c,
9343 0x8078, 0x080c, 0x6c50, 0x0005, 0x0016, 0x00d6, 0x6118, 0x2168,
9344 0x6900, 0xd184, 0x0188, 0x6104, 0xa18e, 0x000a, 0x1128, 0x699c,
9345 0xd1a4, 0x1110, 0x2001, 0x0007, 0x080c, 0x4c30, 0x2001, 0x0000,
9346 0x080c, 0x4c1e, 0x080c, 0x2aff, 0x00de, 0x001e, 0x0005, 0x00d6,
9347 0x6618, 0x2668, 0x6804, 0xa084, 0xff00, 0x8007, 0x00de, 0xa0b2,
9348 0x000c, 0x1a0c, 0x14f6, 0xa1b6, 0x0015, 0x1110, 0x003b, 0x0028,
9349 0xa1b6, 0x0016, 0x190c, 0x14f6, 0x006b, 0x0005, 0x86b9, 0x86b9,
9350 0x86b9, 0x86b9, 0x86b9, 0x86b9, 0xa08f, 0xa056, 0x86b9, 0x86b9,
9351 0x86b9, 0x86b9, 0x86b9, 0x86b9, 0x86b9, 0x86b9, 0x86b9, 0x86b9,
9352 0xa08f, 0xa096, 0x86b9, 0x86b9, 0x86b9, 0x86b9, 0x00f6, 0x2079,
9353 0xad51, 0x7804, 0xd0ac, 0x11e0, 0x6018, 0xa07d, 0x01c8, 0x7800,
9354 0xd0f4, 0x1118, 0x7810, 0xa005, 0x1198, 0x2001, 0x0000, 0x080c,
9355 0x4c1e, 0x2001, 0x0002, 0x080c, 0x4c30, 0x601f, 0x0001, 0x6003,
9356 0x0001, 0x6007, 0x0002, 0x080c, 0x67ee, 0x080c, 0x6c50, 0x00a8,
9357 0x2011, 0xb283, 0x2204, 0x8211, 0x220c, 0x080c, 0x2676, 0x1168,
9358 0x00c6, 0x080c, 0x4cdc, 0x0120, 0x00ce, 0x080c, 0x8078, 0x0028,
9359 0x080c, 0x493a, 0x00ce, 0x080c, 0x8078, 0x00fe, 0x0005, 0x6604,
9360 0xa6b6, 0x001e, 0x1110, 0x080c, 0x8078, 0x0005, 0x080c, 0x8940,
9361 0x1138, 0x6003, 0x0001, 0x6007, 0x0001, 0x080c, 0x67ee, 0x0010,
9362 0x080c, 0x8078, 0x0005, 0x6004, 0xa08a, 0x0080, 0x1a0c, 0x14f6,
9363 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005, 0xa182,
9364 0x0040, 0x0002, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c7, 0xa0c5,
9365 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5,
9366 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0xa0c5, 0x080c, 0x14f6, 0x00d6,
9367 0x00e6, 0x00f6, 0x0156, 0x0046, 0x0026, 0x6218, 0xa280, 0x002b,
9368 0x2004, 0xa005, 0x0120, 0x2021, 0x0000, 0x080c, 0xab96, 0x6106,
9369 0x2071, 0xb280, 0x7444, 0xa4a4, 0xff00, 0x0904, 0xa129, 0xa486,
9370 0x2000, 0x1130, 0x2009, 0x0001, 0x2011, 0x0200, 0x080c, 0x663f,
9371 0x080c, 0x15d9, 0x090c, 0x14f6, 0x6003, 0x0007, 0x2d00, 0x6837,
9372 0x010d, 0x6803, 0x0000, 0x683b, 0x0000, 0x6c5a, 0x2c00, 0x685e,
9373 0x6008, 0x68b2, 0x6018, 0x2078, 0x78a0, 0x8007, 0x7130, 0x694a,
9374 0x0016, 0xa084, 0xff00, 0x6846, 0x684f, 0x0000, 0x6857, 0x0036,
9375 0x080c, 0x510c, 0x001e, 0xa486, 0x2000, 0x1130, 0x2019, 0x0017,
9376 0x080c, 0xa8eb, 0x0804, 0xa186, 0xa486, 0x0400, 0x1130, 0x2019,
9377 0x0002, 0x080c, 0xa89d, 0x0804, 0xa186, 0xa486, 0x0200, 0x1110,
9378 0x080c, 0xa882, 0xa486, 0x1000, 0x1110, 0x080c, 0xa8d0, 0x0804,
9379 0xa186, 0x2069, 0xb048, 0x6a00, 0xd284, 0x0904, 0xa1d5, 0xa284,
9380 0x0300, 0x1904, 0xa1cf, 0x6804, 0xa005, 0x0904, 0xa1c0, 0x2d78,
9381 0x6003, 0x0007, 0x080c, 0x15c0, 0x0904, 0xa18d, 0x7800, 0xd08c,
9382 0x1118, 0x7804, 0x8001, 0x7806, 0x6013, 0x0000, 0x6803, 0x0000,
9383 0x6837, 0x0116, 0x683b, 0x0000, 0x6008, 0x68b2, 0x2c00, 0x684a,
9384 0x6018, 0x2078, 0x78a0, 0x8007, 0x7130, 0x6986, 0x6846, 0x7928,
9385 0x698a, 0x792c, 0x698e, 0x7930, 0x6992, 0x7934, 0x6996, 0x6853,
9386 0x003d, 0x7244, 0xa294, 0x0003, 0xa286, 0x0002, 0x1118, 0x684f,
9387 0x0040, 0x0040, 0xa286, 0x0001, 0x1118, 0x684f, 0x0080, 0x0010,
9388 0x684f, 0x0000, 0x20a9, 0x000a, 0x2001, 0xb290, 0xad90, 0x0015,
9389 0x200c, 0x810f, 0x2112, 0x8000, 0x8210, 0x1f04, 0xa178, 0x200c,
9390 0x6982, 0x8000, 0x200c, 0x697e, 0x080c, 0x510c, 0x002e, 0x004e,
9391 0x015e, 0x00fe, 0x00ee, 0x00de, 0x0005, 0x6013, 0x0100, 0x6003,
9392 0x0001, 0x6007, 0x0041, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0c70,
9393 0x2069, 0xb292, 0x2d04, 0xa084, 0xff00, 0xa086, 0x1200, 0x11a8,
9394 0x2069, 0xb280, 0x686c, 0xa084, 0x00ff, 0x0016, 0x6110, 0xa18c,
9395 0x0700, 0xa10d, 0x6112, 0x001e, 0x6003, 0x0001, 0x6007, 0x0043,
9396 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0888, 0x6013, 0x0200, 0x6003,
9397 0x0001, 0x6007, 0x0041, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0830,
9398 0x6013, 0x0300, 0x0010, 0x6013, 0x0100, 0x6003, 0x0001, 0x6007,
9399 0x0041, 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0804, 0xa186, 0x6013,
9400 0x0500, 0x0c98, 0x6013, 0x0600, 0x0818, 0x6013, 0x0200, 0x0800,
9401 0xa186, 0x0013, 0x1170, 0x6004, 0xa08a, 0x0040, 0x0a0c, 0x14f6,
9402 0xa08a, 0x0053, 0x1a0c, 0x14f6, 0xa082, 0x0040, 0x2008, 0x0804,
9403 0xa252, 0xa186, 0x0051, 0x0138, 0xa186, 0x0047, 0x11d8, 0x6004,
9404 0xa086, 0x0041, 0x0518, 0x2001, 0x0109, 0x2004, 0xd084, 0x01f0,
9405 0x0126, 0x2091, 0x2800, 0x0006, 0x0016, 0x0026, 0x080c, 0x6699,
9406 0x002e, 0x001e, 0x000e, 0x012e, 0x6000, 0xa086, 0x0002, 0x1170,
9407 0x0804, 0xa295, 0xa186, 0x0027, 0x0120, 0xa186, 0x0014, 0x190c,
9408 0x14f6, 0x6004, 0xa082, 0x0040, 0x2008, 0x001a, 0x080c, 0x80be,
9409 0x0005, 0xa22c, 0xa22e, 0xa22e, 0xa22c, 0xa22c, 0xa22c, 0xa22c,
9410 0xa22c, 0xa22c, 0xa22c, 0xa22c, 0xa22c, 0xa22c, 0xa22c, 0xa22c,
9411 0xa22c, 0xa22c, 0xa22c, 0xa22c, 0x080c, 0x14f6, 0x080c, 0x6b73,
9412 0x080c, 0x6c50, 0x0036, 0x00d6, 0x6010, 0xa06d, 0x01c0, 0xad84,
9413 0xf000, 0x01a8, 0x6003, 0x0002, 0x6018, 0x2004, 0xd0bc, 0x1178,
9414 0x2019, 0x0004, 0x080c, 0xa91f, 0x6013, 0x0000, 0x6014, 0xa005,
9415 0x1120, 0x2001, 0xafa4, 0x2004, 0x6016, 0x6003, 0x0007, 0x00de,
9416 0x003e, 0x0005, 0x0002, 0xa266, 0xa283, 0xa26f, 0xa28f, 0xa266,
9417 0xa266, 0xa266, 0xa266, 0xa266, 0xa266, 0xa266, 0xa266, 0xa266,
9418 0xa266, 0xa266, 0xa266, 0xa266, 0xa266, 0xa266, 0x080c, 0x14f6,
9419 0x6010, 0xa088, 0x0013, 0x2104, 0xa085, 0x0400, 0x200a, 0x080c,
9420 0x6b73, 0x6010, 0xa080, 0x0013, 0x2004, 0xd0b4, 0x0138, 0x6003,
9421 0x0007, 0x2009, 0x0043, 0x080c, 0x80a7, 0x0010, 0x6003, 0x0002,
9422 0x080c, 0x6c50, 0x0005, 0x080c, 0x6b73, 0x080c, 0xab55, 0x1120,
9423 0x080c, 0x6618, 0x080c, 0x8078, 0x080c, 0x6c50, 0x0005, 0x080c,
9424 0x6b73, 0x2009, 0x0041, 0x0804, 0xa3de, 0xa182, 0x0040, 0x0002,
9425 0xa2ab, 0xa2ad, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ae,
9426 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab, 0xa2ab,
9427 0xa2ab, 0xa2b9, 0xa2ab, 0x080c, 0x14f6, 0x0005, 0x6003, 0x0004,
9428 0x6110, 0x20e1, 0x0005, 0x3d18, 0x3e20, 0x2c10, 0x080c, 0x1824,
9429 0x0005, 0x00d6, 0x080c, 0x6618, 0x00de, 0x080c, 0xabb4, 0x080c,
9430 0x8078, 0x0005, 0xa182, 0x0040, 0x0002, 0xa2d8, 0xa2d8, 0xa2d8,
9431 0xa2d8, 0xa2d8, 0xa2d8, 0xa2d8, 0xa2da, 0xa2d8, 0xa2dd, 0xa316,
9432 0xa2d8, 0xa2d8, 0xa2d8, 0xa2d8, 0xa316, 0xa2d8, 0xa2d8, 0xa2d8,
9433 0x080c, 0x14f6, 0x080c, 0x80be, 0x0005, 0x2001, 0xad71, 0x2004,
9434 0xd0e4, 0x0158, 0x2001, 0x0100, 0x2004, 0xa082, 0x0005, 0x0228,
9435 0x2001, 0x011f, 0x2004, 0x6036, 0x0010, 0x6037, 0x0000, 0x080c,
9436 0x6c05, 0x080c, 0x6d0d, 0x6010, 0x00d6, 0x2068, 0x684c, 0xd0fc,
9437 0x0150, 0xa08c, 0x0003, 0xa18e, 0x0002, 0x0168, 0x2009, 0x0041,
9438 0x00de, 0x0804, 0xa3de, 0x6003, 0x0007, 0x6017, 0x0000, 0x080c,
9439 0x6618, 0x00de, 0x0005, 0x080c, 0xab55, 0x0110, 0x00de, 0x0005,
9440 0x080c, 0x6618, 0x080c, 0x8078, 0x00de, 0x0ca0, 0x0036, 0x080c,
9441 0x6c05, 0x080c, 0x6d0d, 0x6010, 0x00d6, 0x2068, 0x6018, 0x2004,
9442 0xd0bc, 0x0188, 0x684c, 0xa084, 0x0003, 0xa086, 0x0002, 0x0140,
9443 0x687c, 0x632c, 0xa31a, 0x632e, 0x6880, 0x6328, 0xa31b, 0x632a,
9444 0x6003, 0x0002, 0x0080, 0x2019, 0x0004, 0x080c, 0xa91f, 0x6014,
9445 0xa005, 0x1128, 0x2001, 0xafa4, 0x2004, 0x8003, 0x6016, 0x6013,
9446 0x0000, 0x6003, 0x0007, 0x00de, 0x003e, 0x0005, 0xa186, 0x0013,
9447 0x1150, 0x6004, 0xa086, 0x0042, 0x190c, 0x14f6, 0x080c, 0x6b73,
9448 0x080c, 0x6c50, 0x0005, 0xa186, 0x0027, 0x0118, 0xa186, 0x0014,
9449 0x1180, 0x6004, 0xa086, 0x0042, 0x190c, 0x14f6, 0x2001, 0x0007,
9450 0x080c, 0x4c5d, 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50,
9451 0x0005, 0xa182, 0x0040, 0x0002, 0xa37f, 0xa37f, 0xa37f, 0xa37f,
9452 0xa37f, 0xa37f, 0xa37f, 0xa381, 0xa38d, 0xa37f, 0xa37f, 0xa37f,
9453 0xa37f, 0xa37f, 0xa37f, 0xa37f, 0xa37f, 0xa37f, 0xa37f, 0x080c,
9454 0x14f6, 0x0036, 0x0046, 0x20e1, 0x0005, 0x3d18, 0x3e20, 0x2c10,
9455 0x080c, 0x1824, 0x004e, 0x003e, 0x0005, 0x6010, 0x00d6, 0x2068,
9456 0x6810, 0x6a14, 0x0006, 0x0046, 0x0056, 0x6c7c, 0xa422, 0x6d80,
9457 0x2200, 0xa52b, 0x602c, 0xa420, 0x642e, 0x6028, 0xa529, 0x652a,
9458 0x005e, 0x004e, 0x000e, 0xa20d, 0x1178, 0x684c, 0xd0fc, 0x0120,
9459 0x2009, 0x0041, 0x00de, 0x0490, 0x6003, 0x0007, 0x6017, 0x0000,
9460 0x080c, 0x6618, 0x00de, 0x0005, 0x0006, 0x00f6, 0x2c78, 0x080c,
9461 0x5029, 0x00fe, 0x000e, 0x0120, 0x6003, 0x0002, 0x00de, 0x0005,
9462 0x2009, 0xad0d, 0x210c, 0xd19c, 0x0118, 0x6003, 0x0007, 0x0010,
9463 0x6003, 0x0006, 0x0021, 0x080c, 0x661a, 0x00de, 0x0005, 0xd2fc,
9464 0x0140, 0x8002, 0x8000, 0x8212, 0xa291, 0x0000, 0x2009, 0x0009,
9465 0x0010, 0x2009, 0x0015, 0x6a6a, 0x6866, 0x0005, 0xa182, 0x0040,
9466 0x0208, 0x0062, 0xa186, 0x0013, 0x0120, 0xa186, 0x0014, 0x190c,
9467 0x14f6, 0x6020, 0xd0dc, 0x090c, 0x14f6, 0x0005, 0xa401, 0xa408,
9468 0xa414, 0xa420, 0xa401, 0xa401, 0xa401, 0xa42f, 0xa401, 0xa403,
9469 0xa403, 0xa401, 0xa401, 0xa401, 0xa401, 0xa403, 0xa401, 0xa403,
9470 0xa401, 0x080c, 0x14f6, 0x6020, 0xd0dc, 0x090c, 0x14f6, 0x0005,
9471 0x6003, 0x0001, 0x6106, 0x080c, 0x67a8, 0x0126, 0x2091, 0x8000,
9472 0x080c, 0x6c50, 0x012e, 0x0005, 0x6003, 0x0001, 0x6106, 0x080c,
9473 0x67a8, 0x0126, 0x2091, 0x8000, 0x080c, 0x6c50, 0x012e, 0x0005,
9474 0x6003, 0x0003, 0x6106, 0x2c10, 0x080c, 0x1e6e, 0x0126, 0x2091,
9475 0x8000, 0x080c, 0x680b, 0x080c, 0x6d0d, 0x012e, 0x0005, 0xa016,
9476 0x080c, 0x1824, 0x0005, 0x0126, 0x2091, 0x8000, 0x0036, 0x00d6,
9477 0xa182, 0x0040, 0x0023, 0x00de, 0x003e, 0x012e, 0x0005, 0xa44f,
9478 0xa451, 0xa463, 0xa47e, 0xa44f, 0xa44f, 0xa44f, 0xa493, 0xa44f,
9479 0xa44f, 0xa44f, 0xa44f, 0xa44f, 0xa44f, 0xa44f, 0xa44f, 0x080c,
9480 0x14f6, 0x6010, 0x2068, 0x684c, 0xd0fc, 0x01f8, 0xa09c, 0x0003,
9481 0xa39e, 0x0003, 0x01d0, 0x6003, 0x0001, 0x6106, 0x080c, 0x67a8,
9482 0x080c, 0x6c50, 0x0498, 0x6010, 0x2068, 0x684c, 0xd0fc, 0x0168,
9483 0xa09c, 0x0003, 0xa39e, 0x0003, 0x0140, 0x6003, 0x0001, 0x6106,
9484 0x080c, 0x67a8, 0x080c, 0x6c50, 0x0408, 0x6013, 0x0000, 0x6017,
9485 0x0000, 0x2019, 0x0004, 0x080c, 0xa91f, 0x00c0, 0x6010, 0x2068,
9486 0x684c, 0xd0fc, 0x0d90, 0xa09c, 0x0003, 0xa39e, 0x0003, 0x0d68,
9487 0x6003, 0x0003, 0x6106, 0x2c10, 0x080c, 0x1e6e, 0x080c, 0x680b,
9488 0x080c, 0x6d0d, 0x0018, 0xa016, 0x080c, 0x1824, 0x0005, 0x080c,
9489 0x6b73, 0x6110, 0x81ff, 0x0158, 0x00d6, 0x2168, 0x080c, 0xabfa,
9490 0x0036, 0x2019, 0x0029, 0x080c, 0xa91f, 0x003e, 0x00de, 0x080c,
9491 0x974e, 0x080c, 0x6c50, 0x0005, 0x080c, 0x6c05, 0x6110, 0x81ff,
9492 0x0158, 0x00d6, 0x2168, 0x080c, 0xabfa, 0x0036, 0x2019, 0x0029,
9493 0x080c, 0xa91f, 0x003e, 0x00de, 0x080c, 0x974e, 0x080c, 0x6d0d,
9494 0x0005, 0xa182, 0x0085, 0x0002, 0xa4cd, 0xa4cb, 0xa4cb, 0xa4d9,
9495 0xa4cb, 0xa4cb, 0xa4cb, 0x080c, 0x14f6, 0x6003, 0x000b, 0x6106,
9496 0x080c, 0x67a8, 0x0126, 0x2091, 0x8000, 0x080c, 0x6c50, 0x012e,
9497 0x0005, 0x0026, 0x00e6, 0x080c, 0xab4e, 0x0118, 0x080c, 0x8078,
9498 0x00c8, 0x2071, 0xb280, 0x7224, 0x6212, 0x7220, 0x080c, 0xa7ce,
9499 0x0118, 0x6007, 0x0086, 0x0040, 0x6007, 0x0087, 0x7224, 0xa296,
9500 0xffff, 0x1110, 0x6007, 0x0086, 0x6003, 0x0001, 0x080c, 0x67a8,
9501 0x080c, 0x6c50, 0x00ee, 0x002e, 0x0005, 0xa186, 0x0013, 0x1160,
9502 0x6004, 0xa08a, 0x0085, 0x0a0c, 0x14f6, 0xa08a, 0x008c, 0x1a0c,
9503 0x14f6, 0xa082, 0x0085, 0x00a2, 0xa186, 0x0027, 0x0130, 0xa186,
9504 0x0014, 0x0118, 0x080c, 0x80be, 0x0050, 0x2001, 0x0007, 0x080c,
9505 0x4c5d, 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005,
9506 0xa527, 0xa529, 0xa529, 0xa527, 0xa527, 0xa527, 0xa527, 0x080c,
9507 0x14f6, 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005,
9508 0xa182, 0x0085, 0x0a0c, 0x14f6, 0xa182, 0x008c, 0x1a0c, 0x14f6,
9509 0xa182, 0x0085, 0x0002, 0xa542, 0xa542, 0xa542, 0xa544, 0xa542,
9510 0xa542, 0xa542, 0x080c, 0x14f6, 0x0005, 0xa186, 0x0013, 0x0148,
9511 0xa186, 0x0014, 0x0130, 0xa186, 0x0027, 0x0118, 0x080c, 0x80be,
9512 0x0030, 0x080c, 0x6b73, 0x080c, 0x974e, 0x080c, 0x6c50, 0x0005,
9513 0x0036, 0x080c, 0xabb4, 0x603f, 0x0000, 0x2019, 0x000b, 0x0031,
9514 0x601f, 0x0006, 0x6003, 0x0007, 0x003e, 0x0005, 0x0126, 0x0036,
9515 0x2091, 0x8000, 0x0086, 0x2c40, 0x0096, 0x2049, 0x0000, 0x080c,
9516 0x7b9a, 0x009e, 0x008e, 0x1578, 0x0076, 0x2c38, 0x080c, 0x7c34,
9517 0x007e, 0x1548, 0x6000, 0xa086, 0x0000, 0x0528, 0x601c, 0xa086,
9518 0x0007, 0x0508, 0x00d6, 0x6000, 0xa086, 0x0004, 0x1150, 0x080c,
9519 0xabb4, 0x601f, 0x0007, 0x2001, 0xafa3, 0x2004, 0x6016, 0x080c,
9520 0x190b, 0x6010, 0x2068, 0x080c, 0x9596, 0x0110, 0x080c, 0xa91f,
9521 0x00de, 0x6013, 0x0000, 0x080c, 0xabb4, 0x601f, 0x0007, 0x2001,
9522 0xafa3, 0x2004, 0x6016, 0x003e, 0x012e, 0x0005, 0x00f6, 0x00c6,
9523 0x0036, 0x0156, 0x2079, 0xb280, 0x7938, 0x783c, 0x080c, 0x2676,
9524 0x1904, 0xa5f1, 0x0016, 0x00c6, 0x080c, 0x4cdc, 0x15c0, 0x2011,
9525 0xb290, 0xac98, 0x000a, 0x20a9, 0x0004, 0x080c, 0x8a7c, 0x1578,
9526 0x001e, 0x002e, 0x0026, 0x0016, 0x2019, 0x0029, 0x080c, 0x7cf4,
9527 0x080c, 0x68e7, 0x0076, 0x2039, 0x0000, 0x080c, 0x681d, 0x007e,
9528 0x001e, 0x0076, 0x2039, 0x0000, 0x080c, 0xa712, 0x007e, 0x080c,
9529 0x4ecf, 0x0026, 0x6204, 0xa294, 0xff00, 0x8217, 0xa286, 0x0006,
9530 0x0118, 0xa286, 0x0004, 0x1118, 0x62a0, 0x080c, 0x2b87, 0x002e,
9531 0x001e, 0x080c, 0x493a, 0x6612, 0x6516, 0xa006, 0x0010, 0x00ce,
9532 0x001e, 0x015e, 0x003e, 0x00ce, 0x00fe, 0x0005, 0x00c6, 0x00d6,
9533 0x00e6, 0x0016, 0x2009, 0xad20, 0x2104, 0xa086, 0x0074, 0x1904,
9534 0xa64b, 0x2069, 0xb28e, 0x690c, 0xa182, 0x0100, 0x06c0, 0x6908,
9535 0xa184, 0x8000, 0x05e8, 0x2001, 0xaf9d, 0x2004, 0xa005, 0x1160,
9536 0x6018, 0x2070, 0x7010, 0xa084, 0x00ff, 0x0118, 0x7000, 0xd0f4,
9537 0x0118, 0xa184, 0x0800, 0x0560, 0x6910, 0xa18a, 0x0001, 0x0610,
9538 0x6914, 0x2069, 0xb2ae, 0x6904, 0x81ff, 0x1198, 0x690c, 0xa182,
9539 0x0100, 0x02a8, 0x6908, 0x81ff, 0x1178, 0x6910, 0xa18a, 0x0001,
9540 0x0288, 0x6918, 0xa18a, 0x0001, 0x0298, 0x00d0, 0x6013, 0x0100,
9541 0x00a0, 0x6013, 0x0300, 0x0088, 0x6013, 0x0500, 0x0070, 0x6013,
9542 0x0700, 0x0058, 0x6013, 0x0900, 0x0040, 0x6013, 0x0b00, 0x0028,
9543 0x6013, 0x0f00, 0x0010, 0x6013, 0x2d00, 0xa085, 0x0001, 0x0008,
9544 0xa006, 0x001e, 0x00ee, 0x00de, 0x00ce, 0x0005, 0x00c6, 0x00d6,
9545 0x0026, 0x0036, 0x0156, 0x6218, 0x2268, 0x6b04, 0xa394, 0x00ff,
9546 0xa286, 0x0006, 0x0190, 0xa286, 0x0004, 0x0178, 0xa394, 0xff00,
9547 0x8217, 0xa286, 0x0006, 0x0148, 0xa286, 0x0004, 0x0130, 0x00c6,
9548 0x2d60, 0x080c, 0x4ceb, 0x00ce, 0x04c0, 0x2011, 0xb296, 0xad98,
9549 0x000a, 0x20a9, 0x0004, 0x080c, 0x8a7c, 0x1580, 0x2011, 0xb29a,
9550 0xad98, 0x0006, 0x20a9, 0x0004, 0x080c, 0x8a7c, 0x1538, 0x0046,
9551 0x0016, 0x6aa0, 0xa294, 0x00ff, 0x8227, 0xa006, 0x2009, 0xad52,
9552 0x210c, 0xd1a4, 0x0138, 0x2009, 0x0029, 0x080c, 0xa96c, 0x6800,
9553 0xc0e5, 0x6802, 0x2019, 0x0029, 0x080c, 0x68e7, 0x0076, 0x2039,
9554 0x0000, 0x080c, 0x681d, 0x2c08, 0x080c, 0xa712, 0x007e, 0x2001,
9555 0x0007, 0x080c, 0x4c5d, 0x001e, 0x004e, 0xa006, 0x015e, 0x003e,
9556 0x002e, 0x00de, 0x00ce, 0x0005, 0x00d6, 0x2069, 0xb28e, 0x6800,
9557 0xa086, 0x0800, 0x0118, 0x6013, 0x0000, 0x0008, 0xa006, 0x00de,
9558 0x0005, 0x00c6, 0x00f6, 0x0016, 0x0026, 0x0036, 0x0156, 0x2079,
9559 0xb28c, 0x7930, 0x7834, 0x080c, 0x2676, 0x11a0, 0x080c, 0x4cdc,
9560 0x1188, 0x2011, 0xb290, 0xac98, 0x000a, 0x20a9, 0x0004, 0x080c,
9561 0x8a7c, 0x1140, 0x2011, 0xb294, 0xac98, 0x0006, 0x20a9, 0x0004,
9562 0x080c, 0x8a7c, 0x015e, 0x003e, 0x002e, 0x001e, 0x00fe, 0x00ce,
9563 0x0005, 0x00c6, 0x0006, 0x0016, 0x0026, 0x0036, 0x0156, 0x2011,
9564 0xb283, 0x2204, 0x8211, 0x220c, 0x080c, 0x2676, 0x11a0, 0x080c,
9565 0x4cdc, 0x1188, 0x2011, 0xb296, 0xac98, 0x000a, 0x20a9, 0x0004,
9566 0x080c, 0x8a7c, 0x1140, 0x2011, 0xb29a, 0xac98, 0x0006, 0x20a9,
9567 0x0004, 0x080c, 0x8a7c, 0x015e, 0x003e, 0x002e, 0x001e, 0x000e,
9568 0x00ce, 0x0005, 0x00e6, 0x00c6, 0x0086, 0x0076, 0x0066, 0x0056,
9569 0x0046, 0x0026, 0x0126, 0x2091, 0x8000, 0x2740, 0x2029, 0xafd0,
9570 0x252c, 0x2021, 0xafd6, 0x2424, 0x2061, 0xb400, 0x2071, 0xad00,
9571 0x7644, 0x7064, 0x81ff, 0x0128, 0x8001, 0xa602, 0x1a04, 0xa78e,
9572 0x0018, 0xa606, 0x0904, 0xa78e, 0x2100, 0xac06, 0x0904, 0xa785,
9573 0x080c, 0xa990, 0x0904, 0xa785, 0x671c, 0xa786, 0x0001, 0x0904,
9574 0xa7a5, 0xa786, 0x0004, 0x0904, 0xa7a5, 0xa786, 0x0007, 0x05e8,
9575 0x2500, 0xac06, 0x05d0, 0x2400, 0xac06, 0x05b8, 0x080c, 0xa9a0,
9576 0x15a0, 0x88ff, 0x0118, 0x6050, 0xa906, 0x1578, 0x00d6, 0x6000,
9577 0xa086, 0x0004, 0x1120, 0x0016, 0x080c, 0x190b, 0x001e, 0xa786,
9578 0x0008, 0x1148, 0x080c, 0x9789, 0x1130, 0x080c, 0x85f3, 0x00de,
9579 0x080c, 0x974e, 0x00d0, 0x6010, 0x2068, 0x080c, 0x9596, 0x0190,
9580 0xa786, 0x0003, 0x1528, 0x6837, 0x0103, 0x6b4a, 0x6847, 0x0000,
9581 0x080c, 0xabfa, 0x0016, 0x080c, 0x97fd, 0x080c, 0x510c, 0x001e,
9582 0x080c, 0x9742, 0x00de, 0x080c, 0x974e, 0xace0, 0x0018, 0x2001,
9583 0xad16, 0x2004, 0xac02, 0x1210, 0x0804, 0xa726, 0x012e, 0x002e,
9584 0x004e, 0x005e, 0x006e, 0x007e, 0x008e, 0x00ce, 0x00ee, 0x0005,
9585 0xa786, 0x0006, 0x19c0, 0xa386, 0x0005, 0x0128, 0x080c, 0xabfa,
9586 0x080c, 0xa91f, 0x08f8, 0x00de, 0x0c00, 0x080c, 0xa9a0, 0x19e8,
9587 0x81ff, 0x09d8, 0xa180, 0x0001, 0x2004, 0xa086, 0x0018, 0x0130,
9588 0xa180, 0x0001, 0x2004, 0xa086, 0x002d, 0x1978, 0x6000, 0xa086,
9589 0x0002, 0x1958, 0x080c, 0x9778, 0x0130, 0x080c, 0x9789, 0x1928,
9590 0x080c, 0x85f3, 0x0038, 0x080c, 0x2aff, 0x080c, 0x9789, 0x1110,
9591 0x080c, 0x85f3, 0x080c, 0x974e, 0x0804, 0xa785, 0x00c6, 0x00e6,
9592 0x0016, 0x2c08, 0x2170, 0x080c, 0xa940, 0x001e, 0x0120, 0x601c,
9593 0xa084, 0x000f, 0x001b, 0x00ee, 0x00ce, 0x0005, 0xa7e6, 0xa7e6,
9594 0xa7e6, 0xa7e6, 0xa7e6, 0xa7e6, 0xa7e8, 0xa7e6, 0xa006, 0x0005,
9595 0x0046, 0x0016, 0x7018, 0xa080, 0x0028, 0x2024, 0xa4a4, 0x00ff,
9596 0x8427, 0x2c00, 0x2009, 0x0020, 0x080c, 0xa96c, 0x001e, 0x004e,
9597 0x0036, 0x2019, 0x0002, 0x080c, 0xa566, 0x003e, 0xa085, 0x0001,
9598 0x0005, 0x2001, 0x0001, 0x080c, 0x4c1e, 0x0156, 0x0016, 0x0026,
9599 0x0036, 0x20a9, 0x0004, 0x2019, 0xad05, 0x2011, 0xb296, 0x080c,
9600 0x8a7c, 0x003e, 0x002e, 0x001e, 0x015e, 0xa005, 0x0005, 0x00f6,
9601 0x00e6, 0x00c6, 0x0086, 0x0076, 0x0066, 0x0026, 0x0126, 0x2091,
9602 0x8000, 0x2740, 0x2061, 0xb400, 0x2079, 0x0001, 0x8fff, 0x0904,
9603 0xa875, 0x2071, 0xad00, 0x7644, 0x7064, 0x8001, 0xa602, 0x1a04,
9604 0xa875, 0x88ff, 0x0128, 0x2800, 0xac06, 0x15b0, 0x2079, 0x0000,
9605 0x080c, 0xa990, 0x0588, 0x2400, 0xac06, 0x0570, 0x671c, 0xa786,
9606 0x0006, 0x1550, 0xa786, 0x0007, 0x0538, 0x88ff, 0x1140, 0x6018,
9607 0xa206, 0x1510, 0x85ff, 0x0118, 0x6050, 0xa106, 0x11e8, 0x00d6,
9608 0x6000, 0xa086, 0x0004, 0x1150, 0x080c, 0xabb4, 0x601f, 0x0007,
9609 0x2001, 0xafa3, 0x2004, 0x6016, 0x080c, 0x190b, 0x6010, 0x2068,
9610 0x080c, 0x9596, 0x0120, 0x0046, 0x080c, 0xa91f, 0x004e, 0x00de,
9611 0x080c, 0x974e, 0x88ff, 0x1198, 0xace0, 0x0018, 0x2001, 0xad16,
9612 0x2004, 0xac02, 0x1210, 0x0804, 0xa826, 0xa006, 0x012e, 0x002e,
9613 0x006e, 0x007e, 0x008e, 0x00ce, 0x00ee, 0x00fe, 0x0005, 0xa8c5,
9614 0x0001, 0x0ca0, 0x0076, 0x0056, 0x0086, 0x2041, 0x0000, 0x2029,
9615 0x0001, 0x2c20, 0x2019, 0x0002, 0x6218, 0x0096, 0x2049, 0x0000,
9616 0x080c, 0x7b9a, 0x009e, 0x008e, 0x2039, 0x0000, 0x080c, 0x7c34,
9617 0x080c, 0xa817, 0x005e, 0x007e, 0x0005, 0x0026, 0x0046, 0x0056,
9618 0x0076, 0x00c6, 0x0156, 0x2c20, 0x2128, 0x20a9, 0x007f, 0x2009,
9619 0x0000, 0x0016, 0x0036, 0x080c, 0x4cdc, 0x11b0, 0x2c10, 0x0056,
9620 0x0086, 0x2041, 0x0000, 0x2508, 0x2029, 0x0001, 0x0096, 0x2049,
9621 0x0000, 0x080c, 0x7b9a, 0x009e, 0x008e, 0x2039, 0x0000, 0x080c,
9622 0x7c34, 0x080c, 0xa817, 0x005e, 0x003e, 0x001e, 0x8108, 0x1f04,
9623 0xa8a9, 0x015e, 0x00ce, 0x007e, 0x005e, 0x004e, 0x002e, 0x0005,
9624 0x0076, 0x0056, 0x6218, 0x0086, 0x2041, 0x0000, 0x2029, 0x0001,
9625 0x2019, 0x0048, 0x0096, 0x2049, 0x0000, 0x080c, 0x7b9a, 0x009e,
9626 0x008e, 0x2039, 0x0000, 0x080c, 0x7c34, 0x2c20, 0x080c, 0xa817,
9627 0x005e, 0x007e, 0x0005, 0x0026, 0x0046, 0x0056, 0x0076, 0x00c6,
9628 0x0156, 0x2c20, 0x20a9, 0x007f, 0x2009, 0x0000, 0x0016, 0x0036,
9629 0x080c, 0x4cdc, 0x11c0, 0x2c10, 0x0086, 0x2041, 0x0000, 0x2828,
9630 0x0046, 0x2021, 0x0001, 0x080c, 0xab96, 0x004e, 0x0096, 0x2049,
9631 0x0000, 0x080c, 0x7b9a, 0x009e, 0x008e, 0x2039, 0x0000, 0x080c,
9632 0x7c34, 0x080c, 0xa817, 0x003e, 0x001e, 0x8108, 0x1f04, 0xa8f6,
9633 0x015e, 0x00ce, 0x007e, 0x005e, 0x004e, 0x002e, 0x0005, 0x0016,
9634 0x00f6, 0x3800, 0xd08c, 0x0130, 0xad82, 0x1000, 0x02b0, 0xad82,
9635 0xad00, 0x0230, 0xad82, 0xe400, 0x0280, 0xad82, 0xffff, 0x1268,
9636 0x6800, 0xa07d, 0x0138, 0x6803, 0x0000, 0x6b52, 0x080c, 0x510c,
9637 0x2f68, 0x0cb0, 0x6b52, 0x080c, 0x510c, 0x00fe, 0x001e, 0x0005,
9638 0x00e6, 0x0046, 0x0036, 0x2061, 0xb400, 0x2071, 0xad00, 0x7444,
9639 0x7064, 0x8001, 0xa402, 0x12d8, 0x2100, 0xac06, 0x0168, 0x6000,
9640 0xa086, 0x0000, 0x0148, 0x6008, 0xa206, 0x1130, 0x6018, 0xa1a0,
9641 0x0006, 0x2424, 0xa406, 0x0140, 0xace0, 0x0018, 0x2001, 0xad16,
9642 0x2004, 0xac02, 0x1220, 0x0c08, 0xa085, 0x0001, 0x0008, 0xa006,
9643 0x003e, 0x004e, 0x00ee, 0x0005, 0x00d6, 0x0006, 0x080c, 0x15d9,
9644 0x000e, 0x090c, 0x14f6, 0x6837, 0x010d, 0x685e, 0x0026, 0x2010,
9645 0x080c, 0x9586, 0x2001, 0x0000, 0x0120, 0x2200, 0xa080, 0x0014,
9646 0x2004, 0x002e, 0x684a, 0x6956, 0x6c46, 0x684f, 0x0000, 0xa006,
9647 0x68b2, 0x6802, 0x683a, 0x685a, 0x080c, 0x510c, 0x00de, 0x0005,
9648 0x6700, 0xa786, 0x0000, 0x0158, 0xa786, 0x0001, 0x0140, 0xa786,
9649 0x000a, 0x0128, 0xa786, 0x0009, 0x0110, 0xa085, 0x0001, 0x0005,
9650 0x00e6, 0x6018, 0x2070, 0x70a0, 0xa206, 0x00ee, 0x0005, 0x0016,
9651 0x6004, 0xa08e, 0x001e, 0x11a0, 0x8007, 0x6130, 0xa18c, 0x00ff,
9652 0xa105, 0x6032, 0x6007, 0x0085, 0x6003, 0x000b, 0x601f, 0x0005,
9653 0x2001, 0xafa4, 0x2004, 0x6016, 0x080c, 0x67a8, 0x080c, 0x6c50,
9654 0x001e, 0x0005, 0xe000, 0xe000, 0x0005, 0x6020, 0xd0e4, 0x0158,
9655 0xd0cc, 0x0118, 0x080c, 0x9866, 0x0030, 0x080c, 0xabb4, 0x080c,
9656 0x6618, 0x080c, 0x8078, 0x0005, 0xa280, 0x0007, 0x2004, 0xa084,
9657 0x000f, 0x0002, 0xa9e3, 0xa9e3, 0xa9e3, 0xa9e8, 0xa9e3, 0xa9e5,
9658 0xa9e5, 0xa9e3, 0xa9e5, 0xa006, 0x0005, 0x00c6, 0x2260, 0x00ce,
9659 0xa085, 0x0001, 0x0005, 0xa280, 0x0007, 0x2004, 0xa084, 0x000f,
9660 0x0002, 0xa9fa, 0xa9fa, 0xa9fa, 0xa9fa, 0xa9fa, 0xa9fa, 0xaa05,
9661 0xa9fa, 0xa9fa, 0x6007, 0x003b, 0x602b, 0x0009, 0x6013, 0x2a00,
9662 0x6003, 0x0001, 0x080c, 0x67a8, 0x0005, 0x00c6, 0x2260, 0x080c,
9663 0xabb4, 0x603f, 0x0000, 0x6020, 0xc0f4, 0xc0cc, 0x6022, 0x6037,
9664 0x0000, 0x00ce, 0x00d6, 0x2268, 0xa186, 0x0007, 0x1904, 0xaa60,
9665 0x6810, 0xa005, 0x0138, 0xa080, 0x0013, 0x2004, 0xd0fc, 0x1110,
9666 0x00de, 0x08c0, 0x6007, 0x003a, 0x6003, 0x0001, 0x080c, 0x67a8,
9667 0x080c, 0x6c50, 0x00c6, 0x2d60, 0x6100, 0xa186, 0x0002, 0x1904,
9668 0xaae7, 0x6010, 0xa005, 0x1138, 0x6000, 0xa086, 0x0007, 0x190c,
9669 0x14f6, 0x0804, 0xaae7, 0xa08c, 0xf000, 0x1130, 0x0028, 0x2068,
9670 0x6800, 0xa005, 0x1de0, 0x2d00, 0xa080, 0x0013, 0x2004, 0xa084,
9671 0x0003, 0xa086, 0x0002, 0x1180, 0x6010, 0x2068, 0x684c, 0xc0dc,
9672 0xc0f4, 0x684e, 0x6850, 0xc0f4, 0xc0fc, 0x6852, 0x2009, 0x0043,
9673 0x080c, 0xa3de, 0x0804, 0xaae7, 0x2009, 0x0041, 0x0804, 0xaae1,
9674 0xa186, 0x0005, 0x15f0, 0x6810, 0xa080, 0x0013, 0x2004, 0xd0bc,
9675 0x1118, 0x00de, 0x0804, 0xa9fa, 0xd0b4, 0x0128, 0xd0fc, 0x090c,
9676 0x14f6, 0x0804, 0xaa18, 0x6007, 0x003a, 0x6003, 0x0001, 0x080c,
9677 0x67a8, 0x080c, 0x6c50, 0x00c6, 0x2d60, 0x6100, 0xa186, 0x0002,
9678 0x0120, 0xa186, 0x0004, 0x1904, 0xaae7, 0x2071, 0xaffd, 0x7000,
9679 0xa086, 0x0003, 0x1128, 0x7004, 0xac06, 0x1110, 0x7003, 0x0000,
9680 0x6810, 0xa080, 0x0013, 0x200c, 0xc1f4, 0xc1dc, 0x2102, 0x8000,
9681 0x200c, 0xc1f4, 0xc1fc, 0xc1bc, 0x2102, 0x2009, 0x0042, 0x0804,
9682 0xaae1, 0x0036, 0x00d6, 0x00d6, 0x080c, 0x15d9, 0x003e, 0x090c,
9683 0x14f6, 0x6837, 0x010d, 0x6803, 0x0000, 0x683b, 0x0000, 0x685b,
9684 0x0000, 0x6b5e, 0x6857, 0x0045, 0x2c00, 0x6862, 0x6034, 0x6872,
9685 0x2360, 0x6020, 0xc0dd, 0x6022, 0x6018, 0xa080, 0x0028, 0x2004,
9686 0xa084, 0x00ff, 0x8007, 0x6350, 0x6b4a, 0x6846, 0x684f, 0x0000,
9687 0x6d6a, 0x6e66, 0x686f, 0x0001, 0x080c, 0x510c, 0x2019, 0x0045,
9688 0x6008, 0x2068, 0x080c, 0xa566, 0x2d00, 0x600a, 0x601f, 0x0006,
9689 0x6003, 0x0007, 0x6017, 0x0000, 0x603f, 0x0000, 0x00de, 0x003e,
9690 0x0038, 0x603f, 0x0000, 0x6003, 0x0007, 0x080c, 0xa3de, 0x00ce,
9691 0x00de, 0x0005, 0xa186, 0x0013, 0x1128, 0x6004, 0xa082, 0x0085,
9692 0x2008, 0x00c2, 0xa186, 0x0027, 0x1178, 0x080c, 0x6b73, 0x0036,
9693 0x00d6, 0x6010, 0x2068, 0x2019, 0x0004, 0x080c, 0xa91f, 0x00de,
9694 0x003e, 0x080c, 0x6c50, 0x0005, 0xa186, 0x0014, 0x0d70, 0x080c,
9695 0x80be, 0x0005, 0xab13, 0xab11, 0xab11, 0xab11, 0xab11, 0xab11,
9696 0xab13, 0x080c, 0x14f6, 0x080c, 0x6b73, 0x6003, 0x000c, 0x080c,
9697 0x6c50, 0x0005, 0xa182, 0x008c, 0x1220, 0xa182, 0x0085, 0x0208,
9698 0x001a, 0x080c, 0x80be, 0x0005, 0xab2b, 0xab2b, 0xab2b, 0xab2b,
9699 0xab2d, 0xab4b, 0xab2b, 0x080c, 0x14f6, 0x00d6, 0x2c68, 0x080c,
9700 0x8022, 0x01a0, 0x6003, 0x0001, 0x6007, 0x001e, 0x2009, 0xb28e,
9701 0x210c, 0x6136, 0x2009, 0xb28f, 0x210c, 0x613a, 0x600b, 0xffff,
9702 0x6918, 0x611a, 0x601f, 0x0004, 0x080c, 0x67a8, 0x2d60, 0x080c,
9703 0x8078, 0x00de, 0x0005, 0x080c, 0x8078, 0x0005, 0x00e6, 0x6018,
9704 0x2070, 0x7000, 0xd0ec, 0x00ee, 0x0005, 0x6010, 0xa080, 0x0013,
9705 0x200c, 0xd1ec, 0x05d0, 0x2001, 0xad71, 0x2004, 0xd0ec, 0x05a8,
9706 0x6003, 0x0002, 0x6020, 0xc0e5, 0x6022, 0xd1ac, 0x0180, 0x00f6,
9707 0x2c78, 0x080c, 0x5025, 0x00fe, 0x0150, 0x2001, 0xafa5, 0x2004,
9708 0x603e, 0x2009, 0xad71, 0x210c, 0xd1f4, 0x11e8, 0x0080, 0x2009,
9709 0xad71, 0x210c, 0xd1f4, 0x0128, 0x6020, 0xc0e4, 0x6022, 0xa006,
9710 0x00a0, 0x2001, 0xafa5, 0x200c, 0x8103, 0xa100, 0x603e, 0x6018,
9711 0xa088, 0x002b, 0x2104, 0xa005, 0x0118, 0xa088, 0x0003, 0x0cd0,
9712 0x2c0a, 0x600f, 0x0000, 0xa085, 0x0001, 0x0005, 0x0016, 0x00c6,
9713 0x00e6, 0x6150, 0xa2f0, 0x002b, 0x2e04, 0x2060, 0x8cff, 0x0180,
9714 0x84ff, 0x1118, 0x6050, 0xa106, 0x1138, 0x600c, 0x2072, 0x080c,
9715 0x6618, 0x080c, 0x8078, 0x0010, 0xacf0, 0x0003, 0x2e64, 0x0c70,
9716 0x00ee, 0x00ce, 0x001e, 0x0005, 0x00d6, 0x6018, 0xa0e8, 0x002b,
9717 0x2d04, 0xa005, 0x0140, 0xac06, 0x0120, 0x2d04, 0xa0e8, 0x0003,
9718 0x0cb8, 0x600c, 0x206a, 0x00de, 0x0005, 0x0026, 0x0036, 0x0156,
9719 0x2011, 0xad27, 0x2204, 0xa084, 0x00ff, 0x2019, 0xb28e, 0x2334,
9720 0xa636, 0x11d8, 0x8318, 0x2334, 0x2204, 0xa084, 0xff00, 0xa636,
9721 0x11a0, 0x2011, 0xb290, 0x6018, 0xa098, 0x000a, 0x20a9, 0x0004,
9722 0x080c, 0x8a7c, 0x1150, 0x2011, 0xb294, 0x6018, 0xa098, 0x0006,
9723 0x20a9, 0x0004, 0x080c, 0x8a7c, 0x1100, 0x015e, 0x003e, 0x002e,
9724 0x0005, 0x00e6, 0x2071, 0xad00, 0x080c, 0x48f5, 0x080c, 0x28fa,
9725 0x00ee, 0x0005, 0x00e6, 0x6018, 0x2070, 0x7000, 0xd0fc, 0x0108,
9726 0x0011, 0x00ee, 0x0005, 0x6850, 0xc0e5, 0x6852, 0x0005, 0x00e6,
9727 0x00c6, 0x0076, 0x0066, 0x0056, 0x0046, 0x0026, 0x0016, 0x0126,
9728 0x2091, 0x8000, 0x2029, 0xafd0, 0x252c, 0x2021, 0xafd6, 0x2424,
9729 0x2061, 0xb400, 0x2071, 0xad00, 0x7644, 0x7064, 0xa606, 0x0578,
9730 0x671c, 0xa786, 0x0001, 0x0118, 0xa786, 0x0008, 0x1500, 0x2500,
9731 0xac06, 0x01e8, 0x2400, 0xac06, 0x01d0, 0x080c, 0xa990, 0x01b8,
9732 0x080c, 0xa9a0, 0x11a0, 0x6000, 0xa086, 0x0004, 0x1120, 0x0016,
9733 0x080c, 0x190b, 0x001e, 0x080c, 0x9778, 0x1110, 0x080c, 0x2aff,
9734 0x080c, 0x9789, 0x1110, 0x080c, 0x85f3, 0x080c, 0x974e, 0xace0,
9735 0x0018, 0x2001, 0xad16, 0x2004, 0xac02, 0x1208, 0x0858, 0x012e,
9736 0x001e, 0x002e, 0x004e, 0x005e, 0x006e, 0x007e, 0x00ce, 0x00ee,
9737 0x0005, 0x0126, 0x0006, 0x00e6, 0x2091, 0x8000, 0x2071, 0xad40,
9738 0xd5a4, 0x0118, 0x7034, 0x8000, 0x7036, 0xd5b4, 0x0118, 0x7030,
9739 0x8000, 0x7032, 0xd5ac, 0x0118, 0x2071, 0xad4a, 0x0451, 0x00ee,
9740 0x000e, 0x012e, 0x0005, 0x0126, 0x0006, 0x00e6, 0x2091, 0x8000,
9741 0x2071, 0xad40, 0xd5a4, 0x0118, 0x7034, 0x8000, 0x7036, 0xd5b4,
9742 0x0118, 0x7030, 0x8000, 0x7032, 0xd5ac, 0x0118, 0x2071, 0xad4a,
9743 0x0081, 0x00ee, 0x000e, 0x012e, 0x0005, 0x0126, 0x0006, 0x00e6,
9744 0x2091, 0x8000, 0x2071, 0xad42, 0x0021, 0x00ee, 0x000e, 0x012e,
9745 0x0005, 0x2e04, 0x8000, 0x2072, 0x1220, 0x8e70, 0x2e04, 0x8000,
9746 0x2072, 0x0005, 0x00e6, 0x2071, 0xad40, 0x0c99, 0x00ee, 0x0005,
9747 0x00e6, 0x2071, 0xad44, 0x0c69, 0x00ee, 0x0005, 0x0001, 0x0002,
9748 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200,
9749 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0x8529
9750};
9751
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c
index 275ed9bd898c..d5fdcb9a8842 100644
--- a/drivers/scsi/sata_mv.c
+++ b/drivers/scsi/sata_mv.c
@@ -378,7 +378,6 @@ static struct scsi_host_template mv_sht = {
378 .name = DRV_NAME, 378 .name = DRV_NAME,
379 .ioctl = ata_scsi_ioctl, 379 .ioctl = ata_scsi_ioctl,
380 .queuecommand = ata_scsi_queuecmd, 380 .queuecommand = ata_scsi_queuecmd,
381 .eh_strategy_handler = ata_scsi_error,
382 .can_queue = MV_USE_Q_DEPTH, 381 .can_queue = MV_USE_Q_DEPTH,
383 .this_id = ATA_SHT_THIS_ID, 382 .this_id = ATA_SHT_THIS_ID,
384 .sg_tablesize = MV_MAX_SG_CT / 2, 383 .sg_tablesize = MV_MAX_SG_CT / 2,
@@ -748,7 +747,7 @@ static void mv_dump_all_regs(void __iomem *mmio_base, int port,
748 mv_dump_mem(mmio_base+0xf00, 0x4); 747 mv_dump_mem(mmio_base+0xf00, 0x4);
749 mv_dump_mem(mmio_base+0x1d00, 0x6c); 748 mv_dump_mem(mmio_base+0x1d00, 0x6c);
750 for (hc = start_hc; hc < start_hc + num_hcs; hc++) { 749 for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
751 hc_base = mv_hc_base(mmio_base, port >> MV_PORT_HC_SHIFT); 750 hc_base = mv_hc_base(mmio_base, hc);
752 DPRINTK("HC regs (HC %i):\n", hc); 751 DPRINTK("HC regs (HC %i):\n", hc);
753 mv_dump_mem(hc_base, 0x1c); 752 mv_dump_mem(hc_base, 0x1c);
754 } 753 }
@@ -1010,7 +1009,7 @@ static void mv_fill_sg(struct ata_queued_cmd *qc)
1010 1009
1011 pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff); 1010 pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff);
1012 pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16); 1011 pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
1013 pp->sg_tbl[i].flags_size = cpu_to_le32(len); 1012 pp->sg_tbl[i].flags_size = cpu_to_le32(len & 0xffff);
1014 1013
1015 sg_len -= len; 1014 sg_len -= len;
1016 addr += len; 1015 addr += len;
@@ -1350,7 +1349,6 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1350{ 1349{
1351 void __iomem *mmio = host_set->mmio_base; 1350 void __iomem *mmio = host_set->mmio_base;
1352 void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1351 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1353 struct ata_port *ap;
1354 struct ata_queued_cmd *qc; 1352 struct ata_queued_cmd *qc;
1355 u32 hc_irq_cause; 1353 u32 hc_irq_cause;
1356 int shift, port, port0, hard_port, handled; 1354 int shift, port, port0, hard_port, handled;
@@ -1373,25 +1371,32 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1373 1371
1374 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { 1372 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
1375 u8 ata_status = 0; 1373 u8 ata_status = 0;
1376 ap = host_set->ports[port]; 1374 struct ata_port *ap = host_set->ports[port];
1375 struct mv_port_priv *pp = ap->private_data;
1376
1377 hard_port = port & MV_PORT_MASK; /* range 0-3 */ 1377 hard_port = port & MV_PORT_MASK; /* range 0-3 */
1378 handled = 0; /* ensure ata_status is set if handled++ */ 1378 handled = 0; /* ensure ata_status is set if handled++ */
1379 1379
1380 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) { 1380 /* Note that DEV_IRQ might happen spuriously during EDMA,
1381 /* new CRPB on the queue; just one at a time until NCQ 1381 * and should be ignored in such cases. We could mask it,
1382 */ 1382 * but it's pretty rare and may not be worth the overhead.
1383 ata_status = mv_get_crpb_status(ap); 1383 */
1384 handled++; 1384 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
1385 } else if ((DEV_IRQ << hard_port) & hc_irq_cause) { 1385 /* EDMA: check for response queue interrupt */
1386 /* received ATA IRQ; read the status reg to clear INTRQ 1386 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) {
1387 */ 1387 ata_status = mv_get_crpb_status(ap);
1388 ata_status = readb((void __iomem *) 1388 handled = 1;
1389 }
1390 } else {
1391 /* PIO: check for device (drive) interrupt */
1392 if ((DEV_IRQ << hard_port) & hc_irq_cause) {
1393 ata_status = readb((void __iomem *)
1389 ap->ioaddr.status_addr); 1394 ap->ioaddr.status_addr);
1390 handled++; 1395 handled = 1;
1396 }
1391 } 1397 }
1392 1398
1393 if (ap && 1399 if (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))
1394 (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR)))
1395 continue; 1400 continue;
1396 1401
1397 err_mask = ac_err_mask(ata_status); 1402 err_mask = ac_err_mask(ata_status);
@@ -1403,12 +1408,12 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1403 if ((PORT0_ERR << shift) & relevant) { 1408 if ((PORT0_ERR << shift) & relevant) {
1404 mv_err_intr(ap); 1409 mv_err_intr(ap);
1405 err_mask |= AC_ERR_OTHER; 1410 err_mask |= AC_ERR_OTHER;
1406 handled++; 1411 handled = 1;
1407 } 1412 }
1408 1413
1409 if (handled && ap) { 1414 if (handled) {
1410 qc = ata_qc_from_tag(ap, ap->active_tag); 1415 qc = ata_qc_from_tag(ap, ap->active_tag);
1411 if (NULL != qc) { 1416 if (qc && (qc->flags & ATA_QCFLAG_ACTIVE)) {
1412 VPRINTK("port %u IRQ found for qc, " 1417 VPRINTK("port %u IRQ found for qc, "
1413 "ata_status 0x%x\n", port,ata_status); 1418 "ata_status 0x%x\n", port,ata_status);
1414 /* mark qc status appropriately */ 1419 /* mark qc status appropriately */
diff --git a/drivers/scsi/sata_nv.c b/drivers/scsi/sata_nv.c
index f77bf183dfab..9f553081b5e8 100644
--- a/drivers/scsi/sata_nv.c
+++ b/drivers/scsi/sata_nv.c
@@ -201,7 +201,6 @@ static struct scsi_host_template nv_sht = {
201 .name = DRV_NAME, 201 .name = DRV_NAME,
202 .ioctl = ata_scsi_ioctl, 202 .ioctl = ata_scsi_ioctl,
203 .queuecommand = ata_scsi_queuecmd, 203 .queuecommand = ata_scsi_queuecmd,
204 .eh_strategy_handler = ata_scsi_error,
205 .can_queue = ATA_DEF_QUEUE, 204 .can_queue = ATA_DEF_QUEUE,
206 .this_id = ATA_SHT_THIS_ID, 205 .this_id = ATA_SHT_THIS_ID,
207 .sg_tablesize = LIBATA_MAX_PRD, 206 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c
index cc928c68a479..7eb67a6bdc64 100644
--- a/drivers/scsi/sata_promise.c
+++ b/drivers/scsi/sata_promise.c
@@ -111,7 +111,6 @@ static struct scsi_host_template pdc_ata_sht = {
111 .name = DRV_NAME, 111 .name = DRV_NAME,
112 .ioctl = ata_scsi_ioctl, 112 .ioctl = ata_scsi_ioctl,
113 .queuecommand = ata_scsi_queuecmd, 113 .queuecommand = ata_scsi_queuecmd,
114 .eh_strategy_handler = ata_scsi_error,
115 .can_queue = ATA_DEF_QUEUE, 114 .can_queue = ATA_DEF_QUEUE,
116 .this_id = ATA_SHT_THIS_ID, 115 .this_id = ATA_SHT_THIS_ID,
117 .sg_tablesize = LIBATA_MAX_PRD, 116 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c
index 9ffe1ef0d205..886f3447dd48 100644
--- a/drivers/scsi/sata_qstor.c
+++ b/drivers/scsi/sata_qstor.c
@@ -132,7 +132,6 @@ static struct scsi_host_template qs_ata_sht = {
132 .name = DRV_NAME, 132 .name = DRV_NAME,
133 .ioctl = ata_scsi_ioctl, 133 .ioctl = ata_scsi_ioctl,
134 .queuecommand = ata_scsi_queuecmd, 134 .queuecommand = ata_scsi_queuecmd,
135 .eh_strategy_handler = ata_scsi_error,
136 .can_queue = ATA_DEF_QUEUE, 135 .can_queue = ATA_DEF_QUEUE,
137 .this_id = ATA_SHT_THIS_ID, 136 .this_id = ATA_SHT_THIS_ID,
138 .sg_tablesize = QS_MAX_PRD, 137 .sg_tablesize = QS_MAX_PRD,
diff --git a/drivers/scsi/sata_sil.c b/drivers/scsi/sata_sil.c
index 18c296c56899..106627299d55 100644
--- a/drivers/scsi/sata_sil.c
+++ b/drivers/scsi/sata_sil.c
@@ -146,7 +146,6 @@ static struct scsi_host_template sil_sht = {
146 .name = DRV_NAME, 146 .name = DRV_NAME,
147 .ioctl = ata_scsi_ioctl, 147 .ioctl = ata_scsi_ioctl,
148 .queuecommand = ata_scsi_queuecmd, 148 .queuecommand = ata_scsi_queuecmd,
149 .eh_strategy_handler = ata_scsi_error,
150 .can_queue = ATA_DEF_QUEUE, 149 .can_queue = ATA_DEF_QUEUE,
151 .this_id = ATA_SHT_THIS_ID, 150 .this_id = ATA_SHT_THIS_ID,
152 .sg_tablesize = LIBATA_MAX_PRD, 151 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c
index 068c98a4111b..f7264fd611c2 100644
--- a/drivers/scsi/sata_sil24.c
+++ b/drivers/scsi/sata_sil24.c
@@ -281,7 +281,6 @@ static struct scsi_host_template sil24_sht = {
281 .name = DRV_NAME, 281 .name = DRV_NAME,
282 .ioctl = ata_scsi_ioctl, 282 .ioctl = ata_scsi_ioctl,
283 .queuecommand = ata_scsi_queuecmd, 283 .queuecommand = ata_scsi_queuecmd,
284 .eh_strategy_handler = ata_scsi_error,
285 .can_queue = ATA_DEF_QUEUE, 284 .can_queue = ATA_DEF_QUEUE,
286 .this_id = ATA_SHT_THIS_ID, 285 .this_id = ATA_SHT_THIS_ID,
287 .sg_tablesize = LIBATA_MAX_PRD, 286 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_sis.c b/drivers/scsi/sata_sis.c
index acc8439dea23..728530df2e07 100644
--- a/drivers/scsi/sata_sis.c
+++ b/drivers/scsi/sata_sis.c
@@ -87,7 +87,6 @@ static struct scsi_host_template sis_sht = {
87 .name = DRV_NAME, 87 .name = DRV_NAME,
88 .ioctl = ata_scsi_ioctl, 88 .ioctl = ata_scsi_ioctl,
89 .queuecommand = ata_scsi_queuecmd, 89 .queuecommand = ata_scsi_queuecmd,
90 .eh_strategy_handler = ata_scsi_error,
91 .can_queue = ATA_DEF_QUEUE, 90 .can_queue = ATA_DEF_QUEUE,
92 .this_id = ATA_SHT_THIS_ID, 91 .this_id = ATA_SHT_THIS_ID,
93 .sg_tablesize = ATA_MAX_PRD, 92 .sg_tablesize = ATA_MAX_PRD,
diff --git a/drivers/scsi/sata_svw.c b/drivers/scsi/sata_svw.c
index 724f0ed6a52d..53b0d5c0a61f 100644
--- a/drivers/scsi/sata_svw.c
+++ b/drivers/scsi/sata_svw.c
@@ -290,7 +290,6 @@ static struct scsi_host_template k2_sata_sht = {
290 .name = DRV_NAME, 290 .name = DRV_NAME,
291 .ioctl = ata_scsi_ioctl, 291 .ioctl = ata_scsi_ioctl,
292 .queuecommand = ata_scsi_queuecmd, 292 .queuecommand = ata_scsi_queuecmd,
293 .eh_strategy_handler = ata_scsi_error,
294 .can_queue = ATA_DEF_QUEUE, 293 .can_queue = ATA_DEF_QUEUE,
295 .this_id = ATA_SHT_THIS_ID, 294 .this_id = ATA_SHT_THIS_ID,
296 .sg_tablesize = LIBATA_MAX_PRD, 295 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c
index ae70f60c7c0d..4139ad4b1df0 100644
--- a/drivers/scsi/sata_sx4.c
+++ b/drivers/scsi/sata_sx4.c
@@ -182,7 +182,6 @@ static struct scsi_host_template pdc_sata_sht = {
182 .name = DRV_NAME, 182 .name = DRV_NAME,
183 .ioctl = ata_scsi_ioctl, 183 .ioctl = ata_scsi_ioctl,
184 .queuecommand = ata_scsi_queuecmd, 184 .queuecommand = ata_scsi_queuecmd,
185 .eh_strategy_handler = ata_scsi_error,
186 .can_queue = ATA_DEF_QUEUE, 185 .can_queue = ATA_DEF_QUEUE,
187 .this_id = ATA_SHT_THIS_ID, 186 .this_id = ATA_SHT_THIS_ID,
188 .sg_tablesize = LIBATA_MAX_PRD, 187 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_uli.c b/drivers/scsi/sata_uli.c
index 7ac5a5f5a905..38b52bd3fa3f 100644
--- a/drivers/scsi/sata_uli.c
+++ b/drivers/scsi/sata_uli.c
@@ -81,7 +81,6 @@ static struct scsi_host_template uli_sht = {
81 .name = DRV_NAME, 81 .name = DRV_NAME,
82 .ioctl = ata_scsi_ioctl, 82 .ioctl = ata_scsi_ioctl,
83 .queuecommand = ata_scsi_queuecmd, 83 .queuecommand = ata_scsi_queuecmd,
84 .eh_strategy_handler = ata_scsi_error,
85 .can_queue = ATA_DEF_QUEUE, 84 .can_queue = ATA_DEF_QUEUE,
86 .this_id = ATA_SHT_THIS_ID, 85 .this_id = ATA_SHT_THIS_ID,
87 .sg_tablesize = LIBATA_MAX_PRD, 86 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_via.c b/drivers/scsi/sata_via.c
index 791bf652ba63..9e7ae4e0db32 100644
--- a/drivers/scsi/sata_via.c
+++ b/drivers/scsi/sata_via.c
@@ -94,7 +94,6 @@ static struct scsi_host_template svia_sht = {
94 .name = DRV_NAME, 94 .name = DRV_NAME,
95 .ioctl = ata_scsi_ioctl, 95 .ioctl = ata_scsi_ioctl,
96 .queuecommand = ata_scsi_queuecmd, 96 .queuecommand = ata_scsi_queuecmd,
97 .eh_strategy_handler = ata_scsi_error,
98 .can_queue = ATA_DEF_QUEUE, 97 .can_queue = ATA_DEF_QUEUE,
99 .this_id = ATA_SHT_THIS_ID, 98 .this_id = ATA_SHT_THIS_ID,
100 .sg_tablesize = LIBATA_MAX_PRD, 99 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/sata_vsc.c b/drivers/scsi/sata_vsc.c
index 836bbbb26ff2..8a29ce340b47 100644
--- a/drivers/scsi/sata_vsc.c
+++ b/drivers/scsi/sata_vsc.c
@@ -263,7 +263,6 @@ static struct scsi_host_template vsc_sata_sht = {
263 .name = DRV_NAME, 263 .name = DRV_NAME,
264 .ioctl = ata_scsi_ioctl, 264 .ioctl = ata_scsi_ioctl,
265 .queuecommand = ata_scsi_queuecmd, 265 .queuecommand = ata_scsi_queuecmd,
266 .eh_strategy_handler = ata_scsi_error,
267 .can_queue = ATA_DEF_QUEUE, 266 .can_queue = ATA_DEF_QUEUE,
268 .this_id = ATA_SHT_THIS_ID, 267 .this_id = ATA_SHT_THIS_ID,
269 .sg_tablesize = LIBATA_MAX_PRD, 268 .sg_tablesize = LIBATA_MAX_PRD,
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 6913b0623167..73994e2ac2cb 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -565,7 +565,8 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
565 /* 565 /*
566 * If SCSI-2 or lower, store the LUN value in cmnd. 566 * If SCSI-2 or lower, store the LUN value in cmnd.
567 */ 567 */
568 if (cmd->device->scsi_level <= SCSI_2) { 568 if (cmd->device->scsi_level <= SCSI_2 &&
569 cmd->device->scsi_level != SCSI_UNKNOWN) {
569 cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) | 570 cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) |
570 (cmd->device->lun << 5 & 0xe0); 571 (cmd->device->lun << 5 & 0xe0);
571 } 572 }
@@ -1243,7 +1244,7 @@ static int __init init_scsi(void)
1243 if (error) 1244 if (error)
1244 goto cleanup_sysctl; 1245 goto cleanup_sysctl;
1245 1246
1246 for_each_cpu(i) 1247 for_each_possible_cpu(i)
1247 INIT_LIST_HEAD(&per_cpu(scsi_done_q, i)); 1248 INIT_LIST_HEAD(&per_cpu(scsi_done_q, i));
1248 1249
1249 printk(KERN_NOTICE "SCSI subsystem initialized\n"); 1250 printk(KERN_NOTICE "SCSI subsystem initialized\n");
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 84c3937ae8fb..c750d3399a97 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -132,7 +132,9 @@ static struct {
132 {"CMD", "CRA-7280", NULL, BLIST_SPARSELUN}, /* CMD RAID Controller */ 132 {"CMD", "CRA-7280", NULL, BLIST_SPARSELUN}, /* CMD RAID Controller */
133 {"CNSI", "G7324", NULL, BLIST_SPARSELUN}, /* Chaparral G7324 RAID */ 133 {"CNSI", "G7324", NULL, BLIST_SPARSELUN}, /* Chaparral G7324 RAID */
134 {"CNSi", "G8324", NULL, BLIST_SPARSELUN}, /* Chaparral G8324 RAID */ 134 {"CNSi", "G8324", NULL, BLIST_SPARSELUN}, /* Chaparral G8324 RAID */
135 {"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN}, 135 {"COMPAQ", "ARRAY CONTROLLER", NULL, BLIST_SPARSELUN | BLIST_LARGELUN |
136 BLIST_MAX_512 | BLIST_REPORTLUN2}, /* Compaq RA4x00 */
137 {"COMPAQ", "LOGICAL VOLUME", NULL, BLIST_FORCELUN | BLIST_MAX_512}, /* Compaq RA4x00 */
136 {"COMPAQ", "CR3500", NULL, BLIST_FORCELUN}, 138 {"COMPAQ", "CR3500", NULL, BLIST_FORCELUN},
137 {"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD}, 139 {"COMPAQ", "MSA1000", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
138 {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD}, 140 {"COMPAQ", "MSA1000 VOLUME", NULL, BLIST_SPARSELUN | BLIST_NOSTARTONADD},
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 5f0fdfb2618c..1c75646f9689 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -1537,8 +1537,8 @@ int scsi_error_handler(void *data)
1537 * what we need to do to get it up and online again (if we can). 1537 * what we need to do to get it up and online again (if we can).
1538 * If we fail, we end up taking the thing offline. 1538 * If we fail, we end up taking the thing offline.
1539 */ 1539 */
1540 if (shost->hostt->eh_strategy_handler) 1540 if (shost->transportt->eh_strategy_handler)
1541 shost->hostt->eh_strategy_handler(shost); 1541 shost->transportt->eh_strategy_handler(shost);
1542 else 1542 else
1543 scsi_unjam_host(shost); 1543 scsi_unjam_host(shost);
1544 1544
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 36e930066649..a89aff61d3d8 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -158,180 +158,6 @@ int scsi_set_medium_removal(struct scsi_device *sdev, char state)
158EXPORT_SYMBOL(scsi_set_medium_removal); 158EXPORT_SYMBOL(scsi_set_medium_removal);
159 159
160/* 160/*
161 * This interface is deprecated - users should use the scsi generic (sg)
162 * interface instead, as this is a more flexible approach to performing
163 * generic SCSI commands on a device.
164 *
165 * The structure that we are passed should look like:
166 *
167 * struct sdata {
168 * unsigned int inlen; [i] Length of data to be written to device
169 * unsigned int outlen; [i] Length of data to be read from device
170 * unsigned char cmd[x]; [i] SCSI command (6 <= x <= 12).
171 * [o] Data read from device starts here.
172 * [o] On error, sense buffer starts here.
173 * unsigned char wdata[y]; [i] Data written to device starts here.
174 * };
175 * Notes:
176 * - The SCSI command length is determined by examining the 1st byte
177 * of the given command. There is no way to override this.
178 * - Data transfers are limited to PAGE_SIZE (4K on i386, 8K on alpha).
179 * - The length (x + y) must be at least OMAX_SB_LEN bytes long to
180 * accommodate the sense buffer when an error occurs.
181 * The sense buffer is truncated to OMAX_SB_LEN (16) bytes so that
182 * old code will not be surprised.
183 * - If a Unix error occurs (e.g. ENOMEM) then the user will receive
184 * a negative return and the Unix error code in 'errno'.
185 * If the SCSI command succeeds then 0 is returned.
186 * Positive numbers returned are the compacted SCSI error codes (4
187 * bytes in one int) where the lowest byte is the SCSI status.
188 * See the drivers/scsi/scsi.h file for more information on this.
189 *
190 */
191#define OMAX_SB_LEN 16 /* Old sense buffer length */
192
193int scsi_ioctl_send_command(struct scsi_device *sdev,
194 struct scsi_ioctl_command __user *sic)
195{
196 char *buf;
197 unsigned char cmd[MAX_COMMAND_SIZE];
198 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
199 char __user *cmd_in;
200 unsigned char opcode;
201 unsigned int inlen, outlen, cmdlen;
202 unsigned int needed, buf_needed;
203 int timeout, retries, result;
204 int data_direction;
205 gfp_t gfp_mask = GFP_KERNEL;
206
207 if (!sic)
208 return -EINVAL;
209
210 if (sdev->host->unchecked_isa_dma)
211 gfp_mask |= GFP_DMA;
212
213 /*
214 * Verify that we can read at least this much.
215 */
216 if (!access_ok(VERIFY_READ, sic, sizeof(Scsi_Ioctl_Command)))
217 return -EFAULT;
218
219 if(__get_user(inlen, &sic->inlen))
220 return -EFAULT;
221
222 if(__get_user(outlen, &sic->outlen))
223 return -EFAULT;
224
225 /*
226 * We do not transfer more than MAX_BUF with this interface.
227 * If the user needs to transfer more data than this, they
228 * should use scsi_generics (sg) instead.
229 */
230 if (inlen > MAX_BUF)
231 return -EINVAL;
232 if (outlen > MAX_BUF)
233 return -EINVAL;
234
235 cmd_in = sic->data;
236 if(get_user(opcode, cmd_in))
237 return -EFAULT;
238
239 needed = buf_needed = (inlen > outlen ? inlen : outlen);
240 if (buf_needed) {
241 buf_needed = (buf_needed + 511) & ~511;
242 if (buf_needed > MAX_BUF)
243 buf_needed = MAX_BUF;
244 buf = kzalloc(buf_needed, gfp_mask);
245 if (!buf)
246 return -ENOMEM;
247 if (inlen == 0) {
248 data_direction = DMA_FROM_DEVICE;
249 } else if (outlen == 0 ) {
250 data_direction = DMA_TO_DEVICE;
251 } else {
252 /*
253 * Can this ever happen?
254 */
255 data_direction = DMA_BIDIRECTIONAL;
256 }
257
258 } else {
259 buf = NULL;
260 data_direction = DMA_NONE;
261 }
262
263 /*
264 * Obtain the command from the user's address space.
265 */
266 cmdlen = COMMAND_SIZE(opcode);
267
268 result = -EFAULT;
269
270 if (!access_ok(VERIFY_READ, cmd_in, cmdlen + inlen))
271 goto error;
272
273 if(__copy_from_user(cmd, cmd_in, cmdlen))
274 goto error;
275
276 /*
277 * Obtain the data to be sent to the device (if any).
278 */
279
280 if(inlen && copy_from_user(buf, cmd_in + cmdlen, inlen))
281 goto error;
282
283 switch (opcode) {
284 case SEND_DIAGNOSTIC:
285 case FORMAT_UNIT:
286 timeout = FORMAT_UNIT_TIMEOUT;
287 retries = 1;
288 break;
289 case START_STOP:
290 timeout = START_STOP_TIMEOUT;
291 retries = NORMAL_RETRIES;
292 break;
293 case MOVE_MEDIUM:
294 timeout = MOVE_MEDIUM_TIMEOUT;
295 retries = NORMAL_RETRIES;
296 break;
297 case READ_ELEMENT_STATUS:
298 timeout = READ_ELEMENT_STATUS_TIMEOUT;
299 retries = NORMAL_RETRIES;
300 break;
301 case READ_DEFECT_DATA:
302 timeout = READ_DEFECT_DATA_TIMEOUT;
303 retries = 1;
304 break;
305 default:
306 timeout = IOCTL_NORMAL_TIMEOUT;
307 retries = NORMAL_RETRIES;
308 break;
309 }
310
311 result = scsi_execute(sdev, cmd, data_direction, buf, needed,
312 sense, timeout, retries, 0);
313
314 /*
315 * If there was an error condition, pass the info back to the user.
316 */
317 if (result) {
318 int sb_len = sizeof(*sense);
319
320 sb_len = (sb_len > OMAX_SB_LEN) ? OMAX_SB_LEN : sb_len;
321 if (copy_to_user(cmd_in, sense, sb_len))
322 result = -EFAULT;
323 } else {
324 if (outlen && copy_to_user(cmd_in, buf, outlen))
325 result = -EFAULT;
326 }
327
328error:
329 kfree(buf);
330 return result;
331}
332EXPORT_SYMBOL(scsi_ioctl_send_command);
333
334/*
335 * The scsi_ioctl_get_pci() function places into arg the value 161 * The scsi_ioctl_get_pci() function places into arg the value
336 * pci_dev::slot_name (8 characters) for the PCI device (if any). 162 * pci_dev::slot_name (8 characters) for the PCI device (if any).
337 * Returns: 0 on success 163 * Returns: 0 on success
@@ -409,7 +235,7 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
409 case SCSI_IOCTL_SEND_COMMAND: 235 case SCSI_IOCTL_SEND_COMMAND:
410 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) 236 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
411 return -EACCES; 237 return -EACCES;
412 return scsi_ioctl_send_command(sdev, arg); 238 return sg_scsi_ioctl(NULL, sdev->request_queue, NULL, arg);
413 case SCSI_IOCTL_DOORLOCK: 239 case SCSI_IOCTL_DOORLOCK:
414 return scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT); 240 return scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT);
415 case SCSI_IOCTL_DOORUNLOCK: 241 case SCSI_IOCTL_DOORUNLOCK:
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 8f010a314a3d..7b0f9a3810d2 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1479,6 +1479,8 @@ static inline int scsi_host_queue_ready(struct request_queue *q,
1479static void scsi_kill_request(struct request *req, request_queue_t *q) 1479static void scsi_kill_request(struct request *req, request_queue_t *q)
1480{ 1480{
1481 struct scsi_cmnd *cmd = req->special; 1481 struct scsi_cmnd *cmd = req->special;
1482 struct scsi_device *sdev = cmd->device;
1483 struct Scsi_Host *shost = sdev->host;
1482 1484
1483 blkdev_dequeue_request(req); 1485 blkdev_dequeue_request(req);
1484 1486
@@ -1491,6 +1493,19 @@ static void scsi_kill_request(struct request *req, request_queue_t *q)
1491 scsi_init_cmd_errh(cmd); 1493 scsi_init_cmd_errh(cmd);
1492 cmd->result = DID_NO_CONNECT << 16; 1494 cmd->result = DID_NO_CONNECT << 16;
1493 atomic_inc(&cmd->device->iorequest_cnt); 1495 atomic_inc(&cmd->device->iorequest_cnt);
1496
1497 /*
1498 * SCSI request completion path will do scsi_device_unbusy(),
1499 * bump busy counts. To bump the counters, we need to dance
1500 * with the locks as normal issue path does.
1501 */
1502 sdev->device_busy++;
1503 spin_unlock(sdev->request_queue->queue_lock);
1504 spin_lock(shost->host_lock);
1505 shost->host_busy++;
1506 spin_unlock(shost->host_lock);
1507 spin_lock(sdev->request_queue->queue_lock);
1508
1494 __scsi_done(cmd); 1509 __scsi_done(cmd);
1495} 1510}
1496 1511
diff --git a/drivers/scsi/scsi_sas_internal.h b/drivers/scsi/scsi_sas_internal.h
new file mode 100644
index 000000000000..d76e6e3d8ca5
--- /dev/null
+++ b/drivers/scsi/scsi_sas_internal.h
@@ -0,0 +1,38 @@
1#ifndef _SCSI_SAS_INTERNAL_H
2#define _SCSI_SAS_INTERNAL_H
3
4#define SAS_HOST_ATTRS 0
5#define SAS_PORT_ATTRS 17
6#define SAS_RPORT_ATTRS 7
7#define SAS_END_DEV_ATTRS 3
8#define SAS_EXPANDER_ATTRS 7
9
10struct sas_internal {
11 struct scsi_transport_template t;
12 struct sas_function_template *f;
13 struct sas_domain_function_template *dft;
14
15 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_rphy_attrs[SAS_RPORT_ATTRS];
18 struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS];
19 struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS];
20
21 struct transport_container phy_attr_cont;
22 struct transport_container rphy_attr_cont;
23 struct transport_container end_dev_attr_cont;
24 struct transport_container expander_attr_cont;
25
26 /*
27 * The array of null terminated pointers to attributes
28 * needed by scsi_sysfs.c
29 */
30 struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1];
31 struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1];
32 struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1];
33 struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1];
34 struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1];
35};
36#define to_sas_internal(tmpl) container_of(tmpl, struct sas_internal, t)
37
38#endif
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index f14945996ede..1a5474bd11a1 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -673,6 +673,7 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
673 case TYPE_MEDIUM_CHANGER: 673 case TYPE_MEDIUM_CHANGER:
674 case TYPE_ENCLOSURE: 674 case TYPE_ENCLOSURE:
675 case TYPE_COMM: 675 case TYPE_COMM:
676 case TYPE_RAID:
676 case TYPE_RBC: 677 case TYPE_RBC:
677 sdev->writeable = 1; 678 sdev->writeable = 1;
678 break; 679 break;
@@ -738,6 +739,13 @@ static int scsi_add_lun(struct scsi_device *sdev, char *inq_result, int *bflags)
738 sdev->select_no_atn = 1; 739 sdev->select_no_atn = 1;
739 740
740 /* 741 /*
742 * Maximum 512 sector transfer length
743 * broken RA4x00 Compaq Disk Array
744 */
745 if (*bflags & BLIST_MAX_512)
746 blk_queue_max_sectors(sdev->request_queue, 512);
747
748 /*
741 * Some devices may not want to have a start command automatically 749 * Some devices may not want to have a start command automatically
742 * issued when a device is added. 750 * issued when a device is added.
743 */ 751 */
@@ -1123,10 +1131,13 @@ static int scsi_report_lun_scan(struct scsi_target *starget, int bflags,
1123 * Also allow SCSI-2 if BLIST_REPORTLUN2 is set and host adapter does 1131 * Also allow SCSI-2 if BLIST_REPORTLUN2 is set and host adapter does
1124 * support more than 8 LUNs. 1132 * support more than 8 LUNs.
1125 */ 1133 */
1126 if ((bflags & BLIST_NOREPORTLUN) || 1134 if (bflags & BLIST_NOREPORTLUN)
1127 starget->scsi_level < SCSI_2 || 1135 return 1;
1128 (starget->scsi_level < SCSI_3 && 1136 if (starget->scsi_level < SCSI_2 &&
1129 (!(bflags & BLIST_REPORTLUN2) || shost->max_lun <= 8)) ) 1137 starget->scsi_level != SCSI_UNKNOWN)
1138 return 1;
1139 if (starget->scsi_level < SCSI_3 &&
1140 (!(bflags & BLIST_REPORTLUN2) || shost->max_lun <= 8))
1130 return 1; 1141 return 1;
1131 if (bflags & BLIST_NOLUN) 1142 if (bflags & BLIST_NOLUN)
1132 return 0; 1143 return 0;
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 8db656214b5c..95c5478dcdfd 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -34,6 +34,8 @@
34#include <scsi/scsi_cmnd.h> 34#include <scsi/scsi_cmnd.h>
35#include "scsi_priv.h" 35#include "scsi_priv.h"
36 36
37static int fc_queue_work(struct Scsi_Host *, struct work_struct *);
38
37/* 39/*
38 * Redefine so that we can have same named attributes in the 40 * Redefine so that we can have same named attributes in the
39 * sdev/starget/host objects. 41 * sdev/starget/host objects.
@@ -213,10 +215,8 @@ fc_bitfield_name_search(remote_port_roles, fc_remote_port_role_names)
213#define FC_MGMTSRVR_PORTID 0x00000a 215#define FC_MGMTSRVR_PORTID 0x00000a
214 216
215 217
216static void fc_shost_remove_rports(void *data);
217static void fc_timeout_deleted_rport(void *data); 218static void fc_timeout_deleted_rport(void *data);
218static void fc_scsi_scan_rport(void *data); 219static void fc_scsi_scan_rport(void *data);
219static void fc_rport_terminate(struct fc_rport *rport);
220 220
221/* 221/*
222 * Attribute counts pre object type... 222 * Attribute counts pre object type...
@@ -288,42 +288,58 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
288 struct class_device *cdev) 288 struct class_device *cdev)
289{ 289{
290 struct Scsi_Host *shost = dev_to_shost(dev); 290 struct Scsi_Host *shost = dev_to_shost(dev);
291 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
291 292
292 /* 293 /*
293 * Set default values easily detected by the midlayer as 294 * Set default values easily detected by the midlayer as
294 * failure cases. The scsi lldd is responsible for initializing 295 * failure cases. The scsi lldd is responsible for initializing
295 * all transport attributes to valid values per host. 296 * all transport attributes to valid values per host.
296 */ 297 */
297 fc_host_node_name(shost) = -1; 298 fc_host->node_name = -1;
298 fc_host_port_name(shost) = -1; 299 fc_host->port_name = -1;
299 fc_host_permanent_port_name(shost) = -1; 300 fc_host->permanent_port_name = -1;
300 fc_host_supported_classes(shost) = FC_COS_UNSPECIFIED; 301 fc_host->supported_classes = FC_COS_UNSPECIFIED;
301 memset(fc_host_supported_fc4s(shost), 0, 302 memset(fc_host->supported_fc4s, 0,
302 sizeof(fc_host_supported_fc4s(shost))); 303 sizeof(fc_host->supported_fc4s));
303 memset(fc_host_symbolic_name(shost), 0, 304 memset(fc_host->symbolic_name, 0,
304 sizeof(fc_host_symbolic_name(shost))); 305 sizeof(fc_host->symbolic_name));
305 fc_host_supported_speeds(shost) = FC_PORTSPEED_UNKNOWN; 306 fc_host->supported_speeds = FC_PORTSPEED_UNKNOWN;
306 fc_host_maxframe_size(shost) = -1; 307 fc_host->maxframe_size = -1;
307 memset(fc_host_serial_number(shost), 0, 308 memset(fc_host->serial_number, 0,
308 sizeof(fc_host_serial_number(shost))); 309 sizeof(fc_host->serial_number));
309 310
310 fc_host_port_id(shost) = -1; 311 fc_host->port_id = -1;
311 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; 312 fc_host->port_type = FC_PORTTYPE_UNKNOWN;
312 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; 313 fc_host->port_state = FC_PORTSTATE_UNKNOWN;
313 memset(fc_host_active_fc4s(shost), 0, 314 memset(fc_host->active_fc4s, 0,
314 sizeof(fc_host_active_fc4s(shost))); 315 sizeof(fc_host->active_fc4s));
315 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 316 fc_host->speed = FC_PORTSPEED_UNKNOWN;
316 fc_host_fabric_name(shost) = -1; 317 fc_host->fabric_name = -1;
317 318
318 fc_host_tgtid_bind_type(shost) = FC_TGTID_BIND_BY_WWPN; 319 fc_host->tgtid_bind_type = FC_TGTID_BIND_BY_WWPN;
319 320
320 INIT_LIST_HEAD(&fc_host_rports(shost)); 321 INIT_LIST_HEAD(&fc_host->rports);
321 INIT_LIST_HEAD(&fc_host_rport_bindings(shost)); 322 INIT_LIST_HEAD(&fc_host->rport_bindings);
322 fc_host_next_rport_number(shost) = 0; 323 fc_host->next_rport_number = 0;
323 fc_host_next_target_id(shost) = 0; 324 fc_host->next_target_id = 0;
324 325
325 fc_host_flags(shost) = 0; 326 snprintf(fc_host->work_q_name, KOBJ_NAME_LEN, "fc_wq_%d",
326 INIT_WORK(&fc_host_rport_del_work(shost), fc_shost_remove_rports, shost); 327 shost->host_no);
328 fc_host->work_q = create_singlethread_workqueue(
329 fc_host->work_q_name);
330 if (!fc_host->work_q)
331 return -ENOMEM;
332
333 snprintf(fc_host->devloss_work_q_name, KOBJ_NAME_LEN, "fc_dl_%d",
334 shost->host_no);
335 fc_host->devloss_work_q = create_singlethread_workqueue(
336 fc_host->devloss_work_q_name);
337 if (!fc_host->devloss_work_q) {
338 destroy_workqueue(fc_host->work_q);
339 fc_host->work_q = NULL;
340 return -ENOMEM;
341 }
342
327 return 0; 343 return 0;
328} 344}
329 345
@@ -879,9 +895,9 @@ store_fc_private_host_tgtid_bind_type(struct class_device *cdev,
879 while (!list_empty(&fc_host_rport_bindings(shost))) { 895 while (!list_empty(&fc_host_rport_bindings(shost))) {
880 get_list_head_entry(rport, 896 get_list_head_entry(rport,
881 &fc_host_rport_bindings(shost), peers); 897 &fc_host_rport_bindings(shost), peers);
882 spin_unlock_irqrestore(shost->host_lock, flags); 898 list_del(&rport->peers);
883 fc_rport_terminate(rport); 899 rport->port_state = FC_PORTSTATE_DELETED;
884 spin_lock_irqsave(shost->host_lock, flags); 900 fc_queue_work(shost, &rport->rport_delete_work);
885 } 901 }
886 spin_unlock_irqrestore(shost->host_lock, flags); 902 spin_unlock_irqrestore(shost->host_lock, flags);
887 } 903 }
@@ -1262,6 +1278,90 @@ void fc_release_transport(struct scsi_transport_template *t)
1262} 1278}
1263EXPORT_SYMBOL(fc_release_transport); 1279EXPORT_SYMBOL(fc_release_transport);
1264 1280
1281/**
1282 * fc_queue_work - Queue work to the fc_host workqueue.
1283 * @shost: Pointer to Scsi_Host bound to fc_host.
1284 * @work: Work to queue for execution.
1285 *
1286 * Return value:
1287 * 0 on success / != 0 for error
1288 **/
1289static int
1290fc_queue_work(struct Scsi_Host *shost, struct work_struct *work)
1291{
1292 if (unlikely(!fc_host_work_q(shost))) {
1293 printk(KERN_ERR
1294 "ERROR: FC host '%s' attempted to queue work, "
1295 "when no workqueue created.\n", shost->hostt->name);
1296 dump_stack();
1297
1298 return -EINVAL;
1299 }
1300
1301 return queue_work(fc_host_work_q(shost), work);
1302}
1303
1304/**
1305 * fc_flush_work - Flush a fc_host's workqueue.
1306 * @shost: Pointer to Scsi_Host bound to fc_host.
1307 **/
1308static void
1309fc_flush_work(struct Scsi_Host *shost)
1310{
1311 if (!fc_host_work_q(shost)) {
1312 printk(KERN_ERR
1313 "ERROR: FC host '%s' attempted to flush work, "
1314 "when no workqueue created.\n", shost->hostt->name);
1315 dump_stack();
1316 return;
1317 }
1318
1319 flush_workqueue(fc_host_work_q(shost));
1320}
1321
1322/**
1323 * fc_queue_devloss_work - Schedule work for the fc_host devloss workqueue.
1324 * @shost: Pointer to Scsi_Host bound to fc_host.
1325 * @work: Work to queue for execution.
1326 * @delay: jiffies to delay the work queuing
1327 *
1328 * Return value:
1329 * 0 on success / != 0 for error
1330 **/
1331static int
1332fc_queue_devloss_work(struct Scsi_Host *shost, struct work_struct *work,
1333 unsigned long delay)
1334{
1335 if (unlikely(!fc_host_devloss_work_q(shost))) {
1336 printk(KERN_ERR
1337 "ERROR: FC host '%s' attempted to queue work, "
1338 "when no workqueue created.\n", shost->hostt->name);
1339 dump_stack();
1340
1341 return -EINVAL;
1342 }
1343
1344 return queue_delayed_work(fc_host_devloss_work_q(shost), work, delay);
1345}
1346
1347/**
1348 * fc_flush_devloss - Flush a fc_host's devloss workqueue.
1349 * @shost: Pointer to Scsi_Host bound to fc_host.
1350 **/
1351static void
1352fc_flush_devloss(struct Scsi_Host *shost)
1353{
1354 if (!fc_host_devloss_work_q(shost)) {
1355 printk(KERN_ERR
1356 "ERROR: FC host '%s' attempted to flush work, "
1357 "when no workqueue created.\n", shost->hostt->name);
1358 dump_stack();
1359 return;
1360 }
1361
1362 flush_workqueue(fc_host_devloss_work_q(shost));
1363}
1364
1265 1365
1266/** 1366/**
1267 * fc_remove_host - called to terminate any fc_transport-related elements 1367 * fc_remove_host - called to terminate any fc_transport-related elements
@@ -1283,36 +1383,103 @@ void
1283fc_remove_host(struct Scsi_Host *shost) 1383fc_remove_host(struct Scsi_Host *shost)
1284{ 1384{
1285 struct fc_rport *rport, *next_rport; 1385 struct fc_rport *rport, *next_rport;
1386 struct workqueue_struct *work_q;
1387 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1286 1388
1287 /* Remove any remote ports */ 1389 /* Remove any remote ports */
1288 list_for_each_entry_safe(rport, next_rport, 1390 list_for_each_entry_safe(rport, next_rport,
1289 &fc_host_rports(shost), peers) 1391 &fc_host->rports, peers) {
1290 fc_rport_terminate(rport); 1392 list_del(&rport->peers);
1393 rport->port_state = FC_PORTSTATE_DELETED;
1394 fc_queue_work(shost, &rport->rport_delete_work);
1395 }
1396
1291 list_for_each_entry_safe(rport, next_rport, 1397 list_for_each_entry_safe(rport, next_rport,
1292 &fc_host_rport_bindings(shost), peers) 1398 &fc_host->rport_bindings, peers) {
1293 fc_rport_terminate(rport); 1399 list_del(&rport->peers);
1400 rport->port_state = FC_PORTSTATE_DELETED;
1401 fc_queue_work(shost, &rport->rport_delete_work);
1402 }
1403
1404 /* flush all scan work items */
1405 scsi_flush_work(shost);
1406
1407 /* flush all stgt delete, and rport delete work items, then kill it */
1408 if (fc_host->work_q) {
1409 work_q = fc_host->work_q;
1410 fc_host->work_q = NULL;
1411 destroy_workqueue(work_q);
1412 }
1413
1414 /* flush all devloss work items, then kill it */
1415 if (fc_host->devloss_work_q) {
1416 work_q = fc_host->devloss_work_q;
1417 fc_host->devloss_work_q = NULL;
1418 destroy_workqueue(work_q);
1419 }
1294} 1420}
1295EXPORT_SYMBOL(fc_remove_host); 1421EXPORT_SYMBOL(fc_remove_host);
1296 1422
1297/* 1423
1298 * fc_rport_tgt_remove - Removes the scsi target on the remote port 1424/**
1299 * @rport: The remote port to be operated on 1425 * fc_starget_delete - called to delete the scsi decendents of an rport
1300 */ 1426 * (target and all sdevs)
1427 *
1428 * @data: remote port to be operated on.
1429 **/
1301static void 1430static void
1302fc_rport_tgt_remove(struct fc_rport *rport) 1431fc_starget_delete(void *data)
1303{ 1432{
1433 struct fc_rport *rport = (struct fc_rport *)data;
1304 struct Scsi_Host *shost = rport_to_shost(rport); 1434 struct Scsi_Host *shost = rport_to_shost(rport);
1435 unsigned long flags;
1305 1436
1306 scsi_target_unblock(&rport->dev); 1437 scsi_target_unblock(&rport->dev);
1307 1438
1308 /* Stop anything on the workq */ 1439 spin_lock_irqsave(shost->host_lock, flags);
1309 if (!cancel_delayed_work(&rport->dev_loss_work)) 1440 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
1310 flush_scheduled_work(); 1441 spin_unlock_irqrestore(shost->host_lock, flags);
1311 scsi_flush_work(shost); 1442 if (!cancel_delayed_work(&rport->dev_loss_work))
1443 fc_flush_devloss(shost);
1444 spin_lock_irqsave(shost->host_lock, flags);
1445 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1446 }
1447 spin_unlock_irqrestore(shost->host_lock, flags);
1312 1448
1313 scsi_remove_target(&rport->dev); 1449 scsi_remove_target(&rport->dev);
1314} 1450}
1315 1451
1452
1453/**
1454 * fc_rport_final_delete - finish rport termination and delete it.
1455 *
1456 * @data: remote port to be deleted.
1457 **/
1458static void
1459fc_rport_final_delete(void *data)
1460{
1461 struct fc_rport *rport = (struct fc_rport *)data;
1462 struct device *dev = &rport->dev;
1463 struct Scsi_Host *shost = rport_to_shost(rport);
1464
1465 /* Delete SCSI target and sdevs */
1466 if (rport->scsi_target_id != -1)
1467 fc_starget_delete(data);
1468
1469 /*
1470 * if a scan is pending, flush the SCSI Host work_q so that
1471 * that we can reclaim the rport scan work element.
1472 */
1473 if (rport->flags & FC_RPORT_SCAN_PENDING)
1474 scsi_flush_work(shost);
1475
1476 transport_remove_device(dev);
1477 device_del(dev);
1478 transport_destroy_device(dev);
1479 put_device(&shost->shost_gendev);
1480}
1481
1482
1316/** 1483/**
1317 * fc_rport_create - allocates and creates a remote FC port. 1484 * fc_rport_create - allocates and creates a remote FC port.
1318 * @shost: scsi host the remote port is connected to. 1485 * @shost: scsi host the remote port is connected to.
@@ -1330,8 +1497,7 @@ struct fc_rport *
1330fc_rport_create(struct Scsi_Host *shost, int channel, 1497fc_rport_create(struct Scsi_Host *shost, int channel,
1331 struct fc_rport_identifiers *ids) 1498 struct fc_rport_identifiers *ids)
1332{ 1499{
1333 struct fc_host_attrs *fc_host = 1500 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1334 (struct fc_host_attrs *)shost->shost_data;
1335 struct fc_internal *fci = to_fc_internal(shost->transportt); 1501 struct fc_internal *fci = to_fc_internal(shost->transportt);
1336 struct fc_rport *rport; 1502 struct fc_rport *rport;
1337 struct device *dev; 1503 struct device *dev;
@@ -1360,6 +1526,8 @@ fc_rport_create(struct Scsi_Host *shost, int channel,
1360 1526
1361 INIT_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport, rport); 1527 INIT_WORK(&rport->dev_loss_work, fc_timeout_deleted_rport, rport);
1362 INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport); 1528 INIT_WORK(&rport->scan_work, fc_scsi_scan_rport, rport);
1529 INIT_WORK(&rport->stgt_delete_work, fc_starget_delete, rport);
1530 INIT_WORK(&rport->rport_delete_work, fc_rport_final_delete, rport);
1363 1531
1364 spin_lock_irqsave(shost->host_lock, flags); 1532 spin_lock_irqsave(shost->host_lock, flags);
1365 1533
@@ -1368,7 +1536,7 @@ fc_rport_create(struct Scsi_Host *shost, int channel,
1368 rport->scsi_target_id = fc_host->next_target_id++; 1536 rport->scsi_target_id = fc_host->next_target_id++;
1369 else 1537 else
1370 rport->scsi_target_id = -1; 1538 rport->scsi_target_id = -1;
1371 list_add_tail(&rport->peers, &fc_host_rports(shost)); 1539 list_add_tail(&rport->peers, &fc_host->rports);
1372 get_device(&shost->shost_gendev); 1540 get_device(&shost->shost_gendev);
1373 1541
1374 spin_unlock_irqrestore(shost->host_lock, flags); 1542 spin_unlock_irqrestore(shost->host_lock, flags);
@@ -1389,9 +1557,11 @@ fc_rport_create(struct Scsi_Host *shost, int channel,
1389 transport_add_device(dev); 1557 transport_add_device(dev);
1390 transport_configure_device(dev); 1558 transport_configure_device(dev);
1391 1559
1392 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) 1560 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
1393 /* initiate a scan of the target */ 1561 /* initiate a scan of the target */
1562 rport->flags |= FC_RPORT_SCAN_PENDING;
1394 scsi_queue_work(shost, &rport->scan_work); 1563 scsi_queue_work(shost, &rport->scan_work);
1564 }
1395 1565
1396 return rport; 1566 return rport;
1397 1567
@@ -1451,10 +1621,14 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1451 struct fc_rport_identifiers *ids) 1621 struct fc_rport_identifiers *ids)
1452{ 1622{
1453 struct fc_internal *fci = to_fc_internal(shost->transportt); 1623 struct fc_internal *fci = to_fc_internal(shost->transportt);
1624 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1454 struct fc_rport *rport; 1625 struct fc_rport *rport;
1455 unsigned long flags; 1626 unsigned long flags;
1456 int match = 0; 1627 int match = 0;
1457 1628
1629 /* ensure any stgt delete functions are done */
1630 fc_flush_work(shost);
1631
1458 /* 1632 /*
1459 * Search the list of "active" rports, for an rport that has been 1633 * Search the list of "active" rports, for an rport that has been
1460 * deleted, but we've held off the real delete while the target 1634 * deleted, but we've held off the real delete while the target
@@ -1462,12 +1636,12 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1462 */ 1636 */
1463 spin_lock_irqsave(shost->host_lock, flags); 1637 spin_lock_irqsave(shost->host_lock, flags);
1464 1638
1465 list_for_each_entry(rport, &fc_host_rports(shost), peers) { 1639 list_for_each_entry(rport, &fc_host->rports, peers) {
1466 1640
1467 if ((rport->port_state == FC_PORTSTATE_BLOCKED) && 1641 if ((rport->port_state == FC_PORTSTATE_BLOCKED) &&
1468 (rport->channel == channel)) { 1642 (rport->channel == channel)) {
1469 1643
1470 switch (fc_host_tgtid_bind_type(shost)) { 1644 switch (fc_host->tgtid_bind_type) {
1471 case FC_TGTID_BIND_BY_WWPN: 1645 case FC_TGTID_BIND_BY_WWPN:
1472 case FC_TGTID_BIND_NONE: 1646 case FC_TGTID_BIND_NONE:
1473 if (rport->port_name == ids->port_name) 1647 if (rport->port_name == ids->port_name)
@@ -1521,27 +1695,34 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1521 * transaction. 1695 * transaction.
1522 */ 1696 */
1523 if (!cancel_delayed_work(work)) 1697 if (!cancel_delayed_work(work))
1524 flush_scheduled_work(); 1698 fc_flush_devloss(shost);
1699
1700 spin_lock_irqsave(shost->host_lock, flags);
1701
1702 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1525 1703
1526 /* initiate a scan of the target */ 1704 /* initiate a scan of the target */
1705 rport->flags |= FC_RPORT_SCAN_PENDING;
1527 scsi_queue_work(shost, &rport->scan_work); 1706 scsi_queue_work(shost, &rport->scan_work);
1528 1707
1708 spin_unlock_irqrestore(shost->host_lock, flags);
1709
1529 return rport; 1710 return rport;
1530 } 1711 }
1531 } 1712 }
1532 } 1713 }
1533 1714
1534 /* Search the bindings array */ 1715 /* Search the bindings array */
1535 if (fc_host_tgtid_bind_type(shost) != FC_TGTID_BIND_NONE) { 1716 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
1536 1717
1537 /* search for a matching consistent binding */ 1718 /* search for a matching consistent binding */
1538 1719
1539 list_for_each_entry(rport, &fc_host_rport_bindings(shost), 1720 list_for_each_entry(rport, &fc_host->rport_bindings,
1540 peers) { 1721 peers) {
1541 if (rport->channel != channel) 1722 if (rport->channel != channel)
1542 continue; 1723 continue;
1543 1724
1544 switch (fc_host_tgtid_bind_type(shost)) { 1725 switch (fc_host->tgtid_bind_type) {
1545 case FC_TGTID_BIND_BY_WWPN: 1726 case FC_TGTID_BIND_BY_WWPN:
1546 if (rport->port_name == ids->port_name) 1727 if (rport->port_name == ids->port_name)
1547 match = 1; 1728 match = 1;
@@ -1559,8 +1740,7 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1559 } 1740 }
1560 1741
1561 if (match) { 1742 if (match) {
1562 list_move_tail(&rport->peers, 1743 list_move_tail(&rport->peers, &fc_host->rports);
1563 &fc_host_rports(shost));
1564 break; 1744 break;
1565 } 1745 }
1566 } 1746 }
@@ -1574,15 +1754,17 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1574 rport->roles = ids->roles; 1754 rport->roles = ids->roles;
1575 rport->port_state = FC_PORTSTATE_ONLINE; 1755 rport->port_state = FC_PORTSTATE_ONLINE;
1576 1756
1577 spin_unlock_irqrestore(shost->host_lock, flags);
1578
1579 if (fci->f->dd_fcrport_size) 1757 if (fci->f->dd_fcrport_size)
1580 memset(rport->dd_data, 0, 1758 memset(rport->dd_data, 0,
1581 fci->f->dd_fcrport_size); 1759 fci->f->dd_fcrport_size);
1582 1760
1583 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) 1761 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET) {
1584 /* initiate a scan of the target */ 1762 /* initiate a scan of the target */
1763 rport->flags |= FC_RPORT_SCAN_PENDING;
1585 scsi_queue_work(shost, &rport->scan_work); 1764 scsi_queue_work(shost, &rport->scan_work);
1765 }
1766
1767 spin_unlock_irqrestore(shost->host_lock, flags);
1586 1768
1587 return rport; 1769 return rport;
1588 } 1770 }
@@ -1597,30 +1779,6 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1597} 1779}
1598EXPORT_SYMBOL(fc_remote_port_add); 1780EXPORT_SYMBOL(fc_remote_port_add);
1599 1781
1600/*
1601 * fc_rport_terminate - this routine tears down and deallocates a remote port.
1602 * @rport: The remote port to be terminated
1603 *
1604 * Notes:
1605 * This routine assumes no locks are held on entry.
1606 */
1607static void
1608fc_rport_terminate(struct fc_rport *rport)
1609{
1610 struct Scsi_Host *shost = rport_to_shost(rport);
1611 struct device *dev = &rport->dev;
1612 unsigned long flags;
1613
1614 fc_rport_tgt_remove(rport);
1615
1616 transport_remove_device(dev);
1617 device_del(dev);
1618 transport_destroy_device(dev);
1619 spin_lock_irqsave(shost->host_lock, flags);
1620 list_del(&rport->peers);
1621 spin_unlock_irqrestore(shost->host_lock, flags);
1622 put_device(&shost->shost_gendev);
1623}
1624 1782
1625/** 1783/**
1626 * fc_remote_port_delete - notifies the fc transport that a remote 1784 * fc_remote_port_delete - notifies the fc transport that a remote
@@ -1675,20 +1833,39 @@ fc_rport_terminate(struct fc_rport *rport)
1675void 1833void
1676fc_remote_port_delete(struct fc_rport *rport) 1834fc_remote_port_delete(struct fc_rport *rport)
1677{ 1835{
1836 struct Scsi_Host *shost = rport_to_shost(rport);
1678 int timeout = rport->dev_loss_tmo; 1837 int timeout = rport->dev_loss_tmo;
1838 unsigned long flags;
1839
1840 /*
1841 * No need to flush the fc_host work_q's, as all adds are synchronous.
1842 *
1843 * We do need to reclaim the rport scan work element, so eventually
1844 * (in fc_rport_final_delete()) we'll flush the scsi host work_q if
1845 * there's still a scan pending.
1846 */
1847
1848 spin_lock_irqsave(shost->host_lock, flags);
1679 1849
1680 /* If no scsi target id mapping, delete it */ 1850 /* If no scsi target id mapping, delete it */
1681 if (rport->scsi_target_id == -1) { 1851 if (rport->scsi_target_id == -1) {
1682 fc_rport_terminate(rport); 1852 list_del(&rport->peers);
1853 rport->port_state = FC_PORTSTATE_DELETED;
1854 fc_queue_work(shost, &rport->rport_delete_work);
1855 spin_unlock_irqrestore(shost->host_lock, flags);
1683 return; 1856 return;
1684 } 1857 }
1685 1858
1859 rport->port_state = FC_PORTSTATE_BLOCKED;
1860
1861 rport->flags |= FC_RPORT_DEVLOSS_PENDING;
1862
1863 spin_unlock_irqrestore(shost->host_lock, flags);
1864
1686 scsi_target_block(&rport->dev); 1865 scsi_target_block(&rport->dev);
1687 1866
1688 /* cap the length the devices can be blocked until they are deleted */ 1867 /* cap the length the devices can be blocked until they are deleted */
1689 schedule_delayed_work(&rport->dev_loss_work, timeout * HZ); 1868 fc_queue_devloss_work(shost, &rport->dev_loss_work, timeout * HZ);
1690
1691 rport->port_state = FC_PORTSTATE_BLOCKED;
1692} 1869}
1693EXPORT_SYMBOL(fc_remote_port_delete); 1870EXPORT_SYMBOL(fc_remote_port_delete);
1694 1871
@@ -1716,8 +1893,7 @@ void
1716fc_remote_port_rolechg(struct fc_rport *rport, u32 roles) 1893fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
1717{ 1894{
1718 struct Scsi_Host *shost = rport_to_shost(rport); 1895 struct Scsi_Host *shost = rport_to_shost(rport);
1719 struct fc_host_attrs *fc_host = 1896 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1720 (struct fc_host_attrs *)shost->shost_data;
1721 unsigned long flags; 1897 unsigned long flags;
1722 int create = 0; 1898 int create = 0;
1723 1899
@@ -1729,10 +1905,11 @@ fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
1729 } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) 1905 } else if (!(rport->roles & FC_RPORT_ROLE_FCP_TARGET))
1730 create = 1; 1906 create = 1;
1731 } 1907 }
1732 spin_unlock_irqrestore(shost->host_lock, flags);
1733 1908
1734 rport->roles = roles; 1909 rport->roles = roles;
1735 1910
1911 spin_unlock_irqrestore(shost->host_lock, flags);
1912
1736 if (create) { 1913 if (create) {
1737 /* 1914 /*
1738 * There may have been a delete timer running on the 1915 * There may have been a delete timer running on the
@@ -1747,10 +1924,20 @@ fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
1747 * transaction. 1924 * transaction.
1748 */ 1925 */
1749 if (!cancel_delayed_work(&rport->dev_loss_work)) 1926 if (!cancel_delayed_work(&rport->dev_loss_work))
1750 flush_scheduled_work(); 1927 fc_flush_devloss(shost);
1928
1929 spin_lock_irqsave(shost->host_lock, flags);
1930 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1931 spin_unlock_irqrestore(shost->host_lock, flags);
1932
1933 /* ensure any stgt delete functions are done */
1934 fc_flush_work(shost);
1751 1935
1752 /* initiate a scan of the target */ 1936 /* initiate a scan of the target */
1937 spin_lock_irqsave(shost->host_lock, flags);
1938 rport->flags |= FC_RPORT_SCAN_PENDING;
1753 scsi_queue_work(shost, &rport->scan_work); 1939 scsi_queue_work(shost, &rport->scan_work);
1940 spin_unlock_irqrestore(shost->host_lock, flags);
1754 } 1941 }
1755} 1942}
1756EXPORT_SYMBOL(fc_remote_port_rolechg); 1943EXPORT_SYMBOL(fc_remote_port_rolechg);
@@ -1767,22 +1954,24 @@ fc_timeout_deleted_rport(void *data)
1767{ 1954{
1768 struct fc_rport *rport = (struct fc_rport *)data; 1955 struct fc_rport *rport = (struct fc_rport *)data;
1769 struct Scsi_Host *shost = rport_to_shost(rport); 1956 struct Scsi_Host *shost = rport_to_shost(rport);
1957 struct fc_host_attrs *fc_host = shost_to_fc_host(shost);
1770 unsigned long flags; 1958 unsigned long flags;
1771 1959
1772 spin_lock_irqsave(shost->host_lock, flags); 1960 spin_lock_irqsave(shost->host_lock, flags);
1773 1961
1962 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1963
1774 /* 1964 /*
1775 * If the port is ONLINE, then it came back, but was no longer an 1965 * If the port is ONLINE, then it came back. Validate it's still an
1776 * FCP target. Thus we need to tear down the scsi_target on it. 1966 * FCP target. If not, tear down the scsi_target on it.
1777 */ 1967 */
1778 if (rport->port_state == FC_PORTSTATE_ONLINE) { 1968 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
1779 spin_unlock_irqrestore(shost->host_lock, flags); 1969 !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
1780
1781 dev_printk(KERN_ERR, &rport->dev, 1970 dev_printk(KERN_ERR, &rport->dev,
1782 "blocked FC remote port time out: removing target\n"); 1971 "blocked FC remote port time out: no longer"
1783 1972 " a FCP target, removing starget\n");
1784 fc_rport_tgt_remove(rport); 1973 fc_queue_work(shost, &rport->stgt_delete_work);
1785 1974 spin_unlock_irqrestore(shost->host_lock, flags);
1786 return; 1975 return;
1787 } 1976 }
1788 1977
@@ -1793,11 +1982,13 @@ fc_timeout_deleted_rport(void *data)
1793 return; 1982 return;
1794 } 1983 }
1795 1984
1796 if (fc_host_tgtid_bind_type(shost) == FC_TGTID_BIND_NONE) { 1985 if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) {
1797 spin_unlock_irqrestore(shost->host_lock, flags); 1986 list_del(&rport->peers);
1987 rport->port_state = FC_PORTSTATE_DELETED;
1798 dev_printk(KERN_ERR, &rport->dev, 1988 dev_printk(KERN_ERR, &rport->dev,
1799 "blocked FC remote port time out: removing target\n"); 1989 "blocked FC remote port time out: removing target\n");
1800 fc_rport_terminate(rport); 1990 fc_queue_work(shost, &rport->rport_delete_work);
1991 spin_unlock_irqrestore(shost->host_lock, flags);
1801 return; 1992 return;
1802 } 1993 }
1803 1994
@@ -1805,7 +1996,7 @@ fc_timeout_deleted_rport(void *data)
1805 "blocked FC remote port time out: removing target and " 1996 "blocked FC remote port time out: removing target and "
1806 "saving binding\n"); 1997 "saving binding\n");
1807 1998
1808 list_move_tail(&rport->peers, &fc_host_rport_bindings(shost)); 1999 list_move_tail(&rport->peers, &fc_host->rport_bindings);
1809 2000
1810 /* 2001 /*
1811 * Note: We do not remove or clear the hostdata area. This allows 2002 * Note: We do not remove or clear the hostdata area. This allows
@@ -1819,10 +2010,10 @@ fc_timeout_deleted_rport(void *data)
1819 rport->maxframe_size = -1; 2010 rport->maxframe_size = -1;
1820 rport->supported_classes = FC_COS_UNSPECIFIED; 2011 rport->supported_classes = FC_COS_UNSPECIFIED;
1821 rport->roles = FC_RPORT_ROLE_UNKNOWN; 2012 rport->roles = FC_RPORT_ROLE_UNKNOWN;
1822 rport->port_state = FC_PORTSTATE_DELETED; 2013 rport->port_state = FC_PORTSTATE_NOTPRESENT;
1823 2014
1824 /* remove the identifiers that aren't used in the consisting binding */ 2015 /* remove the identifiers that aren't used in the consisting binding */
1825 switch (fc_host_tgtid_bind_type(shost)) { 2016 switch (fc_host->tgtid_bind_type) {
1826 case FC_TGTID_BIND_BY_WWPN: 2017 case FC_TGTID_BIND_BY_WWPN:
1827 rport->node_name = -1; 2018 rport->node_name = -1;
1828 rport->port_id = -1; 2019 rport->port_id = -1;
@@ -1843,17 +2034,8 @@ fc_timeout_deleted_rport(void *data)
1843 * As this only occurs if the remote port (scsi target) 2034 * As this only occurs if the remote port (scsi target)
1844 * went away and didn't come back - we'll remove 2035 * went away and didn't come back - we'll remove
1845 * all attached scsi devices. 2036 * all attached scsi devices.
1846 *
1847 * We'll schedule the shost work item to perform the actual removal
1848 * to avoid recursion in the different flush calls if we perform
1849 * the removal in each target - and there are lots of targets
1850 * whose timeouts fire at the same time.
1851 */ 2037 */
1852 2038 fc_queue_work(shost, &rport->stgt_delete_work);
1853 if ( !(fc_host_flags(shost) & FC_SHOST_RPORT_DEL_SCHEDULED)) {
1854 fc_host_flags(shost) |= FC_SHOST_RPORT_DEL_SCHEDULED;
1855 scsi_queue_work(shost, &fc_host_rport_del_work(shost));
1856 }
1857 2039
1858 spin_unlock_irqrestore(shost->host_lock, flags); 2040 spin_unlock_irqrestore(shost->host_lock, flags);
1859} 2041}
@@ -1870,44 +2052,18 @@ static void
1870fc_scsi_scan_rport(void *data) 2052fc_scsi_scan_rport(void *data)
1871{ 2053{
1872 struct fc_rport *rport = (struct fc_rport *)data; 2054 struct fc_rport *rport = (struct fc_rport *)data;
1873 2055 struct Scsi_Host *shost = rport_to_shost(rport);
1874 scsi_target_unblock(&rport->dev);
1875 scsi_scan_target(&rport->dev, rport->channel, rport->scsi_target_id,
1876 SCAN_WILD_CARD, 1);
1877}
1878
1879
1880/**
1881 * fc_shost_remove_rports - called to remove all rports that are marked
1882 * as in a deleted (not connected) state.
1883 *
1884 * @data: shost whose rports are to be looked at
1885 **/
1886static void
1887fc_shost_remove_rports(void *data)
1888{
1889 struct Scsi_Host *shost = (struct Scsi_Host *)data;
1890 struct fc_rport *rport, *next_rport;
1891 unsigned long flags; 2056 unsigned long flags;
1892 2057
1893 spin_lock_irqsave(shost->host_lock, flags); 2058 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
1894 while (fc_host_flags(shost) & FC_SHOST_RPORT_DEL_SCHEDULED) { 2059 (rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
1895 2060 scsi_target_unblock(&rport->dev);
1896 fc_host_flags(shost) &= ~FC_SHOST_RPORT_DEL_SCHEDULED; 2061 scsi_scan_target(&rport->dev, rport->channel,
1897 2062 rport->scsi_target_id, SCAN_WILD_CARD, 1);
1898restart_search:
1899 list_for_each_entry_safe(rport, next_rport,
1900 &fc_host_rport_bindings(shost), peers) {
1901 if (rport->port_state == FC_PORTSTATE_DELETED) {
1902 rport->port_state = FC_PORTSTATE_NOTPRESENT;
1903 spin_unlock_irqrestore(shost->host_lock, flags);
1904 fc_rport_tgt_remove(rport);
1905 spin_lock_irqsave(shost->host_lock, flags);
1906 goto restart_search;
1907 }
1908 }
1909
1910 } 2063 }
2064
2065 spin_lock_irqsave(shost->host_lock, flags);
2066 rport->flags &= ~FC_RPORT_SCAN_PENDING;
1911 spin_unlock_irqrestore(shost->host_lock, flags); 2067 spin_unlock_irqrestore(shost->host_lock, flags);
1912} 2068}
1913 2069
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 134c44c8538a..8b6d65e21bae 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -35,40 +35,7 @@
35#include <scsi/scsi_transport.h> 35#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_sas.h> 36#include <scsi/scsi_transport_sas.h>
37 37
38 38#include "scsi_sas_internal.h"
39#define SAS_HOST_ATTRS 0
40#define SAS_PORT_ATTRS 17
41#define SAS_RPORT_ATTRS 7
42#define SAS_END_DEV_ATTRS 3
43#define SAS_EXPANDER_ATTRS 7
44
45struct sas_internal {
46 struct scsi_transport_template t;
47 struct sas_function_template *f;
48
49 struct class_device_attribute private_host_attrs[SAS_HOST_ATTRS];
50 struct class_device_attribute private_phy_attrs[SAS_PORT_ATTRS];
51 struct class_device_attribute private_rphy_attrs[SAS_RPORT_ATTRS];
52 struct class_device_attribute private_end_dev_attrs[SAS_END_DEV_ATTRS];
53 struct class_device_attribute private_expander_attrs[SAS_EXPANDER_ATTRS];
54
55 struct transport_container phy_attr_cont;
56 struct transport_container rphy_attr_cont;
57 struct transport_container end_dev_attr_cont;
58 struct transport_container expander_attr_cont;
59
60 /*
61 * The array of null terminated pointers to attributes
62 * needed by scsi_sysfs.c
63 */
64 struct class_device_attribute *host_attrs[SAS_HOST_ATTRS + 1];
65 struct class_device_attribute *phy_attrs[SAS_PORT_ATTRS + 1];
66 struct class_device_attribute *rphy_attrs[SAS_RPORT_ATTRS + 1];
67 struct class_device_attribute *end_dev_attrs[SAS_END_DEV_ATTRS + 1];
68 struct class_device_attribute *expander_attrs[SAS_EXPANDER_ATTRS + 1];
69};
70#define to_sas_internal(tmpl) container_of(tmpl, struct sas_internal, t)
71
72struct sas_host_attrs { 39struct sas_host_attrs {
73 struct list_head rphy_list; 40 struct list_head rphy_list;
74 struct mutex lock; 41 struct mutex lock;
@@ -406,8 +373,6 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
406 if (!phy) 373 if (!phy)
407 return NULL; 374 return NULL;
408 375
409 get_device(parent);
410
411 phy->number = number; 376 phy->number = number;
412 377
413 device_initialize(&phy->dev); 378 device_initialize(&phy->dev);
@@ -459,10 +424,7 @@ EXPORT_SYMBOL(sas_phy_add);
459void sas_phy_free(struct sas_phy *phy) 424void sas_phy_free(struct sas_phy *phy)
460{ 425{
461 transport_destroy_device(&phy->dev); 426 transport_destroy_device(&phy->dev);
462 put_device(phy->dev.parent); 427 put_device(&phy->dev);
463 put_device(phy->dev.parent);
464 put_device(phy->dev.parent);
465 kfree(phy);
466} 428}
467EXPORT_SYMBOL(sas_phy_free); 429EXPORT_SYMBOL(sas_phy_free);
468 430
@@ -484,7 +446,7 @@ sas_phy_delete(struct sas_phy *phy)
484 transport_remove_device(dev); 446 transport_remove_device(dev);
485 device_del(dev); 447 device_del(dev);
486 transport_destroy_device(dev); 448 transport_destroy_device(dev);
487 put_device(dev->parent); 449 put_device(dev);
488} 450}
489EXPORT_SYMBOL(sas_phy_delete); 451EXPORT_SYMBOL(sas_phy_delete);
490 452
@@ -800,7 +762,6 @@ struct sas_rphy *sas_end_device_alloc(struct sas_phy *parent)
800 762
801 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); 763 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
802 if (!rdev) { 764 if (!rdev) {
803 put_device(&parent->dev);
804 return NULL; 765 return NULL;
805 } 766 }
806 767
@@ -836,7 +797,6 @@ struct sas_rphy *sas_expander_alloc(struct sas_phy *parent,
836 797
837 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); 798 rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
838 if (!rdev) { 799 if (!rdev) {
839 put_device(&parent->dev);
840 return NULL; 800 return NULL;
841 } 801 }
842 802
@@ -885,6 +845,8 @@ int sas_rphy_add(struct sas_rphy *rphy)
885 (identify->target_port_protocols & 845 (identify->target_port_protocols &
886 (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA))) 846 (SAS_PROTOCOL_SSP|SAS_PROTOCOL_STP|SAS_PROTOCOL_SATA)))
887 rphy->scsi_target_id = sas_host->next_target_id++; 847 rphy->scsi_target_id = sas_host->next_target_id++;
848 else if (identify->device_type == SAS_END_DEVICE)
849 rphy->scsi_target_id = -1;
888 mutex_unlock(&sas_host->lock); 850 mutex_unlock(&sas_host->lock);
889 851
890 if (identify->device_type == SAS_END_DEVICE && 852 if (identify->device_type == SAS_END_DEVICE &&
@@ -910,6 +872,7 @@ EXPORT_SYMBOL(sas_rphy_add);
910 */ 872 */
911void sas_rphy_free(struct sas_rphy *rphy) 873void sas_rphy_free(struct sas_rphy *rphy)
912{ 874{
875 struct device *dev = &rphy->dev;
913 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent); 876 struct Scsi_Host *shost = dev_to_shost(rphy->dev.parent->parent);
914 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost); 877 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
915 878
@@ -917,21 +880,9 @@ void sas_rphy_free(struct sas_rphy *rphy)
917 list_del(&rphy->list); 880 list_del(&rphy->list);
918 mutex_unlock(&sas_host->lock); 881 mutex_unlock(&sas_host->lock);
919 882
920 transport_destroy_device(&rphy->dev); 883 transport_destroy_device(dev);
921 put_device(rphy->dev.parent);
922 put_device(rphy->dev.parent);
923 put_device(rphy->dev.parent);
924 if (rphy->identify.device_type == SAS_END_DEVICE) {
925 struct sas_end_device *edev = rphy_to_end_device(rphy);
926
927 kfree(edev);
928 } else {
929 /* must be expander */
930 struct sas_expander_device *edev =
931 rphy_to_expander_device(rphy);
932 884
933 kfree(edev); 885 put_device(dev);
934 }
935} 886}
936EXPORT_SYMBOL(sas_rphy_free); 887EXPORT_SYMBOL(sas_rphy_free);
937 888
@@ -971,7 +922,7 @@ sas_rphy_delete(struct sas_rphy *rphy)
971 922
972 parent->rphy = NULL; 923 parent->rphy = NULL;
973 924
974 put_device(&parent->dev); 925 put_device(dev);
975} 926}
976EXPORT_SYMBOL(sas_rphy_delete); 927EXPORT_SYMBOL(sas_rphy_delete);
977 928
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 7405d0df95db..b098942445ec 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -748,6 +748,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
748 /* 748 /*
749 * most likely out of mem, but could also be a bad map 749 * most likely out of mem, but could also be a bad map
750 */ 750 */
751 sg_finish_rem_req(srp);
751 return -ENOMEM; 752 return -ENOMEM;
752 } else 753 } else
753 return 0; 754 return 0;
@@ -1044,7 +1045,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
1044 if (!sg_allow_access(opcode, sdp->device->type)) 1045 if (!sg_allow_access(opcode, sdp->device->type))
1045 return -EPERM; 1046 return -EPERM;
1046 } 1047 }
1047 return scsi_ioctl_send_command(sdp->device, p); 1048 return sg_scsi_ioctl(filp, sdp->device->request_queue, NULL, p);
1048 case SG_SET_DEBUG: 1049 case SG_SET_DEBUG:
1049 result = get_user(val, ip); 1050 result = get_user(val, ip);
1050 if (result) 1051 if (result)
@@ -1798,8 +1799,10 @@ sg_build_direct(Sg_request * srp, Sg_fd * sfp, int dxfer_len)
1798 res = st_map_user_pages(schp->buffer, mx_sc_elems, 1799 res = st_map_user_pages(schp->buffer, mx_sc_elems,
1799 (unsigned long)hp->dxferp, dxfer_len, 1800 (unsigned long)hp->dxferp, dxfer_len,
1800 (SG_DXFER_TO_DEV == hp->dxfer_direction) ? 1 : 0); 1801 (SG_DXFER_TO_DEV == hp->dxfer_direction) ? 1 : 0);
1801 if (res <= 0) 1802 if (res <= 0) {
1803 sg_remove_scat(schp);
1802 return 1; 1804 return 1;
1805 }
1803 schp->k_use_sg = res; 1806 schp->k_use_sg = res;
1804 schp->dio_in_use = 1; 1807 schp->dio_in_use = 1;
1805 hp->info |= SG_INFO_DIRECT_IO; 1808 hp->info |= SG_INFO_DIRECT_IO;
diff --git a/drivers/scsi/sym53c8xx_2/sym_defs.h b/drivers/scsi/sym53c8xx_2/sym_defs.h
index 3659dd7b9d76..defccc477d1e 100644
--- a/drivers/scsi/sym53c8xx_2/sym_defs.h
+++ b/drivers/scsi/sym53c8xx_2/sym_defs.h
@@ -40,7 +40,7 @@
40#ifndef SYM_DEFS_H 40#ifndef SYM_DEFS_H
41#define SYM_DEFS_H 41#define SYM_DEFS_H
42 42
43#define SYM_VERSION "2.2.2" 43#define SYM_VERSION "2.2.3"
44#define SYM_DRIVER_NAME "sym-" SYM_VERSION 44#define SYM_DRIVER_NAME "sym-" SYM_VERSION
45 45
46/* 46/*
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 1fffd2b3c654..9c83b4d39a26 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -134,66 +134,17 @@ static void sym2_setup_params(void)
134 } 134 }
135} 135}
136 136
137/*
138 * We used to try to deal with 64-bit BARs here, but don't any more.
139 * There are many parts of this driver which would need to be modified
140 * to handle a 64-bit base address, including scripts. I'm uncomfortable
141 * with making those changes when I have no way of testing it, so I'm
142 * just going to disable it.
143 *
144 * Note that some machines (eg HP rx8620 and Superdome) have bus addresses
145 * below 4GB and physical addresses above 4GB. These will continue to work.
146 */
147static int __devinit
148pci_get_base_address(struct pci_dev *pdev, int index, unsigned long *basep)
149{
150 u32 tmp;
151 unsigned long base;
152#define PCI_BAR_OFFSET(index) (PCI_BASE_ADDRESS_0 + (index<<2))
153
154 pci_read_config_dword(pdev, PCI_BAR_OFFSET(index++), &tmp);
155 base = tmp;
156 if ((tmp & 0x7) == PCI_BASE_ADDRESS_MEM_TYPE_64) {
157 pci_read_config_dword(pdev, PCI_BAR_OFFSET(index++), &tmp);
158 if (tmp > 0) {
159 dev_err(&pdev->dev,
160 "BAR %d is 64-bit, disabling\n", index - 1);
161 base = 0;
162 }
163 }
164
165 if ((base & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) {
166 base &= PCI_BASE_ADDRESS_IO_MASK;
167 } else {
168 base &= PCI_BASE_ADDRESS_MEM_MASK;
169 }
170
171 *basep = base;
172 return index;
173#undef PCI_BAR_OFFSET
174}
175
176static struct scsi_transport_template *sym2_transport_template = NULL; 137static struct scsi_transport_template *sym2_transport_template = NULL;
177 138
178/* 139/*
179 * Used by the eh thread to wait for command completion.
180 * It is allocated on the eh thread stack.
181 */
182struct sym_eh_wait {
183 struct completion done;
184 struct timer_list timer;
185 void (*old_done)(struct scsi_cmnd *);
186 int to_do;
187 int timed_out;
188};
189
190/*
191 * Driver private area in the SCSI command structure. 140 * Driver private area in the SCSI command structure.
192 */ 141 */
193struct sym_ucmd { /* Override the SCSI pointer structure */ 142struct sym_ucmd { /* Override the SCSI pointer structure */
194 dma_addr_t data_mapping; 143 dma_addr_t data_mapping;
195 u_char data_mapped; 144 unsigned char data_mapped;
196 struct sym_eh_wait *eh_wait; 145 unsigned char to_do; /* For error handling */
146 void (*old_done)(struct scsi_cmnd *); /* For error handling */
147 struct completion *eh_done; /* For error handling */
197}; 148};
198 149
199#define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp)) 150#define SYM_UCMD_PTR(cmd) ((struct sym_ucmd *)(&(cmd)->SCp))
@@ -514,8 +465,6 @@ static inline int sym_setup_cdb(struct sym_hcb *np, struct scsi_cmnd *cmd, struc
514 */ 465 */
515int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp) 466int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct sym_ccb *cp)
516{ 467{
517 struct sym_tcb *tp = &np->target[cp->target];
518 struct sym_lcb *lp = sym_lp(tp, cp->lun);
519 u32 lastp, goalp; 468 u32 lastp, goalp;
520 int dir; 469 int dir;
521 470
@@ -596,7 +545,7 @@ int sym_setup_data_and_start(struct sym_hcb *np, struct scsi_cmnd *cmd, struct s
596 /* 545 /*
597 * activate this job. 546 * activate this job.
598 */ 547 */
599 sym_start_next_ccbs(np, lp, 2); 548 sym_put_start_queue(np, cp);
600 return 0; 549 return 0;
601 550
602out_abort: 551out_abort:
@@ -751,80 +700,54 @@ static void sym53c8xx_timer(unsigned long npref)
751 * What we will do regarding the involved SCSI command. 700 * What we will do regarding the involved SCSI command.
752 */ 701 */
753#define SYM_EH_DO_IGNORE 0 702#define SYM_EH_DO_IGNORE 0
754#define SYM_EH_DO_COMPLETE 1
755#define SYM_EH_DO_WAIT 2 703#define SYM_EH_DO_WAIT 2
756 704
757/* 705/*
758 * Our general completion handler. 706 * scsi_done() alias when error recovery is in progress.
759 */ 707 */
760static void __sym_eh_done(struct scsi_cmnd *cmd, int timed_out) 708static void sym_eh_done(struct scsi_cmnd *cmd)
761{ 709{
762 struct sym_eh_wait *ep = SYM_UCMD_PTR(cmd)->eh_wait; 710 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
763 if (!ep) 711 BUILD_BUG_ON(sizeof(struct scsi_pointer) < sizeof(struct sym_ucmd));
764 return;
765
766 /* Try to avoid a race here (not 100% safe) */
767 if (!timed_out) {
768 ep->timed_out = 0;
769 if (ep->to_do == SYM_EH_DO_WAIT && !del_timer(&ep->timer))
770 return;
771 }
772 712
773 /* Revert everything */ 713 cmd->scsi_done = ucmd->old_done;
774 SYM_UCMD_PTR(cmd)->eh_wait = NULL;
775 cmd->scsi_done = ep->old_done;
776 714
777 /* Wake up the eh thread if it wants to sleep */ 715 if (ucmd->to_do == SYM_EH_DO_WAIT)
778 if (ep->to_do == SYM_EH_DO_WAIT) 716 complete(ucmd->eh_done);
779 complete(&ep->done);
780} 717}
781 718
782/* 719/*
783 * scsi_done() alias when error recovery is in progress.
784 */
785static void sym_eh_done(struct scsi_cmnd *cmd) { __sym_eh_done(cmd, 0); }
786
787/*
788 * Some timeout handler to avoid waiting too long.
789 */
790static void sym_eh_timeout(u_long p) { __sym_eh_done((struct scsi_cmnd *)p, 1); }
791
792/*
793 * Generic method for our eh processing. 720 * Generic method for our eh processing.
794 * The 'op' argument tells what we have to do. 721 * The 'op' argument tells what we have to do.
795 */ 722 */
796static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd) 723static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd)
797{ 724{
798 struct sym_hcb *np = SYM_SOFTC_PTR(cmd); 725 struct sym_hcb *np = SYM_SOFTC_PTR(cmd);
726 struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd);
727 struct Scsi_Host *host = cmd->device->host;
799 SYM_QUEHEAD *qp; 728 SYM_QUEHEAD *qp;
800 int to_do = SYM_EH_DO_IGNORE; 729 int to_do = SYM_EH_DO_IGNORE;
801 int sts = -1; 730 int sts = -1;
802 struct sym_eh_wait eh, *ep = &eh; 731 struct completion eh_done;
803 732
804 dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname); 733 dev_warn(&cmd->device->sdev_gendev, "%s operation started.\n", opname);
805 734
735 spin_lock_irq(host->host_lock);
806 /* This one is queued in some place -> to wait for completion */ 736 /* This one is queued in some place -> to wait for completion */
807 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { 737 FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) {
808 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq); 738 struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, link_ccbq);
809 if (cp->cmd == cmd) { 739 if (cp->cmd == cmd) {
810 to_do = SYM_EH_DO_WAIT; 740 to_do = SYM_EH_DO_WAIT;
811 goto prepare; 741 break;
812 } 742 }
813 } 743 }
814 744
815prepare: 745 if (to_do == SYM_EH_DO_WAIT) {
816 /* Prepare stuff to either ignore, complete or wait for completion */ 746 init_completion(&eh_done);
817 switch(to_do) { 747 ucmd->old_done = cmd->scsi_done;
818 default: 748 ucmd->eh_done = &eh_done;
819 case SYM_EH_DO_IGNORE: 749 wmb();
820 break;
821 case SYM_EH_DO_WAIT:
822 init_completion(&ep->done);
823 /* fall through */
824 case SYM_EH_DO_COMPLETE:
825 ep->old_done = cmd->scsi_done;
826 cmd->scsi_done = sym_eh_done; 750 cmd->scsi_done = sym_eh_done;
827 SYM_UCMD_PTR(cmd)->eh_wait = ep;
828 } 751 }
829 752
830 /* Try to proceed the operation we have been asked for */ 753 /* Try to proceed the operation we have been asked for */
@@ -851,29 +774,19 @@ prepare:
851 774
852 /* On error, restore everything and cross fingers :) */ 775 /* On error, restore everything and cross fingers :) */
853 if (sts) { 776 if (sts) {
854 SYM_UCMD_PTR(cmd)->eh_wait = NULL; 777 cmd->scsi_done = ucmd->old_done;
855 cmd->scsi_done = ep->old_done;
856 to_do = SYM_EH_DO_IGNORE; 778 to_do = SYM_EH_DO_IGNORE;
857 } 779 }
858 780
859 ep->to_do = to_do; 781 ucmd->to_do = to_do;
860 /* Complete the command with locks held as required by the driver */ 782 spin_unlock_irq(host->host_lock);
861 if (to_do == SYM_EH_DO_COMPLETE)
862 sym_xpt_done2(np, cmd, DID_ABORT);
863 783
864 /* Wait for completion with locks released, as required by kernel */
865 if (to_do == SYM_EH_DO_WAIT) { 784 if (to_do == SYM_EH_DO_WAIT) {
866 init_timer(&ep->timer); 785 if (!wait_for_completion_timeout(&eh_done, 5*HZ)) {
867 ep->timer.expires = jiffies + (5*HZ); 786 ucmd->to_do = SYM_EH_DO_IGNORE;
868 ep->timer.function = sym_eh_timeout; 787 wmb();
869 ep->timer.data = (u_long)cmd;
870 ep->timed_out = 1; /* Be pessimistic for once :) */
871 add_timer(&ep->timer);
872 spin_unlock_irq(np->s.host->host_lock);
873 wait_for_completion(&ep->done);
874 spin_lock_irq(np->s.host->host_lock);
875 if (ep->timed_out)
876 sts = -2; 788 sts = -2;
789 }
877 } 790 }
878 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname, 791 dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname,
879 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed"); 792 sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed");
@@ -886,46 +799,22 @@ prepare:
886 */ 799 */
887static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd) 800static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd)
888{ 801{
889 int rc; 802 return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
890
891 spin_lock_irq(cmd->device->host->host_lock);
892 rc = sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd);
893 spin_unlock_irq(cmd->device->host->host_lock);
894
895 return rc;
896} 803}
897 804
898static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd) 805static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd)
899{ 806{
900 int rc; 807 return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
901
902 spin_lock_irq(cmd->device->host->host_lock);
903 rc = sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd);
904 spin_unlock_irq(cmd->device->host->host_lock);
905
906 return rc;
907} 808}
908 809
909static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd) 810static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd)
910{ 811{
911 int rc; 812 return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
912
913 spin_lock_irq(cmd->device->host->host_lock);
914 rc = sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd);
915 spin_unlock_irq(cmd->device->host->host_lock);
916
917 return rc;
918} 813}
919 814
920static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd) 815static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd)
921{ 816{
922 int rc; 817 return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
923
924 spin_lock_irq(cmd->device->host->host_lock);
925 rc = sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd);
926 spin_unlock_irq(cmd->device->host->host_lock);
927
928 return rc;
929} 818}
930 819
931/* 820/*
@@ -944,15 +833,12 @@ static void sym_tune_dev_queuing(struct sym_tcb *tp, int lun, u_short reqtags)
944 if (reqtags > lp->s.scdev_depth) 833 if (reqtags > lp->s.scdev_depth)
945 reqtags = lp->s.scdev_depth; 834 reqtags = lp->s.scdev_depth;
946 835
947 lp->started_limit = reqtags ? reqtags : 2;
948 lp->started_max = 1;
949 lp->s.reqtags = reqtags; 836 lp->s.reqtags = reqtags;
950 837
951 if (reqtags != oldtags) { 838 if (reqtags != oldtags) {
952 dev_info(&tp->starget->dev, 839 dev_info(&tp->starget->dev,
953 "tagged command queuing %s, command queue depth %d.\n", 840 "tagged command queuing %s, command queue depth %d.\n",
954 lp->s.reqtags ? "enabled" : "disabled", 841 lp->s.reqtags ? "enabled" : "disabled", reqtags);
955 lp->started_limit);
956 } 842 }
957} 843}
958 844
@@ -1866,15 +1752,25 @@ static int __devinit sym_set_workarounds(struct sym_device *device)
1866static void __devinit 1752static void __devinit
1867sym_init_device(struct pci_dev *pdev, struct sym_device *device) 1753sym_init_device(struct pci_dev *pdev, struct sym_device *device)
1868{ 1754{
1869 int i; 1755 int i = 2;
1756 struct pci_bus_region bus_addr;
1870 1757
1871 device->host_id = SYM_SETUP_HOST_ID; 1758 device->host_id = SYM_SETUP_HOST_ID;
1872 device->pdev = pdev; 1759 device->pdev = pdev;
1873 1760
1874 i = pci_get_base_address(pdev, 1, &device->mmio_base); 1761 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1875 pci_get_base_address(pdev, i, &device->ram_base); 1762 device->mmio_base = bus_addr.start;
1763
1764 /*
1765 * If the BAR is 64-bit, resource 2 will be occupied by the
1766 * upper 32 bits
1767 */
1768 if (!pdev->resource[i].flags)
1769 i++;
1770 pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1771 device->ram_base = bus_addr.start;
1876 1772
1877#ifndef CONFIG_SCSI_SYM53C8XX_IOMAPPED 1773#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
1878 if (device->mmio_base) 1774 if (device->mmio_base)
1879 device->s.ioaddr = pci_iomap(pdev, 1, 1775 device->s.ioaddr = pci_iomap(pdev, 1,
1880 pci_resource_len(pdev, 1)); 1776 pci_resource_len(pdev, 1));
@@ -1978,7 +1874,8 @@ static struct scsi_host_template sym2_template = {
1978 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler, 1874 .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler,
1979 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler, 1875 .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler,
1980 .this_id = 7, 1876 .this_id = 7,
1981 .use_clustering = DISABLE_CLUSTERING, 1877 .use_clustering = ENABLE_CLUSTERING,
1878 .max_sectors = 0xFFFF,
1982#ifdef SYM_LINUX_PROC_INFO_SUPPORT 1879#ifdef SYM_LINUX_PROC_INFO_SUPPORT
1983 .proc_info = sym53c8xx_proc_info, 1880 .proc_info = sym53c8xx_proc_info,
1984 .proc_name = NAME53C8XX, 1881 .proc_name = NAME53C8XX,
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.h b/drivers/scsi/sym53c8xx_2/sym_glue.h
index cc92d0c70cd7..a446cda3f64c 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.h
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.h
@@ -68,7 +68,7 @@
68 */ 68 */
69#define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2) 69#define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
70 70
71#define SYM_OPT_HANDLE_DEVICE_QUEUEING 71#undef SYM_OPT_HANDLE_DEVICE_QUEUEING
72#define SYM_OPT_LIMIT_COMMAND_REORDERING 72#define SYM_OPT_LIMIT_COMMAND_REORDERING
73 73
74/* 74/*
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.c b/drivers/scsi/sym53c8xx_2/sym_hipd.c
index 60850cbe3a85..a671bdc07450 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.c
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.c
@@ -72,7 +72,10 @@ static void sym_printl_hex(u_char *p, int n)
72 72
73static void sym_print_msg(struct sym_ccb *cp, char *label, u_char *msg) 73static void sym_print_msg(struct sym_ccb *cp, char *label, u_char *msg)
74{ 74{
75 sym_print_addr(cp->cmd, "%s: ", label); 75 if (label)
76 sym_print_addr(cp->cmd, "%s: ", label);
77 else
78 sym_print_addr(cp->cmd, "");
76 79
77 spi_print_msg(msg); 80 spi_print_msg(msg);
78 printf("\n"); 81 printf("\n");
@@ -472,7 +475,7 @@ static int sym_getpciclock (struct sym_hcb *np)
472 * calculations more simple. 475 * calculations more simple.
473 */ 476 */
474#define _5M 5000000 477#define _5M 5000000
475static u32 div_10M[] = {2*_5M, 3*_5M, 4*_5M, 6*_5M, 8*_5M, 12*_5M, 16*_5M}; 478static const u32 div_10M[] = {2*_5M, 3*_5M, 4*_5M, 6*_5M, 8*_5M, 12*_5M, 16*_5M};
476 479
477/* 480/*
478 * Get clock factor and sync divisor for a given 481 * Get clock factor and sync divisor for a given
@@ -645,6 +648,37 @@ static void sym_save_initial_setting (struct sym_hcb *np)
645} 648}
646 649
647/* 650/*
651 * Set SCSI BUS mode.
652 * - LVD capable chips (895/895A/896/1010) report the current BUS mode
653 * through the STEST4 IO register.
654 * - For previous generation chips (825/825A/875), the user has to tell us
655 * how to check against HVD, since a 100% safe algorithm is not possible.
656 */
657static void sym_set_bus_mode(struct sym_hcb *np, struct sym_nvram *nvram)
658{
659 if (np->scsi_mode)
660 return;
661
662 np->scsi_mode = SMODE_SE;
663 if (np->features & (FE_ULTRA2|FE_ULTRA3))
664 np->scsi_mode = (np->sv_stest4 & SMODE);
665 else if (np->features & FE_DIFF) {
666 if (SYM_SETUP_SCSI_DIFF == 1) {
667 if (np->sv_scntl3) {
668 if (np->sv_stest2 & 0x20)
669 np->scsi_mode = SMODE_HVD;
670 } else if (nvram->type == SYM_SYMBIOS_NVRAM) {
671 if (!(INB(np, nc_gpreg) & 0x08))
672 np->scsi_mode = SMODE_HVD;
673 }
674 } else if (SYM_SETUP_SCSI_DIFF == 2)
675 np->scsi_mode = SMODE_HVD;
676 }
677 if (np->scsi_mode == SMODE_HVD)
678 np->rv_stest2 |= 0x20;
679}
680
681/*
648 * Prepare io register values used by sym_start_up() 682 * Prepare io register values used by sym_start_up()
649 * according to selected and supported features. 683 * according to selected and supported features.
650 */ 684 */
@@ -654,10 +688,7 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
654 u32 period; 688 u32 period;
655 int i; 689 int i;
656 690
657 /* 691 np->maxwide = (np->features & FE_WIDE) ? 1 : 0;
658 * Wide ?
659 */
660 np->maxwide = (np->features & FE_WIDE)? 1 : 0;
661 692
662 /* 693 /*
663 * Guess the frequency of the chip's clock. 694 * Guess the frequency of the chip's clock.
@@ -838,6 +869,7 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
838 * Get parity checking, host ID and verbose mode from NVRAM 869 * Get parity checking, host ID and verbose mode from NVRAM
839 */ 870 */
840 np->myaddr = 255; 871 np->myaddr = 255;
872 np->scsi_mode = 0;
841 sym_nvram_setup_host(shost, np, nvram); 873 sym_nvram_setup_host(shost, np, nvram);
842 874
843 /* 875 /*
@@ -854,33 +886,7 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
854 */ 886 */
855 sym_init_burst(np, burst_max); 887 sym_init_burst(np, burst_max);
856 888
857 /* 889 sym_set_bus_mode(np, nvram);
858 * Set SCSI BUS mode.
859 * - LVD capable chips (895/895A/896/1010) report the
860 * current BUS mode through the STEST4 IO register.
861 * - For previous generation chips (825/825A/875),
862 * user has to tell us how to check against HVD,
863 * since a 100% safe algorithm is not possible.
864 */
865 np->scsi_mode = SMODE_SE;
866 if (np->features & (FE_ULTRA2|FE_ULTRA3))
867 np->scsi_mode = (np->sv_stest4 & SMODE);
868 else if (np->features & FE_DIFF) {
869 if (SYM_SETUP_SCSI_DIFF == 1) {
870 if (np->sv_scntl3) {
871 if (np->sv_stest2 & 0x20)
872 np->scsi_mode = SMODE_HVD;
873 }
874 else if (nvram->type == SYM_SYMBIOS_NVRAM) {
875 if (!(INB(np, nc_gpreg) & 0x08))
876 np->scsi_mode = SMODE_HVD;
877 }
878 }
879 else if (SYM_SETUP_SCSI_DIFF == 2)
880 np->scsi_mode = SMODE_HVD;
881 }
882 if (np->scsi_mode == SMODE_HVD)
883 np->rv_stest2 |= 0x20;
884 890
885 /* 891 /*
886 * Set LED support from SCRIPTS. 892 * Set LED support from SCRIPTS.
@@ -973,8 +979,8 @@ static int sym_prepare_setting(struct Scsi_Host *shost, struct sym_hcb *np, stru
973 * 979 *
974 * Has to be called with interrupts disabled. 980 * Has to be called with interrupts disabled.
975 */ 981 */
976#ifndef CONFIG_SCSI_SYM53C8XX_IOMAPPED 982#ifdef CONFIG_SCSI_SYM53C8XX_MMIO
977static int sym_regtest (struct sym_hcb *np) 983static int sym_regtest(struct sym_hcb *np)
978{ 984{
979 register volatile u32 data; 985 register volatile u32 data;
980 /* 986 /*
@@ -992,20 +998,25 @@ static int sym_regtest (struct sym_hcb *np)
992#endif 998#endif
993 printf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n", 999 printf ("CACHE TEST FAILED: reg dstat-sstat2 readback %x.\n",
994 (unsigned) data); 1000 (unsigned) data);
995 return (0x10); 1001 return 0x10;
996 } 1002 }
997 return (0); 1003 return 0;
1004}
1005#else
1006static inline int sym_regtest(struct sym_hcb *np)
1007{
1008 return 0;
998} 1009}
999#endif 1010#endif
1000 1011
1001static int sym_snooptest (struct sym_hcb *np) 1012static int sym_snooptest(struct sym_hcb *np)
1002{ 1013{
1003 u32 sym_rd, sym_wr, sym_bk, host_rd, host_wr, pc, dstat; 1014 u32 sym_rd, sym_wr, sym_bk, host_rd, host_wr, pc, dstat;
1004 int i, err=0; 1015 int i, err;
1005#ifndef CONFIG_SCSI_SYM53C8XX_IOMAPPED 1016
1006 err |= sym_regtest (np); 1017 err = sym_regtest(np);
1007 if (err) return (err); 1018 if (err)
1008#endif 1019 return err;
1009restart_test: 1020restart_test:
1010 /* 1021 /*
1011 * Enable Master Parity Checking as we intend 1022 * Enable Master Parity Checking as we intend
@@ -1094,7 +1105,7 @@ restart_test:
1094 err |= 4; 1105 err |= 4;
1095 } 1106 }
1096 1107
1097 return (err); 1108 return err;
1098} 1109}
1099 1110
1100/* 1111/*
@@ -1464,7 +1475,7 @@ static int sym_prepare_nego(struct sym_hcb *np, struct sym_ccb *cp, u_char *msgp
1464/* 1475/*
1465 * Insert a job into the start queue. 1476 * Insert a job into the start queue.
1466 */ 1477 */
1467static void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp) 1478void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp)
1468{ 1479{
1469 u_short qidx; 1480 u_short qidx;
1470 1481
@@ -4481,7 +4492,7 @@ static void sym_int_sir (struct sym_hcb *np)
4481 switch (np->msgin [2]) { 4492 switch (np->msgin [2]) {
4482 case M_X_MODIFY_DP: 4493 case M_X_MODIFY_DP:
4483 if (DEBUG_FLAGS & DEBUG_POINTER) 4494 if (DEBUG_FLAGS & DEBUG_POINTER)
4484 sym_print_msg(cp,"modify DP",np->msgin); 4495 sym_print_msg(cp, NULL, np->msgin);
4485 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) + 4496 tmp = (np->msgin[3]<<24) + (np->msgin[4]<<16) +
4486 (np->msgin[5]<<8) + (np->msgin[6]); 4497 (np->msgin[5]<<8) + (np->msgin[6]);
4487 sym_modify_dp(np, tp, cp, tmp); 4498 sym_modify_dp(np, tp, cp, tmp);
@@ -4508,7 +4519,7 @@ static void sym_int_sir (struct sym_hcb *np)
4508 */ 4519 */
4509 case M_IGN_RESIDUE: 4520 case M_IGN_RESIDUE:
4510 if (DEBUG_FLAGS & DEBUG_POINTER) 4521 if (DEBUG_FLAGS & DEBUG_POINTER)
4511 sym_print_msg(cp,"ign wide residue", np->msgin); 4522 sym_print_msg(cp, NULL, np->msgin);
4512 if (cp->host_flags & HF_SENSE) 4523 if (cp->host_flags & HF_SENSE)
4513 OUTL_DSP(np, SCRIPTA_BA(np, clrack)); 4524 OUTL_DSP(np, SCRIPTA_BA(np, clrack));
4514 else 4525 else
@@ -4597,7 +4608,8 @@ struct sym_ccb *sym_get_ccb (struct sym_hcb *np, struct scsi_cmnd *cmd, u_char t
4597 * Debugging purpose. 4608 * Debugging purpose.
4598 */ 4609 */
4599#ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING 4610#ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4600 assert(lp->busy_itl == 0); 4611 if (lp->busy_itl != 0)
4612 goto out_free;
4601#endif 4613#endif
4602 /* 4614 /*
4603 * Allocate resources for tags if not yet. 4615 * Allocate resources for tags if not yet.
@@ -4642,7 +4654,8 @@ struct sym_ccb *sym_get_ccb (struct sym_hcb *np, struct scsi_cmnd *cmd, u_char t
4642 * Debugging purpose. 4654 * Debugging purpose.
4643 */ 4655 */
4644#ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING 4656#ifndef SYM_OPT_HANDLE_DEVICE_QUEUEING
4645 assert(lp->busy_itl == 0 && lp->busy_itlq == 0); 4657 if (lp->busy_itl != 0 || lp->busy_itlq != 0)
4658 goto out_free;
4646#endif 4659#endif
4647 /* 4660 /*
4648 * Count this nexus for this LUN. 4661 * Count this nexus for this LUN.
diff --git a/drivers/scsi/sym53c8xx_2/sym_hipd.h b/drivers/scsi/sym53c8xx_2/sym_hipd.h
index 2456090bb241..79ab6a177039 100644
--- a/drivers/scsi/sym53c8xx_2/sym_hipd.h
+++ b/drivers/scsi/sym53c8xx_2/sym_hipd.h
@@ -1049,6 +1049,8 @@ int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int);
1049struct sym_chip *sym_lookup_chip_table(u_short device_id, u_char revision); 1049struct sym_chip *sym_lookup_chip_table(u_short device_id, u_char revision);
1050#ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING 1050#ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1051void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn); 1051void sym_start_next_ccbs(struct sym_hcb *np, struct sym_lcb *lp, int maxn);
1052#else
1053void sym_put_start_queue(struct sym_hcb *np, struct sym_ccb *cp);
1052#endif 1054#endif
1053void sym_start_up(struct sym_hcb *np, int reason); 1055void sym_start_up(struct sym_hcb *np, int reason);
1054void sym_interrupt(struct sym_hcb *np); 1056void sym_interrupt(struct sym_hcb *np);
diff --git a/drivers/scsi/zalon.c b/drivers/scsi/zalon.c
index b131432c677d..a6cfbb3b361c 100644
--- a/drivers/scsi/zalon.c
+++ b/drivers/scsi/zalon.c
@@ -88,7 +88,7 @@ zalon_probe(struct parisc_device *dev)
88 struct gsc_irq gsc_irq; 88 struct gsc_irq gsc_irq;
89 u32 zalon_vers; 89 u32 zalon_vers;
90 int error = -ENODEV; 90 int error = -ENODEV;
91 void __iomem *zalon = ioremap(dev->hpa.start, 4096); 91 void __iomem *zalon = ioremap_nocache(dev->hpa.start, 4096);
92 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET; 92 void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
93 static int unit = 0; 93 static int unit = 0;
94 struct Scsi_Host *host; 94 struct Scsi_Host *host;
diff --git a/drivers/serial/8250_gsc.c b/drivers/serial/8250_gsc.c
index 8b4947933d9b..913c71cc0569 100644
--- a/drivers/serial/8250_gsc.c
+++ b/drivers/serial/8250_gsc.c
@@ -52,13 +52,14 @@ serial_init_chip(struct parisc_device *dev)
52 address += 0x800; 52 address += 0x800;
53 } 53 }
54 54
55 memset(&port, 0, sizeof(struct uart_port)); 55 memset(&port, 0, sizeof(port));
56 port.mapbase = address; 56 port.iotype = UPIO_MEM;
57 port.irq = dev->irq; 57 port.uartclk = LASI_BASE_BAUD * 16;
58 port.iotype = UPIO_MEM; 58 port.mapbase = address;
59 port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; 59 port.membase = ioremap_nocache(address, 16);
60 port.uartclk = LASI_BASE_BAUD * 16; 60 port.irq = dev->irq;
61 port.dev = &dev->dev; 61 port.flags = UPF_BOOT_AUTOCONF;
62 port.dev = &dev->dev;
62 63
63 err = serial8250_register_port(&port); 64 err = serial8250_register_port(&port);
64 if (err < 0) { 65 if (err < 0) {
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index fe0d8b8e91c8..7d22dc0478d3 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -63,6 +63,33 @@ config SERIAL_8250_CONSOLE
63 63
64 If unsure, say N. 64 If unsure, say N.
65 65
66config SERIAL_8250_GSC
67 tristate
68 depends on SERIAL_8250 && GSC
69 default SERIAL_8250
70
71config SERIAL_8250_PCI
72 tristate "8250/16550 PCI device support" if EMBEDDED
73 depends on SERIAL_8250 && PCI
74 default SERIAL_8250
75 help
76 This builds standard PCI serial support. You may be able to
77 disable this feature if you only need legacy serial support.
78 Saves about 9K.
79
80config SERIAL_8250_PNP
81 tristate "8250/16550 PNP device support" if EMBEDDED
82 depends on SERIAL_8250 && PNP
83 default SERIAL_8250
84 help
85 This builds standard PNP serial support. You may be able to
86 disable this feature if you only need legacy serial support.
87
88config SERIAL_8250_HP300
89 tristate
90 depends on SERIAL_8250 && HP300
91 default SERIAL_8250
92
66config SERIAL_8250_CS 93config SERIAL_8250_CS
67 tristate "8250/16550 PCMCIA device support" 94 tristate "8250/16550 PCMCIA device support"
68 depends on PCMCIA && SERIAL_8250 95 depends on PCMCIA && SERIAL_8250
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index d2b4c214876b..0a71bf68a03f 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -4,15 +4,13 @@
4# $Id: Makefile,v 1.8 2002/07/21 21:32:30 rmk Exp $ 4# $Id: Makefile,v 1.8 2002/07/21 21:32:30 rmk Exp $
5# 5#
6 6
7serial-8250-y :=
8serial-8250-$(CONFIG_PNP) += 8250_pnp.o
9serial-8250-$(CONFIG_GSC) += 8250_gsc.o
10serial-8250-$(CONFIG_PCI) += 8250_pci.o
11serial-8250-$(CONFIG_HP300) += 8250_hp300.o
12
13obj-$(CONFIG_SERIAL_CORE) += serial_core.o 7obj-$(CONFIG_SERIAL_CORE) += serial_core.o
14obj-$(CONFIG_SERIAL_21285) += 21285.o 8obj-$(CONFIG_SERIAL_21285) += 21285.o
15obj-$(CONFIG_SERIAL_8250) += 8250.o $(serial-8250-y) 9obj-$(CONFIG_SERIAL_8250) += 8250.o
10obj-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
11obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o
12obj-$(CONFIG_SERIAL_8250_PCI) += 8250_pci.o
13obj-$(CONFIG_SERIAL_8250_HP300) += 8250_hp300.o
16obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o 14obj-$(CONFIG_SERIAL_8250_CS) += serial_cs.o
17obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o 15obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o
18obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o 16obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h
index dfc1e86d3aa1..043f50b1d10c 100644
--- a/drivers/serial/jsm/jsm.h
+++ b/drivers/serial/jsm/jsm.h
@@ -20,7 +20,7 @@
20 * 20 *
21 * Contact Information: 21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com> 22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com> 23 * Wendy Xiong <wendyx@us.ibm.com>
24 * 24 *
25 ***********************************************************************/ 25 ***********************************************************************/
26 26
diff --git a/drivers/serial/jsm/jsm_driver.c b/drivers/serial/jsm/jsm_driver.c
index b1b66e71d281..b3e1f71be4da 100644
--- a/drivers/serial/jsm/jsm_driver.c
+++ b/drivers/serial/jsm/jsm_driver.c
@@ -20,7 +20,7 @@
20 * 20 *
21 * Contact Information: 21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com> 22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com> 23 * Wendy Xiong <wendyx@us.ibm.com>
24 * 24 *
25 * 25 *
26 ***********************************************************************/ 26 ***********************************************************************/
diff --git a/drivers/serial/jsm/jsm_neo.c b/drivers/serial/jsm/jsm_neo.c
index 87e4e2cf8ce7..a5fc589d6ef5 100644
--- a/drivers/serial/jsm/jsm_neo.c
+++ b/drivers/serial/jsm/jsm_neo.c
@@ -20,7 +20,7 @@
20 * 20 *
21 * Contact Information: 21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com> 22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com> 23 * Wendy Xiong <wendyx@us.ibm.com>
24 * 24 *
25 ***********************************************************************/ 25 ***********************************************************************/
26#include <linux/delay.h> /* For udelay */ 26#include <linux/delay.h> /* For udelay */
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index 4d48b625cd3d..7d823705193c 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -142,12 +142,14 @@ static void jsm_tty_send_xchar(struct uart_port *port, char ch)
142{ 142{
143 unsigned long lock_flags; 143 unsigned long lock_flags;
144 struct jsm_channel *channel = (struct jsm_channel *)port; 144 struct jsm_channel *channel = (struct jsm_channel *)port;
145 struct termios *termios;
145 146
146 spin_lock_irqsave(&port->lock, lock_flags); 147 spin_lock_irqsave(&port->lock, lock_flags);
147 if (ch == port->info->tty->termios->c_cc[VSTART]) 148 termios = port->info->tty->termios;
149 if (ch == termios->c_cc[VSTART])
148 channel->ch_bd->bd_ops->send_start_character(channel); 150 channel->ch_bd->bd_ops->send_start_character(channel);
149 151
150 if (ch == port->info->tty->termios->c_cc[VSTOP]) 152 if (ch == termios->c_cc[VSTOP])
151 channel->ch_bd->bd_ops->send_stop_character(channel); 153 channel->ch_bd->bd_ops->send_stop_character(channel);
152 spin_unlock_irqrestore(&port->lock, lock_flags); 154 spin_unlock_irqrestore(&port->lock, lock_flags);
153} 155}
@@ -178,6 +180,7 @@ static int jsm_tty_open(struct uart_port *port)
178 struct jsm_board *brd; 180 struct jsm_board *brd;
179 int rc = 0; 181 int rc = 0;
180 struct jsm_channel *channel = (struct jsm_channel *)port; 182 struct jsm_channel *channel = (struct jsm_channel *)port;
183 struct termios *termios;
181 184
182 /* Get board pointer from our array of majors we have allocated */ 185 /* Get board pointer from our array of majors we have allocated */
183 brd = channel->ch_bd; 186 brd = channel->ch_bd;
@@ -239,12 +242,13 @@ static int jsm_tty_open(struct uart_port *port)
239 channel->ch_cached_lsr = 0; 242 channel->ch_cached_lsr = 0;
240 channel->ch_stops_sent = 0; 243 channel->ch_stops_sent = 0;
241 244
242 channel->ch_c_cflag = port->info->tty->termios->c_cflag; 245 termios = port->info->tty->termios;
243 channel->ch_c_iflag = port->info->tty->termios->c_iflag; 246 channel->ch_c_cflag = termios->c_cflag;
244 channel->ch_c_oflag = port->info->tty->termios->c_oflag; 247 channel->ch_c_iflag = termios->c_iflag;
245 channel->ch_c_lflag = port->info->tty->termios->c_lflag; 248 channel->ch_c_oflag = termios->c_oflag;
246 channel->ch_startc = port->info->tty->termios->c_cc[VSTART]; 249 channel->ch_c_lflag = termios->c_lflag;
247 channel->ch_stopc = port->info->tty->termios->c_cc[VSTOP]; 250 channel->ch_startc = termios->c_cc[VSTART];
251 channel->ch_stopc = termios->c_cc[VSTOP];
248 252
249 /* Tell UART to init itself */ 253 /* Tell UART to init itself */
250 brd->bd_ops->uart_init(channel); 254 brd->bd_ops->uart_init(channel);
@@ -784,6 +788,7 @@ static void jsm_carrier(struct jsm_channel *ch)
784 788
785void jsm_check_queue_flow_control(struct jsm_channel *ch) 789void jsm_check_queue_flow_control(struct jsm_channel *ch)
786{ 790{
791 struct board_ops *bd_ops = ch->ch_bd->bd_ops;
787 int qleft = 0; 792 int qleft = 0;
788 793
789 /* Store how much space we have left in the queue */ 794 /* Store how much space we have left in the queue */
@@ -809,7 +814,7 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
809 /* HWFLOW */ 814 /* HWFLOW */
810 if (ch->ch_c_cflag & CRTSCTS) { 815 if (ch->ch_c_cflag & CRTSCTS) {
811 if(!(ch->ch_flags & CH_RECEIVER_OFF)) { 816 if(!(ch->ch_flags & CH_RECEIVER_OFF)) {
812 ch->ch_bd->bd_ops->disable_receiver(ch); 817 bd_ops->disable_receiver(ch);
813 ch->ch_flags |= (CH_RECEIVER_OFF); 818 ch->ch_flags |= (CH_RECEIVER_OFF);
814 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, 819 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
815 "Internal queue hit hilevel mark (%d)! Turning off interrupts.\n", 820 "Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
@@ -819,7 +824,7 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
819 /* SWFLOW */ 824 /* SWFLOW */
820 else if (ch->ch_c_iflag & IXOFF) { 825 else if (ch->ch_c_iflag & IXOFF) {
821 if (ch->ch_stops_sent <= MAX_STOPS_SENT) { 826 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
822 ch->ch_bd->bd_ops->send_stop_character(ch); 827 bd_ops->send_stop_character(ch);
823 ch->ch_stops_sent++; 828 ch->ch_stops_sent++;
824 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, 829 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
825 "Sending stop char! Times sent: %x\n", ch->ch_stops_sent); 830 "Sending stop char! Times sent: %x\n", ch->ch_stops_sent);
@@ -846,7 +851,7 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
846 /* HWFLOW */ 851 /* HWFLOW */
847 if (ch->ch_c_cflag & CRTSCTS) { 852 if (ch->ch_c_cflag & CRTSCTS) {
848 if (ch->ch_flags & CH_RECEIVER_OFF) { 853 if (ch->ch_flags & CH_RECEIVER_OFF) {
849 ch->ch_bd->bd_ops->enable_receiver(ch); 854 bd_ops->enable_receiver(ch);
850 ch->ch_flags &= ~(CH_RECEIVER_OFF); 855 ch->ch_flags &= ~(CH_RECEIVER_OFF);
851 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, 856 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
852 "Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n", 857 "Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
@@ -856,7 +861,7 @@ void jsm_check_queue_flow_control(struct jsm_channel *ch)
856 /* SWFLOW */ 861 /* SWFLOW */
857 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) { 862 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
858 ch->ch_stops_sent = 0; 863 ch->ch_stops_sent = 0;
859 ch->ch_bd->bd_ops->send_start_character(ch); 864 bd_ops->send_start_character(ch);
860 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "Sending start char!\n"); 865 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "Sending start char!\n");
861 } 866 }
862 } 867 }
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index 868eaf4a1a68..64c0e89124c9 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -51,7 +51,7 @@
51#define MUX_BREAK(status) ((status & 0xF000) == 0x2000) 51#define MUX_BREAK(status) ((status & 0xF000) == 0x2000)
52 52
53#define MUX_NR 256 53#define MUX_NR 256
54static unsigned int port_cnt = 0; 54static unsigned int port_cnt __read_mostly;
55static struct uart_port mux_ports[MUX_NR]; 55static struct uart_port mux_ports[MUX_NR];
56 56
57static struct uart_driver mux_driver = { 57static struct uart_driver mux_driver = {
@@ -461,7 +461,7 @@ static int __init mux_probe(struct parisc_device *dev)
461 port->iobase = 0; 461 port->iobase = 0;
462 port->mapbase = dev->hpa.start + MUX_OFFSET + 462 port->mapbase = dev->hpa.start + MUX_OFFSET +
463 (i * MUX_LINE_OFFSET); 463 (i * MUX_LINE_OFFSET);
464 port->membase = ioremap(port->mapbase, MUX_LINE_OFFSET); 464 port->membase = ioremap_nocache(port->mapbase, MUX_LINE_OFFSET);
465 port->iotype = UPIO_MEM; 465 port->iotype = UPIO_MEM;
466 port->type = PORT_MUX; 466 port->type = PORT_MUX;
467 port->irq = NO_IRQ; 467 port->irq = NO_IRQ;
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index c30333694fde..2c70773543e0 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -41,6 +41,7 @@
41#include <linux/string.h> 41#include <linux/string.h>
42#include <linux/timer.h> 42#include <linux/timer.h>
43#include <linux/serial_core.h> 43#include <linux/serial_core.h>
44#include <linux/delay.h>
44#include <linux/major.h> 45#include <linux/major.h>
45#include <asm/io.h> 46#include <asm/io.h>
46#include <asm/system.h> 47#include <asm/system.h>
@@ -97,11 +98,13 @@ static const struct multi_id multi_id[] = {
97#define MULTI_COUNT (sizeof(multi_id)/sizeof(struct multi_id)) 98#define MULTI_COUNT (sizeof(multi_id)/sizeof(struct multi_id))
98 99
99struct serial_info { 100struct serial_info {
100 dev_link_t link; 101 struct pcmcia_device *p_dev;
101 int ndev; 102 int ndev;
102 int multi; 103 int multi;
103 int slave; 104 int slave;
104 int manfid; 105 int manfid;
106 int prodid;
107 int c950ctrl;
105 dev_node_t node[4]; 108 dev_node_t node[4];
106 int line[4]; 109 int line[4];
107}; 110};
@@ -113,9 +116,36 @@ struct serial_cfg_mem {
113}; 116};
114 117
115 118
116static void serial_config(dev_link_t * link); 119static int serial_config(struct pcmcia_device * link);
117 120
118 121
122static void wakeup_card(struct serial_info *info)
123{
124 int ctrl = info->c950ctrl;
125
126 if (info->manfid == MANFID_OXSEMI) {
127 outb(12, ctrl + 1);
128 } else if (info->manfid == MANFID_POSSIO && info->prodid == PRODID_POSSIO_GCC) {
129 /* request_region? oxsemi branch does no request_region too... */
130 /* This sequence is needed to properly initialize MC45 attached to OXCF950.
131 * I tried decreasing these msleep()s, but it worked properly (survived
132 * 1000 stop/start operations) with these timeouts (or bigger). */
133 outb(0xA, ctrl + 1);
134 msleep(100);
135 outb(0xE, ctrl + 1);
136 msleep(300);
137 outb(0xC, ctrl + 1);
138 msleep(100);
139 outb(0xE, ctrl + 1);
140 msleep(200);
141 outb(0xF, ctrl + 1);
142 msleep(100);
143 outb(0xE, ctrl + 1);
144 msleep(100);
145 outb(0xC, ctrl + 1);
146 }
147}
148
119/*====================================================================== 149/*======================================================================
120 150
121 After a card is removed, serial_remove() will unregister 151 After a card is removed, serial_remove() will unregister
@@ -123,67 +153,45 @@ static void serial_config(dev_link_t * link);
123 153
124======================================================================*/ 154======================================================================*/
125 155
126static void serial_remove(dev_link_t *link) 156static void serial_remove(struct pcmcia_device *link)
127{ 157{
128 struct serial_info *info = link->priv; 158 struct serial_info *info = link->priv;
129 int i; 159 int i;
130 160
131 link->state &= ~DEV_PRESENT;
132
133 DEBUG(0, "serial_release(0x%p)\n", link); 161 DEBUG(0, "serial_release(0x%p)\n", link);
134 162
135 /* 163 /*
136 * Recheck to see if the device is still configured. 164 * Recheck to see if the device is still configured.
137 */ 165 */
138 if (info->link.state & DEV_CONFIG) { 166 for (i = 0; i < info->ndev; i++)
139 for (i = 0; i < info->ndev; i++) 167 serial8250_unregister_port(info->line[i]);
140 serial8250_unregister_port(info->line[i]);
141 168
142 info->link.dev = NULL; 169 info->p_dev->dev_node = NULL;
143 170
144 if (!info->slave) { 171 if (!info->slave)
145 pcmcia_release_configuration(info->link.handle); 172 pcmcia_disable_device(link);
146 pcmcia_release_io(info->link.handle, &info->link.io);
147 pcmcia_release_irq(info->link.handle, &info->link.irq);
148 }
149
150 info->link.state &= ~DEV_CONFIG;
151 }
152} 173}
153 174
154static int serial_suspend(struct pcmcia_device *dev) 175static int serial_suspend(struct pcmcia_device *link)
155{ 176{
156 dev_link_t *link = dev_to_instance(dev); 177 struct serial_info *info = link->priv;
157 link->state |= DEV_SUSPEND; 178 int i;
158
159 if (link->state & DEV_CONFIG) {
160 struct serial_info *info = link->priv;
161 int i;
162
163 for (i = 0; i < info->ndev; i++)
164 serial8250_suspend_port(info->line[i]);
165 179
166 if (!info->slave) 180 for (i = 0; i < info->ndev; i++)
167 pcmcia_release_configuration(link->handle); 181 serial8250_suspend_port(info->line[i]);
168 }
169 182
170 return 0; 183 return 0;
171} 184}
172 185
173static int serial_resume(struct pcmcia_device *dev) 186static int serial_resume(struct pcmcia_device *link)
174{ 187{
175 dev_link_t *link = dev_to_instance(dev); 188 if (pcmcia_dev_present(link)) {
176 link->state &= ~DEV_SUSPEND;
177
178 if (DEV_OK(link)) {
179 struct serial_info *info = link->priv; 189 struct serial_info *info = link->priv;
180 int i; 190 int i;
181 191
182 if (!info->slave)
183 pcmcia_request_configuration(link->handle, &link->conf);
184
185 for (i = 0; i < info->ndev; i++) 192 for (i = 0; i < info->ndev; i++)
186 serial8250_resume_port(info->line[i]); 193 serial8250_resume_port(info->line[i]);
194 wakeup_card(info);
187 } 195 }
188 196
189 return 0; 197 return 0;
@@ -197,10 +205,9 @@ static int serial_resume(struct pcmcia_device *dev)
197 205
198======================================================================*/ 206======================================================================*/
199 207
200static int serial_probe(struct pcmcia_device *p_dev) 208static int serial_probe(struct pcmcia_device *link)
201{ 209{
202 struct serial_info *info; 210 struct serial_info *info;
203 dev_link_t *link;
204 211
205 DEBUG(0, "serial_attach()\n"); 212 DEBUG(0, "serial_attach()\n");
206 213
@@ -209,7 +216,7 @@ static int serial_probe(struct pcmcia_device *p_dev)
209 if (!info) 216 if (!info)
210 return -ENOMEM; 217 return -ENOMEM;
211 memset(info, 0, sizeof (*info)); 218 memset(info, 0, sizeof (*info));
212 link = &info->link; 219 info->p_dev = link;
213 link->priv = info; 220 link->priv = info;
214 221
215 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 222 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -223,12 +230,7 @@ static int serial_probe(struct pcmcia_device *p_dev)
223 } 230 }
224 link->conf.IntType = INT_MEMORY_AND_IO; 231 link->conf.IntType = INT_MEMORY_AND_IO;
225 232
226 link->handle = p_dev; 233 return serial_config(link);
227 p_dev->instance = link;
228 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
229 serial_config(link);
230
231 return 0;
232} 234}
233 235
234/*====================================================================== 236/*======================================================================
@@ -240,9 +242,8 @@ static int serial_probe(struct pcmcia_device *p_dev)
240 242
241======================================================================*/ 243======================================================================*/
242 244
243static void serial_detach(struct pcmcia_device *p_dev) 245static void serial_detach(struct pcmcia_device *link)
244{ 246{
245 dev_link_t *link = dev_to_instance(p_dev);
246 struct serial_info *info = link->priv; 247 struct serial_info *info = link->priv;
247 248
248 DEBUG(0, "serial_detach(0x%p)\n", link); 249 DEBUG(0, "serial_detach(0x%p)\n", link);
@@ -263,7 +264,7 @@ static void serial_detach(struct pcmcia_device *p_dev)
263 264
264/*====================================================================*/ 265/*====================================================================*/
265 266
266static int setup_serial(client_handle_t handle, struct serial_info * info, 267static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
267 kio_addr_t iobase, int irq) 268 kio_addr_t iobase, int irq)
268{ 269{
269 struct uart_port port; 270 struct uart_port port;
@@ -298,7 +299,7 @@ static int setup_serial(client_handle_t handle, struct serial_info * info,
298/*====================================================================*/ 299/*====================================================================*/
299 300
300static int 301static int
301first_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse) 302first_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
302{ 303{
303 int i; 304 int i;
304 i = pcmcia_get_first_tuple(handle, tuple); 305 i = pcmcia_get_first_tuple(handle, tuple);
@@ -311,7 +312,7 @@ first_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse)
311} 312}
312 313
313static int 314static int
314next_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse) 315next_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
315{ 316{
316 int i; 317 int i;
317 i = pcmcia_get_next_tuple(handle, tuple); 318 i = pcmcia_get_next_tuple(handle, tuple);
@@ -325,11 +326,10 @@ next_tuple(client_handle_t handle, tuple_t * tuple, cisparse_t * parse)
325 326
326/*====================================================================*/ 327/*====================================================================*/
327 328
328static int simple_config(dev_link_t *link) 329static int simple_config(struct pcmcia_device *link)
329{ 330{
330 static const kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 331 static const kio_addr_t base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
331 static const int size_table[2] = { 8, 16 }; 332 static const int size_table[2] = { 8, 16 };
332 client_handle_t handle = link->handle;
333 struct serial_info *info = link->priv; 333 struct serial_info *info = link->priv;
334 struct serial_cfg_mem *cfg_mem; 334 struct serial_cfg_mem *cfg_mem;
335 tuple_t *tuple; 335 tuple_t *tuple;
@@ -350,7 +350,7 @@ static int simple_config(dev_link_t *link)
350 buf = cfg_mem->buf; 350 buf = cfg_mem->buf;
351 351
352 /* If the card is already configured, look up the port and irq */ 352 /* If the card is already configured, look up the port and irq */
353 i = pcmcia_get_configuration_info(handle, &config); 353 i = pcmcia_get_configuration_info(link, &config);
354 if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) { 354 if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) {
355 kio_addr_t port = 0; 355 kio_addr_t port = 0;
356 if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) { 356 if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) {
@@ -363,10 +363,9 @@ static int simple_config(dev_link_t *link)
363 } 363 }
364 if (info->slave) { 364 if (info->slave) {
365 kfree(cfg_mem); 365 kfree(cfg_mem);
366 return setup_serial(handle, info, port, config.AssignedIRQ); 366 return setup_serial(link, info, port, config.AssignedIRQ);
367 } 367 }
368 } 368 }
369 link->conf.Vcc = config.Vcc;
370 369
371 /* First pass: look for a config entry that looks normal. */ 370 /* First pass: look for a config entry that looks normal. */
372 tuple->TupleData = (cisdata_t *) buf; 371 tuple->TupleData = (cisdata_t *) buf;
@@ -377,12 +376,12 @@ static int simple_config(dev_link_t *link)
377 /* Two tries: without IO aliases, then with aliases */ 376 /* Two tries: without IO aliases, then with aliases */
378 for (s = 0; s < 2; s++) { 377 for (s = 0; s < 2; s++) {
379 for (try = 0; try < 2; try++) { 378 for (try = 0; try < 2; try++) {
380 i = first_tuple(handle, tuple, parse); 379 i = first_tuple(link, tuple, parse);
381 while (i != CS_NO_MORE_ITEMS) { 380 while (i != CS_NO_MORE_ITEMS) {
382 if (i != CS_SUCCESS) 381 if (i != CS_SUCCESS)
383 goto next_entry; 382 goto next_entry;
384 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 383 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
385 link->conf.Vpp1 = link->conf.Vpp2 = 384 link->conf.Vpp =
386 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 385 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
387 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) && 386 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) &&
388 (cf->io.win[0].base != 0)) { 387 (cf->io.win[0].base != 0)) {
@@ -390,19 +389,19 @@ static int simple_config(dev_link_t *link)
390 link->io.BasePort1 = cf->io.win[0].base; 389 link->io.BasePort1 = cf->io.win[0].base;
391 link->io.IOAddrLines = (try == 0) ? 390 link->io.IOAddrLines = (try == 0) ?
392 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 391 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
393 i = pcmcia_request_io(link->handle, &link->io); 392 i = pcmcia_request_io(link, &link->io);
394 if (i == CS_SUCCESS) 393 if (i == CS_SUCCESS)
395 goto found_port; 394 goto found_port;
396 } 395 }
397next_entry: 396next_entry:
398 i = next_tuple(handle, tuple, parse); 397 i = next_tuple(link, tuple, parse);
399 } 398 }
400 } 399 }
401 } 400 }
402 /* Second pass: try to find an entry that isn't picky about 401 /* Second pass: try to find an entry that isn't picky about
403 its base address, then try to grab any standard serial port 402 its base address, then try to grab any standard serial port
404 address, and finally try to get any free port. */ 403 address, and finally try to get any free port. */
405 i = first_tuple(handle, tuple, parse); 404 i = first_tuple(link, tuple, parse);
406 while (i != CS_NO_MORE_ITEMS) { 405 while (i != CS_NO_MORE_ITEMS) {
407 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && 406 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) &&
408 ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 407 ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
@@ -410,50 +409,48 @@ next_entry:
410 for (j = 0; j < 5; j++) { 409 for (j = 0; j < 5; j++) {
411 link->io.BasePort1 = base[j]; 410 link->io.BasePort1 = base[j];
412 link->io.IOAddrLines = base[j] ? 16 : 3; 411 link->io.IOAddrLines = base[j] ? 16 : 3;
413 i = pcmcia_request_io(link->handle, &link->io); 412 i = pcmcia_request_io(link, &link->io);
414 if (i == CS_SUCCESS) 413 if (i == CS_SUCCESS)
415 goto found_port; 414 goto found_port;
416 } 415 }
417 } 416 }
418 i = next_tuple(handle, tuple, parse); 417 i = next_tuple(link, tuple, parse);
419 } 418 }
420 419
421 found_port: 420 found_port:
422 if (i != CS_SUCCESS) { 421 if (i != CS_SUCCESS) {
423 printk(KERN_NOTICE 422 printk(KERN_NOTICE
424 "serial_cs: no usable port range found, giving up\n"); 423 "serial_cs: no usable port range found, giving up\n");
425 cs_error(link->handle, RequestIO, i); 424 cs_error(link, RequestIO, i);
426 kfree(cfg_mem); 425 kfree(cfg_mem);
427 return -1; 426 return -1;
428 } 427 }
429 428
430 i = pcmcia_request_irq(link->handle, &link->irq); 429 i = pcmcia_request_irq(link, &link->irq);
431 if (i != CS_SUCCESS) { 430 if (i != CS_SUCCESS) {
432 cs_error(link->handle, RequestIRQ, i); 431 cs_error(link, RequestIRQ, i);
433 link->irq.AssignedIRQ = 0; 432 link->irq.AssignedIRQ = 0;
434 } 433 }
435 if (info->multi && (info->manfid == MANFID_3COM)) 434 if (info->multi && (info->manfid == MANFID_3COM))
436 link->conf.ConfigIndex &= ~(0x08); 435 link->conf.ConfigIndex &= ~(0x08);
437 i = pcmcia_request_configuration(link->handle, &link->conf); 436 i = pcmcia_request_configuration(link, &link->conf);
438 if (i != CS_SUCCESS) { 437 if (i != CS_SUCCESS) {
439 cs_error(link->handle, RequestConfiguration, i); 438 cs_error(link, RequestConfiguration, i);
440 kfree(cfg_mem); 439 kfree(cfg_mem);
441 return -1; 440 return -1;
442 } 441 }
443 kfree(cfg_mem); 442 kfree(cfg_mem);
444 return setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); 443 return setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
445} 444}
446 445
447static int multi_config(dev_link_t * link) 446static int multi_config(struct pcmcia_device * link)
448{ 447{
449 client_handle_t handle = link->handle;
450 struct serial_info *info = link->priv; 448 struct serial_info *info = link->priv;
451 struct serial_cfg_mem *cfg_mem; 449 struct serial_cfg_mem *cfg_mem;
452 tuple_t *tuple; 450 tuple_t *tuple;
453 u_char *buf; 451 u_char *buf;
454 cisparse_t *parse; 452 cisparse_t *parse;
455 cistpl_cftable_entry_t *cf; 453 cistpl_cftable_entry_t *cf;
456 config_info_t config;
457 int i, rc, base2 = 0; 454 int i, rc, base2 = 0;
458 455
459 cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); 456 cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL);
@@ -464,14 +461,6 @@ static int multi_config(dev_link_t * link)
464 cf = &parse->cftable_entry; 461 cf = &parse->cftable_entry;
465 buf = cfg_mem->buf; 462 buf = cfg_mem->buf;
466 463
467 i = pcmcia_get_configuration_info(handle, &config);
468 if (i != CS_SUCCESS) {
469 cs_error(handle, GetConfigurationInfo, i);
470 rc = -1;
471 goto free_cfg_mem;
472 }
473 link->conf.Vcc = config.Vcc;
474
475 tuple->TupleData = (cisdata_t *) buf; 464 tuple->TupleData = (cisdata_t *) buf;
476 tuple->TupleOffset = 0; 465 tuple->TupleOffset = 0;
477 tuple->TupleDataMax = 255; 466 tuple->TupleDataMax = 255;
@@ -480,7 +469,7 @@ static int multi_config(dev_link_t * link)
480 469
481 /* First, look for a generic full-sized window */ 470 /* First, look for a generic full-sized window */
482 link->io.NumPorts1 = info->multi * 8; 471 link->io.NumPorts1 = info->multi * 8;
483 i = first_tuple(handle, tuple, parse); 472 i = first_tuple(link, tuple, parse);
484 while (i != CS_NO_MORE_ITEMS) { 473 while (i != CS_NO_MORE_ITEMS) {
485 /* The quad port cards have bad CIS's, so just look for a 474 /* The quad port cards have bad CIS's, so just look for a
486 window larger than 8 ports and assume it will be right */ 475 window larger than 8 ports and assume it will be right */
@@ -490,19 +479,19 @@ static int multi_config(dev_link_t * link)
490 link->io.BasePort1 = cf->io.win[0].base; 479 link->io.BasePort1 = cf->io.win[0].base;
491 link->io.IOAddrLines = 480 link->io.IOAddrLines =
492 cf->io.flags & CISTPL_IO_LINES_MASK; 481 cf->io.flags & CISTPL_IO_LINES_MASK;
493 i = pcmcia_request_io(link->handle, &link->io); 482 i = pcmcia_request_io(link, &link->io);
494 base2 = link->io.BasePort1 + 8; 483 base2 = link->io.BasePort1 + 8;
495 if (i == CS_SUCCESS) 484 if (i == CS_SUCCESS)
496 break; 485 break;
497 } 486 }
498 i = next_tuple(handle, tuple, parse); 487 i = next_tuple(link, tuple, parse);
499 } 488 }
500 489
501 /* If that didn't work, look for two windows */ 490 /* If that didn't work, look for two windows */
502 if (i != CS_SUCCESS) { 491 if (i != CS_SUCCESS) {
503 link->io.NumPorts1 = link->io.NumPorts2 = 8; 492 link->io.NumPorts1 = link->io.NumPorts2 = 8;
504 info->multi = 2; 493 info->multi = 2;
505 i = first_tuple(handle, tuple, parse); 494 i = first_tuple(link, tuple, parse);
506 while (i != CS_NO_MORE_ITEMS) { 495 while (i != CS_NO_MORE_ITEMS) {
507 if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) { 496 if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) {
508 link->conf.ConfigIndex = cf->index; 497 link->conf.ConfigIndex = cf->index;
@@ -510,26 +499,26 @@ static int multi_config(dev_link_t * link)
510 link->io.BasePort2 = cf->io.win[1].base; 499 link->io.BasePort2 = cf->io.win[1].base;
511 link->io.IOAddrLines = 500 link->io.IOAddrLines =
512 cf->io.flags & CISTPL_IO_LINES_MASK; 501 cf->io.flags & CISTPL_IO_LINES_MASK;
513 i = pcmcia_request_io(link->handle, &link->io); 502 i = pcmcia_request_io(link, &link->io);
514 base2 = link->io.BasePort2; 503 base2 = link->io.BasePort2;
515 if (i == CS_SUCCESS) 504 if (i == CS_SUCCESS)
516 break; 505 break;
517 } 506 }
518 i = next_tuple(handle, tuple, parse); 507 i = next_tuple(link, tuple, parse);
519 } 508 }
520 } 509 }
521 510
522 if (i != CS_SUCCESS) { 511 if (i != CS_SUCCESS) {
523 cs_error(link->handle, RequestIO, i); 512 cs_error(link, RequestIO, i);
524 rc = -1; 513 rc = -1;
525 goto free_cfg_mem; 514 goto free_cfg_mem;
526 } 515 }
527 516
528 i = pcmcia_request_irq(link->handle, &link->irq); 517 i = pcmcia_request_irq(link, &link->irq);
529 if (i != CS_SUCCESS) { 518 if (i != CS_SUCCESS) {
530 printk(KERN_NOTICE 519 printk(KERN_NOTICE
531 "serial_cs: no usable port range found, giving up\n"); 520 "serial_cs: no usable port range found, giving up\n");
532 cs_error(link->handle, RequestIRQ, i); 521 cs_error(link, RequestIRQ, i);
533 link->irq.AssignedIRQ = 0; 522 link->irq.AssignedIRQ = 0;
534 } 523 }
535 /* Socket Dual IO: this enables irq's for second port */ 524 /* Socket Dual IO: this enables irq's for second port */
@@ -537,35 +526,43 @@ static int multi_config(dev_link_t * link)
537 link->conf.Present |= PRESENT_EXT_STATUS; 526 link->conf.Present |= PRESENT_EXT_STATUS;
538 link->conf.ExtStatus = ESR_REQ_ATTN_ENA; 527 link->conf.ExtStatus = ESR_REQ_ATTN_ENA;
539 } 528 }
540 i = pcmcia_request_configuration(link->handle, &link->conf); 529 i = pcmcia_request_configuration(link, &link->conf);
541 if (i != CS_SUCCESS) { 530 if (i != CS_SUCCESS) {
542 cs_error(link->handle, RequestConfiguration, i); 531 cs_error(link, RequestConfiguration, i);
543 rc = -1; 532 rc = -1;
544 goto free_cfg_mem; 533 goto free_cfg_mem;
545 } 534 }
546 535
547 /* The Oxford Semiconductor OXCF950 cards are in fact single-port: 536 /* The Oxford Semiconductor OXCF950 cards are in fact single-port:
548 8 registers are for the UART, the others are extra registers */ 537 * 8 registers are for the UART, the others are extra registers.
549 if (info->manfid == MANFID_OXSEMI) { 538 * Siemen's MC45 PCMCIA (Possio's GCC) is OXCF950 based too.
539 */
540 if (info->manfid == MANFID_OXSEMI || (info->manfid == MANFID_POSSIO &&
541 info->prodid == PRODID_POSSIO_GCC)) {
542 int err;
543
550 if (cf->index == 1 || cf->index == 3) { 544 if (cf->index == 1 || cf->index == 3) {
551 setup_serial(handle, info, base2, link->irq.AssignedIRQ); 545 err = setup_serial(link, info, base2,
552 outb(12, link->io.BasePort1 + 1); 546 link->irq.AssignedIRQ);
547 base2 = link->io.BasePort1;
553 } else { 548 } else {
554 setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); 549 err = setup_serial(link, info, link->io.BasePort1,
555 outb(12, base2 + 1); 550 link->irq.AssignedIRQ);
556 } 551 }
552 info->c950ctrl = base2;
553 wakeup_card(info);
557 rc = 0; 554 rc = 0;
558 goto free_cfg_mem; 555 goto free_cfg_mem;
559 } 556 }
560 557
561 setup_serial(handle, info, link->io.BasePort1, link->irq.AssignedIRQ); 558 setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
562 /* The Nokia cards are not really multiport cards */ 559 /* The Nokia cards are not really multiport cards */
563 if (info->manfid == MANFID_NOKIA) { 560 if (info->manfid == MANFID_NOKIA) {
564 rc = 0; 561 rc = 0;
565 goto free_cfg_mem; 562 goto free_cfg_mem;
566 } 563 }
567 for (i = 0; i < info->multi - 1; i++) 564 for (i = 0; i < info->multi - 1; i++)
568 setup_serial(handle, info, base2 + (8 * i), 565 setup_serial(link, info, base2 + (8 * i),
569 link->irq.AssignedIRQ); 566 link->irq.AssignedIRQ);
570 rc = 0; 567 rc = 0;
571free_cfg_mem: 568free_cfg_mem:
@@ -581,9 +578,8 @@ free_cfg_mem:
581 578
582======================================================================*/ 579======================================================================*/
583 580
584void serial_config(dev_link_t * link) 581static int serial_config(struct pcmcia_device * link)
585{ 582{
586 client_handle_t handle = link->handle;
587 struct serial_info *info = link->priv; 583 struct serial_info *info = link->priv;
588 struct serial_cfg_mem *cfg_mem; 584 struct serial_cfg_mem *cfg_mem;
589 tuple_t *tuple; 585 tuple_t *tuple;
@@ -609,7 +605,7 @@ void serial_config(dev_link_t * link)
609 tuple->Attributes = 0; 605 tuple->Attributes = 0;
610 /* Get configuration register information */ 606 /* Get configuration register information */
611 tuple->DesiredTuple = CISTPL_CONFIG; 607 tuple->DesiredTuple = CISTPL_CONFIG;
612 last_ret = first_tuple(handle, tuple, parse); 608 last_ret = first_tuple(link, tuple, parse);
613 if (last_ret != CS_SUCCESS) { 609 if (last_ret != CS_SUCCESS) {
614 last_fn = ParseTuple; 610 last_fn = ParseTuple;
615 goto cs_failed; 611 goto cs_failed;
@@ -617,18 +613,16 @@ void serial_config(dev_link_t * link)
617 link->conf.ConfigBase = parse->config.base; 613 link->conf.ConfigBase = parse->config.base;
618 link->conf.Present = parse->config.rmask[0]; 614 link->conf.Present = parse->config.rmask[0];
619 615
620 /* Configure card */
621 link->state |= DEV_CONFIG;
622
623 /* Is this a compliant multifunction card? */ 616 /* Is this a compliant multifunction card? */
624 tuple->DesiredTuple = CISTPL_LONGLINK_MFC; 617 tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
625 tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK; 618 tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK;
626 info->multi = (first_tuple(handle, tuple, parse) == CS_SUCCESS); 619 info->multi = (first_tuple(link, tuple, parse) == CS_SUCCESS);
627 620
628 /* Is this a multiport card? */ 621 /* Is this a multiport card? */
629 tuple->DesiredTuple = CISTPL_MANFID; 622 tuple->DesiredTuple = CISTPL_MANFID;
630 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { 623 if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
631 info->manfid = parse->manfid.manf; 624 info->manfid = parse->manfid.manf;
625 info->prodid = le16_to_cpu(buf[1]);
632 for (i = 0; i < MULTI_COUNT; i++) 626 for (i = 0; i < MULTI_COUNT; i++)
633 if ((info->manfid == multi_id[i].manfid) && 627 if ((info->manfid == multi_id[i].manfid) &&
634 (parse->manfid.card == multi_id[i].prodid)) 628 (parse->manfid.card == multi_id[i].prodid))
@@ -641,11 +635,11 @@ void serial_config(dev_link_t * link)
641 multifunction cards that ask for appropriate IO port ranges */ 635 multifunction cards that ask for appropriate IO port ranges */
642 tuple->DesiredTuple = CISTPL_FUNCID; 636 tuple->DesiredTuple = CISTPL_FUNCID;
643 if ((info->multi == 0) && 637 if ((info->multi == 0) &&
644 ((first_tuple(handle, tuple, parse) != CS_SUCCESS) || 638 ((first_tuple(link, tuple, parse) != CS_SUCCESS) ||
645 (parse->funcid.func == CISTPL_FUNCID_MULTI) || 639 (parse->funcid.func == CISTPL_FUNCID_MULTI) ||
646 (parse->funcid.func == CISTPL_FUNCID_SERIAL))) { 640 (parse->funcid.func == CISTPL_FUNCID_SERIAL))) {
647 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 641 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
648 if (first_tuple(handle, tuple, parse) == CS_SUCCESS) { 642 if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
649 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0)) 643 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0))
650 info->multi = cf->io.win[0].len >> 3; 644 info->multi = cf->io.win[0].len >> 3;
651 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) && 645 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) &&
@@ -664,31 +658,30 @@ void serial_config(dev_link_t * link)
664 658
665 if (info->manfid == MANFID_IBM) { 659 if (info->manfid == MANFID_IBM) {
666 conf_reg_t reg = { 0, CS_READ, 0x800, 0 }; 660 conf_reg_t reg = { 0, CS_READ, 0x800, 0 };
667 last_ret = pcmcia_access_configuration_register(link->handle, &reg); 661 last_ret = pcmcia_access_configuration_register(link, &reg);
668 if (last_ret) { 662 if (last_ret) {
669 last_fn = AccessConfigurationRegister; 663 last_fn = AccessConfigurationRegister;
670 goto cs_failed; 664 goto cs_failed;
671 } 665 }
672 reg.Action = CS_WRITE; 666 reg.Action = CS_WRITE;
673 reg.Value = reg.Value | 1; 667 reg.Value = reg.Value | 1;
674 last_ret = pcmcia_access_configuration_register(link->handle, &reg); 668 last_ret = pcmcia_access_configuration_register(link, &reg);
675 if (last_ret) { 669 if (last_ret) {
676 last_fn = AccessConfigurationRegister; 670 last_fn = AccessConfigurationRegister;
677 goto cs_failed; 671 goto cs_failed;
678 } 672 }
679 } 673 }
680 674
681 link->dev = &info->node[0]; 675 link->dev_node = &info->node[0];
682 link->state &= ~DEV_CONFIG_PENDING;
683 kfree(cfg_mem); 676 kfree(cfg_mem);
684 return; 677 return 0;
685 678
686 cs_failed: 679 cs_failed:
687 cs_error(link->handle, last_fn, last_ret); 680 cs_error(link, last_fn, last_ret);
688 failed: 681 failed:
689 serial_remove(link); 682 serial_remove(link);
690 link->state &= ~DEV_CONFIG_PENDING;
691 kfree(cfg_mem); 683 kfree(cfg_mem);
684 return -ENODEV;
692} 685}
693 686
694static struct pcmcia_device_id serial_ids[] = { 687static struct pcmcia_device_id serial_ids[] = {
@@ -739,6 +732,7 @@ static struct pcmcia_device_id serial_ids[] = {
739 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77), 732 PCMCIA_MFC_DEVICE_PROD_ID1(1, "Motorola MARQUIS", 0xf03e4e77),
740 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302), 733 PCMCIA_MFC_DEVICE_PROD_ID2(1, "FAX/Modem/Ethernet Combo Card ", 0x1ed59302),
741 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301), 734 PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0301),
735 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x0276),
742 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039), 736 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0039),
743 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006), 737 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0006),
744 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a), 738 PCMCIA_DEVICE_MANF_CARD(0x0105, 0x410a),
@@ -757,6 +751,7 @@ static struct pcmcia_device_id serial_ids[] = {
757 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef), 751 PCMCIA_DEVICE_PROD_ID14("MEGAHERTZ", "PCMCIA MODEM", 0xf510db04, 0xbd6c43ef),
758 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef), 752 PCMCIA_DEVICE_PROD_ID124("TOSHIBA", "T144PF", "PCMCIA MODEM", 0xb4585a1a, 0x7271409c, 0xbd6c43ef),
759 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0), 753 PCMCIA_DEVICE_PROD_ID123("FUJITSU", "FC14F ", "MBH10213", 0x6ee5a3d8, 0x30ead12b, 0xb00f05a0),
754 PCMCIA_DEVICE_PROD_ID123("Novatel Wireless", "Merlin UMTS Modem", "U630", 0x32607776, 0xd9e73b13, 0xe87332e),
760 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a), 755 PCMCIA_DEVICE_PROD_ID13("MEGAHERTZ", "V.34 PCMCIA MODEM", 0xf510db04, 0xbb2cce4a),
761 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02), 756 PCMCIA_DEVICE_PROD_ID12("Brain Boxes", "Bluetooth PC Card", 0xee138382, 0xd4ce9b02),
762 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa), 757 PCMCIA_DEVICE_PROD_ID12("CIRRUS LOGIC", "FAX MODEM", 0xe625f451, 0xcecd6dfa),
diff --git a/drivers/sn/ioc3.c b/drivers/sn/ioc3.c
index 93449a1a0065..0b49ff78efc1 100644
--- a/drivers/sn/ioc3.c
+++ b/drivers/sn/ioc3.c
@@ -11,6 +11,7 @@
11#include <linux/errno.h> 11#include <linux/errno.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/dma-mapping.h>
14#include <linux/interrupt.h> 15#include <linux/interrupt.h>
15#include <linux/spinlock.h> 16#include <linux/spinlock.h>
16#include <linux/delay.h> 17#include <linux/delay.h>
@@ -619,9 +620,9 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
619 pci_set_master(pdev); 620 pci_set_master(pdev);
620 621
621#ifdef USE_64BIT_DMA 622#ifdef USE_64BIT_DMA
622 ret = pci_set_dma_mask(pdev, 0xffffffffffffffffULL); 623 ret = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
623 if (!ret) { 624 if (!ret) {
624 ret = pci_set_consistent_dma_mask(pdev, 0xffffffffffffffffULL); 625 ret = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
625 if (ret < 0) { 626 if (ret < 0) {
626 printk(KERN_WARNING "%s: Unable to obtain 64 bit DMA " 627 printk(KERN_WARNING "%s: Unable to obtain 64 bit DMA "
627 "for consistent allocations\n", 628 "for consistent allocations\n",
diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c
index d3a7b0c3d38b..dda0ca45d904 100644
--- a/drivers/telephony/ixj_pcmcia.c
+++ b/drivers/telephony/ixj_pcmcia.c
@@ -35,73 +35,52 @@ typedef struct ixj_info_t {
35} ixj_info_t; 35} ixj_info_t;
36 36
37static void ixj_detach(struct pcmcia_device *p_dev); 37static void ixj_detach(struct pcmcia_device *p_dev);
38static void ixj_config(dev_link_t * link); 38static int ixj_config(struct pcmcia_device * link);
39static void ixj_cs_release(dev_link_t * link); 39static void ixj_cs_release(struct pcmcia_device * link);
40 40
41static int ixj_attach(struct pcmcia_device *p_dev) 41static int ixj_probe(struct pcmcia_device *p_dev)
42{ 42{
43 dev_link_t *link;
44
45 DEBUG(0, "ixj_attach()\n"); 43 DEBUG(0, "ixj_attach()\n");
46 /* Create new ixj device */ 44 /* Create new ixj device */
47 link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL); 45 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
48 if (!link) 46 p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
49 return -ENOMEM; 47 p_dev->io.IOAddrLines = 3;
50 memset(link, 0, sizeof(struct dev_link_t)); 48 p_dev->conf.IntType = INT_MEMORY_AND_IO;
51 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 49 p_dev->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
52 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 50 if (!p_dev->priv) {
53 link->io.IOAddrLines = 3;
54 link->conf.Vcc = 50;
55 link->conf.IntType = INT_MEMORY_AND_IO;
56 link->priv = kmalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
57 if (!link->priv) {
58 kfree(link);
59 return -ENOMEM; 51 return -ENOMEM;
60 } 52 }
61 memset(link->priv, 0, sizeof(struct ixj_info_t)); 53 memset(p_dev->priv, 0, sizeof(struct ixj_info_t));
62
63 link->handle = p_dev;
64 p_dev->instance = link;
65 54
66 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; 55 return ixj_config(p_dev);
67 ixj_config(link);
68
69 return 0;
70} 56}
71 57
72static void ixj_detach(struct pcmcia_device *p_dev) 58static void ixj_detach(struct pcmcia_device *link)
73{ 59{
74 dev_link_t *link = dev_to_instance(p_dev);
75
76 DEBUG(0, "ixj_detach(0x%p)\n", link); 60 DEBUG(0, "ixj_detach(0x%p)\n", link);
77 61
78 link->state &= ~DEV_RELEASE_PENDING; 62 ixj_cs_release(link);
79 if (link->state & DEV_CONFIG)
80 ixj_cs_release(link);
81 63
82 kfree(link->priv); 64 kfree(link->priv);
83 kfree(link);
84} 65}
85 66
86#define CS_CHECK(fn, ret) \ 67#define CS_CHECK(fn, ret) \
87do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 68do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
88 69
89static void ixj_get_serial(dev_link_t * link, IXJ * j) 70static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
90{ 71{
91 client_handle_t handle;
92 tuple_t tuple; 72 tuple_t tuple;
93 u_short buf[128]; 73 u_short buf[128];
94 char *str; 74 char *str;
95 int last_ret, last_fn, i, place; 75 int last_ret, last_fn, i, place;
96 handle = link->handle;
97 DEBUG(0, "ixj_get_serial(0x%p)\n", link); 76 DEBUG(0, "ixj_get_serial(0x%p)\n", link);
98 tuple.TupleData = (cisdata_t *) buf; 77 tuple.TupleData = (cisdata_t *) buf;
99 tuple.TupleOffset = 0; 78 tuple.TupleOffset = 0;
100 tuple.TupleDataMax = 80; 79 tuple.TupleDataMax = 80;
101 tuple.Attributes = 0; 80 tuple.Attributes = 0;
102 tuple.DesiredTuple = CISTPL_VERS_1; 81 tuple.DesiredTuple = CISTPL_VERS_1;
103 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 82 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
104 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 83 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
105 str = (char *) buf; 84 str = (char *) buf;
106 printk("PCMCIA Version %d.%d\n", str[0], str[1]); 85 printk("PCMCIA Version %d.%d\n", str[0], str[1]);
107 str += 2; 86 str += 2;
@@ -149,22 +128,19 @@ static void ixj_get_serial(dev_link_t * link, IXJ * j)
149 return; 128 return;
150} 129}
151 130
152static void ixj_config(dev_link_t * link) 131static int ixj_config(struct pcmcia_device * link)
153{ 132{
154 IXJ *j; 133 IXJ *j;
155 client_handle_t handle;
156 ixj_info_t *info; 134 ixj_info_t *info;
157 tuple_t tuple; 135 tuple_t tuple;
158 u_short buf[128]; 136 u_short buf[128];
159 cisparse_t parse; 137 cisparse_t parse;
160 config_info_t conf;
161 cistpl_cftable_entry_t *cfg = &parse.cftable_entry; 138 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
162 cistpl_cftable_entry_t dflt = 139 cistpl_cftable_entry_t dflt =
163 { 140 {
164 0 141 0
165 }; 142 };
166 int last_ret, last_fn; 143 int last_ret, last_fn;
167 handle = link->handle;
168 info = link->priv; 144 info = link->priv;
169 DEBUG(0, "ixj_config(0x%p)\n", link); 145 DEBUG(0, "ixj_config(0x%p)\n", link);
170 tuple.TupleData = (cisdata_t *) buf; 146 tuple.TupleData = (cisdata_t *) buf;
@@ -172,19 +148,17 @@ static void ixj_config(dev_link_t * link)
172 tuple.TupleDataMax = 255; 148 tuple.TupleDataMax = 255;
173 tuple.Attributes = 0; 149 tuple.Attributes = 0;
174 tuple.DesiredTuple = CISTPL_CONFIG; 150 tuple.DesiredTuple = CISTPL_CONFIG;
175 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 151 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
176 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 152 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
177 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 153 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
178 link->conf.ConfigBase = parse.config.base; 154 link->conf.ConfigBase = parse.config.base;
179 link->conf.Present = parse.config.rmask[0]; 155 link->conf.Present = parse.config.rmask[0];
180 link->state |= DEV_CONFIG;
181 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf));
182 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 156 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
183 tuple.Attributes = 0; 157 tuple.Attributes = 0;
184 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 158 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
185 while (1) { 159 while (1) {
186 if (pcmcia_get_tuple_data(handle, &tuple) != 0 || 160 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
187 pcmcia_parse_tuple(handle, &tuple, &parse) != 0) 161 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
188 goto next_entry; 162 goto next_entry;
189 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 163 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
190 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; 164 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
@@ -195,7 +169,7 @@ static void ixj_config(dev_link_t * link)
195 link->io.BasePort2 = io->win[1].base; 169 link->io.BasePort2 = io->win[1].base;
196 link->io.NumPorts2 = io->win[1].len; 170 link->io.NumPorts2 = io->win[1].len;
197 } 171 }
198 if (pcmcia_request_io(link->handle, &link->io) != 0) 172 if (pcmcia_request_io(link, &link->io) != 0)
199 goto next_entry; 173 goto next_entry;
200 /* If we've got this far, we're done */ 174 /* If we've got this far, we're done */
201 break; 175 break;
@@ -203,10 +177,10 @@ static void ixj_config(dev_link_t * link)
203 next_entry: 177 next_entry:
204 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 178 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
205 dflt = *cfg; 179 dflt = *cfg;
206 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); 180 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
207 } 181 }
208 182
209 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); 183 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
210 184
211 /* 185 /*
212 * Register the card with the core. 186 * Register the card with the core.
@@ -215,46 +189,21 @@ static void ixj_config(dev_link_t * link)
215 189
216 info->ndev = 1; 190 info->ndev = 1;
217 info->node.major = PHONE_MAJOR; 191 info->node.major = PHONE_MAJOR;
218 link->dev = &info->node; 192 link->dev_node = &info->node;
219 ixj_get_serial(link, j); 193 ixj_get_serial(link, j);
220 link->state &= ~DEV_CONFIG_PENDING; 194 return 0;
221 return;
222 cs_failed: 195 cs_failed:
223 cs_error(link->handle, last_fn, last_ret); 196 cs_error(link, last_fn, last_ret);
224 ixj_cs_release(link); 197 ixj_cs_release(link);
198 return -ENODEV;
225} 199}
226 200
227static void ixj_cs_release(dev_link_t *link) 201static void ixj_cs_release(struct pcmcia_device *link)
228{ 202{
229 ixj_info_t *info = link->priv; 203 ixj_info_t *info = link->priv;
230 DEBUG(0, "ixj_cs_release(0x%p)\n", link); 204 DEBUG(0, "ixj_cs_release(0x%p)\n", link);
231 info->ndev = 0; 205 info->ndev = 0;
232 link->dev = NULL; 206 pcmcia_disable_device(link);
233 pcmcia_release_configuration(link->handle);
234 pcmcia_release_io(link->handle, &link->io);
235 link->state &= ~DEV_CONFIG;
236}
237
238static int ixj_suspend(struct pcmcia_device *dev)
239{
240 dev_link_t *link = dev_to_instance(dev);
241
242 link->state |= DEV_SUSPEND;
243 if (link->state & DEV_CONFIG)
244 pcmcia_release_configuration(link->handle);
245
246 return 0;
247}
248
249static int ixj_resume(struct pcmcia_device *dev)
250{
251 dev_link_t *link = dev_to_instance(dev);
252
253 link->state &= ~DEV_SUSPEND;
254 if (DEV_OK(link))
255 pcmcia_request_configuration(link->handle, &link->conf);
256
257 return 0;
258} 207}
259 208
260static struct pcmcia_device_id ixj_ids[] = { 209static struct pcmcia_device_id ixj_ids[] = {
@@ -268,11 +217,9 @@ static struct pcmcia_driver ixj_driver = {
268 .drv = { 217 .drv = {
269 .name = "ixj_cs", 218 .name = "ixj_cs",
270 }, 219 },
271 .probe = ixj_attach, 220 .probe = ixj_probe,
272 .remove = ixj_detach, 221 .remove = ixj_detach,
273 .id_table = ixj_ids, 222 .id_table = ixj_ids,
274 .suspend = ixj_suspend,
275 .resume = ixj_resume,
276}; 223};
277 224
278static int __init ixj_pcmcia_init(void) 225static int __init ixj_pcmcia_init(void)
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 830d2c982670..b38990adf1cd 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -68,7 +68,7 @@
68 68
69#include "usbatm.h" 69#include "usbatm.h"
70 70
71#define EAGLEUSBVERSION "ueagle 1.2" 71#define EAGLEUSBVERSION "ueagle 1.3"
72 72
73 73
74/* 74/*
@@ -243,7 +243,7 @@ enum {
243#define BULK_TIMEOUT 300 243#define BULK_TIMEOUT 300
244#define CTRL_TIMEOUT 1000 244#define CTRL_TIMEOUT 1000
245 245
246#define ACK_TIMEOUT msecs_to_jiffies(1500) 246#define ACK_TIMEOUT msecs_to_jiffies(3000)
247 247
248#define UEA_INTR_IFACE_NO 0 248#define UEA_INTR_IFACE_NO 0
249#define UEA_US_IFACE_NO 1 249#define UEA_US_IFACE_NO 1
@@ -314,6 +314,10 @@ struct cmv {
314 ((d) & 0xff) << 16 | \ 314 ((d) & 0xff) << 16 | \
315 ((a) & 0xff) << 8 | \ 315 ((a) & 0xff) << 8 | \
316 ((b) & 0xff)) 316 ((b) & 0xff))
317#define GETSA1(a) ((a >> 8) & 0xff)
318#define GETSA2(a) (a & 0xff)
319#define GETSA3(a) ((a >> 24) & 0xff)
320#define GETSA4(a) ((a >> 16) & 0xff)
317 321
318#define SA_CNTL MAKESA('C', 'N', 'T', 'L') 322#define SA_CNTL MAKESA('C', 'N', 'T', 'L')
319#define SA_DIAG MAKESA('D', 'I', 'A', 'G') 323#define SA_DIAG MAKESA('D', 'I', 'A', 'G')
@@ -728,11 +732,12 @@ bad2:
728 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i); 732 uea_err(INS_TO_USBDEV(sc), "sending DSP block %u failed\n", i);
729 return; 733 return;
730bad1: 734bad1:
731 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n",pageno); 735 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno);
732} 736}
733 737
734static inline void wake_up_cmv_ack(struct uea_softc *sc) 738static inline void wake_up_cmv_ack(struct uea_softc *sc)
735{ 739{
740 BUG_ON(sc->cmv_ack);
736 sc->cmv_ack = 1; 741 sc->cmv_ack = 1;
737 wake_up(&sc->cmv_ack_wait); 742 wake_up(&sc->cmv_ack_wait);
738} 743}
@@ -743,6 +748,9 @@ static inline int wait_cmv_ack(struct uea_softc *sc)
743 sc->cmv_ack, ACK_TIMEOUT); 748 sc->cmv_ack, ACK_TIMEOUT);
744 sc->cmv_ack = 0; 749 sc->cmv_ack = 0;
745 750
751 uea_dbg(INS_TO_USBDEV(sc), "wait_event_timeout : %d ms\n",
752 jiffies_to_msecs(ret));
753
746 if (ret < 0) 754 if (ret < 0)
747 return ret; 755 return ret;
748 756
@@ -791,6 +799,12 @@ static int uea_cmv(struct uea_softc *sc,
791 struct cmv cmv; 799 struct cmv cmv;
792 int ret; 800 int ret;
793 801
802 uea_enters(INS_TO_USBDEV(sc));
803 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
804 "offset : 0x%04x, data : 0x%08x\n",
805 FUNCTION_TYPE(function), FUNCTION_SUBTYPE(function),
806 GETSA1(address), GETSA2(address), GETSA3(address),
807 GETSA4(address), offset, data);
794 /* we send a request, but we expect a reply */ 808 /* we send a request, but we expect a reply */
795 sc->cmv_function = function | 0x2; 809 sc->cmv_function = function | 0x2;
796 sc->cmv_idx++; 810 sc->cmv_idx++;
@@ -808,7 +822,9 @@ static int uea_cmv(struct uea_softc *sc,
808 ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv); 822 ret = uea_request(sc, UEA_SET_BLOCK, UEA_MPTX_START, CMV_SIZE, &cmv);
809 if (ret < 0) 823 if (ret < 0)
810 return ret; 824 return ret;
811 return wait_cmv_ack(sc); 825 ret = wait_cmv_ack(sc);
826 uea_leaves(INS_TO_USBDEV(sc));
827 return ret;
812} 828}
813 829
814static inline int uea_read_cmv(struct uea_softc *sc, 830static inline int uea_read_cmv(struct uea_softc *sc,
@@ -922,7 +938,7 @@ static int uea_stat(struct uea_softc *sc)
922 * we check the status again in order to detect the failure earlier 938 * we check the status again in order to detect the failure earlier
923 */ 939 */
924 if (sc->stats.phy.flags) { 940 if (sc->stats.phy.flags) {
925 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = %d\n", 941 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
926 sc->stats.phy.flags); 942 sc->stats.phy.flags);
927 return 0; 943 return 0;
928 } 944 }
@@ -1063,7 +1079,13 @@ static int uea_start_reset(struct uea_softc *sc)
1063 uea_enters(INS_TO_USBDEV(sc)); 1079 uea_enters(INS_TO_USBDEV(sc));
1064 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n"); 1080 uea_info(INS_TO_USBDEV(sc), "(re)booting started\n");
1065 1081
1082 /* mask interrupt */
1066 sc->booting = 1; 1083 sc->booting = 1;
1084 /* We need to set this here because, a ack timeout could have occured,
1085 * but before we start the reboot, the ack occurs and set this to 1.
1086 * So we will failed to wait Ready CMV.
1087 */
1088 sc->cmv_ack = 0;
1067 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST); 1089 UPDATE_ATM_STAT(signal, ATM_PHY_SIG_LOST);
1068 1090
1069 /* reset statistics */ 1091 /* reset statistics */
@@ -1089,6 +1111,7 @@ static int uea_start_reset(struct uea_softc *sc)
1089 1111
1090 msleep(1000); 1112 msleep(1000);
1091 sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY); 1113 sc->cmv_function = MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY);
1114 /* demask interrupt */
1092 sc->booting = 0; 1115 sc->booting = 0;
1093 1116
1094 /* start loading DSP */ 1117 /* start loading DSP */
@@ -1101,6 +1124,8 @@ static int uea_start_reset(struct uea_softc *sc)
1101 if (ret < 0) 1124 if (ret < 0)
1102 return ret; 1125 return ret;
1103 1126
1127 uea_vdbg(INS_TO_USBDEV(sc), "Ready CMV received\n");
1128
1104 /* Enter in R-IDLE (cmv) until instructed otherwise */ 1129 /* Enter in R-IDLE (cmv) until instructed otherwise */
1105 ret = uea_write_cmv(sc, SA_CNTL, 0, 1); 1130 ret = uea_write_cmv(sc, SA_CNTL, 0, 1);
1106 if (ret < 0) 1131 if (ret < 0)
@@ -1121,6 +1146,7 @@ static int uea_start_reset(struct uea_softc *sc)
1121 } 1146 }
1122 /* Enter in R-ACT-REQ */ 1147 /* Enter in R-ACT-REQ */
1123 ret = uea_write_cmv(sc, SA_CNTL, 0, 2); 1148 ret = uea_write_cmv(sc, SA_CNTL, 0, 2);
1149 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1124out: 1150out:
1125 release_firmware(cmvs_fw); 1151 release_firmware(cmvs_fw);
1126 sc->reset = 0; 1152 sc->reset = 0;
@@ -1235,6 +1261,7 @@ static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv)
1235 1261
1236 if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) { 1262 if (cmv->bFunction == MAKEFUNCTION(ADSLDIRECTIVE, MODEMREADY)) {
1237 wake_up_cmv_ack(sc); 1263 wake_up_cmv_ack(sc);
1264 uea_leaves(INS_TO_USBDEV(sc));
1238 return; 1265 return;
1239 } 1266 }
1240 1267
@@ -1249,6 +1276,7 @@ static void uea_dispatch_cmv(struct uea_softc *sc, struct cmv* cmv)
1249 sc->data = sc->data << 16 | sc->data >> 16; 1276 sc->data = sc->data << 16 | sc->data >> 16;
1250 1277
1251 wake_up_cmv_ack(sc); 1278 wake_up_cmv_ack(sc);
1279 uea_leaves(INS_TO_USBDEV(sc));
1252 return; 1280 return;
1253 1281
1254bad2: 1282bad2:
@@ -1256,12 +1284,14 @@ bad2:
1256 "Function : %d, Subfunction : %d\n", 1284 "Function : %d, Subfunction : %d\n",
1257 FUNCTION_TYPE(cmv->bFunction), 1285 FUNCTION_TYPE(cmv->bFunction),
1258 FUNCTION_SUBTYPE(cmv->bFunction)); 1286 FUNCTION_SUBTYPE(cmv->bFunction));
1287 uea_leaves(INS_TO_USBDEV(sc));
1259 return; 1288 return;
1260 1289
1261bad1: 1290bad1:
1262 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, " 1291 uea_err(INS_TO_USBDEV(sc), "invalid cmv received, "
1263 "wPreamble %d, bDirection %d\n", 1292 "wPreamble %d, bDirection %d\n",
1264 le16_to_cpu(cmv->wPreamble), cmv->bDirection); 1293 le16_to_cpu(cmv->wPreamble), cmv->bDirection);
1294 uea_leaves(INS_TO_USBDEV(sc));
1265} 1295}
1266 1296
1267/* 1297/*
@@ -1346,7 +1376,7 @@ static int uea_boot(struct uea_softc *sc)
1346 if (ret < 0) { 1376 if (ret < 0) {
1347 uea_err(INS_TO_USBDEV(sc), 1377 uea_err(INS_TO_USBDEV(sc),
1348 "urb submition failed with error %d\n", ret); 1378 "urb submition failed with error %d\n", ret);
1349 goto err1; 1379 goto err;
1350 } 1380 }
1351 1381
1352 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm"); 1382 sc->kthread = kthread_run(uea_kthread, sc, "ueagle-atm");
@@ -1360,10 +1390,10 @@ static int uea_boot(struct uea_softc *sc)
1360 1390
1361err2: 1391err2:
1362 usb_kill_urb(sc->urb_int); 1392 usb_kill_urb(sc->urb_int);
1363err1:
1364 kfree(intr);
1365err: 1393err:
1366 usb_free_urb(sc->urb_int); 1394 usb_free_urb(sc->urb_int);
1395 sc->urb_int = NULL;
1396 kfree(intr);
1367 uea_leaves(INS_TO_USBDEV(sc)); 1397 uea_leaves(INS_TO_USBDEV(sc));
1368 return -ENOMEM; 1398 return -ENOMEM;
1369} 1399}
@@ -1508,7 +1538,7 @@ static ssize_t read_##name(struct device *dev, \
1508 int ret = -ENODEV; \ 1538 int ret = -ENODEV; \
1509 struct uea_softc *sc; \ 1539 struct uea_softc *sc; \
1510 \ 1540 \
1511 mutex_lock(&uea_mutex); \ 1541 mutex_lock(&uea_mutex); \
1512 sc = dev_to_uea(dev); \ 1542 sc = dev_to_uea(dev); \
1513 if (!sc) \ 1543 if (!sc) \
1514 goto out; \ 1544 goto out; \
@@ -1516,7 +1546,7 @@ static ssize_t read_##name(struct device *dev, \
1516 if (reset) \ 1546 if (reset) \
1517 sc->stats.phy.name = 0; \ 1547 sc->stats.phy.name = 0; \
1518out: \ 1548out: \
1519 mutex_unlock(&uea_mutex); \ 1549 mutex_unlock(&uea_mutex); \
1520 return ret; \ 1550 return ret; \
1521} \ 1551} \
1522 \ 1552 \
@@ -1643,7 +1673,7 @@ static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
1643 1673
1644 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL); 1674 sc = kzalloc(sizeof(struct uea_softc), GFP_KERNEL);
1645 if (!sc) { 1675 if (!sc) {
1646 uea_err(INS_TO_USBDEV(sc), "uea_init: not enough memory !\n"); 1676 uea_err(usb, "uea_init: not enough memory !\n");
1647 return -ENOMEM; 1677 return -ENOMEM;
1648 } 1678 }
1649 1679
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index ff03184da403..a08787e253aa 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -99,4 +99,11 @@ config USB_OTG_WHITELIST
99 normal Linux-USB hosts do (other than the warning), and is 99 normal Linux-USB hosts do (other than the warning), and is
100 convenient for many stages of product development. 100 convenient for many stages of product development.
101 101
102config USB_OTG_BLACKLIST_HUB
103 bool "Disable external hubs"
104 depends on USB_OTG
105 help
106 If you say Y here, then Linux will refuse to enumerate
107 external hubs. OTG hosts are allowed to reduce hardware
108 and software costs by not supporting external hubs.
102 109
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index e0afb5ad29e5..66b78404ab34 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -213,11 +213,9 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
213 213
214 if (hcd->driver->suspend) { 214 if (hcd->driver->suspend) {
215 retval = hcd->driver->suspend(hcd, message); 215 retval = hcd->driver->suspend(hcd, message);
216 if (retval) { 216 suspend_report_result(hcd->driver->suspend, retval);
217 dev_dbg (&dev->dev, "PCI pre-suspend fail, %d\n", 217 if (retval)
218 retval);
219 goto done; 218 goto done;
220 }
221 } 219 }
222 synchronize_irq(dev->irq); 220 synchronize_irq(dev->irq);
223 221
@@ -263,6 +261,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
263 * some device state (e.g. as part of clock reinit). 261 * some device state (e.g. as part of clock reinit).
264 */ 262 */
265 retval = pci_set_power_state (dev, PCI_D3hot); 263 retval = pci_set_power_state (dev, PCI_D3hot);
264 suspend_report_result(pci_set_power_state, retval);
266 if (retval == 0) { 265 if (retval == 0) {
267 int wake = device_can_wakeup(&hcd->self.root_hub->dev); 266 int wake = device_can_wakeup(&hcd->self.root_hub->dev);
268 267
@@ -296,7 +295,7 @@ done:
296 295
297#ifdef CONFIG_PPC_PMAC 296#ifdef CONFIG_PPC_PMAC
298 /* Disable ASIC clocks for USB */ 297 /* Disable ASIC clocks for USB */
299 if (_machine == _MACH_Pmac) { 298 if (machine_is(powermac)) {
300 struct device_node *of_node; 299 struct device_node *of_node;
301 300
302 of_node = pci_device_to_OF_node (dev); 301 of_node = pci_device_to_OF_node (dev);
@@ -331,7 +330,7 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
331 330
332#ifdef CONFIG_PPC_PMAC 331#ifdef CONFIG_PPC_PMAC
333 /* Reenable ASIC clocks for USB */ 332 /* Reenable ASIC clocks for USB */
334 if (_machine == _MACH_Pmac) { 333 if (machine_is(powermac)) {
335 struct device_node *of_node; 334 struct device_node *of_node;
336 335
337 of_node = pci_device_to_OF_node (dev); 336 of_node = pci_device_to_OF_node (dev);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 8e65f7a237e4..0c87f73f2933 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -836,6 +836,13 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
836 desc = intf->cur_altsetting; 836 desc = intf->cur_altsetting;
837 hdev = interface_to_usbdev(intf); 837 hdev = interface_to_usbdev(intf);
838 838
839#ifdef CONFIG_USB_OTG_BLACKLIST_HUB
840 if (hdev->parent) {
841 dev_warn(&intf->dev, "ignoring external hub\n");
842 return -ENODEV;
843 }
844#endif
845
839 /* Some hubs have a subclass of 1, which AFAICT according to the */ 846 /* Some hubs have a subclass of 1, which AFAICT according to the */
840 /* specs is not defined, but it works */ 847 /* specs is not defined, but it works */
841 if ((desc->desc.bInterfaceSubClass != 0) && 848 if ((desc->desc.bInterfaceSubClass != 0) &&
@@ -1022,7 +1029,6 @@ void usb_set_device_state(struct usb_device *udev,
1022 recursively_mark_NOTATTACHED(udev); 1029 recursively_mark_NOTATTACHED(udev);
1023 spin_unlock_irqrestore(&device_state_lock, flags); 1030 spin_unlock_irqrestore(&device_state_lock, flags);
1024} 1031}
1025EXPORT_SYMBOL(usb_set_device_state);
1026 1032
1027 1033
1028#ifdef CONFIG_PM 1034#ifdef CONFIG_PM
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index d7352aa73b5e..b7fdc1cd134a 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -1194,7 +1194,6 @@ EXPORT_SYMBOL(usb_disabled);
1194EXPORT_SYMBOL_GPL(usb_get_intf); 1194EXPORT_SYMBOL_GPL(usb_get_intf);
1195EXPORT_SYMBOL_GPL(usb_put_intf); 1195EXPORT_SYMBOL_GPL(usb_put_intf);
1196 1196
1197EXPORT_SYMBOL(usb_alloc_dev);
1198EXPORT_SYMBOL(usb_put_dev); 1197EXPORT_SYMBOL(usb_put_dev);
1199EXPORT_SYMBOL(usb_get_dev); 1198EXPORT_SYMBOL(usb_get_dev);
1200EXPORT_SYMBOL(usb_hub_tt_clear_buffer); 1199EXPORT_SYMBOL(usb_hub_tt_clear_buffer);
@@ -1208,7 +1207,6 @@ EXPORT_SYMBOL(usb_ifnum_to_if);
1208EXPORT_SYMBOL(usb_altnum_to_altsetting); 1207EXPORT_SYMBOL(usb_altnum_to_altsetting);
1209 1208
1210EXPORT_SYMBOL(usb_reset_device); 1209EXPORT_SYMBOL(usb_reset_device);
1211EXPORT_SYMBOL(usb_disconnect);
1212 1210
1213EXPORT_SYMBOL(__usb_get_extra_descriptor); 1211EXPORT_SYMBOL(__usb_get_extra_descriptor);
1214 1212
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index d80f71877d68..363b2ad74ae6 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -69,11 +69,11 @@ choice
69 often need board-specific hooks. 69 often need board-specific hooks.
70 70
71config USB_GADGET_NET2280 71config USB_GADGET_NET2280
72 boolean "NetChip 2280" 72 boolean "NetChip 228x"
73 depends on PCI 73 depends on PCI
74 select USB_GADGET_DUALSPEED 74 select USB_GADGET_DUALSPEED
75 help 75 help
76 NetChip 2280 is a PCI based USB peripheral controller which 76 NetChip 2280 / 2282 is a PCI based USB peripheral controller which
77 supports both full and high speed USB 2.0 data transfers. 77 supports both full and high speed USB 2.0 data transfers.
78 78
79 It has six configurable endpoints, as well as endpoint zero 79 It has six configurable endpoints, as well as endpoint zero
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 865858cfd1c2..b8d0b7825bf3 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1709,7 +1709,7 @@ static int __devexit at91udc_remove(struct platform_device *dev)
1709} 1709}
1710 1710
1711#ifdef CONFIG_PM 1711#ifdef CONFIG_PM
1712static int at91udc_suspend(struct platform_device *dev, u32 state, u32 level) 1712static int at91udc_suspend(struct platform_device *dev, pm_message_t mesg)
1713{ 1713{
1714 struct at91_udc *udc = platform_get_drvdata(dev); 1714 struct at91_udc *udc = platform_get_drvdata(dev);
1715 1715
@@ -1731,7 +1731,7 @@ static int at91udc_suspend(struct platform_device *dev, u32 state, u32 level)
1731 return 0; 1731 return 0;
1732} 1732}
1733 1733
1734static int at91udc_resume(struct platform_device *dev, u32 level) 1734static int at91udc_resume(struct platform_device *dev)
1735{ 1735{
1736 struct at91_udc *udc = platform_get_drvdata(dev); 1736 struct at91_udc *udc = platform_get_drvdata(dev);
1737 1737
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index c3d8e5c5bf28..9c4422ac9de4 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -2338,6 +2338,9 @@ autoconf_fail:
2338 hs_subset_descriptors(); 2338 hs_subset_descriptors();
2339 } 2339 }
2340 2340
2341 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
2342 usb_gadget_set_selfpowered (gadget);
2343
2341 /* For now RNDIS is always a second config */ 2344 /* For now RNDIS is always a second config */
2342 if (rndis) 2345 if (rndis)
2343 device_desc.bNumConfigurations = 2; 2346 device_desc.bNumConfigurations = 2;
@@ -2361,9 +2364,6 @@ autoconf_fail:
2361#endif 2364#endif
2362#endif /* DUALSPEED */ 2365#endif /* DUALSPEED */
2363 2366
2364 device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
2365 usb_gadget_set_selfpowered (gadget);
2366
2367 if (gadget->is_otg) { 2367 if (gadget->is_otg) {
2368 otg_descriptor.bmAttributes |= USB_OTG_HNP, 2368 otg_descriptor.bmAttributes |= USB_OTG_HNP,
2369 eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 2369 eth_config.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index cf3be299e353..6f887478b148 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -71,6 +71,12 @@
71 * requirement amounts to two 16K buffers, size configurable by a parameter. 71 * requirement amounts to two 16K buffers, size configurable by a parameter.
72 * Support is included for both full-speed and high-speed operation. 72 * Support is included for both full-speed and high-speed operation.
73 * 73 *
74 * Note that the driver is slightly non-portable in that it assumes a
75 * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
76 * interrupt-in endpoints. With most device controllers this isn't an
77 * issue, but there may be some with hardware restrictions that prevent
78 * a buffer from being used by more than one endpoint.
79 *
74 * Module options: 80 * Module options:
75 * 81 *
76 * file=filename[,filename...] 82 * file=filename[,filename...]
@@ -108,6 +114,14 @@
108 * setting are not allowed when the medium is loaded. 114 * setting are not allowed when the medium is loaded.
109 * 115 *
110 * This gadget driver is heavily based on "Gadget Zero" by David Brownell. 116 * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
117 * The driver's SCSI command interface was based on the "Information
118 * technology - Small Computer System Interface - 2" document from
119 * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
120 * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
121 * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
122 * "Universal Serial Bus Mass Storage Class UFI Command Specification"
123 * document, Revision 1.0, December 14, 1998, available at
124 * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
111 */ 125 */
112 126
113 127
@@ -334,11 +348,9 @@ MODULE_LICENSE("Dual BSD/GPL");
334 348
335#define MAX_LUNS 8 349#define MAX_LUNS 8
336 350
337 /* Arggh! There should be a module_param_array_named macro! */
338static char *file[MAX_LUNS];
339static int ro[MAX_LUNS];
340
341static struct { 351static struct {
352 char *file[MAX_LUNS];
353 int ro[MAX_LUNS];
342 int num_filenames; 354 int num_filenames;
343 int num_ros; 355 int num_ros;
344 unsigned int nluns; 356 unsigned int nluns;
@@ -370,10 +382,11 @@ static struct {
370 }; 382 };
371 383
372 384
373module_param_array(file, charp, &mod_data.num_filenames, S_IRUGO); 385module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
386 S_IRUGO);
374MODULE_PARM_DESC(file, "names of backing files or devices"); 387MODULE_PARM_DESC(file, "names of backing files or devices");
375 388
376module_param_array(ro, bool, &mod_data.num_ros, S_IRUGO); 389module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
377MODULE_PARM_DESC(ro, "true to force read-only"); 390MODULE_PARM_DESC(ro, "true to force read-only");
378 391
379module_param_named(luns, mod_data.nluns, uint, S_IRUGO); 392module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
@@ -1795,6 +1808,7 @@ static int do_write(struct fsg_dev *fsg)
1795 * the bulk-out maxpacket size */ 1808 * the bulk-out maxpacket size */
1796 bh->outreq->length = bh->bulk_out_intended_length = 1809 bh->outreq->length = bh->bulk_out_intended_length =
1797 amount; 1810 amount;
1811 bh->outreq->short_not_ok = 1;
1798 start_transfer(fsg, fsg->bulk_out, bh->outreq, 1812 start_transfer(fsg, fsg->bulk_out, bh->outreq,
1799 &bh->outreq_busy, &bh->state); 1813 &bh->outreq_busy, &bh->state);
1800 fsg->next_buffhd_to_fill = bh->next; 1814 fsg->next_buffhd_to_fill = bh->next;
@@ -2398,6 +2412,7 @@ static int throw_away_data(struct fsg_dev *fsg)
2398 * the bulk-out maxpacket size */ 2412 * the bulk-out maxpacket size */
2399 bh->outreq->length = bh->bulk_out_intended_length = 2413 bh->outreq->length = bh->bulk_out_intended_length =
2400 amount; 2414 amount;
2415 bh->outreq->short_not_ok = 1;
2401 start_transfer(fsg, fsg->bulk_out, bh->outreq, 2416 start_transfer(fsg, fsg->bulk_out, bh->outreq,
2402 &bh->outreq_busy, &bh->state); 2417 &bh->outreq_busy, &bh->state);
2403 fsg->next_buffhd_to_fill = bh->next; 2418 fsg->next_buffhd_to_fill = bh->next;
@@ -3029,6 +3044,7 @@ static int get_next_command(struct fsg_dev *fsg)
3029 3044
3030 /* Queue a request to read a Bulk-only CBW */ 3045 /* Queue a request to read a Bulk-only CBW */
3031 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN); 3046 set_bulk_out_req_length(fsg, bh, USB_BULK_CB_WRAP_LEN);
3047 bh->outreq->short_not_ok = 1;
3032 start_transfer(fsg, fsg->bulk_out, bh->outreq, 3048 start_transfer(fsg, fsg->bulk_out, bh->outreq,
3033 &bh->outreq_busy, &bh->state); 3049 &bh->outreq_busy, &bh->state);
3034 3050
@@ -3859,7 +3875,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3859 3875
3860 for (i = 0; i < fsg->nluns; ++i) { 3876 for (i = 0; i < fsg->nluns; ++i) {
3861 curlun = &fsg->luns[i]; 3877 curlun = &fsg->luns[i];
3862 curlun->ro = ro[i]; 3878 curlun->ro = mod_data.ro[i];
3863 curlun->dev.parent = &gadget->dev; 3879 curlun->dev.parent = &gadget->dev;
3864 curlun->dev.driver = &fsg_driver.driver; 3880 curlun->dev.driver = &fsg_driver.driver;
3865 dev_set_drvdata(&curlun->dev, fsg); 3881 dev_set_drvdata(&curlun->dev, fsg);
@@ -3876,8 +3892,9 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3876 kref_get(&fsg->ref); 3892 kref_get(&fsg->ref);
3877 } 3893 }
3878 3894
3879 if (file[i] && *file[i]) { 3895 if (mod_data.file[i] && *mod_data.file[i]) {
3880 if ((rc = open_backing_file(curlun, file[i])) != 0) 3896 if ((rc = open_backing_file(curlun,
3897 mod_data.file[i])) != 0)
3881 goto out; 3898 goto out;
3882 } else if (!mod_data.removable) { 3899 } else if (!mod_data.removable) {
3883 ERROR(fsg, "no file given for LUN%d\n", i); 3900 ERROR(fsg, "no file given for LUN%d\n", i);
@@ -3953,6 +3970,9 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3953 for (i = 0; i < NUM_BUFFERS; ++i) { 3970 for (i = 0; i < NUM_BUFFERS; ++i) {
3954 struct fsg_buffhd *bh = &fsg->buffhds[i]; 3971 struct fsg_buffhd *bh = &fsg->buffhds[i];
3955 3972
3973 /* Allocate for the bulk-in endpoint. We assume that
3974 * the buffer will also work with the bulk-out (and
3975 * interrupt-in) endpoint. */
3956 bh->buf = usb_ep_alloc_buffer(fsg->bulk_in, mod_data.buflen, 3976 bh->buf = usb_ep_alloc_buffer(fsg->bulk_in, mod_data.buflen,
3957 &bh->dma, GFP_KERNEL); 3977 &bh->dma, GFP_KERNEL);
3958 if (!bh->buf) 3978 if (!bh->buf)
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index c4081407171f..aa80f0910720 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -100,9 +100,9 @@
100#define gadget_is_musbhsfc(g) 0 100#define gadget_is_musbhsfc(g) 0
101#endif 101#endif
102 102
103/* Mentor high speed "dual role" controller, peripheral mode */ 103/* Mentor high speed "dual role" controller, in peripheral role */
104#ifdef CONFIG_USB_GADGET_MUSBHDRC 104#ifdef CONFIG_USB_GADGET_MUSB_HDRC
105#define gadget_is_musbhdrc(g) !strcmp("musbhdrc_udc", (g)->name) 105#define gadget_is_musbhdrc(g) !strcmp("musb_hdrc", (g)->name)
106#else 106#else
107#define gadget_is_musbhdrc(g) 0 107#define gadget_is_musbhdrc(g) 0
108#endif 108#endif
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 3f618ce6998d..42b457030b03 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -810,7 +810,7 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
810 if (value == 0) 810 if (value == 0)
811 data->state = STATE_EP_ENABLED; 811 data->state = STATE_EP_ENABLED;
812 break; 812 break;
813#ifdef HIGHSPEED 813#ifdef CONFIG_USB_GADGET_DUALSPEED
814 case USB_SPEED_HIGH: 814 case USB_SPEED_HIGH:
815 /* fails if caller didn't provide that descriptor... */ 815 /* fails if caller didn't provide that descriptor... */
816 value = usb_ep_enable (ep, &data->hs_desc); 816 value = usb_ep_enable (ep, &data->hs_desc);
@@ -982,7 +982,7 @@ ep0_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
982 /* assume that was SET_CONFIGURATION */ 982 /* assume that was SET_CONFIGURATION */
983 if (dev->current_config) { 983 if (dev->current_config) {
984 unsigned power; 984 unsigned power;
985#ifdef HIGHSPEED 985#ifdef CONFIG_USB_GADGET_DUALSPEED
986 if (dev->gadget->speed == USB_SPEED_HIGH) 986 if (dev->gadget->speed == USB_SPEED_HIGH)
987 power = dev->hs_config->bMaxPower; 987 power = dev->hs_config->bMaxPower;
988 else 988 else
@@ -1262,7 +1262,7 @@ static struct file_operations ep0_io_operations = {
1262 * Unrecognized ep0 requests may be handled in user space. 1262 * Unrecognized ep0 requests may be handled in user space.
1263 */ 1263 */
1264 1264
1265#ifdef HIGHSPEED 1265#ifdef CONFIG_USB_GADGET_DUALSPEED
1266static void make_qualifier (struct dev_data *dev) 1266static void make_qualifier (struct dev_data *dev)
1267{ 1267{
1268 struct usb_qualifier_descriptor qual; 1268 struct usb_qualifier_descriptor qual;
@@ -1291,7 +1291,7 @@ static int
1291config_buf (struct dev_data *dev, u8 type, unsigned index) 1291config_buf (struct dev_data *dev, u8 type, unsigned index)
1292{ 1292{
1293 int len; 1293 int len;
1294#ifdef HIGHSPEED 1294#ifdef CONFIG_USB_GADGET_DUALSPEED
1295 int hs; 1295 int hs;
1296#endif 1296#endif
1297 1297
@@ -1299,7 +1299,7 @@ config_buf (struct dev_data *dev, u8 type, unsigned index)
1299 if (index > 0) 1299 if (index > 0)
1300 return -EINVAL; 1300 return -EINVAL;
1301 1301
1302#ifdef HIGHSPEED 1302#ifdef CONFIG_USB_GADGET_DUALSPEED
1303 hs = (dev->gadget->speed == USB_SPEED_HIGH); 1303 hs = (dev->gadget->speed == USB_SPEED_HIGH);
1304 if (type == USB_DT_OTHER_SPEED_CONFIG) 1304 if (type == USB_DT_OTHER_SPEED_CONFIG)
1305 hs = !hs; 1305 hs = !hs;
@@ -1335,12 +1335,12 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1335 dev->state = STATE_CONNECTED; 1335 dev->state = STATE_CONNECTED;
1336 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket; 1336 dev->dev->bMaxPacketSize0 = gadget->ep0->maxpacket;
1337 1337
1338#ifdef HIGHSPEED 1338#ifdef CONFIG_USB_GADGET_DUALSPEED
1339 if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == 0) { 1339 if (gadget->speed == USB_SPEED_HIGH && dev->hs_config == 0) {
1340 ERROR (dev, "no high speed config??\n"); 1340 ERROR (dev, "no high speed config??\n");
1341 return -EINVAL; 1341 return -EINVAL;
1342 } 1342 }
1343#endif /* HIGHSPEED */ 1343#endif /* CONFIG_USB_GADGET_DUALSPEED */
1344 1344
1345 INFO (dev, "connected\n"); 1345 INFO (dev, "connected\n");
1346 event = next_event (dev, GADGETFS_CONNECT); 1346 event = next_event (dev, GADGETFS_CONNECT);
@@ -1352,11 +1352,11 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1352 /* ... down_trylock (&data->lock) ... */ 1352 /* ... down_trylock (&data->lock) ... */
1353 if (data->state != STATE_EP_DEFER_ENABLE) 1353 if (data->state != STATE_EP_DEFER_ENABLE)
1354 continue; 1354 continue;
1355#ifdef HIGHSPEED 1355#ifdef CONFIG_USB_GADGET_DUALSPEED
1356 if (gadget->speed == USB_SPEED_HIGH) 1356 if (gadget->speed == USB_SPEED_HIGH)
1357 value = usb_ep_enable (ep, &data->hs_desc); 1357 value = usb_ep_enable (ep, &data->hs_desc);
1358 else 1358 else
1359#endif /* HIGHSPEED */ 1359#endif /* CONFIG_USB_GADGET_DUALSPEED */
1360 value = usb_ep_enable (ep, &data->desc); 1360 value = usb_ep_enable (ep, &data->desc);
1361 if (value) { 1361 if (value) {
1362 ERROR (dev, "deferred %s enable --> %d\n", 1362 ERROR (dev, "deferred %s enable --> %d\n",
@@ -1391,7 +1391,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1391 value = min (w_length, (u16) sizeof *dev->dev); 1391 value = min (w_length, (u16) sizeof *dev->dev);
1392 req->buf = dev->dev; 1392 req->buf = dev->dev;
1393 break; 1393 break;
1394#ifdef HIGHSPEED 1394#ifdef CONFIG_USB_GADGET_DUALSPEED
1395 case USB_DT_DEVICE_QUALIFIER: 1395 case USB_DT_DEVICE_QUALIFIER:
1396 if (!dev->hs_config) 1396 if (!dev->hs_config)
1397 break; 1397 break;
@@ -1428,7 +1428,7 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1428 // user mode expected to disable endpoints 1428 // user mode expected to disable endpoints
1429 } else { 1429 } else {
1430 u8 config, power; 1430 u8 config, power;
1431#ifdef HIGHSPEED 1431#ifdef CONFIG_USB_GADGET_DUALSPEED
1432 if (gadget->speed == USB_SPEED_HIGH) { 1432 if (gadget->speed == USB_SPEED_HIGH) {
1433 config = dev->hs_config->bConfigurationValue; 1433 config = dev->hs_config->bConfigurationValue;
1434 power = dev->hs_config->bMaxPower; 1434 power = dev->hs_config->bMaxPower;
@@ -1728,7 +1728,7 @@ gadgetfs_suspend (struct usb_gadget *gadget)
1728} 1728}
1729 1729
1730static struct usb_gadget_driver gadgetfs_driver = { 1730static struct usb_gadget_driver gadgetfs_driver = {
1731#ifdef HIGHSPEED 1731#ifdef CONFIG_USB_GADGET_DUALSPEED
1732 .speed = USB_SPEED_HIGH, 1732 .speed = USB_SPEED_HIGH,
1733#else 1733#else
1734 .speed = USB_SPEED_FULL, 1734 .speed = USB_SPEED_FULL,
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index fb73dc100535..6a4b93ad1082 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -26,6 +26,8 @@
26 * Copyright (C) 2003 David Brownell 26 * Copyright (C) 2003 David Brownell
27 * Copyright (C) 2003-2005 PLX Technology, Inc. 27 * Copyright (C) 2003-2005 PLX Technology, Inc.
28 * 28 *
29 * Modified Seth Levy 2005 PLX Technology, Inc. to provide compatibility with 2282 chip
30 *
29 * This program is free software; you can redistribute it and/or modify 31 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by 32 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or 33 * the Free Software Foundation; either version 2 of the License, or
@@ -71,8 +73,8 @@
71#include <asm/unaligned.h> 73#include <asm/unaligned.h>
72 74
73 75
74#define DRIVER_DESC "PLX NET2280 USB Peripheral Controller" 76#define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
75#define DRIVER_VERSION "2005 Feb 03" 77#define DRIVER_VERSION "2005 Sept 27"
76 78
77#define DMA_ADDR_INVALID (~(dma_addr_t)0) 79#define DMA_ADDR_INVALID (~(dma_addr_t)0)
78#define EP_DONTUSE 13 /* nonzero */ 80#define EP_DONTUSE 13 /* nonzero */
@@ -118,7 +120,7 @@ module_param (fifo_mode, ushort, 0644);
118/* enable_suspend -- When enabled, the driver will respond to 120/* enable_suspend -- When enabled, the driver will respond to
119 * USB suspend requests by powering down the NET2280. Otherwise, 121 * USB suspend requests by powering down the NET2280. Otherwise,
120 * USB suspend requests will be ignored. This is acceptible for 122 * USB suspend requests will be ignored. This is acceptible for
121 * self-powered devices, and helps avoid some quirks. 123 * self-powered devices
122 */ 124 */
123static int enable_suspend = 0; 125static int enable_suspend = 0;
124 126
@@ -223,6 +225,11 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
223 ep->is_in = (tmp & USB_DIR_IN) != 0; 225 ep->is_in = (tmp & USB_DIR_IN) != 0;
224 if (!ep->is_in) 226 if (!ep->is_in)
225 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp); 227 writel ((1 << SET_NAK_OUT_PACKETS), &ep->regs->ep_rsp);
228 else if (dev->pdev->device != 0x2280) {
229 /* Added for 2282, Don't use nak packets on an in endpoint, this was ignored on 2280 */
230 writel ((1 << CLEAR_NAK_OUT_PACKETS)
231 | (1 << CLEAR_NAK_OUT_PACKETS_MODE), &ep->regs->ep_rsp);
232 }
226 233
227 writel (tmp, &ep->regs->ep_cfg); 234 writel (tmp, &ep->regs->ep_cfg);
228 235
@@ -232,8 +239,9 @@ net2280_enable (struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
232 writel (tmp, &dev->regs->pciirqenb0); 239 writel (tmp, &dev->regs->pciirqenb0);
233 240
234 tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE) 241 tmp = (1 << DATA_PACKET_RECEIVED_INTERRUPT_ENABLE)
235 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE) 242 | (1 << DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE);
236 | readl (&ep->regs->ep_irqenb); 243 if (dev->pdev->device == 0x2280)
244 tmp |= readl (&ep->regs->ep_irqenb);
237 writel (tmp, &ep->regs->ep_irqenb); 245 writel (tmp, &ep->regs->ep_irqenb);
238 } else { /* dma, per-request */ 246 } else { /* dma, per-request */
239 tmp = (1 << (8 + ep->num)); /* completion */ 247 tmp = (1 << (8 + ep->num)); /* completion */
@@ -314,10 +322,18 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
314 /* init to our chosen defaults, notably so that we NAK OUT 322 /* init to our chosen defaults, notably so that we NAK OUT
315 * packets until the driver queues a read (+note erratum 0112) 323 * packets until the driver queues a read (+note erratum 0112)
316 */ 324 */
317 tmp = (1 << SET_NAK_OUT_PACKETS_MODE) 325 if (!ep->is_in || ep->dev->pdev->device == 0x2280) {
326 tmp = (1 << SET_NAK_OUT_PACKETS_MODE)
318 | (1 << SET_NAK_OUT_PACKETS) 327 | (1 << SET_NAK_OUT_PACKETS)
319 | (1 << CLEAR_EP_HIDE_STATUS_PHASE) 328 | (1 << CLEAR_EP_HIDE_STATUS_PHASE)
320 | (1 << CLEAR_INTERRUPT_MODE); 329 | (1 << CLEAR_INTERRUPT_MODE);
330 } else {
331 /* added for 2282 */
332 tmp = (1 << CLEAR_NAK_OUT_PACKETS_MODE)
333 | (1 << CLEAR_NAK_OUT_PACKETS)
334 | (1 << CLEAR_EP_HIDE_STATUS_PHASE)
335 | (1 << CLEAR_INTERRUPT_MODE);
336 }
321 337
322 if (ep->num != 0) { 338 if (ep->num != 0) {
323 tmp |= (1 << CLEAR_ENDPOINT_TOGGLE) 339 tmp |= (1 << CLEAR_ENDPOINT_TOGGLE)
@@ -326,14 +342,18 @@ static void ep_reset (struct net2280_regs __iomem *regs, struct net2280_ep *ep)
326 writel (tmp, &ep->regs->ep_rsp); 342 writel (tmp, &ep->regs->ep_rsp);
327 343
328 /* scrub most status bits, and flush any fifo state */ 344 /* scrub most status bits, and flush any fifo state */
329 writel ( (1 << TIMEOUT) 345 if (ep->dev->pdev->device == 0x2280)
346 tmp = (1 << FIFO_OVERFLOW)
347 | (1 << FIFO_UNDERFLOW);
348 else
349 tmp = 0;
350
351 writel (tmp | (1 << TIMEOUT)
330 | (1 << USB_STALL_SENT) 352 | (1 << USB_STALL_SENT)
331 | (1 << USB_IN_NAK_SENT) 353 | (1 << USB_IN_NAK_SENT)
332 | (1 << USB_IN_ACK_RCVD) 354 | (1 << USB_IN_ACK_RCVD)
333 | (1 << USB_OUT_PING_NAK_SENT) 355 | (1 << USB_OUT_PING_NAK_SENT)
334 | (1 << USB_OUT_ACK_SENT) 356 | (1 << USB_OUT_ACK_SENT)
335 | (1 << FIFO_OVERFLOW)
336 | (1 << FIFO_UNDERFLOW)
337 | (1 << FIFO_FLUSH) 357 | (1 << FIFO_FLUSH)
338 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT) 358 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT)
339 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) 359 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)
@@ -718,7 +738,7 @@ fill_dma_desc (struct net2280_ep *ep, struct net2280_request *req, int valid)
718 */ 738 */
719 if (ep->is_in) 739 if (ep->is_in)
720 dmacount |= (1 << DMA_DIRECTION); 740 dmacount |= (1 << DMA_DIRECTION);
721 else if ((dmacount % ep->ep.maxpacket) != 0) 741 if ((!ep->is_in && (dmacount % ep->ep.maxpacket) != 0) || ep->dev->pdev->device != 0x2280)
722 dmacount |= (1 << END_OF_CHAIN); 742 dmacount |= (1 << END_OF_CHAIN);
723 743
724 req->valid = valid; 744 req->valid = valid;
@@ -760,9 +780,12 @@ static inline void stop_dma (struct net2280_dma_regs __iomem *dma)
760static void start_queue (struct net2280_ep *ep, u32 dmactl, u32 td_dma) 780static void start_queue (struct net2280_ep *ep, u32 dmactl, u32 td_dma)
761{ 781{
762 struct net2280_dma_regs __iomem *dma = ep->dma; 782 struct net2280_dma_regs __iomem *dma = ep->dma;
783 unsigned int tmp = (1 << VALID_BIT) | (ep->is_in << DMA_DIRECTION);
763 784
764 writel ((1 << VALID_BIT) | (ep->is_in << DMA_DIRECTION), 785 if (ep->dev->pdev->device != 0x2280)
765 &dma->dmacount); 786 tmp |= (1 << END_OF_CHAIN);
787
788 writel (tmp, &dma->dmacount);
766 writel (readl (&dma->dmastat), &dma->dmastat); 789 writel (readl (&dma->dmastat), &dma->dmastat);
767 790
768 writel (td_dma, &dma->dmadesc); 791 writel (td_dma, &dma->dmadesc);
@@ -2110,7 +2133,11 @@ static void handle_ep_small (struct net2280_ep *ep)
2110 VDEBUG (ep->dev, "%s ack ep_stat %08x, req %p\n", 2133 VDEBUG (ep->dev, "%s ack ep_stat %08x, req %p\n",
2111 ep->ep.name, t, req ? &req->req : 0); 2134 ep->ep.name, t, req ? &req->req : 0);
2112#endif 2135#endif
2113 writel (t & ~(1 << NAK_OUT_PACKETS), &ep->regs->ep_stat); 2136 if (!ep->is_in || ep->dev->pdev->device == 0x2280)
2137 writel (t & ~(1 << NAK_OUT_PACKETS), &ep->regs->ep_stat);
2138 else
2139 /* Added for 2282 */
2140 writel (t, &ep->regs->ep_stat);
2114 2141
2115 /* for ep0, monitor token irqs to catch data stage length errors 2142 /* for ep0, monitor token irqs to catch data stage length errors
2116 * and to synchronize on status. 2143 * and to synchronize on status.
@@ -2214,7 +2241,8 @@ static void handle_ep_small (struct net2280_ep *ep)
2214 if (likely (req)) { 2241 if (likely (req)) {
2215 req->td->dmacount = 0; 2242 req->td->dmacount = 0;
2216 t = readl (&ep->regs->ep_avail); 2243 t = readl (&ep->regs->ep_avail);
2217 dma_done (ep, req, count, t); 2244 dma_done (ep, req, count,
2245 (ep->out_overflow || t) ? -EOVERFLOW : 0);
2218 } 2246 }
2219 2247
2220 /* also flush to prevent erratum 0106 trouble */ 2248 /* also flush to prevent erratum 0106 trouble */
@@ -2337,7 +2365,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2337 u32 raw [2]; 2365 u32 raw [2];
2338 struct usb_ctrlrequest r; 2366 struct usb_ctrlrequest r;
2339 } u; 2367 } u;
2340 int tmp = 0; 2368 int tmp;
2341 struct net2280_request *req; 2369 struct net2280_request *req;
2342 2370
2343 if (dev->gadget.speed == USB_SPEED_UNKNOWN) { 2371 if (dev->gadget.speed == USB_SPEED_UNKNOWN) {
@@ -2364,14 +2392,19 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2364 } 2392 }
2365 ep->stopped = 0; 2393 ep->stopped = 0;
2366 dev->protocol_stall = 0; 2394 dev->protocol_stall = 0;
2367 writel ( (1 << TIMEOUT) 2395
2396 if (ep->dev->pdev->device == 0x2280)
2397 tmp = (1 << FIFO_OVERFLOW)
2398 | (1 << FIFO_UNDERFLOW);
2399 else
2400 tmp = 0;
2401
2402 writel (tmp | (1 << TIMEOUT)
2368 | (1 << USB_STALL_SENT) 2403 | (1 << USB_STALL_SENT)
2369 | (1 << USB_IN_NAK_SENT) 2404 | (1 << USB_IN_NAK_SENT)
2370 | (1 << USB_IN_ACK_RCVD) 2405 | (1 << USB_IN_ACK_RCVD)
2371 | (1 << USB_OUT_PING_NAK_SENT) 2406 | (1 << USB_OUT_PING_NAK_SENT)
2372 | (1 << USB_OUT_ACK_SENT) 2407 | (1 << USB_OUT_ACK_SENT)
2373 | (1 << FIFO_OVERFLOW)
2374 | (1 << FIFO_UNDERFLOW)
2375 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT) 2408 | (1 << SHORT_PACKET_OUT_DONE_INTERRUPT)
2376 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT) 2409 | (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)
2377 | (1 << DATA_PACKET_RECEIVED_INTERRUPT) 2410 | (1 << DATA_PACKET_RECEIVED_INTERRUPT)
@@ -2385,6 +2418,8 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2385 cpu_to_le32s (&u.raw [0]); 2418 cpu_to_le32s (&u.raw [0]);
2386 cpu_to_le32s (&u.raw [1]); 2419 cpu_to_le32s (&u.raw [1]);
2387 2420
2421 tmp = 0;
2422
2388#define w_value le16_to_cpup (&u.r.wValue) 2423#define w_value le16_to_cpup (&u.r.wValue)
2389#define w_index le16_to_cpup (&u.r.wIndex) 2424#define w_index le16_to_cpup (&u.r.wIndex)
2390#define w_length le16_to_cpup (&u.r.wLength) 2425#define w_length le16_to_cpup (&u.r.wLength)
@@ -2594,10 +2629,17 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2594 writel (stat, &dev->regs->irqstat1); 2629 writel (stat, &dev->regs->irqstat1);
2595 2630
2596 /* some status we can just ignore */ 2631 /* some status we can just ignore */
2597 stat &= ~((1 << CONTROL_STATUS_INTERRUPT) 2632 if (dev->pdev->device == 0x2280)
2598 | (1 << SUSPEND_REQUEST_INTERRUPT) 2633 stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
2599 | (1 << RESUME_INTERRUPT) 2634 | (1 << SUSPEND_REQUEST_INTERRUPT)
2600 | (1 << SOF_INTERRUPT)); 2635 | (1 << RESUME_INTERRUPT)
2636 | (1 << SOF_INTERRUPT));
2637 else
2638 stat &= ~((1 << CONTROL_STATUS_INTERRUPT)
2639 | (1 << RESUME_INTERRUPT)
2640 | (1 << SOF_DOWN_INTERRUPT)
2641 | (1 << SOF_INTERRUPT));
2642
2601 if (!stat) 2643 if (!stat)
2602 return; 2644 return;
2603 // DEBUG (dev, "irqstat1 %08x\n", stat); 2645 // DEBUG (dev, "irqstat1 %08x\n", stat);
@@ -2939,6 +2981,13 @@ static struct pci_device_id pci_ids [] = { {
2939 .device = 0x2280, 2981 .device = 0x2280,
2940 .subvendor = PCI_ANY_ID, 2982 .subvendor = PCI_ANY_ID,
2941 .subdevice = PCI_ANY_ID, 2983 .subdevice = PCI_ANY_ID,
2984}, {
2985 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
2986 .class_mask = ~0,
2987 .vendor = 0x17cc,
2988 .device = 0x2282,
2989 .subvendor = PCI_ANY_ID,
2990 .subdevice = PCI_ANY_ID,
2942 2991
2943}, { /* end: all zeroes */ } 2992}, { /* end: all zeroes */ }
2944}; 2993};
diff --git a/drivers/usb/gadget/net2280.h b/drivers/usb/gadget/net2280.h
index fff4509cf340..957d6df34015 100644
--- a/drivers/usb/gadget/net2280.h
+++ b/drivers/usb/gadget/net2280.h
@@ -22,420 +22,7 @@
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */ 23 */
24 24
25/*-------------------------------------------------------------------------*/ 25#include <linux/usb/net2280.h>
26
27/* NET2280 MEMORY MAPPED REGISTERS
28 *
29 * The register layout came from the chip documentation, and the bit
30 * number definitions were extracted from chip specification.
31 *
32 * Use the shift operator ('<<') to build bit masks, with readl/writel
33 * to access the registers through PCI.
34 */
35
36/* main registers, BAR0 + 0x0000 */
37struct net2280_regs {
38 // offset 0x0000
39 u32 devinit;
40#define LOCAL_CLOCK_FREQUENCY 8
41#define FORCE_PCI_RESET 7
42#define PCI_ID 6
43#define PCI_ENABLE 5
44#define FIFO_SOFT_RESET 4
45#define CFG_SOFT_RESET 3
46#define PCI_SOFT_RESET 2
47#define USB_SOFT_RESET 1
48#define M8051_RESET 0
49 u32 eectl;
50#define EEPROM_ADDRESS_WIDTH 23
51#define EEPROM_CHIP_SELECT_ACTIVE 22
52#define EEPROM_PRESENT 21
53#define EEPROM_VALID 20
54#define EEPROM_BUSY 19
55#define EEPROM_CHIP_SELECT_ENABLE 18
56#define EEPROM_BYTE_READ_START 17
57#define EEPROM_BYTE_WRITE_START 16
58#define EEPROM_READ_DATA 8
59#define EEPROM_WRITE_DATA 0
60 u32 eeclkfreq;
61 u32 _unused0;
62 // offset 0x0010
63
64 u32 pciirqenb0; /* interrupt PCI master ... */
65#define SETUP_PACKET_INTERRUPT_ENABLE 7
66#define ENDPOINT_F_INTERRUPT_ENABLE 6
67#define ENDPOINT_E_INTERRUPT_ENABLE 5
68#define ENDPOINT_D_INTERRUPT_ENABLE 4
69#define ENDPOINT_C_INTERRUPT_ENABLE 3
70#define ENDPOINT_B_INTERRUPT_ENABLE 2
71#define ENDPOINT_A_INTERRUPT_ENABLE 1
72#define ENDPOINT_0_INTERRUPT_ENABLE 0
73 u32 pciirqenb1;
74#define PCI_INTERRUPT_ENABLE 31
75#define POWER_STATE_CHANGE_INTERRUPT_ENABLE 27
76#define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE 26
77#define PCI_PARITY_ERROR_INTERRUPT_ENABLE 25
78#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE 20
79#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE 19
80#define PCI_TARGET_ABORT_ASSERTED_INTERRUPT_ENABLE 18
81#define PCI_RETRY_ABORT_INTERRUPT_ENABLE 17
82#define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE 16
83#define GPIO_INTERRUPT_ENABLE 13
84#define DMA_D_INTERRUPT_ENABLE 12
85#define DMA_C_INTERRUPT_ENABLE 11
86#define DMA_B_INTERRUPT_ENABLE 10
87#define DMA_A_INTERRUPT_ENABLE 9
88#define EEPROM_DONE_INTERRUPT_ENABLE 8
89#define VBUS_INTERRUPT_ENABLE 7
90#define CONTROL_STATUS_INTERRUPT_ENABLE 6
91#define ROOT_PORT_RESET_INTERRUPT_ENABLE 4
92#define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
93#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 2
94#define RESUME_INTERRUPT_ENABLE 1
95#define SOF_INTERRUPT_ENABLE 0
96 u32 cpu_irqenb0; /* ... or onboard 8051 */
97#define SETUP_PACKET_INTERRUPT_ENABLE 7
98#define ENDPOINT_F_INTERRUPT_ENABLE 6
99#define ENDPOINT_E_INTERRUPT_ENABLE 5
100#define ENDPOINT_D_INTERRUPT_ENABLE 4
101#define ENDPOINT_C_INTERRUPT_ENABLE 3
102#define ENDPOINT_B_INTERRUPT_ENABLE 2
103#define ENDPOINT_A_INTERRUPT_ENABLE 1
104#define ENDPOINT_0_INTERRUPT_ENABLE 0
105 u32 cpu_irqenb1;
106#define CPU_INTERRUPT_ENABLE 31
107#define POWER_STATE_CHANGE_INTERRUPT_ENABLE 27
108#define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE 26
109#define PCI_PARITY_ERROR_INTERRUPT_ENABLE 25
110#define PCI_INTA_INTERRUPT_ENABLE 24
111#define PCI_PME_INTERRUPT_ENABLE 23
112#define PCI_SERR_INTERRUPT_ENABLE 22
113#define PCI_PERR_INTERRUPT_ENABLE 21
114#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE 20
115#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE 19
116#define PCI_RETRY_ABORT_INTERRUPT_ENABLE 17
117#define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE 16
118#define GPIO_INTERRUPT_ENABLE 13
119#define DMA_D_INTERRUPT_ENABLE 12
120#define DMA_C_INTERRUPT_ENABLE 11
121#define DMA_B_INTERRUPT_ENABLE 10
122#define DMA_A_INTERRUPT_ENABLE 9
123#define EEPROM_DONE_INTERRUPT_ENABLE 8
124#define VBUS_INTERRUPT_ENABLE 7
125#define CONTROL_STATUS_INTERRUPT_ENABLE 6
126#define ROOT_PORT_RESET_INTERRUPT_ENABLE 4
127#define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
128#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 2
129#define RESUME_INTERRUPT_ENABLE 1
130#define SOF_INTERRUPT_ENABLE 0
131
132 // offset 0x0020
133 u32 _unused1;
134 u32 usbirqenb1;
135#define USB_INTERRUPT_ENABLE 31
136#define POWER_STATE_CHANGE_INTERRUPT_ENABLE 27
137#define PCI_ARBITER_TIMEOUT_INTERRUPT_ENABLE 26
138#define PCI_PARITY_ERROR_INTERRUPT_ENABLE 25
139#define PCI_INTA_INTERRUPT_ENABLE 24
140#define PCI_PME_INTERRUPT_ENABLE 23
141#define PCI_SERR_INTERRUPT_ENABLE 22
142#define PCI_PERR_INTERRUPT_ENABLE 21
143#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT_ENABLE 20
144#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT_ENABLE 19
145#define PCI_RETRY_ABORT_INTERRUPT_ENABLE 17
146#define PCI_MASTER_CYCLE_DONE_INTERRUPT_ENABLE 16
147#define GPIO_INTERRUPT_ENABLE 13
148#define DMA_D_INTERRUPT_ENABLE 12
149#define DMA_C_INTERRUPT_ENABLE 11
150#define DMA_B_INTERRUPT_ENABLE 10
151#define DMA_A_INTERRUPT_ENABLE 9
152#define EEPROM_DONE_INTERRUPT_ENABLE 8
153#define VBUS_INTERRUPT_ENABLE 7
154#define CONTROL_STATUS_INTERRUPT_ENABLE 6
155#define ROOT_PORT_RESET_INTERRUPT_ENABLE 4
156#define SUSPEND_REQUEST_INTERRUPT_ENABLE 3
157#define SUSPEND_REQUEST_CHANGE_INTERRUPT_ENABLE 2
158#define RESUME_INTERRUPT_ENABLE 1
159#define SOF_INTERRUPT_ENABLE 0
160 u32 irqstat0;
161#define INTA_ASSERTED 12
162#define SETUP_PACKET_INTERRUPT 7
163#define ENDPOINT_F_INTERRUPT 6
164#define ENDPOINT_E_INTERRUPT 5
165#define ENDPOINT_D_INTERRUPT 4
166#define ENDPOINT_C_INTERRUPT 3
167#define ENDPOINT_B_INTERRUPT 2
168#define ENDPOINT_A_INTERRUPT 1
169#define ENDPOINT_0_INTERRUPT 0
170 u32 irqstat1;
171#define POWER_STATE_CHANGE_INTERRUPT 27
172#define PCI_ARBITER_TIMEOUT_INTERRUPT 26
173#define PCI_PARITY_ERROR_INTERRUPT 25
174#define PCI_INTA_INTERRUPT 24
175#define PCI_PME_INTERRUPT 23
176#define PCI_SERR_INTERRUPT 22
177#define PCI_PERR_INTERRUPT 21
178#define PCI_MASTER_ABORT_RECEIVED_INTERRUPT 20
179#define PCI_TARGET_ABORT_RECEIVED_INTERRUPT 19
180#define PCI_RETRY_ABORT_INTERRUPT 17
181#define PCI_MASTER_CYCLE_DONE_INTERRUPT 16
182#define GPIO_INTERRUPT 13
183#define DMA_D_INTERRUPT 12
184#define DMA_C_INTERRUPT 11
185#define DMA_B_INTERRUPT 10
186#define DMA_A_INTERRUPT 9
187#define EEPROM_DONE_INTERRUPT 8
188#define VBUS_INTERRUPT 7
189#define CONTROL_STATUS_INTERRUPT 6
190#define ROOT_PORT_RESET_INTERRUPT 4
191#define SUSPEND_REQUEST_INTERRUPT 3
192#define SUSPEND_REQUEST_CHANGE_INTERRUPT 2
193#define RESUME_INTERRUPT 1
194#define SOF_INTERRUPT 0
195 // offset 0x0030
196 u32 idxaddr;
197 u32 idxdata;
198 u32 fifoctl;
199#define PCI_BASE2_RANGE 16
200#define IGNORE_FIFO_AVAILABILITY 3
201#define PCI_BASE2_SELECT 2
202#define FIFO_CONFIGURATION_SELECT 0
203 u32 _unused2;
204 // offset 0x0040
205 u32 memaddr;
206#define START 28
207#define DIRECTION 27
208#define FIFO_DIAGNOSTIC_SELECT 24
209#define MEMORY_ADDRESS 0
210 u32 memdata0;
211 u32 memdata1;
212 u32 _unused3;
213 // offset 0x0050
214 u32 gpioctl;
215#define GPIO3_LED_SELECT 12
216#define GPIO3_INTERRUPT_ENABLE 11
217#define GPIO2_INTERRUPT_ENABLE 10
218#define GPIO1_INTERRUPT_ENABLE 9
219#define GPIO0_INTERRUPT_ENABLE 8
220#define GPIO3_OUTPUT_ENABLE 7
221#define GPIO2_OUTPUT_ENABLE 6
222#define GPIO1_OUTPUT_ENABLE 5
223#define GPIO0_OUTPUT_ENABLE 4
224#define GPIO3_DATA 3
225#define GPIO2_DATA 2
226#define GPIO1_DATA 1
227#define GPIO0_DATA 0
228 u32 gpiostat;
229#define GPIO3_INTERRUPT 3
230#define GPIO2_INTERRUPT 2
231#define GPIO1_INTERRUPT 1
232#define GPIO0_INTERRUPT 0
233} __attribute__ ((packed));
234
235/* usb control, BAR0 + 0x0080 */
236struct net2280_usb_regs {
237 // offset 0x0080
238 u32 stdrsp;
239#define STALL_UNSUPPORTED_REQUESTS 31
240#define SET_TEST_MODE 16
241#define GET_OTHER_SPEED_CONFIGURATION 15
242#define GET_DEVICE_QUALIFIER 14
243#define SET_ADDRESS 13
244#define ENDPOINT_SET_CLEAR_HALT 12
245#define DEVICE_SET_CLEAR_DEVICE_REMOTE_WAKEUP 11
246#define GET_STRING_DESCRIPTOR_2 10
247#define GET_STRING_DESCRIPTOR_1 9
248#define GET_STRING_DESCRIPTOR_0 8
249#define GET_SET_INTERFACE 6
250#define GET_SET_CONFIGURATION 5
251#define GET_CONFIGURATION_DESCRIPTOR 4
252#define GET_DEVICE_DESCRIPTOR 3
253#define GET_ENDPOINT_STATUS 2
254#define GET_INTERFACE_STATUS 1
255#define GET_DEVICE_STATUS 0
256 u32 prodvendid;
257#define PRODUCT_ID 16
258#define VENDOR_ID 0
259 u32 relnum;
260 u32 usbctl;
261#define SERIAL_NUMBER_INDEX 16
262#define PRODUCT_ID_STRING_ENABLE 13
263#define VENDOR_ID_STRING_ENABLE 12
264#define USB_ROOT_PORT_WAKEUP_ENABLE 11
265#define VBUS_PIN 10
266#define TIMED_DISCONNECT 9
267#define SUSPEND_IMMEDIATELY 7
268#define SELF_POWERED_USB_DEVICE 6
269#define REMOTE_WAKEUP_SUPPORT 5
270#define PME_POLARITY 4
271#define USB_DETECT_ENABLE 3
272#define PME_WAKEUP_ENABLE 2
273#define DEVICE_REMOTE_WAKEUP_ENABLE 1
274#define SELF_POWERED_STATUS 0
275 // offset 0x0090
276 u32 usbstat;
277#define HIGH_SPEED 7
278#define FULL_SPEED 6
279#define GENERATE_RESUME 5
280#define GENERATE_DEVICE_REMOTE_WAKEUP 4
281 u32 xcvrdiag;
282#define FORCE_HIGH_SPEED_MODE 31
283#define FORCE_FULL_SPEED_MODE 30
284#define USB_TEST_MODE 24
285#define LINE_STATE 16
286#define TRANSCEIVER_OPERATION_MODE 2
287#define TRANSCEIVER_SELECT 1
288#define TERMINATION_SELECT 0
289 u32 setup0123;
290 u32 setup4567;
291 // offset 0x0090
292 u32 _unused0;
293 u32 ouraddr;
294#define FORCE_IMMEDIATE 7
295#define OUR_USB_ADDRESS 0
296 u32 ourconfig;
297} __attribute__ ((packed));
298
299/* pci control, BAR0 + 0x0100 */
300struct net2280_pci_regs {
301 // offset 0x0100
302 u32 pcimstctl;
303#define PCI_ARBITER_PARK_SELECT 13
304#define PCI_MULTI LEVEL_ARBITER 12
305#define PCI_RETRY_ABORT_ENABLE 11
306#define DMA_MEMORY_WRITE_AND_INVALIDATE_ENABLE 10
307#define DMA_READ_MULTIPLE_ENABLE 9
308#define DMA_READ_LINE_ENABLE 8
309#define PCI_MASTER_COMMAND_SELECT 6
310#define MEM_READ_OR_WRITE 0
311#define IO_READ_OR_WRITE 1
312#define CFG_READ_OR_WRITE 2
313#define PCI_MASTER_START 5
314#define PCI_MASTER_READ_WRITE 4
315#define PCI_MASTER_WRITE 0
316#define PCI_MASTER_READ 1
317#define PCI_MASTER_BYTE_WRITE_ENABLES 0
318 u32 pcimstaddr;
319 u32 pcimstdata;
320 u32 pcimststat;
321#define PCI_ARBITER_CLEAR 2
322#define PCI_EXTERNAL_ARBITER 1
323#define PCI_HOST_MODE 0
324} __attribute__ ((packed));
325
326/* dma control, BAR0 + 0x0180 ... array of four structs like this,
327 * for channels 0..3. see also struct net2280_dma: descriptor
328 * that can be loaded into some of these registers.
329 */
330struct net2280_dma_regs { /* [11.7] */
331 // offset 0x0180, 0x01a0, 0x01c0, 0x01e0,
332 u32 dmactl;
333#define DMA_SCATTER_GATHER_DONE_INTERRUPT_ENABLE 25
334#define DMA_CLEAR_COUNT_ENABLE 21
335#define DESCRIPTOR_POLLING_RATE 19
336#define POLL_CONTINUOUS 0
337#define POLL_1_USEC 1
338#define POLL_100_USEC 2
339#define POLL_1_MSEC 3
340#define DMA_VALID_BIT_POLLING_ENABLE 18
341#define DMA_VALID_BIT_ENABLE 17
342#define DMA_SCATTER_GATHER_ENABLE 16
343#define DMA_OUT_AUTO_START_ENABLE 4
344#define DMA_PREEMPT_ENABLE 3
345#define DMA_FIFO_VALIDATE 2
346#define DMA_ENABLE 1
347#define DMA_ADDRESS_HOLD 0
348 u32 dmastat;
349#define DMA_SCATTER_GATHER_DONE_INTERRUPT 25
350#define DMA_TRANSACTION_DONE_INTERRUPT 24
351#define DMA_ABORT 1
352#define DMA_START 0
353 u32 _unused0 [2];
354 // offset 0x0190, 0x01b0, 0x01d0, 0x01f0,
355 u32 dmacount;
356#define VALID_BIT 31
357#define DMA_DIRECTION 30
358#define DMA_DONE_INTERRUPT_ENABLE 29
359#define END_OF_CHAIN 28
360#define DMA_BYTE_COUNT_MASK ((1<<24)-1)
361#define DMA_BYTE_COUNT 0
362 u32 dmaaddr;
363 u32 dmadesc;
364 u32 _unused1;
365} __attribute__ ((packed));
366
367/* dedicated endpoint registers, BAR0 + 0x0200 */
368
369struct net2280_dep_regs { /* [11.8] */
370 // offset 0x0200, 0x0210, 0x220, 0x230, 0x240
371 u32 dep_cfg;
372 // offset 0x0204, 0x0214, 0x224, 0x234, 0x244
373 u32 dep_rsp;
374 u32 _unused [2];
375} __attribute__ ((packed));
376
377/* configurable endpoint registers, BAR0 + 0x0300 ... array of seven structs
378 * like this, for ep0 then the configurable endpoints A..F
379 * ep0 reserved for control; E and F have only 64 bytes of fifo
380 */
381struct net2280_ep_regs { /* [11.9] */
382 // offset 0x0300, 0x0320, 0x0340, 0x0360, 0x0380, 0x03a0, 0x03c0
383 u32 ep_cfg;
384#define ENDPOINT_BYTE_COUNT 16
385#define ENDPOINT_ENABLE 10
386#define ENDPOINT_TYPE 8
387#define ENDPOINT_DIRECTION 7
388#define ENDPOINT_NUMBER 0
389 u32 ep_rsp;
390#define SET_NAK_OUT_PACKETS 15
391#define SET_EP_HIDE_STATUS_PHASE 14
392#define SET_EP_FORCE_CRC_ERROR 13
393#define SET_INTERRUPT_MODE 12
394#define SET_CONTROL_STATUS_PHASE_HANDSHAKE 11
395#define SET_NAK_OUT_PACKETS_MODE 10
396#define SET_ENDPOINT_TOGGLE 9
397#define SET_ENDPOINT_HALT 8
398#define CLEAR_NAK_OUT_PACKETS 7
399#define CLEAR_EP_HIDE_STATUS_PHASE 6
400#define CLEAR_EP_FORCE_CRC_ERROR 5
401#define CLEAR_INTERRUPT_MODE 4
402#define CLEAR_CONTROL_STATUS_PHASE_HANDSHAKE 3
403#define CLEAR_NAK_OUT_PACKETS_MODE 2
404#define CLEAR_ENDPOINT_TOGGLE 1
405#define CLEAR_ENDPOINT_HALT 0
406 u32 ep_irqenb;
407#define SHORT_PACKET_OUT_DONE_INTERRUPT_ENABLE 6
408#define SHORT_PACKET_TRANSFERRED_INTERRUPT_ENABLE 5
409#define DATA_PACKET_RECEIVED_INTERRUPT_ENABLE 3
410#define DATA_PACKET_TRANSMITTED_INTERRUPT_ENABLE 2
411#define DATA_OUT_PING_TOKEN_INTERRUPT_ENABLE 1
412#define DATA_IN_TOKEN_INTERRUPT_ENABLE 0
413 u32 ep_stat;
414#define FIFO_VALID_COUNT 24
415#define HIGH_BANDWIDTH_OUT_TRANSACTION_PID 22
416#define TIMEOUT 21
417#define USB_STALL_SENT 20
418#define USB_IN_NAK_SENT 19
419#define USB_IN_ACK_RCVD 18
420#define USB_OUT_PING_NAK_SENT 17
421#define USB_OUT_ACK_SENT 16
422#define FIFO_OVERFLOW 13
423#define FIFO_UNDERFLOW 12
424#define FIFO_FULL 11
425#define FIFO_EMPTY 10
426#define FIFO_FLUSH 9
427#define SHORT_PACKET_OUT_DONE_INTERRUPT 6
428#define SHORT_PACKET_TRANSFERRED_INTERRUPT 5
429#define NAK_OUT_PACKETS 4
430#define DATA_PACKET_RECEIVED_INTERRUPT 3
431#define DATA_PACKET_TRANSMITTED_INTERRUPT 2
432#define DATA_OUT_PING_TOKEN_INTERRUPT 1
433#define DATA_IN_TOKEN_INTERRUPT 0
434 // offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0
435 u32 ep_avail;
436 u32 ep_data;
437 u32 _unused0 [2];
438} __attribute__ ((packed));
439 26
440/*-------------------------------------------------------------------------*/ 27/*-------------------------------------------------------------------------*/
441 28
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 51424f66a765..68e3d8f5da89 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -572,9 +572,10 @@ static void source_sink_complete (struct usb_ep *ep, struct usb_request *req)
572 switch (status) { 572 switch (status) {
573 573
574 case 0: /* normal completion? */ 574 case 0: /* normal completion? */
575 if (ep == dev->out_ep) 575 if (ep == dev->out_ep) {
576 check_read_data (dev, ep, req); 576 check_read_data (dev, ep, req);
577 else 577 memset (req->buf, 0x55, req->length);
578 } else
578 reinit_write_data (dev, ep, req); 579 reinit_write_data (dev, ep, req);
579 break; 580 break;
580 581
@@ -626,6 +627,8 @@ source_sink_start_ep (struct usb_ep *ep, gfp_t gfp_flags)
626 627
627 if (strcmp (ep->name, EP_IN_NAME) == 0) 628 if (strcmp (ep->name, EP_IN_NAME) == 0)
628 reinit_write_data (ep->driver_data, ep, req); 629 reinit_write_data (ep->driver_data, ep, req);
630 else
631 memset (req->buf, 0x55, req->length);
629 632
630 status = usb_ep_queue (ep, req, gfp_flags); 633 status = usb_ep_queue (ep, req, gfp_flags);
631 if (status) { 634 if (status) {
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 980030d684d5..6b7350b52419 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -20,7 +20,7 @@
20#include <asm/arch/board.h> 20#include <asm/arch/board.h>
21 21
22#ifndef CONFIG_ARCH_AT91RM9200 22#ifndef CONFIG_ARCH_AT91RM9200
23#error "This file is AT91RM9200 bus glue. CONFIG_ARCH_AT91RM9200 must be defined." 23#error "CONFIG_ARCH_AT91RM9200 must be defined."
24#endif 24#endif
25 25
26/* interface and function clocks */ 26/* interface and function clocks */
@@ -84,8 +84,6 @@ static int usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
84 * Allocates basic resources for this USB host controller, and 84 * Allocates basic resources for this USB host controller, and
85 * then invokes the start() method for the HCD associated with it 85 * then invokes the start() method for the HCD associated with it
86 * through the hotplug entry's driver_data. 86 * through the hotplug entry's driver_data.
87 *
88 * Store this function in the HCD's struct pci_driver as probe().
89 */ 87 */
90int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev) 88int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *pdev)
91{ 89{
@@ -148,7 +146,6 @@ int usb_hcd_at91_probe (const struct hc_driver *driver, struct platform_device *
148} 146}
149 147
150 148
151/* may be called without controller electrically present */
152/* may be called with controller, bus, and devices active */ 149/* may be called with controller, bus, and devices active */
153 150
154/** 151/**
@@ -166,11 +163,11 @@ static int usb_hcd_at91_remove (struct usb_hcd *hcd, struct platform_device *pde
166 usb_remove_hcd(hcd); 163 usb_remove_hcd(hcd);
167 at91_stop_hc(pdev); 164 at91_stop_hc(pdev);
168 iounmap(hcd->regs); 165 iounmap(hcd->regs);
169 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 166 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
170 167
171 clk_put(fclk); 168 clk_put(fclk);
172 clk_put(iclk); 169 clk_put(iclk);
173 fclk = iclk = NULL; 170 fclk = iclk = NULL;
174 171
175 dev_set_drvdata(&pdev->dev, NULL); 172 dev_set_drvdata(&pdev->dev, NULL);
176 return 0; 173 return 0;
@@ -235,8 +232,8 @@ static const struct hc_driver ohci_at91_hc_driver = {
235 .hub_control = ohci_hub_control, 232 .hub_control = ohci_hub_control,
236 233
237#ifdef CONFIG_PM 234#ifdef CONFIG_PM
238 .hub_suspend = ohci_hub_suspend, 235 .bus_suspend = ohci_bus_suspend,
239 .hub_resume = ohci_hub_resume, 236 .bus_resume = ohci_bus_resume,
240#endif 237#endif
241 .start_port_reset = ohci_start_port_reset, 238 .start_port_reset = ohci_start_port_reset,
242}; 239};
@@ -254,21 +251,21 @@ static int ohci_hcd_at91_drv_remove(struct platform_device *dev)
254} 251}
255 252
256#ifdef CONFIG_PM 253#ifdef CONFIG_PM
257static int ohci_hcd_at91_drv_suspend(struct platform_device *dev, u32 state, u32 level)
258{
259 printk("%s(%s:%d): not implemented yet\n",
260 __func__, __FILE__, __LINE__);
261 254
255/* REVISIT suspend/resume look "too" simple here */
256
257static int
258ohci_hcd_at91_drv_suspend(struct platform_device *dev, pm_message_t mesg)
259{
262 clk_disable(fclk); 260 clk_disable(fclk);
261 clk_disable(iclk);
263 262
264 return 0; 263 return 0;
265} 264}
266 265
267static int ohci_hcd_at91_drv_resume(struct platform_device *dev, u32 state) 266static int ohci_hcd_at91_drv_resume(struct platform_device *dev)
268{ 267{
269 printk("%s(%s:%d): not implemented yet\n", 268 clk_enable(iclk);
270 __func__, __FILE__, __LINE__);
271
272 clk_enable(fclk); 269 clk_enable(fclk);
273 270
274 return 0; 271 return 0;
@@ -278,6 +275,8 @@ static int ohci_hcd_at91_drv_resume(struct platform_device *dev, u32 state)
278#define ohci_hcd_at91_drv_resume NULL 275#define ohci_hcd_at91_drv_resume NULL
279#endif 276#endif
280 277
278MODULE_ALIAS("at91rm9200-ohci");
279
281static struct platform_driver ohci_hcd_at91_driver = { 280static struct platform_driver ohci_hcd_at91_driver = {
282 .probe = ohci_hcd_at91_drv_probe, 281 .probe = ohci_hcd_at91_drv_probe,
283 .remove = ohci_hcd_at91_drv_remove, 282 .remove = ohci_hcd_at91_drv_remove,
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 682bf2215660..1da5de573a6f 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -30,6 +30,7 @@
30/* clock device associated with the hcd */ 30/* clock device associated with the hcd */
31 31
32static struct clk *clk; 32static struct clk *clk;
33static struct clk *usb_clk;
33 34
34/* forward definitions */ 35/* forward definitions */
35 36
@@ -37,7 +38,7 @@ static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc);
37 38
38/* conversion functions */ 39/* conversion functions */
39 40
40struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd) 41static struct s3c2410_hcd_info *to_s3c2410_info(struct usb_hcd *hcd)
41{ 42{
42 return hcd->self.controller->platform_data; 43 return hcd->self.controller->platform_data;
43} 44}
@@ -47,6 +48,10 @@ static void s3c2410_start_hc(struct platform_device *dev, struct usb_hcd *hcd)
47 struct s3c2410_hcd_info *info = dev->dev.platform_data; 48 struct s3c2410_hcd_info *info = dev->dev.platform_data;
48 49
49 dev_dbg(&dev->dev, "s3c2410_start_hc:\n"); 50 dev_dbg(&dev->dev, "s3c2410_start_hc:\n");
51
52 clk_enable(usb_clk);
53 mdelay(2); /* let the bus clock stabilise */
54
50 clk_enable(clk); 55 clk_enable(clk);
51 56
52 if (info != NULL) { 57 if (info != NULL) {
@@ -75,6 +80,7 @@ static void s3c2410_stop_hc(struct platform_device *dev)
75 } 80 }
76 81
77 clk_disable(clk); 82 clk_disable(clk);
83 clk_disable(usb_clk);
78} 84}
79 85
80/* ohci_s3c2410_hub_status_data 86/* ohci_s3c2410_hub_status_data
@@ -316,7 +322,8 @@ static void s3c2410_hcd_oc(struct s3c2410_hcd_info *info, int port_oc)
316 * 322 *
317*/ 323*/
318 324
319void usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev) 325static void
326usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
320{ 327{
321 usb_remove_hcd(hcd); 328 usb_remove_hcd(hcd);
322 s3c2410_stop_hc(dev); 329 s3c2410_stop_hc(dev);
@@ -334,8 +341,8 @@ void usb_hcd_s3c2410_remove (struct usb_hcd *hcd, struct platform_device *dev)
334 * through the hotplug entry's driver_data. 341 * through the hotplug entry's driver_data.
335 * 342 *
336 */ 343 */
337int usb_hcd_s3c2410_probe (const struct hc_driver *driver, 344static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
338 struct platform_device *dev) 345 struct platform_device *dev)
339{ 346{
340 struct usb_hcd *hcd = NULL; 347 struct usb_hcd *hcd = NULL;
341 int retval; 348 int retval;
@@ -353,14 +360,21 @@ int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
353 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 360 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
354 dev_err(&dev->dev, "request_mem_region failed"); 361 dev_err(&dev->dev, "request_mem_region failed");
355 retval = -EBUSY; 362 retval = -EBUSY;
356 goto err0; 363 goto err_put;
357 } 364 }
358 365
359 clk = clk_get(NULL, "usb-host"); 366 clk = clk_get(&dev->dev, "usb-host");
360 if (IS_ERR(clk)) { 367 if (IS_ERR(clk)) {
361 dev_err(&dev->dev, "cannot get usb-host clock\n"); 368 dev_err(&dev->dev, "cannot get usb-host clock\n");
362 retval = -ENOENT; 369 retval = -ENOENT;
363 goto err1; 370 goto err_mem;
371 }
372
373 usb_clk = clk_get(&dev->dev, "upll");
374 if (IS_ERR(usb_clk)) {
375 dev_err(&dev->dev, "cannot get usb-host clock\n");
376 retval = -ENOENT;
377 goto err_clk;
364 } 378 }
365 379
366 s3c2410_start_hc(dev, hcd); 380 s3c2410_start_hc(dev, hcd);
@@ -369,26 +383,29 @@ int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
369 if (!hcd->regs) { 383 if (!hcd->regs) {
370 dev_err(&dev->dev, "ioremap failed\n"); 384 dev_err(&dev->dev, "ioremap failed\n");
371 retval = -ENOMEM; 385 retval = -ENOMEM;
372 goto err2; 386 goto err_ioremap;
373 } 387 }
374 388
375 ohci_hcd_init(hcd_to_ohci(hcd)); 389 ohci_hcd_init(hcd_to_ohci(hcd));
376 390
377 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT); 391 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
378 if (retval != 0) 392 if (retval != 0)
379 goto err2; 393 goto err_ioremap;
380 394
381 return 0; 395 return 0;
382 396
383 err2: 397 err_ioremap:
384 s3c2410_stop_hc(dev); 398 s3c2410_stop_hc(dev);
385 iounmap(hcd->regs); 399 iounmap(hcd->regs);
400 clk_put(usb_clk);
401
402 err_clk:
386 clk_put(clk); 403 clk_put(clk);
387 404
388 err1: 405 err_mem:
389 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 406 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
390 407
391 err0: 408 err_put:
392 usb_put_hcd(hcd); 409 usb_put_hcd(hcd);
393 return retval; 410 return retval;
394} 411}
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 9e81c26313f9..1045f846fbe2 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/acpi.h> 17#include <linux/acpi.h>
18#include "pci-quirks.h"
18 19
19 20
20#define UHCI_USBLEGSUP 0xc0 /* legacy support */ 21#define UHCI_USBLEGSUP 0xc0 /* legacy support */
diff --git a/drivers/usb/host/pci-quirks.h b/drivers/usb/host/pci-quirks.h
new file mode 100644
index 000000000000..1564edfff6fe
--- /dev/null
+++ b/drivers/usb/host/pci-quirks.h
@@ -0,0 +1,7 @@
1#ifndef __LINUX_USB_PCI_QUIRKS_H
2#define __LINUX_USB_PCI_QUIRKS_H
3
4void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
5int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
6
7#endif /* __LINUX_USB_PCI_QUIRKS_H */
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 134d2000128a..302aa1ec312f 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -67,11 +67,11 @@ module_param(pc_debug, int, 0644);
67static const char driver_name[DEV_NAME_LEN] = "sl811_cs"; 67static const char driver_name[DEV_NAME_LEN] = "sl811_cs";
68 68
69typedef struct local_info_t { 69typedef struct local_info_t {
70 dev_link_t link; 70 struct pcmcia_device *p_dev;
71 dev_node_t node; 71 dev_node_t node;
72} local_info_t; 72} local_info_t;
73 73
74static void sl811_cs_release(dev_link_t * link); 74static void sl811_cs_release(struct pcmcia_device * link);
75 75
76/*====================================================================*/ 76/*====================================================================*/
77 77
@@ -138,41 +138,27 @@ static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq)
138 138
139/*====================================================================*/ 139/*====================================================================*/
140 140
141static void sl811_cs_detach(struct pcmcia_device *p_dev) 141static void sl811_cs_detach(struct pcmcia_device *link)
142{ 142{
143 dev_link_t *link = dev_to_instance(p_dev);
144
145 DBG(0, "sl811_cs_detach(0x%p)\n", link); 143 DBG(0, "sl811_cs_detach(0x%p)\n", link);
146 144
147 link->state &= ~DEV_PRESENT; 145 sl811_cs_release(link);
148 if (link->state & DEV_CONFIG)
149 sl811_cs_release(link);
150 146
151 /* This points to the parent local_info_t struct */ 147 /* This points to the parent local_info_t struct */
152 kfree(link->priv); 148 kfree(link->priv);
153} 149}
154 150
155static void sl811_cs_release(dev_link_t * link) 151static void sl811_cs_release(struct pcmcia_device * link)
156{ 152{
157
158 DBG(0, "sl811_cs_release(0x%p)\n", link); 153 DBG(0, "sl811_cs_release(0x%p)\n", link);
159 154
160 /* Unlink the device chain */ 155 pcmcia_disable_device(link);
161 link->dev = NULL;
162
163 platform_device_unregister(&platform_dev); 156 platform_device_unregister(&platform_dev);
164 pcmcia_release_configuration(link->handle);
165 if (link->io.NumPorts1)
166 pcmcia_release_io(link->handle, &link->io);
167 if (link->irq.AssignedIRQ)
168 pcmcia_release_irq(link->handle, &link->irq);
169 link->state &= ~DEV_CONFIG;
170} 157}
171 158
172static void sl811_cs_config(dev_link_t *link) 159static int sl811_cs_config(struct pcmcia_device *link)
173{ 160{
174 client_handle_t handle = link->handle; 161 struct device *parent = &handle_to_dev(link);
175 struct device *parent = &handle_to_dev(handle);
176 local_info_t *dev = link->priv; 162 local_info_t *dev = link->priv;
177 tuple_t tuple; 163 tuple_t tuple;
178 cisparse_t parse; 164 cisparse_t parse;
@@ -188,27 +174,23 @@ static void sl811_cs_config(dev_link_t *link)
188 tuple.TupleData = buf; 174 tuple.TupleData = buf;
189 tuple.TupleDataMax = sizeof(buf); 175 tuple.TupleDataMax = sizeof(buf);
190 tuple.TupleOffset = 0; 176 tuple.TupleOffset = 0;
191 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 177 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
192 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); 178 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
193 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); 179 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
194 link->conf.ConfigBase = parse.config.base; 180 link->conf.ConfigBase = parse.config.base;
195 link->conf.Present = parse.config.rmask[0]; 181 link->conf.Present = parse.config.rmask[0];
196 182
197 /* Configure card */
198 link->state |= DEV_CONFIG;
199
200 /* Look up the current Vcc */ 183 /* Look up the current Vcc */
201 CS_CHECK(GetConfigurationInfo, 184 CS_CHECK(GetConfigurationInfo,
202 pcmcia_get_configuration_info(handle, &conf)); 185 pcmcia_get_configuration_info(link, &conf));
203 link->conf.Vcc = conf.Vcc;
204 186
205 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 187 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
206 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); 188 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
207 while (1) { 189 while (1) {
208 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 190 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
209 191
210 if (pcmcia_get_tuple_data(handle, &tuple) != 0 192 if (pcmcia_get_tuple_data(link, &tuple) != 0
211 || pcmcia_parse_tuple(handle, &tuple, &parse) 193 || pcmcia_parse_tuple(link, &tuple, &parse)
212 != 0) 194 != 0)
213 goto next_entry; 195 goto next_entry;
214 196
@@ -234,10 +216,10 @@ static void sl811_cs_config(dev_link_t *link)
234 } 216 }
235 217
236 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 218 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
237 link->conf.Vpp1 = link->conf.Vpp2 = 219 link->conf.Vpp =
238 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 220 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
239 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 221 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
240 link->conf.Vpp1 = link->conf.Vpp2 = 222 link->conf.Vpp =
241 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; 223 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
242 224
243 /* we need an interrupt */ 225 /* we need an interrupt */
@@ -254,15 +236,14 @@ static void sl811_cs_config(dev_link_t *link)
254 link->io.BasePort1 = io->win[0].base; 236 link->io.BasePort1 = io->win[0].base;
255 link->io.NumPorts1 = io->win[0].len; 237 link->io.NumPorts1 = io->win[0].len;
256 238
257 if (pcmcia_request_io(link->handle, &link->io) != 0) 239 if (pcmcia_request_io(link, &link->io) != 0)
258 goto next_entry; 240 goto next_entry;
259 } 241 }
260 break; 242 break;
261 243
262next_entry: 244next_entry:
263 if (link->io.NumPorts1) 245 pcmcia_disable_device(link);
264 pcmcia_release_io(link->handle, &link->io); 246 last_ret = pcmcia_get_next_tuple(link, &tuple);
265 last_ret = pcmcia_get_next_tuple(handle, &tuple);
266 } 247 }
267 248
268 /* require an IRQ and two registers */ 249 /* require an IRQ and two registers */
@@ -270,71 +251,46 @@ next_entry:
270 goto cs_failed; 251 goto cs_failed;
271 if (link->conf.Attributes & CONF_ENABLE_IRQ) 252 if (link->conf.Attributes & CONF_ENABLE_IRQ)
272 CS_CHECK(RequestIRQ, 253 CS_CHECK(RequestIRQ,
273 pcmcia_request_irq(link->handle, &link->irq)); 254 pcmcia_request_irq(link, &link->irq));
274 else 255 else
275 goto cs_failed; 256 goto cs_failed;
276 257
277 CS_CHECK(RequestConfiguration, 258 CS_CHECK(RequestConfiguration,
278 pcmcia_request_configuration(link->handle, &link->conf)); 259 pcmcia_request_configuration(link, &link->conf));
279 260
280 sprintf(dev->node.dev_name, driver_name); 261 sprintf(dev->node.dev_name, driver_name);
281 dev->node.major = dev->node.minor = 0; 262 dev->node.major = dev->node.minor = 0;
282 link->dev = &dev->node; 263 link->dev_node = &dev->node;
283 264
284 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", 265 printk(KERN_INFO "%s: index 0x%02x: ",
285 dev->node.dev_name, link->conf.ConfigIndex, 266 dev->node.dev_name, link->conf.ConfigIndex);
286 link->conf.Vcc/10, link->conf.Vcc%10); 267 if (link->conf.Vpp)
287 if (link->conf.Vpp1) 268 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
288 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
289 printk(", irq %d", link->irq.AssignedIRQ); 269 printk(", irq %d", link->irq.AssignedIRQ);
290 printk(", io 0x%04x-0x%04x", link->io.BasePort1, 270 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
291 link->io.BasePort1+link->io.NumPorts1-1); 271 link->io.BasePort1+link->io.NumPorts1-1);
292 printk("\n"); 272 printk("\n");
293 273
294 link->state &= ~DEV_CONFIG_PENDING;
295
296 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ) 274 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
297 < 0) { 275 < 0) {
298cs_failed: 276cs_failed:
299 printk("sl811_cs_config failed\n"); 277 printk("sl811_cs_config failed\n");
300 cs_error(link->handle, last_fn, last_ret); 278 cs_error(link, last_fn, last_ret);
301 sl811_cs_release(link); 279 sl811_cs_release(link);
302 link->state &= ~DEV_CONFIG_PENDING; 280 return -ENODEV;
303 } 281 }
304}
305
306static int sl811_suspend(struct pcmcia_device *dev)
307{
308 dev_link_t *link = dev_to_instance(dev);
309
310 link->state |= DEV_SUSPEND;
311 if (link->state & DEV_CONFIG)
312 pcmcia_release_configuration(link->handle);
313
314 return 0;
315}
316
317static int sl811_resume(struct pcmcia_device *dev)
318{
319 dev_link_t *link = dev_to_instance(dev);
320
321 link->state &= ~DEV_SUSPEND;
322 if (link->state & DEV_CONFIG)
323 pcmcia_request_configuration(link->handle, &link->conf);
324
325 return 0; 282 return 0;
326} 283}
327 284
328static int sl811_cs_attach(struct pcmcia_device *p_dev) 285static int sl811_cs_probe(struct pcmcia_device *link)
329{ 286{
330 local_info_t *local; 287 local_info_t *local;
331 dev_link_t *link;
332 288
333 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 289 local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
334 if (!local) 290 if (!local)
335 return -ENOMEM; 291 return -ENOMEM;
336 memset(local, 0, sizeof(local_info_t)); 292 memset(local, 0, sizeof(local_info_t));
337 link = &local->link; 293 local->p_dev = link;
338 link->priv = local; 294 link->priv = local;
339 295
340 /* Initialize */ 296 /* Initialize */
@@ -343,16 +299,9 @@ static int sl811_cs_attach(struct pcmcia_device *p_dev)
343 link->irq.Handler = NULL; 299 link->irq.Handler = NULL;
344 300
345 link->conf.Attributes = 0; 301 link->conf.Attributes = 0;
346 link->conf.Vcc = 33;
347 link->conf.IntType = INT_MEMORY_AND_IO; 302 link->conf.IntType = INT_MEMORY_AND_IO;
348 303
349 link->handle = p_dev; 304 return sl811_cs_config(link);
350 p_dev->instance = link;
351
352 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
353 sl811_cs_config(link);
354
355 return 0;
356} 305}
357 306
358static struct pcmcia_device_id sl811_ids[] = { 307static struct pcmcia_device_id sl811_ids[] = {
@@ -366,11 +315,9 @@ static struct pcmcia_driver sl811_cs_driver = {
366 .drv = { 315 .drv = {
367 .name = (char *)driver_name, 316 .name = (char *)driver_name,
368 }, 317 },
369 .probe = sl811_cs_attach, 318 .probe = sl811_cs_probe,
370 .remove = sl811_cs_detach, 319 .remove = sl811_cs_detach,
371 .id_table = sl811_ids, 320 .id_table = sl811_ids,
372 .suspend = sl811_suspend,
373 .resume = sl811_resume,
374}; 321};
375 322
376/*====================================================================*/ 323/*====================================================================*/
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 4edb8330c440..c0c4db78b590 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -50,6 +50,7 @@
50 50
51#include "../core/hcd.h" 51#include "../core/hcd.h"
52#include "uhci-hcd.h" 52#include "uhci-hcd.h"
53#include "pci-quirks.h"
53 54
54/* 55/*
55 * Version Information 56 * Version Information
@@ -100,9 +101,6 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
100#include "uhci-q.c" 101#include "uhci-q.c"
101#include "uhci-hub.c" 102#include "uhci-hub.c"
102 103
103extern void uhci_reset_hc(struct pci_dev *pdev, unsigned long base);
104extern int uhci_check_and_reset_hc(struct pci_dev *pdev, unsigned long base);
105
106/* 104/*
107 * Finish up a host controller reset and update the recorded state. 105 * Finish up a host controller reset and update the recorded state.
108 */ 106 */
@@ -117,8 +115,7 @@ static void finish_reset(struct uhci_hcd *uhci)
117 for (port = 0; port < uhci->rh_numports; ++port) 115 for (port = 0; port < uhci->rh_numports; ++port)
118 outw(0, uhci->io_addr + USBPORTSC1 + (port * 2)); 116 outw(0, uhci->io_addr + USBPORTSC1 + (port * 2));
119 117
120 uhci->port_c_suspend = uhci->suspended_ports = 118 uhci->port_c_suspend = uhci->resuming_ports = 0;
121 uhci->resuming_ports = 0;
122 uhci->rh_state = UHCI_RH_RESET; 119 uhci->rh_state = UHCI_RH_RESET;
123 uhci->is_stopped = UHCI_IS_STOPPED; 120 uhci->is_stopped = UHCI_IS_STOPPED;
124 uhci_to_hcd(uhci)->state = HC_STATE_HALT; 121 uhci_to_hcd(uhci)->state = HC_STATE_HALT;
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 4a69c7eb09bd..d5c8f4d92823 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -415,7 +415,6 @@ struct uhci_hcd {
415 415
416 /* Support for port suspend/resume/reset */ 416 /* Support for port suspend/resume/reset */
417 unsigned long port_c_suspend; /* Bit-arrays of ports */ 417 unsigned long port_c_suspend; /* Bit-arrays of ports */
418 unsigned long suspended_ports;
419 unsigned long resuming_ports; 418 unsigned long resuming_ports;
420 unsigned long ports_timeout; /* Time to stop signalling */ 419 unsigned long ports_timeout; /* Time to stop signalling */
421 420
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 152971d16769..c8451d9578f1 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -85,11 +85,10 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
85{ 85{
86 int status; 86 int status;
87 87
88 if (test_bit(port, &uhci->suspended_ports)) { 88 if (inw(port_addr) & (USBPORTSC_SUSP | USBPORTSC_RD)) {
89 CLR_RH_PORTSTAT(USBPORTSC_SUSP | USBPORTSC_RD); 89 CLR_RH_PORTSTAT(USBPORTSC_SUSP | USBPORTSC_RD);
90 clear_bit(port, &uhci->suspended_ports); 90 if (test_bit(port, &uhci->resuming_ports))
91 clear_bit(port, &uhci->resuming_ports); 91 set_bit(port, &uhci->port_c_suspend);
92 set_bit(port, &uhci->port_c_suspend);
93 92
94 /* The controller won't actually turn off the RD bit until 93 /* The controller won't actually turn off the RD bit until
95 * it has had a chance to send a low-speed EOP sequence, 94 * it has had a chance to send a low-speed EOP sequence,
@@ -97,6 +96,7 @@ static void uhci_finish_suspend(struct uhci_hcd *uhci, int port,
97 * slightly longer for good luck. */ 96 * slightly longer for good luck. */
98 udelay(4); 97 udelay(4);
99 } 98 }
99 clear_bit(port, &uhci->resuming_ports);
100} 100}
101 101
102/* Wait for the UHCI controller in HP's iLO2 server management chip. 102/* Wait for the UHCI controller in HP's iLO2 server management chip.
@@ -265,8 +265,6 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
265 wPortChange |= USB_PORT_STAT_C_SUSPEND; 265 wPortChange |= USB_PORT_STAT_C_SUSPEND;
266 lstatus |= 1; 266 lstatus |= 1;
267 } 267 }
268 if (test_bit(port, &uhci->suspended_ports))
269 lstatus |= 2;
270 if (test_bit(port, &uhci->resuming_ports)) 268 if (test_bit(port, &uhci->resuming_ports))
271 lstatus |= 4; 269 lstatus |= 4;
272 270
@@ -309,7 +307,6 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
309 307
310 switch (wValue) { 308 switch (wValue) {
311 case USB_PORT_FEAT_SUSPEND: 309 case USB_PORT_FEAT_SUSPEND:
312 set_bit(port, &uhci->suspended_ports);
313 SET_RH_PORTSTAT(USBPORTSC_SUSP); 310 SET_RH_PORTSTAT(USBPORTSC_SUSP);
314 OK(0); 311 OK(0);
315 case USB_PORT_FEAT_RESET: 312 case USB_PORT_FEAT_RESET:
@@ -343,8 +340,11 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
343 CLR_RH_PORTSTAT(USBPORTSC_PEC); 340 CLR_RH_PORTSTAT(USBPORTSC_PEC);
344 OK(0); 341 OK(0);
345 case USB_PORT_FEAT_SUSPEND: 342 case USB_PORT_FEAT_SUSPEND:
346 if (test_bit(port, &uhci->suspended_ports) && 343 if (!(inw(port_addr) & USBPORTSC_SUSP)) {
347 !test_and_set_bit(port, 344
345 /* Make certain the port isn't suspended */
346 uhci_finish_suspend(uhci, port, port_addr);
347 } else if (!test_and_set_bit(port,
348 &uhci->resuming_ports)) { 348 &uhci->resuming_ports)) {
349 SET_RH_PORTSTAT(USBPORTSC_RD); 349 SET_RH_PORTSTAT(USBPORTSC_RD);
350 350
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 5246b35301de..650103bc9618 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -200,45 +200,41 @@ config USB_POWERMATE
200 To compile this driver as a module, choose M here: the 200 To compile this driver as a module, choose M here: the
201 module will be called powermate. 201 module will be called powermate.
202 202
203config USB_MTOUCH 203config USB_TOUCHSCREEN
204 tristate "MicroTouch USB Touchscreen Driver" 204 tristate "USB Touchscreen Driver"
205 depends on USB && INPUT 205 depends on USB && INPUT
206 ---help--- 206 ---help---
207 Say Y here if you want to use a MicroTouch (Now 3M) USB 207 USB Touchscreen driver for:
208 Touchscreen controller. 208 - eGalax Touchkit USB
209 - PanJit TouchSet USB
210 - 3M MicroTouch USB
211 - ITM
209 212
210 See <file:Documentation/usb/mtouch.txt> for additional information. 213 Have a look at <http://linux.chapter7.ch/touchkit/> for
211 214 a usage description and the required user-space stuff.
212 To compile this driver as a module, choose M here: the
213 module will be called mtouchusb.
214
215config USB_ITMTOUCH
216 tristate "ITM Touch USB Touchscreen Driver"
217 depends on USB && INPUT
218 ---help---
219 Say Y here if you want to use a ITM Touch USB
220 Touchscreen controller.
221
222 This touchscreen is used in LG 1510SF monitors.
223 215
224 To compile this driver as a module, choose M here: the 216 To compile this driver as a module, choose M here: the
225 module will be called itmtouch. 217 module will be called usbtouchscreen.
226 218
227config USB_EGALAX 219config USB_TOUCHSCREEN_EGALAX
228 tristate "eGalax TouchKit USB Touchscreen Driver" 220 default y
229 depends on USB && INPUT 221 bool "eGalax device support" if EMBEDDED
230 ---help--- 222 depends on USB_TOUCHSCREEN
231 Say Y here if you want to use a eGalax TouchKit USB
232 Touchscreen controller.
233 223
234 The driver has been tested on a Xenarc 700TSV monitor 224config USB_TOUCHSCREEN_PANJIT
235 with eGalax touchscreen. 225 default y
226 bool "PanJit device support" if EMBEDDED
227 depends on USB_TOUCHSCREEN
236 228
237 Have a look at <http://linux.chapter7.ch/touchkit/> for 229config USB_TOUCHSCREEN_3M
238 a usage description and the required user-space stuff. 230 default y
231 bool "3M/Microtouch device support" if EMBEDDED
232 depends on USB_TOUCHSCREEN
239 233
240 To compile this driver as a module, choose M here: the 234config USB_TOUCHSCREEN_ITM
241 module will be called touchkitusb. 235 default y
236 bool "ITM device support" if EMBEDDED
237 depends on USB_TOUCHSCREEN
242 238
243config USB_YEALINK 239config USB_YEALINK
244 tristate "Yealink usb-p1k voip phone" 240 tristate "Yealink usb-p1k voip phone"
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index d512d9f488fe..764114529c56 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_USB_MOUSE) += usbmouse.o
37obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o 37obj-$(CONFIG_USB_MTOUCH) += mtouchusb.o
38obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o 38obj-$(CONFIG_USB_ITMTOUCH) += itmtouch.o
39obj-$(CONFIG_USB_EGALAX) += touchkitusb.o 39obj-$(CONFIG_USB_EGALAX) += touchkitusb.o
40obj-$(CONFIG_USB_TOUCHSCREEN) += usbtouchscreen.o
40obj-$(CONFIG_USB_POWERMATE) += powermate.o 41obj-$(CONFIG_USB_POWERMATE) += powermate.o
41obj-$(CONFIG_USB_WACOM) += wacom.o 42obj-$(CONFIG_USB_WACOM) += wacom.o
42obj-$(CONFIG_USB_ACECAD) += acecad.o 43obj-$(CONFIG_USB_ACECAD) += acecad.o
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index d4bf1701046b..f419bd82ab7f 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1372,6 +1372,11 @@ void hid_close(struct hid_device *hid)
1372 usb_kill_urb(hid->urbin); 1372 usb_kill_urb(hid->urbin);
1373} 1373}
1374 1374
1375#define USB_VENDOR_ID_PANJIT 0x134c
1376
1377#define USB_VENDOR_ID_SILVERCREST 0x062a
1378#define USB_DEVICE_ID_SILVERCREST_KB 0x0201
1379
1375/* 1380/*
1376 * Initialize all reports 1381 * Initialize all reports
1377 */ 1382 */
@@ -1655,9 +1660,12 @@ static const struct hid_blacklist {
1655 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3, HID_QUIRK_IGNORE }, 1660 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3, HID_QUIRK_IGNORE },
1656 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 1, HID_QUIRK_IGNORE }, 1661 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 1, HID_QUIRK_IGNORE },
1657 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 2, HID_QUIRK_IGNORE }, 1662 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 2, HID_QUIRK_IGNORE },
1663 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 3, HID_QUIRK_IGNORE },
1664 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 4, HID_QUIRK_IGNORE },
1658 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 5, HID_QUIRK_IGNORE }, 1665 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS3 + 5, HID_QUIRK_IGNORE },
1659 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_CINTIQ, HID_QUIRK_IGNORE }, 1666 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_CINTIQ, HID_QUIRK_IGNORE },
1660 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_DTF, HID_QUIRK_IGNORE }, 1667 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_DTF, HID_QUIRK_IGNORE },
1668 { USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_DTF + 3, HID_QUIRK_IGNORE },
1661 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1669 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1662 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE }, 1670 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
1663 1671
@@ -1675,6 +1683,7 @@ static const struct hid_blacklist {
1675 { USB_VENDOR_ID_HP, USB_DEVICE_ID_HP_USBHUB_KB, HID_QUIRK_NOGET }, 1683 { USB_VENDOR_ID_HP, USB_DEVICE_ID_HP_USBHUB_KB, HID_QUIRK_NOGET },
1676 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET }, 1684 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET },
1677 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1685 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1686 { USB_VENDOR_ID_SILVERCREST, USB_DEVICE_ID_SILVERCREST_KB, HID_QUIRK_NOGET },
1678 1687
1679 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_POWERMOUSE, HID_QUIRK_2WHEEL_POWERMOUSE }, 1688 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_POWERMOUSE, HID_QUIRK_2WHEEL_POWERMOUSE },
1680 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, 1689 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
@@ -1701,6 +1710,11 @@ static const struct hid_blacklist {
1701 { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN }, 1710 { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
1702 { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN }, 1711 { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
1703 1712
1713 { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE },
1714 { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE },
1715 { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE },
1716 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
1717
1704 { 0, 0 } 1718 { 0, 0 }
1705}; 1719};
1706 1720
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index 72e698658b53..d5c91ee67991 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -34,12 +34,6 @@
34 34
35#include "hid.h" 35#include "hid.h"
36 36
37/* Drivers' initializing functions */
38extern int hid_lgff_init(struct hid_device* hid);
39extern int hid_lg3d_init(struct hid_device* hid);
40extern int hid_pid_init(struct hid_device* hid);
41extern int hid_tmff_init(struct hid_device* hid);
42
43/* 37/*
44 * This table contains pointers to initializers. To add support for new 38 * This table contains pointers to initializers. To add support for new
45 * devices, you need to add the USB vendor and product ids here. 39 * devices, you need to add the USB vendor and product ids here.
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index cb0d80f49252..25bc85f8ce39 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -510,7 +510,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
510 case 0x025: map_key_clear(KEY_TV); break; 510 case 0x025: map_key_clear(KEY_TV); break;
511 case 0x026: map_key_clear(KEY_MENU); break; 511 case 0x026: map_key_clear(KEY_MENU); break;
512 case 0x031: map_key_clear(KEY_AUDIO); break; 512 case 0x031: map_key_clear(KEY_AUDIO); break;
513 case 0x032: map_key_clear(KEY_SUBTITLE); break; 513 case 0x032: map_key_clear(KEY_TEXT); break;
514 case 0x033: map_key_clear(KEY_LAST); break; 514 case 0x033: map_key_clear(KEY_LAST); break;
515 case 0x047: map_key_clear(KEY_MP3); break; 515 case 0x047: map_key_clear(KEY_MP3); break;
516 case 0x048: map_key_clear(KEY_DVD); break; 516 case 0x048: map_key_clear(KEY_DVD); break;
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index 4e1b784fe527..9c62837b5b89 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -533,3 +533,8 @@ static inline int hid_ff_event(struct hid_device *hid, struct input_dev *input,
533 return hid->ff_event(hid, input, type, code, value); 533 return hid->ff_event(hid, input, type, code, value);
534 return -ENOSYS; 534 return -ENOSYS;
535} 535}
536
537int hid_lgff_init(struct hid_device* hid);
538int hid_tmff_init(struct hid_device* hid);
539int hid_pid_init(struct hid_device* hid);
540
diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c
index b4a051b549d1..3d911976f378 100644
--- a/drivers/usb/input/keyspan_remote.c
+++ b/drivers/usb/input/keyspan_remote.c
@@ -297,6 +297,8 @@ static void keyspan_check_data(struct usb_keyspan *remote, struct pt_regs *regs)
297 remote->data.bits_left -= 6; 297 remote->data.bits_left -= 6;
298 } else { 298 } else {
299 err("%s - Error in message, invalid toggle.\n", __FUNCTION__); 299 err("%s - Error in message, invalid toggle.\n", __FUNCTION__);
300 remote->stage = 0;
301 return;
300 } 302 }
301 303
302 keyspan_load_tester(remote, 5); 304 keyspan_load_tester(remote, 5);
diff --git a/drivers/usb/input/usbtouchscreen.c b/drivers/usb/input/usbtouchscreen.c
new file mode 100644
index 000000000000..e9a07c1e905b
--- /dev/null
+++ b/drivers/usb/input/usbtouchscreen.c
@@ -0,0 +1,605 @@
1/******************************************************************************
2 * usbtouchscreen.c
3 * Driver for USB Touchscreens, supporting those devices:
4 * - eGalax Touchkit
5 * - 3M/Microtouch
6 * - ITM
7 * - PanJit TouchSet
8 *
9 * Copyright (C) 2004-2006 by Daniel Ritz <daniel.ritz@gmx.ch>
10 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 * Driver is based on touchkitusb.c
27 * - ITM parts are from itmtouch.c
28 * - 3M parts are from mtouchusb.c
29 * - PanJit parts are from an unmerged driver by Lanslott Gish
30 *
31 *****************************************************************************/
32
33//#define DEBUG
34
35#include <linux/config.h>
36#include <linux/kernel.h>
37#include <linux/slab.h>
38#include <linux/input.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/usb.h>
42#include <linux/usb_input.h>
43
44
45#define DRIVER_VERSION "v0.3"
46#define DRIVER_AUTHOR "Daniel Ritz <daniel.ritz@gmx.ch>"
47#define DRIVER_DESC "USB Touchscreen Driver"
48
49static int swap_xy;
50module_param(swap_xy, bool, 0644);
51MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
52
53/* device specifc data/functions */
54struct usbtouch_usb;
55struct usbtouch_device_info {
56 int min_xc, max_xc;
57 int min_yc, max_yc;
58 int min_press, max_press;
59 int rept_size;
60 int flags;
61
62 void (*process_pkt) (struct usbtouch_usb *usbtouch, struct pt_regs *regs, unsigned char *pkt, int len);
63 int (*read_data) (unsigned char *pkt, int *x, int *y, int *touch, int *press);
64 int (*init) (struct usbtouch_usb *usbtouch);
65};
66
67#define USBTOUCH_FLG_BUFFER 0x01
68
69
70/* a usbtouch device */
71struct usbtouch_usb {
72 unsigned char *data;
73 dma_addr_t data_dma;
74 unsigned char *buffer;
75 int buf_len;
76 struct urb *irq;
77 struct usb_device *udev;
78 struct input_dev *input;
79 struct usbtouch_device_info *type;
80 char name[128];
81 char phys[64];
82};
83
84static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
85 struct pt_regs *regs, unsigned char *pkt, int len);
86
87/* device types */
88enum {
89 DEVTPYE_DUMMY = -1,
90 DEVTYPE_EGALAX,
91 DEVTYPE_PANJIT,
92 DEVTYPE_3M,
93 DEVTYPE_ITM,
94};
95
96static struct usb_device_id usbtouch_devices[] = {
97#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
98 {USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},
99 {USB_DEVICE(0x0123, 0x0001), .driver_info = DEVTYPE_EGALAX},
100 {USB_DEVICE(0x0eef, 0x0001), .driver_info = DEVTYPE_EGALAX},
101 {USB_DEVICE(0x0eef, 0x0002), .driver_info = DEVTYPE_EGALAX},
102#endif
103
104#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
105 {USB_DEVICE(0x134c, 0x0001), .driver_info = DEVTYPE_PANJIT},
106 {USB_DEVICE(0x134c, 0x0002), .driver_info = DEVTYPE_PANJIT},
107 {USB_DEVICE(0x134c, 0x0003), .driver_info = DEVTYPE_PANJIT},
108 {USB_DEVICE(0x134c, 0x0004), .driver_info = DEVTYPE_PANJIT},
109#endif
110
111#ifdef CONFIG_USB_TOUCHSCREEN_3M
112 {USB_DEVICE(0x0596, 0x0001), .driver_info = DEVTYPE_3M},
113#endif
114
115#ifdef CONFIG_USB_TOUCHSCREEN_ITM
116 {USB_DEVICE(0x0403, 0xf9e9), .driver_info = DEVTYPE_ITM},
117#endif
118
119 {}
120};
121
122
123/*****************************************************************************
124 * eGalax part
125 */
126
127#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
128
129#define EGALAX_PKT_TYPE_MASK 0xFE
130#define EGALAX_PKT_TYPE_REPT 0x80
131#define EGALAX_PKT_TYPE_DIAG 0x0A
132
133static int egalax_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
134{
135 if ((pkt[0] & EGALAX_PKT_TYPE_MASK) != EGALAX_PKT_TYPE_REPT)
136 return 0;
137
138 *x = ((pkt[3] & 0x0F) << 7) | (pkt[4] & 0x7F);
139 *y = ((pkt[1] & 0x0F) << 7) | (pkt[2] & 0x7F);
140 *touch = pkt[0] & 0x01;
141
142 return 1;
143
144}
145
146static int egalax_get_pkt_len(unsigned char *buf)
147{
148 switch (buf[0] & EGALAX_PKT_TYPE_MASK) {
149 case EGALAX_PKT_TYPE_REPT:
150 return 5;
151
152 case EGALAX_PKT_TYPE_DIAG:
153 return buf[1] + 2;
154 }
155
156 return 0;
157}
158
159static void egalax_process(struct usbtouch_usb *usbtouch, struct pt_regs *regs,
160 unsigned char *pkt, int len)
161{
162 unsigned char *buffer;
163 int pkt_len, buf_len, pos;
164
165 /* if the buffer contains data, append */
166 if (unlikely(usbtouch->buf_len)) {
167 int tmp;
168
169 /* if only 1 byte in buffer, add another one to get length */
170 if (usbtouch->buf_len == 1)
171 usbtouch->buffer[1] = pkt[0];
172
173 pkt_len = egalax_get_pkt_len(usbtouch->buffer);
174
175 /* unknown packet: drop everything */
176 if (!pkt_len)
177 return;
178
179 /* append, process */
180 tmp = pkt_len - usbtouch->buf_len;
181 memcpy(usbtouch->buffer + usbtouch->buf_len, pkt, tmp);
182 usbtouch_process_pkt(usbtouch, regs, usbtouch->buffer, pkt_len);
183
184 buffer = pkt + tmp;
185 buf_len = len - tmp;
186 } else {
187 buffer = pkt;
188 buf_len = len;
189 }
190
191 /* only one byte left in buffer */
192 if (unlikely(buf_len == 1)) {
193 usbtouch->buffer[0] = buffer[0];
194 usbtouch->buf_len = 1;
195 return;
196 }
197
198 /* loop over the buffer */
199 pos = 0;
200 while (pos < buf_len) {
201 /* get packet len */
202 pkt_len = egalax_get_pkt_len(buffer + pos);
203
204 /* unknown packet: drop everything */
205 if (unlikely(!pkt_len))
206 return;
207
208 /* full packet: process */
209 if (likely(pkt_len <= buf_len)) {
210 usbtouch_process_pkt(usbtouch, regs, buffer + pos, pkt_len);
211 } else {
212 /* incomplete packet: save in buffer */
213 memcpy(usbtouch->buffer, buffer + pos, buf_len - pos);
214 usbtouch->buf_len = buf_len - pos;
215 }
216 pos += pkt_len;
217 }
218}
219#endif
220
221
222/*****************************************************************************
223 * PanJit Part
224 */
225#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
226static int panjit_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
227{
228 *x = ((pkt[2] & 0x0F) << 8) | pkt[1];
229 *y = ((pkt[4] & 0x0F) << 8) | pkt[3];
230 *touch = pkt[0] & 0x01;
231
232 return 1;
233}
234#endif
235
236
237/*****************************************************************************
238 * 3M/Microtouch Part
239 */
240#ifdef CONFIG_USB_TOUCHSCREEN_3M
241
242#define MTOUCHUSB_ASYNC_REPORT 1
243#define MTOUCHUSB_RESET 7
244#define MTOUCHUSB_REQ_CTRLLR_ID 10
245
246static int mtouch_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
247{
248 *x = (pkt[8] << 8) | pkt[7];
249 *y = (pkt[10] << 8) | pkt[9];
250 *touch = (pkt[2] & 0x40) ? 1 : 0;
251
252 return 1;
253}
254
255static int mtouch_init(struct usbtouch_usb *usbtouch)
256{
257 int ret;
258
259 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
260 MTOUCHUSB_RESET,
261 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
262 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
263 dbg("%s - usb_control_msg - MTOUCHUSB_RESET - bytes|err: %d",
264 __FUNCTION__, ret);
265 if (ret < 0)
266 return ret;
267
268 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0),
269 MTOUCHUSB_ASYNC_REPORT,
270 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
271 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
272 dbg("%s - usb_control_msg - MTOUCHUSB_ASYNC_REPORT - bytes|err: %d",
273 __FUNCTION__, ret);
274 if (ret < 0)
275 return ret;
276
277 return 0;
278}
279#endif
280
281
282/*****************************************************************************
283 * ITM Part
284 */
285#ifdef CONFIG_USB_TOUCHSCREEN_ITM
286static int itm_read_data(unsigned char *pkt, int *x, int *y, int *touch, int *press)
287{
288 *x = ((pkt[0] & 0x1F) << 7) | (pkt[3] & 0x7F);
289 *x = ((pkt[1] & 0x1F) << 7) | (pkt[4] & 0x7F);
290 *press = ((pkt[2] & 0x1F) << 7) | (pkt[5] & 0x7F);
291 *touch = ~pkt[7] & 0x20;
292
293 return 1;
294}
295#endif
296
297
298/*****************************************************************************
299 * the different device descriptors
300 */
301static struct usbtouch_device_info usbtouch_dev_info[] = {
302#ifdef CONFIG_USB_TOUCHSCREEN_EGALAX
303 [DEVTYPE_EGALAX] = {
304 .min_xc = 0x0,
305 .max_xc = 0x07ff,
306 .min_yc = 0x0,
307 .max_yc = 0x07ff,
308 .rept_size = 16,
309 .flags = USBTOUCH_FLG_BUFFER,
310 .process_pkt = egalax_process,
311 .read_data = egalax_read_data,
312 },
313#endif
314
315#ifdef CONFIG_USB_TOUCHSCREEN_PANJIT
316 [DEVTYPE_PANJIT] = {
317 .min_xc = 0x0,
318 .max_xc = 0x0fff,
319 .min_yc = 0x0,
320 .max_yc = 0x0fff,
321 .rept_size = 8,
322 .read_data = panjit_read_data,
323 },
324#endif
325
326#ifdef CONFIG_USB_TOUCHSCREEN_3M
327 [DEVTYPE_3M] = {
328 .min_xc = 0x0,
329 .max_xc = 0x4000,
330 .min_yc = 0x0,
331 .max_yc = 0x4000,
332 .rept_size = 11,
333 .read_data = mtouch_read_data,
334 .init = mtouch_init,
335 },
336#endif
337
338#ifdef CONFIG_USB_TOUCHSCREEN_ITM
339 [DEVTYPE_ITM] = {
340 .min_xc = 0x0,
341 .max_xc = 0x0fff,
342 .min_yc = 0x0,
343 .max_yc = 0x0fff,
344 .max_press = 0xff,
345 .rept_size = 8,
346 .read_data = itm_read_data,
347 },
348#endif
349};
350
351
352/*****************************************************************************
353 * Generic Part
354 */
355static void usbtouch_process_pkt(struct usbtouch_usb *usbtouch,
356 struct pt_regs *regs, unsigned char *pkt, int len)
357{
358 int x, y, touch, press;
359 struct usbtouch_device_info *type = usbtouch->type;
360
361 if (!type->read_data(pkt, &x, &y, &touch, &press))
362 return;
363
364 input_regs(usbtouch->input, regs);
365 input_report_key(usbtouch->input, BTN_TOUCH, touch);
366
367 if (swap_xy) {
368 input_report_abs(usbtouch->input, ABS_X, y);
369 input_report_abs(usbtouch->input, ABS_Y, x);
370 } else {
371 input_report_abs(usbtouch->input, ABS_X, x);
372 input_report_abs(usbtouch->input, ABS_Y, y);
373 }
374 if (type->max_press)
375 input_report_abs(usbtouch->input, ABS_PRESSURE, press);
376 input_sync(usbtouch->input);
377}
378
379
380static void usbtouch_irq(struct urb *urb, struct pt_regs *regs)
381{
382 struct usbtouch_usb *usbtouch = urb->context;
383 int retval;
384
385 switch (urb->status) {
386 case 0:
387 /* success */
388 break;
389 case -ETIMEDOUT:
390 /* this urb is timing out */
391 dbg("%s - urb timed out - was the device unplugged?",
392 __FUNCTION__);
393 return;
394 case -ECONNRESET:
395 case -ENOENT:
396 case -ESHUTDOWN:
397 /* this urb is terminated, clean up */
398 dbg("%s - urb shutting down with status: %d",
399 __FUNCTION__, urb->status);
400 return;
401 default:
402 dbg("%s - nonzero urb status received: %d",
403 __FUNCTION__, urb->status);
404 goto exit;
405 }
406
407 usbtouch->type->process_pkt(usbtouch, regs, usbtouch->data, urb->actual_length);
408
409exit:
410 retval = usb_submit_urb(urb, GFP_ATOMIC);
411 if (retval)
412 err("%s - usb_submit_urb failed with result: %d",
413 __FUNCTION__, retval);
414}
415
416static int usbtouch_open(struct input_dev *input)
417{
418 struct usbtouch_usb *usbtouch = input->private;
419
420 usbtouch->irq->dev = usbtouch->udev;
421
422 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
423 return -EIO;
424
425 return 0;
426}
427
428static void usbtouch_close(struct input_dev *input)
429{
430 struct usbtouch_usb *usbtouch = input->private;
431
432 usb_kill_urb(usbtouch->irq);
433}
434
435
436static void usbtouch_free_buffers(struct usb_device *udev,
437 struct usbtouch_usb *usbtouch)
438{
439 if (usbtouch->data)
440 usb_buffer_free(udev, usbtouch->type->rept_size,
441 usbtouch->data, usbtouch->data_dma);
442 kfree(usbtouch->buffer);
443}
444
445
446static int usbtouch_probe(struct usb_interface *intf,
447 const struct usb_device_id *id)
448{
449 struct usbtouch_usb *usbtouch;
450 struct input_dev *input_dev;
451 struct usb_host_interface *interface;
452 struct usb_endpoint_descriptor *endpoint;
453 struct usb_device *udev = interface_to_usbdev(intf);
454 struct usbtouch_device_info *type;
455 int err;
456
457 interface = intf->cur_altsetting;
458 endpoint = &interface->endpoint[0].desc;
459
460 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
461 input_dev = input_allocate_device();
462 if (!usbtouch || !input_dev)
463 goto out_free;
464
465 type = &usbtouch_dev_info[id->driver_info];
466 usbtouch->type = type;
467 if (!type->process_pkt)
468 type->process_pkt = usbtouch_process_pkt;
469
470 usbtouch->data = usb_buffer_alloc(udev, type->rept_size,
471 SLAB_KERNEL, &usbtouch->data_dma);
472 if (!usbtouch->data)
473 goto out_free;
474
475 if (type->flags & USBTOUCH_FLG_BUFFER) {
476 usbtouch->buffer = kmalloc(type->rept_size, GFP_KERNEL);
477 if (!usbtouch->buffer)
478 goto out_free_buffers;
479 }
480
481 usbtouch->irq = usb_alloc_urb(0, GFP_KERNEL);
482 if (!usbtouch->irq) {
483 dbg("%s - usb_alloc_urb failed: usbtouch->irq", __FUNCTION__);
484 goto out_free_buffers;
485 }
486
487 usbtouch->udev = udev;
488 usbtouch->input = input_dev;
489
490 if (udev->manufacturer)
491 strlcpy(usbtouch->name, udev->manufacturer, sizeof(usbtouch->name));
492
493 if (udev->product) {
494 if (udev->manufacturer)
495 strlcat(usbtouch->name, " ", sizeof(usbtouch->name));
496 strlcat(usbtouch->name, udev->product, sizeof(usbtouch->name));
497 }
498
499 if (!strlen(usbtouch->name))
500 snprintf(usbtouch->name, sizeof(usbtouch->name),
501 "USB Touchscreen %04x:%04x",
502 le16_to_cpu(udev->descriptor.idVendor),
503 le16_to_cpu(udev->descriptor.idProduct));
504
505 usb_make_path(udev, usbtouch->phys, sizeof(usbtouch->phys));
506 strlcpy(usbtouch->phys, "/input0", sizeof(usbtouch->phys));
507
508 input_dev->name = usbtouch->name;
509 input_dev->phys = usbtouch->phys;
510 usb_to_input_id(udev, &input_dev->id);
511 input_dev->cdev.dev = &intf->dev;
512 input_dev->private = usbtouch;
513 input_dev->open = usbtouch_open;
514 input_dev->close = usbtouch_close;
515
516 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
517 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
518 input_set_abs_params(input_dev, ABS_X, type->min_xc, type->max_xc, 0, 0);
519 input_set_abs_params(input_dev, ABS_Y, type->min_yc, type->max_yc, 0, 0);
520 if (type->max_press)
521 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
522 type->max_press, 0, 0);
523
524 usb_fill_int_urb(usbtouch->irq, usbtouch->udev,
525 usb_rcvintpipe(usbtouch->udev, 0x81),
526 usbtouch->data, type->rept_size,
527 usbtouch_irq, usbtouch, endpoint->bInterval);
528
529 usbtouch->irq->transfer_dma = usbtouch->data_dma;
530 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
531
532 /* device specific init */
533 if (type->init) {
534 err = type->init(usbtouch);
535 if (err) {
536 dbg("%s - type->init() failed, err: %d", __FUNCTION__, err);
537 goto out_free_buffers;
538 }
539 }
540
541 err = input_register_device(usbtouch->input);
542 if (err) {
543 dbg("%s - input_register_device failed, err: %d", __FUNCTION__, err);
544 goto out_free_buffers;
545 }
546
547 usb_set_intfdata(intf, usbtouch);
548
549 return 0;
550
551out_free_buffers:
552 usbtouch_free_buffers(udev, usbtouch);
553out_free:
554 input_free_device(input_dev);
555 kfree(usbtouch);
556 return -ENOMEM;
557}
558
559static void usbtouch_disconnect(struct usb_interface *intf)
560{
561 struct usbtouch_usb *usbtouch = usb_get_intfdata(intf);
562
563 dbg("%s - called", __FUNCTION__);
564
565 if (!usbtouch)
566 return;
567
568 dbg("%s - usbtouch is initialized, cleaning up", __FUNCTION__);
569 usb_set_intfdata(intf, NULL);
570 usb_kill_urb(usbtouch->irq);
571 input_unregister_device(usbtouch->input);
572 usb_free_urb(usbtouch->irq);
573 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
574 kfree(usbtouch);
575}
576
577MODULE_DEVICE_TABLE(usb, usbtouch_devices);
578
579static struct usb_driver usbtouch_driver = {
580 .name = "usbtouchscreen",
581 .probe = usbtouch_probe,
582 .disconnect = usbtouch_disconnect,
583 .id_table = usbtouch_devices,
584};
585
586static int __init usbtouch_init(void)
587{
588 return usb_register(&usbtouch_driver);
589}
590
591static void __exit usbtouch_cleanup(void)
592{
593 usb_deregister(&usbtouch_driver);
594}
595
596module_init(usbtouch_init);
597module_exit(usbtouch_cleanup);
598
599MODULE_AUTHOR(DRIVER_AUTHOR);
600MODULE_DESCRIPTION(DRIVER_DESC);
601MODULE_LICENSE("GPL");
602
603MODULE_ALIAS("touchkitusb");
604MODULE_ALIAS("itmtouch");
605MODULE_ALIAS("mtouchusb");
diff --git a/drivers/usb/input/wacom.c b/drivers/usb/input/wacom.c
index d3e15df9e815..cf84c6096f29 100644
--- a/drivers/usb/input/wacom.c
+++ b/drivers/usb/input/wacom.c
@@ -9,7 +9,7 @@
9 * Copyright (c) 2000 Daniel Egger <egger@suse.de> 9 * Copyright (c) 2000 Daniel Egger <egger@suse.de>
10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com> 10 * Copyright (c) 2001 Frederic Lepied <flepied@mandrakesoft.com>
11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be> 11 * Copyright (c) 2004 Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
12 * Copyright (c) 2002-2005 Ping Cheng <pingc@wacom.com> 12 * Copyright (c) 2002-2006 Ping Cheng <pingc@wacom.com>
13 * 13 *
14 * ChangeLog: 14 * ChangeLog:
15 * v0.1 (vp) - Initial release 15 * v0.1 (vp) - Initial release
@@ -56,6 +56,8 @@
56 * - Merged wacom_intuos3_irq into wacom_intuos_irq 56 * - Merged wacom_intuos3_irq into wacom_intuos_irq
57 * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc. 57 * v1.44 (pc) - Added support for Graphire4, Cintiq 710, Intuos3 6x11, etc.
58 * - Report Device IDs 58 * - Report Device IDs
59 * v1.45 (pc) - Added support for DTF 521, Intuos3 12x12 and 12x19
60 * - Minor data report fix
59 */ 61 */
60 62
61/* 63/*
@@ -78,7 +80,7 @@
78/* 80/*
79 * Version Information 81 * Version Information
80 */ 82 */
81#define DRIVER_VERSION "v1.44" 83#define DRIVER_VERSION "v1.45"
82#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" 84#define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>"
83#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver" 85#define DRIVER_DESC "USB Wacom Graphire and Wacom Intuos tablet driver"
84#define DRIVER_LICENSE "GPL" 86#define DRIVER_LICENSE "GPL"
@@ -99,6 +101,8 @@ enum {
99 PL, 101 PL,
100 INTUOS, 102 INTUOS,
101 INTUOS3, 103 INTUOS3,
104 INTUOS312,
105 INTUOS319,
102 CINTIQ, 106 CINTIQ,
103 MAX_TYPE 107 MAX_TYPE
104}; 108};
@@ -127,7 +131,19 @@ struct wacom {
127 char phys[32]; 131 char phys[32];
128}; 132};
129 133
134#define USB_REQ_GET_REPORT 0x01
130#define USB_REQ_SET_REPORT 0x09 135#define USB_REQ_SET_REPORT 0x09
136
137static int usb_get_report(struct usb_interface *intf, unsigned char type,
138 unsigned char id, void *buf, int size)
139{
140 return usb_control_msg(interface_to_usbdev(intf),
141 usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
142 USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
143 (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
144 buf, size, 100);
145}
146
131static int usb_set_report(struct usb_interface *intf, unsigned char type, 147static int usb_set_report(struct usb_interface *intf, unsigned char type,
132 unsigned char id, void *buf, int size) 148 unsigned char id, void *buf, int size)
133{ 149{
@@ -206,7 +222,8 @@ static void wacom_pl_irq(struct urb *urb, struct pt_regs *regs)
206 wacom->tool[1] = BTN_TOOL_PEN; 222 wacom->tool[1] = BTN_TOOL_PEN;
207 id = STYLUS_DEVICE_ID; 223 id = STYLUS_DEVICE_ID;
208 } 224 }
209 input_report_key(dev, wacom->tool[1], id); /* report in proximity for tool */ 225 input_report_key(dev, wacom->tool[1], prox); /* report in proximity for tool */
226 input_report_abs(dev, ABS_MISC, id); /* report tool id */
210 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); 227 input_report_abs(dev, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14));
211 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); 228 input_report_abs(dev, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14));
212 input_report_abs(dev, ABS_PRESSURE, pressure); 229 input_report_abs(dev, ABS_PRESSURE, pressure);
@@ -239,7 +256,7 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
239 struct wacom *wacom = urb->context; 256 struct wacom *wacom = urb->context;
240 unsigned char *data = wacom->data; 257 unsigned char *data = wacom->data;
241 struct input_dev *dev = wacom->dev; 258 struct input_dev *dev = wacom->dev;
242 int retval; 259 int retval, id;
243 260
244 switch (urb->status) { 261 switch (urb->status) {
245 case 0: 262 case 0:
@@ -263,12 +280,15 @@ static void wacom_ptu_irq(struct urb *urb, struct pt_regs *regs)
263 280
264 input_regs(dev, regs); 281 input_regs(dev, regs);
265 if (data[1] & 0x04) { 282 if (data[1] & 0x04) {
266 input_report_key(dev, BTN_TOOL_RUBBER, (data[1] & 0x20) ? ERASER_DEVICE_ID : 0); 283 input_report_key(dev, BTN_TOOL_RUBBER, data[1] & 0x20);
267 input_report_key(dev, BTN_TOUCH, data[1] & 0x08); 284 input_report_key(dev, BTN_TOUCH, data[1] & 0x08);
285 id = ERASER_DEVICE_ID;
268 } else { 286 } else {
269 input_report_key(dev, BTN_TOOL_PEN, (data[1] & 0x20) ? STYLUS_DEVICE_ID : 0); 287 input_report_key(dev, BTN_TOOL_PEN, data[1] & 0x20);
270 input_report_key(dev, BTN_TOUCH, data[1] & 0x01); 288 input_report_key(dev, BTN_TOUCH, data[1] & 0x01);
289 id = STYLUS_DEVICE_ID;
271 } 290 }
291 input_report_abs(dev, ABS_MISC, id); /* report tool id */
272 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2])); 292 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[2]));
273 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4])); 293 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[4]));
274 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6])); 294 input_report_abs(dev, ABS_PRESSURE, le16_to_cpu(*(__le16 *) &data[6]));
@@ -312,7 +332,8 @@ static void wacom_penpartner_irq(struct urb *urb, struct pt_regs *regs)
312 } 332 }
313 333
314 input_regs(dev, regs); 334 input_regs(dev, regs);
315 input_report_key(dev, BTN_TOOL_PEN, STYLUS_DEVICE_ID); 335 input_report_key(dev, BTN_TOOL_PEN, 1);
336 input_report_abs(dev, ABS_MISC, STYLUS_DEVICE_ID); /* report tool id */
316 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1])); 337 input_report_abs(dev, ABS_X, le16_to_cpu(*(__le16 *) &data[1]));
317 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3])); 338 input_report_abs(dev, ABS_Y, le16_to_cpu(*(__le16 *) &data[3]));
318 input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127); 339 input_report_abs(dev, ABS_PRESSURE, (signed char)data[6] + 127);
@@ -350,6 +371,8 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
350 goto exit; 371 goto exit;
351 } 372 }
352 373
374 if (data[0] == 99) return; /* for Volito tablets */
375
353 if (data[0] != 2) { 376 if (data[0] != 2) {
354 dbg("wacom_graphire_irq: received unknown report #%d", data[0]); 377 dbg("wacom_graphire_irq: received unknown report #%d", data[0]);
355 goto exit; 378 goto exit;
@@ -374,10 +397,10 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
374 case 2: /* Mouse with wheel */ 397 case 2: /* Mouse with wheel */
375 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04); 398 input_report_key(dev, BTN_MIDDLE, data[1] & 0x04);
376 if (wacom->features->type == WACOM_G4) { 399 if (wacom->features->type == WACOM_G4) {
377 rw = data[7] & 0x04 ? -(data[7] & 0x03) : (data[7] & 0x03); 400 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
378 input_report_rel(dev, REL_WHEEL, rw); 401 input_report_rel(dev, REL_WHEEL, -rw);
379 } else 402 } else
380 input_report_rel(dev, REL_WHEEL, (signed char) data[6]); 403 input_report_rel(dev, REL_WHEEL, -(signed char) data[6]);
381 /* fall through */ 404 /* fall through */
382 405
383 case 3: /* Mouse without wheel */ 406 case 3: /* Mouse without wheel */
@@ -406,39 +429,27 @@ static void wacom_graphire_irq(struct urb *urb, struct pt_regs *regs)
406 } 429 }
407 } 430 }
408 431
409 input_report_key(dev, wacom->tool[0], (data[1] & 0x10) ? id : 0); 432 if (data[1] & 0x10)
433 input_report_abs(dev, ABS_MISC, id); /* report tool id */
434 else
435 input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
436 input_report_key(dev, wacom->tool[0], data[1] & 0x10);
410 input_sync(dev); 437 input_sync(dev);
411 438
412 /* send pad data */ 439 /* send pad data */
413 if (wacom->features->type == WACOM_G4) { 440 if (wacom->features->type == WACOM_G4) {
414 /* fist time sending pad data */ 441 if ((wacom->serial[1] & 0xc0) != (data[7] & 0xf8)) {
415 if (wacom->tool[1] != BTN_TOOL_FINGER) { 442 wacom->id[1] = 1;
416 wacom->id[1] = 0; 443 wacom->serial[1] = (data[7] & 0xf8);
417 wacom->serial[1] = (data[7] & 0x38) >> 2;
418 }
419 if (data[7] & 0xf8) {
420 input_report_key(dev, BTN_0, (data[7] & 0x40)); 444 input_report_key(dev, BTN_0, (data[7] & 0x40));
421 input_report_key(dev, BTN_4, (data[7] & 0x80)); 445 input_report_key(dev, BTN_4, (data[7] & 0x80));
422 if (((data[7] & 0x38) >> 2) == (wacom->serial[1] & 0x0e)) 446 rw = ((data[7] & 0x18) >> 3) - ((data[7] & 0x20) >> 3);
423 /* alter REL_WHEEL value so X apps can get it */
424 wacom->serial[1] += (wacom->serial[1] & 0x01) ? -1 : 1;
425 else
426 wacom->serial[1] = (data[7] & 0x38 ) >> 2;
427
428 /* don't alter the value when there is no wheel event */
429 if (wacom->serial[1] == 1)
430 wacom->serial[1] = 0;
431 rw = wacom->serial[1];
432 rw = (rw & 0x08) ? -(rw & 0x07) : (rw & 0x07);
433 input_report_rel(dev, REL_WHEEL, rw); 447 input_report_rel(dev, REL_WHEEL, rw);
434 wacom->tool[1] = BTN_TOOL_FINGER; 448 input_report_key(dev, BTN_TOOL_FINGER, 0xf0);
435 wacom->id[1] = data[7] & 0xf8;
436 input_report_key(dev, wacom->tool[1], 0xf0);
437 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0); 449 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
438 } else if (wacom->id[1]) { 450 } else if (wacom->id[1]) {
439 wacom->id[1] = 0; 451 wacom->id[1] = 0;
440 wacom->serial[1] = 0; 452 input_report_key(dev, BTN_TOOL_FINGER, 0);
441 input_report_key(dev, wacom->tool[1], 0);
442 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0); 453 input_event(dev, EV_MSC, MSC_SERIAL, 0xf0);
443 } 454 }
444 input_sync(dev); 455 input_sync(dev);
@@ -516,21 +527,31 @@ static int wacom_intuos_inout(struct urb *urb)
516 default: /* Unknown tool */ 527 default: /* Unknown tool */
517 wacom->tool[idx] = BTN_TOOL_PEN; 528 wacom->tool[idx] = BTN_TOOL_PEN;
518 } 529 }
519 input_report_key(dev, wacom->tool[idx], wacom->id[idx]); 530 if(!((wacom->tool[idx] == BTN_TOOL_LENS) &&
520 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 531 ((wacom->features->type == INTUOS312)
521 input_sync(dev); 532 || (wacom->features->type == INTUOS319)))) {
533 input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
534 input_report_key(dev, wacom->tool[idx], 1);
535 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
536 input_sync(dev);
537 }
522 return 1; 538 return 1;
523 } 539 }
524 540
525 /* Exit report */ 541 /* Exit report */
526 if ((data[1] & 0xfe) == 0x80) { 542 if ((data[1] & 0xfe) == 0x80) {
527 input_report_key(dev, wacom->tool[idx], 0); 543 input_report_key(dev, wacom->tool[idx], 0);
544 input_report_abs(dev, ABS_MISC, 0); /* reset tool id */
528 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 545 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
529 input_sync(dev); 546 input_sync(dev);
530 return 1; 547 return 1;
531 } 548 }
532 549
533 return 0; 550 if((wacom->tool[idx] == BTN_TOOL_LENS) && ((wacom->features->type == INTUOS312)
551 || (wacom->features->type == INTUOS319)))
552 return 1;
553 else
554 return 0;
534} 555}
535 556
536static void wacom_intuos_general(struct urb *urb) 557static void wacom_intuos_general(struct urb *urb)
@@ -600,10 +621,9 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
600 /* pad packets. Works as a second tool and is always in prox */ 621 /* pad packets. Works as a second tool and is always in prox */
601 if (data[0] == 12) { 622 if (data[0] == 12) {
602 /* initiate the pad as a device */ 623 /* initiate the pad as a device */
603 if (wacom->tool[1] != BTN_TOOL_FINGER) { 624 if (wacom->tool[1] != BTN_TOOL_FINGER)
604 wacom->tool[1] = BTN_TOOL_FINGER; 625 wacom->tool[1] = BTN_TOOL_FINGER;
605 input_report_key(dev, wacom->tool[1], 1); 626
606 }
607 input_report_key(dev, BTN_0, (data[5] & 0x01)); 627 input_report_key(dev, BTN_0, (data[5] & 0x01));
608 input_report_key(dev, BTN_1, (data[5] & 0x02)); 628 input_report_key(dev, BTN_1, (data[5] & 0x02));
609 input_report_key(dev, BTN_2, (data[5] & 0x04)); 629 input_report_key(dev, BTN_2, (data[5] & 0x04));
@@ -614,6 +634,11 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
614 input_report_key(dev, BTN_7, (data[6] & 0x08)); 634 input_report_key(dev, BTN_7, (data[6] & 0x08));
615 input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]); 635 input_report_abs(dev, ABS_RX, ((data[1] & 0x1f) << 8) | data[2]);
616 input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]); 636 input_report_abs(dev, ABS_RY, ((data[3] & 0x1f) << 8) | data[4]);
637
638 if((data[5] & 0x0f) | (data[6] & 0x0f) | (data[1] & 0x1f) | data[2])
639 input_report_key(dev, wacom->tool[1], 1);
640 else
641 input_report_key(dev, wacom->tool[1], 0);
617 input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff); 642 input_event(dev, EV_MSC, MSC_SERIAL, 0xffffffff);
618 input_sync(dev); 643 input_sync(dev);
619 goto exit; 644 goto exit;
@@ -676,8 +701,8 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
676 input_report_key(dev, BTN_LEFT, data[8] & 0x04); 701 input_report_key(dev, BTN_LEFT, data[8] & 0x04);
677 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08); 702 input_report_key(dev, BTN_MIDDLE, data[8] & 0x08);
678 input_report_key(dev, BTN_RIGHT, data[8] & 0x10); 703 input_report_key(dev, BTN_RIGHT, data[8] & 0x10);
679 input_report_rel(dev, REL_WHEEL, ((data[8] & 0x02) >> 1) 704 input_report_rel(dev, REL_WHEEL, (data[8] & 0x01)
680 - (data[8] & 0x01)); 705 - ((data[8] & 0x02) >> 1));
681 706
682 /* I3 2D mouse side buttons */ 707 /* I3 2D mouse side buttons */
683 if (wacom->features->type == INTUOS3) { 708 if (wacom->features->type == INTUOS3) {
@@ -695,7 +720,8 @@ static void wacom_intuos_irq(struct urb *urb, struct pt_regs *regs)
695 } 720 }
696 } 721 }
697 722
698 input_report_key(dev, wacom->tool[idx], wacom->id[idx]); 723 input_report_abs(dev, ABS_MISC, wacom->id[idx]); /* report tool id */
724 input_report_key(dev, wacom->tool[idx], 1);
699 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]); 725 input_event(dev, EV_MSC, MSC_SERIAL, wacom->serial[idx]);
700 input_sync(dev); 726 input_sync(dev);
701 727
@@ -733,7 +759,8 @@ static struct wacom_features wacom_features[] = {
733 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq }, 759 { "Wacom PL800", 8, 7220, 5780, 511, 32, PL, wacom_pl_irq },
734 { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq }, 760 { "Wacom PL700", 8, 6758, 5406, 511, 32, PL, wacom_pl_irq },
735 { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq }, 761 { "Wacom PL510", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
736 { "Wacom PL710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq }, 762 { "Wacom DTU710", 8, 34080, 27660, 511, 32, PL, wacom_pl_irq },
763 { "Wacom DTF521", 8, 6282, 4762, 511, 32, PL, wacom_pl_irq },
737 { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq }, 764 { "Wacom DTF720", 8, 6858, 5506, 511, 32, PL, wacom_pl_irq },
738 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq }, 765 { "Wacom Cintiq Partner",8, 20480, 15360, 511, 32, PL, wacom_ptu_irq },
739 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq }, 766 { "Wacom Intuos2 4x5", 10, 12700, 10600, 1023, 15, INTUOS, wacom_intuos_irq },
@@ -744,6 +771,8 @@ static struct wacom_features wacom_features[] = {
744 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq }, 771 { "Wacom Intuos3 4x5", 10, 25400, 20320, 1023, 15, INTUOS3, wacom_intuos_irq },
745 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq }, 772 { "Wacom Intuos3 6x8", 10, 40640, 30480, 1023, 15, INTUOS3, wacom_intuos_irq },
746 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq }, 773 { "Wacom Intuos3 9x12", 10, 60960, 45720, 1023, 15, INTUOS3, wacom_intuos_irq },
774 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 15, INTUOS312, wacom_intuos_irq },
775 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 15, INTUOS319, wacom_intuos_irq },
747 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq }, 776 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 15, INTUOS3, wacom_intuos_irq },
748 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq }, 777 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 15, CINTIQ, wacom_intuos_irq },
749 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq }, 778 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 15, INTUOS, wacom_intuos_irq },
@@ -779,6 +808,7 @@ static struct usb_device_id wacom_ids[] = {
779 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) }, 808 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
780 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) }, 809 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
781 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) }, 810 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
811 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC3) },
782 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) }, 812 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
783 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) }, 813 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
784 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) }, 814 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
@@ -788,6 +818,8 @@ static struct usb_device_id wacom_ids[] = {
788 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) }, 818 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
789 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) }, 819 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
790 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) }, 820 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
821 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
822 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
791 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) }, 823 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
792 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) }, 824 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
793 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) }, 825 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
@@ -820,7 +852,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
820 struct usb_endpoint_descriptor *endpoint; 852 struct usb_endpoint_descriptor *endpoint;
821 struct wacom *wacom; 853 struct wacom *wacom;
822 struct input_dev *input_dev; 854 struct input_dev *input_dev;
823 char rep_data[2] = {0x02, 0x02}; 855 char rep_data[2], limit = 0;
824 856
825 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); 857 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
826 input_dev = input_allocate_device(); 858 input_dev = input_allocate_device();
@@ -857,6 +889,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
857 input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0); 889 input_set_abs_params(input_dev, ABS_X, 0, wacom->features->x_max, 4, 0);
858 input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0); 890 input_set_abs_params(input_dev, ABS_Y, 0, wacom->features->y_max, 4, 0);
859 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0); 891 input_set_abs_params(input_dev, ABS_PRESSURE, 0, wacom->features->pressure_max, 0, 0);
892 input_dev->absbit[LONG(ABS_MISC)] |= BIT(ABS_MISC);
860 893
861 switch (wacom->features->type) { 894 switch (wacom->features->type) {
862 case WACOM_G4: 895 case WACOM_G4:
@@ -875,6 +908,8 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
875 break; 908 break;
876 909
877 case INTUOS3: 910 case INTUOS3:
911 case INTUOS312:
912 case INTUOS319:
878 case CINTIQ: 913 case CINTIQ:
879 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 914 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
880 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 915 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3) | BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
@@ -916,10 +951,13 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
916 951
917 input_register_device(wacom->dev); 952 input_register_device(wacom->dev);
918 953
919 /* ask the tablet to report tablet data */ 954 /* Ask the tablet to report tablet data. Repeat until it succeeds */
920 usb_set_report(intf, 3, 2, rep_data, 2); 955 do {
921 /* repeat once (not sure why the first call often fails) */ 956 rep_data[0] = 2;
922 usb_set_report(intf, 3, 2, rep_data, 2); 957 rep_data[1] = 2;
958 usb_set_report(intf, 3, 2, rep_data, 2);
959 usb_get_report(intf, 3, 2, rep_data, 2);
960 } while (rep_data[1] != 2 && limit++ < 5);
923 961
924 usb_set_intfdata(intf, wacom); 962 usb_set_intfdata(intf, wacom);
925 return 0; 963 return 0;
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 9d59b901841c..ccc5e8238bd8 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -381,6 +381,7 @@ alloc_sglist (int nents, int max, int vary)
381 381
382 for (i = 0; i < nents; i++) { 382 for (i = 0; i < nents; i++) {
383 char *buf; 383 char *buf;
384 unsigned j;
384 385
385 buf = kzalloc (size, SLAB_KERNEL); 386 buf = kzalloc (size, SLAB_KERNEL);
386 if (!buf) { 387 if (!buf) {
@@ -391,6 +392,16 @@ alloc_sglist (int nents, int max, int vary)
391 /* kmalloc pages are always physically contiguous! */ 392 /* kmalloc pages are always physically contiguous! */
392 sg_init_one(&sg[i], buf, size); 393 sg_init_one(&sg[i], buf, size);
393 394
395 switch (pattern) {
396 case 0:
397 /* already zeroed */
398 break;
399 case 1:
400 for (j = 0; j < size; j++)
401 *buf++ = (u8) (j % 63);
402 break;
403 }
404
394 if (vary) { 405 if (vary) {
395 size += vary; 406 size += vary;
396 size %= max; 407 size %= max;
@@ -425,6 +436,8 @@ static int perform_sglist (
425 usb_sg_wait (req); 436 usb_sg_wait (req);
426 retval = req->status; 437 retval = req->status;
427 438
439 /* FIXME check resulting data pattern */
440
428 /* FIXME if endpoint halted, clear halt (and log) */ 441 /* FIXME if endpoint halted, clear halt (and log) */
429 } 442 }
430 443
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index 3094970615cb..12b599a0b539 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -37,7 +37,6 @@
37 37
38#include "usbnet.h" 38#include "usbnet.h"
39 39
40
41/* ASIX AX8817X based USB 2.0 Ethernet Devices */ 40/* ASIX AX8817X based USB 2.0 Ethernet Devices */
42 41
43#define AX_CMD_SET_SW_MII 0x06 42#define AX_CMD_SET_SW_MII 0x06
@@ -109,7 +108,7 @@
109#define AX_EEPROM_MAGIC 0xdeadbeef 108#define AX_EEPROM_MAGIC 0xdeadbeef
110 109
111/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ 110/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
112struct ax8817x_data { 111struct asix_data {
113 u8 multi_filter[AX_MCAST_FILTER_SIZE]; 112 u8 multi_filter[AX_MCAST_FILTER_SIZE];
114}; 113};
115 114
@@ -121,7 +120,7 @@ struct ax88172_int_data {
121 u16 res3; 120 u16 res3;
122} __attribute__ ((packed)); 121} __attribute__ ((packed));
123 122
124static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 123static int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
125 u16 size, void *data) 124 u16 size, void *data)
126{ 125{
127 return usb_control_msg( 126 return usb_control_msg(
@@ -136,7 +135,7 @@ static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
136 USB_CTRL_GET_TIMEOUT); 135 USB_CTRL_GET_TIMEOUT);
137} 136}
138 137
139static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, 138static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
140 u16 size, void *data) 139 u16 size, void *data)
141{ 140{
142 return usb_control_msg( 141 return usb_control_msg(
@@ -151,19 +150,80 @@ static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
151 USB_CTRL_SET_TIMEOUT); 150 USB_CTRL_SET_TIMEOUT);
152} 151}
153 152
154static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs) 153static void asix_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
155{ 154{
156 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context; 155 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
157 156
158 if (urb->status < 0) 157 if (urb->status < 0)
159 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d", 158 printk(KERN_DEBUG "asix_async_cmd_callback() failed with %d",
160 urb->status); 159 urb->status);
161 160
162 kfree(req); 161 kfree(req);
163 usb_free_urb(urb); 162 usb_free_urb(urb);
164} 163}
165 164
166static void ax8817x_status(struct usbnet *dev, struct urb *urb) 165static inline int asix_set_sw_mii(struct usbnet *dev)
166{
167 int ret;
168 ret = asix_write_cmd(dev, AX_CMD_SET_SW_MII, 0x0000, 0, 0, NULL);
169 if (ret < 0)
170 devdbg(dev, "Failed to enable software MII access");
171 return ret;
172}
173
174static inline int asix_set_hw_mii(struct usbnet *dev)
175{
176 int ret;
177 ret = asix_write_cmd(dev, AX_CMD_SET_HW_MII, 0x0000, 0, 0, NULL);
178 if (ret < 0)
179 devdbg(dev, "Failed to enable hardware MII access");
180 return ret;
181}
182
183static inline int asix_get_phyid(struct usbnet *dev)
184{
185 int ret = 0;
186 void *buf;
187
188 buf = kmalloc(2, GFP_KERNEL);
189 if (!buf)
190 goto out1;
191
192 if ((ret = asix_read_cmd(dev, AX_CMD_READ_PHY_ID,
193 0, 0, 2, buf)) < 2) {
194 devdbg(dev, "Error reading PHYID register: %02x", ret);
195 goto out2;
196 }
197 ret = *((u8 *)buf + 1);
198out2:
199 kfree(buf);
200out1:
201 return ret;
202}
203
204static int asix_sw_reset(struct usbnet *dev, u8 flags)
205{
206 int ret;
207
208 ret = asix_write_cmd(dev, AX_CMD_SW_RESET, flags, 0, 0, NULL);
209 if (ret < 0)
210 devdbg(dev,"Failed to send software reset: %02x", ret);
211
212 return ret;
213}
214
215static int asix_write_rx_ctl(struct usbnet *dev, u16 mode)
216{
217 int ret;
218
219 ret = asix_write_cmd(dev, AX_CMD_WRITE_RX_CTL, mode, 0, 0, NULL);
220 if (ret < 0)
221 devdbg(dev, "Failed to write RX_CTL mode: %02x", ret);
222
223 return ret;
224}
225
226static void asix_status(struct usbnet *dev, struct urb *urb)
167{ 227{
168 struct ax88172_int_data *event; 228 struct ax88172_int_data *event;
169 int link; 229 int link;
@@ -179,12 +239,12 @@ static void ax8817x_status(struct usbnet *dev, struct urb *urb)
179 usbnet_defer_kevent (dev, EVENT_LINK_RESET ); 239 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
180 } else 240 } else
181 netif_carrier_off(dev->net); 241 netif_carrier_off(dev->net);
182 devdbg(dev, "ax8817x - Link Status is: %d", link); 242 devdbg(dev, "Link Status is: %d", link);
183 } 243 }
184} 244}
185 245
186static void 246static void
187ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index, 247asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
188 u16 size, void *data) 248 u16 size, void *data)
189{ 249{
190 struct usb_ctrlrequest *req; 250 struct usb_ctrlrequest *req;
@@ -211,7 +271,7 @@ ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
211 usb_fill_control_urb(urb, dev->udev, 271 usb_fill_control_urb(urb, dev->udev,
212 usb_sndctrlpipe(dev->udev, 0), 272 usb_sndctrlpipe(dev->udev, 0),
213 (void *)req, data, size, 273 (void *)req, data, size,
214 ax8817x_async_cmd_callback, req); 274 asix_async_cmd_callback, req);
215 275
216 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 276 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
217 deverr(dev, "Error submitting the control message: status=%d", 277 deverr(dev, "Error submitting the control message: status=%d",
@@ -221,10 +281,10 @@ ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
221 } 281 }
222} 282}
223 283
224static void ax8817x_set_multicast(struct net_device *net) 284static void asix_set_multicast(struct net_device *net)
225{ 285{
226 struct usbnet *dev = netdev_priv(net); 286 struct usbnet *dev = netdev_priv(net);
227 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data; 287 struct asix_data *data = (struct asix_data *)&dev->data;
228 u8 rx_ctl = 0x8c; 288 u8 rx_ctl = 0x8c;
229 289
230 if (net->flags & IFF_PROMISC) { 290 if (net->flags & IFF_PROMISC) {
@@ -255,53 +315,51 @@ static void ax8817x_set_multicast(struct net_device *net)
255 mc_list = mc_list->next; 315 mc_list = mc_list->next;
256 } 316 }
257 317
258 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0, 318 asix_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
259 AX_MCAST_FILTER_SIZE, data->multi_filter); 319 AX_MCAST_FILTER_SIZE, data->multi_filter);
260 320
261 rx_ctl |= 0x10; 321 rx_ctl |= 0x10;
262 } 322 }
263 323
264 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL); 324 asix_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
265} 325}
266 326
267static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc) 327static int asix_mdio_read(struct net_device *netdev, int phy_id, int loc)
268{ 328{
269 struct usbnet *dev = netdev_priv(netdev); 329 struct usbnet *dev = netdev_priv(netdev);
270 u16 res; 330 u16 res;
271 u8 buf[1];
272 331
273 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); 332 asix_set_sw_mii(dev);
274 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, 333 asix_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
275 (__u16)loc, 2, (u16 *)&res); 334 (__u16)loc, 2, (u16 *)&res);
276 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); 335 asix_set_hw_mii(dev);
277 336
278 return res & 0xffff; 337 return res & 0xffff;
279} 338}
280 339
281/* same as above, but converts resulting value to cpu byte order */ 340/* same as above, but converts resulting value to cpu byte order */
282static int ax8817x_mdio_read_le(struct net_device *netdev, int phy_id, int loc) 341static int asix_mdio_read_le(struct net_device *netdev, int phy_id, int loc)
283{ 342{
284 return le16_to_cpu(ax8817x_mdio_read(netdev,phy_id, loc)); 343 return le16_to_cpu(asix_mdio_read(netdev,phy_id, loc));
285} 344}
286 345
287static void 346static void
288ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val) 347asix_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
289{ 348{
290 struct usbnet *dev = netdev_priv(netdev); 349 struct usbnet *dev = netdev_priv(netdev);
291 u16 res = val; 350 u16 res = val;
292 u8 buf[1];
293 351
294 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf); 352 asix_set_sw_mii(dev);
295 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, 353 asix_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
296 (__u16)loc, 2, (u16 *)&res); 354 (__u16)loc, 2, (u16 *)&res);
297 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf); 355 asix_set_hw_mii(dev);
298} 356}
299 357
300/* same as above, but converts new value to le16 byte order before writing */ 358/* same as above, but converts new value to le16 byte order before writing */
301static void 359static void
302ax8817x_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val) 360asix_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val)
303{ 361{
304 ax8817x_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) ); 362 asix_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) );
305} 363}
306 364
307static int ax88172_link_reset(struct usbnet *dev) 365static int ax88172_link_reset(struct usbnet *dev)
@@ -312,23 +370,23 @@ static int ax88172_link_reset(struct usbnet *dev)
312 u8 mode; 370 u8 mode;
313 371
314 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN; 372 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
315 lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); 373 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
316 adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); 374 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
317 res = mii_nway_result(lpa|adv); 375 res = mii_nway_result(lpa|adv);
318 if (res & LPA_DUPLEX) 376 if (res & LPA_DUPLEX)
319 mode |= AX_MEDIUM_FULL_DUPLEX; 377 mode |= AX_MEDIUM_FULL_DUPLEX;
320 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); 378 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
321 379
322 return 0; 380 return 0;
323} 381}
324 382
325static void 383static void
326ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 384asix_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
327{ 385{
328 struct usbnet *dev = netdev_priv(net); 386 struct usbnet *dev = netdev_priv(net);
329 u8 opt; 387 u8 opt;
330 388
331 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) { 389 if (asix_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
332 wolinfo->supported = 0; 390 wolinfo->supported = 0;
333 wolinfo->wolopts = 0; 391 wolinfo->wolopts = 0;
334 return; 392 return;
@@ -344,7 +402,7 @@ ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
344} 402}
345 403
346static int 404static int
347ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) 405asix_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
348{ 406{
349 struct usbnet *dev = netdev_priv(net); 407 struct usbnet *dev = netdev_priv(net);
350 u8 opt = 0; 408 u8 opt = 0;
@@ -357,19 +415,19 @@ ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
357 if (opt != 0) 415 if (opt != 0)
358 opt |= AX_MONITOR_MODE; 416 opt |= AX_MONITOR_MODE;
359 417
360 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE, 418 if (asix_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
361 opt, 0, 0, &buf) < 0) 419 opt, 0, 0, &buf) < 0)
362 return -EINVAL; 420 return -EINVAL;
363 421
364 return 0; 422 return 0;
365} 423}
366 424
367static int ax8817x_get_eeprom_len(struct net_device *net) 425static int asix_get_eeprom_len(struct net_device *net)
368{ 426{
369 return AX_EEPROM_LEN; 427 return AX_EEPROM_LEN;
370} 428}
371 429
372static int ax8817x_get_eeprom(struct net_device *net, 430static int asix_get_eeprom(struct net_device *net,
373 struct ethtool_eeprom *eeprom, u8 *data) 431 struct ethtool_eeprom *eeprom, u8 *data)
374{ 432{
375 struct usbnet *dev = netdev_priv(net); 433 struct usbnet *dev = netdev_priv(net);
@@ -386,14 +444,14 @@ static int ax8817x_get_eeprom(struct net_device *net,
386 444
387 /* ax8817x returns 2 bytes from eeprom on read */ 445 /* ax8817x returns 2 bytes from eeprom on read */
388 for (i=0; i < eeprom->len / 2; i++) { 446 for (i=0; i < eeprom->len / 2; i++) {
389 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM, 447 if (asix_read_cmd(dev, AX_CMD_READ_EEPROM,
390 eeprom->offset + i, 0, 2, &ebuf[i]) < 0) 448 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
391 return -EINVAL; 449 return -EINVAL;
392 } 450 }
393 return 0; 451 return 0;
394} 452}
395 453
396static void ax8817x_get_drvinfo (struct net_device *net, 454static void asix_get_drvinfo (struct net_device *net,
397 struct ethtool_drvinfo *info) 455 struct ethtool_drvinfo *info)
398{ 456{
399 /* Inherit standard device info */ 457 /* Inherit standard device info */
@@ -401,14 +459,14 @@ static void ax8817x_get_drvinfo (struct net_device *net,
401 info->eedump_len = 0x3e; 459 info->eedump_len = 0x3e;
402} 460}
403 461
404static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd) 462static int asix_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
405{ 463{
406 struct usbnet *dev = netdev_priv(net); 464 struct usbnet *dev = netdev_priv(net);
407 465
408 return mii_ethtool_gset(&dev->mii,cmd); 466 return mii_ethtool_gset(&dev->mii,cmd);
409} 467}
410 468
411static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd) 469static int asix_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
412{ 470{
413 struct usbnet *dev = netdev_priv(net); 471 struct usbnet *dev = netdev_priv(net);
414 472
@@ -418,27 +476,27 @@ static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
418/* We need to override some ethtool_ops so we require our 476/* We need to override some ethtool_ops so we require our
419 own structure so we don't interfere with other usbnet 477 own structure so we don't interfere with other usbnet
420 devices that may be connected at the same time. */ 478 devices that may be connected at the same time. */
421static struct ethtool_ops ax8817x_ethtool_ops = { 479static struct ethtool_ops ax88172_ethtool_ops = {
422 .get_drvinfo = ax8817x_get_drvinfo, 480 .get_drvinfo = asix_get_drvinfo,
423 .get_link = ethtool_op_get_link, 481 .get_link = ethtool_op_get_link,
424 .get_msglevel = usbnet_get_msglevel, 482 .get_msglevel = usbnet_get_msglevel,
425 .set_msglevel = usbnet_set_msglevel, 483 .set_msglevel = usbnet_set_msglevel,
426 .get_wol = ax8817x_get_wol, 484 .get_wol = asix_get_wol,
427 .set_wol = ax8817x_set_wol, 485 .set_wol = asix_set_wol,
428 .get_eeprom_len = ax8817x_get_eeprom_len, 486 .get_eeprom_len = asix_get_eeprom_len,
429 .get_eeprom = ax8817x_get_eeprom, 487 .get_eeprom = asix_get_eeprom,
430 .get_settings = ax8817x_get_settings, 488 .get_settings = asix_get_settings,
431 .set_settings = ax8817x_set_settings, 489 .set_settings = asix_set_settings,
432}; 490};
433 491
434static int ax8817x_ioctl (struct net_device *net, struct ifreq *rq, int cmd) 492static int asix_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
435{ 493{
436 struct usbnet *dev = netdev_priv(net); 494 struct usbnet *dev = netdev_priv(net);
437 495
438 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL); 496 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
439} 497}
440 498
441static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf) 499static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
442{ 500{
443 int ret = 0; 501 int ret = 0;
444 void *buf; 502 void *buf;
@@ -455,55 +513,39 @@ static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
455 513
456 /* Toggle the GPIOs in a manufacturer/model specific way */ 514 /* Toggle the GPIOs in a manufacturer/model specific way */
457 for (i = 2; i >= 0; i--) { 515 for (i = 2; i >= 0; i--) {
458 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, 516 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
459 (gpio_bits >> (i * 8)) & 0xff, 0, 0, 517 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
460 buf)) < 0) 518 buf)) < 0)
461 goto out2; 519 goto out2;
462 msleep(5); 520 msleep(5);
463 } 521 }
464 522
465 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 523 if ((ret = asix_write_rx_ctl(dev,0x80)) < 0)
466 0x80, 0, 0, buf)) < 0) {
467 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
468 goto out2; 524 goto out2;
469 }
470 525
471 /* Get the MAC address */ 526 /* Get the MAC address */
472 memset(buf, 0, ETH_ALEN); 527 memset(buf, 0, ETH_ALEN);
473 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 528 if ((ret = asix_read_cmd(dev, AX_CMD_READ_NODE_ID,
474 0, 0, 6, buf)) < 0) { 529 0, 0, 6, buf)) < 0) {
475 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret); 530 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
476 goto out2; 531 goto out2;
477 } 532 }
478 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 533 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
479 534
480 /* Get the PHY id */
481 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID,
482 0, 0, 2, buf)) < 0) {
483 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
484 goto out2;
485 } else if (ret < 2) {
486 /* this should always return 2 bytes */
487 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
488 ret);
489 ret = -EIO;
490 goto out2;
491 }
492
493 /* Initialize MII structure */ 535 /* Initialize MII structure */
494 dev->mii.dev = dev->net; 536 dev->mii.dev = dev->net;
495 dev->mii.mdio_read = ax8817x_mdio_read; 537 dev->mii.mdio_read = asix_mdio_read;
496 dev->mii.mdio_write = ax8817x_mdio_write; 538 dev->mii.mdio_write = asix_mdio_write;
497 dev->mii.phy_id_mask = 0x3f; 539 dev->mii.phy_id_mask = 0x3f;
498 dev->mii.reg_num_mask = 0x1f; 540 dev->mii.reg_num_mask = 0x1f;
499 dev->mii.phy_id = *((u8 *)buf + 1); 541 dev->mii.phy_id = asix_get_phyid(dev);
500 dev->net->do_ioctl = ax8817x_ioctl; 542 dev->net->do_ioctl = asix_ioctl;
501 543
502 dev->net->set_multicast_list = ax8817x_set_multicast; 544 dev->net->set_multicast_list = asix_set_multicast;
503 dev->net->ethtool_ops = &ax8817x_ethtool_ops; 545 dev->net->ethtool_ops = &ax88172_ethtool_ops;
504 546
505 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 547 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
506 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, 548 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
507 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); 549 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
508 mii_nway_restart(&dev->mii); 550 mii_nway_restart(&dev->mii);
509 551
@@ -515,16 +557,16 @@ out1:
515} 557}
516 558
517static struct ethtool_ops ax88772_ethtool_ops = { 559static struct ethtool_ops ax88772_ethtool_ops = {
518 .get_drvinfo = ax8817x_get_drvinfo, 560 .get_drvinfo = asix_get_drvinfo,
519 .get_link = ethtool_op_get_link, 561 .get_link = ethtool_op_get_link,
520 .get_msglevel = usbnet_get_msglevel, 562 .get_msglevel = usbnet_get_msglevel,
521 .set_msglevel = usbnet_set_msglevel, 563 .set_msglevel = usbnet_set_msglevel,
522 .get_wol = ax8817x_get_wol, 564 .get_wol = asix_get_wol,
523 .set_wol = ax8817x_set_wol, 565 .set_wol = asix_set_wol,
524 .get_eeprom_len = ax8817x_get_eeprom_len, 566 .get_eeprom_len = asix_get_eeprom_len,
525 .get_eeprom = ax8817x_get_eeprom, 567 .get_eeprom = asix_get_eeprom,
526 .get_settings = ax8817x_get_settings, 568 .get_settings = asix_get_settings,
527 .set_settings = ax8817x_set_settings, 569 .set_settings = asix_set_settings,
528}; 570};
529 571
530static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf) 572static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
@@ -541,62 +583,45 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
541 goto out1; 583 goto out1;
542 } 584 }
543 585
544 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS, 586 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_GPIOS,
545 0x00B0, 0, 0, buf)) < 0) 587 0x00B0, 0, 0, buf)) < 0)
546 goto out2; 588 goto out2;
547 589
548 msleep(5); 590 msleep(5);
549 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 591 if ((ret = asix_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
550 0x0001, 0, 0, buf)) < 0) { 592 0x0001, 0, 0, buf)) < 0) {
551 dbg("Select PHY #1 failed: %d", ret); 593 dbg("Select PHY #1 failed: %d", ret);
552 goto out2; 594 goto out2;
553 } 595 }
554 596
555 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 597 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPPD)) < 0)
556 0, 0, buf)) < 0) {
557 dbg("Failed to power down internal PHY: %d", ret);
558 goto out2; 598 goto out2;
559 }
560 599
561 msleep(150); 600 msleep(150);
562 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 601 if ((ret = asix_sw_reset(dev, AX_SWRESET_CLEAR)) < 0)
563 0, 0, buf)) < 0) {
564 dbg("Failed to perform software reset: %d", ret);
565 goto out2; 602 goto out2;
566 }
567 603
568 msleep(150); 604 msleep(150);
569 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, 605 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
570 AX_SWRESET_IPRL | AX_SWRESET_PRL,
571 0, 0, buf)) < 0) {
572 dbg("Failed to set Internal/External PHY reset control: %d",
573 ret);
574 goto out2; 606 goto out2;
575 }
576 607
577 msleep(150); 608 msleep(150);
578 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 609 if ((ret = asix_write_rx_ctl(dev, 0x00)) < 0)
579 0x0000, 0, 0, buf)) < 0) {
580 dbg("Failed to reset RX_CTL: %d", ret);
581 goto out2; 610 goto out2;
582 }
583 611
584 /* Get the MAC address */ 612 /* Get the MAC address */
585 memset(buf, 0, ETH_ALEN); 613 memset(buf, 0, ETH_ALEN);
586 if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 614 if ((ret = asix_read_cmd(dev, AX88772_CMD_READ_NODE_ID,
587 0, 0, ETH_ALEN, buf)) < 0) { 615 0, 0, ETH_ALEN, buf)) < 0) {
588 dbg("Failed to read MAC address: %d", ret); 616 dbg("Failed to read MAC address: %d", ret);
589 goto out2; 617 goto out2;
590 } 618 }
591 memcpy(dev->net->dev_addr, buf, ETH_ALEN); 619 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
592 620
593 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 621 if ((ret = asix_set_sw_mii(dev)) < 0)
594 0, 0, 0, buf)) < 0) {
595 dbg("Enabling software MII failed: %d", ret);
596 goto out2; 622 goto out2;
597 }
598 623
599 if (((ret = ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 624 if (((ret = asix_read_cmd(dev, AX_CMD_READ_MII_REG,
600 0x0010, 2, 2, buf)) < 0) 625 0x0010, 2, 2, buf)) < 0)
601 || (*((u16 *)buf) != 0x003b)) { 626 || (*((u16 *)buf) != 0x003b)) {
602 dbg("Read PHY register 2 must be 0x3b00: %d", ret); 627 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
@@ -605,74 +630,49 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
605 630
606 /* Initialize MII structure */ 631 /* Initialize MII structure */
607 dev->mii.dev = dev->net; 632 dev->mii.dev = dev->net;
608 dev->mii.mdio_read = ax8817x_mdio_read; 633 dev->mii.mdio_read = asix_mdio_read;
609 dev->mii.mdio_write = ax8817x_mdio_write; 634 dev->mii.mdio_write = asix_mdio_write;
610 dev->mii.phy_id_mask = 0xff; 635 dev->mii.phy_id_mask = 0xff;
611 dev->mii.reg_num_mask = 0xff; 636 dev->mii.reg_num_mask = 0xff;
612 dev->net->do_ioctl = ax8817x_ioctl; 637 dev->net->do_ioctl = asix_ioctl;
638 dev->mii.phy_id = asix_get_phyid(dev);
613 639
614 /* Get the PHY id */ 640 if ((ret = asix_sw_reset(dev, AX_SWRESET_PRL)) < 0)
615 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID,
616 0, 0, 2, buf)) < 0) {
617 dbg("Error reading PHY ID: %02x", ret);
618 goto out2; 641 goto out2;
619 } else if (ret < 2) {
620 /* this should always return 2 bytes */
621 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
622 ret);
623 ret = -EIO;
624 goto out2;
625 }
626 dev->mii.phy_id = *((u8 *)buf + 1);
627 642
628 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL,
629 0, 0, buf)) < 0) {
630 dbg("Set external PHY reset pin level: %d", ret);
631 goto out2;
632 }
633 msleep(150); 643 msleep(150);
634 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, 644
635 AX_SWRESET_IPRL | AX_SWRESET_PRL, 645 if ((ret = asix_sw_reset(dev, AX_SWRESET_IPRL | AX_SWRESET_PRL)) < 0)
636 0, 0, buf)) < 0) {
637 dbg("Set Internal/External PHY reset control: %d", ret);
638 goto out2; 646 goto out2;
639 }
640 msleep(150);
641 647
648 msleep(150);
642 649
643 dev->net->set_multicast_list = ax8817x_set_multicast; 650 dev->net->set_multicast_list = asix_set_multicast;
644 dev->net->ethtool_ops = &ax88772_ethtool_ops; 651 dev->net->ethtool_ops = &ax88772_ethtool_ops;
645 652
646 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET); 653 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
647 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE, 654 asix_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
648 ADVERTISE_ALL | ADVERTISE_CSMA); 655 ADVERTISE_ALL | ADVERTISE_CSMA);
649 mii_nway_restart(&dev->mii); 656 mii_nway_restart(&dev->mii);
650 657
651 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, 658 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE,
652 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) { 659 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
653 dbg("Write medium mode register: %d", ret); 660 dbg("Write medium mode register: %d", ret);
654 goto out2; 661 goto out2;
655 } 662 }
656 663
657 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, 664 if ((ret = asix_write_cmd(dev, AX_CMD_WRITE_IPG0,
658 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT, 665 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
659 AX88772_IPG2_DEFAULT, 0, buf)) < 0) { 666 AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
660 dbg("Write IPG,IPG1,IPG2 failed: %d", ret); 667 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
661 goto out2; 668 goto out2;
662 } 669 }
663 if ((ret = 670 if ((ret = asix_set_hw_mii(dev)) < 0)
664 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
665 dbg("Failed to set hardware MII: %02x", ret);
666 goto out2; 671 goto out2;
667 }
668 672
669 /* Set RX_CTL to default values with 2k buffer, and enable cactus */ 673 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
670 if ((ret = 674 if ((ret = asix_write_rx_ctl(dev, 0x0088)) < 0)
671 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
672 buf)) < 0) {
673 dbg("Reset RX_CTL failed: %d", ret);
674 goto out2; 675 goto out2;
675 }
676 676
677 kfree(buf); 677 kfree(buf);
678 678
@@ -794,23 +794,23 @@ static int ax88772_link_reset(struct usbnet *dev)
794 u16 mode; 794 u16 mode;
795 795
796 mode = AX88772_MEDIUM_DEFAULT; 796 mode = AX88772_MEDIUM_DEFAULT;
797 lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA); 797 lpa = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
798 adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE); 798 adv = asix_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
799 res = mii_nway_result(lpa|adv); 799 res = mii_nway_result(lpa|adv);
800 800
801 if ((res & LPA_DUPLEX) == 0) 801 if ((res & LPA_DUPLEX) == 0)
802 mode &= ~AX88772_MEDIUM_FULL_DUPLEX; 802 mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
803 if ((res & LPA_100) == 0) 803 if ((res & LPA_100) == 0)
804 mode &= ~AX88772_MEDIUM_100MB; 804 mode &= ~AX88772_MEDIUM_100MB;
805 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL); 805 asix_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
806 806
807 return 0; 807 return 0;
808} 808}
809 809
810static const struct driver_info ax8817x_info = { 810static const struct driver_info ax8817x_info = {
811 .description = "ASIX AX8817x USB 2.0 Ethernet", 811 .description = "ASIX AX8817x USB 2.0 Ethernet",
812 .bind = ax8817x_bind, 812 .bind = ax88172_bind,
813 .status = ax8817x_status, 813 .status = asix_status,
814 .link_reset = ax88172_link_reset, 814 .link_reset = ax88172_link_reset,
815 .reset = ax88172_link_reset, 815 .reset = ax88172_link_reset,
816 .flags = FLAG_ETHER, 816 .flags = FLAG_ETHER,
@@ -819,8 +819,8 @@ static const struct driver_info ax8817x_info = {
819 819
820static const struct driver_info dlink_dub_e100_info = { 820static const struct driver_info dlink_dub_e100_info = {
821 .description = "DLink DUB-E100 USB Ethernet", 821 .description = "DLink DUB-E100 USB Ethernet",
822 .bind = ax8817x_bind, 822 .bind = ax88172_bind,
823 .status = ax8817x_status, 823 .status = asix_status,
824 .link_reset = ax88172_link_reset, 824 .link_reset = ax88172_link_reset,
825 .reset = ax88172_link_reset, 825 .reset = ax88172_link_reset,
826 .flags = FLAG_ETHER, 826 .flags = FLAG_ETHER,
@@ -829,8 +829,8 @@ static const struct driver_info dlink_dub_e100_info = {
829 829
830static const struct driver_info netgear_fa120_info = { 830static const struct driver_info netgear_fa120_info = {
831 .description = "Netgear FA-120 USB Ethernet", 831 .description = "Netgear FA-120 USB Ethernet",
832 .bind = ax8817x_bind, 832 .bind = ax88172_bind,
833 .status = ax8817x_status, 833 .status = asix_status,
834 .link_reset = ax88172_link_reset, 834 .link_reset = ax88172_link_reset,
835 .reset = ax88172_link_reset, 835 .reset = ax88172_link_reset,
836 .flags = FLAG_ETHER, 836 .flags = FLAG_ETHER,
@@ -839,8 +839,8 @@ static const struct driver_info netgear_fa120_info = {
839 839
840static const struct driver_info hawking_uf200_info = { 840static const struct driver_info hawking_uf200_info = {
841 .description = "Hawking UF200 USB Ethernet", 841 .description = "Hawking UF200 USB Ethernet",
842 .bind = ax8817x_bind, 842 .bind = ax88172_bind,
843 .status = ax8817x_status, 843 .status = asix_status,
844 .link_reset = ax88172_link_reset, 844 .link_reset = ax88172_link_reset,
845 .reset = ax88172_link_reset, 845 .reset = ax88172_link_reset,
846 .flags = FLAG_ETHER, 846 .flags = FLAG_ETHER,
@@ -850,13 +850,12 @@ static const struct driver_info hawking_uf200_info = {
850static const struct driver_info ax88772_info = { 850static const struct driver_info ax88772_info = {
851 .description = "ASIX AX88772 USB 2.0 Ethernet", 851 .description = "ASIX AX88772 USB 2.0 Ethernet",
852 .bind = ax88772_bind, 852 .bind = ax88772_bind,
853 .status = ax8817x_status, 853 .status = asix_status,
854 .link_reset = ax88772_link_reset, 854 .link_reset = ax88772_link_reset,
855 .reset = ax88772_link_reset, 855 .reset = ax88772_link_reset,
856 .flags = FLAG_ETHER | FLAG_FRAMING_AX, 856 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
857 .rx_fixup = ax88772_rx_fixup, 857 .rx_fixup = ax88772_rx_fixup,
858 .tx_fixup = ax88772_tx_fixup, 858 .tx_fixup = ax88772_tx_fixup,
859 .data = 0x00130103,
860}; 859};
861 860
862static const struct usb_device_id products [] = { 861static const struct usb_device_id products [] = {
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index 5b6675684567..2deb4c01539e 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -262,7 +262,7 @@ static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
262 usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb, 262 usb_fill_control_urb(pegasus->ctrl_urb, pegasus->usb,
263 usb_sndctrlpipe(pegasus->usb, 0), 263 usb_sndctrlpipe(pegasus->usb, 0),
264 (char *) &pegasus->dr, 264 (char *) &pegasus->dr,
265 &tmp, 1, ctrl_callback, pegasus); 265 tmp, 1, ctrl_callback, pegasus);
266 266
267 add_wait_queue(&pegasus->ctrl_wait, &wait); 267 add_wait_queue(&pegasus->ctrl_wait, &wait);
268 set_current_state(TASK_UNINTERRUPTIBLE); 268 set_current_state(TASK_UNINTERRUPTIBLE);
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c
index 49991ac1bf3b..94ddfe16fdda 100644
--- a/drivers/usb/net/rndis_host.c
+++ b/drivers/usb/net/rndis_host.c
@@ -39,6 +39,20 @@
39 * RNDIS is NDIS remoted over USB. It's a MSFT variant of CDC ACM ... of 39 * RNDIS is NDIS remoted over USB. It's a MSFT variant of CDC ACM ... of
40 * course ACM was intended for modems, not Ethernet links! USB's standard 40 * course ACM was intended for modems, not Ethernet links! USB's standard
41 * for Ethernet links is "CDC Ethernet", which is significantly simpler. 41 * for Ethernet links is "CDC Ethernet", which is significantly simpler.
42 *
43 * NOTE that Microsoft's "RNDIS 1.0" specification is incomplete. Issues
44 * include:
45 * - Power management in particular relies on information that's scattered
46 * through other documentation, and which is incomplete or incorrect even
47 * there.
48 * - There are various undocumented protocol requirements, such as the
49 * need to send unused garbage in control-OUT messages.
50 * - In some cases, MS-Windows will emit undocumented requests; this
51 * matters more to peripheral implementations than host ones.
52 *
53 * For these reasons and others, ** USE OF RNDIS IS STRONGLY DISCOURAGED ** in
54 * favor of such non-proprietary alternatives as CDC Ethernet or the newer (and
55 * currently rare) "Ethernet Emulation Model" (EEM).
42 */ 56 */
43 57
44/* 58/*
@@ -72,17 +86,17 @@ struct rndis_msg_hdr {
72 */ 86 */
73#define RNDIS_MSG_PACKET ccpu2(0x00000001) /* 1-N packets */ 87#define RNDIS_MSG_PACKET ccpu2(0x00000001) /* 1-N packets */
74#define RNDIS_MSG_INIT ccpu2(0x00000002) 88#define RNDIS_MSG_INIT ccpu2(0x00000002)
75#define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION) 89#define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION)
76#define RNDIS_MSG_HALT ccpu2(0x00000003) 90#define RNDIS_MSG_HALT ccpu2(0x00000003)
77#define RNDIS_MSG_QUERY ccpu2(0x00000004) 91#define RNDIS_MSG_QUERY ccpu2(0x00000004)
78#define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION) 92#define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION)
79#define RNDIS_MSG_SET ccpu2(0x00000005) 93#define RNDIS_MSG_SET ccpu2(0x00000005)
80#define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION) 94#define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION)
81#define RNDIS_MSG_RESET ccpu2(0x00000006) 95#define RNDIS_MSG_RESET ccpu2(0x00000006)
82#define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION) 96#define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION)
83#define RNDIS_MSG_INDICATE ccpu2(0x00000007) 97#define RNDIS_MSG_INDICATE ccpu2(0x00000007)
84#define RNDIS_MSG_KEEPALIVE ccpu2(0x00000008) 98#define RNDIS_MSG_KEEPALIVE ccpu2(0x00000008)
85#define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION) 99#define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION)
86 100
87/* codes for "status" field of completion messages */ 101/* codes for "status" field of completion messages */
88#define RNDIS_STATUS_SUCCESS ccpu2(0x00000000) 102#define RNDIS_STATUS_SUCCESS ccpu2(0x00000000)
@@ -596,13 +610,13 @@ static struct usb_driver rndis_driver = {
596 610
597static int __init rndis_init(void) 611static int __init rndis_init(void)
598{ 612{
599 return usb_register(&rndis_driver); 613 return usb_register(&rndis_driver);
600} 614}
601module_init(rndis_init); 615module_init(rndis_init);
602 616
603static void __exit rndis_exit(void) 617static void __exit rndis_exit(void)
604{ 618{
605 usb_deregister(&rndis_driver); 619 usb_deregister(&rndis_driver);
606} 620}
607module_exit(rndis_exit); 621module_exit(rndis_exit);
608 622
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index fe9b60cd8d95..9b1e4ed1d07e 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -1736,6 +1736,7 @@ static const struct iw_handler_def zd1201_iw_handlers = {
1736 .standard = (iw_handler *)zd1201_iw_handler, 1736 .standard = (iw_handler *)zd1201_iw_handler,
1737 .private = (iw_handler *)zd1201_private_handler, 1737 .private = (iw_handler *)zd1201_private_handler,
1738 .private_args = (struct iw_priv_args *) zd1201_private_args, 1738 .private_args = (struct iw_priv_args *) zd1201_private_args,
1739 .get_wireless_stats = zd1201_get_wireless_stats,
1739}; 1740};
1740 1741
1741static int zd1201_probe(struct usb_interface *interface, 1742static int zd1201_probe(struct usb_interface *interface,
@@ -1796,7 +1797,6 @@ static int zd1201_probe(struct usb_interface *interface,
1796 zd->dev->open = zd1201_net_open; 1797 zd->dev->open = zd1201_net_open;
1797 zd->dev->stop = zd1201_net_stop; 1798 zd->dev->stop = zd1201_net_stop;
1798 zd->dev->get_stats = zd1201_get_stats; 1799 zd->dev->get_stats = zd1201_get_stats;
1799 zd->dev->get_wireless_stats = zd1201_get_wireless_stats;
1800 zd->dev->wireless_handlers = 1800 zd->dev->wireless_handlers =
1801 (struct iw_handler_def *)&zd1201_iw_handlers; 1801 (struct iw_handler_def *)&zd1201_iw_handlers;
1802 zd->dev->hard_start_xmit = zd1201_hard_start_xmit; 1802 zd->dev->hard_start_xmit = zd1201_hard_start_xmit;
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 5a8a2c91c2b2..f96b73f54bf1 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -158,6 +158,15 @@ config USB_SERIAL_FTDI_SIO
158 To compile this driver as a module, choose M here: the 158 To compile this driver as a module, choose M here: the
159 module will be called ftdi_sio. 159 module will be called ftdi_sio.
160 160
161config USB_SERIAL_FUNSOFT
162 tristate "USB Fundamental Software Dongle Driver"
163 depends on USB_SERIAL
164 ---help---
165 Say Y here if you want to use the Fundamental Software dongle.
166
167 To compile this driver as a module, choose M here: the
168 module will be called funsoft.
169
161config USB_SERIAL_VISOR 170config USB_SERIAL_VISOR
162 tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver" 171 tristate "USB Handspring Visor / Palm m50x / Sony Clie Driver"
163 depends on USB_SERIAL 172 depends on USB_SERIAL
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index f7fe4172efed..93c21245b1af 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_USB_SERIAL_EDGEPORT) += io_edgeport.o
22obj-$(CONFIG_USB_SERIAL_EDGEPORT_TI) += io_ti.o 22obj-$(CONFIG_USB_SERIAL_EDGEPORT_TI) += io_ti.o
23obj-$(CONFIG_USB_SERIAL_EMPEG) += empeg.o 23obj-$(CONFIG_USB_SERIAL_EMPEG) += empeg.o
24obj-$(CONFIG_USB_SERIAL_FTDI_SIO) += ftdi_sio.o 24obj-$(CONFIG_USB_SERIAL_FTDI_SIO) += ftdi_sio.o
25obj-$(CONFIG_USB_SERIAL_FUNSOFT) += funsoft.o
25obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o 26obj-$(CONFIG_USB_SERIAL_GARMIN) += garmin_gps.o
26obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o 27obj-$(CONFIG_USB_SERIAL_HP4X) += hp4x.o
27obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o 28obj-$(CONFIG_USB_SERIAL_IPAQ) += ipaq.o
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 167f8ec56131..8023bb7279b1 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -54,7 +54,7 @@ static struct console usbcons;
54 * serial.c code, except that the specifier is "ttyUSB" instead 54 * serial.c code, except that the specifier is "ttyUSB" instead
55 * of "ttyS". 55 * of "ttyS".
56 */ 56 */
57static int __init usb_console_setup(struct console *co, char *options) 57static int usb_console_setup(struct console *co, char *options)
58{ 58{
59 struct usbcons_info *info = &usbcons_info; 59 struct usbcons_info *info = &usbcons_info;
60 int baud = 9600; 60 int baud = 9600;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index f3af81b4dd29..f5851db67f5b 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -489,10 +489,12 @@ static struct usb_device_id id_table_combined [] = {
489 { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) }, 489 { USB_DEVICE(KOBIL_VID, KOBIL_CONV_KAAN_PID) },
490 { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) }, 490 { USB_DEVICE(POSIFLEX_VID, POSIFLEX_PP7000_PID) },
491 { USB_DEVICE(FTDI_VID, FTDI_TTUSB_PID) }, 491 { USB_DEVICE(FTDI_VID, FTDI_TTUSB_PID) },
492 { USB_DEVICE(FTDI_VID, FTDI_ECLO_COM_1WIRE_PID) },
492 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) }, 493 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_777_PID) },
493 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) }, 494 { USB_DEVICE(FTDI_VID, FTDI_WESTREX_MODEL_8900F_PID) },
494 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) }, 495 { USB_DEVICE(FTDI_VID, FTDI_PCDJ_DAC2_PID) },
495 { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) }, 496 { USB_DEVICE(ICOM_ID1_VID, ICOM_ID1_PID) },
497 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_TMU_PID) },
496 { }, /* Optional parameter entry */ 498 { }, /* Optional parameter entry */
497 { } /* Terminating entry */ 499 { } /* Terminating entry */
498}; 500};
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 8da773c2744d..2155f0e4a378 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -399,6 +399,21 @@
399#define FTDI_WESTREX_MODEL_777_PID 0xDC00 /* Model 777 */ 399#define FTDI_WESTREX_MODEL_777_PID 0xDC00 /* Model 777 */
400#define FTDI_WESTREX_MODEL_8900F_PID 0xDC01 /* Model 8900F */ 400#define FTDI_WESTREX_MODEL_8900F_PID 0xDC01 /* Model 8900F */
401 401
402/*
403 * Eclo (http://www.eclo.pt/) product IDs.
404 * PID 0xEA90 submitted by Martin Grill.
405 */
406#define FTDI_ECLO_COM_1WIRE_PID 0xEA90 /* COM to 1-Wire USB adaptor */
407
408/*
409 * Papouch products (http://www.papouch.com/)
410 * Submitted by Folkert van Heusden
411 */
412
413#define PAPOUCH_VID 0x5050 /* Vendor ID */
414#define PAPOUCH_TMU_PID 0x0400 /* TMU USB Thermometer */
415
416
402/* Commands */ 417/* Commands */
403#define FTDI_SIO_RESET 0 /* Reset the port */ 418#define FTDI_SIO_RESET 0 /* Reset the port */
404#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 419#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
new file mode 100644
index 000000000000..803721b97e2e
--- /dev/null
+++ b/drivers/usb/serial/funsoft.c
@@ -0,0 +1,65 @@
1/*
2 * Funsoft Serial USB driver
3 *
4 * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 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(0x1404, 0xcddc) },
20 { },
21};
22MODULE_DEVICE_TABLE(usb, id_table);
23
24static struct usb_driver funsoft_driver = {
25 .name = "funsoft",
26 .probe = usb_serial_probe,
27 .disconnect = usb_serial_disconnect,
28 .id_table = id_table,
29 .no_dynamic_id = 1,
30};
31
32static struct usb_serial_driver funsoft_device = {
33 .driver = {
34 .owner = THIS_MODULE,
35 .name = "funsoft",
36 },
37 .id_table = id_table,
38 .num_interrupt_in = NUM_DONT_CARE,
39 .num_bulk_in = NUM_DONT_CARE,
40 .num_bulk_out = NUM_DONT_CARE,
41 .num_ports = 1,
42};
43
44static int __init funsoft_init(void)
45{
46 int retval;
47
48 retval = usb_serial_register(&funsoft_device);
49 if (retval)
50 return retval;
51 retval = usb_register(&funsoft_driver);
52 if (retval)
53 usb_serial_deregister(&funsoft_device);
54 return retval;
55}
56
57static void __exit funsoft_exit(void)
58{
59 usb_deregister(&funsoft_driver);
60 usb_serial_deregister(&funsoft_device);
61}
62
63module_init(funsoft_init);
64module_exit(funsoft_exit);
65MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 495db5755df9..5cf2b80add7a 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -28,6 +28,7 @@
28 2005-09-10 v0.4.3 added HUAWEI E600 card and Audiovox AirCard 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 29 2005-09-20 v0.4.4 increased recv buffer size: the card sometimes
30 wants to send >2000 bytes. 30 wants to send >2000 bytes.
31 2006-04-10 v0.4.2 fixed two array overrun errors :-/
31 32
32 Work sponsored by: Sigos GmbH, Germany <info@sigos.de> 33 Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
33 34
@@ -582,14 +583,14 @@ static void option_setup_urbs(struct usb_serial *serial)
582 portdata = usb_get_serial_port_data(port); 583 portdata = usb_get_serial_port_data(port);
583 584
584 /* Do indat endpoints first */ 585 /* Do indat endpoints first */
585 for (j = 0; j <= N_IN_URB; ++j) { 586 for (j = 0; j < N_IN_URB; ++j) {
586 portdata->in_urbs[j] = option_setup_urb (serial, 587 portdata->in_urbs[j] = option_setup_urb (serial,
587 port->bulk_in_endpointAddress, USB_DIR_IN, port, 588 port->bulk_in_endpointAddress, USB_DIR_IN, port,
588 portdata->in_buffer[j], IN_BUFLEN, option_indat_callback); 589 portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
589 } 590 }
590 591
591 /* outdat endpoints */ 592 /* outdat endpoints */
592 for (j = 0; j <= N_OUT_URB; ++j) { 593 for (j = 0; j < N_OUT_URB; ++j) {
593 portdata->out_urbs[j] = option_setup_urb (serial, 594 portdata->out_urbs[j] = option_setup_urb (serial,
594 port->bulk_out_endpointAddress, USB_DIR_OUT, port, 595 port->bulk_out_endpointAddress, USB_DIR_OUT, port,
595 portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback); 596 portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index b3014fda645c..ccf746b27d4e 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -78,6 +78,7 @@ static struct usb_device_id id_table [] = {
78 { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) }, 78 { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_PRODUCT_ID) },
79 { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) }, 79 { USB_DEVICE(LEADTEK_VENDOR_ID, LEADTEK_9531_PRODUCT_ID) },
80 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, 80 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) },
81 { USB_DEVICE(OTI_VENDOR_ID, OTI_PRODUCT_ID) },
81 { } /* Terminating entry */ 82 { } /* Terminating entry */
82}; 83};
83 84
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 77901d143979..09f379b19e98 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -79,3 +79,7 @@
79/* USB GSM cable from Speed Dragon Multimedia, Ltd */ 79/* USB GSM cable from Speed Dragon Multimedia, Ltd */
80#define SPEEDDRAGON_VENDOR_ID 0x0e55 80#define SPEEDDRAGON_VENDOR_ID 0x0e55
81#define SPEEDDRAGON_PRODUCT_ID 0x110b 81#define SPEEDDRAGON_PRODUCT_ID 0x110b
82
83/* Ours Technology Inc DKU-5 clone, chipset: Prolific Technology Inc */
84#define OTI_VENDOR_ID 0x0ea0
85#define OTI_PRODUCT_ID 0x6858
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 097f4e8488fe..071f86a59c08 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -27,10 +27,10 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/mutex.h>
30#include <linux/list.h> 31#include <linux/list.h>
31#include <linux/smp_lock.h> 32#include <linux/smp_lock.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33#include <asm/semaphore.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include "usb-serial.h" 35#include "usb-serial.h"
36#include "pl2303.h" 36#include "pl2303.h"
@@ -192,7 +192,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
192 if (!port) 192 if (!port)
193 return -ENODEV; 193 return -ENODEV;
194 194
195 if (down_interruptible(&port->sem)) 195 if (mutex_lock_interruptible(&port->mutex))
196 return -ERESTARTSYS; 196 return -ERESTARTSYS;
197 197
198 ++port->open_count; 198 ++port->open_count;
@@ -219,7 +219,7 @@ static int serial_open (struct tty_struct *tty, struct file * filp)
219 goto bailout_module_put; 219 goto bailout_module_put;
220 } 220 }
221 221
222 up(&port->sem); 222 mutex_unlock(&port->mutex);
223 return 0; 223 return 0;
224 224
225bailout_module_put: 225bailout_module_put:
@@ -227,7 +227,7 @@ bailout_module_put:
227bailout_kref_put: 227bailout_kref_put:
228 kref_put(&serial->kref, destroy_serial); 228 kref_put(&serial->kref, destroy_serial);
229 port->open_count = 0; 229 port->open_count = 0;
230 up(&port->sem); 230 mutex_unlock(&port->mutex);
231 return retval; 231 return retval;
232} 232}
233 233
@@ -240,10 +240,10 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
240 240
241 dbg("%s - port %d", __FUNCTION__, port->number); 241 dbg("%s - port %d", __FUNCTION__, port->number);
242 242
243 down(&port->sem); 243 mutex_lock(&port->mutex);
244 244
245 if (port->open_count == 0) { 245 if (port->open_count == 0) {
246 up(&port->sem); 246 mutex_unlock(&port->mutex);
247 return; 247 return;
248 } 248 }
249 249
@@ -262,7 +262,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
262 module_put(port->serial->type->driver.owner); 262 module_put(port->serial->type->driver.owner);
263 } 263 }
264 264
265 up(&port->sem); 265 mutex_unlock(&port->mutex);
266 kref_put(&port->serial->kref, destroy_serial); 266 kref_put(&port->serial->kref, destroy_serial);
267} 267}
268 268
@@ -783,7 +783,7 @@ int usb_serial_probe(struct usb_interface *interface,
783 port->number = i + serial->minor; 783 port->number = i + serial->minor;
784 port->serial = serial; 784 port->serial = serial;
785 spin_lock_init(&port->lock); 785 spin_lock_init(&port->lock);
786 sema_init(&port->sem, 1); 786 mutex_init(&port->mutex);
787 INIT_WORK(&port->work, usb_serial_port_softint, port); 787 INIT_WORK(&port->work, usb_serial_port_softint, port);
788 serial->port[i] = port; 788 serial->port[i] = port;
789 } 789 }
diff --git a/drivers/usb/serial/usb-serial.h b/drivers/usb/serial/usb-serial.h
index d7d27c3385b3..dc89d8710460 100644
--- a/drivers/usb/serial/usb-serial.h
+++ b/drivers/usb/serial/usb-serial.h
@@ -16,7 +16,7 @@
16 16
17#include <linux/config.h> 17#include <linux/config.h>
18#include <linux/kref.h> 18#include <linux/kref.h>
19#include <asm/semaphore.h> 19#include <linux/mutex.h>
20 20
21#define SERIAL_TTY_MAJOR 188 /* Nice legal number now */ 21#define SERIAL_TTY_MAJOR 188 /* Nice legal number now */
22#define SERIAL_TTY_MINORS 255 /* loads of devices :) */ 22#define SERIAL_TTY_MINORS 255 /* loads of devices :) */
@@ -31,7 +31,7 @@
31 * @serial: pointer back to the struct usb_serial owner of this port. 31 * @serial: pointer back to the struct usb_serial owner of this port.
32 * @tty: pointer to the corresponding tty for this port. 32 * @tty: pointer to the corresponding tty for this port.
33 * @lock: spinlock to grab when updating portions of this structure. 33 * @lock: spinlock to grab when updating portions of this structure.
34 * @sem: semaphore used to synchronize serial_open() and serial_close() 34 * @mutex: mutex used to synchronize serial_open() and serial_close()
35 * access for this port. 35 * access for this port.
36 * @number: the number of the port (the minor number). 36 * @number: the number of the port (the minor number).
37 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port. 37 * @interrupt_in_buffer: pointer to the interrupt in buffer for this port.
@@ -63,7 +63,7 @@ struct usb_serial_port {
63 struct usb_serial * serial; 63 struct usb_serial * serial;
64 struct tty_struct * tty; 64 struct tty_struct * tty;
65 spinlock_t lock; 65 spinlock_t lock;
66 struct semaphore sem; 66 struct mutex mutex;
67 unsigned char number; 67 unsigned char number;
68 68
69 unsigned char * interrupt_in_buffer; 69 unsigned char * interrupt_in_buffer;
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 92be101feba7..be9eec225743 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -48,7 +48,8 @@ config USB_STORAGE_FREECOM
48 48
49config USB_STORAGE_ISD200 49config USB_STORAGE_ISD200
50 bool "ISD-200 USB/ATA Bridge support" 50 bool "ISD-200 USB/ATA Bridge support"
51 depends on USB_STORAGE && BLK_DEV_IDE 51 depends on USB_STORAGE
52 depends on BLK_DEV_IDE=y || BLK_DEV_IDE=USB_STORAGE
52 ---help--- 53 ---help---
53 Say Y here if you want to use USB Mass Store devices based 54 Say Y here if you want to use USB Mass Store devices based
54 on the In-Systems Design ISD-200 USB/ATA bridge. 55 on the In-Systems Design ISD-200 USB/ATA bridge.
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 22e9d696fdd2..9060e7137441 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -904,18 +904,6 @@ config FB_MATROX_MULTIHEAD
904 There is no need for enabling 'Matrox multihead support' if you have 904 There is no need for enabling 'Matrox multihead support' if you have
905 only one Matrox card in the box. 905 only one Matrox card in the box.
906 906
907config FB_RADEON_OLD
908 tristate "ATI Radeon display support (Old driver)"
909 depends on FB && PCI
910 select FB_CFB_FILLRECT
911 select FB_CFB_COPYAREA
912 select FB_CFB_IMAGEBLIT
913 select FB_MACMODES if PPC
914 help
915 Choose this option if you want to use an ATI Radeon graphics card as
916 a framebuffer device. There are both PCI and AGP versions. You
917 don't need to choose this to run the Radeon in plain VGA mode.
918
919config FB_RADEON 907config FB_RADEON
920 tristate "ATI Radeon display support" 908 tristate "ATI Radeon display support"
921 depends on FB && PCI 909 depends on FB && PCI
@@ -973,7 +961,7 @@ config FB_ATY128
973 961
974config FB_ATY 962config FB_ATY
975 tristate "ATI Mach64 display support" if PCI || ATARI 963 tristate "ATI Mach64 display support" if PCI || ATARI
976 depends on FB 964 depends on FB && !SPARC32
977 select FB_CFB_FILLRECT 965 select FB_CFB_FILLRECT
978 select FB_CFB_COPYAREA 966 select FB_CFB_COPYAREA
979 select FB_CFB_IMAGEBLIT 967 select FB_CFB_IMAGEBLIT
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index cb90218515ac..23de3b2c7856 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -39,7 +39,6 @@ obj-$(CONFIG_FB_KYRO) += kyro/
39obj-$(CONFIG_FB_SAVAGE) += savage/ 39obj-$(CONFIG_FB_SAVAGE) += savage/
40obj-$(CONFIG_FB_GEODE) += geode/ 40obj-$(CONFIG_FB_GEODE) += geode/
41obj-$(CONFIG_FB_I810) += vgastate.o 41obj-$(CONFIG_FB_I810) += vgastate.o
42obj-$(CONFIG_FB_RADEON_OLD) += radeonfb.o
43obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o 42obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o
44obj-$(CONFIG_FB_VIRGE) += virgefb.o 43obj-$(CONFIG_FB_VIRGE) += virgefb.o
45obj-$(CONFIG_FB_3DFX) += tdfxfb.o 44obj-$(CONFIG_FB_3DFX) += tdfxfb.o
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 821c6da8e42c..f7bbff4ddc6a 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -67,6 +67,7 @@
67#include <asm/io.h> 67#include <asm/io.h>
68 68
69#ifdef CONFIG_PPC_PMAC 69#ifdef CONFIG_PPC_PMAC
70#include <asm/machdep.h>
70#include <asm/pmac_feature.h> 71#include <asm/pmac_feature.h>
71#include <asm/prom.h> 72#include <asm/prom.h>
72#include <asm/pci-bridge.h> 73#include <asm/pci-bridge.h>
@@ -1748,7 +1749,7 @@ static int __init aty128_init(struct pci_dev *pdev, const struct pci_device_id *
1748 1749
1749 var = default_var; 1750 var = default_var;
1750#ifdef CONFIG_PPC_PMAC 1751#ifdef CONFIG_PPC_PMAC
1751 if (_machine == _MACH_Pmac) { 1752 if (machine_is(powermac)) {
1752 /* Indicate sleep capability */ 1753 /* Indicate sleep capability */
1753 if (par->chip_gen == rage_M3) { 1754 if (par->chip_gen == rage_M3) {
1754 pmac_call_feature(PMAC_FTR_DEVICE_CAN_WAKE, NULL, 0, 1); 1755 pmac_call_feature(PMAC_FTR_DEVICE_CAN_WAKE, NULL, 0, 1);
@@ -2011,7 +2012,7 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2011 return 0; 2012 return 0;
2012 2013
2013#ifdef CONFIG_PMAC_BACKLIGHT 2014#ifdef CONFIG_PMAC_BACKLIGHT
2014 if ((_machine == _MACH_Pmac) && blank) 2015 if (machine_is(powermac) && blank)
2015 set_backlight_enable(0); 2016 set_backlight_enable(0);
2016#endif /* CONFIG_PMAC_BACKLIGHT */ 2017#endif /* CONFIG_PMAC_BACKLIGHT */
2017 2018
@@ -2029,7 +2030,7 @@ static int aty128fb_blank(int blank, struct fb_info *fb)
2029 aty128_set_lcd_enable(par, par->lcd_on && !blank); 2030 aty128_set_lcd_enable(par, par->lcd_on && !blank);
2030 } 2031 }
2031#ifdef CONFIG_PMAC_BACKLIGHT 2032#ifdef CONFIG_PMAC_BACKLIGHT
2032 if ((_machine == _MACH_Pmac) && !blank) 2033 if (machine_is(powermac) && !blank)
2033 set_backlight_enable(1); 2034 set_backlight_enable(1);
2034#endif /* CONFIG_PMAC_BACKLIGHT */ 2035#endif /* CONFIG_PMAC_BACKLIGHT */
2035 return 0; 2036 return 0;
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index e799fcca365a..d9d7d3c4cae2 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -75,6 +75,7 @@
75#include "ati_ids.h" 75#include "ati_ids.h"
76 76
77#ifdef __powerpc__ 77#ifdef __powerpc__
78#include <asm/machdep.h>
78#include <asm/prom.h> 79#include <asm/prom.h>
79#include "../macmodes.h" 80#include "../macmodes.h"
80#endif 81#endif
@@ -2518,7 +2519,7 @@ static int __init aty_init(struct fb_info *info, const char *name)
2518 2519
2519 memset(&var, 0, sizeof(var)); 2520 memset(&var, 0, sizeof(var));
2520#ifdef CONFIG_PPC 2521#ifdef CONFIG_PPC
2521 if (_machine == _MACH_Pmac) { 2522 if (machine_is(powermac)) {
2522 /* 2523 /*
2523 * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it 2524 * FIXME: The NVRAM stuff should be put in a Mac-specific file, as it
2524 * applies to all Mac video cards 2525 * applies to all Mac video cards
@@ -2673,7 +2674,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
2673 return 0; 2674 return 0;
2674 2675
2675#ifdef CONFIG_PMAC_BACKLIGHT 2676#ifdef CONFIG_PMAC_BACKLIGHT
2676 if ((_machine == _MACH_Pmac) && blank > FB_BLANK_NORMAL) 2677 if (machine_is(powermac) && blank > FB_BLANK_NORMAL)
2677 set_backlight_enable(0); 2678 set_backlight_enable(0);
2678#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2679#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2679 if (par->lcd_table && blank > FB_BLANK_NORMAL && 2680 if (par->lcd_table && blank > FB_BLANK_NORMAL &&
@@ -2705,7 +2706,7 @@ static int atyfb_blank(int blank, struct fb_info *info)
2705 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par); 2706 aty_st_le32(CRTC_GEN_CNTL, gen_cntl, par);
2706 2707
2707#ifdef CONFIG_PMAC_BACKLIGHT 2708#ifdef CONFIG_PMAC_BACKLIGHT
2708 if ((_machine == _MACH_Pmac) && blank <= FB_BLANK_NORMAL) 2709 if (machine_is(powermac) && blank <= FB_BLANK_NORMAL)
2709 set_backlight_enable(1); 2710 set_backlight_enable(1);
2710#elif defined(CONFIG_FB_ATY_GENERIC_LCD) 2711#elif defined(CONFIG_FB_ATY_GENERIC_LCD)
2711 if (par->lcd_table && blank <= FB_BLANK_NORMAL && 2712 if (par->lcd_table && blank <= FB_BLANK_NORMAL &&
@@ -3399,7 +3400,7 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3399 struct atyfb_par *par; 3400 struct atyfb_par *par;
3400 int i, rc = -ENOMEM; 3401 int i, rc = -ENOMEM;
3401 3402
3402 for (i = ARRAY_SIZE(aty_chips); i >= 0; i--) 3403 for (i = ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
3403 if (pdev->device == aty_chips[i].pci_id) 3404 if (pdev->device == aty_chips[i].pci_id)
3404 break; 3405 break;
3405 3406
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index 5886a2f1323e..c7091761cef4 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -20,7 +20,7 @@
20#include <linux/agp_backend.h> 20#include <linux/agp_backend.h>
21 21
22#ifdef CONFIG_PPC_PMAC 22#ifdef CONFIG_PPC_PMAC
23#include <asm/processor.h> 23#include <asm/machdep.h>
24#include <asm/prom.h> 24#include <asm/prom.h>
25#include <asm/pmac_feature.h> 25#include <asm/pmac_feature.h>
26#endif 26#endif
@@ -2745,7 +2745,7 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk)
2745 rinfo->pm_mode |= radeon_pm_off; 2745 rinfo->pm_mode |= radeon_pm_off;
2746 } 2746 }
2747#if defined(CONFIG_PPC_PMAC) 2747#if defined(CONFIG_PPC_PMAC)
2748 if (_machine == _MACH_Pmac && rinfo->of_node) { 2748 if (machine_is(powermac) && rinfo->of_node) {
2749 if (rinfo->is_mobility && rinfo->pm_reg && 2749 if (rinfo->is_mobility && rinfo->pm_reg &&
2750 rinfo->family <= CHIP_FAMILY_RV250) 2750 rinfo->family <= CHIP_FAMILY_RV250)
2751 rinfo->pm_mode |= radeon_pm_d2; 2751 rinfo->pm_mode |= radeon_pm_d2;
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 9d996f2c10d5..b895eaaa73fd 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -43,11 +43,11 @@ config LCD_DEVICE
43 default y 43 default y
44 44
45config BACKLIGHT_CORGI 45config BACKLIGHT_CORGI
46 tristate "Sharp Corgi Backlight Driver (SL-C7xx Series)" 46 tristate "Sharp Corgi Backlight Driver (SL Series)"
47 depends on BACKLIGHT_DEVICE && PXA_SHARPSL 47 depends on BACKLIGHT_DEVICE && PXA_SHARPSL
48 default y 48 default y
49 help 49 help
50 If you have a Sharp Zaurus SL-C7xx, say y to enable the 50 If you have a Sharp Zaurus SL-C7xx, SL-Cxx00 or SL-6000x say y to enable the
51 backlight driver. 51 backlight driver.
52 52
53config BACKLIGHT_HP680 53config BACKLIGHT_HP680
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 151fda8dded0..334b1db1bd7c 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -16,14 +16,12 @@
16 16
17static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 17static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
18{ 18{
19 int rc; 19 int rc = -ENXIO;
20 struct backlight_device *bd = to_backlight_device(cdev); 20 struct backlight_device *bd = to_backlight_device(cdev);
21 21
22 down(&bd->sem); 22 down(&bd->sem);
23 if (likely(bd->props && bd->props->get_power)) 23 if (likely(bd->props))
24 rc = sprintf(buf, "%d\n", bd->props->get_power(bd)); 24 rc = sprintf(buf, "%d\n", bd->props->power);
25 else
26 rc = -ENXIO;
27 up(&bd->sem); 25 up(&bd->sem);
28 26
29 return rc; 27 return rc;
@@ -31,7 +29,7 @@ static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
31 29
32static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 30static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count)
33{ 31{
34 int rc, power; 32 int rc = -ENXIO, power;
35 char *endp; 33 char *endp;
36 struct backlight_device *bd = to_backlight_device(cdev); 34 struct backlight_device *bd = to_backlight_device(cdev);
37 35
@@ -40,12 +38,13 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
40 return -EINVAL; 38 return -EINVAL;
41 39
42 down(&bd->sem); 40 down(&bd->sem);
43 if (likely(bd->props && bd->props->set_power)) { 41 if (likely(bd->props)) {
44 pr_debug("backlight: set power to %d\n", power); 42 pr_debug("backlight: set power to %d\n", power);
45 bd->props->set_power(bd, power); 43 bd->props->power = power;
44 if (likely(bd->props->update_status))
45 bd->props->update_status(bd);
46 rc = count; 46 rc = count;
47 } else 47 }
48 rc = -ENXIO;
49 up(&bd->sem); 48 up(&bd->sem);
50 49
51 return rc; 50 return rc;
@@ -53,14 +52,12 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
53 52
54static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) 53static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
55{ 54{
56 int rc; 55 int rc = -ENXIO;
57 struct backlight_device *bd = to_backlight_device(cdev); 56 struct backlight_device *bd = to_backlight_device(cdev);
58 57
59 down(&bd->sem); 58 down(&bd->sem);
60 if (likely(bd->props && bd->props->get_brightness)) 59 if (likely(bd->props))
61 rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd)); 60 rc = sprintf(buf, "%d\n", bd->props->brightness);
62 else
63 rc = -ENXIO;
64 up(&bd->sem); 61 up(&bd->sem);
65 62
66 return rc; 63 return rc;
@@ -68,7 +65,7 @@ static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf)
68 65
69static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 66static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count)
70{ 67{
71 int rc, brightness; 68 int rc = -ENXIO, brightness;
72 char *endp; 69 char *endp;
73 struct backlight_device *bd = to_backlight_device(cdev); 70 struct backlight_device *bd = to_backlight_device(cdev);
74 71
@@ -77,12 +74,18 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
77 return -EINVAL; 74 return -EINVAL;
78 75
79 down(&bd->sem); 76 down(&bd->sem);
80 if (likely(bd->props && bd->props->set_brightness)) { 77 if (likely(bd->props)) {
81 pr_debug("backlight: set brightness to %d\n", brightness); 78 if (brightness > bd->props->max_brightness)
82 bd->props->set_brightness(bd, brightness); 79 rc = -EINVAL;
83 rc = count; 80 else {
84 } else 81 pr_debug("backlight: set brightness to %d\n",
85 rc = -ENXIO; 82 brightness);
83 bd->props->brightness = brightness;
84 if (likely(bd->props->update_status))
85 bd->props->update_status(bd);
86 rc = count;
87 }
88 }
86 up(&bd->sem); 89 up(&bd->sem);
87 90
88 return rc; 91 return rc;
@@ -90,14 +93,26 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
90 93
91static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) 94static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf)
92{ 95{
93 int rc; 96 int rc = -ENXIO;
94 struct backlight_device *bd = to_backlight_device(cdev); 97 struct backlight_device *bd = to_backlight_device(cdev);
95 98
96 down(&bd->sem); 99 down(&bd->sem);
97 if (likely(bd->props)) 100 if (likely(bd->props))
98 rc = sprintf(buf, "%d\n", bd->props->max_brightness); 101 rc = sprintf(buf, "%d\n", bd->props->max_brightness);
99 else 102 up(&bd->sem);
100 rc = -ENXIO; 103
104 return rc;
105}
106
107static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
108 char *buf)
109{
110 int rc = -ENXIO;
111 struct backlight_device *bd = to_backlight_device(cdev);
112
113 down(&bd->sem);
114 if (likely(bd->props && bd->props->get_brightness))
115 rc = sprintf(buf, "%d\n", bd->props->get_brightness(bd));
101 up(&bd->sem); 116 up(&bd->sem);
102 117
103 return rc; 118 return rc;
@@ -123,7 +138,10 @@ static struct class backlight_class = {
123 138
124static struct class_device_attribute bl_class_device_attributes[] = { 139static struct class_device_attribute bl_class_device_attributes[] = {
125 DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power), 140 DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power),
126 DECLARE_ATTR(brightness, 0644, backlight_show_brightness, backlight_store_brightness), 141 DECLARE_ATTR(brightness, 0644, backlight_show_brightness,
142 backlight_store_brightness),
143 DECLARE_ATTR(actual_brightness, 0444, backlight_show_actual_brightness,
144 NULL),
127 DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), 145 DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL),
128}; 146};
129 147
@@ -144,8 +162,12 @@ static int fb_notifier_callback(struct notifier_block *self,
144 bd = container_of(self, struct backlight_device, fb_notif); 162 bd = container_of(self, struct backlight_device, fb_notif);
145 down(&bd->sem); 163 down(&bd->sem);
146 if (bd->props) 164 if (bd->props)
147 if (!bd->props->check_fb || bd->props->check_fb(evdata->info)) 165 if (!bd->props->check_fb ||
148 bd->props->set_power(bd, *(int *)evdata->data); 166 bd->props->check_fb(evdata->info)) {
167 bd->props->fb_blank = *(int *)evdata->data;
168 if (likely(bd->props && bd->props->update_status))
169 bd->props->update_status(bd);
170 }
149 up(&bd->sem); 171 up(&bd->sem);
150 return 0; 172 return 0;
151} 173}
@@ -231,6 +253,12 @@ void backlight_device_unregister(struct backlight_device *bd)
231 &bl_class_device_attributes[i]); 253 &bl_class_device_attributes[i]);
232 254
233 down(&bd->sem); 255 down(&bd->sem);
256 if (likely(bd->props && bd->props->update_status)) {
257 bd->props->brightness = 0;
258 bd->props->power = 0;
259 bd->props->update_status(bd);
260 }
261
234 bd->props = NULL; 262 bd->props = NULL;
235 up(&bd->sem); 263 up(&bd->sem);
236 264
diff --git a/drivers/video/backlight/corgi_bl.c b/drivers/video/backlight/corgi_bl.c
index d0aaf450e8c7..2ebbfd95145f 100644
--- a/drivers/video/backlight/corgi_bl.c
+++ b/drivers/video/backlight/corgi_bl.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Backlight Driver for Sharp Corgi 2 * Backlight Driver for Sharp Zaurus Handhelds (various models)
3 * 3 *
4 * Copyright (c) 2004-2005 Richard Purdie 4 * Copyright (c) 2004-2006 Richard Purdie
5 * 5 *
6 * Based on Sharp's 2.4 Backlight Driver 6 * Based on Sharp's 2.4 Backlight Driver
7 * 7 *
@@ -15,80 +15,63 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/spinlock.h> 18#include <linux/mutex.h>
19#include <linux/fb.h> 19#include <linux/fb.h>
20#include <linux/backlight.h> 20#include <linux/backlight.h>
21
22#include <asm/arch/sharpsl.h> 21#include <asm/arch/sharpsl.h>
23#include <asm/hardware/sharpsl_pm.h> 22#include <asm/hardware/sharpsl_pm.h>
24 23
25#define CORGI_DEFAULT_INTENSITY 0x1f 24static int corgibl_intensity;
26#define CORGI_LIMIT_MASK 0x0b 25static DEFINE_MUTEX(bl_mutex);
27
28static int corgibl_powermode = FB_BLANK_UNBLANK;
29static int current_intensity = 0;
30static int corgibl_limit = 0;
31static void (*corgibl_mach_set_intensity)(int intensity);
32static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
33static struct backlight_properties corgibl_data; 26static struct backlight_properties corgibl_data;
27static struct backlight_device *corgi_backlight_device;
28static struct corgibl_machinfo *bl_machinfo;
34 29
35static void corgibl_send_intensity(int intensity) 30static unsigned long corgibl_flags;
31#define CORGIBL_SUSPENDED 0x01
32#define CORGIBL_BATTLOW 0x02
33
34static int corgibl_send_intensity(struct backlight_device *bd)
36{ 35{
37 unsigned long flags;
38 void (*corgi_kick_batt)(void); 36 void (*corgi_kick_batt)(void);
37 int intensity = bd->props->brightness;
39 38
40 if (corgibl_powermode != FB_BLANK_UNBLANK) { 39 if (bd->props->power != FB_BLANK_UNBLANK)
41 intensity = 0; 40 intensity = 0;
42 } else { 41 if (bd->props->fb_blank != FB_BLANK_UNBLANK)
43 if (corgibl_limit) 42 intensity = 0;
44 intensity &= CORGI_LIMIT_MASK; 43 if (corgibl_flags & CORGIBL_SUSPENDED)
45 } 44 intensity = 0;
46 45 if (corgibl_flags & CORGIBL_BATTLOW)
47 spin_lock_irqsave(&bl_lock, flags); 46 intensity &= bl_machinfo->limit_mask;
48 47
49 corgibl_mach_set_intensity(intensity); 48 mutex_lock(&bl_mutex);
49 bl_machinfo->set_bl_intensity(intensity);
50 mutex_unlock(&bl_mutex);
50 51
51 spin_unlock_irqrestore(&bl_lock, flags); 52 corgibl_intensity = intensity;
52 53
53 corgi_kick_batt = symbol_get(sharpsl_battery_kick); 54 corgi_kick_batt = symbol_get(sharpsl_battery_kick);
54 if (corgi_kick_batt) { 55 if (corgi_kick_batt) {
55 corgi_kick_batt(); 56 corgi_kick_batt();
56 symbol_put(sharpsl_battery_kick); 57 symbol_put(sharpsl_battery_kick);
57 } 58 }
58}
59 59
60static void corgibl_blank(int blank) 60 return 0;
61{
62 switch(blank) {
63
64 case FB_BLANK_NORMAL:
65 case FB_BLANK_VSYNC_SUSPEND:
66 case FB_BLANK_HSYNC_SUSPEND:
67 case FB_BLANK_POWERDOWN:
68 if (corgibl_powermode == FB_BLANK_UNBLANK) {
69 corgibl_send_intensity(0);
70 corgibl_powermode = blank;
71 }
72 break;
73 case FB_BLANK_UNBLANK:
74 if (corgibl_powermode != FB_BLANK_UNBLANK) {
75 corgibl_powermode = blank;
76 corgibl_send_intensity(current_intensity);
77 }
78 break;
79 }
80} 61}
81 62
82#ifdef CONFIG_PM 63#ifdef CONFIG_PM
83static int corgibl_suspend(struct platform_device *dev, pm_message_t state) 64static int corgibl_suspend(struct platform_device *dev, pm_message_t state)
84{ 65{
85 corgibl_blank(FB_BLANK_POWERDOWN); 66 corgibl_flags |= CORGIBL_SUSPENDED;
67 corgibl_send_intensity(corgi_backlight_device);
86 return 0; 68 return 0;
87} 69}
88 70
89static int corgibl_resume(struct platform_device *dev) 71static int corgibl_resume(struct platform_device *dev)
90{ 72{
91 corgibl_blank(FB_BLANK_UNBLANK); 73 corgibl_flags &= ~CORGIBL_SUSPENDED;
74 corgibl_send_intensity(corgi_backlight_device);
92 return 0; 75 return 0;
93} 76}
94#else 77#else
@@ -96,68 +79,55 @@ static int corgibl_resume(struct platform_device *dev)
96#define corgibl_resume NULL 79#define corgibl_resume NULL
97#endif 80#endif
98 81
99 82static int corgibl_get_intensity(struct backlight_device *bd)
100static int corgibl_set_power(struct backlight_device *bd, int state)
101{
102 corgibl_blank(state);
103 return 0;
104}
105
106static int corgibl_get_power(struct backlight_device *bd)
107{ 83{
108 return corgibl_powermode; 84 return corgibl_intensity;
109} 85}
110 86
111static int corgibl_set_intensity(struct backlight_device *bd, int intensity) 87static int corgibl_set_intensity(struct backlight_device *bd)
112{ 88{
113 if (intensity > corgibl_data.max_brightness) 89 corgibl_send_intensity(corgi_backlight_device);
114 intensity = corgibl_data.max_brightness;
115 corgibl_send_intensity(intensity);
116 current_intensity=intensity;
117 return 0; 90 return 0;
118} 91}
119 92
120static int corgibl_get_intensity(struct backlight_device *bd)
121{
122 return current_intensity;
123}
124
125/* 93/*
126 * Called when the battery is low to limit the backlight intensity. 94 * Called when the battery is low to limit the backlight intensity.
127 * If limit==0 clear any limit, otherwise limit the intensity 95 * If limit==0 clear any limit, otherwise limit the intensity
128 */ 96 */
129void corgibl_limit_intensity(int limit) 97void corgibl_limit_intensity(int limit)
130{ 98{
131 corgibl_limit = (limit ? 1 : 0); 99 if (limit)
132 corgibl_send_intensity(current_intensity); 100 corgibl_flags |= CORGIBL_BATTLOW;
101 else
102 corgibl_flags &= ~CORGIBL_BATTLOW;
103 corgibl_send_intensity(corgi_backlight_device);
133} 104}
134EXPORT_SYMBOL(corgibl_limit_intensity); 105EXPORT_SYMBOL(corgibl_limit_intensity);
135 106
136 107
137static struct backlight_properties corgibl_data = { 108static struct backlight_properties corgibl_data = {
138 .owner = THIS_MODULE, 109 .owner = THIS_MODULE,
139 .get_power = corgibl_get_power,
140 .set_power = corgibl_set_power,
141 .get_brightness = corgibl_get_intensity, 110 .get_brightness = corgibl_get_intensity,
142 .set_brightness = corgibl_set_intensity, 111 .update_status = corgibl_set_intensity,
143}; 112};
144 113
145static struct backlight_device *corgi_backlight_device;
146
147static int __init corgibl_probe(struct platform_device *pdev) 114static int __init corgibl_probe(struct platform_device *pdev)
148{ 115{
149 struct corgibl_machinfo *machinfo = pdev->dev.platform_data; 116 struct corgibl_machinfo *machinfo = pdev->dev.platform_data;
150 117
118 bl_machinfo = machinfo;
151 corgibl_data.max_brightness = machinfo->max_intensity; 119 corgibl_data.max_brightness = machinfo->max_intensity;
152 corgibl_mach_set_intensity = machinfo->set_bl_intensity; 120 if (!machinfo->limit_mask)
121 machinfo->limit_mask = -1;
153 122
154 corgi_backlight_device = backlight_device_register ("corgi-bl", 123 corgi_backlight_device = backlight_device_register ("corgi-bl",
155 NULL, &corgibl_data); 124 NULL, &corgibl_data);
156 if (IS_ERR (corgi_backlight_device)) 125 if (IS_ERR (corgi_backlight_device))
157 return PTR_ERR (corgi_backlight_device); 126 return PTR_ERR (corgi_backlight_device);
158 127
159 corgibl_set_intensity(NULL, CORGI_DEFAULT_INTENSITY); 128 corgibl_data.power = FB_BLANK_UNBLANK;
160 corgibl_limit_intensity(0); 129 corgibl_data.brightness = machinfo->default_intensity;
130 corgibl_send_intensity(corgi_backlight_device);
161 131
162 printk("Corgi Backlight Driver Initialized.\n"); 132 printk("Corgi Backlight Driver Initialized.\n");
163 return 0; 133 return 0;
@@ -167,8 +137,6 @@ static int corgibl_remove(struct platform_device *dev)
167{ 137{
168 backlight_device_unregister(corgi_backlight_device); 138 backlight_device_unregister(corgi_backlight_device);
169 139
170 corgibl_set_intensity(NULL, 0);
171
172 printk("Corgi Backlight Driver Unloaded\n"); 140 printk("Corgi Backlight Driver Unloaded\n");
173 return 0; 141 return 0;
174} 142}
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index 95da4c9ed1f1..a71e984c93d4 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -13,7 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/device.h> 16#include <linux/platform_device.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/fb.h> 18#include <linux/fb.h>
19#include <linux/backlight.h> 19#include <linux/backlight.h>
@@ -25,66 +25,58 @@
25#define HP680_MAX_INTENSITY 255 25#define HP680_MAX_INTENSITY 255
26#define HP680_DEFAULT_INTENSITY 10 26#define HP680_DEFAULT_INTENSITY 10
27 27
28static int hp680bl_powermode = FB_BLANK_UNBLANK; 28static int hp680bl_suspended;
29static int current_intensity = 0; 29static int current_intensity = 0;
30static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED; 30static spinlock_t bl_lock = SPIN_LOCK_UNLOCKED;
31static struct backlight_device *hp680_backlight_device;
31 32
32static void hp680bl_send_intensity(int intensity) 33static void hp680bl_send_intensity(struct backlight_device *bd)
33{ 34{
34 unsigned long flags; 35 unsigned long flags;
36 u16 v;
37 int intensity = bd->props->brightness;
35 38
36 if (hp680bl_powermode != FB_BLANK_UNBLANK) 39 if (bd->props->power != FB_BLANK_UNBLANK)
40 intensity = 0;
41 if (bd->props->fb_blank != FB_BLANK_UNBLANK)
42 intensity = 0;
43 if (hp680bl_suspended)
37 intensity = 0; 44 intensity = 0;
38 45
39 spin_lock_irqsave(&bl_lock, flags); 46 spin_lock_irqsave(&bl_lock, flags);
40 sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS); 47 if (intensity && current_intensity == 0) {
48 sh_dac_enable(DAC_LCD_BRIGHTNESS);
49 v = inw(HD64461_GPBDR);
50 v &= ~HD64461_GPBDR_LCDOFF;
51 outw(v, HD64461_GPBDR);
52 sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
53 } else if (intensity == 0 && current_intensity != 0) {
54 sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
55 sh_dac_disable(DAC_LCD_BRIGHTNESS);
56 v = inw(HD64461_GPBDR);
57 v |= HD64461_GPBDR_LCDOFF;
58 outw(v, HD64461_GPBDR);
59 } else if (intensity) {
60 sh_dac_output(255-(u8)intensity, DAC_LCD_BRIGHTNESS);
61 }
41 spin_unlock_irqrestore(&bl_lock, flags); 62 spin_unlock_irqrestore(&bl_lock, flags);
42}
43 63
44static void hp680bl_blank(int blank) 64 current_intensity = intensity;
45{
46 u16 v;
47
48 switch(blank) {
49
50 case FB_BLANK_NORMAL:
51 case FB_BLANK_VSYNC_SUSPEND:
52 case FB_BLANK_HSYNC_SUSPEND:
53 case FB_BLANK_POWERDOWN:
54 if (hp680bl_powermode == FB_BLANK_UNBLANK) {
55 hp680bl_send_intensity(0);
56 hp680bl_powermode = blank;
57 sh_dac_disable(DAC_LCD_BRIGHTNESS);
58 v = inw(HD64461_GPBDR);
59 v |= HD64461_GPBDR_LCDOFF;
60 outw(v, HD64461_GPBDR);
61 }
62 break;
63 case FB_BLANK_UNBLANK:
64 if (hp680bl_powermode != FB_BLANK_UNBLANK) {
65 sh_dac_enable(DAC_LCD_BRIGHTNESS);
66 v = inw(HD64461_GPBDR);
67 v &= ~HD64461_GPBDR_LCDOFF;
68 outw(v, HD64461_GPBDR);
69 hp680bl_powermode = blank;
70 hp680bl_send_intensity(current_intensity);
71 }
72 break;
73 }
74} 65}
75 66
67
76#ifdef CONFIG_PM 68#ifdef CONFIG_PM
77static int hp680bl_suspend(struct device *dev, pm_message_t state, u32 level) 69static int hp680bl_suspend(struct platform_device *dev, pm_message_t state)
78{ 70{
79 if (level == SUSPEND_POWER_DOWN) 71 hp680bl_suspended = 1;
80 hp680bl_blank(FB_BLANK_POWERDOWN); 72 hp680bl_send_intensity(hp680_backlight_device);
81 return 0; 73 return 0;
82} 74}
83 75
84static int hp680bl_resume(struct device *dev, u32 level) 76static int hp680bl_resume(struct platform_device *dev)
85{ 77{
86 if (level == RESUME_POWER_ON) 78 hp680bl_suspended = 0;
87 hp680bl_blank(FB_BLANK_UNBLANK); 79 hp680bl_send_intensity(hp680_backlight_device);
88 return 0; 80 return 0;
89} 81}
90#else 82#else
@@ -92,24 +84,9 @@ static int hp680bl_resume(struct device *dev, u32 level)
92#define hp680bl_resume NULL 84#define hp680bl_resume NULL
93#endif 85#endif
94 86
95 87static int hp680bl_set_intensity(struct backlight_device *bd)
96static int hp680bl_set_power(struct backlight_device *bd, int state)
97{ 88{
98 hp680bl_blank(state); 89 hp680bl_send_intensity(bd);
99 return 0;
100}
101
102static int hp680bl_get_power(struct backlight_device *bd)
103{
104 return hp680bl_powermode;
105}
106
107static int hp680bl_set_intensity(struct backlight_device *bd, int intensity)
108{
109 if (intensity > HP680_MAX_INTENSITY)
110 intensity = HP680_MAX_INTENSITY;
111 hp680bl_send_intensity(intensity);
112 current_intensity = intensity;
113 return 0; 90 return 0;
114} 91}
115 92
@@ -120,65 +97,67 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
120 97
121static struct backlight_properties hp680bl_data = { 98static struct backlight_properties hp680bl_data = {
122 .owner = THIS_MODULE, 99 .owner = THIS_MODULE,
123 .get_power = hp680bl_get_power,
124 .set_power = hp680bl_set_power,
125 .max_brightness = HP680_MAX_INTENSITY, 100 .max_brightness = HP680_MAX_INTENSITY,
126 .get_brightness = hp680bl_get_intensity, 101 .get_brightness = hp680bl_get_intensity,
127 .set_brightness = hp680bl_set_intensity, 102 .update_status = hp680bl_set_intensity,
128}; 103};
129 104
130static struct backlight_device *hp680_backlight_device; 105static int __init hp680bl_probe(struct platform_device *dev)
131
132static int __init hp680bl_probe(struct device *dev)
133{ 106{
134 hp680_backlight_device = backlight_device_register ("hp680-bl", 107 hp680_backlight_device = backlight_device_register ("hp680-bl",
135 NULL, &hp680bl_data); 108 NULL, &hp680bl_data);
136 if (IS_ERR (hp680_backlight_device)) 109 if (IS_ERR (hp680_backlight_device))
137 return PTR_ERR (hp680_backlight_device); 110 return PTR_ERR (hp680_backlight_device);
138 111
139 hp680bl_set_intensity(NULL, HP680_DEFAULT_INTENSITY); 112 hp680_backlight_device->props->brightness = HP680_DEFAULT_INTENSITY;
113 hp680bl_send_intensity(hp680_backlight_device);
140 114
141 return 0; 115 return 0;
142} 116}
143 117
144static int hp680bl_remove(struct device *dev) 118static int hp680bl_remove(struct platform_device *dev)
145{ 119{
146 backlight_device_unregister(hp680_backlight_device); 120 backlight_device_unregister(hp680_backlight_device);
147 121
148 return 0; 122 return 0;
149} 123}
150 124
151static struct device_driver hp680bl_driver = { 125static struct platform_driver hp680bl_driver = {
152 .name = "hp680-bl",
153 .bus = &platform_bus_type,
154 .probe = hp680bl_probe, 126 .probe = hp680bl_probe,
155 .remove = hp680bl_remove, 127 .remove = hp680bl_remove,
156 .suspend = hp680bl_suspend, 128 .suspend = hp680bl_suspend,
157 .resume = hp680bl_resume, 129 .resume = hp680bl_resume,
130 .driver = {
131 .name = "hp680-bl",
132 },
158}; 133};
159 134
160static struct platform_device hp680bl_device = { 135static struct platform_device *hp680bl_device;
161 .name = "hp680-bl",
162 .id = -1,
163};
164 136
165static int __init hp680bl_init(void) 137static int __init hp680bl_init(void)
166{ 138{
167 int ret; 139 int ret;
168 140
169 ret=driver_register(&hp680bl_driver); 141 ret = platform_driver_register(&hp680bl_driver);
170 if (!ret) { 142 if (!ret) {
171 ret = platform_device_register(&hp680bl_device); 143 hp680bl_device = platform_device_alloc("hp680-bl", -1);
172 if (ret) 144 if (!hp680bl_device)
173 driver_unregister(&hp680bl_driver); 145 return -ENOMEM;
146
147 ret = platform_device_add(hp680bl_device);
148
149 if (ret) {
150 platform_device_put(hp680bl_device);
151 platform_driver_unregister(&hp680bl_driver);
152 }
174 } 153 }
175 return ret; 154 return ret;
176} 155}
177 156
178static void __exit hp680bl_exit(void) 157static void __exit hp680bl_exit(void)
179{ 158{
180 platform_device_unregister(&hp680bl_device); 159 platform_device_unregister(hp680bl_device);
181 driver_unregister(&hp680bl_driver); 160 platform_driver_unregister(&hp680bl_driver);
182} 161}
183 162
184module_init(hp680bl_init); 163module_init(hp680bl_init);
diff --git a/drivers/video/cfbimgblt.c b/drivers/video/cfbimgblt.c
index 910e2338a27e..8ba6152db2fd 100644
--- a/drivers/video/cfbimgblt.c
+++ b/drivers/video/cfbimgblt.c
@@ -169,7 +169,7 @@ static inline void slow_imageblit(const struct fb_image *image, struct fb_info *
169 169
170 while (j--) { 170 while (j--) {
171 l--; 171 l--;
172 color = (*s & 1 << (FB_BIT_NR(l))) ? fgcolor : bgcolor; 172 color = (*s & (1 << l)) ? fgcolor : bgcolor;
173 val |= FB_SHIFT_HIGH(color, shift); 173 val |= FB_SHIFT_HIGH(color, shift);
174 174
175 /* Did the bitshift spill bits to the next long? */ 175 /* Did the bitshift spill bits to the next long? */
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index 66d6f2f0a219..1103010af54a 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -60,8 +60,8 @@
60#include <asm/amigahw.h> 60#include <asm/amigahw.h>
61#endif 61#endif
62#ifdef CONFIG_PPC_PREP 62#ifdef CONFIG_PPC_PREP
63#include <asm/processor.h> 63#include <asm/machdep.h>
64#define isPReP (_machine == _MACH_prep) 64#define isPReP (machine_is(prep))
65#else 65#else
66#define isPReP 0 66#define isPReP 0
67#endif 67#endif
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 041d06987861..ca020719d20b 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -466,7 +466,7 @@ static int __init fb_console_setup(char *this_opt)
466 int i, j; 466 int i, j;
467 467
468 if (!this_opt || !*this_opt) 468 if (!this_opt || !*this_opt)
469 return 0; 469 return 1;
470 470
471 while ((options = strsep(&this_opt, ",")) != NULL) { 471 while ((options = strsep(&this_opt, ",")) != NULL) {
472 if (!strncmp(options, "font:", 5)) 472 if (!strncmp(options, "font:", 5))
@@ -481,10 +481,10 @@ static int __init fb_console_setup(char *this_opt)
481 options++; 481 options++;
482 } 482 }
483 if (*options != ',') 483 if (*options != ',')
484 return 0; 484 return 1;
485 options++; 485 options++;
486 } else 486 } else
487 return 0; 487 return 1;
488 } 488 }
489 489
490 if (!strncmp(options, "map:", 4)) { 490 if (!strncmp(options, "map:", 4)) {
@@ -496,7 +496,7 @@ static int __init fb_console_setup(char *this_opt)
496 con2fb_map_boot[i] = 496 con2fb_map_boot[i] =
497 (options[j++]-'0') % FB_MAX; 497 (options[j++]-'0') % FB_MAX;
498 } 498 }
499 return 0; 499 return 1;
500 } 500 }
501 501
502 if (!strncmp(options, "vc:", 3)) { 502 if (!strncmp(options, "vc:", 3)) {
@@ -518,7 +518,7 @@ static int __init fb_console_setup(char *this_opt)
518 rotate = 0; 518 rotate = 0;
519 } 519 }
520 } 520 }
521 return 0; 521 return 1;
522} 522}
523 523
524__setup("fbcon=", fb_console_setup); 524__setup("fbcon=", fb_console_setup);
@@ -1142,6 +1142,7 @@ static void fbcon_init(struct vc_data *vc, int init)
1142 set_blitting_type(vc, info); 1142 set_blitting_type(vc, info);
1143 } 1143 }
1144 1144
1145 ops->p = &fb_display[fg_console];
1145} 1146}
1146 1147
1147static void fbcon_deinit(struct vc_data *vc) 1148static void fbcon_deinit(struct vc_data *vc)
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
index 0339f5640a78..74ac2acaf72c 100644
--- a/drivers/video/console/sticore.c
+++ b/drivers/video/console/sticore.c
@@ -275,7 +275,7 @@ static int __init sti_setup(char *str)
275 if (str) 275 if (str)
276 strlcpy (default_sti_path, str, sizeof (default_sti_path)); 276 strlcpy (default_sti_path, str, sizeof (default_sti_path));
277 277
278 return 0; 278 return 1;
279} 279}
280 280
281/* Assuming the machine has multiple STI consoles (=graphic cards) which 281/* Assuming the machine has multiple STI consoles (=graphic cards) which
@@ -321,7 +321,7 @@ static int __init sti_font_setup(char *str)
321 i++; 321 i++;
322 } 322 }
323 323
324 return 0; 324 return 1;
325} 325}
326 326
327/* The optional linux kernel parameter "sti_font" defines which font 327/* The optional linux kernel parameter "sti_font" defines which font
@@ -373,7 +373,7 @@ sti_dump_globcfg(struct sti_glob_cfg *glob_cfg, unsigned int sti_mem_request)
373 glob_cfg->save_addr)); 373 glob_cfg->save_addr));
374 374
375 /* dump extended cfg */ 375 /* dump extended cfg */
376 cfg = PTR_STI(glob_cfg->ext_ptr); 376 cfg = PTR_STI((unsigned long)glob_cfg->ext_ptr);
377 DPRINTK(( KERN_INFO 377 DPRINTK(( KERN_INFO
378 "monitor %d\n" 378 "monitor %d\n"
379 "in friendly mode: %d\n" 379 "in friendly mode: %d\n"
@@ -453,25 +453,11 @@ sti_init_glob_cfg(struct sti_struct *sti,
453 sti->regions_phys[i] = 453 sti->regions_phys[i] =
454 REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa); 454 REGION_OFFSET_TO_PHYS(sti->regions[i], newhpa);
455 455
456 /* remap virtually */
457 /* FIXME: add BTLB support if btlb==1 */
458 len = sti->regions[i].region_desc.length * 4096; 456 len = sti->regions[i].region_desc.length * 4096;
459
460/* XXX: Enabling IOREMAP debugging causes a crash, so we must be passing
461 * a virtual address to something expecting a physical address that doesn't
462 * go through a readX macro */
463#if 0
464 if (len)
465 glob_cfg->region_ptrs[i] = (unsigned long) (
466 sti->regions[i].region_desc.cache ?
467 ioremap(sti->regions_phys[i], len) :
468 ioremap_nocache(sti->regions_phys[i], len) );
469#else
470 if (len) 457 if (len)
471 glob_cfg->region_ptrs[i] = sti->regions_phys[i]; 458 glob_cfg->region_ptrs[i] = sti->regions_phys[i];
472#endif
473 459
474 DPRINTK(("region #%d: phys %08lx, virt %08x, len=%lukB, " 460 DPRINTK(("region #%d: phys %08lx, region_ptr %08x, len=%lukB, "
475 "btlb=%d, sysonly=%d, cache=%d, last=%d\n", 461 "btlb=%d, sysonly=%d, cache=%d, last=%d\n",
476 i, sti->regions_phys[i], glob_cfg->region_ptrs[i], 462 i, sti->regions_phys[i], glob_cfg->region_ptrs[i],
477 len/1024, 463 len/1024,
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index b1a8dca76430..8d8eadb64853 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -435,6 +435,11 @@ int fb_prepare_logo(struct fb_info *info, int rotate)
435 depth = info->var.green.length; 435 depth = info->var.green.length;
436 } 436 }
437 437
438 if (info->fix.visual == FB_VISUAL_STATIC_PSEUDOCOLOR) {
439 /* assume console colormap */
440 depth = 4;
441 }
442
438 if (depth >= 8) { 443 if (depth >= 8) {
439 switch (info->fix.visual) { 444 switch (info->fix.visual) {
440 case FB_VISUAL_TRUECOLOR: 445 case FB_VISUAL_TRUECOLOR:
@@ -1588,7 +1593,7 @@ static int __init video_setup(char *options)
1588 } 1593 }
1589 } 1594 }
1590 1595
1591 return 0; 1596 return 1;
1592} 1597}
1593__setup("video=", video_setup); 1598__setup("video=", video_setup);
1594#endif 1599#endif
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index 951c9974a1d3..23c1827b2d0b 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -115,6 +115,7 @@
115#include <asm/uaccess.h> 115#include <asm/uaccess.h>
116 116
117#ifdef CONFIG_PPC_PMAC 117#ifdef CONFIG_PPC_PMAC
118#include <asm/machdep.h>
118unsigned char nvram_read_byte(int); 119unsigned char nvram_read_byte(int);
119static int default_vmode = VMODE_NVRAM; 120static int default_vmode = VMODE_NVRAM;
120static int default_cmode = CMODE_NVRAM; 121static int default_cmode = CMODE_NVRAM;
@@ -1833,7 +1834,7 @@ static int initMatrox2(WPMINFO struct board* b){
1833 /* FIXME: Where to move this?! */ 1834 /* FIXME: Where to move this?! */
1834#if defined(CONFIG_PPC_PMAC) 1835#if defined(CONFIG_PPC_PMAC)
1835#ifndef MODULE 1836#ifndef MODULE
1836 if (_machine == _MACH_Pmac) { 1837 if (machine_is(powermac)) {
1837 struct fb_var_screeninfo var; 1838 struct fb_var_screeninfo var;
1838 if (default_vmode <= 0 || default_vmode > VMODE_MAX) 1839 if (default_vmode <= 0 || default_vmode > VMODE_MAX)
1839 default_vmode = VMODE_640_480_60; 1840 default_vmode = VMODE_640_480_60;
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index 6d3e4890cb43..093ab9977c7c 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -30,6 +30,7 @@
30#include <asm/pci-bridge.h> 30#include <asm/pci-bridge.h>
31#endif 31#endif
32#ifdef CONFIG_PMAC_BACKLIGHT 32#ifdef CONFIG_PMAC_BACKLIGHT
33#include <asm/machdep.h>
33#include <asm/backlight.h> 34#include <asm/backlight.h>
34#endif 35#endif
35 36
@@ -1355,7 +1356,7 @@ static int nvidiafb_blank(int blank, struct fb_info *info)
1355 NVWriteCrtc(par, 0x1a, vesa); 1356 NVWriteCrtc(par, 0x1a, vesa);
1356 1357
1357#ifdef CONFIG_PMAC_BACKLIGHT 1358#ifdef CONFIG_PMAC_BACKLIGHT
1358 if (par->FlatPanel && _machine == _MACH_Pmac) { 1359 if (par->FlatPanel && machine_is(powermac)) {
1359 set_backlight_enable(!blank); 1360 set_backlight_enable(!blank);
1360 } 1361 }
1361#endif 1362#endif
@@ -1741,7 +1742,7 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1741 info->fix.id, 1742 info->fix.id,
1742 par->FbMapSize / (1024 * 1024), info->fix.smem_start); 1743 par->FbMapSize / (1024 * 1024), info->fix.smem_start);
1743#ifdef CONFIG_PMAC_BACKLIGHT 1744#ifdef CONFIG_PMAC_BACKLIGHT
1744 if (par->FlatPanel && _machine == _MACH_Pmac) 1745 if (par->FlatPanel && machine_is(powermac))
1745 register_backlight_controller(&nvidia_backlight_controller, 1746 register_backlight_controller(&nvidia_backlight_controller,
1746 par, "mnca"); 1747 par, "mnca");
1747#endif 1748#endif
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 53ad61f1038c..809fc5eefc15 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -232,9 +232,9 @@ static int pxafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
232 if (var->yres < MIN_YRES) 232 if (var->yres < MIN_YRES)
233 var->yres = MIN_YRES; 233 var->yres = MIN_YRES;
234 if (var->xres > fbi->max_xres) 234 if (var->xres > fbi->max_xres)
235 var->xres = fbi->max_xres; 235 return -EINVAL;
236 if (var->yres > fbi->max_yres) 236 if (var->yres > fbi->max_yres)
237 var->yres = fbi->max_yres; 237 return -EINVAL;
238 var->xres_virtual = 238 var->xres_virtual =
239 max(var->xres_virtual, var->xres); 239 max(var->xres_virtual, var->xres);
240 var->yres_virtual = 240 var->yres_virtual =
@@ -781,7 +781,7 @@ static void pxafb_disable_controller(struct pxafb_info *fbi)
781 LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */ 781 LCCR0 &= ~LCCR0_LDM; /* Enable LCD Disable Done Interrupt */
782 LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */ 782 LCCR0 |= LCCR0_DIS; /* Disable LCD Controller */
783 783
784 schedule_timeout(20 * HZ / 1000); 784 schedule_timeout(200 * HZ / 1000);
785 remove_wait_queue(&fbi->ctrlr_wait, &wait); 785 remove_wait_queue(&fbi->ctrlr_wait, &wait);
786 786
787 /* disable LCD controller clock */ 787 /* disable LCD controller clock */
@@ -1274,7 +1274,7 @@ int __init pxafb_probe(struct platform_device *dev)
1274 struct pxafb_mach_info *inf; 1274 struct pxafb_mach_info *inf;
1275 int ret; 1275 int ret;
1276 1276
1277 dev_dbg(dev, "pxafb_probe\n"); 1277 dev_dbg(&dev->dev, "pxafb_probe\n");
1278 1278
1279 inf = dev->dev.platform_data; 1279 inf = dev->dev.platform_data;
1280 ret = -ENOMEM; 1280 ret = -ENOMEM;
diff --git a/drivers/video/radeonfb.c b/drivers/video/radeonfb.c
deleted file mode 100644
index 24982adb3aa2..000000000000
--- a/drivers/video/radeonfb.c
+++ /dev/null
@@ -1,3167 +0,0 @@
1/*
2 * drivers/video/radeonfb.c
3 * framebuffer driver for ATI Radeon chipset video boards
4 *
5 * Copyright 2000 Ani Joshi <ajoshi@kernel.crashing.org>
6 *
7 *
8 * ChangeLog:
9 * 2000-08-03 initial version 0.0.1
10 * 2000-09-10 more bug fixes, public release 0.0.5
11 * 2001-02-19 mode bug fixes, 0.0.7
12 * 2001-07-05 fixed scrolling issues, engine initialization,
13 * and minor mode tweaking, 0.0.9
14 * 2001-09-07 Radeon VE support, Nick Kurshev
15 * blanking, pan_display, and cmap fixes, 0.1.0
16 * 2001-10-10 Radeon 7500 and 8500 support, and experimental
17 * flat panel support, 0.1.1
18 * 2001-11-17 Radeon M6 (ppc) support, Daniel Berlin, 0.1.2
19 * 2001-11-18 DFP fixes, Kevin Hendricks, 0.1.3
20 * 2001-11-29 more cmap, backlight fixes, Benjamin Herrenschmidt
21 * 2002-01-18 DFP panel detection via BIOS, Michael Clark, 0.1.4
22 * 2002-06-02 console switching, mode set fixes, accel fixes
23 * 2002-06-03 MTRR support, Peter Horton, 0.1.5
24 * 2002-09-21 rv250, r300, m9 initial support,
25 * added mirror option, 0.1.6
26 *
27 * Special thanks to ATI DevRel team for their hardware donations.
28 *
29 */
30
31
32#define RADEON_VERSION "0.1.6"
33
34
35#include <linux/config.h>
36#include <linux/module.h>
37#include <linux/kernel.h>
38#include <linux/errno.h>
39#include <linux/string.h>
40#include <linux/mm.h>
41#include <linux/tty.h>
42#include <linux/slab.h>
43#include <linux/delay.h>
44#include <linux/fb.h>
45#include <linux/ioport.h>
46#include <linux/init.h>
47#include <linux/pci.h>
48#include <linux/vmalloc.h>
49
50#include <asm/io.h>
51#include <asm/uaccess.h>
52#if defined(__powerpc__)
53#include <asm/prom.h>
54#include <asm/pci-bridge.h>
55#include "macmodes.h"
56
57#ifdef CONFIG_NVRAM
58#include <linux/nvram.h>
59#endif
60
61#ifdef CONFIG_PMAC_BACKLIGHT
62#include <asm/backlight.h>
63#endif
64
65#ifdef CONFIG_BOOTX_TEXT
66#include <asm/btext.h>
67#endif
68
69#ifdef CONFIG_ADB_PMU
70#include <linux/adb.h>
71#include <linux/pmu.h>
72#endif
73
74#endif /* __powerpc__ */
75
76#ifdef CONFIG_MTRR
77#include <asm/mtrr.h>
78#endif
79
80#include <video/radeon.h>
81#include <linux/radeonfb.h>
82
83#define DEBUG 0
84
85#if DEBUG
86#define RTRACE printk
87#else
88#define RTRACE if(0) printk
89#endif
90
91// XXX
92#undef CONFIG_PMAC_PBOOK
93
94
95enum radeon_chips {
96 RADEON_QD,
97 RADEON_QE,
98 RADEON_QF,
99 RADEON_QG,
100 RADEON_QY,
101 RADEON_QZ,
102 RADEON_LW,
103 RADEON_LX,
104 RADEON_LY,
105 RADEON_LZ,
106 RADEON_QL,
107 RADEON_QN,
108 RADEON_QO,
109 RADEON_Ql,
110 RADEON_BB,
111 RADEON_QW,
112 RADEON_QX,
113 RADEON_Id,
114 RADEON_Ie,
115 RADEON_If,
116 RADEON_Ig,
117 RADEON_Ya,
118 RADEON_Yd,
119 RADEON_Ld,
120 RADEON_Le,
121 RADEON_Lf,
122 RADEON_Lg,
123 RADEON_ND,
124 RADEON_NE,
125 RADEON_NF,
126 RADEON_NG,
127 RADEON_QM
128};
129
130enum radeon_arch {
131 RADEON_R100,
132 RADEON_RV100,
133 RADEON_R200,
134 RADEON_RV200,
135 RADEON_RV250,
136 RADEON_R300,
137 RADEON_M6,
138 RADEON_M7,
139 RADEON_M9
140};
141
142static struct radeon_chip_info {
143 const char *name;
144 unsigned char arch;
145} radeon_chip_info[] __devinitdata = {
146 { "QD", RADEON_R100 },
147 { "QE", RADEON_R100 },
148 { "QF", RADEON_R100 },
149 { "QG", RADEON_R100 },
150 { "VE QY", RADEON_RV100 },
151 { "VE QZ", RADEON_RV100 },
152 { "M7 LW", RADEON_M7 },
153 { "M7 LX", RADEON_M7 },
154 { "M6 LY", RADEON_M6 },
155 { "M6 LZ", RADEON_M6 },
156 { "8500 QL", RADEON_R200 },
157 { "8500 QN", RADEON_R200 },
158 { "8500 QO", RADEON_R200 },
159 { "8500 Ql", RADEON_R200 },
160 { "8500 BB", RADEON_R200 },
161 { "7500 QW", RADEON_RV200 },
162 { "7500 QX", RADEON_RV200 },
163 { "9000 Id", RADEON_RV250 },
164 { "9000 Ie", RADEON_RV250 },
165 { "9000 If", RADEON_RV250 },
166 { "9000 Ig", RADEON_RV250 },
167 { "M9 Ld", RADEON_M9 },
168 { "M9 Le", RADEON_M9 },
169 { "M9 Lf", RADEON_M9 },
170 { "M9 Lg", RADEON_M9 },
171 { "9700 ND", RADEON_R300 },
172 { "9700 NE", RADEON_R300 },
173 { "9700 NF", RADEON_R300 },
174 { "9700 NG", RADEON_R300 },
175 { "9100 QM", RADEON_R200 }
176};
177
178
179enum radeon_montype
180{
181 MT_NONE,
182 MT_CRT, /* CRT */
183 MT_LCD, /* LCD */
184 MT_DFP, /* DVI */
185 MT_CTV, /* composite TV */
186 MT_STV /* S-Video out */
187};
188
189
190static struct pci_device_id radeonfb_pci_table[] = {
191 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QD, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QD},
192 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QE},
193 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QF},
194 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QG},
195 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QY},
196 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QZ},
197 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LW},
198 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LX},
199 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LY, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LY},
200 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_LZ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_LZ},
201 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QL},
202 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QN, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QN},
203 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QO},
204 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ql, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ql},
205 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_BB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_BB},
206 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QW, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QW},
207 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QX},
208 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Id},
209 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ie, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ie},
210 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_If, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_If},
211 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ig, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ig},
212 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ya, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ya},
213 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Yd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Yd},
214 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Ld, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Ld},
215 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Le, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Le},
216 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lf, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lf},
217 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_Lg, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_Lg},
218 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_ND, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_ND},
219 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NE},
220 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NF},
221 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_NG, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_NG},
222 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RADEON_QM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RADEON_QM},
223 { 0, }
224};
225MODULE_DEVICE_TABLE(pci, radeonfb_pci_table);
226
227
228typedef struct {
229 u16 reg;
230 u32 val;
231} reg_val;
232
233
234/* these common regs are cleared before mode setting so they do not
235 * interfere with anything
236 */
237static reg_val common_regs[] = {
238 { OVR_CLR, 0 },
239 { OVR_WID_LEFT_RIGHT, 0 },
240 { OVR_WID_TOP_BOTTOM, 0 },
241 { OV0_SCALE_CNTL, 0 },
242 { SUBPIC_CNTL, 0 },
243 { VIPH_CONTROL, 0 },
244 { I2C_CNTL_1, 0 },
245 { GEN_INT_CNTL, 0 },
246 { CAP0_TRIG_CNTL, 0 },
247};
248
249static reg_val common_regs_m6[] = {
250 { OVR_CLR, 0 },
251 { OVR_WID_LEFT_RIGHT, 0 },
252 { OVR_WID_TOP_BOTTOM, 0 },
253 { OV0_SCALE_CNTL, 0 },
254 { SUBPIC_CNTL, 0 },
255 { GEN_INT_CNTL, 0 },
256 { CAP0_TRIG_CNTL, 0 }
257};
258
259typedef struct {
260 u8 clock_chip_type;
261 u8 struct_size;
262 u8 accelerator_entry;
263 u8 VGA_entry;
264 u16 VGA_table_offset;
265 u16 POST_table_offset;
266 u16 XCLK;
267 u16 MCLK;
268 u8 num_PLL_blocks;
269 u8 size_PLL_blocks;
270 u16 PCLK_ref_freq;
271 u16 PCLK_ref_divider;
272 u32 PCLK_min_freq;
273 u32 PCLK_max_freq;
274 u16 MCLK_ref_freq;
275 u16 MCLK_ref_divider;
276 u32 MCLK_min_freq;
277 u32 MCLK_max_freq;
278 u16 XCLK_ref_freq;
279 u16 XCLK_ref_divider;
280 u32 XCLK_min_freq;
281 u32 XCLK_max_freq;
282} __attribute__ ((packed)) PLL_BLOCK;
283
284
285struct pll_info {
286 int ppll_max;
287 int ppll_min;
288 int xclk;
289 int ref_div;
290 int ref_clk;
291};
292
293
294struct ram_info {
295 int ml;
296 int mb;
297 int trcd;
298 int trp;
299 int twr;
300 int cl;
301 int tr2w;
302 int loop_latency;
303 int rloop;
304};
305
306
307struct radeon_regs {
308 /* CRTC regs */
309 u32 crtc_h_total_disp;
310 u32 crtc_h_sync_strt_wid;
311 u32 crtc_v_total_disp;
312 u32 crtc_v_sync_strt_wid;
313 u32 crtc_pitch;
314 u32 crtc_gen_cntl;
315 u32 crtc_ext_cntl;
316 u32 dac_cntl;
317
318 u32 flags;
319 u32 pix_clock;
320 int xres, yres;
321
322 /* DDA regs */
323 u32 dda_config;
324 u32 dda_on_off;
325
326 /* PLL regs */
327 u32 ppll_div_3;
328 u32 ppll_ref_div;
329 u32 vclk_ecp_cntl;
330
331 /* Flat panel regs */
332 u32 fp_crtc_h_total_disp;
333 u32 fp_crtc_v_total_disp;
334 u32 fp_gen_cntl;
335 u32 fp_h_sync_strt_wid;
336 u32 fp_horz_stretch;
337 u32 fp_panel_cntl;
338 u32 fp_v_sync_strt_wid;
339 u32 fp_vert_stretch;
340 u32 lvds_gen_cntl;
341 u32 lvds_pll_cntl;
342 u32 tmds_crc;
343 u32 tmds_transmitter_cntl;
344
345#if defined(__BIG_ENDIAN)
346 u32 surface_cntl;
347#endif
348};
349
350
351struct radeonfb_info {
352 struct fb_info info;
353
354 struct radeon_regs state;
355 struct radeon_regs init_state;
356
357 char name[32];
358 char ram_type[12];
359
360 unsigned long mmio_base_phys;
361 unsigned long fb_base_phys;
362
363 void __iomem *mmio_base;
364 void __iomem *fb_base;
365
366 struct pci_dev *pdev;
367
368 unsigned char *EDID;
369 unsigned char __iomem *bios_seg;
370
371 u32 pseudo_palette[17];
372 struct { u8 red, green, blue, pad; } palette[256];
373
374 int chipset;
375 unsigned char arch;
376 int video_ram;
377 u8 rev;
378 int pitch, bpp, depth;
379 int xres, yres, pixclock;
380 int xres_virtual, yres_virtual;
381 u32 accel_flags;
382
383 int use_default_var;
384 int got_dfpinfo;
385
386 int hasCRTC2;
387 int crtDisp_type;
388 int dviDisp_type;
389
390 int panel_xres, panel_yres;
391 int clock;
392 int hOver_plus, hSync_width, hblank;
393 int vOver_plus, vSync_width, vblank;
394 int hAct_high, vAct_high, interlaced;
395 int synct, misc;
396
397 u32 dp_gui_master_cntl;
398
399 struct pll_info pll;
400 int pll_output_freq, post_div, fb_div;
401
402 struct ram_info ram;
403
404 int mtrr_hdl;
405
406#ifdef CONFIG_PMAC_PBOOK
407 int pm_reg;
408 u32 save_regs[64];
409 u32 mdll, mdll2;
410#endif /* CONFIG_PMAC_PBOOK */
411 int asleep;
412
413 struct radeonfb_info *next;
414};
415
416
417static struct fb_var_screeninfo radeonfb_default_var = {
418 640, 480, 640, 480, 0, 0, 8, 0,
419 {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0},
420 0, 0, -1, -1, 0, 39721, 40, 24, 32, 11, 96, 2,
421 0, FB_VMODE_NONINTERLACED
422};
423
424/*
425 * IO macros
426 */
427
428#define INREG8(addr) readb((rinfo->mmio_base)+addr)
429#define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
430#define INREG(addr) readl((rinfo->mmio_base)+addr)
431#define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
432
433#define OUTPLL(addr,val) \
434 do { \
435 OUTREG8(CLOCK_CNTL_INDEX, (addr & 0x0000003f) | 0x00000080); \
436 OUTREG(CLOCK_CNTL_DATA, val); \
437 } while(0)
438
439#define OUTPLLP(addr,val,mask) \
440 do { \
441 unsigned int _tmp = INPLL(addr); \
442 _tmp &= (mask); \
443 _tmp |= (val); \
444 OUTPLL(addr, _tmp); \
445 } while (0)
446
447#define OUTREGP(addr,val,mask) \
448 do { \
449 unsigned int _tmp = INREG(addr); \
450 _tmp &= (mask); \
451 _tmp |= (val); \
452 OUTREG(addr, _tmp); \
453 } while (0)
454
455
456static __inline__ u32 _INPLL(struct radeonfb_info *rinfo, u32 addr)
457{
458 OUTREG8(CLOCK_CNTL_INDEX, addr & 0x0000003f);
459 return (INREG(CLOCK_CNTL_DATA));
460}
461
462#define INPLL(addr) _INPLL(rinfo, addr)
463
464#define PRIMARY_MONITOR(rinfo) ((rinfo->dviDisp_type != MT_NONE) && \
465 (rinfo->dviDisp_type != MT_STV) && \
466 (rinfo->dviDisp_type != MT_CTV) ? \
467 rinfo->dviDisp_type : rinfo->crtDisp_type)
468
469static char *GET_MON_NAME(int type)
470{
471 char *pret = NULL;
472
473 switch (type) {
474 case MT_NONE:
475 pret = "no";
476 break;
477 case MT_CRT:
478 pret = "CRT";
479 break;
480 case MT_DFP:
481 pret = "DFP";
482 break;
483 case MT_LCD:
484 pret = "LCD";
485 break;
486 case MT_CTV:
487 pret = "CTV";
488 break;
489 case MT_STV:
490 pret = "STV";
491 break;
492 }
493
494 return pret;
495}
496
497
498/*
499 * 2D engine routines
500 */
501
502static __inline__ void radeon_engine_flush (struct radeonfb_info *rinfo)
503{
504 int i;
505
506 /* initiate flush */
507 OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
508 ~RB2D_DC_FLUSH_ALL);
509
510 for (i=0; i < 2000000; i++) {
511 if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
512 break;
513 }
514}
515
516
517static __inline__ void _radeon_fifo_wait (struct radeonfb_info *rinfo, int entries)
518{
519 int i;
520
521 for (i=0; i<2000000; i++)
522 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
523 return;
524}
525
526
527static __inline__ void _radeon_engine_idle (struct radeonfb_info *rinfo)
528{
529 int i;
530
531 /* ensure FIFO is empty before waiting for idle */
532 _radeon_fifo_wait (rinfo, 64);
533
534 for (i=0; i<2000000; i++) {
535 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
536 radeon_engine_flush (rinfo);
537 return;
538 }
539 }
540}
541
542
543#define radeon_engine_idle() _radeon_engine_idle(rinfo)
544#define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
545
546
547
548/*
549 * helper routines
550 */
551
552static __inline__ u32 radeon_get_dstbpp(u16 depth)
553{
554 switch (depth) {
555 case 8:
556 return DST_8BPP;
557 case 15:
558 return DST_15BPP;
559 case 16:
560 return DST_16BPP;
561 case 32:
562 return DST_32BPP;
563 default:
564 return 0;
565 }
566}
567
568
569static inline int var_to_depth(const struct fb_var_screeninfo *var)
570{
571 if (var->bits_per_pixel != 16)
572 return var->bits_per_pixel;
573 return (var->green.length == 6) ? 16 : 15;
574}
575
576
577static void _radeon_engine_reset(struct radeonfb_info *rinfo)
578{
579 u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
580
581 radeon_engine_flush (rinfo);
582
583 clock_cntl_index = INREG(CLOCK_CNTL_INDEX);
584 mclk_cntl = INPLL(MCLK_CNTL);
585
586 OUTPLL(MCLK_CNTL, (mclk_cntl |
587 FORCEON_MCLKA |
588 FORCEON_MCLKB |
589 FORCEON_YCLKA |
590 FORCEON_YCLKB |
591 FORCEON_MC |
592 FORCEON_AIC));
593 rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
594
595 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset |
596 SOFT_RESET_CP |
597 SOFT_RESET_HI |
598 SOFT_RESET_SE |
599 SOFT_RESET_RE |
600 SOFT_RESET_PP |
601 SOFT_RESET_E2 |
602 SOFT_RESET_RB);
603 INREG(RBBM_SOFT_RESET);
604 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset & (u32)
605 ~(SOFT_RESET_CP |
606 SOFT_RESET_HI |
607 SOFT_RESET_SE |
608 SOFT_RESET_RE |
609 SOFT_RESET_PP |
610 SOFT_RESET_E2 |
611 SOFT_RESET_RB));
612 INREG(RBBM_SOFT_RESET);
613
614 OUTPLL(MCLK_CNTL, mclk_cntl);
615 OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
616 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
617
618 return;
619}
620
621#define radeon_engine_reset() _radeon_engine_reset(rinfo)
622
623
624static __inline__ int round_div(int num, int den)
625{
626 return (num + (den / 2)) / den;
627}
628
629
630
631static __inline__ int min_bits_req(int val)
632{
633 int bits_req = 0;
634
635 if (val == 0)
636 bits_req = 1;
637
638 while (val) {
639 val >>= 1;
640 bits_req++;
641 }
642
643 return (bits_req);
644}
645
646
647static __inline__ int _max(int val1, int val2)
648{
649 if (val1 >= val2)
650 return val1;
651 else
652 return val2;
653}
654
655
656
657/*
658 * globals
659 */
660
661#ifndef MODULE
662static char *mode_option;
663#endif
664
665static char noaccel = 0;
666static char mirror = 0;
667static int panel_yres = 0;
668static char force_dfp = 0;
669static struct radeonfb_info *board_list = NULL;
670static char nomtrr = 0;
671
672/*
673 * prototypes
674 */
675
676static void radeon_save_state (struct radeonfb_info *rinfo,
677 struct radeon_regs *save);
678static void radeon_engine_init (struct radeonfb_info *rinfo);
679static void radeon_write_mode (struct radeonfb_info *rinfo,
680 struct radeon_regs *mode);
681static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo);
682static int __devinit radeon_init_disp (struct radeonfb_info *rinfo);
683static int radeon_init_disp_var (struct radeonfb_info *rinfo, struct fb_var_screeninfo *var);
684static void __iomem *radeon_find_rom(struct radeonfb_info *rinfo);
685static void radeon_get_pllinfo(struct radeonfb_info *rinfo, void __iomem *bios_seg);
686static void radeon_get_moninfo (struct radeonfb_info *rinfo);
687static int radeon_get_dfpinfo (struct radeonfb_info *rinfo);
688static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo);
689static void radeon_get_EDID(struct radeonfb_info *rinfo);
690static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo);
691static void radeon_update_default_var(struct radeonfb_info *rinfo);
692
693#ifdef CONFIG_PPC_OF
694
695static int radeon_read_OF (struct radeonfb_info *rinfo);
696static int radeon_get_EDID_OF(struct radeonfb_info *rinfo);
697extern struct device_node *pci_device_to_OF_node(struct pci_dev *dev);
698
699#ifdef CONFIG_PMAC_PBOOK
700int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when);
701static struct pmu_sleep_notifier radeon_sleep_notifier = {
702 radeon_sleep_notify, SLEEP_LEVEL_VIDEO,
703};
704#endif /* CONFIG_PMAC_PBOOK */
705#ifdef CONFIG_PMAC_BACKLIGHT
706static int radeon_set_backlight_enable(int on, int level, void *data);
707static int radeon_set_backlight_level(int level, void *data);
708static struct backlight_controller radeon_backlight_controller = {
709 radeon_set_backlight_enable,
710 radeon_set_backlight_level
711};
712#endif /* CONFIG_PMAC_BACKLIGHT */
713
714#endif /* CONFIG_PPC_OF */
715
716
717static void __iomem *radeon_find_rom(struct radeonfb_info *rinfo)
718{
719#if defined(__i386__)
720 u32 segstart;
721 char __iomem *rom_base;
722 char __iomem *rom;
723 int stage;
724 int i,j;
725 char aty_rom_sig[] = "761295520";
726 char *radeon_sig[] = {
727 "RG6",
728 "RADEON"
729 };
730
731 for(segstart=0x000c0000; segstart<0x000f0000; segstart+=0x00001000) {
732
733 stage = 1;
734
735 rom_base = ioremap(segstart, 0x1000);
736
737 if ((*rom_base == 0x55) && (((*(rom_base + 1)) & 0xff) == 0xaa))
738 stage = 2;
739
740
741 if (stage != 2) {
742 iounmap(rom_base);
743 continue;
744 }
745
746 rom = rom_base;
747
748 for (i = 0; (i < 128 - strlen(aty_rom_sig)) && (stage != 3); i++) {
749 if (aty_rom_sig[0] == *rom)
750 if (strncmp(aty_rom_sig, rom,
751 strlen(aty_rom_sig)) == 0)
752 stage = 3;
753 rom++;
754 }
755 if (stage != 3) {
756 iounmap(rom_base);
757 continue;
758 }
759 rom = rom_base;
760
761 for (i = 0; (i < 512) && (stage != 4); i++) {
762 for (j = 0; j < ARRAY_SIZE(radeon_sig); j++) {
763 if (radeon_sig[j][0] == *rom)
764 if (strncmp(radeon_sig[j], rom,
765 strlen(radeon_sig[j])) == 0) {
766 stage = 4;
767 break;
768 }
769 }
770 rom++;
771 }
772 if (stage != 4) {
773 iounmap(rom_base);
774 continue;
775 }
776
777 return rom_base;
778 }
779#endif
780 return NULL;
781}
782
783
784
785
786static void radeon_get_pllinfo(struct radeonfb_info *rinfo, void __iomem *bios_seg)
787{
788 void __iomem *bios_header;
789 void __iomem *header_ptr;
790 u16 bios_header_offset, pll_info_offset;
791 PLL_BLOCK pll;
792
793 if (bios_seg) {
794 bios_header = bios_seg + 0x48L;
795 header_ptr = bios_header;
796
797 bios_header_offset = readw(header_ptr);
798 bios_header = bios_seg + bios_header_offset;
799 bios_header += 0x30;
800
801 header_ptr = bios_header;
802 pll_info_offset = readw(header_ptr);
803 header_ptr = bios_seg + pll_info_offset;
804
805 memcpy_fromio(&pll, header_ptr, 50);
806
807 rinfo->pll.xclk = (u32)pll.XCLK;
808 rinfo->pll.ref_clk = (u32)pll.PCLK_ref_freq;
809 rinfo->pll.ref_div = (u32)pll.PCLK_ref_divider;
810 rinfo->pll.ppll_min = pll.PCLK_min_freq;
811 rinfo->pll.ppll_max = pll.PCLK_max_freq;
812
813 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from BIOS\n",
814 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
815 } else {
816#ifdef CONFIG_PPC_OF
817 if (radeon_read_OF(rinfo)) {
818 unsigned int tmp, Nx, M, ref_div, xclk;
819
820 tmp = INPLL(M_SPLL_REF_FB_DIV);
821 ref_div = INPLL(PPLL_REF_DIV) & 0x3ff;
822
823 Nx = (tmp & 0xff00) >> 8;
824 M = (tmp & 0xff);
825 xclk = ((((2 * Nx * rinfo->pll.ref_clk) + (M)) /
826 (2 * M)));
827
828 rinfo->pll.xclk = xclk;
829 rinfo->pll.ref_div = ref_div;
830 rinfo->pll.ppll_min = 12000;
831 rinfo->pll.ppll_max = 35000;
832
833 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d from OF\n",
834 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
835
836 return;
837 }
838#endif
839 /* no BIOS or BIOS not found, use defaults */
840 switch (rinfo->chipset) {
841 case PCI_DEVICE_ID_ATI_RADEON_QW:
842 case PCI_DEVICE_ID_ATI_RADEON_QX:
843 rinfo->pll.ppll_max = 35000;
844 rinfo->pll.ppll_min = 12000;
845 rinfo->pll.xclk = 23000;
846 rinfo->pll.ref_div = 12;
847 rinfo->pll.ref_clk = 2700;
848 break;
849 case PCI_DEVICE_ID_ATI_RADEON_QL:
850 case PCI_DEVICE_ID_ATI_RADEON_QN:
851 case PCI_DEVICE_ID_ATI_RADEON_QO:
852 case PCI_DEVICE_ID_ATI_RADEON_Ql:
853 case PCI_DEVICE_ID_ATI_RADEON_BB:
854 rinfo->pll.ppll_max = 35000;
855 rinfo->pll.ppll_min = 12000;
856 rinfo->pll.xclk = 27500;
857 rinfo->pll.ref_div = 12;
858 rinfo->pll.ref_clk = 2700;
859 break;
860 case PCI_DEVICE_ID_ATI_RADEON_Id:
861 case PCI_DEVICE_ID_ATI_RADEON_Ie:
862 case PCI_DEVICE_ID_ATI_RADEON_If:
863 case PCI_DEVICE_ID_ATI_RADEON_Ig:
864 rinfo->pll.ppll_max = 35000;
865 rinfo->pll.ppll_min = 12000;
866 rinfo->pll.xclk = 25000;
867 rinfo->pll.ref_div = 12;
868 rinfo->pll.ref_clk = 2700;
869 break;
870 case PCI_DEVICE_ID_ATI_RADEON_ND:
871 case PCI_DEVICE_ID_ATI_RADEON_NE:
872 case PCI_DEVICE_ID_ATI_RADEON_NF:
873 case PCI_DEVICE_ID_ATI_RADEON_NG:
874 rinfo->pll.ppll_max = 40000;
875 rinfo->pll.ppll_min = 20000;
876 rinfo->pll.xclk = 27000;
877 rinfo->pll.ref_div = 12;
878 rinfo->pll.ref_clk = 2700;
879 break;
880 case PCI_DEVICE_ID_ATI_RADEON_QD:
881 case PCI_DEVICE_ID_ATI_RADEON_QE:
882 case PCI_DEVICE_ID_ATI_RADEON_QF:
883 case PCI_DEVICE_ID_ATI_RADEON_QG:
884 default:
885 rinfo->pll.ppll_max = 35000;
886 rinfo->pll.ppll_min = 12000;
887 rinfo->pll.xclk = 16600;
888 rinfo->pll.ref_div = 67;
889 rinfo->pll.ref_clk = 2700;
890 break;
891 }
892
893 printk("radeonfb: ref_clk=%d, ref_div=%d, xclk=%d defaults\n",
894 rinfo->pll.ref_clk, rinfo->pll.ref_div, rinfo->pll.xclk);
895 }
896}
897
898
899static void radeon_get_moninfo (struct radeonfb_info *rinfo)
900{
901 unsigned int tmp;
902
903 if (force_dfp) {
904 rinfo->dviDisp_type = MT_DFP;
905 return;
906 }
907
908 tmp = INREG(BIOS_4_SCRATCH);
909 printk(KERN_DEBUG "radeon_get_moninfo: bios 4 scratch = %x\n", tmp);
910
911 if (rinfo->hasCRTC2) {
912 /* primary DVI port */
913 if (tmp & 0x08)
914 rinfo->dviDisp_type = MT_DFP;
915 else if (tmp & 0x4)
916 rinfo->dviDisp_type = MT_LCD;
917 else if (tmp & 0x200)
918 rinfo->dviDisp_type = MT_CRT;
919 else if (tmp & 0x10)
920 rinfo->dviDisp_type = MT_CTV;
921 else if (tmp & 0x20)
922 rinfo->dviDisp_type = MT_STV;
923
924 /* secondary CRT port */
925 if (tmp & 0x2)
926 rinfo->crtDisp_type = MT_CRT;
927 else if (tmp & 0x800)
928 rinfo->crtDisp_type = MT_DFP;
929 else if (tmp & 0x400)
930 rinfo->crtDisp_type = MT_LCD;
931 else if (tmp & 0x1000)
932 rinfo->crtDisp_type = MT_CTV;
933 else if (tmp & 0x2000)
934 rinfo->crtDisp_type = MT_STV;
935 } else {
936 rinfo->dviDisp_type = MT_NONE;
937
938 tmp = INREG(FP_GEN_CNTL);
939
940 if (tmp & FP_EN_TMDS)
941 rinfo->crtDisp_type = MT_DFP;
942 else
943 rinfo->crtDisp_type = MT_CRT;
944 }
945}
946
947
948
949static void radeon_get_EDID(struct radeonfb_info *rinfo)
950{
951#ifdef CONFIG_PPC_OF
952 if (!radeon_get_EDID_OF(rinfo))
953 RTRACE("radeonfb: could not retrieve EDID from OF\n");
954#else
955 /* XXX use other methods later */
956#endif
957}
958
959
960#ifdef CONFIG_PPC_OF
961static int radeon_get_EDID_OF(struct radeonfb_info *rinfo)
962{
963 struct device_node *dp;
964 unsigned char *pedid = NULL;
965 static char *propnames[] = { "DFP,EDID", "LCD,EDID", "EDID", "EDID1", NULL };
966 int i;
967
968 dp = pci_device_to_OF_node(rinfo->pdev);
969 while (dp != NULL) {
970 for (i = 0; propnames[i] != NULL; ++i) {
971 pedid = (unsigned char *)
972 get_property(dp, propnames[i], NULL);
973 if (pedid != NULL) {
974 rinfo->EDID = pedid;
975 return 1;
976 }
977 }
978 dp = dp->child;
979 }
980 return 0;
981}
982#endif /* CONFIG_PPC_OF */
983
984
985static int radeon_dfp_parse_EDID(struct radeonfb_info *rinfo)
986{
987 unsigned char *block = rinfo->EDID;
988
989 if (!block)
990 return 0;
991
992 /* jump to the detailed timing block section */
993 block += 54;
994
995 rinfo->clock = (block[0] + (block[1] << 8));
996 rinfo->panel_xres = (block[2] + ((block[4] & 0xf0) << 4));
997 rinfo->hblank = (block[3] + ((block[4] & 0x0f) << 8));
998 rinfo->panel_yres = (block[5] + ((block[7] & 0xf0) << 4));
999 rinfo->vblank = (block[6] + ((block[7] & 0x0f) << 8));
1000 rinfo->hOver_plus = (block[8] + ((block[11] & 0xc0) << 2));
1001 rinfo->hSync_width = (block[9] + ((block[11] & 0x30) << 4));
1002 rinfo->vOver_plus = ((block[10] >> 4) + ((block[11] & 0x0c) << 2));
1003 rinfo->vSync_width = ((block[10] & 0x0f) + ((block[11] & 0x03) << 4));
1004 rinfo->interlaced = ((block[17] & 0x80) >> 7);
1005 rinfo->synct = ((block[17] & 0x18) >> 3);
1006 rinfo->misc = ((block[17] & 0x06) >> 1);
1007 rinfo->hAct_high = rinfo->vAct_high = 0;
1008 if (rinfo->synct == 3) {
1009 if (rinfo->misc & 2)
1010 rinfo->hAct_high = 1;
1011 if (rinfo->misc & 1)
1012 rinfo->vAct_high = 1;
1013 }
1014
1015 printk("radeonfb: detected DFP panel size from EDID: %dx%d\n",
1016 rinfo->panel_xres, rinfo->panel_yres);
1017
1018 rinfo->got_dfpinfo = 1;
1019
1020 return 1;
1021}
1022
1023
1024static void radeon_update_default_var(struct radeonfb_info *rinfo)
1025{
1026 struct fb_var_screeninfo *var = &radeonfb_default_var;
1027
1028 var->xres = rinfo->panel_xres;
1029 var->yres = rinfo->panel_yres;
1030 var->xres_virtual = rinfo->panel_xres;
1031 var->yres_virtual = rinfo->panel_yres;
1032 var->xoffset = var->yoffset = 0;
1033 var->bits_per_pixel = 8;
1034 var->pixclock = 100000000 / rinfo->clock;
1035 var->left_margin = (rinfo->hblank - rinfo->hOver_plus - rinfo->hSync_width);
1036 var->right_margin = rinfo->hOver_plus;
1037 var->upper_margin = (rinfo->vblank - rinfo->vOver_plus - rinfo->vSync_width);
1038 var->lower_margin = rinfo->vOver_plus;
1039 var->hsync_len = rinfo->hSync_width;
1040 var->vsync_len = rinfo->vSync_width;
1041 var->sync = 0;
1042 if (rinfo->synct == 3) {
1043 if (rinfo->hAct_high)
1044 var->sync |= FB_SYNC_HOR_HIGH_ACT;
1045 if (rinfo->vAct_high)
1046 var->sync |= FB_SYNC_VERT_HIGH_ACT;
1047 }
1048
1049 var->vmode = 0;
1050 if (rinfo->interlaced)
1051 var->vmode |= FB_VMODE_INTERLACED;
1052
1053 rinfo->use_default_var = 1;
1054}
1055
1056
1057static int radeon_get_dfpinfo_BIOS(struct radeonfb_info *rinfo)
1058{
1059 char __iomem *fpbiosstart, *tmp, *tmp0;
1060 char stmp[30];
1061 int i;
1062
1063 if (!rinfo->bios_seg)
1064 return 0;
1065
1066 if (!(fpbiosstart = rinfo->bios_seg + readw(rinfo->bios_seg + 0x48))) {
1067 printk("radeonfb: Failed to detect DFP panel info using BIOS\n");
1068 return 0;
1069 }
1070
1071 if (!(tmp = rinfo->bios_seg + readw(fpbiosstart + 0x40))) {
1072 printk("radeonfb: Failed to detect DFP panel info using BIOS\n");
1073 return 0;
1074 }
1075
1076 for(i=0; i<24; i++)
1077 stmp[i] = readb(tmp+i+1);
1078 stmp[24] = 0;
1079 printk("radeonfb: panel ID string: %s\n", stmp);
1080 rinfo->panel_xres = readw(tmp + 25);
1081 rinfo->panel_yres = readw(tmp + 27);
1082 printk("radeonfb: detected DFP panel size from BIOS: %dx%d\n",
1083 rinfo->panel_xres, rinfo->panel_yres);
1084
1085 for(i=0; i<32; i++) {
1086 tmp0 = rinfo->bios_seg + readw(tmp+64+i*2);
1087 if (tmp0 == 0)
1088 break;
1089 if ((readw(tmp0) == rinfo->panel_xres) &&
1090 (readw(tmp0+2) == rinfo->panel_yres)) {
1091 rinfo->hblank = (readw(tmp0+17) - readw(tmp0+19)) * 8;
1092 rinfo->hOver_plus = ((readw(tmp0+21) - readw(tmp0+19) -1) * 8) & 0x7fff;
1093 rinfo->hSync_width = readb(tmp0+23) * 8;
1094 rinfo->vblank = readw(tmp0+24) - readw(tmp0+26);
1095 rinfo->vOver_plus = (readw(tmp0+28) & 0x7ff) - readw(tmp0+26);
1096 rinfo->vSync_width = (readw(tmp0+28) & 0xf800) >> 11;
1097 rinfo->clock = readw(tmp0+9);
1098
1099 rinfo->got_dfpinfo = 1;
1100 return 1;
1101 }
1102 }
1103
1104 return 0;
1105}
1106
1107
1108
1109static int radeon_get_dfpinfo (struct radeonfb_info *rinfo)
1110{
1111 unsigned int tmp;
1112 unsigned short a, b;
1113
1114 if (radeon_get_dfpinfo_BIOS(rinfo))
1115 radeon_update_default_var(rinfo);
1116
1117 if (radeon_dfp_parse_EDID(rinfo))
1118 radeon_update_default_var(rinfo);
1119
1120 if (!rinfo->got_dfpinfo) {
1121 /*
1122 * it seems all else has failed now and we
1123 * resort to probing registers for our DFP info
1124 */
1125 if (panel_yres) {
1126 rinfo->panel_yres = panel_yres;
1127 } else {
1128 tmp = INREG(FP_VERT_STRETCH);
1129 tmp &= 0x00fff000;
1130 rinfo->panel_yres = (unsigned short)(tmp >> 0x0c) + 1;
1131 }
1132
1133 switch (rinfo->panel_yres) {
1134 case 480:
1135 rinfo->panel_xres = 640;
1136 break;
1137 case 600:
1138 rinfo->panel_xres = 800;
1139 break;
1140 case 768:
1141#if defined(__powerpc__)
1142 if (rinfo->dviDisp_type == MT_LCD)
1143 rinfo->panel_xres = 1152;
1144 else
1145#endif
1146 rinfo->panel_xres = 1024;
1147 break;
1148 case 1024:
1149 rinfo->panel_xres = 1280;
1150 break;
1151 case 1050:
1152 rinfo->panel_xres = 1400;
1153 break;
1154 case 1200:
1155 rinfo->panel_xres = 1600;
1156 break;
1157 default:
1158 printk("radeonfb: Failed to detect DFP panel size\n");
1159 return 0;
1160 }
1161
1162 printk("radeonfb: detected DFP panel size from registers: %dx%d\n",
1163 rinfo->panel_xres, rinfo->panel_yres);
1164
1165 tmp = INREG(FP_CRTC_H_TOTAL_DISP);
1166 a = (tmp & FP_CRTC_H_TOTAL_MASK) + 4;
1167 b = (tmp & 0x01ff0000) >> FP_CRTC_H_DISP_SHIFT;
1168 rinfo->hblank = (a - b + 1) * 8;
1169
1170 tmp = INREG(FP_H_SYNC_STRT_WID);
1171 rinfo->hOver_plus = (unsigned short) ((tmp & FP_H_SYNC_STRT_CHAR_MASK) >>
1172 FP_H_SYNC_STRT_CHAR_SHIFT) - b - 1;
1173 rinfo->hOver_plus *= 8;
1174 rinfo->hSync_width = (unsigned short) ((tmp & FP_H_SYNC_WID_MASK) >>
1175 FP_H_SYNC_WID_SHIFT);
1176 rinfo->hSync_width *= 8;
1177 tmp = INREG(FP_CRTC_V_TOTAL_DISP);
1178 a = (tmp & FP_CRTC_V_TOTAL_MASK) + 1;
1179 b = (tmp & FP_CRTC_V_DISP_MASK) >> FP_CRTC_V_DISP_SHIFT;
1180 rinfo->vblank = a - b /* + 24 */ ;
1181
1182 tmp = INREG(FP_V_SYNC_STRT_WID);
1183 rinfo->vOver_plus = (unsigned short) (tmp & FP_V_SYNC_STRT_MASK)
1184 - b + 1;
1185 rinfo->vSync_width = (unsigned short) ((tmp & FP_V_SYNC_WID_MASK) >>
1186 FP_V_SYNC_WID_SHIFT);
1187
1188 return 1;
1189 }
1190
1191 return 1;
1192}
1193
1194
1195#ifdef CONFIG_PPC_OF
1196static int radeon_read_OF (struct radeonfb_info *rinfo)
1197{
1198 struct device_node *dp;
1199 unsigned int *xtal;
1200
1201 dp = pci_device_to_OF_node(rinfo->pdev);
1202
1203 xtal = (unsigned int *) get_property(dp, "ATY,RefCLK", NULL);
1204
1205 rinfo->pll.ref_clk = *xtal / 10;
1206
1207 if (*xtal)
1208 return 1;
1209 else
1210 return 0;
1211}
1212#endif
1213
1214
1215static void radeon_engine_init (struct radeonfb_info *rinfo)
1216{
1217 u32 temp;
1218
1219 /* disable 3D engine */
1220 OUTREG(RB3D_CNTL, 0);
1221
1222 radeon_engine_reset ();
1223
1224 radeon_fifo_wait (1);
1225 OUTREG(RB2D_DSTCACHE_MODE, 0);
1226
1227 radeon_fifo_wait (1);
1228 temp = INREG(DEFAULT_PITCH_OFFSET);
1229 OUTREG(DEFAULT_PITCH_OFFSET, ((temp & 0xc0000000) |
1230 (rinfo->pitch << 0x16)));
1231
1232 radeon_fifo_wait (1);
1233 OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
1234
1235 radeon_fifo_wait (1);
1236 OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
1237 DEFAULT_SC_BOTTOM_MAX));
1238
1239 temp = radeon_get_dstbpp(rinfo->depth);
1240 rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
1241 radeon_fifo_wait (1);
1242 OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl |
1243 GMC_BRUSH_SOLID_COLOR |
1244 GMC_SRC_DATATYPE_COLOR));
1245
1246 radeon_fifo_wait (7);
1247
1248 /* clear line drawing regs */
1249 OUTREG(DST_LINE_START, 0);
1250 OUTREG(DST_LINE_END, 0);
1251
1252 /* set brush color regs */
1253 OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff);
1254 OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000);
1255
1256 /* set source color regs */
1257 OUTREG(DP_SRC_FRGD_CLR, 0xffffffff);
1258 OUTREG(DP_SRC_BKGD_CLR, 0x00000000);
1259
1260 /* default write mask */
1261 OUTREG(DP_WRITE_MSK, 0xffffffff);
1262
1263 radeon_engine_idle ();
1264}
1265
1266
1267static int __devinit radeon_init_disp (struct radeonfb_info *rinfo)
1268{
1269 struct fb_info *info = &rinfo->info;
1270 struct fb_var_screeninfo var;
1271
1272 var = radeonfb_default_var;
1273 if ((radeon_init_disp_var(rinfo, &var)) < 0)
1274 return -1;
1275
1276 rinfo->depth = var_to_depth(&var);
1277 rinfo->bpp = var.bits_per_pixel;
1278
1279 info->var = var;
1280 fb_alloc_cmap(&info->cmap, 256, 0);
1281
1282 var.activate = FB_ACTIVATE_NOW;
1283 return 0;
1284}
1285
1286
1287static int radeon_init_disp_var (struct radeonfb_info *rinfo,
1288 struct fb_var_screeninfo *var)
1289{
1290#ifndef MODULE
1291 if (mode_option)
1292 fb_find_mode (var, &rinfo->info, mode_option,
1293 NULL, 0, NULL, 8);
1294 else
1295#endif
1296 if (rinfo->use_default_var)
1297 /* We will use the modified default far */
1298 *var = radeonfb_default_var;
1299 else
1300
1301 fb_find_mode (var, &rinfo->info, "640x480-8@60",
1302 NULL, 0, NULL, 0);
1303
1304 if (noaccel)
1305 var->accel_flags &= ~FB_ACCELF_TEXT;
1306 else
1307 var->accel_flags |= FB_ACCELF_TEXT;
1308
1309 return 0;
1310}
1311
1312
1313static int radeon_do_maximize(struct radeonfb_info *rinfo,
1314 struct fb_var_screeninfo *var,
1315 struct fb_var_screeninfo *v,
1316 int nom, int den)
1317{
1318 static struct {
1319 int xres, yres;
1320 } modes[] = {
1321 {1600, 1280},
1322 {1280, 1024},
1323 {1024, 768},
1324 {800, 600},
1325 {640, 480},
1326 {-1, -1}
1327 };
1328 int i;
1329
1330 /* use highest possible virtual resolution */
1331 if (v->xres_virtual == -1 && v->yres_virtual == -1) {
1332 printk("radeonfb: using max available virtual resolution\n");
1333 for (i=0; modes[i].xres != -1; i++) {
1334 if (modes[i].xres * nom / den * modes[i].yres <
1335 rinfo->video_ram / 2)
1336 break;
1337 }
1338 if (modes[i].xres == -1) {
1339 printk("radeonfb: could not find virtual resolution that fits into video memory!\n");
1340 return -EINVAL;
1341 }
1342 v->xres_virtual = modes[i].xres;
1343 v->yres_virtual = modes[i].yres;
1344
1345 printk("radeonfb: virtual resolution set to max of %dx%d\n",
1346 v->xres_virtual, v->yres_virtual);
1347 } else if (v->xres_virtual == -1) {
1348 v->xres_virtual = (rinfo->video_ram * den /
1349 (nom * v->yres_virtual * 2)) & ~15;
1350 } else if (v->yres_virtual == -1) {
1351 v->xres_virtual = (v->xres_virtual + 15) & ~15;
1352 v->yres_virtual = rinfo->video_ram * den /
1353 (nom * v->xres_virtual *2);
1354 } else {
1355 if (v->xres_virtual * nom / den * v->yres_virtual >
1356 rinfo->video_ram) {
1357 return -EINVAL;
1358 }
1359 }
1360
1361 if (v->xres_virtual * nom / den >= 8192) {
1362 v->xres_virtual = 8192 * den / nom - 16;
1363 }
1364
1365 if (v->xres_virtual < v->xres)
1366 return -EINVAL;
1367
1368 if (v->yres_virtual < v->yres)
1369 return -EINVAL;
1370
1371 return 0;
1372}
1373
1374
1375static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
1376{
1377 struct radeonfb_info *rinfo = (struct radeonfb_info *) info->par;
1378 struct fb_var_screeninfo v;
1379 int nom, den;
1380
1381 memcpy (&v, var, sizeof (v));
1382
1383 switch (v.bits_per_pixel) {
1384 case 0 ... 8:
1385 v.bits_per_pixel = 8;
1386 break;
1387 case 9 ... 16:
1388 v.bits_per_pixel = 16;
1389 break;
1390 case 17 ... 24:
1391#if 0 /* Doesn't seem to work */
1392 v.bits_per_pixel = 24;
1393 break;
1394#endif
1395 return -EINVAL;
1396 case 25 ... 32:
1397 v.bits_per_pixel = 32;
1398 break;
1399 default:
1400 return -EINVAL;
1401 }
1402
1403 switch (var_to_depth(&v)) {
1404 case 8:
1405 nom = den = 1;
1406 v.red.offset = v.green.offset = v.blue.offset = 0;
1407 v.red.length = v.green.length = v.blue.length = 8;
1408 v.transp.offset = v.transp.length = 0;
1409 break;
1410 case 15:
1411 nom = 2;
1412 den = 1;
1413 v.red.offset = 10;
1414 v.green.offset = 5;
1415 v.blue.offset = 0;
1416 v.red.length = v.green.length = v.blue.length = 5;
1417 v.transp.offset = v.transp.length = 0;
1418 break;
1419 case 16:
1420 nom = 2;
1421 den = 1;
1422 v.red.offset = 11;
1423 v.green.offset = 5;
1424 v.blue.offset = 0;
1425 v.red.length = 5;
1426 v.green.length = 6;
1427 v.blue.length = 5;
1428 v.transp.offset = v.transp.length = 0;
1429 break;
1430 case 24:
1431 nom = 4;
1432 den = 1;
1433 v.red.offset = 16;
1434 v.green.offset = 8;
1435 v.blue.offset = 0;
1436 v.red.length = v.blue.length = v.green.length = 8;
1437 v.transp.offset = v.transp.length = 0;
1438 break;
1439 case 32:
1440 nom = 4;
1441 den = 1;
1442 v.red.offset = 16;
1443 v.green.offset = 8;
1444 v.blue.offset = 0;
1445 v.red.length = v.blue.length = v.green.length = 8;
1446 v.transp.offset = 24;
1447 v.transp.length = 8;
1448 break;
1449 default:
1450 printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n",
1451 var->xres, var->yres, var->bits_per_pixel);
1452 return -EINVAL;
1453 }
1454
1455 if (radeon_do_maximize(rinfo, var, &v, nom, den) < 0)
1456 return -EINVAL;
1457
1458 if (v.xoffset < 0)
1459 v.xoffset = 0;
1460 if (v.yoffset < 0)
1461 v.yoffset = 0;
1462
1463 if (v.xoffset > v.xres_virtual - v.xres)
1464 v.xoffset = v.xres_virtual - v.xres - 1;
1465
1466 if (v.yoffset > v.yres_virtual - v.yres)
1467 v.yoffset = v.yres_virtual - v.yres - 1;
1468
1469 v.red.msb_right = v.green.msb_right = v.blue.msb_right =
1470 v.transp.offset = v.transp.length =
1471 v.transp.msb_right = 0;
1472
1473 if (noaccel)
1474 v.accel_flags = 0;
1475
1476 memcpy(var, &v, sizeof(v));
1477
1478 return 0;
1479}
1480
1481
1482static int radeonfb_pan_display (struct fb_var_screeninfo *var,
1483 struct fb_info *info)
1484{
1485 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1486
1487 if ((var->xoffset + var->xres > var->xres_virtual)
1488 || (var->yoffset + var->yres > var->yres_virtual))
1489 return -EINVAL;
1490
1491 if (rinfo->asleep)
1492 return 0;
1493
1494 OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
1495 * var->bits_per_pixel / 8) & ~7);
1496 return 0;
1497}
1498
1499
1500static int radeonfb_ioctl (struct fb_info *info, unsigned int cmd,
1501 unsigned long arg)
1502{
1503 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1504 unsigned int tmp;
1505 u32 value = 0;
1506 int rc;
1507
1508 switch (cmd) {
1509 /*
1510 * TODO: set mirror accordingly for non-Mobility chipsets with 2 CRTC's
1511 */
1512 case FBIO_RADEON_SET_MIRROR:
1513 switch (rinfo->arch) {
1514 case RADEON_R100:
1515 case RADEON_RV100:
1516 case RADEON_R200:
1517 case RADEON_RV200:
1518 case RADEON_RV250:
1519 case RADEON_R300:
1520 return -EINVAL;
1521 default:
1522 /* RADEON M6, RADEON_M7, RADEON_M9 */
1523 break;
1524 }
1525
1526 rc = get_user(value, (__u32 __user *)arg);
1527
1528 if (rc)
1529 return rc;
1530
1531 if (value & 0x01) {
1532 tmp = INREG(LVDS_GEN_CNTL);
1533
1534 tmp |= (LVDS_ON | LVDS_BLON);
1535 } else {
1536 tmp = INREG(LVDS_GEN_CNTL);
1537
1538 tmp &= ~(LVDS_ON | LVDS_BLON);
1539 }
1540
1541 OUTREG(LVDS_GEN_CNTL, tmp);
1542
1543 if (value & 0x02) {
1544 tmp = INREG(CRTC_EXT_CNTL);
1545 tmp |= CRTC_CRT_ON;
1546
1547 mirror = 1;
1548 } else {
1549 tmp = INREG(CRTC_EXT_CNTL);
1550 tmp &= ~CRTC_CRT_ON;
1551
1552 mirror = 0;
1553 }
1554
1555 OUTREG(CRTC_EXT_CNTL, tmp);
1556
1557 break;
1558 case FBIO_RADEON_GET_MIRROR:
1559 switch (rinfo->arch) {
1560 case RADEON_R100:
1561 case RADEON_RV100:
1562 case RADEON_R200:
1563 case RADEON_RV200:
1564 case RADEON_RV250:
1565 case RADEON_R300:
1566 return -EINVAL;
1567 default:
1568 /* RADEON M6, RADEON_M7, RADEON_M9 */
1569 break;
1570 }
1571
1572 tmp = INREG(LVDS_GEN_CNTL);
1573 if ((LVDS_ON | LVDS_BLON) & tmp)
1574 value |= 0x01;
1575
1576 tmp = INREG(CRTC_EXT_CNTL);
1577 if (CRTC_CRT_ON & tmp)
1578 value |= 0x02;
1579
1580 return put_user(value, (__u32 __user *)arg);
1581 default:
1582 return -EINVAL;
1583 }
1584
1585 return -EINVAL;
1586}
1587
1588
1589static int radeonfb_blank (int blank, struct fb_info *info)
1590{
1591 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1592 u32 val = INREG(CRTC_EXT_CNTL);
1593 u32 val2 = INREG(LVDS_GEN_CNTL);
1594
1595 if (rinfo->asleep)
1596 return 0;
1597
1598#ifdef CONFIG_PMAC_BACKLIGHT
1599 if (rinfo->dviDisp_type == MT_LCD && _machine == _MACH_Pmac) {
1600 set_backlight_enable(!blank);
1601 return 0;
1602 }
1603#endif
1604
1605 /* reset it */
1606 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
1607 CRTC_VSYNC_DIS);
1608 val2 &= ~(LVDS_DISPLAY_DIS);
1609
1610 switch (blank) {
1611 case FB_BLANK_UNBLANK:
1612 case FB_BLANK_NORMAL:
1613 break;
1614 case FB_BLANK_VSYNC_SUSPEND:
1615 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS);
1616 break;
1617 case FB_BLANK_HSYNC_SUSPEND:
1618 val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS);
1619 break;
1620 case FB_BLANK_POWERDOWN:
1621 val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS |
1622 CRTC_HSYNC_DIS);
1623 val2 |= (LVDS_DISPLAY_DIS);
1624 break;
1625 }
1626
1627 switch (rinfo->dviDisp_type) {
1628 case MT_LCD:
1629 OUTREG(LVDS_GEN_CNTL, val2);
1630 break;
1631 case MT_CRT:
1632 default:
1633 OUTREG(CRTC_EXT_CNTL, val);
1634 break;
1635 }
1636
1637 /* let fbcon do a soft blank for us */
1638 return (blank == FB_BLANK_NORMAL) ? 1 : 0;
1639}
1640
1641
1642static int radeonfb_setcolreg (unsigned regno, unsigned red, unsigned green,
1643 unsigned blue, unsigned transp, struct fb_info *info)
1644{
1645 struct radeonfb_info *rinfo = (struct radeonfb_info *) info;
1646 u32 pindex, vclk_cntl;
1647 unsigned int i;
1648
1649 if (regno > 255)
1650 return 1;
1651
1652 red >>= 8;
1653 green >>= 8;
1654 blue >>= 8;
1655 rinfo->palette[regno].red = red;
1656 rinfo->palette[regno].green = green;
1657 rinfo->palette[regno].blue = blue;
1658
1659 /* default */
1660 pindex = regno;
1661
1662 if (!rinfo->asleep) {
1663 vclk_cntl = INPLL(VCLK_ECP_CNTL);
1664 OUTPLL(VCLK_ECP_CNTL, vclk_cntl & ~PIXCLK_DAC_ALWAYS_ONb);
1665
1666 if (rinfo->bpp == 16) {
1667 pindex = regno * 8;
1668
1669 if (rinfo->depth == 16 && regno > 63)
1670 return 1;
1671 if (rinfo->depth == 15 && regno > 31)
1672 return 1;
1673
1674 /* For 565, the green component is mixed one order below */
1675 if (rinfo->depth == 16) {
1676 OUTREG(PALETTE_INDEX, pindex>>1);
1677 OUTREG(PALETTE_DATA, (rinfo->palette[regno>>1].red << 16) |
1678 (green << 8) | (rinfo->palette[regno>>1].blue));
1679 green = rinfo->palette[regno<<1].green;
1680 }
1681 }
1682
1683 if (rinfo->depth != 16 || regno < 32) {
1684 OUTREG(PALETTE_INDEX, pindex);
1685 OUTREG(PALETTE_DATA, (red << 16) | (green << 8) | blue);
1686 }
1687
1688 OUTPLL(VCLK_ECP_CNTL, vclk_cntl);
1689 }
1690 if (regno < 16) {
1691 switch (rinfo->depth) {
1692 case 15:
1693 ((u16 *) (info->pseudo_palette))[regno] =
1694 (regno << 10) | (regno << 5) | regno;
1695 break;
1696 case 16:
1697 ((u16 *) (info->pseudo_palette))[regno] =
1698 (regno << 11) | (regno << 6) | regno;
1699 break;
1700 case 24:
1701 ((u32 *) (info->pseudo_palette))[regno] =
1702 (regno << 16) | (regno << 8) | regno;
1703 break;
1704 case 32:
1705 i = (regno << 8) | regno;
1706 ((u32 *) (info->pseudo_palette))[regno] =
1707 (i << 16) | i;
1708 break;
1709 }
1710 }
1711 return 0;
1712}
1713
1714
1715
1716static void radeon_save_state (struct radeonfb_info *rinfo,
1717 struct radeon_regs *save)
1718{
1719 /* CRTC regs */
1720 save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL);
1721 save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL);
1722 save->dac_cntl = INREG(DAC_CNTL);
1723 save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP);
1724 save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID);
1725 save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP);
1726 save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID);
1727 save->crtc_pitch = INREG(CRTC_PITCH);
1728#if defined(__BIG_ENDIAN)
1729 save->surface_cntl = INREG(SURFACE_CNTL);
1730#endif
1731
1732 /* FP regs */
1733 save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP);
1734 save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP);
1735 save->fp_gen_cntl = INREG(FP_GEN_CNTL);
1736 save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID);
1737 save->fp_horz_stretch = INREG(FP_HORZ_STRETCH);
1738 save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID);
1739 save->fp_vert_stretch = INREG(FP_VERT_STRETCH);
1740 save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
1741 save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL);
1742 save->tmds_crc = INREG(TMDS_CRC);
1743 save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);
1744 save->vclk_ecp_cntl = INPLL(VCLK_ECP_CNTL);
1745}
1746
1747
1748
1749static int radeonfb_set_par (struct fb_info *info)
1750{
1751 struct radeonfb_info *rinfo = (struct radeonfb_info *)info->par;
1752 struct fb_var_screeninfo *mode = &info->var;
1753 struct radeon_regs newmode;
1754 int hTotal, vTotal, hSyncStart, hSyncEnd,
1755 hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync;
1756 u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5};
1757 u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5};
1758 u32 dotClock = 1000000000 / mode->pixclock,
1759 sync, h_sync_pol, v_sync_pol;
1760 int freq = dotClock / 10; /* x 100 */
1761 int xclk_freq, vclk_freq, xclk_per_trans, xclk_per_trans_precise;
1762 int useable_precision, roff, ron;
1763 int min_bits, format = 0;
1764 int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid;
1765 int primary_mon = PRIMARY_MONITOR(rinfo);
1766 int depth = var_to_depth(mode);
1767 int accel = (mode->accel_flags & FB_ACCELF_TEXT) != 0;
1768
1769 rinfo->xres = mode->xres;
1770 rinfo->yres = mode->yres;
1771 rinfo->xres_virtual = mode->xres_virtual;
1772 rinfo->yres_virtual = mode->yres_virtual;
1773 rinfo->pixclock = mode->pixclock;
1774
1775 hSyncStart = mode->xres + mode->right_margin;
1776 hSyncEnd = hSyncStart + mode->hsync_len;
1777 hTotal = hSyncEnd + mode->left_margin;
1778
1779 vSyncStart = mode->yres + mode->lower_margin;
1780 vSyncEnd = vSyncStart + mode->vsync_len;
1781 vTotal = vSyncEnd + mode->upper_margin;
1782
1783 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1784 if (rinfo->panel_xres < mode->xres)
1785 rinfo->xres = mode->xres = rinfo->panel_xres;
1786 if (rinfo->panel_yres < mode->yres)
1787 rinfo->yres = mode->yres = rinfo->panel_yres;
1788
1789 hTotal = mode->xres + rinfo->hblank;
1790 hSyncStart = mode->xres + rinfo->hOver_plus;
1791 hSyncEnd = hSyncStart + rinfo->hSync_width;
1792
1793 vTotal = mode->yres + rinfo->vblank;
1794 vSyncStart = mode->yres + rinfo->vOver_plus;
1795 vSyncEnd = vSyncStart + rinfo->vSync_width;
1796 }
1797
1798 sync = mode->sync;
1799 h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1800 v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1801
1802 RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n",
1803 hSyncStart, hSyncEnd, hTotal);
1804 RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n",
1805 vSyncStart, vSyncEnd, vTotal);
1806
1807 hsync_wid = (hSyncEnd - hSyncStart) / 8;
1808 vsync_wid = vSyncEnd - vSyncStart;
1809 if (hsync_wid == 0)
1810 hsync_wid = 1;
1811 else if (hsync_wid > 0x3f) /* max */
1812 hsync_wid = 0x3f;
1813
1814 if (vsync_wid == 0)
1815 vsync_wid = 1;
1816 else if (vsync_wid > 0x1f) /* max */
1817 vsync_wid = 0x1f;
1818
1819 hSyncPol = mode->sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1;
1820 vSyncPol = mode->sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1;
1821
1822 cSync = mode->sync & FB_SYNC_COMP_HIGH_ACT ? (1 << 4) : 0;
1823
1824 format = radeon_get_dstbpp(depth);
1825 bytpp = mode->bits_per_pixel >> 3;
1826
1827 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD))
1828 hsync_fudge = hsync_fudge_fp[format-1];
1829 else
1830 hsync_fudge = hsync_adj_tab[format-1];
1831
1832 hsync_start = hSyncStart - 8 + hsync_fudge;
1833
1834 newmode.crtc_gen_cntl = CRTC_EXT_DISP_EN | CRTC_EN |
1835 (format << 8);
1836
1837 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1838 newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN;
1839 if (mirror)
1840 newmode.crtc_ext_cntl |= CRTC_CRT_ON;
1841
1842 newmode.crtc_gen_cntl &= ~(CRTC_DBL_SCAN_EN |
1843 CRTC_INTERLACE_EN);
1844 } else {
1845 newmode.crtc_ext_cntl = VGA_ATI_LINEAR | XCRT_CNT_EN |
1846 CRTC_CRT_ON;
1847 }
1848
1849 newmode.dac_cntl = /* INREG(DAC_CNTL) | */ DAC_MASK_ALL | DAC_VGA_ADR_EN |
1850 DAC_8BIT_EN;
1851
1852 newmode.crtc_h_total_disp = ((((hTotal / 8) - 1) & 0x3ff) |
1853 (((mode->xres / 8) - 1) << 16));
1854
1855 newmode.crtc_h_sync_strt_wid = ((hsync_start & 0x1fff) |
1856 (hsync_wid << 16) | (h_sync_pol << 23));
1857
1858 newmode.crtc_v_total_disp = ((vTotal - 1) & 0xffff) |
1859 ((mode->yres - 1) << 16);
1860
1861 newmode.crtc_v_sync_strt_wid = (((vSyncStart - 1) & 0xfff) |
1862 (vsync_wid << 16) | (v_sync_pol << 23));
1863
1864 if (accel) {
1865 /* We first calculate the engine pitch */
1866 rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
1867 & ~(0x3f)) >> 6;
1868
1869 /* Then, re-multiply it to get the CRTC pitch */
1870 newmode.crtc_pitch = (rinfo->pitch << 3) / ((mode->bits_per_pixel + 1) / 8);
1871 } else
1872 newmode.crtc_pitch = (mode->xres_virtual >> 3);
1873 newmode.crtc_pitch |= (newmode.crtc_pitch << 16);
1874
1875#if defined(__BIG_ENDIAN)
1876 /*
1877 * It looks like recent chips have a problem with SURFACE_CNTL,
1878 * setting SURF_TRANSLATION_DIS completely disables the
1879 * swapper as well, so we leave it unset now.
1880 */
1881 newmode.surface_cntl = 0;
1882
1883 /* Setup swapping on both apertures, though we currently
1884 * only use aperture 0, enabling swapper on aperture 1
1885 * won't harm
1886 */
1887 switch (mode->bits_per_pixel) {
1888 case 16:
1889 newmode.surface_cntl |= NONSURF_AP0_SWP_16BPP;
1890 newmode.surface_cntl |= NONSURF_AP1_SWP_16BPP;
1891 break;
1892 case 24:
1893 case 32:
1894 newmode.surface_cntl |= NONSURF_AP0_SWP_32BPP;
1895 newmode.surface_cntl |= NONSURF_AP1_SWP_32BPP;
1896 break;
1897 }
1898#endif
1899
1900 rinfo->pitch = ((mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8) + 0x3f)
1901 & ~(0x3f)) / 64;
1902
1903 RTRACE("h_total_disp = 0x%x\t hsync_strt_wid = 0x%x\n",
1904 newmode.crtc_h_total_disp, newmode.crtc_h_sync_strt_wid);
1905 RTRACE("v_total_disp = 0x%x\t vsync_strt_wid = 0x%x\n",
1906 newmode.crtc_v_total_disp, newmode.crtc_v_sync_strt_wid);
1907
1908 newmode.xres = mode->xres;
1909 newmode.yres = mode->yres;
1910
1911 rinfo->bpp = mode->bits_per_pixel;
1912 rinfo->depth = depth;
1913
1914 if (freq > rinfo->pll.ppll_max)
1915 freq = rinfo->pll.ppll_max;
1916 if (freq*12 < rinfo->pll.ppll_min)
1917 freq = rinfo->pll.ppll_min / 12;
1918
1919 {
1920 struct {
1921 int divider;
1922 int bitvalue;
1923 } *post_div,
1924 post_divs[] = {
1925 { 1, 0 },
1926 { 2, 1 },
1927 { 4, 2 },
1928 { 8, 3 },
1929 { 3, 4 },
1930 { 16, 5 },
1931 { 6, 6 },
1932 { 12, 7 },
1933 { 0, 0 },
1934 };
1935
1936 for (post_div = &post_divs[0]; post_div->divider; ++post_div) {
1937 rinfo->pll_output_freq = post_div->divider * freq;
1938 if (rinfo->pll_output_freq >= rinfo->pll.ppll_min &&
1939 rinfo->pll_output_freq <= rinfo->pll.ppll_max)
1940 break;
1941 }
1942
1943 rinfo->post_div = post_div->divider;
1944 rinfo->fb_div = round_div(rinfo->pll.ref_div*rinfo->pll_output_freq,
1945 rinfo->pll.ref_clk);
1946 newmode.ppll_ref_div = rinfo->pll.ref_div;
1947 newmode.ppll_div_3 = rinfo->fb_div | (post_div->bitvalue << 16);
1948 }
1949 newmode.vclk_ecp_cntl = rinfo->init_state.vclk_ecp_cntl;
1950
1951#ifdef CONFIG_PPC_OF
1952 /* Gross hack for iBook with M7 until I find out a proper fix */
1953 if (machine_is_compatible("PowerBook4,3") && rinfo->arch == RADEON_M7)
1954 newmode.ppll_div_3 = 0x000600ad;
1955#endif /* CONFIG_PPC_OF */
1956
1957 RTRACE("post div = 0x%x\n", rinfo->post_div);
1958 RTRACE("fb_div = 0x%x\n", rinfo->fb_div);
1959 RTRACE("ppll_div_3 = 0x%x\n", newmode.ppll_div_3);
1960
1961 /* DDA */
1962 vclk_freq = round_div(rinfo->pll.ref_clk * rinfo->fb_div,
1963 rinfo->pll.ref_div * rinfo->post_div);
1964 xclk_freq = rinfo->pll.xclk;
1965
1966 xclk_per_trans = round_div(xclk_freq * 128, vclk_freq * mode->bits_per_pixel);
1967
1968 min_bits = min_bits_req(xclk_per_trans);
1969 useable_precision = min_bits + 1;
1970
1971 xclk_per_trans_precise = round_div((xclk_freq * 128) << (11 - useable_precision),
1972 vclk_freq * mode->bits_per_pixel);
1973
1974 ron = (4 * rinfo->ram.mb + 3 * _max(rinfo->ram.trcd - 2, 0) +
1975 2 * rinfo->ram.trp + rinfo->ram.twr + rinfo->ram.cl + rinfo->ram.tr2w +
1976 xclk_per_trans) << (11 - useable_precision);
1977 roff = xclk_per_trans_precise * (32 - 4);
1978
1979 RTRACE("ron = %d, roff = %d\n", ron, roff);
1980 RTRACE("vclk_freq = %d, per = %d\n", vclk_freq, xclk_per_trans_precise);
1981
1982 if ((ron + rinfo->ram.rloop) >= roff) {
1983 printk("radeonfb: error ron out of range\n");
1984 return -EINVAL;
1985 }
1986
1987 newmode.dda_config = (xclk_per_trans_precise |
1988 (useable_precision << 16) |
1989 (rinfo->ram.rloop << 20));
1990 newmode.dda_on_off = (ron << 16) | roff;
1991
1992 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1993 unsigned int hRatio, vRatio;
1994
1995 /* We force the pixel clock to be always enabled. Allowing it
1996 * to be power managed during blanking would save power, but has
1997 * nasty interactions with the 2D engine & sleep code that haven't
1998 * been solved yet. --BenH
1999 */
2000 newmode.vclk_ecp_cntl &= ~PIXCLK_DAC_ALWAYS_ONb;
2001
2002 if (mode->xres > rinfo->panel_xres)
2003 mode->xres = rinfo->panel_xres;
2004 if (mode->yres > rinfo->panel_yres)
2005 mode->yres = rinfo->panel_yres;
2006
2007 newmode.fp_horz_stretch = (((rinfo->panel_xres / 8) - 1)
2008 << HORZ_PANEL_SHIFT);
2009 newmode.fp_vert_stretch = ((rinfo->panel_yres - 1)
2010 << VERT_PANEL_SHIFT);
2011
2012 if (mode->xres != rinfo->panel_xres) {
2013 hRatio = round_div(mode->xres * HORZ_STRETCH_RATIO_MAX,
2014 rinfo->panel_xres);
2015 newmode.fp_horz_stretch = (((((unsigned long)hRatio) & HORZ_STRETCH_RATIO_MASK)) |
2016 (newmode.fp_horz_stretch &
2017 (HORZ_PANEL_SIZE | HORZ_FP_LOOP_STRETCH |
2018 HORZ_AUTO_RATIO_INC)));
2019 newmode.fp_horz_stretch |= (HORZ_STRETCH_BLEND |
2020 HORZ_STRETCH_ENABLE);
2021 }
2022 newmode.fp_horz_stretch &= ~HORZ_AUTO_RATIO;
2023
2024 if (mode->yres != rinfo->panel_yres) {
2025 vRatio = round_div(mode->yres * VERT_STRETCH_RATIO_MAX,
2026 rinfo->panel_yres);
2027 newmode.fp_vert_stretch = (((((unsigned long)vRatio) & VERT_STRETCH_RATIO_MASK)) |
2028 (newmode.fp_vert_stretch &
2029 (VERT_PANEL_SIZE | VERT_STRETCH_RESERVED)));
2030 newmode.fp_vert_stretch |= (VERT_STRETCH_BLEND |
2031 VERT_STRETCH_ENABLE);
2032 }
2033 newmode.fp_vert_stretch &= ~VERT_AUTO_RATIO_EN;
2034
2035 newmode.fp_gen_cntl = (rinfo->init_state.fp_gen_cntl & (u32)
2036 ~(FP_SEL_CRTC2 |
2037 FP_RMX_HVSYNC_CONTROL_EN |
2038 FP_DFP_SYNC_SEL |
2039 FP_CRT_SYNC_SEL |
2040 FP_CRTC_LOCK_8DOT |
2041 FP_USE_SHADOW_EN |
2042 FP_CRTC_USE_SHADOW_VEND |
2043 FP_CRT_SYNC_ALT));
2044
2045 newmode.fp_gen_cntl |= (FP_CRTC_DONT_SHADOW_VPAR |
2046 FP_CRTC_DONT_SHADOW_HEND);
2047
2048 newmode.lvds_gen_cntl = rinfo->init_state.lvds_gen_cntl;
2049 newmode.lvds_pll_cntl = rinfo->init_state.lvds_pll_cntl;
2050 newmode.tmds_crc = rinfo->init_state.tmds_crc;
2051 newmode.tmds_transmitter_cntl = rinfo->init_state.tmds_transmitter_cntl;
2052
2053 if (primary_mon == MT_LCD) {
2054 newmode.lvds_gen_cntl |= (LVDS_ON | LVDS_BLON);
2055 newmode.fp_gen_cntl &= ~(FP_FPON | FP_TMDS_EN);
2056 } else {
2057 /* DFP */
2058 newmode.fp_gen_cntl |= (FP_FPON | FP_TMDS_EN);
2059 newmode.tmds_transmitter_cntl = (TMDS_RAN_PAT_RST |
2060 TMDS_ICHCSEL | TMDS_PLL_EN) &
2061 ~(TMDS_PLLRST);
2062 newmode.crtc_ext_cntl &= ~CRTC_CRT_ON;
2063 }
2064
2065 newmode.fp_crtc_h_total_disp = (((rinfo->hblank / 8) & 0x3ff) |
2066 (((mode->xres / 8) - 1) << 16));
2067 newmode.fp_crtc_v_total_disp = (rinfo->vblank & 0xffff) |
2068 ((mode->yres - 1) << 16);
2069 newmode.fp_h_sync_strt_wid = ((rinfo->hOver_plus & 0x1fff) |
2070 (hsync_wid << 16) | (h_sync_pol << 23));
2071 newmode.fp_v_sync_strt_wid = ((rinfo->vOver_plus & 0xfff) |
2072 (vsync_wid << 16) | (v_sync_pol << 23));
2073 }
2074
2075 /* do it! */
2076 if (!rinfo->asleep) {
2077 radeon_write_mode (rinfo, &newmode);
2078 /* (re)initialize the engine */
2079 if (noaccel)
2080 radeon_engine_init (rinfo);
2081
2082 }
2083 /* Update fix */
2084 if (accel)
2085 info->fix.line_length = rinfo->pitch*64;
2086 else
2087 info->fix.line_length = mode->xres_virtual * ((mode->bits_per_pixel + 1) / 8);
2088 info->fix.visual = rinfo->depth == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
2089
2090#ifdef CONFIG_BOOTX_TEXT
2091 /* Update debug text engine */
2092 btext_update_display(rinfo->fb_base_phys, mode->xres, mode->yres,
2093 rinfo->depth, info->fix.line_length);
2094#endif
2095
2096 return 0;
2097}
2098
2099
2100static void radeon_write_mode (struct radeonfb_info *rinfo,
2101 struct radeon_regs *mode)
2102{
2103 int i;
2104 int primary_mon = PRIMARY_MONITOR(rinfo);
2105
2106 radeonfb_blank(VESA_POWERDOWN, (struct fb_info *)rinfo);
2107
2108
2109 if (rinfo->arch == RADEON_M6) {
2110 for (i=0; i<7; i++)
2111 OUTREG(common_regs_m6[i].reg, common_regs_m6[i].val);
2112 } else {
2113 for (i=0; i<9; i++)
2114 OUTREG(common_regs[i].reg, common_regs[i].val);
2115 }
2116
2117 OUTREG(CRTC_GEN_CNTL, mode->crtc_gen_cntl);
2118 OUTREGP(CRTC_EXT_CNTL, mode->crtc_ext_cntl,
2119 CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS);
2120 OUTREGP(DAC_CNTL, mode->dac_cntl, DAC_RANGE_CNTL | DAC_BLANKING);
2121 OUTREG(CRTC_H_TOTAL_DISP, mode->crtc_h_total_disp);
2122 OUTREG(CRTC_H_SYNC_STRT_WID, mode->crtc_h_sync_strt_wid);
2123 OUTREG(CRTC_V_TOTAL_DISP, mode->crtc_v_total_disp);
2124 OUTREG(CRTC_V_SYNC_STRT_WID, mode->crtc_v_sync_strt_wid);
2125 OUTREG(CRTC_OFFSET, 0);
2126 OUTREG(CRTC_OFFSET_CNTL, 0);
2127 OUTREG(CRTC_PITCH, mode->crtc_pitch);
2128
2129#if defined(__BIG_ENDIAN)
2130 OUTREG(SURFACE_CNTL, mode->surface_cntl);
2131#endif
2132
2133 while ((INREG(CLOCK_CNTL_INDEX) & PPLL_DIV_SEL_MASK) !=
2134 PPLL_DIV_SEL_MASK) {
2135 OUTREGP(CLOCK_CNTL_INDEX, PPLL_DIV_SEL_MASK, 0xffff);
2136 }
2137
2138 OUTPLLP(PPLL_CNTL, PPLL_RESET, 0xffff);
2139
2140 while ((INPLL(PPLL_REF_DIV) & PPLL_REF_DIV_MASK) !=
2141 (mode->ppll_ref_div & PPLL_REF_DIV_MASK)) {
2142 OUTPLLP(PPLL_REF_DIV, mode->ppll_ref_div, ~PPLL_REF_DIV_MASK);
2143 }
2144
2145 while ((INPLL(PPLL_DIV_3) & PPLL_FB3_DIV_MASK) !=
2146 (mode->ppll_div_3 & PPLL_FB3_DIV_MASK)) {
2147 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_FB3_DIV_MASK);
2148 }
2149
2150 while ((INPLL(PPLL_DIV_3) & PPLL_POST3_DIV_MASK) !=
2151 (mode->ppll_div_3 & PPLL_POST3_DIV_MASK)) {
2152 OUTPLLP(PPLL_DIV_3, mode->ppll_div_3, ~PPLL_POST3_DIV_MASK);
2153 }
2154
2155 OUTPLL(HTOTAL_CNTL, 0);
2156
2157 OUTPLLP(PPLL_CNTL, 0, ~PPLL_RESET);
2158
2159// OUTREG(DDA_CONFIG, mode->dda_config);
2160// OUTREG(DDA_ON_OFF, mode->dda_on_off);
2161
2162 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
2163 OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
2164 OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
2165 OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
2166 OUTREG(FP_V_SYNC_STRT_WID, mode->fp_v_sync_strt_wid);
2167 OUTREG(FP_HORZ_STRETCH, mode->fp_horz_stretch);
2168 OUTREG(FP_VERT_STRETCH, mode->fp_vert_stretch);
2169 OUTREG(FP_GEN_CNTL, mode->fp_gen_cntl);
2170 OUTREG(TMDS_CRC, mode->tmds_crc);
2171 OUTREG(TMDS_TRANSMITTER_CNTL, mode->tmds_transmitter_cntl);
2172
2173 if (primary_mon == MT_LCD) {
2174 unsigned int tmp = INREG(LVDS_GEN_CNTL);
2175
2176 mode->lvds_gen_cntl &= ~LVDS_STATE_MASK;
2177 mode->lvds_gen_cntl |= (rinfo->init_state.lvds_gen_cntl & LVDS_STATE_MASK);
2178
2179 if ((tmp & (LVDS_ON | LVDS_BLON)) ==
2180 (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON))) {
2181 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
2182 } else {
2183 if (mode->lvds_gen_cntl & (LVDS_ON | LVDS_BLON)) {
2184 udelay(1000);
2185 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
2186 } else {
2187 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl |
2188 LVDS_BLON);
2189 udelay(1000);
2190 OUTREG(LVDS_GEN_CNTL, mode->lvds_gen_cntl);
2191 }
2192 }
2193 }
2194 }
2195
2196 radeonfb_blank(VESA_NO_BLANKING, (struct fb_info *)rinfo);
2197
2198 OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
2199
2200 return;
2201}
2202
2203static struct fb_ops radeonfb_ops = {
2204 .owner = THIS_MODULE,
2205 .fb_check_var = radeonfb_check_var,
2206 .fb_set_par = radeonfb_set_par,
2207 .fb_setcolreg = radeonfb_setcolreg,
2208 .fb_pan_display = radeonfb_pan_display,
2209 .fb_blank = radeonfb_blank,
2210 .fb_ioctl = radeonfb_ioctl,
2211#if 0
2212 .fb_fillrect = radeonfb_fillrect,
2213 .fb_copyarea = radeonfb_copyarea,
2214 .fb_imageblit = radeonfb_imageblit,
2215 .fb_rasterimg = radeonfb_rasterimg,
2216#else
2217 .fb_fillrect = cfb_fillrect,
2218 .fb_copyarea = cfb_copyarea,
2219 .fb_imageblit = cfb_imageblit,
2220#endif
2221};
2222
2223
2224static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
2225{
2226 struct fb_info *info;
2227
2228 info = &rinfo->info;
2229
2230 info->par = rinfo;
2231 info->pseudo_palette = rinfo->pseudo_palette;
2232 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2233 info->fbops = &radeonfb_ops;
2234 info->screen_base = rinfo->fb_base;
2235
2236 /* Fill fix common fields */
2237 strlcpy(info->fix.id, rinfo->name, sizeof(info->fix.id));
2238 info->fix.smem_start = rinfo->fb_base_phys;
2239 info->fix.smem_len = rinfo->video_ram;
2240 info->fix.type = FB_TYPE_PACKED_PIXELS;
2241 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
2242 info->fix.xpanstep = 8;
2243 info->fix.ypanstep = 1;
2244 info->fix.ywrapstep = 0;
2245 info->fix.type_aux = 0;
2246 info->fix.mmio_start = rinfo->mmio_base_phys;
2247 info->fix.mmio_len = RADEON_REGSIZE;
2248 if (noaccel)
2249 info->fix.accel = FB_ACCEL_NONE;
2250 else
2251 info->fix.accel = FB_ACCEL_ATI_RADEON;
2252
2253 if (radeon_init_disp (rinfo) < 0)
2254 return -1;
2255
2256 return 0;
2257}
2258
2259
2260#ifdef CONFIG_PMAC_BACKLIGHT
2261
2262/* TODO: Dbl check these tables, we don't go up to full ON backlight
2263 * in these, possibly because we noticed MacOS doesn't, but I'd prefer
2264 * having some more official numbers from ATI
2265 */
2266static int backlight_conv_m6[] = {
2267 0xff, 0xc0, 0xb5, 0xaa, 0x9f, 0x94, 0x89, 0x7e,
2268 0x73, 0x68, 0x5d, 0x52, 0x47, 0x3c, 0x31, 0x24
2269};
2270static int backlight_conv_m7[] = {
2271 0x00, 0x3f, 0x4a, 0x55, 0x60, 0x6b, 0x76, 0x81,
2272 0x8c, 0x97, 0xa2, 0xad, 0xb8, 0xc3, 0xce, 0xd9
2273};
2274
2275#define BACKLIGHT_LVDS_OFF
2276#undef BACKLIGHT_DAC_OFF
2277
2278/* We turn off the LCD completely instead of just dimming the backlight.
2279 * This provides some greater power saving and the display is useless
2280 * without backlight anyway.
2281 */
2282
2283static int radeon_set_backlight_enable(int on, int level, void *data)
2284{
2285 struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
2286 unsigned int lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
2287 int* conv_table;
2288
2289 /* Pardon me for that hack... maybe some day we can figure
2290 * out in what direction backlight should work on a given
2291 * panel ?
2292 */
2293 if ((rinfo->arch == RADEON_M7 || rinfo->arch == RADEON_M9)
2294 && !machine_is_compatible("PowerBook4,3"))
2295 conv_table = backlight_conv_m7;
2296 else
2297 conv_table = backlight_conv_m6;
2298
2299 lvds_gen_cntl |= (LVDS_BL_MOD_EN | LVDS_BLON);
2300 if (on && (level > BACKLIGHT_OFF)) {
2301 lvds_gen_cntl |= LVDS_DIGON;
2302 if (!(lvds_gen_cntl & LVDS_ON)) {
2303 lvds_gen_cntl &= ~LVDS_BLON;
2304 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2305 (void)INREG(LVDS_GEN_CNTL);
2306 mdelay(10);
2307 lvds_gen_cntl |= LVDS_BLON;
2308 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2309 }
2310 lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK;
2311 lvds_gen_cntl |= (conv_table[level] <<
2312 LVDS_BL_MOD_LEVEL_SHIFT);
2313 lvds_gen_cntl |= (LVDS_ON | LVDS_EN);
2314 lvds_gen_cntl &= ~LVDS_DISPLAY_DIS;
2315 } else {
2316 lvds_gen_cntl &= ~LVDS_BL_MOD_LEVEL_MASK;
2317 lvds_gen_cntl |= (conv_table[0] <<
2318 LVDS_BL_MOD_LEVEL_SHIFT);
2319 lvds_gen_cntl |= LVDS_DISPLAY_DIS;
2320 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2321 udelay(10);
2322 lvds_gen_cntl &= ~(LVDS_ON | LVDS_EN | LVDS_BLON | LVDS_DIGON);
2323 }
2324
2325 OUTREG(LVDS_GEN_CNTL, lvds_gen_cntl);
2326 rinfo->init_state.lvds_gen_cntl &= ~LVDS_STATE_MASK;
2327 rinfo->init_state.lvds_gen_cntl |= (lvds_gen_cntl & LVDS_STATE_MASK);
2328
2329 return 0;
2330}
2331
2332static int radeon_set_backlight_level(int level, void *data)
2333{
2334 return radeon_set_backlight_enable(1, level, data);
2335}
2336#endif /* CONFIG_PMAC_BACKLIGHT */
2337
2338
2339#ifdef CONFIG_PMAC_PBOOK
2340
2341static u32 dbg_clk;
2342
2343/*
2344 * Radeon M6 Power Management code. This code currently only supports
2345 * the mobile chips, it's based from some informations provided by ATI
2346 * along with hours of tracing of MacOS drivers
2347 */
2348
2349static void radeon_pm_save_regs(struct radeonfb_info *rinfo)
2350{
2351 rinfo->save_regs[0] = INPLL(PLL_PWRMGT_CNTL);
2352 rinfo->save_regs[1] = INPLL(CLK_PWRMGT_CNTL);
2353 rinfo->save_regs[2] = INPLL(MCLK_CNTL);
2354 rinfo->save_regs[3] = INPLL(SCLK_CNTL);
2355 rinfo->save_regs[4] = INPLL(CLK_PIN_CNTL);
2356 rinfo->save_regs[5] = INPLL(VCLK_ECP_CNTL);
2357 rinfo->save_regs[6] = INPLL(PIXCLKS_CNTL);
2358 rinfo->save_regs[7] = INPLL(MCLK_MISC);
2359 rinfo->save_regs[8] = INPLL(P2PLL_CNTL);
2360
2361 rinfo->save_regs[9] = INREG(DISP_MISC_CNTL);
2362 rinfo->save_regs[10] = INREG(DISP_PWR_MAN);
2363 rinfo->save_regs[11] = INREG(LVDS_GEN_CNTL);
2364 rinfo->save_regs[12] = INREG(LVDS_PLL_CNTL);
2365 rinfo->save_regs[13] = INREG(TV_DAC_CNTL);
2366 rinfo->save_regs[14] = INREG(BUS_CNTL1);
2367 rinfo->save_regs[15] = INREG(CRTC_OFFSET_CNTL);
2368 rinfo->save_regs[16] = INREG(AGP_CNTL);
2369 rinfo->save_regs[17] = (INREG(CRTC_GEN_CNTL) & 0xfdffffff) | 0x04000000;
2370 rinfo->save_regs[18] = (INREG(CRTC2_GEN_CNTL) & 0xfdffffff) | 0x04000000;
2371 rinfo->save_regs[19] = INREG(GPIOPAD_A);
2372 rinfo->save_regs[20] = INREG(GPIOPAD_EN);
2373 rinfo->save_regs[21] = INREG(GPIOPAD_MASK);
2374 rinfo->save_regs[22] = INREG(ZV_LCDPAD_A);
2375 rinfo->save_regs[23] = INREG(ZV_LCDPAD_EN);
2376 rinfo->save_regs[24] = INREG(ZV_LCDPAD_MASK);
2377 rinfo->save_regs[25] = INREG(GPIO_VGA_DDC);
2378 rinfo->save_regs[26] = INREG(GPIO_DVI_DDC);
2379 rinfo->save_regs[27] = INREG(GPIO_MONID);
2380 rinfo->save_regs[28] = INREG(GPIO_CRT2_DDC);
2381
2382 rinfo->save_regs[29] = INREG(SURFACE_CNTL);
2383 rinfo->save_regs[30] = INREG(MC_FB_LOCATION);
2384 rinfo->save_regs[31] = INREG(DISPLAY_BASE_ADDR);
2385 rinfo->save_regs[32] = INREG(MC_AGP_LOCATION);
2386 rinfo->save_regs[33] = INREG(CRTC2_DISPLAY_BASE_ADDR);
2387}
2388
2389static void radeon_pm_restore_regs(struct radeonfb_info *rinfo)
2390{
2391 OUTPLL(P2PLL_CNTL, rinfo->save_regs[8] & 0xFFFFFFFE); /* First */
2392
2393 OUTPLL(PLL_PWRMGT_CNTL, rinfo->save_regs[0]);
2394 OUTPLL(CLK_PWRMGT_CNTL, rinfo->save_regs[1]);
2395 OUTPLL(MCLK_CNTL, rinfo->save_regs[2]);
2396 OUTPLL(SCLK_CNTL, rinfo->save_regs[3]);
2397 OUTPLL(CLK_PIN_CNTL, rinfo->save_regs[4]);
2398 OUTPLL(VCLK_ECP_CNTL, rinfo->save_regs[5]);
2399 OUTPLL(PIXCLKS_CNTL, rinfo->save_regs[6]);
2400 OUTPLL(MCLK_MISC, rinfo->save_regs[7]);
2401
2402 OUTREG(DISP_MISC_CNTL, rinfo->save_regs[9]);
2403 OUTREG(DISP_PWR_MAN, rinfo->save_regs[10]);
2404 OUTREG(LVDS_GEN_CNTL, rinfo->save_regs[11]);
2405 OUTREG(LVDS_PLL_CNTL,rinfo->save_regs[12]);
2406 OUTREG(TV_DAC_CNTL, rinfo->save_regs[13]);
2407 OUTREG(BUS_CNTL1, rinfo->save_regs[14]);
2408 OUTREG(CRTC_OFFSET_CNTL, rinfo->save_regs[15]);
2409 OUTREG(AGP_CNTL, rinfo->save_regs[16]);
2410 OUTREG(CRTC_GEN_CNTL, rinfo->save_regs[17]);
2411 OUTREG(CRTC2_GEN_CNTL, rinfo->save_regs[18]);
2412
2413 // wait VBL before that one ?
2414 OUTPLL(P2PLL_CNTL, rinfo->save_regs[8]);
2415
2416 OUTREG(GPIOPAD_A, rinfo->save_regs[19]);
2417 OUTREG(GPIOPAD_EN, rinfo->save_regs[20]);
2418 OUTREG(GPIOPAD_MASK, rinfo->save_regs[21]);
2419 OUTREG(ZV_LCDPAD_A, rinfo->save_regs[22]);
2420 OUTREG(ZV_LCDPAD_EN, rinfo->save_regs[23]);
2421 OUTREG(ZV_LCDPAD_MASK, rinfo->save_regs[24]);
2422 OUTREG(GPIO_VGA_DDC, rinfo->save_regs[25]);
2423 OUTREG(GPIO_DVI_DDC, rinfo->save_regs[26]);
2424 OUTREG(GPIO_MONID, rinfo->save_regs[27]);
2425 OUTREG(GPIO_CRT2_DDC, rinfo->save_regs[28]);
2426}
2427
2428static void radeon_pm_disable_iopad(struct radeonfb_info *rinfo)
2429{
2430 OUTREG(GPIOPAD_MASK, 0x0001ffff);
2431 OUTREG(GPIOPAD_EN, 0x00000400);
2432 OUTREG(GPIOPAD_A, 0x00000000);
2433 OUTREG(ZV_LCDPAD_MASK, 0x00000000);
2434 OUTREG(ZV_LCDPAD_EN, 0x00000000);
2435 OUTREG(ZV_LCDPAD_A, 0x00000000);
2436 OUTREG(GPIO_VGA_DDC, 0x00030000);
2437 OUTREG(GPIO_DVI_DDC, 0x00000000);
2438 OUTREG(GPIO_MONID, 0x00030000);
2439 OUTREG(GPIO_CRT2_DDC, 0x00000000);
2440}
2441
2442static void radeon_pm_program_v2clk(struct radeonfb_info *rinfo)
2443{
2444//
2445// u32 reg;
2446//
2447// OUTPLL(P2PLL_REF_DIV, 0x0c);
2448//
2449// .../... figure out what macos does here
2450}
2451
2452static void radeon_pm_low_current(struct radeonfb_info *rinfo)
2453{
2454 u32 reg;
2455
2456 reg = INREG(BUS_CNTL1);
2457 reg &= ~BUS_CNTL1_MOBILE_PLATFORM_SEL_MASK;
2458 reg |= BUS_CNTL1_AGPCLK_VALID | (1<<BUS_CNTL1_MOBILE_PLATFORM_SEL_SHIFT);
2459 OUTREG(BUS_CNTL1, reg);
2460
2461 reg = INPLL(PLL_PWRMGT_CNTL);
2462 reg |= PLL_PWRMGT_CNTL_SPLL_TURNOFF | PLL_PWRMGT_CNTL_PPLL_TURNOFF |
2463 PLL_PWRMGT_CNTL_P2PLL_TURNOFF | PLL_PWRMGT_CNTL_TVPLL_TURNOFF;
2464 reg &= ~PLL_PWRMGT_CNTL_SU_MCLK_USE_BCLK;
2465 reg &= ~PLL_PWRMGT_CNTL_MOBILE_SU;
2466 OUTPLL(PLL_PWRMGT_CNTL, reg);
2467
2468// reg = INPLL(TV_PLL_CNTL1);
2469// reg |= TV_PLL_CNTL1__TVPLL_RESET | TV_PLL_CNTL1__TVPLL_SLEEP;
2470// OUTPLL(TV_PLL_CNTL1, reg);
2471
2472 reg = INREG(TV_DAC_CNTL);
2473 reg &= ~(TV_DAC_CNTL_BGADJ_MASK |TV_DAC_CNTL_DACADJ_MASK);
2474 reg |=TV_DAC_CNTL_BGSLEEP | TV_DAC_CNTL_RDACPD | TV_DAC_CNTL_GDACPD |
2475 TV_DAC_CNTL_BDACPD |
2476 (8<<TV_DAC_CNTL_BGADJ__SHIFT) | (8<<TV_DAC_CNTL_DACADJ__SHIFT);
2477 OUTREG(TV_DAC_CNTL, reg);
2478
2479 reg = INREG(TMDS_TRANSMITTER_CNTL);
2480 reg &= ~(TMDS_PLL_EN |TMDS_PLLRST);
2481 OUTREG(TMDS_TRANSMITTER_CNTL, reg);
2482
2483// lvds_pll_cntl = regr32(g, LVDS_PLL_CNTL);
2484// lvds_pll_cntl &= ~LVDS_PLL_CNTL__LVDS_PLL_EN;
2485// lvds_pll_cntl |= LVDS_PLL_CNTL__LVDS_PLL_RESET;
2486// regw32(g, LVDS_PLL_CNTL, lvds_pll_cntl);
2487
2488 reg = INREG(DAC_CNTL);
2489 reg &= ~DAC_CMP_EN;
2490 OUTREG(DAC_CNTL, reg);
2491
2492 reg = INREG(DAC_CNTL2);
2493 reg &= ~DAC2_CMP_EN;
2494 OUTREG(DAC_CNTL2, reg);
2495
2496 reg = INREG(TV_DAC_CNTL);
2497 reg &= ~TV_DAC_CNTL_DETECT;
2498 OUTREG(TV_DAC_CNTL, reg);
2499}
2500
2501static void radeon_pm_setup_for_suspend(struct radeonfb_info *rinfo)
2502{
2503 /* This code is disabled. It does what is in the pm_init
2504 * function of the MacOS driver code ATI sent me. However,
2505 * it doesn't fix my sleep problem, and is causing other issues
2506 * on wakeup (bascially the machine dying when switching consoles
2507 * I haven't had time to investigate this yet
2508 */
2509#if 0
2510 u32 disp_misc_cntl;
2511 u32 disp_pwr_man;
2512 u32 temp;
2513
2514 // set SPLL, MPLL, PPLL, P2PLL, TVPLL, SCLK, MCLK, PCLK, P2CLK,
2515 // TCLK and TEST_MODE to 0
2516 temp = INPLL(CLK_PWRMGT_CNTL);
2517 OUTPLL(CLK_PWRMGT_CNTL , temp & ~0xc00002ff);
2518
2519 // Turn on Power Management
2520 temp = INPLL(CLK_PWRMGT_CNTL);
2521 OUTPLL(CLK_PWRMGT_CNTL , temp | 0x00000400);
2522
2523 // Turn off display clock if using mobile chips
2524 temp = INPLL(CLK_PWRMGT_CNTL);
2525 OUTREG(CLK_PWRMGT_CNTL , temp | 0x00100000);
2526
2527 // Force PIXCLK_ALWAYS_ON and PIXCLK_DAC_ALWAYS_ON
2528 temp = INPLL(VCLK_ECP_CNTL);
2529 OUTPLL(VCLK_ECP_CNTL, temp & ~0x000000c0);
2530
2531 // Force ECP_FORCE_ON to 1
2532 temp = INPLL(VCLK_ECP_CNTL);
2533 OUTPLL(VCLK_ECP_CNTL, temp | 0x00040000);
2534
2535 // Force PIXCLK_BLEND_ALWAYS_ON and PIXCLK_GV_ALWAYS_ON
2536 temp = INPLL(PIXCLKS_CNTL);
2537 OUTPLL(PIXCLKS_CNTL, temp & ~0x00001800);
2538
2539 // Forcing SCLK_CNTL to ON
2540 OUTPLL(SCLK_CNTL, (INPLL(SCLK_CNTL)& 0x00000007) | 0xffff8000 );
2541
2542 // Set PM control over XTALIN pad
2543 temp = INPLL(CLK_PIN_CNTL);
2544 OUTPLL(CLK_PIN_CNTL, temp | 0x00080000);
2545
2546 // Force MCLK and YCLK and MC as dynamic
2547 temp = INPLL(MCLK_CNTL);
2548 OUTPLL(MCLK_CNTL, temp & 0xffeaffff);
2549
2550 // PLL_TURNOFF
2551 temp = INPLL(PLL_PWRMGT_CNTL);
2552 OUTPLL(PLL_PWRMGT_CNTL, temp | 0x0000001f);
2553
2554 // set MOBILE_SU to 1 if M6 or DDR64 is detected
2555 temp = INPLL(PLL_PWRMGT_CNTL);
2556 OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00010000);
2557
2558 // select PM access mode (PM_MODE_SEL) (use ACPI mode)
2559// temp = INPLL(PLL_PWRMGT_CNTL);
2560// OUTPLL(PLL_PWRMGT_CNTL, temp | 0x00002000);
2561 temp = INPLL(PLL_PWRMGT_CNTL);
2562 OUTPLL(PLL_PWRMGT_CNTL, temp & ~0x00002000);
2563
2564 // set DISP_MISC_CNTL register
2565 disp_misc_cntl = INREG(DISP_MISC_CNTL);
2566 disp_misc_cntl &= ~( DISP_MISC_CNTL_SOFT_RESET_GRPH_PP |
2567 DISP_MISC_CNTL_SOFT_RESET_SUBPIC_PP |
2568 DISP_MISC_CNTL_SOFT_RESET_OV0_PP |
2569 DISP_MISC_CNTL_SOFT_RESET_GRPH_SCLK |
2570 DISP_MISC_CNTL_SOFT_RESET_SUBPIC_SCLK |
2571 DISP_MISC_CNTL_SOFT_RESET_OV0_SCLK |
2572 DISP_MISC_CNTL_SOFT_RESET_GRPH2_PP |
2573 DISP_MISC_CNTL_SOFT_RESET_GRPH2_SCLK |
2574 DISP_MISC_CNTL_SOFT_RESET_LVDS |
2575 DISP_MISC_CNTL_SOFT_RESET_TMDS |
2576 DISP_MISC_CNTL_SOFT_RESET_DIG_TMDS |
2577 DISP_MISC_CNTL_SOFT_RESET_TV);
2578 OUTREG(DISP_MISC_CNTL, disp_misc_cntl);
2579
2580 // set DISP_PWR_MAN register
2581 disp_pwr_man = INREG(DISP_PWR_MAN);
2582 // clau - 9.29.2000 - changes made to bit23:18 to set to 1 as requested by George
2583 disp_pwr_man |= (DISP_PWR_MAN_DIG_TMDS_ENABLE_RST |
2584 DISP_PWR_MAN_TV_ENABLE_RST |
2585 // DISP_PWR_MAN_AUTO_PWRUP_EN |
2586 DISP_PWR_MAN_DISP_D3_GRPH_RST |
2587 DISP_PWR_MAN_DISP_D3_SUBPIC_RST |
2588 DISP_PWR_MAN_DISP_D3_OV0_RST |
2589 DISP_PWR_MAN_DISP_D1D2_GRPH_RST |
2590 DISP_PWR_MAN_DISP_D1D2_SUBPIC_RST |
2591 DISP_PWR_MAN_DISP_D1D2_OV0_RST);
2592 disp_pwr_man &= ~(DISP_PWR_MAN_DISP_PWR_MAN_D3_CRTC_EN |
2593 DISP_PWR_MAN_DISP2_PWR_MAN_D3_CRTC2_EN|
2594 DISP_PWR_MAN_DISP_D3_RST |
2595 DISP_PWR_MAN_DISP_D3_REG_RST);
2596 OUTREG(DISP_PWR_MAN, disp_pwr_man);
2597
2598 // clau - 10.24.2000
2599 // - add in setting for BUS_CNTL1 b27:26 = 0x01 and b31 = 0x1
2600 // - add in setting for AGP_CNTL b7:0 = 0x20
2601 // - add in setting for DVI_DDC_DATA_OUT_EN b17:16 = 0x0
2602
2603 // the following settings (two lines) are applied at a later part of this function, only on mobile platform
2604 // requres -mobile flag
2605 OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1) & 0xf3ffffff) | 0x04000000);
2606 OUTREG(BUS_CNTL1, INREG(BUS_CNTL1) | 0x80000000);
2607 OUTREG(AGP_CNTL, (INREG(AGP_CNTL) & 0xffffff00) | 0x20);
2608 OUTREG(GPIO_DVI_DDC, INREG(GPIO_DVI_DDC) & 0xfffcffff);
2609
2610 // yulee - 12.12.2000
2611 // A12 only
2612 // EN_MCLK_TRISTATE_IN_SUSPEND@MCLK_MISC = 1
2613 // ACCESS_REGS_IN_SUSPEND@CLK_PIN_CNTL = 0
2614 // only on mobile platform
2615 OUTPLL(MCLK_MISC, INPLL(MCLK_MISC) | 0x00040000 );
2616
2617 // yulee -12.12.2000
2618 // AGPCLK_VALID@BUS_CNTL1 = 1
2619 // MOBILE_PLATFORM_SEL@BUS_CNTL1 = 01
2620 // CRTC_STEREO_SYNC_OUT_EN@CRTC_OFFSET_CNTL = 0
2621 // CG_CLK_TO_OUTPIN@CLK_PIN_CNTL = 0
2622 // only on mobile platform
2623 OUTPLL(CLK_PIN_CNTL, INPLL(CLK_PIN_CNTL ) & 0xFFFFF7FF );
2624 OUTREG(BUS_CNTL1, (INREG(BUS_CNTL1 ) & 0xF3FFFFFF) | 0x84000000 );
2625 OUTREG(CRTC_OFFSET_CNTL, INREG(CRTC_OFFSET_CNTL ) & 0xFFEFFFFF );
2626
2627 mdelay(100);
2628#endif
2629
2630 /* Disable CRTCs */
2631 OUTREG(CRTC_GEN_CNTL, (INREG(CRTC_GEN_CNTL) & ~CRTC_EN) | CRTC_DISP_REQ_EN_B);
2632 OUTREG(CRTC2_GEN_CNTL, (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B);
2633 (void)INREG(CRTC2_GEN_CNTL);
2634 mdelay(17);
2635}
2636
2637static void radeon_set_suspend(struct radeonfb_info *rinfo, int suspend)
2638{
2639 u16 pwr_cmd;
2640
2641 if (!rinfo->pm_reg)
2642 return;
2643
2644 /* Set the chip into appropriate suspend mode (we use D2,
2645 * D3 would require a compete re-initialization of the chip,
2646 * including PCI config registers, clocks, AGP conf, ...)
2647 */
2648 if (suspend) {
2649 /* According to ATI, we should program V2CLK here, I have
2650 * to verify what's up exactly
2651 */
2652 /* Save some registers */
2653 radeon_pm_save_regs(rinfo);
2654
2655 /* Check that on M7 too, might work might not. M7 may also
2656 * need explicit enabling of PM
2657 */
2658 if (rinfo->arch == RADEON_M6) {
2659 /* Program V2CLK */
2660 radeon_pm_program_v2clk(rinfo);
2661
2662 /* Disable IO PADs */
2663 radeon_pm_disable_iopad(rinfo);
2664
2665 /* Set low current */
2666 radeon_pm_low_current(rinfo);
2667
2668 /* Prepare chip for power management */
2669 radeon_pm_setup_for_suspend(rinfo);
2670
2671 /* Reset the MDLL */
2672 OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) | MCKOA_RESET);
2673 (void)INPLL(MDLL_RDCKA);
2674 OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET);
2675 (void)INPLL(MDLL_RDCKA);
2676 }
2677
2678 /* Switch PCI power managment to D2. */
2679 for (;;) {
2680 pci_read_config_word(
2681 rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL,
2682 &pwr_cmd);
2683 if (pwr_cmd & 2)
2684 break;
2685 pci_write_config_word(
2686 rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL,
2687 (pwr_cmd & ~PCI_PM_CTRL_STATE_MASK) | 2);
2688 mdelay(500);
2689 }
2690 } else {
2691 /* Switch back PCI powermanagment to D0 */
2692 mdelay(200);
2693 pci_write_config_word(rinfo->pdev, rinfo->pm_reg+PCI_PM_CTRL, 0);
2694 mdelay(500);
2695
2696 dbg_clk = INPLL(1);
2697
2698 /* Do we need that on M7 ? */
2699 if (rinfo->arch == RADEON_M6) {
2700 /* Restore the MDLL */
2701 OUTPLL(MDLL_CKO, INPLL(MDLL_CKO) & ~MCKOA_RESET);
2702 (void)INPLL(MDLL_CKO);
2703 }
2704
2705 /* Restore some registers */
2706 radeon_pm_restore_regs(rinfo);
2707 }
2708}
2709
2710/*
2711 * Save the contents of the framebuffer when we go to sleep,
2712 * and restore it when we wake up again.
2713 */
2714
2715int radeon_sleep_notify(struct pmu_sleep_notifier *self, int when)
2716{
2717 struct radeonfb_info *rinfo;
2718
2719 for (rinfo = board_list; rinfo != NULL; rinfo = rinfo->next) {
2720 struct fb_fix_screeninfo fix;
2721 int nb;
2722 struct display *disp;
2723
2724 disp = (rinfo->currcon < 0) ? rinfo->info.disp : &fb_display[rinfo->currcon];
2725
2726 switch (rinfo->arch) {
2727 case RADEON_M6:
2728 case RADEON_M7:
2729 case RADEON_M9:
2730 break;
2731 default:
2732 return PBOOK_SLEEP_REFUSE;
2733 }
2734
2735 radeonfb_get_fix(&fix, fg_console, (struct fb_info *)rinfo);
2736 nb = fb_display[fg_console].var.yres * fix.line_length;
2737
2738 switch (when) {
2739 case PBOOK_SLEEP_NOW:
2740 acquire_console_sem();
2741 disp->dispsw = &fbcon_dummy;
2742
2743 if (!noaccel) {
2744 /* Make sure engine is reset */
2745 radeon_engine_reset();
2746 radeon_engine_idle();
2747 }
2748
2749 /* Blank display and LCD */
2750 radeonfb_blank(VESA_POWERDOWN+1,
2751 (struct fb_info *)rinfo);
2752
2753 /* Sleep */
2754 rinfo->asleep = 1;
2755 radeon_set_suspend(rinfo, 1);
2756 release_console_sem();
2757
2758 break;
2759 case PBOOK_WAKE:
2760 acquire_console_sem();
2761 /* Wakeup */
2762 radeon_set_suspend(rinfo, 0);
2763
2764 if (!noaccel)
2765 radeon_engine_init(rinfo);
2766 rinfo->asleep = 0;
2767 radeon_set_dispsw(rinfo, disp);
2768 radeon_load_video_mode(rinfo, &disp->var);
2769 do_install_cmap(rinfo->currcon < 0 ? 0 : rinfo->currcon,
2770 (struct fb_info *)rinfo);
2771
2772 radeonfb_blank(0, (struct fb_info *)rinfo);
2773 release_console_sem();
2774 printk("CLK_PIN_CNTL on wakeup was: %08x\n", dbg_clk);
2775 break;
2776 }
2777 }
2778
2779 return PBOOK_SLEEP_OK;
2780}
2781
2782#endif /* CONFIG_PMAC_PBOOK */
2783
2784static int radeonfb_pci_register (struct pci_dev *pdev,
2785 const struct pci_device_id *ent)
2786{
2787 struct radeonfb_info *rinfo;
2788 struct radeon_chip_info *rci = &radeon_chip_info[ent->driver_data];
2789 u32 tmp;
2790
2791 RTRACE("radeonfb_pci_register BEGIN\n");
2792
2793 /* Enable device in PCI config */
2794 if (pci_enable_device(pdev) != 0) {
2795 printk(KERN_ERR "radeonfb: Cannot enable PCI device\n");
2796 return -ENODEV;
2797 }
2798
2799 rinfo = kmalloc (sizeof (struct radeonfb_info), GFP_KERNEL);
2800 if (!rinfo) {
2801 printk ("radeonfb: could not allocate memory\n");
2802 return -ENODEV;
2803 }
2804
2805 memset (rinfo, 0, sizeof (struct radeonfb_info));
2806 //info = &rinfo->info;
2807 rinfo->pdev = pdev;
2808 strcpy(rinfo->name, rci->name);
2809 rinfo->arch = rci->arch;
2810
2811 /* Set base addrs */
2812 rinfo->fb_base_phys = pci_resource_start (pdev, 0);
2813 rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
2814
2815 /* request the mem regions */
2816 if (!request_mem_region (rinfo->fb_base_phys,
2817 pci_resource_len(pdev, 0), "radeonfb")) {
2818 printk ("radeonfb: cannot reserve FB region\n");
2819 kfree (rinfo);
2820 return -ENODEV;
2821 }
2822
2823 if (!request_mem_region (rinfo->mmio_base_phys,
2824 pci_resource_len(pdev, 2), "radeonfb")) {
2825 printk ("radeonfb: cannot reserve MMIO region\n");
2826 release_mem_region (rinfo->fb_base_phys,
2827 pci_resource_len(pdev, 0));
2828 kfree (rinfo);
2829 return -ENODEV;
2830 }
2831
2832 /* map the regions */
2833 rinfo->mmio_base = ioremap (rinfo->mmio_base_phys, RADEON_REGSIZE);
2834 if (!rinfo->mmio_base) {
2835 printk ("radeonfb: cannot map MMIO\n");
2836 release_mem_region (rinfo->mmio_base_phys,
2837 pci_resource_len(pdev, 2));
2838 release_mem_region (rinfo->fb_base_phys,
2839 pci_resource_len(pdev, 0));
2840 kfree (rinfo);
2841 return -ENODEV;
2842 }
2843
2844 rinfo->chipset = pdev->device;
2845
2846 switch (rinfo->arch) {
2847 case RADEON_R100:
2848 rinfo->hasCRTC2 = 0;
2849 break;
2850 default:
2851 /* all the rest have it */
2852 rinfo->hasCRTC2 = 1;
2853 break;
2854 }
2855#if 0
2856 if (rinfo->arch == RADEON_M7) {
2857 /*
2858 * Noticed some errors in accel with M7, will have to work these out...
2859 */
2860 noaccel = 1;
2861 }
2862#endif
2863 if (mirror)
2864 printk("radeonfb: mirroring display to CRT\n");
2865
2866 /* framebuffer size */
2867 tmp = INREG(CONFIG_MEMSIZE);
2868
2869 /* mem size is bits [28:0], mask off the rest */
2870 rinfo->video_ram = tmp & CONFIG_MEMSIZE_MASK;
2871
2872 /* ram type */
2873 tmp = INREG(MEM_SDRAM_MODE_REG);
2874 switch ((MEM_CFG_TYPE & tmp) >> 30) {
2875 case 0:
2876 /* SDR SGRAM (2:1) */
2877 strcpy(rinfo->ram_type, "SDR SGRAM");
2878 rinfo->ram.ml = 4;
2879 rinfo->ram.mb = 4;
2880 rinfo->ram.trcd = 1;
2881 rinfo->ram.trp = 2;
2882 rinfo->ram.twr = 1;
2883 rinfo->ram.cl = 2;
2884 rinfo->ram.loop_latency = 16;
2885 rinfo->ram.rloop = 16;
2886
2887 break;
2888 case 1:
2889 /* DDR SGRAM */
2890 strcpy(rinfo->ram_type, "DDR SGRAM");
2891 rinfo->ram.ml = 4;
2892 rinfo->ram.mb = 4;
2893 rinfo->ram.trcd = 3;
2894 rinfo->ram.trp = 3;
2895 rinfo->ram.twr = 2;
2896 rinfo->ram.cl = 3;
2897 rinfo->ram.tr2w = 1;
2898 rinfo->ram.loop_latency = 16;
2899 rinfo->ram.rloop = 16;
2900
2901 break;
2902 default:
2903 /* 64-bit SDR SGRAM */
2904 strcpy(rinfo->ram_type, "SDR SGRAM 64");
2905 rinfo->ram.ml = 4;
2906 rinfo->ram.mb = 8;
2907 rinfo->ram.trcd = 3;
2908 rinfo->ram.trp = 3;
2909 rinfo->ram.twr = 1;
2910 rinfo->ram.cl = 3;
2911 rinfo->ram.tr2w = 1;
2912 rinfo->ram.loop_latency = 17;
2913 rinfo->ram.rloop = 17;
2914
2915 break;
2916 }
2917
2918 rinfo->bios_seg = radeon_find_rom(rinfo);
2919 radeon_get_pllinfo(rinfo, rinfo->bios_seg);
2920
2921 /*
2922 * Hack to get around some busted production M6's
2923 * reporting no ram
2924 */
2925 if (rinfo->video_ram == 0) {
2926 switch (pdev->device) {
2927 case PCI_DEVICE_ID_ATI_RADEON_LY:
2928 case PCI_DEVICE_ID_ATI_RADEON_LZ:
2929 rinfo->video_ram = 8192 * 1024;
2930 break;
2931 default:
2932 break;
2933 }
2934 }
2935
2936
2937 RTRACE("radeonfb: probed %s %dk videoram\n", (rinfo->ram_type), (rinfo->video_ram/1024));
2938
2939#if !defined(__powerpc__)
2940 radeon_get_moninfo(rinfo);
2941#else
2942 switch (pdev->device) {
2943 case PCI_DEVICE_ID_ATI_RADEON_LW:
2944 case PCI_DEVICE_ID_ATI_RADEON_LX:
2945 case PCI_DEVICE_ID_ATI_RADEON_LY:
2946 case PCI_DEVICE_ID_ATI_RADEON_LZ:
2947 rinfo->dviDisp_type = MT_LCD;
2948 break;
2949 default:
2950 radeon_get_moninfo(rinfo);
2951 break;
2952 }
2953#endif
2954
2955 radeon_get_EDID(rinfo);
2956
2957 if ((rinfo->dviDisp_type == MT_DFP) || (rinfo->dviDisp_type == MT_LCD) ||
2958 (rinfo->crtDisp_type == MT_DFP)) {
2959 if (!radeon_get_dfpinfo(rinfo)) {
2960 iounmap(rinfo->mmio_base);
2961 release_mem_region (rinfo->mmio_base_phys,
2962 pci_resource_len(pdev, 2));
2963 release_mem_region (rinfo->fb_base_phys,
2964 pci_resource_len(pdev, 0));
2965 kfree (rinfo);
2966 return -ENODEV;
2967 }
2968 }
2969
2970 rinfo->fb_base = ioremap (rinfo->fb_base_phys, rinfo->video_ram);
2971 if (!rinfo->fb_base) {
2972 printk ("radeonfb: cannot map FB\n");
2973 iounmap(rinfo->mmio_base);
2974 release_mem_region (rinfo->mmio_base_phys,
2975 pci_resource_len(pdev, 2));
2976 release_mem_region (rinfo->fb_base_phys,
2977 pci_resource_len(pdev, 0));
2978 kfree (rinfo);
2979 return -ENODEV;
2980 }
2981
2982 /* I SHOULD FIX THAT CRAP ! I should probably mimmic XFree DRI
2983 * driver setup here.
2984 *
2985 * On PPC, OF based cards setup the internal memory
2986 * mapping in strange ways. We change it so that the
2987 * framebuffer is mapped at 0 and given half of the card's
2988 * address space (2Gb). AGP is mapped high (0xe0000000) and
2989 * can use up to 512Mb. Once DRI is fully implemented, we
2990 * will have to setup the PCI remapper to remap the agp_special_page
2991 * memory page somewhere between those regions so that the card
2992 * use a normal PCI bus master cycle to access the ring read ptr.
2993 * --BenH.
2994 */
2995#ifdef CONFIG_ALL_PPC
2996 if (rinfo->hasCRTC2)
2997 OUTREG(CRTC2_GEN_CNTL,
2998 (INREG(CRTC2_GEN_CNTL) & ~CRTC2_EN) | CRTC2_DISP_REQ_EN_B);
2999 OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) | CRTC_DISPLAY_DIS);
3000 OUTREG(MC_FB_LOCATION, 0x7fff0000);
3001 OUTREG(MC_AGP_LOCATION, 0xffffe000);
3002 OUTREG(DISPLAY_BASE_ADDR, 0x00000000);
3003 if (rinfo->hasCRTC2)
3004 OUTREG(CRTC2_DISPLAY_BASE_ADDR, 0x00000000);
3005 OUTREG(SRC_OFFSET, 0x00000000);
3006 OUTREG(DST_OFFSET, 0x00000000);
3007 mdelay(10);
3008 OUTREG(CRTC_EXT_CNTL, INREG(CRTC_EXT_CNTL) & ~CRTC_DISPLAY_DIS);
3009#endif /* CONFIG_ALL_PPC */
3010
3011 /* save current mode regs before we switch into the new one
3012 * so we can restore this upon __exit
3013 */
3014 radeon_save_state (rinfo, &rinfo->init_state);
3015
3016 /* set all the vital stuff */
3017 radeon_set_fbinfo (rinfo);
3018
3019 pci_set_drvdata(pdev, rinfo);
3020 rinfo->next = board_list;
3021 board_list = rinfo;
3022 ((struct fb_info *) rinfo)->device = &pdev->dev;
3023 if (register_framebuffer ((struct fb_info *) rinfo) < 0) {
3024 printk ("radeonfb: could not register framebuffer\n");
3025 iounmap(rinfo->fb_base);
3026 iounmap(rinfo->mmio_base);
3027 release_mem_region (rinfo->mmio_base_phys,
3028 pci_resource_len(pdev, 2));
3029 release_mem_region (rinfo->fb_base_phys,
3030 pci_resource_len(pdev, 0));
3031 kfree (rinfo);
3032 return -ENODEV;
3033 }
3034
3035#ifdef CONFIG_MTRR
3036 rinfo->mtrr_hdl = nomtrr ? -1 : mtrr_add(rinfo->fb_base_phys,
3037 rinfo->video_ram,
3038 MTRR_TYPE_WRCOMB, 1);
3039#endif
3040
3041#ifdef CONFIG_PMAC_BACKLIGHT
3042 if (rinfo->dviDisp_type == MT_LCD)
3043 register_backlight_controller(&radeon_backlight_controller,
3044 rinfo, "ati");
3045#endif
3046
3047#ifdef CONFIG_PMAC_PBOOK
3048 if (rinfo->dviDisp_type == MT_LCD) {
3049 rinfo->pm_reg = pci_find_capability(pdev, PCI_CAP_ID_PM);
3050 pmu_register_sleep_notifier(&radeon_sleep_notifier);
3051 }
3052#endif
3053
3054 printk ("radeonfb: ATI Radeon %s %s %d MB\n", rinfo->name, rinfo->ram_type,
3055 (rinfo->video_ram/(1024*1024)));
3056
3057 if (rinfo->hasCRTC2) {
3058 printk("radeonfb: DVI port %s monitor connected\n",
3059 GET_MON_NAME(rinfo->dviDisp_type));
3060 printk("radeonfb: CRT port %s monitor connected\n",
3061 GET_MON_NAME(rinfo->crtDisp_type));
3062 } else {
3063 printk("radeonfb: CRT port %s monitor connected\n",
3064 GET_MON_NAME(rinfo->crtDisp_type));
3065 }
3066
3067 RTRACE("radeonfb_pci_register END\n");
3068
3069 return 0;
3070}
3071
3072
3073
3074static void __devexit radeonfb_pci_unregister (struct pci_dev *pdev)
3075{
3076 struct radeonfb_info *rinfo = pci_get_drvdata(pdev);
3077
3078 if (!rinfo)
3079 return;
3080
3081 /* restore original state
3082 *
3083 * Doesn't quite work yet, possibly because of the PPC hacking
3084 * I do on startup, disable for now. --BenH
3085 */
3086 radeon_write_mode (rinfo, &rinfo->init_state);
3087
3088#ifdef CONFIG_MTRR
3089 if (rinfo->mtrr_hdl >= 0)
3090 mtrr_del(rinfo->mtrr_hdl, 0, 0);
3091#endif
3092
3093 unregister_framebuffer ((struct fb_info *) rinfo);
3094
3095 iounmap(rinfo->mmio_base);
3096 iounmap(rinfo->fb_base);
3097
3098 release_mem_region (rinfo->mmio_base_phys,
3099 pci_resource_len(pdev, 2));
3100 release_mem_region (rinfo->fb_base_phys,
3101 pci_resource_len(pdev, 0));
3102
3103 kfree (rinfo);
3104}
3105
3106
3107static struct pci_driver radeonfb_driver = {
3108 .name = "radeonfb",
3109 .id_table = radeonfb_pci_table,
3110 .probe = radeonfb_pci_register,
3111 .remove = __devexit_p(radeonfb_pci_unregister),
3112};
3113
3114#ifndef MODULE
3115static int __init radeonfb_old_setup (char *options)
3116{
3117 char *this_opt;
3118
3119 if (!options || !*options)
3120 return 0;
3121
3122 while ((this_opt = strsep (&options, ",")) != NULL) {
3123 if (!*this_opt)
3124 continue;
3125 if (!strncmp(this_opt, "noaccel", 7)) {
3126 noaccel = 1;
3127 } else if (!strncmp(this_opt, "mirror", 6)) {
3128 mirror = 1;
3129 } else if (!strncmp(this_opt, "dfp", 3)) {
3130 force_dfp = 1;
3131 } else if (!strncmp(this_opt, "panel_yres:", 11)) {
3132 panel_yres = simple_strtoul((this_opt+11), NULL, 0);
3133 } else if (!strncmp(this_opt, "nomtrr", 6)) {
3134 nomtrr = 1;
3135 } else
3136 mode_option = this_opt;
3137 }
3138
3139 return 0;
3140}
3141#endif /* MODULE */
3142
3143static int __init radeonfb_old_init (void)
3144{
3145#ifndef MODULE
3146 char *option = NULL;
3147
3148 if (fb_get_options("radeonfb_old", &option))
3149 return -ENODEV;
3150 radeonfb_old_setup(option);
3151#endif
3152 return pci_register_driver (&radeonfb_driver);
3153}
3154
3155
3156static void __exit radeonfb_old_exit (void)
3157{
3158 pci_unregister_driver (&radeonfb_driver);
3159}
3160
3161module_init(radeonfb_old_init);
3162module_exit(radeonfb_old_exit);
3163
3164
3165MODULE_AUTHOR("Ani Joshi");
3166MODULE_DESCRIPTION("framebuffer driver for ATI Radeon chipset");
3167MODULE_LICENSE("GPL");
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index f841f013b96f..3e9308f0f165 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -49,6 +49,7 @@
49#include <asm/pci-bridge.h> 49#include <asm/pci-bridge.h>
50#endif 50#endif
51#ifdef CONFIG_PMAC_BACKLIGHT 51#ifdef CONFIG_PMAC_BACKLIGHT
52#include <asm/machdep.h>
52#include <asm/backlight.h> 53#include <asm/backlight.h>
53#endif 54#endif
54 55
@@ -1247,7 +1248,7 @@ static int rivafb_blank(int blank, struct fb_info *info)
1247 CRTCout(par, 0x1a, vesa); 1248 CRTCout(par, 0x1a, vesa);
1248 1249
1249#ifdef CONFIG_PMAC_BACKLIGHT 1250#ifdef CONFIG_PMAC_BACKLIGHT
1250 if ( par->FlatPanel && _machine == _MACH_Pmac) { 1251 if ( par->FlatPanel && machine_is(powermac)) {
1251 set_backlight_enable(!blank); 1252 set_backlight_enable(!blank);
1252 } 1253 }
1253#endif 1254#endif
@@ -2037,9 +2038,9 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
2037 info->fix.smem_len / (1024 * 1024), 2038 info->fix.smem_len / (1024 * 1024),
2038 info->fix.smem_start); 2039 info->fix.smem_start);
2039#ifdef CONFIG_PMAC_BACKLIGHT 2040#ifdef CONFIG_PMAC_BACKLIGHT
2040 if (default_par->FlatPanel && _machine == _MACH_Pmac) 2041 if (default_par->FlatPanel && machine_is(powermac))
2041 register_backlight_controller(&riva_backlight_controller, 2042 register_backlight_controller(&riva_backlight_controller,
2042 default_par, "mnca"); 2043 default_par, "mnca");
2043#endif 2044#endif
2044 NVTRACE_LEAVE(); 2045 NVTRACE_LEAVE();
2045 return 0; 2046 return 0;
diff --git a/drivers/video/sticore.h b/drivers/video/sticore.h
index dc93336af557..1a9a60c74be3 100644
--- a/drivers/video/sticore.h
+++ b/drivers/video/sticore.h
@@ -34,36 +34,20 @@
34 * for them to fix it and steal their solution. prumpf 34 * for them to fix it and steal their solution. prumpf
35 */ 35 */
36 36
37#define STI_WAIT 1 37#include <asm/io.h>
38
39#include <asm/io.h> /* for USE_HPPA_IOREMAP */
40
41#if USE_HPPA_IOREMAP
42 38
43#define STI_PTR(p) (p) 39#define STI_WAIT 1
44#define PTR_STI(p) (p)
45static inline int STI_CALL( unsigned long func,
46 void *flags, void *inptr, void *outptr, void *glob_cfg )
47{
48 int (*f)(void *,void *,void *,void *);
49 f = (void*)func;
50 return f(flags, inptr, outptr, glob_cfg);
51}
52
53#else /* !USE_HPPA_IOREMAP */
54 40
55#define STI_PTR(p) ( virt_to_phys(p) ) 41#define STI_PTR(p) ( virt_to_phys(p) )
56#define PTR_STI(p) ( phys_to_virt((long)p) ) 42#define PTR_STI(p) ( phys_to_virt((unsigned long)p) )
57#define STI_CALL(func, flags, inptr, outptr, glob_cfg) \ 43#define STI_CALL(func, flags, inptr, outptr, glob_cfg) \
58 ({ \ 44 ({ \
59 pdc_sti_call( func, (unsigned long)STI_PTR(flags), \ 45 pdc_sti_call( func, STI_PTR(flags), \
60 (unsigned long)STI_PTR(inptr), \ 46 STI_PTR(inptr), \
61 (unsigned long)STI_PTR(outptr), \ 47 STI_PTR(outptr), \
62 (unsigned long)STI_PTR(glob_cfg)); \ 48 STI_PTR(glob_cfg)); \
63 }) 49 })
64 50
65#endif /* USE_HPPA_IOREMAP */
66
67 51
68#define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x) 52#define sti_onscreen_x(sti) (sti->glob_cfg->onscreen_x)
69#define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y) 53#define sti_onscreen_y(sti) (sti->glob_cfg->onscreen_y)
@@ -352,8 +336,9 @@ struct sti_struct {
352 struct sti_conf_outptr outptr; /* configuration */ 336 struct sti_conf_outptr outptr; /* configuration */
353 struct sti_conf_outptr_ext outptr_ext; 337 struct sti_conf_outptr_ext outptr_ext;
354 338
355 /* PCI data structures (pg. 17ff from sti.pdf) */
356 struct pci_dev *pd; 339 struct pci_dev *pd;
340
341 /* PCI data structures (pg. 17ff from sti.pdf) */
357 u8 rm_entry[16]; /* pci region mapper array == pci config space offset */ 342 u8 rm_entry[16]; /* pci region mapper array == pci config space offset */
358 343
359 /* pointer to the fb_info where this STI device is used */ 344 /* pointer to the fb_info where this STI device is used */
diff --git a/drivers/video/stifb.c b/drivers/video/stifb.c
index 56d71d6e9a72..4a292aae6eb2 100644
--- a/drivers/video/stifb.c
+++ b/drivers/video/stifb.c
@@ -3,7 +3,7 @@
3 * Low level Frame buffer driver for HP workstations with 3 * Low level Frame buffer driver for HP workstations with
4 * STI (standard text interface) video firmware. 4 * STI (standard text interface) video firmware.
5 * 5 *
6 * Copyright (C) 2001-2005 Helge Deller <deller@gmx.de> 6 * Copyright (C) 2001-2006 Helge Deller <deller@gmx.de>
7 * Portions Copyright (C) 2001 Thomas Bogendoerfer <tsbogend@alpha.franken.de> 7 * Portions Copyright (C) 2001 Thomas Bogendoerfer <tsbogend@alpha.franken.de>
8 * 8 *
9 * Based on: 9 * Based on:
@@ -514,7 +514,7 @@ rattlerSetupPlanes(struct stifb_info *fb)
514 SETUP_HW(fb); 514 SETUP_HW(fb);
515 WRITE_BYTE(1, fb, REG_16b1); 515 WRITE_BYTE(1, fb, REG_16b1);
516 516
517 fb_memset(fb->info.fix.smem_start, 0xff, 517 fb_memset((void*)fb->info.fix.smem_start, 0xff,
518 fb->info.var.yres*fb->info.fix.line_length); 518 fb->info.var.yres*fb->info.fix.line_length);
519 519
520 CRX24_SET_OVLY_MASK(fb); 520 CRX24_SET_OVLY_MASK(fb);
@@ -908,83 +908,6 @@ SETUP_HCRX(struct stifb_info *fb)
908 908
909/* ------------------- driver specific functions --------------------------- */ 909/* ------------------- driver specific functions --------------------------- */
910 910
911#define TMPBUFLEN 2048
912
913static ssize_t
914stifb_read(struct file *file, char *buf, size_t count, loff_t *ppos)
915{
916 unsigned long p = *ppos;
917 struct inode *inode = file->f_dentry->d_inode;
918 int fbidx = iminor(inode);
919 struct fb_info *info = registered_fb[fbidx];
920 char tmpbuf[TMPBUFLEN];
921
922 if (!info || ! info->screen_base)
923 return -ENODEV;
924
925 if (p >= info->fix.smem_len)
926 return 0;
927 if (count >= info->fix.smem_len)
928 count = info->fix.smem_len;
929 if (count + p > info->fix.smem_len)
930 count = info->fix.smem_len - p;
931 if (count > sizeof(tmpbuf))
932 count = sizeof(tmpbuf);
933 if (count) {
934 char *base_addr;
935
936 base_addr = info->screen_base;
937 memcpy_fromio(&tmpbuf, base_addr+p, count);
938 count -= copy_to_user(buf, &tmpbuf, count);
939 if (!count)
940 return -EFAULT;
941 *ppos += count;
942 }
943 return count;
944}
945
946static ssize_t
947stifb_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
948{
949 struct inode *inode = file->f_dentry->d_inode;
950 int fbidx = iminor(inode);
951 struct fb_info *info = registered_fb[fbidx];
952 unsigned long p = *ppos;
953 size_t c;
954 int err;
955 char tmpbuf[TMPBUFLEN];
956
957 if (!info || !info->screen_base)
958 return -ENODEV;
959
960 if (p > info->fix.smem_len)
961 return -ENOSPC;
962 if (count >= info->fix.smem_len)
963 count = info->fix.smem_len;
964 err = 0;
965 if (count + p > info->fix.smem_len) {
966 count = info->fix.smem_len - p;
967 err = -ENOSPC;
968 }
969
970 p += (unsigned long)info->screen_base;
971 c = count;
972 while (c) {
973 int len = c > sizeof(tmpbuf) ? sizeof(tmpbuf) : c;
974 err = -EFAULT;
975 if (copy_from_user(&tmpbuf, buf, len))
976 break;
977 memcpy_toio(p, &tmpbuf, len);
978 c -= len;
979 p += len;
980 buf += len;
981 *ppos += len;
982 }
983 if (count-c)
984 return (count-c);
985 return err;
986}
987
988static int 911static int
989stifb_setcolreg(u_int regno, u_int red, u_int green, 912stifb_setcolreg(u_int regno, u_int red, u_int green,
990 u_int blue, u_int transp, struct fb_info *info) 913 u_int blue, u_int transp, struct fb_info *info)
@@ -1137,8 +1060,6 @@ stifb_init_display(struct stifb_info *fb)
1137 1060
1138static struct fb_ops stifb_ops = { 1061static struct fb_ops stifb_ops = {
1139 .owner = THIS_MODULE, 1062 .owner = THIS_MODULE,
1140 .fb_read = stifb_read,
1141 .fb_write = stifb_write,
1142 .fb_setcolreg = stifb_setcolreg, 1063 .fb_setcolreg = stifb_setcolreg,
1143 .fb_blank = stifb_blank, 1064 .fb_blank = stifb_blank,
1144 .fb_fillrect = cfb_fillrect, 1065 .fb_fillrect = cfb_fillrect,
@@ -1162,7 +1083,7 @@ stifb_init_fb(struct sti_struct *sti, int bpp_pref)
1162 char *dev_name; 1083 char *dev_name;
1163 int bpp, xres, yres; 1084 int bpp, xres, yres;
1164 1085
1165 fb = kmalloc(sizeof(*fb), GFP_ATOMIC); 1086 fb = kzalloc(sizeof(*fb), GFP_ATOMIC);
1166 if (!fb) { 1087 if (!fb) {
1167 printk(KERN_ERR "stifb: Could not allocate stifb structure\n"); 1088 printk(KERN_ERR "stifb: Could not allocate stifb structure\n");
1168 return -ENODEV; 1089 return -ENODEV;
@@ -1171,7 +1092,6 @@ stifb_init_fb(struct sti_struct *sti, int bpp_pref)
1171 info = &fb->info; 1092 info = &fb->info;
1172 1093
1173 /* set struct to a known state */ 1094 /* set struct to a known state */
1174 memset(fb, 0, sizeof(*fb));
1175 fix = &info->fix; 1095 fix = &info->fix;
1176 var = &info->var; 1096 var = &info->var;
1177 1097
@@ -1234,7 +1154,7 @@ stifb_init_fb(struct sti_struct *sti, int bpp_pref)
1234 case S9000_ID_TOMCAT: /* Dual CRX, behaves else like a CRX */ 1154 case S9000_ID_TOMCAT: /* Dual CRX, behaves else like a CRX */
1235 /* FIXME: TomCat supports two heads: 1155 /* FIXME: TomCat supports two heads:
1236 * fb.iobase = REGION_BASE(fb_info,3); 1156 * fb.iobase = REGION_BASE(fb_info,3);
1237 * fb.screen_base = (void*) REGION_BASE(fb_info,2); 1157 * fb.screen_base = ioremap_nocache(REGION_BASE(fb_info,2),xxx);
1238 * for now we only support the left one ! */ 1158 * for now we only support the left one ! */
1239 xres = fb->ngle_rom.x_size_visible; 1159 xres = fb->ngle_rom.x_size_visible;
1240 yres = fb->ngle_rom.y_size_visible; 1160 yres = fb->ngle_rom.y_size_visible;
@@ -1327,7 +1247,8 @@ stifb_init_fb(struct sti_struct *sti, int bpp_pref)
1327 1247
1328 strcpy(fix->id, "stifb"); 1248 strcpy(fix->id, "stifb");
1329 info->fbops = &stifb_ops; 1249 info->fbops = &stifb_ops;
1330 info->screen_base = (void*) REGION_BASE(fb,1); 1250 info->screen_base = ioremap_nocache(REGION_BASE(fb,1), fix->smem_len);
1251 info->screen_size = fix->smem_len;
1331 info->flags = FBINFO_DEFAULT; 1252 info->flags = FBINFO_DEFAULT;
1332 info->pseudo_palette = &fb->pseudo_palette; 1253 info->pseudo_palette = &fb->pseudo_palette;
1333 1254
@@ -1457,7 +1378,7 @@ stifb_setup(char *options)
1457 int i; 1378 int i;
1458 1379
1459 if (!options || !*options) 1380 if (!options || !*options)
1460 return 0; 1381 return 1;
1461 1382
1462 if (strncmp(options, "off", 3) == 0) { 1383 if (strncmp(options, "off", 3) == 0) {
1463 stifb_disabled = 1; 1384 stifb_disabled = 1;
@@ -1472,7 +1393,7 @@ stifb_setup(char *options)
1472 stifb_bpp_pref[i] = simple_strtoul(options, &options, 10); 1393 stifb_bpp_pref[i] = simple_strtoul(options, &options, 10);
1473 } 1394 }
1474 } 1395 }
1475 return 0; 1396 return 1;
1476} 1397}
1477 1398
1478__setup("stifb=", stifb_setup); 1399__setup("stifb=", stifb_setup);
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index 8982e540214c..b0b9acfdd430 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -57,7 +57,7 @@ static unsigned short *pmi_base = NULL;
57static void (*pmi_start)(void); 57static void (*pmi_start)(void);
58static void (*pmi_pal)(void); 58static void (*pmi_pal)(void);
59static int depth; 59static int depth;
60 60static int vga_compat;
61/* --------------------------------------------------------------------- */ 61/* --------------------------------------------------------------------- */
62 62
63static int vesafb_pan_display(struct fb_var_screeninfo *var, 63static int vesafb_pan_display(struct fb_var_screeninfo *var,
@@ -83,9 +83,10 @@ static int vesafb_pan_display(struct fb_var_screeninfo *var,
83static void vesa_setpalette(int regno, unsigned red, unsigned green, 83static void vesa_setpalette(int regno, unsigned red, unsigned green,
84 unsigned blue) 84 unsigned blue)
85{ 85{
86 int shift = 16 - depth;
87
86#ifdef __i386__ 88#ifdef __i386__
87 struct { u_char blue, green, red, pad; } entry; 89 struct { u_char blue, green, red, pad; } entry;
88 int shift = 16 - depth;
89 90
90 if (pmi_setpal) { 91 if (pmi_setpal) {
91 entry.red = red >> shift; 92 entry.red = red >> shift;
@@ -101,14 +102,20 @@ static void vesa_setpalette(int regno, unsigned red, unsigned green,
101 "d" (regno), /* EDX */ 102 "d" (regno), /* EDX */
102 "D" (&entry), /* EDI */ 103 "D" (&entry), /* EDI */
103 "S" (&pmi_pal)); /* ESI */ 104 "S" (&pmi_pal)); /* ESI */
104 } else { 105 return;
105 /* without protected mode interface, try VGA registers... */ 106 }
107#endif
108
109/*
110 * without protected mode interface and if VGA compatible,
111 * try VGA registers...
112 */
113 if (vga_compat) {
106 outb_p(regno, dac_reg); 114 outb_p(regno, dac_reg);
107 outb_p(red >> shift, dac_val); 115 outb_p(red >> shift, dac_val);
108 outb_p(green >> shift, dac_val); 116 outb_p(green >> shift, dac_val);
109 outb_p(blue >> shift, dac_val); 117 outb_p(blue >> shift, dac_val);
110 } 118 }
111#endif
112} 119}
113 120
114static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green, 121static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
@@ -214,6 +221,7 @@ static int __init vesafb_probe(struct platform_device *dev)
214 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) 221 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
215 return -ENODEV; 222 return -ENODEV;
216 223
224 vga_compat = (screen_info.capabilities & 2) ? 0 : 1;
217 vesafb_fix.smem_start = screen_info.lfb_base; 225 vesafb_fix.smem_start = screen_info.lfb_base;
218 vesafb_defined.bits_per_pixel = screen_info.lfb_depth; 226 vesafb_defined.bits_per_pixel = screen_info.lfb_depth;
219 if (15 == vesafb_defined.bits_per_pixel) 227 if (15 == vesafb_defined.bits_per_pixel)
@@ -318,6 +326,12 @@ static int __init vesafb_probe(struct platform_device *dev)
318 } 326 }
319 } 327 }
320 328
329 if (vesafb_defined.bits_per_pixel == 8 && !pmi_setpal && !vga_compat) {
330 printk(KERN_WARNING "vesafb: hardware palette is unchangeable,\n"
331 " colors may be incorrect\n");
332 vesafb_fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR;
333 }
334
321 vesafb_defined.xres_virtual = vesafb_defined.xres; 335 vesafb_defined.xres_virtual = vesafb_defined.xres;
322 vesafb_defined.yres_virtual = vesafb_fix.smem_len / vesafb_fix.line_length; 336 vesafb_defined.yres_virtual = vesafb_fix.smem_len / vesafb_fix.line_length;
323 if (ypan && vesafb_defined.yres_virtual > vesafb_defined.yres) { 337 if (ypan && vesafb_defined.yres_virtual > vesafb_defined.yres) {
@@ -354,7 +368,8 @@ static int __init vesafb_probe(struct platform_device *dev)
354 printk(KERN_INFO "vesafb: %s: " 368 printk(KERN_INFO "vesafb: %s: "
355 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", 369 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
356 (vesafb_defined.bits_per_pixel > 8) ? 370 (vesafb_defined.bits_per_pixel > 8) ?
357 "Truecolor" : "Pseudocolor", 371 "Truecolor" : (vga_compat || pmi_setpal) ?
372 "Pseudocolor" : "Static Pseudocolor",
358 screen_info.rsvd_size, 373 screen_info.rsvd_size,
359 screen_info.red_size, 374 screen_info.red_size,
360 screen_info.green_size, 375 screen_info.green_size,
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index f6e24ee85f07..5fc86ea20692 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -4,8 +4,9 @@
4 * Frame Buffer Device for ATI Imageon w100 (Wallaby) 4 * Frame Buffer Device for ATI Imageon w100 (Wallaby)
5 * 5 *
6 * Copyright (C) 2002, ATI Corp. 6 * Copyright (C) 2002, ATI Corp.
7 * Copyright (C) 2004-2005 Richard Purdie 7 * Copyright (C) 2004-2006 Richard Purdie
8 * Copyright (c) 2005 Ian Molton 8 * Copyright (c) 2005 Ian Molton
9 * Copyright (c) 2006 Alberto Mardegan
9 * 10 *
10 * Rewritten for 2.6 by Richard Purdie <rpurdie@rpsys.net> 11 * Rewritten for 2.6 by Richard Purdie <rpurdie@rpsys.net>
11 * 12 *
@@ -14,6 +15,9 @@
14 * 15 *
15 * w32xx support by Ian Molton 16 * w32xx support by Ian Molton
16 * 17 *
18 * Hardware acceleration support by Alberto Mardegan
19 * <mardy@users.sourceforge.net>
20 *
17 * This program is free software; you can redistribute it and/or modify 21 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as 22 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation. 23 * published by the Free Software Foundation.
@@ -47,6 +51,7 @@ static void w100_set_dispregs(struct w100fb_par*);
47static void w100_update_enable(void); 51static void w100_update_enable(void);
48static void w100_update_disable(void); 52static void w100_update_disable(void);
49static void calc_hsync(struct w100fb_par *par); 53static void calc_hsync(struct w100fb_par *par);
54static void w100_init_graphic_engine(struct w100fb_par *par);
50struct w100_pll_info *w100_get_xtal_table(unsigned int freq); 55struct w100_pll_info *w100_get_xtal_table(unsigned int freq);
51 56
52/* Pseudo palette size */ 57/* Pseudo palette size */
@@ -248,6 +253,152 @@ static int w100fb_blank(int blank_mode, struct fb_info *info)
248} 253}
249 254
250 255
256static void w100_fifo_wait(int entries)
257{
258 union rbbm_status_u status;
259 int i;
260
261 for (i = 0; i < 2000000; i++) {
262 status.val = readl(remapped_regs + mmRBBM_STATUS);
263 if (status.f.cmdfifo_avail >= entries)
264 return;
265 udelay(1);
266 }
267 printk(KERN_ERR "w100fb: FIFO Timeout!\n");
268}
269
270
271static int w100fb_sync(struct fb_info *info)
272{
273 union rbbm_status_u status;
274 int i;
275
276 for (i = 0; i < 2000000; i++) {
277 status.val = readl(remapped_regs + mmRBBM_STATUS);
278 if (!status.f.gui_active)
279 return 0;
280 udelay(1);
281 }
282 printk(KERN_ERR "w100fb: Graphic engine timeout!\n");
283 return -EBUSY;
284}
285
286
287static void w100_init_graphic_engine(struct w100fb_par *par)
288{
289 union dp_gui_master_cntl_u gmc;
290 union dp_mix_u dp_mix;
291 union dp_datatype_u dp_datatype;
292 union dp_cntl_u dp_cntl;
293
294 w100_fifo_wait(4);
295 writel(W100_FB_BASE, remapped_regs + mmDST_OFFSET);
296 writel(par->xres, remapped_regs + mmDST_PITCH);
297 writel(W100_FB_BASE, remapped_regs + mmSRC_OFFSET);
298 writel(par->xres, remapped_regs + mmSRC_PITCH);
299
300 w100_fifo_wait(3);
301 writel(0, remapped_regs + mmSC_TOP_LEFT);
302 writel((par->yres << 16) | par->xres, remapped_regs + mmSC_BOTTOM_RIGHT);
303 writel(0x1fff1fff, remapped_regs + mmSRC_SC_BOTTOM_RIGHT);
304
305 w100_fifo_wait(4);
306 dp_cntl.val = 0;
307 dp_cntl.f.dst_x_dir = 1;
308 dp_cntl.f.dst_y_dir = 1;
309 dp_cntl.f.src_x_dir = 1;
310 dp_cntl.f.src_y_dir = 1;
311 dp_cntl.f.dst_major_x = 1;
312 dp_cntl.f.src_major_x = 1;
313 writel(dp_cntl.val, remapped_regs + mmDP_CNTL);
314
315 gmc.val = 0;
316 gmc.f.gmc_src_pitch_offset_cntl = 1;
317 gmc.f.gmc_dst_pitch_offset_cntl = 1;
318 gmc.f.gmc_src_clipping = 1;
319 gmc.f.gmc_dst_clipping = 1;
320 gmc.f.gmc_brush_datatype = GMC_BRUSH_NONE;
321 gmc.f.gmc_dst_datatype = 3; /* from DstType_16Bpp_444 */
322 gmc.f.gmc_src_datatype = SRC_DATATYPE_EQU_DST;
323 gmc.f.gmc_byte_pix_order = 1;
324 gmc.f.gmc_default_sel = 0;
325 gmc.f.gmc_rop3 = ROP3_SRCCOPY;
326 gmc.f.gmc_dp_src_source = DP_SRC_MEM_RECTANGULAR;
327 gmc.f.gmc_clr_cmp_fcn_dis = 1;
328 gmc.f.gmc_wr_msk_dis = 1;
329 gmc.f.gmc_dp_op = DP_OP_ROP;
330 writel(gmc.val, remapped_regs + mmDP_GUI_MASTER_CNTL);
331
332 dp_datatype.val = dp_mix.val = 0;
333 dp_datatype.f.dp_dst_datatype = gmc.f.gmc_dst_datatype;
334 dp_datatype.f.dp_brush_datatype = gmc.f.gmc_brush_datatype;
335 dp_datatype.f.dp_src2_type = 0;
336 dp_datatype.f.dp_src2_datatype = gmc.f.gmc_src_datatype;
337 dp_datatype.f.dp_src_datatype = gmc.f.gmc_src_datatype;
338 dp_datatype.f.dp_byte_pix_order = gmc.f.gmc_byte_pix_order;
339 writel(dp_datatype.val, remapped_regs + mmDP_DATATYPE);
340
341 dp_mix.f.dp_src_source = gmc.f.gmc_dp_src_source;
342 dp_mix.f.dp_src2_source = 1;
343 dp_mix.f.dp_rop3 = gmc.f.gmc_rop3;
344 dp_mix.f.dp_op = gmc.f.gmc_dp_op;
345 writel(dp_mix.val, remapped_regs + mmDP_MIX);
346}
347
348
349static void w100fb_fillrect(struct fb_info *info,
350 const struct fb_fillrect *rect)
351{
352 union dp_gui_master_cntl_u gmc;
353
354 if (info->state != FBINFO_STATE_RUNNING)
355 return;
356 if (info->flags & FBINFO_HWACCEL_DISABLED) {
357 cfb_fillrect(info, rect);
358 return;
359 }
360
361 gmc.val = readl(remapped_regs + mmDP_GUI_MASTER_CNTL);
362 gmc.f.gmc_rop3 = ROP3_PATCOPY;
363 gmc.f.gmc_brush_datatype = GMC_BRUSH_SOLID_COLOR;
364 w100_fifo_wait(2);
365 writel(gmc.val, remapped_regs + mmDP_GUI_MASTER_CNTL);
366 writel(rect->color, remapped_regs + mmDP_BRUSH_FRGD_CLR);
367
368 w100_fifo_wait(2);
369 writel((rect->dy << 16) | (rect->dx & 0xffff), remapped_regs + mmDST_Y_X);
370 writel((rect->width << 16) | (rect->height & 0xffff),
371 remapped_regs + mmDST_WIDTH_HEIGHT);
372}
373
374
375static void w100fb_copyarea(struct fb_info *info,
376 const struct fb_copyarea *area)
377{
378 u32 dx = area->dx, dy = area->dy, sx = area->sx, sy = area->sy;
379 u32 h = area->height, w = area->width;
380 union dp_gui_master_cntl_u gmc;
381
382 if (info->state != FBINFO_STATE_RUNNING)
383 return;
384 if (info->flags & FBINFO_HWACCEL_DISABLED) {
385 cfb_copyarea(info, area);
386 return;
387 }
388
389 gmc.val = readl(remapped_regs + mmDP_GUI_MASTER_CNTL);
390 gmc.f.gmc_rop3 = ROP3_SRCCOPY;
391 gmc.f.gmc_brush_datatype = GMC_BRUSH_NONE;
392 w100_fifo_wait(1);
393 writel(gmc.val, remapped_regs + mmDP_GUI_MASTER_CNTL);
394
395 w100_fifo_wait(3);
396 writel((sy << 16) | (sx & 0xffff), remapped_regs + mmSRC_Y_X);
397 writel((dy << 16) | (dx & 0xffff), remapped_regs + mmDST_Y_X);
398 writel((w << 16) | (h & 0xffff), remapped_regs + mmDST_WIDTH_HEIGHT);
399}
400
401
251/* 402/*
252 * Change the resolution by calling the appropriate hardware functions 403 * Change the resolution by calling the appropriate hardware functions
253 */ 404 */
@@ -265,6 +416,7 @@ static void w100fb_activate_var(struct w100fb_par *par)
265 w100_init_lcd(par); 416 w100_init_lcd(par);
266 w100_set_dispregs(par); 417 w100_set_dispregs(par);
267 w100_update_enable(); 418 w100_update_enable();
419 w100_init_graphic_engine(par);
268 420
269 calc_hsync(par); 421 calc_hsync(par);
270 422
@@ -394,9 +546,10 @@ static struct fb_ops w100fb_ops = {
394 .fb_set_par = w100fb_set_par, 546 .fb_set_par = w100fb_set_par,
395 .fb_setcolreg = w100fb_setcolreg, 547 .fb_setcolreg = w100fb_setcolreg,
396 .fb_blank = w100fb_blank, 548 .fb_blank = w100fb_blank,
397 .fb_fillrect = cfb_fillrect, 549 .fb_fillrect = w100fb_fillrect,
398 .fb_copyarea = cfb_copyarea, 550 .fb_copyarea = w100fb_copyarea,
399 .fb_imageblit = cfb_imageblit, 551 .fb_imageblit = cfb_imageblit,
552 .fb_sync = w100fb_sync,
400}; 553};
401 554
402#ifdef CONFIG_PM 555#ifdef CONFIG_PM
@@ -543,7 +696,8 @@ int __init w100fb_probe(struct platform_device *pdev)
543 } 696 }
544 697
545 info->fbops = &w100fb_ops; 698 info->fbops = &w100fb_ops;
546 info->flags = FBINFO_DEFAULT; 699 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
700 FBINFO_HWACCEL_FILLRECT;
547 info->node = -1; 701 info->node = -1;
548 info->screen_base = remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE); 702 info->screen_base = remapped_fbuf + (W100_FB_BASE-MEM_WINDOW_BASE);
549 info->screen_size = REMAPPED_FB_LEN; 703 info->screen_size = REMAPPED_FB_LEN;
diff --git a/drivers/video/w100fb.h b/drivers/video/w100fb.h
index 7a58a1e3e427..fffae7b4f6e9 100644
--- a/drivers/video/w100fb.h
+++ b/drivers/video/w100fb.h
@@ -122,15 +122,32 @@
122/* Block DISPLAY End: */ 122/* Block DISPLAY End: */
123 123
124/* Block GFX Start: */ 124/* Block GFX Start: */
125#define mmDST_OFFSET 0x1004
126#define mmDST_PITCH 0x1008
127#define mmDST_Y_X 0x1038
128#define mmDST_WIDTH_HEIGHT 0x1198
129#define mmDP_GUI_MASTER_CNTL 0x106C
125#define mmBRUSH_OFFSET 0x108C 130#define mmBRUSH_OFFSET 0x108C
126#define mmBRUSH_Y_X 0x1074 131#define mmBRUSH_Y_X 0x1074
132#define mmDP_BRUSH_FRGD_CLR 0x107C
133#define mmSRC_OFFSET 0x11AC
134#define mmSRC_PITCH 0x11B0
135#define mmSRC_Y_X 0x1034
127#define mmDEFAULT_PITCH_OFFSET 0x10A0 136#define mmDEFAULT_PITCH_OFFSET 0x10A0
128#define mmDEFAULT_SC_BOTTOM_RIGHT 0x10A8 137#define mmDEFAULT_SC_BOTTOM_RIGHT 0x10A8
129#define mmDEFAULT2_SC_BOTTOM_RIGHT 0x10AC 138#define mmDEFAULT2_SC_BOTTOM_RIGHT 0x10AC
139#define mmSC_TOP_LEFT 0x11BC
140#define mmSC_BOTTOM_RIGHT 0x11C0
141#define mmSRC_SC_BOTTOM_RIGHT 0x11C4
130#define mmGLOBAL_ALPHA 0x1210 142#define mmGLOBAL_ALPHA 0x1210
131#define mmFILTER_COEF 0x1214 143#define mmFILTER_COEF 0x1214
132#define mmMVC_CNTL_START 0x11E0 144#define mmMVC_CNTL_START 0x11E0
133#define mmE2_ARITHMETIC_CNTL 0x1220 145#define mmE2_ARITHMETIC_CNTL 0x1220
146#define mmDP_CNTL 0x11C8
147#define mmDP_CNTL_DST_DIR 0x11CC
148#define mmDP_DATATYPE 0x12C4
149#define mmDP_MIX 0x12C8
150#define mmDP_WRITE_MSK 0x12CC
134#define mmENG_CNTL 0x13E8 151#define mmENG_CNTL 0x13E8
135#define mmENG_PERF_CNT 0x13F0 152#define mmENG_PERF_CNT 0x13F0
136/* Block GFX End: */ 153/* Block GFX End: */
@@ -179,6 +196,7 @@
179/* Block RBBM Start: */ 196/* Block RBBM Start: */
180#define mmWAIT_UNTIL 0x1400 197#define mmWAIT_UNTIL 0x1400
181#define mmISYNC_CNTL 0x1404 198#define mmISYNC_CNTL 0x1404
199#define mmRBBM_STATUS 0x0140
182#define mmRBBM_CNTL 0x0144 200#define mmRBBM_CNTL 0x0144
183#define mmNQWAIT_UNTIL 0x0150 201#define mmNQWAIT_UNTIL 0x0150
184/* Block RBBM End: */ 202/* Block RBBM End: */
@@ -225,147 +243,147 @@
225/* Register structure definitions */ 243/* Register structure definitions */
226 244
227struct wrap_top_dir_t { 245struct wrap_top_dir_t {
228 unsigned long top_addr : 23; 246 u32 top_addr : 23;
229 unsigned long : 9; 247 u32 : 9;
230} __attribute__((packed)); 248} __attribute__((packed));
231 249
232union wrap_top_dir_u { 250union wrap_top_dir_u {
233 unsigned long val : 32; 251 u32 val : 32;
234 struct wrap_top_dir_t f; 252 struct wrap_top_dir_t f;
235} __attribute__((packed)); 253} __attribute__((packed));
236 254
237struct wrap_start_dir_t { 255struct wrap_start_dir_t {
238 unsigned long start_addr : 23; 256 u32 start_addr : 23;
239 unsigned long : 9; 257 u32 : 9;
240} __attribute__((packed)); 258} __attribute__((packed));
241 259
242union wrap_start_dir_u { 260union wrap_start_dir_u {
243 unsigned long val : 32; 261 u32 val : 32;
244 struct wrap_start_dir_t f; 262 struct wrap_start_dir_t f;
245} __attribute__((packed)); 263} __attribute__((packed));
246 264
247struct cif_cntl_t { 265struct cif_cntl_t {
248 unsigned long swap_reg : 2; 266 u32 swap_reg : 2;
249 unsigned long swap_fbuf_1 : 2; 267 u32 swap_fbuf_1 : 2;
250 unsigned long swap_fbuf_2 : 2; 268 u32 swap_fbuf_2 : 2;
251 unsigned long swap_fbuf_3 : 2; 269 u32 swap_fbuf_3 : 2;
252 unsigned long pmi_int_disable : 1; 270 u32 pmi_int_disable : 1;
253 unsigned long pmi_schmen_disable : 1; 271 u32 pmi_schmen_disable : 1;
254 unsigned long intb_oe : 1; 272 u32 intb_oe : 1;
255 unsigned long en_wait_to_compensate_dq_prop_dly : 1; 273 u32 en_wait_to_compensate_dq_prop_dly : 1;
256 unsigned long compensate_wait_rd_size : 2; 274 u32 compensate_wait_rd_size : 2;
257 unsigned long wait_asserted_timeout_val : 2; 275 u32 wait_asserted_timeout_val : 2;
258 unsigned long wait_masked_val : 2; 276 u32 wait_masked_val : 2;
259 unsigned long en_wait_timeout : 1; 277 u32 en_wait_timeout : 1;
260 unsigned long en_one_clk_setup_before_wait : 1; 278 u32 en_one_clk_setup_before_wait : 1;
261 unsigned long interrupt_active_high : 1; 279 u32 interrupt_active_high : 1;
262 unsigned long en_overwrite_straps : 1; 280 u32 en_overwrite_straps : 1;
263 unsigned long strap_wait_active_hi : 1; 281 u32 strap_wait_active_hi : 1;
264 unsigned long lat_busy_count : 2; 282 u32 lat_busy_count : 2;
265 unsigned long lat_rd_pm4_sclk_busy : 1; 283 u32 lat_rd_pm4_sclk_busy : 1;
266 unsigned long dis_system_bits : 1; 284 u32 dis_system_bits : 1;
267 unsigned long dis_mr : 1; 285 u32 dis_mr : 1;
268 unsigned long cif_spare_1 : 4; 286 u32 cif_spare_1 : 4;
269} __attribute__((packed)); 287} __attribute__((packed));
270 288
271union cif_cntl_u { 289union cif_cntl_u {
272 unsigned long val : 32; 290 u32 val : 32;
273 struct cif_cntl_t f; 291 struct cif_cntl_t f;
274} __attribute__((packed)); 292} __attribute__((packed));
275 293
276struct cfgreg_base_t { 294struct cfgreg_base_t {
277 unsigned long cfgreg_base : 24; 295 u32 cfgreg_base : 24;
278 unsigned long : 8; 296 u32 : 8;
279} __attribute__((packed)); 297} __attribute__((packed));
280 298
281union cfgreg_base_u { 299union cfgreg_base_u {
282 unsigned long val : 32; 300 u32 val : 32;
283 struct cfgreg_base_t f; 301 struct cfgreg_base_t f;
284} __attribute__((packed)); 302} __attribute__((packed));
285 303
286struct cif_io_t { 304struct cif_io_t {
287 unsigned long dq_srp : 1; 305 u32 dq_srp : 1;
288 unsigned long dq_srn : 1; 306 u32 dq_srn : 1;
289 unsigned long dq_sp : 4; 307 u32 dq_sp : 4;
290 unsigned long dq_sn : 4; 308 u32 dq_sn : 4;
291 unsigned long waitb_srp : 1; 309 u32 waitb_srp : 1;
292 unsigned long waitb_srn : 1; 310 u32 waitb_srn : 1;
293 unsigned long waitb_sp : 4; 311 u32 waitb_sp : 4;
294 unsigned long waitb_sn : 4; 312 u32 waitb_sn : 4;
295 unsigned long intb_srp : 1; 313 u32 intb_srp : 1;
296 unsigned long intb_srn : 1; 314 u32 intb_srn : 1;
297 unsigned long intb_sp : 4; 315 u32 intb_sp : 4;
298 unsigned long intb_sn : 4; 316 u32 intb_sn : 4;
299 unsigned long : 2; 317 u32 : 2;
300} __attribute__((packed)); 318} __attribute__((packed));
301 319
302union cif_io_u { 320union cif_io_u {
303 unsigned long val : 32; 321 u32 val : 32;
304 struct cif_io_t f; 322 struct cif_io_t f;
305} __attribute__((packed)); 323} __attribute__((packed));
306 324
307struct cif_read_dbg_t { 325struct cif_read_dbg_t {
308 unsigned long unpacker_pre_fetch_trig_gen : 2; 326 u32 unpacker_pre_fetch_trig_gen : 2;
309 unsigned long dly_second_rd_fetch_trig : 1; 327 u32 dly_second_rd_fetch_trig : 1;
310 unsigned long rst_rd_burst_id : 1; 328 u32 rst_rd_burst_id : 1;
311 unsigned long dis_rd_burst_id : 1; 329 u32 dis_rd_burst_id : 1;
312 unsigned long en_block_rd_when_packer_is_not_emp : 1; 330 u32 en_block_rd_when_packer_is_not_emp : 1;
313 unsigned long dis_pre_fetch_cntl_sm : 1; 331 u32 dis_pre_fetch_cntl_sm : 1;
314 unsigned long rbbm_chrncy_dis : 1; 332 u32 rbbm_chrncy_dis : 1;
315 unsigned long rbbm_rd_after_wr_lat : 2; 333 u32 rbbm_rd_after_wr_lat : 2;
316 unsigned long dis_be_during_rd : 1; 334 u32 dis_be_during_rd : 1;
317 unsigned long one_clk_invalidate_pulse : 1; 335 u32 one_clk_invalidate_pulse : 1;
318 unsigned long dis_chnl_priority : 1; 336 u32 dis_chnl_priority : 1;
319 unsigned long rst_read_path_a_pls : 1; 337 u32 rst_read_path_a_pls : 1;
320 unsigned long rst_read_path_b_pls : 1; 338 u32 rst_read_path_b_pls : 1;
321 unsigned long dis_reg_rd_fetch_trig : 1; 339 u32 dis_reg_rd_fetch_trig : 1;
322 unsigned long dis_rd_fetch_trig_from_ind_addr : 1; 340 u32 dis_rd_fetch_trig_from_ind_addr : 1;
323 unsigned long dis_rd_same_byte_to_trig_fetch : 1; 341 u32 dis_rd_same_byte_to_trig_fetch : 1;
324 unsigned long dis_dir_wrap : 1; 342 u32 dis_dir_wrap : 1;
325 unsigned long dis_ring_buf_to_force_dec : 1; 343 u32 dis_ring_buf_to_force_dec : 1;
326 unsigned long dis_addr_comp_in_16bit : 1; 344 u32 dis_addr_comp_in_16bit : 1;
327 unsigned long clr_w : 1; 345 u32 clr_w : 1;
328 unsigned long err_rd_tag_is_3 : 1; 346 u32 err_rd_tag_is_3 : 1;
329 unsigned long err_load_when_ful_a : 1; 347 u32 err_load_when_ful_a : 1;
330 unsigned long err_load_when_ful_b : 1; 348 u32 err_load_when_ful_b : 1;
331 unsigned long : 7; 349 u32 : 7;
332} __attribute__((packed)); 350} __attribute__((packed));
333 351
334union cif_read_dbg_u { 352union cif_read_dbg_u {
335 unsigned long val : 32; 353 u32 val : 32;
336 struct cif_read_dbg_t f; 354 struct cif_read_dbg_t f;
337} __attribute__((packed)); 355} __attribute__((packed));
338 356
339struct cif_write_dbg_t { 357struct cif_write_dbg_t {
340 unsigned long packer_timeout_count : 2; 358 u32 packer_timeout_count : 2;
341 unsigned long en_upper_load_cond : 1; 359 u32 en_upper_load_cond : 1;
342 unsigned long en_chnl_change_cond : 1; 360 u32 en_chnl_change_cond : 1;
343 unsigned long dis_addr_comp_cond : 1; 361 u32 dis_addr_comp_cond : 1;
344 unsigned long dis_load_same_byte_addr_cond : 1; 362 u32 dis_load_same_byte_addr_cond : 1;
345 unsigned long dis_timeout_cond : 1; 363 u32 dis_timeout_cond : 1;
346 unsigned long dis_timeout_during_rbbm : 1; 364 u32 dis_timeout_during_rbbm : 1;
347 unsigned long dis_packer_ful_during_rbbm_timeout : 1; 365 u32 dis_packer_ful_during_rbbm_timeout : 1;
348 unsigned long en_dword_split_to_rbbm : 1; 366 u32 en_dword_split_to_rbbm : 1;
349 unsigned long en_dummy_val : 1; 367 u32 en_dummy_val : 1;
350 unsigned long dummy_val_sel : 1; 368 u32 dummy_val_sel : 1;
351 unsigned long mask_pm4_wrptr_dec : 1; 369 u32 mask_pm4_wrptr_dec : 1;
352 unsigned long dis_mc_clean_cond : 1; 370 u32 dis_mc_clean_cond : 1;
353 unsigned long err_two_reqi_during_ful : 1; 371 u32 err_two_reqi_during_ful : 1;
354 unsigned long err_reqi_during_idle_clk : 1; 372 u32 err_reqi_during_idle_clk : 1;
355 unsigned long err_global : 1; 373 u32 err_global : 1;
356 unsigned long en_wr_buf_dbg_load : 1; 374 u32 en_wr_buf_dbg_load : 1;
357 unsigned long en_wr_buf_dbg_path : 1; 375 u32 en_wr_buf_dbg_path : 1;
358 unsigned long sel_wr_buf_byte : 3; 376 u32 sel_wr_buf_byte : 3;
359 unsigned long dis_rd_flush_wr : 1; 377 u32 dis_rd_flush_wr : 1;
360 unsigned long dis_packer_ful_cond : 1; 378 u32 dis_packer_ful_cond : 1;
361 unsigned long dis_invalidate_by_ops_chnl : 1; 379 u32 dis_invalidate_by_ops_chnl : 1;
362 unsigned long en_halt_when_reqi_err : 1; 380 u32 en_halt_when_reqi_err : 1;
363 unsigned long cif_spare_2 : 5; 381 u32 cif_spare_2 : 5;
364 unsigned long : 1; 382 u32 : 1;
365} __attribute__((packed)); 383} __attribute__((packed));
366 384
367union cif_write_dbg_u { 385union cif_write_dbg_u {
368 unsigned long val : 32; 386 u32 val : 32;
369 struct cif_write_dbg_t f; 387 struct cif_write_dbg_t f;
370} __attribute__((packed)); 388} __attribute__((packed));
371 389
@@ -403,327 +421,327 @@ union cpu_defaults_u {
403} __attribute__((packed)); 421} __attribute__((packed));
404 422
405struct crtc_total_t { 423struct crtc_total_t {
406 unsigned long crtc_h_total : 10; 424 u32 crtc_h_total : 10;
407 unsigned long : 6; 425 u32 : 6;
408 unsigned long crtc_v_total : 10; 426 u32 crtc_v_total : 10;
409 unsigned long : 6; 427 u32 : 6;
410} __attribute__((packed)); 428} __attribute__((packed));
411 429
412union crtc_total_u { 430union crtc_total_u {
413 unsigned long val : 32; 431 u32 val : 32;
414 struct crtc_total_t f; 432 struct crtc_total_t f;
415} __attribute__((packed)); 433} __attribute__((packed));
416 434
417struct crtc_ss_t { 435struct crtc_ss_t {
418 unsigned long ss_start : 10; 436 u32 ss_start : 10;
419 unsigned long : 6; 437 u32 : 6;
420 unsigned long ss_end : 10; 438 u32 ss_end : 10;
421 unsigned long : 2; 439 u32 : 2;
422 unsigned long ss_align : 1; 440 u32 ss_align : 1;
423 unsigned long ss_pol : 1; 441 u32 ss_pol : 1;
424 unsigned long ss_run_mode : 1; 442 u32 ss_run_mode : 1;
425 unsigned long ss_en : 1; 443 u32 ss_en : 1;
426} __attribute__((packed)); 444} __attribute__((packed));
427 445
428union crtc_ss_u { 446union crtc_ss_u {
429 unsigned long val : 32; 447 u32 val : 32;
430 struct crtc_ss_t f; 448 struct crtc_ss_t f;
431} __attribute__((packed)); 449} __attribute__((packed));
432 450
433struct active_h_disp_t { 451struct active_h_disp_t {
434 unsigned long active_h_start : 10; 452 u32 active_h_start : 10;
435 unsigned long : 6; 453 u32 : 6;
436 unsigned long active_h_end : 10; 454 u32 active_h_end : 10;
437 unsigned long : 6; 455 u32 : 6;
438} __attribute__((packed)); 456} __attribute__((packed));
439 457
440union active_h_disp_u { 458union active_h_disp_u {
441 unsigned long val : 32; 459 u32 val : 32;
442 struct active_h_disp_t f; 460 struct active_h_disp_t f;
443} __attribute__((packed)); 461} __attribute__((packed));
444 462
445struct active_v_disp_t { 463struct active_v_disp_t {
446 unsigned long active_v_start : 10; 464 u32 active_v_start : 10;
447 unsigned long : 6; 465 u32 : 6;
448 unsigned long active_v_end : 10; 466 u32 active_v_end : 10;
449 unsigned long : 6; 467 u32 : 6;
450} __attribute__((packed)); 468} __attribute__((packed));
451 469
452union active_v_disp_u { 470union active_v_disp_u {
453 unsigned long val : 32; 471 u32 val : 32;
454 struct active_v_disp_t f; 472 struct active_v_disp_t f;
455} __attribute__((packed)); 473} __attribute__((packed));
456 474
457struct graphic_h_disp_t { 475struct graphic_h_disp_t {
458 unsigned long graphic_h_start : 10; 476 u32 graphic_h_start : 10;
459 unsigned long : 6; 477 u32 : 6;
460 unsigned long graphic_h_end : 10; 478 u32 graphic_h_end : 10;
461 unsigned long : 6; 479 u32 : 6;
462} __attribute__((packed)); 480} __attribute__((packed));
463 481
464union graphic_h_disp_u { 482union graphic_h_disp_u {
465 unsigned long val : 32; 483 u32 val : 32;
466 struct graphic_h_disp_t f; 484 struct graphic_h_disp_t f;
467} __attribute__((packed)); 485} __attribute__((packed));
468 486
469struct graphic_v_disp_t { 487struct graphic_v_disp_t {
470 unsigned long graphic_v_start : 10; 488 u32 graphic_v_start : 10;
471 unsigned long : 6; 489 u32 : 6;
472 unsigned long graphic_v_end : 10; 490 u32 graphic_v_end : 10;
473 unsigned long : 6; 491 u32 : 6;
474} __attribute__((packed)); 492} __attribute__((packed));
475 493
476union graphic_v_disp_u{ 494union graphic_v_disp_u{
477 unsigned long val : 32; 495 u32 val : 32;
478 struct graphic_v_disp_t f; 496 struct graphic_v_disp_t f;
479} __attribute__((packed)); 497} __attribute__((packed));
480 498
481struct graphic_ctrl_t_w100 { 499struct graphic_ctrl_t_w100 {
482 unsigned long color_depth : 3; 500 u32 color_depth : 3;
483 unsigned long portrait_mode : 2; 501 u32 portrait_mode : 2;
484 unsigned long low_power_on : 1; 502 u32 low_power_on : 1;
485 unsigned long req_freq : 4; 503 u32 req_freq : 4;
486 unsigned long en_crtc : 1; 504 u32 en_crtc : 1;
487 unsigned long en_graphic_req : 1; 505 u32 en_graphic_req : 1;
488 unsigned long en_graphic_crtc : 1; 506 u32 en_graphic_crtc : 1;
489 unsigned long total_req_graphic : 9; 507 u32 total_req_graphic : 9;
490 unsigned long lcd_pclk_on : 1; 508 u32 lcd_pclk_on : 1;
491 unsigned long lcd_sclk_on : 1; 509 u32 lcd_sclk_on : 1;
492 unsigned long pclk_running : 1; 510 u32 pclk_running : 1;
493 unsigned long sclk_running : 1; 511 u32 sclk_running : 1;
494 unsigned long : 6; 512 u32 : 6;
495} __attribute__((packed)); 513} __attribute__((packed));
496 514
497struct graphic_ctrl_t_w32xx { 515struct graphic_ctrl_t_w32xx {
498 unsigned long color_depth : 3; 516 u32 color_depth : 3;
499 unsigned long portrait_mode : 2; 517 u32 portrait_mode : 2;
500 unsigned long low_power_on : 1; 518 u32 low_power_on : 1;
501 unsigned long req_freq : 4; 519 u32 req_freq : 4;
502 unsigned long en_crtc : 1; 520 u32 en_crtc : 1;
503 unsigned long en_graphic_req : 1; 521 u32 en_graphic_req : 1;
504 unsigned long en_graphic_crtc : 1; 522 u32 en_graphic_crtc : 1;
505 unsigned long total_req_graphic : 10; 523 u32 total_req_graphic : 10;
506 unsigned long lcd_pclk_on : 1; 524 u32 lcd_pclk_on : 1;
507 unsigned long lcd_sclk_on : 1; 525 u32 lcd_sclk_on : 1;
508 unsigned long pclk_running : 1; 526 u32 pclk_running : 1;
509 unsigned long sclk_running : 1; 527 u32 sclk_running : 1;
510 unsigned long : 5; 528 u32 : 5;
511} __attribute__((packed)); 529} __attribute__((packed));
512 530
513union graphic_ctrl_u { 531union graphic_ctrl_u {
514 unsigned long val : 32; 532 u32 val : 32;
515 struct graphic_ctrl_t_w100 f_w100; 533 struct graphic_ctrl_t_w100 f_w100;
516 struct graphic_ctrl_t_w32xx f_w32xx; 534 struct graphic_ctrl_t_w32xx f_w32xx;
517} __attribute__((packed)); 535} __attribute__((packed));
518 536
519struct video_ctrl_t { 537struct video_ctrl_t {
520 unsigned long video_mode : 1; 538 u32 video_mode : 1;
521 unsigned long keyer_en : 1; 539 u32 keyer_en : 1;
522 unsigned long en_video_req : 1; 540 u32 en_video_req : 1;
523 unsigned long en_graphic_req_video : 1; 541 u32 en_graphic_req_video : 1;
524 unsigned long en_video_crtc : 1; 542 u32 en_video_crtc : 1;
525 unsigned long video_hor_exp : 2; 543 u32 video_hor_exp : 2;
526 unsigned long video_ver_exp : 2; 544 u32 video_ver_exp : 2;
527 unsigned long uv_combine : 1; 545 u32 uv_combine : 1;
528 unsigned long total_req_video : 9; 546 u32 total_req_video : 9;
529 unsigned long video_ch_sel : 1; 547 u32 video_ch_sel : 1;
530 unsigned long video_portrait : 2; 548 u32 video_portrait : 2;
531 unsigned long yuv2rgb_en : 1; 549 u32 yuv2rgb_en : 1;
532 unsigned long yuv2rgb_option : 1; 550 u32 yuv2rgb_option : 1;
533 unsigned long video_inv_hor : 1; 551 u32 video_inv_hor : 1;
534 unsigned long video_inv_ver : 1; 552 u32 video_inv_ver : 1;
535 unsigned long gamma_sel : 2; 553 u32 gamma_sel : 2;
536 unsigned long dis_limit : 1; 554 u32 dis_limit : 1;
537 unsigned long en_uv_hblend : 1; 555 u32 en_uv_hblend : 1;
538 unsigned long rgb_gamma_sel : 2; 556 u32 rgb_gamma_sel : 2;
539} __attribute__((packed)); 557} __attribute__((packed));
540 558
541union video_ctrl_u { 559union video_ctrl_u {
542 unsigned long val : 32; 560 u32 val : 32;
543 struct video_ctrl_t f; 561 struct video_ctrl_t f;
544} __attribute__((packed)); 562} __attribute__((packed));
545 563
546struct disp_db_buf_cntl_rd_t { 564struct disp_db_buf_cntl_rd_t {
547 unsigned long en_db_buf : 1; 565 u32 en_db_buf : 1;
548 unsigned long update_db_buf_done : 1; 566 u32 update_db_buf_done : 1;
549 unsigned long db_buf_cntl : 6; 567 u32 db_buf_cntl : 6;
550 unsigned long : 24; 568 u32 : 24;
551} __attribute__((packed)); 569} __attribute__((packed));
552 570
553union disp_db_buf_cntl_rd_u { 571union disp_db_buf_cntl_rd_u {
554 unsigned long val : 32; 572 u32 val : 32;
555 struct disp_db_buf_cntl_rd_t f; 573 struct disp_db_buf_cntl_rd_t f;
556} __attribute__((packed)); 574} __attribute__((packed));
557 575
558struct disp_db_buf_cntl_wr_t { 576struct disp_db_buf_cntl_wr_t {
559 unsigned long en_db_buf : 1; 577 u32 en_db_buf : 1;
560 unsigned long update_db_buf : 1; 578 u32 update_db_buf : 1;
561 unsigned long db_buf_cntl : 6; 579 u32 db_buf_cntl : 6;
562 unsigned long : 24; 580 u32 : 24;
563} __attribute__((packed)); 581} __attribute__((packed));
564 582
565union disp_db_buf_cntl_wr_u { 583union disp_db_buf_cntl_wr_u {
566 unsigned long val : 32; 584 u32 val : 32;
567 struct disp_db_buf_cntl_wr_t f; 585 struct disp_db_buf_cntl_wr_t f;
568} __attribute__((packed)); 586} __attribute__((packed));
569 587
570struct gamma_value1_t { 588struct gamma_value1_t {
571 unsigned long gamma1 : 8; 589 u32 gamma1 : 8;
572 unsigned long gamma2 : 8; 590 u32 gamma2 : 8;
573 unsigned long gamma3 : 8; 591 u32 gamma3 : 8;
574 unsigned long gamma4 : 8; 592 u32 gamma4 : 8;
575} __attribute__((packed)); 593} __attribute__((packed));
576 594
577union gamma_value1_u { 595union gamma_value1_u {
578 unsigned long val : 32; 596 u32 val : 32;
579 struct gamma_value1_t f; 597 struct gamma_value1_t f;
580} __attribute__((packed)); 598} __attribute__((packed));
581 599
582struct gamma_value2_t { 600struct gamma_value2_t {
583 unsigned long gamma5 : 8; 601 u32 gamma5 : 8;
584 unsigned long gamma6 : 8; 602 u32 gamma6 : 8;
585 unsigned long gamma7 : 8; 603 u32 gamma7 : 8;
586 unsigned long gamma8 : 8; 604 u32 gamma8 : 8;
587} __attribute__((packed)); 605} __attribute__((packed));
588 606
589union gamma_value2_u { 607union gamma_value2_u {
590 unsigned long val : 32; 608 u32 val : 32;
591 struct gamma_value2_t f; 609 struct gamma_value2_t f;
592} __attribute__((packed)); 610} __attribute__((packed));
593 611
594struct gamma_slope_t { 612struct gamma_slope_t {
595 unsigned long slope1 : 3; 613 u32 slope1 : 3;
596 unsigned long slope2 : 3; 614 u32 slope2 : 3;
597 unsigned long slope3 : 3; 615 u32 slope3 : 3;
598 unsigned long slope4 : 3; 616 u32 slope4 : 3;
599 unsigned long slope5 : 3; 617 u32 slope5 : 3;
600 unsigned long slope6 : 3; 618 u32 slope6 : 3;
601 unsigned long slope7 : 3; 619 u32 slope7 : 3;
602 unsigned long slope8 : 3; 620 u32 slope8 : 3;
603 unsigned long : 8; 621 u32 : 8;
604} __attribute__((packed)); 622} __attribute__((packed));
605 623
606union gamma_slope_u { 624union gamma_slope_u {
607 unsigned long val : 32; 625 u32 val : 32;
608 struct gamma_slope_t f; 626 struct gamma_slope_t f;
609} __attribute__((packed)); 627} __attribute__((packed));
610 628
611struct mc_ext_mem_location_t { 629struct mc_ext_mem_location_t {
612 unsigned long mc_ext_mem_start : 16; 630 u32 mc_ext_mem_start : 16;
613 unsigned long mc_ext_mem_top : 16; 631 u32 mc_ext_mem_top : 16;
614} __attribute__((packed)); 632} __attribute__((packed));
615 633
616union mc_ext_mem_location_u { 634union mc_ext_mem_location_u {
617 unsigned long val : 32; 635 u32 val : 32;
618 struct mc_ext_mem_location_t f; 636 struct mc_ext_mem_location_t f;
619} __attribute__((packed)); 637} __attribute__((packed));
620 638
621struct mc_fb_location_t { 639struct mc_fb_location_t {
622 unsigned long mc_fb_start : 16; 640 u32 mc_fb_start : 16;
623 unsigned long mc_fb_top : 16; 641 u32 mc_fb_top : 16;
624} __attribute__((packed)); 642} __attribute__((packed));
625 643
626union mc_fb_location_u { 644union mc_fb_location_u {
627 unsigned long val : 32; 645 u32 val : 32;
628 struct mc_fb_location_t f; 646 struct mc_fb_location_t f;
629} __attribute__((packed)); 647} __attribute__((packed));
630 648
631struct clk_pin_cntl_t { 649struct clk_pin_cntl_t {
632 unsigned long osc_en : 1; 650 u32 osc_en : 1;
633 unsigned long osc_gain : 5; 651 u32 osc_gain : 5;
634 unsigned long dont_use_xtalin : 1; 652 u32 dont_use_xtalin : 1;
635 unsigned long xtalin_pm_en : 1; 653 u32 xtalin_pm_en : 1;
636 unsigned long xtalin_dbl_en : 1; 654 u32 xtalin_dbl_en : 1;
637 unsigned long : 7; 655 u32 : 7;
638 unsigned long cg_debug : 16; 656 u32 cg_debug : 16;
639} __attribute__((packed)); 657} __attribute__((packed));
640 658
641union clk_pin_cntl_u { 659union clk_pin_cntl_u {
642 unsigned long val : 32; 660 u32 val : 32;
643 struct clk_pin_cntl_t f; 661 struct clk_pin_cntl_t f;
644} __attribute__((packed)); 662} __attribute__((packed));
645 663
646struct pll_ref_fb_div_t { 664struct pll_ref_fb_div_t {
647 unsigned long pll_ref_div : 4; 665 u32 pll_ref_div : 4;
648 unsigned long : 4; 666 u32 : 4;
649 unsigned long pll_fb_div_int : 6; 667 u32 pll_fb_div_int : 6;
650 unsigned long : 2; 668 u32 : 2;
651 unsigned long pll_fb_div_frac : 3; 669 u32 pll_fb_div_frac : 3;
652 unsigned long : 1; 670 u32 : 1;
653 unsigned long pll_reset_time : 4; 671 u32 pll_reset_time : 4;
654 unsigned long pll_lock_time : 8; 672 u32 pll_lock_time : 8;
655} __attribute__((packed)); 673} __attribute__((packed));
656 674
657union pll_ref_fb_div_u { 675union pll_ref_fb_div_u {
658 unsigned long val : 32; 676 u32 val : 32;
659 struct pll_ref_fb_div_t f; 677 struct pll_ref_fb_div_t f;
660} __attribute__((packed)); 678} __attribute__((packed));
661 679
662struct pll_cntl_t { 680struct pll_cntl_t {
663 unsigned long pll_pwdn : 1; 681 u32 pll_pwdn : 1;
664 unsigned long pll_reset : 1; 682 u32 pll_reset : 1;
665 unsigned long pll_pm_en : 1; 683 u32 pll_pm_en : 1;
666 unsigned long pll_mode : 1; 684 u32 pll_mode : 1;
667 unsigned long pll_refclk_sel : 1; 685 u32 pll_refclk_sel : 1;
668 unsigned long pll_fbclk_sel : 1; 686 u32 pll_fbclk_sel : 1;
669 unsigned long pll_tcpoff : 1; 687 u32 pll_tcpoff : 1;
670 unsigned long pll_pcp : 3; 688 u32 pll_pcp : 3;
671 unsigned long pll_pvg : 3; 689 u32 pll_pvg : 3;
672 unsigned long pll_vcofr : 1; 690 u32 pll_vcofr : 1;
673 unsigned long pll_ioffset : 2; 691 u32 pll_ioffset : 2;
674 unsigned long pll_pecc_mode : 2; 692 u32 pll_pecc_mode : 2;
675 unsigned long pll_pecc_scon : 2; 693 u32 pll_pecc_scon : 2;
676 unsigned long pll_dactal : 4; 694 u32 pll_dactal : 4;
677 unsigned long pll_cp_clip : 2; 695 u32 pll_cp_clip : 2;
678 unsigned long pll_conf : 3; 696 u32 pll_conf : 3;
679 unsigned long pll_mbctrl : 2; 697 u32 pll_mbctrl : 2;
680 unsigned long pll_ring_off : 1; 698 u32 pll_ring_off : 1;
681} __attribute__((packed)); 699} __attribute__((packed));
682 700
683union pll_cntl_u { 701union pll_cntl_u {
684 unsigned long val : 32; 702 u32 val : 32;
685 struct pll_cntl_t f; 703 struct pll_cntl_t f;
686} __attribute__((packed)); 704} __attribute__((packed));
687 705
688struct sclk_cntl_t { 706struct sclk_cntl_t {
689 unsigned long sclk_src_sel : 2; 707 u32 sclk_src_sel : 2;
690 unsigned long : 2; 708 u32 : 2;
691 unsigned long sclk_post_div_fast : 4; 709 u32 sclk_post_div_fast : 4;
692 unsigned long sclk_clkon_hys : 3; 710 u32 sclk_clkon_hys : 3;
693 unsigned long sclk_post_div_slow : 4; 711 u32 sclk_post_div_slow : 4;
694 unsigned long disp_cg_ok2switch_en : 1; 712 u32 disp_cg_ok2switch_en : 1;
695 unsigned long sclk_force_reg : 1; 713 u32 sclk_force_reg : 1;
696 unsigned long sclk_force_disp : 1; 714 u32 sclk_force_disp : 1;
697 unsigned long sclk_force_mc : 1; 715 u32 sclk_force_mc : 1;
698 unsigned long sclk_force_extmc : 1; 716 u32 sclk_force_extmc : 1;
699 unsigned long sclk_force_cp : 1; 717 u32 sclk_force_cp : 1;
700 unsigned long sclk_force_e2 : 1; 718 u32 sclk_force_e2 : 1;
701 unsigned long sclk_force_e3 : 1; 719 u32 sclk_force_e3 : 1;
702 unsigned long sclk_force_idct : 1; 720 u32 sclk_force_idct : 1;
703 unsigned long sclk_force_bist : 1; 721 u32 sclk_force_bist : 1;
704 unsigned long busy_extend_cp : 1; 722 u32 busy_extend_cp : 1;
705 unsigned long busy_extend_e2 : 1; 723 u32 busy_extend_e2 : 1;
706 unsigned long busy_extend_e3 : 1; 724 u32 busy_extend_e3 : 1;
707 unsigned long busy_extend_idct : 1; 725 u32 busy_extend_idct : 1;
708 unsigned long : 3; 726 u32 : 3;
709} __attribute__((packed)); 727} __attribute__((packed));
710 728
711union sclk_cntl_u { 729union sclk_cntl_u {
712 unsigned long val : 32; 730 u32 val : 32;
713 struct sclk_cntl_t f; 731 struct sclk_cntl_t f;
714} __attribute__((packed)); 732} __attribute__((packed));
715 733
716struct pclk_cntl_t { 734struct pclk_cntl_t {
717 unsigned long pclk_src_sel : 2; 735 u32 pclk_src_sel : 2;
718 unsigned long : 2; 736 u32 : 2;
719 unsigned long pclk_post_div : 4; 737 u32 pclk_post_div : 4;
720 unsigned long : 8; 738 u32 : 8;
721 unsigned long pclk_force_disp : 1; 739 u32 pclk_force_disp : 1;
722 unsigned long : 15; 740 u32 : 15;
723} __attribute__((packed)); 741} __attribute__((packed));
724 742
725union pclk_cntl_u { 743union pclk_cntl_u {
726 unsigned long val : 32; 744 u32 val : 32;
727 struct pclk_cntl_t f; 745 struct pclk_cntl_t f;
728} __attribute__((packed)); 746} __attribute__((packed));
729 747
@@ -735,36 +753,176 @@ union pclk_cntl_u {
735#define TESTCLK_SRC_XTAL 0x06 753#define TESTCLK_SRC_XTAL 0x06
736 754
737struct clk_test_cntl_t { 755struct clk_test_cntl_t {
738 unsigned long testclk_sel : 4; 756 u32 testclk_sel : 4;
739 unsigned long : 3; 757 u32 : 3;
740 unsigned long start_check_freq : 1; 758 u32 start_check_freq : 1;
741 unsigned long tstcount_rst : 1; 759 u32 tstcount_rst : 1;
742 unsigned long : 15; 760 u32 : 15;
743 unsigned long test_count : 8; 761 u32 test_count : 8;
744} __attribute__((packed)); 762} __attribute__((packed));
745 763
746union clk_test_cntl_u { 764union clk_test_cntl_u {
747 unsigned long val : 32; 765 u32 val : 32;
748 struct clk_test_cntl_t f; 766 struct clk_test_cntl_t f;
749} __attribute__((packed)); 767} __attribute__((packed));
750 768
751struct pwrmgt_cntl_t { 769struct pwrmgt_cntl_t {
752 unsigned long pwm_enable : 1; 770 u32 pwm_enable : 1;
753 unsigned long : 1; 771 u32 : 1;
754 unsigned long pwm_mode_req : 2; 772 u32 pwm_mode_req : 2;
755 unsigned long pwm_wakeup_cond : 2; 773 u32 pwm_wakeup_cond : 2;
756 unsigned long pwm_fast_noml_hw_en : 1; 774 u32 pwm_fast_noml_hw_en : 1;
757 unsigned long pwm_noml_fast_hw_en : 1; 775 u32 pwm_noml_fast_hw_en : 1;
758 unsigned long pwm_fast_noml_cond : 4; 776 u32 pwm_fast_noml_cond : 4;
759 unsigned long pwm_noml_fast_cond : 4; 777 u32 pwm_noml_fast_cond : 4;
760 unsigned long pwm_idle_timer : 8; 778 u32 pwm_idle_timer : 8;
761 unsigned long pwm_busy_timer : 8; 779 u32 pwm_busy_timer : 8;
762} __attribute__((packed)); 780} __attribute__((packed));
763 781
764union pwrmgt_cntl_u { 782union pwrmgt_cntl_u {
765 unsigned long val : 32; 783 u32 val : 32;
766 struct pwrmgt_cntl_t f; 784 struct pwrmgt_cntl_t f;
767} __attribute__((packed)); 785} __attribute__((packed));
768 786
787#define SRC_DATATYPE_EQU_DST 3
788
789#define ROP3_SRCCOPY 0xcc
790#define ROP3_PATCOPY 0xf0
791
792#define GMC_BRUSH_SOLID_COLOR 13
793#define GMC_BRUSH_NONE 15
794
795#define DP_SRC_MEM_RECTANGULAR 2
796
797#define DP_OP_ROP 0
798
799struct dp_gui_master_cntl_t {
800 u32 gmc_src_pitch_offset_cntl : 1;
801 u32 gmc_dst_pitch_offset_cntl : 1;
802 u32 gmc_src_clipping : 1;
803 u32 gmc_dst_clipping : 1;
804 u32 gmc_brush_datatype : 4;
805 u32 gmc_dst_datatype : 4;
806 u32 gmc_src_datatype : 3;
807 u32 gmc_byte_pix_order : 1;
808 u32 gmc_default_sel : 1;
809 u32 gmc_rop3 : 8;
810 u32 gmc_dp_src_source : 3;
811 u32 gmc_clr_cmp_fcn_dis : 1;
812 u32 : 1;
813 u32 gmc_wr_msk_dis : 1;
814 u32 gmc_dp_op : 1;
815} __attribute__((packed));
816
817union dp_gui_master_cntl_u {
818 u32 val : 32;
819 struct dp_gui_master_cntl_t f;
820} __attribute__((packed));
821
822struct rbbm_status_t {
823 u32 cmdfifo_avail : 7;
824 u32 : 1;
825 u32 hirq_on_rbb : 1;
826 u32 cprq_on_rbb : 1;
827 u32 cfrq_on_rbb : 1;
828 u32 hirq_in_rtbuf : 1;
829 u32 cprq_in_rtbuf : 1;
830 u32 cfrq_in_rtbuf : 1;
831 u32 cf_pipe_busy : 1;
832 u32 eng_ev_busy : 1;
833 u32 cp_cmdstrm_busy : 1;
834 u32 e2_busy : 1;
835 u32 rb2d_busy : 1;
836 u32 rb3d_busy : 1;
837 u32 se_busy : 1;
838 u32 re_busy : 1;
839 u32 tam_busy : 1;
840 u32 tdm_busy : 1;
841 u32 pb_busy : 1;
842 u32 : 6;
843 u32 gui_active : 1;
844} __attribute__((packed));
845
846union rbbm_status_u {
847 u32 val : 32;
848 struct rbbm_status_t f;
849} __attribute__((packed));
850
851struct dp_datatype_t {
852 u32 dp_dst_datatype : 4;
853 u32 : 4;
854 u32 dp_brush_datatype : 4;
855 u32 dp_src2_type : 1;
856 u32 dp_src2_datatype : 3;
857 u32 dp_src_datatype : 3;
858 u32 : 11;
859 u32 dp_byte_pix_order : 1;
860 u32 : 1;
861} __attribute__((packed));
862
863union dp_datatype_u {
864 u32 val : 32;
865 struct dp_datatype_t f;
866} __attribute__((packed));
867
868struct dp_mix_t {
869 u32 : 8;
870 u32 dp_src_source : 3;
871 u32 dp_src2_source : 3;
872 u32 : 2;
873 u32 dp_rop3 : 8;
874 u32 dp_op : 1;
875 u32 : 7;
876} __attribute__((packed));
877
878union dp_mix_u {
879 u32 val : 32;
880 struct dp_mix_t f;
881} __attribute__((packed));
882
883struct eng_cntl_t {
884 u32 erc_reg_rd_ws : 1;
885 u32 erc_reg_wr_ws : 1;
886 u32 erc_idle_reg_wr : 1;
887 u32 dis_engine_triggers : 1;
888 u32 dis_rop_src_uses_dst_w_h : 1;
889 u32 dis_src_uses_dst_dirmaj : 1;
890 u32 : 6;
891 u32 force_3dclk_when_2dclk : 1;
892 u32 : 19;
893} __attribute__((packed));
894
895union eng_cntl_u {
896 u32 val : 32;
897 struct eng_cntl_t f;
898} __attribute__((packed));
899
900struct dp_cntl_t {
901 u32 dst_x_dir : 1;
902 u32 dst_y_dir : 1;
903 u32 src_x_dir : 1;
904 u32 src_y_dir : 1;
905 u32 dst_major_x : 1;
906 u32 src_major_x : 1;
907 u32 : 26;
908} __attribute__((packed));
909
910union dp_cntl_u {
911 u32 val : 32;
912 struct dp_cntl_t f;
913} __attribute__((packed));
914
915struct dp_cntl_dst_dir_t {
916 u32 : 15;
917 u32 dst_y_dir : 1;
918 u32 : 15;
919 u32 dst_x_dir : 1;
920} __attribute__((packed));
921
922union dp_cntl_dst_dir_u {
923 u32 val : 32;
924 struct dp_cntl_dst_dir_t f;
925} __attribute__((packed));
926
769#endif 927#endif
770 928